diff options
author | Michał Górny <gentoo@mgorny.alt.pl> | 2010-07-11 11:50:02 +0200 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-07-11 11:25:56 -0700 |
commit | 49e3e6196c243ba1995ec1000b51ccee768493a4 (patch) | |
tree | a2bca3f06dcf9a7a28dd6afcd352a93179e2041b /pym/repoman | |
parent | eca826bd3aa70697955ebcd035cf939efd7ab8db (diff) | |
download | portage-49e3e6196c243ba1995ec1000b51ccee768493a4.tar.gz portage-49e3e6196c243ba1995ec1000b51ccee768493a4.tar.bz2 portage-49e3e6196c243ba1995ec1000b51ccee768493a4.zip |
Rewrite VCS detection code in repoman.
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.
Diffstat (limited to 'pym/repoman')
-rw-r--r-- | pym/repoman/utilities.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 305080411..a07b4a436 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -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 |