changeset 137:5aefcbf1e50c

add a gimport command This allows for exporting git commits to hg commits without doing an explicit fetch, which is useful when directly manipulating the git repository
author Sverre Rabbelier <sverre@rabbelier.nl>
date Fri, 15 May 2009 00:48:24 +0200
parents 74385b613bb7
children 2fa3ac775983
files __init__.py git_handler.py
diffstat 2 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/__init__.py	Fri May 15 00:43:38 2009 +0200
+++ b/__init__.py	Fri May 15 00:48:24 2009 +0200
@@ -45,6 +45,10 @@
     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_commits()
@@ -90,6 +94,8 @@
        ),
   "gpush":
         (gpush, [], _('hg gpush remote')),
+  "gimport":
+        (gimport, [], _('hg gimport')),
   "gexport":
         (gexport, [], _('hg gexport')),
   "gfetch":
--- a/git_handler.py	Fri May 15 00:43:38 2009 +0200
+++ b/git_handler.py	Fri May 15 00:48:24 2009 +0200
@@ -113,13 +113,16 @@
 
     ## 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_commits(self):
         self.export_git_objects()
@@ -435,17 +438,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: