1 |
Since os.chdir calls may not be safe to use in threads, iterators, |
2 |
or event-driven code, make FindVCS support a cwd argument which |
3 |
defaults to the current working directory. |
4 |
--- |
5 |
pym/repoman/vcs/vcs.py | 20 +++++++++++++++----- |
6 |
1 file changed, 15 insertions(+), 5 deletions(-) |
7 |
|
8 |
diff --git a/pym/repoman/vcs/vcs.py b/pym/repoman/vcs/vcs.py |
9 |
index 49d3058..a463335 100644 |
10 |
--- a/pym/repoman/vcs/vcs.py |
11 |
+++ b/pym/repoman/vcs/vcs.py |
12 |
@@ -39,15 +39,25 @@ _FindVCS_data = ( |
13 |
) |
14 |
|
15 |
|
16 |
-def FindVCS(): |
17 |
- """ Try to figure out in what VCS' working tree we are. """ |
18 |
+def FindVCS(cwd=None): |
19 |
+ """ |
20 |
+ Try to figure out in what VCS' working tree we are. |
21 |
+ |
22 |
+ @param cwd: working directory (default is os.getcwd()) |
23 |
+ @type cwd: str |
24 |
+ @return: list of strings describing the discovered vcs types |
25 |
+ @rtype: list |
26 |
+ """ |
27 |
+ |
28 |
+ if cwd is None: |
29 |
+ cwd = os.getcwd() |
30 |
|
31 |
outvcs = [] |
32 |
|
33 |
def seek(depth=None): |
34 |
""" Seek for VCSes that have a top-level data directory only. """ |
35 |
retvcs = [] |
36 |
- pathprep = '' |
37 |
+ pathprep = cwd |
38 |
|
39 |
while depth is None or depth > 0: |
40 |
for vcs_type in _FindVCS_data: |
41 |
@@ -70,10 +80,10 @@ def FindVCS(): |
42 |
return retvcs |
43 |
|
44 |
# Level zero VCS-es. |
45 |
- if os.path.isdir('CVS'): |
46 |
+ if os.path.isdir(os.path.join(cwd, 'CVS')): |
47 |
outvcs.append('cvs') |
48 |
if os.path.isdir('.svn'): # <1.7 |
49 |
- outvcs.append('svn') |
50 |
+ outvcs.append(os.path.join(cwd, 'svn')) |
51 |
|
52 |
# If we already found one of 'level zeros', just take a quick look |
53 |
# at the current directory. Otherwise, seek parents till we get |
54 |
-- |
55 |
2.4.9 |