Show More
@@ -1,2976 +1,2970 | |||||
1 | # commands.py - command processing for mercurial |
|
1 | # commands.py - command processing for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005 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") |
|
12 | demandload(globals(), "fancyopts ui hg util lock revlog") | |
13 | demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") |
|
13 | demandload(globals(), "fnmatch hgweb mdiff random signal time traceback") | |
14 | demandload(globals(), "errno socket version struct atexit sets bz2") |
|
14 | demandload(globals(), "errno socket version struct atexit sets bz2") | |
15 |
|
15 | |||
16 | class UnknownCommand(Exception): |
|
16 | class UnknownCommand(Exception): | |
17 | """Exception raised if command is not in the command table.""" |
|
17 | """Exception raised if command is not in the command table.""" | |
18 | class AmbiguousCommand(Exception): |
|
18 | class AmbiguousCommand(Exception): | |
19 | """Exception raised if command shortcut matches more than one command.""" |
|
19 | """Exception raised if command shortcut matches more than one command.""" | |
20 |
|
20 | |||
21 | def filterfiles(filters, files): |
|
21 | def filterfiles(filters, files): | |
22 | l = [x for x in files if x in filters] |
|
22 | l = [x for x in files if x in filters] | |
23 |
|
23 | |||
24 | for t in filters: |
|
24 | for t in filters: | |
25 | if t and t[-1] != "/": |
|
25 | if t and t[-1] != "/": | |
26 | t += "/" |
|
26 | t += "/" | |
27 | l += [x for x in files if x.startswith(t)] |
|
27 | l += [x for x in files if x.startswith(t)] | |
28 | return l |
|
28 | return l | |
29 |
|
29 | |||
30 | def relpath(repo, args): |
|
30 | def relpath(repo, args): | |
31 | cwd = repo.getcwd() |
|
31 | cwd = repo.getcwd() | |
32 | if cwd: |
|
32 | if cwd: | |
33 | return [util.normpath(os.path.join(cwd, x)) for x in args] |
|
33 | return [util.normpath(os.path.join(cwd, x)) for x in args] | |
34 | return args |
|
34 | return args | |
35 |
|
35 | |||
36 | def matchpats(repo, pats=[], opts={}, head=''): |
|
36 | def matchpats(repo, pats=[], opts={}, head=''): | |
37 | cwd = repo.getcwd() |
|
37 | cwd = repo.getcwd() | |
38 | if not pats and cwd: |
|
38 | if not pats and cwd: | |
39 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
|
39 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
40 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
|
40 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
41 | cwd = '' |
|
41 | cwd = '' | |
42 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
42 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | |
43 | opts.get('exclude'), head) |
|
43 | opts.get('exclude'), head) | |
44 |
|
44 | |||
45 | def makewalk(repo, pats, opts, node=None, head=''): |
|
45 | def makewalk(repo, pats, opts, node=None, head=''): | |
46 | files, matchfn, anypats = matchpats(repo, pats, opts, head) |
|
46 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | |
47 | exact = dict(zip(files, files)) |
|
47 | exact = dict(zip(files, files)) | |
48 | def walk(): |
|
48 | def walk(): | |
49 | for src, fn in repo.walk(node=node, files=files, match=matchfn): |
|
49 | for src, fn in repo.walk(node=node, files=files, match=matchfn): | |
50 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
50 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
51 | return files, matchfn, walk() |
|
51 | return files, matchfn, walk() | |
52 |
|
52 | |||
53 | def walk(repo, pats, opts, node=None, head=''): |
|
53 | def walk(repo, pats, opts, node=None, head=''): | |
54 | files, matchfn, results = makewalk(repo, pats, opts, node, head) |
|
54 | files, matchfn, results = makewalk(repo, pats, opts, node, head) | |
55 | for r in results: |
|
55 | for r in results: | |
56 | yield r |
|
56 | yield r | |
57 |
|
57 | |||
58 | def walkchangerevs(ui, repo, pats, opts): |
|
58 | def walkchangerevs(ui, repo, pats, opts): | |
59 | '''Iterate over files and the revs they changed in. |
|
59 | '''Iterate over files and the revs they changed in. | |
60 |
|
60 | |||
61 | Callers most commonly need to iterate backwards over the history |
|
61 | Callers most commonly need to iterate backwards over the history | |
62 | it is interested in. Doing so has awful (quadratic-looking) |
|
62 | it is interested in. Doing so has awful (quadratic-looking) | |
63 | performance, so we use iterators in a "windowed" way. |
|
63 | performance, so we use iterators in a "windowed" way. | |
64 |
|
64 | |||
65 | We walk a window of revisions in the desired order. Within the |
|
65 | We walk a window of revisions in the desired order. Within the | |
66 | window, we first walk forwards to gather data, then in the desired |
|
66 | window, we first walk forwards to gather data, then in the desired | |
67 | order (usually backwards) to display it. |
|
67 | order (usually backwards) to display it. | |
68 |
|
68 | |||
69 | This function returns an (iterator, getchange, matchfn) tuple. The |
|
69 | This function returns an (iterator, getchange, matchfn) tuple. The | |
70 | getchange function returns the changelog entry for a numeric |
|
70 | getchange function returns the changelog entry for a numeric | |
71 | revision. The iterator yields 3-tuples. They will be of one of |
|
71 | revision. The iterator yields 3-tuples. They will be of one of | |
72 | the following forms: |
|
72 | the following forms: | |
73 |
|
73 | |||
74 | "window", incrementing, lastrev: stepping through a window, |
|
74 | "window", incrementing, lastrev: stepping through a window, | |
75 | positive if walking forwards through revs, last rev in the |
|
75 | positive if walking forwards through revs, last rev in the | |
76 | sequence iterated over - use to reset state for the current window |
|
76 | sequence iterated over - use to reset state for the current window | |
77 |
|
77 | |||
78 | "add", rev, fns: out-of-order traversal of the given file names |
|
78 | "add", rev, fns: out-of-order traversal of the given file names | |
79 | fns, which changed during revision rev - use to gather data for |
|
79 | fns, which changed during revision rev - use to gather data for | |
80 | possible display |
|
80 | possible display | |
81 |
|
81 | |||
82 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
82 | "iter", rev, None: in-order traversal of the revs earlier iterated | |
83 | over with "add" - use to display data''' |
|
83 | over with "add" - use to display data''' | |
84 |
|
84 | |||
85 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
85 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
86 | if start < end: |
|
86 | if start < end: | |
87 | while start < end: |
|
87 | while start < end: | |
88 | yield start, min(windowsize, end-start) |
|
88 | yield start, min(windowsize, end-start) | |
89 | start += windowsize |
|
89 | start += windowsize | |
90 | if windowsize < sizelimit: |
|
90 | if windowsize < sizelimit: | |
91 | windowsize *= 2 |
|
91 | windowsize *= 2 | |
92 | else: |
|
92 | else: | |
93 | while start > end: |
|
93 | while start > end: | |
94 | yield start, min(windowsize, start-end-1) |
|
94 | yield start, min(windowsize, start-end-1) | |
95 | start -= windowsize |
|
95 | start -= windowsize | |
96 | if windowsize < sizelimit: |
|
96 | if windowsize < sizelimit: | |
97 | windowsize *= 2 |
|
97 | windowsize *= 2 | |
98 |
|
98 | |||
99 |
|
99 | |||
100 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
100 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
101 |
|
101 | |||
102 | if repo.changelog.count() == 0: |
|
102 | if repo.changelog.count() == 0: | |
103 | return [], False, matchfn |
|
103 | return [], False, matchfn | |
104 |
|
104 | |||
105 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
|
105 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | |
106 | wanted = {} |
|
106 | wanted = {} | |
107 | slowpath = anypats |
|
107 | slowpath = anypats | |
108 | fncache = {} |
|
108 | fncache = {} | |
109 |
|
109 | |||
110 | chcache = {} |
|
110 | chcache = {} | |
111 | def getchange(rev): |
|
111 | def getchange(rev): | |
112 | ch = chcache.get(rev) |
|
112 | ch = chcache.get(rev) | |
113 | if ch is None: |
|
113 | if ch is None: | |
114 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) |
|
114 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) | |
115 | return ch |
|
115 | return ch | |
116 |
|
116 | |||
117 | if not slowpath and not files: |
|
117 | if not slowpath and not files: | |
118 | # No files, no patterns. Display all revs. |
|
118 | # No files, no patterns. Display all revs. | |
119 | wanted = dict(zip(revs, revs)) |
|
119 | wanted = dict(zip(revs, revs)) | |
120 | if not slowpath: |
|
120 | if not slowpath: | |
121 | # Only files, no patterns. Check the history of each file. |
|
121 | # Only files, no patterns. Check the history of each file. | |
122 | def filerevgen(filelog): |
|
122 | def filerevgen(filelog): | |
123 | for i, window in increasing_windows(filelog.count()-1, -1): |
|
123 | for i, window in increasing_windows(filelog.count()-1, -1): | |
124 | revs = [] |
|
124 | revs = [] | |
125 | for j in xrange(i - window, i + 1): |
|
125 | for j in xrange(i - window, i + 1): | |
126 | revs.append(filelog.linkrev(filelog.node(j))) |
|
126 | revs.append(filelog.linkrev(filelog.node(j))) | |
127 | revs.reverse() |
|
127 | revs.reverse() | |
128 | for rev in revs: |
|
128 | for rev in revs: | |
129 | yield rev |
|
129 | yield rev | |
130 |
|
130 | |||
131 | minrev, maxrev = min(revs), max(revs) |
|
131 | minrev, maxrev = min(revs), max(revs) | |
132 | for file_ in files: |
|
132 | for file_ in files: | |
133 | filelog = repo.file(file_) |
|
133 | filelog = repo.file(file_) | |
134 | # A zero count may be a directory or deleted file, so |
|
134 | # A zero count may be a directory or deleted file, so | |
135 | # try to find matching entries on the slow path. |
|
135 | # try to find matching entries on the slow path. | |
136 | if filelog.count() == 0: |
|
136 | if filelog.count() == 0: | |
137 | slowpath = True |
|
137 | slowpath = True | |
138 | break |
|
138 | break | |
139 | for rev in filerevgen(filelog): |
|
139 | for rev in filerevgen(filelog): | |
140 | if rev <= maxrev: |
|
140 | if rev <= maxrev: | |
141 | if rev < minrev: |
|
141 | if rev < minrev: | |
142 | break |
|
142 | break | |
143 | fncache.setdefault(rev, []) |
|
143 | fncache.setdefault(rev, []) | |
144 | fncache[rev].append(file_) |
|
144 | fncache[rev].append(file_) | |
145 | wanted[rev] = 1 |
|
145 | wanted[rev] = 1 | |
146 | if slowpath: |
|
146 | if slowpath: | |
147 | # The slow path checks files modified in every changeset. |
|
147 | # The slow path checks files modified in every changeset. | |
148 | def changerevgen(): |
|
148 | def changerevgen(): | |
149 | for i, window in increasing_windows(repo.changelog.count()-1, -1): |
|
149 | for i, window in increasing_windows(repo.changelog.count()-1, -1): | |
150 | for j in xrange(i - window, i + 1): |
|
150 | for j in xrange(i - window, i + 1): | |
151 | yield j, getchange(j)[3] |
|
151 | yield j, getchange(j)[3] | |
152 |
|
152 | |||
153 | for rev, changefiles in changerevgen(): |
|
153 | for rev, changefiles in changerevgen(): | |
154 | matches = filter(matchfn, changefiles) |
|
154 | matches = filter(matchfn, changefiles) | |
155 | if matches: |
|
155 | if matches: | |
156 | fncache[rev] = matches |
|
156 | fncache[rev] = matches | |
157 | wanted[rev] = 1 |
|
157 | wanted[rev] = 1 | |
158 |
|
158 | |||
159 | def iterate(): |
|
159 | def iterate(): | |
160 | for i, window in increasing_windows(0, len(revs)): |
|
160 | for i, window in increasing_windows(0, len(revs)): | |
161 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
161 | yield 'window', revs[0] < revs[-1], revs[-1] | |
162 | nrevs = [rev for rev in revs[i:i+window] |
|
162 | nrevs = [rev for rev in revs[i:i+window] | |
163 | if rev in wanted] |
|
163 | if rev in wanted] | |
164 | srevs = list(nrevs) |
|
164 | srevs = list(nrevs) | |
165 | srevs.sort() |
|
165 | srevs.sort() | |
166 | for rev in srevs: |
|
166 | for rev in srevs: | |
167 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) |
|
167 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) | |
168 | yield 'add', rev, fns |
|
168 | yield 'add', rev, fns | |
169 | for rev in nrevs: |
|
169 | for rev in nrevs: | |
170 | yield 'iter', rev, None |
|
170 | yield 'iter', rev, None | |
171 | return iterate(), getchange, matchfn |
|
171 | return iterate(), getchange, matchfn | |
172 |
|
172 | |||
173 | revrangesep = ':' |
|
173 | revrangesep = ':' | |
174 |
|
174 | |||
175 | def revrange(ui, repo, revs, revlog=None): |
|
175 | def revrange(ui, repo, revs, revlog=None): | |
176 | """Yield revision as strings from a list of revision specifications.""" |
|
176 | """Yield revision as strings from a list of revision specifications.""" | |
177 | if revlog is None: |
|
177 | if revlog is None: | |
178 | revlog = repo.changelog |
|
178 | revlog = repo.changelog | |
179 | revcount = revlog.count() |
|
179 | revcount = revlog.count() | |
180 | def fix(val, defval): |
|
180 | def fix(val, defval): | |
181 | if not val: |
|
181 | if not val: | |
182 | return defval |
|
182 | return defval | |
183 | try: |
|
183 | try: | |
184 | num = int(val) |
|
184 | num = int(val) | |
185 | if str(num) != val: |
|
185 | if str(num) != val: | |
186 | raise ValueError |
|
186 | raise ValueError | |
187 | if num < 0: |
|
187 | if num < 0: | |
188 | num += revcount |
|
188 | num += revcount | |
189 | if num < 0: |
|
189 | if num < 0: | |
190 | num = 0 |
|
190 | num = 0 | |
191 | elif num >= revcount: |
|
191 | elif num >= revcount: | |
192 | raise ValueError |
|
192 | raise ValueError | |
193 | except ValueError: |
|
193 | except ValueError: | |
194 | try: |
|
194 | try: | |
195 | num = repo.changelog.rev(repo.lookup(val)) |
|
195 | num = repo.changelog.rev(repo.lookup(val)) | |
196 | except KeyError: |
|
196 | except KeyError: | |
197 | try: |
|
197 | try: | |
198 | num = revlog.rev(revlog.lookup(val)) |
|
198 | num = revlog.rev(revlog.lookup(val)) | |
199 | except KeyError: |
|
199 | except KeyError: | |
200 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
200 | raise util.Abort(_('invalid revision identifier %s'), val) | |
201 | return num |
|
201 | return num | |
202 | seen = {} |
|
202 | seen = {} | |
203 | for spec in revs: |
|
203 | for spec in revs: | |
204 | if spec.find(revrangesep) >= 0: |
|
204 | if spec.find(revrangesep) >= 0: | |
205 | start, end = spec.split(revrangesep, 1) |
|
205 | start, end = spec.split(revrangesep, 1) | |
206 | start = fix(start, 0) |
|
206 | start = fix(start, 0) | |
207 | end = fix(end, revcount - 1) |
|
207 | end = fix(end, revcount - 1) | |
208 | step = start > end and -1 or 1 |
|
208 | step = start > end and -1 or 1 | |
209 | for rev in xrange(start, end+step, step): |
|
209 | for rev in xrange(start, end+step, step): | |
210 | if rev in seen: |
|
210 | if rev in seen: | |
211 | continue |
|
211 | continue | |
212 | seen[rev] = 1 |
|
212 | seen[rev] = 1 | |
213 | yield str(rev) |
|
213 | yield str(rev) | |
214 | else: |
|
214 | else: | |
215 | rev = fix(spec, None) |
|
215 | rev = fix(spec, None) | |
216 | if rev in seen: |
|
216 | if rev in seen: | |
217 | continue |
|
217 | continue | |
218 | seen[rev] = 1 |
|
218 | seen[rev] = 1 | |
219 | yield str(rev) |
|
219 | yield str(rev) | |
220 |
|
220 | |||
221 | def make_filename(repo, r, pat, node=None, |
|
221 | def make_filename(repo, r, pat, node=None, | |
222 | total=None, seqno=None, revwidth=None, pathname=None): |
|
222 | total=None, seqno=None, revwidth=None, pathname=None): | |
223 | node_expander = { |
|
223 | node_expander = { | |
224 | 'H': lambda: hex(node), |
|
224 | 'H': lambda: hex(node), | |
225 | 'R': lambda: str(r.rev(node)), |
|
225 | 'R': lambda: str(r.rev(node)), | |
226 | 'h': lambda: short(node), |
|
226 | 'h': lambda: short(node), | |
227 | } |
|
227 | } | |
228 | expander = { |
|
228 | expander = { | |
229 | '%': lambda: '%', |
|
229 | '%': lambda: '%', | |
230 | 'b': lambda: os.path.basename(repo.root), |
|
230 | 'b': lambda: os.path.basename(repo.root), | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | try: |
|
233 | try: | |
234 | if node: |
|
234 | if node: | |
235 | expander.update(node_expander) |
|
235 | expander.update(node_expander) | |
236 | if node and revwidth is not None: |
|
236 | if node and revwidth is not None: | |
237 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) |
|
237 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | |
238 | if total is not None: |
|
238 | if total is not None: | |
239 | expander['N'] = lambda: str(total) |
|
239 | expander['N'] = lambda: str(total) | |
240 | if seqno is not None: |
|
240 | if seqno is not None: | |
241 | expander['n'] = lambda: str(seqno) |
|
241 | expander['n'] = lambda: str(seqno) | |
242 | if total is not None and seqno is not None: |
|
242 | if total is not None and seqno is not None: | |
243 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) |
|
243 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) | |
244 | if pathname is not None: |
|
244 | if pathname is not None: | |
245 | expander['s'] = lambda: os.path.basename(pathname) |
|
245 | expander['s'] = lambda: os.path.basename(pathname) | |
246 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
246 | expander['d'] = lambda: os.path.dirname(pathname) or '.' | |
247 | expander['p'] = lambda: pathname |
|
247 | expander['p'] = lambda: pathname | |
248 |
|
248 | |||
249 | newname = [] |
|
249 | newname = [] | |
250 | patlen = len(pat) |
|
250 | patlen = len(pat) | |
251 | i = 0 |
|
251 | i = 0 | |
252 | while i < patlen: |
|
252 | while i < patlen: | |
253 | c = pat[i] |
|
253 | c = pat[i] | |
254 | if c == '%': |
|
254 | if c == '%': | |
255 | i += 1 |
|
255 | i += 1 | |
256 | c = pat[i] |
|
256 | c = pat[i] | |
257 | c = expander[c]() |
|
257 | c = expander[c]() | |
258 | newname.append(c) |
|
258 | newname.append(c) | |
259 | i += 1 |
|
259 | i += 1 | |
260 | return ''.join(newname) |
|
260 | return ''.join(newname) | |
261 | except KeyError, inst: |
|
261 | except KeyError, inst: | |
262 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), |
|
262 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), | |
263 | inst.args[0]) |
|
263 | inst.args[0]) | |
264 |
|
264 | |||
265 | def make_file(repo, r, pat, node=None, |
|
265 | def make_file(repo, r, pat, node=None, | |
266 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
266 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): | |
267 | if not pat or pat == '-': |
|
267 | if not pat or pat == '-': | |
268 | return 'w' in mode and sys.stdout or sys.stdin |
|
268 | return 'w' in mode and sys.stdout or sys.stdin | |
269 | if hasattr(pat, 'write') and 'w' in mode: |
|
269 | if hasattr(pat, 'write') and 'w' in mode: | |
270 | return pat |
|
270 | return pat | |
271 | if hasattr(pat, 'read') and 'r' in mode: |
|
271 | if hasattr(pat, 'read') and 'r' in mode: | |
272 | return pat |
|
272 | return pat | |
273 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, |
|
273 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, | |
274 | pathname), |
|
274 | pathname), | |
275 | mode) |
|
275 | mode) | |
276 |
|
276 | |||
277 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
277 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | |
278 | changes=None, text=False, opts={}): |
|
278 | changes=None, text=False, opts={}): | |
279 | if not node1: |
|
279 | if not node1: | |
280 | node1 = repo.dirstate.parents()[0] |
|
280 | node1 = repo.dirstate.parents()[0] | |
281 | # reading the data for node1 early allows it to play nicely |
|
281 | # reading the data for node1 early allows it to play nicely | |
282 | # with repo.changes and the revlog cache. |
|
282 | # with repo.changes and the revlog cache. | |
283 | change = repo.changelog.read(node1) |
|
283 | change = repo.changelog.read(node1) | |
284 | mmap = repo.manifest.read(change[0]) |
|
284 | mmap = repo.manifest.read(change[0]) | |
285 | date1 = util.datestr(change[2]) |
|
285 | date1 = util.datestr(change[2]) | |
286 |
|
286 | |||
287 | if not changes: |
|
287 | if not changes: | |
288 | changes = repo.changes(node1, node2, files, match=match) |
|
288 | changes = repo.changes(node1, node2, files, match=match) | |
289 | modified, added, removed, deleted, unknown = changes |
|
289 | modified, added, removed, deleted, unknown = changes | |
290 | if files: |
|
290 | if files: | |
291 | modified, added, removed = map(lambda x: filterfiles(files, x), |
|
291 | modified, added, removed = map(lambda x: filterfiles(files, x), | |
292 | (modified, added, removed)) |
|
292 | (modified, added, removed)) | |
293 |
|
293 | |||
294 | if not modified and not added and not removed: |
|
294 | if not modified and not added and not removed: | |
295 | return |
|
295 | return | |
296 |
|
296 | |||
297 | if node2: |
|
297 | if node2: | |
298 | change = repo.changelog.read(node2) |
|
298 | change = repo.changelog.read(node2) | |
299 | mmap2 = repo.manifest.read(change[0]) |
|
299 | mmap2 = repo.manifest.read(change[0]) | |
300 | date2 = util.datestr(change[2]) |
|
300 | date2 = util.datestr(change[2]) | |
301 | def read(f): |
|
301 | def read(f): | |
302 | return repo.file(f).read(mmap2[f]) |
|
302 | return repo.file(f).read(mmap2[f]) | |
303 | else: |
|
303 | else: | |
304 | date2 = util.datestr() |
|
304 | date2 = util.datestr() | |
305 | def read(f): |
|
305 | def read(f): | |
306 | return repo.wread(f) |
|
306 | return repo.wread(f) | |
307 |
|
307 | |||
308 | if ui.quiet: |
|
308 | if ui.quiet: | |
309 | r = None |
|
309 | r = None | |
310 | else: |
|
310 | else: | |
311 | hexfunc = ui.verbose and hex or short |
|
311 | hexfunc = ui.verbose and hex or short | |
312 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
312 | r = [hexfunc(node) for node in [node1, node2] if node] | |
313 |
|
313 | |||
314 | diffopts = ui.diffopts() |
|
314 | diffopts = ui.diffopts() | |
315 | showfunc = opts.get('show_function') or diffopts['showfunc'] |
|
315 | showfunc = opts.get('show_function') or diffopts['showfunc'] | |
316 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] |
|
316 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] | |
317 | for f in modified: |
|
317 | for f in modified: | |
318 | to = None |
|
318 | to = None | |
319 | if f in mmap: |
|
319 | if f in mmap: | |
320 | to = repo.file(f).read(mmap[f]) |
|
320 | to = repo.file(f).read(mmap[f]) | |
321 | tn = read(f) |
|
321 | tn = read(f) | |
322 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
322 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
323 | showfunc=showfunc, ignorews=ignorews)) |
|
323 | showfunc=showfunc, ignorews=ignorews)) | |
324 | for f in added: |
|
324 | for f in added: | |
325 | to = None |
|
325 | to = None | |
326 | tn = read(f) |
|
326 | tn = read(f) | |
327 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
327 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
328 | showfunc=showfunc, ignorews=ignorews)) |
|
328 | showfunc=showfunc, ignorews=ignorews)) | |
329 | for f in removed: |
|
329 | for f in removed: | |
330 | to = repo.file(f).read(mmap[f]) |
|
330 | to = repo.file(f).read(mmap[f]) | |
331 | tn = None |
|
331 | tn = None | |
332 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
332 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
333 | showfunc=showfunc, ignorews=ignorews)) |
|
333 | showfunc=showfunc, ignorews=ignorews)) | |
334 |
|
334 | |||
335 | def trimuser(ui, name, rev, revcache): |
|
335 | def trimuser(ui, name, rev, revcache): | |
336 | """trim the name of the user who committed a change""" |
|
336 | """trim the name of the user who committed a change""" | |
337 | user = revcache.get(rev) |
|
337 | user = revcache.get(rev) | |
338 | if user is None: |
|
338 | if user is None: | |
339 | user = revcache[rev] = ui.shortuser(name) |
|
339 | user = revcache[rev] = ui.shortuser(name) | |
340 | return user |
|
340 | return user | |
341 |
|
341 | |||
342 | def show_changeset(ui, repo, rev=0, changenode=None, brinfo=None): |
|
342 | def show_changeset(ui, repo, rev=0, changenode=None, brinfo=None): | |
343 | """show a single changeset or file revision""" |
|
343 | """show a single changeset or file revision""" | |
344 | log = repo.changelog |
|
344 | log = repo.changelog | |
345 | if changenode is None: |
|
345 | if changenode is None: | |
346 | changenode = log.node(rev) |
|
346 | changenode = log.node(rev) | |
347 | elif not rev: |
|
347 | elif not rev: | |
348 | rev = log.rev(changenode) |
|
348 | rev = log.rev(changenode) | |
349 |
|
349 | |||
350 | if ui.quiet: |
|
350 | if ui.quiet: | |
351 | ui.write("%d:%s\n" % (rev, short(changenode))) |
|
351 | ui.write("%d:%s\n" % (rev, short(changenode))) | |
352 | return |
|
352 | return | |
353 |
|
353 | |||
354 | changes = log.read(changenode) |
|
354 | changes = log.read(changenode) | |
355 | date = util.datestr(changes[2]) |
|
355 | date = util.datestr(changes[2]) | |
356 |
|
356 | |||
357 | parents = [(log.rev(p), ui.verbose and hex(p) or short(p)) |
|
357 | parents = [(log.rev(p), ui.verbose and hex(p) or short(p)) | |
358 | for p in log.parents(changenode) |
|
358 | for p in log.parents(changenode) | |
359 | if ui.debugflag or p != nullid] |
|
359 | if ui.debugflag or p != nullid] | |
360 | if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1: |
|
360 | if not ui.debugflag and len(parents) == 1 and parents[0][0] == rev-1: | |
361 | parents = [] |
|
361 | parents = [] | |
362 |
|
362 | |||
363 | if ui.verbose: |
|
363 | if ui.verbose: | |
364 | ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) |
|
364 | ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) | |
365 | else: |
|
365 | else: | |
366 | ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) |
|
366 | ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) | |
367 |
|
367 | |||
368 | for tag in repo.nodetags(changenode): |
|
368 | for tag in repo.nodetags(changenode): | |
369 | ui.status(_("tag: %s\n") % tag) |
|
369 | ui.status(_("tag: %s\n") % tag) | |
370 | for parent in parents: |
|
370 | for parent in parents: | |
371 | ui.write(_("parent: %d:%s\n") % parent) |
|
371 | ui.write(_("parent: %d:%s\n") % parent) | |
372 |
|
372 | |||
373 | if brinfo and changenode in brinfo: |
|
373 | if brinfo and changenode in brinfo: | |
374 | br = brinfo[changenode] |
|
374 | br = brinfo[changenode] | |
375 | ui.write(_("branch: %s\n") % " ".join(br)) |
|
375 | ui.write(_("branch: %s\n") % " ".join(br)) | |
376 |
|
376 | |||
377 | ui.debug(_("manifest: %d:%s\n") % (repo.manifest.rev(changes[0]), |
|
377 | ui.debug(_("manifest: %d:%s\n") % (repo.manifest.rev(changes[0]), | |
378 | hex(changes[0]))) |
|
378 | hex(changes[0]))) | |
379 | ui.status(_("user: %s\n") % changes[1]) |
|
379 | ui.status(_("user: %s\n") % changes[1]) | |
380 | ui.status(_("date: %s\n") % date) |
|
380 | ui.status(_("date: %s\n") % date) | |
381 |
|
381 | |||
382 | if ui.debugflag: |
|
382 | if ui.debugflag: | |
383 | files = repo.changes(log.parents(changenode)[0], changenode) |
|
383 | files = repo.changes(log.parents(changenode)[0], changenode) | |
384 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], files): |
|
384 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], files): | |
385 | if value: |
|
385 | if value: | |
386 | ui.note("%-12s %s\n" % (key, " ".join(value))) |
|
386 | ui.note("%-12s %s\n" % (key, " ".join(value))) | |
387 | else: |
|
387 | else: | |
388 | ui.note(_("files: %s\n") % " ".join(changes[3])) |
|
388 | ui.note(_("files: %s\n") % " ".join(changes[3])) | |
389 |
|
389 | |||
390 | description = changes[4].strip() |
|
390 | description = changes[4].strip() | |
391 | if description: |
|
391 | if description: | |
392 | if ui.verbose: |
|
392 | if ui.verbose: | |
393 | ui.status(_("description:\n")) |
|
393 | ui.status(_("description:\n")) | |
394 | ui.status(description) |
|
394 | ui.status(description) | |
395 | ui.status("\n\n") |
|
395 | ui.status("\n\n") | |
396 | else: |
|
396 | else: | |
397 | ui.status(_("summary: %s\n") % description.splitlines()[0]) |
|
397 | ui.status(_("summary: %s\n") % description.splitlines()[0]) | |
398 | ui.status("\n") |
|
398 | ui.status("\n") | |
399 |
|
399 | |||
400 | def show_version(ui): |
|
400 | def show_version(ui): | |
401 | """output version and copyright information""" |
|
401 | """output version and copyright information""" | |
402 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
402 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | |
403 | % version.get_version()) |
|
403 | % version.get_version()) | |
404 | ui.status(_( |
|
404 | ui.status(_( | |
405 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
|
405 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" | |
406 | "This is free software; see the source for copying conditions. " |
|
406 | "This is free software; see the source for copying conditions. " | |
407 | "There is NO\nwarranty; " |
|
407 | "There is NO\nwarranty; " | |
408 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
408 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
409 | )) |
|
409 | )) | |
410 |
|
410 | |||
411 | def help_(ui, cmd=None, with_version=False): |
|
411 | def help_(ui, cmd=None, with_version=False): | |
412 | """show help for a given command or all commands""" |
|
412 | """show help for a given command or all commands""" | |
413 | option_lists = [] |
|
413 | option_lists = [] | |
414 | if cmd and cmd != 'shortlist': |
|
414 | if cmd and cmd != 'shortlist': | |
415 | if with_version: |
|
415 | if with_version: | |
416 | show_version(ui) |
|
416 | show_version(ui) | |
417 | ui.write('\n') |
|
417 | ui.write('\n') | |
418 | aliases, i = find(cmd) |
|
418 | aliases, i = find(cmd) | |
419 | # synopsis |
|
419 | # synopsis | |
420 | ui.write("%s\n\n" % i[2]) |
|
420 | ui.write("%s\n\n" % i[2]) | |
421 |
|
421 | |||
422 | # description |
|
422 | # description | |
423 | doc = i[0].__doc__ |
|
423 | doc = i[0].__doc__ | |
424 | if not doc: |
|
424 | if not doc: | |
425 | doc = _("(No help text available)") |
|
425 | doc = _("(No help text available)") | |
426 | if ui.quiet: |
|
426 | if ui.quiet: | |
427 | doc = doc.splitlines(0)[0] |
|
427 | doc = doc.splitlines(0)[0] | |
428 | ui.write("%s\n" % doc.rstrip()) |
|
428 | ui.write("%s\n" % doc.rstrip()) | |
429 |
|
429 | |||
430 | if not ui.quiet: |
|
430 | if not ui.quiet: | |
431 | # aliases |
|
431 | # aliases | |
432 | if len(aliases) > 1: |
|
432 | if len(aliases) > 1: | |
433 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
433 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | |
434 |
|
434 | |||
435 | # options |
|
435 | # options | |
436 | if i[1]: |
|
436 | if i[1]: | |
437 | option_lists.append(("options", i[1])) |
|
437 | option_lists.append(("options", i[1])) | |
438 |
|
438 | |||
439 | else: |
|
439 | else: | |
440 | # program name |
|
440 | # program name | |
441 | if ui.verbose or with_version: |
|
441 | if ui.verbose or with_version: | |
442 | show_version(ui) |
|
442 | show_version(ui) | |
443 | else: |
|
443 | else: | |
444 | ui.status(_("Mercurial Distributed SCM\n")) |
|
444 | ui.status(_("Mercurial Distributed SCM\n")) | |
445 | ui.status('\n') |
|
445 | ui.status('\n') | |
446 |
|
446 | |||
447 | # list of commands |
|
447 | # list of commands | |
448 | if cmd == "shortlist": |
|
448 | if cmd == "shortlist": | |
449 | ui.status(_('basic commands (use "hg help" ' |
|
449 | ui.status(_('basic commands (use "hg help" ' | |
450 | 'for the full list or option "-v" for details):\n\n')) |
|
450 | 'for the full list or option "-v" for details):\n\n')) | |
451 | elif ui.verbose: |
|
451 | elif ui.verbose: | |
452 | ui.status(_('list of commands:\n\n')) |
|
452 | ui.status(_('list of commands:\n\n')) | |
453 | else: |
|
453 | else: | |
454 | ui.status(_('list of commands (use "hg help -v" ' |
|
454 | ui.status(_('list of commands (use "hg help -v" ' | |
455 | 'to show aliases and global options):\n\n')) |
|
455 | 'to show aliases and global options):\n\n')) | |
456 |
|
456 | |||
457 | h = {} |
|
457 | h = {} | |
458 | cmds = {} |
|
458 | cmds = {} | |
459 | for c, e in table.items(): |
|
459 | for c, e in table.items(): | |
460 | f = c.split("|")[0] |
|
460 | f = c.split("|")[0] | |
461 | if cmd == "shortlist" and not f.startswith("^"): |
|
461 | if cmd == "shortlist" and not f.startswith("^"): | |
462 | continue |
|
462 | continue | |
463 | f = f.lstrip("^") |
|
463 | f = f.lstrip("^") | |
464 | if not ui.debugflag and f.startswith("debug"): |
|
464 | if not ui.debugflag and f.startswith("debug"): | |
465 | continue |
|
465 | continue | |
466 | doc = e[0].__doc__ |
|
466 | doc = e[0].__doc__ | |
467 | if not doc: |
|
467 | if not doc: | |
468 | doc = _("(No help text available)") |
|
468 | doc = _("(No help text available)") | |
469 | h[f] = doc.splitlines(0)[0].rstrip() |
|
469 | h[f] = doc.splitlines(0)[0].rstrip() | |
470 | cmds[f] = c.lstrip("^") |
|
470 | cmds[f] = c.lstrip("^") | |
471 |
|
471 | |||
472 | fns = h.keys() |
|
472 | fns = h.keys() | |
473 | fns.sort() |
|
473 | fns.sort() | |
474 | m = max(map(len, fns)) |
|
474 | m = max(map(len, fns)) | |
475 | for f in fns: |
|
475 | for f in fns: | |
476 | if ui.verbose: |
|
476 | if ui.verbose: | |
477 | commands = cmds[f].replace("|",", ") |
|
477 | commands = cmds[f].replace("|",", ") | |
478 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
478 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
479 | else: |
|
479 | else: | |
480 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
480 | ui.write(' %-*s %s\n' % (m, f, h[f])) | |
481 |
|
481 | |||
482 | # global options |
|
482 | # global options | |
483 | if ui.verbose: |
|
483 | if ui.verbose: | |
484 | option_lists.append(("global options", globalopts)) |
|
484 | option_lists.append(("global options", globalopts)) | |
485 |
|
485 | |||
486 | # list all option lists |
|
486 | # list all option lists | |
487 | opt_output = [] |
|
487 | opt_output = [] | |
488 | for title, options in option_lists: |
|
488 | for title, options in option_lists: | |
489 | opt_output.append(("\n%s:\n" % title, None)) |
|
489 | opt_output.append(("\n%s:\n" % title, None)) | |
490 | for shortopt, longopt, default, desc in options: |
|
490 | for shortopt, longopt, default, desc in options: | |
491 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
491 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | |
492 | longopt and " --%s" % longopt), |
|
492 | longopt and " --%s" % longopt), | |
493 | "%s%s" % (desc, |
|
493 | "%s%s" % (desc, | |
494 | default |
|
494 | default | |
495 | and _(" (default: %s)") % default |
|
495 | and _(" (default: %s)") % default | |
496 | or ""))) |
|
496 | or ""))) | |
497 |
|
497 | |||
498 | if opt_output: |
|
498 | if opt_output: | |
499 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
499 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) | |
500 | for first, second in opt_output: |
|
500 | for first, second in opt_output: | |
501 | if second: |
|
501 | if second: | |
502 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
502 | ui.write(" %-*s %s\n" % (opts_len, first, second)) | |
503 | else: |
|
503 | else: | |
504 | ui.write("%s\n" % first) |
|
504 | ui.write("%s\n" % first) | |
505 |
|
505 | |||
506 | # Commands start here, listed alphabetically |
|
506 | # Commands start here, listed alphabetically | |
507 |
|
507 | |||
508 | def add(ui, repo, *pats, **opts): |
|
508 | def add(ui, repo, *pats, **opts): | |
509 | """add the specified files on the next commit |
|
509 | """add the specified files on the next commit | |
510 |
|
510 | |||
511 | Schedule files to be version controlled and added to the repository. |
|
511 | Schedule files to be version controlled and added to the repository. | |
512 |
|
512 | |||
513 | The files will be added to the repository at the next commit. |
|
513 | The files will be added to the repository at the next commit. | |
514 |
|
514 | |||
515 | If no names are given, add all files in the repository. |
|
515 | If no names are given, add all files in the repository. | |
516 | """ |
|
516 | """ | |
517 |
|
517 | |||
518 | names = [] |
|
518 | names = [] | |
519 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
519 | for src, abs, rel, exact in walk(repo, pats, opts): | |
520 | if exact: |
|
520 | if exact: | |
521 | if ui.verbose: |
|
521 | if ui.verbose: | |
522 | ui.status(_('adding %s\n') % rel) |
|
522 | ui.status(_('adding %s\n') % rel) | |
523 | names.append(abs) |
|
523 | names.append(abs) | |
524 | elif repo.dirstate.state(abs) == '?': |
|
524 | elif repo.dirstate.state(abs) == '?': | |
525 | ui.status(_('adding %s\n') % rel) |
|
525 | ui.status(_('adding %s\n') % rel) | |
526 | names.append(abs) |
|
526 | names.append(abs) | |
527 | repo.add(names) |
|
527 | repo.add(names) | |
528 |
|
528 | |||
529 | def addremove(ui, repo, *pats, **opts): |
|
529 | def addremove(ui, repo, *pats, **opts): | |
530 | """add all new files, delete all missing files |
|
530 | """add all new files, delete all missing files | |
531 |
|
531 | |||
532 | Add all new files and remove all missing files from the repository. |
|
532 | Add all new files and remove all missing files from the repository. | |
533 |
|
533 | |||
534 | New files are ignored if they match any of the patterns in .hgignore. As |
|
534 | New files are ignored if they match any of the patterns in .hgignore. As | |
535 | with add, these changes take effect at the next commit. |
|
535 | with add, these changes take effect at the next commit. | |
536 | """ |
|
536 | """ | |
537 | return addremove_lock(ui, repo, pats, opts) |
|
537 | return addremove_lock(ui, repo, pats, opts) | |
538 |
|
538 | |||
539 | def addremove_lock(ui, repo, pats, opts, wlock=None): |
|
539 | def addremove_lock(ui, repo, pats, opts, wlock=None): | |
540 | add, remove = [], [] |
|
540 | add, remove = [], [] | |
541 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
541 | for src, abs, rel, exact in walk(repo, pats, opts): | |
542 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
542 | if src == 'f' and repo.dirstate.state(abs) == '?': | |
543 | add.append(abs) |
|
543 | add.append(abs) | |
544 | if ui.verbose or not exact: |
|
544 | if ui.verbose or not exact: | |
545 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
545 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) | |
546 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
|
546 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | |
547 | remove.append(abs) |
|
547 | remove.append(abs) | |
548 | if ui.verbose or not exact: |
|
548 | if ui.verbose or not exact: | |
549 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
549 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) | |
550 | repo.add(add, wlock=wlock) |
|
550 | repo.add(add, wlock=wlock) | |
551 | repo.remove(remove, wlock=wlock) |
|
551 | repo.remove(remove, wlock=wlock) | |
552 |
|
552 | |||
553 | def annotate(ui, repo, *pats, **opts): |
|
553 | def annotate(ui, repo, *pats, **opts): | |
554 | """show changeset information per file line |
|
554 | """show changeset information per file line | |
555 |
|
555 | |||
556 | List changes in files, showing the revision id responsible for each line |
|
556 | List changes in files, showing the revision id responsible for each line | |
557 |
|
557 | |||
558 | This command is useful to discover who did a change or when a change took |
|
558 | This command is useful to discover who did a change or when a change took | |
559 | place. |
|
559 | place. | |
560 |
|
560 | |||
561 | Without the -a option, annotate will avoid processing files it |
|
561 | Without the -a option, annotate will avoid processing files it | |
562 | detects as binary. With -a, annotate will generate an annotation |
|
562 | detects as binary. With -a, annotate will generate an annotation | |
563 | anyway, probably with undesirable results. |
|
563 | anyway, probably with undesirable results. | |
564 | """ |
|
564 | """ | |
565 | def getnode(rev): |
|
565 | def getnode(rev): | |
566 | return short(repo.changelog.node(rev)) |
|
566 | return short(repo.changelog.node(rev)) | |
567 |
|
567 | |||
568 | ucache = {} |
|
568 | ucache = {} | |
569 | def getname(rev): |
|
569 | def getname(rev): | |
570 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
570 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
571 | return trimuser(ui, cl[1], rev, ucache) |
|
571 | return trimuser(ui, cl[1], rev, ucache) | |
572 |
|
572 | |||
573 | dcache = {} |
|
573 | dcache = {} | |
574 | def getdate(rev): |
|
574 | def getdate(rev): | |
575 | datestr = dcache.get(rev) |
|
575 | datestr = dcache.get(rev) | |
576 | if datestr is None: |
|
576 | if datestr is None: | |
577 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
577 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
578 | datestr = dcache[rev] = util.datestr(cl[2]) |
|
578 | datestr = dcache[rev] = util.datestr(cl[2]) | |
579 | return datestr |
|
579 | return datestr | |
580 |
|
580 | |||
581 | if not pats: |
|
581 | if not pats: | |
582 | raise util.Abort(_('at least one file name or pattern required')) |
|
582 | raise util.Abort(_('at least one file name or pattern required')) | |
583 |
|
583 | |||
584 | opmap = [['user', getname], ['number', str], ['changeset', getnode], |
|
584 | opmap = [['user', getname], ['number', str], ['changeset', getnode], | |
585 | ['date', getdate]] |
|
585 | ['date', getdate]] | |
586 | if not opts['user'] and not opts['changeset'] and not opts['date']: |
|
586 | if not opts['user'] and not opts['changeset'] and not opts['date']: | |
587 | opts['number'] = 1 |
|
587 | opts['number'] = 1 | |
588 |
|
588 | |||
589 | if opts['rev']: |
|
589 | if opts['rev']: | |
590 | node = repo.changelog.lookup(opts['rev']) |
|
590 | node = repo.changelog.lookup(opts['rev']) | |
591 | else: |
|
591 | else: | |
592 | node = repo.dirstate.parents()[0] |
|
592 | node = repo.dirstate.parents()[0] | |
593 | change = repo.changelog.read(node) |
|
593 | change = repo.changelog.read(node) | |
594 | mmap = repo.manifest.read(change[0]) |
|
594 | mmap = repo.manifest.read(change[0]) | |
595 |
|
595 | |||
596 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): |
|
596 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): | |
597 | f = repo.file(abs) |
|
597 | f = repo.file(abs) | |
598 | if not opts['text'] and util.binary(f.read(mmap[abs])): |
|
598 | if not opts['text'] and util.binary(f.read(mmap[abs])): | |
599 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
599 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | |
600 | continue |
|
600 | continue | |
601 |
|
601 | |||
602 | lines = f.annotate(mmap[abs]) |
|
602 | lines = f.annotate(mmap[abs]) | |
603 | pieces = [] |
|
603 | pieces = [] | |
604 |
|
604 | |||
605 | for o, f in opmap: |
|
605 | for o, f in opmap: | |
606 | if opts[o]: |
|
606 | if opts[o]: | |
607 | l = [f(n) for n, dummy in lines] |
|
607 | l = [f(n) for n, dummy in lines] | |
608 | if l: |
|
608 | if l: | |
609 | m = max(map(len, l)) |
|
609 | m = max(map(len, l)) | |
610 | pieces.append(["%*s" % (m, x) for x in l]) |
|
610 | pieces.append(["%*s" % (m, x) for x in l]) | |
611 |
|
611 | |||
612 | if pieces: |
|
612 | if pieces: | |
613 | for p, l in zip(zip(*pieces), lines): |
|
613 | for p, l in zip(zip(*pieces), lines): | |
614 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
614 | ui.write("%s: %s" % (" ".join(p), l[1])) | |
615 |
|
615 | |||
616 | def bundle(ui, repo, fname, dest="default-push", **opts): |
|
616 | def bundle(ui, repo, fname, dest="default-push", **opts): | |
617 | """create a changegroup file |
|
617 | """create a changegroup file | |
618 |
|
618 | |||
619 | Generate a compressed changegroup file collecting all changesets |
|
619 | Generate a compressed changegroup file collecting all changesets | |
620 | not found in the other repository. |
|
620 | not found in the other repository. | |
621 |
|
621 | |||
622 | This file can then be transferred using conventional means and |
|
622 | This file can then be transferred using conventional means and | |
623 | applied to another repository with the unbundle command. This is |
|
623 | applied to another repository with the unbundle command. This is | |
624 | useful when native push and pull are not available or when |
|
624 | useful when native push and pull are not available or when | |
625 | exporting an entire repository is undesirable. The standard file |
|
625 | exporting an entire repository is undesirable. The standard file | |
626 | extension is ".hg". |
|
626 | extension is ".hg". | |
627 |
|
627 | |||
628 | Unlike import/export, this exactly preserves all changeset |
|
628 | Unlike import/export, this exactly preserves all changeset | |
629 | contents including permissions, rename data, and revision history. |
|
629 | contents including permissions, rename data, and revision history. | |
630 | """ |
|
630 | """ | |
631 | f = open(fname, "wb") |
|
631 | f = open(fname, "wb") | |
632 | dest = ui.expandpath(dest, repo.root) |
|
632 | dest = ui.expandpath(dest, repo.root) | |
633 | other = hg.repository(ui, dest) |
|
633 | other = hg.repository(ui, dest) | |
634 | o = repo.findoutgoing(other) |
|
634 | o = repo.findoutgoing(other) | |
635 | cg = repo.changegroup(o, 'bundle') |
|
635 | cg = repo.changegroup(o, 'bundle') | |
636 |
|
636 | |||
637 | try: |
|
637 | try: | |
638 | f.write("HG10") |
|
638 | f.write("HG10") | |
639 | z = bz2.BZ2Compressor(9) |
|
639 | z = bz2.BZ2Compressor(9) | |
640 | while 1: |
|
640 | while 1: | |
641 | chunk = cg.read(4096) |
|
641 | chunk = cg.read(4096) | |
642 | if not chunk: |
|
642 | if not chunk: | |
643 | break |
|
643 | break | |
644 | f.write(z.compress(chunk)) |
|
644 | f.write(z.compress(chunk)) | |
645 | f.write(z.flush()) |
|
645 | f.write(z.flush()) | |
646 | except: |
|
646 | except: | |
647 | os.unlink(fname) |
|
647 | os.unlink(fname) | |
648 | raise |
|
648 | raise | |
649 |
|
649 | |||
650 | def cat(ui, repo, file1, *pats, **opts): |
|
650 | def cat(ui, repo, file1, *pats, **opts): | |
651 | """output the latest or given revisions of files |
|
651 | """output the latest or given revisions of files | |
652 |
|
652 | |||
653 | Print the specified files as they were at the given revision. |
|
653 | Print the specified files as they were at the given revision. | |
654 | If no revision is given then the tip is used. |
|
654 | If no revision is given then the tip is used. | |
655 |
|
655 | |||
656 | Output may be to a file, in which case the name of the file is |
|
656 | Output may be to a file, in which case the name of the file is | |
657 | given using a format string. The formatting rules are the same as |
|
657 | given using a format string. The formatting rules are the same as | |
658 | for the export command, with the following additions: |
|
658 | for the export command, with the following additions: | |
659 |
|
659 | |||
660 | %s basename of file being printed |
|
660 | %s basename of file being printed | |
661 | %d dirname of file being printed, or '.' if in repo root |
|
661 | %d dirname of file being printed, or '.' if in repo root | |
662 | %p root-relative path name of file being printed |
|
662 | %p root-relative path name of file being printed | |
663 | """ |
|
663 | """ | |
664 | mf = {} |
|
664 | mf = {} | |
665 | rev = opts['rev'] |
|
665 | rev = opts['rev'] | |
666 | if rev: |
|
666 | if rev: | |
667 | node = repo.lookup(rev) |
|
667 | node = repo.lookup(rev) | |
668 | else: |
|
668 | else: | |
669 | node = repo.changelog.tip() |
|
669 | node = repo.changelog.tip() | |
670 | change = repo.changelog.read(node) |
|
670 | change = repo.changelog.read(node) | |
671 | mf = repo.manifest.read(change[0]) |
|
671 | mf = repo.manifest.read(change[0]) | |
672 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): |
|
672 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): | |
673 | r = repo.file(abs) |
|
673 | r = repo.file(abs) | |
674 | n = mf[abs] |
|
674 | n = mf[abs] | |
675 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) |
|
675 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) | |
676 | fp.write(r.read(n)) |
|
676 | fp.write(r.read(n)) | |
677 |
|
677 | |||
678 | def clone(ui, source, dest=None, **opts): |
|
678 | def clone(ui, source, dest=None, **opts): | |
679 | """make a copy of an existing repository |
|
679 | """make a copy of an existing repository | |
680 |
|
680 | |||
681 | Create a copy of an existing repository in a new directory. |
|
681 | Create a copy of an existing repository in a new directory. | |
682 |
|
682 | |||
683 | If no destination directory name is specified, it defaults to the |
|
683 | If no destination directory name is specified, it defaults to the | |
684 | basename of the source. |
|
684 | basename of the source. | |
685 |
|
685 | |||
686 | The location of the source is added to the new repository's |
|
686 | The location of the source is added to the new repository's | |
687 | .hg/hgrc file, as the default to be used for future pulls. |
|
687 | .hg/hgrc file, as the default to be used for future pulls. | |
688 |
|
688 | |||
689 | For efficiency, hardlinks are used for cloning whenever the source |
|
689 | For efficiency, hardlinks are used for cloning whenever the source | |
690 | and destination are on the same filesystem. Some filesystems, |
|
690 | and destination are on the same filesystem. Some filesystems, | |
691 | such as AFS, implement hardlinking incorrectly, but do not report |
|
691 | such as AFS, implement hardlinking incorrectly, but do not report | |
692 | errors. In these cases, use the --pull option to avoid |
|
692 | errors. In these cases, use the --pull option to avoid | |
693 | hardlinking. |
|
693 | hardlinking. | |
694 |
|
694 | |||
695 | See pull for valid source format details. |
|
695 | See pull for valid source format details. | |
696 | """ |
|
696 | """ | |
697 | if dest is None: |
|
697 | if dest is None: | |
698 | dest = os.path.basename(os.path.normpath(source)) |
|
698 | dest = os.path.basename(os.path.normpath(source)) | |
699 |
|
699 | |||
700 | if os.path.exists(dest): |
|
700 | if os.path.exists(dest): | |
701 | raise util.Abort(_("destination '%s' already exists"), dest) |
|
701 | raise util.Abort(_("destination '%s' already exists"), dest) | |
702 |
|
702 | |||
703 | dest = os.path.realpath(dest) |
|
703 | dest = os.path.realpath(dest) | |
704 |
|
704 | |||
705 | class Dircleanup(object): |
|
705 | class Dircleanup(object): | |
706 | def __init__(self, dir_): |
|
706 | def __init__(self, dir_): | |
707 | self.rmtree = shutil.rmtree |
|
707 | self.rmtree = shutil.rmtree | |
708 | self.dir_ = dir_ |
|
708 | self.dir_ = dir_ | |
709 | os.mkdir(dir_) |
|
709 | os.mkdir(dir_) | |
710 | def close(self): |
|
710 | def close(self): | |
711 | self.dir_ = None |
|
711 | self.dir_ = None | |
712 | def __del__(self): |
|
712 | def __del__(self): | |
713 | if self.dir_: |
|
713 | if self.dir_: | |
714 | self.rmtree(self.dir_, True) |
|
714 | self.rmtree(self.dir_, True) | |
715 |
|
715 | |||
716 | if opts['ssh']: |
|
716 | if opts['ssh']: | |
717 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
717 | ui.setconfig("ui", "ssh", opts['ssh']) | |
718 | if opts['remotecmd']: |
|
718 | if opts['remotecmd']: | |
719 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
719 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
720 |
|
720 | |||
721 | if not os.path.exists(source): |
|
721 | if not os.path.exists(source): | |
722 | source = ui.expandpath(source) |
|
722 | source = ui.expandpath(source) | |
723 |
|
723 | |||
724 | d = Dircleanup(dest) |
|
724 | d = Dircleanup(dest) | |
725 | abspath = source |
|
725 | abspath = source | |
726 | other = hg.repository(ui, source) |
|
726 | other = hg.repository(ui, source) | |
727 |
|
727 | |||
728 | copy = False |
|
728 | copy = False | |
729 | if other.dev() != -1: |
|
729 | if other.dev() != -1: | |
730 | abspath = os.path.abspath(source) |
|
730 | abspath = os.path.abspath(source) | |
731 | if not opts['pull'] and not opts['rev']: |
|
731 | if not opts['pull'] and not opts['rev']: | |
732 | copy = True |
|
732 | copy = True | |
733 |
|
733 | |||
734 | if copy: |
|
734 | if copy: | |
735 | try: |
|
735 | try: | |
736 | # we use a lock here because if we race with commit, we |
|
736 | # we use a lock here because if we race with commit, we | |
737 | # can end up with extra data in the cloned revlogs that's |
|
737 | # can end up with extra data in the cloned revlogs that's | |
738 | # not pointed to by changesets, thus causing verify to |
|
738 | # not pointed to by changesets, thus causing verify to | |
739 | # fail |
|
739 | # fail | |
740 | l1 = other.lock() |
|
740 | l1 = other.lock() | |
741 | except lock.LockException: |
|
741 | except lock.LockException: | |
742 | copy = False |
|
742 | copy = False | |
743 |
|
743 | |||
744 | if copy: |
|
744 | if copy: | |
745 | # we lock here to avoid premature writing to the target |
|
745 | # we lock here to avoid premature writing to the target | |
746 | os.mkdir(os.path.join(dest, ".hg")) |
|
746 | os.mkdir(os.path.join(dest, ".hg")) | |
747 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) |
|
747 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) | |
748 |
|
748 | |||
749 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" |
|
749 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" | |
750 | for f in files.split(): |
|
750 | for f in files.split(): | |
751 | src = os.path.join(source, ".hg", f) |
|
751 | src = os.path.join(source, ".hg", f) | |
752 | dst = os.path.join(dest, ".hg", f) |
|
752 | dst = os.path.join(dest, ".hg", f) | |
753 | try: |
|
753 | try: | |
754 | util.copyfiles(src, dst) |
|
754 | util.copyfiles(src, dst) | |
755 | except OSError, inst: |
|
755 | except OSError, inst: | |
756 | if inst.errno != errno.ENOENT: |
|
756 | if inst.errno != errno.ENOENT: | |
757 | raise |
|
757 | raise | |
758 |
|
758 | |||
759 | repo = hg.repository(ui, dest) |
|
759 | repo = hg.repository(ui, dest) | |
760 |
|
760 | |||
761 | else: |
|
761 | else: | |
762 | revs = None |
|
762 | revs = None | |
763 | if opts['rev']: |
|
763 | if opts['rev']: | |
764 | if not other.local(): |
|
764 | if not other.local(): | |
765 | error = _("clone -r not supported yet for remote repositories.") |
|
765 | error = _("clone -r not supported yet for remote repositories.") | |
766 | raise util.Abort(error) |
|
766 | raise util.Abort(error) | |
767 | else: |
|
767 | else: | |
768 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
768 | revs = [other.lookup(rev) for rev in opts['rev']] | |
769 | repo = hg.repository(ui, dest, create=1) |
|
769 | repo = hg.repository(ui, dest, create=1) | |
770 | repo.pull(other, heads = revs) |
|
770 | repo.pull(other, heads = revs) | |
771 |
|
771 | |||
772 | f = repo.opener("hgrc", "w", text=True) |
|
772 | f = repo.opener("hgrc", "w", text=True) | |
773 | f.write("[paths]\n") |
|
773 | f.write("[paths]\n") | |
774 | f.write("default = %s\n" % abspath) |
|
774 | f.write("default = %s\n" % abspath) | |
775 | f.close() |
|
775 | f.close() | |
776 |
|
776 | |||
777 | if not opts['noupdate']: |
|
777 | if not opts['noupdate']: | |
778 | update(repo.ui, repo) |
|
778 | update(repo.ui, repo) | |
779 |
|
779 | |||
780 | d.close() |
|
780 | d.close() | |
781 |
|
781 | |||
782 | def commit(ui, repo, *pats, **opts): |
|
782 | def commit(ui, repo, *pats, **opts): | |
783 | """commit the specified files or all outstanding changes |
|
783 | """commit the specified files or all outstanding changes | |
784 |
|
784 | |||
785 | Commit changes to the given files into the repository. |
|
785 | Commit changes to the given files into the repository. | |
786 |
|
786 | |||
787 | If a list of files is omitted, all changes reported by "hg status" |
|
787 | If a list of files is omitted, all changes reported by "hg status" | |
788 | will be commited. |
|
788 | will be commited. | |
789 |
|
789 | |||
790 | The HGEDITOR or EDITOR environment variables are used to start an |
|
790 | The HGEDITOR or EDITOR environment variables are used to start an | |
791 | editor to add a commit comment. |
|
791 | editor to add a commit comment. | |
792 | """ |
|
792 | """ | |
793 | message = opts['message'] |
|
793 | message = opts['message'] | |
794 | logfile = opts['logfile'] |
|
794 | logfile = opts['logfile'] | |
795 |
|
795 | |||
796 | if message and logfile: |
|
796 | if message and logfile: | |
797 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
797 | raise util.Abort(_('options --message and --logfile are mutually ' | |
798 | 'exclusive')) |
|
798 | 'exclusive')) | |
799 | if not message and logfile: |
|
799 | if not message and logfile: | |
800 | try: |
|
800 | try: | |
801 | if logfile == '-': |
|
801 | if logfile == '-': | |
802 | message = sys.stdin.read() |
|
802 | message = sys.stdin.read() | |
803 | else: |
|
803 | else: | |
804 | message = open(logfile).read() |
|
804 | message = open(logfile).read() | |
805 | except IOError, inst: |
|
805 | except IOError, inst: | |
806 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
806 | raise util.Abort(_("can't read commit message '%s': %s") % | |
807 | (logfile, inst.strerror)) |
|
807 | (logfile, inst.strerror)) | |
808 |
|
808 | |||
809 | if opts['addremove']: |
|
809 | if opts['addremove']: | |
810 | addremove(ui, repo, *pats, **opts) |
|
810 | addremove(ui, repo, *pats, **opts) | |
811 | fns, match, anypats = matchpats(repo, pats, opts) |
|
811 | fns, match, anypats = matchpats(repo, pats, opts) | |
812 | if pats: |
|
812 | if pats: | |
813 | modified, added, removed, deleted, unknown = ( |
|
813 | modified, added, removed, deleted, unknown = ( | |
814 | repo.changes(files=fns, match=match)) |
|
814 | repo.changes(files=fns, match=match)) | |
815 | files = modified + added + removed |
|
815 | files = modified + added + removed | |
816 | else: |
|
816 | else: | |
817 | files = [] |
|
817 | files = [] | |
818 | try: |
|
818 | try: | |
819 | repo.commit(files, message, opts['user'], opts['date'], match) |
|
819 | repo.commit(files, message, opts['user'], opts['date'], match) | |
820 | except ValueError, inst: |
|
820 | except ValueError, inst: | |
821 | raise util.Abort(str(inst)) |
|
821 | raise util.Abort(str(inst)) | |
822 |
|
822 | |||
823 | def docopy(ui, repo, pats, opts, wlock): |
|
823 | def docopy(ui, repo, pats, opts, wlock): | |
824 | # called with the repo lock held |
|
824 | # called with the repo lock held | |
825 | cwd = repo.getcwd() |
|
825 | cwd = repo.getcwd() | |
826 | errors = 0 |
|
826 | errors = 0 | |
827 | copied = [] |
|
827 | copied = [] | |
828 | targets = {} |
|
828 | targets = {} | |
829 |
|
829 | |||
830 | def okaytocopy(abs, rel, exact): |
|
830 | def okaytocopy(abs, rel, exact): | |
831 | reasons = {'?': _('is not managed'), |
|
831 | reasons = {'?': _('is not managed'), | |
832 | 'a': _('has been marked for add'), |
|
832 | 'a': _('has been marked for add'), | |
833 | 'r': _('has been marked for remove')} |
|
833 | 'r': _('has been marked for remove')} | |
834 | state = repo.dirstate.state(abs) |
|
834 | state = repo.dirstate.state(abs) | |
835 | reason = reasons.get(state) |
|
835 | reason = reasons.get(state) | |
836 | if reason: |
|
836 | if reason: | |
837 | if state == 'a': |
|
837 | if state == 'a': | |
838 | origsrc = repo.dirstate.copied(abs) |
|
838 | origsrc = repo.dirstate.copied(abs) | |
839 | if origsrc is not None: |
|
839 | if origsrc is not None: | |
840 | return origsrc |
|
840 | return origsrc | |
841 | if exact: |
|
841 | if exact: | |
842 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
842 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | |
843 | else: |
|
843 | else: | |
844 | return abs |
|
844 | return abs | |
845 |
|
845 | |||
846 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
846 | def copy(origsrc, abssrc, relsrc, target, exact): | |
847 | abstarget = util.canonpath(repo.root, cwd, target) |
|
847 | abstarget = util.canonpath(repo.root, cwd, target) | |
848 | reltarget = util.pathto(cwd, abstarget) |
|
848 | reltarget = util.pathto(cwd, abstarget) | |
849 | prevsrc = targets.get(abstarget) |
|
849 | prevsrc = targets.get(abstarget) | |
850 | if prevsrc is not None: |
|
850 | if prevsrc is not None: | |
851 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
851 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
852 | (reltarget, abssrc, prevsrc)) |
|
852 | (reltarget, abssrc, prevsrc)) | |
853 | return |
|
853 | return | |
854 | if (not opts['after'] and os.path.exists(reltarget) or |
|
854 | if (not opts['after'] and os.path.exists(reltarget) or | |
855 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
855 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | |
856 | if not opts['force']: |
|
856 | if not opts['force']: | |
857 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
857 | ui.warn(_('%s: not overwriting - file exists\n') % | |
858 | reltarget) |
|
858 | reltarget) | |
859 | return |
|
859 | return | |
860 | if not opts['after']: |
|
860 | if not opts['after']: | |
861 | os.unlink(reltarget) |
|
861 | os.unlink(reltarget) | |
862 | if opts['after']: |
|
862 | if opts['after']: | |
863 | if not os.path.exists(reltarget): |
|
863 | if not os.path.exists(reltarget): | |
864 | return |
|
864 | return | |
865 | else: |
|
865 | else: | |
866 | targetdir = os.path.dirname(reltarget) or '.' |
|
866 | targetdir = os.path.dirname(reltarget) or '.' | |
867 | if not os.path.isdir(targetdir): |
|
867 | if not os.path.isdir(targetdir): | |
868 | os.makedirs(targetdir) |
|
868 | os.makedirs(targetdir) | |
869 | try: |
|
869 | try: | |
870 | restore = repo.dirstate.state(abstarget) == 'r' |
|
870 | restore = repo.dirstate.state(abstarget) == 'r' | |
871 | if restore: |
|
871 | if restore: | |
872 | repo.undelete([abstarget], wlock) |
|
872 | repo.undelete([abstarget], wlock) | |
873 | try: |
|
873 | try: | |
874 | shutil.copyfile(relsrc, reltarget) |
|
874 | shutil.copyfile(relsrc, reltarget) | |
875 | shutil.copymode(relsrc, reltarget) |
|
875 | shutil.copymode(relsrc, reltarget) | |
876 | restore = False |
|
876 | restore = False | |
877 | finally: |
|
877 | finally: | |
878 | if restore: |
|
878 | if restore: | |
879 | repo.remove([abstarget], wlock) |
|
879 | repo.remove([abstarget], wlock) | |
880 | except shutil.Error, inst: |
|
880 | except shutil.Error, inst: | |
881 | raise util.Abort(str(inst)) |
|
881 | raise util.Abort(str(inst)) | |
882 | except IOError, inst: |
|
882 | except IOError, inst: | |
883 | if inst.errno == errno.ENOENT: |
|
883 | if inst.errno == errno.ENOENT: | |
884 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
884 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
885 | else: |
|
885 | else: | |
886 | ui.warn(_('%s: cannot copy - %s\n') % |
|
886 | ui.warn(_('%s: cannot copy - %s\n') % | |
887 | (relsrc, inst.strerror)) |
|
887 | (relsrc, inst.strerror)) | |
888 | errors += 1 |
|
888 | errors += 1 | |
889 | return |
|
889 | return | |
890 | if ui.verbose or not exact: |
|
890 | if ui.verbose or not exact: | |
891 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
891 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
892 | targets[abstarget] = abssrc |
|
892 | targets[abstarget] = abssrc | |
893 | if abstarget != origsrc: |
|
893 | if abstarget != origsrc: | |
894 | repo.copy(origsrc, abstarget, wlock) |
|
894 | repo.copy(origsrc, abstarget, wlock) | |
895 | copied.append((abssrc, relsrc, exact)) |
|
895 | copied.append((abssrc, relsrc, exact)) | |
896 |
|
896 | |||
897 | def targetpathfn(pat, dest, srcs): |
|
897 | def targetpathfn(pat, dest, srcs): | |
898 | if os.path.isdir(pat): |
|
898 | if os.path.isdir(pat): | |
899 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
899 | abspfx = util.canonpath(repo.root, cwd, pat) | |
900 | if destdirexists: |
|
900 | if destdirexists: | |
901 | striplen = len(os.path.split(abspfx)[0]) |
|
901 | striplen = len(os.path.split(abspfx)[0]) | |
902 | else: |
|
902 | else: | |
903 | striplen = len(abspfx) |
|
903 | striplen = len(abspfx) | |
904 | if striplen: |
|
904 | if striplen: | |
905 | striplen += len(os.sep) |
|
905 | striplen += len(os.sep) | |
906 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
906 | res = lambda p: os.path.join(dest, p[striplen:]) | |
907 | elif destdirexists: |
|
907 | elif destdirexists: | |
908 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
908 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
909 | else: |
|
909 | else: | |
910 | res = lambda p: dest |
|
910 | res = lambda p: dest | |
911 | return res |
|
911 | return res | |
912 |
|
912 | |||
913 | def targetpathafterfn(pat, dest, srcs): |
|
913 | def targetpathafterfn(pat, dest, srcs): | |
914 | if util.patkind(pat, None)[0]: |
|
914 | if util.patkind(pat, None)[0]: | |
915 | # a mercurial pattern |
|
915 | # a mercurial pattern | |
916 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
916 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
917 | else: |
|
917 | else: | |
918 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
918 | abspfx = util.canonpath(repo.root, cwd, pat) | |
919 | if len(abspfx) < len(srcs[0][0]): |
|
919 | if len(abspfx) < len(srcs[0][0]): | |
920 | # A directory. Either the target path contains the last |
|
920 | # A directory. Either the target path contains the last | |
921 | # component of the source path or it does not. |
|
921 | # component of the source path or it does not. | |
922 | def evalpath(striplen): |
|
922 | def evalpath(striplen): | |
923 | score = 0 |
|
923 | score = 0 | |
924 | for s in srcs: |
|
924 | for s in srcs: | |
925 | t = os.path.join(dest, s[0][striplen:]) |
|
925 | t = os.path.join(dest, s[0][striplen:]) | |
926 | if os.path.exists(t): |
|
926 | if os.path.exists(t): | |
927 | score += 1 |
|
927 | score += 1 | |
928 | return score |
|
928 | return score | |
929 |
|
929 | |||
930 | striplen = len(abspfx) |
|
930 | striplen = len(abspfx) | |
931 | if striplen: |
|
931 | if striplen: | |
932 | striplen += len(os.sep) |
|
932 | striplen += len(os.sep) | |
933 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
933 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
934 | score = evalpath(striplen) |
|
934 | score = evalpath(striplen) | |
935 | striplen1 = len(os.path.split(abspfx)[0]) |
|
935 | striplen1 = len(os.path.split(abspfx)[0]) | |
936 | if striplen1: |
|
936 | if striplen1: | |
937 | striplen1 += len(os.sep) |
|
937 | striplen1 += len(os.sep) | |
938 | if evalpath(striplen1) > score: |
|
938 | if evalpath(striplen1) > score: | |
939 | striplen = striplen1 |
|
939 | striplen = striplen1 | |
940 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
940 | res = lambda p: os.path.join(dest, p[striplen:]) | |
941 | else: |
|
941 | else: | |
942 | # a file |
|
942 | # a file | |
943 | if destdirexists: |
|
943 | if destdirexists: | |
944 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
944 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
945 | else: |
|
945 | else: | |
946 | res = lambda p: dest |
|
946 | res = lambda p: dest | |
947 | return res |
|
947 | return res | |
948 |
|
948 | |||
949 |
|
949 | |||
950 | pats = list(pats) |
|
950 | pats = list(pats) | |
951 | if not pats: |
|
951 | if not pats: | |
952 | raise util.Abort(_('no source or destination specified')) |
|
952 | raise util.Abort(_('no source or destination specified')) | |
953 | if len(pats) == 1: |
|
953 | if len(pats) == 1: | |
954 | raise util.Abort(_('no destination specified')) |
|
954 | raise util.Abort(_('no destination specified')) | |
955 | dest = pats.pop() |
|
955 | dest = pats.pop() | |
956 | destdirexists = os.path.isdir(dest) |
|
956 | destdirexists = os.path.isdir(dest) | |
957 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
957 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | |
958 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
958 | raise util.Abort(_('with multiple sources, destination must be an ' | |
959 | 'existing directory')) |
|
959 | 'existing directory')) | |
960 | if opts['after']: |
|
960 | if opts['after']: | |
961 | tfn = targetpathafterfn |
|
961 | tfn = targetpathafterfn | |
962 | else: |
|
962 | else: | |
963 | tfn = targetpathfn |
|
963 | tfn = targetpathfn | |
964 | copylist = [] |
|
964 | copylist = [] | |
965 | for pat in pats: |
|
965 | for pat in pats: | |
966 | srcs = [] |
|
966 | srcs = [] | |
967 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): |
|
967 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | |
968 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
968 | origsrc = okaytocopy(abssrc, relsrc, exact) | |
969 | if origsrc: |
|
969 | if origsrc: | |
970 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
970 | srcs.append((origsrc, abssrc, relsrc, exact)) | |
971 | if not srcs: |
|
971 | if not srcs: | |
972 | continue |
|
972 | continue | |
973 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
973 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
974 | if not copylist: |
|
974 | if not copylist: | |
975 | raise util.Abort(_('no files to copy')) |
|
975 | raise util.Abort(_('no files to copy')) | |
976 |
|
976 | |||
977 | for targetpath, srcs in copylist: |
|
977 | for targetpath, srcs in copylist: | |
978 | for origsrc, abssrc, relsrc, exact in srcs: |
|
978 | for origsrc, abssrc, relsrc, exact in srcs: | |
979 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
979 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | |
980 |
|
980 | |||
981 | if errors: |
|
981 | if errors: | |
982 | ui.warn(_('(consider using --after)\n')) |
|
982 | ui.warn(_('(consider using --after)\n')) | |
983 | return errors, copied |
|
983 | return errors, copied | |
984 |
|
984 | |||
985 | def copy(ui, repo, *pats, **opts): |
|
985 | def copy(ui, repo, *pats, **opts): | |
986 | """mark files as copied for the next commit |
|
986 | """mark files as copied for the next commit | |
987 |
|
987 | |||
988 | Mark dest as having copies of source files. If dest is a |
|
988 | Mark dest as having copies of source files. If dest is a | |
989 | directory, copies are put in that directory. If dest is a file, |
|
989 | directory, copies are put in that directory. If dest is a file, | |
990 | there can only be one source. |
|
990 | there can only be one source. | |
991 |
|
991 | |||
992 | By default, this command copies the contents of files as they |
|
992 | By default, this command copies the contents of files as they | |
993 | stand in the working directory. If invoked with --after, the |
|
993 | stand in the working directory. If invoked with --after, the | |
994 | operation is recorded, but no copying is performed. |
|
994 | operation is recorded, but no copying is performed. | |
995 |
|
995 | |||
996 | This command takes effect in the next commit. |
|
996 | This command takes effect in the next commit. | |
997 |
|
997 | |||
998 | NOTE: This command should be treated as experimental. While it |
|
998 | NOTE: This command should be treated as experimental. While it | |
999 | should properly record copied files, this information is not yet |
|
999 | should properly record copied files, this information is not yet | |
1000 | fully used by merge, nor fully reported by log. |
|
1000 | fully used by merge, nor fully reported by log. | |
1001 | """ |
|
1001 | """ | |
1002 | try: |
|
1002 | try: | |
1003 | wlock = repo.wlock(0) |
|
1003 | wlock = repo.wlock(0) | |
1004 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1004 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
1005 | except lock.LockHeld, inst: |
|
1005 | except lock.LockHeld, inst: | |
1006 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) |
|
1006 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) | |
1007 | errs = 1 |
|
1007 | errs = 1 | |
1008 | return errs |
|
1008 | return errs | |
1009 |
|
1009 | |||
1010 | def debugancestor(ui, index, rev1, rev2): |
|
1010 | def debugancestor(ui, index, rev1, rev2): | |
1011 | """find the ancestor revision of two revisions in a given index""" |
|
1011 | """find the ancestor revision of two revisions in a given index""" | |
1012 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") |
|
1012 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") | |
1013 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1013 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | |
1014 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1014 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | |
1015 |
|
1015 | |||
1016 | def debugrebuildstate(ui, repo, rev=None): |
|
1016 | def debugrebuildstate(ui, repo, rev=None): | |
1017 | """rebuild the dirstate as it would look like for the given revision""" |
|
1017 | """rebuild the dirstate as it would look like for the given revision""" | |
1018 | if not rev: |
|
1018 | if not rev: | |
1019 | rev = repo.changelog.tip() |
|
1019 | rev = repo.changelog.tip() | |
1020 | else: |
|
1020 | else: | |
1021 | rev = repo.lookup(rev) |
|
1021 | rev = repo.lookup(rev) | |
1022 | change = repo.changelog.read(rev) |
|
1022 | change = repo.changelog.read(rev) | |
1023 | n = change[0] |
|
1023 | n = change[0] | |
1024 | files = repo.manifest.readflags(n) |
|
1024 | files = repo.manifest.readflags(n) | |
1025 | wlock = repo.wlock() |
|
1025 | wlock = repo.wlock() | |
1026 | repo.dirstate.rebuild(rev, files.iteritems()) |
|
1026 | repo.dirstate.rebuild(rev, files.iteritems()) | |
1027 |
|
1027 | |||
1028 | def debugcheckstate(ui, repo): |
|
1028 | def debugcheckstate(ui, repo): | |
1029 | """validate the correctness of the current dirstate""" |
|
1029 | """validate the correctness of the current dirstate""" | |
1030 | parent1, parent2 = repo.dirstate.parents() |
|
1030 | parent1, parent2 = repo.dirstate.parents() | |
1031 | repo.dirstate.read() |
|
1031 | repo.dirstate.read() | |
1032 | dc = repo.dirstate.map |
|
1032 | dc = repo.dirstate.map | |
1033 | keys = dc.keys() |
|
1033 | keys = dc.keys() | |
1034 | keys.sort() |
|
1034 | keys.sort() | |
1035 | m1n = repo.changelog.read(parent1)[0] |
|
1035 | m1n = repo.changelog.read(parent1)[0] | |
1036 | m2n = repo.changelog.read(parent2)[0] |
|
1036 | m2n = repo.changelog.read(parent2)[0] | |
1037 | m1 = repo.manifest.read(m1n) |
|
1037 | m1 = repo.manifest.read(m1n) | |
1038 | m2 = repo.manifest.read(m2n) |
|
1038 | m2 = repo.manifest.read(m2n) | |
1039 | errors = 0 |
|
1039 | errors = 0 | |
1040 | for f in dc: |
|
1040 | for f in dc: | |
1041 | state = repo.dirstate.state(f) |
|
1041 | state = repo.dirstate.state(f) | |
1042 | if state in "nr" and f not in m1: |
|
1042 | if state in "nr" and f not in m1: | |
1043 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1043 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | |
1044 | errors += 1 |
|
1044 | errors += 1 | |
1045 | if state in "a" and f in m1: |
|
1045 | if state in "a" and f in m1: | |
1046 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1046 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | |
1047 | errors += 1 |
|
1047 | errors += 1 | |
1048 | if state in "m" and f not in m1 and f not in m2: |
|
1048 | if state in "m" and f not in m1 and f not in m2: | |
1049 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1049 | ui.warn(_("%s in state %s, but not in either manifest\n") % | |
1050 | (f, state)) |
|
1050 | (f, state)) | |
1051 | errors += 1 |
|
1051 | errors += 1 | |
1052 | for f in m1: |
|
1052 | for f in m1: | |
1053 | state = repo.dirstate.state(f) |
|
1053 | state = repo.dirstate.state(f) | |
1054 | if state not in "nrm": |
|
1054 | if state not in "nrm": | |
1055 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1055 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | |
1056 | errors += 1 |
|
1056 | errors += 1 | |
1057 | if errors: |
|
1057 | if errors: | |
1058 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1058 | error = _(".hg/dirstate inconsistent with current parent's manifest") | |
1059 | raise util.Abort(error) |
|
1059 | raise util.Abort(error) | |
1060 |
|
1060 | |||
1061 | def debugconfig(ui): |
|
1061 | def debugconfig(ui, repo): | |
1062 | """show combined config settings from all hgrc files""" |
|
1062 | """show combined config settings from all hgrc files""" | |
1063 | try: |
|
|||
1064 | repo = hg.repository(ui) |
|
|||
1065 | ui = repo.ui |
|
|||
1066 | except hg.RepoError: |
|
|||
1067 | pass |
|
|||
1068 | for section, name, value in ui.walkconfig(): |
|
1063 | for section, name, value in ui.walkconfig(): | |
1069 | ui.write('%s.%s=%s\n' % (section, name, value)) |
|
1064 | ui.write('%s.%s=%s\n' % (section, name, value)) | |
1070 |
|
1065 | |||
1071 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
1066 | def debugsetparents(ui, repo, rev1, rev2=None): | |
1072 | """manually set the parents of the current working directory |
|
1067 | """manually set the parents of the current working directory | |
1073 |
|
1068 | |||
1074 | This is useful for writing repository conversion tools, but should |
|
1069 | This is useful for writing repository conversion tools, but should | |
1075 | be used with care. |
|
1070 | be used with care. | |
1076 | """ |
|
1071 | """ | |
1077 |
|
1072 | |||
1078 | if not rev2: |
|
1073 | if not rev2: | |
1079 | rev2 = hex(nullid) |
|
1074 | rev2 = hex(nullid) | |
1080 |
|
1075 | |||
1081 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
1076 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | |
1082 |
|
1077 | |||
1083 | def debugstate(ui, repo): |
|
1078 | def debugstate(ui, repo): | |
1084 | """show the contents of the current dirstate""" |
|
1079 | """show the contents of the current dirstate""" | |
1085 | repo.dirstate.read() |
|
1080 | repo.dirstate.read() | |
1086 | dc = repo.dirstate.map |
|
1081 | dc = repo.dirstate.map | |
1087 | keys = dc.keys() |
|
1082 | keys = dc.keys() | |
1088 | keys.sort() |
|
1083 | keys.sort() | |
1089 | for file_ in keys: |
|
1084 | for file_ in keys: | |
1090 | ui.write("%c %3o %10d %s %s\n" |
|
1085 | ui.write("%c %3o %10d %s %s\n" | |
1091 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
1086 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | |
1092 | time.strftime("%x %X", |
|
1087 | time.strftime("%x %X", | |
1093 | time.localtime(dc[file_][3])), file_)) |
|
1088 | time.localtime(dc[file_][3])), file_)) | |
1094 | for f in repo.dirstate.copies: |
|
1089 | for f in repo.dirstate.copies: | |
1095 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) |
|
1090 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) | |
1096 |
|
1091 | |||
1097 | def debugdata(ui, file_, rev): |
|
1092 | def debugdata(ui, file_, rev): | |
1098 | """dump the contents of an data file revision""" |
|
1093 | """dump the contents of an data file revision""" | |
1099 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
1094 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | |
1100 | file_[:-2] + ".i", file_) |
|
1095 | file_[:-2] + ".i", file_) | |
1101 | try: |
|
1096 | try: | |
1102 | ui.write(r.revision(r.lookup(rev))) |
|
1097 | ui.write(r.revision(r.lookup(rev))) | |
1103 | except KeyError: |
|
1098 | except KeyError: | |
1104 | raise util.Abort(_('invalid revision identifier %s'), rev) |
|
1099 | raise util.Abort(_('invalid revision identifier %s'), rev) | |
1105 |
|
1100 | |||
1106 | def debugindex(ui, file_): |
|
1101 | def debugindex(ui, file_): | |
1107 | """dump the contents of an index file""" |
|
1102 | """dump the contents of an index file""" | |
1108 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") |
|
1103 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | |
1109 | ui.write(" rev offset length base linkrev" + |
|
1104 | ui.write(" rev offset length base linkrev" + | |
1110 | " nodeid p1 p2\n") |
|
1105 | " nodeid p1 p2\n") | |
1111 | for i in range(r.count()): |
|
1106 | for i in range(r.count()): | |
1112 | e = r.index[i] |
|
1107 | e = r.index[i] | |
1113 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1108 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
1114 | i, e[0], e[1], e[2], e[3], |
|
1109 | i, e[0], e[1], e[2], e[3], | |
1115 | short(e[6]), short(e[4]), short(e[5]))) |
|
1110 | short(e[6]), short(e[4]), short(e[5]))) | |
1116 |
|
1111 | |||
1117 | def debugindexdot(ui, file_): |
|
1112 | def debugindexdot(ui, file_): | |
1118 | """dump an index DAG as a .dot file""" |
|
1113 | """dump an index DAG as a .dot file""" | |
1119 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") |
|
1114 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | |
1120 | ui.write("digraph G {\n") |
|
1115 | ui.write("digraph G {\n") | |
1121 | for i in range(r.count()): |
|
1116 | for i in range(r.count()): | |
1122 | e = r.index[i] |
|
1117 | e = r.index[i] | |
1123 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) |
|
1118 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) | |
1124 | if e[5] != nullid: |
|
1119 | if e[5] != nullid: | |
1125 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) |
|
1120 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) | |
1126 | ui.write("}\n") |
|
1121 | ui.write("}\n") | |
1127 |
|
1122 | |||
1128 | def debugrename(ui, repo, file, rev=None): |
|
1123 | def debugrename(ui, repo, file, rev=None): | |
1129 | """dump rename information""" |
|
1124 | """dump rename information""" | |
1130 | r = repo.file(relpath(repo, [file])[0]) |
|
1125 | r = repo.file(relpath(repo, [file])[0]) | |
1131 | if rev: |
|
1126 | if rev: | |
1132 | try: |
|
1127 | try: | |
1133 | # assume all revision numbers are for changesets |
|
1128 | # assume all revision numbers are for changesets | |
1134 | n = repo.lookup(rev) |
|
1129 | n = repo.lookup(rev) | |
1135 | change = repo.changelog.read(n) |
|
1130 | change = repo.changelog.read(n) | |
1136 | m = repo.manifest.read(change[0]) |
|
1131 | m = repo.manifest.read(change[0]) | |
1137 | n = m[relpath(repo, [file])[0]] |
|
1132 | n = m[relpath(repo, [file])[0]] | |
1138 | except (hg.RepoError, KeyError): |
|
1133 | except (hg.RepoError, KeyError): | |
1139 | n = r.lookup(rev) |
|
1134 | n = r.lookup(rev) | |
1140 | else: |
|
1135 | else: | |
1141 | n = r.tip() |
|
1136 | n = r.tip() | |
1142 | m = r.renamed(n) |
|
1137 | m = r.renamed(n) | |
1143 | if m: |
|
1138 | if m: | |
1144 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) |
|
1139 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) | |
1145 | else: |
|
1140 | else: | |
1146 | ui.write(_("not renamed\n")) |
|
1141 | ui.write(_("not renamed\n")) | |
1147 |
|
1142 | |||
1148 | def debugwalk(ui, repo, *pats, **opts): |
|
1143 | def debugwalk(ui, repo, *pats, **opts): | |
1149 | """show how files match on given patterns""" |
|
1144 | """show how files match on given patterns""" | |
1150 | items = list(walk(repo, pats, opts)) |
|
1145 | items = list(walk(repo, pats, opts)) | |
1151 | if not items: |
|
1146 | if not items: | |
1152 | return |
|
1147 | return | |
1153 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1148 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | |
1154 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1149 | max([len(abs) for (src, abs, rel, exact) in items]), | |
1155 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1150 | max([len(rel) for (src, abs, rel, exact) in items])) | |
1156 | for src, abs, rel, exact in items: |
|
1151 | for src, abs, rel, exact in items: | |
1157 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1152 | line = fmt % (src, abs, rel, exact and 'exact' or '') | |
1158 | ui.write("%s\n" % line.rstrip()) |
|
1153 | ui.write("%s\n" % line.rstrip()) | |
1159 |
|
1154 | |||
1160 | def diff(ui, repo, *pats, **opts): |
|
1155 | def diff(ui, repo, *pats, **opts): | |
1161 | """diff repository (or selected files) |
|
1156 | """diff repository (or selected files) | |
1162 |
|
1157 | |||
1163 | Show differences between revisions for the specified files. |
|
1158 | Show differences between revisions for the specified files. | |
1164 |
|
1159 | |||
1165 | Differences between files are shown using the unified diff format. |
|
1160 | Differences between files are shown using the unified diff format. | |
1166 |
|
1161 | |||
1167 | When two revision arguments are given, then changes are shown |
|
1162 | When two revision arguments are given, then changes are shown | |
1168 | between those revisions. If only one revision is specified then |
|
1163 | between those revisions. If only one revision is specified then | |
1169 | that revision is compared to the working directory, and, when no |
|
1164 | that revision is compared to the working directory, and, when no | |
1170 | revisions are specified, the working directory files are compared |
|
1165 | revisions are specified, the working directory files are compared | |
1171 | to its parent. |
|
1166 | to its parent. | |
1172 |
|
1167 | |||
1173 | Without the -a option, diff will avoid generating diffs of files |
|
1168 | Without the -a option, diff will avoid generating diffs of files | |
1174 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1169 | it detects as binary. With -a, diff will generate a diff anyway, | |
1175 | probably with undesirable results. |
|
1170 | probably with undesirable results. | |
1176 | """ |
|
1171 | """ | |
1177 | node1, node2 = None, None |
|
1172 | node1, node2 = None, None | |
1178 | revs = [repo.lookup(x) for x in opts['rev']] |
|
1173 | revs = [repo.lookup(x) for x in opts['rev']] | |
1179 |
|
1174 | |||
1180 | if len(revs) > 0: |
|
1175 | if len(revs) > 0: | |
1181 | node1 = revs[0] |
|
1176 | node1 = revs[0] | |
1182 | if len(revs) > 1: |
|
1177 | if len(revs) > 1: | |
1183 | node2 = revs[1] |
|
1178 | node2 = revs[1] | |
1184 | if len(revs) > 2: |
|
1179 | if len(revs) > 2: | |
1185 | raise util.Abort(_("too many revisions to diff")) |
|
1180 | raise util.Abort(_("too many revisions to diff")) | |
1186 |
|
1181 | |||
1187 | fns, matchfn, anypats = matchpats(repo, pats, opts) |
|
1182 | fns, matchfn, anypats = matchpats(repo, pats, opts) | |
1188 |
|
1183 | |||
1189 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
|
1184 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | |
1190 | text=opts['text'], opts=opts) |
|
1185 | text=opts['text'], opts=opts) | |
1191 |
|
1186 | |||
1192 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
|
1187 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | |
1193 | node = repo.lookup(changeset) |
|
1188 | node = repo.lookup(changeset) | |
1194 | parents = [p for p in repo.changelog.parents(node) if p != nullid] |
|
1189 | parents = [p for p in repo.changelog.parents(node) if p != nullid] | |
1195 | if opts['switch_parent']: |
|
1190 | if opts['switch_parent']: | |
1196 | parents.reverse() |
|
1191 | parents.reverse() | |
1197 | prev = (parents and parents[0]) or nullid |
|
1192 | prev = (parents and parents[0]) or nullid | |
1198 | change = repo.changelog.read(node) |
|
1193 | change = repo.changelog.read(node) | |
1199 |
|
1194 | |||
1200 | fp = make_file(repo, repo.changelog, opts['output'], |
|
1195 | fp = make_file(repo, repo.changelog, opts['output'], | |
1201 | node=node, total=total, seqno=seqno, |
|
1196 | node=node, total=total, seqno=seqno, | |
1202 | revwidth=revwidth) |
|
1197 | revwidth=revwidth) | |
1203 | if fp != sys.stdout: |
|
1198 | if fp != sys.stdout: | |
1204 | ui.note("%s\n" % fp.name) |
|
1199 | ui.note("%s\n" % fp.name) | |
1205 |
|
1200 | |||
1206 | fp.write("# HG changeset patch\n") |
|
1201 | fp.write("# HG changeset patch\n") | |
1207 | fp.write("# User %s\n" % change[1]) |
|
1202 | fp.write("# User %s\n" % change[1]) | |
1208 | fp.write("# Node ID %s\n" % hex(node)) |
|
1203 | fp.write("# Node ID %s\n" % hex(node)) | |
1209 | fp.write("# Parent %s\n" % hex(prev)) |
|
1204 | fp.write("# Parent %s\n" % hex(prev)) | |
1210 | if len(parents) > 1: |
|
1205 | if len(parents) > 1: | |
1211 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
1206 | fp.write("# Parent %s\n" % hex(parents[1])) | |
1212 | fp.write(change[4].rstrip()) |
|
1207 | fp.write(change[4].rstrip()) | |
1213 | fp.write("\n\n") |
|
1208 | fp.write("\n\n") | |
1214 |
|
1209 | |||
1215 | dodiff(fp, ui, repo, prev, node, text=opts['text']) |
|
1210 | dodiff(fp, ui, repo, prev, node, text=opts['text']) | |
1216 | if fp != sys.stdout: |
|
1211 | if fp != sys.stdout: | |
1217 | fp.close() |
|
1212 | fp.close() | |
1218 |
|
1213 | |||
1219 | def export(ui, repo, *changesets, **opts): |
|
1214 | def export(ui, repo, *changesets, **opts): | |
1220 | """dump the header and diffs for one or more changesets |
|
1215 | """dump the header and diffs for one or more changesets | |
1221 |
|
1216 | |||
1222 | Print the changeset header and diffs for one or more revisions. |
|
1217 | Print the changeset header and diffs for one or more revisions. | |
1223 |
|
1218 | |||
1224 | The information shown in the changeset header is: author, |
|
1219 | The information shown in the changeset header is: author, | |
1225 | changeset hash, parent and commit comment. |
|
1220 | changeset hash, parent and commit comment. | |
1226 |
|
1221 | |||
1227 | Output may be to a file, in which case the name of the file is |
|
1222 | Output may be to a file, in which case the name of the file is | |
1228 | given using a format string. The formatting rules are as follows: |
|
1223 | given using a format string. The formatting rules are as follows: | |
1229 |
|
1224 | |||
1230 | %% literal "%" character |
|
1225 | %% literal "%" character | |
1231 | %H changeset hash (40 bytes of hexadecimal) |
|
1226 | %H changeset hash (40 bytes of hexadecimal) | |
1232 | %N number of patches being generated |
|
1227 | %N number of patches being generated | |
1233 | %R changeset revision number |
|
1228 | %R changeset revision number | |
1234 | %b basename of the exporting repository |
|
1229 | %b basename of the exporting repository | |
1235 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1230 | %h short-form changeset hash (12 bytes of hexadecimal) | |
1236 | %n zero-padded sequence number, starting at 1 |
|
1231 | %n zero-padded sequence number, starting at 1 | |
1237 | %r zero-padded changeset revision number |
|
1232 | %r zero-padded changeset revision number | |
1238 |
|
1233 | |||
1239 | Without the -a option, export will avoid generating diffs of files |
|
1234 | Without the -a option, export will avoid generating diffs of files | |
1240 | it detects as binary. With -a, export will generate a diff anyway, |
|
1235 | it detects as binary. With -a, export will generate a diff anyway, | |
1241 | probably with undesirable results. |
|
1236 | probably with undesirable results. | |
1242 |
|
1237 | |||
1243 | With the --switch-parent option, the diff will be against the second |
|
1238 | With the --switch-parent option, the diff will be against the second | |
1244 | parent. It can be useful to review a merge. |
|
1239 | parent. It can be useful to review a merge. | |
1245 | """ |
|
1240 | """ | |
1246 | if not changesets: |
|
1241 | if not changesets: | |
1247 | raise util.Abort(_("export requires at least one changeset")) |
|
1242 | raise util.Abort(_("export requires at least one changeset")) | |
1248 | seqno = 0 |
|
1243 | seqno = 0 | |
1249 | revs = list(revrange(ui, repo, changesets)) |
|
1244 | revs = list(revrange(ui, repo, changesets)) | |
1250 | total = len(revs) |
|
1245 | total = len(revs) | |
1251 | revwidth = max(map(len, revs)) |
|
1246 | revwidth = max(map(len, revs)) | |
1252 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") |
|
1247 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") | |
1253 | ui.note(msg) |
|
1248 | ui.note(msg) | |
1254 | for cset in revs: |
|
1249 | for cset in revs: | |
1255 | seqno += 1 |
|
1250 | seqno += 1 | |
1256 | doexport(ui, repo, cset, seqno, total, revwidth, opts) |
|
1251 | doexport(ui, repo, cset, seqno, total, revwidth, opts) | |
1257 |
|
1252 | |||
1258 | def forget(ui, repo, *pats, **opts): |
|
1253 | def forget(ui, repo, *pats, **opts): | |
1259 | """don't add the specified files on the next commit |
|
1254 | """don't add the specified files on the next commit | |
1260 |
|
1255 | |||
1261 | Undo an 'hg add' scheduled for the next commit. |
|
1256 | Undo an 'hg add' scheduled for the next commit. | |
1262 | """ |
|
1257 | """ | |
1263 | forget = [] |
|
1258 | forget = [] | |
1264 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
1259 | for src, abs, rel, exact in walk(repo, pats, opts): | |
1265 | if repo.dirstate.state(abs) == 'a': |
|
1260 | if repo.dirstate.state(abs) == 'a': | |
1266 | forget.append(abs) |
|
1261 | forget.append(abs) | |
1267 | if ui.verbose or not exact: |
|
1262 | if ui.verbose or not exact: | |
1268 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
|
1263 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) | |
1269 | repo.forget(forget) |
|
1264 | repo.forget(forget) | |
1270 |
|
1265 | |||
1271 | def grep(ui, repo, pattern, *pats, **opts): |
|
1266 | def grep(ui, repo, pattern, *pats, **opts): | |
1272 | """search for a pattern in specified files and revisions |
|
1267 | """search for a pattern in specified files and revisions | |
1273 |
|
1268 | |||
1274 | Search revisions of files for a regular expression. |
|
1269 | Search revisions of files for a regular expression. | |
1275 |
|
1270 | |||
1276 | This command behaves differently than Unix grep. It only accepts |
|
1271 | This command behaves differently than Unix grep. It only accepts | |
1277 | Python/Perl regexps. It searches repository history, not the |
|
1272 | Python/Perl regexps. It searches repository history, not the | |
1278 | working directory. It always prints the revision number in which |
|
1273 | working directory. It always prints the revision number in which | |
1279 | a match appears. |
|
1274 | a match appears. | |
1280 |
|
1275 | |||
1281 | By default, grep only prints output for the first revision of a |
|
1276 | By default, grep only prints output for the first revision of a | |
1282 | file in which it finds a match. To get it to print every revision |
|
1277 | file in which it finds a match. To get it to print every revision | |
1283 | that contains a change in match status ("-" for a match that |
|
1278 | that contains a change in match status ("-" for a match that | |
1284 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1279 | becomes a non-match, or "+" for a non-match that becomes a match), | |
1285 | use the --all flag. |
|
1280 | use the --all flag. | |
1286 | """ |
|
1281 | """ | |
1287 | reflags = 0 |
|
1282 | reflags = 0 | |
1288 | if opts['ignore_case']: |
|
1283 | if opts['ignore_case']: | |
1289 | reflags |= re.I |
|
1284 | reflags |= re.I | |
1290 | regexp = re.compile(pattern, reflags) |
|
1285 | regexp = re.compile(pattern, reflags) | |
1291 | sep, eol = ':', '\n' |
|
1286 | sep, eol = ':', '\n' | |
1292 | if opts['print0']: |
|
1287 | if opts['print0']: | |
1293 | sep = eol = '\0' |
|
1288 | sep = eol = '\0' | |
1294 |
|
1289 | |||
1295 | fcache = {} |
|
1290 | fcache = {} | |
1296 | def getfile(fn): |
|
1291 | def getfile(fn): | |
1297 | if fn not in fcache: |
|
1292 | if fn not in fcache: | |
1298 | fcache[fn] = repo.file(fn) |
|
1293 | fcache[fn] = repo.file(fn) | |
1299 | return fcache[fn] |
|
1294 | return fcache[fn] | |
1300 |
|
1295 | |||
1301 | def matchlines(body): |
|
1296 | def matchlines(body): | |
1302 | begin = 0 |
|
1297 | begin = 0 | |
1303 | linenum = 0 |
|
1298 | linenum = 0 | |
1304 | while True: |
|
1299 | while True: | |
1305 | match = regexp.search(body, begin) |
|
1300 | match = regexp.search(body, begin) | |
1306 | if not match: |
|
1301 | if not match: | |
1307 | break |
|
1302 | break | |
1308 | mstart, mend = match.span() |
|
1303 | mstart, mend = match.span() | |
1309 | linenum += body.count('\n', begin, mstart) + 1 |
|
1304 | linenum += body.count('\n', begin, mstart) + 1 | |
1310 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1305 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
1311 | lend = body.find('\n', mend) |
|
1306 | lend = body.find('\n', mend) | |
1312 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1307 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
1313 | begin = lend + 1 |
|
1308 | begin = lend + 1 | |
1314 |
|
1309 | |||
1315 | class linestate(object): |
|
1310 | class linestate(object): | |
1316 | def __init__(self, line, linenum, colstart, colend): |
|
1311 | def __init__(self, line, linenum, colstart, colend): | |
1317 | self.line = line |
|
1312 | self.line = line | |
1318 | self.linenum = linenum |
|
1313 | self.linenum = linenum | |
1319 | self.colstart = colstart |
|
1314 | self.colstart = colstart | |
1320 | self.colend = colend |
|
1315 | self.colend = colend | |
1321 | def __eq__(self, other): |
|
1316 | def __eq__(self, other): | |
1322 | return self.line == other.line |
|
1317 | return self.line == other.line | |
1323 | def __hash__(self): |
|
1318 | def __hash__(self): | |
1324 | return hash(self.line) |
|
1319 | return hash(self.line) | |
1325 |
|
1320 | |||
1326 | matches = {} |
|
1321 | matches = {} | |
1327 | def grepbody(fn, rev, body): |
|
1322 | def grepbody(fn, rev, body): | |
1328 | matches[rev].setdefault(fn, {}) |
|
1323 | matches[rev].setdefault(fn, {}) | |
1329 | m = matches[rev][fn] |
|
1324 | m = matches[rev][fn] | |
1330 | for lnum, cstart, cend, line in matchlines(body): |
|
1325 | for lnum, cstart, cend, line in matchlines(body): | |
1331 | s = linestate(line, lnum, cstart, cend) |
|
1326 | s = linestate(line, lnum, cstart, cend) | |
1332 | m[s] = s |
|
1327 | m[s] = s | |
1333 |
|
1328 | |||
1334 | # FIXME: prev isn't used, why ? |
|
1329 | # FIXME: prev isn't used, why ? | |
1335 | prev = {} |
|
1330 | prev = {} | |
1336 | ucache = {} |
|
1331 | ucache = {} | |
1337 | def display(fn, rev, states, prevstates): |
|
1332 | def display(fn, rev, states, prevstates): | |
1338 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) |
|
1333 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) | |
1339 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) |
|
1334 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) | |
1340 | counts = {'-': 0, '+': 0} |
|
1335 | counts = {'-': 0, '+': 0} | |
1341 | filerevmatches = {} |
|
1336 | filerevmatches = {} | |
1342 | for l in diff: |
|
1337 | for l in diff: | |
1343 | if incrementing or not opts['all']: |
|
1338 | if incrementing or not opts['all']: | |
1344 | change = ((l in prevstates) and '-') or '+' |
|
1339 | change = ((l in prevstates) and '-') or '+' | |
1345 | r = rev |
|
1340 | r = rev | |
1346 | else: |
|
1341 | else: | |
1347 | change = ((l in states) and '-') or '+' |
|
1342 | change = ((l in states) and '-') or '+' | |
1348 | r = prev[fn] |
|
1343 | r = prev[fn] | |
1349 | cols = [fn, str(rev)] |
|
1344 | cols = [fn, str(rev)] | |
1350 | if opts['line_number']: |
|
1345 | if opts['line_number']: | |
1351 | cols.append(str(l.linenum)) |
|
1346 | cols.append(str(l.linenum)) | |
1352 | if opts['all']: |
|
1347 | if opts['all']: | |
1353 | cols.append(change) |
|
1348 | cols.append(change) | |
1354 | if opts['user']: |
|
1349 | if opts['user']: | |
1355 | cols.append(trimuser(ui, getchange(rev)[1], rev, |
|
1350 | cols.append(trimuser(ui, getchange(rev)[1], rev, | |
1356 | ucache)) |
|
1351 | ucache)) | |
1357 | if opts['files_with_matches']: |
|
1352 | if opts['files_with_matches']: | |
1358 | c = (fn, rev) |
|
1353 | c = (fn, rev) | |
1359 | if c in filerevmatches: |
|
1354 | if c in filerevmatches: | |
1360 | continue |
|
1355 | continue | |
1361 | filerevmatches[c] = 1 |
|
1356 | filerevmatches[c] = 1 | |
1362 | else: |
|
1357 | else: | |
1363 | cols.append(l.line) |
|
1358 | cols.append(l.line) | |
1364 | ui.write(sep.join(cols), eol) |
|
1359 | ui.write(sep.join(cols), eol) | |
1365 | counts[change] += 1 |
|
1360 | counts[change] += 1 | |
1366 | return counts['+'], counts['-'] |
|
1361 | return counts['+'], counts['-'] | |
1367 |
|
1362 | |||
1368 | fstate = {} |
|
1363 | fstate = {} | |
1369 | skip = {} |
|
1364 | skip = {} | |
1370 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1365 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1371 | count = 0 |
|
1366 | count = 0 | |
1372 | incrementing = False |
|
1367 | incrementing = False | |
1373 | for st, rev, fns in changeiter: |
|
1368 | for st, rev, fns in changeiter: | |
1374 | if st == 'window': |
|
1369 | if st == 'window': | |
1375 | incrementing = rev |
|
1370 | incrementing = rev | |
1376 | matches.clear() |
|
1371 | matches.clear() | |
1377 | elif st == 'add': |
|
1372 | elif st == 'add': | |
1378 | change = repo.changelog.read(repo.lookup(str(rev))) |
|
1373 | change = repo.changelog.read(repo.lookup(str(rev))) | |
1379 | mf = repo.manifest.read(change[0]) |
|
1374 | mf = repo.manifest.read(change[0]) | |
1380 | matches[rev] = {} |
|
1375 | matches[rev] = {} | |
1381 | for fn in fns: |
|
1376 | for fn in fns: | |
1382 | if fn in skip: |
|
1377 | if fn in skip: | |
1383 | continue |
|
1378 | continue | |
1384 | fstate.setdefault(fn, {}) |
|
1379 | fstate.setdefault(fn, {}) | |
1385 | try: |
|
1380 | try: | |
1386 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1381 | grepbody(fn, rev, getfile(fn).read(mf[fn])) | |
1387 | except KeyError: |
|
1382 | except KeyError: | |
1388 | pass |
|
1383 | pass | |
1389 | elif st == 'iter': |
|
1384 | elif st == 'iter': | |
1390 | states = matches[rev].items() |
|
1385 | states = matches[rev].items() | |
1391 | states.sort() |
|
1386 | states.sort() | |
1392 | for fn, m in states: |
|
1387 | for fn, m in states: | |
1393 | if fn in skip: |
|
1388 | if fn in skip: | |
1394 | continue |
|
1389 | continue | |
1395 | if incrementing or not opts['all'] or fstate[fn]: |
|
1390 | if incrementing or not opts['all'] or fstate[fn]: | |
1396 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1391 | pos, neg = display(fn, rev, m, fstate[fn]) | |
1397 | count += pos + neg |
|
1392 | count += pos + neg | |
1398 | if pos and not opts['all']: |
|
1393 | if pos and not opts['all']: | |
1399 | skip[fn] = True |
|
1394 | skip[fn] = True | |
1400 | fstate[fn] = m |
|
1395 | fstate[fn] = m | |
1401 | prev[fn] = rev |
|
1396 | prev[fn] = rev | |
1402 |
|
1397 | |||
1403 | if not incrementing: |
|
1398 | if not incrementing: | |
1404 | fstate = fstate.items() |
|
1399 | fstate = fstate.items() | |
1405 | fstate.sort() |
|
1400 | fstate.sort() | |
1406 | for fn, state in fstate: |
|
1401 | for fn, state in fstate: | |
1407 | if fn in skip: |
|
1402 | if fn in skip: | |
1408 | continue |
|
1403 | continue | |
1409 | display(fn, rev, {}, state) |
|
1404 | display(fn, rev, {}, state) | |
1410 | return (count == 0 and 1) or 0 |
|
1405 | return (count == 0 and 1) or 0 | |
1411 |
|
1406 | |||
1412 | def heads(ui, repo, **opts): |
|
1407 | def heads(ui, repo, **opts): | |
1413 | """show current repository heads |
|
1408 | """show current repository heads | |
1414 |
|
1409 | |||
1415 | Show all repository head changesets. |
|
1410 | Show all repository head changesets. | |
1416 |
|
1411 | |||
1417 | Repository "heads" are changesets that don't have children |
|
1412 | Repository "heads" are changesets that don't have children | |
1418 | changesets. They are where development generally takes place and |
|
1413 | changesets. They are where development generally takes place and | |
1419 | are the usual targets for update and merge operations. |
|
1414 | are the usual targets for update and merge operations. | |
1420 | """ |
|
1415 | """ | |
1421 | if opts['rev']: |
|
1416 | if opts['rev']: | |
1422 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1417 | heads = repo.heads(repo.lookup(opts['rev'])) | |
1423 | else: |
|
1418 | else: | |
1424 | heads = repo.heads() |
|
1419 | heads = repo.heads() | |
1425 | br = None |
|
1420 | br = None | |
1426 | if opts['branches']: |
|
1421 | if opts['branches']: | |
1427 | br = repo.branchlookup(heads) |
|
1422 | br = repo.branchlookup(heads) | |
1428 | for n in heads: |
|
1423 | for n in heads: | |
1429 | show_changeset(ui, repo, changenode=n, brinfo=br) |
|
1424 | show_changeset(ui, repo, changenode=n, brinfo=br) | |
1430 |
|
1425 | |||
1431 | def identify(ui, repo): |
|
1426 | def identify(ui, repo): | |
1432 | """print information about the working copy |
|
1427 | """print information about the working copy | |
1433 |
|
1428 | |||
1434 | Print a short summary of the current state of the repo. |
|
1429 | Print a short summary of the current state of the repo. | |
1435 |
|
1430 | |||
1436 | This summary identifies the repository state using one or two parent |
|
1431 | This summary identifies the repository state using one or two parent | |
1437 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1432 | hash identifiers, followed by a "+" if there are uncommitted changes | |
1438 | in the working directory, followed by a list of tags for this revision. |
|
1433 | in the working directory, followed by a list of tags for this revision. | |
1439 | """ |
|
1434 | """ | |
1440 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1435 | parents = [p for p in repo.dirstate.parents() if p != nullid] | |
1441 | if not parents: |
|
1436 | if not parents: | |
1442 | ui.write(_("unknown\n")) |
|
1437 | ui.write(_("unknown\n")) | |
1443 | return |
|
1438 | return | |
1444 |
|
1439 | |||
1445 | hexfunc = ui.verbose and hex or short |
|
1440 | hexfunc = ui.verbose and hex or short | |
1446 | modified, added, removed, deleted, unknown = repo.changes() |
|
1441 | modified, added, removed, deleted, unknown = repo.changes() | |
1447 | output = ["%s%s" % |
|
1442 | output = ["%s%s" % | |
1448 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1443 | ('+'.join([hexfunc(parent) for parent in parents]), | |
1449 | (modified or added or removed or deleted) and "+" or "")] |
|
1444 | (modified or added or removed or deleted) and "+" or "")] | |
1450 |
|
1445 | |||
1451 | if not ui.quiet: |
|
1446 | if not ui.quiet: | |
1452 | # multiple tags for a single parent separated by '/' |
|
1447 | # multiple tags for a single parent separated by '/' | |
1453 | parenttags = ['/'.join(tags) |
|
1448 | parenttags = ['/'.join(tags) | |
1454 | for tags in map(repo.nodetags, parents) if tags] |
|
1449 | for tags in map(repo.nodetags, parents) if tags] | |
1455 | # tags for multiple parents separated by ' + ' |
|
1450 | # tags for multiple parents separated by ' + ' | |
1456 | if parenttags: |
|
1451 | if parenttags: | |
1457 | output.append(' + '.join(parenttags)) |
|
1452 | output.append(' + '.join(parenttags)) | |
1458 |
|
1453 | |||
1459 | ui.write("%s\n" % ' '.join(output)) |
|
1454 | ui.write("%s\n" % ' '.join(output)) | |
1460 |
|
1455 | |||
1461 | def import_(ui, repo, patch1, *patches, **opts): |
|
1456 | def import_(ui, repo, patch1, *patches, **opts): | |
1462 | """import an ordered set of patches |
|
1457 | """import an ordered set of patches | |
1463 |
|
1458 | |||
1464 | Import a list of patches and commit them individually. |
|
1459 | Import a list of patches and commit them individually. | |
1465 |
|
1460 | |||
1466 | If there are outstanding changes in the working directory, import |
|
1461 | If there are outstanding changes in the working directory, import | |
1467 | will abort unless given the -f flag. |
|
1462 | will abort unless given the -f flag. | |
1468 |
|
1463 | |||
1469 | If a patch looks like a mail message (its first line starts with |
|
1464 | If a patch looks like a mail message (its first line starts with | |
1470 | "From " or looks like an RFC822 header), it will not be applied |
|
1465 | "From " or looks like an RFC822 header), it will not be applied | |
1471 | unless the -f option is used. The importer neither parses nor |
|
1466 | unless the -f option is used. The importer neither parses nor | |
1472 | discards mail headers, so use -f only to override the "mailness" |
|
1467 | discards mail headers, so use -f only to override the "mailness" | |
1473 | safety check, not to import a real mail message. |
|
1468 | safety check, not to import a real mail message. | |
1474 | """ |
|
1469 | """ | |
1475 | patches = (patch1,) + patches |
|
1470 | patches = (patch1,) + patches | |
1476 |
|
1471 | |||
1477 | if not opts['force']: |
|
1472 | if not opts['force']: | |
1478 | modified, added, removed, deleted, unknown = repo.changes() |
|
1473 | modified, added, removed, deleted, unknown = repo.changes() | |
1479 | if modified or added or removed or deleted: |
|
1474 | if modified or added or removed or deleted: | |
1480 | raise util.Abort(_("outstanding uncommitted changes")) |
|
1475 | raise util.Abort(_("outstanding uncommitted changes")) | |
1481 |
|
1476 | |||
1482 | d = opts["base"] |
|
1477 | d = opts["base"] | |
1483 | strip = opts["strip"] |
|
1478 | strip = opts["strip"] | |
1484 |
|
1479 | |||
1485 | mailre = re.compile(r'(?:From |[\w-]+:)') |
|
1480 | mailre = re.compile(r'(?:From |[\w-]+:)') | |
1486 |
|
1481 | |||
1487 | # attempt to detect the start of a patch |
|
1482 | # attempt to detect the start of a patch | |
1488 | # (this heuristic is borrowed from quilt) |
|
1483 | # (this heuristic is borrowed from quilt) | |
1489 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + |
|
1484 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + | |
1490 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + |
|
1485 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + | |
1491 | '(---|\*\*\*)[ \t])') |
|
1486 | '(---|\*\*\*)[ \t])') | |
1492 |
|
1487 | |||
1493 | for patch in patches: |
|
1488 | for patch in patches: | |
1494 | ui.status(_("applying %s\n") % patch) |
|
1489 | ui.status(_("applying %s\n") % patch) | |
1495 | pf = os.path.join(d, patch) |
|
1490 | pf = os.path.join(d, patch) | |
1496 |
|
1491 | |||
1497 | message = [] |
|
1492 | message = [] | |
1498 | user = None |
|
1493 | user = None | |
1499 | hgpatch = False |
|
1494 | hgpatch = False | |
1500 | for line in file(pf): |
|
1495 | for line in file(pf): | |
1501 | line = line.rstrip() |
|
1496 | line = line.rstrip() | |
1502 | if (not message and not hgpatch and |
|
1497 | if (not message and not hgpatch and | |
1503 | mailre.match(line) and not opts['force']): |
|
1498 | mailre.match(line) and not opts['force']): | |
1504 | if len(line) > 35: |
|
1499 | if len(line) > 35: | |
1505 | line = line[:32] + '...' |
|
1500 | line = line[:32] + '...' | |
1506 | raise util.Abort(_('first line looks like a ' |
|
1501 | raise util.Abort(_('first line looks like a ' | |
1507 | 'mail header: ') + line) |
|
1502 | 'mail header: ') + line) | |
1508 | if diffre.match(line): |
|
1503 | if diffre.match(line): | |
1509 | break |
|
1504 | break | |
1510 | elif hgpatch: |
|
1505 | elif hgpatch: | |
1511 | # parse values when importing the result of an hg export |
|
1506 | # parse values when importing the result of an hg export | |
1512 | if line.startswith("# User "): |
|
1507 | if line.startswith("# User "): | |
1513 | user = line[7:] |
|
1508 | user = line[7:] | |
1514 | ui.debug(_('User: %s\n') % user) |
|
1509 | ui.debug(_('User: %s\n') % user) | |
1515 | elif not line.startswith("# ") and line: |
|
1510 | elif not line.startswith("# ") and line: | |
1516 | message.append(line) |
|
1511 | message.append(line) | |
1517 | hgpatch = False |
|
1512 | hgpatch = False | |
1518 | elif line == '# HG changeset patch': |
|
1513 | elif line == '# HG changeset patch': | |
1519 | hgpatch = True |
|
1514 | hgpatch = True | |
1520 | message = [] # We may have collected garbage |
|
1515 | message = [] # We may have collected garbage | |
1521 | else: |
|
1516 | else: | |
1522 | message.append(line) |
|
1517 | message.append(line) | |
1523 |
|
1518 | |||
1524 | # make sure message isn't empty |
|
1519 | # make sure message isn't empty | |
1525 | if not message: |
|
1520 | if not message: | |
1526 | message = _("imported patch %s\n") % patch |
|
1521 | message = _("imported patch %s\n") % patch | |
1527 | else: |
|
1522 | else: | |
1528 | message = "%s\n" % '\n'.join(message) |
|
1523 | message = "%s\n" % '\n'.join(message) | |
1529 | ui.debug(_('message:\n%s\n') % message) |
|
1524 | ui.debug(_('message:\n%s\n') % message) | |
1530 |
|
1525 | |||
1531 | files = util.patch(strip, pf, ui) |
|
1526 | files = util.patch(strip, pf, ui) | |
1532 |
|
1527 | |||
1533 | if len(files) > 0: |
|
1528 | if len(files) > 0: | |
1534 | addremove(ui, repo, *files) |
|
1529 | addremove(ui, repo, *files) | |
1535 | repo.commit(files, message, user) |
|
1530 | repo.commit(files, message, user) | |
1536 |
|
1531 | |||
1537 | def incoming(ui, repo, source="default", **opts): |
|
1532 | def incoming(ui, repo, source="default", **opts): | |
1538 | """show new changesets found in source |
|
1533 | """show new changesets found in source | |
1539 |
|
1534 | |||
1540 | Show new changesets found in the specified repo or the default |
|
1535 | Show new changesets found in the specified repo or the default | |
1541 | pull repo. These are the changesets that would be pulled if a pull |
|
1536 | pull repo. These are the changesets that would be pulled if a pull | |
1542 | was requested. |
|
1537 | was requested. | |
1543 |
|
1538 | |||
1544 | Currently only local repositories are supported. |
|
1539 | Currently only local repositories are supported. | |
1545 | """ |
|
1540 | """ | |
1546 | source = ui.expandpath(source, repo.root) |
|
1541 | source = ui.expandpath(source, repo.root) | |
1547 | other = hg.repository(ui, source) |
|
1542 | other = hg.repository(ui, source) | |
1548 | if not other.local(): |
|
1543 | if not other.local(): | |
1549 | raise util.Abort(_("incoming doesn't work for remote repositories yet")) |
|
1544 | raise util.Abort(_("incoming doesn't work for remote repositories yet")) | |
1550 | o = repo.findincoming(other) |
|
1545 | o = repo.findincoming(other) | |
1551 | if not o: |
|
1546 | if not o: | |
1552 | return |
|
1547 | return | |
1553 | o = other.changelog.nodesbetween(o)[0] |
|
1548 | o = other.changelog.nodesbetween(o)[0] | |
1554 | if opts['newest_first']: |
|
1549 | if opts['newest_first']: | |
1555 | o.reverse() |
|
1550 | o.reverse() | |
1556 | for n in o: |
|
1551 | for n in o: | |
1557 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1552 | parents = [p for p in other.changelog.parents(n) if p != nullid] | |
1558 | if opts['no_merges'] and len(parents) == 2: |
|
1553 | if opts['no_merges'] and len(parents) == 2: | |
1559 | continue |
|
1554 | continue | |
1560 | show_changeset(ui, other, changenode=n) |
|
1555 | show_changeset(ui, other, changenode=n) | |
1561 | if opts['patch']: |
|
1556 | if opts['patch']: | |
1562 | prev = (parents and parents[0]) or nullid |
|
1557 | prev = (parents and parents[0]) or nullid | |
1563 | dodiff(ui, ui, other, prev, n) |
|
1558 | dodiff(ui, ui, other, prev, n) | |
1564 | ui.write("\n") |
|
1559 | ui.write("\n") | |
1565 |
|
1560 | |||
1566 | def init(ui, dest="."): |
|
1561 | def init(ui, dest="."): | |
1567 | """create a new repository in the given directory |
|
1562 | """create a new repository in the given directory | |
1568 |
|
1563 | |||
1569 | Initialize a new repository in the given directory. If the given |
|
1564 | Initialize a new repository in the given directory. If the given | |
1570 | directory does not exist, it is created. |
|
1565 | directory does not exist, it is created. | |
1571 |
|
1566 | |||
1572 | If no directory is given, the current directory is used. |
|
1567 | If no directory is given, the current directory is used. | |
1573 | """ |
|
1568 | """ | |
1574 | if not os.path.exists(dest): |
|
1569 | if not os.path.exists(dest): | |
1575 | os.mkdir(dest) |
|
1570 | os.mkdir(dest) | |
1576 | hg.repository(ui, dest, create=1) |
|
1571 | hg.repository(ui, dest, create=1) | |
1577 |
|
1572 | |||
1578 | def locate(ui, repo, *pats, **opts): |
|
1573 | def locate(ui, repo, *pats, **opts): | |
1579 | """locate files matching specific patterns |
|
1574 | """locate files matching specific patterns | |
1580 |
|
1575 | |||
1581 | Print all files under Mercurial control whose names match the |
|
1576 | Print all files under Mercurial control whose names match the | |
1582 | given patterns. |
|
1577 | given patterns. | |
1583 |
|
1578 | |||
1584 | This command searches the current directory and its |
|
1579 | This command searches the current directory and its | |
1585 | subdirectories. To search an entire repository, move to the root |
|
1580 | subdirectories. To search an entire repository, move to the root | |
1586 | of the repository. |
|
1581 | of the repository. | |
1587 |
|
1582 | |||
1588 | If no patterns are given to match, this command prints all file |
|
1583 | If no patterns are given to match, this command prints all file | |
1589 | names. |
|
1584 | names. | |
1590 |
|
1585 | |||
1591 | If you want to feed the output of this command into the "xargs" |
|
1586 | If you want to feed the output of this command into the "xargs" | |
1592 | command, use the "-0" option to both this command and "xargs". |
|
1587 | command, use the "-0" option to both this command and "xargs". | |
1593 | This will avoid the problem of "xargs" treating single filenames |
|
1588 | This will avoid the problem of "xargs" treating single filenames | |
1594 | that contain white space as multiple filenames. |
|
1589 | that contain white space as multiple filenames. | |
1595 | """ |
|
1590 | """ | |
1596 | end = opts['print0'] and '\0' or '\n' |
|
1591 | end = opts['print0'] and '\0' or '\n' | |
1597 | rev = opts['rev'] |
|
1592 | rev = opts['rev'] | |
1598 | if rev: |
|
1593 | if rev: | |
1599 | node = repo.lookup(rev) |
|
1594 | node = repo.lookup(rev) | |
1600 | else: |
|
1595 | else: | |
1601 | node = None |
|
1596 | node = None | |
1602 |
|
1597 | |||
1603 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
1598 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
1604 | head='(?:.*/|)'): |
|
1599 | head='(?:.*/|)'): | |
1605 | if not node and repo.dirstate.state(abs) == '?': |
|
1600 | if not node and repo.dirstate.state(abs) == '?': | |
1606 | continue |
|
1601 | continue | |
1607 | if opts['fullpath']: |
|
1602 | if opts['fullpath']: | |
1608 | ui.write(os.path.join(repo.root, abs), end) |
|
1603 | ui.write(os.path.join(repo.root, abs), end) | |
1609 | else: |
|
1604 | else: | |
1610 | ui.write(((pats and rel) or abs), end) |
|
1605 | ui.write(((pats and rel) or abs), end) | |
1611 |
|
1606 | |||
1612 | def log(ui, repo, *pats, **opts): |
|
1607 | def log(ui, repo, *pats, **opts): | |
1613 | """show revision history of entire repository or files |
|
1608 | """show revision history of entire repository or files | |
1614 |
|
1609 | |||
1615 | Print the revision history of the specified files or the entire project. |
|
1610 | Print the revision history of the specified files or the entire project. | |
1616 |
|
1611 | |||
1617 | By default this command outputs: changeset id and hash, tags, |
|
1612 | By default this command outputs: changeset id and hash, tags, | |
1618 | non-trivial parents, user, date and time, and a summary for each |
|
1613 | non-trivial parents, user, date and time, and a summary for each | |
1619 | commit. When the -v/--verbose switch is used, the list of changed |
|
1614 | commit. When the -v/--verbose switch is used, the list of changed | |
1620 | files and full commit message is shown. |
|
1615 | files and full commit message is shown. | |
1621 | """ |
|
1616 | """ | |
1622 | class dui(object): |
|
1617 | class dui(object): | |
1623 | # Implement and delegate some ui protocol. Save hunks of |
|
1618 | # Implement and delegate some ui protocol. Save hunks of | |
1624 | # output for later display in the desired order. |
|
1619 | # output for later display in the desired order. | |
1625 | def __init__(self, ui): |
|
1620 | def __init__(self, ui): | |
1626 | self.ui = ui |
|
1621 | self.ui = ui | |
1627 | self.hunk = {} |
|
1622 | self.hunk = {} | |
1628 | def bump(self, rev): |
|
1623 | def bump(self, rev): | |
1629 | self.rev = rev |
|
1624 | self.rev = rev | |
1630 | self.hunk[rev] = [] |
|
1625 | self.hunk[rev] = [] | |
1631 | def note(self, *args): |
|
1626 | def note(self, *args): | |
1632 | if self.verbose: |
|
1627 | if self.verbose: | |
1633 | self.write(*args) |
|
1628 | self.write(*args) | |
1634 | def status(self, *args): |
|
1629 | def status(self, *args): | |
1635 | if not self.quiet: |
|
1630 | if not self.quiet: | |
1636 | self.write(*args) |
|
1631 | self.write(*args) | |
1637 | def write(self, *args): |
|
1632 | def write(self, *args): | |
1638 | self.hunk[self.rev].append(args) |
|
1633 | self.hunk[self.rev].append(args) | |
1639 | def debug(self, *args): |
|
1634 | def debug(self, *args): | |
1640 | if self.debugflag: |
|
1635 | if self.debugflag: | |
1641 | self.write(*args) |
|
1636 | self.write(*args) | |
1642 | def __getattr__(self, key): |
|
1637 | def __getattr__(self, key): | |
1643 | return getattr(self.ui, key) |
|
1638 | return getattr(self.ui, key) | |
1644 |
|
1639 | |||
1645 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1640 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1646 |
|
1641 | |||
1647 | if opts['limit']: |
|
1642 | if opts['limit']: | |
1648 | try: |
|
1643 | try: | |
1649 | limit = int(opts['limit']) |
|
1644 | limit = int(opts['limit']) | |
1650 | except ValueError: |
|
1645 | except ValueError: | |
1651 | raise util.Abort(_('limit must be a positive integer')) |
|
1646 | raise util.Abort(_('limit must be a positive integer')) | |
1652 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1647 | if limit <= 0: raise util.Abort(_('limit must be positive')) | |
1653 | else: |
|
1648 | else: | |
1654 | limit = sys.maxint |
|
1649 | limit = sys.maxint | |
1655 | count = 0 |
|
1650 | count = 0 | |
1656 |
|
1651 | |||
1657 | for st, rev, fns in changeiter: |
|
1652 | for st, rev, fns in changeiter: | |
1658 | if st == 'window': |
|
1653 | if st == 'window': | |
1659 | du = dui(ui) |
|
1654 | du = dui(ui) | |
1660 | elif st == 'add': |
|
1655 | elif st == 'add': | |
1661 | du.bump(rev) |
|
1656 | du.bump(rev) | |
1662 | changenode = repo.changelog.node(rev) |
|
1657 | changenode = repo.changelog.node(rev) | |
1663 | parents = [p for p in repo.changelog.parents(changenode) |
|
1658 | parents = [p for p in repo.changelog.parents(changenode) | |
1664 | if p != nullid] |
|
1659 | if p != nullid] | |
1665 | if opts['no_merges'] and len(parents) == 2: |
|
1660 | if opts['no_merges'] and len(parents) == 2: | |
1666 | continue |
|
1661 | continue | |
1667 | if opts['only_merges'] and len(parents) != 2: |
|
1662 | if opts['only_merges'] and len(parents) != 2: | |
1668 | continue |
|
1663 | continue | |
1669 |
|
1664 | |||
1670 | if opts['keyword']: |
|
1665 | if opts['keyword']: | |
1671 | changes = getchange(rev) |
|
1666 | changes = getchange(rev) | |
1672 | miss = 0 |
|
1667 | miss = 0 | |
1673 | for k in [kw.lower() for kw in opts['keyword']]: |
|
1668 | for k in [kw.lower() for kw in opts['keyword']]: | |
1674 | if not (k in changes[1].lower() or |
|
1669 | if not (k in changes[1].lower() or | |
1675 | k in changes[4].lower() or |
|
1670 | k in changes[4].lower() or | |
1676 | k in " ".join(changes[3][:20]).lower()): |
|
1671 | k in " ".join(changes[3][:20]).lower()): | |
1677 | miss = 1 |
|
1672 | miss = 1 | |
1678 | break |
|
1673 | break | |
1679 | if miss: |
|
1674 | if miss: | |
1680 | continue |
|
1675 | continue | |
1681 |
|
1676 | |||
1682 | br = None |
|
1677 | br = None | |
1683 | if opts['branches']: |
|
1678 | if opts['branches']: | |
1684 | br = repo.branchlookup([repo.changelog.node(rev)]) |
|
1679 | br = repo.branchlookup([repo.changelog.node(rev)]) | |
1685 |
|
1680 | |||
1686 | show_changeset(du, repo, rev, brinfo=br) |
|
1681 | show_changeset(du, repo, rev, brinfo=br) | |
1687 | if opts['patch']: |
|
1682 | if opts['patch']: | |
1688 | prev = (parents and parents[0]) or nullid |
|
1683 | prev = (parents and parents[0]) or nullid | |
1689 | dodiff(du, du, repo, prev, changenode, match=matchfn) |
|
1684 | dodiff(du, du, repo, prev, changenode, match=matchfn) | |
1690 | du.write("\n\n") |
|
1685 | du.write("\n\n") | |
1691 | elif st == 'iter': |
|
1686 | elif st == 'iter': | |
1692 | if count == limit: break |
|
1687 | if count == limit: break | |
1693 | if du.hunk[rev]: |
|
1688 | if du.hunk[rev]: | |
1694 | count += 1 |
|
1689 | count += 1 | |
1695 | for args in du.hunk[rev]: |
|
1690 | for args in du.hunk[rev]: | |
1696 | ui.write(*args) |
|
1691 | ui.write(*args) | |
1697 |
|
1692 | |||
1698 | def manifest(ui, repo, rev=None): |
|
1693 | def manifest(ui, repo, rev=None): | |
1699 | """output the latest or given revision of the project manifest |
|
1694 | """output the latest or given revision of the project manifest | |
1700 |
|
1695 | |||
1701 | Print a list of version controlled files for the given revision. |
|
1696 | Print a list of version controlled files for the given revision. | |
1702 |
|
1697 | |||
1703 | The manifest is the list of files being version controlled. If no revision |
|
1698 | The manifest is the list of files being version controlled. If no revision | |
1704 | is given then the tip is used. |
|
1699 | is given then the tip is used. | |
1705 | """ |
|
1700 | """ | |
1706 | if rev: |
|
1701 | if rev: | |
1707 | try: |
|
1702 | try: | |
1708 | # assume all revision numbers are for changesets |
|
1703 | # assume all revision numbers are for changesets | |
1709 | n = repo.lookup(rev) |
|
1704 | n = repo.lookup(rev) | |
1710 | change = repo.changelog.read(n) |
|
1705 | change = repo.changelog.read(n) | |
1711 | n = change[0] |
|
1706 | n = change[0] | |
1712 | except hg.RepoError: |
|
1707 | except hg.RepoError: | |
1713 | n = repo.manifest.lookup(rev) |
|
1708 | n = repo.manifest.lookup(rev) | |
1714 | else: |
|
1709 | else: | |
1715 | n = repo.manifest.tip() |
|
1710 | n = repo.manifest.tip() | |
1716 | m = repo.manifest.read(n) |
|
1711 | m = repo.manifest.read(n) | |
1717 | mf = repo.manifest.readflags(n) |
|
1712 | mf = repo.manifest.readflags(n) | |
1718 | files = m.keys() |
|
1713 | files = m.keys() | |
1719 | files.sort() |
|
1714 | files.sort() | |
1720 |
|
1715 | |||
1721 | for f in files: |
|
1716 | for f in files: | |
1722 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) |
|
1717 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) | |
1723 |
|
1718 | |||
1724 | def outgoing(ui, repo, dest="default-push", **opts): |
|
1719 | def outgoing(ui, repo, dest="default-push", **opts): | |
1725 | """show changesets not found in destination |
|
1720 | """show changesets not found in destination | |
1726 |
|
1721 | |||
1727 | Show changesets not found in the specified destination repo or the |
|
1722 | Show changesets not found in the specified destination repo or the | |
1728 | default push repo. These are the changesets that would be pushed |
|
1723 | default push repo. These are the changesets that would be pushed | |
1729 | if a push was requested. |
|
1724 | if a push was requested. | |
1730 |
|
1725 | |||
1731 | See pull for valid source format details. |
|
1726 | See pull for valid source format details. | |
1732 | """ |
|
1727 | """ | |
1733 | dest = ui.expandpath(dest, repo.root) |
|
1728 | dest = ui.expandpath(dest, repo.root) | |
1734 | other = hg.repository(ui, dest) |
|
1729 | other = hg.repository(ui, dest) | |
1735 | o = repo.findoutgoing(other) |
|
1730 | o = repo.findoutgoing(other) | |
1736 | o = repo.changelog.nodesbetween(o)[0] |
|
1731 | o = repo.changelog.nodesbetween(o)[0] | |
1737 | if opts['newest_first']: |
|
1732 | if opts['newest_first']: | |
1738 | o.reverse() |
|
1733 | o.reverse() | |
1739 | for n in o: |
|
1734 | for n in o: | |
1740 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
1735 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | |
1741 | if opts['no_merges'] and len(parents) == 2: |
|
1736 | if opts['no_merges'] and len(parents) == 2: | |
1742 | continue |
|
1737 | continue | |
1743 | show_changeset(ui, repo, changenode=n) |
|
1738 | show_changeset(ui, repo, changenode=n) | |
1744 | if opts['patch']: |
|
1739 | if opts['patch']: | |
1745 | prev = (parents and parents[0]) or nullid |
|
1740 | prev = (parents and parents[0]) or nullid | |
1746 | dodiff(ui, ui, repo, prev, n) |
|
1741 | dodiff(ui, ui, repo, prev, n) | |
1747 | ui.write("\n") |
|
1742 | ui.write("\n") | |
1748 |
|
1743 | |||
1749 | def parents(ui, repo, rev=None, branches=None): |
|
1744 | def parents(ui, repo, rev=None, branches=None): | |
1750 | """show the parents of the working dir or revision |
|
1745 | """show the parents of the working dir or revision | |
1751 |
|
1746 | |||
1752 | Print the working directory's parent revisions. |
|
1747 | Print the working directory's parent revisions. | |
1753 | """ |
|
1748 | """ | |
1754 | if rev: |
|
1749 | if rev: | |
1755 | p = repo.changelog.parents(repo.lookup(rev)) |
|
1750 | p = repo.changelog.parents(repo.lookup(rev)) | |
1756 | else: |
|
1751 | else: | |
1757 | p = repo.dirstate.parents() |
|
1752 | p = repo.dirstate.parents() | |
1758 |
|
1753 | |||
1759 | br = None |
|
1754 | br = None | |
1760 | if branches is not None: |
|
1755 | if branches is not None: | |
1761 | br = repo.branchlookup(p) |
|
1756 | br = repo.branchlookup(p) | |
1762 | for n in p: |
|
1757 | for n in p: | |
1763 | if n != nullid: |
|
1758 | if n != nullid: | |
1764 | show_changeset(ui, repo, changenode=n, brinfo=br) |
|
1759 | show_changeset(ui, repo, changenode=n, brinfo=br) | |
1765 |
|
1760 | |||
1766 | def paths(ui, search=None): |
|
1761 | def paths(ui, repo, search=None): | |
1767 | """show definition of symbolic path names |
|
1762 | """show definition of symbolic path names | |
1768 |
|
1763 | |||
1769 | Show definition of symbolic path name NAME. If no name is given, show |
|
1764 | Show definition of symbolic path name NAME. If no name is given, show | |
1770 | definition of available names. |
|
1765 | definition of available names. | |
1771 |
|
1766 | |||
1772 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
1767 | Path names are defined in the [paths] section of /etc/mercurial/hgrc | |
1773 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
1768 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. | |
1774 | """ |
|
1769 | """ | |
1775 | try: |
|
|||
1776 | repo = hg.repository(ui) |
|
|||
1777 | ui = repo.ui |
|
|||
1778 | except hg.RepoError: |
|
|||
1779 | pass |
|
|||
1780 |
|
||||
1781 | if search: |
|
1770 | if search: | |
1782 | for name, path in ui.configitems("paths"): |
|
1771 | for name, path in ui.configitems("paths"): | |
1783 | if name == search: |
|
1772 | if name == search: | |
1784 | ui.write("%s\n" % path) |
|
1773 | ui.write("%s\n" % path) | |
1785 | return |
|
1774 | return | |
1786 | ui.warn(_("not found!\n")) |
|
1775 | ui.warn(_("not found!\n")) | |
1787 | return 1 |
|
1776 | return 1 | |
1788 | else: |
|
1777 | else: | |
1789 | for name, path in ui.configitems("paths"): |
|
1778 | for name, path in ui.configitems("paths"): | |
1790 | ui.write("%s = %s\n" % (name, path)) |
|
1779 | ui.write("%s = %s\n" % (name, path)) | |
1791 |
|
1780 | |||
1792 | def pull(ui, repo, source="default", **opts): |
|
1781 | def pull(ui, repo, source="default", **opts): | |
1793 | """pull changes from the specified source |
|
1782 | """pull changes from the specified source | |
1794 |
|
1783 | |||
1795 | Pull changes from a remote repository to a local one. |
|
1784 | Pull changes from a remote repository to a local one. | |
1796 |
|
1785 | |||
1797 | This finds all changes from the repository at the specified path |
|
1786 | This finds all changes from the repository at the specified path | |
1798 | or URL and adds them to the local repository. By default, this |
|
1787 | or URL and adds them to the local repository. By default, this | |
1799 | does not update the copy of the project in the working directory. |
|
1788 | does not update the copy of the project in the working directory. | |
1800 |
|
1789 | |||
1801 | Valid URLs are of the form: |
|
1790 | Valid URLs are of the form: | |
1802 |
|
1791 | |||
1803 | local/filesystem/path |
|
1792 | local/filesystem/path | |
1804 | http://[user@]host[:port][/path] |
|
1793 | http://[user@]host[:port][/path] | |
1805 | https://[user@]host[:port][/path] |
|
1794 | https://[user@]host[:port][/path] | |
1806 | ssh://[user@]host[:port][/path] |
|
1795 | ssh://[user@]host[:port][/path] | |
1807 |
|
1796 | |||
1808 | SSH requires an accessible shell account on the destination machine |
|
1797 | SSH requires an accessible shell account on the destination machine | |
1809 | and a copy of hg in the remote path. With SSH, paths are relative |
|
1798 | and a copy of hg in the remote path. With SSH, paths are relative | |
1810 | to the remote user's home directory by default; use two slashes at |
|
1799 | to the remote user's home directory by default; use two slashes at | |
1811 | the start of a path to specify it as relative to the filesystem root. |
|
1800 | the start of a path to specify it as relative to the filesystem root. | |
1812 | """ |
|
1801 | """ | |
1813 | source = ui.expandpath(source, repo.root) |
|
1802 | source = ui.expandpath(source, repo.root) | |
1814 | ui.status(_('pulling from %s\n') % (source)) |
|
1803 | ui.status(_('pulling from %s\n') % (source)) | |
1815 |
|
1804 | |||
1816 | if opts['ssh']: |
|
1805 | if opts['ssh']: | |
1817 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
1806 | ui.setconfig("ui", "ssh", opts['ssh']) | |
1818 | if opts['remotecmd']: |
|
1807 | if opts['remotecmd']: | |
1819 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
1808 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
1820 |
|
1809 | |||
1821 | other = hg.repository(ui, source) |
|
1810 | other = hg.repository(ui, source) | |
1822 | revs = None |
|
1811 | revs = None | |
1823 | if opts['rev'] and not other.local(): |
|
1812 | if opts['rev'] and not other.local(): | |
1824 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) |
|
1813 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) | |
1825 | elif opts['rev']: |
|
1814 | elif opts['rev']: | |
1826 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
1815 | revs = [other.lookup(rev) for rev in opts['rev']] | |
1827 | r = repo.pull(other, heads=revs) |
|
1816 | r = repo.pull(other, heads=revs) | |
1828 | if not r: |
|
1817 | if not r: | |
1829 | if opts['update']: |
|
1818 | if opts['update']: | |
1830 | return update(ui, repo) |
|
1819 | return update(ui, repo) | |
1831 | else: |
|
1820 | else: | |
1832 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
1821 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
1833 |
|
1822 | |||
1834 | return r |
|
1823 | return r | |
1835 |
|
1824 | |||
1836 | def push(ui, repo, dest="default-push", **opts): |
|
1825 | def push(ui, repo, dest="default-push", **opts): | |
1837 | """push changes to the specified destination |
|
1826 | """push changes to the specified destination | |
1838 |
|
1827 | |||
1839 | Push changes from the local repository to the given destination. |
|
1828 | Push changes from the local repository to the given destination. | |
1840 |
|
1829 | |||
1841 | This is the symmetrical operation for pull. It helps to move |
|
1830 | This is the symmetrical operation for pull. It helps to move | |
1842 | changes from the current repository to a different one. If the |
|
1831 | changes from the current repository to a different one. If the | |
1843 | destination is local this is identical to a pull in that directory |
|
1832 | destination is local this is identical to a pull in that directory | |
1844 | from the current one. |
|
1833 | from the current one. | |
1845 |
|
1834 | |||
1846 | By default, push will refuse to run if it detects the result would |
|
1835 | By default, push will refuse to run if it detects the result would | |
1847 | increase the number of remote heads. This generally indicates the |
|
1836 | increase the number of remote heads. This generally indicates the | |
1848 | the client has forgotten to sync and merge before pushing. |
|
1837 | the client has forgotten to sync and merge before pushing. | |
1849 |
|
1838 | |||
1850 | Valid URLs are of the form: |
|
1839 | Valid URLs are of the form: | |
1851 |
|
1840 | |||
1852 | local/filesystem/path |
|
1841 | local/filesystem/path | |
1853 | ssh://[user@]host[:port][/path] |
|
1842 | ssh://[user@]host[:port][/path] | |
1854 |
|
1843 | |||
1855 | SSH requires an accessible shell account on the destination |
|
1844 | SSH requires an accessible shell account on the destination | |
1856 | machine and a copy of hg in the remote path. |
|
1845 | machine and a copy of hg in the remote path. | |
1857 | """ |
|
1846 | """ | |
1858 | dest = ui.expandpath(dest, repo.root) |
|
1847 | dest = ui.expandpath(dest, repo.root) | |
1859 | ui.status('pushing to %s\n' % (dest)) |
|
1848 | ui.status('pushing to %s\n' % (dest)) | |
1860 |
|
1849 | |||
1861 | if opts['ssh']: |
|
1850 | if opts['ssh']: | |
1862 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
1851 | ui.setconfig("ui", "ssh", opts['ssh']) | |
1863 | if opts['remotecmd']: |
|
1852 | if opts['remotecmd']: | |
1864 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
1853 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
1865 |
|
1854 | |||
1866 | other = hg.repository(ui, dest) |
|
1855 | other = hg.repository(ui, dest) | |
1867 | revs = None |
|
1856 | revs = None | |
1868 | if opts['rev']: |
|
1857 | if opts['rev']: | |
1869 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
1858 | revs = [repo.lookup(rev) for rev in opts['rev']] | |
1870 | r = repo.push(other, opts['force'], revs=revs) |
|
1859 | r = repo.push(other, opts['force'], revs=revs) | |
1871 | return r |
|
1860 | return r | |
1872 |
|
1861 | |||
1873 | def rawcommit(ui, repo, *flist, **rc): |
|
1862 | def rawcommit(ui, repo, *flist, **rc): | |
1874 | """raw commit interface (DEPRECATED) |
|
1863 | """raw commit interface (DEPRECATED) | |
1875 |
|
1864 | |||
1876 | (DEPRECATED) |
|
1865 | (DEPRECATED) | |
1877 | Lowlevel commit, for use in helper scripts. |
|
1866 | Lowlevel commit, for use in helper scripts. | |
1878 |
|
1867 | |||
1879 | This command is not intended to be used by normal users, as it is |
|
1868 | This command is not intended to be used by normal users, as it is | |
1880 | primarily useful for importing from other SCMs. |
|
1869 | primarily useful for importing from other SCMs. | |
1881 |
|
1870 | |||
1882 | This command is now deprecated and will be removed in a future |
|
1871 | This command is now deprecated and will be removed in a future | |
1883 | release, please use debugsetparents and commit instead. |
|
1872 | release, please use debugsetparents and commit instead. | |
1884 | """ |
|
1873 | """ | |
1885 |
|
1874 | |||
1886 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
1875 | ui.warn(_("(the rawcommit command is deprecated)\n")) | |
1887 |
|
1876 | |||
1888 | message = rc['message'] |
|
1877 | message = rc['message'] | |
1889 | if not message and rc['logfile']: |
|
1878 | if not message and rc['logfile']: | |
1890 | try: |
|
1879 | try: | |
1891 | message = open(rc['logfile']).read() |
|
1880 | message = open(rc['logfile']).read() | |
1892 | except IOError: |
|
1881 | except IOError: | |
1893 | pass |
|
1882 | pass | |
1894 | if not message and not rc['logfile']: |
|
1883 | if not message and not rc['logfile']: | |
1895 | raise util.Abort(_("missing commit message")) |
|
1884 | raise util.Abort(_("missing commit message")) | |
1896 |
|
1885 | |||
1897 | files = relpath(repo, list(flist)) |
|
1886 | files = relpath(repo, list(flist)) | |
1898 | if rc['files']: |
|
1887 | if rc['files']: | |
1899 | files += open(rc['files']).read().splitlines() |
|
1888 | files += open(rc['files']).read().splitlines() | |
1900 |
|
1889 | |||
1901 | rc['parent'] = map(repo.lookup, rc['parent']) |
|
1890 | rc['parent'] = map(repo.lookup, rc['parent']) | |
1902 |
|
1891 | |||
1903 | try: |
|
1892 | try: | |
1904 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) |
|
1893 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) | |
1905 | except ValueError, inst: |
|
1894 | except ValueError, inst: | |
1906 | raise util.Abort(str(inst)) |
|
1895 | raise util.Abort(str(inst)) | |
1907 |
|
1896 | |||
1908 | def recover(ui, repo): |
|
1897 | def recover(ui, repo): | |
1909 | """roll back an interrupted transaction |
|
1898 | """roll back an interrupted transaction | |
1910 |
|
1899 | |||
1911 | Recover from an interrupted commit or pull. |
|
1900 | Recover from an interrupted commit or pull. | |
1912 |
|
1901 | |||
1913 | This command tries to fix the repository status after an interrupted |
|
1902 | This command tries to fix the repository status after an interrupted | |
1914 | operation. It should only be necessary when Mercurial suggests it. |
|
1903 | operation. It should only be necessary when Mercurial suggests it. | |
1915 | """ |
|
1904 | """ | |
1916 | if repo.recover(): |
|
1905 | if repo.recover(): | |
1917 | return repo.verify() |
|
1906 | return repo.verify() | |
1918 | return False |
|
1907 | return False | |
1919 |
|
1908 | |||
1920 | def remove(ui, repo, pat, *pats, **opts): |
|
1909 | def remove(ui, repo, pat, *pats, **opts): | |
1921 | """remove the specified files on the next commit |
|
1910 | """remove the specified files on the next commit | |
1922 |
|
1911 | |||
1923 | Schedule the indicated files for removal from the repository. |
|
1912 | Schedule the indicated files for removal from the repository. | |
1924 |
|
1913 | |||
1925 | This command schedules the files to be removed at the next commit. |
|
1914 | This command schedules the files to be removed at the next commit. | |
1926 | This only removes files from the current branch, not from the |
|
1915 | This only removes files from the current branch, not from the | |
1927 | entire project history. If the files still exist in the working |
|
1916 | entire project history. If the files still exist in the working | |
1928 | directory, they will be deleted from it. |
|
1917 | directory, they will be deleted from it. | |
1929 | """ |
|
1918 | """ | |
1930 | names = [] |
|
1919 | names = [] | |
1931 | def okaytoremove(abs, rel, exact): |
|
1920 | def okaytoremove(abs, rel, exact): | |
1932 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) |
|
1921 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) | |
1933 | reason = None |
|
1922 | reason = None | |
1934 | if modified: |
|
1923 | if modified: | |
1935 | reason = _('is modified') |
|
1924 | reason = _('is modified') | |
1936 | elif added: |
|
1925 | elif added: | |
1937 | reason = _('has been marked for add') |
|
1926 | reason = _('has been marked for add') | |
1938 | elif unknown: |
|
1927 | elif unknown: | |
1939 | reason = _('is not managed') |
|
1928 | reason = _('is not managed') | |
1940 | if reason: |
|
1929 | if reason: | |
1941 | if exact: |
|
1930 | if exact: | |
1942 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
1931 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | |
1943 | else: |
|
1932 | else: | |
1944 | return True |
|
1933 | return True | |
1945 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): |
|
1934 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): | |
1946 | if okaytoremove(abs, rel, exact): |
|
1935 | if okaytoremove(abs, rel, exact): | |
1947 | if ui.verbose or not exact: |
|
1936 | if ui.verbose or not exact: | |
1948 | ui.status(_('removing %s\n') % rel) |
|
1937 | ui.status(_('removing %s\n') % rel) | |
1949 | names.append(abs) |
|
1938 | names.append(abs) | |
1950 | repo.remove(names, unlink=True) |
|
1939 | repo.remove(names, unlink=True) | |
1951 |
|
1940 | |||
1952 | def rename(ui, repo, *pats, **opts): |
|
1941 | def rename(ui, repo, *pats, **opts): | |
1953 | """rename files; equivalent of copy + remove |
|
1942 | """rename files; equivalent of copy + remove | |
1954 |
|
1943 | |||
1955 | Mark dest as copies of sources; mark sources for deletion. If |
|
1944 | Mark dest as copies of sources; mark sources for deletion. If | |
1956 | dest is a directory, copies are put in that directory. If dest is |
|
1945 | dest is a directory, copies are put in that directory. If dest is | |
1957 | a file, there can only be one source. |
|
1946 | a file, there can only be one source. | |
1958 |
|
1947 | |||
1959 | By default, this command copies the contents of files as they |
|
1948 | By default, this command copies the contents of files as they | |
1960 | stand in the working directory. If invoked with --after, the |
|
1949 | stand in the working directory. If invoked with --after, the | |
1961 | operation is recorded, but no copying is performed. |
|
1950 | operation is recorded, but no copying is performed. | |
1962 |
|
1951 | |||
1963 | This command takes effect in the next commit. |
|
1952 | This command takes effect in the next commit. | |
1964 |
|
1953 | |||
1965 | NOTE: This command should be treated as experimental. While it |
|
1954 | NOTE: This command should be treated as experimental. While it | |
1966 | should properly record rename files, this information is not yet |
|
1955 | should properly record rename files, this information is not yet | |
1967 | fully used by merge, nor fully reported by log. |
|
1956 | fully used by merge, nor fully reported by log. | |
1968 | """ |
|
1957 | """ | |
1969 | try: |
|
1958 | try: | |
1970 | wlock = repo.wlock(0) |
|
1959 | wlock = repo.wlock(0) | |
1971 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1960 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
1972 | names = [] |
|
1961 | names = [] | |
1973 | for abs, rel, exact in copied: |
|
1962 | for abs, rel, exact in copied: | |
1974 | if ui.verbose or not exact: |
|
1963 | if ui.verbose or not exact: | |
1975 | ui.status(_('removing %s\n') % rel) |
|
1964 | ui.status(_('removing %s\n') % rel) | |
1976 | names.append(abs) |
|
1965 | names.append(abs) | |
1977 | repo.remove(names, True, wlock) |
|
1966 | repo.remove(names, True, wlock) | |
1978 | except lock.LockHeld, inst: |
|
1967 | except lock.LockHeld, inst: | |
1979 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) |
|
1968 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) | |
1980 | errs = 1 |
|
1969 | errs = 1 | |
1981 | return errs |
|
1970 | return errs | |
1982 |
|
1971 | |||
1983 | def revert(ui, repo, *pats, **opts): |
|
1972 | def revert(ui, repo, *pats, **opts): | |
1984 | """revert modified files or dirs back to their unmodified states |
|
1973 | """revert modified files or dirs back to their unmodified states | |
1985 |
|
1974 | |||
1986 | In its default mode, it reverts any uncommitted modifications made |
|
1975 | In its default mode, it reverts any uncommitted modifications made | |
1987 | to the named files or directories. This restores the contents of |
|
1976 | to the named files or directories. This restores the contents of | |
1988 | the affected files to an unmodified state. |
|
1977 | the affected files to an unmodified state. | |
1989 |
|
1978 | |||
1990 | Using the -r option, it reverts the given files or directories to |
|
1979 | Using the -r option, it reverts the given files or directories to | |
1991 | their state as of an earlier revision. This can be helpful to "roll |
|
1980 | their state as of an earlier revision. This can be helpful to "roll | |
1992 | back" some or all of a change that should not have been committed. |
|
1981 | back" some or all of a change that should not have been committed. | |
1993 |
|
1982 | |||
1994 | Revert modifies the working directory. It does not commit any |
|
1983 | Revert modifies the working directory. It does not commit any | |
1995 | changes, or change the parent of the current working directory. |
|
1984 | changes, or change the parent of the current working directory. | |
1996 |
|
1985 | |||
1997 | If a file has been deleted, it is recreated. If the executable |
|
1986 | If a file has been deleted, it is recreated. If the executable | |
1998 | mode of a file was changed, it is reset. |
|
1987 | mode of a file was changed, it is reset. | |
1999 |
|
1988 | |||
2000 | If names are given, all files matching the names are reverted. |
|
1989 | If names are given, all files matching the names are reverted. | |
2001 |
|
1990 | |||
2002 | If no arguments are given, all files in the repository are reverted. |
|
1991 | If no arguments are given, all files in the repository are reverted. | |
2003 | """ |
|
1992 | """ | |
2004 | node = opts['rev'] and repo.lookup(opts['rev']) or \ |
|
1993 | node = opts['rev'] and repo.lookup(opts['rev']) or \ | |
2005 | repo.dirstate.parents()[0] |
|
1994 | repo.dirstate.parents()[0] | |
2006 |
|
1995 | |||
2007 | files, choose, anypats = matchpats(repo, pats, opts) |
|
1996 | files, choose, anypats = matchpats(repo, pats, opts) | |
2008 | modified, added, removed, deleted, unknown = repo.changes(match=choose) |
|
1997 | modified, added, removed, deleted, unknown = repo.changes(match=choose) | |
2009 | repo.forget(added) |
|
1998 | repo.forget(added) | |
2010 | repo.undelete(removed) |
|
1999 | repo.undelete(removed) | |
2011 |
|
2000 | |||
2012 | return repo.update(node, False, True, choose, False) |
|
2001 | return repo.update(node, False, True, choose, False) | |
2013 |
|
2002 | |||
2014 | def root(ui, repo): |
|
2003 | def root(ui, repo): | |
2015 | """print the root (top) of the current working dir |
|
2004 | """print the root (top) of the current working dir | |
2016 |
|
2005 | |||
2017 | Print the root directory of the current repository. |
|
2006 | Print the root directory of the current repository. | |
2018 | """ |
|
2007 | """ | |
2019 | ui.write(repo.root + "\n") |
|
2008 | ui.write(repo.root + "\n") | |
2020 |
|
2009 | |||
2021 | def serve(ui, repo, **opts): |
|
2010 | def serve(ui, repo, **opts): | |
2022 | """export the repository via HTTP |
|
2011 | """export the repository via HTTP | |
2023 |
|
2012 | |||
2024 | Start a local HTTP repository browser and pull server. |
|
2013 | Start a local HTTP repository browser and pull server. | |
2025 |
|
2014 | |||
2026 | By default, the server logs accesses to stdout and errors to |
|
2015 | By default, the server logs accesses to stdout and errors to | |
2027 | stderr. Use the "-A" and "-E" options to log to files. |
|
2016 | stderr. Use the "-A" and "-E" options to log to files. | |
2028 | """ |
|
2017 | """ | |
2029 |
|
2018 | |||
2030 | if opts["stdio"]: |
|
2019 | if opts["stdio"]: | |
2031 | fin, fout = sys.stdin, sys.stdout |
|
2020 | fin, fout = sys.stdin, sys.stdout | |
2032 | sys.stdout = sys.stderr |
|
2021 | sys.stdout = sys.stderr | |
2033 |
|
2022 | |||
2034 | # Prevent insertion/deletion of CRs |
|
2023 | # Prevent insertion/deletion of CRs | |
2035 | util.set_binary(fin) |
|
2024 | util.set_binary(fin) | |
2036 | util.set_binary(fout) |
|
2025 | util.set_binary(fout) | |
2037 |
|
2026 | |||
2038 | def getarg(): |
|
2027 | def getarg(): | |
2039 | argline = fin.readline()[:-1] |
|
2028 | argline = fin.readline()[:-1] | |
2040 | arg, l = argline.split() |
|
2029 | arg, l = argline.split() | |
2041 | val = fin.read(int(l)) |
|
2030 | val = fin.read(int(l)) | |
2042 | return arg, val |
|
2031 | return arg, val | |
2043 | def respond(v): |
|
2032 | def respond(v): | |
2044 | fout.write("%d\n" % len(v)) |
|
2033 | fout.write("%d\n" % len(v)) | |
2045 | fout.write(v) |
|
2034 | fout.write(v) | |
2046 | fout.flush() |
|
2035 | fout.flush() | |
2047 |
|
2036 | |||
2048 | lock = None |
|
2037 | lock = None | |
2049 |
|
2038 | |||
2050 | while 1: |
|
2039 | while 1: | |
2051 | cmd = fin.readline()[:-1] |
|
2040 | cmd = fin.readline()[:-1] | |
2052 | if cmd == '': |
|
2041 | if cmd == '': | |
2053 | return |
|
2042 | return | |
2054 | if cmd == "heads": |
|
2043 | if cmd == "heads": | |
2055 | h = repo.heads() |
|
2044 | h = repo.heads() | |
2056 | respond(" ".join(map(hex, h)) + "\n") |
|
2045 | respond(" ".join(map(hex, h)) + "\n") | |
2057 | if cmd == "lock": |
|
2046 | if cmd == "lock": | |
2058 | lock = repo.lock() |
|
2047 | lock = repo.lock() | |
2059 | respond("") |
|
2048 | respond("") | |
2060 | if cmd == "unlock": |
|
2049 | if cmd == "unlock": | |
2061 | if lock: |
|
2050 | if lock: | |
2062 | lock.release() |
|
2051 | lock.release() | |
2063 | lock = None |
|
2052 | lock = None | |
2064 | respond("") |
|
2053 | respond("") | |
2065 | elif cmd == "branches": |
|
2054 | elif cmd == "branches": | |
2066 | arg, nodes = getarg() |
|
2055 | arg, nodes = getarg() | |
2067 | nodes = map(bin, nodes.split(" ")) |
|
2056 | nodes = map(bin, nodes.split(" ")) | |
2068 | r = [] |
|
2057 | r = [] | |
2069 | for b in repo.branches(nodes): |
|
2058 | for b in repo.branches(nodes): | |
2070 | r.append(" ".join(map(hex, b)) + "\n") |
|
2059 | r.append(" ".join(map(hex, b)) + "\n") | |
2071 | respond("".join(r)) |
|
2060 | respond("".join(r)) | |
2072 | elif cmd == "between": |
|
2061 | elif cmd == "between": | |
2073 | arg, pairs = getarg() |
|
2062 | arg, pairs = getarg() | |
2074 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
2063 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | |
2075 | r = [] |
|
2064 | r = [] | |
2076 | for b in repo.between(pairs): |
|
2065 | for b in repo.between(pairs): | |
2077 | r.append(" ".join(map(hex, b)) + "\n") |
|
2066 | r.append(" ".join(map(hex, b)) + "\n") | |
2078 | respond("".join(r)) |
|
2067 | respond("".join(r)) | |
2079 | elif cmd == "changegroup": |
|
2068 | elif cmd == "changegroup": | |
2080 | nodes = [] |
|
2069 | nodes = [] | |
2081 | arg, roots = getarg() |
|
2070 | arg, roots = getarg() | |
2082 | nodes = map(bin, roots.split(" ")) |
|
2071 | nodes = map(bin, roots.split(" ")) | |
2083 |
|
2072 | |||
2084 | cg = repo.changegroup(nodes, 'serve') |
|
2073 | cg = repo.changegroup(nodes, 'serve') | |
2085 | while 1: |
|
2074 | while 1: | |
2086 | d = cg.read(4096) |
|
2075 | d = cg.read(4096) | |
2087 | if not d: |
|
2076 | if not d: | |
2088 | break |
|
2077 | break | |
2089 | fout.write(d) |
|
2078 | fout.write(d) | |
2090 |
|
2079 | |||
2091 | fout.flush() |
|
2080 | fout.flush() | |
2092 |
|
2081 | |||
2093 | elif cmd == "addchangegroup": |
|
2082 | elif cmd == "addchangegroup": | |
2094 | if not lock: |
|
2083 | if not lock: | |
2095 | respond("not locked") |
|
2084 | respond("not locked") | |
2096 | continue |
|
2085 | continue | |
2097 | respond("") |
|
2086 | respond("") | |
2098 |
|
2087 | |||
2099 | r = repo.addchangegroup(fin) |
|
2088 | r = repo.addchangegroup(fin) | |
2100 | respond("") |
|
2089 | respond("") | |
2101 |
|
2090 | |||
2102 | optlist = "name templates style address port ipv6 accesslog errorlog" |
|
2091 | optlist = "name templates style address port ipv6 accesslog errorlog" | |
2103 | for o in optlist.split(): |
|
2092 | for o in optlist.split(): | |
2104 | if opts[o]: |
|
2093 | if opts[o]: | |
2105 | ui.setconfig("web", o, opts[o]) |
|
2094 | ui.setconfig("web", o, opts[o]) | |
2106 |
|
2095 | |||
2107 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2096 | if opts['daemon'] and not opts['daemon_pipefds']: | |
2108 | rfd, wfd = os.pipe() |
|
2097 | rfd, wfd = os.pipe() | |
2109 | args = sys.argv[:] |
|
2098 | args = sys.argv[:] | |
2110 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2099 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | |
2111 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2100 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | |
2112 | args[0], args) |
|
2101 | args[0], args) | |
2113 | os.close(wfd) |
|
2102 | os.close(wfd) | |
2114 | os.read(rfd, 1) |
|
2103 | os.read(rfd, 1) | |
2115 | os._exit(0) |
|
2104 | os._exit(0) | |
2116 |
|
2105 | |||
2117 | try: |
|
2106 | try: | |
2118 | httpd = hgweb.create_server(repo) |
|
2107 | httpd = hgweb.create_server(repo) | |
2119 | except socket.error, inst: |
|
2108 | except socket.error, inst: | |
2120 | raise util.Abort(_('cannot start server: ') + inst.args[1]) |
|
2109 | raise util.Abort(_('cannot start server: ') + inst.args[1]) | |
2121 |
|
2110 | |||
2122 | if ui.verbose: |
|
2111 | if ui.verbose: | |
2123 | addr, port = httpd.socket.getsockname() |
|
2112 | addr, port = httpd.socket.getsockname() | |
2124 | if addr == '0.0.0.0': |
|
2113 | if addr == '0.0.0.0': | |
2125 | addr = socket.gethostname() |
|
2114 | addr = socket.gethostname() | |
2126 | else: |
|
2115 | else: | |
2127 | try: |
|
2116 | try: | |
2128 | addr = socket.gethostbyaddr(addr)[0] |
|
2117 | addr = socket.gethostbyaddr(addr)[0] | |
2129 | except socket.error: |
|
2118 | except socket.error: | |
2130 | pass |
|
2119 | pass | |
2131 | if port != 80: |
|
2120 | if port != 80: | |
2132 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) |
|
2121 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) | |
2133 | else: |
|
2122 | else: | |
2134 | ui.status(_('listening at http://%s/\n') % addr) |
|
2123 | ui.status(_('listening at http://%s/\n') % addr) | |
2135 |
|
2124 | |||
2136 | if opts['pid_file']: |
|
2125 | if opts['pid_file']: | |
2137 | fp = open(opts['pid_file'], 'w') |
|
2126 | fp = open(opts['pid_file'], 'w') | |
2138 | fp.write(str(os.getpid())) |
|
2127 | fp.write(str(os.getpid())) | |
2139 | fp.close() |
|
2128 | fp.close() | |
2140 |
|
2129 | |||
2141 | if opts['daemon_pipefds']: |
|
2130 | if opts['daemon_pipefds']: | |
2142 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2131 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | |
2143 | os.close(rfd) |
|
2132 | os.close(rfd) | |
2144 | os.write(wfd, 'y') |
|
2133 | os.write(wfd, 'y') | |
2145 | os.close(wfd) |
|
2134 | os.close(wfd) | |
2146 | sys.stdout.flush() |
|
2135 | sys.stdout.flush() | |
2147 | sys.stderr.flush() |
|
2136 | sys.stderr.flush() | |
2148 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2137 | fd = os.open(util.nulldev, os.O_RDWR) | |
2149 | if fd != 0: os.dup2(fd, 0) |
|
2138 | if fd != 0: os.dup2(fd, 0) | |
2150 | if fd != 1: os.dup2(fd, 1) |
|
2139 | if fd != 1: os.dup2(fd, 1) | |
2151 | if fd != 2: os.dup2(fd, 2) |
|
2140 | if fd != 2: os.dup2(fd, 2) | |
2152 | if fd not in (0, 1, 2): os.close(fd) |
|
2141 | if fd not in (0, 1, 2): os.close(fd) | |
2153 |
|
2142 | |||
2154 | httpd.serve_forever() |
|
2143 | httpd.serve_forever() | |
2155 |
|
2144 | |||
2156 | def status(ui, repo, *pats, **opts): |
|
2145 | def status(ui, repo, *pats, **opts): | |
2157 | """show changed files in the working directory |
|
2146 | """show changed files in the working directory | |
2158 |
|
2147 | |||
2159 | Show changed files in the repository. If names are |
|
2148 | Show changed files in the repository. If names are | |
2160 | given, only files that match are shown. |
|
2149 | given, only files that match are shown. | |
2161 |
|
2150 | |||
2162 | The codes used to show the status of files are: |
|
2151 | The codes used to show the status of files are: | |
2163 | M = modified |
|
2152 | M = modified | |
2164 | A = added |
|
2153 | A = added | |
2165 | R = removed |
|
2154 | R = removed | |
2166 | ! = deleted, but still tracked |
|
2155 | ! = deleted, but still tracked | |
2167 | ? = not tracked |
|
2156 | ? = not tracked | |
2168 | """ |
|
2157 | """ | |
2169 |
|
2158 | |||
2170 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
2159 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
2171 | cwd = (pats and repo.getcwd()) or '' |
|
2160 | cwd = (pats and repo.getcwd()) or '' | |
2172 | modified, added, removed, deleted, unknown = [ |
|
2161 | modified, added, removed, deleted, unknown = [ | |
2173 | [util.pathto(cwd, x) for x in n] |
|
2162 | [util.pathto(cwd, x) for x in n] | |
2174 | for n in repo.changes(files=files, match=matchfn)] |
|
2163 | for n in repo.changes(files=files, match=matchfn)] | |
2175 |
|
2164 | |||
2176 | changetypes = [(_('modified'), 'M', modified), |
|
2165 | changetypes = [(_('modified'), 'M', modified), | |
2177 | (_('added'), 'A', added), |
|
2166 | (_('added'), 'A', added), | |
2178 | (_('removed'), 'R', removed), |
|
2167 | (_('removed'), 'R', removed), | |
2179 | (_('deleted'), '!', deleted), |
|
2168 | (_('deleted'), '!', deleted), | |
2180 | (_('unknown'), '?', unknown)] |
|
2169 | (_('unknown'), '?', unknown)] | |
2181 |
|
2170 | |||
2182 | end = opts['print0'] and '\0' or '\n' |
|
2171 | end = opts['print0'] and '\0' or '\n' | |
2183 |
|
2172 | |||
2184 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] |
|
2173 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] | |
2185 | or changetypes): |
|
2174 | or changetypes): | |
2186 | if opts['no_status']: |
|
2175 | if opts['no_status']: | |
2187 | format = "%%s%s" % end |
|
2176 | format = "%%s%s" % end | |
2188 | else: |
|
2177 | else: | |
2189 | format = "%s %%s%s" % (char, end); |
|
2178 | format = "%s %%s%s" % (char, end); | |
2190 |
|
2179 | |||
2191 | for f in changes: |
|
2180 | for f in changes: | |
2192 | ui.write(format % f) |
|
2181 | ui.write(format % f) | |
2193 |
|
2182 | |||
2194 | def tag(ui, repo, name, rev_=None, **opts): |
|
2183 | def tag(ui, repo, name, rev_=None, **opts): | |
2195 | """add a tag for the current tip or a given revision |
|
2184 | """add a tag for the current tip or a given revision | |
2196 |
|
2185 | |||
2197 | Name a particular revision using <name>. |
|
2186 | Name a particular revision using <name>. | |
2198 |
|
2187 | |||
2199 | Tags are used to name particular revisions of the repository and are |
|
2188 | Tags are used to name particular revisions of the repository and are | |
2200 | very useful to compare different revision, to go back to significant |
|
2189 | very useful to compare different revision, to go back to significant | |
2201 | earlier versions or to mark branch points as releases, etc. |
|
2190 | earlier versions or to mark branch points as releases, etc. | |
2202 |
|
2191 | |||
2203 | If no revision is given, the tip is used. |
|
2192 | If no revision is given, the tip is used. | |
2204 |
|
2193 | |||
2205 | To facilitate version control, distribution, and merging of tags, |
|
2194 | To facilitate version control, distribution, and merging of tags, | |
2206 | they are stored as a file named ".hgtags" which is managed |
|
2195 | they are stored as a file named ".hgtags" which is managed | |
2207 | similarly to other project files and can be hand-edited if |
|
2196 | similarly to other project files and can be hand-edited if | |
2208 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2197 | necessary. The file '.hg/localtags' is used for local tags (not | |
2209 | shared among repositories). |
|
2198 | shared among repositories). | |
2210 | """ |
|
2199 | """ | |
2211 | if name == "tip": |
|
2200 | if name == "tip": | |
2212 | raise util.Abort(_("the name 'tip' is reserved")) |
|
2201 | raise util.Abort(_("the name 'tip' is reserved")) | |
2213 | if rev_ is not None: |
|
2202 | if rev_ is not None: | |
2214 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2203 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | |
2215 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2204 | "please use 'hg tag [-r REV] NAME' instead\n")) | |
2216 | if opts['rev']: |
|
2205 | if opts['rev']: | |
2217 | raise util.Abort(_("use only one form to specify the revision")) |
|
2206 | raise util.Abort(_("use only one form to specify the revision")) | |
2218 | if opts['rev']: |
|
2207 | if opts['rev']: | |
2219 | rev_ = opts['rev'] |
|
2208 | rev_ = opts['rev'] | |
2220 | if rev_: |
|
2209 | if rev_: | |
2221 | r = hex(repo.lookup(rev_)) |
|
2210 | r = hex(repo.lookup(rev_)) | |
2222 | else: |
|
2211 | else: | |
2223 | r = hex(repo.changelog.tip()) |
|
2212 | r = hex(repo.changelog.tip()) | |
2224 |
|
2213 | |||
2225 | disallowed = (revrangesep, '\r', '\n') |
|
2214 | disallowed = (revrangesep, '\r', '\n') | |
2226 | for c in disallowed: |
|
2215 | for c in disallowed: | |
2227 | if name.find(c) >= 0: |
|
2216 | if name.find(c) >= 0: | |
2228 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) |
|
2217 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) | |
2229 |
|
2218 | |||
2230 | repo.hook('pretag', throw=True, node=r, tag=name, |
|
2219 | repo.hook('pretag', throw=True, node=r, tag=name, | |
2231 | local=int(not not opts['local'])) |
|
2220 | local=int(not not opts['local'])) | |
2232 |
|
2221 | |||
2233 | if opts['local']: |
|
2222 | if opts['local']: | |
2234 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) |
|
2223 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) | |
2235 | repo.hook('tag', node=r, tag=name, local=1) |
|
2224 | repo.hook('tag', node=r, tag=name, local=1) | |
2236 | return |
|
2225 | return | |
2237 |
|
2226 | |||
2238 | for x in repo.changes(): |
|
2227 | for x in repo.changes(): | |
2239 | if ".hgtags" in x: |
|
2228 | if ".hgtags" in x: | |
2240 | raise util.Abort(_("working copy of .hgtags is changed " |
|
2229 | raise util.Abort(_("working copy of .hgtags is changed " | |
2241 | "(please commit .hgtags manually)")) |
|
2230 | "(please commit .hgtags manually)")) | |
2242 |
|
2231 | |||
2243 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) |
|
2232 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) | |
2244 | if repo.dirstate.state(".hgtags") == '?': |
|
2233 | if repo.dirstate.state(".hgtags") == '?': | |
2245 | repo.add([".hgtags"]) |
|
2234 | repo.add([".hgtags"]) | |
2246 |
|
2235 | |||
2247 | message = (opts['message'] or |
|
2236 | message = (opts['message'] or | |
2248 | _("Added tag %s for changeset %s") % (name, r)) |
|
2237 | _("Added tag %s for changeset %s") % (name, r)) | |
2249 | try: |
|
2238 | try: | |
2250 | repo.commit([".hgtags"], message, opts['user'], opts['date']) |
|
2239 | repo.commit([".hgtags"], message, opts['user'], opts['date']) | |
2251 | repo.hook('tag', node=r, tag=name, local=0) |
|
2240 | repo.hook('tag', node=r, tag=name, local=0) | |
2252 | except ValueError, inst: |
|
2241 | except ValueError, inst: | |
2253 | raise util.Abort(str(inst)) |
|
2242 | raise util.Abort(str(inst)) | |
2254 |
|
2243 | |||
2255 | def tags(ui, repo): |
|
2244 | def tags(ui, repo): | |
2256 | """list repository tags |
|
2245 | """list repository tags | |
2257 |
|
2246 | |||
2258 | List the repository tags. |
|
2247 | List the repository tags. | |
2259 |
|
2248 | |||
2260 | This lists both regular and local tags. |
|
2249 | This lists both regular and local tags. | |
2261 | """ |
|
2250 | """ | |
2262 |
|
2251 | |||
2263 | l = repo.tagslist() |
|
2252 | l = repo.tagslist() | |
2264 | l.reverse() |
|
2253 | l.reverse() | |
2265 | for t, n in l: |
|
2254 | for t, n in l: | |
2266 | try: |
|
2255 | try: | |
2267 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) |
|
2256 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) | |
2268 | except KeyError: |
|
2257 | except KeyError: | |
2269 | r = " ?:?" |
|
2258 | r = " ?:?" | |
2270 | ui.write("%-30s %s\n" % (t, r)) |
|
2259 | ui.write("%-30s %s\n" % (t, r)) | |
2271 |
|
2260 | |||
2272 | def tip(ui, repo, **opts): |
|
2261 | def tip(ui, repo, **opts): | |
2273 | """show the tip revision |
|
2262 | """show the tip revision | |
2274 |
|
2263 | |||
2275 | Show the tip revision. |
|
2264 | Show the tip revision. | |
2276 | """ |
|
2265 | """ | |
2277 | n = repo.changelog.tip() |
|
2266 | n = repo.changelog.tip() | |
2278 | br = None |
|
2267 | br = None | |
2279 | if opts['branches']: |
|
2268 | if opts['branches']: | |
2280 | br = repo.branchlookup([n]) |
|
2269 | br = repo.branchlookup([n]) | |
2281 | show_changeset(ui, repo, changenode=n, brinfo=br) |
|
2270 | show_changeset(ui, repo, changenode=n, brinfo=br) | |
2282 | if opts['patch']: |
|
2271 | if opts['patch']: | |
2283 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) |
|
2272 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) | |
2284 |
|
2273 | |||
2285 | def unbundle(ui, repo, fname, **opts): |
|
2274 | def unbundle(ui, repo, fname, **opts): | |
2286 | """apply a changegroup file |
|
2275 | """apply a changegroup file | |
2287 |
|
2276 | |||
2288 | Apply a compressed changegroup file generated by the bundle |
|
2277 | Apply a compressed changegroup file generated by the bundle | |
2289 | command. |
|
2278 | command. | |
2290 | """ |
|
2279 | """ | |
2291 | f = urllib.urlopen(fname) |
|
2280 | f = urllib.urlopen(fname) | |
2292 |
|
2281 | |||
2293 | if f.read(4) != "HG10": |
|
2282 | if f.read(4) != "HG10": | |
2294 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) |
|
2283 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) | |
2295 |
|
2284 | |||
2296 | def bzgenerator(f): |
|
2285 | def bzgenerator(f): | |
2297 | zd = bz2.BZ2Decompressor() |
|
2286 | zd = bz2.BZ2Decompressor() | |
2298 | for chunk in f: |
|
2287 | for chunk in f: | |
2299 | yield zd.decompress(chunk) |
|
2288 | yield zd.decompress(chunk) | |
2300 |
|
2289 | |||
2301 | bzgen = bzgenerator(util.filechunkiter(f, 4096)) |
|
2290 | bzgen = bzgenerator(util.filechunkiter(f, 4096)) | |
2302 | if repo.addchangegroup(util.chunkbuffer(bzgen)): |
|
2291 | if repo.addchangegroup(util.chunkbuffer(bzgen)): | |
2303 | return 1 |
|
2292 | return 1 | |
2304 |
|
2293 | |||
2305 | if opts['update']: |
|
2294 | if opts['update']: | |
2306 | return update(ui, repo) |
|
2295 | return update(ui, repo) | |
2307 | else: |
|
2296 | else: | |
2308 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2297 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2309 |
|
2298 | |||
2310 | def undo(ui, repo): |
|
2299 | def undo(ui, repo): | |
2311 | """undo the last commit or pull |
|
2300 | """undo the last commit or pull | |
2312 |
|
2301 | |||
2313 | Roll back the last pull or commit transaction on the |
|
2302 | Roll back the last pull or commit transaction on the | |
2314 | repository, restoring the project to its earlier state. |
|
2303 | repository, restoring the project to its earlier state. | |
2315 |
|
2304 | |||
2316 | This command should be used with care. There is only one level of |
|
2305 | This command should be used with care. There is only one level of | |
2317 | undo and there is no redo. |
|
2306 | undo and there is no redo. | |
2318 |
|
2307 | |||
2319 | This command is not intended for use on public repositories. Once |
|
2308 | This command is not intended for use on public repositories. Once | |
2320 | a change is visible for pull by other users, undoing it locally is |
|
2309 | a change is visible for pull by other users, undoing it locally is | |
2321 | ineffective. |
|
2310 | ineffective. | |
2322 | """ |
|
2311 | """ | |
2323 | repo.undo() |
|
2312 | repo.undo() | |
2324 |
|
2313 | |||
2325 | def update(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2314 | def update(ui, repo, node=None, merge=False, clean=False, force=None, | |
2326 | branch=None): |
|
2315 | branch=None): | |
2327 | """update or merge working directory |
|
2316 | """update or merge working directory | |
2328 |
|
2317 | |||
2329 | Update the working directory to the specified revision. |
|
2318 | Update the working directory to the specified revision. | |
2330 |
|
2319 | |||
2331 | If there are no outstanding changes in the working directory and |
|
2320 | If there are no outstanding changes in the working directory and | |
2332 | there is a linear relationship between the current version and the |
|
2321 | there is a linear relationship between the current version and the | |
2333 | requested version, the result is the requested version. |
|
2322 | requested version, the result is the requested version. | |
2334 |
|
2323 | |||
2335 | Otherwise the result is a merge between the contents of the |
|
2324 | Otherwise the result is a merge between the contents of the | |
2336 | current working directory and the requested version. Files that |
|
2325 | current working directory and the requested version. Files that | |
2337 | changed between either parent are marked as changed for the next |
|
2326 | changed between either parent are marked as changed for the next | |
2338 | commit and a commit must be performed before any further updates |
|
2327 | commit and a commit must be performed before any further updates | |
2339 | are allowed. |
|
2328 | are allowed. | |
2340 |
|
2329 | |||
2341 | By default, update will refuse to run if doing so would require |
|
2330 | By default, update will refuse to run if doing so would require | |
2342 | merging or discarding local changes. |
|
2331 | merging or discarding local changes. | |
2343 | """ |
|
2332 | """ | |
2344 | if branch: |
|
2333 | if branch: | |
2345 | br = repo.branchlookup(branch=branch) |
|
2334 | br = repo.branchlookup(branch=branch) | |
2346 | found = [] |
|
2335 | found = [] | |
2347 | for x in br: |
|
2336 | for x in br: | |
2348 | if branch in br[x]: |
|
2337 | if branch in br[x]: | |
2349 | found.append(x) |
|
2338 | found.append(x) | |
2350 | if len(found) > 1: |
|
2339 | if len(found) > 1: | |
2351 | ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2340 | ui.warn(_("Found multiple heads for %s\n") % branch) | |
2352 | for x in found: |
|
2341 | for x in found: | |
2353 | show_changeset(ui, repo, changenode=x, brinfo=br) |
|
2342 | show_changeset(ui, repo, changenode=x, brinfo=br) | |
2354 | return 1 |
|
2343 | return 1 | |
2355 | if len(found) == 1: |
|
2344 | if len(found) == 1: | |
2356 | node = found[0] |
|
2345 | node = found[0] | |
2357 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) |
|
2346 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) | |
2358 | else: |
|
2347 | else: | |
2359 | ui.warn(_("branch %s not found\n") % (branch)) |
|
2348 | ui.warn(_("branch %s not found\n") % (branch)) | |
2360 | return 1 |
|
2349 | return 1 | |
2361 | else: |
|
2350 | else: | |
2362 | node = node and repo.lookup(node) or repo.changelog.tip() |
|
2351 | node = node and repo.lookup(node) or repo.changelog.tip() | |
2363 | return repo.update(node, allow=merge, force=clean, forcemerge=force) |
|
2352 | return repo.update(node, allow=merge, force=clean, forcemerge=force) | |
2364 |
|
2353 | |||
2365 | def verify(ui, repo): |
|
2354 | def verify(ui, repo): | |
2366 | """verify the integrity of the repository |
|
2355 | """verify the integrity of the repository | |
2367 |
|
2356 | |||
2368 | Verify the integrity of the current repository. |
|
2357 | Verify the integrity of the current repository. | |
2369 |
|
2358 | |||
2370 | This will perform an extensive check of the repository's |
|
2359 | This will perform an extensive check of the repository's | |
2371 | integrity, validating the hashes and checksums of each entry in |
|
2360 | integrity, validating the hashes and checksums of each entry in | |
2372 | the changelog, manifest, and tracked files, as well as the |
|
2361 | the changelog, manifest, and tracked files, as well as the | |
2373 | integrity of their crosslinks and indices. |
|
2362 | integrity of their crosslinks and indices. | |
2374 | """ |
|
2363 | """ | |
2375 | return repo.verify() |
|
2364 | return repo.verify() | |
2376 |
|
2365 | |||
2377 | # Command options and aliases are listed here, alphabetically |
|
2366 | # Command options and aliases are listed here, alphabetically | |
2378 |
|
2367 | |||
2379 | table = { |
|
2368 | table = { | |
2380 | "^add": |
|
2369 | "^add": | |
2381 | (add, |
|
2370 | (add, | |
2382 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2371 | [('I', 'include', [], _('include names matching the given patterns')), | |
2383 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2372 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2384 | _('hg add [OPTION]... [FILE]...')), |
|
2373 | _('hg add [OPTION]... [FILE]...')), | |
2385 | "addremove": |
|
2374 | "addremove": | |
2386 | (addremove, |
|
2375 | (addremove, | |
2387 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2376 | [('I', 'include', [], _('include names matching the given patterns')), | |
2388 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2377 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2389 | _('hg addremove [OPTION]... [FILE]...')), |
|
2378 | _('hg addremove [OPTION]... [FILE]...')), | |
2390 | "^annotate": |
|
2379 | "^annotate": | |
2391 | (annotate, |
|
2380 | (annotate, | |
2392 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2381 | [('r', 'rev', '', _('annotate the specified revision')), | |
2393 | ('a', 'text', None, _('treat all files as text')), |
|
2382 | ('a', 'text', None, _('treat all files as text')), | |
2394 | ('u', 'user', None, _('list the author')), |
|
2383 | ('u', 'user', None, _('list the author')), | |
2395 | ('d', 'date', None, _('list the date')), |
|
2384 | ('d', 'date', None, _('list the date')), | |
2396 | ('n', 'number', None, _('list the revision number (default)')), |
|
2385 | ('n', 'number', None, _('list the revision number (default)')), | |
2397 | ('c', 'changeset', None, _('list the changeset')), |
|
2386 | ('c', 'changeset', None, _('list the changeset')), | |
2398 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2387 | ('I', 'include', [], _('include names matching the given patterns')), | |
2399 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2388 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2400 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2389 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | |
2401 | "bundle": |
|
2390 | "bundle": | |
2402 | (bundle, |
|
2391 | (bundle, | |
2403 | [], |
|
2392 | [], | |
2404 | _('hg bundle FILE DEST')), |
|
2393 | _('hg bundle FILE DEST')), | |
2405 | "cat": |
|
2394 | "cat": | |
2406 | (cat, |
|
2395 | (cat, | |
2407 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2396 | [('o', 'output', '', _('print output to file with formatted name')), | |
2408 | ('r', 'rev', '', _('print the given revision')), |
|
2397 | ('r', 'rev', '', _('print the given revision')), | |
2409 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2398 | ('I', 'include', [], _('include names matching the given patterns')), | |
2410 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2399 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2411 | _('hg cat [OPTION]... FILE...')), |
|
2400 | _('hg cat [OPTION]... FILE...')), | |
2412 | "^clone": |
|
2401 | "^clone": | |
2413 | (clone, |
|
2402 | (clone, | |
2414 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2403 | [('U', 'noupdate', None, _('do not update the new working directory')), | |
2415 | ('r', 'rev', [], |
|
2404 | ('r', 'rev', [], | |
2416 | _('a changeset you would like to have after cloning')), |
|
2405 | _('a changeset you would like to have after cloning')), | |
2417 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2406 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
2418 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2407 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2419 | ('', 'remotecmd', '', |
|
2408 | ('', 'remotecmd', '', | |
2420 | _('specify hg command to run on the remote side'))], |
|
2409 | _('specify hg command to run on the remote side'))], | |
2421 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2410 | _('hg clone [OPTION]... SOURCE [DEST]')), | |
2422 | "^commit|ci": |
|
2411 | "^commit|ci": | |
2423 | (commit, |
|
2412 | (commit, | |
2424 | [('A', 'addremove', None, _('run addremove during commit')), |
|
2413 | [('A', 'addremove', None, _('run addremove during commit')), | |
2425 | ('m', 'message', '', _('use <text> as commit message')), |
|
2414 | ('m', 'message', '', _('use <text> as commit message')), | |
2426 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
2415 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
2427 | ('d', 'date', '', _('record datecode as commit date')), |
|
2416 | ('d', 'date', '', _('record datecode as commit date')), | |
2428 | ('u', 'user', '', _('record user as commiter')), |
|
2417 | ('u', 'user', '', _('record user as commiter')), | |
2429 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2418 | ('I', 'include', [], _('include names matching the given patterns')), | |
2430 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2419 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2431 | _('hg commit [OPTION]... [FILE]...')), |
|
2420 | _('hg commit [OPTION]... [FILE]...')), | |
2432 | "copy|cp": |
|
2421 | "copy|cp": | |
2433 | (copy, |
|
2422 | (copy, | |
2434 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2423 | [('A', 'after', None, _('record a copy that has already occurred')), | |
2435 | ('f', 'force', None, |
|
2424 | ('f', 'force', None, | |
2436 | _('forcibly copy over an existing managed file')), |
|
2425 | _('forcibly copy over an existing managed file')), | |
2437 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2426 | ('I', 'include', [], _('include names matching the given patterns')), | |
2438 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2427 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2439 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2428 | _('hg copy [OPTION]... [SOURCE]... DEST')), | |
2440 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2429 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | |
2441 | "debugrebuildstate": |
|
2430 | "debugrebuildstate": | |
2442 | (debugrebuildstate, |
|
2431 | (debugrebuildstate, | |
2443 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2432 | [('r', 'rev', '', _('revision to rebuild to'))], | |
2444 | _('debugrebuildstate [-r REV] [REV]')), |
|
2433 | _('debugrebuildstate [-r REV] [REV]')), | |
2445 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2434 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | |
2446 | "debugconfig": (debugconfig, [], _('debugconfig')), |
|
2435 | "debugconfig": (debugconfig, [], _('debugconfig')), | |
2447 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2436 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | |
2448 | "debugstate": (debugstate, [], _('debugstate')), |
|
2437 | "debugstate": (debugstate, [], _('debugstate')), | |
2449 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2438 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | |
2450 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2439 | "debugindex": (debugindex, [], _('debugindex FILE')), | |
2451 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2440 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | |
2452 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2441 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), | |
2453 | "debugwalk": |
|
2442 | "debugwalk": | |
2454 | (debugwalk, |
|
2443 | (debugwalk, | |
2455 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2444 | [('I', 'include', [], _('include names matching the given patterns')), | |
2456 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2445 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2457 | _('debugwalk [OPTION]... [FILE]...')), |
|
2446 | _('debugwalk [OPTION]... [FILE]...')), | |
2458 | "^diff": |
|
2447 | "^diff": | |
2459 | (diff, |
|
2448 | (diff, | |
2460 | [('r', 'rev', [], _('revision')), |
|
2449 | [('r', 'rev', [], _('revision')), | |
2461 | ('a', 'text', None, _('treat all files as text')), |
|
2450 | ('a', 'text', None, _('treat all files as text')), | |
2462 | ('p', 'show-function', None, |
|
2451 | ('p', 'show-function', None, | |
2463 | _('show which function each change is in')), |
|
2452 | _('show which function each change is in')), | |
2464 | ('w', 'ignore-all-space', None, |
|
2453 | ('w', 'ignore-all-space', None, | |
2465 | _('ignore white space when comparing lines')), |
|
2454 | _('ignore white space when comparing lines')), | |
2466 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2455 | ('I', 'include', [], _('include names matching the given patterns')), | |
2467 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2456 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2468 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), |
|
2457 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), | |
2469 | "^export": |
|
2458 | "^export": | |
2470 | (export, |
|
2459 | (export, | |
2471 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2460 | [('o', 'output', '', _('print output to file with formatted name')), | |
2472 | ('a', 'text', None, _('treat all files as text')), |
|
2461 | ('a', 'text', None, _('treat all files as text')), | |
2473 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2462 | ('', 'switch-parent', None, _('diff against the second parent'))], | |
2474 | _('hg export [-a] [-o OUTFILESPEC] REV...')), |
|
2463 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | |
2475 | "forget": |
|
2464 | "forget": | |
2476 | (forget, |
|
2465 | (forget, | |
2477 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2466 | [('I', 'include', [], _('include names matching the given patterns')), | |
2478 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2467 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2479 | _('hg forget [OPTION]... FILE...')), |
|
2468 | _('hg forget [OPTION]... FILE...')), | |
2480 | "grep": |
|
2469 | "grep": | |
2481 | (grep, |
|
2470 | (grep, | |
2482 | [('0', 'print0', None, _('end fields with NUL')), |
|
2471 | [('0', 'print0', None, _('end fields with NUL')), | |
2483 | ('', 'all', None, _('print all revisions that match')), |
|
2472 | ('', 'all', None, _('print all revisions that match')), | |
2484 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2473 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2485 | ('l', 'files-with-matches', None, |
|
2474 | ('l', 'files-with-matches', None, | |
2486 | _('print only filenames and revs that match')), |
|
2475 | _('print only filenames and revs that match')), | |
2487 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2476 | ('n', 'line-number', None, _('print matching line numbers')), | |
2488 | ('r', 'rev', [], _('search in given revision range')), |
|
2477 | ('r', 'rev', [], _('search in given revision range')), | |
2489 | ('u', 'user', None, _('print user who committed change')), |
|
2478 | ('u', 'user', None, _('print user who committed change')), | |
2490 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2479 | ('I', 'include', [], _('include names matching the given patterns')), | |
2491 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2480 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2492 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2481 | _('hg grep [OPTION]... PATTERN [FILE]...')), | |
2493 | "heads": |
|
2482 | "heads": | |
2494 | (heads, |
|
2483 | (heads, | |
2495 | [('b', 'branches', None, _('show branches')), |
|
2484 | [('b', 'branches', None, _('show branches')), | |
2496 | ('r', 'rev', '', _('show only heads which are descendants of rev'))], |
|
2485 | ('r', 'rev', '', _('show only heads which are descendants of rev'))], | |
2497 | _('hg heads [-b] [-r <rev>]')), |
|
2486 | _('hg heads [-b] [-r <rev>]')), | |
2498 | "help": (help_, [], _('hg help [COMMAND]')), |
|
2487 | "help": (help_, [], _('hg help [COMMAND]')), | |
2499 | "identify|id": (identify, [], _('hg identify')), |
|
2488 | "identify|id": (identify, [], _('hg identify')), | |
2500 | "import|patch": |
|
2489 | "import|patch": | |
2501 | (import_, |
|
2490 | (import_, | |
2502 | [('p', 'strip', 1, |
|
2491 | [('p', 'strip', 1, | |
2503 | _('directory strip option for patch. This has the same\n') + |
|
2492 | _('directory strip option for patch. This has the same\n') + | |
2504 | _('meaning as the corresponding patch option')), |
|
2493 | _('meaning as the corresponding patch option')), | |
2505 | ('b', 'base', '', _('base path')), |
|
2494 | ('b', 'base', '', _('base path')), | |
2506 | ('f', 'force', None, |
|
2495 | ('f', 'force', None, | |
2507 | _('skip check for outstanding uncommitted changes'))], |
|
2496 | _('skip check for outstanding uncommitted changes'))], | |
2508 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), |
|
2497 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), | |
2509 | "incoming|in": (incoming, |
|
2498 | "incoming|in": (incoming, | |
2510 | [('M', 'no-merges', None, _('do not show merges')), |
|
2499 | [('M', 'no-merges', None, _('do not show merges')), | |
2511 | ('p', 'patch', None, _('show patch')), |
|
2500 | ('p', 'patch', None, _('show patch')), | |
2512 | ('n', 'newest-first', None, _('show newest record first'))], |
|
2501 | ('n', 'newest-first', None, _('show newest record first'))], | |
2513 | _('hg incoming [-p] [-n] [-M] [SOURCE]')), |
|
2502 | _('hg incoming [-p] [-n] [-M] [SOURCE]')), | |
2514 | "^init": (init, [], _('hg init [DEST]')), |
|
2503 | "^init": (init, [], _('hg init [DEST]')), | |
2515 | "locate": |
|
2504 | "locate": | |
2516 | (locate, |
|
2505 | (locate, | |
2517 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
2506 | [('r', 'rev', '', _('search the repository as it stood at rev')), | |
2518 | ('0', 'print0', None, |
|
2507 | ('0', 'print0', None, | |
2519 | _('end filenames with NUL, for use with xargs')), |
|
2508 | _('end filenames with NUL, for use with xargs')), | |
2520 | ('f', 'fullpath', None, |
|
2509 | ('f', 'fullpath', None, | |
2521 | _('print complete paths from the filesystem root')), |
|
2510 | _('print complete paths from the filesystem root')), | |
2522 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2511 | ('I', 'include', [], _('include names matching the given patterns')), | |
2523 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2512 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2524 | _('hg locate [OPTION]... [PATTERN]...')), |
|
2513 | _('hg locate [OPTION]... [PATTERN]...')), | |
2525 | "^log|history": |
|
2514 | "^log|history": | |
2526 | (log, |
|
2515 | (log, | |
2527 | [('b', 'branches', None, _('show branches')), |
|
2516 | [('b', 'branches', None, _('show branches')), | |
2528 | ('k', 'keyword', [], _('search for a keyword')), |
|
2517 | ('k', 'keyword', [], _('search for a keyword')), | |
2529 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
2518 | ('l', 'limit', '', _('limit number of changes displayed')), | |
2530 | ('r', 'rev', [], _('show the specified revision or range')), |
|
2519 | ('r', 'rev', [], _('show the specified revision or range')), | |
2531 | ('M', 'no-merges', None, _('do not show merges')), |
|
2520 | ('M', 'no-merges', None, _('do not show merges')), | |
2532 | ('m', 'only-merges', None, _('show only merges')), |
|
2521 | ('m', 'only-merges', None, _('show only merges')), | |
2533 | ('p', 'patch', None, _('show patch')), |
|
2522 | ('p', 'patch', None, _('show patch')), | |
2534 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2523 | ('I', 'include', [], _('include names matching the given patterns')), | |
2535 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2524 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2536 | _('hg log [OPTION]... [FILE]')), |
|
2525 | _('hg log [OPTION]... [FILE]')), | |
2537 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
2526 | "manifest": (manifest, [], _('hg manifest [REV]')), | |
2538 | "outgoing|out": (outgoing, |
|
2527 | "outgoing|out": (outgoing, | |
2539 | [('M', 'no-merges', None, _('do not show merges')), |
|
2528 | [('M', 'no-merges', None, _('do not show merges')), | |
2540 | ('p', 'patch', None, _('show patch')), |
|
2529 | ('p', 'patch', None, _('show patch')), | |
2541 | ('n', 'newest-first', None, _('show newest record first'))], |
|
2530 | ('n', 'newest-first', None, _('show newest record first'))], | |
2542 | _('hg outgoing [-M] [-p] [-n] [DEST]')), |
|
2531 | _('hg outgoing [-M] [-p] [-n] [DEST]')), | |
2543 | "^parents": |
|
2532 | "^parents": | |
2544 | (parents, |
|
2533 | (parents, | |
2545 | [('b', 'branches', None, _('show branches'))], |
|
2534 | [('b', 'branches', None, _('show branches'))], | |
2546 | _('hg parents [-b] [REV]')), |
|
2535 | _('hg parents [-b] [REV]')), | |
2547 | "paths": (paths, [], _('hg paths [NAME]')), |
|
2536 | "paths": (paths, [], _('hg paths [NAME]')), | |
2548 | "^pull": |
|
2537 | "^pull": | |
2549 | (pull, |
|
2538 | (pull, | |
2550 | [('u', 'update', None, |
|
2539 | [('u', 'update', None, | |
2551 | _('update the working directory to tip after pull')), |
|
2540 | _('update the working directory to tip after pull')), | |
2552 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2541 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2553 | ('r', 'rev', [], _('a specific revision you would like to pull')), |
|
2542 | ('r', 'rev', [], _('a specific revision you would like to pull')), | |
2554 | ('', 'remotecmd', '', |
|
2543 | ('', 'remotecmd', '', | |
2555 | _('specify hg command to run on the remote side'))], |
|
2544 | _('specify hg command to run on the remote side'))], | |
2556 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), |
|
2545 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), | |
2557 | "^push": |
|
2546 | "^push": | |
2558 | (push, |
|
2547 | (push, | |
2559 | [('f', 'force', None, _('force push')), |
|
2548 | [('f', 'force', None, _('force push')), | |
2560 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2549 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2561 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
2550 | ('r', 'rev', [], _('a specific revision you would like to push')), | |
2562 | ('', 'remotecmd', '', |
|
2551 | ('', 'remotecmd', '', | |
2563 | _('specify hg command to run on the remote side'))], |
|
2552 | _('specify hg command to run on the remote side'))], | |
2564 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), |
|
2553 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), | |
2565 | "debugrawcommit|rawcommit": |
|
2554 | "debugrawcommit|rawcommit": | |
2566 | (rawcommit, |
|
2555 | (rawcommit, | |
2567 | [('p', 'parent', [], _('parent')), |
|
2556 | [('p', 'parent', [], _('parent')), | |
2568 | ('d', 'date', '', _('date code')), |
|
2557 | ('d', 'date', '', _('date code')), | |
2569 | ('u', 'user', '', _('user')), |
|
2558 | ('u', 'user', '', _('user')), | |
2570 | ('F', 'files', '', _('file list')), |
|
2559 | ('F', 'files', '', _('file list')), | |
2571 | ('m', 'message', '', _('commit message')), |
|
2560 | ('m', 'message', '', _('commit message')), | |
2572 | ('l', 'logfile', '', _('commit message file'))], |
|
2561 | ('l', 'logfile', '', _('commit message file'))], | |
2573 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
2562 | _('hg debugrawcommit [OPTION]... [FILE]...')), | |
2574 | "recover": (recover, [], _('hg recover')), |
|
2563 | "recover": (recover, [], _('hg recover')), | |
2575 | "^remove|rm": |
|
2564 | "^remove|rm": | |
2576 | (remove, |
|
2565 | (remove, | |
2577 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2566 | [('I', 'include', [], _('include names matching the given patterns')), | |
2578 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2567 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2579 | _('hg remove [OPTION]... FILE...')), |
|
2568 | _('hg remove [OPTION]... FILE...')), | |
2580 | "rename|mv": |
|
2569 | "rename|mv": | |
2581 | (rename, |
|
2570 | (rename, | |
2582 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
2571 | [('A', 'after', None, _('record a rename that has already occurred')), | |
2583 | ('f', 'force', None, |
|
2572 | ('f', 'force', None, | |
2584 | _('forcibly copy over an existing managed file')), |
|
2573 | _('forcibly copy over an existing managed file')), | |
2585 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2574 | ('I', 'include', [], _('include names matching the given patterns')), | |
2586 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2575 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2587 | _('hg rename [OPTION]... [SOURCE]... DEST')), |
|
2576 | _('hg rename [OPTION]... [SOURCE]... DEST')), | |
2588 | "^revert": |
|
2577 | "^revert": | |
2589 | (revert, |
|
2578 | (revert, | |
2590 | [('r', 'rev', '', _('revision to revert to')), |
|
2579 | [('r', 'rev', '', _('revision to revert to')), | |
2591 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2580 | ('I', 'include', [], _('include names matching the given patterns')), | |
2592 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2581 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2593 | _('hg revert [-r REV] [NAME]...')), |
|
2582 | _('hg revert [-r REV] [NAME]...')), | |
2594 | "root": (root, [], _('hg root')), |
|
2583 | "root": (root, [], _('hg root')), | |
2595 | "^serve": |
|
2584 | "^serve": | |
2596 | (serve, |
|
2585 | (serve, | |
2597 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
2586 | [('A', 'accesslog', '', _('name of access log file to write to')), | |
2598 | ('d', 'daemon', None, _('run server in background')), |
|
2587 | ('d', 'daemon', None, _('run server in background')), | |
2599 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
2588 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
2600 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
2589 | ('E', 'errorlog', '', _('name of error log file to write to')), | |
2601 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
2590 | ('p', 'port', 0, _('port to use (default: 8000)')), | |
2602 | ('a', 'address', '', _('address to use')), |
|
2591 | ('a', 'address', '', _('address to use')), | |
2603 | ('n', 'name', '', |
|
2592 | ('n', 'name', '', | |
2604 | _('name to show in web pages (default: working dir)')), |
|
2593 | _('name to show in web pages (default: working dir)')), | |
2605 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
2594 | ('', 'pid-file', '', _('name of file to write process ID to')), | |
2606 | ('', 'stdio', None, _('for remote clients')), |
|
2595 | ('', 'stdio', None, _('for remote clients')), | |
2607 | ('t', 'templates', '', _('web templates to use')), |
|
2596 | ('t', 'templates', '', _('web templates to use')), | |
2608 | ('', 'style', '', _('template style to use')), |
|
2597 | ('', 'style', '', _('template style to use')), | |
2609 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
2598 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | |
2610 | _('hg serve [OPTION]...')), |
|
2599 | _('hg serve [OPTION]...')), | |
2611 | "^status|st": |
|
2600 | "^status|st": | |
2612 | (status, |
|
2601 | (status, | |
2613 | [('m', 'modified', None, _('show only modified files')), |
|
2602 | [('m', 'modified', None, _('show only modified files')), | |
2614 | ('a', 'added', None, _('show only added files')), |
|
2603 | ('a', 'added', None, _('show only added files')), | |
2615 | ('r', 'removed', None, _('show only removed files')), |
|
2604 | ('r', 'removed', None, _('show only removed files')), | |
2616 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
2605 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
2617 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
2606 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
2618 | ('n', 'no-status', None, _('hide status prefix')), |
|
2607 | ('n', 'no-status', None, _('hide status prefix')), | |
2619 | ('0', 'print0', None, |
|
2608 | ('0', 'print0', None, | |
2620 | _('end filenames with NUL, for use with xargs')), |
|
2609 | _('end filenames with NUL, for use with xargs')), | |
2621 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2610 | ('I', 'include', [], _('include names matching the given patterns')), | |
2622 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2611 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2623 | _('hg status [OPTION]... [FILE]...')), |
|
2612 | _('hg status [OPTION]... [FILE]...')), | |
2624 | "tag": |
|
2613 | "tag": | |
2625 | (tag, |
|
2614 | (tag, | |
2626 | [('l', 'local', None, _('make the tag local')), |
|
2615 | [('l', 'local', None, _('make the tag local')), | |
2627 | ('m', 'message', '', _('message for tag commit log entry')), |
|
2616 | ('m', 'message', '', _('message for tag commit log entry')), | |
2628 | ('d', 'date', '', _('record datecode as commit date')), |
|
2617 | ('d', 'date', '', _('record datecode as commit date')), | |
2629 | ('u', 'user', '', _('record user as commiter')), |
|
2618 | ('u', 'user', '', _('record user as commiter')), | |
2630 | ('r', 'rev', '', _('revision to tag'))], |
|
2619 | ('r', 'rev', '', _('revision to tag'))], | |
2631 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
2620 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | |
2632 | "tags": (tags, [], _('hg tags')), |
|
2621 | "tags": (tags, [], _('hg tags')), | |
2633 | "tip": |
|
2622 | "tip": | |
2634 | (tip, |
|
2623 | (tip, | |
2635 | [('b', 'branches', None, _('show branches')), |
|
2624 | [('b', 'branches', None, _('show branches')), | |
2636 | ('p', 'patch', None, _('show patch'))], |
|
2625 | ('p', 'patch', None, _('show patch'))], | |
2637 | _('hg tip [-b] [-p]')), |
|
2626 | _('hg tip [-b] [-p]')), | |
2638 | "unbundle": |
|
2627 | "unbundle": | |
2639 | (unbundle, |
|
2628 | (unbundle, | |
2640 | [('u', 'update', None, |
|
2629 | [('u', 'update', None, | |
2641 | _('update the working directory to tip after unbundle'))], |
|
2630 | _('update the working directory to tip after unbundle'))], | |
2642 | _('hg unbundle [-u] FILE')), |
|
2631 | _('hg unbundle [-u] FILE')), | |
2643 | "undo": (undo, [], _('hg undo')), |
|
2632 | "undo": (undo, [], _('hg undo')), | |
2644 | "^update|up|checkout|co": |
|
2633 | "^update|up|checkout|co": | |
2645 | (update, |
|
2634 | (update, | |
2646 | [('b', 'branch', '', _('checkout the head of a specific branch')), |
|
2635 | [('b', 'branch', '', _('checkout the head of a specific branch')), | |
2647 | ('m', 'merge', None, _('allow merging of branches')), |
|
2636 | ('m', 'merge', None, _('allow merging of branches')), | |
2648 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
2637 | ('C', 'clean', None, _('overwrite locally modified files')), | |
2649 | ('f', 'force', None, _('force a merge with outstanding changes'))], |
|
2638 | ('f', 'force', None, _('force a merge with outstanding changes'))], | |
2650 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), |
|
2639 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), | |
2651 | "verify": (verify, [], _('hg verify')), |
|
2640 | "verify": (verify, [], _('hg verify')), | |
2652 | "version": (show_version, [], _('hg version')), |
|
2641 | "version": (show_version, [], _('hg version')), | |
2653 | } |
|
2642 | } | |
2654 |
|
2643 | |||
2655 | globalopts = [ |
|
2644 | globalopts = [ | |
2656 | ('R', 'repository', '', _('repository root directory')), |
|
2645 | ('R', 'repository', '', _('repository root directory')), | |
2657 | ('', 'cwd', '', _('change working directory')), |
|
2646 | ('', 'cwd', '', _('change working directory')), | |
2658 | ('y', 'noninteractive', None, |
|
2647 | ('y', 'noninteractive', None, | |
2659 | _('do not prompt, assume \'yes\' for any required answers')), |
|
2648 | _('do not prompt, assume \'yes\' for any required answers')), | |
2660 | ('q', 'quiet', None, _('suppress output')), |
|
2649 | ('q', 'quiet', None, _('suppress output')), | |
2661 | ('v', 'verbose', None, _('enable additional output')), |
|
2650 | ('v', 'verbose', None, _('enable additional output')), | |
2662 | ('', 'debug', None, _('enable debugging output')), |
|
2651 | ('', 'debug', None, _('enable debugging output')), | |
2663 | ('', 'debugger', None, _('start debugger')), |
|
2652 | ('', 'debugger', None, _('start debugger')), | |
2664 | ('', 'traceback', None, _('print traceback on exception')), |
|
2653 | ('', 'traceback', None, _('print traceback on exception')), | |
2665 | ('', 'time', None, _('time how long the command takes')), |
|
2654 | ('', 'time', None, _('time how long the command takes')), | |
2666 | ('', 'profile', None, _('print command execution profile')), |
|
2655 | ('', 'profile', None, _('print command execution profile')), | |
2667 | ('', 'version', None, _('output version information and exit')), |
|
2656 | ('', 'version', None, _('output version information and exit')), | |
2668 | ('h', 'help', None, _('display help and exit')), |
|
2657 | ('h', 'help', None, _('display help and exit')), | |
2669 | ] |
|
2658 | ] | |
2670 |
|
2659 | |||
2671 |
norepo = ("clone init version help debugancestor debug |
|
2660 | norepo = ("clone init version help debugancestor debugdata" | |
2672 |
" debugindex debugindexdot |
|
2661 | " debugindex debugindexdot") | |
|
2662 | optionalrepo = ("paths debugconfig") | |||
2673 |
|
2663 | |||
2674 | def find(cmd): |
|
2664 | def find(cmd): | |
2675 | """Return (aliases, command table entry) for command string.""" |
|
2665 | """Return (aliases, command table entry) for command string.""" | |
2676 | choice = [] |
|
2666 | choice = [] | |
2677 | debugchoice = [] |
|
2667 | debugchoice = [] | |
2678 | for e in table.keys(): |
|
2668 | for e in table.keys(): | |
2679 | aliases = e.lstrip("^").split("|") |
|
2669 | aliases = e.lstrip("^").split("|") | |
2680 | if cmd in aliases: |
|
2670 | if cmd in aliases: | |
2681 | return aliases, table[e] |
|
2671 | return aliases, table[e] | |
2682 | for a in aliases: |
|
2672 | for a in aliases: | |
2683 | if a.startswith(cmd): |
|
2673 | if a.startswith(cmd): | |
2684 | if aliases[0].startswith("debug"): |
|
2674 | if aliases[0].startswith("debug"): | |
2685 | debugchoice.append([aliases, table[e]]) |
|
2675 | debugchoice.append([aliases, table[e]]) | |
2686 | else: |
|
2676 | else: | |
2687 | choice.append([aliases, table[e]]) |
|
2677 | choice.append([aliases, table[e]]) | |
2688 | break |
|
2678 | break | |
2689 |
|
2679 | |||
2690 | if not choice and debugchoice: |
|
2680 | if not choice and debugchoice: | |
2691 | choice = debugchoice |
|
2681 | choice = debugchoice | |
2692 |
|
2682 | |||
2693 | if len(choice) > 1: |
|
2683 | if len(choice) > 1: | |
2694 | clist = [] |
|
2684 | clist = [] | |
2695 | for aliases, table_e in choice: |
|
2685 | for aliases, table_e in choice: | |
2696 | if aliases[0].startswith(cmd): |
|
2686 | if aliases[0].startswith(cmd): | |
2697 | clist.append(aliases[0]) |
|
2687 | clist.append(aliases[0]) | |
2698 | for a in aliases[1:]: |
|
2688 | for a in aliases[1:]: | |
2699 | if a.startswith(cmd) and not aliases[0].startswith(a): |
|
2689 | if a.startswith(cmd) and not aliases[0].startswith(a): | |
2700 | clist.append(a) |
|
2690 | clist.append(a) | |
2701 | clist.sort() |
|
2691 | clist.sort() | |
2702 | raise AmbiguousCommand(cmd, clist) |
|
2692 | raise AmbiguousCommand(cmd, clist) | |
2703 |
|
2693 | |||
2704 | if choice: |
|
2694 | if choice: | |
2705 | return choice[0] |
|
2695 | return choice[0] | |
2706 |
|
2696 | |||
2707 | raise UnknownCommand(cmd) |
|
2697 | raise UnknownCommand(cmd) | |
2708 |
|
2698 | |||
2709 | class SignalInterrupt(Exception): |
|
2699 | class SignalInterrupt(Exception): | |
2710 | """Exception raised on SIGTERM and SIGHUP.""" |
|
2700 | """Exception raised on SIGTERM and SIGHUP.""" | |
2711 |
|
2701 | |||
2712 | def catchterm(*args): |
|
2702 | def catchterm(*args): | |
2713 | raise SignalInterrupt |
|
2703 | raise SignalInterrupt | |
2714 |
|
2704 | |||
2715 | def run(): |
|
2705 | def run(): | |
2716 | sys.exit(dispatch(sys.argv[1:])) |
|
2706 | sys.exit(dispatch(sys.argv[1:])) | |
2717 |
|
2707 | |||
2718 | class ParseError(Exception): |
|
2708 | class ParseError(Exception): | |
2719 | """Exception raised on errors in parsing the command line.""" |
|
2709 | """Exception raised on errors in parsing the command line.""" | |
2720 |
|
2710 | |||
2721 | def parse(ui, args): |
|
2711 | def parse(ui, args): | |
2722 | options = {} |
|
2712 | options = {} | |
2723 | cmdoptions = {} |
|
2713 | cmdoptions = {} | |
2724 |
|
2714 | |||
2725 | try: |
|
2715 | try: | |
2726 | args = fancyopts.fancyopts(args, globalopts, options) |
|
2716 | args = fancyopts.fancyopts(args, globalopts, options) | |
2727 | except fancyopts.getopt.GetoptError, inst: |
|
2717 | except fancyopts.getopt.GetoptError, inst: | |
2728 | raise ParseError(None, inst) |
|
2718 | raise ParseError(None, inst) | |
2729 |
|
2719 | |||
2730 | if args: |
|
2720 | if args: | |
2731 | cmd, args = args[0], args[1:] |
|
2721 | cmd, args = args[0], args[1:] | |
2732 | aliases, i = find(cmd) |
|
2722 | aliases, i = find(cmd) | |
2733 | cmd = aliases[0] |
|
2723 | cmd = aliases[0] | |
2734 | defaults = ui.config("defaults", cmd) |
|
2724 | defaults = ui.config("defaults", cmd) | |
2735 | if defaults: |
|
2725 | if defaults: | |
2736 | args = defaults.split() + args |
|
2726 | args = defaults.split() + args | |
2737 | c = list(i[1]) |
|
2727 | c = list(i[1]) | |
2738 | else: |
|
2728 | else: | |
2739 | cmd = None |
|
2729 | cmd = None | |
2740 | c = [] |
|
2730 | c = [] | |
2741 |
|
2731 | |||
2742 | # combine global options into local |
|
2732 | # combine global options into local | |
2743 | for o in globalopts: |
|
2733 | for o in globalopts: | |
2744 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
2734 | c.append((o[0], o[1], options[o[1]], o[3])) | |
2745 |
|
2735 | |||
2746 | try: |
|
2736 | try: | |
2747 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
2737 | args = fancyopts.fancyopts(args, c, cmdoptions) | |
2748 | except fancyopts.getopt.GetoptError, inst: |
|
2738 | except fancyopts.getopt.GetoptError, inst: | |
2749 | raise ParseError(cmd, inst) |
|
2739 | raise ParseError(cmd, inst) | |
2750 |
|
2740 | |||
2751 | # separate global options back out |
|
2741 | # separate global options back out | |
2752 | for o in globalopts: |
|
2742 | for o in globalopts: | |
2753 | n = o[1] |
|
2743 | n = o[1] | |
2754 | options[n] = cmdoptions[n] |
|
2744 | options[n] = cmdoptions[n] | |
2755 | del cmdoptions[n] |
|
2745 | del cmdoptions[n] | |
2756 |
|
2746 | |||
2757 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
2747 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | |
2758 |
|
2748 | |||
2759 | def dispatch(args): |
|
2749 | def dispatch(args): | |
2760 | signal.signal(signal.SIGTERM, catchterm) |
|
2750 | signal.signal(signal.SIGTERM, catchterm) | |
2761 | try: |
|
2751 | try: | |
2762 | signal.signal(signal.SIGHUP, catchterm) |
|
2752 | signal.signal(signal.SIGHUP, catchterm) | |
2763 | except AttributeError: |
|
2753 | except AttributeError: | |
2764 | pass |
|
2754 | pass | |
2765 |
|
2755 | |||
2766 | try: |
|
2756 | try: | |
2767 | u = ui.ui() |
|
2757 | u = ui.ui() | |
2768 | except util.Abort, inst: |
|
2758 | except util.Abort, inst: | |
2769 | sys.stderr.write(_("abort: %s\n") % inst) |
|
2759 | sys.stderr.write(_("abort: %s\n") % inst) | |
2770 | sys.exit(1) |
|
2760 | sys.exit(1) | |
2771 |
|
2761 | |||
2772 | external = [] |
|
2762 | external = [] | |
2773 | for x in u.extensions(): |
|
2763 | for x in u.extensions(): | |
2774 | def on_exception(exc, inst): |
|
2764 | def on_exception(exc, inst): | |
2775 | u.warn(_("*** failed to import extension %s\n") % x[1]) |
|
2765 | u.warn(_("*** failed to import extension %s\n") % x[1]) | |
2776 | u.warn("%s\n" % inst) |
|
2766 | u.warn("%s\n" % inst) | |
2777 | if "--traceback" in sys.argv[1:]: |
|
2767 | if "--traceback" in sys.argv[1:]: | |
2778 | traceback.print_exc() |
|
2768 | traceback.print_exc() | |
2779 | if x[1]: |
|
2769 | if x[1]: | |
2780 | try: |
|
2770 | try: | |
2781 | mod = imp.load_source(x[0], x[1]) |
|
2771 | mod = imp.load_source(x[0], x[1]) | |
2782 | except Exception, inst: |
|
2772 | except Exception, inst: | |
2783 | on_exception(Exception, inst) |
|
2773 | on_exception(Exception, inst) | |
2784 | continue |
|
2774 | continue | |
2785 | else: |
|
2775 | else: | |
2786 | def importh(name): |
|
2776 | def importh(name): | |
2787 | mod = __import__(name) |
|
2777 | mod = __import__(name) | |
2788 | components = name.split('.') |
|
2778 | components = name.split('.') | |
2789 | for comp in components[1:]: |
|
2779 | for comp in components[1:]: | |
2790 | mod = getattr(mod, comp) |
|
2780 | mod = getattr(mod, comp) | |
2791 | return mod |
|
2781 | return mod | |
2792 | try: |
|
2782 | try: | |
2793 | mod = importh(x[0]) |
|
2783 | mod = importh(x[0]) | |
2794 | except Exception, inst: |
|
2784 | except Exception, inst: | |
2795 | on_exception(Exception, inst) |
|
2785 | on_exception(Exception, inst) | |
2796 | continue |
|
2786 | continue | |
2797 |
|
2787 | |||
2798 | external.append(mod) |
|
2788 | external.append(mod) | |
2799 | for x in external: |
|
2789 | for x in external: | |
2800 | cmdtable = getattr(x, 'cmdtable', {}) |
|
2790 | cmdtable = getattr(x, 'cmdtable', {}) | |
2801 | for t in cmdtable: |
|
2791 | for t in cmdtable: | |
2802 | if t in table: |
|
2792 | if t in table: | |
2803 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) |
|
2793 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) | |
2804 | table.update(cmdtable) |
|
2794 | table.update(cmdtable) | |
2805 |
|
2795 | |||
2806 | try: |
|
2796 | try: | |
2807 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
2797 | cmd, func, args, options, cmdoptions = parse(u, args) | |
2808 | except ParseError, inst: |
|
2798 | except ParseError, inst: | |
2809 | if inst.args[0]: |
|
2799 | if inst.args[0]: | |
2810 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
2800 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
2811 | help_(u, inst.args[0]) |
|
2801 | help_(u, inst.args[0]) | |
2812 | else: |
|
2802 | else: | |
2813 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
2803 | u.warn(_("hg: %s\n") % inst.args[1]) | |
2814 | help_(u, 'shortlist') |
|
2804 | help_(u, 'shortlist') | |
2815 | sys.exit(-1) |
|
2805 | sys.exit(-1) | |
2816 | except AmbiguousCommand, inst: |
|
2806 | except AmbiguousCommand, inst: | |
2817 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
2807 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
2818 | (inst.args[0], " ".join(inst.args[1]))) |
|
2808 | (inst.args[0], " ".join(inst.args[1]))) | |
2819 | sys.exit(1) |
|
2809 | sys.exit(1) | |
2820 | except UnknownCommand, inst: |
|
2810 | except UnknownCommand, inst: | |
2821 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
2811 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
2822 | help_(u, 'shortlist') |
|
2812 | help_(u, 'shortlist') | |
2823 | sys.exit(1) |
|
2813 | sys.exit(1) | |
2824 |
|
2814 | |||
2825 | if options["time"]: |
|
2815 | if options["time"]: | |
2826 | def get_times(): |
|
2816 | def get_times(): | |
2827 | t = os.times() |
|
2817 | t = os.times() | |
2828 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
2818 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | |
2829 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
2819 | t = (t[0], t[1], t[2], t[3], time.clock()) | |
2830 | return t |
|
2820 | return t | |
2831 | s = get_times() |
|
2821 | s = get_times() | |
2832 | def print_time(): |
|
2822 | def print_time(): | |
2833 | t = get_times() |
|
2823 | t = get_times() | |
2834 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
2824 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | |
2835 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
2825 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | |
2836 | atexit.register(print_time) |
|
2826 | atexit.register(print_time) | |
2837 |
|
2827 | |||
2838 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
2828 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
2839 | not options["noninteractive"]) |
|
2829 | not options["noninteractive"]) | |
2840 |
|
2830 | |||
2841 | # enter the debugger before command execution |
|
2831 | # enter the debugger before command execution | |
2842 | if options['debugger']: |
|
2832 | if options['debugger']: | |
2843 | pdb.set_trace() |
|
2833 | pdb.set_trace() | |
2844 |
|
2834 | |||
2845 | try: |
|
2835 | try: | |
2846 | try: |
|
2836 | try: | |
2847 | path = options["repository"] |
|
2837 | path = options["repository"] | |
2848 | if path: |
|
2838 | if path: | |
2849 | repo = hg.repository(u, path=path) |
|
2839 | repo = hg.repository(u, path=path) | |
2850 | else: |
|
2840 | else: | |
2851 | repo = None |
|
2841 | repo = None | |
2852 | path = "" |
|
2842 | path = "" | |
2853 |
|
2843 | |||
2854 | if options['help']: |
|
2844 | if options['help']: | |
2855 | help_(u, cmd, options['version']) |
|
2845 | help_(u, cmd, options['version']) | |
2856 | sys.exit(0) |
|
2846 | sys.exit(0) | |
2857 | elif options['version']: |
|
2847 | elif options['version']: | |
2858 | show_version(u) |
|
2848 | show_version(u) | |
2859 | sys.exit(0) |
|
2849 | sys.exit(0) | |
2860 | elif not cmd: |
|
2850 | elif not cmd: | |
2861 | help_(u, 'shortlist') |
|
2851 | help_(u, 'shortlist') | |
2862 | sys.exit(0) |
|
2852 | sys.exit(0) | |
2863 |
|
2853 | |||
2864 | if options['cwd']: |
|
2854 | if options['cwd']: | |
2865 | try: |
|
2855 | try: | |
2866 | os.chdir(options['cwd']) |
|
2856 | os.chdir(options['cwd']) | |
2867 | except OSError, inst: |
|
2857 | except OSError, inst: | |
2868 | raise util.Abort('%s: %s' % |
|
2858 | raise util.Abort('%s: %s' % | |
2869 | (options['cwd'], inst.strerror)) |
|
2859 | (options['cwd'], inst.strerror)) | |
2870 |
|
2860 | |||
2871 | if cmd not in norepo.split(): |
|
2861 | if cmd not in norepo.split(): | |
|
2862 | try: | |||
2872 | if not repo: |
|
2863 | if not repo: | |
2873 | repo = hg.repository(u, path=path) |
|
2864 | repo = hg.repository(u, path=path) | |
2874 | u = repo.ui |
|
2865 | u = repo.ui | |
2875 | for x in external: |
|
2866 | for x in external: | |
2876 | if hasattr(x, 'reposetup'): |
|
2867 | if hasattr(x, 'reposetup'): | |
2877 | x.reposetup(u, repo) |
|
2868 | x.reposetup(u, repo) | |
|
2869 | except hg.RepoError: | |||
|
2870 | if cmd not in optionalrepo.split(): | |||
|
2871 | raise | |||
2878 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
2872 | d = lambda: func(u, repo, *args, **cmdoptions) | |
2879 | else: |
|
2873 | else: | |
2880 | d = lambda: func(u, *args, **cmdoptions) |
|
2874 | d = lambda: func(u, *args, **cmdoptions) | |
2881 |
|
2875 | |||
2882 | try: |
|
2876 | try: | |
2883 | if options['profile']: |
|
2877 | if options['profile']: | |
2884 | import hotshot, hotshot.stats |
|
2878 | import hotshot, hotshot.stats | |
2885 | prof = hotshot.Profile("hg.prof") |
|
2879 | prof = hotshot.Profile("hg.prof") | |
2886 | try: |
|
2880 | try: | |
2887 | try: |
|
2881 | try: | |
2888 | return prof.runcall(d) |
|
2882 | return prof.runcall(d) | |
2889 | except: |
|
2883 | except: | |
2890 | try: |
|
2884 | try: | |
2891 | u.warn(_('exception raised - generating ' |
|
2885 | u.warn(_('exception raised - generating ' | |
2892 | 'profile anyway\n')) |
|
2886 | 'profile anyway\n')) | |
2893 | except: |
|
2887 | except: | |
2894 | pass |
|
2888 | pass | |
2895 | raise |
|
2889 | raise | |
2896 | finally: |
|
2890 | finally: | |
2897 | prof.close() |
|
2891 | prof.close() | |
2898 | stats = hotshot.stats.load("hg.prof") |
|
2892 | stats = hotshot.stats.load("hg.prof") | |
2899 | stats.strip_dirs() |
|
2893 | stats.strip_dirs() | |
2900 | stats.sort_stats('time', 'calls') |
|
2894 | stats.sort_stats('time', 'calls') | |
2901 | stats.print_stats(40) |
|
2895 | stats.print_stats(40) | |
2902 | else: |
|
2896 | else: | |
2903 | return d() |
|
2897 | return d() | |
2904 | finally: |
|
2898 | finally: | |
2905 | u.flush() |
|
2899 | u.flush() | |
2906 | except: |
|
2900 | except: | |
2907 | # enter the debugger when we hit an exception |
|
2901 | # enter the debugger when we hit an exception | |
2908 | if options['debugger']: |
|
2902 | if options['debugger']: | |
2909 | pdb.post_mortem(sys.exc_info()[2]) |
|
2903 | pdb.post_mortem(sys.exc_info()[2]) | |
2910 | if options['traceback']: |
|
2904 | if options['traceback']: | |
2911 | traceback.print_exc() |
|
2905 | traceback.print_exc() | |
2912 | raise |
|
2906 | raise | |
2913 | except hg.RepoError, inst: |
|
2907 | except hg.RepoError, inst: | |
2914 | u.warn(_("abort: "), inst, "!\n") |
|
2908 | u.warn(_("abort: "), inst, "!\n") | |
2915 | except revlog.RevlogError, inst: |
|
2909 | except revlog.RevlogError, inst: | |
2916 | u.warn(_("abort: "), inst, "!\n") |
|
2910 | u.warn(_("abort: "), inst, "!\n") | |
2917 | except SignalInterrupt: |
|
2911 | except SignalInterrupt: | |
2918 | u.warn(_("killed!\n")) |
|
2912 | u.warn(_("killed!\n")) | |
2919 | except KeyboardInterrupt: |
|
2913 | except KeyboardInterrupt: | |
2920 | try: |
|
2914 | try: | |
2921 | u.warn(_("interrupted!\n")) |
|
2915 | u.warn(_("interrupted!\n")) | |
2922 | except IOError, inst: |
|
2916 | except IOError, inst: | |
2923 | if inst.errno == errno.EPIPE: |
|
2917 | if inst.errno == errno.EPIPE: | |
2924 | if u.debugflag: |
|
2918 | if u.debugflag: | |
2925 | u.warn(_("\nbroken pipe\n")) |
|
2919 | u.warn(_("\nbroken pipe\n")) | |
2926 | else: |
|
2920 | else: | |
2927 | raise |
|
2921 | raise | |
2928 | except IOError, inst: |
|
2922 | except IOError, inst: | |
2929 | if hasattr(inst, "code"): |
|
2923 | if hasattr(inst, "code"): | |
2930 | u.warn(_("abort: %s\n") % inst) |
|
2924 | u.warn(_("abort: %s\n") % inst) | |
2931 | elif hasattr(inst, "reason"): |
|
2925 | elif hasattr(inst, "reason"): | |
2932 | u.warn(_("abort: error: %s\n") % inst.reason[1]) |
|
2926 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | |
2933 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
2927 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | |
2934 | if u.debugflag: |
|
2928 | if u.debugflag: | |
2935 | u.warn(_("broken pipe\n")) |
|
2929 | u.warn(_("broken pipe\n")) | |
2936 | elif getattr(inst, "strerror", None): |
|
2930 | elif getattr(inst, "strerror", None): | |
2937 | if getattr(inst, "filename", None): |
|
2931 | if getattr(inst, "filename", None): | |
2938 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) |
|
2932 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) | |
2939 | else: |
|
2933 | else: | |
2940 | u.warn(_("abort: %s\n") % inst.strerror) |
|
2934 | u.warn(_("abort: %s\n") % inst.strerror) | |
2941 | else: |
|
2935 | else: | |
2942 | raise |
|
2936 | raise | |
2943 | except OSError, inst: |
|
2937 | except OSError, inst: | |
2944 | if hasattr(inst, "filename"): |
|
2938 | if hasattr(inst, "filename"): | |
2945 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
2939 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | |
2946 | else: |
|
2940 | else: | |
2947 | u.warn(_("abort: %s\n") % inst.strerror) |
|
2941 | u.warn(_("abort: %s\n") % inst.strerror) | |
2948 | except util.Abort, inst: |
|
2942 | except util.Abort, inst: | |
2949 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') |
|
2943 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') | |
2950 | sys.exit(1) |
|
2944 | sys.exit(1) | |
2951 | except TypeError, inst: |
|
2945 | except TypeError, inst: | |
2952 | # was this an argument error? |
|
2946 | # was this an argument error? | |
2953 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
2947 | tb = traceback.extract_tb(sys.exc_info()[2]) | |
2954 | if len(tb) > 2: # no |
|
2948 | if len(tb) > 2: # no | |
2955 | raise |
|
2949 | raise | |
2956 | u.debug(inst, "\n") |
|
2950 | u.debug(inst, "\n") | |
2957 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
2951 | u.warn(_("%s: invalid arguments\n") % cmd) | |
2958 | help_(u, cmd) |
|
2952 | help_(u, cmd) | |
2959 | except AmbiguousCommand, inst: |
|
2953 | except AmbiguousCommand, inst: | |
2960 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
2954 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
2961 | (inst.args[0], " ".join(inst.args[1]))) |
|
2955 | (inst.args[0], " ".join(inst.args[1]))) | |
2962 | help_(u, 'shortlist') |
|
2956 | help_(u, 'shortlist') | |
2963 | except UnknownCommand, inst: |
|
2957 | except UnknownCommand, inst: | |
2964 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
2958 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
2965 | help_(u, 'shortlist') |
|
2959 | help_(u, 'shortlist') | |
2966 | except SystemExit: |
|
2960 | except SystemExit: | |
2967 | # don't catch this in the catch-all below |
|
2961 | # don't catch this in the catch-all below | |
2968 | raise |
|
2962 | raise | |
2969 | except: |
|
2963 | except: | |
2970 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
2964 | u.warn(_("** unknown exception encountered, details follow\n")) | |
2971 | u.warn(_("** report bug details to mercurial@selenic.com\n")) |
|
2965 | u.warn(_("** report bug details to mercurial@selenic.com\n")) | |
2972 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
2966 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | |
2973 | % version.get_version()) |
|
2967 | % version.get_version()) | |
2974 | raise |
|
2968 | raise | |
2975 |
|
2969 | |||
2976 | sys.exit(-1) |
|
2970 | sys.exit(-1) |
General Comments 0
You need to be logged in to leave comments.
Login now