hg-fast-export.py: Minor tweaks/cleanup
authorRocco Rutte <pdmef@gmx.net>
Thu, 25 Oct 2007 13:21:46 +0000 (15:21 +0200)
committerRocco Rutte <pdmef@gmx.net>
Thu, 25 Oct 2007 13:21:46 +0000 (15:21 +0200)
Remove some unused variables, generalize dictionary-splitting and make
sure we don't sort filename lists twice (repo.status returns files
sorted already).

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
hg-fast-export.py

index c85e84e439dacf75e27adf76e1b28f467f9d8812..811333367f43fa2c8085bb0991cbfb551ef7145c 100755 (executable)
@@ -41,18 +41,18 @@ def get_parent_mark(parent,marks):
   otherwise the SHA1 from the cache."""
   return marks.get(str(parent),':%d' % (parent+1))
 
-def mismatch(f1,f2):
+def file_mismatch(f1,f2):
   """See if two revisions of a file are not equal."""
   return node.hex(f1)!=node.hex(f2)
 
-def outer_set(dleft,dright,l,c,r):
+def split_dict(dleft,dright,l=[],c=[],r=[],match=file_mismatch):
   """Loop over our repository and find all changed and missing files."""
   for left in dleft.keys():
     right=dright.get(left,None)
     if right==None:
       # we have the file but our parent hasn't: add to left set
       l.append(left)
-    elif mismatch(dleft[left],right):
+    elif match(dleft[left],right):
       # we have it but checksums mismatch: add to center set
       c.append(left)
   for right in dright.keys():
@@ -69,11 +69,10 @@ def get_filechanges(repo,revision,parents,mleft):
   for p in parents:
     if p<0: continue
     mright=repo.changectx(p).manifest()
-    dleft=mleft.keys()
-    dleft.sort()
-    dright=mright.keys()
-    dright.sort()
-    l,c,r=outer_set(mleft,mright,l,c,r)
+    l,c,r=split_dict(mleft,mright,l,c,r)
+  l.sort()
+  c.sort()
+  r.sort()
   return l,c,r
 
 def get_author(logmessage,committer,authors):
@@ -115,11 +114,9 @@ def get_author(logmessage,committer,authors):
 
 def export_file_contents(ctx,manifest,files):
   count=0
-  files.sort()
   max=len(files)
   for file in files:
-    fctx=ctx.filectx(file)
-    d=fctx.data()
+    d=ctx.filectx(file).data()
     wr('M %s inline %s' % (gitmode(manifest.execf(file)),file))
     wr('data %d' % len(d)) # had some trouble with size()
     wr(d)
@@ -194,6 +191,7 @@ def export_commit(ui,repo,revision,marks,heads,last,max,count,authors,sob):
   if revision==0:
     # first revision: feed in full manifest
     added=man.keys()
+    added.sort()
     type='full'
   elif is_merge(parents):
     # later merge revision: feed in changed manifest
@@ -213,7 +211,8 @@ def export_commit(ui,repo,revision,marks,heads,last,max,count,authors,sob):
       (branch,type,revision+1,max,len(added),len(changed),len(removed)))
 
   map(lambda r: wr('D %s' % r),removed)
-  export_file_contents(ctx,man,added+changed)
+  export_file_contents(ctx,man,added)
+  export_file_contents(ctx,man,changed)
   wr()
 
   return checkpoint(count)