PATCH: add git to verify-cvs2svn.py ; fix too many warnings issue

James Blackburn <[email protected]> Tue, 24 Aug 2010 17:19:51 +0100
Newsgroups gmane.comp.version-control.subversion.cvs2svn.devel
Message-ID <[email protected]>
Hi All,

Attached is a patch to add --git support to verify-cvs2svn.py -- in a
similar manner to HgRepos.

It also fixes an issue whereby file mismatches are reproted file_size
/ 8K times.

Cheers,
James

------------------------------------------------------
http://cvs2svn.tigris.org/ds/viewMessage.do?dsForumId=1667&dsMessageId=2650730

To unsubscribe from this discussion, e-mail: [[email protected]].
verify-cvs2svn.patch (application/octet-stream, 3.4 KB)
### Eclipse Workspace Patch 1.0
#P cvs2svn
Index: contrib/verify-cvs2svn.py
===================================================================
--- contrib/verify-cvs2svn.py	(revision 5247)
+++ contrib/verify-cvs2svn.py	(working copy)
@@ -42,6 +42,7 @@
 CVS_CMD = 'cvs'
 SVN_CMD = 'svn'
 HG_CMD = 'hg'
+GIT_CMD = 'git'
 
 
 def pipe(cmd):
@@ -247,7 +248,75 @@
   name = 'git'
 
   def __init__(self, path):
-    raise NotImplementedError()
+    self.path = path
+    self.repo_cmd = [GIT_CMD, '--git-dir=' + self.path + '/.git', '--work-tree=' + self.path]
+
+    self._branches = None               # cache result of branches()
+    self._have_master = None           # so export_trunk() doesn't blow up
+
+  def __str__(self):
+    return os.path.basename(self.path)
+
+  def _export(self, dest_path, rev):
+    # clone the repository
+    cmd = [GIT_CMD, 'clone', '-q', self.path, dest_path ]
+    
+    (output, status) = pipe(cmd)
+    if status or output:
+      cmd_failed(cmd, output, status)
+      
+    if not os.path.exists(dest_path):
+      raise RuntimeError('Git clone of %s to %s failed!' % self.path, dest_path)
+    
+    # Now checkout the specified branch / tag
+    cmd = [GIT_CMD, '--git-dir=' + dest_path + '/.git', '--work-tree=' + dest_path]
+
+    # Checkout the given branch / tag
+    cmd = cmd + ['checkout', '-q', rev]
+    (output, status) = pipe(cmd)
+    if status or output:
+      cmd_failed(cmd, output, status)
+
+  def export_trunk(self, dest_path):
+    self.branches()                     # ensure _have_default is set
+    if self._have_master:
+      self._export(dest_path, 'master')
+    else:
+      # same as CVS does when exporting empty trunk
+      os.mkdir(dest_path)
+
+  def export_tag(self, dest_path, tag):
+    self._export(dest_path, tag)
+
+  def export_branch(self, dest_path, branch):
+    self._export(dest_path, branch)
+
+  def tags(self):
+    cmd = self.repo_cmd + ['tag']
+    tags = self._split_output(cmd)
+    return tags
+
+  def branches(self):
+    if self._branches is None:
+      cmd = self.repo_cmd + ['branch']
+      branches = self._split_output(cmd)
+      # Remove the two chracters at the start of the branch name
+      for i in range(len(branches)):
+        branches[i] = branches[i][2:]
+      self._branches = branches
+      try:
+        branches.remove('master')
+        self._have_master = True
+      except ValueError:
+        self._have_master = False
+
+    return self._branches
+
+  def _split_output(self, cmd):
+    (output, status) = pipe(cmd)
+    if status:
+      cmd_failed(cmd, output, status)
+    return output.split("\n")[:-1]
 
 def transform_symbol(ctx, name):
   """Transform the symbol NAME using the renaming rules specified
@@ -316,6 +385,7 @@
       failures.report('File contents differ for %s' % rel_path,
                       details=diff)
       ok = False
+      break
     if len(data1) == 0:
       # eof
       break
@@ -494,7 +564,7 @@
                     help='assume verify-repos is hg')
   parser.add_option('--git',
                     action='store_const', dest='repos_type', const='git',
-                    help='assume verify-repos is git (not implemented!)')
+                    help='assume verify-repos is git')
   parser.add_option('--suppress-keywords',
                     action='store_const', dest='keyword_opt', const='-kk',
                     help='suppress CVS keyword expansion '