hg2git.py: Refactor main code into hg2git() function
authorRocco Rutte <pdmef@gmx.net>
Thu, 8 Mar 2007 11:21:21 +0000 (11:21 +0000)
committerRocco Rutte <pdmef@gmx.net>
Thu, 8 Mar 2007 11:21:21 +0000 (11:21 +0000)
Now this can even be used as a module from other python scripts by
simply calling the hg2git() function.

Except some config values nobody really ever wants to change, it's even
save to run several hg2git() functions in parallel as no global vars or
the like are used by intention (but it makes the code uglier).

Signed-off-by: Rocco Rutte <pdmef@gmx.net>
hg2git.py

index ee95dfb..1683cb5 100644 (file)
--- a/hg2git.py
+++ b/hg2git.py
@@ -238,9 +238,7 @@ def verify_heads(ui,repo,cache):
         '\n%s (repo) != %s (cache)\n' % (b,sha1,c))
   return True
 
-if __name__=='__main__':
-  if len(sys.argv)!=6: sys.exit(usage(1))
-  repourl,m,marksfile,headsfile,tipfile=sys.argv[1:]
+def hg2git(repourl,m,marksfile,headsfile,tipfile):
   _max=int(m)
 
   marks_cache=load_cache(marksfile)
@@ -250,7 +248,7 @@ if __name__=='__main__':
   ui,repo=setup_repo(repourl)
 
   if not verify_heads(ui,repo,heads_cache):
-    sys.exit(1)
+    return 1
 
   tip=repo.changelog.count()
 
@@ -271,3 +269,10 @@ if __name__=='__main__':
   state_cache['tip']=max
   state_cache['repo']=repourl
   save_cache(tipfile,state_cache)
+
+  return 0
+
+if __name__=='__main__':
+  if len(sys.argv)!=6: sys.exit(usage(1))
+  repourl,m,marksfile,headsfile,tipfile=sys.argv[1:]
+  sys.exit(hg2git(repourl,m,marksfile,headsfile,tipfile))