Commits

Brendan Cully  committed de73179

Convert dulwich progress into mercurial ui.progress

Breaks most tests cosmetically, but for the better.

  • Participants
  • Parent commits d89d4e9

Comments (0)

Files changed (1)

File hggit/git_handler.py

 import util
 from overlay import overlayrepo
 
+class GitProgress(object):
+    """convert git server progress strings into mercurial progress"""
+    def __init__(self, ui):
+        self.ui = ui
+
+        self.lasttopic = None
+        self.msgbuf = ''
+
+    def progress(self, msg):
+        # 'Counting objects: 33640, done.\n'
+        # 'Compressing objects:   0% (1/9955)   \r
+        msgs = re.split('[\r\n]', self.msgbuf + msg)
+        self.msgbuf = msgs.pop()
+
+        for msg in msgs:
+            td = msg.split(':', 1)
+            data = td.pop()
+            if not td:
+                self.flush(data)
+                continue
+            topic = td[0]
+
+            m = re.search('\((\d+)/(\d+)\)', data)
+            if m:
+                if self.lasttopic and self.lasttopic != topic:
+                    self.flush()
+                self.lasttopic = topic
+
+                pos, total = map(int, m.group(1, 2))
+                self.ui.progress(topic, pos, total=total)
+            else:
+                self.flush(msg)
+
+    def flush(self, msg=None):
+        if self.lasttopic:
+            self.ui.progress(self.lasttopic, None)
+        self.lasttopic = None
+        if msg:
+            self.ui.note(msg + '\n')
+
 class GitHandler(object):
     mapfile = 'git-mapfile'
     tagsfile = 'git-tags'
         f, commit = self.git.object_store.add_pack()
         try:
             try:
-                return client.fetch_pack(path, determine_wants, graphwalker,
-                                         f.write, self.ui.status)
+                progress = GitProgress(self.ui)
+                ret = client.fetch_pack(path, determine_wants, graphwalker,
+                                        f.write, progress.progress)
+                progress.flush()
+                return ret
             except (HangupException, GitProtocolError), e:
                 raise hgutil.Abort(_("git remote error: ") + str(e))
         finally: