# HG changeset patch # User Scott Chacon # Date 1242752456 25200 # Node ID 2fa3ac77598394bdabf4fa01ab58646c25911f7a # Parent 8cabda8ae1c6aa891b5850d0091bc62c088e8c2e# Parent 5aefcbf1e50c363d6550dd975f26f07167bf5e85 merged in srabbeliers stuff diff -r 8cabda8ae1c6 -r 2fa3ac775983 __init__.py --- a/__init__.py Tue May 19 09:40:54 2009 -0700 +++ b/__init__.py Tue May 19 10:00:56 2009 -0700 @@ -45,21 +45,27 @@ git = GitHandler(repo, ui) git.push(remote_name) +def gimport(ui, repo, remote_name=None): + git = GitHandler(repo, ui) + git.import_commits(remote_name) + def gexport(ui, repo): git = GitHandler(repo, ui) - git.export() + git.export_commits() def gremote(ui, repo, *args): git = GitHandler(repo, ui) if len(args) == 0: git.remote_list() + elif len(args) < 2: + repo.ui.warn(_("must supply an action and a remote\n")) else: verb = args[0] nick = args[1] if verb == 'add': - if args[2]: + if len(args) == 3: git.remote_add(nick, args[2]) else: repo.ui.warn(_("must supply a url to add as a remote\n")) @@ -88,6 +94,8 @@ ), "gpush": (gpush, [], _('hg gpush remote')), + "gimport": + (gimport, [], _('hg gimport')), "gexport": (gexport, [], _('hg gexport')), "gfetch": diff -r 8cabda8ae1c6 -r 2fa3ac775983 git_handler.py --- a/git_handler.py Tue May 19 09:40:54 2009 -0700 +++ b/git_handler.py Tue May 19 10:00:56 2009 -0700 @@ -51,7 +51,12 @@ self.ui = ui self.mapfile = 'git-mapfile' self.configfile = 'git-config' - self.gitdir = self.repo.join('git') + + if ui.config('git', 'intree'): + self.gitdir = self.repo.wjoin('.git') + else: + self.gitdir = self.repo.join('git') + self.init_if_missing() self.load_git() self.load_map() @@ -109,22 +114,25 @@ ## END FILE LOAD AND SAVE METHODS + def import_commits(self, remote_name): + self.import_git_objects(remote_name) + self.save_map() + def fetch(self, remote_name): self.ui.status(_("fetching from : %s\n") % remote_name) self.export_git_objects() refs = self.fetch_pack(remote_name) if refs: - self.import_git_objects(remote_name) - self.save_map() + self.import_commits(remote_name) - def export(self): + def export_commits(self): self.export_git_objects() self.update_references() self.save_map() def push(self, remote_name): self.ui.status(_("pushing to : %s\n") % remote_name) - self.export() + self.export_commits() self.update_remote_references(remote_name) self.upload_pack(remote_name) @@ -473,17 +481,18 @@ f.close() raise - def import_git_objects(self, remote_name): + def import_git_objects(self, remote_name=None): self.ui.status(_("importing Git objects into Hg\n")) # import heads as remote references todo = [] done = set() convert_list = {} self.renames = {} - - # get a list of all the head shas - for head, sha in self.git.remote_refs(remote_name).iteritems(): - todo.append(sha) + + if remote_name: + todo = self.git.remote_refs(remote_name).values()[:] + else: + todo = self.git.heads().values()[:] # traverse the heads getting a list of all the unique commits while todo: @@ -503,7 +512,11 @@ commits = toposort.TopoSort(convert_list).items() # import each of the commits, oldest first - for csha in commits: + total = len(commits) + magnitude = int(math.log(total, 10)) + 1 if total else 1 + for i, csha in enumerate(commits): + if i%100 == 0: + self.ui.status(_("at: %*d/%d\n") % (magnitude, i, total)) commit = convert_list[csha] if not self.map_hg_get(csha): # it's already here self.import_git_commit(commit)