Show More
@@ -1,2004 +1,1980 b'' | |||||
1 | # queue.py - patch queues for mercurial |
|
1 | # queue.py - patch queues for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> |
|
3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | '''patch management and development |
|
8 | '''patch management and development | |
9 |
|
9 | |||
10 | This extension lets you work with a stack of patches in a Mercurial |
|
10 | This extension lets you work with a stack of patches in a Mercurial | |
11 | repository. It manages two stacks of patches - all known patches, and |
|
11 | repository. It manages two stacks of patches - all known patches, and | |
12 | applied patches (subset of known patches). |
|
12 | applied patches (subset of known patches). | |
13 |
|
13 | |||
14 | Known patches are represented as patch files in the .hg/patches |
|
14 | Known patches are represented as patch files in the .hg/patches | |
15 | directory. Applied patches are both patch files and changesets. |
|
15 | directory. Applied patches are both patch files and changesets. | |
16 |
|
16 | |||
17 | Common tasks (use "hg help command" for more details): |
|
17 | Common tasks (use "hg help command" for more details): | |
18 |
|
18 | |||
19 | prepare repository to work with patches qinit |
|
19 | prepare repository to work with patches qinit | |
20 | create new patch qnew |
|
20 | create new patch qnew | |
21 | import existing patch qimport |
|
21 | import existing patch qimport | |
22 |
|
22 | |||
23 | print patch series qseries |
|
23 | print patch series qseries | |
24 | print applied patches qapplied |
|
24 | print applied patches qapplied | |
25 | print name of top applied patch qtop |
|
25 | print name of top applied patch qtop | |
26 |
|
26 | |||
27 | add known patch to applied stack qpush |
|
27 | add known patch to applied stack qpush | |
28 | remove patch from applied stack qpop |
|
28 | remove patch from applied stack qpop | |
29 | refresh contents of top applied patch qrefresh |
|
29 | refresh contents of top applied patch qrefresh | |
30 | ''' |
|
30 | ''' | |
31 |
|
31 | |||
32 | from mercurial.demandload import * |
|
32 | from mercurial.demandload import * | |
33 | from mercurial.i18n import gettext as _ |
|
33 | from mercurial.i18n import gettext as _ | |
34 | demandload(globals(), "os sys re struct traceback errno bz2") |
|
34 | demandload(globals(), "os sys re struct traceback errno bz2") | |
35 | demandload(globals(), "mercurial:cmdutil,commands,hg,patch,revlog,ui,util") |
|
35 | demandload(globals(), "mercurial:cmdutil,commands,hg,patch,revlog,ui,util") | |
36 |
|
36 | |||
37 | commands.norepo += " qclone qversion" |
|
37 | commands.norepo += " qclone qversion" | |
38 |
|
38 | |||
39 | class statusentry: |
|
39 | class statusentry: | |
40 | def __init__(self, rev, name=None): |
|
40 | def __init__(self, rev, name=None): | |
41 | if not name: |
|
41 | if not name: | |
42 | fields = rev.split(':') |
|
42 | fields = rev.split(':') | |
43 | if len(fields) == 2: |
|
43 | if len(fields) == 2: | |
44 | self.rev, self.name = fields |
|
44 | self.rev, self.name = fields | |
45 | else: |
|
45 | else: | |
46 | self.rev, self.name = None, None |
|
46 | self.rev, self.name = None, None | |
47 | else: |
|
47 | else: | |
48 | self.rev, self.name = rev, name |
|
48 | self.rev, self.name = rev, name | |
49 |
|
49 | |||
50 | def __str__(self): |
|
50 | def __str__(self): | |
51 | return self.rev + ':' + self.name |
|
51 | return self.rev + ':' + self.name | |
52 |
|
52 | |||
53 | class queue: |
|
53 | class queue: | |
54 | def __init__(self, ui, path, patchdir=None): |
|
54 | def __init__(self, ui, path, patchdir=None): | |
55 | self.basepath = path |
|
55 | self.basepath = path | |
56 | self.path = patchdir or os.path.join(path, "patches") |
|
56 | self.path = patchdir or os.path.join(path, "patches") | |
57 | self.opener = util.opener(self.path) |
|
57 | self.opener = util.opener(self.path) | |
58 | self.ui = ui |
|
58 | self.ui = ui | |
59 | self.applied = [] |
|
59 | self.applied = [] | |
60 | self.full_series = [] |
|
60 | self.full_series = [] | |
61 | self.applied_dirty = 0 |
|
61 | self.applied_dirty = 0 | |
62 | self.series_dirty = 0 |
|
62 | self.series_dirty = 0 | |
63 | self.series_path = "series" |
|
63 | self.series_path = "series" | |
64 | self.status_path = "status" |
|
64 | self.status_path = "status" | |
65 | self.guards_path = "guards" |
|
65 | self.guards_path = "guards" | |
66 | self.active_guards = None |
|
66 | self.active_guards = None | |
67 | self.guards_dirty = False |
|
67 | self.guards_dirty = False | |
68 | self._diffopts = None |
|
68 | self._diffopts = None | |
69 |
|
69 | |||
70 | if os.path.exists(self.join(self.series_path)): |
|
70 | if os.path.exists(self.join(self.series_path)): | |
71 | self.full_series = self.opener(self.series_path).read().splitlines() |
|
71 | self.full_series = self.opener(self.series_path).read().splitlines() | |
72 | self.parse_series() |
|
72 | self.parse_series() | |
73 |
|
73 | |||
74 | if os.path.exists(self.join(self.status_path)): |
|
74 | if os.path.exists(self.join(self.status_path)): | |
75 | lines = self.opener(self.status_path).read().splitlines() |
|
75 | lines = self.opener(self.status_path).read().splitlines() | |
76 | self.applied = [statusentry(l) for l in lines] |
|
76 | self.applied = [statusentry(l) for l in lines] | |
77 |
|
77 | |||
78 | def diffopts(self): |
|
78 | def diffopts(self): | |
79 | if self._diffopts is None: |
|
79 | if self._diffopts is None: | |
80 | self._diffopts = self.ui.diffopts() |
|
80 | self._diffopts = self.ui.diffopts() | |
81 | return self._diffopts |
|
81 | return self._diffopts | |
82 |
|
82 | |||
83 | def join(self, *p): |
|
83 | def join(self, *p): | |
84 | return os.path.join(self.path, *p) |
|
84 | return os.path.join(self.path, *p) | |
85 |
|
85 | |||
86 | def find_series(self, patch): |
|
86 | def find_series(self, patch): | |
87 | pre = re.compile("(\s*)([^#]+)") |
|
87 | pre = re.compile("(\s*)([^#]+)") | |
88 | index = 0 |
|
88 | index = 0 | |
89 | for l in self.full_series: |
|
89 | for l in self.full_series: | |
90 | m = pre.match(l) |
|
90 | m = pre.match(l) | |
91 | if m: |
|
91 | if m: | |
92 | s = m.group(2) |
|
92 | s = m.group(2) | |
93 | s = s.rstrip() |
|
93 | s = s.rstrip() | |
94 | if s == patch: |
|
94 | if s == patch: | |
95 | return index |
|
95 | return index | |
96 | index += 1 |
|
96 | index += 1 | |
97 | return None |
|
97 | return None | |
98 |
|
98 | |||
99 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') |
|
99 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') | |
100 |
|
100 | |||
101 | def parse_series(self): |
|
101 | def parse_series(self): | |
102 | self.series = [] |
|
102 | self.series = [] | |
103 | self.series_guards = [] |
|
103 | self.series_guards = [] | |
104 | for l in self.full_series: |
|
104 | for l in self.full_series: | |
105 | h = l.find('#') |
|
105 | h = l.find('#') | |
106 | if h == -1: |
|
106 | if h == -1: | |
107 | patch = l |
|
107 | patch = l | |
108 | comment = '' |
|
108 | comment = '' | |
109 | elif h == 0: |
|
109 | elif h == 0: | |
110 | continue |
|
110 | continue | |
111 | else: |
|
111 | else: | |
112 | patch = l[:h] |
|
112 | patch = l[:h] | |
113 | comment = l[h:] |
|
113 | comment = l[h:] | |
114 | patch = patch.strip() |
|
114 | patch = patch.strip() | |
115 | if patch: |
|
115 | if patch: | |
116 | self.series.append(patch) |
|
116 | self.series.append(patch) | |
117 | self.series_guards.append(self.guard_re.findall(comment)) |
|
117 | self.series_guards.append(self.guard_re.findall(comment)) | |
118 |
|
118 | |||
119 | def check_guard(self, guard): |
|
119 | def check_guard(self, guard): | |
120 | bad_chars = '# \t\r\n\f' |
|
120 | bad_chars = '# \t\r\n\f' | |
121 | first = guard[0] |
|
121 | first = guard[0] | |
122 | for c in '-+': |
|
122 | for c in '-+': | |
123 | if first == c: |
|
123 | if first == c: | |
124 | return (_('guard %r starts with invalid character: %r') % |
|
124 | return (_('guard %r starts with invalid character: %r') % | |
125 | (guard, c)) |
|
125 | (guard, c)) | |
126 | for c in bad_chars: |
|
126 | for c in bad_chars: | |
127 | if c in guard: |
|
127 | if c in guard: | |
128 | return _('invalid character in guard %r: %r') % (guard, c) |
|
128 | return _('invalid character in guard %r: %r') % (guard, c) | |
129 |
|
129 | |||
130 | def set_active(self, guards): |
|
130 | def set_active(self, guards): | |
131 | for guard in guards: |
|
131 | for guard in guards: | |
132 | bad = self.check_guard(guard) |
|
132 | bad = self.check_guard(guard) | |
133 | if bad: |
|
133 | if bad: | |
134 | raise util.Abort(bad) |
|
134 | raise util.Abort(bad) | |
135 | guards = dict.fromkeys(guards).keys() |
|
135 | guards = dict.fromkeys(guards).keys() | |
136 | guards.sort() |
|
136 | guards.sort() | |
137 | self.ui.debug('active guards: %s\n' % ' '.join(guards)) |
|
137 | self.ui.debug('active guards: %s\n' % ' '.join(guards)) | |
138 | self.active_guards = guards |
|
138 | self.active_guards = guards | |
139 | self.guards_dirty = True |
|
139 | self.guards_dirty = True | |
140 |
|
140 | |||
141 | def active(self): |
|
141 | def active(self): | |
142 | if self.active_guards is None: |
|
142 | if self.active_guards is None: | |
143 | self.active_guards = [] |
|
143 | self.active_guards = [] | |
144 | try: |
|
144 | try: | |
145 | guards = self.opener(self.guards_path).read().split() |
|
145 | guards = self.opener(self.guards_path).read().split() | |
146 | except IOError, err: |
|
146 | except IOError, err: | |
147 | if err.errno != errno.ENOENT: raise |
|
147 | if err.errno != errno.ENOENT: raise | |
148 | guards = [] |
|
148 | guards = [] | |
149 | for i, guard in enumerate(guards): |
|
149 | for i, guard in enumerate(guards): | |
150 | bad = self.check_guard(guard) |
|
150 | bad = self.check_guard(guard) | |
151 | if bad: |
|
151 | if bad: | |
152 | self.ui.warn('%s:%d: %s\n' % |
|
152 | self.ui.warn('%s:%d: %s\n' % | |
153 | (self.join(self.guards_path), i + 1, bad)) |
|
153 | (self.join(self.guards_path), i + 1, bad)) | |
154 | else: |
|
154 | else: | |
155 | self.active_guards.append(guard) |
|
155 | self.active_guards.append(guard) | |
156 | return self.active_guards |
|
156 | return self.active_guards | |
157 |
|
157 | |||
158 | def set_guards(self, idx, guards): |
|
158 | def set_guards(self, idx, guards): | |
159 | for g in guards: |
|
159 | for g in guards: | |
160 | if len(g) < 2: |
|
160 | if len(g) < 2: | |
161 | raise util.Abort(_('guard %r too short') % g) |
|
161 | raise util.Abort(_('guard %r too short') % g) | |
162 | if g[0] not in '-+': |
|
162 | if g[0] not in '-+': | |
163 | raise util.Abort(_('guard %r starts with invalid char') % g) |
|
163 | raise util.Abort(_('guard %r starts with invalid char') % g) | |
164 | bad = self.check_guard(g[1:]) |
|
164 | bad = self.check_guard(g[1:]) | |
165 | if bad: |
|
165 | if bad: | |
166 | raise util.Abort(bad) |
|
166 | raise util.Abort(bad) | |
167 | drop = self.guard_re.sub('', self.full_series[idx]) |
|
167 | drop = self.guard_re.sub('', self.full_series[idx]) | |
168 | self.full_series[idx] = drop + ''.join([' #' + g for g in guards]) |
|
168 | self.full_series[idx] = drop + ''.join([' #' + g for g in guards]) | |
169 | self.parse_series() |
|
169 | self.parse_series() | |
170 | self.series_dirty = True |
|
170 | self.series_dirty = True | |
171 |
|
171 | |||
172 | def pushable(self, idx): |
|
172 | def pushable(self, idx): | |
173 | if isinstance(idx, str): |
|
173 | if isinstance(idx, str): | |
174 | idx = self.series.index(idx) |
|
174 | idx = self.series.index(idx) | |
175 | patchguards = self.series_guards[idx] |
|
175 | patchguards = self.series_guards[idx] | |
176 | if not patchguards: |
|
176 | if not patchguards: | |
177 | return True, None |
|
177 | return True, None | |
178 | default = False |
|
178 | default = False | |
179 | guards = self.active() |
|
179 | guards = self.active() | |
180 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] |
|
180 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] | |
181 | if exactneg: |
|
181 | if exactneg: | |
182 | return False, exactneg[0] |
|
182 | return False, exactneg[0] | |
183 | pos = [g for g in patchguards if g[0] == '+'] |
|
183 | pos = [g for g in patchguards if g[0] == '+'] | |
184 | exactpos = [g for g in pos if g[1:] in guards] |
|
184 | exactpos = [g for g in pos if g[1:] in guards] | |
185 | if pos: |
|
185 | if pos: | |
186 | if exactpos: |
|
186 | if exactpos: | |
187 | return True, exactpos[0] |
|
187 | return True, exactpos[0] | |
188 | return False, pos |
|
188 | return False, pos | |
189 | return True, '' |
|
189 | return True, '' | |
190 |
|
190 | |||
191 | def explain_pushable(self, idx, all_patches=False): |
|
191 | def explain_pushable(self, idx, all_patches=False): | |
192 | write = all_patches and self.ui.write or self.ui.warn |
|
192 | write = all_patches and self.ui.write or self.ui.warn | |
193 | if all_patches or self.ui.verbose: |
|
193 | if all_patches or self.ui.verbose: | |
194 | if isinstance(idx, str): |
|
194 | if isinstance(idx, str): | |
195 | idx = self.series.index(idx) |
|
195 | idx = self.series.index(idx) | |
196 | pushable, why = self.pushable(idx) |
|
196 | pushable, why = self.pushable(idx) | |
197 | if all_patches and pushable: |
|
197 | if all_patches and pushable: | |
198 | if why is None: |
|
198 | if why is None: | |
199 | write(_('allowing %s - no guards in effect\n') % |
|
199 | write(_('allowing %s - no guards in effect\n') % | |
200 | self.series[idx]) |
|
200 | self.series[idx]) | |
201 | else: |
|
201 | else: | |
202 | if not why: |
|
202 | if not why: | |
203 | write(_('allowing %s - no matching negative guards\n') % |
|
203 | write(_('allowing %s - no matching negative guards\n') % | |
204 | self.series[idx]) |
|
204 | self.series[idx]) | |
205 | else: |
|
205 | else: | |
206 | write(_('allowing %s - guarded by %r\n') % |
|
206 | write(_('allowing %s - guarded by %r\n') % | |
207 | (self.series[idx], why)) |
|
207 | (self.series[idx], why)) | |
208 | if not pushable: |
|
208 | if not pushable: | |
209 | if why: |
|
209 | if why: | |
210 | write(_('skipping %s - guarded by %r\n') % |
|
210 | write(_('skipping %s - guarded by %r\n') % | |
211 | (self.series[idx], ' '.join(why))) |
|
211 | (self.series[idx], ' '.join(why))) | |
212 | else: |
|
212 | else: | |
213 | write(_('skipping %s - no matching guards\n') % |
|
213 | write(_('skipping %s - no matching guards\n') % | |
214 | self.series[idx]) |
|
214 | self.series[idx]) | |
215 |
|
215 | |||
216 | def save_dirty(self): |
|
216 | def save_dirty(self): | |
217 | def write_list(items, path): |
|
217 | def write_list(items, path): | |
218 | fp = self.opener(path, 'w') |
|
218 | fp = self.opener(path, 'w') | |
219 | for i in items: |
|
219 | for i in items: | |
220 | print >> fp, i |
|
220 | print >> fp, i | |
221 | fp.close() |
|
221 | fp.close() | |
222 | if self.applied_dirty: write_list(map(str, self.applied), self.status_path) |
|
222 | if self.applied_dirty: write_list(map(str, self.applied), self.status_path) | |
223 | if self.series_dirty: write_list(self.full_series, self.series_path) |
|
223 | if self.series_dirty: write_list(self.full_series, self.series_path) | |
224 | if self.guards_dirty: write_list(self.active_guards, self.guards_path) |
|
224 | if self.guards_dirty: write_list(self.active_guards, self.guards_path) | |
225 |
|
225 | |||
226 | def readheaders(self, patch): |
|
226 | def readheaders(self, patch): | |
227 | def eatdiff(lines): |
|
227 | def eatdiff(lines): | |
228 | while lines: |
|
228 | while lines: | |
229 | l = lines[-1] |
|
229 | l = lines[-1] | |
230 | if (l.startswith("diff -") or |
|
230 | if (l.startswith("diff -") or | |
231 | l.startswith("Index:") or |
|
231 | l.startswith("Index:") or | |
232 | l.startswith("===========")): |
|
232 | l.startswith("===========")): | |
233 | del lines[-1] |
|
233 | del lines[-1] | |
234 | else: |
|
234 | else: | |
235 | break |
|
235 | break | |
236 | def eatempty(lines): |
|
236 | def eatempty(lines): | |
237 | while lines: |
|
237 | while lines: | |
238 | l = lines[-1] |
|
238 | l = lines[-1] | |
239 | if re.match('\s*$', l): |
|
239 | if re.match('\s*$', l): | |
240 | del lines[-1] |
|
240 | del lines[-1] | |
241 | else: |
|
241 | else: | |
242 | break |
|
242 | break | |
243 |
|
243 | |||
244 | pf = self.join(patch) |
|
244 | pf = self.join(patch) | |
245 | message = [] |
|
245 | message = [] | |
246 | comments = [] |
|
246 | comments = [] | |
247 | user = None |
|
247 | user = None | |
248 | date = None |
|
248 | date = None | |
249 | format = None |
|
249 | format = None | |
250 | subject = None |
|
250 | subject = None | |
251 | diffstart = 0 |
|
251 | diffstart = 0 | |
252 |
|
252 | |||
253 | for line in file(pf): |
|
253 | for line in file(pf): | |
254 | line = line.rstrip() |
|
254 | line = line.rstrip() | |
255 | if diffstart: |
|
255 | if diffstart: | |
256 | if line.startswith('+++ '): |
|
256 | if line.startswith('+++ '): | |
257 | diffstart = 2 |
|
257 | diffstart = 2 | |
258 | break |
|
258 | break | |
259 | if line.startswith("--- "): |
|
259 | if line.startswith("--- "): | |
260 | diffstart = 1 |
|
260 | diffstart = 1 | |
261 | continue |
|
261 | continue | |
262 | elif format == "hgpatch": |
|
262 | elif format == "hgpatch": | |
263 | # parse values when importing the result of an hg export |
|
263 | # parse values when importing the result of an hg export | |
264 | if line.startswith("# User "): |
|
264 | if line.startswith("# User "): | |
265 | user = line[7:] |
|
265 | user = line[7:] | |
266 | elif line.startswith("# Date "): |
|
266 | elif line.startswith("# Date "): | |
267 | date = line[7:] |
|
267 | date = line[7:] | |
268 | elif not line.startswith("# ") and line: |
|
268 | elif not line.startswith("# ") and line: | |
269 | message.append(line) |
|
269 | message.append(line) | |
270 | format = None |
|
270 | format = None | |
271 | elif line == '# HG changeset patch': |
|
271 | elif line == '# HG changeset patch': | |
272 | format = "hgpatch" |
|
272 | format = "hgpatch" | |
273 | elif (format != "tagdone" and (line.startswith("Subject: ") or |
|
273 | elif (format != "tagdone" and (line.startswith("Subject: ") or | |
274 | line.startswith("subject: "))): |
|
274 | line.startswith("subject: "))): | |
275 | subject = line[9:] |
|
275 | subject = line[9:] | |
276 | format = "tag" |
|
276 | format = "tag" | |
277 | elif (format != "tagdone" and (line.startswith("From: ") or |
|
277 | elif (format != "tagdone" and (line.startswith("From: ") or | |
278 | line.startswith("from: "))): |
|
278 | line.startswith("from: "))): | |
279 | user = line[6:] |
|
279 | user = line[6:] | |
280 | format = "tag" |
|
280 | format = "tag" | |
281 | elif format == "tag" and line == "": |
|
281 | elif format == "tag" and line == "": | |
282 | # when looking for tags (subject: from: etc) they |
|
282 | # when looking for tags (subject: from: etc) they | |
283 | # end once you find a blank line in the source |
|
283 | # end once you find a blank line in the source | |
284 | format = "tagdone" |
|
284 | format = "tagdone" | |
285 | elif message or line: |
|
285 | elif message or line: | |
286 | message.append(line) |
|
286 | message.append(line) | |
287 | comments.append(line) |
|
287 | comments.append(line) | |
288 |
|
288 | |||
289 | eatdiff(message) |
|
289 | eatdiff(message) | |
290 | eatdiff(comments) |
|
290 | eatdiff(comments) | |
291 | eatempty(message) |
|
291 | eatempty(message) | |
292 | eatempty(comments) |
|
292 | eatempty(comments) | |
293 |
|
293 | |||
294 | # make sure message isn't empty |
|
294 | # make sure message isn't empty | |
295 | if format and format.startswith("tag") and subject: |
|
295 | if format and format.startswith("tag") and subject: | |
296 | message.insert(0, "") |
|
296 | message.insert(0, "") | |
297 | message.insert(0, subject) |
|
297 | message.insert(0, subject) | |
298 | return (message, comments, user, date, diffstart > 1) |
|
298 | return (message, comments, user, date, diffstart > 1) | |
299 |
|
299 | |||
300 | def printdiff(self, repo, node1, node2=None, files=None, |
|
300 | def printdiff(self, repo, node1, node2=None, files=None, | |
301 | fp=None, changes=None, opts=None): |
|
301 | fp=None, changes=None, opts=None): | |
302 | patch.diff(repo, node1, node2, files, |
|
302 | patch.diff(repo, node1, node2, files, | |
303 | fp=fp, changes=changes, opts=self.diffopts()) |
|
303 | fp=fp, changes=changes, opts=self.diffopts()) | |
304 |
|
304 | |||
305 | def mergeone(self, repo, mergeq, head, patch, rev, wlock): |
|
305 | def mergeone(self, repo, mergeq, head, patch, rev, wlock): | |
306 | # first try just applying the patch |
|
306 | # first try just applying the patch | |
307 | (err, n) = self.apply(repo, [ patch ], update_status=False, |
|
307 | (err, n) = self.apply(repo, [ patch ], update_status=False, | |
308 | strict=True, merge=rev, wlock=wlock) |
|
308 | strict=True, merge=rev, wlock=wlock) | |
309 |
|
309 | |||
310 | if err == 0: |
|
310 | if err == 0: | |
311 | return (err, n) |
|
311 | return (err, n) | |
312 |
|
312 | |||
313 | if n is None: |
|
313 | if n is None: | |
314 | raise util.Abort(_("apply failed for patch %s") % patch) |
|
314 | raise util.Abort(_("apply failed for patch %s") % patch) | |
315 |
|
315 | |||
316 | self.ui.warn("patch didn't work out, merging %s\n" % patch) |
|
316 | self.ui.warn("patch didn't work out, merging %s\n" % patch) | |
317 |
|
317 | |||
318 | # apply failed, strip away that rev and merge. |
|
318 | # apply failed, strip away that rev and merge. | |
319 | hg.clean(repo, head, wlock=wlock) |
|
319 | hg.clean(repo, head, wlock=wlock) | |
320 | self.strip(repo, n, update=False, backup='strip', wlock=wlock) |
|
320 | self.strip(repo, n, update=False, backup='strip', wlock=wlock) | |
321 |
|
321 | |||
322 | c = repo.changelog.read(rev) |
|
322 | c = repo.changelog.read(rev) | |
323 | ret = hg.merge(repo, rev, wlock=wlock) |
|
323 | ret = hg.merge(repo, rev, wlock=wlock) | |
324 | if ret: |
|
324 | if ret: | |
325 | raise util.Abort(_("update returned %d") % ret) |
|
325 | raise util.Abort(_("update returned %d") % ret) | |
326 | n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) |
|
326 | n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) | |
327 | if n == None: |
|
327 | if n == None: | |
328 | raise util.Abort(_("repo commit failed")) |
|
328 | raise util.Abort(_("repo commit failed")) | |
329 | try: |
|
329 | try: | |
330 | message, comments, user, date, patchfound = mergeq.readheaders(patch) |
|
330 | message, comments, user, date, patchfound = mergeq.readheaders(patch) | |
331 | except: |
|
331 | except: | |
332 | raise util.Abort(_("unable to read %s") % patch) |
|
332 | raise util.Abort(_("unable to read %s") % patch) | |
333 |
|
333 | |||
334 | patchf = self.opener(patch, "w") |
|
334 | patchf = self.opener(patch, "w") | |
335 | if comments: |
|
335 | if comments: | |
336 | comments = "\n".join(comments) + '\n\n' |
|
336 | comments = "\n".join(comments) + '\n\n' | |
337 | patchf.write(comments) |
|
337 | patchf.write(comments) | |
338 | self.printdiff(repo, head, n, fp=patchf) |
|
338 | self.printdiff(repo, head, n, fp=patchf) | |
339 | patchf.close() |
|
339 | patchf.close() | |
340 | return (0, n) |
|
340 | return (0, n) | |
341 |
|
341 | |||
342 | def qparents(self, repo, rev=None): |
|
342 | def qparents(self, repo, rev=None): | |
343 | if rev is None: |
|
343 | if rev is None: | |
344 | (p1, p2) = repo.dirstate.parents() |
|
344 | (p1, p2) = repo.dirstate.parents() | |
345 | if p2 == revlog.nullid: |
|
345 | if p2 == revlog.nullid: | |
346 | return p1 |
|
346 | return p1 | |
347 | if len(self.applied) == 0: |
|
347 | if len(self.applied) == 0: | |
348 | return None |
|
348 | return None | |
349 | return revlog.bin(self.applied[-1].rev) |
|
349 | return revlog.bin(self.applied[-1].rev) | |
350 | pp = repo.changelog.parents(rev) |
|
350 | pp = repo.changelog.parents(rev) | |
351 | if pp[1] != revlog.nullid: |
|
351 | if pp[1] != revlog.nullid: | |
352 | arevs = [ x.rev for x in self.applied ] |
|
352 | arevs = [ x.rev for x in self.applied ] | |
353 | p0 = revlog.hex(pp[0]) |
|
353 | p0 = revlog.hex(pp[0]) | |
354 | p1 = revlog.hex(pp[1]) |
|
354 | p1 = revlog.hex(pp[1]) | |
355 | if p0 in arevs: |
|
355 | if p0 in arevs: | |
356 | return pp[0] |
|
356 | return pp[0] | |
357 | if p1 in arevs: |
|
357 | if p1 in arevs: | |
358 | return pp[1] |
|
358 | return pp[1] | |
359 | return pp[0] |
|
359 | return pp[0] | |
360 |
|
360 | |||
361 | def mergepatch(self, repo, mergeq, series, wlock): |
|
361 | def mergepatch(self, repo, mergeq, series, wlock): | |
362 | if len(self.applied) == 0: |
|
362 | if len(self.applied) == 0: | |
363 | # each of the patches merged in will have two parents. This |
|
363 | # each of the patches merged in will have two parents. This | |
364 | # can confuse the qrefresh, qdiff, and strip code because it |
|
364 | # can confuse the qrefresh, qdiff, and strip code because it | |
365 | # needs to know which parent is actually in the patch queue. |
|
365 | # needs to know which parent is actually in the patch queue. | |
366 | # so, we insert a merge marker with only one parent. This way |
|
366 | # so, we insert a merge marker with only one parent. This way | |
367 | # the first patch in the queue is never a merge patch |
|
367 | # the first patch in the queue is never a merge patch | |
368 | # |
|
368 | # | |
369 | pname = ".hg.patches.merge.marker" |
|
369 | pname = ".hg.patches.merge.marker" | |
370 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1, |
|
370 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1, | |
371 | wlock=wlock) |
|
371 | wlock=wlock) | |
372 | self.applied.append(statusentry(revlog.hex(n), pname)) |
|
372 | self.applied.append(statusentry(revlog.hex(n), pname)) | |
373 | self.applied_dirty = 1 |
|
373 | self.applied_dirty = 1 | |
374 |
|
374 | |||
375 | head = self.qparents(repo) |
|
375 | head = self.qparents(repo) | |
376 |
|
376 | |||
377 | for patch in series: |
|
377 | for patch in series: | |
378 | patch = mergeq.lookup(patch, strict=True) |
|
378 | patch = mergeq.lookup(patch, strict=True) | |
379 | if not patch: |
|
379 | if not patch: | |
380 | self.ui.warn("patch %s does not exist\n" % patch) |
|
380 | self.ui.warn("patch %s does not exist\n" % patch) | |
381 | return (1, None) |
|
381 | return (1, None) | |
382 | pushable, reason = self.pushable(patch) |
|
382 | pushable, reason = self.pushable(patch) | |
383 | if not pushable: |
|
383 | if not pushable: | |
384 | self.explain_pushable(patch, all_patches=True) |
|
384 | self.explain_pushable(patch, all_patches=True) | |
385 | continue |
|
385 | continue | |
386 | info = mergeq.isapplied(patch) |
|
386 | info = mergeq.isapplied(patch) | |
387 | if not info: |
|
387 | if not info: | |
388 | self.ui.warn("patch %s is not applied\n" % patch) |
|
388 | self.ui.warn("patch %s is not applied\n" % patch) | |
389 | return (1, None) |
|
389 | return (1, None) | |
390 | rev = revlog.bin(info[1]) |
|
390 | rev = revlog.bin(info[1]) | |
391 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) |
|
391 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) | |
392 | if head: |
|
392 | if head: | |
393 | self.applied.append(statusentry(revlog.hex(head), patch)) |
|
393 | self.applied.append(statusentry(revlog.hex(head), patch)) | |
394 | self.applied_dirty = 1 |
|
394 | self.applied_dirty = 1 | |
395 | if err: |
|
395 | if err: | |
396 | return (err, head) |
|
396 | return (err, head) | |
397 | return (0, head) |
|
397 | return (0, head) | |
398 |
|
398 | |||
399 | def patch(self, repo, patchfile): |
|
399 | def patch(self, repo, patchfile): | |
400 | '''Apply patchfile to the working directory. |
|
400 | '''Apply patchfile to the working directory. | |
401 | patchfile: file name of patch''' |
|
401 | patchfile: file name of patch''' | |
402 | try: |
|
402 | try: | |
403 | pp = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') |
|
403 | (files, fuzz) = patch.patch(patchfile, self.ui, strip=1, | |
404 | f = os.popen("%s -d %s -p1 --no-backup-if-mismatch < %s" % |
|
404 | cwd=repo.root) | |
405 | (pp, util.shellquote(repo.root), util.shellquote(patchfile))) |
|
405 | except Exception, inst: | |
406 | except: |
|
406 | self.ui.note(str(inst) + '\n') | |
407 | self.ui.warn("patch failed, unable to continue (try -v)\n") |
|
407 | if not self.ui.verbose: | |
408 | return (None, [], False) |
|
408 | self.ui.warn("patch failed, unable to continue (try -v)\n") | |
409 | files = [] |
|
409 | return (False, [], False) | |
410 | fuzz = False |
|
|||
411 | for l in f: |
|
|||
412 | l = l.rstrip('\r\n'); |
|
|||
413 | if self.ui.verbose: |
|
|||
414 | self.ui.warn(l + "\n") |
|
|||
415 | if l[:14] == 'patching file ': |
|
|||
416 | pf = os.path.normpath(util.parse_patch_output(l)) |
|
|||
417 | if pf not in files: |
|
|||
418 | files.append(pf) |
|
|||
419 | printed_file = False |
|
|||
420 | file_str = l |
|
|||
421 | elif l.find('with fuzz') >= 0: |
|
|||
422 | if not printed_file: |
|
|||
423 | self.ui.warn(file_str + '\n') |
|
|||
424 | printed_file = True |
|
|||
425 | self.ui.warn(l + '\n') |
|
|||
426 | fuzz = True |
|
|||
427 | elif l.find('saving rejects to file') >= 0: |
|
|||
428 | self.ui.warn(l + '\n') |
|
|||
429 | elif l.find('FAILED') >= 0: |
|
|||
430 | if not printed_file: |
|
|||
431 | self.ui.warn(file_str + '\n') |
|
|||
432 | printed_file = True |
|
|||
433 | self.ui.warn(l + '\n') |
|
|||
434 |
|
410 | |||
435 |
return ( |
|
411 | return (True, files.keys(), fuzz) | |
436 |
|
412 | |||
437 | def apply(self, repo, series, list=False, update_status=True, |
|
413 | def apply(self, repo, series, list=False, update_status=True, | |
438 | strict=False, patchdir=None, merge=None, wlock=None): |
|
414 | strict=False, patchdir=None, merge=None, wlock=None): | |
439 | # TODO unify with commands.py |
|
415 | # TODO unify with commands.py | |
440 | if not patchdir: |
|
416 | if not patchdir: | |
441 | patchdir = self.path |
|
417 | patchdir = self.path | |
442 | err = 0 |
|
418 | err = 0 | |
443 | if not wlock: |
|
419 | if not wlock: | |
444 | wlock = repo.wlock() |
|
420 | wlock = repo.wlock() | |
445 | lock = repo.lock() |
|
421 | lock = repo.lock() | |
446 | tr = repo.transaction() |
|
422 | tr = repo.transaction() | |
447 | n = None |
|
423 | n = None | |
448 | for patch in series: |
|
424 | for patch in series: | |
449 | pushable, reason = self.pushable(patch) |
|
425 | pushable, reason = self.pushable(patch) | |
450 | if not pushable: |
|
426 | if not pushable: | |
451 | self.explain_pushable(patch, all_patches=True) |
|
427 | self.explain_pushable(patch, all_patches=True) | |
452 | continue |
|
428 | continue | |
453 | self.ui.warn("applying %s\n" % patch) |
|
429 | self.ui.warn("applying %s\n" % patch) | |
454 | pf = os.path.join(patchdir, patch) |
|
430 | pf = os.path.join(patchdir, patch) | |
455 |
|
431 | |||
456 | try: |
|
432 | try: | |
457 | message, comments, user, date, patchfound = self.readheaders(patch) |
|
433 | message, comments, user, date, patchfound = self.readheaders(patch) | |
458 | except: |
|
434 | except: | |
459 | self.ui.warn("Unable to read %s\n" % pf) |
|
435 | self.ui.warn("Unable to read %s\n" % pf) | |
460 | err = 1 |
|
436 | err = 1 | |
461 | break |
|
437 | break | |
462 |
|
438 | |||
463 | if not message: |
|
439 | if not message: | |
464 | message = "imported patch %s\n" % patch |
|
440 | message = "imported patch %s\n" % patch | |
465 | else: |
|
441 | else: | |
466 | if list: |
|
442 | if list: | |
467 | message.append("\nimported patch %s" % patch) |
|
443 | message.append("\nimported patch %s" % patch) | |
468 | message = '\n'.join(message) |
|
444 | message = '\n'.join(message) | |
469 |
|
445 | |||
470 | (patcherr, files, fuzz) = self.patch(repo, pf) |
|
446 | (patcherr, files, fuzz) = self.patch(repo, pf) | |
471 | patcherr = not patcherr |
|
447 | patcherr = not patcherr | |
472 |
|
448 | |||
473 | if merge and len(files) > 0: |
|
449 | if merge and len(files) > 0: | |
474 | # Mark as merged and update dirstate parent info |
|
450 | # Mark as merged and update dirstate parent info | |
475 | repo.dirstate.update(repo.dirstate.filterfiles(files), 'm') |
|
451 | repo.dirstate.update(repo.dirstate.filterfiles(files), 'm') | |
476 | p1, p2 = repo.dirstate.parents() |
|
452 | p1, p2 = repo.dirstate.parents() | |
477 | repo.dirstate.setparents(p1, merge) |
|
453 | repo.dirstate.setparents(p1, merge) | |
478 | if len(files) > 0: |
|
454 | if len(files) > 0: | |
479 | cwd = repo.getcwd() |
|
455 | cwd = repo.getcwd() | |
480 | cfiles = files |
|
456 | cfiles = files | |
481 | if cwd: |
|
457 | if cwd: | |
482 | cfiles = [util.pathto(cwd, f) for f in files] |
|
458 | cfiles = [util.pathto(cwd, f) for f in files] | |
483 | cmdutil.addremove(repo, cfiles, wlock=wlock) |
|
459 | cmdutil.addremove(repo, cfiles, wlock=wlock) | |
484 | n = repo.commit(files, message, user, date, force=1, lock=lock, |
|
460 | n = repo.commit(files, message, user, date, force=1, lock=lock, | |
485 | wlock=wlock) |
|
461 | wlock=wlock) | |
486 |
|
462 | |||
487 | if n == None: |
|
463 | if n == None: | |
488 | raise util.Abort(_("repo commit failed")) |
|
464 | raise util.Abort(_("repo commit failed")) | |
489 |
|
465 | |||
490 | if update_status: |
|
466 | if update_status: | |
491 | self.applied.append(statusentry(revlog.hex(n), patch)) |
|
467 | self.applied.append(statusentry(revlog.hex(n), patch)) | |
492 |
|
468 | |||
493 | if patcherr: |
|
469 | if patcherr: | |
494 | if not patchfound: |
|
470 | if not patchfound: | |
495 | self.ui.warn("patch %s is empty\n" % patch) |
|
471 | self.ui.warn("patch %s is empty\n" % patch) | |
496 | err = 0 |
|
472 | err = 0 | |
497 | else: |
|
473 | else: | |
498 | self.ui.warn("patch failed, rejects left in working dir\n") |
|
474 | self.ui.warn("patch failed, rejects left in working dir\n") | |
499 | err = 1 |
|
475 | err = 1 | |
500 | break |
|
476 | break | |
501 |
|
477 | |||
502 | if fuzz and strict: |
|
478 | if fuzz and strict: | |
503 | self.ui.warn("fuzz found when applying patch, stopping\n") |
|
479 | self.ui.warn("fuzz found when applying patch, stopping\n") | |
504 | err = 1 |
|
480 | err = 1 | |
505 | break |
|
481 | break | |
506 | tr.close() |
|
482 | tr.close() | |
507 | return (err, n) |
|
483 | return (err, n) | |
508 |
|
484 | |||
509 | def delete(self, repo, patches, keep=False): |
|
485 | def delete(self, repo, patches, keep=False): | |
510 | realpatches = [] |
|
486 | realpatches = [] | |
511 | for patch in patches: |
|
487 | for patch in patches: | |
512 | patch = self.lookup(patch, strict=True) |
|
488 | patch = self.lookup(patch, strict=True) | |
513 | info = self.isapplied(patch) |
|
489 | info = self.isapplied(patch) | |
514 | if info: |
|
490 | if info: | |
515 | raise util.Abort(_("cannot delete applied patch %s") % patch) |
|
491 | raise util.Abort(_("cannot delete applied patch %s") % patch) | |
516 | if patch not in self.series: |
|
492 | if patch not in self.series: | |
517 | raise util.Abort(_("patch %s not in series file") % patch) |
|
493 | raise util.Abort(_("patch %s not in series file") % patch) | |
518 | realpatches.append(patch) |
|
494 | realpatches.append(patch) | |
519 |
|
495 | |||
520 | if not keep: |
|
496 | if not keep: | |
521 | r = self.qrepo() |
|
497 | r = self.qrepo() | |
522 | if r: |
|
498 | if r: | |
523 | r.remove(realpatches, True) |
|
499 | r.remove(realpatches, True) | |
524 | else: |
|
500 | else: | |
525 | os.unlink(self.join(patch)) |
|
501 | os.unlink(self.join(patch)) | |
526 |
|
502 | |||
527 | indices = [self.find_series(p) for p in realpatches] |
|
503 | indices = [self.find_series(p) for p in realpatches] | |
528 | indices.sort() |
|
504 | indices.sort() | |
529 | for i in indices[-1::-1]: |
|
505 | for i in indices[-1::-1]: | |
530 | del self.full_series[i] |
|
506 | del self.full_series[i] | |
531 | self.parse_series() |
|
507 | self.parse_series() | |
532 | self.series_dirty = 1 |
|
508 | self.series_dirty = 1 | |
533 |
|
509 | |||
534 | def check_toppatch(self, repo): |
|
510 | def check_toppatch(self, repo): | |
535 | if len(self.applied) > 0: |
|
511 | if len(self.applied) > 0: | |
536 | top = revlog.bin(self.applied[-1].rev) |
|
512 | top = revlog.bin(self.applied[-1].rev) | |
537 | pp = repo.dirstate.parents() |
|
513 | pp = repo.dirstate.parents() | |
538 | if top not in pp: |
|
514 | if top not in pp: | |
539 | raise util.Abort(_("queue top not at same revision as working directory")) |
|
515 | raise util.Abort(_("queue top not at same revision as working directory")) | |
540 | return top |
|
516 | return top | |
541 | return None |
|
517 | return None | |
542 | def check_localchanges(self, repo, force=False, refresh=True): |
|
518 | def check_localchanges(self, repo, force=False, refresh=True): | |
543 | m, a, r, d = repo.status()[:4] |
|
519 | m, a, r, d = repo.status()[:4] | |
544 | if m or a or r or d: |
|
520 | if m or a or r or d: | |
545 | if not force: |
|
521 | if not force: | |
546 | if refresh: |
|
522 | if refresh: | |
547 | raise util.Abort(_("local changes found, refresh first")) |
|
523 | raise util.Abort(_("local changes found, refresh first")) | |
548 | else: |
|
524 | else: | |
549 | raise util.Abort(_("local changes found")) |
|
525 | raise util.Abort(_("local changes found")) | |
550 | return m, a, r, d |
|
526 | return m, a, r, d | |
551 | def new(self, repo, patch, msg=None, force=None): |
|
527 | def new(self, repo, patch, msg=None, force=None): | |
552 | if os.path.exists(self.join(patch)): |
|
528 | if os.path.exists(self.join(patch)): | |
553 | raise util.Abort(_('patch "%s" already exists') % patch) |
|
529 | raise util.Abort(_('patch "%s" already exists') % patch) | |
554 | m, a, r, d = self.check_localchanges(repo, force) |
|
530 | m, a, r, d = self.check_localchanges(repo, force) | |
555 | commitfiles = m + a + r |
|
531 | commitfiles = m + a + r | |
556 | self.check_toppatch(repo) |
|
532 | self.check_toppatch(repo) | |
557 | wlock = repo.wlock() |
|
533 | wlock = repo.wlock() | |
558 | insert = self.full_series_end() |
|
534 | insert = self.full_series_end() | |
559 | if msg: |
|
535 | if msg: | |
560 | n = repo.commit(commitfiles, "[mq]: %s" % msg, force=True, |
|
536 | n = repo.commit(commitfiles, "[mq]: %s" % msg, force=True, | |
561 | wlock=wlock) |
|
537 | wlock=wlock) | |
562 | else: |
|
538 | else: | |
563 | n = repo.commit(commitfiles, |
|
539 | n = repo.commit(commitfiles, | |
564 | "New patch: %s" % patch, force=True, wlock=wlock) |
|
540 | "New patch: %s" % patch, force=True, wlock=wlock) | |
565 | if n == None: |
|
541 | if n == None: | |
566 | raise util.Abort(_("repo commit failed")) |
|
542 | raise util.Abort(_("repo commit failed")) | |
567 | self.full_series[insert:insert] = [patch] |
|
543 | self.full_series[insert:insert] = [patch] | |
568 | self.applied.append(statusentry(revlog.hex(n), patch)) |
|
544 | self.applied.append(statusentry(revlog.hex(n), patch)) | |
569 | self.parse_series() |
|
545 | self.parse_series() | |
570 | self.series_dirty = 1 |
|
546 | self.series_dirty = 1 | |
571 | self.applied_dirty = 1 |
|
547 | self.applied_dirty = 1 | |
572 | p = self.opener(patch, "w") |
|
548 | p = self.opener(patch, "w") | |
573 | if msg: |
|
549 | if msg: | |
574 | msg = msg + "\n" |
|
550 | msg = msg + "\n" | |
575 | p.write(msg) |
|
551 | p.write(msg) | |
576 | p.close() |
|
552 | p.close() | |
577 | wlock = None |
|
553 | wlock = None | |
578 | r = self.qrepo() |
|
554 | r = self.qrepo() | |
579 | if r: r.add([patch]) |
|
555 | if r: r.add([patch]) | |
580 | if commitfiles: |
|
556 | if commitfiles: | |
581 | self.refresh(repo, short=True) |
|
557 | self.refresh(repo, short=True) | |
582 |
|
558 | |||
583 | def strip(self, repo, rev, update=True, backup="all", wlock=None): |
|
559 | def strip(self, repo, rev, update=True, backup="all", wlock=None): | |
584 | def limitheads(chlog, stop): |
|
560 | def limitheads(chlog, stop): | |
585 | """return the list of all nodes that have no children""" |
|
561 | """return the list of all nodes that have no children""" | |
586 | p = {} |
|
562 | p = {} | |
587 | h = [] |
|
563 | h = [] | |
588 | stoprev = 0 |
|
564 | stoprev = 0 | |
589 | if stop in chlog.nodemap: |
|
565 | if stop in chlog.nodemap: | |
590 | stoprev = chlog.rev(stop) |
|
566 | stoprev = chlog.rev(stop) | |
591 |
|
567 | |||
592 | for r in range(chlog.count() - 1, -1, -1): |
|
568 | for r in range(chlog.count() - 1, -1, -1): | |
593 | n = chlog.node(r) |
|
569 | n = chlog.node(r) | |
594 | if n not in p: |
|
570 | if n not in p: | |
595 | h.append(n) |
|
571 | h.append(n) | |
596 | if n == stop: |
|
572 | if n == stop: | |
597 | break |
|
573 | break | |
598 | if r < stoprev: |
|
574 | if r < stoprev: | |
599 | break |
|
575 | break | |
600 | for pn in chlog.parents(n): |
|
576 | for pn in chlog.parents(n): | |
601 | p[pn] = 1 |
|
577 | p[pn] = 1 | |
602 | return h |
|
578 | return h | |
603 |
|
579 | |||
604 | def bundle(cg): |
|
580 | def bundle(cg): | |
605 | backupdir = repo.join("strip-backup") |
|
581 | backupdir = repo.join("strip-backup") | |
606 | if not os.path.isdir(backupdir): |
|
582 | if not os.path.isdir(backupdir): | |
607 | os.mkdir(backupdir) |
|
583 | os.mkdir(backupdir) | |
608 | name = os.path.join(backupdir, "%s" % revlog.short(rev)) |
|
584 | name = os.path.join(backupdir, "%s" % revlog.short(rev)) | |
609 | name = savename(name) |
|
585 | name = savename(name) | |
610 | self.ui.warn("saving bundle to %s\n" % name) |
|
586 | self.ui.warn("saving bundle to %s\n" % name) | |
611 | # TODO, exclusive open |
|
587 | # TODO, exclusive open | |
612 | f = open(name, "wb") |
|
588 | f = open(name, "wb") | |
613 | try: |
|
589 | try: | |
614 | f.write("HG10") |
|
590 | f.write("HG10") | |
615 | z = bz2.BZ2Compressor(9) |
|
591 | z = bz2.BZ2Compressor(9) | |
616 | while 1: |
|
592 | while 1: | |
617 | chunk = cg.read(4096) |
|
593 | chunk = cg.read(4096) | |
618 | if not chunk: |
|
594 | if not chunk: | |
619 | break |
|
595 | break | |
620 | f.write(z.compress(chunk)) |
|
596 | f.write(z.compress(chunk)) | |
621 | f.write(z.flush()) |
|
597 | f.write(z.flush()) | |
622 | except: |
|
598 | except: | |
623 | os.unlink(name) |
|
599 | os.unlink(name) | |
624 | raise |
|
600 | raise | |
625 | f.close() |
|
601 | f.close() | |
626 | return name |
|
602 | return name | |
627 |
|
603 | |||
628 | def stripall(rev, revnum): |
|
604 | def stripall(rev, revnum): | |
629 | cl = repo.changelog |
|
605 | cl = repo.changelog | |
630 | c = cl.read(rev) |
|
606 | c = cl.read(rev) | |
631 | mm = repo.manifest.read(c[0]) |
|
607 | mm = repo.manifest.read(c[0]) | |
632 | seen = {} |
|
608 | seen = {} | |
633 |
|
609 | |||
634 | for x in xrange(revnum, cl.count()): |
|
610 | for x in xrange(revnum, cl.count()): | |
635 | c = cl.read(cl.node(x)) |
|
611 | c = cl.read(cl.node(x)) | |
636 | for f in c[3]: |
|
612 | for f in c[3]: | |
637 | if f in seen: |
|
613 | if f in seen: | |
638 | continue |
|
614 | continue | |
639 | seen[f] = 1 |
|
615 | seen[f] = 1 | |
640 | if f in mm: |
|
616 | if f in mm: | |
641 | filerev = mm[f] |
|
617 | filerev = mm[f] | |
642 | else: |
|
618 | else: | |
643 | filerev = 0 |
|
619 | filerev = 0 | |
644 | seen[f] = filerev |
|
620 | seen[f] = filerev | |
645 | # we go in two steps here so the strip loop happens in a |
|
621 | # we go in two steps here so the strip loop happens in a | |
646 | # sensible order. When stripping many files, this helps keep |
|
622 | # sensible order. When stripping many files, this helps keep | |
647 | # our disk access patterns under control. |
|
623 | # our disk access patterns under control. | |
648 | seen_list = seen.keys() |
|
624 | seen_list = seen.keys() | |
649 | seen_list.sort() |
|
625 | seen_list.sort() | |
650 | for f in seen_list: |
|
626 | for f in seen_list: | |
651 | ff = repo.file(f) |
|
627 | ff = repo.file(f) | |
652 | filerev = seen[f] |
|
628 | filerev = seen[f] | |
653 | if filerev != 0: |
|
629 | if filerev != 0: | |
654 | if filerev in ff.nodemap: |
|
630 | if filerev in ff.nodemap: | |
655 | filerev = ff.rev(filerev) |
|
631 | filerev = ff.rev(filerev) | |
656 | else: |
|
632 | else: | |
657 | filerev = 0 |
|
633 | filerev = 0 | |
658 | ff.strip(filerev, revnum) |
|
634 | ff.strip(filerev, revnum) | |
659 |
|
635 | |||
660 | if not wlock: |
|
636 | if not wlock: | |
661 | wlock = repo.wlock() |
|
637 | wlock = repo.wlock() | |
662 | lock = repo.lock() |
|
638 | lock = repo.lock() | |
663 | chlog = repo.changelog |
|
639 | chlog = repo.changelog | |
664 | # TODO delete the undo files, and handle undo of merge sets |
|
640 | # TODO delete the undo files, and handle undo of merge sets | |
665 | pp = chlog.parents(rev) |
|
641 | pp = chlog.parents(rev) | |
666 | revnum = chlog.rev(rev) |
|
642 | revnum = chlog.rev(rev) | |
667 |
|
643 | |||
668 | if update: |
|
644 | if update: | |
669 | self.check_localchanges(repo, refresh=False) |
|
645 | self.check_localchanges(repo, refresh=False) | |
670 | urev = self.qparents(repo, rev) |
|
646 | urev = self.qparents(repo, rev) | |
671 | hg.clean(repo, urev, wlock=wlock) |
|
647 | hg.clean(repo, urev, wlock=wlock) | |
672 | repo.dirstate.write() |
|
648 | repo.dirstate.write() | |
673 |
|
649 | |||
674 | # save is a list of all the branches we are truncating away |
|
650 | # save is a list of all the branches we are truncating away | |
675 | # that we actually want to keep. changegroup will be used |
|
651 | # that we actually want to keep. changegroup will be used | |
676 | # to preserve them and add them back after the truncate |
|
652 | # to preserve them and add them back after the truncate | |
677 | saveheads = [] |
|
653 | saveheads = [] | |
678 | savebases = {} |
|
654 | savebases = {} | |
679 |
|
655 | |||
680 | heads = limitheads(chlog, rev) |
|
656 | heads = limitheads(chlog, rev) | |
681 | seen = {} |
|
657 | seen = {} | |
682 |
|
658 | |||
683 | # search through all the heads, finding those where the revision |
|
659 | # search through all the heads, finding those where the revision | |
684 | # we want to strip away is an ancestor. Also look for merges |
|
660 | # we want to strip away is an ancestor. Also look for merges | |
685 | # that might be turned into new heads by the strip. |
|
661 | # that might be turned into new heads by the strip. | |
686 | while heads: |
|
662 | while heads: | |
687 | h = heads.pop() |
|
663 | h = heads.pop() | |
688 | n = h |
|
664 | n = h | |
689 | while True: |
|
665 | while True: | |
690 | seen[n] = 1 |
|
666 | seen[n] = 1 | |
691 | pp = chlog.parents(n) |
|
667 | pp = chlog.parents(n) | |
692 | if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: |
|
668 | if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: | |
693 | if pp[1] not in seen: |
|
669 | if pp[1] not in seen: | |
694 | heads.append(pp[1]) |
|
670 | heads.append(pp[1]) | |
695 | if pp[0] == revlog.nullid: |
|
671 | if pp[0] == revlog.nullid: | |
696 | break |
|
672 | break | |
697 | if chlog.rev(pp[0]) < revnum: |
|
673 | if chlog.rev(pp[0]) < revnum: | |
698 | break |
|
674 | break | |
699 | n = pp[0] |
|
675 | n = pp[0] | |
700 | if n == rev: |
|
676 | if n == rev: | |
701 | break |
|
677 | break | |
702 | r = chlog.reachable(h, rev) |
|
678 | r = chlog.reachable(h, rev) | |
703 | if rev not in r: |
|
679 | if rev not in r: | |
704 | saveheads.append(h) |
|
680 | saveheads.append(h) | |
705 | for x in r: |
|
681 | for x in r: | |
706 | if chlog.rev(x) > revnum: |
|
682 | if chlog.rev(x) > revnum: | |
707 | savebases[x] = 1 |
|
683 | savebases[x] = 1 | |
708 |
|
684 | |||
709 | # create a changegroup for all the branches we need to keep |
|
685 | # create a changegroup for all the branches we need to keep | |
710 | if backup == "all": |
|
686 | if backup == "all": | |
711 | backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') |
|
687 | backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') | |
712 | bundle(backupch) |
|
688 | bundle(backupch) | |
713 | if saveheads: |
|
689 | if saveheads: | |
714 | backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') |
|
690 | backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') | |
715 | chgrpfile = bundle(backupch) |
|
691 | chgrpfile = bundle(backupch) | |
716 |
|
692 | |||
717 | stripall(rev, revnum) |
|
693 | stripall(rev, revnum) | |
718 |
|
694 | |||
719 | change = chlog.read(rev) |
|
695 | change = chlog.read(rev) | |
720 | repo.manifest.strip(repo.manifest.rev(change[0]), revnum) |
|
696 | repo.manifest.strip(repo.manifest.rev(change[0]), revnum) | |
721 | chlog.strip(revnum, revnum) |
|
697 | chlog.strip(revnum, revnum) | |
722 | if saveheads: |
|
698 | if saveheads: | |
723 | self.ui.status("adding branch\n") |
|
699 | self.ui.status("adding branch\n") | |
724 | commands.unbundle(self.ui, repo, chgrpfile, update=False) |
|
700 | commands.unbundle(self.ui, repo, chgrpfile, update=False) | |
725 | if backup != "strip": |
|
701 | if backup != "strip": | |
726 | os.unlink(chgrpfile) |
|
702 | os.unlink(chgrpfile) | |
727 |
|
703 | |||
728 | def isapplied(self, patch): |
|
704 | def isapplied(self, patch): | |
729 | """returns (index, rev, patch)""" |
|
705 | """returns (index, rev, patch)""" | |
730 | for i in xrange(len(self.applied)): |
|
706 | for i in xrange(len(self.applied)): | |
731 | a = self.applied[i] |
|
707 | a = self.applied[i] | |
732 | if a.name == patch: |
|
708 | if a.name == patch: | |
733 | return (i, a.rev, a.name) |
|
709 | return (i, a.rev, a.name) | |
734 | return None |
|
710 | return None | |
735 |
|
711 | |||
736 | # if the exact patch name does not exist, we try a few |
|
712 | # if the exact patch name does not exist, we try a few | |
737 | # variations. If strict is passed, we try only #1 |
|
713 | # variations. If strict is passed, we try only #1 | |
738 | # |
|
714 | # | |
739 | # 1) a number to indicate an offset in the series file |
|
715 | # 1) a number to indicate an offset in the series file | |
740 | # 2) a unique substring of the patch name was given |
|
716 | # 2) a unique substring of the patch name was given | |
741 | # 3) patchname[-+]num to indicate an offset in the series file |
|
717 | # 3) patchname[-+]num to indicate an offset in the series file | |
742 | def lookup(self, patch, strict=False): |
|
718 | def lookup(self, patch, strict=False): | |
743 | patch = patch and str(patch) |
|
719 | patch = patch and str(patch) | |
744 |
|
720 | |||
745 | def partial_name(s): |
|
721 | def partial_name(s): | |
746 | if s in self.series: |
|
722 | if s in self.series: | |
747 | return s |
|
723 | return s | |
748 | matches = [x for x in self.series if s in x] |
|
724 | matches = [x for x in self.series if s in x] | |
749 | if len(matches) > 1: |
|
725 | if len(matches) > 1: | |
750 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) |
|
726 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) | |
751 | for m in matches: |
|
727 | for m in matches: | |
752 | self.ui.warn(' %s\n' % m) |
|
728 | self.ui.warn(' %s\n' % m) | |
753 | return None |
|
729 | return None | |
754 | if matches: |
|
730 | if matches: | |
755 | return matches[0] |
|
731 | return matches[0] | |
756 | if len(self.series) > 0 and len(self.applied) > 0: |
|
732 | if len(self.series) > 0 and len(self.applied) > 0: | |
757 | if s == 'qtip': |
|
733 | if s == 'qtip': | |
758 | return self.series[self.series_end()-1] |
|
734 | return self.series[self.series_end()-1] | |
759 | if s == 'qbase': |
|
735 | if s == 'qbase': | |
760 | return self.series[0] |
|
736 | return self.series[0] | |
761 | return None |
|
737 | return None | |
762 | if patch == None: |
|
738 | if patch == None: | |
763 | return None |
|
739 | return None | |
764 |
|
740 | |||
765 | # we don't want to return a partial match until we make |
|
741 | # we don't want to return a partial match until we make | |
766 | # sure the file name passed in does not exist (checked below) |
|
742 | # sure the file name passed in does not exist (checked below) | |
767 | res = partial_name(patch) |
|
743 | res = partial_name(patch) | |
768 | if res and res == patch: |
|
744 | if res and res == patch: | |
769 | return res |
|
745 | return res | |
770 |
|
746 | |||
771 | if not os.path.isfile(self.join(patch)): |
|
747 | if not os.path.isfile(self.join(patch)): | |
772 | try: |
|
748 | try: | |
773 | sno = int(patch) |
|
749 | sno = int(patch) | |
774 | except(ValueError, OverflowError): |
|
750 | except(ValueError, OverflowError): | |
775 | pass |
|
751 | pass | |
776 | else: |
|
752 | else: | |
777 | if sno < len(self.series): |
|
753 | if sno < len(self.series): | |
778 | return self.series[sno] |
|
754 | return self.series[sno] | |
779 | if not strict: |
|
755 | if not strict: | |
780 | # return any partial match made above |
|
756 | # return any partial match made above | |
781 | if res: |
|
757 | if res: | |
782 | return res |
|
758 | return res | |
783 | minus = patch.rsplit('-', 1) |
|
759 | minus = patch.rsplit('-', 1) | |
784 | if len(minus) > 1: |
|
760 | if len(minus) > 1: | |
785 | res = partial_name(minus[0]) |
|
761 | res = partial_name(minus[0]) | |
786 | if res: |
|
762 | if res: | |
787 | i = self.series.index(res) |
|
763 | i = self.series.index(res) | |
788 | try: |
|
764 | try: | |
789 | off = int(minus[1] or 1) |
|
765 | off = int(minus[1] or 1) | |
790 | except(ValueError, OverflowError): |
|
766 | except(ValueError, OverflowError): | |
791 | pass |
|
767 | pass | |
792 | else: |
|
768 | else: | |
793 | if i - off >= 0: |
|
769 | if i - off >= 0: | |
794 | return self.series[i - off] |
|
770 | return self.series[i - off] | |
795 | plus = patch.rsplit('+', 1) |
|
771 | plus = patch.rsplit('+', 1) | |
796 | if len(plus) > 1: |
|
772 | if len(plus) > 1: | |
797 | res = partial_name(plus[0]) |
|
773 | res = partial_name(plus[0]) | |
798 | if res: |
|
774 | if res: | |
799 | i = self.series.index(res) |
|
775 | i = self.series.index(res) | |
800 | try: |
|
776 | try: | |
801 | off = int(plus[1] or 1) |
|
777 | off = int(plus[1] or 1) | |
802 | except(ValueError, OverflowError): |
|
778 | except(ValueError, OverflowError): | |
803 | pass |
|
779 | pass | |
804 | else: |
|
780 | else: | |
805 | if i + off < len(self.series): |
|
781 | if i + off < len(self.series): | |
806 | return self.series[i + off] |
|
782 | return self.series[i + off] | |
807 | raise util.Abort(_("patch %s not in series") % patch) |
|
783 | raise util.Abort(_("patch %s not in series") % patch) | |
808 |
|
784 | |||
809 | def push(self, repo, patch=None, force=False, list=False, |
|
785 | def push(self, repo, patch=None, force=False, list=False, | |
810 | mergeq=None, wlock=None): |
|
786 | mergeq=None, wlock=None): | |
811 | if not wlock: |
|
787 | if not wlock: | |
812 | wlock = repo.wlock() |
|
788 | wlock = repo.wlock() | |
813 | patch = self.lookup(patch) |
|
789 | patch = self.lookup(patch) | |
814 | if patch and self.isapplied(patch): |
|
790 | if patch and self.isapplied(patch): | |
815 | self.ui.warn(_("patch %s is already applied\n") % patch) |
|
791 | self.ui.warn(_("patch %s is already applied\n") % patch) | |
816 | sys.exit(1) |
|
792 | sys.exit(1) | |
817 | if self.series_end() == len(self.series): |
|
793 | if self.series_end() == len(self.series): | |
818 | self.ui.warn(_("patch series fully applied\n")) |
|
794 | self.ui.warn(_("patch series fully applied\n")) | |
819 | sys.exit(1) |
|
795 | sys.exit(1) | |
820 | if not force: |
|
796 | if not force: | |
821 | self.check_localchanges(repo) |
|
797 | self.check_localchanges(repo) | |
822 |
|
798 | |||
823 | self.applied_dirty = 1; |
|
799 | self.applied_dirty = 1; | |
824 | start = self.series_end() |
|
800 | start = self.series_end() | |
825 | if start > 0: |
|
801 | if start > 0: | |
826 | self.check_toppatch(repo) |
|
802 | self.check_toppatch(repo) | |
827 | if not patch: |
|
803 | if not patch: | |
828 | patch = self.series[start] |
|
804 | patch = self.series[start] | |
829 | end = start + 1 |
|
805 | end = start + 1 | |
830 | else: |
|
806 | else: | |
831 | end = self.series.index(patch, start) + 1 |
|
807 | end = self.series.index(patch, start) + 1 | |
832 | s = self.series[start:end] |
|
808 | s = self.series[start:end] | |
833 | if mergeq: |
|
809 | if mergeq: | |
834 | ret = self.mergepatch(repo, mergeq, s, wlock) |
|
810 | ret = self.mergepatch(repo, mergeq, s, wlock) | |
835 | else: |
|
811 | else: | |
836 | ret = self.apply(repo, s, list, wlock=wlock) |
|
812 | ret = self.apply(repo, s, list, wlock=wlock) | |
837 | top = self.applied[-1].name |
|
813 | top = self.applied[-1].name | |
838 | if ret[0]: |
|
814 | if ret[0]: | |
839 | self.ui.write("Errors during apply, please fix and refresh %s\n" % |
|
815 | self.ui.write("Errors during apply, please fix and refresh %s\n" % | |
840 | top) |
|
816 | top) | |
841 | else: |
|
817 | else: | |
842 | self.ui.write("Now at: %s\n" % top) |
|
818 | self.ui.write("Now at: %s\n" % top) | |
843 | return ret[0] |
|
819 | return ret[0] | |
844 |
|
820 | |||
845 | def pop(self, repo, patch=None, force=False, update=True, all=False, |
|
821 | def pop(self, repo, patch=None, force=False, update=True, all=False, | |
846 | wlock=None): |
|
822 | wlock=None): | |
847 | def getfile(f, rev): |
|
823 | def getfile(f, rev): | |
848 | t = repo.file(f).read(rev) |
|
824 | t = repo.file(f).read(rev) | |
849 | try: |
|
825 | try: | |
850 | repo.wfile(f, "w").write(t) |
|
826 | repo.wfile(f, "w").write(t) | |
851 | except IOError: |
|
827 | except IOError: | |
852 | try: |
|
828 | try: | |
853 | os.makedirs(os.path.dirname(repo.wjoin(f))) |
|
829 | os.makedirs(os.path.dirname(repo.wjoin(f))) | |
854 | except OSError, err: |
|
830 | except OSError, err: | |
855 | if err.errno != errno.EEXIST: raise |
|
831 | if err.errno != errno.EEXIST: raise | |
856 | repo.wfile(f, "w").write(t) |
|
832 | repo.wfile(f, "w").write(t) | |
857 |
|
833 | |||
858 | if not wlock: |
|
834 | if not wlock: | |
859 | wlock = repo.wlock() |
|
835 | wlock = repo.wlock() | |
860 | if patch: |
|
836 | if patch: | |
861 | # index, rev, patch |
|
837 | # index, rev, patch | |
862 | info = self.isapplied(patch) |
|
838 | info = self.isapplied(patch) | |
863 | if not info: |
|
839 | if not info: | |
864 | patch = self.lookup(patch) |
|
840 | patch = self.lookup(patch) | |
865 | info = self.isapplied(patch) |
|
841 | info = self.isapplied(patch) | |
866 | if not info: |
|
842 | if not info: | |
867 | raise util.Abort(_("patch %s is not applied") % patch) |
|
843 | raise util.Abort(_("patch %s is not applied") % patch) | |
868 | if len(self.applied) == 0: |
|
844 | if len(self.applied) == 0: | |
869 | self.ui.warn(_("no patches applied\n")) |
|
845 | self.ui.warn(_("no patches applied\n")) | |
870 | sys.exit(1) |
|
846 | sys.exit(1) | |
871 |
|
847 | |||
872 | if not update: |
|
848 | if not update: | |
873 | parents = repo.dirstate.parents() |
|
849 | parents = repo.dirstate.parents() | |
874 | rr = [ revlog.bin(x.rev) for x in self.applied ] |
|
850 | rr = [ revlog.bin(x.rev) for x in self.applied ] | |
875 | for p in parents: |
|
851 | for p in parents: | |
876 | if p in rr: |
|
852 | if p in rr: | |
877 | self.ui.warn("qpop: forcing dirstate update\n") |
|
853 | self.ui.warn("qpop: forcing dirstate update\n") | |
878 | update = True |
|
854 | update = True | |
879 |
|
855 | |||
880 | if not force and update: |
|
856 | if not force and update: | |
881 | self.check_localchanges(repo) |
|
857 | self.check_localchanges(repo) | |
882 |
|
858 | |||
883 | self.applied_dirty = 1; |
|
859 | self.applied_dirty = 1; | |
884 | end = len(self.applied) |
|
860 | end = len(self.applied) | |
885 | if not patch: |
|
861 | if not patch: | |
886 | if all: |
|
862 | if all: | |
887 | popi = 0 |
|
863 | popi = 0 | |
888 | else: |
|
864 | else: | |
889 | popi = len(self.applied) - 1 |
|
865 | popi = len(self.applied) - 1 | |
890 | else: |
|
866 | else: | |
891 | popi = info[0] + 1 |
|
867 | popi = info[0] + 1 | |
892 | if popi >= end: |
|
868 | if popi >= end: | |
893 | self.ui.warn("qpop: %s is already at the top\n" % patch) |
|
869 | self.ui.warn("qpop: %s is already at the top\n" % patch) | |
894 | return |
|
870 | return | |
895 | info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name] |
|
871 | info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name] | |
896 |
|
872 | |||
897 | start = info[0] |
|
873 | start = info[0] | |
898 | rev = revlog.bin(info[1]) |
|
874 | rev = revlog.bin(info[1]) | |
899 |
|
875 | |||
900 | # we know there are no local changes, so we can make a simplified |
|
876 | # we know there are no local changes, so we can make a simplified | |
901 | # form of hg.update. |
|
877 | # form of hg.update. | |
902 | if update: |
|
878 | if update: | |
903 | top = self.check_toppatch(repo) |
|
879 | top = self.check_toppatch(repo) | |
904 | qp = self.qparents(repo, rev) |
|
880 | qp = self.qparents(repo, rev) | |
905 | changes = repo.changelog.read(qp) |
|
881 | changes = repo.changelog.read(qp) | |
906 | mmap = repo.manifest.read(changes[0]) |
|
882 | mmap = repo.manifest.read(changes[0]) | |
907 | m, a, r, d, u = repo.status(qp, top)[:5] |
|
883 | m, a, r, d, u = repo.status(qp, top)[:5] | |
908 | if d: |
|
884 | if d: | |
909 | raise util.Abort("deletions found between repo revs") |
|
885 | raise util.Abort("deletions found between repo revs") | |
910 | for f in m: |
|
886 | for f in m: | |
911 | getfile(f, mmap[f]) |
|
887 | getfile(f, mmap[f]) | |
912 | for f in r: |
|
888 | for f in r: | |
913 | getfile(f, mmap[f]) |
|
889 | getfile(f, mmap[f]) | |
914 | util.set_exec(repo.wjoin(f), mmap.execf(f)) |
|
890 | util.set_exec(repo.wjoin(f), mmap.execf(f)) | |
915 | repo.dirstate.update(m + r, 'n') |
|
891 | repo.dirstate.update(m + r, 'n') | |
916 | for f in a: |
|
892 | for f in a: | |
917 | try: os.unlink(repo.wjoin(f)) |
|
893 | try: os.unlink(repo.wjoin(f)) | |
918 | except: raise |
|
894 | except: raise | |
919 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
|
895 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) | |
920 | except: pass |
|
896 | except: pass | |
921 | if a: |
|
897 | if a: | |
922 | repo.dirstate.forget(a) |
|
898 | repo.dirstate.forget(a) | |
923 | repo.dirstate.setparents(qp, revlog.nullid) |
|
899 | repo.dirstate.setparents(qp, revlog.nullid) | |
924 | self.strip(repo, rev, update=False, backup='strip', wlock=wlock) |
|
900 | self.strip(repo, rev, update=False, backup='strip', wlock=wlock) | |
925 | del self.applied[start:end] |
|
901 | del self.applied[start:end] | |
926 | if len(self.applied): |
|
902 | if len(self.applied): | |
927 | self.ui.write("Now at: %s\n" % self.applied[-1].name) |
|
903 | self.ui.write("Now at: %s\n" % self.applied[-1].name) | |
928 | else: |
|
904 | else: | |
929 | self.ui.write("Patch queue now empty\n") |
|
905 | self.ui.write("Patch queue now empty\n") | |
930 |
|
906 | |||
931 | def diff(self, repo, files): |
|
907 | def diff(self, repo, files): | |
932 | top = self.check_toppatch(repo) |
|
908 | top = self.check_toppatch(repo) | |
933 | if not top: |
|
909 | if not top: | |
934 | self.ui.write("No patches applied\n") |
|
910 | self.ui.write("No patches applied\n") | |
935 | return |
|
911 | return | |
936 | qp = self.qparents(repo, top) |
|
912 | qp = self.qparents(repo, top) | |
937 | self.printdiff(repo, qp, files=files) |
|
913 | self.printdiff(repo, qp, files=files) | |
938 |
|
914 | |||
939 | def refresh(self, repo, msg='', short=False): |
|
915 | def refresh(self, repo, msg='', short=False): | |
940 | if len(self.applied) == 0: |
|
916 | if len(self.applied) == 0: | |
941 | self.ui.write("No patches applied\n") |
|
917 | self.ui.write("No patches applied\n") | |
942 | return |
|
918 | return | |
943 | wlock = repo.wlock() |
|
919 | wlock = repo.wlock() | |
944 | self.check_toppatch(repo) |
|
920 | self.check_toppatch(repo) | |
945 | (top, patch) = (self.applied[-1].rev, self.applied[-1].name) |
|
921 | (top, patch) = (self.applied[-1].rev, self.applied[-1].name) | |
946 | top = revlog.bin(top) |
|
922 | top = revlog.bin(top) | |
947 | cparents = repo.changelog.parents(top) |
|
923 | cparents = repo.changelog.parents(top) | |
948 | patchparent = self.qparents(repo, top) |
|
924 | patchparent = self.qparents(repo, top) | |
949 | message, comments, user, date, patchfound = self.readheaders(patch) |
|
925 | message, comments, user, date, patchfound = self.readheaders(patch) | |
950 |
|
926 | |||
951 | patchf = self.opener(patch, "w") |
|
927 | patchf = self.opener(patch, "w") | |
952 | msg = msg.rstrip() |
|
928 | msg = msg.rstrip() | |
953 | if msg: |
|
929 | if msg: | |
954 | if comments: |
|
930 | if comments: | |
955 | # Remove existing message. |
|
931 | # Remove existing message. | |
956 | ci = 0 |
|
932 | ci = 0 | |
957 | for mi in range(len(message)): |
|
933 | for mi in range(len(message)): | |
958 | while message[mi] != comments[ci]: |
|
934 | while message[mi] != comments[ci]: | |
959 | ci += 1 |
|
935 | ci += 1 | |
960 | del comments[ci] |
|
936 | del comments[ci] | |
961 | comments.append(msg) |
|
937 | comments.append(msg) | |
962 | if comments: |
|
938 | if comments: | |
963 | comments = "\n".join(comments) + '\n\n' |
|
939 | comments = "\n".join(comments) + '\n\n' | |
964 | patchf.write(comments) |
|
940 | patchf.write(comments) | |
965 |
|
941 | |||
966 | tip = repo.changelog.tip() |
|
942 | tip = repo.changelog.tip() | |
967 | if top == tip: |
|
943 | if top == tip: | |
968 | # if the top of our patch queue is also the tip, there is an |
|
944 | # if the top of our patch queue is also the tip, there is an | |
969 | # optimization here. We update the dirstate in place and strip |
|
945 | # optimization here. We update the dirstate in place and strip | |
970 | # off the tip commit. Then just commit the current directory |
|
946 | # off the tip commit. Then just commit the current directory | |
971 | # tree. We can also send repo.commit the list of files |
|
947 | # tree. We can also send repo.commit the list of files | |
972 | # changed to speed up the diff |
|
948 | # changed to speed up the diff | |
973 | # |
|
949 | # | |
974 | # in short mode, we only diff the files included in the |
|
950 | # in short mode, we only diff the files included in the | |
975 | # patch already |
|
951 | # patch already | |
976 | # |
|
952 | # | |
977 | # this should really read: |
|
953 | # this should really read: | |
978 | # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5] |
|
954 | # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5] | |
979 | # but we do it backwards to take advantage of manifest/chlog |
|
955 | # but we do it backwards to take advantage of manifest/chlog | |
980 | # caching against the next repo.status call |
|
956 | # caching against the next repo.status call | |
981 | # |
|
957 | # | |
982 | mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5] |
|
958 | mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5] | |
983 | if short: |
|
959 | if short: | |
984 | filelist = mm + aa + dd |
|
960 | filelist = mm + aa + dd | |
985 | else: |
|
961 | else: | |
986 | filelist = None |
|
962 | filelist = None | |
987 | m, a, r, d, u = repo.status(files=filelist)[:5] |
|
963 | m, a, r, d, u = repo.status(files=filelist)[:5] | |
988 |
|
964 | |||
989 | # we might end up with files that were added between tip and |
|
965 | # we might end up with files that were added between tip and | |
990 | # the dirstate parent, but then changed in the local dirstate. |
|
966 | # the dirstate parent, but then changed in the local dirstate. | |
991 | # in this case, we want them to only show up in the added section |
|
967 | # in this case, we want them to only show up in the added section | |
992 | for x in m: |
|
968 | for x in m: | |
993 | if x not in aa: |
|
969 | if x not in aa: | |
994 | mm.append(x) |
|
970 | mm.append(x) | |
995 | # we might end up with files added by the local dirstate that |
|
971 | # we might end up with files added by the local dirstate that | |
996 | # were deleted by the patch. In this case, they should only |
|
972 | # were deleted by the patch. In this case, they should only | |
997 | # show up in the changed section. |
|
973 | # show up in the changed section. | |
998 | for x in a: |
|
974 | for x in a: | |
999 | if x in dd: |
|
975 | if x in dd: | |
1000 | del dd[dd.index(x)] |
|
976 | del dd[dd.index(x)] | |
1001 | mm.append(x) |
|
977 | mm.append(x) | |
1002 | else: |
|
978 | else: | |
1003 | aa.append(x) |
|
979 | aa.append(x) | |
1004 | # make sure any files deleted in the local dirstate |
|
980 | # make sure any files deleted in the local dirstate | |
1005 | # are not in the add or change column of the patch |
|
981 | # are not in the add or change column of the patch | |
1006 | forget = [] |
|
982 | forget = [] | |
1007 | for x in d + r: |
|
983 | for x in d + r: | |
1008 | if x in aa: |
|
984 | if x in aa: | |
1009 | del aa[aa.index(x)] |
|
985 | del aa[aa.index(x)] | |
1010 | forget.append(x) |
|
986 | forget.append(x) | |
1011 | continue |
|
987 | continue | |
1012 | elif x in mm: |
|
988 | elif x in mm: | |
1013 | del mm[mm.index(x)] |
|
989 | del mm[mm.index(x)] | |
1014 | dd.append(x) |
|
990 | dd.append(x) | |
1015 |
|
991 | |||
1016 | m = list(util.unique(mm)) |
|
992 | m = list(util.unique(mm)) | |
1017 | r = list(util.unique(dd)) |
|
993 | r = list(util.unique(dd)) | |
1018 | a = list(util.unique(aa)) |
|
994 | a = list(util.unique(aa)) | |
1019 | filelist = list(util.unique(m + r + a)) |
|
995 | filelist = list(util.unique(m + r + a)) | |
1020 | self.printdiff(repo, patchparent, files=filelist, |
|
996 | self.printdiff(repo, patchparent, files=filelist, | |
1021 | changes=(m, a, r, [], u), fp=patchf) |
|
997 | changes=(m, a, r, [], u), fp=patchf) | |
1022 | patchf.close() |
|
998 | patchf.close() | |
1023 |
|
999 | |||
1024 | changes = repo.changelog.read(tip) |
|
1000 | changes = repo.changelog.read(tip) | |
1025 | repo.dirstate.setparents(*cparents) |
|
1001 | repo.dirstate.setparents(*cparents) | |
1026 | repo.dirstate.update(a, 'a') |
|
1002 | repo.dirstate.update(a, 'a') | |
1027 | repo.dirstate.update(r, 'r') |
|
1003 | repo.dirstate.update(r, 'r') | |
1028 | repo.dirstate.update(m, 'n') |
|
1004 | repo.dirstate.update(m, 'n') | |
1029 | repo.dirstate.forget(forget) |
|
1005 | repo.dirstate.forget(forget) | |
1030 |
|
1006 | |||
1031 | if not msg: |
|
1007 | if not msg: | |
1032 | if not message: |
|
1008 | if not message: | |
1033 | message = "patch queue: %s\n" % patch |
|
1009 | message = "patch queue: %s\n" % patch | |
1034 | else: |
|
1010 | else: | |
1035 | message = "\n".join(message) |
|
1011 | message = "\n".join(message) | |
1036 | else: |
|
1012 | else: | |
1037 | message = msg |
|
1013 | message = msg | |
1038 |
|
1014 | |||
1039 | self.strip(repo, top, update=False, backup='strip', wlock=wlock) |
|
1015 | self.strip(repo, top, update=False, backup='strip', wlock=wlock) | |
1040 | n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) |
|
1016 | n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) | |
1041 | self.applied[-1] = statusentry(revlog.hex(n), patch) |
|
1017 | self.applied[-1] = statusentry(revlog.hex(n), patch) | |
1042 | self.applied_dirty = 1 |
|
1018 | self.applied_dirty = 1 | |
1043 | else: |
|
1019 | else: | |
1044 | self.printdiff(repo, patchparent, fp=patchf) |
|
1020 | self.printdiff(repo, patchparent, fp=patchf) | |
1045 | patchf.close() |
|
1021 | patchf.close() | |
1046 | self.pop(repo, force=True, wlock=wlock) |
|
1022 | self.pop(repo, force=True, wlock=wlock) | |
1047 | self.push(repo, force=True, wlock=wlock) |
|
1023 | self.push(repo, force=True, wlock=wlock) | |
1048 |
|
1024 | |||
1049 | def init(self, repo, create=False): |
|
1025 | def init(self, repo, create=False): | |
1050 | if os.path.isdir(self.path): |
|
1026 | if os.path.isdir(self.path): | |
1051 | raise util.Abort(_("patch queue directory already exists")) |
|
1027 | raise util.Abort(_("patch queue directory already exists")) | |
1052 | os.mkdir(self.path) |
|
1028 | os.mkdir(self.path) | |
1053 | if create: |
|
1029 | if create: | |
1054 | return self.qrepo(create=True) |
|
1030 | return self.qrepo(create=True) | |
1055 |
|
1031 | |||
1056 | def unapplied(self, repo, patch=None): |
|
1032 | def unapplied(self, repo, patch=None): | |
1057 | if patch and patch not in self.series: |
|
1033 | if patch and patch not in self.series: | |
1058 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1034 | raise util.Abort(_("patch %s is not in series file") % patch) | |
1059 | if not patch: |
|
1035 | if not patch: | |
1060 | start = self.series_end() |
|
1036 | start = self.series_end() | |
1061 | else: |
|
1037 | else: | |
1062 | start = self.series.index(patch) + 1 |
|
1038 | start = self.series.index(patch) + 1 | |
1063 | unapplied = [] |
|
1039 | unapplied = [] | |
1064 | for i in xrange(start, len(self.series)): |
|
1040 | for i in xrange(start, len(self.series)): | |
1065 | pushable, reason = self.pushable(i) |
|
1041 | pushable, reason = self.pushable(i) | |
1066 | if pushable: |
|
1042 | if pushable: | |
1067 | unapplied.append((i, self.series[i])) |
|
1043 | unapplied.append((i, self.series[i])) | |
1068 | self.explain_pushable(i) |
|
1044 | self.explain_pushable(i) | |
1069 | return unapplied |
|
1045 | return unapplied | |
1070 |
|
1046 | |||
1071 | def qseries(self, repo, missing=None, summary=False): |
|
1047 | def qseries(self, repo, missing=None, summary=False): | |
1072 | start = self.series_end(all_patches=True) |
|
1048 | start = self.series_end(all_patches=True) | |
1073 | if not missing: |
|
1049 | if not missing: | |
1074 | for i in range(len(self.series)): |
|
1050 | for i in range(len(self.series)): | |
1075 | patch = self.series[i] |
|
1051 | patch = self.series[i] | |
1076 | if self.ui.verbose: |
|
1052 | if self.ui.verbose: | |
1077 | if i < start: |
|
1053 | if i < start: | |
1078 | status = 'A' |
|
1054 | status = 'A' | |
1079 | elif self.pushable(i)[0]: |
|
1055 | elif self.pushable(i)[0]: | |
1080 | status = 'U' |
|
1056 | status = 'U' | |
1081 | else: |
|
1057 | else: | |
1082 | status = 'G' |
|
1058 | status = 'G' | |
1083 | self.ui.write('%d %s ' % (i, status)) |
|
1059 | self.ui.write('%d %s ' % (i, status)) | |
1084 | if summary: |
|
1060 | if summary: | |
1085 | msg = self.readheaders(patch)[0] |
|
1061 | msg = self.readheaders(patch)[0] | |
1086 | msg = msg and ': ' + msg[0] or ': ' |
|
1062 | msg = msg and ': ' + msg[0] or ': ' | |
1087 | else: |
|
1063 | else: | |
1088 | msg = '' |
|
1064 | msg = '' | |
1089 | self.ui.write('%s%s\n' % (patch, msg)) |
|
1065 | self.ui.write('%s%s\n' % (patch, msg)) | |
1090 | else: |
|
1066 | else: | |
1091 | msng_list = [] |
|
1067 | msng_list = [] | |
1092 | for root, dirs, files in os.walk(self.path): |
|
1068 | for root, dirs, files in os.walk(self.path): | |
1093 | d = root[len(self.path) + 1:] |
|
1069 | d = root[len(self.path) + 1:] | |
1094 | for f in files: |
|
1070 | for f in files: | |
1095 | fl = os.path.join(d, f) |
|
1071 | fl = os.path.join(d, f) | |
1096 | if (fl not in self.series and |
|
1072 | if (fl not in self.series and | |
1097 | fl not in (self.status_path, self.series_path) |
|
1073 | fl not in (self.status_path, self.series_path) | |
1098 | and not fl.startswith('.')): |
|
1074 | and not fl.startswith('.')): | |
1099 | msng_list.append(fl) |
|
1075 | msng_list.append(fl) | |
1100 | msng_list.sort() |
|
1076 | msng_list.sort() | |
1101 | for x in msng_list: |
|
1077 | for x in msng_list: | |
1102 | if self.ui.verbose: |
|
1078 | if self.ui.verbose: | |
1103 | self.ui.write("D ") |
|
1079 | self.ui.write("D ") | |
1104 | self.ui.write("%s\n" % x) |
|
1080 | self.ui.write("%s\n" % x) | |
1105 |
|
1081 | |||
1106 | def issaveline(self, l): |
|
1082 | def issaveline(self, l): | |
1107 | if l.name == '.hg.patches.save.line': |
|
1083 | if l.name == '.hg.patches.save.line': | |
1108 | return True |
|
1084 | return True | |
1109 |
|
1085 | |||
1110 | def qrepo(self, create=False): |
|
1086 | def qrepo(self, create=False): | |
1111 | if create or os.path.isdir(self.join(".hg")): |
|
1087 | if create or os.path.isdir(self.join(".hg")): | |
1112 | return hg.repository(self.ui, path=self.path, create=create) |
|
1088 | return hg.repository(self.ui, path=self.path, create=create) | |
1113 |
|
1089 | |||
1114 | def restore(self, repo, rev, delete=None, qupdate=None): |
|
1090 | def restore(self, repo, rev, delete=None, qupdate=None): | |
1115 | c = repo.changelog.read(rev) |
|
1091 | c = repo.changelog.read(rev) | |
1116 | desc = c[4].strip() |
|
1092 | desc = c[4].strip() | |
1117 | lines = desc.splitlines() |
|
1093 | lines = desc.splitlines() | |
1118 | i = 0 |
|
1094 | i = 0 | |
1119 | datastart = None |
|
1095 | datastart = None | |
1120 | series = [] |
|
1096 | series = [] | |
1121 | applied = [] |
|
1097 | applied = [] | |
1122 | qpp = None |
|
1098 | qpp = None | |
1123 | for i in xrange(0, len(lines)): |
|
1099 | for i in xrange(0, len(lines)): | |
1124 | if lines[i] == 'Patch Data:': |
|
1100 | if lines[i] == 'Patch Data:': | |
1125 | datastart = i + 1 |
|
1101 | datastart = i + 1 | |
1126 | elif lines[i].startswith('Dirstate:'): |
|
1102 | elif lines[i].startswith('Dirstate:'): | |
1127 | l = lines[i].rstrip() |
|
1103 | l = lines[i].rstrip() | |
1128 | l = l[10:].split(' ') |
|
1104 | l = l[10:].split(' ') | |
1129 | qpp = [ hg.bin(x) for x in l ] |
|
1105 | qpp = [ hg.bin(x) for x in l ] | |
1130 | elif datastart != None: |
|
1106 | elif datastart != None: | |
1131 | l = lines[i].rstrip() |
|
1107 | l = lines[i].rstrip() | |
1132 | se = statusentry(l) |
|
1108 | se = statusentry(l) | |
1133 | file_ = se.name |
|
1109 | file_ = se.name | |
1134 | if se.rev: |
|
1110 | if se.rev: | |
1135 | applied.append(se) |
|
1111 | applied.append(se) | |
1136 | series.append(file_) |
|
1112 | series.append(file_) | |
1137 | if datastart == None: |
|
1113 | if datastart == None: | |
1138 | self.ui.warn("No saved patch data found\n") |
|
1114 | self.ui.warn("No saved patch data found\n") | |
1139 | return 1 |
|
1115 | return 1 | |
1140 | self.ui.warn("restoring status: %s\n" % lines[0]) |
|
1116 | self.ui.warn("restoring status: %s\n" % lines[0]) | |
1141 | self.full_series = series |
|
1117 | self.full_series = series | |
1142 | self.applied = applied |
|
1118 | self.applied = applied | |
1143 | self.parse_series() |
|
1119 | self.parse_series() | |
1144 | self.series_dirty = 1 |
|
1120 | self.series_dirty = 1 | |
1145 | self.applied_dirty = 1 |
|
1121 | self.applied_dirty = 1 | |
1146 | heads = repo.changelog.heads() |
|
1122 | heads = repo.changelog.heads() | |
1147 | if delete: |
|
1123 | if delete: | |
1148 | if rev not in heads: |
|
1124 | if rev not in heads: | |
1149 | self.ui.warn("save entry has children, leaving it alone\n") |
|
1125 | self.ui.warn("save entry has children, leaving it alone\n") | |
1150 | else: |
|
1126 | else: | |
1151 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) |
|
1127 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) | |
1152 | pp = repo.dirstate.parents() |
|
1128 | pp = repo.dirstate.parents() | |
1153 | if rev in pp: |
|
1129 | if rev in pp: | |
1154 | update = True |
|
1130 | update = True | |
1155 | else: |
|
1131 | else: | |
1156 | update = False |
|
1132 | update = False | |
1157 | self.strip(repo, rev, update=update, backup='strip') |
|
1133 | self.strip(repo, rev, update=update, backup='strip') | |
1158 | if qpp: |
|
1134 | if qpp: | |
1159 | self.ui.warn("saved queue repository parents: %s %s\n" % |
|
1135 | self.ui.warn("saved queue repository parents: %s %s\n" % | |
1160 | (hg.short(qpp[0]), hg.short(qpp[1]))) |
|
1136 | (hg.short(qpp[0]), hg.short(qpp[1]))) | |
1161 | if qupdate: |
|
1137 | if qupdate: | |
1162 | print "queue directory updating" |
|
1138 | print "queue directory updating" | |
1163 | r = self.qrepo() |
|
1139 | r = self.qrepo() | |
1164 | if not r: |
|
1140 | if not r: | |
1165 | self.ui.warn("Unable to load queue repository\n") |
|
1141 | self.ui.warn("Unable to load queue repository\n") | |
1166 | return 1 |
|
1142 | return 1 | |
1167 | hg.clean(r, qpp[0]) |
|
1143 | hg.clean(r, qpp[0]) | |
1168 |
|
1144 | |||
1169 | def save(self, repo, msg=None): |
|
1145 | def save(self, repo, msg=None): | |
1170 | if len(self.applied) == 0: |
|
1146 | if len(self.applied) == 0: | |
1171 | self.ui.warn("save: no patches applied, exiting\n") |
|
1147 | self.ui.warn("save: no patches applied, exiting\n") | |
1172 | return 1 |
|
1148 | return 1 | |
1173 | if self.issaveline(self.applied[-1]): |
|
1149 | if self.issaveline(self.applied[-1]): | |
1174 | self.ui.warn("status is already saved\n") |
|
1150 | self.ui.warn("status is already saved\n") | |
1175 | return 1 |
|
1151 | return 1 | |
1176 |
|
1152 | |||
1177 | ar = [ ':' + x for x in self.full_series ] |
|
1153 | ar = [ ':' + x for x in self.full_series ] | |
1178 | if not msg: |
|
1154 | if not msg: | |
1179 | msg = "hg patches saved state" |
|
1155 | msg = "hg patches saved state" | |
1180 | else: |
|
1156 | else: | |
1181 | msg = "hg patches: " + msg.rstrip('\r\n') |
|
1157 | msg = "hg patches: " + msg.rstrip('\r\n') | |
1182 | r = self.qrepo() |
|
1158 | r = self.qrepo() | |
1183 | if r: |
|
1159 | if r: | |
1184 | pp = r.dirstate.parents() |
|
1160 | pp = r.dirstate.parents() | |
1185 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) |
|
1161 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) | |
1186 | msg += "\n\nPatch Data:\n" |
|
1162 | msg += "\n\nPatch Data:\n" | |
1187 | text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and |
|
1163 | text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and | |
1188 | "\n".join(ar) + '\n' or "") |
|
1164 | "\n".join(ar) + '\n' or "") | |
1189 | n = repo.commit(None, text, user=None, force=1) |
|
1165 | n = repo.commit(None, text, user=None, force=1) | |
1190 | if not n: |
|
1166 | if not n: | |
1191 | self.ui.warn("repo commit failed\n") |
|
1167 | self.ui.warn("repo commit failed\n") | |
1192 | return 1 |
|
1168 | return 1 | |
1193 | self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line')) |
|
1169 | self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line')) | |
1194 | self.applied_dirty = 1 |
|
1170 | self.applied_dirty = 1 | |
1195 |
|
1171 | |||
1196 | def full_series_end(self): |
|
1172 | def full_series_end(self): | |
1197 | if len(self.applied) > 0: |
|
1173 | if len(self.applied) > 0: | |
1198 | p = self.applied[-1].name |
|
1174 | p = self.applied[-1].name | |
1199 | end = self.find_series(p) |
|
1175 | end = self.find_series(p) | |
1200 | if end == None: |
|
1176 | if end == None: | |
1201 | return len(self.full_series) |
|
1177 | return len(self.full_series) | |
1202 | return end + 1 |
|
1178 | return end + 1 | |
1203 | return 0 |
|
1179 | return 0 | |
1204 |
|
1180 | |||
1205 | def series_end(self, all_patches=False): |
|
1181 | def series_end(self, all_patches=False): | |
1206 | end = 0 |
|
1182 | end = 0 | |
1207 | def next(start): |
|
1183 | def next(start): | |
1208 | if all_patches: |
|
1184 | if all_patches: | |
1209 | return start |
|
1185 | return start | |
1210 | i = start |
|
1186 | i = start | |
1211 | while i < len(self.series): |
|
1187 | while i < len(self.series): | |
1212 | p, reason = self.pushable(i) |
|
1188 | p, reason = self.pushable(i) | |
1213 | if p: |
|
1189 | if p: | |
1214 | break |
|
1190 | break | |
1215 | self.explain_pushable(i) |
|
1191 | self.explain_pushable(i) | |
1216 | i += 1 |
|
1192 | i += 1 | |
1217 | return i |
|
1193 | return i | |
1218 | if len(self.applied) > 0: |
|
1194 | if len(self.applied) > 0: | |
1219 | p = self.applied[-1].name |
|
1195 | p = self.applied[-1].name | |
1220 | try: |
|
1196 | try: | |
1221 | end = self.series.index(p) |
|
1197 | end = self.series.index(p) | |
1222 | except ValueError: |
|
1198 | except ValueError: | |
1223 | return 0 |
|
1199 | return 0 | |
1224 | return next(end + 1) |
|
1200 | return next(end + 1) | |
1225 | return next(end) |
|
1201 | return next(end) | |
1226 |
|
1202 | |||
1227 | def qapplied(self, repo, patch=None): |
|
1203 | def qapplied(self, repo, patch=None): | |
1228 | if patch and patch not in self.series: |
|
1204 | if patch and patch not in self.series: | |
1229 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1205 | raise util.Abort(_("patch %s is not in series file") % patch) | |
1230 | if not patch: |
|
1206 | if not patch: | |
1231 | end = len(self.applied) |
|
1207 | end = len(self.applied) | |
1232 | else: |
|
1208 | else: | |
1233 | end = self.series.index(patch) + 1 |
|
1209 | end = self.series.index(patch) + 1 | |
1234 | for x in xrange(end): |
|
1210 | for x in xrange(end): | |
1235 | p = self.appliedname(x) |
|
1211 | p = self.appliedname(x) | |
1236 | self.ui.write("%s\n" % p) |
|
1212 | self.ui.write("%s\n" % p) | |
1237 |
|
1213 | |||
1238 | def appliedname(self, index): |
|
1214 | def appliedname(self, index): | |
1239 | pname = self.applied[index].name |
|
1215 | pname = self.applied[index].name | |
1240 | if not self.ui.verbose: |
|
1216 | if not self.ui.verbose: | |
1241 | p = pname |
|
1217 | p = pname | |
1242 | else: |
|
1218 | else: | |
1243 | p = str(self.series.index(pname)) + " " + p |
|
1219 | p = str(self.series.index(pname)) + " " + p | |
1244 | return p |
|
1220 | return p | |
1245 |
|
1221 | |||
1246 | def top(self, repo): |
|
1222 | def top(self, repo): | |
1247 | if len(self.applied): |
|
1223 | if len(self.applied): | |
1248 | p = self.appliedname(-1) |
|
1224 | p = self.appliedname(-1) | |
1249 | self.ui.write(p + '\n') |
|
1225 | self.ui.write(p + '\n') | |
1250 | else: |
|
1226 | else: | |
1251 | self.ui.write("No patches applied\n") |
|
1227 | self.ui.write("No patches applied\n") | |
1252 |
|
1228 | |||
1253 | def next(self, repo): |
|
1229 | def next(self, repo): | |
1254 | end = self.series_end() |
|
1230 | end = self.series_end() | |
1255 | if end == len(self.series): |
|
1231 | if end == len(self.series): | |
1256 | self.ui.write("All patches applied\n") |
|
1232 | self.ui.write("All patches applied\n") | |
1257 | else: |
|
1233 | else: | |
1258 | p = self.series[end] |
|
1234 | p = self.series[end] | |
1259 | if self.ui.verbose: |
|
1235 | if self.ui.verbose: | |
1260 | self.ui.write("%d " % self.series.index(p)) |
|
1236 | self.ui.write("%d " % self.series.index(p)) | |
1261 | self.ui.write(p + '\n') |
|
1237 | self.ui.write(p + '\n') | |
1262 |
|
1238 | |||
1263 | def prev(self, repo): |
|
1239 | def prev(self, repo): | |
1264 | if len(self.applied) > 1: |
|
1240 | if len(self.applied) > 1: | |
1265 | p = self.appliedname(-2) |
|
1241 | p = self.appliedname(-2) | |
1266 | self.ui.write(p + '\n') |
|
1242 | self.ui.write(p + '\n') | |
1267 | elif len(self.applied) == 1: |
|
1243 | elif len(self.applied) == 1: | |
1268 | self.ui.write("Only one patch applied\n") |
|
1244 | self.ui.write("Only one patch applied\n") | |
1269 | else: |
|
1245 | else: | |
1270 | self.ui.write("No patches applied\n") |
|
1246 | self.ui.write("No patches applied\n") | |
1271 |
|
1247 | |||
1272 | def qimport(self, repo, files, patch=None, existing=None, force=None): |
|
1248 | def qimport(self, repo, files, patch=None, existing=None, force=None): | |
1273 | if len(files) > 1 and patch: |
|
1249 | if len(files) > 1 and patch: | |
1274 | raise util.Abort(_('option "-n" not valid when importing multiple ' |
|
1250 | raise util.Abort(_('option "-n" not valid when importing multiple ' | |
1275 | 'files')) |
|
1251 | 'files')) | |
1276 | i = 0 |
|
1252 | i = 0 | |
1277 | added = [] |
|
1253 | added = [] | |
1278 | for filename in files: |
|
1254 | for filename in files: | |
1279 | if existing: |
|
1255 | if existing: | |
1280 | if not patch: |
|
1256 | if not patch: | |
1281 | patch = filename |
|
1257 | patch = filename | |
1282 | if not os.path.isfile(self.join(patch)): |
|
1258 | if not os.path.isfile(self.join(patch)): | |
1283 | raise util.Abort(_("patch %s does not exist") % patch) |
|
1259 | raise util.Abort(_("patch %s does not exist") % patch) | |
1284 | else: |
|
1260 | else: | |
1285 | try: |
|
1261 | try: | |
1286 | text = file(filename).read() |
|
1262 | text = file(filename).read() | |
1287 | except IOError: |
|
1263 | except IOError: | |
1288 | raise util.Abort(_("unable to read %s") % patch) |
|
1264 | raise util.Abort(_("unable to read %s") % patch) | |
1289 | if not patch: |
|
1265 | if not patch: | |
1290 | patch = os.path.split(filename)[1] |
|
1266 | patch = os.path.split(filename)[1] | |
1291 | if not force and os.path.exists(self.join(patch)): |
|
1267 | if not force and os.path.exists(self.join(patch)): | |
1292 | raise util.Abort(_('patch "%s" already exists') % patch) |
|
1268 | raise util.Abort(_('patch "%s" already exists') % patch) | |
1293 | patchf = self.opener(patch, "w") |
|
1269 | patchf = self.opener(patch, "w") | |
1294 | patchf.write(text) |
|
1270 | patchf.write(text) | |
1295 | if patch in self.series: |
|
1271 | if patch in self.series: | |
1296 | raise util.Abort(_('patch %s is already in the series file') |
|
1272 | raise util.Abort(_('patch %s is already in the series file') | |
1297 | % patch) |
|
1273 | % patch) | |
1298 | index = self.full_series_end() + i |
|
1274 | index = self.full_series_end() + i | |
1299 | self.full_series[index:index] = [patch] |
|
1275 | self.full_series[index:index] = [patch] | |
1300 | self.parse_series() |
|
1276 | self.parse_series() | |
1301 | self.ui.warn("adding %s to series file\n" % patch) |
|
1277 | self.ui.warn("adding %s to series file\n" % patch) | |
1302 | i += 1 |
|
1278 | i += 1 | |
1303 | added.append(patch) |
|
1279 | added.append(patch) | |
1304 | patch = None |
|
1280 | patch = None | |
1305 | self.series_dirty = 1 |
|
1281 | self.series_dirty = 1 | |
1306 | qrepo = self.qrepo() |
|
1282 | qrepo = self.qrepo() | |
1307 | if qrepo: |
|
1283 | if qrepo: | |
1308 | qrepo.add(added) |
|
1284 | qrepo.add(added) | |
1309 |
|
1285 | |||
1310 | def delete(ui, repo, patch, *patches, **opts): |
|
1286 | def delete(ui, repo, patch, *patches, **opts): | |
1311 | """remove patches from queue |
|
1287 | """remove patches from queue | |
1312 |
|
1288 | |||
1313 | The patches must not be applied. |
|
1289 | The patches must not be applied. | |
1314 | With -k, the patch files are preserved in the patch directory.""" |
|
1290 | With -k, the patch files are preserved in the patch directory.""" | |
1315 | q = repo.mq |
|
1291 | q = repo.mq | |
1316 | q.delete(repo, (patch,) + patches, keep=opts.get('keep')) |
|
1292 | q.delete(repo, (patch,) + patches, keep=opts.get('keep')) | |
1317 | q.save_dirty() |
|
1293 | q.save_dirty() | |
1318 | return 0 |
|
1294 | return 0 | |
1319 |
|
1295 | |||
1320 | def applied(ui, repo, patch=None, **opts): |
|
1296 | def applied(ui, repo, patch=None, **opts): | |
1321 | """print the patches already applied""" |
|
1297 | """print the patches already applied""" | |
1322 | repo.mq.qapplied(repo, patch) |
|
1298 | repo.mq.qapplied(repo, patch) | |
1323 | return 0 |
|
1299 | return 0 | |
1324 |
|
1300 | |||
1325 | def unapplied(ui, repo, patch=None, **opts): |
|
1301 | def unapplied(ui, repo, patch=None, **opts): | |
1326 | """print the patches not yet applied""" |
|
1302 | """print the patches not yet applied""" | |
1327 | for i, p in repo.mq.unapplied(repo, patch): |
|
1303 | for i, p in repo.mq.unapplied(repo, patch): | |
1328 | if ui.verbose: |
|
1304 | if ui.verbose: | |
1329 | ui.write("%d " % i) |
|
1305 | ui.write("%d " % i) | |
1330 | ui.write("%s\n" % p) |
|
1306 | ui.write("%s\n" % p) | |
1331 |
|
1307 | |||
1332 | def qimport(ui, repo, *filename, **opts): |
|
1308 | def qimport(ui, repo, *filename, **opts): | |
1333 | """import a patch""" |
|
1309 | """import a patch""" | |
1334 | q = repo.mq |
|
1310 | q = repo.mq | |
1335 | q.qimport(repo, filename, patch=opts['name'], |
|
1311 | q.qimport(repo, filename, patch=opts['name'], | |
1336 | existing=opts['existing'], force=opts['force']) |
|
1312 | existing=opts['existing'], force=opts['force']) | |
1337 | q.save_dirty() |
|
1313 | q.save_dirty() | |
1338 | return 0 |
|
1314 | return 0 | |
1339 |
|
1315 | |||
1340 | def init(ui, repo, **opts): |
|
1316 | def init(ui, repo, **opts): | |
1341 | """init a new queue repository |
|
1317 | """init a new queue repository | |
1342 |
|
1318 | |||
1343 | The queue repository is unversioned by default. If -c is |
|
1319 | The queue repository is unversioned by default. If -c is | |
1344 | specified, qinit will create a separate nested repository |
|
1320 | specified, qinit will create a separate nested repository | |
1345 | for patches. Use qcommit to commit changes to this queue |
|
1321 | for patches. Use qcommit to commit changes to this queue | |
1346 | repository.""" |
|
1322 | repository.""" | |
1347 | q = repo.mq |
|
1323 | q = repo.mq | |
1348 | r = q.init(repo, create=opts['create_repo']) |
|
1324 | r = q.init(repo, create=opts['create_repo']) | |
1349 | q.save_dirty() |
|
1325 | q.save_dirty() | |
1350 | if r: |
|
1326 | if r: | |
1351 | fp = r.wopener('.hgignore', 'w') |
|
1327 | fp = r.wopener('.hgignore', 'w') | |
1352 | print >> fp, 'syntax: glob' |
|
1328 | print >> fp, 'syntax: glob' | |
1353 | print >> fp, 'status' |
|
1329 | print >> fp, 'status' | |
1354 | fp.close() |
|
1330 | fp.close() | |
1355 | r.wopener('series', 'w').close() |
|
1331 | r.wopener('series', 'w').close() | |
1356 | r.add(['.hgignore', 'series']) |
|
1332 | r.add(['.hgignore', 'series']) | |
1357 | return 0 |
|
1333 | return 0 | |
1358 |
|
1334 | |||
1359 | def clone(ui, source, dest=None, **opts): |
|
1335 | def clone(ui, source, dest=None, **opts): | |
1360 | '''clone main and patch repository at same time |
|
1336 | '''clone main and patch repository at same time | |
1361 |
|
1337 | |||
1362 | If source is local, destination will have no patches applied. If |
|
1338 | If source is local, destination will have no patches applied. If | |
1363 | source is remote, this command can not check if patches are |
|
1339 | source is remote, this command can not check if patches are | |
1364 | applied in source, so cannot guarantee that patches are not |
|
1340 | applied in source, so cannot guarantee that patches are not | |
1365 | applied in destination. If you clone remote repository, be sure |
|
1341 | applied in destination. If you clone remote repository, be sure | |
1366 | before that it has no patches applied. |
|
1342 | before that it has no patches applied. | |
1367 |
|
1343 | |||
1368 | Source patch repository is looked for in <src>/.hg/patches by |
|
1344 | Source patch repository is looked for in <src>/.hg/patches by | |
1369 | default. Use -p <url> to change. |
|
1345 | default. Use -p <url> to change. | |
1370 | ''' |
|
1346 | ''' | |
1371 | commands.setremoteconfig(ui, opts) |
|
1347 | commands.setremoteconfig(ui, opts) | |
1372 | if dest is None: |
|
1348 | if dest is None: | |
1373 | dest = hg.defaultdest(source) |
|
1349 | dest = hg.defaultdest(source) | |
1374 | sr = hg.repository(ui, ui.expandpath(source)) |
|
1350 | sr = hg.repository(ui, ui.expandpath(source)) | |
1375 | qbase, destrev = None, None |
|
1351 | qbase, destrev = None, None | |
1376 | if sr.local(): |
|
1352 | if sr.local(): | |
1377 | reposetup(ui, sr) |
|
1353 | reposetup(ui, sr) | |
1378 | if sr.mq.applied: |
|
1354 | if sr.mq.applied: | |
1379 | qbase = revlog.bin(sr.mq.applied[0].rev) |
|
1355 | qbase = revlog.bin(sr.mq.applied[0].rev) | |
1380 | if not hg.islocal(dest): |
|
1356 | if not hg.islocal(dest): | |
1381 | destrev = sr.parents(qbase)[0] |
|
1357 | destrev = sr.parents(qbase)[0] | |
1382 | ui.note(_('cloning main repo\n')) |
|
1358 | ui.note(_('cloning main repo\n')) | |
1383 | sr, dr = hg.clone(ui, sr, dest, |
|
1359 | sr, dr = hg.clone(ui, sr, dest, | |
1384 | pull=opts['pull'], |
|
1360 | pull=opts['pull'], | |
1385 | rev=destrev, |
|
1361 | rev=destrev, | |
1386 | update=False, |
|
1362 | update=False, | |
1387 | stream=opts['uncompressed']) |
|
1363 | stream=opts['uncompressed']) | |
1388 | ui.note(_('cloning patch repo\n')) |
|
1364 | ui.note(_('cloning patch repo\n')) | |
1389 | spr, dpr = hg.clone(ui, opts['patches'] or (sr.url() + '/.hg/patches'), |
|
1365 | spr, dpr = hg.clone(ui, opts['patches'] or (sr.url() + '/.hg/patches'), | |
1390 | dr.url() + '/.hg/patches', |
|
1366 | dr.url() + '/.hg/patches', | |
1391 | pull=opts['pull'], |
|
1367 | pull=opts['pull'], | |
1392 | update=not opts['noupdate'], |
|
1368 | update=not opts['noupdate'], | |
1393 | stream=opts['uncompressed']) |
|
1369 | stream=opts['uncompressed']) | |
1394 | if dr.local(): |
|
1370 | if dr.local(): | |
1395 | if qbase: |
|
1371 | if qbase: | |
1396 | ui.note(_('stripping applied patches from destination repo\n')) |
|
1372 | ui.note(_('stripping applied patches from destination repo\n')) | |
1397 | reposetup(ui, dr) |
|
1373 | reposetup(ui, dr) | |
1398 | dr.mq.strip(dr, qbase, update=False, backup=None) |
|
1374 | dr.mq.strip(dr, qbase, update=False, backup=None) | |
1399 | if not opts['noupdate']: |
|
1375 | if not opts['noupdate']: | |
1400 | ui.note(_('updating destination repo\n')) |
|
1376 | ui.note(_('updating destination repo\n')) | |
1401 | hg.update(dr, dr.changelog.tip()) |
|
1377 | hg.update(dr, dr.changelog.tip()) | |
1402 |
|
1378 | |||
1403 | def commit(ui, repo, *pats, **opts): |
|
1379 | def commit(ui, repo, *pats, **opts): | |
1404 | """commit changes in the queue repository""" |
|
1380 | """commit changes in the queue repository""" | |
1405 | q = repo.mq |
|
1381 | q = repo.mq | |
1406 | r = q.qrepo() |
|
1382 | r = q.qrepo() | |
1407 | if not r: raise util.Abort('no queue repository') |
|
1383 | if not r: raise util.Abort('no queue repository') | |
1408 | commands.commit(r.ui, r, *pats, **opts) |
|
1384 | commands.commit(r.ui, r, *pats, **opts) | |
1409 |
|
1385 | |||
1410 | def series(ui, repo, **opts): |
|
1386 | def series(ui, repo, **opts): | |
1411 | """print the entire series file""" |
|
1387 | """print the entire series file""" | |
1412 | repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) |
|
1388 | repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary']) | |
1413 | return 0 |
|
1389 | return 0 | |
1414 |
|
1390 | |||
1415 | def top(ui, repo, **opts): |
|
1391 | def top(ui, repo, **opts): | |
1416 | """print the name of the current patch""" |
|
1392 | """print the name of the current patch""" | |
1417 | repo.mq.top(repo) |
|
1393 | repo.mq.top(repo) | |
1418 | return 0 |
|
1394 | return 0 | |
1419 |
|
1395 | |||
1420 | def next(ui, repo, **opts): |
|
1396 | def next(ui, repo, **opts): | |
1421 | """print the name of the next patch""" |
|
1397 | """print the name of the next patch""" | |
1422 | repo.mq.next(repo) |
|
1398 | repo.mq.next(repo) | |
1423 | return 0 |
|
1399 | return 0 | |
1424 |
|
1400 | |||
1425 | def prev(ui, repo, **opts): |
|
1401 | def prev(ui, repo, **opts): | |
1426 | """print the name of the previous patch""" |
|
1402 | """print the name of the previous patch""" | |
1427 | repo.mq.prev(repo) |
|
1403 | repo.mq.prev(repo) | |
1428 | return 0 |
|
1404 | return 0 | |
1429 |
|
1405 | |||
1430 | def new(ui, repo, patch, **opts): |
|
1406 | def new(ui, repo, patch, **opts): | |
1431 | """create a new patch |
|
1407 | """create a new patch | |
1432 |
|
1408 | |||
1433 | qnew creates a new patch on top of the currently-applied patch |
|
1409 | qnew creates a new patch on top of the currently-applied patch | |
1434 | (if any). It will refuse to run if there are any outstanding |
|
1410 | (if any). It will refuse to run if there are any outstanding | |
1435 | changes unless -f is specified, in which case the patch will |
|
1411 | changes unless -f is specified, in which case the patch will | |
1436 | be initialised with them. |
|
1412 | be initialised with them. | |
1437 |
|
1413 | |||
1438 | -m or -l set the patch header as well as the commit message. |
|
1414 | -m or -l set the patch header as well as the commit message. | |
1439 | If neither is specified, the patch header is empty and the |
|
1415 | If neither is specified, the patch header is empty and the | |
1440 | commit message is 'New patch: PATCH'""" |
|
1416 | commit message is 'New patch: PATCH'""" | |
1441 | q = repo.mq |
|
1417 | q = repo.mq | |
1442 | message = commands.logmessage(opts) |
|
1418 | message = commands.logmessage(opts) | |
1443 | q.new(repo, patch, msg=message, force=opts['force']) |
|
1419 | q.new(repo, patch, msg=message, force=opts['force']) | |
1444 | q.save_dirty() |
|
1420 | q.save_dirty() | |
1445 | return 0 |
|
1421 | return 0 | |
1446 |
|
1422 | |||
1447 | def refresh(ui, repo, **opts): |
|
1423 | def refresh(ui, repo, **opts): | |
1448 | """update the current patch""" |
|
1424 | """update the current patch""" | |
1449 | q = repo.mq |
|
1425 | q = repo.mq | |
1450 | message = commands.logmessage(opts) |
|
1426 | message = commands.logmessage(opts) | |
1451 | if opts['edit']: |
|
1427 | if opts['edit']: | |
1452 | if message: |
|
1428 | if message: | |
1453 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1429 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) | |
1454 | patch = q.applied[-1].name |
|
1430 | patch = q.applied[-1].name | |
1455 | (message, comment, user, date, hasdiff) = q.readheaders(patch) |
|
1431 | (message, comment, user, date, hasdiff) = q.readheaders(patch) | |
1456 | message = ui.edit('\n'.join(message), user or ui.username()) |
|
1432 | message = ui.edit('\n'.join(message), user or ui.username()) | |
1457 | q.refresh(repo, msg=message, short=opts['short']) |
|
1433 | q.refresh(repo, msg=message, short=opts['short']) | |
1458 | q.save_dirty() |
|
1434 | q.save_dirty() | |
1459 | return 0 |
|
1435 | return 0 | |
1460 |
|
1436 | |||
1461 | def diff(ui, repo, *files, **opts): |
|
1437 | def diff(ui, repo, *files, **opts): | |
1462 | """diff of the current patch""" |
|
1438 | """diff of the current patch""" | |
1463 | # deep in the dirstate code, the walkhelper method wants a list, not a tuple |
|
1439 | # deep in the dirstate code, the walkhelper method wants a list, not a tuple | |
1464 | repo.mq.diff(repo, list(files)) |
|
1440 | repo.mq.diff(repo, list(files)) | |
1465 | return 0 |
|
1441 | return 0 | |
1466 |
|
1442 | |||
1467 | def fold(ui, repo, *files, **opts): |
|
1443 | def fold(ui, repo, *files, **opts): | |
1468 | """fold the named patches into the current patch |
|
1444 | """fold the named patches into the current patch | |
1469 |
|
1445 | |||
1470 | Patches must not yet be applied. Each patch will be successively |
|
1446 | Patches must not yet be applied. Each patch will be successively | |
1471 | applied to the current patch in the order given. If all the |
|
1447 | applied to the current patch in the order given. If all the | |
1472 | patches apply successfully, the current patch will be refreshed |
|
1448 | patches apply successfully, the current patch will be refreshed | |
1473 | with the new cumulative patch, and the folded patches will |
|
1449 | with the new cumulative patch, and the folded patches will | |
1474 | be deleted. With -k/--keep, the folded patch files will not |
|
1450 | be deleted. With -k/--keep, the folded patch files will not | |
1475 | be removed afterwards. |
|
1451 | be removed afterwards. | |
1476 |
|
1452 | |||
1477 | The header for each folded patch will be concatenated with |
|
1453 | The header for each folded patch will be concatenated with | |
1478 | the current patch header, separated by a line of '* * *'.""" |
|
1454 | the current patch header, separated by a line of '* * *'.""" | |
1479 |
|
1455 | |||
1480 | q = repo.mq |
|
1456 | q = repo.mq | |
1481 |
|
1457 | |||
1482 | if not files: |
|
1458 | if not files: | |
1483 | raise util.Abort(_('qfold requires at least one patch name')) |
|
1459 | raise util.Abort(_('qfold requires at least one patch name')) | |
1484 | if not q.check_toppatch(repo): |
|
1460 | if not q.check_toppatch(repo): | |
1485 | raise util.Abort(_('No patches applied\n')) |
|
1461 | raise util.Abort(_('No patches applied\n')) | |
1486 |
|
1462 | |||
1487 | message = commands.logmessage(opts) |
|
1463 | message = commands.logmessage(opts) | |
1488 | if opts['edit']: |
|
1464 | if opts['edit']: | |
1489 | if message: |
|
1465 | if message: | |
1490 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
1466 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) | |
1491 |
|
1467 | |||
1492 | parent = q.lookup('qtip') |
|
1468 | parent = q.lookup('qtip') | |
1493 | patches = [] |
|
1469 | patches = [] | |
1494 | messages = [] |
|
1470 | messages = [] | |
1495 | for f in files: |
|
1471 | for f in files: | |
1496 | patch = q.lookup(f) |
|
1472 | patch = q.lookup(f) | |
1497 | if patch in patches or patch == parent: |
|
1473 | if patch in patches or patch == parent: | |
1498 | ui.warn(_('Skipping already folded patch %s') % patch) |
|
1474 | ui.warn(_('Skipping already folded patch %s') % patch) | |
1499 | if q.isapplied(patch): |
|
1475 | if q.isapplied(patch): | |
1500 | raise util.Abort(_('qfold cannot fold already applied patch %s') % patch) |
|
1476 | raise util.Abort(_('qfold cannot fold already applied patch %s') % patch) | |
1501 | patches.append(patch) |
|
1477 | patches.append(patch) | |
1502 |
|
1478 | |||
1503 | for patch in patches: |
|
1479 | for patch in patches: | |
1504 | if not message: |
|
1480 | if not message: | |
1505 | messages.append(q.readheaders(patch)[0]) |
|
1481 | messages.append(q.readheaders(patch)[0]) | |
1506 | pf = q.join(patch) |
|
1482 | pf = q.join(patch) | |
1507 | (patchsuccess, files, fuzz) = q.patch(repo, pf) |
|
1483 | (patchsuccess, files, fuzz) = q.patch(repo, pf) | |
1508 | if not patchsuccess: |
|
1484 | if not patchsuccess: | |
1509 | raise util.Abort(_('Error folding patch %s') % patch) |
|
1485 | raise util.Abort(_('Error folding patch %s') % patch) | |
1510 |
|
1486 | |||
1511 | if not message: |
|
1487 | if not message: | |
1512 | message, comments, user = q.readheaders(parent)[0:3] |
|
1488 | message, comments, user = q.readheaders(parent)[0:3] | |
1513 | for msg in messages: |
|
1489 | for msg in messages: | |
1514 | message.append('* * *') |
|
1490 | message.append('* * *') | |
1515 | message.extend(msg) |
|
1491 | message.extend(msg) | |
1516 | message = '\n'.join(message) |
|
1492 | message = '\n'.join(message) | |
1517 |
|
1493 | |||
1518 | if opts['edit']: |
|
1494 | if opts['edit']: | |
1519 | message = ui.edit(message, user or ui.username()) |
|
1495 | message = ui.edit(message, user or ui.username()) | |
1520 |
|
1496 | |||
1521 | q.refresh(repo, msg=message) |
|
1497 | q.refresh(repo, msg=message) | |
1522 |
|
1498 | |||
1523 | for patch in patches: |
|
1499 | for patch in patches: | |
1524 | q.delete(repo, patch, keep=opts['keep']) |
|
1500 | q.delete(repo, patch, keep=opts['keep']) | |
1525 |
|
1501 | |||
1526 | q.save_dirty() |
|
1502 | q.save_dirty() | |
1527 |
|
1503 | |||
1528 | def guard(ui, repo, *args, **opts): |
|
1504 | def guard(ui, repo, *args, **opts): | |
1529 | '''set or print guards for a patch |
|
1505 | '''set or print guards for a patch | |
1530 |
|
1506 | |||
1531 | guards control whether a patch can be pushed. a patch with no |
|
1507 | guards control whether a patch can be pushed. a patch with no | |
1532 | guards is aways pushed. a patch with posative guard ("+foo") is |
|
1508 | guards is aways pushed. a patch with posative guard ("+foo") is | |
1533 | pushed only if qselect command enables guard "foo". a patch with |
|
1509 | pushed only if qselect command enables guard "foo". a patch with | |
1534 | nagative guard ("-foo") is never pushed if qselect command enables |
|
1510 | nagative guard ("-foo") is never pushed if qselect command enables | |
1535 | guard "foo". |
|
1511 | guard "foo". | |
1536 |
|
1512 | |||
1537 | with no arguments, default is to print current active guards. |
|
1513 | with no arguments, default is to print current active guards. | |
1538 | with arguments, set active guards for patch. |
|
1514 | with arguments, set active guards for patch. | |
1539 |
|
1515 | |||
1540 | to set nagative guard "-foo" on topmost patch ("--" is needed so |
|
1516 | to set nagative guard "-foo" on topmost patch ("--" is needed so | |
1541 | hg will not interpret "-foo" as argument): |
|
1517 | hg will not interpret "-foo" as argument): | |
1542 | hg qguard -- -foo |
|
1518 | hg qguard -- -foo | |
1543 |
|
1519 | |||
1544 | to set guards on other patch: |
|
1520 | to set guards on other patch: | |
1545 | hg qguard other.patch +2.6.17 -stable |
|
1521 | hg qguard other.patch +2.6.17 -stable | |
1546 | ''' |
|
1522 | ''' | |
1547 | def status(idx): |
|
1523 | def status(idx): | |
1548 | guards = q.series_guards[idx] or ['unguarded'] |
|
1524 | guards = q.series_guards[idx] or ['unguarded'] | |
1549 | ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards))) |
|
1525 | ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards))) | |
1550 | q = repo.mq |
|
1526 | q = repo.mq | |
1551 | patch = None |
|
1527 | patch = None | |
1552 | args = list(args) |
|
1528 | args = list(args) | |
1553 | if opts['list']: |
|
1529 | if opts['list']: | |
1554 | if args or opts['none']: |
|
1530 | if args or opts['none']: | |
1555 | raise util.Abort(_('cannot mix -l/--list with options or arguments')) |
|
1531 | raise util.Abort(_('cannot mix -l/--list with options or arguments')) | |
1556 | for i in xrange(len(q.series)): |
|
1532 | for i in xrange(len(q.series)): | |
1557 | status(i) |
|
1533 | status(i) | |
1558 | return |
|
1534 | return | |
1559 | if not args or args[0][0:1] in '-+': |
|
1535 | if not args or args[0][0:1] in '-+': | |
1560 | if not q.applied: |
|
1536 | if not q.applied: | |
1561 | raise util.Abort(_('no patches applied')) |
|
1537 | raise util.Abort(_('no patches applied')) | |
1562 | patch = q.applied[-1].name |
|
1538 | patch = q.applied[-1].name | |
1563 | if patch is None and args[0][0:1] not in '-+': |
|
1539 | if patch is None and args[0][0:1] not in '-+': | |
1564 | patch = args.pop(0) |
|
1540 | patch = args.pop(0) | |
1565 | if patch is None: |
|
1541 | if patch is None: | |
1566 | raise util.Abort(_('no patch to work with')) |
|
1542 | raise util.Abort(_('no patch to work with')) | |
1567 | if args or opts['none']: |
|
1543 | if args or opts['none']: | |
1568 | q.set_guards(q.find_series(patch), args) |
|
1544 | q.set_guards(q.find_series(patch), args) | |
1569 | q.save_dirty() |
|
1545 | q.save_dirty() | |
1570 | else: |
|
1546 | else: | |
1571 | status(q.series.index(q.lookup(patch))) |
|
1547 | status(q.series.index(q.lookup(patch))) | |
1572 |
|
1548 | |||
1573 | def header(ui, repo, patch=None): |
|
1549 | def header(ui, repo, patch=None): | |
1574 | """Print the header of the topmost or specified patch""" |
|
1550 | """Print the header of the topmost or specified patch""" | |
1575 | q = repo.mq |
|
1551 | q = repo.mq | |
1576 |
|
1552 | |||
1577 | if patch: |
|
1553 | if patch: | |
1578 | patch = q.lookup(patch) |
|
1554 | patch = q.lookup(patch) | |
1579 | else: |
|
1555 | else: | |
1580 | if not q.applied: |
|
1556 | if not q.applied: | |
1581 | ui.write('No patches applied\n') |
|
1557 | ui.write('No patches applied\n') | |
1582 | return |
|
1558 | return | |
1583 | patch = q.lookup('qtip') |
|
1559 | patch = q.lookup('qtip') | |
1584 | message = repo.mq.readheaders(patch)[0] |
|
1560 | message = repo.mq.readheaders(patch)[0] | |
1585 |
|
1561 | |||
1586 | ui.write('\n'.join(message) + '\n') |
|
1562 | ui.write('\n'.join(message) + '\n') | |
1587 |
|
1563 | |||
1588 | def lastsavename(path): |
|
1564 | def lastsavename(path): | |
1589 | (directory, base) = os.path.split(path) |
|
1565 | (directory, base) = os.path.split(path) | |
1590 | names = os.listdir(directory) |
|
1566 | names = os.listdir(directory) | |
1591 | namere = re.compile("%s.([0-9]+)" % base) |
|
1567 | namere = re.compile("%s.([0-9]+)" % base) | |
1592 | maxindex = None |
|
1568 | maxindex = None | |
1593 | maxname = None |
|
1569 | maxname = None | |
1594 | for f in names: |
|
1570 | for f in names: | |
1595 | m = namere.match(f) |
|
1571 | m = namere.match(f) | |
1596 | if m: |
|
1572 | if m: | |
1597 | index = int(m.group(1)) |
|
1573 | index = int(m.group(1)) | |
1598 | if maxindex == None or index > maxindex: |
|
1574 | if maxindex == None or index > maxindex: | |
1599 | maxindex = index |
|
1575 | maxindex = index | |
1600 | maxname = f |
|
1576 | maxname = f | |
1601 | if maxname: |
|
1577 | if maxname: | |
1602 | return (os.path.join(directory, maxname), maxindex) |
|
1578 | return (os.path.join(directory, maxname), maxindex) | |
1603 | return (None, None) |
|
1579 | return (None, None) | |
1604 |
|
1580 | |||
1605 | def savename(path): |
|
1581 | def savename(path): | |
1606 | (last, index) = lastsavename(path) |
|
1582 | (last, index) = lastsavename(path) | |
1607 | if last is None: |
|
1583 | if last is None: | |
1608 | index = 0 |
|
1584 | index = 0 | |
1609 | newpath = path + ".%d" % (index + 1) |
|
1585 | newpath = path + ".%d" % (index + 1) | |
1610 | return newpath |
|
1586 | return newpath | |
1611 |
|
1587 | |||
1612 | def push(ui, repo, patch=None, **opts): |
|
1588 | def push(ui, repo, patch=None, **opts): | |
1613 | """push the next patch onto the stack""" |
|
1589 | """push the next patch onto the stack""" | |
1614 | q = repo.mq |
|
1590 | q = repo.mq | |
1615 | mergeq = None |
|
1591 | mergeq = None | |
1616 |
|
1592 | |||
1617 | if opts['all']: |
|
1593 | if opts['all']: | |
1618 | patch = q.series[-1] |
|
1594 | patch = q.series[-1] | |
1619 | if opts['merge']: |
|
1595 | if opts['merge']: | |
1620 | if opts['name']: |
|
1596 | if opts['name']: | |
1621 | newpath = opts['name'] |
|
1597 | newpath = opts['name'] | |
1622 | else: |
|
1598 | else: | |
1623 | newpath, i = lastsavename(q.path) |
|
1599 | newpath, i = lastsavename(q.path) | |
1624 | if not newpath: |
|
1600 | if not newpath: | |
1625 | ui.warn("no saved queues found, please use -n\n") |
|
1601 | ui.warn("no saved queues found, please use -n\n") | |
1626 | return 1 |
|
1602 | return 1 | |
1627 | mergeq = queue(ui, repo.join(""), newpath) |
|
1603 | mergeq = queue(ui, repo.join(""), newpath) | |
1628 | ui.warn("merging with queue at: %s\n" % mergeq.path) |
|
1604 | ui.warn("merging with queue at: %s\n" % mergeq.path) | |
1629 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
|
1605 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], | |
1630 | mergeq=mergeq) |
|
1606 | mergeq=mergeq) | |
1631 | q.save_dirty() |
|
1607 | q.save_dirty() | |
1632 | return ret |
|
1608 | return ret | |
1633 |
|
1609 | |||
1634 | def pop(ui, repo, patch=None, **opts): |
|
1610 | def pop(ui, repo, patch=None, **opts): | |
1635 | """pop the current patch off the stack""" |
|
1611 | """pop the current patch off the stack""" | |
1636 | localupdate = True |
|
1612 | localupdate = True | |
1637 | if opts['name']: |
|
1613 | if opts['name']: | |
1638 | q = queue(ui, repo.join(""), repo.join(opts['name'])) |
|
1614 | q = queue(ui, repo.join(""), repo.join(opts['name'])) | |
1639 | ui.warn('using patch queue: %s\n' % q.path) |
|
1615 | ui.warn('using patch queue: %s\n' % q.path) | |
1640 | localupdate = False |
|
1616 | localupdate = False | |
1641 | else: |
|
1617 | else: | |
1642 | q = repo.mq |
|
1618 | q = repo.mq | |
1643 | q.pop(repo, patch, force=opts['force'], update=localupdate, all=opts['all']) |
|
1619 | q.pop(repo, patch, force=opts['force'], update=localupdate, all=opts['all']) | |
1644 | q.save_dirty() |
|
1620 | q.save_dirty() | |
1645 | return 0 |
|
1621 | return 0 | |
1646 |
|
1622 | |||
1647 | def rename(ui, repo, patch, name=None, **opts): |
|
1623 | def rename(ui, repo, patch, name=None, **opts): | |
1648 | """rename a patch |
|
1624 | """rename a patch | |
1649 |
|
1625 | |||
1650 | With one argument, renames the current patch to PATCH1. |
|
1626 | With one argument, renames the current patch to PATCH1. | |
1651 | With two arguments, renames PATCH1 to PATCH2.""" |
|
1627 | With two arguments, renames PATCH1 to PATCH2.""" | |
1652 |
|
1628 | |||
1653 | q = repo.mq |
|
1629 | q = repo.mq | |
1654 |
|
1630 | |||
1655 | if not name: |
|
1631 | if not name: | |
1656 | name = patch |
|
1632 | name = patch | |
1657 | patch = None |
|
1633 | patch = None | |
1658 |
|
1634 | |||
1659 | if name in q.series: |
|
1635 | if name in q.series: | |
1660 | raise util.Abort(_('A patch named %s already exists in the series file') % name) |
|
1636 | raise util.Abort(_('A patch named %s already exists in the series file') % name) | |
1661 |
|
1637 | |||
1662 | absdest = q.join(name) |
|
1638 | absdest = q.join(name) | |
1663 | if os.path.exists(absdest): |
|
1639 | if os.path.exists(absdest): | |
1664 | raise util.Abort(_('%s already exists') % absdest) |
|
1640 | raise util.Abort(_('%s already exists') % absdest) | |
1665 |
|
1641 | |||
1666 | if patch: |
|
1642 | if patch: | |
1667 | patch = q.lookup(patch) |
|
1643 | patch = q.lookup(patch) | |
1668 | else: |
|
1644 | else: | |
1669 | if not q.applied: |
|
1645 | if not q.applied: | |
1670 | ui.write(_('No patches applied\n')) |
|
1646 | ui.write(_('No patches applied\n')) | |
1671 | return |
|
1647 | return | |
1672 | patch = q.lookup('qtip') |
|
1648 | patch = q.lookup('qtip') | |
1673 |
|
1649 | |||
1674 | if ui.verbose: |
|
1650 | if ui.verbose: | |
1675 | ui.write('Renaming %s to %s\n' % (patch, name)) |
|
1651 | ui.write('Renaming %s to %s\n' % (patch, name)) | |
1676 | i = q.find_series(patch) |
|
1652 | i = q.find_series(patch) | |
1677 | q.full_series[i] = name |
|
1653 | q.full_series[i] = name | |
1678 | q.parse_series() |
|
1654 | q.parse_series() | |
1679 | q.series_dirty = 1 |
|
1655 | q.series_dirty = 1 | |
1680 |
|
1656 | |||
1681 | info = q.isapplied(patch) |
|
1657 | info = q.isapplied(patch) | |
1682 | if info: |
|
1658 | if info: | |
1683 | q.applied[info[0]] = statusentry(info[1], name) |
|
1659 | q.applied[info[0]] = statusentry(info[1], name) | |
1684 | q.applied_dirty = 1 |
|
1660 | q.applied_dirty = 1 | |
1685 |
|
1661 | |||
1686 | util.rename(q.join(patch), absdest) |
|
1662 | util.rename(q.join(patch), absdest) | |
1687 | r = q.qrepo() |
|
1663 | r = q.qrepo() | |
1688 | if r: |
|
1664 | if r: | |
1689 | wlock = r.wlock() |
|
1665 | wlock = r.wlock() | |
1690 | if r.dirstate.state(name) == 'r': |
|
1666 | if r.dirstate.state(name) == 'r': | |
1691 | r.undelete([name], wlock) |
|
1667 | r.undelete([name], wlock) | |
1692 | r.copy(patch, name, wlock) |
|
1668 | r.copy(patch, name, wlock) | |
1693 | r.remove([patch], False, wlock) |
|
1669 | r.remove([patch], False, wlock) | |
1694 |
|
1670 | |||
1695 | q.save_dirty() |
|
1671 | q.save_dirty() | |
1696 |
|
1672 | |||
1697 | def restore(ui, repo, rev, **opts): |
|
1673 | def restore(ui, repo, rev, **opts): | |
1698 | """restore the queue state saved by a rev""" |
|
1674 | """restore the queue state saved by a rev""" | |
1699 | rev = repo.lookup(rev) |
|
1675 | rev = repo.lookup(rev) | |
1700 | q = repo.mq |
|
1676 | q = repo.mq | |
1701 | q.restore(repo, rev, delete=opts['delete'], |
|
1677 | q.restore(repo, rev, delete=opts['delete'], | |
1702 | qupdate=opts['update']) |
|
1678 | qupdate=opts['update']) | |
1703 | q.save_dirty() |
|
1679 | q.save_dirty() | |
1704 | return 0 |
|
1680 | return 0 | |
1705 |
|
1681 | |||
1706 | def save(ui, repo, **opts): |
|
1682 | def save(ui, repo, **opts): | |
1707 | """save current queue state""" |
|
1683 | """save current queue state""" | |
1708 | q = repo.mq |
|
1684 | q = repo.mq | |
1709 | message = commands.logmessage(opts) |
|
1685 | message = commands.logmessage(opts) | |
1710 | ret = q.save(repo, msg=message) |
|
1686 | ret = q.save(repo, msg=message) | |
1711 | if ret: |
|
1687 | if ret: | |
1712 | return ret |
|
1688 | return ret | |
1713 | q.save_dirty() |
|
1689 | q.save_dirty() | |
1714 | if opts['copy']: |
|
1690 | if opts['copy']: | |
1715 | path = q.path |
|
1691 | path = q.path | |
1716 | if opts['name']: |
|
1692 | if opts['name']: | |
1717 | newpath = os.path.join(q.basepath, opts['name']) |
|
1693 | newpath = os.path.join(q.basepath, opts['name']) | |
1718 | if os.path.exists(newpath): |
|
1694 | if os.path.exists(newpath): | |
1719 | if not os.path.isdir(newpath): |
|
1695 | if not os.path.isdir(newpath): | |
1720 | raise util.Abort(_('destination %s exists and is not ' |
|
1696 | raise util.Abort(_('destination %s exists and is not ' | |
1721 | 'a directory') % newpath) |
|
1697 | 'a directory') % newpath) | |
1722 | if not opts['force']: |
|
1698 | if not opts['force']: | |
1723 | raise util.Abort(_('destination %s exists, ' |
|
1699 | raise util.Abort(_('destination %s exists, ' | |
1724 | 'use -f to force') % newpath) |
|
1700 | 'use -f to force') % newpath) | |
1725 | else: |
|
1701 | else: | |
1726 | newpath = savename(path) |
|
1702 | newpath = savename(path) | |
1727 | ui.warn("copy %s to %s\n" % (path, newpath)) |
|
1703 | ui.warn("copy %s to %s\n" % (path, newpath)) | |
1728 | util.copyfiles(path, newpath) |
|
1704 | util.copyfiles(path, newpath) | |
1729 | if opts['empty']: |
|
1705 | if opts['empty']: | |
1730 | try: |
|
1706 | try: | |
1731 | os.unlink(q.join(q.status_path)) |
|
1707 | os.unlink(q.join(q.status_path)) | |
1732 | except: |
|
1708 | except: | |
1733 | pass |
|
1709 | pass | |
1734 | return 0 |
|
1710 | return 0 | |
1735 |
|
1711 | |||
1736 | def strip(ui, repo, rev, **opts): |
|
1712 | def strip(ui, repo, rev, **opts): | |
1737 | """strip a revision and all later revs on the same branch""" |
|
1713 | """strip a revision and all later revs on the same branch""" | |
1738 | rev = repo.lookup(rev) |
|
1714 | rev = repo.lookup(rev) | |
1739 | backup = 'all' |
|
1715 | backup = 'all' | |
1740 | if opts['backup']: |
|
1716 | if opts['backup']: | |
1741 | backup = 'strip' |
|
1717 | backup = 'strip' | |
1742 | elif opts['nobackup']: |
|
1718 | elif opts['nobackup']: | |
1743 | backup = 'none' |
|
1719 | backup = 'none' | |
1744 | repo.mq.strip(repo, rev, backup=backup) |
|
1720 | repo.mq.strip(repo, rev, backup=backup) | |
1745 | return 0 |
|
1721 | return 0 | |
1746 |
|
1722 | |||
1747 | def select(ui, repo, *args, **opts): |
|
1723 | def select(ui, repo, *args, **opts): | |
1748 | '''set or print guarded patches to push |
|
1724 | '''set or print guarded patches to push | |
1749 |
|
1725 | |||
1750 | use qguard command to set or print guards on patch. then use |
|
1726 | use qguard command to set or print guards on patch. then use | |
1751 | qselect to tell mq which guards to use. example: |
|
1727 | qselect to tell mq which guards to use. example: | |
1752 |
|
1728 | |||
1753 | qguard foo.patch -stable (nagative guard) |
|
1729 | qguard foo.patch -stable (nagative guard) | |
1754 | qguard bar.patch +stable (posative guard) |
|
1730 | qguard bar.patch +stable (posative guard) | |
1755 | qselect stable |
|
1731 | qselect stable | |
1756 |
|
1732 | |||
1757 | this sets "stable" guard. mq will skip foo.patch (because it has |
|
1733 | this sets "stable" guard. mq will skip foo.patch (because it has | |
1758 | nagative match) but push bar.patch (because it has posative |
|
1734 | nagative match) but push bar.patch (because it has posative | |
1759 | match). patch is pushed if any posative guards match and no |
|
1735 | match). patch is pushed if any posative guards match and no | |
1760 | nagative guards match. |
|
1736 | nagative guards match. | |
1761 |
|
1737 | |||
1762 | with no arguments, default is to print current active guards. |
|
1738 | with no arguments, default is to print current active guards. | |
1763 | with arguments, set active guards as given. |
|
1739 | with arguments, set active guards as given. | |
1764 |
|
1740 | |||
1765 | use -n/--none to deactivate guards (no other arguments needed). |
|
1741 | use -n/--none to deactivate guards (no other arguments needed). | |
1766 | when no guards active, patches with posative guards are skipped, |
|
1742 | when no guards active, patches with posative guards are skipped, | |
1767 | patches with nagative guards are pushed. |
|
1743 | patches with nagative guards are pushed. | |
1768 |
|
1744 | |||
1769 | qselect can change guards of applied patches. it does not pop |
|
1745 | qselect can change guards of applied patches. it does not pop | |
1770 | guarded patches by default. use --pop to pop back to last applied |
|
1746 | guarded patches by default. use --pop to pop back to last applied | |
1771 | patch that is not guarded. use --reapply (implies --pop) to push |
|
1747 | patch that is not guarded. use --reapply (implies --pop) to push | |
1772 | back to current patch afterwards, but skip guarded patches. |
|
1748 | back to current patch afterwards, but skip guarded patches. | |
1773 |
|
1749 | |||
1774 | use -s/--series to print list of all guards in series file (no |
|
1750 | use -s/--series to print list of all guards in series file (no | |
1775 | other arguments needed). use -v for more information.''' |
|
1751 | other arguments needed). use -v for more information.''' | |
1776 |
|
1752 | |||
1777 | q = repo.mq |
|
1753 | q = repo.mq | |
1778 | guards = q.active() |
|
1754 | guards = q.active() | |
1779 | if args or opts['none']: |
|
1755 | if args or opts['none']: | |
1780 | old_unapplied = q.unapplied(repo) |
|
1756 | old_unapplied = q.unapplied(repo) | |
1781 | old_guarded = [i for i in xrange(len(q.applied)) if |
|
1757 | old_guarded = [i for i in xrange(len(q.applied)) if | |
1782 | not q.pushable(i)[0]] |
|
1758 | not q.pushable(i)[0]] | |
1783 | q.set_active(args) |
|
1759 | q.set_active(args) | |
1784 | q.save_dirty() |
|
1760 | q.save_dirty() | |
1785 | if not args: |
|
1761 | if not args: | |
1786 | ui.status(_('guards deactivated\n')) |
|
1762 | ui.status(_('guards deactivated\n')) | |
1787 | if not opts['pop'] and not opts['reapply']: |
|
1763 | if not opts['pop'] and not opts['reapply']: | |
1788 | unapplied = q.unapplied(repo) |
|
1764 | unapplied = q.unapplied(repo) | |
1789 | guarded = [i for i in xrange(len(q.applied)) |
|
1765 | guarded = [i for i in xrange(len(q.applied)) | |
1790 | if not q.pushable(i)[0]] |
|
1766 | if not q.pushable(i)[0]] | |
1791 | if len(unapplied) != len(old_unapplied): |
|
1767 | if len(unapplied) != len(old_unapplied): | |
1792 | ui.status(_('number of unguarded, unapplied patches has ' |
|
1768 | ui.status(_('number of unguarded, unapplied patches has ' | |
1793 | 'changed from %d to %d\n') % |
|
1769 | 'changed from %d to %d\n') % | |
1794 | (len(old_unapplied), len(unapplied))) |
|
1770 | (len(old_unapplied), len(unapplied))) | |
1795 | if len(guarded) != len(old_guarded): |
|
1771 | if len(guarded) != len(old_guarded): | |
1796 | ui.status(_('number of guarded, applied patches has changed ' |
|
1772 | ui.status(_('number of guarded, applied patches has changed ' | |
1797 | 'from %d to %d\n') % |
|
1773 | 'from %d to %d\n') % | |
1798 | (len(old_guarded), len(guarded))) |
|
1774 | (len(old_guarded), len(guarded))) | |
1799 | elif opts['series']: |
|
1775 | elif opts['series']: | |
1800 | guards = {} |
|
1776 | guards = {} | |
1801 | noguards = 0 |
|
1777 | noguards = 0 | |
1802 | for gs in q.series_guards: |
|
1778 | for gs in q.series_guards: | |
1803 | if not gs: |
|
1779 | if not gs: | |
1804 | noguards += 1 |
|
1780 | noguards += 1 | |
1805 | for g in gs: |
|
1781 | for g in gs: | |
1806 | guards.setdefault(g, 0) |
|
1782 | guards.setdefault(g, 0) | |
1807 | guards[g] += 1 |
|
1783 | guards[g] += 1 | |
1808 | if ui.verbose: |
|
1784 | if ui.verbose: | |
1809 | guards['NONE'] = noguards |
|
1785 | guards['NONE'] = noguards | |
1810 | guards = guards.items() |
|
1786 | guards = guards.items() | |
1811 | guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:])) |
|
1787 | guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:])) | |
1812 | if guards: |
|
1788 | if guards: | |
1813 | ui.note(_('guards in series file:\n')) |
|
1789 | ui.note(_('guards in series file:\n')) | |
1814 | for guard, count in guards: |
|
1790 | for guard, count in guards: | |
1815 | ui.note('%2d ' % count) |
|
1791 | ui.note('%2d ' % count) | |
1816 | ui.write(guard, '\n') |
|
1792 | ui.write(guard, '\n') | |
1817 | else: |
|
1793 | else: | |
1818 | ui.note(_('no guards in series file\n')) |
|
1794 | ui.note(_('no guards in series file\n')) | |
1819 | else: |
|
1795 | else: | |
1820 | if guards: |
|
1796 | if guards: | |
1821 | ui.note(_('active guards:\n')) |
|
1797 | ui.note(_('active guards:\n')) | |
1822 | for g in guards: |
|
1798 | for g in guards: | |
1823 | ui.write(g, '\n') |
|
1799 | ui.write(g, '\n') | |
1824 | else: |
|
1800 | else: | |
1825 | ui.write(_('no active guards\n')) |
|
1801 | ui.write(_('no active guards\n')) | |
1826 | reapply = opts['reapply'] and q.applied and q.appliedname(-1) |
|
1802 | reapply = opts['reapply'] and q.applied and q.appliedname(-1) | |
1827 | popped = False |
|
1803 | popped = False | |
1828 | if opts['pop'] or opts['reapply']: |
|
1804 | if opts['pop'] or opts['reapply']: | |
1829 | for i in xrange(len(q.applied)): |
|
1805 | for i in xrange(len(q.applied)): | |
1830 | pushable, reason = q.pushable(i) |
|
1806 | pushable, reason = q.pushable(i) | |
1831 | if not pushable: |
|
1807 | if not pushable: | |
1832 | ui.status(_('popping guarded patches\n')) |
|
1808 | ui.status(_('popping guarded patches\n')) | |
1833 | popped = True |
|
1809 | popped = True | |
1834 | if i == 0: |
|
1810 | if i == 0: | |
1835 | q.pop(repo, all=True) |
|
1811 | q.pop(repo, all=True) | |
1836 | else: |
|
1812 | else: | |
1837 | q.pop(repo, i-1) |
|
1813 | q.pop(repo, i-1) | |
1838 | break |
|
1814 | break | |
1839 | if popped: |
|
1815 | if popped: | |
1840 | try: |
|
1816 | try: | |
1841 | if reapply: |
|
1817 | if reapply: | |
1842 | ui.status(_('reapplying unguarded patches\n')) |
|
1818 | ui.status(_('reapplying unguarded patches\n')) | |
1843 | q.push(repo, reapply) |
|
1819 | q.push(repo, reapply) | |
1844 | finally: |
|
1820 | finally: | |
1845 | q.save_dirty() |
|
1821 | q.save_dirty() | |
1846 |
|
1822 | |||
1847 | def reposetup(ui, repo): |
|
1823 | def reposetup(ui, repo): | |
1848 | class mqrepo(repo.__class__): |
|
1824 | class mqrepo(repo.__class__): | |
1849 | def abort_if_wdir_patched(self, errmsg, force=False): |
|
1825 | def abort_if_wdir_patched(self, errmsg, force=False): | |
1850 | if self.mq.applied and not force: |
|
1826 | if self.mq.applied and not force: | |
1851 | parent = revlog.hex(self.dirstate.parents()[0]) |
|
1827 | parent = revlog.hex(self.dirstate.parents()[0]) | |
1852 | if parent in [s.rev for s in self.mq.applied]: |
|
1828 | if parent in [s.rev for s in self.mq.applied]: | |
1853 | raise util.Abort(errmsg) |
|
1829 | raise util.Abort(errmsg) | |
1854 |
|
1830 | |||
1855 | def commit(self, *args, **opts): |
|
1831 | def commit(self, *args, **opts): | |
1856 | if len(args) >= 6: |
|
1832 | if len(args) >= 6: | |
1857 | force = args[5] |
|
1833 | force = args[5] | |
1858 | else: |
|
1834 | else: | |
1859 | force = opts.get('force') |
|
1835 | force = opts.get('force') | |
1860 | self.abort_if_wdir_patched( |
|
1836 | self.abort_if_wdir_patched( | |
1861 | _('cannot commit over an applied mq patch'), |
|
1837 | _('cannot commit over an applied mq patch'), | |
1862 | force) |
|
1838 | force) | |
1863 |
|
1839 | |||
1864 | return super(mqrepo, self).commit(*args, **opts) |
|
1840 | return super(mqrepo, self).commit(*args, **opts) | |
1865 |
|
1841 | |||
1866 | def push(self, remote, force=False, revs=None): |
|
1842 | def push(self, remote, force=False, revs=None): | |
1867 | if self.mq.applied and not force: |
|
1843 | if self.mq.applied and not force: | |
1868 | raise util.Abort(_('source has mq patches applied')) |
|
1844 | raise util.Abort(_('source has mq patches applied')) | |
1869 | return super(mqrepo, self).push(remote, force, revs) |
|
1845 | return super(mqrepo, self).push(remote, force, revs) | |
1870 |
|
1846 | |||
1871 | def tags(self): |
|
1847 | def tags(self): | |
1872 | if self.tagscache: |
|
1848 | if self.tagscache: | |
1873 | return self.tagscache |
|
1849 | return self.tagscache | |
1874 |
|
1850 | |||
1875 | tagscache = super(mqrepo, self).tags() |
|
1851 | tagscache = super(mqrepo, self).tags() | |
1876 |
|
1852 | |||
1877 | q = self.mq |
|
1853 | q = self.mq | |
1878 | if not q.applied: |
|
1854 | if not q.applied: | |
1879 | return tagscache |
|
1855 | return tagscache | |
1880 |
|
1856 | |||
1881 | mqtags = [(patch.rev, patch.name) for patch in q.applied] |
|
1857 | mqtags = [(patch.rev, patch.name) for patch in q.applied] | |
1882 | mqtags.append((mqtags[-1][0], 'qtip')) |
|
1858 | mqtags.append((mqtags[-1][0], 'qtip')) | |
1883 | mqtags.append((mqtags[0][0], 'qbase')) |
|
1859 | mqtags.append((mqtags[0][0], 'qbase')) | |
1884 | for patch in mqtags: |
|
1860 | for patch in mqtags: | |
1885 | if patch[1] in tagscache: |
|
1861 | if patch[1] in tagscache: | |
1886 | self.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1]) |
|
1862 | self.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1]) | |
1887 | else: |
|
1863 | else: | |
1888 | tagscache[patch[1]] = revlog.bin(patch[0]) |
|
1864 | tagscache[patch[1]] = revlog.bin(patch[0]) | |
1889 |
|
1865 | |||
1890 | return tagscache |
|
1866 | return tagscache | |
1891 |
|
1867 | |||
1892 | if repo.local(): |
|
1868 | if repo.local(): | |
1893 | repo.__class__ = mqrepo |
|
1869 | repo.__class__ = mqrepo | |
1894 | repo.mq = queue(ui, repo.join("")) |
|
1870 | repo.mq = queue(ui, repo.join("")) | |
1895 |
|
1871 | |||
1896 | cmdtable = { |
|
1872 | cmdtable = { | |
1897 | "qapplied": (applied, [], 'hg qapplied [PATCH]'), |
|
1873 | "qapplied": (applied, [], 'hg qapplied [PATCH]'), | |
1898 | "qclone": (clone, |
|
1874 | "qclone": (clone, | |
1899 | [('', 'pull', None, _('use pull protocol to copy metadata')), |
|
1875 | [('', 'pull', None, _('use pull protocol to copy metadata')), | |
1900 | ('U', 'noupdate', None, _('do not update the new working directories')), |
|
1876 | ('U', 'noupdate', None, _('do not update the new working directories')), | |
1901 | ('', 'uncompressed', None, |
|
1877 | ('', 'uncompressed', None, | |
1902 | _('use uncompressed transfer (fast over LAN)')), |
|
1878 | _('use uncompressed transfer (fast over LAN)')), | |
1903 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
1879 | ('e', 'ssh', '', _('specify ssh command to use')), | |
1904 | ('p', 'patches', '', _('location of source patch repo')), |
|
1880 | ('p', 'patches', '', _('location of source patch repo')), | |
1905 | ('', 'remotecmd', '', |
|
1881 | ('', 'remotecmd', '', | |
1906 | _('specify hg command to run on the remote side'))], |
|
1882 | _('specify hg command to run on the remote side'))], | |
1907 | 'hg qclone [OPTION]... SOURCE [DEST]'), |
|
1883 | 'hg qclone [OPTION]... SOURCE [DEST]'), | |
1908 | "qcommit|qci": |
|
1884 | "qcommit|qci": | |
1909 | (commit, |
|
1885 | (commit, | |
1910 | commands.table["^commit|ci"][1], |
|
1886 | commands.table["^commit|ci"][1], | |
1911 | 'hg qcommit [OPTION]... [FILE]...'), |
|
1887 | 'hg qcommit [OPTION]... [FILE]...'), | |
1912 | "^qdiff": (diff, [], 'hg qdiff [FILE]...'), |
|
1888 | "^qdiff": (diff, [], 'hg qdiff [FILE]...'), | |
1913 | "qdelete|qremove|qrm": |
|
1889 | "qdelete|qremove|qrm": | |
1914 | (delete, |
|
1890 | (delete, | |
1915 | [('k', 'keep', None, _('keep patch file'))], |
|
1891 | [('k', 'keep', None, _('keep patch file'))], | |
1916 | 'hg qdelete [-k] PATCH'), |
|
1892 | 'hg qdelete [-k] PATCH'), | |
1917 | 'qfold': |
|
1893 | 'qfold': | |
1918 | (fold, |
|
1894 | (fold, | |
1919 | [('e', 'edit', None, _('edit patch header')), |
|
1895 | [('e', 'edit', None, _('edit patch header')), | |
1920 | ('k', 'keep', None, _('keep folded patch files')), |
|
1896 | ('k', 'keep', None, _('keep folded patch files')), | |
1921 | ('m', 'message', '', _('set patch header to <text>')), |
|
1897 | ('m', 'message', '', _('set patch header to <text>')), | |
1922 | ('l', 'logfile', '', _('set patch header to contents of <file>'))], |
|
1898 | ('l', 'logfile', '', _('set patch header to contents of <file>'))], | |
1923 | 'hg qfold [-e] [-m <text>] [-l <file] PATCH...'), |
|
1899 | 'hg qfold [-e] [-m <text>] [-l <file] PATCH...'), | |
1924 | 'qguard': (guard, [('l', 'list', None, _('list all patches and guards')), |
|
1900 | 'qguard': (guard, [('l', 'list', None, _('list all patches and guards')), | |
1925 | ('n', 'none', None, _('drop all guards'))], |
|
1901 | ('n', 'none', None, _('drop all guards'))], | |
1926 | 'hg qguard [PATCH] [+GUARD...] [-GUARD...]'), |
|
1902 | 'hg qguard [PATCH] [+GUARD...] [-GUARD...]'), | |
1927 | 'qheader': (header, [], |
|
1903 | 'qheader': (header, [], | |
1928 | _('hg qheader [PATCH]')), |
|
1904 | _('hg qheader [PATCH]')), | |
1929 | "^qimport": |
|
1905 | "^qimport": | |
1930 | (qimport, |
|
1906 | (qimport, | |
1931 | [('e', 'existing', None, 'import file in patch dir'), |
|
1907 | [('e', 'existing', None, 'import file in patch dir'), | |
1932 | ('n', 'name', '', 'patch file name'), |
|
1908 | ('n', 'name', '', 'patch file name'), | |
1933 | ('f', 'force', None, 'overwrite existing files')], |
|
1909 | ('f', 'force', None, 'overwrite existing files')], | |
1934 | 'hg qimport [-e] [-n NAME] [-f] FILE...'), |
|
1910 | 'hg qimport [-e] [-n NAME] [-f] FILE...'), | |
1935 | "^qinit": |
|
1911 | "^qinit": | |
1936 | (init, |
|
1912 | (init, | |
1937 | [('c', 'create-repo', None, 'create queue repository')], |
|
1913 | [('c', 'create-repo', None, 'create queue repository')], | |
1938 | 'hg qinit [-c]'), |
|
1914 | 'hg qinit [-c]'), | |
1939 | "qnew": |
|
1915 | "qnew": | |
1940 | (new, |
|
1916 | (new, | |
1941 | [('m', 'message', '', _('use <text> as commit message')), |
|
1917 | [('m', 'message', '', _('use <text> as commit message')), | |
1942 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
1918 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
1943 | ('f', 'force', None, _('import uncommitted changes into patch'))], |
|
1919 | ('f', 'force', None, _('import uncommitted changes into patch'))], | |
1944 | 'hg qnew [-m TEXT] [-l FILE] [-f] PATCH'), |
|
1920 | 'hg qnew [-m TEXT] [-l FILE] [-f] PATCH'), | |
1945 | "qnext": (next, [], 'hg qnext'), |
|
1921 | "qnext": (next, [], 'hg qnext'), | |
1946 | "qprev": (prev, [], 'hg qprev'), |
|
1922 | "qprev": (prev, [], 'hg qprev'), | |
1947 | "^qpop": |
|
1923 | "^qpop": | |
1948 | (pop, |
|
1924 | (pop, | |
1949 | [('a', 'all', None, 'pop all patches'), |
|
1925 | [('a', 'all', None, 'pop all patches'), | |
1950 | ('n', 'name', '', 'queue name to pop'), |
|
1926 | ('n', 'name', '', 'queue name to pop'), | |
1951 | ('f', 'force', None, 'forget any local changes')], |
|
1927 | ('f', 'force', None, 'forget any local changes')], | |
1952 | 'hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]'), |
|
1928 | 'hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]'), | |
1953 | "^qpush": |
|
1929 | "^qpush": | |
1954 | (push, |
|
1930 | (push, | |
1955 | [('f', 'force', None, 'apply if the patch has rejects'), |
|
1931 | [('f', 'force', None, 'apply if the patch has rejects'), | |
1956 | ('l', 'list', None, 'list patch name in commit text'), |
|
1932 | ('l', 'list', None, 'list patch name in commit text'), | |
1957 | ('a', 'all', None, 'apply all patches'), |
|
1933 | ('a', 'all', None, 'apply all patches'), | |
1958 | ('m', 'merge', None, 'merge from another queue'), |
|
1934 | ('m', 'merge', None, 'merge from another queue'), | |
1959 | ('n', 'name', '', 'merge queue name')], |
|
1935 | ('n', 'name', '', 'merge queue name')], | |
1960 | 'hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]'), |
|
1936 | 'hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]'), | |
1961 | "^qrefresh": |
|
1937 | "^qrefresh": | |
1962 | (refresh, |
|
1938 | (refresh, | |
1963 | [('e', 'edit', None, _('edit commit message')), |
|
1939 | [('e', 'edit', None, _('edit commit message')), | |
1964 | ('m', 'message', '', _('change commit message with <text>')), |
|
1940 | ('m', 'message', '', _('change commit message with <text>')), | |
1965 | ('l', 'logfile', '', _('change commit message with <file> content')), |
|
1941 | ('l', 'logfile', '', _('change commit message with <file> content')), | |
1966 | ('s', 'short', None, 'short refresh')], |
|
1942 | ('s', 'short', None, 'short refresh')], | |
1967 | 'hg qrefresh [-e] [-m TEXT] [-l FILE] [-s]'), |
|
1943 | 'hg qrefresh [-e] [-m TEXT] [-l FILE] [-s]'), | |
1968 | 'qrename|qmv': |
|
1944 | 'qrename|qmv': | |
1969 | (rename, [], 'hg qrename PATCH1 [PATCH2]'), |
|
1945 | (rename, [], 'hg qrename PATCH1 [PATCH2]'), | |
1970 | "qrestore": |
|
1946 | "qrestore": | |
1971 | (restore, |
|
1947 | (restore, | |
1972 | [('d', 'delete', None, 'delete save entry'), |
|
1948 | [('d', 'delete', None, 'delete save entry'), | |
1973 | ('u', 'update', None, 'update queue working dir')], |
|
1949 | ('u', 'update', None, 'update queue working dir')], | |
1974 | 'hg qrestore [-d] [-u] REV'), |
|
1950 | 'hg qrestore [-d] [-u] REV'), | |
1975 | "qsave": |
|
1951 | "qsave": | |
1976 | (save, |
|
1952 | (save, | |
1977 | [('m', 'message', '', _('use <text> as commit message')), |
|
1953 | [('m', 'message', '', _('use <text> as commit message')), | |
1978 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
1954 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
1979 | ('c', 'copy', None, 'copy patch directory'), |
|
1955 | ('c', 'copy', None, 'copy patch directory'), | |
1980 | ('n', 'name', '', 'copy directory name'), |
|
1956 | ('n', 'name', '', 'copy directory name'), | |
1981 | ('e', 'empty', None, 'clear queue status file'), |
|
1957 | ('e', 'empty', None, 'clear queue status file'), | |
1982 | ('f', 'force', None, 'force copy')], |
|
1958 | ('f', 'force', None, 'force copy')], | |
1983 | 'hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'), |
|
1959 | 'hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'), | |
1984 | "qselect": (select, |
|
1960 | "qselect": (select, | |
1985 | [('n', 'none', None, _('disable all guards')), |
|
1961 | [('n', 'none', None, _('disable all guards')), | |
1986 | ('s', 'series', None, _('list all guards in series file')), |
|
1962 | ('s', 'series', None, _('list all guards in series file')), | |
1987 | ('', 'pop', None, |
|
1963 | ('', 'pop', None, | |
1988 | _('pop to before first guarded applied patch')), |
|
1964 | _('pop to before first guarded applied patch')), | |
1989 | ('', 'reapply', None, _('pop, then reapply patches'))], |
|
1965 | ('', 'reapply', None, _('pop, then reapply patches'))], | |
1990 | 'hg qselect [OPTION...] [GUARD...]'), |
|
1966 | 'hg qselect [OPTION...] [GUARD...]'), | |
1991 | "qseries": |
|
1967 | "qseries": | |
1992 | (series, |
|
1968 | (series, | |
1993 | [('m', 'missing', None, 'print patches not in series'), |
|
1969 | [('m', 'missing', None, 'print patches not in series'), | |
1994 | ('s', 'summary', None, _('print first line of patch header'))], |
|
1970 | ('s', 'summary', None, _('print first line of patch header'))], | |
1995 | 'hg qseries [-m]'), |
|
1971 | 'hg qseries [-m]'), | |
1996 | "^strip": |
|
1972 | "^strip": | |
1997 | (strip, |
|
1973 | (strip, | |
1998 | [('f', 'force', None, 'force multi-head removal'), |
|
1974 | [('f', 'force', None, 'force multi-head removal'), | |
1999 | ('b', 'backup', None, 'bundle unrelated changesets'), |
|
1975 | ('b', 'backup', None, 'bundle unrelated changesets'), | |
2000 | ('n', 'nobackup', None, 'no backups')], |
|
1976 | ('n', 'nobackup', None, 'no backups')], | |
2001 | 'hg strip [-f] [-b] [-n] REV'), |
|
1977 | 'hg strip [-f] [-b] [-n] REV'), | |
2002 | "qtop": (top, [], 'hg qtop'), |
|
1978 | "qtop": (top, [], 'hg qtop'), | |
2003 | "qunapplied": (unapplied, [], 'hg qunapplied [PATCH]'), |
|
1979 | "qunapplied": (unapplied, [], 'hg qunapplied [PATCH]'), | |
2004 | } |
|
1980 | } |
@@ -1,3521 +1,3521 b'' | |||||
1 | # commands.py - command processing for mercurial |
|
1 | # commands.py - command processing for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from demandload import demandload |
|
8 | from demandload import demandload | |
9 | from node import * |
|
9 | from node import * | |
10 | from i18n import gettext as _ |
|
10 | from i18n import gettext as _ | |
11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") |
|
11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") | |
12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") |
|
12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") | |
13 | demandload(globals(), "fnmatch difflib patch random signal tempfile time") |
|
13 | demandload(globals(), "fnmatch difflib patch random signal tempfile time") | |
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") |
|
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") | |
15 | demandload(globals(), "archival cStringIO changegroup") |
|
15 | demandload(globals(), "archival cStringIO changegroup") | |
16 | demandload(globals(), "cmdutil hgweb.server sshserver") |
|
16 | demandload(globals(), "cmdutil hgweb.server sshserver") | |
17 |
|
17 | |||
18 | class UnknownCommand(Exception): |
|
18 | class UnknownCommand(Exception): | |
19 | """Exception raised if command is not in the command table.""" |
|
19 | """Exception raised if command is not in the command table.""" | |
20 | class AmbiguousCommand(Exception): |
|
20 | class AmbiguousCommand(Exception): | |
21 | """Exception raised if command shortcut matches more than one command.""" |
|
21 | """Exception raised if command shortcut matches more than one command.""" | |
22 |
|
22 | |||
23 | def bail_if_changed(repo): |
|
23 | def bail_if_changed(repo): | |
24 | modified, added, removed, deleted = repo.status()[:4] |
|
24 | modified, added, removed, deleted = repo.status()[:4] | |
25 | if modified or added or removed or deleted: |
|
25 | if modified or added or removed or deleted: | |
26 | raise util.Abort(_("outstanding uncommitted changes")) |
|
26 | raise util.Abort(_("outstanding uncommitted changes")) | |
27 |
|
27 | |||
28 | def relpath(repo, args): |
|
28 | def relpath(repo, args): | |
29 | cwd = repo.getcwd() |
|
29 | cwd = repo.getcwd() | |
30 | if cwd: |
|
30 | if cwd: | |
31 | return [util.normpath(os.path.join(cwd, x)) for x in args] |
|
31 | return [util.normpath(os.path.join(cwd, x)) for x in args] | |
32 | return args |
|
32 | return args | |
33 |
|
33 | |||
34 | def logmessage(opts): |
|
34 | def logmessage(opts): | |
35 | """ get the log message according to -m and -l option """ |
|
35 | """ get the log message according to -m and -l option """ | |
36 | message = opts['message'] |
|
36 | message = opts['message'] | |
37 | logfile = opts['logfile'] |
|
37 | logfile = opts['logfile'] | |
38 |
|
38 | |||
39 | if message and logfile: |
|
39 | if message and logfile: | |
40 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
40 | raise util.Abort(_('options --message and --logfile are mutually ' | |
41 | 'exclusive')) |
|
41 | 'exclusive')) | |
42 | if not message and logfile: |
|
42 | if not message and logfile: | |
43 | try: |
|
43 | try: | |
44 | if logfile == '-': |
|
44 | if logfile == '-': | |
45 | message = sys.stdin.read() |
|
45 | message = sys.stdin.read() | |
46 | else: |
|
46 | else: | |
47 | message = open(logfile).read() |
|
47 | message = open(logfile).read() | |
48 | except IOError, inst: |
|
48 | except IOError, inst: | |
49 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
49 | raise util.Abort(_("can't read commit message '%s': %s") % | |
50 | (logfile, inst.strerror)) |
|
50 | (logfile, inst.strerror)) | |
51 | return message |
|
51 | return message | |
52 |
|
52 | |||
53 | def walkchangerevs(ui, repo, pats, opts): |
|
53 | def walkchangerevs(ui, repo, pats, opts): | |
54 | '''Iterate over files and the revs they changed in. |
|
54 | '''Iterate over files and the revs they changed in. | |
55 |
|
55 | |||
56 | Callers most commonly need to iterate backwards over the history |
|
56 | Callers most commonly need to iterate backwards over the history | |
57 | it is interested in. Doing so has awful (quadratic-looking) |
|
57 | it is interested in. Doing so has awful (quadratic-looking) | |
58 | performance, so we use iterators in a "windowed" way. |
|
58 | performance, so we use iterators in a "windowed" way. | |
59 |
|
59 | |||
60 | We walk a window of revisions in the desired order. Within the |
|
60 | We walk a window of revisions in the desired order. Within the | |
61 | window, we first walk forwards to gather data, then in the desired |
|
61 | window, we first walk forwards to gather data, then in the desired | |
62 | order (usually backwards) to display it. |
|
62 | order (usually backwards) to display it. | |
63 |
|
63 | |||
64 | This function returns an (iterator, getchange, matchfn) tuple. The |
|
64 | This function returns an (iterator, getchange, matchfn) tuple. The | |
65 | getchange function returns the changelog entry for a numeric |
|
65 | getchange function returns the changelog entry for a numeric | |
66 | revision. The iterator yields 3-tuples. They will be of one of |
|
66 | revision. The iterator yields 3-tuples. They will be of one of | |
67 | the following forms: |
|
67 | the following forms: | |
68 |
|
68 | |||
69 | "window", incrementing, lastrev: stepping through a window, |
|
69 | "window", incrementing, lastrev: stepping through a window, | |
70 | positive if walking forwards through revs, last rev in the |
|
70 | positive if walking forwards through revs, last rev in the | |
71 | sequence iterated over - use to reset state for the current window |
|
71 | sequence iterated over - use to reset state for the current window | |
72 |
|
72 | |||
73 | "add", rev, fns: out-of-order traversal of the given file names |
|
73 | "add", rev, fns: out-of-order traversal of the given file names | |
74 | fns, which changed during revision rev - use to gather data for |
|
74 | fns, which changed during revision rev - use to gather data for | |
75 | possible display |
|
75 | possible display | |
76 |
|
76 | |||
77 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
77 | "iter", rev, None: in-order traversal of the revs earlier iterated | |
78 | over with "add" - use to display data''' |
|
78 | over with "add" - use to display data''' | |
79 |
|
79 | |||
80 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
80 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
81 | if start < end: |
|
81 | if start < end: | |
82 | while start < end: |
|
82 | while start < end: | |
83 | yield start, min(windowsize, end-start) |
|
83 | yield start, min(windowsize, end-start) | |
84 | start += windowsize |
|
84 | start += windowsize | |
85 | if windowsize < sizelimit: |
|
85 | if windowsize < sizelimit: | |
86 | windowsize *= 2 |
|
86 | windowsize *= 2 | |
87 | else: |
|
87 | else: | |
88 | while start > end: |
|
88 | while start > end: | |
89 | yield start, min(windowsize, start-end-1) |
|
89 | yield start, min(windowsize, start-end-1) | |
90 | start -= windowsize |
|
90 | start -= windowsize | |
91 | if windowsize < sizelimit: |
|
91 | if windowsize < sizelimit: | |
92 | windowsize *= 2 |
|
92 | windowsize *= 2 | |
93 |
|
93 | |||
94 |
|
94 | |||
95 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
95 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
96 | follow = opts.get('follow') or opts.get('follow_first') |
|
96 | follow = opts.get('follow') or opts.get('follow_first') | |
97 |
|
97 | |||
98 | if repo.changelog.count() == 0: |
|
98 | if repo.changelog.count() == 0: | |
99 | return [], False, matchfn |
|
99 | return [], False, matchfn | |
100 |
|
100 | |||
101 | if follow: |
|
101 | if follow: | |
102 | p = repo.dirstate.parents()[0] |
|
102 | p = repo.dirstate.parents()[0] | |
103 | if p == nullid: |
|
103 | if p == nullid: | |
104 | ui.warn(_('No working directory revision; defaulting to tip\n')) |
|
104 | ui.warn(_('No working directory revision; defaulting to tip\n')) | |
105 | start = 'tip' |
|
105 | start = 'tip' | |
106 | else: |
|
106 | else: | |
107 | start = repo.changelog.rev(p) |
|
107 | start = repo.changelog.rev(p) | |
108 | defrange = '%s:0' % start |
|
108 | defrange = '%s:0' % start | |
109 | else: |
|
109 | else: | |
110 | defrange = 'tip:0' |
|
110 | defrange = 'tip:0' | |
111 | revs = map(int, revrange(ui, repo, opts['rev'] or [defrange])) |
|
111 | revs = map(int, revrange(ui, repo, opts['rev'] or [defrange])) | |
112 | wanted = {} |
|
112 | wanted = {} | |
113 | slowpath = anypats |
|
113 | slowpath = anypats | |
114 | fncache = {} |
|
114 | fncache = {} | |
115 |
|
115 | |||
116 | chcache = {} |
|
116 | chcache = {} | |
117 | def getchange(rev): |
|
117 | def getchange(rev): | |
118 | ch = chcache.get(rev) |
|
118 | ch = chcache.get(rev) | |
119 | if ch is None: |
|
119 | if ch is None: | |
120 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) |
|
120 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) | |
121 | return ch |
|
121 | return ch | |
122 |
|
122 | |||
123 | if not slowpath and not files: |
|
123 | if not slowpath and not files: | |
124 | # No files, no patterns. Display all revs. |
|
124 | # No files, no patterns. Display all revs. | |
125 | wanted = dict(zip(revs, revs)) |
|
125 | wanted = dict(zip(revs, revs)) | |
126 | copies = [] |
|
126 | copies = [] | |
127 | if not slowpath: |
|
127 | if not slowpath: | |
128 | # Only files, no patterns. Check the history of each file. |
|
128 | # Only files, no patterns. Check the history of each file. | |
129 | def filerevgen(filelog, node): |
|
129 | def filerevgen(filelog, node): | |
130 | cl_count = repo.changelog.count() |
|
130 | cl_count = repo.changelog.count() | |
131 | if node is None: |
|
131 | if node is None: | |
132 | last = filelog.count() - 1 |
|
132 | last = filelog.count() - 1 | |
133 | else: |
|
133 | else: | |
134 | last = filelog.rev(node) |
|
134 | last = filelog.rev(node) | |
135 | for i, window in increasing_windows(last, -1): |
|
135 | for i, window in increasing_windows(last, -1): | |
136 | revs = [] |
|
136 | revs = [] | |
137 | for j in xrange(i - window, i + 1): |
|
137 | for j in xrange(i - window, i + 1): | |
138 | n = filelog.node(j) |
|
138 | n = filelog.node(j) | |
139 | revs.append((filelog.linkrev(n), |
|
139 | revs.append((filelog.linkrev(n), | |
140 | follow and filelog.renamed(n))) |
|
140 | follow and filelog.renamed(n))) | |
141 | revs.reverse() |
|
141 | revs.reverse() | |
142 | for rev in revs: |
|
142 | for rev in revs: | |
143 | # only yield rev for which we have the changelog, it can |
|
143 | # only yield rev for which we have the changelog, it can | |
144 | # happen while doing "hg log" during a pull or commit |
|
144 | # happen while doing "hg log" during a pull or commit | |
145 | if rev[0] < cl_count: |
|
145 | if rev[0] < cl_count: | |
146 | yield rev |
|
146 | yield rev | |
147 | def iterfiles(): |
|
147 | def iterfiles(): | |
148 | for filename in files: |
|
148 | for filename in files: | |
149 | yield filename, None |
|
149 | yield filename, None | |
150 | for filename_node in copies: |
|
150 | for filename_node in copies: | |
151 | yield filename_node |
|
151 | yield filename_node | |
152 | minrev, maxrev = min(revs), max(revs) |
|
152 | minrev, maxrev = min(revs), max(revs) | |
153 | for file_, node in iterfiles(): |
|
153 | for file_, node in iterfiles(): | |
154 | filelog = repo.file(file_) |
|
154 | filelog = repo.file(file_) | |
155 | # A zero count may be a directory or deleted file, so |
|
155 | # A zero count may be a directory or deleted file, so | |
156 | # try to find matching entries on the slow path. |
|
156 | # try to find matching entries on the slow path. | |
157 | if filelog.count() == 0: |
|
157 | if filelog.count() == 0: | |
158 | slowpath = True |
|
158 | slowpath = True | |
159 | break |
|
159 | break | |
160 | for rev, copied in filerevgen(filelog, node): |
|
160 | for rev, copied in filerevgen(filelog, node): | |
161 | if rev <= maxrev: |
|
161 | if rev <= maxrev: | |
162 | if rev < minrev: |
|
162 | if rev < minrev: | |
163 | break |
|
163 | break | |
164 | fncache.setdefault(rev, []) |
|
164 | fncache.setdefault(rev, []) | |
165 | fncache[rev].append(file_) |
|
165 | fncache[rev].append(file_) | |
166 | wanted[rev] = 1 |
|
166 | wanted[rev] = 1 | |
167 | if follow and copied: |
|
167 | if follow and copied: | |
168 | copies.append(copied) |
|
168 | copies.append(copied) | |
169 | if slowpath: |
|
169 | if slowpath: | |
170 | if follow: |
|
170 | if follow: | |
171 | raise util.Abort(_('can only follow copies/renames for explicit ' |
|
171 | raise util.Abort(_('can only follow copies/renames for explicit ' | |
172 | 'file names')) |
|
172 | 'file names')) | |
173 |
|
173 | |||
174 | # The slow path checks files modified in every changeset. |
|
174 | # The slow path checks files modified in every changeset. | |
175 | def changerevgen(): |
|
175 | def changerevgen(): | |
176 | for i, window in increasing_windows(repo.changelog.count()-1, -1): |
|
176 | for i, window in increasing_windows(repo.changelog.count()-1, -1): | |
177 | for j in xrange(i - window, i + 1): |
|
177 | for j in xrange(i - window, i + 1): | |
178 | yield j, getchange(j)[3] |
|
178 | yield j, getchange(j)[3] | |
179 |
|
179 | |||
180 | for rev, changefiles in changerevgen(): |
|
180 | for rev, changefiles in changerevgen(): | |
181 | matches = filter(matchfn, changefiles) |
|
181 | matches = filter(matchfn, changefiles) | |
182 | if matches: |
|
182 | if matches: | |
183 | fncache[rev] = matches |
|
183 | fncache[rev] = matches | |
184 | wanted[rev] = 1 |
|
184 | wanted[rev] = 1 | |
185 |
|
185 | |||
186 | class followfilter: |
|
186 | class followfilter: | |
187 | def __init__(self, onlyfirst=False): |
|
187 | def __init__(self, onlyfirst=False): | |
188 | self.startrev = -1 |
|
188 | self.startrev = -1 | |
189 | self.roots = [] |
|
189 | self.roots = [] | |
190 | self.onlyfirst = onlyfirst |
|
190 | self.onlyfirst = onlyfirst | |
191 |
|
191 | |||
192 | def match(self, rev): |
|
192 | def match(self, rev): | |
193 | def realparents(rev): |
|
193 | def realparents(rev): | |
194 | if self.onlyfirst: |
|
194 | if self.onlyfirst: | |
195 | return repo.changelog.parentrevs(rev)[0:1] |
|
195 | return repo.changelog.parentrevs(rev)[0:1] | |
196 | else: |
|
196 | else: | |
197 | return filter(lambda x: x != -1, repo.changelog.parentrevs(rev)) |
|
197 | return filter(lambda x: x != -1, repo.changelog.parentrevs(rev)) | |
198 |
|
198 | |||
199 | if self.startrev == -1: |
|
199 | if self.startrev == -1: | |
200 | self.startrev = rev |
|
200 | self.startrev = rev | |
201 | return True |
|
201 | return True | |
202 |
|
202 | |||
203 | if rev > self.startrev: |
|
203 | if rev > self.startrev: | |
204 | # forward: all descendants |
|
204 | # forward: all descendants | |
205 | if not self.roots: |
|
205 | if not self.roots: | |
206 | self.roots.append(self.startrev) |
|
206 | self.roots.append(self.startrev) | |
207 | for parent in realparents(rev): |
|
207 | for parent in realparents(rev): | |
208 | if parent in self.roots: |
|
208 | if parent in self.roots: | |
209 | self.roots.append(rev) |
|
209 | self.roots.append(rev) | |
210 | return True |
|
210 | return True | |
211 | else: |
|
211 | else: | |
212 | # backwards: all parents |
|
212 | # backwards: all parents | |
213 | if not self.roots: |
|
213 | if not self.roots: | |
214 | self.roots.extend(realparents(self.startrev)) |
|
214 | self.roots.extend(realparents(self.startrev)) | |
215 | if rev in self.roots: |
|
215 | if rev in self.roots: | |
216 | self.roots.remove(rev) |
|
216 | self.roots.remove(rev) | |
217 | self.roots.extend(realparents(rev)) |
|
217 | self.roots.extend(realparents(rev)) | |
218 | return True |
|
218 | return True | |
219 |
|
219 | |||
220 | return False |
|
220 | return False | |
221 |
|
221 | |||
222 | # it might be worthwhile to do this in the iterator if the rev range |
|
222 | # it might be worthwhile to do this in the iterator if the rev range | |
223 | # is descending and the prune args are all within that range |
|
223 | # is descending and the prune args are all within that range | |
224 | for rev in opts.get('prune', ()): |
|
224 | for rev in opts.get('prune', ()): | |
225 | rev = repo.changelog.rev(repo.lookup(rev)) |
|
225 | rev = repo.changelog.rev(repo.lookup(rev)) | |
226 | ff = followfilter() |
|
226 | ff = followfilter() | |
227 | stop = min(revs[0], revs[-1]) |
|
227 | stop = min(revs[0], revs[-1]) | |
228 | for x in range(rev, stop-1, -1): |
|
228 | for x in range(rev, stop-1, -1): | |
229 | if ff.match(x) and wanted.has_key(x): |
|
229 | if ff.match(x) and wanted.has_key(x): | |
230 | del wanted[x] |
|
230 | del wanted[x] | |
231 |
|
231 | |||
232 | def iterate(): |
|
232 | def iterate(): | |
233 | if follow and not files: |
|
233 | if follow and not files: | |
234 | ff = followfilter(onlyfirst=opts.get('follow_first')) |
|
234 | ff = followfilter(onlyfirst=opts.get('follow_first')) | |
235 | def want(rev): |
|
235 | def want(rev): | |
236 | if ff.match(rev) and rev in wanted: |
|
236 | if ff.match(rev) and rev in wanted: | |
237 | return True |
|
237 | return True | |
238 | return False |
|
238 | return False | |
239 | else: |
|
239 | else: | |
240 | def want(rev): |
|
240 | def want(rev): | |
241 | return rev in wanted |
|
241 | return rev in wanted | |
242 |
|
242 | |||
243 | for i, window in increasing_windows(0, len(revs)): |
|
243 | for i, window in increasing_windows(0, len(revs)): | |
244 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
244 | yield 'window', revs[0] < revs[-1], revs[-1] | |
245 | nrevs = [rev for rev in revs[i:i+window] if want(rev)] |
|
245 | nrevs = [rev for rev in revs[i:i+window] if want(rev)] | |
246 | srevs = list(nrevs) |
|
246 | srevs = list(nrevs) | |
247 | srevs.sort() |
|
247 | srevs.sort() | |
248 | for rev in srevs: |
|
248 | for rev in srevs: | |
249 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) |
|
249 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) | |
250 | yield 'add', rev, fns |
|
250 | yield 'add', rev, fns | |
251 | for rev in nrevs: |
|
251 | for rev in nrevs: | |
252 | yield 'iter', rev, None |
|
252 | yield 'iter', rev, None | |
253 | return iterate(), getchange, matchfn |
|
253 | return iterate(), getchange, matchfn | |
254 |
|
254 | |||
255 | revrangesep = ':' |
|
255 | revrangesep = ':' | |
256 |
|
256 | |||
257 | def revfix(repo, val, defval): |
|
257 | def revfix(repo, val, defval): | |
258 | '''turn user-level id of changeset into rev number. |
|
258 | '''turn user-level id of changeset into rev number. | |
259 | user-level id can be tag, changeset, rev number, or negative rev |
|
259 | user-level id can be tag, changeset, rev number, or negative rev | |
260 | number relative to number of revs (-1 is tip, etc).''' |
|
260 | number relative to number of revs (-1 is tip, etc).''' | |
261 | if not val: |
|
261 | if not val: | |
262 | return defval |
|
262 | return defval | |
263 | try: |
|
263 | try: | |
264 | num = int(val) |
|
264 | num = int(val) | |
265 | if str(num) != val: |
|
265 | if str(num) != val: | |
266 | raise ValueError |
|
266 | raise ValueError | |
267 | if num < 0: |
|
267 | if num < 0: | |
268 | num += repo.changelog.count() |
|
268 | num += repo.changelog.count() | |
269 | if num < 0: |
|
269 | if num < 0: | |
270 | num = 0 |
|
270 | num = 0 | |
271 | elif num >= repo.changelog.count(): |
|
271 | elif num >= repo.changelog.count(): | |
272 | raise ValueError |
|
272 | raise ValueError | |
273 | except ValueError: |
|
273 | except ValueError: | |
274 | try: |
|
274 | try: | |
275 | num = repo.changelog.rev(repo.lookup(val)) |
|
275 | num = repo.changelog.rev(repo.lookup(val)) | |
276 | except KeyError: |
|
276 | except KeyError: | |
277 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
277 | raise util.Abort(_('invalid revision identifier %s'), val) | |
278 | return num |
|
278 | return num | |
279 |
|
279 | |||
280 | def revpair(ui, repo, revs): |
|
280 | def revpair(ui, repo, revs): | |
281 | '''return pair of nodes, given list of revisions. second item can |
|
281 | '''return pair of nodes, given list of revisions. second item can | |
282 | be None, meaning use working dir.''' |
|
282 | be None, meaning use working dir.''' | |
283 | if not revs: |
|
283 | if not revs: | |
284 | return repo.dirstate.parents()[0], None |
|
284 | return repo.dirstate.parents()[0], None | |
285 | end = None |
|
285 | end = None | |
286 | if len(revs) == 1: |
|
286 | if len(revs) == 1: | |
287 | start = revs[0] |
|
287 | start = revs[0] | |
288 | if revrangesep in start: |
|
288 | if revrangesep in start: | |
289 | start, end = start.split(revrangesep, 1) |
|
289 | start, end = start.split(revrangesep, 1) | |
290 | start = revfix(repo, start, 0) |
|
290 | start = revfix(repo, start, 0) | |
291 | end = revfix(repo, end, repo.changelog.count() - 1) |
|
291 | end = revfix(repo, end, repo.changelog.count() - 1) | |
292 | else: |
|
292 | else: | |
293 | start = revfix(repo, start, None) |
|
293 | start = revfix(repo, start, None) | |
294 | elif len(revs) == 2: |
|
294 | elif len(revs) == 2: | |
295 | if revrangesep in revs[0] or revrangesep in revs[1]: |
|
295 | if revrangesep in revs[0] or revrangesep in revs[1]: | |
296 | raise util.Abort(_('too many revisions specified')) |
|
296 | raise util.Abort(_('too many revisions specified')) | |
297 | start = revfix(repo, revs[0], None) |
|
297 | start = revfix(repo, revs[0], None) | |
298 | end = revfix(repo, revs[1], None) |
|
298 | end = revfix(repo, revs[1], None) | |
299 | else: |
|
299 | else: | |
300 | raise util.Abort(_('too many revisions specified')) |
|
300 | raise util.Abort(_('too many revisions specified')) | |
301 | if end is not None: end = repo.lookup(str(end)) |
|
301 | if end is not None: end = repo.lookup(str(end)) | |
302 | return repo.lookup(str(start)), end |
|
302 | return repo.lookup(str(start)), end | |
303 |
|
303 | |||
304 | def revrange(ui, repo, revs): |
|
304 | def revrange(ui, repo, revs): | |
305 | """Yield revision as strings from a list of revision specifications.""" |
|
305 | """Yield revision as strings from a list of revision specifications.""" | |
306 | seen = {} |
|
306 | seen = {} | |
307 | for spec in revs: |
|
307 | for spec in revs: | |
308 | if revrangesep in spec: |
|
308 | if revrangesep in spec: | |
309 | start, end = spec.split(revrangesep, 1) |
|
309 | start, end = spec.split(revrangesep, 1) | |
310 | start = revfix(repo, start, 0) |
|
310 | start = revfix(repo, start, 0) | |
311 | end = revfix(repo, end, repo.changelog.count() - 1) |
|
311 | end = revfix(repo, end, repo.changelog.count() - 1) | |
312 | step = start > end and -1 or 1 |
|
312 | step = start > end and -1 or 1 | |
313 | for rev in xrange(start, end+step, step): |
|
313 | for rev in xrange(start, end+step, step): | |
314 | if rev in seen: |
|
314 | if rev in seen: | |
315 | continue |
|
315 | continue | |
316 | seen[rev] = 1 |
|
316 | seen[rev] = 1 | |
317 | yield str(rev) |
|
317 | yield str(rev) | |
318 | else: |
|
318 | else: | |
319 | rev = revfix(repo, spec, None) |
|
319 | rev = revfix(repo, spec, None) | |
320 | if rev in seen: |
|
320 | if rev in seen: | |
321 | continue |
|
321 | continue | |
322 | seen[rev] = 1 |
|
322 | seen[rev] = 1 | |
323 | yield str(rev) |
|
323 | yield str(rev) | |
324 |
|
324 | |||
325 | def write_bundle(cg, filename=None, compress=True): |
|
325 | def write_bundle(cg, filename=None, compress=True): | |
326 | """Write a bundle file and return its filename. |
|
326 | """Write a bundle file and return its filename. | |
327 |
|
327 | |||
328 | Existing files will not be overwritten. |
|
328 | Existing files will not be overwritten. | |
329 | If no filename is specified, a temporary file is created. |
|
329 | If no filename is specified, a temporary file is created. | |
330 | bz2 compression can be turned off. |
|
330 | bz2 compression can be turned off. | |
331 | The bundle file will be deleted in case of errors. |
|
331 | The bundle file will be deleted in case of errors. | |
332 | """ |
|
332 | """ | |
333 | class nocompress(object): |
|
333 | class nocompress(object): | |
334 | def compress(self, x): |
|
334 | def compress(self, x): | |
335 | return x |
|
335 | return x | |
336 | def flush(self): |
|
336 | def flush(self): | |
337 | return "" |
|
337 | return "" | |
338 |
|
338 | |||
339 | fh = None |
|
339 | fh = None | |
340 | cleanup = None |
|
340 | cleanup = None | |
341 | try: |
|
341 | try: | |
342 | if filename: |
|
342 | if filename: | |
343 | if os.path.exists(filename): |
|
343 | if os.path.exists(filename): | |
344 | raise util.Abort(_("file '%s' already exists"), filename) |
|
344 | raise util.Abort(_("file '%s' already exists"), filename) | |
345 | fh = open(filename, "wb") |
|
345 | fh = open(filename, "wb") | |
346 | else: |
|
346 | else: | |
347 | fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg") |
|
347 | fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg") | |
348 | fh = os.fdopen(fd, "wb") |
|
348 | fh = os.fdopen(fd, "wb") | |
349 | cleanup = filename |
|
349 | cleanup = filename | |
350 |
|
350 | |||
351 | if compress: |
|
351 | if compress: | |
352 | fh.write("HG10") |
|
352 | fh.write("HG10") | |
353 | z = bz2.BZ2Compressor(9) |
|
353 | z = bz2.BZ2Compressor(9) | |
354 | else: |
|
354 | else: | |
355 | fh.write("HG10UN") |
|
355 | fh.write("HG10UN") | |
356 | z = nocompress() |
|
356 | z = nocompress() | |
357 | # parse the changegroup data, otherwise we will block |
|
357 | # parse the changegroup data, otherwise we will block | |
358 | # in case of sshrepo because we don't know the end of the stream |
|
358 | # in case of sshrepo because we don't know the end of the stream | |
359 |
|
359 | |||
360 | # an empty chunkiter is the end of the changegroup |
|
360 | # an empty chunkiter is the end of the changegroup | |
361 | empty = False |
|
361 | empty = False | |
362 | while not empty: |
|
362 | while not empty: | |
363 | empty = True |
|
363 | empty = True | |
364 | for chunk in changegroup.chunkiter(cg): |
|
364 | for chunk in changegroup.chunkiter(cg): | |
365 | empty = False |
|
365 | empty = False | |
366 | fh.write(z.compress(changegroup.genchunk(chunk))) |
|
366 | fh.write(z.compress(changegroup.genchunk(chunk))) | |
367 | fh.write(z.compress(changegroup.closechunk())) |
|
367 | fh.write(z.compress(changegroup.closechunk())) | |
368 | fh.write(z.flush()) |
|
368 | fh.write(z.flush()) | |
369 | cleanup = None |
|
369 | cleanup = None | |
370 | return filename |
|
370 | return filename | |
371 | finally: |
|
371 | finally: | |
372 | if fh is not None: |
|
372 | if fh is not None: | |
373 | fh.close() |
|
373 | fh.close() | |
374 | if cleanup is not None: |
|
374 | if cleanup is not None: | |
375 | os.unlink(cleanup) |
|
375 | os.unlink(cleanup) | |
376 |
|
376 | |||
377 | def trimuser(ui, name, rev, revcache): |
|
377 | def trimuser(ui, name, rev, revcache): | |
378 | """trim the name of the user who committed a change""" |
|
378 | """trim the name of the user who committed a change""" | |
379 | user = revcache.get(rev) |
|
379 | user = revcache.get(rev) | |
380 | if user is None: |
|
380 | if user is None: | |
381 | user = revcache[rev] = ui.shortuser(name) |
|
381 | user = revcache[rev] = ui.shortuser(name) | |
382 | return user |
|
382 | return user | |
383 |
|
383 | |||
384 | class changeset_printer(object): |
|
384 | class changeset_printer(object): | |
385 | '''show changeset information when templating not requested.''' |
|
385 | '''show changeset information when templating not requested.''' | |
386 |
|
386 | |||
387 | def __init__(self, ui, repo): |
|
387 | def __init__(self, ui, repo): | |
388 | self.ui = ui |
|
388 | self.ui = ui | |
389 | self.repo = repo |
|
389 | self.repo = repo | |
390 |
|
390 | |||
391 | def show(self, rev=0, changenode=None, brinfo=None): |
|
391 | def show(self, rev=0, changenode=None, brinfo=None): | |
392 | '''show a single changeset or file revision''' |
|
392 | '''show a single changeset or file revision''' | |
393 | log = self.repo.changelog |
|
393 | log = self.repo.changelog | |
394 | if changenode is None: |
|
394 | if changenode is None: | |
395 | changenode = log.node(rev) |
|
395 | changenode = log.node(rev) | |
396 | elif not rev: |
|
396 | elif not rev: | |
397 | rev = log.rev(changenode) |
|
397 | rev = log.rev(changenode) | |
398 |
|
398 | |||
399 | if self.ui.quiet: |
|
399 | if self.ui.quiet: | |
400 | self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
400 | self.ui.write("%d:%s\n" % (rev, short(changenode))) | |
401 | return |
|
401 | return | |
402 |
|
402 | |||
403 | changes = log.read(changenode) |
|
403 | changes = log.read(changenode) | |
404 | date = util.datestr(changes[2]) |
|
404 | date = util.datestr(changes[2]) | |
405 |
|
405 | |||
406 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) |
|
406 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) | |
407 | for p in log.parents(changenode) |
|
407 | for p in log.parents(changenode) | |
408 | if self.ui.debugflag or p != nullid] |
|
408 | if self.ui.debugflag or p != nullid] | |
409 | if (not self.ui.debugflag and len(parents) == 1 and |
|
409 | if (not self.ui.debugflag and len(parents) == 1 and | |
410 | parents[0][0] == rev-1): |
|
410 | parents[0][0] == rev-1): | |
411 | parents = [] |
|
411 | parents = [] | |
412 |
|
412 | |||
413 | if self.ui.verbose: |
|
413 | if self.ui.verbose: | |
414 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) |
|
414 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) | |
415 | else: |
|
415 | else: | |
416 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) |
|
416 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) | |
417 |
|
417 | |||
418 | for tag in self.repo.nodetags(changenode): |
|
418 | for tag in self.repo.nodetags(changenode): | |
419 | self.ui.status(_("tag: %s\n") % tag) |
|
419 | self.ui.status(_("tag: %s\n") % tag) | |
420 | for parent in parents: |
|
420 | for parent in parents: | |
421 | self.ui.write(_("parent: %d:%s\n") % parent) |
|
421 | self.ui.write(_("parent: %d:%s\n") % parent) | |
422 |
|
422 | |||
423 | if brinfo and changenode in brinfo: |
|
423 | if brinfo and changenode in brinfo: | |
424 | br = brinfo[changenode] |
|
424 | br = brinfo[changenode] | |
425 | self.ui.write(_("branch: %s\n") % " ".join(br)) |
|
425 | self.ui.write(_("branch: %s\n") % " ".join(br)) | |
426 |
|
426 | |||
427 | self.ui.debug(_("manifest: %d:%s\n") % |
|
427 | self.ui.debug(_("manifest: %d:%s\n") % | |
428 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
428 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) | |
429 | self.ui.status(_("user: %s\n") % changes[1]) |
|
429 | self.ui.status(_("user: %s\n") % changes[1]) | |
430 | self.ui.status(_("date: %s\n") % date) |
|
430 | self.ui.status(_("date: %s\n") % date) | |
431 |
|
431 | |||
432 | if self.ui.debugflag: |
|
432 | if self.ui.debugflag: | |
433 | files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
|
433 | files = self.repo.status(log.parents(changenode)[0], changenode)[:3] | |
434 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
434 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
435 | files): |
|
435 | files): | |
436 | if value: |
|
436 | if value: | |
437 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) |
|
437 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) | |
438 | else: |
|
438 | else: | |
439 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) |
|
439 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) | |
440 |
|
440 | |||
441 | description = changes[4].strip() |
|
441 | description = changes[4].strip() | |
442 | if description: |
|
442 | if description: | |
443 | if self.ui.verbose: |
|
443 | if self.ui.verbose: | |
444 | self.ui.status(_("description:\n")) |
|
444 | self.ui.status(_("description:\n")) | |
445 | self.ui.status(description) |
|
445 | self.ui.status(description) | |
446 | self.ui.status("\n\n") |
|
446 | self.ui.status("\n\n") | |
447 | else: |
|
447 | else: | |
448 | self.ui.status(_("summary: %s\n") % |
|
448 | self.ui.status(_("summary: %s\n") % | |
449 | description.splitlines()[0]) |
|
449 | description.splitlines()[0]) | |
450 | self.ui.status("\n") |
|
450 | self.ui.status("\n") | |
451 |
|
451 | |||
452 | def show_changeset(ui, repo, opts): |
|
452 | def show_changeset(ui, repo, opts): | |
453 | '''show one changeset. uses template or regular display. caller |
|
453 | '''show one changeset. uses template or regular display. caller | |
454 | can pass in 'style' and 'template' options in opts.''' |
|
454 | can pass in 'style' and 'template' options in opts.''' | |
455 |
|
455 | |||
456 | tmpl = opts.get('template') |
|
456 | tmpl = opts.get('template') | |
457 | if tmpl: |
|
457 | if tmpl: | |
458 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
458 | tmpl = templater.parsestring(tmpl, quoted=False) | |
459 | else: |
|
459 | else: | |
460 | tmpl = ui.config('ui', 'logtemplate') |
|
460 | tmpl = ui.config('ui', 'logtemplate') | |
461 | if tmpl: tmpl = templater.parsestring(tmpl) |
|
461 | if tmpl: tmpl = templater.parsestring(tmpl) | |
462 | mapfile = opts.get('style') or ui.config('ui', 'style') |
|
462 | mapfile = opts.get('style') or ui.config('ui', 'style') | |
463 | if tmpl or mapfile: |
|
463 | if tmpl or mapfile: | |
464 | if mapfile: |
|
464 | if mapfile: | |
465 | if not os.path.isfile(mapfile): |
|
465 | if not os.path.isfile(mapfile): | |
466 | mapname = templater.templatepath('map-cmdline.' + mapfile) |
|
466 | mapname = templater.templatepath('map-cmdline.' + mapfile) | |
467 | if not mapname: mapname = templater.templatepath(mapfile) |
|
467 | if not mapname: mapname = templater.templatepath(mapfile) | |
468 | if mapname: mapfile = mapname |
|
468 | if mapname: mapfile = mapname | |
469 | try: |
|
469 | try: | |
470 | t = templater.changeset_templater(ui, repo, mapfile) |
|
470 | t = templater.changeset_templater(ui, repo, mapfile) | |
471 | except SyntaxError, inst: |
|
471 | except SyntaxError, inst: | |
472 | raise util.Abort(inst.args[0]) |
|
472 | raise util.Abort(inst.args[0]) | |
473 | if tmpl: t.use_template(tmpl) |
|
473 | if tmpl: t.use_template(tmpl) | |
474 | return t |
|
474 | return t | |
475 | return changeset_printer(ui, repo) |
|
475 | return changeset_printer(ui, repo) | |
476 |
|
476 | |||
477 | def setremoteconfig(ui, opts): |
|
477 | def setremoteconfig(ui, opts): | |
478 | "copy remote options to ui tree" |
|
478 | "copy remote options to ui tree" | |
479 | if opts.get('ssh'): |
|
479 | if opts.get('ssh'): | |
480 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
480 | ui.setconfig("ui", "ssh", opts['ssh']) | |
481 | if opts.get('remotecmd'): |
|
481 | if opts.get('remotecmd'): | |
482 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
482 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
483 |
|
483 | |||
484 | def show_version(ui): |
|
484 | def show_version(ui): | |
485 | """output version and copyright information""" |
|
485 | """output version and copyright information""" | |
486 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
486 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | |
487 | % version.get_version()) |
|
487 | % version.get_version()) | |
488 | ui.status(_( |
|
488 | ui.status(_( | |
489 | "\nCopyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>\n" |
|
489 | "\nCopyright (C) 2005, 2006 Matt Mackall <mpm@selenic.com>\n" | |
490 | "This is free software; see the source for copying conditions. " |
|
490 | "This is free software; see the source for copying conditions. " | |
491 | "There is NO\nwarranty; " |
|
491 | "There is NO\nwarranty; " | |
492 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
492 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
493 | )) |
|
493 | )) | |
494 |
|
494 | |||
495 | def help_(ui, name=None, with_version=False): |
|
495 | def help_(ui, name=None, with_version=False): | |
496 | """show help for a command, extension, or list of commands |
|
496 | """show help for a command, extension, or list of commands | |
497 |
|
497 | |||
498 | With no arguments, print a list of commands and short help. |
|
498 | With no arguments, print a list of commands and short help. | |
499 |
|
499 | |||
500 | Given a command name, print help for that command. |
|
500 | Given a command name, print help for that command. | |
501 |
|
501 | |||
502 | Given an extension name, print help for that extension, and the |
|
502 | Given an extension name, print help for that extension, and the | |
503 | commands it provides.""" |
|
503 | commands it provides.""" | |
504 | option_lists = [] |
|
504 | option_lists = [] | |
505 |
|
505 | |||
506 | def helpcmd(name): |
|
506 | def helpcmd(name): | |
507 | if with_version: |
|
507 | if with_version: | |
508 | show_version(ui) |
|
508 | show_version(ui) | |
509 | ui.write('\n') |
|
509 | ui.write('\n') | |
510 | aliases, i = findcmd(name) |
|
510 | aliases, i = findcmd(name) | |
511 | # synopsis |
|
511 | # synopsis | |
512 | ui.write("%s\n\n" % i[2]) |
|
512 | ui.write("%s\n\n" % i[2]) | |
513 |
|
513 | |||
514 | # description |
|
514 | # description | |
515 | doc = i[0].__doc__ |
|
515 | doc = i[0].__doc__ | |
516 | if not doc: |
|
516 | if not doc: | |
517 | doc = _("(No help text available)") |
|
517 | doc = _("(No help text available)") | |
518 | if ui.quiet: |
|
518 | if ui.quiet: | |
519 | doc = doc.splitlines(0)[0] |
|
519 | doc = doc.splitlines(0)[0] | |
520 | ui.write("%s\n" % doc.rstrip()) |
|
520 | ui.write("%s\n" % doc.rstrip()) | |
521 |
|
521 | |||
522 | if not ui.quiet: |
|
522 | if not ui.quiet: | |
523 | # aliases |
|
523 | # aliases | |
524 | if len(aliases) > 1: |
|
524 | if len(aliases) > 1: | |
525 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
525 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | |
526 |
|
526 | |||
527 | # options |
|
527 | # options | |
528 | if i[1]: |
|
528 | if i[1]: | |
529 | option_lists.append(("options", i[1])) |
|
529 | option_lists.append(("options", i[1])) | |
530 |
|
530 | |||
531 | def helplist(select=None): |
|
531 | def helplist(select=None): | |
532 | h = {} |
|
532 | h = {} | |
533 | cmds = {} |
|
533 | cmds = {} | |
534 | for c, e in table.items(): |
|
534 | for c, e in table.items(): | |
535 | f = c.split("|", 1)[0] |
|
535 | f = c.split("|", 1)[0] | |
536 | if select and not select(f): |
|
536 | if select and not select(f): | |
537 | continue |
|
537 | continue | |
538 | if name == "shortlist" and not f.startswith("^"): |
|
538 | if name == "shortlist" and not f.startswith("^"): | |
539 | continue |
|
539 | continue | |
540 | f = f.lstrip("^") |
|
540 | f = f.lstrip("^") | |
541 | if not ui.debugflag and f.startswith("debug"): |
|
541 | if not ui.debugflag and f.startswith("debug"): | |
542 | continue |
|
542 | continue | |
543 | doc = e[0].__doc__ |
|
543 | doc = e[0].__doc__ | |
544 | if not doc: |
|
544 | if not doc: | |
545 | doc = _("(No help text available)") |
|
545 | doc = _("(No help text available)") | |
546 | h[f] = doc.splitlines(0)[0].rstrip() |
|
546 | h[f] = doc.splitlines(0)[0].rstrip() | |
547 | cmds[f] = c.lstrip("^") |
|
547 | cmds[f] = c.lstrip("^") | |
548 |
|
548 | |||
549 | fns = h.keys() |
|
549 | fns = h.keys() | |
550 | fns.sort() |
|
550 | fns.sort() | |
551 | m = max(map(len, fns)) |
|
551 | m = max(map(len, fns)) | |
552 | for f in fns: |
|
552 | for f in fns: | |
553 | if ui.verbose: |
|
553 | if ui.verbose: | |
554 | commands = cmds[f].replace("|",", ") |
|
554 | commands = cmds[f].replace("|",", ") | |
555 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
555 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
556 | else: |
|
556 | else: | |
557 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
557 | ui.write(' %-*s %s\n' % (m, f, h[f])) | |
558 |
|
558 | |||
559 | def helpext(name): |
|
559 | def helpext(name): | |
560 | try: |
|
560 | try: | |
561 | mod = findext(name) |
|
561 | mod = findext(name) | |
562 | except KeyError: |
|
562 | except KeyError: | |
563 | raise UnknownCommand(name) |
|
563 | raise UnknownCommand(name) | |
564 |
|
564 | |||
565 | doc = (mod.__doc__ or _('No help text available')).splitlines(0) |
|
565 | doc = (mod.__doc__ or _('No help text available')).splitlines(0) | |
566 | ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0])) |
|
566 | ui.write(_('%s extension - %s\n') % (name.split('.')[-1], doc[0])) | |
567 | for d in doc[1:]: |
|
567 | for d in doc[1:]: | |
568 | ui.write(d, '\n') |
|
568 | ui.write(d, '\n') | |
569 |
|
569 | |||
570 | ui.status('\n') |
|
570 | ui.status('\n') | |
571 | if ui.verbose: |
|
571 | if ui.verbose: | |
572 | ui.status(_('list of commands:\n\n')) |
|
572 | ui.status(_('list of commands:\n\n')) | |
573 | else: |
|
573 | else: | |
574 | ui.status(_('list of commands (use "hg help -v %s" ' |
|
574 | ui.status(_('list of commands (use "hg help -v %s" ' | |
575 | 'to show aliases and global options):\n\n') % name) |
|
575 | 'to show aliases and global options):\n\n') % name) | |
576 |
|
576 | |||
577 | modcmds = dict.fromkeys([c.split('|', 1)[0] for c in mod.cmdtable]) |
|
577 | modcmds = dict.fromkeys([c.split('|', 1)[0] for c in mod.cmdtable]) | |
578 | helplist(modcmds.has_key) |
|
578 | helplist(modcmds.has_key) | |
579 |
|
579 | |||
580 | if name and name != 'shortlist': |
|
580 | if name and name != 'shortlist': | |
581 | try: |
|
581 | try: | |
582 | helpcmd(name) |
|
582 | helpcmd(name) | |
583 | except UnknownCommand: |
|
583 | except UnknownCommand: | |
584 | helpext(name) |
|
584 | helpext(name) | |
585 |
|
585 | |||
586 | else: |
|
586 | else: | |
587 | # program name |
|
587 | # program name | |
588 | if ui.verbose or with_version: |
|
588 | if ui.verbose or with_version: | |
589 | show_version(ui) |
|
589 | show_version(ui) | |
590 | else: |
|
590 | else: | |
591 | ui.status(_("Mercurial Distributed SCM\n")) |
|
591 | ui.status(_("Mercurial Distributed SCM\n")) | |
592 | ui.status('\n') |
|
592 | ui.status('\n') | |
593 |
|
593 | |||
594 | # list of commands |
|
594 | # list of commands | |
595 | if name == "shortlist": |
|
595 | if name == "shortlist": | |
596 | ui.status(_('basic commands (use "hg help" ' |
|
596 | ui.status(_('basic commands (use "hg help" ' | |
597 | 'for the full list or option "-v" for details):\n\n')) |
|
597 | 'for the full list or option "-v" for details):\n\n')) | |
598 | elif ui.verbose: |
|
598 | elif ui.verbose: | |
599 | ui.status(_('list of commands:\n\n')) |
|
599 | ui.status(_('list of commands:\n\n')) | |
600 | else: |
|
600 | else: | |
601 | ui.status(_('list of commands (use "hg help -v" ' |
|
601 | ui.status(_('list of commands (use "hg help -v" ' | |
602 | 'to show aliases and global options):\n\n')) |
|
602 | 'to show aliases and global options):\n\n')) | |
603 |
|
603 | |||
604 | helplist() |
|
604 | helplist() | |
605 |
|
605 | |||
606 | # global options |
|
606 | # global options | |
607 | if ui.verbose: |
|
607 | if ui.verbose: | |
608 | option_lists.append(("global options", globalopts)) |
|
608 | option_lists.append(("global options", globalopts)) | |
609 |
|
609 | |||
610 | # list all option lists |
|
610 | # list all option lists | |
611 | opt_output = [] |
|
611 | opt_output = [] | |
612 | for title, options in option_lists: |
|
612 | for title, options in option_lists: | |
613 | opt_output.append(("\n%s:\n" % title, None)) |
|
613 | opt_output.append(("\n%s:\n" % title, None)) | |
614 | for shortopt, longopt, default, desc in options: |
|
614 | for shortopt, longopt, default, desc in options: | |
615 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
615 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | |
616 | longopt and " --%s" % longopt), |
|
616 | longopt and " --%s" % longopt), | |
617 | "%s%s" % (desc, |
|
617 | "%s%s" % (desc, | |
618 | default |
|
618 | default | |
619 | and _(" (default: %s)") % default |
|
619 | and _(" (default: %s)") % default | |
620 | or ""))) |
|
620 | or ""))) | |
621 |
|
621 | |||
622 | if opt_output: |
|
622 | if opt_output: | |
623 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
623 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) | |
624 | for first, second in opt_output: |
|
624 | for first, second in opt_output: | |
625 | if second: |
|
625 | if second: | |
626 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
626 | ui.write(" %-*s %s\n" % (opts_len, first, second)) | |
627 | else: |
|
627 | else: | |
628 | ui.write("%s\n" % first) |
|
628 | ui.write("%s\n" % first) | |
629 |
|
629 | |||
630 | # Commands start here, listed alphabetically |
|
630 | # Commands start here, listed alphabetically | |
631 |
|
631 | |||
632 | def add(ui, repo, *pats, **opts): |
|
632 | def add(ui, repo, *pats, **opts): | |
633 | """add the specified files on the next commit |
|
633 | """add the specified files on the next commit | |
634 |
|
634 | |||
635 | Schedule files to be version controlled and added to the repository. |
|
635 | Schedule files to be version controlled and added to the repository. | |
636 |
|
636 | |||
637 | The files will be added to the repository at the next commit. |
|
637 | The files will be added to the repository at the next commit. | |
638 |
|
638 | |||
639 | If no names are given, add all files in the repository. |
|
639 | If no names are given, add all files in the repository. | |
640 | """ |
|
640 | """ | |
641 |
|
641 | |||
642 | names = [] |
|
642 | names = [] | |
643 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): |
|
643 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | |
644 | if exact: |
|
644 | if exact: | |
645 | if ui.verbose: |
|
645 | if ui.verbose: | |
646 | ui.status(_('adding %s\n') % rel) |
|
646 | ui.status(_('adding %s\n') % rel) | |
647 | names.append(abs) |
|
647 | names.append(abs) | |
648 | elif repo.dirstate.state(abs) == '?': |
|
648 | elif repo.dirstate.state(abs) == '?': | |
649 | ui.status(_('adding %s\n') % rel) |
|
649 | ui.status(_('adding %s\n') % rel) | |
650 | names.append(abs) |
|
650 | names.append(abs) | |
651 | if not opts.get('dry_run'): |
|
651 | if not opts.get('dry_run'): | |
652 | repo.add(names) |
|
652 | repo.add(names) | |
653 |
|
653 | |||
654 | def addremove(ui, repo, *pats, **opts): |
|
654 | def addremove(ui, repo, *pats, **opts): | |
655 | """add all new files, delete all missing files (DEPRECATED) |
|
655 | """add all new files, delete all missing files (DEPRECATED) | |
656 |
|
656 | |||
657 | (DEPRECATED) |
|
657 | (DEPRECATED) | |
658 | Add all new files and remove all missing files from the repository. |
|
658 | Add all new files and remove all missing files from the repository. | |
659 |
|
659 | |||
660 | New files are ignored if they match any of the patterns in .hgignore. As |
|
660 | New files are ignored if they match any of the patterns in .hgignore. As | |
661 | with add, these changes take effect at the next commit. |
|
661 | with add, these changes take effect at the next commit. | |
662 |
|
662 | |||
663 | This command is now deprecated and will be removed in a future |
|
663 | This command is now deprecated and will be removed in a future | |
664 | release. Please use add and remove --after instead. |
|
664 | release. Please use add and remove --after instead. | |
665 | """ |
|
665 | """ | |
666 | ui.warn(_('(the addremove command is deprecated; use add and remove ' |
|
666 | ui.warn(_('(the addremove command is deprecated; use add and remove ' | |
667 | '--after instead)\n')) |
|
667 | '--after instead)\n')) | |
668 | return cmdutil.addremove(repo, pats, opts) |
|
668 | return cmdutil.addremove(repo, pats, opts) | |
669 |
|
669 | |||
670 | def annotate(ui, repo, *pats, **opts): |
|
670 | def annotate(ui, repo, *pats, **opts): | |
671 | """show changeset information per file line |
|
671 | """show changeset information per file line | |
672 |
|
672 | |||
673 | List changes in files, showing the revision id responsible for each line |
|
673 | List changes in files, showing the revision id responsible for each line | |
674 |
|
674 | |||
675 | This command is useful to discover who did a change or when a change took |
|
675 | This command is useful to discover who did a change or when a change took | |
676 | place. |
|
676 | place. | |
677 |
|
677 | |||
678 | Without the -a option, annotate will avoid processing files it |
|
678 | Without the -a option, annotate will avoid processing files it | |
679 | detects as binary. With -a, annotate will generate an annotation |
|
679 | detects as binary. With -a, annotate will generate an annotation | |
680 | anyway, probably with undesirable results. |
|
680 | anyway, probably with undesirable results. | |
681 | """ |
|
681 | """ | |
682 | def getnode(rev): |
|
682 | def getnode(rev): | |
683 | return short(repo.changelog.node(rev)) |
|
683 | return short(repo.changelog.node(rev)) | |
684 |
|
684 | |||
685 | ucache = {} |
|
685 | ucache = {} | |
686 | def getname(rev): |
|
686 | def getname(rev): | |
687 | try: |
|
687 | try: | |
688 | return ucache[rev] |
|
688 | return ucache[rev] | |
689 | except: |
|
689 | except: | |
690 | u = trimuser(ui, repo.changectx(rev).user(), rev, ucache) |
|
690 | u = trimuser(ui, repo.changectx(rev).user(), rev, ucache) | |
691 | ucache[rev] = u |
|
691 | ucache[rev] = u | |
692 | return u |
|
692 | return u | |
693 |
|
693 | |||
694 | dcache = {} |
|
694 | dcache = {} | |
695 | def getdate(rev): |
|
695 | def getdate(rev): | |
696 | datestr = dcache.get(rev) |
|
696 | datestr = dcache.get(rev) | |
697 | if datestr is None: |
|
697 | if datestr is None: | |
698 | datestr = dcache[rev] = util.datestr(repo.changectx(rev).date()) |
|
698 | datestr = dcache[rev] = util.datestr(repo.changectx(rev).date()) | |
699 | return datestr |
|
699 | return datestr | |
700 |
|
700 | |||
701 | if not pats: |
|
701 | if not pats: | |
702 | raise util.Abort(_('at least one file name or pattern required')) |
|
702 | raise util.Abort(_('at least one file name or pattern required')) | |
703 |
|
703 | |||
704 | opmap = [['user', getname], ['number', str], ['changeset', getnode], |
|
704 | opmap = [['user', getname], ['number', str], ['changeset', getnode], | |
705 | ['date', getdate]] |
|
705 | ['date', getdate]] | |
706 | if not opts['user'] and not opts['changeset'] and not opts['date']: |
|
706 | if not opts['user'] and not opts['changeset'] and not opts['date']: | |
707 | opts['number'] = 1 |
|
707 | opts['number'] = 1 | |
708 |
|
708 | |||
709 | ctx = repo.changectx(opts['rev'] or repo.dirstate.parents()[0]) |
|
709 | ctx = repo.changectx(opts['rev'] or repo.dirstate.parents()[0]) | |
710 |
|
710 | |||
711 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, |
|
711 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | |
712 | node=ctx.node()): |
|
712 | node=ctx.node()): | |
713 | fctx = ctx.filectx(abs) |
|
713 | fctx = ctx.filectx(abs) | |
714 | if not opts['text'] and util.binary(fctx.data()): |
|
714 | if not opts['text'] and util.binary(fctx.data()): | |
715 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
715 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | |
716 | continue |
|
716 | continue | |
717 |
|
717 | |||
718 | lines = fctx.annotate() |
|
718 | lines = fctx.annotate() | |
719 | pieces = [] |
|
719 | pieces = [] | |
720 |
|
720 | |||
721 | for o, f in opmap: |
|
721 | for o, f in opmap: | |
722 | if opts[o]: |
|
722 | if opts[o]: | |
723 | l = [f(n) for n, dummy in lines] |
|
723 | l = [f(n) for n, dummy in lines] | |
724 | if l: |
|
724 | if l: | |
725 | m = max(map(len, l)) |
|
725 | m = max(map(len, l)) | |
726 | pieces.append(["%*s" % (m, x) for x in l]) |
|
726 | pieces.append(["%*s" % (m, x) for x in l]) | |
727 |
|
727 | |||
728 | if pieces: |
|
728 | if pieces: | |
729 | for p, l in zip(zip(*pieces), lines): |
|
729 | for p, l in zip(zip(*pieces), lines): | |
730 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
730 | ui.write("%s: %s" % (" ".join(p), l[1])) | |
731 |
|
731 | |||
732 | def archive(ui, repo, dest, **opts): |
|
732 | def archive(ui, repo, dest, **opts): | |
733 | '''create unversioned archive of a repository revision |
|
733 | '''create unversioned archive of a repository revision | |
734 |
|
734 | |||
735 | By default, the revision used is the parent of the working |
|
735 | By default, the revision used is the parent of the working | |
736 | directory; use "-r" to specify a different revision. |
|
736 | directory; use "-r" to specify a different revision. | |
737 |
|
737 | |||
738 | To specify the type of archive to create, use "-t". Valid |
|
738 | To specify the type of archive to create, use "-t". Valid | |
739 | types are: |
|
739 | types are: | |
740 |
|
740 | |||
741 | "files" (default): a directory full of files |
|
741 | "files" (default): a directory full of files | |
742 | "tar": tar archive, uncompressed |
|
742 | "tar": tar archive, uncompressed | |
743 | "tbz2": tar archive, compressed using bzip2 |
|
743 | "tbz2": tar archive, compressed using bzip2 | |
744 | "tgz": tar archive, compressed using gzip |
|
744 | "tgz": tar archive, compressed using gzip | |
745 | "uzip": zip archive, uncompressed |
|
745 | "uzip": zip archive, uncompressed | |
746 | "zip": zip archive, compressed using deflate |
|
746 | "zip": zip archive, compressed using deflate | |
747 |
|
747 | |||
748 | The exact name of the destination archive or directory is given |
|
748 | The exact name of the destination archive or directory is given | |
749 | using a format string; see "hg help export" for details. |
|
749 | using a format string; see "hg help export" for details. | |
750 |
|
750 | |||
751 | Each member added to an archive file has a directory prefix |
|
751 | Each member added to an archive file has a directory prefix | |
752 | prepended. Use "-p" to specify a format string for the prefix. |
|
752 | prepended. Use "-p" to specify a format string for the prefix. | |
753 | The default is the basename of the archive, with suffixes removed. |
|
753 | The default is the basename of the archive, with suffixes removed. | |
754 | ''' |
|
754 | ''' | |
755 |
|
755 | |||
756 | if opts['rev']: |
|
756 | if opts['rev']: | |
757 | node = repo.lookup(opts['rev']) |
|
757 | node = repo.lookup(opts['rev']) | |
758 | else: |
|
758 | else: | |
759 | node, p2 = repo.dirstate.parents() |
|
759 | node, p2 = repo.dirstate.parents() | |
760 | if p2 != nullid: |
|
760 | if p2 != nullid: | |
761 | raise util.Abort(_('uncommitted merge - please provide a ' |
|
761 | raise util.Abort(_('uncommitted merge - please provide a ' | |
762 | 'specific revision')) |
|
762 | 'specific revision')) | |
763 |
|
763 | |||
764 | dest = cmdutil.make_filename(repo, dest, node) |
|
764 | dest = cmdutil.make_filename(repo, dest, node) | |
765 | if os.path.realpath(dest) == repo.root: |
|
765 | if os.path.realpath(dest) == repo.root: | |
766 | raise util.Abort(_('repository root cannot be destination')) |
|
766 | raise util.Abort(_('repository root cannot be destination')) | |
767 | dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts) |
|
767 | dummy, matchfn, dummy = cmdutil.matchpats(repo, [], opts) | |
768 | kind = opts.get('type') or 'files' |
|
768 | kind = opts.get('type') or 'files' | |
769 | prefix = opts['prefix'] |
|
769 | prefix = opts['prefix'] | |
770 | if dest == '-': |
|
770 | if dest == '-': | |
771 | if kind == 'files': |
|
771 | if kind == 'files': | |
772 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
772 | raise util.Abort(_('cannot archive plain files to stdout')) | |
773 | dest = sys.stdout |
|
773 | dest = sys.stdout | |
774 | if not prefix: prefix = os.path.basename(repo.root) + '-%h' |
|
774 | if not prefix: prefix = os.path.basename(repo.root) + '-%h' | |
775 | prefix = cmdutil.make_filename(repo, prefix, node) |
|
775 | prefix = cmdutil.make_filename(repo, prefix, node) | |
776 | archival.archive(repo, dest, node, kind, not opts['no_decode'], |
|
776 | archival.archive(repo, dest, node, kind, not opts['no_decode'], | |
777 | matchfn, prefix) |
|
777 | matchfn, prefix) | |
778 |
|
778 | |||
779 | def backout(ui, repo, rev, **opts): |
|
779 | def backout(ui, repo, rev, **opts): | |
780 | '''reverse effect of earlier changeset |
|
780 | '''reverse effect of earlier changeset | |
781 |
|
781 | |||
782 | Commit the backed out changes as a new changeset. The new |
|
782 | Commit the backed out changes as a new changeset. The new | |
783 | changeset is a child of the backed out changeset. |
|
783 | changeset is a child of the backed out changeset. | |
784 |
|
784 | |||
785 | If you back out a changeset other than the tip, a new head is |
|
785 | If you back out a changeset other than the tip, a new head is | |
786 | created. This head is the parent of the working directory. If |
|
786 | created. This head is the parent of the working directory. If | |
787 | you back out an old changeset, your working directory will appear |
|
787 | you back out an old changeset, your working directory will appear | |
788 | old after the backout. You should merge the backout changeset |
|
788 | old after the backout. You should merge the backout changeset | |
789 | with another head. |
|
789 | with another head. | |
790 |
|
790 | |||
791 | The --merge option remembers the parent of the working directory |
|
791 | The --merge option remembers the parent of the working directory | |
792 | before starting the backout, then merges the new head with that |
|
792 | before starting the backout, then merges the new head with that | |
793 | changeset afterwards. This saves you from doing the merge by |
|
793 | changeset afterwards. This saves you from doing the merge by | |
794 | hand. The result of this merge is not committed, as for a normal |
|
794 | hand. The result of this merge is not committed, as for a normal | |
795 | merge.''' |
|
795 | merge.''' | |
796 |
|
796 | |||
797 | bail_if_changed(repo) |
|
797 | bail_if_changed(repo) | |
798 | op1, op2 = repo.dirstate.parents() |
|
798 | op1, op2 = repo.dirstate.parents() | |
799 | if op2 != nullid: |
|
799 | if op2 != nullid: | |
800 | raise util.Abort(_('outstanding uncommitted merge')) |
|
800 | raise util.Abort(_('outstanding uncommitted merge')) | |
801 | node = repo.lookup(rev) |
|
801 | node = repo.lookup(rev) | |
802 | p1, p2 = repo.changelog.parents(node) |
|
802 | p1, p2 = repo.changelog.parents(node) | |
803 | if p1 == nullid: |
|
803 | if p1 == nullid: | |
804 | raise util.Abort(_('cannot back out a change with no parents')) |
|
804 | raise util.Abort(_('cannot back out a change with no parents')) | |
805 | if p2 != nullid: |
|
805 | if p2 != nullid: | |
806 | if not opts['parent']: |
|
806 | if not opts['parent']: | |
807 | raise util.Abort(_('cannot back out a merge changeset without ' |
|
807 | raise util.Abort(_('cannot back out a merge changeset without ' | |
808 | '--parent')) |
|
808 | '--parent')) | |
809 | p = repo.lookup(opts['parent']) |
|
809 | p = repo.lookup(opts['parent']) | |
810 | if p not in (p1, p2): |
|
810 | if p not in (p1, p2): | |
811 | raise util.Abort(_('%s is not a parent of %s' % |
|
811 | raise util.Abort(_('%s is not a parent of %s' % | |
812 | (short(p), short(node)))) |
|
812 | (short(p), short(node)))) | |
813 | parent = p |
|
813 | parent = p | |
814 | else: |
|
814 | else: | |
815 | if opts['parent']: |
|
815 | if opts['parent']: | |
816 | raise util.Abort(_('cannot use --parent on non-merge changeset')) |
|
816 | raise util.Abort(_('cannot use --parent on non-merge changeset')) | |
817 | parent = p1 |
|
817 | parent = p1 | |
818 | hg.clean(repo, node, show_stats=False) |
|
818 | hg.clean(repo, node, show_stats=False) | |
819 | revert_opts = opts.copy() |
|
819 | revert_opts = opts.copy() | |
820 | revert_opts['rev'] = hex(parent) |
|
820 | revert_opts['rev'] = hex(parent) | |
821 | revert(ui, repo, **revert_opts) |
|
821 | revert(ui, repo, **revert_opts) | |
822 | commit_opts = opts.copy() |
|
822 | commit_opts = opts.copy() | |
823 | commit_opts['addremove'] = False |
|
823 | commit_opts['addremove'] = False | |
824 | if not commit_opts['message'] and not commit_opts['logfile']: |
|
824 | if not commit_opts['message'] and not commit_opts['logfile']: | |
825 | commit_opts['message'] = _("Backed out changeset %s") % (hex(node)) |
|
825 | commit_opts['message'] = _("Backed out changeset %s") % (hex(node)) | |
826 | commit_opts['force_editor'] = True |
|
826 | commit_opts['force_editor'] = True | |
827 | commit(ui, repo, **commit_opts) |
|
827 | commit(ui, repo, **commit_opts) | |
828 | def nice(node): |
|
828 | def nice(node): | |
829 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
829 | return '%d:%s' % (repo.changelog.rev(node), short(node)) | |
830 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
830 | ui.status(_('changeset %s backs out changeset %s\n') % | |
831 | (nice(repo.changelog.tip()), nice(node))) |
|
831 | (nice(repo.changelog.tip()), nice(node))) | |
832 | if op1 != node: |
|
832 | if op1 != node: | |
833 | if opts['merge']: |
|
833 | if opts['merge']: | |
834 | ui.status(_('merging with changeset %s\n') % nice(op1)) |
|
834 | ui.status(_('merging with changeset %s\n') % nice(op1)) | |
835 | n = _lookup(repo, hex(op1)) |
|
835 | n = _lookup(repo, hex(op1)) | |
836 | hg.merge(repo, n) |
|
836 | hg.merge(repo, n) | |
837 | else: |
|
837 | else: | |
838 | ui.status(_('the backout changeset is a new head - ' |
|
838 | ui.status(_('the backout changeset is a new head - ' | |
839 | 'do not forget to merge\n')) |
|
839 | 'do not forget to merge\n')) | |
840 | ui.status(_('(use "backout --merge" ' |
|
840 | ui.status(_('(use "backout --merge" ' | |
841 | 'if you want to auto-merge)\n')) |
|
841 | 'if you want to auto-merge)\n')) | |
842 |
|
842 | |||
843 | def bundle(ui, repo, fname, dest=None, **opts): |
|
843 | def bundle(ui, repo, fname, dest=None, **opts): | |
844 | """create a changegroup file |
|
844 | """create a changegroup file | |
845 |
|
845 | |||
846 | Generate a compressed changegroup file collecting all changesets |
|
846 | Generate a compressed changegroup file collecting all changesets | |
847 | not found in the other repository. |
|
847 | not found in the other repository. | |
848 |
|
848 | |||
849 | This file can then be transferred using conventional means and |
|
849 | This file can then be transferred using conventional means and | |
850 | applied to another repository with the unbundle command. This is |
|
850 | applied to another repository with the unbundle command. This is | |
851 | useful when native push and pull are not available or when |
|
851 | useful when native push and pull are not available or when | |
852 | exporting an entire repository is undesirable. The standard file |
|
852 | exporting an entire repository is undesirable. The standard file | |
853 | extension is ".hg". |
|
853 | extension is ".hg". | |
854 |
|
854 | |||
855 | Unlike import/export, this exactly preserves all changeset |
|
855 | Unlike import/export, this exactly preserves all changeset | |
856 | contents including permissions, rename data, and revision history. |
|
856 | contents including permissions, rename data, and revision history. | |
857 | """ |
|
857 | """ | |
858 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
858 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
859 | other = hg.repository(ui, dest) |
|
859 | other = hg.repository(ui, dest) | |
860 | o = repo.findoutgoing(other, force=opts['force']) |
|
860 | o = repo.findoutgoing(other, force=opts['force']) | |
861 | cg = repo.changegroup(o, 'bundle') |
|
861 | cg = repo.changegroup(o, 'bundle') | |
862 | write_bundle(cg, fname) |
|
862 | write_bundle(cg, fname) | |
863 |
|
863 | |||
864 | def cat(ui, repo, file1, *pats, **opts): |
|
864 | def cat(ui, repo, file1, *pats, **opts): | |
865 | """output the latest or given revisions of files |
|
865 | """output the latest or given revisions of files | |
866 |
|
866 | |||
867 | Print the specified files as they were at the given revision. |
|
867 | Print the specified files as they were at the given revision. | |
868 | If no revision is given then the tip is used. |
|
868 | If no revision is given then the tip is used. | |
869 |
|
869 | |||
870 | Output may be to a file, in which case the name of the file is |
|
870 | Output may be to a file, in which case the name of the file is | |
871 | given using a format string. The formatting rules are the same as |
|
871 | given using a format string. The formatting rules are the same as | |
872 | for the export command, with the following additions: |
|
872 | for the export command, with the following additions: | |
873 |
|
873 | |||
874 | %s basename of file being printed |
|
874 | %s basename of file being printed | |
875 | %d dirname of file being printed, or '.' if in repo root |
|
875 | %d dirname of file being printed, or '.' if in repo root | |
876 | %p root-relative path name of file being printed |
|
876 | %p root-relative path name of file being printed | |
877 | """ |
|
877 | """ | |
878 | ctx = repo.changectx(opts['rev'] or "-1") |
|
878 | ctx = repo.changectx(opts['rev'] or "-1") | |
879 | for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, |
|
879 | for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, | |
880 | ctx.node()): |
|
880 | ctx.node()): | |
881 | fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) |
|
881 | fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) | |
882 | fp.write(ctx.filectx(abs).data()) |
|
882 | fp.write(ctx.filectx(abs).data()) | |
883 |
|
883 | |||
884 | def clone(ui, source, dest=None, **opts): |
|
884 | def clone(ui, source, dest=None, **opts): | |
885 | """make a copy of an existing repository |
|
885 | """make a copy of an existing repository | |
886 |
|
886 | |||
887 | Create a copy of an existing repository in a new directory. |
|
887 | Create a copy of an existing repository in a new directory. | |
888 |
|
888 | |||
889 | If no destination directory name is specified, it defaults to the |
|
889 | If no destination directory name is specified, it defaults to the | |
890 | basename of the source. |
|
890 | basename of the source. | |
891 |
|
891 | |||
892 | The location of the source is added to the new repository's |
|
892 | The location of the source is added to the new repository's | |
893 | .hg/hgrc file, as the default to be used for future pulls. |
|
893 | .hg/hgrc file, as the default to be used for future pulls. | |
894 |
|
894 | |||
895 | For efficiency, hardlinks are used for cloning whenever the source |
|
895 | For efficiency, hardlinks are used for cloning whenever the source | |
896 | and destination are on the same filesystem (note this applies only |
|
896 | and destination are on the same filesystem (note this applies only | |
897 | to the repository data, not to the checked out files). Some |
|
897 | to the repository data, not to the checked out files). Some | |
898 | filesystems, such as AFS, implement hardlinking incorrectly, but |
|
898 | filesystems, such as AFS, implement hardlinking incorrectly, but | |
899 | do not report errors. In these cases, use the --pull option to |
|
899 | do not report errors. In these cases, use the --pull option to | |
900 | avoid hardlinking. |
|
900 | avoid hardlinking. | |
901 |
|
901 | |||
902 | You can safely clone repositories and checked out files using full |
|
902 | You can safely clone repositories and checked out files using full | |
903 | hardlinks with |
|
903 | hardlinks with | |
904 |
|
904 | |||
905 | $ cp -al REPO REPOCLONE |
|
905 | $ cp -al REPO REPOCLONE | |
906 |
|
906 | |||
907 | which is the fastest way to clone. However, the operation is not |
|
907 | which is the fastest way to clone. However, the operation is not | |
908 | atomic (making sure REPO is not modified during the operation is |
|
908 | atomic (making sure REPO is not modified during the operation is | |
909 | up to you) and you have to make sure your editor breaks hardlinks |
|
909 | up to you) and you have to make sure your editor breaks hardlinks | |
910 | (Emacs and most Linux Kernel tools do so). |
|
910 | (Emacs and most Linux Kernel tools do so). | |
911 |
|
911 | |||
912 | If you use the -r option to clone up to a specific revision, no |
|
912 | If you use the -r option to clone up to a specific revision, no | |
913 | subsequent revisions will be present in the cloned repository. |
|
913 | subsequent revisions will be present in the cloned repository. | |
914 | This option implies --pull, even on local repositories. |
|
914 | This option implies --pull, even on local repositories. | |
915 |
|
915 | |||
916 | See pull for valid source format details. |
|
916 | See pull for valid source format details. | |
917 |
|
917 | |||
918 | It is possible to specify an ssh:// URL as the destination, but no |
|
918 | It is possible to specify an ssh:// URL as the destination, but no | |
919 | .hg/hgrc will be created on the remote side. Look at the help text |
|
919 | .hg/hgrc will be created on the remote side. Look at the help text | |
920 | for the pull command for important details about ssh:// URLs. |
|
920 | for the pull command for important details about ssh:// URLs. | |
921 | """ |
|
921 | """ | |
922 | setremoteconfig(ui, opts) |
|
922 | setremoteconfig(ui, opts) | |
923 | hg.clone(ui, ui.expandpath(source), dest, |
|
923 | hg.clone(ui, ui.expandpath(source), dest, | |
924 | pull=opts['pull'], |
|
924 | pull=opts['pull'], | |
925 | stream=opts['uncompressed'], |
|
925 | stream=opts['uncompressed'], | |
926 | rev=opts['rev'], |
|
926 | rev=opts['rev'], | |
927 | update=not opts['noupdate']) |
|
927 | update=not opts['noupdate']) | |
928 |
|
928 | |||
929 | def commit(ui, repo, *pats, **opts): |
|
929 | def commit(ui, repo, *pats, **opts): | |
930 | """commit the specified files or all outstanding changes |
|
930 | """commit the specified files or all outstanding changes | |
931 |
|
931 | |||
932 | Commit changes to the given files into the repository. |
|
932 | Commit changes to the given files into the repository. | |
933 |
|
933 | |||
934 | If a list of files is omitted, all changes reported by "hg status" |
|
934 | If a list of files is omitted, all changes reported by "hg status" | |
935 | will be committed. |
|
935 | will be committed. | |
936 |
|
936 | |||
937 | If no commit message is specified, the editor configured in your hgrc |
|
937 | If no commit message is specified, the editor configured in your hgrc | |
938 | or in the EDITOR environment variable is started to enter a message. |
|
938 | or in the EDITOR environment variable is started to enter a message. | |
939 | """ |
|
939 | """ | |
940 | message = logmessage(opts) |
|
940 | message = logmessage(opts) | |
941 |
|
941 | |||
942 | if opts['addremove']: |
|
942 | if opts['addremove']: | |
943 | cmdutil.addremove(repo, pats, opts) |
|
943 | cmdutil.addremove(repo, pats, opts) | |
944 | fns, match, anypats = cmdutil.matchpats(repo, pats, opts) |
|
944 | fns, match, anypats = cmdutil.matchpats(repo, pats, opts) | |
945 | if pats: |
|
945 | if pats: | |
946 | modified, added, removed = repo.status(files=fns, match=match)[:3] |
|
946 | modified, added, removed = repo.status(files=fns, match=match)[:3] | |
947 | files = modified + added + removed |
|
947 | files = modified + added + removed | |
948 | else: |
|
948 | else: | |
949 | files = [] |
|
949 | files = [] | |
950 | try: |
|
950 | try: | |
951 | repo.commit(files, message, opts['user'], opts['date'], match, |
|
951 | repo.commit(files, message, opts['user'], opts['date'], match, | |
952 | force_editor=opts.get('force_editor')) |
|
952 | force_editor=opts.get('force_editor')) | |
953 | except ValueError, inst: |
|
953 | except ValueError, inst: | |
954 | raise util.Abort(str(inst)) |
|
954 | raise util.Abort(str(inst)) | |
955 |
|
955 | |||
956 | def docopy(ui, repo, pats, opts, wlock): |
|
956 | def docopy(ui, repo, pats, opts, wlock): | |
957 | # called with the repo lock held |
|
957 | # called with the repo lock held | |
958 | cwd = repo.getcwd() |
|
958 | cwd = repo.getcwd() | |
959 | errors = 0 |
|
959 | errors = 0 | |
960 | copied = [] |
|
960 | copied = [] | |
961 | targets = {} |
|
961 | targets = {} | |
962 |
|
962 | |||
963 | def okaytocopy(abs, rel, exact): |
|
963 | def okaytocopy(abs, rel, exact): | |
964 | reasons = {'?': _('is not managed'), |
|
964 | reasons = {'?': _('is not managed'), | |
965 | 'a': _('has been marked for add'), |
|
965 | 'a': _('has been marked for add'), | |
966 | 'r': _('has been marked for remove')} |
|
966 | 'r': _('has been marked for remove')} | |
967 | state = repo.dirstate.state(abs) |
|
967 | state = repo.dirstate.state(abs) | |
968 | reason = reasons.get(state) |
|
968 | reason = reasons.get(state) | |
969 | if reason: |
|
969 | if reason: | |
970 | if state == 'a': |
|
970 | if state == 'a': | |
971 | origsrc = repo.dirstate.copied(abs) |
|
971 | origsrc = repo.dirstate.copied(abs) | |
972 | if origsrc is not None: |
|
972 | if origsrc is not None: | |
973 | return origsrc |
|
973 | return origsrc | |
974 | if exact: |
|
974 | if exact: | |
975 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
975 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | |
976 | else: |
|
976 | else: | |
977 | return abs |
|
977 | return abs | |
978 |
|
978 | |||
979 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
979 | def copy(origsrc, abssrc, relsrc, target, exact): | |
980 | abstarget = util.canonpath(repo.root, cwd, target) |
|
980 | abstarget = util.canonpath(repo.root, cwd, target) | |
981 | reltarget = util.pathto(cwd, abstarget) |
|
981 | reltarget = util.pathto(cwd, abstarget) | |
982 | prevsrc = targets.get(abstarget) |
|
982 | prevsrc = targets.get(abstarget) | |
983 | if prevsrc is not None: |
|
983 | if prevsrc is not None: | |
984 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
984 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
985 | (reltarget, abssrc, prevsrc)) |
|
985 | (reltarget, abssrc, prevsrc)) | |
986 | return |
|
986 | return | |
987 | if (not opts['after'] and os.path.exists(reltarget) or |
|
987 | if (not opts['after'] and os.path.exists(reltarget) or | |
988 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
988 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | |
989 | if not opts['force']: |
|
989 | if not opts['force']: | |
990 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
990 | ui.warn(_('%s: not overwriting - file exists\n') % | |
991 | reltarget) |
|
991 | reltarget) | |
992 | return |
|
992 | return | |
993 | if not opts['after'] and not opts.get('dry_run'): |
|
993 | if not opts['after'] and not opts.get('dry_run'): | |
994 | os.unlink(reltarget) |
|
994 | os.unlink(reltarget) | |
995 | if opts['after']: |
|
995 | if opts['after']: | |
996 | if not os.path.exists(reltarget): |
|
996 | if not os.path.exists(reltarget): | |
997 | return |
|
997 | return | |
998 | else: |
|
998 | else: | |
999 | targetdir = os.path.dirname(reltarget) or '.' |
|
999 | targetdir = os.path.dirname(reltarget) or '.' | |
1000 | if not os.path.isdir(targetdir) and not opts.get('dry_run'): |
|
1000 | if not os.path.isdir(targetdir) and not opts.get('dry_run'): | |
1001 | os.makedirs(targetdir) |
|
1001 | os.makedirs(targetdir) | |
1002 | try: |
|
1002 | try: | |
1003 | restore = repo.dirstate.state(abstarget) == 'r' |
|
1003 | restore = repo.dirstate.state(abstarget) == 'r' | |
1004 | if restore and not opts.get('dry_run'): |
|
1004 | if restore and not opts.get('dry_run'): | |
1005 | repo.undelete([abstarget], wlock) |
|
1005 | repo.undelete([abstarget], wlock) | |
1006 | try: |
|
1006 | try: | |
1007 | if not opts.get('dry_run'): |
|
1007 | if not opts.get('dry_run'): | |
1008 | shutil.copyfile(relsrc, reltarget) |
|
1008 | shutil.copyfile(relsrc, reltarget) | |
1009 | shutil.copymode(relsrc, reltarget) |
|
1009 | shutil.copymode(relsrc, reltarget) | |
1010 | restore = False |
|
1010 | restore = False | |
1011 | finally: |
|
1011 | finally: | |
1012 | if restore: |
|
1012 | if restore: | |
1013 | repo.remove([abstarget], wlock) |
|
1013 | repo.remove([abstarget], wlock) | |
1014 | except shutil.Error, inst: |
|
1014 | except shutil.Error, inst: | |
1015 | raise util.Abort(str(inst)) |
|
1015 | raise util.Abort(str(inst)) | |
1016 | except IOError, inst: |
|
1016 | except IOError, inst: | |
1017 | if inst.errno == errno.ENOENT: |
|
1017 | if inst.errno == errno.ENOENT: | |
1018 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
1018 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
1019 | else: |
|
1019 | else: | |
1020 | ui.warn(_('%s: cannot copy - %s\n') % |
|
1020 | ui.warn(_('%s: cannot copy - %s\n') % | |
1021 | (relsrc, inst.strerror)) |
|
1021 | (relsrc, inst.strerror)) | |
1022 | errors += 1 |
|
1022 | errors += 1 | |
1023 | return |
|
1023 | return | |
1024 | if ui.verbose or not exact: |
|
1024 | if ui.verbose or not exact: | |
1025 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
1025 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
1026 | targets[abstarget] = abssrc |
|
1026 | targets[abstarget] = abssrc | |
1027 | if abstarget != origsrc and not opts.get('dry_run'): |
|
1027 | if abstarget != origsrc and not opts.get('dry_run'): | |
1028 | repo.copy(origsrc, abstarget, wlock) |
|
1028 | repo.copy(origsrc, abstarget, wlock) | |
1029 | copied.append((abssrc, relsrc, exact)) |
|
1029 | copied.append((abssrc, relsrc, exact)) | |
1030 |
|
1030 | |||
1031 | def targetpathfn(pat, dest, srcs): |
|
1031 | def targetpathfn(pat, dest, srcs): | |
1032 | if os.path.isdir(pat): |
|
1032 | if os.path.isdir(pat): | |
1033 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1033 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1034 | if destdirexists: |
|
1034 | if destdirexists: | |
1035 | striplen = len(os.path.split(abspfx)[0]) |
|
1035 | striplen = len(os.path.split(abspfx)[0]) | |
1036 | else: |
|
1036 | else: | |
1037 | striplen = len(abspfx) |
|
1037 | striplen = len(abspfx) | |
1038 | if striplen: |
|
1038 | if striplen: | |
1039 | striplen += len(os.sep) |
|
1039 | striplen += len(os.sep) | |
1040 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1040 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1041 | elif destdirexists: |
|
1041 | elif destdirexists: | |
1042 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1042 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1043 | else: |
|
1043 | else: | |
1044 | res = lambda p: dest |
|
1044 | res = lambda p: dest | |
1045 | return res |
|
1045 | return res | |
1046 |
|
1046 | |||
1047 | def targetpathafterfn(pat, dest, srcs): |
|
1047 | def targetpathafterfn(pat, dest, srcs): | |
1048 | if util.patkind(pat, None)[0]: |
|
1048 | if util.patkind(pat, None)[0]: | |
1049 | # a mercurial pattern |
|
1049 | # a mercurial pattern | |
1050 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1050 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1051 | else: |
|
1051 | else: | |
1052 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1052 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1053 | if len(abspfx) < len(srcs[0][0]): |
|
1053 | if len(abspfx) < len(srcs[0][0]): | |
1054 | # A directory. Either the target path contains the last |
|
1054 | # A directory. Either the target path contains the last | |
1055 | # component of the source path or it does not. |
|
1055 | # component of the source path or it does not. | |
1056 | def evalpath(striplen): |
|
1056 | def evalpath(striplen): | |
1057 | score = 0 |
|
1057 | score = 0 | |
1058 | for s in srcs: |
|
1058 | for s in srcs: | |
1059 | t = os.path.join(dest, s[0][striplen:]) |
|
1059 | t = os.path.join(dest, s[0][striplen:]) | |
1060 | if os.path.exists(t): |
|
1060 | if os.path.exists(t): | |
1061 | score += 1 |
|
1061 | score += 1 | |
1062 | return score |
|
1062 | return score | |
1063 |
|
1063 | |||
1064 | striplen = len(abspfx) |
|
1064 | striplen = len(abspfx) | |
1065 | if striplen: |
|
1065 | if striplen: | |
1066 | striplen += len(os.sep) |
|
1066 | striplen += len(os.sep) | |
1067 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
1067 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
1068 | score = evalpath(striplen) |
|
1068 | score = evalpath(striplen) | |
1069 | striplen1 = len(os.path.split(abspfx)[0]) |
|
1069 | striplen1 = len(os.path.split(abspfx)[0]) | |
1070 | if striplen1: |
|
1070 | if striplen1: | |
1071 | striplen1 += len(os.sep) |
|
1071 | striplen1 += len(os.sep) | |
1072 | if evalpath(striplen1) > score: |
|
1072 | if evalpath(striplen1) > score: | |
1073 | striplen = striplen1 |
|
1073 | striplen = striplen1 | |
1074 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1074 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1075 | else: |
|
1075 | else: | |
1076 | # a file |
|
1076 | # a file | |
1077 | if destdirexists: |
|
1077 | if destdirexists: | |
1078 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1078 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1079 | else: |
|
1079 | else: | |
1080 | res = lambda p: dest |
|
1080 | res = lambda p: dest | |
1081 | return res |
|
1081 | return res | |
1082 |
|
1082 | |||
1083 |
|
1083 | |||
1084 | pats = list(pats) |
|
1084 | pats = list(pats) | |
1085 | if not pats: |
|
1085 | if not pats: | |
1086 | raise util.Abort(_('no source or destination specified')) |
|
1086 | raise util.Abort(_('no source or destination specified')) | |
1087 | if len(pats) == 1: |
|
1087 | if len(pats) == 1: | |
1088 | raise util.Abort(_('no destination specified')) |
|
1088 | raise util.Abort(_('no destination specified')) | |
1089 | dest = pats.pop() |
|
1089 | dest = pats.pop() | |
1090 | destdirexists = os.path.isdir(dest) |
|
1090 | destdirexists = os.path.isdir(dest) | |
1091 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
1091 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | |
1092 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
1092 | raise util.Abort(_('with multiple sources, destination must be an ' | |
1093 | 'existing directory')) |
|
1093 | 'existing directory')) | |
1094 | if opts['after']: |
|
1094 | if opts['after']: | |
1095 | tfn = targetpathafterfn |
|
1095 | tfn = targetpathafterfn | |
1096 | else: |
|
1096 | else: | |
1097 | tfn = targetpathfn |
|
1097 | tfn = targetpathfn | |
1098 | copylist = [] |
|
1098 | copylist = [] | |
1099 | for pat in pats: |
|
1099 | for pat in pats: | |
1100 | srcs = [] |
|
1100 | srcs = [] | |
1101 | for tag, abssrc, relsrc, exact in cmdutil.walk(repo, [pat], opts): |
|
1101 | for tag, abssrc, relsrc, exact in cmdutil.walk(repo, [pat], opts): | |
1102 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
1102 | origsrc = okaytocopy(abssrc, relsrc, exact) | |
1103 | if origsrc: |
|
1103 | if origsrc: | |
1104 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
1104 | srcs.append((origsrc, abssrc, relsrc, exact)) | |
1105 | if not srcs: |
|
1105 | if not srcs: | |
1106 | continue |
|
1106 | continue | |
1107 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
1107 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
1108 | if not copylist: |
|
1108 | if not copylist: | |
1109 | raise util.Abort(_('no files to copy')) |
|
1109 | raise util.Abort(_('no files to copy')) | |
1110 |
|
1110 | |||
1111 | for targetpath, srcs in copylist: |
|
1111 | for targetpath, srcs in copylist: | |
1112 | for origsrc, abssrc, relsrc, exact in srcs: |
|
1112 | for origsrc, abssrc, relsrc, exact in srcs: | |
1113 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
1113 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | |
1114 |
|
1114 | |||
1115 | if errors: |
|
1115 | if errors: | |
1116 | ui.warn(_('(consider using --after)\n')) |
|
1116 | ui.warn(_('(consider using --after)\n')) | |
1117 | return errors, copied |
|
1117 | return errors, copied | |
1118 |
|
1118 | |||
1119 | def copy(ui, repo, *pats, **opts): |
|
1119 | def copy(ui, repo, *pats, **opts): | |
1120 | """mark files as copied for the next commit |
|
1120 | """mark files as copied for the next commit | |
1121 |
|
1121 | |||
1122 | Mark dest as having copies of source files. If dest is a |
|
1122 | Mark dest as having copies of source files. If dest is a | |
1123 | directory, copies are put in that directory. If dest is a file, |
|
1123 | directory, copies are put in that directory. If dest is a file, | |
1124 | there can only be one source. |
|
1124 | there can only be one source. | |
1125 |
|
1125 | |||
1126 | By default, this command copies the contents of files as they |
|
1126 | By default, this command copies the contents of files as they | |
1127 | stand in the working directory. If invoked with --after, the |
|
1127 | stand in the working directory. If invoked with --after, the | |
1128 | operation is recorded, but no copying is performed. |
|
1128 | operation is recorded, but no copying is performed. | |
1129 |
|
1129 | |||
1130 | This command takes effect in the next commit. |
|
1130 | This command takes effect in the next commit. | |
1131 |
|
1131 | |||
1132 | NOTE: This command should be treated as experimental. While it |
|
1132 | NOTE: This command should be treated as experimental. While it | |
1133 | should properly record copied files, this information is not yet |
|
1133 | should properly record copied files, this information is not yet | |
1134 | fully used by merge, nor fully reported by log. |
|
1134 | fully used by merge, nor fully reported by log. | |
1135 | """ |
|
1135 | """ | |
1136 | wlock = repo.wlock(0) |
|
1136 | wlock = repo.wlock(0) | |
1137 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1137 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
1138 | return errs |
|
1138 | return errs | |
1139 |
|
1139 | |||
1140 | def debugancestor(ui, index, rev1, rev2): |
|
1140 | def debugancestor(ui, index, rev1, rev2): | |
1141 | """find the ancestor revision of two revisions in a given index""" |
|
1141 | """find the ancestor revision of two revisions in a given index""" | |
1142 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) |
|
1142 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) | |
1143 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1143 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | |
1144 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1144 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | |
1145 |
|
1145 | |||
1146 | def debugcomplete(ui, cmd='', **opts): |
|
1146 | def debugcomplete(ui, cmd='', **opts): | |
1147 | """returns the completion list associated with the given command""" |
|
1147 | """returns the completion list associated with the given command""" | |
1148 |
|
1148 | |||
1149 | if opts['options']: |
|
1149 | if opts['options']: | |
1150 | options = [] |
|
1150 | options = [] | |
1151 | otables = [globalopts] |
|
1151 | otables = [globalopts] | |
1152 | if cmd: |
|
1152 | if cmd: | |
1153 | aliases, entry = findcmd(cmd) |
|
1153 | aliases, entry = findcmd(cmd) | |
1154 | otables.append(entry[1]) |
|
1154 | otables.append(entry[1]) | |
1155 | for t in otables: |
|
1155 | for t in otables: | |
1156 | for o in t: |
|
1156 | for o in t: | |
1157 | if o[0]: |
|
1157 | if o[0]: | |
1158 | options.append('-%s' % o[0]) |
|
1158 | options.append('-%s' % o[0]) | |
1159 | options.append('--%s' % o[1]) |
|
1159 | options.append('--%s' % o[1]) | |
1160 | ui.write("%s\n" % "\n".join(options)) |
|
1160 | ui.write("%s\n" % "\n".join(options)) | |
1161 | return |
|
1161 | return | |
1162 |
|
1162 | |||
1163 | clist = findpossible(cmd).keys() |
|
1163 | clist = findpossible(cmd).keys() | |
1164 | clist.sort() |
|
1164 | clist.sort() | |
1165 | ui.write("%s\n" % "\n".join(clist)) |
|
1165 | ui.write("%s\n" % "\n".join(clist)) | |
1166 |
|
1166 | |||
1167 | def debugrebuildstate(ui, repo, rev=None): |
|
1167 | def debugrebuildstate(ui, repo, rev=None): | |
1168 | """rebuild the dirstate as it would look like for the given revision""" |
|
1168 | """rebuild the dirstate as it would look like for the given revision""" | |
1169 | if not rev: |
|
1169 | if not rev: | |
1170 | rev = repo.changelog.tip() |
|
1170 | rev = repo.changelog.tip() | |
1171 | else: |
|
1171 | else: | |
1172 | rev = repo.lookup(rev) |
|
1172 | rev = repo.lookup(rev) | |
1173 | change = repo.changelog.read(rev) |
|
1173 | change = repo.changelog.read(rev) | |
1174 | n = change[0] |
|
1174 | n = change[0] | |
1175 | files = repo.manifest.read(n) |
|
1175 | files = repo.manifest.read(n) | |
1176 | wlock = repo.wlock() |
|
1176 | wlock = repo.wlock() | |
1177 | repo.dirstate.rebuild(rev, files) |
|
1177 | repo.dirstate.rebuild(rev, files) | |
1178 |
|
1178 | |||
1179 | def debugcheckstate(ui, repo): |
|
1179 | def debugcheckstate(ui, repo): | |
1180 | """validate the correctness of the current dirstate""" |
|
1180 | """validate the correctness of the current dirstate""" | |
1181 | parent1, parent2 = repo.dirstate.parents() |
|
1181 | parent1, parent2 = repo.dirstate.parents() | |
1182 | repo.dirstate.read() |
|
1182 | repo.dirstate.read() | |
1183 | dc = repo.dirstate.map |
|
1183 | dc = repo.dirstate.map | |
1184 | keys = dc.keys() |
|
1184 | keys = dc.keys() | |
1185 | keys.sort() |
|
1185 | keys.sort() | |
1186 | m1n = repo.changelog.read(parent1)[0] |
|
1186 | m1n = repo.changelog.read(parent1)[0] | |
1187 | m2n = repo.changelog.read(parent2)[0] |
|
1187 | m2n = repo.changelog.read(parent2)[0] | |
1188 | m1 = repo.manifest.read(m1n) |
|
1188 | m1 = repo.manifest.read(m1n) | |
1189 | m2 = repo.manifest.read(m2n) |
|
1189 | m2 = repo.manifest.read(m2n) | |
1190 | errors = 0 |
|
1190 | errors = 0 | |
1191 | for f in dc: |
|
1191 | for f in dc: | |
1192 | state = repo.dirstate.state(f) |
|
1192 | state = repo.dirstate.state(f) | |
1193 | if state in "nr" and f not in m1: |
|
1193 | if state in "nr" and f not in m1: | |
1194 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1194 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | |
1195 | errors += 1 |
|
1195 | errors += 1 | |
1196 | if state in "a" and f in m1: |
|
1196 | if state in "a" and f in m1: | |
1197 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1197 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | |
1198 | errors += 1 |
|
1198 | errors += 1 | |
1199 | if state in "m" and f not in m1 and f not in m2: |
|
1199 | if state in "m" and f not in m1 and f not in m2: | |
1200 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1200 | ui.warn(_("%s in state %s, but not in either manifest\n") % | |
1201 | (f, state)) |
|
1201 | (f, state)) | |
1202 | errors += 1 |
|
1202 | errors += 1 | |
1203 | for f in m1: |
|
1203 | for f in m1: | |
1204 | state = repo.dirstate.state(f) |
|
1204 | state = repo.dirstate.state(f) | |
1205 | if state not in "nrm": |
|
1205 | if state not in "nrm": | |
1206 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1206 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | |
1207 | errors += 1 |
|
1207 | errors += 1 | |
1208 | if errors: |
|
1208 | if errors: | |
1209 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1209 | error = _(".hg/dirstate inconsistent with current parent's manifest") | |
1210 | raise util.Abort(error) |
|
1210 | raise util.Abort(error) | |
1211 |
|
1211 | |||
1212 | def debugconfig(ui, repo, *values): |
|
1212 | def debugconfig(ui, repo, *values): | |
1213 | """show combined config settings from all hgrc files |
|
1213 | """show combined config settings from all hgrc files | |
1214 |
|
1214 | |||
1215 | With no args, print names and values of all config items. |
|
1215 | With no args, print names and values of all config items. | |
1216 |
|
1216 | |||
1217 | With one arg of the form section.name, print just the value of |
|
1217 | With one arg of the form section.name, print just the value of | |
1218 | that config item. |
|
1218 | that config item. | |
1219 |
|
1219 | |||
1220 | With multiple args, print names and values of all config items |
|
1220 | With multiple args, print names and values of all config items | |
1221 | with matching section names.""" |
|
1221 | with matching section names.""" | |
1222 |
|
1222 | |||
1223 | if values: |
|
1223 | if values: | |
1224 | if len([v for v in values if '.' in v]) > 1: |
|
1224 | if len([v for v in values if '.' in v]) > 1: | |
1225 | raise util.Abort(_('only one config item permitted')) |
|
1225 | raise util.Abort(_('only one config item permitted')) | |
1226 | for section, name, value in ui.walkconfig(): |
|
1226 | for section, name, value in ui.walkconfig(): | |
1227 | sectname = section + '.' + name |
|
1227 | sectname = section + '.' + name | |
1228 | if values: |
|
1228 | if values: | |
1229 | for v in values: |
|
1229 | for v in values: | |
1230 | if v == section: |
|
1230 | if v == section: | |
1231 | ui.write('%s=%s\n' % (sectname, value)) |
|
1231 | ui.write('%s=%s\n' % (sectname, value)) | |
1232 | elif v == sectname: |
|
1232 | elif v == sectname: | |
1233 | ui.write(value, '\n') |
|
1233 | ui.write(value, '\n') | |
1234 | else: |
|
1234 | else: | |
1235 | ui.write('%s=%s\n' % (sectname, value)) |
|
1235 | ui.write('%s=%s\n' % (sectname, value)) | |
1236 |
|
1236 | |||
1237 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
1237 | def debugsetparents(ui, repo, rev1, rev2=None): | |
1238 | """manually set the parents of the current working directory |
|
1238 | """manually set the parents of the current working directory | |
1239 |
|
1239 | |||
1240 | This is useful for writing repository conversion tools, but should |
|
1240 | This is useful for writing repository conversion tools, but should | |
1241 | be used with care. |
|
1241 | be used with care. | |
1242 | """ |
|
1242 | """ | |
1243 |
|
1243 | |||
1244 | if not rev2: |
|
1244 | if not rev2: | |
1245 | rev2 = hex(nullid) |
|
1245 | rev2 = hex(nullid) | |
1246 |
|
1246 | |||
1247 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
1247 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | |
1248 |
|
1248 | |||
1249 | def debugstate(ui, repo): |
|
1249 | def debugstate(ui, repo): | |
1250 | """show the contents of the current dirstate""" |
|
1250 | """show the contents of the current dirstate""" | |
1251 | repo.dirstate.read() |
|
1251 | repo.dirstate.read() | |
1252 | dc = repo.dirstate.map |
|
1252 | dc = repo.dirstate.map | |
1253 | keys = dc.keys() |
|
1253 | keys = dc.keys() | |
1254 | keys.sort() |
|
1254 | keys.sort() | |
1255 | for file_ in keys: |
|
1255 | for file_ in keys: | |
1256 | ui.write("%c %3o %10d %s %s\n" |
|
1256 | ui.write("%c %3o %10d %s %s\n" | |
1257 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
1257 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | |
1258 | time.strftime("%x %X", |
|
1258 | time.strftime("%x %X", | |
1259 | time.localtime(dc[file_][3])), file_)) |
|
1259 | time.localtime(dc[file_][3])), file_)) | |
1260 | for f in repo.dirstate.copies: |
|
1260 | for f in repo.dirstate.copies: | |
1261 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) |
|
1261 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) | |
1262 |
|
1262 | |||
1263 | def debugdata(ui, file_, rev): |
|
1263 | def debugdata(ui, file_, rev): | |
1264 | """dump the contents of an data file revision""" |
|
1264 | """dump the contents of an data file revision""" | |
1265 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
1265 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | |
1266 | file_[:-2] + ".i", file_, 0) |
|
1266 | file_[:-2] + ".i", file_, 0) | |
1267 | try: |
|
1267 | try: | |
1268 | ui.write(r.revision(r.lookup(rev))) |
|
1268 | ui.write(r.revision(r.lookup(rev))) | |
1269 | except KeyError: |
|
1269 | except KeyError: | |
1270 | raise util.Abort(_('invalid revision identifier %s'), rev) |
|
1270 | raise util.Abort(_('invalid revision identifier %s'), rev) | |
1271 |
|
1271 | |||
1272 | def debugindex(ui, file_): |
|
1272 | def debugindex(ui, file_): | |
1273 | """dump the contents of an index file""" |
|
1273 | """dump the contents of an index file""" | |
1274 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
1274 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) | |
1275 | ui.write(" rev offset length base linkrev" + |
|
1275 | ui.write(" rev offset length base linkrev" + | |
1276 | " nodeid p1 p2\n") |
|
1276 | " nodeid p1 p2\n") | |
1277 | for i in range(r.count()): |
|
1277 | for i in range(r.count()): | |
1278 | node = r.node(i) |
|
1278 | node = r.node(i) | |
1279 | pp = r.parents(node) |
|
1279 | pp = r.parents(node) | |
1280 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1280 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
1281 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), |
|
1281 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), | |
1282 | short(node), short(pp[0]), short(pp[1]))) |
|
1282 | short(node), short(pp[0]), short(pp[1]))) | |
1283 |
|
1283 | |||
1284 | def debugindexdot(ui, file_): |
|
1284 | def debugindexdot(ui, file_): | |
1285 | """dump an index DAG as a .dot file""" |
|
1285 | """dump an index DAG as a .dot file""" | |
1286 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
1286 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) | |
1287 | ui.write("digraph G {\n") |
|
1287 | ui.write("digraph G {\n") | |
1288 | for i in range(r.count()): |
|
1288 | for i in range(r.count()): | |
1289 | node = r.node(i) |
|
1289 | node = r.node(i) | |
1290 | pp = r.parents(node) |
|
1290 | pp = r.parents(node) | |
1291 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
1291 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) | |
1292 | if pp[1] != nullid: |
|
1292 | if pp[1] != nullid: | |
1293 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
1293 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) | |
1294 | ui.write("}\n") |
|
1294 | ui.write("}\n") | |
1295 |
|
1295 | |||
1296 | def debugrename(ui, repo, file, rev=None): |
|
1296 | def debugrename(ui, repo, file, rev=None): | |
1297 | """dump rename information""" |
|
1297 | """dump rename information""" | |
1298 | r = repo.file(relpath(repo, [file])[0]) |
|
1298 | r = repo.file(relpath(repo, [file])[0]) | |
1299 | if rev: |
|
1299 | if rev: | |
1300 | try: |
|
1300 | try: | |
1301 | # assume all revision numbers are for changesets |
|
1301 | # assume all revision numbers are for changesets | |
1302 | n = repo.lookup(rev) |
|
1302 | n = repo.lookup(rev) | |
1303 | change = repo.changelog.read(n) |
|
1303 | change = repo.changelog.read(n) | |
1304 | m = repo.manifest.read(change[0]) |
|
1304 | m = repo.manifest.read(change[0]) | |
1305 | n = m[relpath(repo, [file])[0]] |
|
1305 | n = m[relpath(repo, [file])[0]] | |
1306 | except (hg.RepoError, KeyError): |
|
1306 | except (hg.RepoError, KeyError): | |
1307 | n = r.lookup(rev) |
|
1307 | n = r.lookup(rev) | |
1308 | else: |
|
1308 | else: | |
1309 | n = r.tip() |
|
1309 | n = r.tip() | |
1310 | m = r.renamed(n) |
|
1310 | m = r.renamed(n) | |
1311 | if m: |
|
1311 | if m: | |
1312 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) |
|
1312 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) | |
1313 | else: |
|
1313 | else: | |
1314 | ui.write(_("not renamed\n")) |
|
1314 | ui.write(_("not renamed\n")) | |
1315 |
|
1315 | |||
1316 | def debugwalk(ui, repo, *pats, **opts): |
|
1316 | def debugwalk(ui, repo, *pats, **opts): | |
1317 | """show how files match on given patterns""" |
|
1317 | """show how files match on given patterns""" | |
1318 | items = list(cmdutil.walk(repo, pats, opts)) |
|
1318 | items = list(cmdutil.walk(repo, pats, opts)) | |
1319 | if not items: |
|
1319 | if not items: | |
1320 | return |
|
1320 | return | |
1321 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1321 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | |
1322 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1322 | max([len(abs) for (src, abs, rel, exact) in items]), | |
1323 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1323 | max([len(rel) for (src, abs, rel, exact) in items])) | |
1324 | for src, abs, rel, exact in items: |
|
1324 | for src, abs, rel, exact in items: | |
1325 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1325 | line = fmt % (src, abs, rel, exact and 'exact' or '') | |
1326 | ui.write("%s\n" % line.rstrip()) |
|
1326 | ui.write("%s\n" % line.rstrip()) | |
1327 |
|
1327 | |||
1328 | def diff(ui, repo, *pats, **opts): |
|
1328 | def diff(ui, repo, *pats, **opts): | |
1329 | """diff repository (or selected files) |
|
1329 | """diff repository (or selected files) | |
1330 |
|
1330 | |||
1331 | Show differences between revisions for the specified files. |
|
1331 | Show differences between revisions for the specified files. | |
1332 |
|
1332 | |||
1333 | Differences between files are shown using the unified diff format. |
|
1333 | Differences between files are shown using the unified diff format. | |
1334 |
|
1334 | |||
1335 | When two revision arguments are given, then changes are shown |
|
1335 | When two revision arguments are given, then changes are shown | |
1336 | between those revisions. If only one revision is specified then |
|
1336 | between those revisions. If only one revision is specified then | |
1337 | that revision is compared to the working directory, and, when no |
|
1337 | that revision is compared to the working directory, and, when no | |
1338 | revisions are specified, the working directory files are compared |
|
1338 | revisions are specified, the working directory files are compared | |
1339 | to its parent. |
|
1339 | to its parent. | |
1340 |
|
1340 | |||
1341 | Without the -a option, diff will avoid generating diffs of files |
|
1341 | Without the -a option, diff will avoid generating diffs of files | |
1342 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1342 | it detects as binary. With -a, diff will generate a diff anyway, | |
1343 | probably with undesirable results. |
|
1343 | probably with undesirable results. | |
1344 | """ |
|
1344 | """ | |
1345 | node1, node2 = revpair(ui, repo, opts['rev']) |
|
1345 | node1, node2 = revpair(ui, repo, opts['rev']) | |
1346 |
|
1346 | |||
1347 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
1347 | fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
1348 |
|
1348 | |||
1349 | patch.diff(repo, node1, node2, fns, match=matchfn, |
|
1349 | patch.diff(repo, node1, node2, fns, match=matchfn, | |
1350 | opts=ui.diffopts(opts)) |
|
1350 | opts=ui.diffopts(opts)) | |
1351 |
|
1351 | |||
1352 | def export(ui, repo, *changesets, **opts): |
|
1352 | def export(ui, repo, *changesets, **opts): | |
1353 | """dump the header and diffs for one or more changesets |
|
1353 | """dump the header and diffs for one or more changesets | |
1354 |
|
1354 | |||
1355 | Print the changeset header and diffs for one or more revisions. |
|
1355 | Print the changeset header and diffs for one or more revisions. | |
1356 |
|
1356 | |||
1357 | The information shown in the changeset header is: author, |
|
1357 | The information shown in the changeset header is: author, | |
1358 | changeset hash, parent and commit comment. |
|
1358 | changeset hash, parent and commit comment. | |
1359 |
|
1359 | |||
1360 | Output may be to a file, in which case the name of the file is |
|
1360 | Output may be to a file, in which case the name of the file is | |
1361 | given using a format string. The formatting rules are as follows: |
|
1361 | given using a format string. The formatting rules are as follows: | |
1362 |
|
1362 | |||
1363 | %% literal "%" character |
|
1363 | %% literal "%" character | |
1364 | %H changeset hash (40 bytes of hexadecimal) |
|
1364 | %H changeset hash (40 bytes of hexadecimal) | |
1365 | %N number of patches being generated |
|
1365 | %N number of patches being generated | |
1366 | %R changeset revision number |
|
1366 | %R changeset revision number | |
1367 | %b basename of the exporting repository |
|
1367 | %b basename of the exporting repository | |
1368 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1368 | %h short-form changeset hash (12 bytes of hexadecimal) | |
1369 | %n zero-padded sequence number, starting at 1 |
|
1369 | %n zero-padded sequence number, starting at 1 | |
1370 | %r zero-padded changeset revision number |
|
1370 | %r zero-padded changeset revision number | |
1371 |
|
1371 | |||
1372 | Without the -a option, export will avoid generating diffs of files |
|
1372 | Without the -a option, export will avoid generating diffs of files | |
1373 | it detects as binary. With -a, export will generate a diff anyway, |
|
1373 | it detects as binary. With -a, export will generate a diff anyway, | |
1374 | probably with undesirable results. |
|
1374 | probably with undesirable results. | |
1375 |
|
1375 | |||
1376 | With the --switch-parent option, the diff will be against the second |
|
1376 | With the --switch-parent option, the diff will be against the second | |
1377 | parent. It can be useful to review a merge. |
|
1377 | parent. It can be useful to review a merge. | |
1378 | """ |
|
1378 | """ | |
1379 | if not changesets: |
|
1379 | if not changesets: | |
1380 | raise util.Abort(_("export requires at least one changeset")) |
|
1380 | raise util.Abort(_("export requires at least one changeset")) | |
1381 | revs = list(revrange(ui, repo, changesets)) |
|
1381 | revs = list(revrange(ui, repo, changesets)) | |
1382 | if len(revs) > 1: |
|
1382 | if len(revs) > 1: | |
1383 | ui.note(_('exporting patches:\n')) |
|
1383 | ui.note(_('exporting patches:\n')) | |
1384 | else: |
|
1384 | else: | |
1385 | ui.note(_('exporting patch:\n')) |
|
1385 | ui.note(_('exporting patch:\n')) | |
1386 | patch.export(repo, map(repo.lookup, revs), template=opts['output'], |
|
1386 | patch.export(repo, map(repo.lookup, revs), template=opts['output'], | |
1387 | switch_parent=opts['switch_parent'], opts=ui.diffopts(opts)) |
|
1387 | switch_parent=opts['switch_parent'], opts=ui.diffopts(opts)) | |
1388 |
|
1388 | |||
1389 | def forget(ui, repo, *pats, **opts): |
|
1389 | def forget(ui, repo, *pats, **opts): | |
1390 | """don't add the specified files on the next commit (DEPRECATED) |
|
1390 | """don't add the specified files on the next commit (DEPRECATED) | |
1391 |
|
1391 | |||
1392 | (DEPRECATED) |
|
1392 | (DEPRECATED) | |
1393 | Undo an 'hg add' scheduled for the next commit. |
|
1393 | Undo an 'hg add' scheduled for the next commit. | |
1394 |
|
1394 | |||
1395 | This command is now deprecated and will be removed in a future |
|
1395 | This command is now deprecated and will be removed in a future | |
1396 | release. Please use revert instead. |
|
1396 | release. Please use revert instead. | |
1397 | """ |
|
1397 | """ | |
1398 | ui.warn(_("(the forget command is deprecated; use revert instead)\n")) |
|
1398 | ui.warn(_("(the forget command is deprecated; use revert instead)\n")) | |
1399 | forget = [] |
|
1399 | forget = [] | |
1400 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): |
|
1400 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | |
1401 | if repo.dirstate.state(abs) == 'a': |
|
1401 | if repo.dirstate.state(abs) == 'a': | |
1402 | forget.append(abs) |
|
1402 | forget.append(abs) | |
1403 | if ui.verbose or not exact: |
|
1403 | if ui.verbose or not exact: | |
1404 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
|
1404 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) | |
1405 | repo.forget(forget) |
|
1405 | repo.forget(forget) | |
1406 |
|
1406 | |||
1407 | def grep(ui, repo, pattern, *pats, **opts): |
|
1407 | def grep(ui, repo, pattern, *pats, **opts): | |
1408 | """search for a pattern in specified files and revisions |
|
1408 | """search for a pattern in specified files and revisions | |
1409 |
|
1409 | |||
1410 | Search revisions of files for a regular expression. |
|
1410 | Search revisions of files for a regular expression. | |
1411 |
|
1411 | |||
1412 | This command behaves differently than Unix grep. It only accepts |
|
1412 | This command behaves differently than Unix grep. It only accepts | |
1413 | Python/Perl regexps. It searches repository history, not the |
|
1413 | Python/Perl regexps. It searches repository history, not the | |
1414 | working directory. It always prints the revision number in which |
|
1414 | working directory. It always prints the revision number in which | |
1415 | a match appears. |
|
1415 | a match appears. | |
1416 |
|
1416 | |||
1417 | By default, grep only prints output for the first revision of a |
|
1417 | By default, grep only prints output for the first revision of a | |
1418 | file in which it finds a match. To get it to print every revision |
|
1418 | file in which it finds a match. To get it to print every revision | |
1419 | that contains a change in match status ("-" for a match that |
|
1419 | that contains a change in match status ("-" for a match that | |
1420 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1420 | becomes a non-match, or "+" for a non-match that becomes a match), | |
1421 | use the --all flag. |
|
1421 | use the --all flag. | |
1422 | """ |
|
1422 | """ | |
1423 | reflags = 0 |
|
1423 | reflags = 0 | |
1424 | if opts['ignore_case']: |
|
1424 | if opts['ignore_case']: | |
1425 | reflags |= re.I |
|
1425 | reflags |= re.I | |
1426 | regexp = re.compile(pattern, reflags) |
|
1426 | regexp = re.compile(pattern, reflags) | |
1427 | sep, eol = ':', '\n' |
|
1427 | sep, eol = ':', '\n' | |
1428 | if opts['print0']: |
|
1428 | if opts['print0']: | |
1429 | sep = eol = '\0' |
|
1429 | sep = eol = '\0' | |
1430 |
|
1430 | |||
1431 | fcache = {} |
|
1431 | fcache = {} | |
1432 | def getfile(fn): |
|
1432 | def getfile(fn): | |
1433 | if fn not in fcache: |
|
1433 | if fn not in fcache: | |
1434 | fcache[fn] = repo.file(fn) |
|
1434 | fcache[fn] = repo.file(fn) | |
1435 | return fcache[fn] |
|
1435 | return fcache[fn] | |
1436 |
|
1436 | |||
1437 | def matchlines(body): |
|
1437 | def matchlines(body): | |
1438 | begin = 0 |
|
1438 | begin = 0 | |
1439 | linenum = 0 |
|
1439 | linenum = 0 | |
1440 | while True: |
|
1440 | while True: | |
1441 | match = regexp.search(body, begin) |
|
1441 | match = regexp.search(body, begin) | |
1442 | if not match: |
|
1442 | if not match: | |
1443 | break |
|
1443 | break | |
1444 | mstart, mend = match.span() |
|
1444 | mstart, mend = match.span() | |
1445 | linenum += body.count('\n', begin, mstart) + 1 |
|
1445 | linenum += body.count('\n', begin, mstart) + 1 | |
1446 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1446 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
1447 | lend = body.find('\n', mend) |
|
1447 | lend = body.find('\n', mend) | |
1448 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1448 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
1449 | begin = lend + 1 |
|
1449 | begin = lend + 1 | |
1450 |
|
1450 | |||
1451 | class linestate(object): |
|
1451 | class linestate(object): | |
1452 | def __init__(self, line, linenum, colstart, colend): |
|
1452 | def __init__(self, line, linenum, colstart, colend): | |
1453 | self.line = line |
|
1453 | self.line = line | |
1454 | self.linenum = linenum |
|
1454 | self.linenum = linenum | |
1455 | self.colstart = colstart |
|
1455 | self.colstart = colstart | |
1456 | self.colend = colend |
|
1456 | self.colend = colend | |
1457 |
|
1457 | |||
1458 | def __eq__(self, other): |
|
1458 | def __eq__(self, other): | |
1459 | return self.line == other.line |
|
1459 | return self.line == other.line | |
1460 |
|
1460 | |||
1461 | matches = {} |
|
1461 | matches = {} | |
1462 | copies = {} |
|
1462 | copies = {} | |
1463 | def grepbody(fn, rev, body): |
|
1463 | def grepbody(fn, rev, body): | |
1464 | matches[rev].setdefault(fn, []) |
|
1464 | matches[rev].setdefault(fn, []) | |
1465 | m = matches[rev][fn] |
|
1465 | m = matches[rev][fn] | |
1466 | for lnum, cstart, cend, line in matchlines(body): |
|
1466 | for lnum, cstart, cend, line in matchlines(body): | |
1467 | s = linestate(line, lnum, cstart, cend) |
|
1467 | s = linestate(line, lnum, cstart, cend) | |
1468 | m.append(s) |
|
1468 | m.append(s) | |
1469 |
|
1469 | |||
1470 | def difflinestates(a, b): |
|
1470 | def difflinestates(a, b): | |
1471 | sm = difflib.SequenceMatcher(None, a, b) |
|
1471 | sm = difflib.SequenceMatcher(None, a, b) | |
1472 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
1472 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | |
1473 | if tag == 'insert': |
|
1473 | if tag == 'insert': | |
1474 | for i in range(blo, bhi): |
|
1474 | for i in range(blo, bhi): | |
1475 | yield ('+', b[i]) |
|
1475 | yield ('+', b[i]) | |
1476 | elif tag == 'delete': |
|
1476 | elif tag == 'delete': | |
1477 | for i in range(alo, ahi): |
|
1477 | for i in range(alo, ahi): | |
1478 | yield ('-', a[i]) |
|
1478 | yield ('-', a[i]) | |
1479 | elif tag == 'replace': |
|
1479 | elif tag == 'replace': | |
1480 | for i in range(alo, ahi): |
|
1480 | for i in range(alo, ahi): | |
1481 | yield ('-', a[i]) |
|
1481 | yield ('-', a[i]) | |
1482 | for i in range(blo, bhi): |
|
1482 | for i in range(blo, bhi): | |
1483 | yield ('+', b[i]) |
|
1483 | yield ('+', b[i]) | |
1484 |
|
1484 | |||
1485 | prev = {} |
|
1485 | prev = {} | |
1486 | ucache = {} |
|
1486 | ucache = {} | |
1487 | def display(fn, rev, states, prevstates): |
|
1487 | def display(fn, rev, states, prevstates): | |
1488 | counts = {'-': 0, '+': 0} |
|
1488 | counts = {'-': 0, '+': 0} | |
1489 | filerevmatches = {} |
|
1489 | filerevmatches = {} | |
1490 | if incrementing or not opts['all']: |
|
1490 | if incrementing or not opts['all']: | |
1491 | a, b = prevstates, states |
|
1491 | a, b = prevstates, states | |
1492 | else: |
|
1492 | else: | |
1493 | a, b = states, prevstates |
|
1493 | a, b = states, prevstates | |
1494 | for change, l in difflinestates(a, b): |
|
1494 | for change, l in difflinestates(a, b): | |
1495 | if incrementing or not opts['all']: |
|
1495 | if incrementing or not opts['all']: | |
1496 | r = rev |
|
1496 | r = rev | |
1497 | else: |
|
1497 | else: | |
1498 | r = prev[fn] |
|
1498 | r = prev[fn] | |
1499 | cols = [fn, str(r)] |
|
1499 | cols = [fn, str(r)] | |
1500 | if opts['line_number']: |
|
1500 | if opts['line_number']: | |
1501 | cols.append(str(l.linenum)) |
|
1501 | cols.append(str(l.linenum)) | |
1502 | if opts['all']: |
|
1502 | if opts['all']: | |
1503 | cols.append(change) |
|
1503 | cols.append(change) | |
1504 | if opts['user']: |
|
1504 | if opts['user']: | |
1505 | cols.append(trimuser(ui, getchange(r)[1], rev, |
|
1505 | cols.append(trimuser(ui, getchange(r)[1], rev, | |
1506 | ucache)) |
|
1506 | ucache)) | |
1507 | if opts['files_with_matches']: |
|
1507 | if opts['files_with_matches']: | |
1508 | c = (fn, rev) |
|
1508 | c = (fn, rev) | |
1509 | if c in filerevmatches: |
|
1509 | if c in filerevmatches: | |
1510 | continue |
|
1510 | continue | |
1511 | filerevmatches[c] = 1 |
|
1511 | filerevmatches[c] = 1 | |
1512 | else: |
|
1512 | else: | |
1513 | cols.append(l.line) |
|
1513 | cols.append(l.line) | |
1514 | ui.write(sep.join(cols), eol) |
|
1514 | ui.write(sep.join(cols), eol) | |
1515 | counts[change] += 1 |
|
1515 | counts[change] += 1 | |
1516 | return counts['+'], counts['-'] |
|
1516 | return counts['+'], counts['-'] | |
1517 |
|
1517 | |||
1518 | fstate = {} |
|
1518 | fstate = {} | |
1519 | skip = {} |
|
1519 | skip = {} | |
1520 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1520 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1521 | count = 0 |
|
1521 | count = 0 | |
1522 | incrementing = False |
|
1522 | incrementing = False | |
1523 | follow = opts.get('follow') |
|
1523 | follow = opts.get('follow') | |
1524 | for st, rev, fns in changeiter: |
|
1524 | for st, rev, fns in changeiter: | |
1525 | if st == 'window': |
|
1525 | if st == 'window': | |
1526 | incrementing = rev |
|
1526 | incrementing = rev | |
1527 | matches.clear() |
|
1527 | matches.clear() | |
1528 | copies.clear() |
|
1528 | copies.clear() | |
1529 | elif st == 'add': |
|
1529 | elif st == 'add': | |
1530 | change = repo.changelog.read(repo.lookup(str(rev))) |
|
1530 | change = repo.changelog.read(repo.lookup(str(rev))) | |
1531 | mf = repo.manifest.read(change[0]) |
|
1531 | mf = repo.manifest.read(change[0]) | |
1532 | matches[rev] = {} |
|
1532 | matches[rev] = {} | |
1533 | for fn in fns: |
|
1533 | for fn in fns: | |
1534 | if fn in skip: |
|
1534 | if fn in skip: | |
1535 | continue |
|
1535 | continue | |
1536 | fstate.setdefault(fn, {}) |
|
1536 | fstate.setdefault(fn, {}) | |
1537 | copies.setdefault(rev, {}) |
|
1537 | copies.setdefault(rev, {}) | |
1538 | try: |
|
1538 | try: | |
1539 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1539 | grepbody(fn, rev, getfile(fn).read(mf[fn])) | |
1540 | if follow: |
|
1540 | if follow: | |
1541 | copied = getfile(fn).renamed(mf[fn]) |
|
1541 | copied = getfile(fn).renamed(mf[fn]) | |
1542 | if copied: |
|
1542 | if copied: | |
1543 | copies[rev][fn] = copied[0] |
|
1543 | copies[rev][fn] = copied[0] | |
1544 | except KeyError: |
|
1544 | except KeyError: | |
1545 | pass |
|
1545 | pass | |
1546 | elif st == 'iter': |
|
1546 | elif st == 'iter': | |
1547 | states = matches[rev].items() |
|
1547 | states = matches[rev].items() | |
1548 | states.sort() |
|
1548 | states.sort() | |
1549 | for fn, m in states: |
|
1549 | for fn, m in states: | |
1550 | copy = copies[rev].get(fn) |
|
1550 | copy = copies[rev].get(fn) | |
1551 | if fn in skip: |
|
1551 | if fn in skip: | |
1552 | if copy: |
|
1552 | if copy: | |
1553 | skip[copy] = True |
|
1553 | skip[copy] = True | |
1554 | continue |
|
1554 | continue | |
1555 | if incrementing or not opts['all'] or fstate[fn]: |
|
1555 | if incrementing or not opts['all'] or fstate[fn]: | |
1556 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1556 | pos, neg = display(fn, rev, m, fstate[fn]) | |
1557 | count += pos + neg |
|
1557 | count += pos + neg | |
1558 | if pos and not opts['all']: |
|
1558 | if pos and not opts['all']: | |
1559 | skip[fn] = True |
|
1559 | skip[fn] = True | |
1560 | if copy: |
|
1560 | if copy: | |
1561 | skip[copy] = True |
|
1561 | skip[copy] = True | |
1562 | fstate[fn] = m |
|
1562 | fstate[fn] = m | |
1563 | if copy: |
|
1563 | if copy: | |
1564 | fstate[copy] = m |
|
1564 | fstate[copy] = m | |
1565 | prev[fn] = rev |
|
1565 | prev[fn] = rev | |
1566 |
|
1566 | |||
1567 | if not incrementing: |
|
1567 | if not incrementing: | |
1568 | fstate = fstate.items() |
|
1568 | fstate = fstate.items() | |
1569 | fstate.sort() |
|
1569 | fstate.sort() | |
1570 | for fn, state in fstate: |
|
1570 | for fn, state in fstate: | |
1571 | if fn in skip: |
|
1571 | if fn in skip: | |
1572 | continue |
|
1572 | continue | |
1573 | if fn not in copies[prev[fn]]: |
|
1573 | if fn not in copies[prev[fn]]: | |
1574 | display(fn, rev, {}, state) |
|
1574 | display(fn, rev, {}, state) | |
1575 | return (count == 0 and 1) or 0 |
|
1575 | return (count == 0 and 1) or 0 | |
1576 |
|
1576 | |||
1577 | def heads(ui, repo, **opts): |
|
1577 | def heads(ui, repo, **opts): | |
1578 | """show current repository heads |
|
1578 | """show current repository heads | |
1579 |
|
1579 | |||
1580 | Show all repository head changesets. |
|
1580 | Show all repository head changesets. | |
1581 |
|
1581 | |||
1582 | Repository "heads" are changesets that don't have children |
|
1582 | Repository "heads" are changesets that don't have children | |
1583 | changesets. They are where development generally takes place and |
|
1583 | changesets. They are where development generally takes place and | |
1584 | are the usual targets for update and merge operations. |
|
1584 | are the usual targets for update and merge operations. | |
1585 | """ |
|
1585 | """ | |
1586 | if opts['rev']: |
|
1586 | if opts['rev']: | |
1587 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1587 | heads = repo.heads(repo.lookup(opts['rev'])) | |
1588 | else: |
|
1588 | else: | |
1589 | heads = repo.heads() |
|
1589 | heads = repo.heads() | |
1590 | br = None |
|
1590 | br = None | |
1591 | if opts['branches']: |
|
1591 | if opts['branches']: | |
1592 | br = repo.branchlookup(heads) |
|
1592 | br = repo.branchlookup(heads) | |
1593 | displayer = show_changeset(ui, repo, opts) |
|
1593 | displayer = show_changeset(ui, repo, opts) | |
1594 | for n in heads: |
|
1594 | for n in heads: | |
1595 | displayer.show(changenode=n, brinfo=br) |
|
1595 | displayer.show(changenode=n, brinfo=br) | |
1596 |
|
1596 | |||
1597 | def identify(ui, repo): |
|
1597 | def identify(ui, repo): | |
1598 | """print information about the working copy |
|
1598 | """print information about the working copy | |
1599 |
|
1599 | |||
1600 | Print a short summary of the current state of the repo. |
|
1600 | Print a short summary of the current state of the repo. | |
1601 |
|
1601 | |||
1602 | This summary identifies the repository state using one or two parent |
|
1602 | This summary identifies the repository state using one or two parent | |
1603 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1603 | hash identifiers, followed by a "+" if there are uncommitted changes | |
1604 | in the working directory, followed by a list of tags for this revision. |
|
1604 | in the working directory, followed by a list of tags for this revision. | |
1605 | """ |
|
1605 | """ | |
1606 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1606 | parents = [p for p in repo.dirstate.parents() if p != nullid] | |
1607 | if not parents: |
|
1607 | if not parents: | |
1608 | ui.write(_("unknown\n")) |
|
1608 | ui.write(_("unknown\n")) | |
1609 | return |
|
1609 | return | |
1610 |
|
1610 | |||
1611 | hexfunc = ui.verbose and hex or short |
|
1611 | hexfunc = ui.verbose and hex or short | |
1612 | modified, added, removed, deleted = repo.status()[:4] |
|
1612 | modified, added, removed, deleted = repo.status()[:4] | |
1613 | output = ["%s%s" % |
|
1613 | output = ["%s%s" % | |
1614 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1614 | ('+'.join([hexfunc(parent) for parent in parents]), | |
1615 | (modified or added or removed or deleted) and "+" or "")] |
|
1615 | (modified or added or removed or deleted) and "+" or "")] | |
1616 |
|
1616 | |||
1617 | if not ui.quiet: |
|
1617 | if not ui.quiet: | |
1618 | # multiple tags for a single parent separated by '/' |
|
1618 | # multiple tags for a single parent separated by '/' | |
1619 | parenttags = ['/'.join(tags) |
|
1619 | parenttags = ['/'.join(tags) | |
1620 | for tags in map(repo.nodetags, parents) if tags] |
|
1620 | for tags in map(repo.nodetags, parents) if tags] | |
1621 | # tags for multiple parents separated by ' + ' |
|
1621 | # tags for multiple parents separated by ' + ' | |
1622 | if parenttags: |
|
1622 | if parenttags: | |
1623 | output.append(' + '.join(parenttags)) |
|
1623 | output.append(' + '.join(parenttags)) | |
1624 |
|
1624 | |||
1625 | ui.write("%s\n" % ' '.join(output)) |
|
1625 | ui.write("%s\n" % ' '.join(output)) | |
1626 |
|
1626 | |||
1627 | def import_(ui, repo, patch1, *patches, **opts): |
|
1627 | def import_(ui, repo, patch1, *patches, **opts): | |
1628 | """import an ordered set of patches |
|
1628 | """import an ordered set of patches | |
1629 |
|
1629 | |||
1630 | Import a list of patches and commit them individually. |
|
1630 | Import a list of patches and commit them individually. | |
1631 |
|
1631 | |||
1632 | If there are outstanding changes in the working directory, import |
|
1632 | If there are outstanding changes in the working directory, import | |
1633 | will abort unless given the -f flag. |
|
1633 | will abort unless given the -f flag. | |
1634 |
|
1634 | |||
1635 | You can import a patch straight from a mail message. Even patches |
|
1635 | You can import a patch straight from a mail message. Even patches | |
1636 | as attachments work (body part must be type text/plain or |
|
1636 | as attachments work (body part must be type text/plain or | |
1637 | text/x-patch to be used). From and Subject headers of email |
|
1637 | text/x-patch to be used). From and Subject headers of email | |
1638 | message are used as default committer and commit message. All |
|
1638 | message are used as default committer and commit message. All | |
1639 | text/plain body parts before first diff are added to commit |
|
1639 | text/plain body parts before first diff are added to commit | |
1640 | message. |
|
1640 | message. | |
1641 |
|
1641 | |||
1642 | If imported patch was generated by hg export, user and description |
|
1642 | If imported patch was generated by hg export, user and description | |
1643 | from patch override values from message headers and body. Values |
|
1643 | from patch override values from message headers and body. Values | |
1644 | given on command line with -m and -u override these. |
|
1644 | given on command line with -m and -u override these. | |
1645 |
|
1645 | |||
1646 | To read a patch from standard input, use patch name "-". |
|
1646 | To read a patch from standard input, use patch name "-". | |
1647 | """ |
|
1647 | """ | |
1648 | patches = (patch1,) + patches |
|
1648 | patches = (patch1,) + patches | |
1649 |
|
1649 | |||
1650 | if not opts['force']: |
|
1650 | if not opts['force']: | |
1651 | bail_if_changed(repo) |
|
1651 | bail_if_changed(repo) | |
1652 |
|
1652 | |||
1653 | d = opts["base"] |
|
1653 | d = opts["base"] | |
1654 | strip = opts["strip"] |
|
1654 | strip = opts["strip"] | |
1655 |
|
1655 | |||
1656 | wlock = repo.wlock() |
|
1656 | wlock = repo.wlock() | |
1657 | lock = repo.lock() |
|
1657 | lock = repo.lock() | |
1658 |
|
1658 | |||
1659 | for p in patches: |
|
1659 | for p in patches: | |
1660 | pf = os.path.join(d, p) |
|
1660 | pf = os.path.join(d, p) | |
1661 |
|
1661 | |||
1662 | if pf == '-': |
|
1662 | if pf == '-': | |
1663 | ui.status(_("applying patch from stdin\n")) |
|
1663 | ui.status(_("applying patch from stdin\n")) | |
1664 | tmpname, message, user, date = patch.extract(ui, sys.stdin) |
|
1664 | tmpname, message, user, date = patch.extract(ui, sys.stdin) | |
1665 | else: |
|
1665 | else: | |
1666 | ui.status(_("applying %s\n") % p) |
|
1666 | ui.status(_("applying %s\n") % p) | |
1667 | tmpname, message, user, date = patch.extract(ui, file(pf)) |
|
1667 | tmpname, message, user, date = patch.extract(ui, file(pf)) | |
1668 |
|
1668 | |||
1669 | if tmpname is None: |
|
1669 | if tmpname is None: | |
1670 | raise util.Abort(_('no diffs found')) |
|
1670 | raise util.Abort(_('no diffs found')) | |
1671 |
|
1671 | |||
1672 | try: |
|
1672 | try: | |
1673 | if opts['message']: |
|
1673 | if opts['message']: | |
1674 | # pickup the cmdline msg |
|
1674 | # pickup the cmdline msg | |
1675 | message = opts['message'] |
|
1675 | message = opts['message'] | |
1676 | elif message: |
|
1676 | elif message: | |
1677 | # pickup the patch msg |
|
1677 | # pickup the patch msg | |
1678 | message = message.strip() |
|
1678 | message = message.strip() | |
1679 | else: |
|
1679 | else: | |
1680 | # launch the editor |
|
1680 | # launch the editor | |
1681 | message = None |
|
1681 | message = None | |
1682 | ui.debug(_('message:\n%s\n') % message) |
|
1682 | ui.debug(_('message:\n%s\n') % message) | |
1683 |
|
1683 | |||
1684 |
files = patch.patch( |
|
1684 | files, fuzz = patch.patch(tmpname, ui, strip=strip, cwd=repo.root) | |
1685 | removes = [] |
|
1685 | removes = [] | |
1686 | if len(files) > 0: |
|
1686 | if len(files) > 0: | |
1687 | cfiles = files.keys() |
|
1687 | cfiles = files.keys() | |
1688 | copies = [] |
|
1688 | copies = [] | |
1689 | copts = {'after': False, 'force': False} |
|
1689 | copts = {'after': False, 'force': False} | |
1690 | cwd = repo.getcwd() |
|
1690 | cwd = repo.getcwd() | |
1691 | if cwd: |
|
1691 | if cwd: | |
1692 | cfiles = [util.pathto(cwd, f) for f in files.keys()] |
|
1692 | cfiles = [util.pathto(cwd, f) for f in files.keys()] | |
1693 | for f in files: |
|
1693 | for f in files: | |
1694 | ctype, gp = files[f] |
|
1694 | ctype, gp = files[f] | |
1695 | if ctype == 'RENAME': |
|
1695 | if ctype == 'RENAME': | |
1696 | copies.append((gp.oldpath, gp.path, gp.copymod)) |
|
1696 | copies.append((gp.oldpath, gp.path, gp.copymod)) | |
1697 | removes.append(gp.oldpath) |
|
1697 | removes.append(gp.oldpath) | |
1698 | elif ctype == 'COPY': |
|
1698 | elif ctype == 'COPY': | |
1699 | copies.append((gp.oldpath, gp.path, gp.copymod)) |
|
1699 | copies.append((gp.oldpath, gp.path, gp.copymod)) | |
1700 | elif ctype == 'DELETE': |
|
1700 | elif ctype == 'DELETE': | |
1701 | removes.append(gp.path) |
|
1701 | removes.append(gp.path) | |
1702 | for src, dst, after in copies: |
|
1702 | for src, dst, after in copies: | |
1703 | absdst = os.path.join(repo.root, dst) |
|
1703 | absdst = os.path.join(repo.root, dst) | |
1704 | if not after and os.path.exists(absdst): |
|
1704 | if not after and os.path.exists(absdst): | |
1705 | raise util.Abort(_('patch creates existing file %s') % dst) |
|
1705 | raise util.Abort(_('patch creates existing file %s') % dst) | |
1706 | if cwd: |
|
1706 | if cwd: | |
1707 | src, dst = [util.pathto(cwd, f) for f in (src, dst)] |
|
1707 | src, dst = [util.pathto(cwd, f) for f in (src, dst)] | |
1708 | copts['after'] = after |
|
1708 | copts['after'] = after | |
1709 | errs, copied = docopy(ui, repo, (src, dst), copts, wlock=wlock) |
|
1709 | errs, copied = docopy(ui, repo, (src, dst), copts, wlock=wlock) | |
1710 | if errs: |
|
1710 | if errs: | |
1711 | raise util.Abort(errs) |
|
1711 | raise util.Abort(errs) | |
1712 | if removes: |
|
1712 | if removes: | |
1713 | repo.remove(removes, True, wlock=wlock) |
|
1713 | repo.remove(removes, True, wlock=wlock) | |
1714 | for f in files: |
|
1714 | for f in files: | |
1715 | ctype, gp = files[f] |
|
1715 | ctype, gp = files[f] | |
1716 | if gp and gp.mode: |
|
1716 | if gp and gp.mode: | |
1717 | x = gp.mode & 0100 != 0 |
|
1717 | x = gp.mode & 0100 != 0 | |
1718 | dst = os.path.join(repo.root, gp.path) |
|
1718 | dst = os.path.join(repo.root, gp.path) | |
1719 | util.set_exec(dst, x) |
|
1719 | util.set_exec(dst, x) | |
1720 | cmdutil.addremove(repo, cfiles, wlock=wlock) |
|
1720 | cmdutil.addremove(repo, cfiles, wlock=wlock) | |
1721 | files = files.keys() |
|
1721 | files = files.keys() | |
1722 | files.extend([r for r in removes if r not in files]) |
|
1722 | files.extend([r for r in removes if r not in files]) | |
1723 | repo.commit(files, message, user, date, wlock=wlock, lock=lock) |
|
1723 | repo.commit(files, message, user, date, wlock=wlock, lock=lock) | |
1724 | finally: |
|
1724 | finally: | |
1725 | os.unlink(tmpname) |
|
1725 | os.unlink(tmpname) | |
1726 |
|
1726 | |||
1727 | def incoming(ui, repo, source="default", **opts): |
|
1727 | def incoming(ui, repo, source="default", **opts): | |
1728 | """show new changesets found in source |
|
1728 | """show new changesets found in source | |
1729 |
|
1729 | |||
1730 | Show new changesets found in the specified path/URL or the default |
|
1730 | Show new changesets found in the specified path/URL or the default | |
1731 | pull location. These are the changesets that would be pulled if a pull |
|
1731 | pull location. These are the changesets that would be pulled if a pull | |
1732 | was requested. |
|
1732 | was requested. | |
1733 |
|
1733 | |||
1734 | For remote repository, using --bundle avoids downloading the changesets |
|
1734 | For remote repository, using --bundle avoids downloading the changesets | |
1735 | twice if the incoming is followed by a pull. |
|
1735 | twice if the incoming is followed by a pull. | |
1736 |
|
1736 | |||
1737 | See pull for valid source format details. |
|
1737 | See pull for valid source format details. | |
1738 | """ |
|
1738 | """ | |
1739 | source = ui.expandpath(source) |
|
1739 | source = ui.expandpath(source) | |
1740 | setremoteconfig(ui, opts) |
|
1740 | setremoteconfig(ui, opts) | |
1741 |
|
1741 | |||
1742 | other = hg.repository(ui, source) |
|
1742 | other = hg.repository(ui, source) | |
1743 | incoming = repo.findincoming(other, force=opts["force"]) |
|
1743 | incoming = repo.findincoming(other, force=opts["force"]) | |
1744 | if not incoming: |
|
1744 | if not incoming: | |
1745 | ui.status(_("no changes found\n")) |
|
1745 | ui.status(_("no changes found\n")) | |
1746 | return |
|
1746 | return | |
1747 |
|
1747 | |||
1748 | cleanup = None |
|
1748 | cleanup = None | |
1749 | try: |
|
1749 | try: | |
1750 | fname = opts["bundle"] |
|
1750 | fname = opts["bundle"] | |
1751 | if fname or not other.local(): |
|
1751 | if fname or not other.local(): | |
1752 | # create a bundle (uncompressed if other repo is not local) |
|
1752 | # create a bundle (uncompressed if other repo is not local) | |
1753 | cg = other.changegroup(incoming, "incoming") |
|
1753 | cg = other.changegroup(incoming, "incoming") | |
1754 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) |
|
1754 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) | |
1755 | # keep written bundle? |
|
1755 | # keep written bundle? | |
1756 | if opts["bundle"]: |
|
1756 | if opts["bundle"]: | |
1757 | cleanup = None |
|
1757 | cleanup = None | |
1758 | if not other.local(): |
|
1758 | if not other.local(): | |
1759 | # use the created uncompressed bundlerepo |
|
1759 | # use the created uncompressed bundlerepo | |
1760 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1760 | other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
1761 |
|
1761 | |||
1762 | revs = None |
|
1762 | revs = None | |
1763 | if opts['rev']: |
|
1763 | if opts['rev']: | |
1764 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
1764 | revs = [other.lookup(rev) for rev in opts['rev']] | |
1765 | o = other.changelog.nodesbetween(incoming, revs)[0] |
|
1765 | o = other.changelog.nodesbetween(incoming, revs)[0] | |
1766 | if opts['newest_first']: |
|
1766 | if opts['newest_first']: | |
1767 | o.reverse() |
|
1767 | o.reverse() | |
1768 | displayer = show_changeset(ui, other, opts) |
|
1768 | displayer = show_changeset(ui, other, opts) | |
1769 | for n in o: |
|
1769 | for n in o: | |
1770 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1770 | parents = [p for p in other.changelog.parents(n) if p != nullid] | |
1771 | if opts['no_merges'] and len(parents) == 2: |
|
1771 | if opts['no_merges'] and len(parents) == 2: | |
1772 | continue |
|
1772 | continue | |
1773 | displayer.show(changenode=n) |
|
1773 | displayer.show(changenode=n) | |
1774 | if opts['patch']: |
|
1774 | if opts['patch']: | |
1775 | prev = (parents and parents[0]) or nullid |
|
1775 | prev = (parents and parents[0]) or nullid | |
1776 | patch.diff(repo, other, prev, n) |
|
1776 | patch.diff(repo, other, prev, n) | |
1777 | ui.write("\n") |
|
1777 | ui.write("\n") | |
1778 | finally: |
|
1778 | finally: | |
1779 | if hasattr(other, 'close'): |
|
1779 | if hasattr(other, 'close'): | |
1780 | other.close() |
|
1780 | other.close() | |
1781 | if cleanup: |
|
1781 | if cleanup: | |
1782 | os.unlink(cleanup) |
|
1782 | os.unlink(cleanup) | |
1783 |
|
1783 | |||
1784 | def init(ui, dest=".", **opts): |
|
1784 | def init(ui, dest=".", **opts): | |
1785 | """create a new repository in the given directory |
|
1785 | """create a new repository in the given directory | |
1786 |
|
1786 | |||
1787 | Initialize a new repository in the given directory. If the given |
|
1787 | Initialize a new repository in the given directory. If the given | |
1788 | directory does not exist, it is created. |
|
1788 | directory does not exist, it is created. | |
1789 |
|
1789 | |||
1790 | If no directory is given, the current directory is used. |
|
1790 | If no directory is given, the current directory is used. | |
1791 |
|
1791 | |||
1792 | It is possible to specify an ssh:// URL as the destination. |
|
1792 | It is possible to specify an ssh:// URL as the destination. | |
1793 | Look at the help text for the pull command for important details |
|
1793 | Look at the help text for the pull command for important details | |
1794 | about ssh:// URLs. |
|
1794 | about ssh:// URLs. | |
1795 | """ |
|
1795 | """ | |
1796 | setremoteconfig(ui, opts) |
|
1796 | setremoteconfig(ui, opts) | |
1797 | hg.repository(ui, dest, create=1) |
|
1797 | hg.repository(ui, dest, create=1) | |
1798 |
|
1798 | |||
1799 | def locate(ui, repo, *pats, **opts): |
|
1799 | def locate(ui, repo, *pats, **opts): | |
1800 | """locate files matching specific patterns |
|
1800 | """locate files matching specific patterns | |
1801 |
|
1801 | |||
1802 | Print all files under Mercurial control whose names match the |
|
1802 | Print all files under Mercurial control whose names match the | |
1803 | given patterns. |
|
1803 | given patterns. | |
1804 |
|
1804 | |||
1805 | This command searches the current directory and its |
|
1805 | This command searches the current directory and its | |
1806 | subdirectories. To search an entire repository, move to the root |
|
1806 | subdirectories. To search an entire repository, move to the root | |
1807 | of the repository. |
|
1807 | of the repository. | |
1808 |
|
1808 | |||
1809 | If no patterns are given to match, this command prints all file |
|
1809 | If no patterns are given to match, this command prints all file | |
1810 | names. |
|
1810 | names. | |
1811 |
|
1811 | |||
1812 | If you want to feed the output of this command into the "xargs" |
|
1812 | If you want to feed the output of this command into the "xargs" | |
1813 | command, use the "-0" option to both this command and "xargs". |
|
1813 | command, use the "-0" option to both this command and "xargs". | |
1814 | This will avoid the problem of "xargs" treating single filenames |
|
1814 | This will avoid the problem of "xargs" treating single filenames | |
1815 | that contain white space as multiple filenames. |
|
1815 | that contain white space as multiple filenames. | |
1816 | """ |
|
1816 | """ | |
1817 | end = opts['print0'] and '\0' or '\n' |
|
1817 | end = opts['print0'] and '\0' or '\n' | |
1818 | rev = opts['rev'] |
|
1818 | rev = opts['rev'] | |
1819 | if rev: |
|
1819 | if rev: | |
1820 | node = repo.lookup(rev) |
|
1820 | node = repo.lookup(rev) | |
1821 | else: |
|
1821 | else: | |
1822 | node = None |
|
1822 | node = None | |
1823 |
|
1823 | |||
1824 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, |
|
1824 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, | |
1825 | head='(?:.*/|)'): |
|
1825 | head='(?:.*/|)'): | |
1826 | if not node and repo.dirstate.state(abs) == '?': |
|
1826 | if not node and repo.dirstate.state(abs) == '?': | |
1827 | continue |
|
1827 | continue | |
1828 | if opts['fullpath']: |
|
1828 | if opts['fullpath']: | |
1829 | ui.write(os.path.join(repo.root, abs), end) |
|
1829 | ui.write(os.path.join(repo.root, abs), end) | |
1830 | else: |
|
1830 | else: | |
1831 | ui.write(((pats and rel) or abs), end) |
|
1831 | ui.write(((pats and rel) or abs), end) | |
1832 |
|
1832 | |||
1833 | def log(ui, repo, *pats, **opts): |
|
1833 | def log(ui, repo, *pats, **opts): | |
1834 | """show revision history of entire repository or files |
|
1834 | """show revision history of entire repository or files | |
1835 |
|
1835 | |||
1836 | Print the revision history of the specified files or the entire |
|
1836 | Print the revision history of the specified files or the entire | |
1837 | project. |
|
1837 | project. | |
1838 |
|
1838 | |||
1839 | File history is shown without following rename or copy history of |
|
1839 | File history is shown without following rename or copy history of | |
1840 | files. Use -f/--follow with a file name to follow history across |
|
1840 | files. Use -f/--follow with a file name to follow history across | |
1841 | renames and copies. --follow without a file name will only show |
|
1841 | renames and copies. --follow without a file name will only show | |
1842 | ancestors or descendants of the starting revision. --follow-first |
|
1842 | ancestors or descendants of the starting revision. --follow-first | |
1843 | only follows the first parent of merge revisions. |
|
1843 | only follows the first parent of merge revisions. | |
1844 |
|
1844 | |||
1845 | If no revision range is specified, the default is tip:0 unless |
|
1845 | If no revision range is specified, the default is tip:0 unless | |
1846 | --follow is set, in which case the working directory parent is |
|
1846 | --follow is set, in which case the working directory parent is | |
1847 | used as the starting revision. |
|
1847 | used as the starting revision. | |
1848 |
|
1848 | |||
1849 | By default this command outputs: changeset id and hash, tags, |
|
1849 | By default this command outputs: changeset id and hash, tags, | |
1850 | non-trivial parents, user, date and time, and a summary for each |
|
1850 | non-trivial parents, user, date and time, and a summary for each | |
1851 | commit. When the -v/--verbose switch is used, the list of changed |
|
1851 | commit. When the -v/--verbose switch is used, the list of changed | |
1852 | files and full commit message is shown. |
|
1852 | files and full commit message is shown. | |
1853 | """ |
|
1853 | """ | |
1854 | class dui(object): |
|
1854 | class dui(object): | |
1855 | # Implement and delegate some ui protocol. Save hunks of |
|
1855 | # Implement and delegate some ui protocol. Save hunks of | |
1856 | # output for later display in the desired order. |
|
1856 | # output for later display in the desired order. | |
1857 | def __init__(self, ui): |
|
1857 | def __init__(self, ui): | |
1858 | self.ui = ui |
|
1858 | self.ui = ui | |
1859 | self.hunk = {} |
|
1859 | self.hunk = {} | |
1860 | self.header = {} |
|
1860 | self.header = {} | |
1861 | def bump(self, rev): |
|
1861 | def bump(self, rev): | |
1862 | self.rev = rev |
|
1862 | self.rev = rev | |
1863 | self.hunk[rev] = [] |
|
1863 | self.hunk[rev] = [] | |
1864 | self.header[rev] = [] |
|
1864 | self.header[rev] = [] | |
1865 | def note(self, *args): |
|
1865 | def note(self, *args): | |
1866 | if self.verbose: |
|
1866 | if self.verbose: | |
1867 | self.write(*args) |
|
1867 | self.write(*args) | |
1868 | def status(self, *args): |
|
1868 | def status(self, *args): | |
1869 | if not self.quiet: |
|
1869 | if not self.quiet: | |
1870 | self.write(*args) |
|
1870 | self.write(*args) | |
1871 | def write(self, *args): |
|
1871 | def write(self, *args): | |
1872 | self.hunk[self.rev].append(args) |
|
1872 | self.hunk[self.rev].append(args) | |
1873 | def write_header(self, *args): |
|
1873 | def write_header(self, *args): | |
1874 | self.header[self.rev].append(args) |
|
1874 | self.header[self.rev].append(args) | |
1875 | def debug(self, *args): |
|
1875 | def debug(self, *args): | |
1876 | if self.debugflag: |
|
1876 | if self.debugflag: | |
1877 | self.write(*args) |
|
1877 | self.write(*args) | |
1878 | def __getattr__(self, key): |
|
1878 | def __getattr__(self, key): | |
1879 | return getattr(self.ui, key) |
|
1879 | return getattr(self.ui, key) | |
1880 |
|
1880 | |||
1881 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1881 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1882 |
|
1882 | |||
1883 | if opts['limit']: |
|
1883 | if opts['limit']: | |
1884 | try: |
|
1884 | try: | |
1885 | limit = int(opts['limit']) |
|
1885 | limit = int(opts['limit']) | |
1886 | except ValueError: |
|
1886 | except ValueError: | |
1887 | raise util.Abort(_('limit must be a positive integer')) |
|
1887 | raise util.Abort(_('limit must be a positive integer')) | |
1888 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1888 | if limit <= 0: raise util.Abort(_('limit must be positive')) | |
1889 | else: |
|
1889 | else: | |
1890 | limit = sys.maxint |
|
1890 | limit = sys.maxint | |
1891 | count = 0 |
|
1891 | count = 0 | |
1892 |
|
1892 | |||
1893 | displayer = show_changeset(ui, repo, opts) |
|
1893 | displayer = show_changeset(ui, repo, opts) | |
1894 | for st, rev, fns in changeiter: |
|
1894 | for st, rev, fns in changeiter: | |
1895 | if st == 'window': |
|
1895 | if st == 'window': | |
1896 | du = dui(ui) |
|
1896 | du = dui(ui) | |
1897 | displayer.ui = du |
|
1897 | displayer.ui = du | |
1898 | elif st == 'add': |
|
1898 | elif st == 'add': | |
1899 | du.bump(rev) |
|
1899 | du.bump(rev) | |
1900 | changenode = repo.changelog.node(rev) |
|
1900 | changenode = repo.changelog.node(rev) | |
1901 | parents = [p for p in repo.changelog.parents(changenode) |
|
1901 | parents = [p for p in repo.changelog.parents(changenode) | |
1902 | if p != nullid] |
|
1902 | if p != nullid] | |
1903 | if opts['no_merges'] and len(parents) == 2: |
|
1903 | if opts['no_merges'] and len(parents) == 2: | |
1904 | continue |
|
1904 | continue | |
1905 | if opts['only_merges'] and len(parents) != 2: |
|
1905 | if opts['only_merges'] and len(parents) != 2: | |
1906 | continue |
|
1906 | continue | |
1907 |
|
1907 | |||
1908 | if opts['keyword']: |
|
1908 | if opts['keyword']: | |
1909 | changes = getchange(rev) |
|
1909 | changes = getchange(rev) | |
1910 | miss = 0 |
|
1910 | miss = 0 | |
1911 | for k in [kw.lower() for kw in opts['keyword']]: |
|
1911 | for k in [kw.lower() for kw in opts['keyword']]: | |
1912 | if not (k in changes[1].lower() or |
|
1912 | if not (k in changes[1].lower() or | |
1913 | k in changes[4].lower() or |
|
1913 | k in changes[4].lower() or | |
1914 | k in " ".join(changes[3][:20]).lower()): |
|
1914 | k in " ".join(changes[3][:20]).lower()): | |
1915 | miss = 1 |
|
1915 | miss = 1 | |
1916 | break |
|
1916 | break | |
1917 | if miss: |
|
1917 | if miss: | |
1918 | continue |
|
1918 | continue | |
1919 |
|
1919 | |||
1920 | br = None |
|
1920 | br = None | |
1921 | if opts['branches']: |
|
1921 | if opts['branches']: | |
1922 | br = repo.branchlookup([repo.changelog.node(rev)]) |
|
1922 | br = repo.branchlookup([repo.changelog.node(rev)]) | |
1923 |
|
1923 | |||
1924 | displayer.show(rev, brinfo=br) |
|
1924 | displayer.show(rev, brinfo=br) | |
1925 | if opts['patch']: |
|
1925 | if opts['patch']: | |
1926 | prev = (parents and parents[0]) or nullid |
|
1926 | prev = (parents and parents[0]) or nullid | |
1927 | patch.diff(repo, prev, changenode, match=matchfn, fp=du) |
|
1927 | patch.diff(repo, prev, changenode, match=matchfn, fp=du) | |
1928 | du.write("\n\n") |
|
1928 | du.write("\n\n") | |
1929 | elif st == 'iter': |
|
1929 | elif st == 'iter': | |
1930 | if count == limit: break |
|
1930 | if count == limit: break | |
1931 | if du.header[rev]: |
|
1931 | if du.header[rev]: | |
1932 | for args in du.header[rev]: |
|
1932 | for args in du.header[rev]: | |
1933 | ui.write_header(*args) |
|
1933 | ui.write_header(*args) | |
1934 | if du.hunk[rev]: |
|
1934 | if du.hunk[rev]: | |
1935 | count += 1 |
|
1935 | count += 1 | |
1936 | for args in du.hunk[rev]: |
|
1936 | for args in du.hunk[rev]: | |
1937 | ui.write(*args) |
|
1937 | ui.write(*args) | |
1938 |
|
1938 | |||
1939 | def manifest(ui, repo, rev=None): |
|
1939 | def manifest(ui, repo, rev=None): | |
1940 | """output the latest or given revision of the project manifest |
|
1940 | """output the latest or given revision of the project manifest | |
1941 |
|
1941 | |||
1942 | Print a list of version controlled files for the given revision. |
|
1942 | Print a list of version controlled files for the given revision. | |
1943 |
|
1943 | |||
1944 | The manifest is the list of files being version controlled. If no revision |
|
1944 | The manifest is the list of files being version controlled. If no revision | |
1945 | is given then the tip is used. |
|
1945 | is given then the tip is used. | |
1946 | """ |
|
1946 | """ | |
1947 | if rev: |
|
1947 | if rev: | |
1948 | try: |
|
1948 | try: | |
1949 | # assume all revision numbers are for changesets |
|
1949 | # assume all revision numbers are for changesets | |
1950 | n = repo.lookup(rev) |
|
1950 | n = repo.lookup(rev) | |
1951 | change = repo.changelog.read(n) |
|
1951 | change = repo.changelog.read(n) | |
1952 | n = change[0] |
|
1952 | n = change[0] | |
1953 | except hg.RepoError: |
|
1953 | except hg.RepoError: | |
1954 | n = repo.manifest.lookup(rev) |
|
1954 | n = repo.manifest.lookup(rev) | |
1955 | else: |
|
1955 | else: | |
1956 | n = repo.manifest.tip() |
|
1956 | n = repo.manifest.tip() | |
1957 | m = repo.manifest.read(n) |
|
1957 | m = repo.manifest.read(n) | |
1958 | files = m.keys() |
|
1958 | files = m.keys() | |
1959 | files.sort() |
|
1959 | files.sort() | |
1960 |
|
1960 | |||
1961 | for f in files: |
|
1961 | for f in files: | |
1962 | ui.write("%40s %3s %s\n" % (hex(m[f]), |
|
1962 | ui.write("%40s %3s %s\n" % (hex(m[f]), | |
1963 | m.execf(f) and "755" or "644", f)) |
|
1963 | m.execf(f) and "755" or "644", f)) | |
1964 |
|
1964 | |||
1965 | def merge(ui, repo, node=None, force=None, branch=None): |
|
1965 | def merge(ui, repo, node=None, force=None, branch=None): | |
1966 | """Merge working directory with another revision |
|
1966 | """Merge working directory with another revision | |
1967 |
|
1967 | |||
1968 | Merge the contents of the current working directory and the |
|
1968 | Merge the contents of the current working directory and the | |
1969 | requested revision. Files that changed between either parent are |
|
1969 | requested revision. Files that changed between either parent are | |
1970 | marked as changed for the next commit and a commit must be |
|
1970 | marked as changed for the next commit and a commit must be | |
1971 | performed before any further updates are allowed. |
|
1971 | performed before any further updates are allowed. | |
1972 |
|
1972 | |||
1973 | If no revision is specified, the working directory's parent is a |
|
1973 | If no revision is specified, the working directory's parent is a | |
1974 | head revision, and the repository contains exactly one other head, |
|
1974 | head revision, and the repository contains exactly one other head, | |
1975 | the other head is merged with by default. Otherwise, an explicit |
|
1975 | the other head is merged with by default. Otherwise, an explicit | |
1976 | revision to merge with must be provided. |
|
1976 | revision to merge with must be provided. | |
1977 | """ |
|
1977 | """ | |
1978 |
|
1978 | |||
1979 | if node: |
|
1979 | if node: | |
1980 | node = _lookup(repo, node, branch) |
|
1980 | node = _lookup(repo, node, branch) | |
1981 | else: |
|
1981 | else: | |
1982 | heads = repo.heads() |
|
1982 | heads = repo.heads() | |
1983 | if len(heads) > 2: |
|
1983 | if len(heads) > 2: | |
1984 | raise util.Abort(_('repo has %d heads - ' |
|
1984 | raise util.Abort(_('repo has %d heads - ' | |
1985 | 'please merge with an explicit rev') % |
|
1985 | 'please merge with an explicit rev') % | |
1986 | len(heads)) |
|
1986 | len(heads)) | |
1987 | if len(heads) == 1: |
|
1987 | if len(heads) == 1: | |
1988 | raise util.Abort(_('there is nothing to merge - ' |
|
1988 | raise util.Abort(_('there is nothing to merge - ' | |
1989 | 'use "hg update" instead')) |
|
1989 | 'use "hg update" instead')) | |
1990 | parent = repo.dirstate.parents()[0] |
|
1990 | parent = repo.dirstate.parents()[0] | |
1991 | if parent not in heads: |
|
1991 | if parent not in heads: | |
1992 | raise util.Abort(_('working dir not at a head rev - ' |
|
1992 | raise util.Abort(_('working dir not at a head rev - ' | |
1993 | 'use "hg update" or merge with an explicit rev')) |
|
1993 | 'use "hg update" or merge with an explicit rev')) | |
1994 | node = parent == heads[0] and heads[-1] or heads[0] |
|
1994 | node = parent == heads[0] and heads[-1] or heads[0] | |
1995 | return hg.merge(repo, node, force=force) |
|
1995 | return hg.merge(repo, node, force=force) | |
1996 |
|
1996 | |||
1997 | def outgoing(ui, repo, dest=None, **opts): |
|
1997 | def outgoing(ui, repo, dest=None, **opts): | |
1998 | """show changesets not found in destination |
|
1998 | """show changesets not found in destination | |
1999 |
|
1999 | |||
2000 | Show changesets not found in the specified destination repository or |
|
2000 | Show changesets not found in the specified destination repository or | |
2001 | the default push location. These are the changesets that would be pushed |
|
2001 | the default push location. These are the changesets that would be pushed | |
2002 | if a push was requested. |
|
2002 | if a push was requested. | |
2003 |
|
2003 | |||
2004 | See pull for valid destination format details. |
|
2004 | See pull for valid destination format details. | |
2005 | """ |
|
2005 | """ | |
2006 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
2006 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
2007 | setremoteconfig(ui, opts) |
|
2007 | setremoteconfig(ui, opts) | |
2008 | revs = None |
|
2008 | revs = None | |
2009 | if opts['rev']: |
|
2009 | if opts['rev']: | |
2010 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
2010 | revs = [repo.lookup(rev) for rev in opts['rev']] | |
2011 |
|
2011 | |||
2012 | other = hg.repository(ui, dest) |
|
2012 | other = hg.repository(ui, dest) | |
2013 | o = repo.findoutgoing(other, force=opts['force']) |
|
2013 | o = repo.findoutgoing(other, force=opts['force']) | |
2014 | if not o: |
|
2014 | if not o: | |
2015 | ui.status(_("no changes found\n")) |
|
2015 | ui.status(_("no changes found\n")) | |
2016 | return |
|
2016 | return | |
2017 | o = repo.changelog.nodesbetween(o, revs)[0] |
|
2017 | o = repo.changelog.nodesbetween(o, revs)[0] | |
2018 | if opts['newest_first']: |
|
2018 | if opts['newest_first']: | |
2019 | o.reverse() |
|
2019 | o.reverse() | |
2020 | displayer = show_changeset(ui, repo, opts) |
|
2020 | displayer = show_changeset(ui, repo, opts) | |
2021 | for n in o: |
|
2021 | for n in o: | |
2022 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
2022 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | |
2023 | if opts['no_merges'] and len(parents) == 2: |
|
2023 | if opts['no_merges'] and len(parents) == 2: | |
2024 | continue |
|
2024 | continue | |
2025 | displayer.show(changenode=n) |
|
2025 | displayer.show(changenode=n) | |
2026 | if opts['patch']: |
|
2026 | if opts['patch']: | |
2027 | prev = (parents and parents[0]) or nullid |
|
2027 | prev = (parents and parents[0]) or nullid | |
2028 | patch.diff(repo, prev, n) |
|
2028 | patch.diff(repo, prev, n) | |
2029 | ui.write("\n") |
|
2029 | ui.write("\n") | |
2030 |
|
2030 | |||
2031 | def parents(ui, repo, file_=None, rev=None, branches=None, **opts): |
|
2031 | def parents(ui, repo, file_=None, rev=None, branches=None, **opts): | |
2032 | """show the parents of the working dir or revision |
|
2032 | """show the parents of the working dir or revision | |
2033 |
|
2033 | |||
2034 | Print the working directory's parent revisions. |
|
2034 | Print the working directory's parent revisions. | |
2035 | """ |
|
2035 | """ | |
2036 | # legacy |
|
2036 | # legacy | |
2037 | if file_ and not rev: |
|
2037 | if file_ and not rev: | |
2038 | try: |
|
2038 | try: | |
2039 | rev = repo.lookup(file_) |
|
2039 | rev = repo.lookup(file_) | |
2040 | file_ = None |
|
2040 | file_ = None | |
2041 | except hg.RepoError: |
|
2041 | except hg.RepoError: | |
2042 | pass |
|
2042 | pass | |
2043 | else: |
|
2043 | else: | |
2044 | ui.warn(_("'hg parent REV' is deprecated, " |
|
2044 | ui.warn(_("'hg parent REV' is deprecated, " | |
2045 | "please use 'hg parents -r REV instead\n")) |
|
2045 | "please use 'hg parents -r REV instead\n")) | |
2046 |
|
2046 | |||
2047 | if rev: |
|
2047 | if rev: | |
2048 | if file_: |
|
2048 | if file_: | |
2049 | ctx = repo.filectx(file_, changeid=rev) |
|
2049 | ctx = repo.filectx(file_, changeid=rev) | |
2050 | else: |
|
2050 | else: | |
2051 | ctx = repo.changectx(rev) |
|
2051 | ctx = repo.changectx(rev) | |
2052 | p = [cp.node() for cp in ctx.parents()] |
|
2052 | p = [cp.node() for cp in ctx.parents()] | |
2053 | else: |
|
2053 | else: | |
2054 | p = repo.dirstate.parents() |
|
2054 | p = repo.dirstate.parents() | |
2055 |
|
2055 | |||
2056 | br = None |
|
2056 | br = None | |
2057 | if branches is not None: |
|
2057 | if branches is not None: | |
2058 | br = repo.branchlookup(p) |
|
2058 | br = repo.branchlookup(p) | |
2059 | displayer = show_changeset(ui, repo, opts) |
|
2059 | displayer = show_changeset(ui, repo, opts) | |
2060 | for n in p: |
|
2060 | for n in p: | |
2061 | if n != nullid: |
|
2061 | if n != nullid: | |
2062 | displayer.show(changenode=n, brinfo=br) |
|
2062 | displayer.show(changenode=n, brinfo=br) | |
2063 |
|
2063 | |||
2064 | def paths(ui, repo, search=None): |
|
2064 | def paths(ui, repo, search=None): | |
2065 | """show definition of symbolic path names |
|
2065 | """show definition of symbolic path names | |
2066 |
|
2066 | |||
2067 | Show definition of symbolic path name NAME. If no name is given, show |
|
2067 | Show definition of symbolic path name NAME. If no name is given, show | |
2068 | definition of available names. |
|
2068 | definition of available names. | |
2069 |
|
2069 | |||
2070 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
2070 | Path names are defined in the [paths] section of /etc/mercurial/hgrc | |
2071 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2071 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. | |
2072 | """ |
|
2072 | """ | |
2073 | if search: |
|
2073 | if search: | |
2074 | for name, path in ui.configitems("paths"): |
|
2074 | for name, path in ui.configitems("paths"): | |
2075 | if name == search: |
|
2075 | if name == search: | |
2076 | ui.write("%s\n" % path) |
|
2076 | ui.write("%s\n" % path) | |
2077 | return |
|
2077 | return | |
2078 | ui.warn(_("not found!\n")) |
|
2078 | ui.warn(_("not found!\n")) | |
2079 | return 1 |
|
2079 | return 1 | |
2080 | else: |
|
2080 | else: | |
2081 | for name, path in ui.configitems("paths"): |
|
2081 | for name, path in ui.configitems("paths"): | |
2082 | ui.write("%s = %s\n" % (name, path)) |
|
2082 | ui.write("%s = %s\n" % (name, path)) | |
2083 |
|
2083 | |||
2084 | def postincoming(ui, repo, modheads, optupdate): |
|
2084 | def postincoming(ui, repo, modheads, optupdate): | |
2085 | if modheads == 0: |
|
2085 | if modheads == 0: | |
2086 | return |
|
2086 | return | |
2087 | if optupdate: |
|
2087 | if optupdate: | |
2088 | if modheads == 1: |
|
2088 | if modheads == 1: | |
2089 | return hg.update(repo, repo.changelog.tip()) # update |
|
2089 | return hg.update(repo, repo.changelog.tip()) # update | |
2090 | else: |
|
2090 | else: | |
2091 | ui.status(_("not updating, since new heads added\n")) |
|
2091 | ui.status(_("not updating, since new heads added\n")) | |
2092 | if modheads > 1: |
|
2092 | if modheads > 1: | |
2093 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
2093 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | |
2094 | else: |
|
2094 | else: | |
2095 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2095 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2096 |
|
2096 | |||
2097 | def pull(ui, repo, source="default", **opts): |
|
2097 | def pull(ui, repo, source="default", **opts): | |
2098 | """pull changes from the specified source |
|
2098 | """pull changes from the specified source | |
2099 |
|
2099 | |||
2100 | Pull changes from a remote repository to a local one. |
|
2100 | Pull changes from a remote repository to a local one. | |
2101 |
|
2101 | |||
2102 | This finds all changes from the repository at the specified path |
|
2102 | This finds all changes from the repository at the specified path | |
2103 | or URL and adds them to the local repository. By default, this |
|
2103 | or URL and adds them to the local repository. By default, this | |
2104 | does not update the copy of the project in the working directory. |
|
2104 | does not update the copy of the project in the working directory. | |
2105 |
|
2105 | |||
2106 | Valid URLs are of the form: |
|
2106 | Valid URLs are of the form: | |
2107 |
|
2107 | |||
2108 | local/filesystem/path |
|
2108 | local/filesystem/path | |
2109 | http://[user@]host[:port]/[path] |
|
2109 | http://[user@]host[:port]/[path] | |
2110 | https://[user@]host[:port]/[path] |
|
2110 | https://[user@]host[:port]/[path] | |
2111 | ssh://[user@]host[:port]/[path] |
|
2111 | ssh://[user@]host[:port]/[path] | |
2112 |
|
2112 | |||
2113 | Some notes about using SSH with Mercurial: |
|
2113 | Some notes about using SSH with Mercurial: | |
2114 | - SSH requires an accessible shell account on the destination machine |
|
2114 | - SSH requires an accessible shell account on the destination machine | |
2115 | and a copy of hg in the remote path or specified with as remotecmd. |
|
2115 | and a copy of hg in the remote path or specified with as remotecmd. | |
2116 | - path is relative to the remote user's home directory by default. |
|
2116 | - path is relative to the remote user's home directory by default. | |
2117 | Use an extra slash at the start of a path to specify an absolute path: |
|
2117 | Use an extra slash at the start of a path to specify an absolute path: | |
2118 | ssh://example.com//tmp/repository |
|
2118 | ssh://example.com//tmp/repository | |
2119 | - Mercurial doesn't use its own compression via SSH; the right thing |
|
2119 | - Mercurial doesn't use its own compression via SSH; the right thing | |
2120 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: |
|
2120 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: | |
2121 | Host *.mylocalnetwork.example.com |
|
2121 | Host *.mylocalnetwork.example.com | |
2122 | Compression off |
|
2122 | Compression off | |
2123 | Host * |
|
2123 | Host * | |
2124 | Compression on |
|
2124 | Compression on | |
2125 | Alternatively specify "ssh -C" as your ssh command in your hgrc or |
|
2125 | Alternatively specify "ssh -C" as your ssh command in your hgrc or | |
2126 | with the --ssh command line option. |
|
2126 | with the --ssh command line option. | |
2127 | """ |
|
2127 | """ | |
2128 | source = ui.expandpath(source) |
|
2128 | source = ui.expandpath(source) | |
2129 | setremoteconfig(ui, opts) |
|
2129 | setremoteconfig(ui, opts) | |
2130 |
|
2130 | |||
2131 | other = hg.repository(ui, source) |
|
2131 | other = hg.repository(ui, source) | |
2132 | ui.status(_('pulling from %s\n') % (source)) |
|
2132 | ui.status(_('pulling from %s\n') % (source)) | |
2133 | revs = None |
|
2133 | revs = None | |
2134 | if opts['rev'] and not other.local(): |
|
2134 | if opts['rev'] and not other.local(): | |
2135 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) |
|
2135 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) | |
2136 | elif opts['rev']: |
|
2136 | elif opts['rev']: | |
2137 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
2137 | revs = [other.lookup(rev) for rev in opts['rev']] | |
2138 | modheads = repo.pull(other, heads=revs, force=opts['force']) |
|
2138 | modheads = repo.pull(other, heads=revs, force=opts['force']) | |
2139 | return postincoming(ui, repo, modheads, opts['update']) |
|
2139 | return postincoming(ui, repo, modheads, opts['update']) | |
2140 |
|
2140 | |||
2141 | def push(ui, repo, dest=None, **opts): |
|
2141 | def push(ui, repo, dest=None, **opts): | |
2142 | """push changes to the specified destination |
|
2142 | """push changes to the specified destination | |
2143 |
|
2143 | |||
2144 | Push changes from the local repository to the given destination. |
|
2144 | Push changes from the local repository to the given destination. | |
2145 |
|
2145 | |||
2146 | This is the symmetrical operation for pull. It helps to move |
|
2146 | This is the symmetrical operation for pull. It helps to move | |
2147 | changes from the current repository to a different one. If the |
|
2147 | changes from the current repository to a different one. If the | |
2148 | destination is local this is identical to a pull in that directory |
|
2148 | destination is local this is identical to a pull in that directory | |
2149 | from the current one. |
|
2149 | from the current one. | |
2150 |
|
2150 | |||
2151 | By default, push will refuse to run if it detects the result would |
|
2151 | By default, push will refuse to run if it detects the result would | |
2152 | increase the number of remote heads. This generally indicates the |
|
2152 | increase the number of remote heads. This generally indicates the | |
2153 | the client has forgotten to sync and merge before pushing. |
|
2153 | the client has forgotten to sync and merge before pushing. | |
2154 |
|
2154 | |||
2155 | Valid URLs are of the form: |
|
2155 | Valid URLs are of the form: | |
2156 |
|
2156 | |||
2157 | local/filesystem/path |
|
2157 | local/filesystem/path | |
2158 | ssh://[user@]host[:port]/[path] |
|
2158 | ssh://[user@]host[:port]/[path] | |
2159 |
|
2159 | |||
2160 | Look at the help text for the pull command for important details |
|
2160 | Look at the help text for the pull command for important details | |
2161 | about ssh:// URLs. |
|
2161 | about ssh:// URLs. | |
2162 |
|
2162 | |||
2163 | Pushing to http:// and https:// URLs is possible, too, if this |
|
2163 | Pushing to http:// and https:// URLs is possible, too, if this | |
2164 | feature is enabled on the remote Mercurial server. |
|
2164 | feature is enabled on the remote Mercurial server. | |
2165 | """ |
|
2165 | """ | |
2166 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
2166 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
2167 | setremoteconfig(ui, opts) |
|
2167 | setremoteconfig(ui, opts) | |
2168 |
|
2168 | |||
2169 | other = hg.repository(ui, dest) |
|
2169 | other = hg.repository(ui, dest) | |
2170 | ui.status('pushing to %s\n' % (dest)) |
|
2170 | ui.status('pushing to %s\n' % (dest)) | |
2171 | revs = None |
|
2171 | revs = None | |
2172 | if opts['rev']: |
|
2172 | if opts['rev']: | |
2173 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
2173 | revs = [repo.lookup(rev) for rev in opts['rev']] | |
2174 | r = repo.push(other, opts['force'], revs=revs) |
|
2174 | r = repo.push(other, opts['force'], revs=revs) | |
2175 | return r == 0 |
|
2175 | return r == 0 | |
2176 |
|
2176 | |||
2177 | def rawcommit(ui, repo, *flist, **rc): |
|
2177 | def rawcommit(ui, repo, *flist, **rc): | |
2178 | """raw commit interface (DEPRECATED) |
|
2178 | """raw commit interface (DEPRECATED) | |
2179 |
|
2179 | |||
2180 | (DEPRECATED) |
|
2180 | (DEPRECATED) | |
2181 | Lowlevel commit, for use in helper scripts. |
|
2181 | Lowlevel commit, for use in helper scripts. | |
2182 |
|
2182 | |||
2183 | This command is not intended to be used by normal users, as it is |
|
2183 | This command is not intended to be used by normal users, as it is | |
2184 | primarily useful for importing from other SCMs. |
|
2184 | primarily useful for importing from other SCMs. | |
2185 |
|
2185 | |||
2186 | This command is now deprecated and will be removed in a future |
|
2186 | This command is now deprecated and will be removed in a future | |
2187 | release, please use debugsetparents and commit instead. |
|
2187 | release, please use debugsetparents and commit instead. | |
2188 | """ |
|
2188 | """ | |
2189 |
|
2189 | |||
2190 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
2190 | ui.warn(_("(the rawcommit command is deprecated)\n")) | |
2191 |
|
2191 | |||
2192 | message = rc['message'] |
|
2192 | message = rc['message'] | |
2193 | if not message and rc['logfile']: |
|
2193 | if not message and rc['logfile']: | |
2194 | try: |
|
2194 | try: | |
2195 | message = open(rc['logfile']).read() |
|
2195 | message = open(rc['logfile']).read() | |
2196 | except IOError: |
|
2196 | except IOError: | |
2197 | pass |
|
2197 | pass | |
2198 | if not message and not rc['logfile']: |
|
2198 | if not message and not rc['logfile']: | |
2199 | raise util.Abort(_("missing commit message")) |
|
2199 | raise util.Abort(_("missing commit message")) | |
2200 |
|
2200 | |||
2201 | files = relpath(repo, list(flist)) |
|
2201 | files = relpath(repo, list(flist)) | |
2202 | if rc['files']: |
|
2202 | if rc['files']: | |
2203 | files += open(rc['files']).read().splitlines() |
|
2203 | files += open(rc['files']).read().splitlines() | |
2204 |
|
2204 | |||
2205 | rc['parent'] = map(repo.lookup, rc['parent']) |
|
2205 | rc['parent'] = map(repo.lookup, rc['parent']) | |
2206 |
|
2206 | |||
2207 | try: |
|
2207 | try: | |
2208 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) |
|
2208 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) | |
2209 | except ValueError, inst: |
|
2209 | except ValueError, inst: | |
2210 | raise util.Abort(str(inst)) |
|
2210 | raise util.Abort(str(inst)) | |
2211 |
|
2211 | |||
2212 | def recover(ui, repo): |
|
2212 | def recover(ui, repo): | |
2213 | """roll back an interrupted transaction |
|
2213 | """roll back an interrupted transaction | |
2214 |
|
2214 | |||
2215 | Recover from an interrupted commit or pull. |
|
2215 | Recover from an interrupted commit or pull. | |
2216 |
|
2216 | |||
2217 | This command tries to fix the repository status after an interrupted |
|
2217 | This command tries to fix the repository status after an interrupted | |
2218 | operation. It should only be necessary when Mercurial suggests it. |
|
2218 | operation. It should only be necessary when Mercurial suggests it. | |
2219 | """ |
|
2219 | """ | |
2220 | if repo.recover(): |
|
2220 | if repo.recover(): | |
2221 | return hg.verify(repo) |
|
2221 | return hg.verify(repo) | |
2222 | return 1 |
|
2222 | return 1 | |
2223 |
|
2223 | |||
2224 | def remove(ui, repo, *pats, **opts): |
|
2224 | def remove(ui, repo, *pats, **opts): | |
2225 | """remove the specified files on the next commit |
|
2225 | """remove the specified files on the next commit | |
2226 |
|
2226 | |||
2227 | Schedule the indicated files for removal from the repository. |
|
2227 | Schedule the indicated files for removal from the repository. | |
2228 |
|
2228 | |||
2229 | This command schedules the files to be removed at the next commit. |
|
2229 | This command schedules the files to be removed at the next commit. | |
2230 | This only removes files from the current branch, not from the |
|
2230 | This only removes files from the current branch, not from the | |
2231 | entire project history. If the files still exist in the working |
|
2231 | entire project history. If the files still exist in the working | |
2232 | directory, they will be deleted from it. If invoked with --after, |
|
2232 | directory, they will be deleted from it. If invoked with --after, | |
2233 | files that have been manually deleted are marked as removed. |
|
2233 | files that have been manually deleted are marked as removed. | |
2234 |
|
2234 | |||
2235 | Modified files and added files are not removed by default. To |
|
2235 | Modified files and added files are not removed by default. To | |
2236 | remove them, use the -f/--force option. |
|
2236 | remove them, use the -f/--force option. | |
2237 | """ |
|
2237 | """ | |
2238 | names = [] |
|
2238 | names = [] | |
2239 | if not opts['after'] and not pats: |
|
2239 | if not opts['after'] and not pats: | |
2240 | raise util.Abort(_('no files specified')) |
|
2240 | raise util.Abort(_('no files specified')) | |
2241 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
2241 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
2242 | exact = dict.fromkeys(files) |
|
2242 | exact = dict.fromkeys(files) | |
2243 | mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5] |
|
2243 | mardu = map(dict.fromkeys, repo.status(files=files, match=matchfn))[:5] | |
2244 | modified, added, removed, deleted, unknown = mardu |
|
2244 | modified, added, removed, deleted, unknown = mardu | |
2245 | remove, forget = [], [] |
|
2245 | remove, forget = [], [] | |
2246 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): |
|
2246 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts): | |
2247 | reason = None |
|
2247 | reason = None | |
2248 | if abs not in deleted and opts['after']: |
|
2248 | if abs not in deleted and opts['after']: | |
2249 | reason = _('is still present') |
|
2249 | reason = _('is still present') | |
2250 | elif abs in modified and not opts['force']: |
|
2250 | elif abs in modified and not opts['force']: | |
2251 | reason = _('is modified (use -f to force removal)') |
|
2251 | reason = _('is modified (use -f to force removal)') | |
2252 | elif abs in added: |
|
2252 | elif abs in added: | |
2253 | if opts['force']: |
|
2253 | if opts['force']: | |
2254 | forget.append(abs) |
|
2254 | forget.append(abs) | |
2255 | continue |
|
2255 | continue | |
2256 | reason = _('has been marked for add (use -f to force removal)') |
|
2256 | reason = _('has been marked for add (use -f to force removal)') | |
2257 | elif abs in unknown: |
|
2257 | elif abs in unknown: | |
2258 | reason = _('is not managed') |
|
2258 | reason = _('is not managed') | |
2259 | elif abs in removed: |
|
2259 | elif abs in removed: | |
2260 | continue |
|
2260 | continue | |
2261 | if reason: |
|
2261 | if reason: | |
2262 | if exact: |
|
2262 | if exact: | |
2263 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
2263 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | |
2264 | else: |
|
2264 | else: | |
2265 | if ui.verbose or not exact: |
|
2265 | if ui.verbose or not exact: | |
2266 | ui.status(_('removing %s\n') % rel) |
|
2266 | ui.status(_('removing %s\n') % rel) | |
2267 | remove.append(abs) |
|
2267 | remove.append(abs) | |
2268 | repo.forget(forget) |
|
2268 | repo.forget(forget) | |
2269 | repo.remove(remove, unlink=not opts['after']) |
|
2269 | repo.remove(remove, unlink=not opts['after']) | |
2270 |
|
2270 | |||
2271 | def rename(ui, repo, *pats, **opts): |
|
2271 | def rename(ui, repo, *pats, **opts): | |
2272 | """rename files; equivalent of copy + remove |
|
2272 | """rename files; equivalent of copy + remove | |
2273 |
|
2273 | |||
2274 | Mark dest as copies of sources; mark sources for deletion. If |
|
2274 | Mark dest as copies of sources; mark sources for deletion. If | |
2275 | dest is a directory, copies are put in that directory. If dest is |
|
2275 | dest is a directory, copies are put in that directory. If dest is | |
2276 | a file, there can only be one source. |
|
2276 | a file, there can only be one source. | |
2277 |
|
2277 | |||
2278 | By default, this command copies the contents of files as they |
|
2278 | By default, this command copies the contents of files as they | |
2279 | stand in the working directory. If invoked with --after, the |
|
2279 | stand in the working directory. If invoked with --after, the | |
2280 | operation is recorded, but no copying is performed. |
|
2280 | operation is recorded, but no copying is performed. | |
2281 |
|
2281 | |||
2282 | This command takes effect in the next commit. |
|
2282 | This command takes effect in the next commit. | |
2283 |
|
2283 | |||
2284 | NOTE: This command should be treated as experimental. While it |
|
2284 | NOTE: This command should be treated as experimental. While it | |
2285 | should properly record rename files, this information is not yet |
|
2285 | should properly record rename files, this information is not yet | |
2286 | fully used by merge, nor fully reported by log. |
|
2286 | fully used by merge, nor fully reported by log. | |
2287 | """ |
|
2287 | """ | |
2288 | wlock = repo.wlock(0) |
|
2288 | wlock = repo.wlock(0) | |
2289 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
2289 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
2290 | names = [] |
|
2290 | names = [] | |
2291 | for abs, rel, exact in copied: |
|
2291 | for abs, rel, exact in copied: | |
2292 | if ui.verbose or not exact: |
|
2292 | if ui.verbose or not exact: | |
2293 | ui.status(_('removing %s\n') % rel) |
|
2293 | ui.status(_('removing %s\n') % rel) | |
2294 | names.append(abs) |
|
2294 | names.append(abs) | |
2295 | if not opts.get('dry_run'): |
|
2295 | if not opts.get('dry_run'): | |
2296 | repo.remove(names, True, wlock) |
|
2296 | repo.remove(names, True, wlock) | |
2297 | return errs |
|
2297 | return errs | |
2298 |
|
2298 | |||
2299 | def revert(ui, repo, *pats, **opts): |
|
2299 | def revert(ui, repo, *pats, **opts): | |
2300 | """revert files or dirs to their states as of some revision |
|
2300 | """revert files or dirs to their states as of some revision | |
2301 |
|
2301 | |||
2302 | With no revision specified, revert the named files or directories |
|
2302 | With no revision specified, revert the named files or directories | |
2303 | to the contents they had in the parent of the working directory. |
|
2303 | to the contents they had in the parent of the working directory. | |
2304 | This restores the contents of the affected files to an unmodified |
|
2304 | This restores the contents of the affected files to an unmodified | |
2305 | state. If the working directory has two parents, you must |
|
2305 | state. If the working directory has two parents, you must | |
2306 | explicitly specify the revision to revert to. |
|
2306 | explicitly specify the revision to revert to. | |
2307 |
|
2307 | |||
2308 | Modified files are saved with a .orig suffix before reverting. |
|
2308 | Modified files are saved with a .orig suffix before reverting. | |
2309 | To disable these backups, use --no-backup. |
|
2309 | To disable these backups, use --no-backup. | |
2310 |
|
2310 | |||
2311 | Using the -r option, revert the given files or directories to |
|
2311 | Using the -r option, revert the given files or directories to | |
2312 | their contents as of a specific revision. This can be helpful to"roll |
|
2312 | their contents as of a specific revision. This can be helpful to"roll | |
2313 | back" some or all of a change that should not have been committed. |
|
2313 | back" some or all of a change that should not have been committed. | |
2314 |
|
2314 | |||
2315 | Revert modifies the working directory. It does not commit any |
|
2315 | Revert modifies the working directory. It does not commit any | |
2316 | changes, or change the parent of the working directory. If you |
|
2316 | changes, or change the parent of the working directory. If you | |
2317 | revert to a revision other than the parent of the working |
|
2317 | revert to a revision other than the parent of the working | |
2318 | directory, the reverted files will thus appear modified |
|
2318 | directory, the reverted files will thus appear modified | |
2319 | afterwards. |
|
2319 | afterwards. | |
2320 |
|
2320 | |||
2321 | If a file has been deleted, it is recreated. If the executable |
|
2321 | If a file has been deleted, it is recreated. If the executable | |
2322 | mode of a file was changed, it is reset. |
|
2322 | mode of a file was changed, it is reset. | |
2323 |
|
2323 | |||
2324 | If names are given, all files matching the names are reverted. |
|
2324 | If names are given, all files matching the names are reverted. | |
2325 |
|
2325 | |||
2326 | If no arguments are given, all files in the repository are reverted. |
|
2326 | If no arguments are given, all files in the repository are reverted. | |
2327 | """ |
|
2327 | """ | |
2328 | parent, p2 = repo.dirstate.parents() |
|
2328 | parent, p2 = repo.dirstate.parents() | |
2329 | if opts['rev']: |
|
2329 | if opts['rev']: | |
2330 | node = repo.lookup(opts['rev']) |
|
2330 | node = repo.lookup(opts['rev']) | |
2331 | elif p2 != nullid: |
|
2331 | elif p2 != nullid: | |
2332 | raise util.Abort(_('working dir has two parents; ' |
|
2332 | raise util.Abort(_('working dir has two parents; ' | |
2333 | 'you must specify the revision to revert to')) |
|
2333 | 'you must specify the revision to revert to')) | |
2334 | else: |
|
2334 | else: | |
2335 | node = parent |
|
2335 | node = parent | |
2336 | mf = repo.manifest.read(repo.changelog.read(node)[0]) |
|
2336 | mf = repo.manifest.read(repo.changelog.read(node)[0]) | |
2337 | if node == parent: |
|
2337 | if node == parent: | |
2338 | pmf = mf |
|
2338 | pmf = mf | |
2339 | else: |
|
2339 | else: | |
2340 | pmf = None |
|
2340 | pmf = None | |
2341 |
|
2341 | |||
2342 | wlock = repo.wlock() |
|
2342 | wlock = repo.wlock() | |
2343 |
|
2343 | |||
2344 | # need all matching names in dirstate and manifest of target rev, |
|
2344 | # need all matching names in dirstate and manifest of target rev, | |
2345 | # so have to walk both. do not print errors if files exist in one |
|
2345 | # so have to walk both. do not print errors if files exist in one | |
2346 | # but not other. |
|
2346 | # but not other. | |
2347 |
|
2347 | |||
2348 | names = {} |
|
2348 | names = {} | |
2349 | target_only = {} |
|
2349 | target_only = {} | |
2350 |
|
2350 | |||
2351 | # walk dirstate. |
|
2351 | # walk dirstate. | |
2352 |
|
2352 | |||
2353 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, |
|
2353 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, | |
2354 | badmatch=mf.has_key): |
|
2354 | badmatch=mf.has_key): | |
2355 | names[abs] = (rel, exact) |
|
2355 | names[abs] = (rel, exact) | |
2356 | if src == 'b': |
|
2356 | if src == 'b': | |
2357 | target_only[abs] = True |
|
2357 | target_only[abs] = True | |
2358 |
|
2358 | |||
2359 | # walk target manifest. |
|
2359 | # walk target manifest. | |
2360 |
|
2360 | |||
2361 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, |
|
2361 | for src, abs, rel, exact in cmdutil.walk(repo, pats, opts, node=node, | |
2362 | badmatch=names.has_key): |
|
2362 | badmatch=names.has_key): | |
2363 | if abs in names: continue |
|
2363 | if abs in names: continue | |
2364 | names[abs] = (rel, exact) |
|
2364 | names[abs] = (rel, exact) | |
2365 | target_only[abs] = True |
|
2365 | target_only[abs] = True | |
2366 |
|
2366 | |||
2367 | changes = repo.status(match=names.has_key, wlock=wlock)[:5] |
|
2367 | changes = repo.status(match=names.has_key, wlock=wlock)[:5] | |
2368 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
|
2368 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) | |
2369 |
|
2369 | |||
2370 | revert = ([], _('reverting %s\n')) |
|
2370 | revert = ([], _('reverting %s\n')) | |
2371 | add = ([], _('adding %s\n')) |
|
2371 | add = ([], _('adding %s\n')) | |
2372 | remove = ([], _('removing %s\n')) |
|
2372 | remove = ([], _('removing %s\n')) | |
2373 | forget = ([], _('forgetting %s\n')) |
|
2373 | forget = ([], _('forgetting %s\n')) | |
2374 | undelete = ([], _('undeleting %s\n')) |
|
2374 | undelete = ([], _('undeleting %s\n')) | |
2375 | update = {} |
|
2375 | update = {} | |
2376 |
|
2376 | |||
2377 | disptable = ( |
|
2377 | disptable = ( | |
2378 | # dispatch table: |
|
2378 | # dispatch table: | |
2379 | # file state |
|
2379 | # file state | |
2380 | # action if in target manifest |
|
2380 | # action if in target manifest | |
2381 | # action if not in target manifest |
|
2381 | # action if not in target manifest | |
2382 | # make backup if in target manifest |
|
2382 | # make backup if in target manifest | |
2383 | # make backup if not in target manifest |
|
2383 | # make backup if not in target manifest | |
2384 | (modified, revert, remove, True, True), |
|
2384 | (modified, revert, remove, True, True), | |
2385 | (added, revert, forget, True, False), |
|
2385 | (added, revert, forget, True, False), | |
2386 | (removed, undelete, None, False, False), |
|
2386 | (removed, undelete, None, False, False), | |
2387 | (deleted, revert, remove, False, False), |
|
2387 | (deleted, revert, remove, False, False), | |
2388 | (unknown, add, None, True, False), |
|
2388 | (unknown, add, None, True, False), | |
2389 | (target_only, add, None, False, False), |
|
2389 | (target_only, add, None, False, False), | |
2390 | ) |
|
2390 | ) | |
2391 |
|
2391 | |||
2392 | entries = names.items() |
|
2392 | entries = names.items() | |
2393 | entries.sort() |
|
2393 | entries.sort() | |
2394 |
|
2394 | |||
2395 | for abs, (rel, exact) in entries: |
|
2395 | for abs, (rel, exact) in entries: | |
2396 | mfentry = mf.get(abs) |
|
2396 | mfentry = mf.get(abs) | |
2397 | def handle(xlist, dobackup): |
|
2397 | def handle(xlist, dobackup): | |
2398 | xlist[0].append(abs) |
|
2398 | xlist[0].append(abs) | |
2399 | update[abs] = 1 |
|
2399 | update[abs] = 1 | |
2400 | if dobackup and not opts['no_backup'] and os.path.exists(rel): |
|
2400 | if dobackup and not opts['no_backup'] and os.path.exists(rel): | |
2401 | bakname = "%s.orig" % rel |
|
2401 | bakname = "%s.orig" % rel | |
2402 | ui.note(_('saving current version of %s as %s\n') % |
|
2402 | ui.note(_('saving current version of %s as %s\n') % | |
2403 | (rel, bakname)) |
|
2403 | (rel, bakname)) | |
2404 | if not opts.get('dry_run'): |
|
2404 | if not opts.get('dry_run'): | |
2405 | shutil.copyfile(rel, bakname) |
|
2405 | shutil.copyfile(rel, bakname) | |
2406 | shutil.copymode(rel, bakname) |
|
2406 | shutil.copymode(rel, bakname) | |
2407 | if ui.verbose or not exact: |
|
2407 | if ui.verbose or not exact: | |
2408 | ui.status(xlist[1] % rel) |
|
2408 | ui.status(xlist[1] % rel) | |
2409 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
2409 | for table, hitlist, misslist, backuphit, backupmiss in disptable: | |
2410 | if abs not in table: continue |
|
2410 | if abs not in table: continue | |
2411 | # file has changed in dirstate |
|
2411 | # file has changed in dirstate | |
2412 | if mfentry: |
|
2412 | if mfentry: | |
2413 | handle(hitlist, backuphit) |
|
2413 | handle(hitlist, backuphit) | |
2414 | elif misslist is not None: |
|
2414 | elif misslist is not None: | |
2415 | handle(misslist, backupmiss) |
|
2415 | handle(misslist, backupmiss) | |
2416 | else: |
|
2416 | else: | |
2417 | if exact: ui.warn(_('file not managed: %s\n' % rel)) |
|
2417 | if exact: ui.warn(_('file not managed: %s\n' % rel)) | |
2418 | break |
|
2418 | break | |
2419 | else: |
|
2419 | else: | |
2420 | # file has not changed in dirstate |
|
2420 | # file has not changed in dirstate | |
2421 | if node == parent: |
|
2421 | if node == parent: | |
2422 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) |
|
2422 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) | |
2423 | continue |
|
2423 | continue | |
2424 | if pmf is None: |
|
2424 | if pmf is None: | |
2425 | # only need parent manifest in this unlikely case, |
|
2425 | # only need parent manifest in this unlikely case, | |
2426 | # so do not read by default |
|
2426 | # so do not read by default | |
2427 | pmf = repo.manifest.read(repo.changelog.read(parent)[0]) |
|
2427 | pmf = repo.manifest.read(repo.changelog.read(parent)[0]) | |
2428 | if abs in pmf: |
|
2428 | if abs in pmf: | |
2429 | if mfentry: |
|
2429 | if mfentry: | |
2430 | # if version of file is same in parent and target |
|
2430 | # if version of file is same in parent and target | |
2431 | # manifests, do nothing |
|
2431 | # manifests, do nothing | |
2432 | if pmf[abs] != mfentry: |
|
2432 | if pmf[abs] != mfentry: | |
2433 | handle(revert, False) |
|
2433 | handle(revert, False) | |
2434 | else: |
|
2434 | else: | |
2435 | handle(remove, False) |
|
2435 | handle(remove, False) | |
2436 |
|
2436 | |||
2437 | if not opts.get('dry_run'): |
|
2437 | if not opts.get('dry_run'): | |
2438 | repo.dirstate.forget(forget[0]) |
|
2438 | repo.dirstate.forget(forget[0]) | |
2439 | r = hg.revert(repo, node, update.has_key, wlock) |
|
2439 | r = hg.revert(repo, node, update.has_key, wlock) | |
2440 | repo.dirstate.update(add[0], 'a') |
|
2440 | repo.dirstate.update(add[0], 'a') | |
2441 | repo.dirstate.update(undelete[0], 'n') |
|
2441 | repo.dirstate.update(undelete[0], 'n') | |
2442 | repo.dirstate.update(remove[0], 'r') |
|
2442 | repo.dirstate.update(remove[0], 'r') | |
2443 | return r |
|
2443 | return r | |
2444 |
|
2444 | |||
2445 | def rollback(ui, repo): |
|
2445 | def rollback(ui, repo): | |
2446 | """roll back the last transaction in this repository |
|
2446 | """roll back the last transaction in this repository | |
2447 |
|
2447 | |||
2448 | Roll back the last transaction in this repository, restoring the |
|
2448 | Roll back the last transaction in this repository, restoring the | |
2449 | project to its state prior to the transaction. |
|
2449 | project to its state prior to the transaction. | |
2450 |
|
2450 | |||
2451 | Transactions are used to encapsulate the effects of all commands |
|
2451 | Transactions are used to encapsulate the effects of all commands | |
2452 | that create new changesets or propagate existing changesets into a |
|
2452 | that create new changesets or propagate existing changesets into a | |
2453 | repository. For example, the following commands are transactional, |
|
2453 | repository. For example, the following commands are transactional, | |
2454 | and their effects can be rolled back: |
|
2454 | and their effects can be rolled back: | |
2455 |
|
2455 | |||
2456 | commit |
|
2456 | commit | |
2457 | import |
|
2457 | import | |
2458 | pull |
|
2458 | pull | |
2459 | push (with this repository as destination) |
|
2459 | push (with this repository as destination) | |
2460 | unbundle |
|
2460 | unbundle | |
2461 |
|
2461 | |||
2462 | This command should be used with care. There is only one level of |
|
2462 | This command should be used with care. There is only one level of | |
2463 | rollback, and there is no way to undo a rollback. |
|
2463 | rollback, and there is no way to undo a rollback. | |
2464 |
|
2464 | |||
2465 | This command is not intended for use on public repositories. Once |
|
2465 | This command is not intended for use on public repositories. Once | |
2466 | changes are visible for pull by other users, rolling a transaction |
|
2466 | changes are visible for pull by other users, rolling a transaction | |
2467 | back locally is ineffective (someone else may already have pulled |
|
2467 | back locally is ineffective (someone else may already have pulled | |
2468 | the changes). Furthermore, a race is possible with readers of the |
|
2468 | the changes). Furthermore, a race is possible with readers of the | |
2469 | repository; for example an in-progress pull from the repository |
|
2469 | repository; for example an in-progress pull from the repository | |
2470 | may fail if a rollback is performed. |
|
2470 | may fail if a rollback is performed. | |
2471 | """ |
|
2471 | """ | |
2472 | repo.rollback() |
|
2472 | repo.rollback() | |
2473 |
|
2473 | |||
2474 | def root(ui, repo): |
|
2474 | def root(ui, repo): | |
2475 | """print the root (top) of the current working dir |
|
2475 | """print the root (top) of the current working dir | |
2476 |
|
2476 | |||
2477 | Print the root directory of the current repository. |
|
2477 | Print the root directory of the current repository. | |
2478 | """ |
|
2478 | """ | |
2479 | ui.write(repo.root + "\n") |
|
2479 | ui.write(repo.root + "\n") | |
2480 |
|
2480 | |||
2481 | def serve(ui, repo, **opts): |
|
2481 | def serve(ui, repo, **opts): | |
2482 | """export the repository via HTTP |
|
2482 | """export the repository via HTTP | |
2483 |
|
2483 | |||
2484 | Start a local HTTP repository browser and pull server. |
|
2484 | Start a local HTTP repository browser and pull server. | |
2485 |
|
2485 | |||
2486 | By default, the server logs accesses to stdout and errors to |
|
2486 | By default, the server logs accesses to stdout and errors to | |
2487 | stderr. Use the "-A" and "-E" options to log to files. |
|
2487 | stderr. Use the "-A" and "-E" options to log to files. | |
2488 | """ |
|
2488 | """ | |
2489 |
|
2489 | |||
2490 | if opts["stdio"]: |
|
2490 | if opts["stdio"]: | |
2491 | if repo is None: |
|
2491 | if repo is None: | |
2492 | raise hg.RepoError(_('no repo found')) |
|
2492 | raise hg.RepoError(_('no repo found')) | |
2493 | s = sshserver.sshserver(ui, repo) |
|
2493 | s = sshserver.sshserver(ui, repo) | |
2494 | s.serve_forever() |
|
2494 | s.serve_forever() | |
2495 |
|
2495 | |||
2496 | optlist = ("name templates style address port ipv6" |
|
2496 | optlist = ("name templates style address port ipv6" | |
2497 | " accesslog errorlog webdir_conf") |
|
2497 | " accesslog errorlog webdir_conf") | |
2498 | for o in optlist.split(): |
|
2498 | for o in optlist.split(): | |
2499 | if opts[o]: |
|
2499 | if opts[o]: | |
2500 | ui.setconfig("web", o, opts[o]) |
|
2500 | ui.setconfig("web", o, opts[o]) | |
2501 |
|
2501 | |||
2502 | if repo is None and not ui.config("web", "webdir_conf"): |
|
2502 | if repo is None and not ui.config("web", "webdir_conf"): | |
2503 | raise hg.RepoError(_('no repo found')) |
|
2503 | raise hg.RepoError(_('no repo found')) | |
2504 |
|
2504 | |||
2505 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2505 | if opts['daemon'] and not opts['daemon_pipefds']: | |
2506 | rfd, wfd = os.pipe() |
|
2506 | rfd, wfd = os.pipe() | |
2507 | args = sys.argv[:] |
|
2507 | args = sys.argv[:] | |
2508 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2508 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | |
2509 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2509 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | |
2510 | args[0], args) |
|
2510 | args[0], args) | |
2511 | os.close(wfd) |
|
2511 | os.close(wfd) | |
2512 | os.read(rfd, 1) |
|
2512 | os.read(rfd, 1) | |
2513 | os._exit(0) |
|
2513 | os._exit(0) | |
2514 |
|
2514 | |||
2515 | try: |
|
2515 | try: | |
2516 | httpd = hgweb.server.create_server(ui, repo) |
|
2516 | httpd = hgweb.server.create_server(ui, repo) | |
2517 | except socket.error, inst: |
|
2517 | except socket.error, inst: | |
2518 | raise util.Abort(_('cannot start server: ') + inst.args[1]) |
|
2518 | raise util.Abort(_('cannot start server: ') + inst.args[1]) | |
2519 |
|
2519 | |||
2520 | if ui.verbose: |
|
2520 | if ui.verbose: | |
2521 | addr, port = httpd.socket.getsockname() |
|
2521 | addr, port = httpd.socket.getsockname() | |
2522 | if addr == '0.0.0.0': |
|
2522 | if addr == '0.0.0.0': | |
2523 | addr = socket.gethostname() |
|
2523 | addr = socket.gethostname() | |
2524 | else: |
|
2524 | else: | |
2525 | try: |
|
2525 | try: | |
2526 | addr = socket.gethostbyaddr(addr)[0] |
|
2526 | addr = socket.gethostbyaddr(addr)[0] | |
2527 | except socket.error: |
|
2527 | except socket.error: | |
2528 | pass |
|
2528 | pass | |
2529 | if port != 80: |
|
2529 | if port != 80: | |
2530 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) |
|
2530 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) | |
2531 | else: |
|
2531 | else: | |
2532 | ui.status(_('listening at http://%s/\n') % addr) |
|
2532 | ui.status(_('listening at http://%s/\n') % addr) | |
2533 |
|
2533 | |||
2534 | if opts['pid_file']: |
|
2534 | if opts['pid_file']: | |
2535 | fp = open(opts['pid_file'], 'w') |
|
2535 | fp = open(opts['pid_file'], 'w') | |
2536 | fp.write(str(os.getpid()) + '\n') |
|
2536 | fp.write(str(os.getpid()) + '\n') | |
2537 | fp.close() |
|
2537 | fp.close() | |
2538 |
|
2538 | |||
2539 | if opts['daemon_pipefds']: |
|
2539 | if opts['daemon_pipefds']: | |
2540 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2540 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | |
2541 | os.close(rfd) |
|
2541 | os.close(rfd) | |
2542 | os.write(wfd, 'y') |
|
2542 | os.write(wfd, 'y') | |
2543 | os.close(wfd) |
|
2543 | os.close(wfd) | |
2544 | sys.stdout.flush() |
|
2544 | sys.stdout.flush() | |
2545 | sys.stderr.flush() |
|
2545 | sys.stderr.flush() | |
2546 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2546 | fd = os.open(util.nulldev, os.O_RDWR) | |
2547 | if fd != 0: os.dup2(fd, 0) |
|
2547 | if fd != 0: os.dup2(fd, 0) | |
2548 | if fd != 1: os.dup2(fd, 1) |
|
2548 | if fd != 1: os.dup2(fd, 1) | |
2549 | if fd != 2: os.dup2(fd, 2) |
|
2549 | if fd != 2: os.dup2(fd, 2) | |
2550 | if fd not in (0, 1, 2): os.close(fd) |
|
2550 | if fd not in (0, 1, 2): os.close(fd) | |
2551 |
|
2551 | |||
2552 | httpd.serve_forever() |
|
2552 | httpd.serve_forever() | |
2553 |
|
2553 | |||
2554 | def status(ui, repo, *pats, **opts): |
|
2554 | def status(ui, repo, *pats, **opts): | |
2555 | """show changed files in the working directory |
|
2555 | """show changed files in the working directory | |
2556 |
|
2556 | |||
2557 | Show status of files in the repository. If names are given, only |
|
2557 | Show status of files in the repository. If names are given, only | |
2558 | files that match are shown. Files that are clean or ignored, are |
|
2558 | files that match are shown. Files that are clean or ignored, are | |
2559 | not listed unless -c (clean), -i (ignored) or -A is given. |
|
2559 | not listed unless -c (clean), -i (ignored) or -A is given. | |
2560 |
|
2560 | |||
2561 | The codes used to show the status of files are: |
|
2561 | The codes used to show the status of files are: | |
2562 | M = modified |
|
2562 | M = modified | |
2563 | A = added |
|
2563 | A = added | |
2564 | R = removed |
|
2564 | R = removed | |
2565 | C = clean |
|
2565 | C = clean | |
2566 | ! = deleted, but still tracked |
|
2566 | ! = deleted, but still tracked | |
2567 | ? = not tracked |
|
2567 | ? = not tracked | |
2568 | I = ignored (not shown by default) |
|
2568 | I = ignored (not shown by default) | |
2569 | = the previous added file was copied from here |
|
2569 | = the previous added file was copied from here | |
2570 | """ |
|
2570 | """ | |
2571 |
|
2571 | |||
2572 | all = opts['all'] |
|
2572 | all = opts['all'] | |
2573 |
|
2573 | |||
2574 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) |
|
2574 | files, matchfn, anypats = cmdutil.matchpats(repo, pats, opts) | |
2575 | cwd = (pats and repo.getcwd()) or '' |
|
2575 | cwd = (pats and repo.getcwd()) or '' | |
2576 | modified, added, removed, deleted, unknown, ignored, clean = [ |
|
2576 | modified, added, removed, deleted, unknown, ignored, clean = [ | |
2577 | [util.pathto(cwd, x) for x in n] |
|
2577 | [util.pathto(cwd, x) for x in n] | |
2578 | for n in repo.status(files=files, match=matchfn, |
|
2578 | for n in repo.status(files=files, match=matchfn, | |
2579 | list_ignored=all or opts['ignored'], |
|
2579 | list_ignored=all or opts['ignored'], | |
2580 | list_clean=all or opts['clean'])] |
|
2580 | list_clean=all or opts['clean'])] | |
2581 |
|
2581 | |||
2582 | changetypes = (('modified', 'M', modified), |
|
2582 | changetypes = (('modified', 'M', modified), | |
2583 | ('added', 'A', added), |
|
2583 | ('added', 'A', added), | |
2584 | ('removed', 'R', removed), |
|
2584 | ('removed', 'R', removed), | |
2585 | ('deleted', '!', deleted), |
|
2585 | ('deleted', '!', deleted), | |
2586 | ('unknown', '?', unknown), |
|
2586 | ('unknown', '?', unknown), | |
2587 | ('ignored', 'I', ignored)) |
|
2587 | ('ignored', 'I', ignored)) | |
2588 |
|
2588 | |||
2589 | explicit_changetypes = changetypes + (('clean', 'C', clean),) |
|
2589 | explicit_changetypes = changetypes + (('clean', 'C', clean),) | |
2590 |
|
2590 | |||
2591 | end = opts['print0'] and '\0' or '\n' |
|
2591 | end = opts['print0'] and '\0' or '\n' | |
2592 |
|
2592 | |||
2593 | for opt, char, changes in ([ct for ct in explicit_changetypes |
|
2593 | for opt, char, changes in ([ct for ct in explicit_changetypes | |
2594 | if all or opts[ct[0]]] |
|
2594 | if all or opts[ct[0]]] | |
2595 | or changetypes): |
|
2595 | or changetypes): | |
2596 | if opts['no_status']: |
|
2596 | if opts['no_status']: | |
2597 | format = "%%s%s" % end |
|
2597 | format = "%%s%s" % end | |
2598 | else: |
|
2598 | else: | |
2599 | format = "%s %%s%s" % (char, end) |
|
2599 | format = "%s %%s%s" % (char, end) | |
2600 |
|
2600 | |||
2601 | for f in changes: |
|
2601 | for f in changes: | |
2602 | ui.write(format % f) |
|
2602 | ui.write(format % f) | |
2603 | if ((all or opts.get('copies')) and not opts.get('no_status') |
|
2603 | if ((all or opts.get('copies')) and not opts.get('no_status') | |
2604 | and opt == 'added' and repo.dirstate.copies.has_key(f)): |
|
2604 | and opt == 'added' and repo.dirstate.copies.has_key(f)): | |
2605 | ui.write(' %s%s' % (repo.dirstate.copies[f], end)) |
|
2605 | ui.write(' %s%s' % (repo.dirstate.copies[f], end)) | |
2606 |
|
2606 | |||
2607 | def tag(ui, repo, name, rev_=None, **opts): |
|
2607 | def tag(ui, repo, name, rev_=None, **opts): | |
2608 | """add a tag for the current tip or a given revision |
|
2608 | """add a tag for the current tip or a given revision | |
2609 |
|
2609 | |||
2610 | Name a particular revision using <name>. |
|
2610 | Name a particular revision using <name>. | |
2611 |
|
2611 | |||
2612 | Tags are used to name particular revisions of the repository and are |
|
2612 | Tags are used to name particular revisions of the repository and are | |
2613 | very useful to compare different revision, to go back to significant |
|
2613 | very useful to compare different revision, to go back to significant | |
2614 | earlier versions or to mark branch points as releases, etc. |
|
2614 | earlier versions or to mark branch points as releases, etc. | |
2615 |
|
2615 | |||
2616 | If no revision is given, the parent of the working directory is used. |
|
2616 | If no revision is given, the parent of the working directory is used. | |
2617 |
|
2617 | |||
2618 | To facilitate version control, distribution, and merging of tags, |
|
2618 | To facilitate version control, distribution, and merging of tags, | |
2619 | they are stored as a file named ".hgtags" which is managed |
|
2619 | they are stored as a file named ".hgtags" which is managed | |
2620 | similarly to other project files and can be hand-edited if |
|
2620 | similarly to other project files and can be hand-edited if | |
2621 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2621 | necessary. The file '.hg/localtags' is used for local tags (not | |
2622 | shared among repositories). |
|
2622 | shared among repositories). | |
2623 | """ |
|
2623 | """ | |
2624 | if name in ['tip', '.']: |
|
2624 | if name in ['tip', '.']: | |
2625 | raise util.Abort(_("the name '%s' is reserved") % name) |
|
2625 | raise util.Abort(_("the name '%s' is reserved") % name) | |
2626 | if rev_ is not None: |
|
2626 | if rev_ is not None: | |
2627 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2627 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | |
2628 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2628 | "please use 'hg tag [-r REV] NAME' instead\n")) | |
2629 | if opts['rev']: |
|
2629 | if opts['rev']: | |
2630 | raise util.Abort(_("use only one form to specify the revision")) |
|
2630 | raise util.Abort(_("use only one form to specify the revision")) | |
2631 | if opts['rev']: |
|
2631 | if opts['rev']: | |
2632 | rev_ = opts['rev'] |
|
2632 | rev_ = opts['rev'] | |
2633 | if rev_: |
|
2633 | if rev_: | |
2634 | r = hex(repo.lookup(rev_)) |
|
2634 | r = hex(repo.lookup(rev_)) | |
2635 | else: |
|
2635 | else: | |
2636 | p1, p2 = repo.dirstate.parents() |
|
2636 | p1, p2 = repo.dirstate.parents() | |
2637 | if p1 == nullid: |
|
2637 | if p1 == nullid: | |
2638 | raise util.Abort(_('no revision to tag')) |
|
2638 | raise util.Abort(_('no revision to tag')) | |
2639 | if p2 != nullid: |
|
2639 | if p2 != nullid: | |
2640 | raise util.Abort(_('outstanding uncommitted merges')) |
|
2640 | raise util.Abort(_('outstanding uncommitted merges')) | |
2641 | r = hex(p1) |
|
2641 | r = hex(p1) | |
2642 |
|
2642 | |||
2643 | repo.tag(name, r, opts['local'], opts['message'], opts['user'], |
|
2643 | repo.tag(name, r, opts['local'], opts['message'], opts['user'], | |
2644 | opts['date']) |
|
2644 | opts['date']) | |
2645 |
|
2645 | |||
2646 | def tags(ui, repo): |
|
2646 | def tags(ui, repo): | |
2647 | """list repository tags |
|
2647 | """list repository tags | |
2648 |
|
2648 | |||
2649 | List the repository tags. |
|
2649 | List the repository tags. | |
2650 |
|
2650 | |||
2651 | This lists both regular and local tags. |
|
2651 | This lists both regular and local tags. | |
2652 | """ |
|
2652 | """ | |
2653 |
|
2653 | |||
2654 | l = repo.tagslist() |
|
2654 | l = repo.tagslist() | |
2655 | l.reverse() |
|
2655 | l.reverse() | |
2656 | for t, n in l: |
|
2656 | for t, n in l: | |
2657 | try: |
|
2657 | try: | |
2658 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) |
|
2658 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) | |
2659 | except KeyError: |
|
2659 | except KeyError: | |
2660 | r = " ?:?" |
|
2660 | r = " ?:?" | |
2661 | if ui.quiet: |
|
2661 | if ui.quiet: | |
2662 | ui.write("%s\n" % t) |
|
2662 | ui.write("%s\n" % t) | |
2663 | else: |
|
2663 | else: | |
2664 | ui.write("%-30s %s\n" % (t, r)) |
|
2664 | ui.write("%-30s %s\n" % (t, r)) | |
2665 |
|
2665 | |||
2666 | def tip(ui, repo, **opts): |
|
2666 | def tip(ui, repo, **opts): | |
2667 | """show the tip revision |
|
2667 | """show the tip revision | |
2668 |
|
2668 | |||
2669 | Show the tip revision. |
|
2669 | Show the tip revision. | |
2670 | """ |
|
2670 | """ | |
2671 | n = repo.changelog.tip() |
|
2671 | n = repo.changelog.tip() | |
2672 | br = None |
|
2672 | br = None | |
2673 | if opts['branches']: |
|
2673 | if opts['branches']: | |
2674 | br = repo.branchlookup([n]) |
|
2674 | br = repo.branchlookup([n]) | |
2675 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
|
2675 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) | |
2676 | if opts['patch']: |
|
2676 | if opts['patch']: | |
2677 | patch.diff(repo, repo.changelog.parents(n)[0], n) |
|
2677 | patch.diff(repo, repo.changelog.parents(n)[0], n) | |
2678 |
|
2678 | |||
2679 | def unbundle(ui, repo, fname, **opts): |
|
2679 | def unbundle(ui, repo, fname, **opts): | |
2680 | """apply a changegroup file |
|
2680 | """apply a changegroup file | |
2681 |
|
2681 | |||
2682 | Apply a compressed changegroup file generated by the bundle |
|
2682 | Apply a compressed changegroup file generated by the bundle | |
2683 | command. |
|
2683 | command. | |
2684 | """ |
|
2684 | """ | |
2685 | f = urllib.urlopen(fname) |
|
2685 | f = urllib.urlopen(fname) | |
2686 |
|
2686 | |||
2687 | header = f.read(6) |
|
2687 | header = f.read(6) | |
2688 | if not header.startswith("HG"): |
|
2688 | if not header.startswith("HG"): | |
2689 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) |
|
2689 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) | |
2690 | elif not header.startswith("HG10"): |
|
2690 | elif not header.startswith("HG10"): | |
2691 | raise util.Abort(_("%s: unknown bundle version") % fname) |
|
2691 | raise util.Abort(_("%s: unknown bundle version") % fname) | |
2692 | elif header == "HG10BZ": |
|
2692 | elif header == "HG10BZ": | |
2693 | def generator(f): |
|
2693 | def generator(f): | |
2694 | zd = bz2.BZ2Decompressor() |
|
2694 | zd = bz2.BZ2Decompressor() | |
2695 | zd.decompress("BZ") |
|
2695 | zd.decompress("BZ") | |
2696 | for chunk in f: |
|
2696 | for chunk in f: | |
2697 | yield zd.decompress(chunk) |
|
2697 | yield zd.decompress(chunk) | |
2698 | elif header == "HG10UN": |
|
2698 | elif header == "HG10UN": | |
2699 | def generator(f): |
|
2699 | def generator(f): | |
2700 | for chunk in f: |
|
2700 | for chunk in f: | |
2701 | yield chunk |
|
2701 | yield chunk | |
2702 | else: |
|
2702 | else: | |
2703 | raise util.Abort(_("%s: unknown bundle compression type") |
|
2703 | raise util.Abort(_("%s: unknown bundle compression type") | |
2704 | % fname) |
|
2704 | % fname) | |
2705 | gen = generator(util.filechunkiter(f, 4096)) |
|
2705 | gen = generator(util.filechunkiter(f, 4096)) | |
2706 | modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle', |
|
2706 | modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle', | |
2707 | 'bundle:' + fname) |
|
2707 | 'bundle:' + fname) | |
2708 | return postincoming(ui, repo, modheads, opts['update']) |
|
2708 | return postincoming(ui, repo, modheads, opts['update']) | |
2709 |
|
2709 | |||
2710 | def undo(ui, repo): |
|
2710 | def undo(ui, repo): | |
2711 | """undo the last commit or pull (DEPRECATED) |
|
2711 | """undo the last commit or pull (DEPRECATED) | |
2712 |
|
2712 | |||
2713 | (DEPRECATED) |
|
2713 | (DEPRECATED) | |
2714 | This command is now deprecated and will be removed in a future |
|
2714 | This command is now deprecated and will be removed in a future | |
2715 | release. Please use the rollback command instead. For usage |
|
2715 | release. Please use the rollback command instead. For usage | |
2716 | instructions, see the rollback command. |
|
2716 | instructions, see the rollback command. | |
2717 | """ |
|
2717 | """ | |
2718 | ui.warn(_('(the undo command is deprecated; use rollback instead)\n')) |
|
2718 | ui.warn(_('(the undo command is deprecated; use rollback instead)\n')) | |
2719 | repo.rollback() |
|
2719 | repo.rollback() | |
2720 |
|
2720 | |||
2721 | def update(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2721 | def update(ui, repo, node=None, merge=False, clean=False, force=None, | |
2722 | branch=None): |
|
2722 | branch=None): | |
2723 | """update or merge working directory |
|
2723 | """update or merge working directory | |
2724 |
|
2724 | |||
2725 | Update the working directory to the specified revision. |
|
2725 | Update the working directory to the specified revision. | |
2726 |
|
2726 | |||
2727 | If there are no outstanding changes in the working directory and |
|
2727 | If there are no outstanding changes in the working directory and | |
2728 | there is a linear relationship between the current version and the |
|
2728 | there is a linear relationship between the current version and the | |
2729 | requested version, the result is the requested version. |
|
2729 | requested version, the result is the requested version. | |
2730 |
|
2730 | |||
2731 | To merge the working directory with another revision, use the |
|
2731 | To merge the working directory with another revision, use the | |
2732 | merge command. |
|
2732 | merge command. | |
2733 |
|
2733 | |||
2734 | By default, update will refuse to run if doing so would require |
|
2734 | By default, update will refuse to run if doing so would require | |
2735 | merging or discarding local changes. |
|
2735 | merging or discarding local changes. | |
2736 | """ |
|
2736 | """ | |
2737 | node = _lookup(repo, node, branch) |
|
2737 | node = _lookup(repo, node, branch) | |
2738 | if merge: |
|
2738 | if merge: | |
2739 | ui.warn(_('(the -m/--merge option is deprecated; ' |
|
2739 | ui.warn(_('(the -m/--merge option is deprecated; ' | |
2740 | 'use the merge command instead)\n')) |
|
2740 | 'use the merge command instead)\n')) | |
2741 | return hg.merge(repo, node, force=force) |
|
2741 | return hg.merge(repo, node, force=force) | |
2742 | elif clean: |
|
2742 | elif clean: | |
2743 | return hg.clean(repo, node) |
|
2743 | return hg.clean(repo, node) | |
2744 | else: |
|
2744 | else: | |
2745 | return hg.update(repo, node) |
|
2745 | return hg.update(repo, node) | |
2746 |
|
2746 | |||
2747 | def _lookup(repo, node, branch=None): |
|
2747 | def _lookup(repo, node, branch=None): | |
2748 | if branch: |
|
2748 | if branch: | |
2749 | br = repo.branchlookup(branch=branch) |
|
2749 | br = repo.branchlookup(branch=branch) | |
2750 | found = [] |
|
2750 | found = [] | |
2751 | for x in br: |
|
2751 | for x in br: | |
2752 | if branch in br[x]: |
|
2752 | if branch in br[x]: | |
2753 | found.append(x) |
|
2753 | found.append(x) | |
2754 | if len(found) > 1: |
|
2754 | if len(found) > 1: | |
2755 | repo.ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2755 | repo.ui.warn(_("Found multiple heads for %s\n") % branch) | |
2756 | for x in found: |
|
2756 | for x in found: | |
2757 | show_changeset(ui, repo, {}).show(changenode=x, brinfo=br) |
|
2757 | show_changeset(ui, repo, {}).show(changenode=x, brinfo=br) | |
2758 | raise util.Abort("") |
|
2758 | raise util.Abort("") | |
2759 | if len(found) == 1: |
|
2759 | if len(found) == 1: | |
2760 | node = found[0] |
|
2760 | node = found[0] | |
2761 | repo.ui.warn(_("Using head %s for branch %s\n") |
|
2761 | repo.ui.warn(_("Using head %s for branch %s\n") | |
2762 | % (short(node), branch)) |
|
2762 | % (short(node), branch)) | |
2763 | else: |
|
2763 | else: | |
2764 | raise util.Abort(_("branch %s not found\n") % (branch)) |
|
2764 | raise util.Abort(_("branch %s not found\n") % (branch)) | |
2765 | else: |
|
2765 | else: | |
2766 | node = node and repo.lookup(node) or repo.changelog.tip() |
|
2766 | node = node and repo.lookup(node) or repo.changelog.tip() | |
2767 | return node |
|
2767 | return node | |
2768 |
|
2768 | |||
2769 | def verify(ui, repo): |
|
2769 | def verify(ui, repo): | |
2770 | """verify the integrity of the repository |
|
2770 | """verify the integrity of the repository | |
2771 |
|
2771 | |||
2772 | Verify the integrity of the current repository. |
|
2772 | Verify the integrity of the current repository. | |
2773 |
|
2773 | |||
2774 | This will perform an extensive check of the repository's |
|
2774 | This will perform an extensive check of the repository's | |
2775 | integrity, validating the hashes and checksums of each entry in |
|
2775 | integrity, validating the hashes and checksums of each entry in | |
2776 | the changelog, manifest, and tracked files, as well as the |
|
2776 | the changelog, manifest, and tracked files, as well as the | |
2777 | integrity of their crosslinks and indices. |
|
2777 | integrity of their crosslinks and indices. | |
2778 | """ |
|
2778 | """ | |
2779 | return hg.verify(repo) |
|
2779 | return hg.verify(repo) | |
2780 |
|
2780 | |||
2781 | # Command options and aliases are listed here, alphabetically |
|
2781 | # Command options and aliases are listed here, alphabetically | |
2782 |
|
2782 | |||
2783 | table = { |
|
2783 | table = { | |
2784 | "^add": |
|
2784 | "^add": | |
2785 | (add, |
|
2785 | (add, | |
2786 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2786 | [('I', 'include', [], _('include names matching the given patterns')), | |
2787 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
2787 | ('X', 'exclude', [], _('exclude names matching the given patterns')), | |
2788 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
2788 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], | |
2789 | _('hg add [OPTION]... [FILE]...')), |
|
2789 | _('hg add [OPTION]... [FILE]...')), | |
2790 | "debugaddremove|addremove": |
|
2790 | "debugaddremove|addremove": | |
2791 | (addremove, |
|
2791 | (addremove, | |
2792 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2792 | [('I', 'include', [], _('include names matching the given patterns')), | |
2793 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
2793 | ('X', 'exclude', [], _('exclude names matching the given patterns')), | |
2794 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
2794 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], | |
2795 | _('hg addremove [OPTION]... [FILE]...')), |
|
2795 | _('hg addremove [OPTION]... [FILE]...')), | |
2796 | "^annotate": |
|
2796 | "^annotate": | |
2797 | (annotate, |
|
2797 | (annotate, | |
2798 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2798 | [('r', 'rev', '', _('annotate the specified revision')), | |
2799 | ('a', 'text', None, _('treat all files as text')), |
|
2799 | ('a', 'text', None, _('treat all files as text')), | |
2800 | ('u', 'user', None, _('list the author')), |
|
2800 | ('u', 'user', None, _('list the author')), | |
2801 | ('d', 'date', None, _('list the date')), |
|
2801 | ('d', 'date', None, _('list the date')), | |
2802 | ('n', 'number', None, _('list the revision number (default)')), |
|
2802 | ('n', 'number', None, _('list the revision number (default)')), | |
2803 | ('c', 'changeset', None, _('list the changeset')), |
|
2803 | ('c', 'changeset', None, _('list the changeset')), | |
2804 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2804 | ('I', 'include', [], _('include names matching the given patterns')), | |
2805 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2805 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2806 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2806 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | |
2807 | "archive": |
|
2807 | "archive": | |
2808 | (archive, |
|
2808 | (archive, | |
2809 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
2809 | [('', 'no-decode', None, _('do not pass files through decoders')), | |
2810 | ('p', 'prefix', '', _('directory prefix for files in archive')), |
|
2810 | ('p', 'prefix', '', _('directory prefix for files in archive')), | |
2811 | ('r', 'rev', '', _('revision to distribute')), |
|
2811 | ('r', 'rev', '', _('revision to distribute')), | |
2812 | ('t', 'type', '', _('type of distribution to create')), |
|
2812 | ('t', 'type', '', _('type of distribution to create')), | |
2813 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2813 | ('I', 'include', [], _('include names matching the given patterns')), | |
2814 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2814 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2815 | _('hg archive [OPTION]... DEST')), |
|
2815 | _('hg archive [OPTION]... DEST')), | |
2816 | "backout": |
|
2816 | "backout": | |
2817 | (backout, |
|
2817 | (backout, | |
2818 | [('', 'merge', None, |
|
2818 | [('', 'merge', None, | |
2819 | _('merge with old dirstate parent after backout')), |
|
2819 | _('merge with old dirstate parent after backout')), | |
2820 | ('m', 'message', '', _('use <text> as commit message')), |
|
2820 | ('m', 'message', '', _('use <text> as commit message')), | |
2821 | ('l', 'logfile', '', _('read commit message from <file>')), |
|
2821 | ('l', 'logfile', '', _('read commit message from <file>')), | |
2822 | ('d', 'date', '', _('record datecode as commit date')), |
|
2822 | ('d', 'date', '', _('record datecode as commit date')), | |
2823 | ('', 'parent', '', _('parent to choose when backing out merge')), |
|
2823 | ('', 'parent', '', _('parent to choose when backing out merge')), | |
2824 | ('u', 'user', '', _('record user as committer')), |
|
2824 | ('u', 'user', '', _('record user as committer')), | |
2825 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2825 | ('I', 'include', [], _('include names matching the given patterns')), | |
2826 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2826 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2827 | _('hg backout [OPTION]... REV')), |
|
2827 | _('hg backout [OPTION]... REV')), | |
2828 | "bundle": |
|
2828 | "bundle": | |
2829 | (bundle, |
|
2829 | (bundle, | |
2830 | [('f', 'force', None, |
|
2830 | [('f', 'force', None, | |
2831 | _('run even when remote repository is unrelated'))], |
|
2831 | _('run even when remote repository is unrelated'))], | |
2832 | _('hg bundle FILE DEST')), |
|
2832 | _('hg bundle FILE DEST')), | |
2833 | "cat": |
|
2833 | "cat": | |
2834 | (cat, |
|
2834 | (cat, | |
2835 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2835 | [('o', 'output', '', _('print output to file with formatted name')), | |
2836 | ('r', 'rev', '', _('print the given revision')), |
|
2836 | ('r', 'rev', '', _('print the given revision')), | |
2837 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2837 | ('I', 'include', [], _('include names matching the given patterns')), | |
2838 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2838 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2839 | _('hg cat [OPTION]... FILE...')), |
|
2839 | _('hg cat [OPTION]... FILE...')), | |
2840 | "^clone": |
|
2840 | "^clone": | |
2841 | (clone, |
|
2841 | (clone, | |
2842 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2842 | [('U', 'noupdate', None, _('do not update the new working directory')), | |
2843 | ('r', 'rev', [], |
|
2843 | ('r', 'rev', [], | |
2844 | _('a changeset you would like to have after cloning')), |
|
2844 | _('a changeset you would like to have after cloning')), | |
2845 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2845 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
2846 | ('', 'uncompressed', None, |
|
2846 | ('', 'uncompressed', None, | |
2847 | _('use uncompressed transfer (fast over LAN)')), |
|
2847 | _('use uncompressed transfer (fast over LAN)')), | |
2848 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2848 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2849 | ('', 'remotecmd', '', |
|
2849 | ('', 'remotecmd', '', | |
2850 | _('specify hg command to run on the remote side'))], |
|
2850 | _('specify hg command to run on the remote side'))], | |
2851 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2851 | _('hg clone [OPTION]... SOURCE [DEST]')), | |
2852 | "^commit|ci": |
|
2852 | "^commit|ci": | |
2853 | (commit, |
|
2853 | (commit, | |
2854 | [('A', 'addremove', None, |
|
2854 | [('A', 'addremove', None, | |
2855 | _('mark new/missing files as added/removed before committing')), |
|
2855 | _('mark new/missing files as added/removed before committing')), | |
2856 | ('m', 'message', '', _('use <text> as commit message')), |
|
2856 | ('m', 'message', '', _('use <text> as commit message')), | |
2857 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
2857 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
2858 | ('d', 'date', '', _('record datecode as commit date')), |
|
2858 | ('d', 'date', '', _('record datecode as commit date')), | |
2859 | ('u', 'user', '', _('record user as commiter')), |
|
2859 | ('u', 'user', '', _('record user as commiter')), | |
2860 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2860 | ('I', 'include', [], _('include names matching the given patterns')), | |
2861 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2861 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2862 | _('hg commit [OPTION]... [FILE]...')), |
|
2862 | _('hg commit [OPTION]... [FILE]...')), | |
2863 | "copy|cp": |
|
2863 | "copy|cp": | |
2864 | (copy, |
|
2864 | (copy, | |
2865 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2865 | [('A', 'after', None, _('record a copy that has already occurred')), | |
2866 | ('f', 'force', None, |
|
2866 | ('f', 'force', None, | |
2867 | _('forcibly copy over an existing managed file')), |
|
2867 | _('forcibly copy over an existing managed file')), | |
2868 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2868 | ('I', 'include', [], _('include names matching the given patterns')), | |
2869 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
2869 | ('X', 'exclude', [], _('exclude names matching the given patterns')), | |
2870 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
2870 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], | |
2871 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2871 | _('hg copy [OPTION]... [SOURCE]... DEST')), | |
2872 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2872 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | |
2873 | "debugcomplete": |
|
2873 | "debugcomplete": | |
2874 | (debugcomplete, |
|
2874 | (debugcomplete, | |
2875 | [('o', 'options', None, _('show the command options'))], |
|
2875 | [('o', 'options', None, _('show the command options'))], | |
2876 | _('debugcomplete [-o] CMD')), |
|
2876 | _('debugcomplete [-o] CMD')), | |
2877 | "debugrebuildstate": |
|
2877 | "debugrebuildstate": | |
2878 | (debugrebuildstate, |
|
2878 | (debugrebuildstate, | |
2879 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2879 | [('r', 'rev', '', _('revision to rebuild to'))], | |
2880 | _('debugrebuildstate [-r REV] [REV]')), |
|
2880 | _('debugrebuildstate [-r REV] [REV]')), | |
2881 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2881 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | |
2882 | "debugconfig": (debugconfig, [], _('debugconfig [NAME]...')), |
|
2882 | "debugconfig": (debugconfig, [], _('debugconfig [NAME]...')), | |
2883 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2883 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | |
2884 | "debugstate": (debugstate, [], _('debugstate')), |
|
2884 | "debugstate": (debugstate, [], _('debugstate')), | |
2885 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2885 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | |
2886 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2886 | "debugindex": (debugindex, [], _('debugindex FILE')), | |
2887 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2887 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | |
2888 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2888 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), | |
2889 | "debugwalk": |
|
2889 | "debugwalk": | |
2890 | (debugwalk, |
|
2890 | (debugwalk, | |
2891 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2891 | [('I', 'include', [], _('include names matching the given patterns')), | |
2892 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2892 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2893 | _('debugwalk [OPTION]... [FILE]...')), |
|
2893 | _('debugwalk [OPTION]... [FILE]...')), | |
2894 | "^diff": |
|
2894 | "^diff": | |
2895 | (diff, |
|
2895 | (diff, | |
2896 | [('r', 'rev', [], _('revision')), |
|
2896 | [('r', 'rev', [], _('revision')), | |
2897 | ('a', 'text', None, _('treat all files as text')), |
|
2897 | ('a', 'text', None, _('treat all files as text')), | |
2898 | ('p', 'show-function', None, |
|
2898 | ('p', 'show-function', None, | |
2899 | _('show which function each change is in')), |
|
2899 | _('show which function each change is in')), | |
2900 | ('g', 'git', None, _('use git extended diff format')), |
|
2900 | ('g', 'git', None, _('use git extended diff format')), | |
2901 | ('w', 'ignore-all-space', None, |
|
2901 | ('w', 'ignore-all-space', None, | |
2902 | _('ignore white space when comparing lines')), |
|
2902 | _('ignore white space when comparing lines')), | |
2903 | ('b', 'ignore-space-change', None, |
|
2903 | ('b', 'ignore-space-change', None, | |
2904 | _('ignore changes in the amount of white space')), |
|
2904 | _('ignore changes in the amount of white space')), | |
2905 | ('B', 'ignore-blank-lines', None, |
|
2905 | ('B', 'ignore-blank-lines', None, | |
2906 | _('ignore changes whose lines are all blank')), |
|
2906 | _('ignore changes whose lines are all blank')), | |
2907 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2907 | ('I', 'include', [], _('include names matching the given patterns')), | |
2908 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2908 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2909 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), |
|
2909 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), | |
2910 | "^export": |
|
2910 | "^export": | |
2911 | (export, |
|
2911 | (export, | |
2912 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2912 | [('o', 'output', '', _('print output to file with formatted name')), | |
2913 | ('a', 'text', None, _('treat all files as text')), |
|
2913 | ('a', 'text', None, _('treat all files as text')), | |
2914 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2914 | ('', 'switch-parent', None, _('diff against the second parent'))], | |
2915 | _('hg export [-a] [-o OUTFILESPEC] REV...')), |
|
2915 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | |
2916 | "debugforget|forget": |
|
2916 | "debugforget|forget": | |
2917 | (forget, |
|
2917 | (forget, | |
2918 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2918 | [('I', 'include', [], _('include names matching the given patterns')), | |
2919 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2919 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2920 | _('hg forget [OPTION]... FILE...')), |
|
2920 | _('hg forget [OPTION]... FILE...')), | |
2921 | "grep": |
|
2921 | "grep": | |
2922 | (grep, |
|
2922 | (grep, | |
2923 | [('0', 'print0', None, _('end fields with NUL')), |
|
2923 | [('0', 'print0', None, _('end fields with NUL')), | |
2924 | ('', 'all', None, _('print all revisions that match')), |
|
2924 | ('', 'all', None, _('print all revisions that match')), | |
2925 | ('f', 'follow', None, |
|
2925 | ('f', 'follow', None, | |
2926 | _('follow changeset history, or file history across copies and renames')), |
|
2926 | _('follow changeset history, or file history across copies and renames')), | |
2927 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2927 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2928 | ('l', 'files-with-matches', None, |
|
2928 | ('l', 'files-with-matches', None, | |
2929 | _('print only filenames and revs that match')), |
|
2929 | _('print only filenames and revs that match')), | |
2930 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2930 | ('n', 'line-number', None, _('print matching line numbers')), | |
2931 | ('r', 'rev', [], _('search in given revision range')), |
|
2931 | ('r', 'rev', [], _('search in given revision range')), | |
2932 | ('u', 'user', None, _('print user who committed change')), |
|
2932 | ('u', 'user', None, _('print user who committed change')), | |
2933 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2933 | ('I', 'include', [], _('include names matching the given patterns')), | |
2934 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2934 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2935 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2935 | _('hg grep [OPTION]... PATTERN [FILE]...')), | |
2936 | "heads": |
|
2936 | "heads": | |
2937 | (heads, |
|
2937 | (heads, | |
2938 | [('b', 'branches', None, _('show branches')), |
|
2938 | [('b', 'branches', None, _('show branches')), | |
2939 | ('', 'style', '', _('display using template map file')), |
|
2939 | ('', 'style', '', _('display using template map file')), | |
2940 | ('r', 'rev', '', _('show only heads which are descendants of rev')), |
|
2940 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | |
2941 | ('', 'template', '', _('display with template'))], |
|
2941 | ('', 'template', '', _('display with template'))], | |
2942 | _('hg heads [-b] [-r <rev>]')), |
|
2942 | _('hg heads [-b] [-r <rev>]')), | |
2943 | "help": (help_, [], _('hg help [COMMAND]')), |
|
2943 | "help": (help_, [], _('hg help [COMMAND]')), | |
2944 | "identify|id": (identify, [], _('hg identify')), |
|
2944 | "identify|id": (identify, [], _('hg identify')), | |
2945 | "import|patch": |
|
2945 | "import|patch": | |
2946 | (import_, |
|
2946 | (import_, | |
2947 | [('p', 'strip', 1, |
|
2947 | [('p', 'strip', 1, | |
2948 | _('directory strip option for patch. This has the same\n' |
|
2948 | _('directory strip option for patch. This has the same\n' | |
2949 | 'meaning as the corresponding patch option')), |
|
2949 | 'meaning as the corresponding patch option')), | |
2950 | ('m', 'message', '', _('use <text> as commit message')), |
|
2950 | ('m', 'message', '', _('use <text> as commit message')), | |
2951 | ('b', 'base', '', _('base path')), |
|
2951 | ('b', 'base', '', _('base path')), | |
2952 | ('f', 'force', None, |
|
2952 | ('f', 'force', None, | |
2953 | _('skip check for outstanding uncommitted changes'))], |
|
2953 | _('skip check for outstanding uncommitted changes'))], | |
2954 | _('hg import [-p NUM] [-b BASE] [-m MESSAGE] [-f] PATCH...')), |
|
2954 | _('hg import [-p NUM] [-b BASE] [-m MESSAGE] [-f] PATCH...')), | |
2955 | "incoming|in": (incoming, |
|
2955 | "incoming|in": (incoming, | |
2956 | [('M', 'no-merges', None, _('do not show merges')), |
|
2956 | [('M', 'no-merges', None, _('do not show merges')), | |
2957 | ('f', 'force', None, |
|
2957 | ('f', 'force', None, | |
2958 | _('run even when remote repository is unrelated')), |
|
2958 | _('run even when remote repository is unrelated')), | |
2959 | ('', 'style', '', _('display using template map file')), |
|
2959 | ('', 'style', '', _('display using template map file')), | |
2960 | ('n', 'newest-first', None, _('show newest record first')), |
|
2960 | ('n', 'newest-first', None, _('show newest record first')), | |
2961 | ('', 'bundle', '', _('file to store the bundles into')), |
|
2961 | ('', 'bundle', '', _('file to store the bundles into')), | |
2962 | ('p', 'patch', None, _('show patch')), |
|
2962 | ('p', 'patch', None, _('show patch')), | |
2963 | ('r', 'rev', [], _('a specific revision up to which you would like to pull')), |
|
2963 | ('r', 'rev', [], _('a specific revision up to which you would like to pull')), | |
2964 | ('', 'template', '', _('display with template')), |
|
2964 | ('', 'template', '', _('display with template')), | |
2965 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2965 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2966 | ('', 'remotecmd', '', |
|
2966 | ('', 'remotecmd', '', | |
2967 | _('specify hg command to run on the remote side'))], |
|
2967 | _('specify hg command to run on the remote side'))], | |
2968 | _('hg incoming [-p] [-n] [-M] [-r REV]...' |
|
2968 | _('hg incoming [-p] [-n] [-M] [-r REV]...' | |
2969 | ' [--bundle FILENAME] [SOURCE]')), |
|
2969 | ' [--bundle FILENAME] [SOURCE]')), | |
2970 | "^init": |
|
2970 | "^init": | |
2971 | (init, |
|
2971 | (init, | |
2972 | [('e', 'ssh', '', _('specify ssh command to use')), |
|
2972 | [('e', 'ssh', '', _('specify ssh command to use')), | |
2973 | ('', 'remotecmd', '', |
|
2973 | ('', 'remotecmd', '', | |
2974 | _('specify hg command to run on the remote side'))], |
|
2974 | _('specify hg command to run on the remote side'))], | |
2975 | _('hg init [-e FILE] [--remotecmd FILE] [DEST]')), |
|
2975 | _('hg init [-e FILE] [--remotecmd FILE] [DEST]')), | |
2976 | "locate": |
|
2976 | "locate": | |
2977 | (locate, |
|
2977 | (locate, | |
2978 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
2978 | [('r', 'rev', '', _('search the repository as it stood at rev')), | |
2979 | ('0', 'print0', None, |
|
2979 | ('0', 'print0', None, | |
2980 | _('end filenames with NUL, for use with xargs')), |
|
2980 | _('end filenames with NUL, for use with xargs')), | |
2981 | ('f', 'fullpath', None, |
|
2981 | ('f', 'fullpath', None, | |
2982 | _('print complete paths from the filesystem root')), |
|
2982 | _('print complete paths from the filesystem root')), | |
2983 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2983 | ('I', 'include', [], _('include names matching the given patterns')), | |
2984 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2984 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2985 | _('hg locate [OPTION]... [PATTERN]...')), |
|
2985 | _('hg locate [OPTION]... [PATTERN]...')), | |
2986 | "^log|history": |
|
2986 | "^log|history": | |
2987 | (log, |
|
2987 | (log, | |
2988 | [('b', 'branches', None, _('show branches')), |
|
2988 | [('b', 'branches', None, _('show branches')), | |
2989 | ('f', 'follow', None, |
|
2989 | ('f', 'follow', None, | |
2990 | _('follow changeset history, or file history across copies and renames')), |
|
2990 | _('follow changeset history, or file history across copies and renames')), | |
2991 | ('', 'follow-first', None, |
|
2991 | ('', 'follow-first', None, | |
2992 | _('only follow the first parent of merge changesets')), |
|
2992 | _('only follow the first parent of merge changesets')), | |
2993 | ('k', 'keyword', [], _('search for a keyword')), |
|
2993 | ('k', 'keyword', [], _('search for a keyword')), | |
2994 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
2994 | ('l', 'limit', '', _('limit number of changes displayed')), | |
2995 | ('r', 'rev', [], _('show the specified revision or range')), |
|
2995 | ('r', 'rev', [], _('show the specified revision or range')), | |
2996 | ('M', 'no-merges', None, _('do not show merges')), |
|
2996 | ('M', 'no-merges', None, _('do not show merges')), | |
2997 | ('', 'style', '', _('display using template map file')), |
|
2997 | ('', 'style', '', _('display using template map file')), | |
2998 | ('m', 'only-merges', None, _('show only merges')), |
|
2998 | ('m', 'only-merges', None, _('show only merges')), | |
2999 | ('p', 'patch', None, _('show patch')), |
|
2999 | ('p', 'patch', None, _('show patch')), | |
3000 | ('P', 'prune', [], _('do not display revision or any of its ancestors')), |
|
3000 | ('P', 'prune', [], _('do not display revision or any of its ancestors')), | |
3001 | ('', 'template', '', _('display with template')), |
|
3001 | ('', 'template', '', _('display with template')), | |
3002 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3002 | ('I', 'include', [], _('include names matching the given patterns')), | |
3003 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3003 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3004 | _('hg log [OPTION]... [FILE]')), |
|
3004 | _('hg log [OPTION]... [FILE]')), | |
3005 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
3005 | "manifest": (manifest, [], _('hg manifest [REV]')), | |
3006 | "merge": |
|
3006 | "merge": | |
3007 | (merge, |
|
3007 | (merge, | |
3008 | [('b', 'branch', '', _('merge with head of a specific branch')), |
|
3008 | [('b', 'branch', '', _('merge with head of a specific branch')), | |
3009 | ('f', 'force', None, _('force a merge with outstanding changes'))], |
|
3009 | ('f', 'force', None, _('force a merge with outstanding changes'))], | |
3010 | _('hg merge [-b TAG] [-f] [REV]')), |
|
3010 | _('hg merge [-b TAG] [-f] [REV]')), | |
3011 | "outgoing|out": (outgoing, |
|
3011 | "outgoing|out": (outgoing, | |
3012 | [('M', 'no-merges', None, _('do not show merges')), |
|
3012 | [('M', 'no-merges', None, _('do not show merges')), | |
3013 | ('f', 'force', None, |
|
3013 | ('f', 'force', None, | |
3014 | _('run even when remote repository is unrelated')), |
|
3014 | _('run even when remote repository is unrelated')), | |
3015 | ('p', 'patch', None, _('show patch')), |
|
3015 | ('p', 'patch', None, _('show patch')), | |
3016 | ('', 'style', '', _('display using template map file')), |
|
3016 | ('', 'style', '', _('display using template map file')), | |
3017 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
3017 | ('r', 'rev', [], _('a specific revision you would like to push')), | |
3018 | ('n', 'newest-first', None, _('show newest record first')), |
|
3018 | ('n', 'newest-first', None, _('show newest record first')), | |
3019 | ('', 'template', '', _('display with template')), |
|
3019 | ('', 'template', '', _('display with template')), | |
3020 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3020 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3021 | ('', 'remotecmd', '', |
|
3021 | ('', 'remotecmd', '', | |
3022 | _('specify hg command to run on the remote side'))], |
|
3022 | _('specify hg command to run on the remote side'))], | |
3023 | _('hg outgoing [-M] [-p] [-n] [-r REV]... [DEST]')), |
|
3023 | _('hg outgoing [-M] [-p] [-n] [-r REV]... [DEST]')), | |
3024 | "^parents": |
|
3024 | "^parents": | |
3025 | (parents, |
|
3025 | (parents, | |
3026 | [('b', 'branches', None, _('show branches')), |
|
3026 | [('b', 'branches', None, _('show branches')), | |
3027 | ('r', 'rev', '', _('show parents from the specified rev')), |
|
3027 | ('r', 'rev', '', _('show parents from the specified rev')), | |
3028 | ('', 'style', '', _('display using template map file')), |
|
3028 | ('', 'style', '', _('display using template map file')), | |
3029 | ('', 'template', '', _('display with template'))], |
|
3029 | ('', 'template', '', _('display with template'))], | |
3030 | _('hg parents [-b] [-r REV] [FILE]')), |
|
3030 | _('hg parents [-b] [-r REV] [FILE]')), | |
3031 | "paths": (paths, [], _('hg paths [NAME]')), |
|
3031 | "paths": (paths, [], _('hg paths [NAME]')), | |
3032 | "^pull": |
|
3032 | "^pull": | |
3033 | (pull, |
|
3033 | (pull, | |
3034 | [('u', 'update', None, |
|
3034 | [('u', 'update', None, | |
3035 | _('update the working directory to tip after pull')), |
|
3035 | _('update the working directory to tip after pull')), | |
3036 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3036 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3037 | ('f', 'force', None, |
|
3037 | ('f', 'force', None, | |
3038 | _('run even when remote repository is unrelated')), |
|
3038 | _('run even when remote repository is unrelated')), | |
3039 | ('r', 'rev', [], _('a specific revision up to which you would like to pull')), |
|
3039 | ('r', 'rev', [], _('a specific revision up to which you would like to pull')), | |
3040 | ('', 'remotecmd', '', |
|
3040 | ('', 'remotecmd', '', | |
3041 | _('specify hg command to run on the remote side'))], |
|
3041 | _('specify hg command to run on the remote side'))], | |
3042 | _('hg pull [-u] [-r REV]... [-e FILE] [--remotecmd FILE] [SOURCE]')), |
|
3042 | _('hg pull [-u] [-r REV]... [-e FILE] [--remotecmd FILE] [SOURCE]')), | |
3043 | "^push": |
|
3043 | "^push": | |
3044 | (push, |
|
3044 | (push, | |
3045 | [('f', 'force', None, _('force push')), |
|
3045 | [('f', 'force', None, _('force push')), | |
3046 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3046 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3047 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
3047 | ('r', 'rev', [], _('a specific revision you would like to push')), | |
3048 | ('', 'remotecmd', '', |
|
3048 | ('', 'remotecmd', '', | |
3049 | _('specify hg command to run on the remote side'))], |
|
3049 | _('specify hg command to run on the remote side'))], | |
3050 | _('hg push [-f] [-r REV]... [-e FILE] [--remotecmd FILE] [DEST]')), |
|
3050 | _('hg push [-f] [-r REV]... [-e FILE] [--remotecmd FILE] [DEST]')), | |
3051 | "debugrawcommit|rawcommit": |
|
3051 | "debugrawcommit|rawcommit": | |
3052 | (rawcommit, |
|
3052 | (rawcommit, | |
3053 | [('p', 'parent', [], _('parent')), |
|
3053 | [('p', 'parent', [], _('parent')), | |
3054 | ('d', 'date', '', _('date code')), |
|
3054 | ('d', 'date', '', _('date code')), | |
3055 | ('u', 'user', '', _('user')), |
|
3055 | ('u', 'user', '', _('user')), | |
3056 | ('F', 'files', '', _('file list')), |
|
3056 | ('F', 'files', '', _('file list')), | |
3057 | ('m', 'message', '', _('commit message')), |
|
3057 | ('m', 'message', '', _('commit message')), | |
3058 | ('l', 'logfile', '', _('commit message file'))], |
|
3058 | ('l', 'logfile', '', _('commit message file'))], | |
3059 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
3059 | _('hg debugrawcommit [OPTION]... [FILE]...')), | |
3060 | "recover": (recover, [], _('hg recover')), |
|
3060 | "recover": (recover, [], _('hg recover')), | |
3061 | "^remove|rm": |
|
3061 | "^remove|rm": | |
3062 | (remove, |
|
3062 | (remove, | |
3063 | [('A', 'after', None, _('record remove that has already occurred')), |
|
3063 | [('A', 'after', None, _('record remove that has already occurred')), | |
3064 | ('f', 'force', None, _('remove file even if modified')), |
|
3064 | ('f', 'force', None, _('remove file even if modified')), | |
3065 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3065 | ('I', 'include', [], _('include names matching the given patterns')), | |
3066 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3066 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3067 | _('hg remove [OPTION]... FILE...')), |
|
3067 | _('hg remove [OPTION]... FILE...')), | |
3068 | "rename|mv": |
|
3068 | "rename|mv": | |
3069 | (rename, |
|
3069 | (rename, | |
3070 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
3070 | [('A', 'after', None, _('record a rename that has already occurred')), | |
3071 | ('f', 'force', None, |
|
3071 | ('f', 'force', None, | |
3072 | _('forcibly copy over an existing managed file')), |
|
3072 | _('forcibly copy over an existing managed file')), | |
3073 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3073 | ('I', 'include', [], _('include names matching the given patterns')), | |
3074 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
3074 | ('X', 'exclude', [], _('exclude names matching the given patterns')), | |
3075 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
3075 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], | |
3076 | _('hg rename [OPTION]... SOURCE... DEST')), |
|
3076 | _('hg rename [OPTION]... SOURCE... DEST')), | |
3077 | "^revert": |
|
3077 | "^revert": | |
3078 | (revert, |
|
3078 | (revert, | |
3079 | [('r', 'rev', '', _('revision to revert to')), |
|
3079 | [('r', 'rev', '', _('revision to revert to')), | |
3080 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
3080 | ('', 'no-backup', None, _('do not save backup copies of files')), | |
3081 | ('I', 'include', [], _('include names matching given patterns')), |
|
3081 | ('I', 'include', [], _('include names matching given patterns')), | |
3082 | ('X', 'exclude', [], _('exclude names matching given patterns')), |
|
3082 | ('X', 'exclude', [], _('exclude names matching given patterns')), | |
3083 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
3083 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], | |
3084 | _('hg revert [-r REV] [NAME]...')), |
|
3084 | _('hg revert [-r REV] [NAME]...')), | |
3085 | "rollback": (rollback, [], _('hg rollback')), |
|
3085 | "rollback": (rollback, [], _('hg rollback')), | |
3086 | "root": (root, [], _('hg root')), |
|
3086 | "root": (root, [], _('hg root')), | |
3087 | "^serve": |
|
3087 | "^serve": | |
3088 | (serve, |
|
3088 | (serve, | |
3089 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
3089 | [('A', 'accesslog', '', _('name of access log file to write to')), | |
3090 | ('d', 'daemon', None, _('run server in background')), |
|
3090 | ('d', 'daemon', None, _('run server in background')), | |
3091 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
3091 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
3092 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
3092 | ('E', 'errorlog', '', _('name of error log file to write to')), | |
3093 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
3093 | ('p', 'port', 0, _('port to use (default: 8000)')), | |
3094 | ('a', 'address', '', _('address to use')), |
|
3094 | ('a', 'address', '', _('address to use')), | |
3095 | ('n', 'name', '', |
|
3095 | ('n', 'name', '', | |
3096 | _('name to show in web pages (default: working dir)')), |
|
3096 | _('name to show in web pages (default: working dir)')), | |
3097 | ('', 'webdir-conf', '', _('name of the webdir config file' |
|
3097 | ('', 'webdir-conf', '', _('name of the webdir config file' | |
3098 | ' (serve more than one repo)')), |
|
3098 | ' (serve more than one repo)')), | |
3099 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
3099 | ('', 'pid-file', '', _('name of file to write process ID to')), | |
3100 | ('', 'stdio', None, _('for remote clients')), |
|
3100 | ('', 'stdio', None, _('for remote clients')), | |
3101 | ('t', 'templates', '', _('web templates to use')), |
|
3101 | ('t', 'templates', '', _('web templates to use')), | |
3102 | ('', 'style', '', _('template style to use')), |
|
3102 | ('', 'style', '', _('template style to use')), | |
3103 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
3103 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | |
3104 | _('hg serve [OPTION]...')), |
|
3104 | _('hg serve [OPTION]...')), | |
3105 | "^status|st": |
|
3105 | "^status|st": | |
3106 | (status, |
|
3106 | (status, | |
3107 | [('A', 'all', None, _('show status of all files')), |
|
3107 | [('A', 'all', None, _('show status of all files')), | |
3108 | ('m', 'modified', None, _('show only modified files')), |
|
3108 | ('m', 'modified', None, _('show only modified files')), | |
3109 | ('a', 'added', None, _('show only added files')), |
|
3109 | ('a', 'added', None, _('show only added files')), | |
3110 | ('r', 'removed', None, _('show only removed files')), |
|
3110 | ('r', 'removed', None, _('show only removed files')), | |
3111 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
3111 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
3112 | ('c', 'clean', None, _('show only files without changes')), |
|
3112 | ('c', 'clean', None, _('show only files without changes')), | |
3113 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
3113 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
3114 | ('i', 'ignored', None, _('show ignored files')), |
|
3114 | ('i', 'ignored', None, _('show ignored files')), | |
3115 | ('n', 'no-status', None, _('hide status prefix')), |
|
3115 | ('n', 'no-status', None, _('hide status prefix')), | |
3116 | ('C', 'copies', None, _('show source of copied files')), |
|
3116 | ('C', 'copies', None, _('show source of copied files')), | |
3117 | ('0', 'print0', None, |
|
3117 | ('0', 'print0', None, | |
3118 | _('end filenames with NUL, for use with xargs')), |
|
3118 | _('end filenames with NUL, for use with xargs')), | |
3119 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3119 | ('I', 'include', [], _('include names matching the given patterns')), | |
3120 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3120 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3121 | _('hg status [OPTION]... [FILE]...')), |
|
3121 | _('hg status [OPTION]... [FILE]...')), | |
3122 | "tag": |
|
3122 | "tag": | |
3123 | (tag, |
|
3123 | (tag, | |
3124 | [('l', 'local', None, _('make the tag local')), |
|
3124 | [('l', 'local', None, _('make the tag local')), | |
3125 | ('m', 'message', '', _('message for tag commit log entry')), |
|
3125 | ('m', 'message', '', _('message for tag commit log entry')), | |
3126 | ('d', 'date', '', _('record datecode as commit date')), |
|
3126 | ('d', 'date', '', _('record datecode as commit date')), | |
3127 | ('u', 'user', '', _('record user as commiter')), |
|
3127 | ('u', 'user', '', _('record user as commiter')), | |
3128 | ('r', 'rev', '', _('revision to tag'))], |
|
3128 | ('r', 'rev', '', _('revision to tag'))], | |
3129 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
3129 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | |
3130 | "tags": (tags, [], _('hg tags')), |
|
3130 | "tags": (tags, [], _('hg tags')), | |
3131 | "tip": |
|
3131 | "tip": | |
3132 | (tip, |
|
3132 | (tip, | |
3133 | [('b', 'branches', None, _('show branches')), |
|
3133 | [('b', 'branches', None, _('show branches')), | |
3134 | ('', 'style', '', _('display using template map file')), |
|
3134 | ('', 'style', '', _('display using template map file')), | |
3135 | ('p', 'patch', None, _('show patch')), |
|
3135 | ('p', 'patch', None, _('show patch')), | |
3136 | ('', 'template', '', _('display with template'))], |
|
3136 | ('', 'template', '', _('display with template'))], | |
3137 | _('hg tip [-b] [-p]')), |
|
3137 | _('hg tip [-b] [-p]')), | |
3138 | "unbundle": |
|
3138 | "unbundle": | |
3139 | (unbundle, |
|
3139 | (unbundle, | |
3140 | [('u', 'update', None, |
|
3140 | [('u', 'update', None, | |
3141 | _('update the working directory to tip after unbundle'))], |
|
3141 | _('update the working directory to tip after unbundle'))], | |
3142 | _('hg unbundle [-u] FILE')), |
|
3142 | _('hg unbundle [-u] FILE')), | |
3143 | "debugundo|undo": (undo, [], _('hg undo')), |
|
3143 | "debugundo|undo": (undo, [], _('hg undo')), | |
3144 | "^update|up|checkout|co": |
|
3144 | "^update|up|checkout|co": | |
3145 | (update, |
|
3145 | (update, | |
3146 | [('b', 'branch', '', _('checkout the head of a specific branch')), |
|
3146 | [('b', 'branch', '', _('checkout the head of a specific branch')), | |
3147 | ('m', 'merge', None, _('allow merging of branches (DEPRECATED)')), |
|
3147 | ('m', 'merge', None, _('allow merging of branches (DEPRECATED)')), | |
3148 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
3148 | ('C', 'clean', None, _('overwrite locally modified files')), | |
3149 | ('f', 'force', None, _('force a merge with outstanding changes'))], |
|
3149 | ('f', 'force', None, _('force a merge with outstanding changes'))], | |
3150 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), |
|
3150 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), | |
3151 | "verify": (verify, [], _('hg verify')), |
|
3151 | "verify": (verify, [], _('hg verify')), | |
3152 | "version": (show_version, [], _('hg version')), |
|
3152 | "version": (show_version, [], _('hg version')), | |
3153 | } |
|
3153 | } | |
3154 |
|
3154 | |||
3155 | globalopts = [ |
|
3155 | globalopts = [ | |
3156 | ('R', 'repository', '', |
|
3156 | ('R', 'repository', '', | |
3157 | _('repository root directory or symbolic path name')), |
|
3157 | _('repository root directory or symbolic path name')), | |
3158 | ('', 'cwd', '', _('change working directory')), |
|
3158 | ('', 'cwd', '', _('change working directory')), | |
3159 | ('y', 'noninteractive', None, |
|
3159 | ('y', 'noninteractive', None, | |
3160 | _('do not prompt, assume \'yes\' for any required answers')), |
|
3160 | _('do not prompt, assume \'yes\' for any required answers')), | |
3161 | ('q', 'quiet', None, _('suppress output')), |
|
3161 | ('q', 'quiet', None, _('suppress output')), | |
3162 | ('v', 'verbose', None, _('enable additional output')), |
|
3162 | ('v', 'verbose', None, _('enable additional output')), | |
3163 | ('', 'config', [], _('set/override config option')), |
|
3163 | ('', 'config', [], _('set/override config option')), | |
3164 | ('', 'debug', None, _('enable debugging output')), |
|
3164 | ('', 'debug', None, _('enable debugging output')), | |
3165 | ('', 'debugger', None, _('start debugger')), |
|
3165 | ('', 'debugger', None, _('start debugger')), | |
3166 | ('', 'lsprof', None, _('print improved command execution profile')), |
|
3166 | ('', 'lsprof', None, _('print improved command execution profile')), | |
3167 | ('', 'traceback', None, _('print traceback on exception')), |
|
3167 | ('', 'traceback', None, _('print traceback on exception')), | |
3168 | ('', 'time', None, _('time how long the command takes')), |
|
3168 | ('', 'time', None, _('time how long the command takes')), | |
3169 | ('', 'profile', None, _('print command execution profile')), |
|
3169 | ('', 'profile', None, _('print command execution profile')), | |
3170 | ('', 'version', None, _('output version information and exit')), |
|
3170 | ('', 'version', None, _('output version information and exit')), | |
3171 | ('h', 'help', None, _('display help and exit')), |
|
3171 | ('h', 'help', None, _('display help and exit')), | |
3172 | ] |
|
3172 | ] | |
3173 |
|
3173 | |||
3174 | norepo = ("clone init version help debugancestor debugcomplete debugdata" |
|
3174 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | |
3175 | " debugindex debugindexdot") |
|
3175 | " debugindex debugindexdot") | |
3176 | optionalrepo = ("paths serve debugconfig") |
|
3176 | optionalrepo = ("paths serve debugconfig") | |
3177 |
|
3177 | |||
3178 | def findpossible(cmd): |
|
3178 | def findpossible(cmd): | |
3179 | """ |
|
3179 | """ | |
3180 | Return cmd -> (aliases, command table entry) |
|
3180 | Return cmd -> (aliases, command table entry) | |
3181 | for each matching command. |
|
3181 | for each matching command. | |
3182 | Return debug commands (or their aliases) only if no normal command matches. |
|
3182 | Return debug commands (or their aliases) only if no normal command matches. | |
3183 | """ |
|
3183 | """ | |
3184 | choice = {} |
|
3184 | choice = {} | |
3185 | debugchoice = {} |
|
3185 | debugchoice = {} | |
3186 | for e in table.keys(): |
|
3186 | for e in table.keys(): | |
3187 | aliases = e.lstrip("^").split("|") |
|
3187 | aliases = e.lstrip("^").split("|") | |
3188 | found = None |
|
3188 | found = None | |
3189 | if cmd in aliases: |
|
3189 | if cmd in aliases: | |
3190 | found = cmd |
|
3190 | found = cmd | |
3191 | else: |
|
3191 | else: | |
3192 | for a in aliases: |
|
3192 | for a in aliases: | |
3193 | if a.startswith(cmd): |
|
3193 | if a.startswith(cmd): | |
3194 | found = a |
|
3194 | found = a | |
3195 | break |
|
3195 | break | |
3196 | if found is not None: |
|
3196 | if found is not None: | |
3197 | if aliases[0].startswith("debug"): |
|
3197 | if aliases[0].startswith("debug"): | |
3198 | debugchoice[found] = (aliases, table[e]) |
|
3198 | debugchoice[found] = (aliases, table[e]) | |
3199 | else: |
|
3199 | else: | |
3200 | choice[found] = (aliases, table[e]) |
|
3200 | choice[found] = (aliases, table[e]) | |
3201 |
|
3201 | |||
3202 | if not choice and debugchoice: |
|
3202 | if not choice and debugchoice: | |
3203 | choice = debugchoice |
|
3203 | choice = debugchoice | |
3204 |
|
3204 | |||
3205 | return choice |
|
3205 | return choice | |
3206 |
|
3206 | |||
3207 | def findcmd(cmd): |
|
3207 | def findcmd(cmd): | |
3208 | """Return (aliases, command table entry) for command string.""" |
|
3208 | """Return (aliases, command table entry) for command string.""" | |
3209 | choice = findpossible(cmd) |
|
3209 | choice = findpossible(cmd) | |
3210 |
|
3210 | |||
3211 | if choice.has_key(cmd): |
|
3211 | if choice.has_key(cmd): | |
3212 | return choice[cmd] |
|
3212 | return choice[cmd] | |
3213 |
|
3213 | |||
3214 | if len(choice) > 1: |
|
3214 | if len(choice) > 1: | |
3215 | clist = choice.keys() |
|
3215 | clist = choice.keys() | |
3216 | clist.sort() |
|
3216 | clist.sort() | |
3217 | raise AmbiguousCommand(cmd, clist) |
|
3217 | raise AmbiguousCommand(cmd, clist) | |
3218 |
|
3218 | |||
3219 | if choice: |
|
3219 | if choice: | |
3220 | return choice.values()[0] |
|
3220 | return choice.values()[0] | |
3221 |
|
3221 | |||
3222 | raise UnknownCommand(cmd) |
|
3222 | raise UnknownCommand(cmd) | |
3223 |
|
3223 | |||
3224 | def catchterm(*args): |
|
3224 | def catchterm(*args): | |
3225 | raise util.SignalInterrupt |
|
3225 | raise util.SignalInterrupt | |
3226 |
|
3226 | |||
3227 | def run(): |
|
3227 | def run(): | |
3228 | sys.exit(dispatch(sys.argv[1:])) |
|
3228 | sys.exit(dispatch(sys.argv[1:])) | |
3229 |
|
3229 | |||
3230 | class ParseError(Exception): |
|
3230 | class ParseError(Exception): | |
3231 | """Exception raised on errors in parsing the command line.""" |
|
3231 | """Exception raised on errors in parsing the command line.""" | |
3232 |
|
3232 | |||
3233 | def parse(ui, args): |
|
3233 | def parse(ui, args): | |
3234 | options = {} |
|
3234 | options = {} | |
3235 | cmdoptions = {} |
|
3235 | cmdoptions = {} | |
3236 |
|
3236 | |||
3237 | try: |
|
3237 | try: | |
3238 | args = fancyopts.fancyopts(args, globalopts, options) |
|
3238 | args = fancyopts.fancyopts(args, globalopts, options) | |
3239 | except fancyopts.getopt.GetoptError, inst: |
|
3239 | except fancyopts.getopt.GetoptError, inst: | |
3240 | raise ParseError(None, inst) |
|
3240 | raise ParseError(None, inst) | |
3241 |
|
3241 | |||
3242 | if args: |
|
3242 | if args: | |
3243 | cmd, args = args[0], args[1:] |
|
3243 | cmd, args = args[0], args[1:] | |
3244 | aliases, i = findcmd(cmd) |
|
3244 | aliases, i = findcmd(cmd) | |
3245 | cmd = aliases[0] |
|
3245 | cmd = aliases[0] | |
3246 | defaults = ui.config("defaults", cmd) |
|
3246 | defaults = ui.config("defaults", cmd) | |
3247 | if defaults: |
|
3247 | if defaults: | |
3248 | args = defaults.split() + args |
|
3248 | args = defaults.split() + args | |
3249 | c = list(i[1]) |
|
3249 | c = list(i[1]) | |
3250 | else: |
|
3250 | else: | |
3251 | cmd = None |
|
3251 | cmd = None | |
3252 | c = [] |
|
3252 | c = [] | |
3253 |
|
3253 | |||
3254 | # combine global options into local |
|
3254 | # combine global options into local | |
3255 | for o in globalopts: |
|
3255 | for o in globalopts: | |
3256 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
3256 | c.append((o[0], o[1], options[o[1]], o[3])) | |
3257 |
|
3257 | |||
3258 | try: |
|
3258 | try: | |
3259 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
3259 | args = fancyopts.fancyopts(args, c, cmdoptions) | |
3260 | except fancyopts.getopt.GetoptError, inst: |
|
3260 | except fancyopts.getopt.GetoptError, inst: | |
3261 | raise ParseError(cmd, inst) |
|
3261 | raise ParseError(cmd, inst) | |
3262 |
|
3262 | |||
3263 | # separate global options back out |
|
3263 | # separate global options back out | |
3264 | for o in globalopts: |
|
3264 | for o in globalopts: | |
3265 | n = o[1] |
|
3265 | n = o[1] | |
3266 | options[n] = cmdoptions[n] |
|
3266 | options[n] = cmdoptions[n] | |
3267 | del cmdoptions[n] |
|
3267 | del cmdoptions[n] | |
3268 |
|
3268 | |||
3269 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
3269 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | |
3270 |
|
3270 | |||
3271 | external = {} |
|
3271 | external = {} | |
3272 |
|
3272 | |||
3273 | def findext(name): |
|
3273 | def findext(name): | |
3274 | '''return module with given extension name''' |
|
3274 | '''return module with given extension name''' | |
3275 | try: |
|
3275 | try: | |
3276 | return sys.modules[external[name]] |
|
3276 | return sys.modules[external[name]] | |
3277 | except KeyError: |
|
3277 | except KeyError: | |
3278 | for k, v in external.iteritems(): |
|
3278 | for k, v in external.iteritems(): | |
3279 | if k.endswith('.' + name) or k.endswith('/' + name) or v == name: |
|
3279 | if k.endswith('.' + name) or k.endswith('/' + name) or v == name: | |
3280 | return sys.modules[v] |
|
3280 | return sys.modules[v] | |
3281 | raise KeyError(name) |
|
3281 | raise KeyError(name) | |
3282 |
|
3282 | |||
3283 | def dispatch(args): |
|
3283 | def dispatch(args): | |
3284 | for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
|
3284 | for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': | |
3285 | num = getattr(signal, name, None) |
|
3285 | num = getattr(signal, name, None) | |
3286 | if num: signal.signal(num, catchterm) |
|
3286 | if num: signal.signal(num, catchterm) | |
3287 |
|
3287 | |||
3288 | try: |
|
3288 | try: | |
3289 | u = ui.ui(traceback='--traceback' in sys.argv[1:]) |
|
3289 | u = ui.ui(traceback='--traceback' in sys.argv[1:]) | |
3290 | except util.Abort, inst: |
|
3290 | except util.Abort, inst: | |
3291 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3291 | sys.stderr.write(_("abort: %s\n") % inst) | |
3292 | return -1 |
|
3292 | return -1 | |
3293 |
|
3293 | |||
3294 | for ext_name, load_from_name in u.extensions(): |
|
3294 | for ext_name, load_from_name in u.extensions(): | |
3295 | try: |
|
3295 | try: | |
3296 | if load_from_name: |
|
3296 | if load_from_name: | |
3297 | # the module will be loaded in sys.modules |
|
3297 | # the module will be loaded in sys.modules | |
3298 | # choose an unique name so that it doesn't |
|
3298 | # choose an unique name so that it doesn't | |
3299 | # conflicts with other modules |
|
3299 | # conflicts with other modules | |
3300 | module_name = "hgext_%s" % ext_name.replace('.', '_') |
|
3300 | module_name = "hgext_%s" % ext_name.replace('.', '_') | |
3301 | mod = imp.load_source(module_name, load_from_name) |
|
3301 | mod = imp.load_source(module_name, load_from_name) | |
3302 | else: |
|
3302 | else: | |
3303 | def importh(name): |
|
3303 | def importh(name): | |
3304 | mod = __import__(name) |
|
3304 | mod = __import__(name) | |
3305 | components = name.split('.') |
|
3305 | components = name.split('.') | |
3306 | for comp in components[1:]: |
|
3306 | for comp in components[1:]: | |
3307 | mod = getattr(mod, comp) |
|
3307 | mod = getattr(mod, comp) | |
3308 | return mod |
|
3308 | return mod | |
3309 | try: |
|
3309 | try: | |
3310 | mod = importh("hgext.%s" % ext_name) |
|
3310 | mod = importh("hgext.%s" % ext_name) | |
3311 | except ImportError: |
|
3311 | except ImportError: | |
3312 | mod = importh(ext_name) |
|
3312 | mod = importh(ext_name) | |
3313 | external[ext_name] = mod.__name__ |
|
3313 | external[ext_name] = mod.__name__ | |
3314 | except (util.SignalInterrupt, KeyboardInterrupt): |
|
3314 | except (util.SignalInterrupt, KeyboardInterrupt): | |
3315 | raise |
|
3315 | raise | |
3316 | except Exception, inst: |
|
3316 | except Exception, inst: | |
3317 | u.warn(_("*** failed to import extension %s: %s\n") % (ext_name, inst)) |
|
3317 | u.warn(_("*** failed to import extension %s: %s\n") % (ext_name, inst)) | |
3318 | if u.print_exc(): |
|
3318 | if u.print_exc(): | |
3319 | return 1 |
|
3319 | return 1 | |
3320 |
|
3320 | |||
3321 | for name in external.itervalues(): |
|
3321 | for name in external.itervalues(): | |
3322 | mod = sys.modules[name] |
|
3322 | mod = sys.modules[name] | |
3323 | uisetup = getattr(mod, 'uisetup', None) |
|
3323 | uisetup = getattr(mod, 'uisetup', None) | |
3324 | if uisetup: |
|
3324 | if uisetup: | |
3325 | uisetup(u) |
|
3325 | uisetup(u) | |
3326 | cmdtable = getattr(mod, 'cmdtable', {}) |
|
3326 | cmdtable = getattr(mod, 'cmdtable', {}) | |
3327 | for t in cmdtable: |
|
3327 | for t in cmdtable: | |
3328 | if t in table: |
|
3328 | if t in table: | |
3329 | u.warn(_("module %s overrides %s\n") % (name, t)) |
|
3329 | u.warn(_("module %s overrides %s\n") % (name, t)) | |
3330 | table.update(cmdtable) |
|
3330 | table.update(cmdtable) | |
3331 |
|
3331 | |||
3332 | try: |
|
3332 | try: | |
3333 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3333 | cmd, func, args, options, cmdoptions = parse(u, args) | |
3334 | if options["time"]: |
|
3334 | if options["time"]: | |
3335 | def get_times(): |
|
3335 | def get_times(): | |
3336 | t = os.times() |
|
3336 | t = os.times() | |
3337 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
3337 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | |
3338 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
3338 | t = (t[0], t[1], t[2], t[3], time.clock()) | |
3339 | return t |
|
3339 | return t | |
3340 | s = get_times() |
|
3340 | s = get_times() | |
3341 | def print_time(): |
|
3341 | def print_time(): | |
3342 | t = get_times() |
|
3342 | t = get_times() | |
3343 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
3343 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | |
3344 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
3344 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | |
3345 | atexit.register(print_time) |
|
3345 | atexit.register(print_time) | |
3346 |
|
3346 | |||
3347 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3347 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
3348 | not options["noninteractive"], options["traceback"], |
|
3348 | not options["noninteractive"], options["traceback"], | |
3349 | options["config"]) |
|
3349 | options["config"]) | |
3350 |
|
3350 | |||
3351 | # enter the debugger before command execution |
|
3351 | # enter the debugger before command execution | |
3352 | if options['debugger']: |
|
3352 | if options['debugger']: | |
3353 | pdb.set_trace() |
|
3353 | pdb.set_trace() | |
3354 |
|
3354 | |||
3355 | try: |
|
3355 | try: | |
3356 | if options['cwd']: |
|
3356 | if options['cwd']: | |
3357 | try: |
|
3357 | try: | |
3358 | os.chdir(options['cwd']) |
|
3358 | os.chdir(options['cwd']) | |
3359 | except OSError, inst: |
|
3359 | except OSError, inst: | |
3360 | raise util.Abort('%s: %s' % |
|
3360 | raise util.Abort('%s: %s' % | |
3361 | (options['cwd'], inst.strerror)) |
|
3361 | (options['cwd'], inst.strerror)) | |
3362 |
|
3362 | |||
3363 | path = u.expandpath(options["repository"]) or "" |
|
3363 | path = u.expandpath(options["repository"]) or "" | |
3364 | repo = path and hg.repository(u, path=path) or None |
|
3364 | repo = path and hg.repository(u, path=path) or None | |
3365 |
|
3365 | |||
3366 | if options['help']: |
|
3366 | if options['help']: | |
3367 | return help_(u, cmd, options['version']) |
|
3367 | return help_(u, cmd, options['version']) | |
3368 | elif options['version']: |
|
3368 | elif options['version']: | |
3369 | return show_version(u) |
|
3369 | return show_version(u) | |
3370 | elif not cmd: |
|
3370 | elif not cmd: | |
3371 | return help_(u, 'shortlist') |
|
3371 | return help_(u, 'shortlist') | |
3372 |
|
3372 | |||
3373 | if cmd not in norepo.split(): |
|
3373 | if cmd not in norepo.split(): | |
3374 | try: |
|
3374 | try: | |
3375 | if not repo: |
|
3375 | if not repo: | |
3376 | repo = hg.repository(u, path=path) |
|
3376 | repo = hg.repository(u, path=path) | |
3377 | u = repo.ui |
|
3377 | u = repo.ui | |
3378 | for name in external.itervalues(): |
|
3378 | for name in external.itervalues(): | |
3379 | mod = sys.modules[name] |
|
3379 | mod = sys.modules[name] | |
3380 | if hasattr(mod, 'reposetup'): |
|
3380 | if hasattr(mod, 'reposetup'): | |
3381 | mod.reposetup(u, repo) |
|
3381 | mod.reposetup(u, repo) | |
3382 | hg.repo_setup_hooks.append(mod.reposetup) |
|
3382 | hg.repo_setup_hooks.append(mod.reposetup) | |
3383 | except hg.RepoError: |
|
3383 | except hg.RepoError: | |
3384 | if cmd not in optionalrepo.split(): |
|
3384 | if cmd not in optionalrepo.split(): | |
3385 | raise |
|
3385 | raise | |
3386 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
3386 | d = lambda: func(u, repo, *args, **cmdoptions) | |
3387 | else: |
|
3387 | else: | |
3388 | d = lambda: func(u, *args, **cmdoptions) |
|
3388 | d = lambda: func(u, *args, **cmdoptions) | |
3389 |
|
3389 | |||
3390 | # reupdate the options, repo/.hg/hgrc may have changed them |
|
3390 | # reupdate the options, repo/.hg/hgrc may have changed them | |
3391 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3391 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
3392 | not options["noninteractive"], options["traceback"], |
|
3392 | not options["noninteractive"], options["traceback"], | |
3393 | options["config"]) |
|
3393 | options["config"]) | |
3394 |
|
3394 | |||
3395 | try: |
|
3395 | try: | |
3396 | if options['profile']: |
|
3396 | if options['profile']: | |
3397 | import hotshot, hotshot.stats |
|
3397 | import hotshot, hotshot.stats | |
3398 | prof = hotshot.Profile("hg.prof") |
|
3398 | prof = hotshot.Profile("hg.prof") | |
3399 | try: |
|
3399 | try: | |
3400 | try: |
|
3400 | try: | |
3401 | return prof.runcall(d) |
|
3401 | return prof.runcall(d) | |
3402 | except: |
|
3402 | except: | |
3403 | try: |
|
3403 | try: | |
3404 | u.warn(_('exception raised - generating ' |
|
3404 | u.warn(_('exception raised - generating ' | |
3405 | 'profile anyway\n')) |
|
3405 | 'profile anyway\n')) | |
3406 | except: |
|
3406 | except: | |
3407 | pass |
|
3407 | pass | |
3408 | raise |
|
3408 | raise | |
3409 | finally: |
|
3409 | finally: | |
3410 | prof.close() |
|
3410 | prof.close() | |
3411 | stats = hotshot.stats.load("hg.prof") |
|
3411 | stats = hotshot.stats.load("hg.prof") | |
3412 | stats.strip_dirs() |
|
3412 | stats.strip_dirs() | |
3413 | stats.sort_stats('time', 'calls') |
|
3413 | stats.sort_stats('time', 'calls') | |
3414 | stats.print_stats(40) |
|
3414 | stats.print_stats(40) | |
3415 | elif options['lsprof']: |
|
3415 | elif options['lsprof']: | |
3416 | try: |
|
3416 | try: | |
3417 | from mercurial import lsprof |
|
3417 | from mercurial import lsprof | |
3418 | except ImportError: |
|
3418 | except ImportError: | |
3419 | raise util.Abort(_( |
|
3419 | raise util.Abort(_( | |
3420 | 'lsprof not available - install from ' |
|
3420 | 'lsprof not available - install from ' | |
3421 | 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) |
|
3421 | 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) | |
3422 | p = lsprof.Profiler() |
|
3422 | p = lsprof.Profiler() | |
3423 | p.enable(subcalls=True) |
|
3423 | p.enable(subcalls=True) | |
3424 | try: |
|
3424 | try: | |
3425 | return d() |
|
3425 | return d() | |
3426 | finally: |
|
3426 | finally: | |
3427 | p.disable() |
|
3427 | p.disable() | |
3428 | stats = lsprof.Stats(p.getstats()) |
|
3428 | stats = lsprof.Stats(p.getstats()) | |
3429 | stats.sort() |
|
3429 | stats.sort() | |
3430 | stats.pprint(top=10, file=sys.stderr, climit=5) |
|
3430 | stats.pprint(top=10, file=sys.stderr, climit=5) | |
3431 | else: |
|
3431 | else: | |
3432 | return d() |
|
3432 | return d() | |
3433 | finally: |
|
3433 | finally: | |
3434 | u.flush() |
|
3434 | u.flush() | |
3435 | except: |
|
3435 | except: | |
3436 | # enter the debugger when we hit an exception |
|
3436 | # enter the debugger when we hit an exception | |
3437 | if options['debugger']: |
|
3437 | if options['debugger']: | |
3438 | pdb.post_mortem(sys.exc_info()[2]) |
|
3438 | pdb.post_mortem(sys.exc_info()[2]) | |
3439 | u.print_exc() |
|
3439 | u.print_exc() | |
3440 | raise |
|
3440 | raise | |
3441 | except ParseError, inst: |
|
3441 | except ParseError, inst: | |
3442 | if inst.args[0]: |
|
3442 | if inst.args[0]: | |
3443 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
3443 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
3444 | help_(u, inst.args[0]) |
|
3444 | help_(u, inst.args[0]) | |
3445 | else: |
|
3445 | else: | |
3446 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
3446 | u.warn(_("hg: %s\n") % inst.args[1]) | |
3447 | help_(u, 'shortlist') |
|
3447 | help_(u, 'shortlist') | |
3448 | except AmbiguousCommand, inst: |
|
3448 | except AmbiguousCommand, inst: | |
3449 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
3449 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
3450 | (inst.args[0], " ".join(inst.args[1]))) |
|
3450 | (inst.args[0], " ".join(inst.args[1]))) | |
3451 | except UnknownCommand, inst: |
|
3451 | except UnknownCommand, inst: | |
3452 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
3452 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
3453 | help_(u, 'shortlist') |
|
3453 | help_(u, 'shortlist') | |
3454 | except hg.RepoError, inst: |
|
3454 | except hg.RepoError, inst: | |
3455 | u.warn(_("abort: %s!\n") % inst) |
|
3455 | u.warn(_("abort: %s!\n") % inst) | |
3456 | except lock.LockHeld, inst: |
|
3456 | except lock.LockHeld, inst: | |
3457 | if inst.errno == errno.ETIMEDOUT: |
|
3457 | if inst.errno == errno.ETIMEDOUT: | |
3458 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
3458 | reason = _('timed out waiting for lock held by %s') % inst.locker | |
3459 | else: |
|
3459 | else: | |
3460 | reason = _('lock held by %s') % inst.locker |
|
3460 | reason = _('lock held by %s') % inst.locker | |
3461 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
3461 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) | |
3462 | except lock.LockUnavailable, inst: |
|
3462 | except lock.LockUnavailable, inst: | |
3463 | u.warn(_("abort: could not lock %s: %s\n") % |
|
3463 | u.warn(_("abort: could not lock %s: %s\n") % | |
3464 | (inst.desc or inst.filename, inst.strerror)) |
|
3464 | (inst.desc or inst.filename, inst.strerror)) | |
3465 | except revlog.RevlogError, inst: |
|
3465 | except revlog.RevlogError, inst: | |
3466 | u.warn(_("abort: "), inst, "!\n") |
|
3466 | u.warn(_("abort: "), inst, "!\n") | |
3467 | except util.SignalInterrupt: |
|
3467 | except util.SignalInterrupt: | |
3468 | u.warn(_("killed!\n")) |
|
3468 | u.warn(_("killed!\n")) | |
3469 | except KeyboardInterrupt: |
|
3469 | except KeyboardInterrupt: | |
3470 | try: |
|
3470 | try: | |
3471 | u.warn(_("interrupted!\n")) |
|
3471 | u.warn(_("interrupted!\n")) | |
3472 | except IOError, inst: |
|
3472 | except IOError, inst: | |
3473 | if inst.errno == errno.EPIPE: |
|
3473 | if inst.errno == errno.EPIPE: | |
3474 | if u.debugflag: |
|
3474 | if u.debugflag: | |
3475 | u.warn(_("\nbroken pipe\n")) |
|
3475 | u.warn(_("\nbroken pipe\n")) | |
3476 | else: |
|
3476 | else: | |
3477 | raise |
|
3477 | raise | |
3478 | except IOError, inst: |
|
3478 | except IOError, inst: | |
3479 | if hasattr(inst, "code"): |
|
3479 | if hasattr(inst, "code"): | |
3480 | u.warn(_("abort: %s\n") % inst) |
|
3480 | u.warn(_("abort: %s\n") % inst) | |
3481 | elif hasattr(inst, "reason"): |
|
3481 | elif hasattr(inst, "reason"): | |
3482 | u.warn(_("abort: error: %s\n") % inst.reason[1]) |
|
3482 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | |
3483 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
3483 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | |
3484 | if u.debugflag: |
|
3484 | if u.debugflag: | |
3485 | u.warn(_("broken pipe\n")) |
|
3485 | u.warn(_("broken pipe\n")) | |
3486 | elif getattr(inst, "strerror", None): |
|
3486 | elif getattr(inst, "strerror", None): | |
3487 | if getattr(inst, "filename", None): |
|
3487 | if getattr(inst, "filename", None): | |
3488 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) |
|
3488 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) | |
3489 | else: |
|
3489 | else: | |
3490 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3490 | u.warn(_("abort: %s\n") % inst.strerror) | |
3491 | else: |
|
3491 | else: | |
3492 | raise |
|
3492 | raise | |
3493 | except OSError, inst: |
|
3493 | except OSError, inst: | |
3494 | if hasattr(inst, "filename"): |
|
3494 | if hasattr(inst, "filename"): | |
3495 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3495 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | |
3496 | else: |
|
3496 | else: | |
3497 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3497 | u.warn(_("abort: %s\n") % inst.strerror) | |
3498 | except util.Abort, inst: |
|
3498 | except util.Abort, inst: | |
3499 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') |
|
3499 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') | |
3500 | except TypeError, inst: |
|
3500 | except TypeError, inst: | |
3501 | # was this an argument error? |
|
3501 | # was this an argument error? | |
3502 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
3502 | tb = traceback.extract_tb(sys.exc_info()[2]) | |
3503 | if len(tb) > 2: # no |
|
3503 | if len(tb) > 2: # no | |
3504 | raise |
|
3504 | raise | |
3505 | u.debug(inst, "\n") |
|
3505 | u.debug(inst, "\n") | |
3506 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
3506 | u.warn(_("%s: invalid arguments\n") % cmd) | |
3507 | help_(u, cmd) |
|
3507 | help_(u, cmd) | |
3508 | except SystemExit, inst: |
|
3508 | except SystemExit, inst: | |
3509 | # Commands shouldn't sys.exit directly, but give a return code. |
|
3509 | # Commands shouldn't sys.exit directly, but give a return code. | |
3510 | # Just in case catch this and and pass exit code to caller. |
|
3510 | # Just in case catch this and and pass exit code to caller. | |
3511 | return inst.code |
|
3511 | return inst.code | |
3512 | except: |
|
3512 | except: | |
3513 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
3513 | u.warn(_("** unknown exception encountered, details follow\n")) | |
3514 | u.warn(_("** report bug details to " |
|
3514 | u.warn(_("** report bug details to " | |
3515 | "http://www.selenic.com/mercurial/bts\n")) |
|
3515 | "http://www.selenic.com/mercurial/bts\n")) | |
3516 | u.warn(_("** or mercurial@selenic.com\n")) |
|
3516 | u.warn(_("** or mercurial@selenic.com\n")) | |
3517 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
3517 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | |
3518 | % version.get_version()) |
|
3518 | % version.get_version()) | |
3519 | raise |
|
3519 | raise | |
3520 |
|
3520 | |||
3521 | return -1 |
|
3521 | return -1 |
@@ -1,419 +1,435 b'' | |||||
1 | # patch.py - patch file parsing routines |
|
1 | # patch.py - patch file parsing routines | |
2 | # |
|
2 | # | |
3 | # Copyright 2006 Brendan Cully <brendan@kublai.com> |
|
3 | # Copyright 2006 Brendan Cully <brendan@kublai.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from demandload import demandload |
|
8 | from demandload import demandload | |
9 | from i18n import gettext as _ |
|
9 | from i18n import gettext as _ | |
10 | from node import * |
|
10 | from node import * | |
11 | demandload(globals(), "cmdutil mdiff util") |
|
11 | demandload(globals(), "cmdutil mdiff util") | |
12 | demandload(globals(), "cStringIO email.Parser os re shutil sys tempfile") |
|
12 | demandload(globals(), "cStringIO email.Parser os re shutil sys tempfile") | |
13 |
|
13 | |||
14 | def extract(ui, fileobj): |
|
14 | def extract(ui, fileobj): | |
15 | '''extract patch from data read from fileobj. |
|
15 | '''extract patch from data read from fileobj. | |
16 |
|
16 | |||
17 | patch can be normal patch or contained in email message. |
|
17 | patch can be normal patch or contained in email message. | |
18 |
|
18 | |||
19 | return tuple (filename, message, user, date). any item in returned |
|
19 | return tuple (filename, message, user, date). any item in returned | |
20 | tuple can be None. if filename is None, fileobj did not contain |
|
20 | tuple can be None. if filename is None, fileobj did not contain | |
21 | patch. caller must unlink filename when done.''' |
|
21 | patch. caller must unlink filename when done.''' | |
22 |
|
22 | |||
23 | # attempt to detect the start of a patch |
|
23 | # attempt to detect the start of a patch | |
24 | # (this heuristic is borrowed from quilt) |
|
24 | # (this heuristic is borrowed from quilt) | |
25 | diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' + |
|
25 | diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' + | |
26 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + |
|
26 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + | |
27 | '(---|\*\*\*)[ \t])', re.MULTILINE) |
|
27 | '(---|\*\*\*)[ \t])', re.MULTILINE) | |
28 |
|
28 | |||
29 | fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') |
|
29 | fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') | |
30 | tmpfp = os.fdopen(fd, 'w') |
|
30 | tmpfp = os.fdopen(fd, 'w') | |
31 | try: |
|
31 | try: | |
32 | hgpatch = False |
|
32 | hgpatch = False | |
33 |
|
33 | |||
34 | msg = email.Parser.Parser().parse(fileobj) |
|
34 | msg = email.Parser.Parser().parse(fileobj) | |
35 |
|
35 | |||
36 | message = msg['Subject'] |
|
36 | message = msg['Subject'] | |
37 | user = msg['From'] |
|
37 | user = msg['From'] | |
38 | # should try to parse msg['Date'] |
|
38 | # should try to parse msg['Date'] | |
39 | date = None |
|
39 | date = None | |
40 |
|
40 | |||
41 | if message: |
|
41 | if message: | |
42 | message = message.replace('\n\t', ' ') |
|
42 | message = message.replace('\n\t', ' ') | |
43 | ui.debug('Subject: %s\n' % message) |
|
43 | ui.debug('Subject: %s\n' % message) | |
44 | if user: |
|
44 | if user: | |
45 | ui.debug('From: %s\n' % user) |
|
45 | ui.debug('From: %s\n' % user) | |
46 | diffs_seen = 0 |
|
46 | diffs_seen = 0 | |
47 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') |
|
47 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') | |
48 |
|
48 | |||
49 | for part in msg.walk(): |
|
49 | for part in msg.walk(): | |
50 | content_type = part.get_content_type() |
|
50 | content_type = part.get_content_type() | |
51 | ui.debug('Content-Type: %s\n' % content_type) |
|
51 | ui.debug('Content-Type: %s\n' % content_type) | |
52 | if content_type not in ok_types: |
|
52 | if content_type not in ok_types: | |
53 | continue |
|
53 | continue | |
54 | payload = part.get_payload(decode=True) |
|
54 | payload = part.get_payload(decode=True) | |
55 | m = diffre.search(payload) |
|
55 | m = diffre.search(payload) | |
56 | if m: |
|
56 | if m: | |
57 | ui.debug(_('found patch at byte %d\n') % m.start(0)) |
|
57 | ui.debug(_('found patch at byte %d\n') % m.start(0)) | |
58 | diffs_seen += 1 |
|
58 | diffs_seen += 1 | |
59 | cfp = cStringIO.StringIO() |
|
59 | cfp = cStringIO.StringIO() | |
60 | if message: |
|
60 | if message: | |
61 | cfp.write(message) |
|
61 | cfp.write(message) | |
62 | cfp.write('\n') |
|
62 | cfp.write('\n') | |
63 | for line in payload[:m.start(0)].splitlines(): |
|
63 | for line in payload[:m.start(0)].splitlines(): | |
64 | if line.startswith('# HG changeset patch'): |
|
64 | if line.startswith('# HG changeset patch'): | |
65 | ui.debug(_('patch generated by hg export\n')) |
|
65 | ui.debug(_('patch generated by hg export\n')) | |
66 | hgpatch = True |
|
66 | hgpatch = True | |
67 | # drop earlier commit message content |
|
67 | # drop earlier commit message content | |
68 | cfp.seek(0) |
|
68 | cfp.seek(0) | |
69 | cfp.truncate() |
|
69 | cfp.truncate() | |
70 | elif hgpatch: |
|
70 | elif hgpatch: | |
71 | if line.startswith('# User '): |
|
71 | if line.startswith('# User '): | |
72 | user = line[7:] |
|
72 | user = line[7:] | |
73 | ui.debug('From: %s\n' % user) |
|
73 | ui.debug('From: %s\n' % user) | |
74 | elif line.startswith("# Date "): |
|
74 | elif line.startswith("# Date "): | |
75 | date = line[7:] |
|
75 | date = line[7:] | |
76 | if not line.startswith('# '): |
|
76 | if not line.startswith('# '): | |
77 | cfp.write(line) |
|
77 | cfp.write(line) | |
78 | cfp.write('\n') |
|
78 | cfp.write('\n') | |
79 | message = cfp.getvalue() |
|
79 | message = cfp.getvalue() | |
80 | if tmpfp: |
|
80 | if tmpfp: | |
81 | tmpfp.write(payload) |
|
81 | tmpfp.write(payload) | |
82 | if not payload.endswith('\n'): |
|
82 | if not payload.endswith('\n'): | |
83 | tmpfp.write('\n') |
|
83 | tmpfp.write('\n') | |
84 | elif not diffs_seen and message and content_type == 'text/plain': |
|
84 | elif not diffs_seen and message and content_type == 'text/plain': | |
85 | message += '\n' + payload |
|
85 | message += '\n' + payload | |
86 | except: |
|
86 | except: | |
87 | tmpfp.close() |
|
87 | tmpfp.close() | |
88 | os.unlink(tmpname) |
|
88 | os.unlink(tmpname) | |
89 | raise |
|
89 | raise | |
90 |
|
90 | |||
91 | tmpfp.close() |
|
91 | tmpfp.close() | |
92 | if not diffs_seen: |
|
92 | if not diffs_seen: | |
93 | os.unlink(tmpname) |
|
93 | os.unlink(tmpname) | |
94 | return None, message, user, date |
|
94 | return None, message, user, date | |
95 | return tmpname, message, user, date |
|
95 | return tmpname, message, user, date | |
96 |
|
96 | |||
97 | def readgitpatch(patchname): |
|
97 | def readgitpatch(patchname): | |
98 | """extract git-style metadata about patches from <patchname>""" |
|
98 | """extract git-style metadata about patches from <patchname>""" | |
99 | class gitpatch: |
|
99 | class gitpatch: | |
100 | "op is one of ADD, DELETE, RENAME, MODIFY or COPY" |
|
100 | "op is one of ADD, DELETE, RENAME, MODIFY or COPY" | |
101 | def __init__(self, path): |
|
101 | def __init__(self, path): | |
102 | self.path = path |
|
102 | self.path = path | |
103 | self.oldpath = None |
|
103 | self.oldpath = None | |
104 | self.mode = None |
|
104 | self.mode = None | |
105 | self.op = 'MODIFY' |
|
105 | self.op = 'MODIFY' | |
106 | self.copymod = False |
|
106 | self.copymod = False | |
107 | self.lineno = 0 |
|
107 | self.lineno = 0 | |
108 |
|
108 | |||
109 | # Filter patch for git information |
|
109 | # Filter patch for git information | |
110 | gitre = re.compile('diff --git a/(.*) b/(.*)') |
|
110 | gitre = re.compile('diff --git a/(.*) b/(.*)') | |
111 | pf = file(patchname) |
|
111 | pf = file(patchname) | |
112 | gp = None |
|
112 | gp = None | |
113 | gitpatches = [] |
|
113 | gitpatches = [] | |
114 | # Can have a git patch with only metadata, causing patch to complain |
|
114 | # Can have a git patch with only metadata, causing patch to complain | |
115 | dopatch = False |
|
115 | dopatch = False | |
116 |
|
116 | |||
117 | lineno = 0 |
|
117 | lineno = 0 | |
118 | for line in pf: |
|
118 | for line in pf: | |
119 | lineno += 1 |
|
119 | lineno += 1 | |
120 | if line.startswith('diff --git'): |
|
120 | if line.startswith('diff --git'): | |
121 | m = gitre.match(line) |
|
121 | m = gitre.match(line) | |
122 | if m: |
|
122 | if m: | |
123 | if gp: |
|
123 | if gp: | |
124 | gitpatches.append(gp) |
|
124 | gitpatches.append(gp) | |
125 | src, dst = m.group(1,2) |
|
125 | src, dst = m.group(1,2) | |
126 | gp = gitpatch(dst) |
|
126 | gp = gitpatch(dst) | |
127 | gp.lineno = lineno |
|
127 | gp.lineno = lineno | |
128 | elif gp: |
|
128 | elif gp: | |
129 | if line.startswith('--- '): |
|
129 | if line.startswith('--- '): | |
130 | if gp.op in ('COPY', 'RENAME'): |
|
130 | if gp.op in ('COPY', 'RENAME'): | |
131 | gp.copymod = True |
|
131 | gp.copymod = True | |
132 | dopatch = 'filter' |
|
132 | dopatch = 'filter' | |
133 | gitpatches.append(gp) |
|
133 | gitpatches.append(gp) | |
134 | gp = None |
|
134 | gp = None | |
135 | if not dopatch: |
|
135 | if not dopatch: | |
136 | dopatch = True |
|
136 | dopatch = True | |
137 | continue |
|
137 | continue | |
138 | if line.startswith('rename from '): |
|
138 | if line.startswith('rename from '): | |
139 | gp.op = 'RENAME' |
|
139 | gp.op = 'RENAME' | |
140 | gp.oldpath = line[12:].rstrip() |
|
140 | gp.oldpath = line[12:].rstrip() | |
141 | elif line.startswith('rename to '): |
|
141 | elif line.startswith('rename to '): | |
142 | gp.path = line[10:].rstrip() |
|
142 | gp.path = line[10:].rstrip() | |
143 | elif line.startswith('copy from '): |
|
143 | elif line.startswith('copy from '): | |
144 | gp.op = 'COPY' |
|
144 | gp.op = 'COPY' | |
145 | gp.oldpath = line[10:].rstrip() |
|
145 | gp.oldpath = line[10:].rstrip() | |
146 | elif line.startswith('copy to '): |
|
146 | elif line.startswith('copy to '): | |
147 | gp.path = line[8:].rstrip() |
|
147 | gp.path = line[8:].rstrip() | |
148 | elif line.startswith('deleted file'): |
|
148 | elif line.startswith('deleted file'): | |
149 | gp.op = 'DELETE' |
|
149 | gp.op = 'DELETE' | |
150 | elif line.startswith('new file mode '): |
|
150 | elif line.startswith('new file mode '): | |
151 | gp.op = 'ADD' |
|
151 | gp.op = 'ADD' | |
152 | gp.mode = int(line.rstrip()[-3:], 8) |
|
152 | gp.mode = int(line.rstrip()[-3:], 8) | |
153 | elif line.startswith('new mode '): |
|
153 | elif line.startswith('new mode '): | |
154 | gp.mode = int(line.rstrip()[-3:], 8) |
|
154 | gp.mode = int(line.rstrip()[-3:], 8) | |
155 | if gp: |
|
155 | if gp: | |
156 | gitpatches.append(gp) |
|
156 | gitpatches.append(gp) | |
157 |
|
157 | |||
158 | if not gitpatches: |
|
158 | if not gitpatches: | |
159 | dopatch = True |
|
159 | dopatch = True | |
160 |
|
160 | |||
161 | return (dopatch, gitpatches) |
|
161 | return (dopatch, gitpatches) | |
162 |
|
162 | |||
163 | def dogitpatch(patchname, gitpatches): |
|
163 | def dogitpatch(patchname, gitpatches): | |
164 | """Preprocess git patch so that vanilla patch can handle it""" |
|
164 | """Preprocess git patch so that vanilla patch can handle it""" | |
165 | pf = file(patchname) |
|
165 | pf = file(patchname) | |
166 | pfline = 1 |
|
166 | pfline = 1 | |
167 |
|
167 | |||
168 | fd, patchname = tempfile.mkstemp(prefix='hg-patch-') |
|
168 | fd, patchname = tempfile.mkstemp(prefix='hg-patch-') | |
169 | tmpfp = os.fdopen(fd, 'w') |
|
169 | tmpfp = os.fdopen(fd, 'w') | |
170 |
|
170 | |||
171 | try: |
|
171 | try: | |
172 | for i in range(len(gitpatches)): |
|
172 | for i in range(len(gitpatches)): | |
173 | p = gitpatches[i] |
|
173 | p = gitpatches[i] | |
174 | if not p.copymod: |
|
174 | if not p.copymod: | |
175 | continue |
|
175 | continue | |
176 |
|
176 | |||
177 | if os.path.exists(p.path): |
|
177 | if os.path.exists(p.path): | |
178 | raise util.Abort(_("cannot create %s: destination already exists") % |
|
178 | raise util.Abort(_("cannot create %s: destination already exists") % | |
179 | p.path) |
|
179 | p.path) | |
180 |
|
180 | |||
181 | (src, dst) = [os.path.join(os.getcwd(), n) |
|
181 | (src, dst) = [os.path.join(os.getcwd(), n) | |
182 | for n in (p.oldpath, p.path)] |
|
182 | for n in (p.oldpath, p.path)] | |
183 |
|
183 | |||
184 | targetdir = os.path.dirname(dst) |
|
184 | targetdir = os.path.dirname(dst) | |
185 | if not os.path.isdir(targetdir): |
|
185 | if not os.path.isdir(targetdir): | |
186 | os.makedirs(targetdir) |
|
186 | os.makedirs(targetdir) | |
187 | try: |
|
187 | try: | |
188 | shutil.copyfile(src, dst) |
|
188 | shutil.copyfile(src, dst) | |
189 | shutil.copymode(src, dst) |
|
189 | shutil.copymode(src, dst) | |
190 | except shutil.Error, inst: |
|
190 | except shutil.Error, inst: | |
191 | raise util.Abort(str(inst)) |
|
191 | raise util.Abort(str(inst)) | |
192 |
|
192 | |||
193 | # rewrite patch hunk |
|
193 | # rewrite patch hunk | |
194 | while pfline < p.lineno: |
|
194 | while pfline < p.lineno: | |
195 | tmpfp.write(pf.readline()) |
|
195 | tmpfp.write(pf.readline()) | |
196 | pfline += 1 |
|
196 | pfline += 1 | |
197 | tmpfp.write('diff --git a/%s b/%s\n' % (p.path, p.path)) |
|
197 | tmpfp.write('diff --git a/%s b/%s\n' % (p.path, p.path)) | |
198 | line = pf.readline() |
|
198 | line = pf.readline() | |
199 | pfline += 1 |
|
199 | pfline += 1 | |
200 | while not line.startswith('--- a/'): |
|
200 | while not line.startswith('--- a/'): | |
201 | tmpfp.write(line) |
|
201 | tmpfp.write(line) | |
202 | line = pf.readline() |
|
202 | line = pf.readline() | |
203 | pfline += 1 |
|
203 | pfline += 1 | |
204 | tmpfp.write('--- a/%s\n' % p.path) |
|
204 | tmpfp.write('--- a/%s\n' % p.path) | |
205 |
|
205 | |||
206 | line = pf.readline() |
|
206 | line = pf.readline() | |
207 | while line: |
|
207 | while line: | |
208 | tmpfp.write(line) |
|
208 | tmpfp.write(line) | |
209 | line = pf.readline() |
|
209 | line = pf.readline() | |
210 | except: |
|
210 | except: | |
211 | tmpfp.close() |
|
211 | tmpfp.close() | |
212 | os.unlink(patchname) |
|
212 | os.unlink(patchname) | |
213 | raise |
|
213 | raise | |
214 |
|
214 | |||
215 | tmpfp.close() |
|
215 | tmpfp.close() | |
216 | return patchname |
|
216 | return patchname | |
217 |
|
217 | |||
218 |
def patch( |
|
218 | def patch(patchname, ui, strip=1, cwd=None): | |
219 | """apply the patch <patchname> to the working directory. |
|
219 | """apply the patch <patchname> to the working directory. | |
220 | a list of patched files is returned""" |
|
220 | a list of patched files is returned""" | |
221 |
|
221 | |||
222 | (dopatch, gitpatches) = readgitpatch(patchname) |
|
222 | (dopatch, gitpatches) = readgitpatch(patchname) | |
223 |
|
223 | |||
224 | files = {} |
|
224 | files = {} | |
|
225 | fuzz = False | |||
225 | if dopatch: |
|
226 | if dopatch: | |
226 | if dopatch == 'filter': |
|
227 | if dopatch == 'filter': | |
227 | patchname = dogitpatch(patchname, gitpatches) |
|
228 | patchname = dogitpatch(patchname, gitpatches) | |
228 | patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') |
|
229 | patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') | |
229 | args = [] |
|
230 | args = [] | |
230 | if cwd: |
|
231 | if cwd: | |
231 | args.append('-d %s' % util.shellquote(cwd)) |
|
232 | args.append('-d %s' % util.shellquote(cwd)) | |
232 | fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, |
|
233 | fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, | |
233 | util.shellquote(patchname))) |
|
234 | util.shellquote(patchname))) | |
234 |
|
235 | |||
235 | if dopatch == 'filter': |
|
236 | if dopatch == 'filter': | |
236 | False and os.unlink(patchname) |
|
237 | False and os.unlink(patchname) | |
237 |
|
238 | |||
238 | for line in fp: |
|
239 | for line in fp: | |
239 | line = line.rstrip() |
|
240 | line = line.rstrip() | |
240 |
ui. |
|
241 | ui.note(line + '\n') | |
241 | if line.startswith('patching file '): |
|
242 | if line.startswith('patching file '): | |
242 | pf = util.parse_patch_output(line) |
|
243 | pf = util.parse_patch_output(line) | |
|
244 | printed_file = False | |||
243 | files.setdefault(pf, (None, None)) |
|
245 | files.setdefault(pf, (None, None)) | |
|
246 | elif line.find('with fuzz') >= 0: | |||
|
247 | fuzz = True | |||
|
248 | if not printed_file: | |||
|
249 | ui.warn(pf + '\n') | |||
|
250 | printed_file = True | |||
|
251 | ui.warn(line + '\n') | |||
|
252 | elif line.find('saving rejects to file') >= 0: | |||
|
253 | ui.warn(line + '\n') | |||
|
254 | elif line.find('FAILED') >= 0: | |||
|
255 | if not printed_file: | |||
|
256 | ui.warn(pf + '\n') | |||
|
257 | printed_file = True | |||
|
258 | ui.warn(line + '\n') | |||
|
259 | ||||
244 | code = fp.close() |
|
260 | code = fp.close() | |
245 | if code: |
|
261 | if code: | |
246 | raise util.Abort(_("patch command failed: %s") % |
|
262 | raise util.Abort(_("patch command failed: %s") % | |
247 | util.explain_exit(code)[0]) |
|
263 | util.explain_exit(code)[0]) | |
248 |
|
264 | |||
249 | for gp in gitpatches: |
|
265 | for gp in gitpatches: | |
250 | files[gp.path] = (gp.op, gp) |
|
266 | files[gp.path] = (gp.op, gp) | |
251 |
|
267 | |||
252 | return files |
|
268 | return (files, fuzz) | |
253 |
|
269 | |||
254 | def diff(repo, node1=None, node2=None, files=None, match=util.always, |
|
270 | def diff(repo, node1=None, node2=None, files=None, match=util.always, | |
255 | fp=None, changes=None, opts=None): |
|
271 | fp=None, changes=None, opts=None): | |
256 | '''print diff of changes to files between two nodes, or node and |
|
272 | '''print diff of changes to files between two nodes, or node and | |
257 | working directory. |
|
273 | working directory. | |
258 |
|
274 | |||
259 | if node1 is None, use first dirstate parent instead. |
|
275 | if node1 is None, use first dirstate parent instead. | |
260 | if node2 is None, compare node1 with working directory.''' |
|
276 | if node2 is None, compare node1 with working directory.''' | |
261 |
|
277 | |||
262 | if opts is None: |
|
278 | if opts is None: | |
263 | opts = mdiff.defaultopts |
|
279 | opts = mdiff.defaultopts | |
264 | if fp is None: |
|
280 | if fp is None: | |
265 | fp = repo.ui |
|
281 | fp = repo.ui | |
266 |
|
282 | |||
267 | if not node1: |
|
283 | if not node1: | |
268 | node1 = repo.dirstate.parents()[0] |
|
284 | node1 = repo.dirstate.parents()[0] | |
269 | # reading the data for node1 early allows it to play nicely |
|
285 | # reading the data for node1 early allows it to play nicely | |
270 | # with repo.status and the revlog cache. |
|
286 | # with repo.status and the revlog cache. | |
271 | change = repo.changelog.read(node1) |
|
287 | change = repo.changelog.read(node1) | |
272 | mmap = repo.manifest.read(change[0]) |
|
288 | mmap = repo.manifest.read(change[0]) | |
273 | date1 = util.datestr(change[2]) |
|
289 | date1 = util.datestr(change[2]) | |
274 |
|
290 | |||
275 | if not changes: |
|
291 | if not changes: | |
276 | changes = repo.status(node1, node2, files, match=match)[:5] |
|
292 | changes = repo.status(node1, node2, files, match=match)[:5] | |
277 | modified, added, removed, deleted, unknown = changes |
|
293 | modified, added, removed, deleted, unknown = changes | |
278 | if files: |
|
294 | if files: | |
279 | def filterfiles(filters): |
|
295 | def filterfiles(filters): | |
280 | l = [x for x in filters if x in files] |
|
296 | l = [x for x in filters if x in files] | |
281 |
|
297 | |||
282 | for t in files: |
|
298 | for t in files: | |
283 | if not t.endswith("/"): |
|
299 | if not t.endswith("/"): | |
284 | t += "/" |
|
300 | t += "/" | |
285 | l += [x for x in filters if x.startswith(t)] |
|
301 | l += [x for x in filters if x.startswith(t)] | |
286 | return l |
|
302 | return l | |
287 |
|
303 | |||
288 | modified, added, removed = map(filterfiles, (modified, added, removed)) |
|
304 | modified, added, removed = map(filterfiles, (modified, added, removed)) | |
289 |
|
305 | |||
290 | if not modified and not added and not removed: |
|
306 | if not modified and not added and not removed: | |
291 | return |
|
307 | return | |
292 |
|
308 | |||
293 | if node2: |
|
309 | if node2: | |
294 | change = repo.changelog.read(node2) |
|
310 | change = repo.changelog.read(node2) | |
295 | mmap2 = repo.manifest.read(change[0]) |
|
311 | mmap2 = repo.manifest.read(change[0]) | |
296 | _date2 = util.datestr(change[2]) |
|
312 | _date2 = util.datestr(change[2]) | |
297 | def date2(f): |
|
313 | def date2(f): | |
298 | return _date2 |
|
314 | return _date2 | |
299 | def read(f): |
|
315 | def read(f): | |
300 | return repo.file(f).read(mmap2[f]) |
|
316 | return repo.file(f).read(mmap2[f]) | |
301 | def renamed(f): |
|
317 | def renamed(f): | |
302 | src = repo.file(f).renamed(mmap2[f]) |
|
318 | src = repo.file(f).renamed(mmap2[f]) | |
303 | return src and src[0] or None |
|
319 | return src and src[0] or None | |
304 | else: |
|
320 | else: | |
305 | tz = util.makedate()[1] |
|
321 | tz = util.makedate()[1] | |
306 | _date2 = util.datestr() |
|
322 | _date2 = util.datestr() | |
307 | def date2(f): |
|
323 | def date2(f): | |
308 | try: |
|
324 | try: | |
309 | return util.datestr((os.lstat(repo.wjoin(f)).st_mtime, tz)) |
|
325 | return util.datestr((os.lstat(repo.wjoin(f)).st_mtime, tz)) | |
310 | except OSError, err: |
|
326 | except OSError, err: | |
311 | if err.errno != errno.ENOENT: raise |
|
327 | if err.errno != errno.ENOENT: raise | |
312 | return _date2 |
|
328 | return _date2 | |
313 | def read(f): |
|
329 | def read(f): | |
314 | return repo.wread(f) |
|
330 | return repo.wread(f) | |
315 | def renamed(f): |
|
331 | def renamed(f): | |
316 | return repo.dirstate.copies.get(f) |
|
332 | return repo.dirstate.copies.get(f) | |
317 |
|
333 | |||
318 | if repo.ui.quiet: |
|
334 | if repo.ui.quiet: | |
319 | r = None |
|
335 | r = None | |
320 | else: |
|
336 | else: | |
321 | hexfunc = repo.ui.verbose and hex or short |
|
337 | hexfunc = repo.ui.verbose and hex or short | |
322 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
338 | r = [hexfunc(node) for node in [node1, node2] if node] | |
323 |
|
339 | |||
324 | if opts.git: |
|
340 | if opts.git: | |
325 | copied = {} |
|
341 | copied = {} | |
326 | for f in added: |
|
342 | for f in added: | |
327 | src = renamed(f) |
|
343 | src = renamed(f) | |
328 | if src: |
|
344 | if src: | |
329 | copied[f] = src |
|
345 | copied[f] = src | |
330 | srcs = [x[1] for x in copied.items()] |
|
346 | srcs = [x[1] for x in copied.items()] | |
331 |
|
347 | |||
332 | all = modified + added + removed |
|
348 | all = modified + added + removed | |
333 | all.sort() |
|
349 | all.sort() | |
334 | for f in all: |
|
350 | for f in all: | |
335 | to = None |
|
351 | to = None | |
336 | tn = None |
|
352 | tn = None | |
337 | dodiff = True |
|
353 | dodiff = True | |
338 | if f in mmap: |
|
354 | if f in mmap: | |
339 | to = repo.file(f).read(mmap[f]) |
|
355 | to = repo.file(f).read(mmap[f]) | |
340 | if f not in removed: |
|
356 | if f not in removed: | |
341 | tn = read(f) |
|
357 | tn = read(f) | |
342 | if opts.git: |
|
358 | if opts.git: | |
343 | def gitmode(x): |
|
359 | def gitmode(x): | |
344 | return x and '100755' or '100644' |
|
360 | return x and '100755' or '100644' | |
345 | def addmodehdr(header, omode, nmode): |
|
361 | def addmodehdr(header, omode, nmode): | |
346 | if omode != nmode: |
|
362 | if omode != nmode: | |
347 | header.append('old mode %s\n' % omode) |
|
363 | header.append('old mode %s\n' % omode) | |
348 | header.append('new mode %s\n' % nmode) |
|
364 | header.append('new mode %s\n' % nmode) | |
349 |
|
365 | |||
350 | a, b = f, f |
|
366 | a, b = f, f | |
351 | header = [] |
|
367 | header = [] | |
352 | if f in added: |
|
368 | if f in added: | |
353 | if node2: |
|
369 | if node2: | |
354 | mode = gitmode(mmap2.execf(f)) |
|
370 | mode = gitmode(mmap2.execf(f)) | |
355 | else: |
|
371 | else: | |
356 | mode = gitmode(util.is_exec(repo.wjoin(f), None)) |
|
372 | mode = gitmode(util.is_exec(repo.wjoin(f), None)) | |
357 | if f in copied: |
|
373 | if f in copied: | |
358 | a = copied[f] |
|
374 | a = copied[f] | |
359 | omode = gitmode(mmap.execf(a)) |
|
375 | omode = gitmode(mmap.execf(a)) | |
360 | addmodehdr(header, omode, mode) |
|
376 | addmodehdr(header, omode, mode) | |
361 | op = a in removed and 'rename' or 'copy' |
|
377 | op = a in removed and 'rename' or 'copy' | |
362 | header.append('%s from %s\n' % (op, a)) |
|
378 | header.append('%s from %s\n' % (op, a)) | |
363 | header.append('%s to %s\n' % (op, f)) |
|
379 | header.append('%s to %s\n' % (op, f)) | |
364 | to = repo.file(a).read(mmap[a]) |
|
380 | to = repo.file(a).read(mmap[a]) | |
365 | else: |
|
381 | else: | |
366 | header.append('new file mode %s\n' % mode) |
|
382 | header.append('new file mode %s\n' % mode) | |
367 | elif f in removed: |
|
383 | elif f in removed: | |
368 | if f in srcs: |
|
384 | if f in srcs: | |
369 | dodiff = False |
|
385 | dodiff = False | |
370 | else: |
|
386 | else: | |
371 | mode = gitmode(mmap.execf(f)) |
|
387 | mode = gitmode(mmap.execf(f)) | |
372 | header.append('deleted file mode %s\n' % mode) |
|
388 | header.append('deleted file mode %s\n' % mode) | |
373 | else: |
|
389 | else: | |
374 | omode = gitmode(mmap.execf(f)) |
|
390 | omode = gitmode(mmap.execf(f)) | |
375 | nmode = gitmode(util.is_exec(repo.wjoin(f), mmap.execf(f))) |
|
391 | nmode = gitmode(util.is_exec(repo.wjoin(f), mmap.execf(f))) | |
376 | addmodehdr(header, omode, nmode) |
|
392 | addmodehdr(header, omode, nmode) | |
377 | r = None |
|
393 | r = None | |
378 | if dodiff: |
|
394 | if dodiff: | |
379 | header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) |
|
395 | header.insert(0, 'diff --git a/%s b/%s\n' % (a, b)) | |
380 | fp.write(''.join(header)) |
|
396 | fp.write(''.join(header)) | |
381 | if dodiff: |
|
397 | if dodiff: | |
382 | fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, opts=opts)) |
|
398 | fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, opts=opts)) | |
383 |
|
399 | |||
384 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
|
400 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, | |
385 | opts=None): |
|
401 | opts=None): | |
386 | '''export changesets as hg patches.''' |
|
402 | '''export changesets as hg patches.''' | |
387 |
|
403 | |||
388 | total = len(revs) |
|
404 | total = len(revs) | |
389 | revwidth = max(map(len, revs)) |
|
405 | revwidth = max(map(len, revs)) | |
390 |
|
406 | |||
391 | def single(node, seqno, fp): |
|
407 | def single(node, seqno, fp): | |
392 | parents = [p for p in repo.changelog.parents(node) if p != nullid] |
|
408 | parents = [p for p in repo.changelog.parents(node) if p != nullid] | |
393 | if switch_parent: |
|
409 | if switch_parent: | |
394 | parents.reverse() |
|
410 | parents.reverse() | |
395 | prev = (parents and parents[0]) or nullid |
|
411 | prev = (parents and parents[0]) or nullid | |
396 | change = repo.changelog.read(node) |
|
412 | change = repo.changelog.read(node) | |
397 |
|
413 | |||
398 | if not fp: |
|
414 | if not fp: | |
399 | fp = cmdutil.make_file(repo, template, node, total=total, |
|
415 | fp = cmdutil.make_file(repo, template, node, total=total, | |
400 | seqno=seqno, revwidth=revwidth) |
|
416 | seqno=seqno, revwidth=revwidth) | |
401 | if fp not in (sys.stdout, repo.ui): |
|
417 | if fp not in (sys.stdout, repo.ui): | |
402 | repo.ui.note("%s\n" % fp.name) |
|
418 | repo.ui.note("%s\n" % fp.name) | |
403 |
|
419 | |||
404 | fp.write("# HG changeset patch\n") |
|
420 | fp.write("# HG changeset patch\n") | |
405 | fp.write("# User %s\n" % change[1]) |
|
421 | fp.write("# User %s\n" % change[1]) | |
406 | fp.write("# Date %d %d\n" % change[2]) |
|
422 | fp.write("# Date %d %d\n" % change[2]) | |
407 | fp.write("# Node ID %s\n" % hex(node)) |
|
423 | fp.write("# Node ID %s\n" % hex(node)) | |
408 | fp.write("# Parent %s\n" % hex(prev)) |
|
424 | fp.write("# Parent %s\n" % hex(prev)) | |
409 | if len(parents) > 1: |
|
425 | if len(parents) > 1: | |
410 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
426 | fp.write("# Parent %s\n" % hex(parents[1])) | |
411 | fp.write(change[4].rstrip()) |
|
427 | fp.write(change[4].rstrip()) | |
412 | fp.write("\n\n") |
|
428 | fp.write("\n\n") | |
413 |
|
429 | |||
414 | diff(repo, prev, node, fp=fp, opts=opts) |
|
430 | diff(repo, prev, node, fp=fp, opts=opts) | |
415 | if fp not in (sys.stdout, repo.ui): |
|
431 | if fp not in (sys.stdout, repo.ui): | |
416 | fp.close() |
|
432 | fp.close() | |
417 |
|
433 | |||
418 | for seqno, cset in enumerate(revs): |
|
434 | for seqno, cset in enumerate(revs): | |
419 | single(cset, seqno, fp) |
|
435 | single(cset, seqno, fp) |
@@ -1,39 +1,34 b'' | |||||
1 | % new file |
|
1 | % new file | |
2 | applying patch from stdin |
|
2 | applying patch from stdin | |
3 | patching file new |
|
|||
4 | % chmod +x |
|
3 | % chmod +x | |
5 | applying patch from stdin |
|
4 | applying patch from stdin | |
6 | % copy |
|
5 | % copy | |
7 | applying patch from stdin |
|
6 | applying patch from stdin | |
8 | a |
|
7 | a | |
9 | a |
|
8 | a | |
10 | % rename |
|
9 | % rename | |
11 | applying patch from stdin |
|
10 | applying patch from stdin | |
12 | copyx |
|
11 | copyx | |
13 | new |
|
12 | new | |
14 | rename |
|
13 | rename | |
15 | % delete |
|
14 | % delete | |
16 | applying patch from stdin |
|
15 | applying patch from stdin | |
17 | patching file copyx |
|
|||
18 | new |
|
16 | new | |
19 | rename |
|
17 | rename | |
20 | % regular diff |
|
18 | % regular diff | |
21 | applying patch from stdin |
|
19 | applying patch from stdin | |
22 | patching file rename |
|
|||
23 | % copy and modify |
|
20 | % copy and modify | |
24 | applying patch from stdin |
|
21 | applying patch from stdin | |
25 | patching file copy2 |
|
|||
26 | a |
|
22 | a | |
27 | a |
|
23 | a | |
28 | b |
|
24 | b | |
29 | a |
|
25 | a | |
30 | a |
|
26 | a | |
31 | % rename and modify |
|
27 | % rename and modify | |
32 | applying patch from stdin |
|
28 | applying patch from stdin | |
33 | patching file rename2 |
|
|||
34 | copy2: No such file or directory |
|
29 | copy2: No such file or directory | |
35 | a |
|
30 | a | |
36 | a |
|
31 | a | |
37 | b |
|
32 | b | |
38 | c |
|
33 | c | |
39 | a |
|
34 | a |
@@ -1,118 +1,107 b'' | |||||
1 | adding a |
|
1 | adding a | |
2 | adding d1/d2/a |
|
2 | adding d1/d2/a | |
3 | % import exported patch |
|
3 | % import exported patch | |
4 | requesting all changes |
|
4 | requesting all changes | |
5 | adding changesets |
|
5 | adding changesets | |
6 | adding manifests |
|
6 | adding manifests | |
7 | adding file changes |
|
7 | adding file changes | |
8 | added 1 changesets with 2 changes to 2 files |
|
8 | added 1 changesets with 2 changes to 2 files | |
9 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
9 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
10 | applying ../tip.patch |
|
10 | applying ../tip.patch | |
11 | patching file a |
|
|||
12 | % message should be same |
|
11 | % message should be same | |
13 | summary: second change |
|
12 | summary: second change | |
14 | % committer should be same |
|
13 | % committer should be same | |
15 | user: someone |
|
14 | user: someone | |
16 | % import of plain diff should fail without message |
|
15 | % import of plain diff should fail without message | |
17 | requesting all changes |
|
16 | requesting all changes | |
18 | adding changesets |
|
17 | adding changesets | |
19 | adding manifests |
|
18 | adding manifests | |
20 | adding file changes |
|
19 | adding file changes | |
21 | added 1 changesets with 2 changes to 2 files |
|
20 | added 1 changesets with 2 changes to 2 files | |
22 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
21 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
23 | applying ../tip.patch |
|
22 | applying ../tip.patch | |
24 | patching file a |
|
|||
25 | transaction abort! |
|
23 | transaction abort! | |
26 | rollback completed |
|
24 | rollback completed | |
27 | % import of plain diff should be ok with message |
|
25 | % import of plain diff should be ok with message | |
28 | requesting all changes |
|
26 | requesting all changes | |
29 | adding changesets |
|
27 | adding changesets | |
30 | adding manifests |
|
28 | adding manifests | |
31 | adding file changes |
|
29 | adding file changes | |
32 | added 1 changesets with 2 changes to 2 files |
|
30 | added 1 changesets with 2 changes to 2 files | |
33 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
31 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
34 | applying ../tip.patch |
|
32 | applying ../tip.patch | |
35 | patching file a |
|
|||
36 | % import from stdin |
|
33 | % import from stdin | |
37 | requesting all changes |
|
34 | requesting all changes | |
38 | adding changesets |
|
35 | adding changesets | |
39 | adding manifests |
|
36 | adding manifests | |
40 | adding file changes |
|
37 | adding file changes | |
41 | added 1 changesets with 2 changes to 2 files |
|
38 | added 1 changesets with 2 changes to 2 files | |
42 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
39 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
43 | applying patch from stdin |
|
40 | applying patch from stdin | |
44 | patching file a |
|
|||
45 | % override commit message |
|
41 | % override commit message | |
46 | requesting all changes |
|
42 | requesting all changes | |
47 | adding changesets |
|
43 | adding changesets | |
48 | adding manifests |
|
44 | adding manifests | |
49 | adding file changes |
|
45 | adding file changes | |
50 | added 1 changesets with 2 changes to 2 files |
|
46 | added 1 changesets with 2 changes to 2 files | |
51 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
47 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
52 | applying patch from stdin |
|
48 | applying patch from stdin | |
53 | patching file a |
|
|||
54 | summary: override |
|
49 | summary: override | |
55 | % plain diff in email, subject, message body |
|
50 | % plain diff in email, subject, message body | |
56 | requesting all changes |
|
51 | requesting all changes | |
57 | adding changesets |
|
52 | adding changesets | |
58 | adding manifests |
|
53 | adding manifests | |
59 | adding file changes |
|
54 | adding file changes | |
60 | added 1 changesets with 2 changes to 2 files |
|
55 | added 1 changesets with 2 changes to 2 files | |
61 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
56 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
62 | applying ../msg.patch |
|
57 | applying ../msg.patch | |
63 | patching file a |
|
|||
64 | user: email patcher |
|
58 | user: email patcher | |
65 | summary: email patch |
|
59 | summary: email patch | |
66 | % plain diff in email, no subject, message body |
|
60 | % plain diff in email, no subject, message body | |
67 | requesting all changes |
|
61 | requesting all changes | |
68 | adding changesets |
|
62 | adding changesets | |
69 | adding manifests |
|
63 | adding manifests | |
70 | adding file changes |
|
64 | adding file changes | |
71 | added 1 changesets with 2 changes to 2 files |
|
65 | added 1 changesets with 2 changes to 2 files | |
72 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
66 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
73 | applying patch from stdin |
|
67 | applying patch from stdin | |
74 | patching file a |
|
|||
75 | % plain diff in email, subject, no message body |
|
68 | % plain diff in email, subject, no message body | |
76 | requesting all changes |
|
69 | requesting all changes | |
77 | adding changesets |
|
70 | adding changesets | |
78 | adding manifests |
|
71 | adding manifests | |
79 | adding file changes |
|
72 | adding file changes | |
80 | added 1 changesets with 2 changes to 2 files |
|
73 | added 1 changesets with 2 changes to 2 files | |
81 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
74 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
82 | applying patch from stdin |
|
75 | applying patch from stdin | |
83 | patching file a |
|
|||
84 | % plain diff in email, no subject, no message body, should fail |
|
76 | % plain diff in email, no subject, no message body, should fail | |
85 | requesting all changes |
|
77 | requesting all changes | |
86 | adding changesets |
|
78 | adding changesets | |
87 | adding manifests |
|
79 | adding manifests | |
88 | adding file changes |
|
80 | adding file changes | |
89 | added 1 changesets with 2 changes to 2 files |
|
81 | added 1 changesets with 2 changes to 2 files | |
90 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
82 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
91 | applying patch from stdin |
|
83 | applying patch from stdin | |
92 | patching file a |
|
|||
93 | transaction abort! |
|
84 | transaction abort! | |
94 | rollback completed |
|
85 | rollback completed | |
95 | % hg export in email, should use patch header |
|
86 | % hg export in email, should use patch header | |
96 | requesting all changes |
|
87 | requesting all changes | |
97 | adding changesets |
|
88 | adding changesets | |
98 | adding manifests |
|
89 | adding manifests | |
99 | adding file changes |
|
90 | adding file changes | |
100 | added 1 changesets with 2 changes to 2 files |
|
91 | added 1 changesets with 2 changes to 2 files | |
101 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
92 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
102 | applying patch from stdin |
|
93 | applying patch from stdin | |
103 | patching file a |
|
|||
104 | summary: second change |
|
94 | summary: second change | |
105 | % hg import in a subdirectory |
|
95 | % hg import in a subdirectory | |
106 | requesting all changes |
|
96 | requesting all changes | |
107 | adding changesets |
|
97 | adding changesets | |
108 | adding manifests |
|
98 | adding manifests | |
109 | adding file changes |
|
99 | adding file changes | |
110 | added 1 changesets with 2 changes to 2 files |
|
100 | added 1 changesets with 2 changes to 2 files | |
111 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
101 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
112 | applying ../../../tip.patch |
|
102 | applying ../../../tip.patch | |
113 | patching file a |
|
|||
114 | % message should be 'subdir change' |
|
103 | % message should be 'subdir change' | |
115 | summary: subdir change |
|
104 | summary: subdir change | |
116 | % committer should be 'someoneelse' |
|
105 | % committer should be 'someoneelse' | |
117 | user: someoneelse |
|
106 | user: someoneelse | |
118 | % should be empty |
|
107 | % should be empty |
General Comments 0
You need to be logged in to leave comments.
Login now