Show More
@@ -25,7 +25,6 b' class Purge(object):' | |||
|
25 | 25 | def __init__(self, act=True, abort_on_err=False, eol='\n'): |
|
26 | 26 | self._repo = None |
|
27 | 27 | self._ui = None |
|
28 | self._hg_root = None | |
|
29 | 28 | self._act = act |
|
30 | 29 | self._abort_on_err = abort_on_err |
|
31 | 30 | self._eol = eol |
@@ -33,7 +32,6 b' class Purge(object):' | |||
|
33 | 32 | def purge(self, ui, repo, dirs=None): |
|
34 | 33 | self._repo = repo |
|
35 | 34 | self._ui = ui |
|
36 | self._hg_root = self._split_path(repo.root) | |
|
37 | 35 | |
|
38 | 36 | directories = [] |
|
39 | 37 | files = [] |
@@ -47,16 +45,14 b' class Purge(object):' | |||
|
47 | 45 | directories.sort() |
|
48 | 46 | |
|
49 | 47 | for f in files: |
|
50 |
self._remove_file( |
|
|
48 | self._remove_file(f) | |
|
51 | 49 | |
|
52 | 50 | for f in directories[::-1]: |
|
53 |
f |
|
|
54 | if not os.listdir(f): | |
|
51 | if not os.listdir(repo.wjoin(f)): | |
|
55 | 52 | self._remove_dir(f) |
|
56 | 53 | |
|
57 | 54 | self._repo = None |
|
58 | 55 | self._ui = None |
|
59 | self._hg_root = None | |
|
60 | 56 | |
|
61 | 57 | def _error(self, msg): |
|
62 | 58 | if self._abort_on_err: |
@@ -65,72 +61,28 b' class Purge(object):' | |||
|
65 | 61 | self._ui.warn(_('warning: %s\n') % msg) |
|
66 | 62 | |
|
67 | 63 | def _remove_file(self, name): |
|
68 | relative_name = self._relative_name(name) | |
|
69 | 64 | # dirstate.state() requires a path relative to the root |
|
70 | 65 | # directory. |
|
71 |
if self._repo.dirstate.state( |
|
|
66 | if self._repo.dirstate.state(name) != '?': | |
|
72 | 67 | return |
|
73 |
self._ui.note(_('Removing file %s\n') % |
|
|
74 | if self._act: | |
|
75 | try: | |
|
76 | os.remove(name) | |
|
77 | except OSError, e: | |
|
78 | self._error(_('%s cannot be removed') % relative_name) | |
|
79 | else: | |
|
80 | self._ui.write('%s%s' % (relative_name, self._eol)) | |
|
81 | ||
|
82 | def _remove_dir(self, name): | |
|
83 | relative_name = self._relative_name(name) | |
|
84 | self._ui.note(_('Removing directory %s\n') % relative_name) | |
|
68 | self._ui.note(_('Removing file %s\n') % name) | |
|
85 | 69 | if self._act: |
|
86 | 70 | try: |
|
87 |
os.r |
|
|
71 | os.remove(self._repo.wjoin(name)) | |
|
88 | 72 | except OSError, e: |
|
89 |
self._error(_('%s cannot be removed') % |
|
|
73 | self._error(_('%s cannot be removed') % name) | |
|
90 | 74 | else: |
|
91 |
self._ui.write('%s%s' % ( |
|
|
92 | ||
|
93 | def _relative_name(self, path): | |
|
94 | ''' | |
|
95 | Returns "path" but relative to the root directory of the | |
|
96 | repository and with '\\' replaced with '/'. | |
|
97 | This is needed because this is the format required by | |
|
98 | self._repo.dirstate.state(). | |
|
99 | ''' | |
|
100 | splitted_path = self._split_path(path)[len(self._hg_root):] | |
|
101 | # Even on Windows self._repo.dirstate.state() wants '/'. | |
|
102 | return self._join_path(splitted_path).replace('\\', '/') | |
|
75 | self._ui.write('%s%s' % (name, self._eol)) | |
|
103 | 76 | |
|
104 |
def _ |
|
|
105 | ''' | |
|
106 | Returns a list of the single files/directories in "path". | |
|
107 | For instance: | |
|
108 | '/home/user/test' -> ['/', 'home', 'user', 'test'] | |
|
109 | 'C:\\Mercurial' -> ['C:\\', 'Mercurial'] | |
|
110 | ''' | |
|
111 |
|
|
|
112 | while True: | |
|
113 | head, tail = os.path.split(path) | |
|
114 | if tail: | |
|
115 | ret.append(tail) | |
|
116 | if head == path: | |
|
117 | ret.append(head) | |
|
118 | break | |
|
119 | path = head | |
|
120 | ret.reverse() | |
|
121 | return ret | |
|
122 | ||
|
123 | def _join_path(self, splitted_path): | |
|
124 | ''' | |
|
125 | Joins a list returned by _split_path(). | |
|
126 | ''' | |
|
127 | ret = '' | |
|
128 | for part in splitted_path: | |
|
129 | if ret: | |
|
130 | ret = os.path.join(ret, part) | |
|
131 | else: | |
|
132 | ret = part | |
|
133 | return ret | |
|
77 | def _remove_dir(self, name): | |
|
78 | self._ui.note(_('Removing directory %s\n') % name) | |
|
79 | if self._act: | |
|
80 | try: | |
|
81 | os.rmdir(self._repo.wjoin(name)) | |
|
82 | except OSError, e: | |
|
83 | self._error(_('%s cannot be removed') % name) | |
|
84 | else: | |
|
85 | self._ui.write('%s%s' % (name, self._eol)) | |
|
134 | 86 | |
|
135 | 87 | |
|
136 | 88 | def purge(ui, repo, *dirs, **opts): |
General Comments 0
You need to be logged in to leave comments.
Login now