Rewrite VCS detection code in repoman.
authorMichał Górny <gentoo@mgorny.alt.pl>
Sun, 11 Jul 2010 09:50:02 +0000 (11:50 +0200)
committerZac Medico <zmedico@gentoo.org>
Sun, 11 Jul 2010 18:25:56 +0000 (11:25 -0700)
Move the real code into repoman.utilities. Support any repository depth
for distributed SCMs -- i.e. Sunrise through git-svn. Bail out if more
than one control version directory is found at the same depth.

bin/repoman
pym/repoman/utilities.py

index 324ad2ea2f59715da72112360d8737137dab83e4..8ded3475ddf0bef5c7637023c097f85c50288684 100755 (executable)
@@ -476,17 +476,14 @@ if portdir is None:
 myreporoot = os.path.basename(portdir_overlay)
 myreporoot += mydir[len(portdir_overlay):]
 
-vcs = None
-if os.path.isdir("CVS"):
-       vcs = "cvs"
-if os.path.isdir(".svn"):
-       vcs = "svn"
-elif os.path.isdir(os.path.join(portdir_overlay, ".git")):
-       vcs = "git"
-elif os.path.isdir(os.path.join(portdir_overlay, ".bzr")):
-       vcs = "bzr"
-elif os.path.isdir(os.path.join(portdir_overlay, ".hg")):
-       vcs = "hg"
+vcses = utilities.FindVCS()
+if len(vcses) > 1:
+       print(red('*** Ambiguous workdir -- more than one VCS found at the same depth: %s.' % ', '.join(vcses)))
+       sys.exit(1)
+elif vcses:
+       vcs = vcses[0]
+else:
+       vcs = None
 
 # Note: We don't use ChangeLogs in distributed SCMs.
 # It will be generated on server side from scm log,
index 30508041164e91c6161c99d921aef2fffe6abe2b..a07b4a43634e3be397da0a418c16bb31b18892cf 100644 (file)
@@ -433,3 +433,47 @@ def FindPortdir(settings):
                portdir += '/'
 
        return [normalize_path(x) for x in (portdir, portdir_overlay, location)]
+
+def FindVCS():
+       """ Try to figure out in what VCS' working tree we are. """
+
+       outvcs = []
+
+       def seek(depth = None):
+               """ Seek for distributed VCSes. """
+               retvcs = []
+               pathprep = ''
+
+               while depth is None or depth > 0:
+                       if os.path.isdir(os.path.join(pathprep, '.git')):
+                               retvcs.append('git')
+                       if os.path.isdir(os.path.join(pathprep, '.bzr')):
+                               retvcs.append('bzr')
+                       if os.path.isdir(os.path.join(pathprep, '.hg')):
+                               retvcs.append('hg')
+
+                       if retvcs:
+                               break
+                       pathprep = os.path.join(pathprep, '..')
+                       if os.path.realpath(pathprep).strip('/') == '':
+                               break
+                       if depth is not None:
+                               depth = depth - 1
+
+               return retvcs
+
+       # Level zero VCS-es.
+       if os.path.isdir('CVS'):
+               outvcs.append('cvs')
+       if os.path.isdir('.svn'):
+               outvcs.append('svn')
+
+       # If we already found one of 'level zeros', just take a quick look
+       # at the current directory. Otherwise, seek parents till we get
+       # something or reach root.
+       if outvcs:
+               outvcs.extend(seek(1))
+       else:
+               outvcs = seek()
+
+       return outvcs