changeset 138:2fa3ac775983

merged in srabbeliers stuff
author Scott Chacon <schacon@gmail.com>
date Tue, 19 May 2009 10:00:56 -0700
parents 8cabda8ae1c6 (current diff) 5aefcbf1e50c (diff)
children 33da6875a534 6701ab807bf5 85eae64ca9e2
files git_handler.py
diffstat 2 files changed, 34 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/__init__.py
+++ b/__init__.py
@@ -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":
--- a/git_handler.py
+++ b/git_handler.py
@@ -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)