Skip to content

Commit 97253a2

Browse files
Felipe Contrerasgitster
authored andcommitted
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>
1 parent 1a2636c commit 97253a2

1 file changed

Lines changed: 33 additions & 8 deletions

File tree

contrib/remote-helpers/git-remote-hg

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ class Marks:
126126
def to_rev(self, mark):
127127
return self.rev_marks[mark]
128128

129+
def next_mark(self):
130+
self.last_mark += 1
131+
return self.last_mark
132+
129133
def get_mark(self, rev):
130134
self.last_mark += 1
131135
self.marks[str(rev)] = self.last_mark
@@ -218,12 +222,29 @@ def fix_file_path(path):
218222
return path
219223
return os.path.relpath(path, '/')
220224

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
227248

228249
def get_filechanges(repo, ctx, parent):
229250
modified = set()
@@ -413,6 +434,8 @@ def export_ref(repo, name, kind, head):
413434
if len(parents) == 0 and rev:
414435
print 'reset %s/%s' % (prefix, ename)
415436

437+
modified_final = export_files(c.filectx(f) for f in modified)
438+
416439
print "commit %s/%s" % (prefix, ename)
417440
print "mark :%d" % (marks.get_mark(rev))
418441
print "author %s" % (author)
@@ -425,8 +448,8 @@ def export_ref(repo, name, kind, head):
425448
if len(parents) > 1:
426449
print "merge :%s" % (rev_to_mark(parents[1]))
427450

428-
for f in modified:
429-
export_file(c.filectx(f))
451+
for f in modified_final:
452+
print "M %s :%u %s" % f
430453
for f in removed:
431454
print "D %s" % (fix_file_path(f))
432455
print
@@ -878,6 +901,7 @@ def main(args):
878901
global peer, mode, bad_mail, bad_name
879902
global track_branches, force_push, is_tmp
880903
global parsed_tags
904+
global filenodes
881905

882906
alias = args[1]
883907
url = args[2]
@@ -921,6 +945,7 @@ def main(args):
921945
parsed_refs = {}
922946
marks = None
923947
parsed_tags = {}
948+
filenodes = {}
924949

925950
repo = get_repo(url, alias)
926951
prefix = 'refs/hg/%s' % alias

0 commit comments

Comments
 (0)