git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 15/16] remote-hg: use marks instead of inlined files

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 22, 2013, 21:55 UTC
Message-ID
<1366667724-567-16-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1366667724-567-1-git-send-email-felipe.contreras@gmail.com>

So that we can find already exported ones. We can never be 100% sure that we already exported such data, due to mercurial design, it at least sometimes we should detect them, and so should give ups some performance boost.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-hg | 41 +++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 8 deletions(-)
diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index f80236b..d0e552c 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -126,6 +126,10 @@ class Marks:
     def to_rev(self, mark):
         return self.rev_marks[mark]
 
+    def next_mark(self):
+        self.last_mark += 1
+        return self.last_mark
+
     def get_mark(self, rev):
         self.last_mark += 1
         self.marks[str(rev)] = self.last_mark
@@ -218,12 +222,29 @@ def fix_file_path(path):
         return path
     return os.path.relpath(path, '/')
 
-def export_file(fc):
-    d = fc.data()
-    path = fix_file_path(fc.path())
-    print "M %s inline %s" % (gitmode(fc.flags()), path)
-    print "data %d" % len(d)
-    print d
+def export_files(files):
+    global marks, filenodes
+
+    final = []
+    for f in files:
+        fid = node.hex(f.filenode())
+
+        if fid in filenodes:
+            mark = filenodes[fid]
+        else:
+            mark = marks.next_mark()
+            filenodes[fid] = mark
+            d = f.data()
+
+            print "blob"
+            print "mark :%u" % mark
+            print "data %d" % len(d)
+            print d
+
+        path = fix_file_path(f.path())
+        final.append((gitmode(f.flags()), mark, path))
+
+    return final
 
 def get_filechanges(repo, ctx, parent):
     modified = set()
@@ -413,6 +434,8 @@ def export_ref(repo, name, kind, head):
         if len(parents) == 0 and rev:
             print 'reset %s/%s' % (prefix, ename)
 
+        modified_final = export_files(c.filectx(f) for f in modified)
+
         print "commit %s/%s" % (prefix, ename)
         print "mark :%d" % (marks.get_mark(rev))
         print "author %s" % (author)
@@ -425,8 +448,8 @@ def export_ref(repo, name, kind, head):
             if len(parents) > 1:
                 print "merge :%s" % (rev_to_mark(parents[1]))
 
-        for f in modified:
-            export_file(c.filectx(f))
+        for f in modified_final:
+            print "M %s :%u %s" % f
         for f in removed:
             print "D %s" % (fix_file_path(f))
         print
@@ -878,6 +901,7 @@ def main(args):
     global peer, mode, bad_mail, bad_name
     global track_branches, force_push, is_tmp
     global parsed_tags
+    global filenodes
 
     alias = args[1]
     url = args[2]
@@ -921,6 +945,7 @@ def main(args):
     parsed_refs = {}
     marks = None
     parsed_tags = {}
+    filenodes = {}
 
     repo = get_repo(url, alias)
     prefix = 'refs/hg/%s' % alias
-- 
1.8.2.1.790.g4588561
Previous: Felipe ContrerasNext: Junio C Hamano
Message 22 of 24 in “remote-hg: second round of improvements”
  1. 00/16 remote-hg: second round of improvementsFelipe Contreras, Apr 22, 2013
  2. 01/16 remote-helpers: avoid has_keyFelipe Contreras, Apr 22, 2013
  3. Junio C HamanoApr 22, 2013
  4. Felipe ContrerasApr 22, 2013
  5. Dusty PhillipsApr 22, 2013
  6. 02/16 remote-hg: safer bookmark pushingFelipe Contreras, Apr 22, 2013
  7. 03/16 remote-hg: use python urlparseFelipe Contreras, Apr 22, 2013
  8. 04/16 remote-hg: properly mark branches up-to-dateFelipe Contreras, Apr 22, 2013
  9. 05/16 remote-hg: add branch_tip() helperFelipe Contreras, Apr 22, 2013
  10. 06/16 remote-hg: add support for tag objectsFelipe Contreras, Apr 22, 2013
  11. 07/16 remote-hg: custom method to write tagsFelipe Contreras, Apr 22, 2013
  12. 08/16 remote-hg: write tags in the appropriate branchFelipe Contreras, Apr 22, 2013
  13. 09/16 remote-hg: add custom local tag write codeFelipe Contreras, Apr 22, 2013
  14. 10/16 remote-hg: improve email sanitationFelipe Contreras, Apr 22, 2013
  15. 11/16 remote-hg: add support for schemes extensionFelipe Contreras, Apr 22, 2013
  16. 12/16 remote-hg: don't update bookmarks unnecessarilyFelipe Contreras, Apr 22, 2013
  17. 13/16 remote-hg: allow refs with spacesFelipe Contreras, Apr 22, 2013
  18. Junio C HamanoApr 22, 2013
  19. Felipe ContrerasApr 22, 2013
  20. Junio C HamanoApr 22, 2013
  21. 14/16 remote-hg: small performance improvementFelipe Contreras, Apr 22, 2013
  22. 15/16 remote-hg: use marks instead of inlined filesFelipe Contreras, Apr 22, 2013
  23. Junio C HamanoApr 22, 2013
  24. 16/16 remote-hg: strip extra newlineFelipe Contreras, Apr 22, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.