remote-hg: use marks instead of inlined files
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 us some performance boost. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Apr 22, 2013 at 16:55 UTC
97253a233226b577da7c030a1f5ffe7445a25bbe
1 file changed
+33
-8
contrib/remote-helpers/git-remote-hg
+33
-8
@@ -126,6 +126,10 @@ class Marks:
126
def to_rev(self, mark):
127
return self.rev_marks[mark]
128
129
+ def next_mark(self):
130
+ self.last_mark += 1
131
+ return self.last_mark
132
+
133
def get_mark(self, rev):
134
self.last_mark += 1
135
self.marks[str(rev)] = self.last_mark
@@ -218,12 +222,29 @@ def fix_file_path(path):
222
return path
223
return os.path.relpath(path, '/')
224
221
-def export_file(fc):
222
- d = fc.data()
223
- path = fix_file_path(fc.path())
224
- print "M %s inline %s" % (gitmode(fc.flags()), path)
225
- print "data %d" % len(d)
226
- print d
225
+def export_files(files):
226
+ global marks, filenodes
227
+
228
+ final = []
229
+ for f in files:
230
+ fid = node.hex(f.filenode())
231
+
232
+ if fid in filenodes:
233
+ mark = filenodes[fid]
234
+ else:
235
+ mark = marks.next_mark()
236
+ filenodes[fid] = mark
237
+ d = f.data()
238
+
239
+ print "blob"
240
+ print "mark :%u" % mark
241
+ print "data %d" % len(d)
242
+ print d
243
+
244
+ path = fix_file_path(f.path())
245
+ final.append((gitmode(f.flags()), mark, path))
246
+
247
+ return final
248
249
def get_filechanges(repo, ctx, parent):
250
modified = set()
@@ -413,6 +434,8 @@ def export_ref(repo, name, kind, head):
434
if len(parents) == 0 and rev:
435
print 'reset %s/%s' % (prefix, ename)
436
437
+ modified_final = export_files(c.filectx(f) for f in modified)
438
+
439
print "commit %s/%s" % (prefix, ename)
440
print "mark :%d" % (marks.get_mark(rev))
441
print "author %s" % (author)
@@ -425,8 +448,8 @@ def export_ref(repo, name, kind, head):
448
if len(parents) > 1:
449
print "merge :%s" % (rev_to_mark(parents[1]))
450
428
- for f in modified:
429
- export_file(c.filectx(f))
451
+ for f in modified_final:
452
+ print "M %s :%u %s" % f
453
for f in removed:
454
print "D %s" % (fix_file_path(f))
455
print
@@ -878,6 +901,7 @@ def main(args):
901
global peer, mode, bad_mail, bad_name
902
global track_branches, force_push, is_tmp
903
global parsed_tags
904
+ global filenodes
905
906
alias = args[1]
907
url = args[2]
@@ -921,6 +945,7 @@ def main(args):
945
parsed_refs = {}
946
marks = None
947
parsed_tags = {}
948
+ filenodes = {}
949
950
repo = get_repo(url, alias)
951
prefix = 'refs/hg/%s' % alias