Show More
@@ -1,1195 +1,1193 b'' | |||||
1 | # cmdutil.py - help for command processing in mercurial |
|
1 | # cmdutil.py - help for command processing in mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import hex, nullid, nullrev, short |
|
8 | from node import hex, nullid, nullrev, short | |
9 | from i18n import _ |
|
9 | from i18n import _ | |
10 | import os, sys, errno, re, tempfile |
|
10 | import os, sys, errno, re, tempfile | |
11 | import util, scmutil, templater, patch, error, templatekw |
|
11 | import util, scmutil, templater, patch, error, templatekw | |
12 | import match as matchmod |
|
12 | import match as matchmod | |
13 | import subrepo |
|
13 | import subrepo | |
14 |
|
14 | |||
15 | expandpats = scmutil.expandpats |
|
|||
16 | match = scmutil.match |
|
15 | match = scmutil.match | |
17 | matchall = scmutil.matchall |
|
16 | matchall = scmutil.matchall | |
18 | matchfiles = scmutil.matchfiles |
|
17 | matchfiles = scmutil.matchfiles | |
19 | addremove = scmutil.addremove |
|
|||
20 | dirstatecopy = scmutil.dirstatecopy |
|
|||
21 |
|
18 | |||
22 | def parsealiases(cmd): |
|
19 | def parsealiases(cmd): | |
23 | return cmd.lstrip("^").split("|") |
|
20 | return cmd.lstrip("^").split("|") | |
24 |
|
21 | |||
25 | def findpossible(cmd, table, strict=False): |
|
22 | def findpossible(cmd, table, strict=False): | |
26 | """ |
|
23 | """ | |
27 | Return cmd -> (aliases, command table entry) |
|
24 | Return cmd -> (aliases, command table entry) | |
28 | for each matching command. |
|
25 | for each matching command. | |
29 | Return debug commands (or their aliases) only if no normal command matches. |
|
26 | Return debug commands (or their aliases) only if no normal command matches. | |
30 | """ |
|
27 | """ | |
31 | choice = {} |
|
28 | choice = {} | |
32 | debugchoice = {} |
|
29 | debugchoice = {} | |
33 | for e in table.keys(): |
|
30 | for e in table.keys(): | |
34 | aliases = parsealiases(e) |
|
31 | aliases = parsealiases(e) | |
35 | found = None |
|
32 | found = None | |
36 | if cmd in aliases: |
|
33 | if cmd in aliases: | |
37 | found = cmd |
|
34 | found = cmd | |
38 | elif not strict: |
|
35 | elif not strict: | |
39 | for a in aliases: |
|
36 | for a in aliases: | |
40 | if a.startswith(cmd): |
|
37 | if a.startswith(cmd): | |
41 | found = a |
|
38 | found = a | |
42 | break |
|
39 | break | |
43 | if found is not None: |
|
40 | if found is not None: | |
44 | if aliases[0].startswith("debug") or found.startswith("debug"): |
|
41 | if aliases[0].startswith("debug") or found.startswith("debug"): | |
45 | debugchoice[found] = (aliases, table[e]) |
|
42 | debugchoice[found] = (aliases, table[e]) | |
46 | else: |
|
43 | else: | |
47 | choice[found] = (aliases, table[e]) |
|
44 | choice[found] = (aliases, table[e]) | |
48 |
|
45 | |||
49 | if not choice and debugchoice: |
|
46 | if not choice and debugchoice: | |
50 | choice = debugchoice |
|
47 | choice = debugchoice | |
51 |
|
48 | |||
52 | return choice |
|
49 | return choice | |
53 |
|
50 | |||
54 | def findcmd(cmd, table, strict=True): |
|
51 | def findcmd(cmd, table, strict=True): | |
55 | """Return (aliases, command table entry) for command string.""" |
|
52 | """Return (aliases, command table entry) for command string.""" | |
56 | choice = findpossible(cmd, table, strict) |
|
53 | choice = findpossible(cmd, table, strict) | |
57 |
|
54 | |||
58 | if cmd in choice: |
|
55 | if cmd in choice: | |
59 | return choice[cmd] |
|
56 | return choice[cmd] | |
60 |
|
57 | |||
61 | if len(choice) > 1: |
|
58 | if len(choice) > 1: | |
62 | clist = choice.keys() |
|
59 | clist = choice.keys() | |
63 | clist.sort() |
|
60 | clist.sort() | |
64 | raise error.AmbiguousCommand(cmd, clist) |
|
61 | raise error.AmbiguousCommand(cmd, clist) | |
65 |
|
62 | |||
66 | if choice: |
|
63 | if choice: | |
67 | return choice.values()[0] |
|
64 | return choice.values()[0] | |
68 |
|
65 | |||
69 | raise error.UnknownCommand(cmd) |
|
66 | raise error.UnknownCommand(cmd) | |
70 |
|
67 | |||
71 | def findrepo(p): |
|
68 | def findrepo(p): | |
72 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
69 | while not os.path.isdir(os.path.join(p, ".hg")): | |
73 | oldp, p = p, os.path.dirname(p) |
|
70 | oldp, p = p, os.path.dirname(p) | |
74 | if p == oldp: |
|
71 | if p == oldp: | |
75 | return None |
|
72 | return None | |
76 |
|
73 | |||
77 | return p |
|
74 | return p | |
78 |
|
75 | |||
79 | def bailifchanged(repo): |
|
76 | def bailifchanged(repo): | |
80 | if repo.dirstate.p2() != nullid: |
|
77 | if repo.dirstate.p2() != nullid: | |
81 | raise util.Abort(_('outstanding uncommitted merge')) |
|
78 | raise util.Abort(_('outstanding uncommitted merge')) | |
82 | modified, added, removed, deleted = repo.status()[:4] |
|
79 | modified, added, removed, deleted = repo.status()[:4] | |
83 | if modified or added or removed or deleted: |
|
80 | if modified or added or removed or deleted: | |
84 | raise util.Abort(_("outstanding uncommitted changes")) |
|
81 | raise util.Abort(_("outstanding uncommitted changes")) | |
85 |
|
82 | |||
86 | def logmessage(opts): |
|
83 | def logmessage(opts): | |
87 | """ get the log message according to -m and -l option """ |
|
84 | """ get the log message according to -m and -l option """ | |
88 | message = opts.get('message') |
|
85 | message = opts.get('message') | |
89 | logfile = opts.get('logfile') |
|
86 | logfile = opts.get('logfile') | |
90 |
|
87 | |||
91 | if message and logfile: |
|
88 | if message and logfile: | |
92 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
89 | raise util.Abort(_('options --message and --logfile are mutually ' | |
93 | 'exclusive')) |
|
90 | 'exclusive')) | |
94 | if not message and logfile: |
|
91 | if not message and logfile: | |
95 | try: |
|
92 | try: | |
96 | if logfile == '-': |
|
93 | if logfile == '-': | |
97 | message = sys.stdin.read() |
|
94 | message = sys.stdin.read() | |
98 | else: |
|
95 | else: | |
99 | message = '\n'.join(util.readfile(logfile).splitlines()) |
|
96 | message = '\n'.join(util.readfile(logfile).splitlines()) | |
100 | except IOError, inst: |
|
97 | except IOError, inst: | |
101 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
98 | raise util.Abort(_("can't read commit message '%s': %s") % | |
102 | (logfile, inst.strerror)) |
|
99 | (logfile, inst.strerror)) | |
103 | return message |
|
100 | return message | |
104 |
|
101 | |||
105 | def loglimit(opts): |
|
102 | def loglimit(opts): | |
106 | """get the log limit according to option -l/--limit""" |
|
103 | """get the log limit according to option -l/--limit""" | |
107 | limit = opts.get('limit') |
|
104 | limit = opts.get('limit') | |
108 | if limit: |
|
105 | if limit: | |
109 | try: |
|
106 | try: | |
110 | limit = int(limit) |
|
107 | limit = int(limit) | |
111 | except ValueError: |
|
108 | except ValueError: | |
112 | raise util.Abort(_('limit must be a positive integer')) |
|
109 | raise util.Abort(_('limit must be a positive integer')) | |
113 | if limit <= 0: |
|
110 | if limit <= 0: | |
114 | raise util.Abort(_('limit must be positive')) |
|
111 | raise util.Abort(_('limit must be positive')) | |
115 | else: |
|
112 | else: | |
116 | limit = None |
|
113 | limit = None | |
117 | return limit |
|
114 | return limit | |
118 |
|
115 | |||
119 | def makefilename(repo, pat, node, |
|
116 | def makefilename(repo, pat, node, | |
120 | total=None, seqno=None, revwidth=None, pathname=None): |
|
117 | total=None, seqno=None, revwidth=None, pathname=None): | |
121 | node_expander = { |
|
118 | node_expander = { | |
122 | 'H': lambda: hex(node), |
|
119 | 'H': lambda: hex(node), | |
123 | 'R': lambda: str(repo.changelog.rev(node)), |
|
120 | 'R': lambda: str(repo.changelog.rev(node)), | |
124 | 'h': lambda: short(node), |
|
121 | 'h': lambda: short(node), | |
125 | } |
|
122 | } | |
126 | expander = { |
|
123 | expander = { | |
127 | '%': lambda: '%', |
|
124 | '%': lambda: '%', | |
128 | 'b': lambda: os.path.basename(repo.root), |
|
125 | 'b': lambda: os.path.basename(repo.root), | |
129 | } |
|
126 | } | |
130 |
|
127 | |||
131 | try: |
|
128 | try: | |
132 | if node: |
|
129 | if node: | |
133 | expander.update(node_expander) |
|
130 | expander.update(node_expander) | |
134 | if node: |
|
131 | if node: | |
135 | expander['r'] = (lambda: |
|
132 | expander['r'] = (lambda: | |
136 | str(repo.changelog.rev(node)).zfill(revwidth or 0)) |
|
133 | str(repo.changelog.rev(node)).zfill(revwidth or 0)) | |
137 | if total is not None: |
|
134 | if total is not None: | |
138 | expander['N'] = lambda: str(total) |
|
135 | expander['N'] = lambda: str(total) | |
139 | if seqno is not None: |
|
136 | if seqno is not None: | |
140 | expander['n'] = lambda: str(seqno) |
|
137 | expander['n'] = lambda: str(seqno) | |
141 | if total is not None and seqno is not None: |
|
138 | if total is not None and seqno is not None: | |
142 | expander['n'] = lambda: str(seqno).zfill(len(str(total))) |
|
139 | expander['n'] = lambda: str(seqno).zfill(len(str(total))) | |
143 | if pathname is not None: |
|
140 | if pathname is not None: | |
144 | expander['s'] = lambda: os.path.basename(pathname) |
|
141 | expander['s'] = lambda: os.path.basename(pathname) | |
145 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
142 | expander['d'] = lambda: os.path.dirname(pathname) or '.' | |
146 | expander['p'] = lambda: pathname |
|
143 | expander['p'] = lambda: pathname | |
147 |
|
144 | |||
148 | newname = [] |
|
145 | newname = [] | |
149 | patlen = len(pat) |
|
146 | patlen = len(pat) | |
150 | i = 0 |
|
147 | i = 0 | |
151 | while i < patlen: |
|
148 | while i < patlen: | |
152 | c = pat[i] |
|
149 | c = pat[i] | |
153 | if c == '%': |
|
150 | if c == '%': | |
154 | i += 1 |
|
151 | i += 1 | |
155 | c = pat[i] |
|
152 | c = pat[i] | |
156 | c = expander[c]() |
|
153 | c = expander[c]() | |
157 | newname.append(c) |
|
154 | newname.append(c) | |
158 | i += 1 |
|
155 | i += 1 | |
159 | return ''.join(newname) |
|
156 | return ''.join(newname) | |
160 | except KeyError, inst: |
|
157 | except KeyError, inst: | |
161 | raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
|
158 | raise util.Abort(_("invalid format spec '%%%s' in output filename") % | |
162 | inst.args[0]) |
|
159 | inst.args[0]) | |
163 |
|
160 | |||
164 | def makefileobj(repo, pat, node=None, total=None, |
|
161 | def makefileobj(repo, pat, node=None, total=None, | |
165 | seqno=None, revwidth=None, mode='wb', pathname=None): |
|
162 | seqno=None, revwidth=None, mode='wb', pathname=None): | |
166 |
|
163 | |||
167 | writable = mode not in ('r', 'rb') |
|
164 | writable = mode not in ('r', 'rb') | |
168 |
|
165 | |||
169 | if not pat or pat == '-': |
|
166 | if not pat or pat == '-': | |
170 | fp = writable and sys.stdout or sys.stdin |
|
167 | fp = writable and sys.stdout or sys.stdin | |
171 | return os.fdopen(os.dup(fp.fileno()), mode) |
|
168 | return os.fdopen(os.dup(fp.fileno()), mode) | |
172 | if hasattr(pat, 'write') and writable: |
|
169 | if hasattr(pat, 'write') and writable: | |
173 | return pat |
|
170 | return pat | |
174 | if hasattr(pat, 'read') and 'r' in mode: |
|
171 | if hasattr(pat, 'read') and 'r' in mode: | |
175 | return pat |
|
172 | return pat | |
176 | return open(makefilename(repo, pat, node, total, seqno, revwidth, |
|
173 | return open(makefilename(repo, pat, node, total, seqno, revwidth, | |
177 | pathname), |
|
174 | pathname), | |
178 | mode) |
|
175 | mode) | |
179 |
|
176 | |||
180 | def copy(ui, repo, pats, opts, rename=False): |
|
177 | def copy(ui, repo, pats, opts, rename=False): | |
181 | # called with the repo lock held |
|
178 | # called with the repo lock held | |
182 | # |
|
179 | # | |
183 | # hgsep => pathname that uses "/" to separate directories |
|
180 | # hgsep => pathname that uses "/" to separate directories | |
184 | # ossep => pathname that uses os.sep to separate directories |
|
181 | # ossep => pathname that uses os.sep to separate directories | |
185 | cwd = repo.getcwd() |
|
182 | cwd = repo.getcwd() | |
186 | targets = {} |
|
183 | targets = {} | |
187 | after = opts.get("after") |
|
184 | after = opts.get("after") | |
188 | dryrun = opts.get("dry_run") |
|
185 | dryrun = opts.get("dry_run") | |
189 | wctx = repo[None] |
|
186 | wctx = repo[None] | |
190 |
|
187 | |||
191 | def walkpat(pat): |
|
188 | def walkpat(pat): | |
192 | srcs = [] |
|
189 | srcs = [] | |
193 | badstates = after and '?' or '?r' |
|
190 | badstates = after and '?' or '?r' | |
194 | m = match(repo, [pat], opts, globbed=True) |
|
191 | m = match(repo, [pat], opts, globbed=True) | |
195 | for abs in repo.walk(m): |
|
192 | for abs in repo.walk(m): | |
196 | state = repo.dirstate[abs] |
|
193 | state = repo.dirstate[abs] | |
197 | rel = m.rel(abs) |
|
194 | rel = m.rel(abs) | |
198 | exact = m.exact(abs) |
|
195 | exact = m.exact(abs) | |
199 | if state in badstates: |
|
196 | if state in badstates: | |
200 | if exact and state == '?': |
|
197 | if exact and state == '?': | |
201 | ui.warn(_('%s: not copying - file is not managed\n') % rel) |
|
198 | ui.warn(_('%s: not copying - file is not managed\n') % rel) | |
202 | if exact and state == 'r': |
|
199 | if exact and state == 'r': | |
203 | ui.warn(_('%s: not copying - file has been marked for' |
|
200 | ui.warn(_('%s: not copying - file has been marked for' | |
204 | ' remove\n') % rel) |
|
201 | ' remove\n') % rel) | |
205 | continue |
|
202 | continue | |
206 | # abs: hgsep |
|
203 | # abs: hgsep | |
207 | # rel: ossep |
|
204 | # rel: ossep | |
208 | srcs.append((abs, rel, exact)) |
|
205 | srcs.append((abs, rel, exact)) | |
209 | return srcs |
|
206 | return srcs | |
210 |
|
207 | |||
211 | # abssrc: hgsep |
|
208 | # abssrc: hgsep | |
212 | # relsrc: ossep |
|
209 | # relsrc: ossep | |
213 | # otarget: ossep |
|
210 | # otarget: ossep | |
214 | def copyfile(abssrc, relsrc, otarget, exact): |
|
211 | def copyfile(abssrc, relsrc, otarget, exact): | |
215 | abstarget = scmutil.canonpath(repo.root, cwd, otarget) |
|
212 | abstarget = scmutil.canonpath(repo.root, cwd, otarget) | |
216 | reltarget = repo.pathto(abstarget, cwd) |
|
213 | reltarget = repo.pathto(abstarget, cwd) | |
217 | target = repo.wjoin(abstarget) |
|
214 | target = repo.wjoin(abstarget) | |
218 | src = repo.wjoin(abssrc) |
|
215 | src = repo.wjoin(abssrc) | |
219 | state = repo.dirstate[abstarget] |
|
216 | state = repo.dirstate[abstarget] | |
220 |
|
217 | |||
221 | scmutil.checkportable(ui, abstarget) |
|
218 | scmutil.checkportable(ui, abstarget) | |
222 |
|
219 | |||
223 | # check for collisions |
|
220 | # check for collisions | |
224 | prevsrc = targets.get(abstarget) |
|
221 | prevsrc = targets.get(abstarget) | |
225 | if prevsrc is not None: |
|
222 | if prevsrc is not None: | |
226 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
223 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
227 | (reltarget, repo.pathto(abssrc, cwd), |
|
224 | (reltarget, repo.pathto(abssrc, cwd), | |
228 | repo.pathto(prevsrc, cwd))) |
|
225 | repo.pathto(prevsrc, cwd))) | |
229 | return |
|
226 | return | |
230 |
|
227 | |||
231 | # check for overwrites |
|
228 | # check for overwrites | |
232 | exists = os.path.lexists(target) |
|
229 | exists = os.path.lexists(target) | |
233 | if not after and exists or after and state in 'mn': |
|
230 | if not after and exists or after and state in 'mn': | |
234 | if not opts['force']: |
|
231 | if not opts['force']: | |
235 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
232 | ui.warn(_('%s: not overwriting - file exists\n') % | |
236 | reltarget) |
|
233 | reltarget) | |
237 | return |
|
234 | return | |
238 |
|
235 | |||
239 | if after: |
|
236 | if after: | |
240 | if not exists: |
|
237 | if not exists: | |
241 | if rename: |
|
238 | if rename: | |
242 | ui.warn(_('%s: not recording move - %s does not exist\n') % |
|
239 | ui.warn(_('%s: not recording move - %s does not exist\n') % | |
243 | (relsrc, reltarget)) |
|
240 | (relsrc, reltarget)) | |
244 | else: |
|
241 | else: | |
245 | ui.warn(_('%s: not recording copy - %s does not exist\n') % |
|
242 | ui.warn(_('%s: not recording copy - %s does not exist\n') % | |
246 | (relsrc, reltarget)) |
|
243 | (relsrc, reltarget)) | |
247 | return |
|
244 | return | |
248 | elif not dryrun: |
|
245 | elif not dryrun: | |
249 | try: |
|
246 | try: | |
250 | if exists: |
|
247 | if exists: | |
251 | os.unlink(target) |
|
248 | os.unlink(target) | |
252 | targetdir = os.path.dirname(target) or '.' |
|
249 | targetdir = os.path.dirname(target) or '.' | |
253 | if not os.path.isdir(targetdir): |
|
250 | if not os.path.isdir(targetdir): | |
254 | os.makedirs(targetdir) |
|
251 | os.makedirs(targetdir) | |
255 | util.copyfile(src, target) |
|
252 | util.copyfile(src, target) | |
256 | except IOError, inst: |
|
253 | except IOError, inst: | |
257 | if inst.errno == errno.ENOENT: |
|
254 | if inst.errno == errno.ENOENT: | |
258 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
255 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
259 | else: |
|
256 | else: | |
260 | ui.warn(_('%s: cannot copy - %s\n') % |
|
257 | ui.warn(_('%s: cannot copy - %s\n') % | |
261 | (relsrc, inst.strerror)) |
|
258 | (relsrc, inst.strerror)) | |
262 | return True # report a failure |
|
259 | return True # report a failure | |
263 |
|
260 | |||
264 | if ui.verbose or not exact: |
|
261 | if ui.verbose or not exact: | |
265 | if rename: |
|
262 | if rename: | |
266 | ui.status(_('moving %s to %s\n') % (relsrc, reltarget)) |
|
263 | ui.status(_('moving %s to %s\n') % (relsrc, reltarget)) | |
267 | else: |
|
264 | else: | |
268 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
265 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
269 |
|
266 | |||
270 | targets[abstarget] = abssrc |
|
267 | targets[abstarget] = abssrc | |
271 |
|
268 | |||
272 | # fix up dirstate |
|
269 | # fix up dirstate | |
273 |
dirstatecopy(ui, repo, wctx, abssrc, abstarget, |
|
270 | scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget, | |
|
271 | dryrun=dryrun, cwd=cwd) | |||
274 | if rename and not dryrun: |
|
272 | if rename and not dryrun: | |
275 | wctx.remove([abssrc], not after) |
|
273 | wctx.remove([abssrc], not after) | |
276 |
|
274 | |||
277 | # pat: ossep |
|
275 | # pat: ossep | |
278 | # dest ossep |
|
276 | # dest ossep | |
279 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
277 | # srcs: list of (hgsep, hgsep, ossep, bool) | |
280 | # return: function that takes hgsep and returns ossep |
|
278 | # return: function that takes hgsep and returns ossep | |
281 | def targetpathfn(pat, dest, srcs): |
|
279 | def targetpathfn(pat, dest, srcs): | |
282 | if os.path.isdir(pat): |
|
280 | if os.path.isdir(pat): | |
283 | abspfx = scmutil.canonpath(repo.root, cwd, pat) |
|
281 | abspfx = scmutil.canonpath(repo.root, cwd, pat) | |
284 | abspfx = util.localpath(abspfx) |
|
282 | abspfx = util.localpath(abspfx) | |
285 | if destdirexists: |
|
283 | if destdirexists: | |
286 | striplen = len(os.path.split(abspfx)[0]) |
|
284 | striplen = len(os.path.split(abspfx)[0]) | |
287 | else: |
|
285 | else: | |
288 | striplen = len(abspfx) |
|
286 | striplen = len(abspfx) | |
289 | if striplen: |
|
287 | if striplen: | |
290 | striplen += len(os.sep) |
|
288 | striplen += len(os.sep) | |
291 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
|
289 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) | |
292 | elif destdirexists: |
|
290 | elif destdirexists: | |
293 | res = lambda p: os.path.join(dest, |
|
291 | res = lambda p: os.path.join(dest, | |
294 | os.path.basename(util.localpath(p))) |
|
292 | os.path.basename(util.localpath(p))) | |
295 | else: |
|
293 | else: | |
296 | res = lambda p: dest |
|
294 | res = lambda p: dest | |
297 | return res |
|
295 | return res | |
298 |
|
296 | |||
299 | # pat: ossep |
|
297 | # pat: ossep | |
300 | # dest ossep |
|
298 | # dest ossep | |
301 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
299 | # srcs: list of (hgsep, hgsep, ossep, bool) | |
302 | # return: function that takes hgsep and returns ossep |
|
300 | # return: function that takes hgsep and returns ossep | |
303 | def targetpathafterfn(pat, dest, srcs): |
|
301 | def targetpathafterfn(pat, dest, srcs): | |
304 | if matchmod.patkind(pat): |
|
302 | if matchmod.patkind(pat): | |
305 | # a mercurial pattern |
|
303 | # a mercurial pattern | |
306 | res = lambda p: os.path.join(dest, |
|
304 | res = lambda p: os.path.join(dest, | |
307 | os.path.basename(util.localpath(p))) |
|
305 | os.path.basename(util.localpath(p))) | |
308 | else: |
|
306 | else: | |
309 | abspfx = scmutil.canonpath(repo.root, cwd, pat) |
|
307 | abspfx = scmutil.canonpath(repo.root, cwd, pat) | |
310 | if len(abspfx) < len(srcs[0][0]): |
|
308 | if len(abspfx) < len(srcs[0][0]): | |
311 | # A directory. Either the target path contains the last |
|
309 | # A directory. Either the target path contains the last | |
312 | # component of the source path or it does not. |
|
310 | # component of the source path or it does not. | |
313 | def evalpath(striplen): |
|
311 | def evalpath(striplen): | |
314 | score = 0 |
|
312 | score = 0 | |
315 | for s in srcs: |
|
313 | for s in srcs: | |
316 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
|
314 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) | |
317 | if os.path.lexists(t): |
|
315 | if os.path.lexists(t): | |
318 | score += 1 |
|
316 | score += 1 | |
319 | return score |
|
317 | return score | |
320 |
|
318 | |||
321 | abspfx = util.localpath(abspfx) |
|
319 | abspfx = util.localpath(abspfx) | |
322 | striplen = len(abspfx) |
|
320 | striplen = len(abspfx) | |
323 | if striplen: |
|
321 | if striplen: | |
324 | striplen += len(os.sep) |
|
322 | striplen += len(os.sep) | |
325 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
323 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
326 | score = evalpath(striplen) |
|
324 | score = evalpath(striplen) | |
327 | striplen1 = len(os.path.split(abspfx)[0]) |
|
325 | striplen1 = len(os.path.split(abspfx)[0]) | |
328 | if striplen1: |
|
326 | if striplen1: | |
329 | striplen1 += len(os.sep) |
|
327 | striplen1 += len(os.sep) | |
330 | if evalpath(striplen1) > score: |
|
328 | if evalpath(striplen1) > score: | |
331 | striplen = striplen1 |
|
329 | striplen = striplen1 | |
332 | res = lambda p: os.path.join(dest, |
|
330 | res = lambda p: os.path.join(dest, | |
333 | util.localpath(p)[striplen:]) |
|
331 | util.localpath(p)[striplen:]) | |
334 | else: |
|
332 | else: | |
335 | # a file |
|
333 | # a file | |
336 | if destdirexists: |
|
334 | if destdirexists: | |
337 | res = lambda p: os.path.join(dest, |
|
335 | res = lambda p: os.path.join(dest, | |
338 | os.path.basename(util.localpath(p))) |
|
336 | os.path.basename(util.localpath(p))) | |
339 | else: |
|
337 | else: | |
340 | res = lambda p: dest |
|
338 | res = lambda p: dest | |
341 | return res |
|
339 | return res | |
342 |
|
340 | |||
343 |
|
341 | |||
344 | pats = expandpats(pats) |
|
342 | pats = scmutil.expandpats(pats) | |
345 | if not pats: |
|
343 | if not pats: | |
346 | raise util.Abort(_('no source or destination specified')) |
|
344 | raise util.Abort(_('no source or destination specified')) | |
347 | if len(pats) == 1: |
|
345 | if len(pats) == 1: | |
348 | raise util.Abort(_('no destination specified')) |
|
346 | raise util.Abort(_('no destination specified')) | |
349 | dest = pats.pop() |
|
347 | dest = pats.pop() | |
350 | destdirexists = os.path.isdir(dest) and not os.path.islink(dest) |
|
348 | destdirexists = os.path.isdir(dest) and not os.path.islink(dest) | |
351 | if not destdirexists: |
|
349 | if not destdirexists: | |
352 | if len(pats) > 1 or matchmod.patkind(pats[0]): |
|
350 | if len(pats) > 1 or matchmod.patkind(pats[0]): | |
353 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
351 | raise util.Abort(_('with multiple sources, destination must be an ' | |
354 | 'existing directory')) |
|
352 | 'existing directory')) | |
355 | if util.endswithsep(dest): |
|
353 | if util.endswithsep(dest): | |
356 | raise util.Abort(_('destination %s is not a directory') % dest) |
|
354 | raise util.Abort(_('destination %s is not a directory') % dest) | |
357 |
|
355 | |||
358 | tfn = targetpathfn |
|
356 | tfn = targetpathfn | |
359 | if after: |
|
357 | if after: | |
360 | tfn = targetpathafterfn |
|
358 | tfn = targetpathafterfn | |
361 | copylist = [] |
|
359 | copylist = [] | |
362 | for pat in pats: |
|
360 | for pat in pats: | |
363 | srcs = walkpat(pat) |
|
361 | srcs = walkpat(pat) | |
364 | if not srcs: |
|
362 | if not srcs: | |
365 | continue |
|
363 | continue | |
366 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
364 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
367 | if not copylist: |
|
365 | if not copylist: | |
368 | raise util.Abort(_('no files to copy')) |
|
366 | raise util.Abort(_('no files to copy')) | |
369 |
|
367 | |||
370 | errors = 0 |
|
368 | errors = 0 | |
371 | for targetpath, srcs in copylist: |
|
369 | for targetpath, srcs in copylist: | |
372 | for abssrc, relsrc, exact in srcs: |
|
370 | for abssrc, relsrc, exact in srcs: | |
373 | if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
|
371 | if copyfile(abssrc, relsrc, targetpath(abssrc), exact): | |
374 | errors += 1 |
|
372 | errors += 1 | |
375 |
|
373 | |||
376 | if errors: |
|
374 | if errors: | |
377 | ui.warn(_('(consider using --after)\n')) |
|
375 | ui.warn(_('(consider using --after)\n')) | |
378 |
|
376 | |||
379 | return errors != 0 |
|
377 | return errors != 0 | |
380 |
|
378 | |||
381 | def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, |
|
379 | def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, | |
382 | runargs=None, appendpid=False): |
|
380 | runargs=None, appendpid=False): | |
383 | '''Run a command as a service.''' |
|
381 | '''Run a command as a service.''' | |
384 |
|
382 | |||
385 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
383 | if opts['daemon'] and not opts['daemon_pipefds']: | |
386 | # Signal child process startup with file removal |
|
384 | # Signal child process startup with file removal | |
387 | lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') |
|
385 | lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') | |
388 | os.close(lockfd) |
|
386 | os.close(lockfd) | |
389 | try: |
|
387 | try: | |
390 | if not runargs: |
|
388 | if not runargs: | |
391 | runargs = util.hgcmd() + sys.argv[1:] |
|
389 | runargs = util.hgcmd() + sys.argv[1:] | |
392 | runargs.append('--daemon-pipefds=%s' % lockpath) |
|
390 | runargs.append('--daemon-pipefds=%s' % lockpath) | |
393 | # Don't pass --cwd to the child process, because we've already |
|
391 | # Don't pass --cwd to the child process, because we've already | |
394 | # changed directory. |
|
392 | # changed directory. | |
395 | for i in xrange(1, len(runargs)): |
|
393 | for i in xrange(1, len(runargs)): | |
396 | if runargs[i].startswith('--cwd='): |
|
394 | if runargs[i].startswith('--cwd='): | |
397 | del runargs[i] |
|
395 | del runargs[i] | |
398 | break |
|
396 | break | |
399 | elif runargs[i].startswith('--cwd'): |
|
397 | elif runargs[i].startswith('--cwd'): | |
400 | del runargs[i:i + 2] |
|
398 | del runargs[i:i + 2] | |
401 | break |
|
399 | break | |
402 | def condfn(): |
|
400 | def condfn(): | |
403 | return not os.path.exists(lockpath) |
|
401 | return not os.path.exists(lockpath) | |
404 | pid = util.rundetached(runargs, condfn) |
|
402 | pid = util.rundetached(runargs, condfn) | |
405 | if pid < 0: |
|
403 | if pid < 0: | |
406 | raise util.Abort(_('child process failed to start')) |
|
404 | raise util.Abort(_('child process failed to start')) | |
407 | finally: |
|
405 | finally: | |
408 | try: |
|
406 | try: | |
409 | os.unlink(lockpath) |
|
407 | os.unlink(lockpath) | |
410 | except OSError, e: |
|
408 | except OSError, e: | |
411 | if e.errno != errno.ENOENT: |
|
409 | if e.errno != errno.ENOENT: | |
412 | raise |
|
410 | raise | |
413 | if parentfn: |
|
411 | if parentfn: | |
414 | return parentfn(pid) |
|
412 | return parentfn(pid) | |
415 | else: |
|
413 | else: | |
416 | return |
|
414 | return | |
417 |
|
415 | |||
418 | if initfn: |
|
416 | if initfn: | |
419 | initfn() |
|
417 | initfn() | |
420 |
|
418 | |||
421 | if opts['pid_file']: |
|
419 | if opts['pid_file']: | |
422 | mode = appendpid and 'a' or 'w' |
|
420 | mode = appendpid and 'a' or 'w' | |
423 | fp = open(opts['pid_file'], mode) |
|
421 | fp = open(opts['pid_file'], mode) | |
424 | fp.write(str(os.getpid()) + '\n') |
|
422 | fp.write(str(os.getpid()) + '\n') | |
425 | fp.close() |
|
423 | fp.close() | |
426 |
|
424 | |||
427 | if opts['daemon_pipefds']: |
|
425 | if opts['daemon_pipefds']: | |
428 | lockpath = opts['daemon_pipefds'] |
|
426 | lockpath = opts['daemon_pipefds'] | |
429 | try: |
|
427 | try: | |
430 | os.setsid() |
|
428 | os.setsid() | |
431 | except AttributeError: |
|
429 | except AttributeError: | |
432 | pass |
|
430 | pass | |
433 | os.unlink(lockpath) |
|
431 | os.unlink(lockpath) | |
434 | util.hidewindow() |
|
432 | util.hidewindow() | |
435 | sys.stdout.flush() |
|
433 | sys.stdout.flush() | |
436 | sys.stderr.flush() |
|
434 | sys.stderr.flush() | |
437 |
|
435 | |||
438 | nullfd = os.open(util.nulldev, os.O_RDWR) |
|
436 | nullfd = os.open(util.nulldev, os.O_RDWR) | |
439 | logfilefd = nullfd |
|
437 | logfilefd = nullfd | |
440 | if logfile: |
|
438 | if logfile: | |
441 | logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND) |
|
439 | logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND) | |
442 | os.dup2(nullfd, 0) |
|
440 | os.dup2(nullfd, 0) | |
443 | os.dup2(logfilefd, 1) |
|
441 | os.dup2(logfilefd, 1) | |
444 | os.dup2(logfilefd, 2) |
|
442 | os.dup2(logfilefd, 2) | |
445 | if nullfd not in (0, 1, 2): |
|
443 | if nullfd not in (0, 1, 2): | |
446 | os.close(nullfd) |
|
444 | os.close(nullfd) | |
447 | if logfile and logfilefd not in (0, 1, 2): |
|
445 | if logfile and logfilefd not in (0, 1, 2): | |
448 | os.close(logfilefd) |
|
446 | os.close(logfilefd) | |
449 |
|
447 | |||
450 | if runfn: |
|
448 | if runfn: | |
451 | return runfn() |
|
449 | return runfn() | |
452 |
|
450 | |||
453 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
|
451 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, | |
454 | opts=None): |
|
452 | opts=None): | |
455 | '''export changesets as hg patches.''' |
|
453 | '''export changesets as hg patches.''' | |
456 |
|
454 | |||
457 | total = len(revs) |
|
455 | total = len(revs) | |
458 | revwidth = max([len(str(rev)) for rev in revs]) |
|
456 | revwidth = max([len(str(rev)) for rev in revs]) | |
459 |
|
457 | |||
460 | def single(rev, seqno, fp): |
|
458 | def single(rev, seqno, fp): | |
461 | ctx = repo[rev] |
|
459 | ctx = repo[rev] | |
462 | node = ctx.node() |
|
460 | node = ctx.node() | |
463 | parents = [p.node() for p in ctx.parents() if p] |
|
461 | parents = [p.node() for p in ctx.parents() if p] | |
464 | branch = ctx.branch() |
|
462 | branch = ctx.branch() | |
465 | if switch_parent: |
|
463 | if switch_parent: | |
466 | parents.reverse() |
|
464 | parents.reverse() | |
467 | prev = (parents and parents[0]) or nullid |
|
465 | prev = (parents and parents[0]) or nullid | |
468 |
|
466 | |||
469 | shouldclose = False |
|
467 | shouldclose = False | |
470 | if not fp: |
|
468 | if not fp: | |
471 | fp = makefileobj(repo, template, node, total=total, seqno=seqno, |
|
469 | fp = makefileobj(repo, template, node, total=total, seqno=seqno, | |
472 | revwidth=revwidth, mode='ab') |
|
470 | revwidth=revwidth, mode='ab') | |
473 | if fp != template: |
|
471 | if fp != template: | |
474 | shouldclose = True |
|
472 | shouldclose = True | |
475 | if fp != sys.stdout and hasattr(fp, 'name'): |
|
473 | if fp != sys.stdout and hasattr(fp, 'name'): | |
476 | repo.ui.note("%s\n" % fp.name) |
|
474 | repo.ui.note("%s\n" % fp.name) | |
477 |
|
475 | |||
478 | fp.write("# HG changeset patch\n") |
|
476 | fp.write("# HG changeset patch\n") | |
479 | fp.write("# User %s\n" % ctx.user()) |
|
477 | fp.write("# User %s\n" % ctx.user()) | |
480 | fp.write("# Date %d %d\n" % ctx.date()) |
|
478 | fp.write("# Date %d %d\n" % ctx.date()) | |
481 | if branch and branch != 'default': |
|
479 | if branch and branch != 'default': | |
482 | fp.write("# Branch %s\n" % branch) |
|
480 | fp.write("# Branch %s\n" % branch) | |
483 | fp.write("# Node ID %s\n" % hex(node)) |
|
481 | fp.write("# Node ID %s\n" % hex(node)) | |
484 | fp.write("# Parent %s\n" % hex(prev)) |
|
482 | fp.write("# Parent %s\n" % hex(prev)) | |
485 | if len(parents) > 1: |
|
483 | if len(parents) > 1: | |
486 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
484 | fp.write("# Parent %s\n" % hex(parents[1])) | |
487 | fp.write(ctx.description().rstrip()) |
|
485 | fp.write(ctx.description().rstrip()) | |
488 | fp.write("\n\n") |
|
486 | fp.write("\n\n") | |
489 |
|
487 | |||
490 | for chunk in patch.diff(repo, prev, node, opts=opts): |
|
488 | for chunk in patch.diff(repo, prev, node, opts=opts): | |
491 | fp.write(chunk) |
|
489 | fp.write(chunk) | |
492 |
|
490 | |||
493 | if shouldclose: |
|
491 | if shouldclose: | |
494 | fp.close() |
|
492 | fp.close() | |
495 |
|
493 | |||
496 | for seqno, rev in enumerate(revs): |
|
494 | for seqno, rev in enumerate(revs): | |
497 | single(rev, seqno + 1, fp) |
|
495 | single(rev, seqno + 1, fp) | |
498 |
|
496 | |||
499 | def diffordiffstat(ui, repo, diffopts, node1, node2, match, |
|
497 | def diffordiffstat(ui, repo, diffopts, node1, node2, match, | |
500 | changes=None, stat=False, fp=None, prefix='', |
|
498 | changes=None, stat=False, fp=None, prefix='', | |
501 | listsubrepos=False): |
|
499 | listsubrepos=False): | |
502 | '''show diff or diffstat.''' |
|
500 | '''show diff or diffstat.''' | |
503 | if fp is None: |
|
501 | if fp is None: | |
504 | write = ui.write |
|
502 | write = ui.write | |
505 | else: |
|
503 | else: | |
506 | def write(s, **kw): |
|
504 | def write(s, **kw): | |
507 | fp.write(s) |
|
505 | fp.write(s) | |
508 |
|
506 | |||
509 | if stat: |
|
507 | if stat: | |
510 | diffopts = diffopts.copy(context=0) |
|
508 | diffopts = diffopts.copy(context=0) | |
511 | width = 80 |
|
509 | width = 80 | |
512 | if not ui.plain(): |
|
510 | if not ui.plain(): | |
513 | width = ui.termwidth() |
|
511 | width = ui.termwidth() | |
514 | chunks = patch.diff(repo, node1, node2, match, changes, diffopts, |
|
512 | chunks = patch.diff(repo, node1, node2, match, changes, diffopts, | |
515 | prefix=prefix) |
|
513 | prefix=prefix) | |
516 | for chunk, label in patch.diffstatui(util.iterlines(chunks), |
|
514 | for chunk, label in patch.diffstatui(util.iterlines(chunks), | |
517 | width=width, |
|
515 | width=width, | |
518 | git=diffopts.git): |
|
516 | git=diffopts.git): | |
519 | write(chunk, label=label) |
|
517 | write(chunk, label=label) | |
520 | else: |
|
518 | else: | |
521 | for chunk, label in patch.diffui(repo, node1, node2, match, |
|
519 | for chunk, label in patch.diffui(repo, node1, node2, match, | |
522 | changes, diffopts, prefix=prefix): |
|
520 | changes, diffopts, prefix=prefix): | |
523 | write(chunk, label=label) |
|
521 | write(chunk, label=label) | |
524 |
|
522 | |||
525 | if listsubrepos: |
|
523 | if listsubrepos: | |
526 | ctx1 = repo[node1] |
|
524 | ctx1 = repo[node1] | |
527 | ctx2 = repo[node2] |
|
525 | ctx2 = repo[node2] | |
528 | for subpath, sub in subrepo.itersubrepos(ctx1, ctx2): |
|
526 | for subpath, sub in subrepo.itersubrepos(ctx1, ctx2): | |
529 | if node2 is not None: |
|
527 | if node2 is not None: | |
530 | node2 = ctx2.substate[subpath][1] |
|
528 | node2 = ctx2.substate[subpath][1] | |
531 | submatch = matchmod.narrowmatcher(subpath, match) |
|
529 | submatch = matchmod.narrowmatcher(subpath, match) | |
532 | sub.diff(diffopts, node2, submatch, changes=changes, |
|
530 | sub.diff(diffopts, node2, submatch, changes=changes, | |
533 | stat=stat, fp=fp, prefix=prefix) |
|
531 | stat=stat, fp=fp, prefix=prefix) | |
534 |
|
532 | |||
535 | class changeset_printer(object): |
|
533 | class changeset_printer(object): | |
536 | '''show changeset information when templating not requested.''' |
|
534 | '''show changeset information when templating not requested.''' | |
537 |
|
535 | |||
538 | def __init__(self, ui, repo, patch, diffopts, buffered): |
|
536 | def __init__(self, ui, repo, patch, diffopts, buffered): | |
539 | self.ui = ui |
|
537 | self.ui = ui | |
540 | self.repo = repo |
|
538 | self.repo = repo | |
541 | self.buffered = buffered |
|
539 | self.buffered = buffered | |
542 | self.patch = patch |
|
540 | self.patch = patch | |
543 | self.diffopts = diffopts |
|
541 | self.diffopts = diffopts | |
544 | self.header = {} |
|
542 | self.header = {} | |
545 | self.hunk = {} |
|
543 | self.hunk = {} | |
546 | self.lastheader = None |
|
544 | self.lastheader = None | |
547 | self.footer = None |
|
545 | self.footer = None | |
548 |
|
546 | |||
549 | def flush(self, rev): |
|
547 | def flush(self, rev): | |
550 | if rev in self.header: |
|
548 | if rev in self.header: | |
551 | h = self.header[rev] |
|
549 | h = self.header[rev] | |
552 | if h != self.lastheader: |
|
550 | if h != self.lastheader: | |
553 | self.lastheader = h |
|
551 | self.lastheader = h | |
554 | self.ui.write(h) |
|
552 | self.ui.write(h) | |
555 | del self.header[rev] |
|
553 | del self.header[rev] | |
556 | if rev in self.hunk: |
|
554 | if rev in self.hunk: | |
557 | self.ui.write(self.hunk[rev]) |
|
555 | self.ui.write(self.hunk[rev]) | |
558 | del self.hunk[rev] |
|
556 | del self.hunk[rev] | |
559 | return 1 |
|
557 | return 1 | |
560 | return 0 |
|
558 | return 0 | |
561 |
|
559 | |||
562 | def close(self): |
|
560 | def close(self): | |
563 | if self.footer: |
|
561 | if self.footer: | |
564 | self.ui.write(self.footer) |
|
562 | self.ui.write(self.footer) | |
565 |
|
563 | |||
566 | def show(self, ctx, copies=None, matchfn=None, **props): |
|
564 | def show(self, ctx, copies=None, matchfn=None, **props): | |
567 | if self.buffered: |
|
565 | if self.buffered: | |
568 | self.ui.pushbuffer() |
|
566 | self.ui.pushbuffer() | |
569 | self._show(ctx, copies, matchfn, props) |
|
567 | self._show(ctx, copies, matchfn, props) | |
570 | self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True) |
|
568 | self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True) | |
571 | else: |
|
569 | else: | |
572 | self._show(ctx, copies, matchfn, props) |
|
570 | self._show(ctx, copies, matchfn, props) | |
573 |
|
571 | |||
574 | def _show(self, ctx, copies, matchfn, props): |
|
572 | def _show(self, ctx, copies, matchfn, props): | |
575 | '''show a single changeset or file revision''' |
|
573 | '''show a single changeset or file revision''' | |
576 | changenode = ctx.node() |
|
574 | changenode = ctx.node() | |
577 | rev = ctx.rev() |
|
575 | rev = ctx.rev() | |
578 |
|
576 | |||
579 | if self.ui.quiet: |
|
577 | if self.ui.quiet: | |
580 | self.ui.write("%d:%s\n" % (rev, short(changenode)), |
|
578 | self.ui.write("%d:%s\n" % (rev, short(changenode)), | |
581 | label='log.node') |
|
579 | label='log.node') | |
582 | return |
|
580 | return | |
583 |
|
581 | |||
584 | log = self.repo.changelog |
|
582 | log = self.repo.changelog | |
585 | date = util.datestr(ctx.date()) |
|
583 | date = util.datestr(ctx.date()) | |
586 |
|
584 | |||
587 | hexfunc = self.ui.debugflag and hex or short |
|
585 | hexfunc = self.ui.debugflag and hex or short | |
588 |
|
586 | |||
589 | parents = [(p, hexfunc(log.node(p))) |
|
587 | parents = [(p, hexfunc(log.node(p))) | |
590 | for p in self._meaningful_parentrevs(log, rev)] |
|
588 | for p in self._meaningful_parentrevs(log, rev)] | |
591 |
|
589 | |||
592 | self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode)), |
|
590 | self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode)), | |
593 | label='log.changeset') |
|
591 | label='log.changeset') | |
594 |
|
592 | |||
595 | branch = ctx.branch() |
|
593 | branch = ctx.branch() | |
596 | # don't show the default branch name |
|
594 | # don't show the default branch name | |
597 | if branch != 'default': |
|
595 | if branch != 'default': | |
598 | self.ui.write(_("branch: %s\n") % branch, |
|
596 | self.ui.write(_("branch: %s\n") % branch, | |
599 | label='log.branch') |
|
597 | label='log.branch') | |
600 | for bookmark in self.repo.nodebookmarks(changenode): |
|
598 | for bookmark in self.repo.nodebookmarks(changenode): | |
601 | self.ui.write(_("bookmark: %s\n") % bookmark, |
|
599 | self.ui.write(_("bookmark: %s\n") % bookmark, | |
602 | label='log.bookmark') |
|
600 | label='log.bookmark') | |
603 | for tag in self.repo.nodetags(changenode): |
|
601 | for tag in self.repo.nodetags(changenode): | |
604 | self.ui.write(_("tag: %s\n") % tag, |
|
602 | self.ui.write(_("tag: %s\n") % tag, | |
605 | label='log.tag') |
|
603 | label='log.tag') | |
606 | for parent in parents: |
|
604 | for parent in parents: | |
607 | self.ui.write(_("parent: %d:%s\n") % parent, |
|
605 | self.ui.write(_("parent: %d:%s\n") % parent, | |
608 | label='log.parent') |
|
606 | label='log.parent') | |
609 |
|
607 | |||
610 | if self.ui.debugflag: |
|
608 | if self.ui.debugflag: | |
611 | mnode = ctx.manifestnode() |
|
609 | mnode = ctx.manifestnode() | |
612 | self.ui.write(_("manifest: %d:%s\n") % |
|
610 | self.ui.write(_("manifest: %d:%s\n") % | |
613 | (self.repo.manifest.rev(mnode), hex(mnode)), |
|
611 | (self.repo.manifest.rev(mnode), hex(mnode)), | |
614 | label='ui.debug log.manifest') |
|
612 | label='ui.debug log.manifest') | |
615 | self.ui.write(_("user: %s\n") % ctx.user(), |
|
613 | self.ui.write(_("user: %s\n") % ctx.user(), | |
616 | label='log.user') |
|
614 | label='log.user') | |
617 | self.ui.write(_("date: %s\n") % date, |
|
615 | self.ui.write(_("date: %s\n") % date, | |
618 | label='log.date') |
|
616 | label='log.date') | |
619 |
|
617 | |||
620 | if self.ui.debugflag: |
|
618 | if self.ui.debugflag: | |
621 | files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
|
619 | files = self.repo.status(log.parents(changenode)[0], changenode)[:3] | |
622 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
620 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
623 | files): |
|
621 | files): | |
624 | if value: |
|
622 | if value: | |
625 | self.ui.write("%-12s %s\n" % (key, " ".join(value)), |
|
623 | self.ui.write("%-12s %s\n" % (key, " ".join(value)), | |
626 | label='ui.debug log.files') |
|
624 | label='ui.debug log.files') | |
627 | elif ctx.files() and self.ui.verbose: |
|
625 | elif ctx.files() and self.ui.verbose: | |
628 | self.ui.write(_("files: %s\n") % " ".join(ctx.files()), |
|
626 | self.ui.write(_("files: %s\n") % " ".join(ctx.files()), | |
629 | label='ui.note log.files') |
|
627 | label='ui.note log.files') | |
630 | if copies and self.ui.verbose: |
|
628 | if copies and self.ui.verbose: | |
631 | copies = ['%s (%s)' % c for c in copies] |
|
629 | copies = ['%s (%s)' % c for c in copies] | |
632 | self.ui.write(_("copies: %s\n") % ' '.join(copies), |
|
630 | self.ui.write(_("copies: %s\n") % ' '.join(copies), | |
633 | label='ui.note log.copies') |
|
631 | label='ui.note log.copies') | |
634 |
|
632 | |||
635 | extra = ctx.extra() |
|
633 | extra = ctx.extra() | |
636 | if extra and self.ui.debugflag: |
|
634 | if extra and self.ui.debugflag: | |
637 | for key, value in sorted(extra.items()): |
|
635 | for key, value in sorted(extra.items()): | |
638 | self.ui.write(_("extra: %s=%s\n") |
|
636 | self.ui.write(_("extra: %s=%s\n") | |
639 | % (key, value.encode('string_escape')), |
|
637 | % (key, value.encode('string_escape')), | |
640 | label='ui.debug log.extra') |
|
638 | label='ui.debug log.extra') | |
641 |
|
639 | |||
642 | description = ctx.description().strip() |
|
640 | description = ctx.description().strip() | |
643 | if description: |
|
641 | if description: | |
644 | if self.ui.verbose: |
|
642 | if self.ui.verbose: | |
645 | self.ui.write(_("description:\n"), |
|
643 | self.ui.write(_("description:\n"), | |
646 | label='ui.note log.description') |
|
644 | label='ui.note log.description') | |
647 | self.ui.write(description, |
|
645 | self.ui.write(description, | |
648 | label='ui.note log.description') |
|
646 | label='ui.note log.description') | |
649 | self.ui.write("\n\n") |
|
647 | self.ui.write("\n\n") | |
650 | else: |
|
648 | else: | |
651 | self.ui.write(_("summary: %s\n") % |
|
649 | self.ui.write(_("summary: %s\n") % | |
652 | description.splitlines()[0], |
|
650 | description.splitlines()[0], | |
653 | label='log.summary') |
|
651 | label='log.summary') | |
654 | self.ui.write("\n") |
|
652 | self.ui.write("\n") | |
655 |
|
653 | |||
656 | self.showpatch(changenode, matchfn) |
|
654 | self.showpatch(changenode, matchfn) | |
657 |
|
655 | |||
658 | def showpatch(self, node, matchfn): |
|
656 | def showpatch(self, node, matchfn): | |
659 | if not matchfn: |
|
657 | if not matchfn: | |
660 | matchfn = self.patch |
|
658 | matchfn = self.patch | |
661 | if matchfn: |
|
659 | if matchfn: | |
662 | stat = self.diffopts.get('stat') |
|
660 | stat = self.diffopts.get('stat') | |
663 | diff = self.diffopts.get('patch') |
|
661 | diff = self.diffopts.get('patch') | |
664 | diffopts = patch.diffopts(self.ui, self.diffopts) |
|
662 | diffopts = patch.diffopts(self.ui, self.diffopts) | |
665 | prev = self.repo.changelog.parents(node)[0] |
|
663 | prev = self.repo.changelog.parents(node)[0] | |
666 | if stat: |
|
664 | if stat: | |
667 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
665 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, | |
668 | match=matchfn, stat=True) |
|
666 | match=matchfn, stat=True) | |
669 | if diff: |
|
667 | if diff: | |
670 | if stat: |
|
668 | if stat: | |
671 | self.ui.write("\n") |
|
669 | self.ui.write("\n") | |
672 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
670 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, | |
673 | match=matchfn, stat=False) |
|
671 | match=matchfn, stat=False) | |
674 | self.ui.write("\n") |
|
672 | self.ui.write("\n") | |
675 |
|
673 | |||
676 | def _meaningful_parentrevs(self, log, rev): |
|
674 | def _meaningful_parentrevs(self, log, rev): | |
677 | """Return list of meaningful (or all if debug) parentrevs for rev. |
|
675 | """Return list of meaningful (or all if debug) parentrevs for rev. | |
678 |
|
676 | |||
679 | For merges (two non-nullrev revisions) both parents are meaningful. |
|
677 | For merges (two non-nullrev revisions) both parents are meaningful. | |
680 | Otherwise the first parent revision is considered meaningful if it |
|
678 | Otherwise the first parent revision is considered meaningful if it | |
681 | is not the preceding revision. |
|
679 | is not the preceding revision. | |
682 | """ |
|
680 | """ | |
683 | parents = log.parentrevs(rev) |
|
681 | parents = log.parentrevs(rev) | |
684 | if not self.ui.debugflag and parents[1] == nullrev: |
|
682 | if not self.ui.debugflag and parents[1] == nullrev: | |
685 | if parents[0] >= rev - 1: |
|
683 | if parents[0] >= rev - 1: | |
686 | parents = [] |
|
684 | parents = [] | |
687 | else: |
|
685 | else: | |
688 | parents = [parents[0]] |
|
686 | parents = [parents[0]] | |
689 | return parents |
|
687 | return parents | |
690 |
|
688 | |||
691 |
|
689 | |||
692 | class changeset_templater(changeset_printer): |
|
690 | class changeset_templater(changeset_printer): | |
693 | '''format changeset information.''' |
|
691 | '''format changeset information.''' | |
694 |
|
692 | |||
695 | def __init__(self, ui, repo, patch, diffopts, mapfile, buffered): |
|
693 | def __init__(self, ui, repo, patch, diffopts, mapfile, buffered): | |
696 | changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered) |
|
694 | changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered) | |
697 | formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) |
|
695 | formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) | |
698 | defaulttempl = { |
|
696 | defaulttempl = { | |
699 | 'parent': '{rev}:{node|formatnode} ', |
|
697 | 'parent': '{rev}:{node|formatnode} ', | |
700 | 'manifest': '{rev}:{node|formatnode}', |
|
698 | 'manifest': '{rev}:{node|formatnode}', | |
701 | 'file_copy': '{name} ({source})', |
|
699 | 'file_copy': '{name} ({source})', | |
702 | 'extra': '{key}={value|stringescape}' |
|
700 | 'extra': '{key}={value|stringescape}' | |
703 | } |
|
701 | } | |
704 | # filecopy is preserved for compatibility reasons |
|
702 | # filecopy is preserved for compatibility reasons | |
705 | defaulttempl['filecopy'] = defaulttempl['file_copy'] |
|
703 | defaulttempl['filecopy'] = defaulttempl['file_copy'] | |
706 | self.t = templater.templater(mapfile, {'formatnode': formatnode}, |
|
704 | self.t = templater.templater(mapfile, {'formatnode': formatnode}, | |
707 | cache=defaulttempl) |
|
705 | cache=defaulttempl) | |
708 | self.cache = {} |
|
706 | self.cache = {} | |
709 |
|
707 | |||
710 | def use_template(self, t): |
|
708 | def use_template(self, t): | |
711 | '''set template string to use''' |
|
709 | '''set template string to use''' | |
712 | self.t.cache['changeset'] = t |
|
710 | self.t.cache['changeset'] = t | |
713 |
|
711 | |||
714 | def _meaningful_parentrevs(self, ctx): |
|
712 | def _meaningful_parentrevs(self, ctx): | |
715 | """Return list of meaningful (or all if debug) parentrevs for rev. |
|
713 | """Return list of meaningful (or all if debug) parentrevs for rev. | |
716 | """ |
|
714 | """ | |
717 | parents = ctx.parents() |
|
715 | parents = ctx.parents() | |
718 | if len(parents) > 1: |
|
716 | if len(parents) > 1: | |
719 | return parents |
|
717 | return parents | |
720 | if self.ui.debugflag: |
|
718 | if self.ui.debugflag: | |
721 | return [parents[0], self.repo['null']] |
|
719 | return [parents[0], self.repo['null']] | |
722 | if parents[0].rev() >= ctx.rev() - 1: |
|
720 | if parents[0].rev() >= ctx.rev() - 1: | |
723 | return [] |
|
721 | return [] | |
724 | return parents |
|
722 | return parents | |
725 |
|
723 | |||
726 | def _show(self, ctx, copies, matchfn, props): |
|
724 | def _show(self, ctx, copies, matchfn, props): | |
727 | '''show a single changeset or file revision''' |
|
725 | '''show a single changeset or file revision''' | |
728 |
|
726 | |||
729 | showlist = templatekw.showlist |
|
727 | showlist = templatekw.showlist | |
730 |
|
728 | |||
731 | # showparents() behaviour depends on ui trace level which |
|
729 | # showparents() behaviour depends on ui trace level which | |
732 | # causes unexpected behaviours at templating level and makes |
|
730 | # causes unexpected behaviours at templating level and makes | |
733 | # it harder to extract it in a standalone function. Its |
|
731 | # it harder to extract it in a standalone function. Its | |
734 | # behaviour cannot be changed so leave it here for now. |
|
732 | # behaviour cannot be changed so leave it here for now. | |
735 | def showparents(**args): |
|
733 | def showparents(**args): | |
736 | ctx = args['ctx'] |
|
734 | ctx = args['ctx'] | |
737 | parents = [[('rev', p.rev()), ('node', p.hex())] |
|
735 | parents = [[('rev', p.rev()), ('node', p.hex())] | |
738 | for p in self._meaningful_parentrevs(ctx)] |
|
736 | for p in self._meaningful_parentrevs(ctx)] | |
739 | return showlist('parent', parents, **args) |
|
737 | return showlist('parent', parents, **args) | |
740 |
|
738 | |||
741 | props = props.copy() |
|
739 | props = props.copy() | |
742 | props.update(templatekw.keywords) |
|
740 | props.update(templatekw.keywords) | |
743 | props['parents'] = showparents |
|
741 | props['parents'] = showparents | |
744 | props['templ'] = self.t |
|
742 | props['templ'] = self.t | |
745 | props['ctx'] = ctx |
|
743 | props['ctx'] = ctx | |
746 | props['repo'] = self.repo |
|
744 | props['repo'] = self.repo | |
747 | props['revcache'] = {'copies': copies} |
|
745 | props['revcache'] = {'copies': copies} | |
748 | props['cache'] = self.cache |
|
746 | props['cache'] = self.cache | |
749 |
|
747 | |||
750 | # find correct templates for current mode |
|
748 | # find correct templates for current mode | |
751 |
|
749 | |||
752 | tmplmodes = [ |
|
750 | tmplmodes = [ | |
753 | (True, None), |
|
751 | (True, None), | |
754 | (self.ui.verbose, 'verbose'), |
|
752 | (self.ui.verbose, 'verbose'), | |
755 | (self.ui.quiet, 'quiet'), |
|
753 | (self.ui.quiet, 'quiet'), | |
756 | (self.ui.debugflag, 'debug'), |
|
754 | (self.ui.debugflag, 'debug'), | |
757 | ] |
|
755 | ] | |
758 |
|
756 | |||
759 | types = {'header': '', 'footer':'', 'changeset': 'changeset'} |
|
757 | types = {'header': '', 'footer':'', 'changeset': 'changeset'} | |
760 | for mode, postfix in tmplmodes: |
|
758 | for mode, postfix in tmplmodes: | |
761 | for type in types: |
|
759 | for type in types: | |
762 | cur = postfix and ('%s_%s' % (type, postfix)) or type |
|
760 | cur = postfix and ('%s_%s' % (type, postfix)) or type | |
763 | if mode and cur in self.t: |
|
761 | if mode and cur in self.t: | |
764 | types[type] = cur |
|
762 | types[type] = cur | |
765 |
|
763 | |||
766 | try: |
|
764 | try: | |
767 |
|
765 | |||
768 | # write header |
|
766 | # write header | |
769 | if types['header']: |
|
767 | if types['header']: | |
770 | h = templater.stringify(self.t(types['header'], **props)) |
|
768 | h = templater.stringify(self.t(types['header'], **props)) | |
771 | if self.buffered: |
|
769 | if self.buffered: | |
772 | self.header[ctx.rev()] = h |
|
770 | self.header[ctx.rev()] = h | |
773 | else: |
|
771 | else: | |
774 | if self.lastheader != h: |
|
772 | if self.lastheader != h: | |
775 | self.lastheader = h |
|
773 | self.lastheader = h | |
776 | self.ui.write(h) |
|
774 | self.ui.write(h) | |
777 |
|
775 | |||
778 | # write changeset metadata, then patch if requested |
|
776 | # write changeset metadata, then patch if requested | |
779 | key = types['changeset'] |
|
777 | key = types['changeset'] | |
780 | self.ui.write(templater.stringify(self.t(key, **props))) |
|
778 | self.ui.write(templater.stringify(self.t(key, **props))) | |
781 | self.showpatch(ctx.node(), matchfn) |
|
779 | self.showpatch(ctx.node(), matchfn) | |
782 |
|
780 | |||
783 | if types['footer']: |
|
781 | if types['footer']: | |
784 | if not self.footer: |
|
782 | if not self.footer: | |
785 | self.footer = templater.stringify(self.t(types['footer'], |
|
783 | self.footer = templater.stringify(self.t(types['footer'], | |
786 | **props)) |
|
784 | **props)) | |
787 |
|
785 | |||
788 | except KeyError, inst: |
|
786 | except KeyError, inst: | |
789 | msg = _("%s: no key named '%s'") |
|
787 | msg = _("%s: no key named '%s'") | |
790 | raise util.Abort(msg % (self.t.mapfile, inst.args[0])) |
|
788 | raise util.Abort(msg % (self.t.mapfile, inst.args[0])) | |
791 | except SyntaxError, inst: |
|
789 | except SyntaxError, inst: | |
792 | raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) |
|
790 | raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) | |
793 |
|
791 | |||
794 | def show_changeset(ui, repo, opts, buffered=False): |
|
792 | def show_changeset(ui, repo, opts, buffered=False): | |
795 | """show one changeset using template or regular display. |
|
793 | """show one changeset using template or regular display. | |
796 |
|
794 | |||
797 | Display format will be the first non-empty hit of: |
|
795 | Display format will be the first non-empty hit of: | |
798 | 1. option 'template' |
|
796 | 1. option 'template' | |
799 | 2. option 'style' |
|
797 | 2. option 'style' | |
800 | 3. [ui] setting 'logtemplate' |
|
798 | 3. [ui] setting 'logtemplate' | |
801 | 4. [ui] setting 'style' |
|
799 | 4. [ui] setting 'style' | |
802 | If all of these values are either the unset or the empty string, |
|
800 | If all of these values are either the unset or the empty string, | |
803 | regular display via changeset_printer() is done. |
|
801 | regular display via changeset_printer() is done. | |
804 | """ |
|
802 | """ | |
805 | # options |
|
803 | # options | |
806 | patch = False |
|
804 | patch = False | |
807 | if opts.get('patch') or opts.get('stat'): |
|
805 | if opts.get('patch') or opts.get('stat'): | |
808 | patch = matchall(repo) |
|
806 | patch = matchall(repo) | |
809 |
|
807 | |||
810 | tmpl = opts.get('template') |
|
808 | tmpl = opts.get('template') | |
811 | style = None |
|
809 | style = None | |
812 | if tmpl: |
|
810 | if tmpl: | |
813 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
811 | tmpl = templater.parsestring(tmpl, quoted=False) | |
814 | else: |
|
812 | else: | |
815 | style = opts.get('style') |
|
813 | style = opts.get('style') | |
816 |
|
814 | |||
817 | # ui settings |
|
815 | # ui settings | |
818 | if not (tmpl or style): |
|
816 | if not (tmpl or style): | |
819 | tmpl = ui.config('ui', 'logtemplate') |
|
817 | tmpl = ui.config('ui', 'logtemplate') | |
820 | if tmpl: |
|
818 | if tmpl: | |
821 | tmpl = templater.parsestring(tmpl) |
|
819 | tmpl = templater.parsestring(tmpl) | |
822 | else: |
|
820 | else: | |
823 | style = util.expandpath(ui.config('ui', 'style', '')) |
|
821 | style = util.expandpath(ui.config('ui', 'style', '')) | |
824 |
|
822 | |||
825 | if not (tmpl or style): |
|
823 | if not (tmpl or style): | |
826 | return changeset_printer(ui, repo, patch, opts, buffered) |
|
824 | return changeset_printer(ui, repo, patch, opts, buffered) | |
827 |
|
825 | |||
828 | mapfile = None |
|
826 | mapfile = None | |
829 | if style and not tmpl: |
|
827 | if style and not tmpl: | |
830 | mapfile = style |
|
828 | mapfile = style | |
831 | if not os.path.split(mapfile)[0]: |
|
829 | if not os.path.split(mapfile)[0]: | |
832 | mapname = (templater.templatepath('map-cmdline.' + mapfile) |
|
830 | mapname = (templater.templatepath('map-cmdline.' + mapfile) | |
833 | or templater.templatepath(mapfile)) |
|
831 | or templater.templatepath(mapfile)) | |
834 | if mapname: |
|
832 | if mapname: | |
835 | mapfile = mapname |
|
833 | mapfile = mapname | |
836 |
|
834 | |||
837 | try: |
|
835 | try: | |
838 | t = changeset_templater(ui, repo, patch, opts, mapfile, buffered) |
|
836 | t = changeset_templater(ui, repo, patch, opts, mapfile, buffered) | |
839 | except SyntaxError, inst: |
|
837 | except SyntaxError, inst: | |
840 | raise util.Abort(inst.args[0]) |
|
838 | raise util.Abort(inst.args[0]) | |
841 | if tmpl: |
|
839 | if tmpl: | |
842 | t.use_template(tmpl) |
|
840 | t.use_template(tmpl) | |
843 | return t |
|
841 | return t | |
844 |
|
842 | |||
845 | def finddate(ui, repo, date): |
|
843 | def finddate(ui, repo, date): | |
846 | """Find the tipmost changeset that matches the given date spec""" |
|
844 | """Find the tipmost changeset that matches the given date spec""" | |
847 |
|
845 | |||
848 | df = util.matchdate(date) |
|
846 | df = util.matchdate(date) | |
849 | m = matchall(repo) |
|
847 | m = matchall(repo) | |
850 | results = {} |
|
848 | results = {} | |
851 |
|
849 | |||
852 | def prep(ctx, fns): |
|
850 | def prep(ctx, fns): | |
853 | d = ctx.date() |
|
851 | d = ctx.date() | |
854 | if df(d[0]): |
|
852 | if df(d[0]): | |
855 | results[ctx.rev()] = d |
|
853 | results[ctx.rev()] = d | |
856 |
|
854 | |||
857 | for ctx in walkchangerevs(repo, m, {'rev': None}, prep): |
|
855 | for ctx in walkchangerevs(repo, m, {'rev': None}, prep): | |
858 | rev = ctx.rev() |
|
856 | rev = ctx.rev() | |
859 | if rev in results: |
|
857 | if rev in results: | |
860 | ui.status(_("Found revision %s from %s\n") % |
|
858 | ui.status(_("Found revision %s from %s\n") % | |
861 | (rev, util.datestr(results[rev]))) |
|
859 | (rev, util.datestr(results[rev]))) | |
862 | return str(rev) |
|
860 | return str(rev) | |
863 |
|
861 | |||
864 | raise util.Abort(_("revision matching date not found")) |
|
862 | raise util.Abort(_("revision matching date not found")) | |
865 |
|
863 | |||
866 | def walkchangerevs(repo, match, opts, prepare): |
|
864 | def walkchangerevs(repo, match, opts, prepare): | |
867 | '''Iterate over files and the revs in which they changed. |
|
865 | '''Iterate over files and the revs in which they changed. | |
868 |
|
866 | |||
869 | Callers most commonly need to iterate backwards over the history |
|
867 | Callers most commonly need to iterate backwards over the history | |
870 | in which they are interested. Doing so has awful (quadratic-looking) |
|
868 | in which they are interested. Doing so has awful (quadratic-looking) | |
871 | performance, so we use iterators in a "windowed" way. |
|
869 | performance, so we use iterators in a "windowed" way. | |
872 |
|
870 | |||
873 | We walk a window of revisions in the desired order. Within the |
|
871 | We walk a window of revisions in the desired order. Within the | |
874 | window, we first walk forwards to gather data, then in the desired |
|
872 | window, we first walk forwards to gather data, then in the desired | |
875 | order (usually backwards) to display it. |
|
873 | order (usually backwards) to display it. | |
876 |
|
874 | |||
877 | This function returns an iterator yielding contexts. Before |
|
875 | This function returns an iterator yielding contexts. Before | |
878 | yielding each context, the iterator will first call the prepare |
|
876 | yielding each context, the iterator will first call the prepare | |
879 | function on each context in the window in forward order.''' |
|
877 | function on each context in the window in forward order.''' | |
880 |
|
878 | |||
881 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
879 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
882 | if start < end: |
|
880 | if start < end: | |
883 | while start < end: |
|
881 | while start < end: | |
884 | yield start, min(windowsize, end - start) |
|
882 | yield start, min(windowsize, end - start) | |
885 | start += windowsize |
|
883 | start += windowsize | |
886 | if windowsize < sizelimit: |
|
884 | if windowsize < sizelimit: | |
887 | windowsize *= 2 |
|
885 | windowsize *= 2 | |
888 | else: |
|
886 | else: | |
889 | while start > end: |
|
887 | while start > end: | |
890 | yield start, min(windowsize, start - end - 1) |
|
888 | yield start, min(windowsize, start - end - 1) | |
891 | start -= windowsize |
|
889 | start -= windowsize | |
892 | if windowsize < sizelimit: |
|
890 | if windowsize < sizelimit: | |
893 | windowsize *= 2 |
|
891 | windowsize *= 2 | |
894 |
|
892 | |||
895 | follow = opts.get('follow') or opts.get('follow_first') |
|
893 | follow = opts.get('follow') or opts.get('follow_first') | |
896 |
|
894 | |||
897 | if not len(repo): |
|
895 | if not len(repo): | |
898 | return [] |
|
896 | return [] | |
899 |
|
897 | |||
900 | if follow: |
|
898 | if follow: | |
901 | defrange = '%s:0' % repo['.'].rev() |
|
899 | defrange = '%s:0' % repo['.'].rev() | |
902 | else: |
|
900 | else: | |
903 | defrange = '-1:0' |
|
901 | defrange = '-1:0' | |
904 | revs = scmutil.revrange(repo, opts['rev'] or [defrange]) |
|
902 | revs = scmutil.revrange(repo, opts['rev'] or [defrange]) | |
905 | if not revs: |
|
903 | if not revs: | |
906 | return [] |
|
904 | return [] | |
907 | wanted = set() |
|
905 | wanted = set() | |
908 | slowpath = match.anypats() or (match.files() and opts.get('removed')) |
|
906 | slowpath = match.anypats() or (match.files() and opts.get('removed')) | |
909 | fncache = {} |
|
907 | fncache = {} | |
910 | change = util.cachefunc(repo.changectx) |
|
908 | change = util.cachefunc(repo.changectx) | |
911 |
|
909 | |||
912 | # First step is to fill wanted, the set of revisions that we want to yield. |
|
910 | # First step is to fill wanted, the set of revisions that we want to yield. | |
913 | # When it does not induce extra cost, we also fill fncache for revisions in |
|
911 | # When it does not induce extra cost, we also fill fncache for revisions in | |
914 | # wanted: a cache of filenames that were changed (ctx.files()) and that |
|
912 | # wanted: a cache of filenames that were changed (ctx.files()) and that | |
915 | # match the file filtering conditions. |
|
913 | # match the file filtering conditions. | |
916 |
|
914 | |||
917 | if not slowpath and not match.files(): |
|
915 | if not slowpath and not match.files(): | |
918 | # No files, no patterns. Display all revs. |
|
916 | # No files, no patterns. Display all revs. | |
919 | wanted = set(revs) |
|
917 | wanted = set(revs) | |
920 | copies = [] |
|
918 | copies = [] | |
921 |
|
919 | |||
922 | if not slowpath: |
|
920 | if not slowpath: | |
923 | # We only have to read through the filelog to find wanted revisions |
|
921 | # We only have to read through the filelog to find wanted revisions | |
924 |
|
922 | |||
925 | minrev, maxrev = min(revs), max(revs) |
|
923 | minrev, maxrev = min(revs), max(revs) | |
926 | def filerevgen(filelog, last): |
|
924 | def filerevgen(filelog, last): | |
927 | """ |
|
925 | """ | |
928 | Only files, no patterns. Check the history of each file. |
|
926 | Only files, no patterns. Check the history of each file. | |
929 |
|
927 | |||
930 | Examines filelog entries within minrev, maxrev linkrev range |
|
928 | Examines filelog entries within minrev, maxrev linkrev range | |
931 | Returns an iterator yielding (linkrev, parentlinkrevs, copied) |
|
929 | Returns an iterator yielding (linkrev, parentlinkrevs, copied) | |
932 | tuples in backwards order |
|
930 | tuples in backwards order | |
933 | """ |
|
931 | """ | |
934 | cl_count = len(repo) |
|
932 | cl_count = len(repo) | |
935 | revs = [] |
|
933 | revs = [] | |
936 | for j in xrange(0, last + 1): |
|
934 | for j in xrange(0, last + 1): | |
937 | linkrev = filelog.linkrev(j) |
|
935 | linkrev = filelog.linkrev(j) | |
938 | if linkrev < minrev: |
|
936 | if linkrev < minrev: | |
939 | continue |
|
937 | continue | |
940 | # only yield rev for which we have the changelog, it can |
|
938 | # only yield rev for which we have the changelog, it can | |
941 | # happen while doing "hg log" during a pull or commit |
|
939 | # happen while doing "hg log" during a pull or commit | |
942 | if linkrev >= cl_count: |
|
940 | if linkrev >= cl_count: | |
943 | break |
|
941 | break | |
944 |
|
942 | |||
945 | parentlinkrevs = [] |
|
943 | parentlinkrevs = [] | |
946 | for p in filelog.parentrevs(j): |
|
944 | for p in filelog.parentrevs(j): | |
947 | if p != nullrev: |
|
945 | if p != nullrev: | |
948 | parentlinkrevs.append(filelog.linkrev(p)) |
|
946 | parentlinkrevs.append(filelog.linkrev(p)) | |
949 | n = filelog.node(j) |
|
947 | n = filelog.node(j) | |
950 | revs.append((linkrev, parentlinkrevs, |
|
948 | revs.append((linkrev, parentlinkrevs, | |
951 | follow and filelog.renamed(n))) |
|
949 | follow and filelog.renamed(n))) | |
952 |
|
950 | |||
953 | return reversed(revs) |
|
951 | return reversed(revs) | |
954 | def iterfiles(): |
|
952 | def iterfiles(): | |
955 | for filename in match.files(): |
|
953 | for filename in match.files(): | |
956 | yield filename, None |
|
954 | yield filename, None | |
957 | for filename_node in copies: |
|
955 | for filename_node in copies: | |
958 | yield filename_node |
|
956 | yield filename_node | |
959 | for file_, node in iterfiles(): |
|
957 | for file_, node in iterfiles(): | |
960 | filelog = repo.file(file_) |
|
958 | filelog = repo.file(file_) | |
961 | if not len(filelog): |
|
959 | if not len(filelog): | |
962 | if node is None: |
|
960 | if node is None: | |
963 | # A zero count may be a directory or deleted file, so |
|
961 | # A zero count may be a directory or deleted file, so | |
964 | # try to find matching entries on the slow path. |
|
962 | # try to find matching entries on the slow path. | |
965 | if follow: |
|
963 | if follow: | |
966 | raise util.Abort( |
|
964 | raise util.Abort( | |
967 | _('cannot follow nonexistent file: "%s"') % file_) |
|
965 | _('cannot follow nonexistent file: "%s"') % file_) | |
968 | slowpath = True |
|
966 | slowpath = True | |
969 | break |
|
967 | break | |
970 | else: |
|
968 | else: | |
971 | continue |
|
969 | continue | |
972 |
|
970 | |||
973 | if node is None: |
|
971 | if node is None: | |
974 | last = len(filelog) - 1 |
|
972 | last = len(filelog) - 1 | |
975 | else: |
|
973 | else: | |
976 | last = filelog.rev(node) |
|
974 | last = filelog.rev(node) | |
977 |
|
975 | |||
978 |
|
976 | |||
979 | # keep track of all ancestors of the file |
|
977 | # keep track of all ancestors of the file | |
980 | ancestors = set([filelog.linkrev(last)]) |
|
978 | ancestors = set([filelog.linkrev(last)]) | |
981 |
|
979 | |||
982 | # iterate from latest to oldest revision |
|
980 | # iterate from latest to oldest revision | |
983 | for rev, flparentlinkrevs, copied in filerevgen(filelog, last): |
|
981 | for rev, flparentlinkrevs, copied in filerevgen(filelog, last): | |
984 | if not follow: |
|
982 | if not follow: | |
985 | if rev > maxrev: |
|
983 | if rev > maxrev: | |
986 | continue |
|
984 | continue | |
987 | else: |
|
985 | else: | |
988 | # Note that last might not be the first interesting |
|
986 | # Note that last might not be the first interesting | |
989 | # rev to us: |
|
987 | # rev to us: | |
990 | # if the file has been changed after maxrev, we'll |
|
988 | # if the file has been changed after maxrev, we'll | |
991 | # have linkrev(last) > maxrev, and we still need |
|
989 | # have linkrev(last) > maxrev, and we still need | |
992 | # to explore the file graph |
|
990 | # to explore the file graph | |
993 | if rev not in ancestors: |
|
991 | if rev not in ancestors: | |
994 | continue |
|
992 | continue | |
995 | # XXX insert 1327 fix here |
|
993 | # XXX insert 1327 fix here | |
996 | if flparentlinkrevs: |
|
994 | if flparentlinkrevs: | |
997 | ancestors.update(flparentlinkrevs) |
|
995 | ancestors.update(flparentlinkrevs) | |
998 |
|
996 | |||
999 | fncache.setdefault(rev, []).append(file_) |
|
997 | fncache.setdefault(rev, []).append(file_) | |
1000 | wanted.add(rev) |
|
998 | wanted.add(rev) | |
1001 | if copied: |
|
999 | if copied: | |
1002 | copies.append(copied) |
|
1000 | copies.append(copied) | |
1003 | if slowpath: |
|
1001 | if slowpath: | |
1004 | # We have to read the changelog to match filenames against |
|
1002 | # We have to read the changelog to match filenames against | |
1005 | # changed files |
|
1003 | # changed files | |
1006 |
|
1004 | |||
1007 | if follow: |
|
1005 | if follow: | |
1008 | raise util.Abort(_('can only follow copies/renames for explicit ' |
|
1006 | raise util.Abort(_('can only follow copies/renames for explicit ' | |
1009 | 'filenames')) |
|
1007 | 'filenames')) | |
1010 |
|
1008 | |||
1011 | # The slow path checks files modified in every changeset. |
|
1009 | # The slow path checks files modified in every changeset. | |
1012 | for i in sorted(revs): |
|
1010 | for i in sorted(revs): | |
1013 | ctx = change(i) |
|
1011 | ctx = change(i) | |
1014 | matches = filter(match, ctx.files()) |
|
1012 | matches = filter(match, ctx.files()) | |
1015 | if matches: |
|
1013 | if matches: | |
1016 | fncache[i] = matches |
|
1014 | fncache[i] = matches | |
1017 | wanted.add(i) |
|
1015 | wanted.add(i) | |
1018 |
|
1016 | |||
1019 | class followfilter(object): |
|
1017 | class followfilter(object): | |
1020 | def __init__(self, onlyfirst=False): |
|
1018 | def __init__(self, onlyfirst=False): | |
1021 | self.startrev = nullrev |
|
1019 | self.startrev = nullrev | |
1022 | self.roots = set() |
|
1020 | self.roots = set() | |
1023 | self.onlyfirst = onlyfirst |
|
1021 | self.onlyfirst = onlyfirst | |
1024 |
|
1022 | |||
1025 | def match(self, rev): |
|
1023 | def match(self, rev): | |
1026 | def realparents(rev): |
|
1024 | def realparents(rev): | |
1027 | if self.onlyfirst: |
|
1025 | if self.onlyfirst: | |
1028 | return repo.changelog.parentrevs(rev)[0:1] |
|
1026 | return repo.changelog.parentrevs(rev)[0:1] | |
1029 | else: |
|
1027 | else: | |
1030 | return filter(lambda x: x != nullrev, |
|
1028 | return filter(lambda x: x != nullrev, | |
1031 | repo.changelog.parentrevs(rev)) |
|
1029 | repo.changelog.parentrevs(rev)) | |
1032 |
|
1030 | |||
1033 | if self.startrev == nullrev: |
|
1031 | if self.startrev == nullrev: | |
1034 | self.startrev = rev |
|
1032 | self.startrev = rev | |
1035 | return True |
|
1033 | return True | |
1036 |
|
1034 | |||
1037 | if rev > self.startrev: |
|
1035 | if rev > self.startrev: | |
1038 | # forward: all descendants |
|
1036 | # forward: all descendants | |
1039 | if not self.roots: |
|
1037 | if not self.roots: | |
1040 | self.roots.add(self.startrev) |
|
1038 | self.roots.add(self.startrev) | |
1041 | for parent in realparents(rev): |
|
1039 | for parent in realparents(rev): | |
1042 | if parent in self.roots: |
|
1040 | if parent in self.roots: | |
1043 | self.roots.add(rev) |
|
1041 | self.roots.add(rev) | |
1044 | return True |
|
1042 | return True | |
1045 | else: |
|
1043 | else: | |
1046 | # backwards: all parents |
|
1044 | # backwards: all parents | |
1047 | if not self.roots: |
|
1045 | if not self.roots: | |
1048 | self.roots.update(realparents(self.startrev)) |
|
1046 | self.roots.update(realparents(self.startrev)) | |
1049 | if rev in self.roots: |
|
1047 | if rev in self.roots: | |
1050 | self.roots.remove(rev) |
|
1048 | self.roots.remove(rev) | |
1051 | self.roots.update(realparents(rev)) |
|
1049 | self.roots.update(realparents(rev)) | |
1052 | return True |
|
1050 | return True | |
1053 |
|
1051 | |||
1054 | return False |
|
1052 | return False | |
1055 |
|
1053 | |||
1056 | # it might be worthwhile to do this in the iterator if the rev range |
|
1054 | # it might be worthwhile to do this in the iterator if the rev range | |
1057 | # is descending and the prune args are all within that range |
|
1055 | # is descending and the prune args are all within that range | |
1058 | for rev in opts.get('prune', ()): |
|
1056 | for rev in opts.get('prune', ()): | |
1059 | rev = repo.changelog.rev(repo.lookup(rev)) |
|
1057 | rev = repo.changelog.rev(repo.lookup(rev)) | |
1060 | ff = followfilter() |
|
1058 | ff = followfilter() | |
1061 | stop = min(revs[0], revs[-1]) |
|
1059 | stop = min(revs[0], revs[-1]) | |
1062 | for x in xrange(rev, stop - 1, -1): |
|
1060 | for x in xrange(rev, stop - 1, -1): | |
1063 | if ff.match(x): |
|
1061 | if ff.match(x): | |
1064 | wanted.discard(x) |
|
1062 | wanted.discard(x) | |
1065 |
|
1063 | |||
1066 | # Now that wanted is correctly initialized, we can iterate over the |
|
1064 | # Now that wanted is correctly initialized, we can iterate over the | |
1067 | # revision range, yielding only revisions in wanted. |
|
1065 | # revision range, yielding only revisions in wanted. | |
1068 | def iterate(): |
|
1066 | def iterate(): | |
1069 | if follow and not match.files(): |
|
1067 | if follow and not match.files(): | |
1070 | ff = followfilter(onlyfirst=opts.get('follow_first')) |
|
1068 | ff = followfilter(onlyfirst=opts.get('follow_first')) | |
1071 | def want(rev): |
|
1069 | def want(rev): | |
1072 | return ff.match(rev) and rev in wanted |
|
1070 | return ff.match(rev) and rev in wanted | |
1073 | else: |
|
1071 | else: | |
1074 | def want(rev): |
|
1072 | def want(rev): | |
1075 | return rev in wanted |
|
1073 | return rev in wanted | |
1076 |
|
1074 | |||
1077 | for i, window in increasing_windows(0, len(revs)): |
|
1075 | for i, window in increasing_windows(0, len(revs)): | |
1078 | nrevs = [rev for rev in revs[i:i + window] if want(rev)] |
|
1076 | nrevs = [rev for rev in revs[i:i + window] if want(rev)] | |
1079 | for rev in sorted(nrevs): |
|
1077 | for rev in sorted(nrevs): | |
1080 | fns = fncache.get(rev) |
|
1078 | fns = fncache.get(rev) | |
1081 | ctx = change(rev) |
|
1079 | ctx = change(rev) | |
1082 | if not fns: |
|
1080 | if not fns: | |
1083 | def fns_generator(): |
|
1081 | def fns_generator(): | |
1084 | for f in ctx.files(): |
|
1082 | for f in ctx.files(): | |
1085 | if match(f): |
|
1083 | if match(f): | |
1086 | yield f |
|
1084 | yield f | |
1087 | fns = fns_generator() |
|
1085 | fns = fns_generator() | |
1088 | prepare(ctx, fns) |
|
1086 | prepare(ctx, fns) | |
1089 | for rev in nrevs: |
|
1087 | for rev in nrevs: | |
1090 | yield change(rev) |
|
1088 | yield change(rev) | |
1091 | return iterate() |
|
1089 | return iterate() | |
1092 |
|
1090 | |||
1093 | def add(ui, repo, match, dryrun, listsubrepos, prefix): |
|
1091 | def add(ui, repo, match, dryrun, listsubrepos, prefix): | |
1094 | join = lambda f: os.path.join(prefix, f) |
|
1092 | join = lambda f: os.path.join(prefix, f) | |
1095 | bad = [] |
|
1093 | bad = [] | |
1096 | oldbad = match.bad |
|
1094 | oldbad = match.bad | |
1097 | match.bad = lambda x, y: bad.append(x) or oldbad(x, y) |
|
1095 | match.bad = lambda x, y: bad.append(x) or oldbad(x, y) | |
1098 | names = [] |
|
1096 | names = [] | |
1099 | wctx = repo[None] |
|
1097 | wctx = repo[None] | |
1100 | cca = None |
|
1098 | cca = None | |
1101 | abort, warn = scmutil.checkportabilityalert(ui) |
|
1099 | abort, warn = scmutil.checkportabilityalert(ui) | |
1102 | if abort or warn: |
|
1100 | if abort or warn: | |
1103 | cca = scmutil.casecollisionauditor(ui, abort, wctx) |
|
1101 | cca = scmutil.casecollisionauditor(ui, abort, wctx) | |
1104 | for f in repo.walk(match): |
|
1102 | for f in repo.walk(match): | |
1105 | exact = match.exact(f) |
|
1103 | exact = match.exact(f) | |
1106 | if exact or f not in repo.dirstate: |
|
1104 | if exact or f not in repo.dirstate: | |
1107 | if cca: |
|
1105 | if cca: | |
1108 | cca(f) |
|
1106 | cca(f) | |
1109 | names.append(f) |
|
1107 | names.append(f) | |
1110 | if ui.verbose or not exact: |
|
1108 | if ui.verbose or not exact: | |
1111 | ui.status(_('adding %s\n') % match.rel(join(f))) |
|
1109 | ui.status(_('adding %s\n') % match.rel(join(f))) | |
1112 |
|
1110 | |||
1113 | if listsubrepos: |
|
1111 | if listsubrepos: | |
1114 | for subpath in wctx.substate: |
|
1112 | for subpath in wctx.substate: | |
1115 | sub = wctx.sub(subpath) |
|
1113 | sub = wctx.sub(subpath) | |
1116 | try: |
|
1114 | try: | |
1117 | submatch = matchmod.narrowmatcher(subpath, match) |
|
1115 | submatch = matchmod.narrowmatcher(subpath, match) | |
1118 | bad.extend(sub.add(ui, submatch, dryrun, prefix)) |
|
1116 | bad.extend(sub.add(ui, submatch, dryrun, prefix)) | |
1119 | except error.LookupError: |
|
1117 | except error.LookupError: | |
1120 | ui.status(_("skipping missing subrepository: %s\n") |
|
1118 | ui.status(_("skipping missing subrepository: %s\n") | |
1121 | % join(subpath)) |
|
1119 | % join(subpath)) | |
1122 |
|
1120 | |||
1123 | if not dryrun: |
|
1121 | if not dryrun: | |
1124 | rejected = wctx.add(names, prefix) |
|
1122 | rejected = wctx.add(names, prefix) | |
1125 | bad.extend(f for f in rejected if f in match.files()) |
|
1123 | bad.extend(f for f in rejected if f in match.files()) | |
1126 | return bad |
|
1124 | return bad | |
1127 |
|
1125 | |||
1128 | def commit(ui, repo, commitfunc, pats, opts): |
|
1126 | def commit(ui, repo, commitfunc, pats, opts): | |
1129 | '''commit the specified files or all outstanding changes''' |
|
1127 | '''commit the specified files or all outstanding changes''' | |
1130 | date = opts.get('date') |
|
1128 | date = opts.get('date') | |
1131 | if date: |
|
1129 | if date: | |
1132 | opts['date'] = util.parsedate(date) |
|
1130 | opts['date'] = util.parsedate(date) | |
1133 | message = logmessage(opts) |
|
1131 | message = logmessage(opts) | |
1134 |
|
1132 | |||
1135 | # extract addremove carefully -- this function can be called from a command |
|
1133 | # extract addremove carefully -- this function can be called from a command | |
1136 | # that doesn't support addremove |
|
1134 | # that doesn't support addremove | |
1137 | if opts.get('addremove'): |
|
1135 | if opts.get('addremove'): | |
1138 | addremove(repo, pats, opts) |
|
1136 | scmutil.addremove(repo, pats, opts) | |
1139 |
|
1137 | |||
1140 | return commitfunc(ui, repo, message, match(repo, pats, opts), opts) |
|
1138 | return commitfunc(ui, repo, message, match(repo, pats, opts), opts) | |
1141 |
|
1139 | |||
1142 | def commiteditor(repo, ctx, subs): |
|
1140 | def commiteditor(repo, ctx, subs): | |
1143 | if ctx.description(): |
|
1141 | if ctx.description(): | |
1144 | return ctx.description() |
|
1142 | return ctx.description() | |
1145 | return commitforceeditor(repo, ctx, subs) |
|
1143 | return commitforceeditor(repo, ctx, subs) | |
1146 |
|
1144 | |||
1147 | def commitforceeditor(repo, ctx, subs): |
|
1145 | def commitforceeditor(repo, ctx, subs): | |
1148 | edittext = [] |
|
1146 | edittext = [] | |
1149 | modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() |
|
1147 | modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() | |
1150 | if ctx.description(): |
|
1148 | if ctx.description(): | |
1151 | edittext.append(ctx.description()) |
|
1149 | edittext.append(ctx.description()) | |
1152 | edittext.append("") |
|
1150 | edittext.append("") | |
1153 | edittext.append("") # Empty line between message and comments. |
|
1151 | edittext.append("") # Empty line between message and comments. | |
1154 | edittext.append(_("HG: Enter commit message." |
|
1152 | edittext.append(_("HG: Enter commit message." | |
1155 | " Lines beginning with 'HG:' are removed.")) |
|
1153 | " Lines beginning with 'HG:' are removed.")) | |
1156 | edittext.append(_("HG: Leave message empty to abort commit.")) |
|
1154 | edittext.append(_("HG: Leave message empty to abort commit.")) | |
1157 | edittext.append("HG: --") |
|
1155 | edittext.append("HG: --") | |
1158 | edittext.append(_("HG: user: %s") % ctx.user()) |
|
1156 | edittext.append(_("HG: user: %s") % ctx.user()) | |
1159 | if ctx.p2(): |
|
1157 | if ctx.p2(): | |
1160 | edittext.append(_("HG: branch merge")) |
|
1158 | edittext.append(_("HG: branch merge")) | |
1161 | if ctx.branch(): |
|
1159 | if ctx.branch(): | |
1162 | edittext.append(_("HG: branch '%s'") % ctx.branch()) |
|
1160 | edittext.append(_("HG: branch '%s'") % ctx.branch()) | |
1163 | edittext.extend([_("HG: subrepo %s") % s for s in subs]) |
|
1161 | edittext.extend([_("HG: subrepo %s") % s for s in subs]) | |
1164 | edittext.extend([_("HG: added %s") % f for f in added]) |
|
1162 | edittext.extend([_("HG: added %s") % f for f in added]) | |
1165 | edittext.extend([_("HG: changed %s") % f for f in modified]) |
|
1163 | edittext.extend([_("HG: changed %s") % f for f in modified]) | |
1166 | edittext.extend([_("HG: removed %s") % f for f in removed]) |
|
1164 | edittext.extend([_("HG: removed %s") % f for f in removed]) | |
1167 | if not added and not modified and not removed: |
|
1165 | if not added and not modified and not removed: | |
1168 | edittext.append(_("HG: no files changed")) |
|
1166 | edittext.append(_("HG: no files changed")) | |
1169 | edittext.append("") |
|
1167 | edittext.append("") | |
1170 | # run editor in the repository root |
|
1168 | # run editor in the repository root | |
1171 | olddir = os.getcwd() |
|
1169 | olddir = os.getcwd() | |
1172 | os.chdir(repo.root) |
|
1170 | os.chdir(repo.root) | |
1173 | text = repo.ui.edit("\n".join(edittext), ctx.user()) |
|
1171 | text = repo.ui.edit("\n".join(edittext), ctx.user()) | |
1174 | text = re.sub("(?m)^HG:.*(\n|$)", "", text) |
|
1172 | text = re.sub("(?m)^HG:.*(\n|$)", "", text) | |
1175 | os.chdir(olddir) |
|
1173 | os.chdir(olddir) | |
1176 |
|
1174 | |||
1177 | if not text.strip(): |
|
1175 | if not text.strip(): | |
1178 | raise util.Abort(_("empty commit message")) |
|
1176 | raise util.Abort(_("empty commit message")) | |
1179 |
|
1177 | |||
1180 | return text |
|
1178 | return text | |
1181 |
|
1179 | |||
1182 | def command(table): |
|
1180 | def command(table): | |
1183 | '''returns a function object bound to table which can be used as |
|
1181 | '''returns a function object bound to table which can be used as | |
1184 | a decorator for populating table as a command table''' |
|
1182 | a decorator for populating table as a command table''' | |
1185 |
|
1183 | |||
1186 | def cmd(name, options, synopsis=None): |
|
1184 | def cmd(name, options, synopsis=None): | |
1187 | def decorator(func): |
|
1185 | def decorator(func): | |
1188 | if synopsis: |
|
1186 | if synopsis: | |
1189 | table[name] = func, options, synopsis |
|
1187 | table[name] = func, options, synopsis | |
1190 | else: |
|
1188 | else: | |
1191 | table[name] = func, options |
|
1189 | table[name] = func, options | |
1192 | return func |
|
1190 | return func | |
1193 | return decorator |
|
1191 | return decorator | |
1194 |
|
1192 | |||
1195 | return cmd |
|
1193 | return cmd |
@@ -1,5022 +1,5022 b'' | |||||
1 | # commands.py - command processing for mercurial |
|
1 | # commands.py - command processing for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from node import hex, bin, nullid, nullrev, short |
|
8 | from node import hex, bin, nullid, nullrev, short | |
9 | from lock import release |
|
9 | from lock import release | |
10 | from i18n import _, gettext |
|
10 | from i18n import _, gettext | |
11 | import os, re, sys, difflib, time, tempfile |
|
11 | import os, re, sys, difflib, time, tempfile | |
12 | import hg, scmutil, util, revlog, extensions, copies, error, bookmarks |
|
12 | import hg, scmutil, util, revlog, extensions, copies, error, bookmarks | |
13 | import patch, help, url, encoding, templatekw, discovery |
|
13 | import patch, help, url, encoding, templatekw, discovery | |
14 | import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server |
|
14 | import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server | |
15 | import merge as mergemod |
|
15 | import merge as mergemod | |
16 | import minirst, revset |
|
16 | import minirst, revset | |
17 | import dagparser, context, simplemerge |
|
17 | import dagparser, context, simplemerge | |
18 | import random, setdiscovery, treediscovery, dagutil |
|
18 | import random, setdiscovery, treediscovery, dagutil | |
19 |
|
19 | |||
20 | table = {} |
|
20 | table = {} | |
21 |
|
21 | |||
22 | command = cmdutil.command(table) |
|
22 | command = cmdutil.command(table) | |
23 |
|
23 | |||
24 | # common command options |
|
24 | # common command options | |
25 |
|
25 | |||
26 | globalopts = [ |
|
26 | globalopts = [ | |
27 | ('R', 'repository', '', |
|
27 | ('R', 'repository', '', | |
28 | _('repository root directory or name of overlay bundle file'), |
|
28 | _('repository root directory or name of overlay bundle file'), | |
29 | _('REPO')), |
|
29 | _('REPO')), | |
30 | ('', 'cwd', '', |
|
30 | ('', 'cwd', '', | |
31 | _('change working directory'), _('DIR')), |
|
31 | _('change working directory'), _('DIR')), | |
32 | ('y', 'noninteractive', None, |
|
32 | ('y', 'noninteractive', None, | |
33 | _('do not prompt, assume \'yes\' for any required answers')), |
|
33 | _('do not prompt, assume \'yes\' for any required answers')), | |
34 | ('q', 'quiet', None, _('suppress output')), |
|
34 | ('q', 'quiet', None, _('suppress output')), | |
35 | ('v', 'verbose', None, _('enable additional output')), |
|
35 | ('v', 'verbose', None, _('enable additional output')), | |
36 | ('', 'config', [], |
|
36 | ('', 'config', [], | |
37 | _('set/override config option (use \'section.name=value\')'), |
|
37 | _('set/override config option (use \'section.name=value\')'), | |
38 | _('CONFIG')), |
|
38 | _('CONFIG')), | |
39 | ('', 'debug', None, _('enable debugging output')), |
|
39 | ('', 'debug', None, _('enable debugging output')), | |
40 | ('', 'debugger', None, _('start debugger')), |
|
40 | ('', 'debugger', None, _('start debugger')), | |
41 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), |
|
41 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), | |
42 | _('ENCODE')), |
|
42 | _('ENCODE')), | |
43 | ('', 'encodingmode', encoding.encodingmode, |
|
43 | ('', 'encodingmode', encoding.encodingmode, | |
44 | _('set the charset encoding mode'), _('MODE')), |
|
44 | _('set the charset encoding mode'), _('MODE')), | |
45 | ('', 'traceback', None, _('always print a traceback on exception')), |
|
45 | ('', 'traceback', None, _('always print a traceback on exception')), | |
46 | ('', 'time', None, _('time how long the command takes')), |
|
46 | ('', 'time', None, _('time how long the command takes')), | |
47 | ('', 'profile', None, _('print command execution profile')), |
|
47 | ('', 'profile', None, _('print command execution profile')), | |
48 | ('', 'version', None, _('output version information and exit')), |
|
48 | ('', 'version', None, _('output version information and exit')), | |
49 | ('h', 'help', None, _('display help and exit')), |
|
49 | ('h', 'help', None, _('display help and exit')), | |
50 | ] |
|
50 | ] | |
51 |
|
51 | |||
52 | dryrunopts = [('n', 'dry-run', None, |
|
52 | dryrunopts = [('n', 'dry-run', None, | |
53 | _('do not perform actions, just print output'))] |
|
53 | _('do not perform actions, just print output'))] | |
54 |
|
54 | |||
55 | remoteopts = [ |
|
55 | remoteopts = [ | |
56 | ('e', 'ssh', '', |
|
56 | ('e', 'ssh', '', | |
57 | _('specify ssh command to use'), _('CMD')), |
|
57 | _('specify ssh command to use'), _('CMD')), | |
58 | ('', 'remotecmd', '', |
|
58 | ('', 'remotecmd', '', | |
59 | _('specify hg command to run on the remote side'), _('CMD')), |
|
59 | _('specify hg command to run on the remote side'), _('CMD')), | |
60 | ('', 'insecure', None, |
|
60 | ('', 'insecure', None, | |
61 | _('do not verify server certificate (ignoring web.cacerts config)')), |
|
61 | _('do not verify server certificate (ignoring web.cacerts config)')), | |
62 | ] |
|
62 | ] | |
63 |
|
63 | |||
64 | walkopts = [ |
|
64 | walkopts = [ | |
65 | ('I', 'include', [], |
|
65 | ('I', 'include', [], | |
66 | _('include names matching the given patterns'), _('PATTERN')), |
|
66 | _('include names matching the given patterns'), _('PATTERN')), | |
67 | ('X', 'exclude', [], |
|
67 | ('X', 'exclude', [], | |
68 | _('exclude names matching the given patterns'), _('PATTERN')), |
|
68 | _('exclude names matching the given patterns'), _('PATTERN')), | |
69 | ] |
|
69 | ] | |
70 |
|
70 | |||
71 | commitopts = [ |
|
71 | commitopts = [ | |
72 | ('m', 'message', '', |
|
72 | ('m', 'message', '', | |
73 | _('use text as commit message'), _('TEXT')), |
|
73 | _('use text as commit message'), _('TEXT')), | |
74 | ('l', 'logfile', '', |
|
74 | ('l', 'logfile', '', | |
75 | _('read commit message from file'), _('FILE')), |
|
75 | _('read commit message from file'), _('FILE')), | |
76 | ] |
|
76 | ] | |
77 |
|
77 | |||
78 | commitopts2 = [ |
|
78 | commitopts2 = [ | |
79 | ('d', 'date', '', |
|
79 | ('d', 'date', '', | |
80 | _('record the specified date as commit date'), _('DATE')), |
|
80 | _('record the specified date as commit date'), _('DATE')), | |
81 | ('u', 'user', '', |
|
81 | ('u', 'user', '', | |
82 | _('record the specified user as committer'), _('USER')), |
|
82 | _('record the specified user as committer'), _('USER')), | |
83 | ] |
|
83 | ] | |
84 |
|
84 | |||
85 | templateopts = [ |
|
85 | templateopts = [ | |
86 | ('', 'style', '', |
|
86 | ('', 'style', '', | |
87 | _('display using template map file'), _('STYLE')), |
|
87 | _('display using template map file'), _('STYLE')), | |
88 | ('', 'template', '', |
|
88 | ('', 'template', '', | |
89 | _('display with template'), _('TEMPLATE')), |
|
89 | _('display with template'), _('TEMPLATE')), | |
90 | ] |
|
90 | ] | |
91 |
|
91 | |||
92 | logopts = [ |
|
92 | logopts = [ | |
93 | ('p', 'patch', None, _('show patch')), |
|
93 | ('p', 'patch', None, _('show patch')), | |
94 | ('g', 'git', None, _('use git extended diff format')), |
|
94 | ('g', 'git', None, _('use git extended diff format')), | |
95 | ('l', 'limit', '', |
|
95 | ('l', 'limit', '', | |
96 | _('limit number of changes displayed'), _('NUM')), |
|
96 | _('limit number of changes displayed'), _('NUM')), | |
97 | ('M', 'no-merges', None, _('do not show merges')), |
|
97 | ('M', 'no-merges', None, _('do not show merges')), | |
98 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
98 | ('', 'stat', None, _('output diffstat-style summary of changes')), | |
99 | ] + templateopts |
|
99 | ] + templateopts | |
100 |
|
100 | |||
101 | diffopts = [ |
|
101 | diffopts = [ | |
102 | ('a', 'text', None, _('treat all files as text')), |
|
102 | ('a', 'text', None, _('treat all files as text')), | |
103 | ('g', 'git', None, _('use git extended diff format')), |
|
103 | ('g', 'git', None, _('use git extended diff format')), | |
104 | ('', 'nodates', None, _('omit dates from diff headers')) |
|
104 | ('', 'nodates', None, _('omit dates from diff headers')) | |
105 | ] |
|
105 | ] | |
106 |
|
106 | |||
107 | diffopts2 = [ |
|
107 | diffopts2 = [ | |
108 | ('p', 'show-function', None, _('show which function each change is in')), |
|
108 | ('p', 'show-function', None, _('show which function each change is in')), | |
109 | ('', 'reverse', None, _('produce a diff that undoes the changes')), |
|
109 | ('', 'reverse', None, _('produce a diff that undoes the changes')), | |
110 | ('w', 'ignore-all-space', None, |
|
110 | ('w', 'ignore-all-space', None, | |
111 | _('ignore white space when comparing lines')), |
|
111 | _('ignore white space when comparing lines')), | |
112 | ('b', 'ignore-space-change', None, |
|
112 | ('b', 'ignore-space-change', None, | |
113 | _('ignore changes in the amount of white space')), |
|
113 | _('ignore changes in the amount of white space')), | |
114 | ('B', 'ignore-blank-lines', None, |
|
114 | ('B', 'ignore-blank-lines', None, | |
115 | _('ignore changes whose lines are all blank')), |
|
115 | _('ignore changes whose lines are all blank')), | |
116 | ('U', 'unified', '', |
|
116 | ('U', 'unified', '', | |
117 | _('number of lines of context to show'), _('NUM')), |
|
117 | _('number of lines of context to show'), _('NUM')), | |
118 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
118 | ('', 'stat', None, _('output diffstat-style summary of changes')), | |
119 | ] |
|
119 | ] | |
120 |
|
120 | |||
121 | similarityopts = [ |
|
121 | similarityopts = [ | |
122 | ('s', 'similarity', '', |
|
122 | ('s', 'similarity', '', | |
123 | _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY')) |
|
123 | _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY')) | |
124 | ] |
|
124 | ] | |
125 |
|
125 | |||
126 | subrepoopts = [ |
|
126 | subrepoopts = [ | |
127 | ('S', 'subrepos', None, |
|
127 | ('S', 'subrepos', None, | |
128 | _('recurse into subrepositories')) |
|
128 | _('recurse into subrepositories')) | |
129 | ] |
|
129 | ] | |
130 |
|
130 | |||
131 | # Commands start here, listed alphabetically |
|
131 | # Commands start here, listed alphabetically | |
132 |
|
132 | |||
133 | @command('^add', |
|
133 | @command('^add', | |
134 | walkopts + subrepoopts + dryrunopts, |
|
134 | walkopts + subrepoopts + dryrunopts, | |
135 | _('[OPTION]... [FILE]...')) |
|
135 | _('[OPTION]... [FILE]...')) | |
136 | def add(ui, repo, *pats, **opts): |
|
136 | def add(ui, repo, *pats, **opts): | |
137 | """add the specified files on the next commit |
|
137 | """add the specified files on the next commit | |
138 |
|
138 | |||
139 | Schedule files to be version controlled and added to the |
|
139 | Schedule files to be version controlled and added to the | |
140 | repository. |
|
140 | repository. | |
141 |
|
141 | |||
142 | The files will be added to the repository at the next commit. To |
|
142 | The files will be added to the repository at the next commit. To | |
143 | undo an add before that, see :hg:`forget`. |
|
143 | undo an add before that, see :hg:`forget`. | |
144 |
|
144 | |||
145 | If no names are given, add all files to the repository. |
|
145 | If no names are given, add all files to the repository. | |
146 |
|
146 | |||
147 | .. container:: verbose |
|
147 | .. container:: verbose | |
148 |
|
148 | |||
149 | An example showing how new (unknown) files are added |
|
149 | An example showing how new (unknown) files are added | |
150 | automatically by :hg:`add`:: |
|
150 | automatically by :hg:`add`:: | |
151 |
|
151 | |||
152 | $ ls |
|
152 | $ ls | |
153 | foo.c |
|
153 | foo.c | |
154 | $ hg status |
|
154 | $ hg status | |
155 | ? foo.c |
|
155 | ? foo.c | |
156 | $ hg add |
|
156 | $ hg add | |
157 | adding foo.c |
|
157 | adding foo.c | |
158 | $ hg status |
|
158 | $ hg status | |
159 | A foo.c |
|
159 | A foo.c | |
160 |
|
160 | |||
161 | Returns 0 if all files are successfully added. |
|
161 | Returns 0 if all files are successfully added. | |
162 | """ |
|
162 | """ | |
163 |
|
163 | |||
164 | m = cmdutil.match(repo, pats, opts) |
|
164 | m = cmdutil.match(repo, pats, opts) | |
165 | rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), |
|
165 | rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), | |
166 | opts.get('subrepos'), prefix="") |
|
166 | opts.get('subrepos'), prefix="") | |
167 | return rejected and 1 or 0 |
|
167 | return rejected and 1 or 0 | |
168 |
|
168 | |||
169 | @command('addremove', |
|
169 | @command('addremove', | |
170 | similarityopts + walkopts + dryrunopts, |
|
170 | similarityopts + walkopts + dryrunopts, | |
171 | _('[OPTION]... [FILE]...')) |
|
171 | _('[OPTION]... [FILE]...')) | |
172 | def addremove(ui, repo, *pats, **opts): |
|
172 | def addremove(ui, repo, *pats, **opts): | |
173 | """add all new files, delete all missing files |
|
173 | """add all new files, delete all missing files | |
174 |
|
174 | |||
175 | Add all new files and remove all missing files from the |
|
175 | Add all new files and remove all missing files from the | |
176 | repository. |
|
176 | repository. | |
177 |
|
177 | |||
178 | New files are ignored if they match any of the patterns in |
|
178 | New files are ignored if they match any of the patterns in | |
179 | ``.hgignore``. As with add, these changes take effect at the next |
|
179 | ``.hgignore``. As with add, these changes take effect at the next | |
180 | commit. |
|
180 | commit. | |
181 |
|
181 | |||
182 | Use the -s/--similarity option to detect renamed files. With a |
|
182 | Use the -s/--similarity option to detect renamed files. With a | |
183 | parameter greater than 0, this compares every removed file with |
|
183 | parameter greater than 0, this compares every removed file with | |
184 | every added file and records those similar enough as renames. This |
|
184 | every added file and records those similar enough as renames. This | |
185 | option takes a percentage between 0 (disabled) and 100 (files must |
|
185 | option takes a percentage between 0 (disabled) and 100 (files must | |
186 | be identical) as its parameter. Detecting renamed files this way |
|
186 | be identical) as its parameter. Detecting renamed files this way | |
187 | can be expensive. After using this option, :hg:`status -C` can be |
|
187 | can be expensive. After using this option, :hg:`status -C` can be | |
188 | used to check which files were identified as moved or renamed. |
|
188 | used to check which files were identified as moved or renamed. | |
189 |
|
189 | |||
190 | Returns 0 if all files are successfully added. |
|
190 | Returns 0 if all files are successfully added. | |
191 | """ |
|
191 | """ | |
192 | try: |
|
192 | try: | |
193 | sim = float(opts.get('similarity') or 100) |
|
193 | sim = float(opts.get('similarity') or 100) | |
194 | except ValueError: |
|
194 | except ValueError: | |
195 | raise util.Abort(_('similarity must be a number')) |
|
195 | raise util.Abort(_('similarity must be a number')) | |
196 | if sim < 0 or sim > 100: |
|
196 | if sim < 0 or sim > 100: | |
197 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
197 | raise util.Abort(_('similarity must be between 0 and 100')) | |
198 |
return cm |
|
198 | return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0) | |
199 |
|
199 | |||
200 | @command('^annotate|blame', |
|
200 | @command('^annotate|blame', | |
201 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), |
|
201 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), | |
202 | ('', 'follow', None, |
|
202 | ('', 'follow', None, | |
203 | _('follow copies/renames and list the filename (DEPRECATED)')), |
|
203 | _('follow copies/renames and list the filename (DEPRECATED)')), | |
204 | ('', 'no-follow', None, _("don't follow copies and renames")), |
|
204 | ('', 'no-follow', None, _("don't follow copies and renames")), | |
205 | ('a', 'text', None, _('treat all files as text')), |
|
205 | ('a', 'text', None, _('treat all files as text')), | |
206 | ('u', 'user', None, _('list the author (long with -v)')), |
|
206 | ('u', 'user', None, _('list the author (long with -v)')), | |
207 | ('f', 'file', None, _('list the filename')), |
|
207 | ('f', 'file', None, _('list the filename')), | |
208 | ('d', 'date', None, _('list the date (short with -q)')), |
|
208 | ('d', 'date', None, _('list the date (short with -q)')), | |
209 | ('n', 'number', None, _('list the revision number (default)')), |
|
209 | ('n', 'number', None, _('list the revision number (default)')), | |
210 | ('c', 'changeset', None, _('list the changeset')), |
|
210 | ('c', 'changeset', None, _('list the changeset')), | |
211 | ('l', 'line-number', None, _('show line number at the first appearance')) |
|
211 | ('l', 'line-number', None, _('show line number at the first appearance')) | |
212 | ] + walkopts, |
|
212 | ] + walkopts, | |
213 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')) |
|
213 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')) | |
214 | def annotate(ui, repo, *pats, **opts): |
|
214 | def annotate(ui, repo, *pats, **opts): | |
215 | """show changeset information by line for each file |
|
215 | """show changeset information by line for each file | |
216 |
|
216 | |||
217 | List changes in files, showing the revision id responsible for |
|
217 | List changes in files, showing the revision id responsible for | |
218 | each line |
|
218 | each line | |
219 |
|
219 | |||
220 | This command is useful for discovering when a change was made and |
|
220 | This command is useful for discovering when a change was made and | |
221 | by whom. |
|
221 | by whom. | |
222 |
|
222 | |||
223 | Without the -a/--text option, annotate will avoid processing files |
|
223 | Without the -a/--text option, annotate will avoid processing files | |
224 | it detects as binary. With -a, annotate will annotate the file |
|
224 | it detects as binary. With -a, annotate will annotate the file | |
225 | anyway, although the results will probably be neither useful |
|
225 | anyway, although the results will probably be neither useful | |
226 | nor desirable. |
|
226 | nor desirable. | |
227 |
|
227 | |||
228 | Returns 0 on success. |
|
228 | Returns 0 on success. | |
229 | """ |
|
229 | """ | |
230 | if opts.get('follow'): |
|
230 | if opts.get('follow'): | |
231 | # --follow is deprecated and now just an alias for -f/--file |
|
231 | # --follow is deprecated and now just an alias for -f/--file | |
232 | # to mimic the behavior of Mercurial before version 1.5 |
|
232 | # to mimic the behavior of Mercurial before version 1.5 | |
233 | opts['file'] = True |
|
233 | opts['file'] = True | |
234 |
|
234 | |||
235 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
235 | datefunc = ui.quiet and util.shortdate or util.datestr | |
236 | getdate = util.cachefunc(lambda x: datefunc(x[0].date())) |
|
236 | getdate = util.cachefunc(lambda x: datefunc(x[0].date())) | |
237 |
|
237 | |||
238 | if not pats: |
|
238 | if not pats: | |
239 | raise util.Abort(_('at least one filename or pattern is required')) |
|
239 | raise util.Abort(_('at least one filename or pattern is required')) | |
240 |
|
240 | |||
241 | opmap = [('user', lambda x: ui.shortuser(x[0].user())), |
|
241 | opmap = [('user', lambda x: ui.shortuser(x[0].user())), | |
242 | ('number', lambda x: str(x[0].rev())), |
|
242 | ('number', lambda x: str(x[0].rev())), | |
243 | ('changeset', lambda x: short(x[0].node())), |
|
243 | ('changeset', lambda x: short(x[0].node())), | |
244 | ('date', getdate), |
|
244 | ('date', getdate), | |
245 | ('file', lambda x: x[0].path()), |
|
245 | ('file', lambda x: x[0].path()), | |
246 | ] |
|
246 | ] | |
247 |
|
247 | |||
248 | if (not opts.get('user') and not opts.get('changeset') |
|
248 | if (not opts.get('user') and not opts.get('changeset') | |
249 | and not opts.get('date') and not opts.get('file')): |
|
249 | and not opts.get('date') and not opts.get('file')): | |
250 | opts['number'] = True |
|
250 | opts['number'] = True | |
251 |
|
251 | |||
252 | linenumber = opts.get('line_number') is not None |
|
252 | linenumber = opts.get('line_number') is not None | |
253 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): |
|
253 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): | |
254 | raise util.Abort(_('at least one of -n/-c is required for -l')) |
|
254 | raise util.Abort(_('at least one of -n/-c is required for -l')) | |
255 |
|
255 | |||
256 | funcmap = [func for op, func in opmap if opts.get(op)] |
|
256 | funcmap = [func for op, func in opmap if opts.get(op)] | |
257 | if linenumber: |
|
257 | if linenumber: | |
258 | lastfunc = funcmap[-1] |
|
258 | lastfunc = funcmap[-1] | |
259 | funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) |
|
259 | funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) | |
260 |
|
260 | |||
261 | def bad(x, y): |
|
261 | def bad(x, y): | |
262 | raise util.Abort("%s: %s" % (x, y)) |
|
262 | raise util.Abort("%s: %s" % (x, y)) | |
263 |
|
263 | |||
264 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
264 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
265 | m = cmdutil.match(repo, pats, opts) |
|
265 | m = cmdutil.match(repo, pats, opts) | |
266 | m.bad = bad |
|
266 | m.bad = bad | |
267 | follow = not opts.get('no_follow') |
|
267 | follow = not opts.get('no_follow') | |
268 | for abs in ctx.walk(m): |
|
268 | for abs in ctx.walk(m): | |
269 | fctx = ctx[abs] |
|
269 | fctx = ctx[abs] | |
270 | if not opts.get('text') and util.binary(fctx.data()): |
|
270 | if not opts.get('text') and util.binary(fctx.data()): | |
271 | ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
|
271 | ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) | |
272 | continue |
|
272 | continue | |
273 |
|
273 | |||
274 | lines = fctx.annotate(follow=follow, linenumber=linenumber) |
|
274 | lines = fctx.annotate(follow=follow, linenumber=linenumber) | |
275 | pieces = [] |
|
275 | pieces = [] | |
276 |
|
276 | |||
277 | for f in funcmap: |
|
277 | for f in funcmap: | |
278 | l = [f(n) for n, dummy in lines] |
|
278 | l = [f(n) for n, dummy in lines] | |
279 | if l: |
|
279 | if l: | |
280 | sized = [(x, encoding.colwidth(x)) for x in l] |
|
280 | sized = [(x, encoding.colwidth(x)) for x in l] | |
281 | ml = max([w for x, w in sized]) |
|
281 | ml = max([w for x, w in sized]) | |
282 | pieces.append(["%s%s" % (' ' * (ml - w), x) for x, w in sized]) |
|
282 | pieces.append(["%s%s" % (' ' * (ml - w), x) for x, w in sized]) | |
283 |
|
283 | |||
284 | if pieces: |
|
284 | if pieces: | |
285 | for p, l in zip(zip(*pieces), lines): |
|
285 | for p, l in zip(zip(*pieces), lines): | |
286 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
286 | ui.write("%s: %s" % (" ".join(p), l[1])) | |
287 |
|
287 | |||
288 | @command('archive', |
|
288 | @command('archive', | |
289 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
289 | [('', 'no-decode', None, _('do not pass files through decoders')), | |
290 | ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
290 | ('p', 'prefix', '', _('directory prefix for files in archive'), | |
291 | _('PREFIX')), |
|
291 | _('PREFIX')), | |
292 | ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
292 | ('r', 'rev', '', _('revision to distribute'), _('REV')), | |
293 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
293 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), | |
294 | ] + subrepoopts + walkopts, |
|
294 | ] + subrepoopts + walkopts, | |
295 | _('[OPTION]... DEST')) |
|
295 | _('[OPTION]... DEST')) | |
296 | def archive(ui, repo, dest, **opts): |
|
296 | def archive(ui, repo, dest, **opts): | |
297 | '''create an unversioned archive of a repository revision |
|
297 | '''create an unversioned archive of a repository revision | |
298 |
|
298 | |||
299 | By default, the revision used is the parent of the working |
|
299 | By default, the revision used is the parent of the working | |
300 | directory; use -r/--rev to specify a different revision. |
|
300 | directory; use -r/--rev to specify a different revision. | |
301 |
|
301 | |||
302 | The archive type is automatically detected based on file |
|
302 | The archive type is automatically detected based on file | |
303 | extension (or override using -t/--type). |
|
303 | extension (or override using -t/--type). | |
304 |
|
304 | |||
305 | Valid types are: |
|
305 | Valid types are: | |
306 |
|
306 | |||
307 | :``files``: a directory full of files (default) |
|
307 | :``files``: a directory full of files (default) | |
308 | :``tar``: tar archive, uncompressed |
|
308 | :``tar``: tar archive, uncompressed | |
309 | :``tbz2``: tar archive, compressed using bzip2 |
|
309 | :``tbz2``: tar archive, compressed using bzip2 | |
310 | :``tgz``: tar archive, compressed using gzip |
|
310 | :``tgz``: tar archive, compressed using gzip | |
311 | :``uzip``: zip archive, uncompressed |
|
311 | :``uzip``: zip archive, uncompressed | |
312 | :``zip``: zip archive, compressed using deflate |
|
312 | :``zip``: zip archive, compressed using deflate | |
313 |
|
313 | |||
314 | The exact name of the destination archive or directory is given |
|
314 | The exact name of the destination archive or directory is given | |
315 | using a format string; see :hg:`help export` for details. |
|
315 | using a format string; see :hg:`help export` for details. | |
316 |
|
316 | |||
317 | Each member added to an archive file has a directory prefix |
|
317 | Each member added to an archive file has a directory prefix | |
318 | prepended. Use -p/--prefix to specify a format string for the |
|
318 | prepended. Use -p/--prefix to specify a format string for the | |
319 | prefix. The default is the basename of the archive, with suffixes |
|
319 | prefix. The default is the basename of the archive, with suffixes | |
320 | removed. |
|
320 | removed. | |
321 |
|
321 | |||
322 | Returns 0 on success. |
|
322 | Returns 0 on success. | |
323 | ''' |
|
323 | ''' | |
324 |
|
324 | |||
325 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
325 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
326 | if not ctx: |
|
326 | if not ctx: | |
327 | raise util.Abort(_('no working directory: please specify a revision')) |
|
327 | raise util.Abort(_('no working directory: please specify a revision')) | |
328 | node = ctx.node() |
|
328 | node = ctx.node() | |
329 | dest = cmdutil.makefilename(repo, dest, node) |
|
329 | dest = cmdutil.makefilename(repo, dest, node) | |
330 | if os.path.realpath(dest) == repo.root: |
|
330 | if os.path.realpath(dest) == repo.root: | |
331 | raise util.Abort(_('repository root cannot be destination')) |
|
331 | raise util.Abort(_('repository root cannot be destination')) | |
332 |
|
332 | |||
333 | kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
333 | kind = opts.get('type') or archival.guesskind(dest) or 'files' | |
334 | prefix = opts.get('prefix') |
|
334 | prefix = opts.get('prefix') | |
335 |
|
335 | |||
336 | if dest == '-': |
|
336 | if dest == '-': | |
337 | if kind == 'files': |
|
337 | if kind == 'files': | |
338 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
338 | raise util.Abort(_('cannot archive plain files to stdout')) | |
339 | dest = sys.stdout |
|
339 | dest = sys.stdout | |
340 | if not prefix: |
|
340 | if not prefix: | |
341 | prefix = os.path.basename(repo.root) + '-%h' |
|
341 | prefix = os.path.basename(repo.root) + '-%h' | |
342 |
|
342 | |||
343 | prefix = cmdutil.makefilename(repo, prefix, node) |
|
343 | prefix = cmdutil.makefilename(repo, prefix, node) | |
344 | matchfn = cmdutil.match(repo, [], opts) |
|
344 | matchfn = cmdutil.match(repo, [], opts) | |
345 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
345 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), | |
346 | matchfn, prefix, subrepos=opts.get('subrepos')) |
|
346 | matchfn, prefix, subrepos=opts.get('subrepos')) | |
347 |
|
347 | |||
348 | @command('backout', |
|
348 | @command('backout', | |
349 | [('', 'merge', None, _('merge with old dirstate parent after backout')), |
|
349 | [('', 'merge', None, _('merge with old dirstate parent after backout')), | |
350 | ('', 'parent', '', _('parent to choose when backing out merge'), _('REV')), |
|
350 | ('', 'parent', '', _('parent to choose when backing out merge'), _('REV')), | |
351 | ('t', 'tool', '', _('specify merge tool')), |
|
351 | ('t', 'tool', '', _('specify merge tool')), | |
352 | ('r', 'rev', '', _('revision to backout'), _('REV')), |
|
352 | ('r', 'rev', '', _('revision to backout'), _('REV')), | |
353 | ] + walkopts + commitopts + commitopts2, |
|
353 | ] + walkopts + commitopts + commitopts2, | |
354 | _('[OPTION]... [-r] REV')) |
|
354 | _('[OPTION]... [-r] REV')) | |
355 | def backout(ui, repo, node=None, rev=None, **opts): |
|
355 | def backout(ui, repo, node=None, rev=None, **opts): | |
356 | '''reverse effect of earlier changeset |
|
356 | '''reverse effect of earlier changeset | |
357 |
|
357 | |||
358 | Prepare a new changeset with the effect of REV undone in the |
|
358 | Prepare a new changeset with the effect of REV undone in the | |
359 | current working directory. |
|
359 | current working directory. | |
360 |
|
360 | |||
361 | If REV is the parent of the working directory, then this new changeset |
|
361 | If REV is the parent of the working directory, then this new changeset | |
362 | is committed automatically. Otherwise, hg needs to merge the |
|
362 | is committed automatically. Otherwise, hg needs to merge the | |
363 | changes and the merged result is left uncommitted. |
|
363 | changes and the merged result is left uncommitted. | |
364 |
|
364 | |||
365 | By default, the pending changeset will have one parent, |
|
365 | By default, the pending changeset will have one parent, | |
366 | maintaining a linear history. With --merge, the pending changeset |
|
366 | maintaining a linear history. With --merge, the pending changeset | |
367 | will instead have two parents: the old parent of the working |
|
367 | will instead have two parents: the old parent of the working | |
368 | directory and a new child of REV that simply undoes REV. |
|
368 | directory and a new child of REV that simply undoes REV. | |
369 |
|
369 | |||
370 | Before version 1.7, the behavior without --merge was equivalent to |
|
370 | Before version 1.7, the behavior without --merge was equivalent to | |
371 | specifying --merge followed by :hg:`update --clean .` to cancel |
|
371 | specifying --merge followed by :hg:`update --clean .` to cancel | |
372 | the merge and leave the child of REV as a head to be merged |
|
372 | the merge and leave the child of REV as a head to be merged | |
373 | separately. |
|
373 | separately. | |
374 |
|
374 | |||
375 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
375 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
376 |
|
376 | |||
377 | Returns 0 on success. |
|
377 | Returns 0 on success. | |
378 | ''' |
|
378 | ''' | |
379 | if rev and node: |
|
379 | if rev and node: | |
380 | raise util.Abort(_("please specify just one revision")) |
|
380 | raise util.Abort(_("please specify just one revision")) | |
381 |
|
381 | |||
382 | if not rev: |
|
382 | if not rev: | |
383 | rev = node |
|
383 | rev = node | |
384 |
|
384 | |||
385 | if not rev: |
|
385 | if not rev: | |
386 | raise util.Abort(_("please specify a revision to backout")) |
|
386 | raise util.Abort(_("please specify a revision to backout")) | |
387 |
|
387 | |||
388 | date = opts.get('date') |
|
388 | date = opts.get('date') | |
389 | if date: |
|
389 | if date: | |
390 | opts['date'] = util.parsedate(date) |
|
390 | opts['date'] = util.parsedate(date) | |
391 |
|
391 | |||
392 | cmdutil.bailifchanged(repo) |
|
392 | cmdutil.bailifchanged(repo) | |
393 | node = scmutil.revsingle(repo, rev).node() |
|
393 | node = scmutil.revsingle(repo, rev).node() | |
394 |
|
394 | |||
395 | op1, op2 = repo.dirstate.parents() |
|
395 | op1, op2 = repo.dirstate.parents() | |
396 | a = repo.changelog.ancestor(op1, node) |
|
396 | a = repo.changelog.ancestor(op1, node) | |
397 | if a != node: |
|
397 | if a != node: | |
398 | raise util.Abort(_('cannot backout change on a different branch')) |
|
398 | raise util.Abort(_('cannot backout change on a different branch')) | |
399 |
|
399 | |||
400 | p1, p2 = repo.changelog.parents(node) |
|
400 | p1, p2 = repo.changelog.parents(node) | |
401 | if p1 == nullid: |
|
401 | if p1 == nullid: | |
402 | raise util.Abort(_('cannot backout a change with no parents')) |
|
402 | raise util.Abort(_('cannot backout a change with no parents')) | |
403 | if p2 != nullid: |
|
403 | if p2 != nullid: | |
404 | if not opts.get('parent'): |
|
404 | if not opts.get('parent'): | |
405 | raise util.Abort(_('cannot backout a merge changeset without ' |
|
405 | raise util.Abort(_('cannot backout a merge changeset without ' | |
406 | '--parent')) |
|
406 | '--parent')) | |
407 | p = repo.lookup(opts['parent']) |
|
407 | p = repo.lookup(opts['parent']) | |
408 | if p not in (p1, p2): |
|
408 | if p not in (p1, p2): | |
409 | raise util.Abort(_('%s is not a parent of %s') % |
|
409 | raise util.Abort(_('%s is not a parent of %s') % | |
410 | (short(p), short(node))) |
|
410 | (short(p), short(node))) | |
411 | parent = p |
|
411 | parent = p | |
412 | else: |
|
412 | else: | |
413 | if opts.get('parent'): |
|
413 | if opts.get('parent'): | |
414 | raise util.Abort(_('cannot use --parent on non-merge changeset')) |
|
414 | raise util.Abort(_('cannot use --parent on non-merge changeset')) | |
415 | parent = p1 |
|
415 | parent = p1 | |
416 |
|
416 | |||
417 | # the backout should appear on the same branch |
|
417 | # the backout should appear on the same branch | |
418 | branch = repo.dirstate.branch() |
|
418 | branch = repo.dirstate.branch() | |
419 | hg.clean(repo, node, show_stats=False) |
|
419 | hg.clean(repo, node, show_stats=False) | |
420 | repo.dirstate.setbranch(branch) |
|
420 | repo.dirstate.setbranch(branch) | |
421 | revert_opts = opts.copy() |
|
421 | revert_opts = opts.copy() | |
422 | revert_opts['date'] = None |
|
422 | revert_opts['date'] = None | |
423 | revert_opts['all'] = True |
|
423 | revert_opts['all'] = True | |
424 | revert_opts['rev'] = hex(parent) |
|
424 | revert_opts['rev'] = hex(parent) | |
425 | revert_opts['no_backup'] = None |
|
425 | revert_opts['no_backup'] = None | |
426 | revert(ui, repo, **revert_opts) |
|
426 | revert(ui, repo, **revert_opts) | |
427 | if not opts.get('merge') and op1 != node: |
|
427 | if not opts.get('merge') and op1 != node: | |
428 | try: |
|
428 | try: | |
429 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
429 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | |
430 | return hg.update(repo, op1) |
|
430 | return hg.update(repo, op1) | |
431 | finally: |
|
431 | finally: | |
432 | ui.setconfig('ui', 'forcemerge', '') |
|
432 | ui.setconfig('ui', 'forcemerge', '') | |
433 |
|
433 | |||
434 | commit_opts = opts.copy() |
|
434 | commit_opts = opts.copy() | |
435 | commit_opts['addremove'] = False |
|
435 | commit_opts['addremove'] = False | |
436 | if not commit_opts['message'] and not commit_opts['logfile']: |
|
436 | if not commit_opts['message'] and not commit_opts['logfile']: | |
437 | # we don't translate commit messages |
|
437 | # we don't translate commit messages | |
438 | commit_opts['message'] = "Backed out changeset %s" % short(node) |
|
438 | commit_opts['message'] = "Backed out changeset %s" % short(node) | |
439 | commit_opts['force_editor'] = True |
|
439 | commit_opts['force_editor'] = True | |
440 | commit(ui, repo, **commit_opts) |
|
440 | commit(ui, repo, **commit_opts) | |
441 | def nice(node): |
|
441 | def nice(node): | |
442 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
442 | return '%d:%s' % (repo.changelog.rev(node), short(node)) | |
443 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
443 | ui.status(_('changeset %s backs out changeset %s\n') % | |
444 | (nice(repo.changelog.tip()), nice(node))) |
|
444 | (nice(repo.changelog.tip()), nice(node))) | |
445 | if opts.get('merge') and op1 != node: |
|
445 | if opts.get('merge') and op1 != node: | |
446 | hg.clean(repo, op1, show_stats=False) |
|
446 | hg.clean(repo, op1, show_stats=False) | |
447 | ui.status(_('merging with changeset %s\n') |
|
447 | ui.status(_('merging with changeset %s\n') | |
448 | % nice(repo.changelog.tip())) |
|
448 | % nice(repo.changelog.tip())) | |
449 | try: |
|
449 | try: | |
450 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
450 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | |
451 | return hg.merge(repo, hex(repo.changelog.tip())) |
|
451 | return hg.merge(repo, hex(repo.changelog.tip())) | |
452 | finally: |
|
452 | finally: | |
453 | ui.setconfig('ui', 'forcemerge', '') |
|
453 | ui.setconfig('ui', 'forcemerge', '') | |
454 | return 0 |
|
454 | return 0 | |
455 |
|
455 | |||
456 | @command('bisect', |
|
456 | @command('bisect', | |
457 | [('r', 'reset', False, _('reset bisect state')), |
|
457 | [('r', 'reset', False, _('reset bisect state')), | |
458 | ('g', 'good', False, _('mark changeset good')), |
|
458 | ('g', 'good', False, _('mark changeset good')), | |
459 | ('b', 'bad', False, _('mark changeset bad')), |
|
459 | ('b', 'bad', False, _('mark changeset bad')), | |
460 | ('s', 'skip', False, _('skip testing changeset')), |
|
460 | ('s', 'skip', False, _('skip testing changeset')), | |
461 | ('e', 'extend', False, _('extend the bisect range')), |
|
461 | ('e', 'extend', False, _('extend the bisect range')), | |
462 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), |
|
462 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), | |
463 | ('U', 'noupdate', False, _('do not update to target'))], |
|
463 | ('U', 'noupdate', False, _('do not update to target'))], | |
464 | _("[-gbsr] [-U] [-c CMD] [REV]")) |
|
464 | _("[-gbsr] [-U] [-c CMD] [REV]")) | |
465 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
465 | def bisect(ui, repo, rev=None, extra=None, command=None, | |
466 | reset=None, good=None, bad=None, skip=None, extend=None, |
|
466 | reset=None, good=None, bad=None, skip=None, extend=None, | |
467 | noupdate=None): |
|
467 | noupdate=None): | |
468 | """subdivision search of changesets |
|
468 | """subdivision search of changesets | |
469 |
|
469 | |||
470 | This command helps to find changesets which introduce problems. To |
|
470 | This command helps to find changesets which introduce problems. To | |
471 | use, mark the earliest changeset you know exhibits the problem as |
|
471 | use, mark the earliest changeset you know exhibits the problem as | |
472 | bad, then mark the latest changeset which is free from the problem |
|
472 | bad, then mark the latest changeset which is free from the problem | |
473 | as good. Bisect will update your working directory to a revision |
|
473 | as good. Bisect will update your working directory to a revision | |
474 | for testing (unless the -U/--noupdate option is specified). Once |
|
474 | for testing (unless the -U/--noupdate option is specified). Once | |
475 | you have performed tests, mark the working directory as good or |
|
475 | you have performed tests, mark the working directory as good or | |
476 | bad, and bisect will either update to another candidate changeset |
|
476 | bad, and bisect will either update to another candidate changeset | |
477 | or announce that it has found the bad revision. |
|
477 | or announce that it has found the bad revision. | |
478 |
|
478 | |||
479 | As a shortcut, you can also use the revision argument to mark a |
|
479 | As a shortcut, you can also use the revision argument to mark a | |
480 | revision as good or bad without checking it out first. |
|
480 | revision as good or bad without checking it out first. | |
481 |
|
481 | |||
482 | If you supply a command, it will be used for automatic bisection. |
|
482 | If you supply a command, it will be used for automatic bisection. | |
483 | Its exit status will be used to mark revisions as good or bad: |
|
483 | Its exit status will be used to mark revisions as good or bad: | |
484 | status 0 means good, 125 means to skip the revision, 127 |
|
484 | status 0 means good, 125 means to skip the revision, 127 | |
485 | (command not found) will abort the bisection, and any other |
|
485 | (command not found) will abort the bisection, and any other | |
486 | non-zero exit status means the revision is bad. |
|
486 | non-zero exit status means the revision is bad. | |
487 |
|
487 | |||
488 | Returns 0 on success. |
|
488 | Returns 0 on success. | |
489 | """ |
|
489 | """ | |
490 | def extendbisectrange(nodes, good): |
|
490 | def extendbisectrange(nodes, good): | |
491 | # bisect is incomplete when it ends on a merge node and |
|
491 | # bisect is incomplete when it ends on a merge node and | |
492 | # one of the parent was not checked. |
|
492 | # one of the parent was not checked. | |
493 | parents = repo[nodes[0]].parents() |
|
493 | parents = repo[nodes[0]].parents() | |
494 | if len(parents) > 1: |
|
494 | if len(parents) > 1: | |
495 | side = good and state['bad'] or state['good'] |
|
495 | side = good and state['bad'] or state['good'] | |
496 | num = len(set(i.node() for i in parents) & set(side)) |
|
496 | num = len(set(i.node() for i in parents) & set(side)) | |
497 | if num == 1: |
|
497 | if num == 1: | |
498 | return parents[0].ancestor(parents[1]) |
|
498 | return parents[0].ancestor(parents[1]) | |
499 | return None |
|
499 | return None | |
500 |
|
500 | |||
501 | def print_result(nodes, good): |
|
501 | def print_result(nodes, good): | |
502 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
502 | displayer = cmdutil.show_changeset(ui, repo, {}) | |
503 | if len(nodes) == 1: |
|
503 | if len(nodes) == 1: | |
504 | # narrowed it down to a single revision |
|
504 | # narrowed it down to a single revision | |
505 | if good: |
|
505 | if good: | |
506 | ui.write(_("The first good revision is:\n")) |
|
506 | ui.write(_("The first good revision is:\n")) | |
507 | else: |
|
507 | else: | |
508 | ui.write(_("The first bad revision is:\n")) |
|
508 | ui.write(_("The first bad revision is:\n")) | |
509 | displayer.show(repo[nodes[0]]) |
|
509 | displayer.show(repo[nodes[0]]) | |
510 | extendnode = extendbisectrange(nodes, good) |
|
510 | extendnode = extendbisectrange(nodes, good) | |
511 | if extendnode is not None: |
|
511 | if extendnode is not None: | |
512 | ui.write(_('Not all ancestors of this changeset have been' |
|
512 | ui.write(_('Not all ancestors of this changeset have been' | |
513 | ' checked.\nUse bisect --extend to continue the ' |
|
513 | ' checked.\nUse bisect --extend to continue the ' | |
514 | 'bisection from\nthe common ancestor, %s.\n') |
|
514 | 'bisection from\nthe common ancestor, %s.\n') | |
515 | % extendnode) |
|
515 | % extendnode) | |
516 | else: |
|
516 | else: | |
517 | # multiple possible revisions |
|
517 | # multiple possible revisions | |
518 | if good: |
|
518 | if good: | |
519 | ui.write(_("Due to skipped revisions, the first " |
|
519 | ui.write(_("Due to skipped revisions, the first " | |
520 | "good revision could be any of:\n")) |
|
520 | "good revision could be any of:\n")) | |
521 | else: |
|
521 | else: | |
522 | ui.write(_("Due to skipped revisions, the first " |
|
522 | ui.write(_("Due to skipped revisions, the first " | |
523 | "bad revision could be any of:\n")) |
|
523 | "bad revision could be any of:\n")) | |
524 | for n in nodes: |
|
524 | for n in nodes: | |
525 | displayer.show(repo[n]) |
|
525 | displayer.show(repo[n]) | |
526 | displayer.close() |
|
526 | displayer.close() | |
527 |
|
527 | |||
528 | def check_state(state, interactive=True): |
|
528 | def check_state(state, interactive=True): | |
529 | if not state['good'] or not state['bad']: |
|
529 | if not state['good'] or not state['bad']: | |
530 | if (good or bad or skip or reset) and interactive: |
|
530 | if (good or bad or skip or reset) and interactive: | |
531 | return |
|
531 | return | |
532 | if not state['good']: |
|
532 | if not state['good']: | |
533 | raise util.Abort(_('cannot bisect (no known good revisions)')) |
|
533 | raise util.Abort(_('cannot bisect (no known good revisions)')) | |
534 | else: |
|
534 | else: | |
535 | raise util.Abort(_('cannot bisect (no known bad revisions)')) |
|
535 | raise util.Abort(_('cannot bisect (no known bad revisions)')) | |
536 | return True |
|
536 | return True | |
537 |
|
537 | |||
538 | # backward compatibility |
|
538 | # backward compatibility | |
539 | if rev in "good bad reset init".split(): |
|
539 | if rev in "good bad reset init".split(): | |
540 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
540 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) | |
541 | cmd, rev, extra = rev, extra, None |
|
541 | cmd, rev, extra = rev, extra, None | |
542 | if cmd == "good": |
|
542 | if cmd == "good": | |
543 | good = True |
|
543 | good = True | |
544 | elif cmd == "bad": |
|
544 | elif cmd == "bad": | |
545 | bad = True |
|
545 | bad = True | |
546 | else: |
|
546 | else: | |
547 | reset = True |
|
547 | reset = True | |
548 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: |
|
548 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: | |
549 | raise util.Abort(_('incompatible arguments')) |
|
549 | raise util.Abort(_('incompatible arguments')) | |
550 |
|
550 | |||
551 | if reset: |
|
551 | if reset: | |
552 | p = repo.join("bisect.state") |
|
552 | p = repo.join("bisect.state") | |
553 | if os.path.exists(p): |
|
553 | if os.path.exists(p): | |
554 | os.unlink(p) |
|
554 | os.unlink(p) | |
555 | return |
|
555 | return | |
556 |
|
556 | |||
557 | state = hbisect.load_state(repo) |
|
557 | state = hbisect.load_state(repo) | |
558 |
|
558 | |||
559 | if command: |
|
559 | if command: | |
560 | changesets = 1 |
|
560 | changesets = 1 | |
561 | try: |
|
561 | try: | |
562 | while changesets: |
|
562 | while changesets: | |
563 | # update state |
|
563 | # update state | |
564 | status = util.system(command) |
|
564 | status = util.system(command) | |
565 | if status == 125: |
|
565 | if status == 125: | |
566 | transition = "skip" |
|
566 | transition = "skip" | |
567 | elif status == 0: |
|
567 | elif status == 0: | |
568 | transition = "good" |
|
568 | transition = "good" | |
569 | # status < 0 means process was killed |
|
569 | # status < 0 means process was killed | |
570 | elif status == 127: |
|
570 | elif status == 127: | |
571 | raise util.Abort(_("failed to execute %s") % command) |
|
571 | raise util.Abort(_("failed to execute %s") % command) | |
572 | elif status < 0: |
|
572 | elif status < 0: | |
573 | raise util.Abort(_("%s killed") % command) |
|
573 | raise util.Abort(_("%s killed") % command) | |
574 | else: |
|
574 | else: | |
575 | transition = "bad" |
|
575 | transition = "bad" | |
576 | ctx = scmutil.revsingle(repo, rev) |
|
576 | ctx = scmutil.revsingle(repo, rev) | |
577 | rev = None # clear for future iterations |
|
577 | rev = None # clear for future iterations | |
578 | state[transition].append(ctx.node()) |
|
578 | state[transition].append(ctx.node()) | |
579 | ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
579 | ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) | |
580 | check_state(state, interactive=False) |
|
580 | check_state(state, interactive=False) | |
581 | # bisect |
|
581 | # bisect | |
582 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
582 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) | |
583 | # update to next check |
|
583 | # update to next check | |
584 | cmdutil.bailifchanged(repo) |
|
584 | cmdutil.bailifchanged(repo) | |
585 | hg.clean(repo, nodes[0], show_stats=False) |
|
585 | hg.clean(repo, nodes[0], show_stats=False) | |
586 | finally: |
|
586 | finally: | |
587 | hbisect.save_state(repo, state) |
|
587 | hbisect.save_state(repo, state) | |
588 | print_result(nodes, good) |
|
588 | print_result(nodes, good) | |
589 | return |
|
589 | return | |
590 |
|
590 | |||
591 | # update state |
|
591 | # update state | |
592 |
|
592 | |||
593 | if rev: |
|
593 | if rev: | |
594 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] |
|
594 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] | |
595 | else: |
|
595 | else: | |
596 | nodes = [repo.lookup('.')] |
|
596 | nodes = [repo.lookup('.')] | |
597 |
|
597 | |||
598 | if good or bad or skip: |
|
598 | if good or bad or skip: | |
599 | if good: |
|
599 | if good: | |
600 | state['good'] += nodes |
|
600 | state['good'] += nodes | |
601 | elif bad: |
|
601 | elif bad: | |
602 | state['bad'] += nodes |
|
602 | state['bad'] += nodes | |
603 | elif skip: |
|
603 | elif skip: | |
604 | state['skip'] += nodes |
|
604 | state['skip'] += nodes | |
605 | hbisect.save_state(repo, state) |
|
605 | hbisect.save_state(repo, state) | |
606 |
|
606 | |||
607 | if not check_state(state): |
|
607 | if not check_state(state): | |
608 | return |
|
608 | return | |
609 |
|
609 | |||
610 | # actually bisect |
|
610 | # actually bisect | |
611 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
611 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) | |
612 | if extend: |
|
612 | if extend: | |
613 | if not changesets: |
|
613 | if not changesets: | |
614 | extendnode = extendbisectrange(nodes, good) |
|
614 | extendnode = extendbisectrange(nodes, good) | |
615 | if extendnode is not None: |
|
615 | if extendnode is not None: | |
616 | ui.write(_("Extending search to changeset %d:%s\n" |
|
616 | ui.write(_("Extending search to changeset %d:%s\n" | |
617 | % (extendnode.rev(), extendnode))) |
|
617 | % (extendnode.rev(), extendnode))) | |
618 | if noupdate: |
|
618 | if noupdate: | |
619 | return |
|
619 | return | |
620 | cmdutil.bailifchanged(repo) |
|
620 | cmdutil.bailifchanged(repo) | |
621 | return hg.clean(repo, extendnode.node()) |
|
621 | return hg.clean(repo, extendnode.node()) | |
622 | raise util.Abort(_("nothing to extend")) |
|
622 | raise util.Abort(_("nothing to extend")) | |
623 |
|
623 | |||
624 | if changesets == 0: |
|
624 | if changesets == 0: | |
625 | print_result(nodes, good) |
|
625 | print_result(nodes, good) | |
626 | else: |
|
626 | else: | |
627 | assert len(nodes) == 1 # only a single node can be tested next |
|
627 | assert len(nodes) == 1 # only a single node can be tested next | |
628 | node = nodes[0] |
|
628 | node = nodes[0] | |
629 | # compute the approximate number of remaining tests |
|
629 | # compute the approximate number of remaining tests | |
630 | tests, size = 0, 2 |
|
630 | tests, size = 0, 2 | |
631 | while size <= changesets: |
|
631 | while size <= changesets: | |
632 | tests, size = tests + 1, size * 2 |
|
632 | tests, size = tests + 1, size * 2 | |
633 | rev = repo.changelog.rev(node) |
|
633 | rev = repo.changelog.rev(node) | |
634 | ui.write(_("Testing changeset %d:%s " |
|
634 | ui.write(_("Testing changeset %d:%s " | |
635 | "(%d changesets remaining, ~%d tests)\n") |
|
635 | "(%d changesets remaining, ~%d tests)\n") | |
636 | % (rev, short(node), changesets, tests)) |
|
636 | % (rev, short(node), changesets, tests)) | |
637 | if not noupdate: |
|
637 | if not noupdate: | |
638 | cmdutil.bailifchanged(repo) |
|
638 | cmdutil.bailifchanged(repo) | |
639 | return hg.clean(repo, node) |
|
639 | return hg.clean(repo, node) | |
640 |
|
640 | |||
641 | @command('bookmarks', |
|
641 | @command('bookmarks', | |
642 | [('f', 'force', False, _('force')), |
|
642 | [('f', 'force', False, _('force')), | |
643 | ('r', 'rev', '', _('revision'), _('REV')), |
|
643 | ('r', 'rev', '', _('revision'), _('REV')), | |
644 | ('d', 'delete', False, _('delete a given bookmark')), |
|
644 | ('d', 'delete', False, _('delete a given bookmark')), | |
645 | ('m', 'rename', '', _('rename a given bookmark'), _('NAME')), |
|
645 | ('m', 'rename', '', _('rename a given bookmark'), _('NAME')), | |
646 | ('i', 'inactive', False, _('do not mark a new bookmark active'))], |
|
646 | ('i', 'inactive', False, _('do not mark a new bookmark active'))], | |
647 | _('hg bookmarks [-f] [-d] [-i] [-m NAME] [-r REV] [NAME]')) |
|
647 | _('hg bookmarks [-f] [-d] [-i] [-m NAME] [-r REV] [NAME]')) | |
648 | def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, |
|
648 | def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, | |
649 | rename=None, inactive=False): |
|
649 | rename=None, inactive=False): | |
650 | '''track a line of development with movable markers |
|
650 | '''track a line of development with movable markers | |
651 |
|
651 | |||
652 | Bookmarks are pointers to certain commits that move when |
|
652 | Bookmarks are pointers to certain commits that move when | |
653 | committing. Bookmarks are local. They can be renamed, copied and |
|
653 | committing. Bookmarks are local. They can be renamed, copied and | |
654 | deleted. It is possible to use bookmark names in :hg:`merge` and |
|
654 | deleted. It is possible to use bookmark names in :hg:`merge` and | |
655 | :hg:`update` to merge and update respectively to a given bookmark. |
|
655 | :hg:`update` to merge and update respectively to a given bookmark. | |
656 |
|
656 | |||
657 | You can use :hg:`bookmark NAME` to set a bookmark on the working |
|
657 | You can use :hg:`bookmark NAME` to set a bookmark on the working | |
658 | directory's parent revision with the given name. If you specify |
|
658 | directory's parent revision with the given name. If you specify | |
659 | a revision using -r REV (where REV may be an existing bookmark), |
|
659 | a revision using -r REV (where REV may be an existing bookmark), | |
660 | the bookmark is assigned to that revision. |
|
660 | the bookmark is assigned to that revision. | |
661 |
|
661 | |||
662 | Bookmarks can be pushed and pulled between repositories (see :hg:`help |
|
662 | Bookmarks can be pushed and pulled between repositories (see :hg:`help | |
663 | push` and :hg:`help pull`). This requires both the local and remote |
|
663 | push` and :hg:`help pull`). This requires both the local and remote | |
664 | repositories to support bookmarks. For versions prior to 1.8, this means |
|
664 | repositories to support bookmarks. For versions prior to 1.8, this means | |
665 | the bookmarks extension must be enabled. |
|
665 | the bookmarks extension must be enabled. | |
666 | ''' |
|
666 | ''' | |
667 | hexfn = ui.debugflag and hex or short |
|
667 | hexfn = ui.debugflag and hex or short | |
668 | marks = repo._bookmarks |
|
668 | marks = repo._bookmarks | |
669 | cur = repo.changectx('.').node() |
|
669 | cur = repo.changectx('.').node() | |
670 |
|
670 | |||
671 | if rename: |
|
671 | if rename: | |
672 | if rename not in marks: |
|
672 | if rename not in marks: | |
673 | raise util.Abort(_("bookmark '%s' does not exist") % rename) |
|
673 | raise util.Abort(_("bookmark '%s' does not exist") % rename) | |
674 | if mark in marks and not force: |
|
674 | if mark in marks and not force: | |
675 | raise util.Abort(_("bookmark '%s' already exists " |
|
675 | raise util.Abort(_("bookmark '%s' already exists " | |
676 | "(use -f to force)") % mark) |
|
676 | "(use -f to force)") % mark) | |
677 | if mark is None: |
|
677 | if mark is None: | |
678 | raise util.Abort(_("new bookmark name required")) |
|
678 | raise util.Abort(_("new bookmark name required")) | |
679 | marks[mark] = marks[rename] |
|
679 | marks[mark] = marks[rename] | |
680 | if repo._bookmarkcurrent == rename and not inactive: |
|
680 | if repo._bookmarkcurrent == rename and not inactive: | |
681 | bookmarks.setcurrent(repo, mark) |
|
681 | bookmarks.setcurrent(repo, mark) | |
682 | del marks[rename] |
|
682 | del marks[rename] | |
683 | bookmarks.write(repo) |
|
683 | bookmarks.write(repo) | |
684 | return |
|
684 | return | |
685 |
|
685 | |||
686 | if delete: |
|
686 | if delete: | |
687 | if mark is None: |
|
687 | if mark is None: | |
688 | raise util.Abort(_("bookmark name required")) |
|
688 | raise util.Abort(_("bookmark name required")) | |
689 | if mark not in marks: |
|
689 | if mark not in marks: | |
690 | raise util.Abort(_("bookmark '%s' does not exist") % mark) |
|
690 | raise util.Abort(_("bookmark '%s' does not exist") % mark) | |
691 | if mark == repo._bookmarkcurrent: |
|
691 | if mark == repo._bookmarkcurrent: | |
692 | bookmarks.setcurrent(repo, None) |
|
692 | bookmarks.setcurrent(repo, None) | |
693 | del marks[mark] |
|
693 | del marks[mark] | |
694 | bookmarks.write(repo) |
|
694 | bookmarks.write(repo) | |
695 | return |
|
695 | return | |
696 |
|
696 | |||
697 | if mark is not None: |
|
697 | if mark is not None: | |
698 | if "\n" in mark: |
|
698 | if "\n" in mark: | |
699 | raise util.Abort(_("bookmark name cannot contain newlines")) |
|
699 | raise util.Abort(_("bookmark name cannot contain newlines")) | |
700 | mark = mark.strip() |
|
700 | mark = mark.strip() | |
701 | if not mark: |
|
701 | if not mark: | |
702 | raise util.Abort(_("bookmark names cannot consist entirely of " |
|
702 | raise util.Abort(_("bookmark names cannot consist entirely of " | |
703 | "whitespace")) |
|
703 | "whitespace")) | |
704 | if inactive and mark == repo._bookmarkcurrent: |
|
704 | if inactive and mark == repo._bookmarkcurrent: | |
705 | bookmarks.setcurrent(repo, None) |
|
705 | bookmarks.setcurrent(repo, None) | |
706 | return |
|
706 | return | |
707 | if mark in marks and not force: |
|
707 | if mark in marks and not force: | |
708 | raise util.Abort(_("bookmark '%s' already exists " |
|
708 | raise util.Abort(_("bookmark '%s' already exists " | |
709 | "(use -f to force)") % mark) |
|
709 | "(use -f to force)") % mark) | |
710 | if ((mark in repo.branchtags() or mark == repo.dirstate.branch()) |
|
710 | if ((mark in repo.branchtags() or mark == repo.dirstate.branch()) | |
711 | and not force): |
|
711 | and not force): | |
712 | raise util.Abort( |
|
712 | raise util.Abort( | |
713 | _("a bookmark cannot have the name of an existing branch")) |
|
713 | _("a bookmark cannot have the name of an existing branch")) | |
714 | if rev: |
|
714 | if rev: | |
715 | marks[mark] = repo.lookup(rev) |
|
715 | marks[mark] = repo.lookup(rev) | |
716 | else: |
|
716 | else: | |
717 | marks[mark] = repo.changectx('.').node() |
|
717 | marks[mark] = repo.changectx('.').node() | |
718 | if not inactive and repo.changectx('.').node() == marks[mark]: |
|
718 | if not inactive and repo.changectx('.').node() == marks[mark]: | |
719 | bookmarks.setcurrent(repo, mark) |
|
719 | bookmarks.setcurrent(repo, mark) | |
720 | bookmarks.write(repo) |
|
720 | bookmarks.write(repo) | |
721 | return |
|
721 | return | |
722 |
|
722 | |||
723 | if mark is None: |
|
723 | if mark is None: | |
724 | if rev: |
|
724 | if rev: | |
725 | raise util.Abort(_("bookmark name required")) |
|
725 | raise util.Abort(_("bookmark name required")) | |
726 | if len(marks) == 0: |
|
726 | if len(marks) == 0: | |
727 | ui.status(_("no bookmarks set\n")) |
|
727 | ui.status(_("no bookmarks set\n")) | |
728 | else: |
|
728 | else: | |
729 | for bmark, n in sorted(marks.iteritems()): |
|
729 | for bmark, n in sorted(marks.iteritems()): | |
730 | current = repo._bookmarkcurrent |
|
730 | current = repo._bookmarkcurrent | |
731 | if bmark == current and n == cur: |
|
731 | if bmark == current and n == cur: | |
732 | prefix, label = '*', 'bookmarks.current' |
|
732 | prefix, label = '*', 'bookmarks.current' | |
733 | else: |
|
733 | else: | |
734 | prefix, label = ' ', '' |
|
734 | prefix, label = ' ', '' | |
735 |
|
735 | |||
736 | if ui.quiet: |
|
736 | if ui.quiet: | |
737 | ui.write("%s\n" % bmark, label=label) |
|
737 | ui.write("%s\n" % bmark, label=label) | |
738 | else: |
|
738 | else: | |
739 | ui.write(" %s %-25s %d:%s\n" % ( |
|
739 | ui.write(" %s %-25s %d:%s\n" % ( | |
740 | prefix, bmark, repo.changelog.rev(n), hexfn(n)), |
|
740 | prefix, bmark, repo.changelog.rev(n), hexfn(n)), | |
741 | label=label) |
|
741 | label=label) | |
742 | return |
|
742 | return | |
743 |
|
743 | |||
744 | @command('branch', |
|
744 | @command('branch', | |
745 | [('f', 'force', None, |
|
745 | [('f', 'force', None, | |
746 | _('set branch name even if it shadows an existing branch')), |
|
746 | _('set branch name even if it shadows an existing branch')), | |
747 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
747 | ('C', 'clean', None, _('reset branch name to parent branch name'))], | |
748 | _('[-fC] [NAME]')) |
|
748 | _('[-fC] [NAME]')) | |
749 | def branch(ui, repo, label=None, **opts): |
|
749 | def branch(ui, repo, label=None, **opts): | |
750 | """set or show the current branch name |
|
750 | """set or show the current branch name | |
751 |
|
751 | |||
752 | With no argument, show the current branch name. With one argument, |
|
752 | With no argument, show the current branch name. With one argument, | |
753 | set the working directory branch name (the branch will not exist |
|
753 | set the working directory branch name (the branch will not exist | |
754 | in the repository until the next commit). Standard practice |
|
754 | in the repository until the next commit). Standard practice | |
755 | recommends that primary development take place on the 'default' |
|
755 | recommends that primary development take place on the 'default' | |
756 | branch. |
|
756 | branch. | |
757 |
|
757 | |||
758 | Unless -f/--force is specified, branch will not let you set a |
|
758 | Unless -f/--force is specified, branch will not let you set a | |
759 | branch name that already exists, even if it's inactive. |
|
759 | branch name that already exists, even if it's inactive. | |
760 |
|
760 | |||
761 | Use -C/--clean to reset the working directory branch to that of |
|
761 | Use -C/--clean to reset the working directory branch to that of | |
762 | the parent of the working directory, negating a previous branch |
|
762 | the parent of the working directory, negating a previous branch | |
763 | change. |
|
763 | change. | |
764 |
|
764 | |||
765 | Use the command :hg:`update` to switch to an existing branch. Use |
|
765 | Use the command :hg:`update` to switch to an existing branch. Use | |
766 | :hg:`commit --close-branch` to mark this branch as closed. |
|
766 | :hg:`commit --close-branch` to mark this branch as closed. | |
767 |
|
767 | |||
768 | Returns 0 on success. |
|
768 | Returns 0 on success. | |
769 | """ |
|
769 | """ | |
770 |
|
770 | |||
771 | if opts.get('clean'): |
|
771 | if opts.get('clean'): | |
772 | label = repo[None].p1().branch() |
|
772 | label = repo[None].p1().branch() | |
773 | repo.dirstate.setbranch(label) |
|
773 | repo.dirstate.setbranch(label) | |
774 | ui.status(_('reset working directory to branch %s\n') % label) |
|
774 | ui.status(_('reset working directory to branch %s\n') % label) | |
775 | elif label: |
|
775 | elif label: | |
776 | if not opts.get('force') and label in repo.branchtags(): |
|
776 | if not opts.get('force') and label in repo.branchtags(): | |
777 | if label not in [p.branch() for p in repo.parents()]: |
|
777 | if label not in [p.branch() for p in repo.parents()]: | |
778 | raise util.Abort(_('a branch of the same name already exists'), |
|
778 | raise util.Abort(_('a branch of the same name already exists'), | |
779 | # i18n: "it" refers to an existing branch |
|
779 | # i18n: "it" refers to an existing branch | |
780 | hint=_("use 'hg update' to switch to it")) |
|
780 | hint=_("use 'hg update' to switch to it")) | |
781 | repo.dirstate.setbranch(label) |
|
781 | repo.dirstate.setbranch(label) | |
782 | ui.status(_('marked working directory as branch %s\n') % label) |
|
782 | ui.status(_('marked working directory as branch %s\n') % label) | |
783 | else: |
|
783 | else: | |
784 | ui.write("%s\n" % repo.dirstate.branch()) |
|
784 | ui.write("%s\n" % repo.dirstate.branch()) | |
785 |
|
785 | |||
786 | @command('branches', |
|
786 | @command('branches', | |
787 | [('a', 'active', False, _('show only branches that have unmerged heads')), |
|
787 | [('a', 'active', False, _('show only branches that have unmerged heads')), | |
788 | ('c', 'closed', False, _('show normal and closed branches'))], |
|
788 | ('c', 'closed', False, _('show normal and closed branches'))], | |
789 | _('[-ac]')) |
|
789 | _('[-ac]')) | |
790 | def branches(ui, repo, active=False, closed=False): |
|
790 | def branches(ui, repo, active=False, closed=False): | |
791 | """list repository named branches |
|
791 | """list repository named branches | |
792 |
|
792 | |||
793 | List the repository's named branches, indicating which ones are |
|
793 | List the repository's named branches, indicating which ones are | |
794 | inactive. If -c/--closed is specified, also list branches which have |
|
794 | inactive. If -c/--closed is specified, also list branches which have | |
795 | been marked closed (see :hg:`commit --close-branch`). |
|
795 | been marked closed (see :hg:`commit --close-branch`). | |
796 |
|
796 | |||
797 | If -a/--active is specified, only show active branches. A branch |
|
797 | If -a/--active is specified, only show active branches. A branch | |
798 | is considered active if it contains repository heads. |
|
798 | is considered active if it contains repository heads. | |
799 |
|
799 | |||
800 | Use the command :hg:`update` to switch to an existing branch. |
|
800 | Use the command :hg:`update` to switch to an existing branch. | |
801 |
|
801 | |||
802 | Returns 0. |
|
802 | Returns 0. | |
803 | """ |
|
803 | """ | |
804 |
|
804 | |||
805 | hexfunc = ui.debugflag and hex or short |
|
805 | hexfunc = ui.debugflag and hex or short | |
806 | activebranches = [repo[n].branch() for n in repo.heads()] |
|
806 | activebranches = [repo[n].branch() for n in repo.heads()] | |
807 | def testactive(tag, node): |
|
807 | def testactive(tag, node): | |
808 | realhead = tag in activebranches |
|
808 | realhead = tag in activebranches | |
809 | open = node in repo.branchheads(tag, closed=False) |
|
809 | open = node in repo.branchheads(tag, closed=False) | |
810 | return realhead and open |
|
810 | return realhead and open | |
811 | branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag) |
|
811 | branches = sorted([(testactive(tag, node), repo.changelog.rev(node), tag) | |
812 | for tag, node in repo.branchtags().items()], |
|
812 | for tag, node in repo.branchtags().items()], | |
813 | reverse=True) |
|
813 | reverse=True) | |
814 |
|
814 | |||
815 | for isactive, node, tag in branches: |
|
815 | for isactive, node, tag in branches: | |
816 | if (not active) or isactive: |
|
816 | if (not active) or isactive: | |
817 | if ui.quiet: |
|
817 | if ui.quiet: | |
818 | ui.write("%s\n" % tag) |
|
818 | ui.write("%s\n" % tag) | |
819 | else: |
|
819 | else: | |
820 | hn = repo.lookup(node) |
|
820 | hn = repo.lookup(node) | |
821 | if isactive: |
|
821 | if isactive: | |
822 | label = 'branches.active' |
|
822 | label = 'branches.active' | |
823 | notice = '' |
|
823 | notice = '' | |
824 | elif hn not in repo.branchheads(tag, closed=False): |
|
824 | elif hn not in repo.branchheads(tag, closed=False): | |
825 | if not closed: |
|
825 | if not closed: | |
826 | continue |
|
826 | continue | |
827 | label = 'branches.closed' |
|
827 | label = 'branches.closed' | |
828 | notice = _(' (closed)') |
|
828 | notice = _(' (closed)') | |
829 | else: |
|
829 | else: | |
830 | label = 'branches.inactive' |
|
830 | label = 'branches.inactive' | |
831 | notice = _(' (inactive)') |
|
831 | notice = _(' (inactive)') | |
832 | if tag == repo.dirstate.branch(): |
|
832 | if tag == repo.dirstate.branch(): | |
833 | label = 'branches.current' |
|
833 | label = 'branches.current' | |
834 | rev = str(node).rjust(31 - encoding.colwidth(tag)) |
|
834 | rev = str(node).rjust(31 - encoding.colwidth(tag)) | |
835 | rev = ui.label('%s:%s' % (rev, hexfunc(hn)), 'log.changeset') |
|
835 | rev = ui.label('%s:%s' % (rev, hexfunc(hn)), 'log.changeset') | |
836 | tag = ui.label(tag, label) |
|
836 | tag = ui.label(tag, label) | |
837 | ui.write("%s %s%s\n" % (tag, rev, notice)) |
|
837 | ui.write("%s %s%s\n" % (tag, rev, notice)) | |
838 |
|
838 | |||
839 | @command('bundle', |
|
839 | @command('bundle', | |
840 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
840 | [('f', 'force', None, _('run even when the destination is unrelated')), | |
841 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), |
|
841 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), | |
842 | _('REV')), |
|
842 | _('REV')), | |
843 | ('b', 'branch', [], _('a specific branch you would like to bundle'), |
|
843 | ('b', 'branch', [], _('a specific branch you would like to bundle'), | |
844 | _('BRANCH')), |
|
844 | _('BRANCH')), | |
845 | ('', 'base', [], |
|
845 | ('', 'base', [], | |
846 | _('a base changeset assumed to be available at the destination'), |
|
846 | _('a base changeset assumed to be available at the destination'), | |
847 | _('REV')), |
|
847 | _('REV')), | |
848 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
848 | ('a', 'all', None, _('bundle all changesets in the repository')), | |
849 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), |
|
849 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), | |
850 | ] + remoteopts, |
|
850 | ] + remoteopts, | |
851 | _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]')) |
|
851 | _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]')) | |
852 | def bundle(ui, repo, fname, dest=None, **opts): |
|
852 | def bundle(ui, repo, fname, dest=None, **opts): | |
853 | """create a changegroup file |
|
853 | """create a changegroup file | |
854 |
|
854 | |||
855 | Generate a compressed changegroup file collecting changesets not |
|
855 | Generate a compressed changegroup file collecting changesets not | |
856 | known to be in another repository. |
|
856 | known to be in another repository. | |
857 |
|
857 | |||
858 | If you omit the destination repository, then hg assumes the |
|
858 | If you omit the destination repository, then hg assumes the | |
859 | destination will have all the nodes you specify with --base |
|
859 | destination will have all the nodes you specify with --base | |
860 | parameters. To create a bundle containing all changesets, use |
|
860 | parameters. To create a bundle containing all changesets, use | |
861 | -a/--all (or --base null). |
|
861 | -a/--all (or --base null). | |
862 |
|
862 | |||
863 | You can change compression method with the -t/--type option. |
|
863 | You can change compression method with the -t/--type option. | |
864 | The available compression methods are: none, bzip2, and |
|
864 | The available compression methods are: none, bzip2, and | |
865 | gzip (by default, bundles are compressed using bzip2). |
|
865 | gzip (by default, bundles are compressed using bzip2). | |
866 |
|
866 | |||
867 | The bundle file can then be transferred using conventional means |
|
867 | The bundle file can then be transferred using conventional means | |
868 | and applied to another repository with the unbundle or pull |
|
868 | and applied to another repository with the unbundle or pull | |
869 | command. This is useful when direct push and pull are not |
|
869 | command. This is useful when direct push and pull are not | |
870 | available or when exporting an entire repository is undesirable. |
|
870 | available or when exporting an entire repository is undesirable. | |
871 |
|
871 | |||
872 | Applying bundles preserves all changeset contents including |
|
872 | Applying bundles preserves all changeset contents including | |
873 | permissions, copy/rename information, and revision history. |
|
873 | permissions, copy/rename information, and revision history. | |
874 |
|
874 | |||
875 | Returns 0 on success, 1 if no changes found. |
|
875 | Returns 0 on success, 1 if no changes found. | |
876 | """ |
|
876 | """ | |
877 | revs = None |
|
877 | revs = None | |
878 | if 'rev' in opts: |
|
878 | if 'rev' in opts: | |
879 | revs = scmutil.revrange(repo, opts['rev']) |
|
879 | revs = scmutil.revrange(repo, opts['rev']) | |
880 |
|
880 | |||
881 | if opts.get('all'): |
|
881 | if opts.get('all'): | |
882 | base = ['null'] |
|
882 | base = ['null'] | |
883 | else: |
|
883 | else: | |
884 | base = scmutil.revrange(repo, opts.get('base')) |
|
884 | base = scmutil.revrange(repo, opts.get('base')) | |
885 | if base: |
|
885 | if base: | |
886 | if dest: |
|
886 | if dest: | |
887 | raise util.Abort(_("--base is incompatible with specifying " |
|
887 | raise util.Abort(_("--base is incompatible with specifying " | |
888 | "a destination")) |
|
888 | "a destination")) | |
889 | common = [repo.lookup(rev) for rev in base] |
|
889 | common = [repo.lookup(rev) for rev in base] | |
890 | heads = revs and map(repo.lookup, revs) or revs |
|
890 | heads = revs and map(repo.lookup, revs) or revs | |
891 | else: |
|
891 | else: | |
892 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
892 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
893 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
893 | dest, branches = hg.parseurl(dest, opts.get('branch')) | |
894 | other = hg.repository(hg.remoteui(repo, opts), dest) |
|
894 | other = hg.repository(hg.remoteui(repo, opts), dest) | |
895 | revs, checkout = hg.addbranchrevs(repo, other, branches, revs) |
|
895 | revs, checkout = hg.addbranchrevs(repo, other, branches, revs) | |
896 | heads = revs and map(repo.lookup, revs) or revs |
|
896 | heads = revs and map(repo.lookup, revs) or revs | |
897 | common, outheads = discovery.findcommonoutgoing(repo, other, |
|
897 | common, outheads = discovery.findcommonoutgoing(repo, other, | |
898 | onlyheads=heads, |
|
898 | onlyheads=heads, | |
899 | force=opts.get('force')) |
|
899 | force=opts.get('force')) | |
900 |
|
900 | |||
901 | cg = repo.getbundle('bundle', common=common, heads=heads) |
|
901 | cg = repo.getbundle('bundle', common=common, heads=heads) | |
902 | if not cg: |
|
902 | if not cg: | |
903 | ui.status(_("no changes found\n")) |
|
903 | ui.status(_("no changes found\n")) | |
904 | return 1 |
|
904 | return 1 | |
905 |
|
905 | |||
906 | bundletype = opts.get('type', 'bzip2').lower() |
|
906 | bundletype = opts.get('type', 'bzip2').lower() | |
907 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} |
|
907 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} | |
908 | bundletype = btypes.get(bundletype) |
|
908 | bundletype = btypes.get(bundletype) | |
909 | if bundletype not in changegroup.bundletypes: |
|
909 | if bundletype not in changegroup.bundletypes: | |
910 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
910 | raise util.Abort(_('unknown bundle type specified with --type')) | |
911 |
|
911 | |||
912 | changegroup.writebundle(cg, fname, bundletype) |
|
912 | changegroup.writebundle(cg, fname, bundletype) | |
913 |
|
913 | |||
914 | @command('cat', |
|
914 | @command('cat', | |
915 | [('o', 'output', '', |
|
915 | [('o', 'output', '', | |
916 | _('print output to file with formatted name'), _('FORMAT')), |
|
916 | _('print output to file with formatted name'), _('FORMAT')), | |
917 | ('r', 'rev', '', _('print the given revision'), _('REV')), |
|
917 | ('r', 'rev', '', _('print the given revision'), _('REV')), | |
918 | ('', 'decode', None, _('apply any matching decode filter')), |
|
918 | ('', 'decode', None, _('apply any matching decode filter')), | |
919 | ] + walkopts, |
|
919 | ] + walkopts, | |
920 | _('[OPTION]... FILE...')) |
|
920 | _('[OPTION]... FILE...')) | |
921 | def cat(ui, repo, file1, *pats, **opts): |
|
921 | def cat(ui, repo, file1, *pats, **opts): | |
922 | """output the current or given revision of files |
|
922 | """output the current or given revision of files | |
923 |
|
923 | |||
924 | Print the specified files as they were at the given revision. If |
|
924 | Print the specified files as they were at the given revision. If | |
925 | no revision is given, the parent of the working directory is used, |
|
925 | no revision is given, the parent of the working directory is used, | |
926 | or tip if no revision is checked out. |
|
926 | or tip if no revision is checked out. | |
927 |
|
927 | |||
928 | Output may be to a file, in which case the name of the file is |
|
928 | Output may be to a file, in which case the name of the file is | |
929 | given using a format string. The formatting rules are the same as |
|
929 | given using a format string. The formatting rules are the same as | |
930 | for the export command, with the following additions: |
|
930 | for the export command, with the following additions: | |
931 |
|
931 | |||
932 | :``%s``: basename of file being printed |
|
932 | :``%s``: basename of file being printed | |
933 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
933 | :``%d``: dirname of file being printed, or '.' if in repository root | |
934 | :``%p``: root-relative path name of file being printed |
|
934 | :``%p``: root-relative path name of file being printed | |
935 |
|
935 | |||
936 | Returns 0 on success. |
|
936 | Returns 0 on success. | |
937 | """ |
|
937 | """ | |
938 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
938 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
939 | err = 1 |
|
939 | err = 1 | |
940 | m = cmdutil.match(repo, (file1,) + pats, opts) |
|
940 | m = cmdutil.match(repo, (file1,) + pats, opts) | |
941 | for abs in ctx.walk(m): |
|
941 | for abs in ctx.walk(m): | |
942 | fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), |
|
942 | fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), | |
943 | pathname=abs) |
|
943 | pathname=abs) | |
944 | data = ctx[abs].data() |
|
944 | data = ctx[abs].data() | |
945 | if opts.get('decode'): |
|
945 | if opts.get('decode'): | |
946 | data = repo.wwritedata(abs, data) |
|
946 | data = repo.wwritedata(abs, data) | |
947 | fp.write(data) |
|
947 | fp.write(data) | |
948 | fp.close() |
|
948 | fp.close() | |
949 | err = 0 |
|
949 | err = 0 | |
950 | return err |
|
950 | return err | |
951 |
|
951 | |||
952 | @command('^clone', |
|
952 | @command('^clone', | |
953 | [('U', 'noupdate', None, |
|
953 | [('U', 'noupdate', None, | |
954 | _('the clone will include an empty working copy (only a repository)')), |
|
954 | _('the clone will include an empty working copy (only a repository)')), | |
955 | ('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')), |
|
955 | ('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')), | |
956 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), |
|
956 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), | |
957 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), |
|
957 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), | |
958 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
958 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
959 | ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')), |
|
959 | ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')), | |
960 | ] + remoteopts, |
|
960 | ] + remoteopts, | |
961 | _('[OPTION]... SOURCE [DEST]')) |
|
961 | _('[OPTION]... SOURCE [DEST]')) | |
962 | def clone(ui, source, dest=None, **opts): |
|
962 | def clone(ui, source, dest=None, **opts): | |
963 | """make a copy of an existing repository |
|
963 | """make a copy of an existing repository | |
964 |
|
964 | |||
965 | Create a copy of an existing repository in a new directory. |
|
965 | Create a copy of an existing repository in a new directory. | |
966 |
|
966 | |||
967 | If no destination directory name is specified, it defaults to the |
|
967 | If no destination directory name is specified, it defaults to the | |
968 | basename of the source. |
|
968 | basename of the source. | |
969 |
|
969 | |||
970 | The location of the source is added to the new repository's |
|
970 | The location of the source is added to the new repository's | |
971 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
971 | ``.hg/hgrc`` file, as the default to be used for future pulls. | |
972 |
|
972 | |||
973 | See :hg:`help urls` for valid source format details. |
|
973 | See :hg:`help urls` for valid source format details. | |
974 |
|
974 | |||
975 | It is possible to specify an ``ssh://`` URL as the destination, but no |
|
975 | It is possible to specify an ``ssh://`` URL as the destination, but no | |
976 | ``.hg/hgrc`` and working directory will be created on the remote side. |
|
976 | ``.hg/hgrc`` and working directory will be created on the remote side. | |
977 | Please see :hg:`help urls` for important details about ``ssh://`` URLs. |
|
977 | Please see :hg:`help urls` for important details about ``ssh://`` URLs. | |
978 |
|
978 | |||
979 | A set of changesets (tags, or branch names) to pull may be specified |
|
979 | A set of changesets (tags, or branch names) to pull may be specified | |
980 | by listing each changeset (tag, or branch name) with -r/--rev. |
|
980 | by listing each changeset (tag, or branch name) with -r/--rev. | |
981 | If -r/--rev is used, the cloned repository will contain only a subset |
|
981 | If -r/--rev is used, the cloned repository will contain only a subset | |
982 | of the changesets of the source repository. Only the set of changesets |
|
982 | of the changesets of the source repository. Only the set of changesets | |
983 | defined by all -r/--rev options (including all their ancestors) |
|
983 | defined by all -r/--rev options (including all their ancestors) | |
984 | will be pulled into the destination repository. |
|
984 | will be pulled into the destination repository. | |
985 | No subsequent changesets (including subsequent tags) will be present |
|
985 | No subsequent changesets (including subsequent tags) will be present | |
986 | in the destination. |
|
986 | in the destination. | |
987 |
|
987 | |||
988 | Using -r/--rev (or 'clone src#rev dest') implies --pull, even for |
|
988 | Using -r/--rev (or 'clone src#rev dest') implies --pull, even for | |
989 | local source repositories. |
|
989 | local source repositories. | |
990 |
|
990 | |||
991 | For efficiency, hardlinks are used for cloning whenever the source |
|
991 | For efficiency, hardlinks are used for cloning whenever the source | |
992 | and destination are on the same filesystem (note this applies only |
|
992 | and destination are on the same filesystem (note this applies only | |
993 | to the repository data, not to the working directory). Some |
|
993 | to the repository data, not to the working directory). Some | |
994 | filesystems, such as AFS, implement hardlinking incorrectly, but |
|
994 | filesystems, such as AFS, implement hardlinking incorrectly, but | |
995 | do not report errors. In these cases, use the --pull option to |
|
995 | do not report errors. In these cases, use the --pull option to | |
996 | avoid hardlinking. |
|
996 | avoid hardlinking. | |
997 |
|
997 | |||
998 | In some cases, you can clone repositories and the working directory |
|
998 | In some cases, you can clone repositories and the working directory | |
999 | using full hardlinks with :: |
|
999 | using full hardlinks with :: | |
1000 |
|
1000 | |||
1001 | $ cp -al REPO REPOCLONE |
|
1001 | $ cp -al REPO REPOCLONE | |
1002 |
|
1002 | |||
1003 | This is the fastest way to clone, but it is not always safe. The |
|
1003 | This is the fastest way to clone, but it is not always safe. The | |
1004 | operation is not atomic (making sure REPO is not modified during |
|
1004 | operation is not atomic (making sure REPO is not modified during | |
1005 | the operation is up to you) and you have to make sure your editor |
|
1005 | the operation is up to you) and you have to make sure your editor | |
1006 | breaks hardlinks (Emacs and most Linux Kernel tools do so). Also, |
|
1006 | breaks hardlinks (Emacs and most Linux Kernel tools do so). Also, | |
1007 | this is not compatible with certain extensions that place their |
|
1007 | this is not compatible with certain extensions that place their | |
1008 | metadata under the .hg directory, such as mq. |
|
1008 | metadata under the .hg directory, such as mq. | |
1009 |
|
1009 | |||
1010 | Mercurial will update the working directory to the first applicable |
|
1010 | Mercurial will update the working directory to the first applicable | |
1011 | revision from this list: |
|
1011 | revision from this list: | |
1012 |
|
1012 | |||
1013 | a) null if -U or the source repository has no changesets |
|
1013 | a) null if -U or the source repository has no changesets | |
1014 | b) if -u . and the source repository is local, the first parent of |
|
1014 | b) if -u . and the source repository is local, the first parent of | |
1015 | the source repository's working directory |
|
1015 | the source repository's working directory | |
1016 | c) the changeset specified with -u (if a branch name, this means the |
|
1016 | c) the changeset specified with -u (if a branch name, this means the | |
1017 | latest head of that branch) |
|
1017 | latest head of that branch) | |
1018 | d) the changeset specified with -r |
|
1018 | d) the changeset specified with -r | |
1019 | e) the tipmost head specified with -b |
|
1019 | e) the tipmost head specified with -b | |
1020 | f) the tipmost head specified with the url#branch source syntax |
|
1020 | f) the tipmost head specified with the url#branch source syntax | |
1021 | g) the tipmost head of the default branch |
|
1021 | g) the tipmost head of the default branch | |
1022 | h) tip |
|
1022 | h) tip | |
1023 |
|
1023 | |||
1024 | Returns 0 on success. |
|
1024 | Returns 0 on success. | |
1025 | """ |
|
1025 | """ | |
1026 | if opts.get('noupdate') and opts.get('updaterev'): |
|
1026 | if opts.get('noupdate') and opts.get('updaterev'): | |
1027 | raise util.Abort(_("cannot specify both --noupdate and --updaterev")) |
|
1027 | raise util.Abort(_("cannot specify both --noupdate and --updaterev")) | |
1028 |
|
1028 | |||
1029 | r = hg.clone(hg.remoteui(ui, opts), source, dest, |
|
1029 | r = hg.clone(hg.remoteui(ui, opts), source, dest, | |
1030 | pull=opts.get('pull'), |
|
1030 | pull=opts.get('pull'), | |
1031 | stream=opts.get('uncompressed'), |
|
1031 | stream=opts.get('uncompressed'), | |
1032 | rev=opts.get('rev'), |
|
1032 | rev=opts.get('rev'), | |
1033 | update=opts.get('updaterev') or not opts.get('noupdate'), |
|
1033 | update=opts.get('updaterev') or not opts.get('noupdate'), | |
1034 | branch=opts.get('branch')) |
|
1034 | branch=opts.get('branch')) | |
1035 |
|
1035 | |||
1036 | return r is None |
|
1036 | return r is None | |
1037 |
|
1037 | |||
1038 | @command('^commit|ci', |
|
1038 | @command('^commit|ci', | |
1039 | [('A', 'addremove', None, |
|
1039 | [('A', 'addremove', None, | |
1040 | _('mark new/missing files as added/removed before committing')), |
|
1040 | _('mark new/missing files as added/removed before committing')), | |
1041 | ('', 'close-branch', None, |
|
1041 | ('', 'close-branch', None, | |
1042 | _('mark a branch as closed, hiding it from the branch list')), |
|
1042 | _('mark a branch as closed, hiding it from the branch list')), | |
1043 | ] + walkopts + commitopts + commitopts2, |
|
1043 | ] + walkopts + commitopts + commitopts2, | |
1044 | _('[OPTION]... [FILE]...')) |
|
1044 | _('[OPTION]... [FILE]...')) | |
1045 | def commit(ui, repo, *pats, **opts): |
|
1045 | def commit(ui, repo, *pats, **opts): | |
1046 | """commit the specified files or all outstanding changes |
|
1046 | """commit the specified files or all outstanding changes | |
1047 |
|
1047 | |||
1048 | Commit changes to the given files into the repository. Unlike a |
|
1048 | Commit changes to the given files into the repository. Unlike a | |
1049 | centralized SCM, this operation is a local operation. See |
|
1049 | centralized SCM, this operation is a local operation. See | |
1050 | :hg:`push` for a way to actively distribute your changes. |
|
1050 | :hg:`push` for a way to actively distribute your changes. | |
1051 |
|
1051 | |||
1052 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1052 | If a list of files is omitted, all changes reported by :hg:`status` | |
1053 | will be committed. |
|
1053 | will be committed. | |
1054 |
|
1054 | |||
1055 | If you are committing the result of a merge, do not provide any |
|
1055 | If you are committing the result of a merge, do not provide any | |
1056 | filenames or -I/-X filters. |
|
1056 | filenames or -I/-X filters. | |
1057 |
|
1057 | |||
1058 | If no commit message is specified, Mercurial starts your |
|
1058 | If no commit message is specified, Mercurial starts your | |
1059 | configured editor where you can enter a message. In case your |
|
1059 | configured editor where you can enter a message. In case your | |
1060 | commit fails, you will find a backup of your message in |
|
1060 | commit fails, you will find a backup of your message in | |
1061 | ``.hg/last-message.txt``. |
|
1061 | ``.hg/last-message.txt``. | |
1062 |
|
1062 | |||
1063 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1063 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
1064 |
|
1064 | |||
1065 | Returns 0 on success, 1 if nothing changed. |
|
1065 | Returns 0 on success, 1 if nothing changed. | |
1066 | """ |
|
1066 | """ | |
1067 | extra = {} |
|
1067 | extra = {} | |
1068 | if opts.get('close_branch'): |
|
1068 | if opts.get('close_branch'): | |
1069 | if repo['.'].node() not in repo.branchheads(): |
|
1069 | if repo['.'].node() not in repo.branchheads(): | |
1070 | # The topo heads set is included in the branch heads set of the |
|
1070 | # The topo heads set is included in the branch heads set of the | |
1071 | # current branch, so it's sufficient to test branchheads |
|
1071 | # current branch, so it's sufficient to test branchheads | |
1072 | raise util.Abort(_('can only close branch heads')) |
|
1072 | raise util.Abort(_('can only close branch heads')) | |
1073 | extra['close'] = 1 |
|
1073 | extra['close'] = 1 | |
1074 | e = cmdutil.commiteditor |
|
1074 | e = cmdutil.commiteditor | |
1075 | if opts.get('force_editor'): |
|
1075 | if opts.get('force_editor'): | |
1076 | e = cmdutil.commitforceeditor |
|
1076 | e = cmdutil.commitforceeditor | |
1077 |
|
1077 | |||
1078 | def commitfunc(ui, repo, message, match, opts): |
|
1078 | def commitfunc(ui, repo, message, match, opts): | |
1079 | return repo.commit(message, opts.get('user'), opts.get('date'), match, |
|
1079 | return repo.commit(message, opts.get('user'), opts.get('date'), match, | |
1080 | editor=e, extra=extra) |
|
1080 | editor=e, extra=extra) | |
1081 |
|
1081 | |||
1082 | branch = repo[None].branch() |
|
1082 | branch = repo[None].branch() | |
1083 | bheads = repo.branchheads(branch) |
|
1083 | bheads = repo.branchheads(branch) | |
1084 |
|
1084 | |||
1085 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
1085 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) | |
1086 | if not node: |
|
1086 | if not node: | |
1087 | stat = repo.status(match=cmdutil.match(repo, pats, opts)) |
|
1087 | stat = repo.status(match=cmdutil.match(repo, pats, opts)) | |
1088 | if stat[3]: |
|
1088 | if stat[3]: | |
1089 | ui.status(_("nothing changed (%d missing files, see 'hg status')\n") |
|
1089 | ui.status(_("nothing changed (%d missing files, see 'hg status')\n") | |
1090 | % len(stat[3])) |
|
1090 | % len(stat[3])) | |
1091 | else: |
|
1091 | else: | |
1092 | ui.status(_("nothing changed\n")) |
|
1092 | ui.status(_("nothing changed\n")) | |
1093 | return 1 |
|
1093 | return 1 | |
1094 |
|
1094 | |||
1095 | ctx = repo[node] |
|
1095 | ctx = repo[node] | |
1096 | parents = ctx.parents() |
|
1096 | parents = ctx.parents() | |
1097 |
|
1097 | |||
1098 | if bheads and not [x for x in parents |
|
1098 | if bheads and not [x for x in parents | |
1099 | if x.node() in bheads and x.branch() == branch]: |
|
1099 | if x.node() in bheads and x.branch() == branch]: | |
1100 | ui.status(_('created new head\n')) |
|
1100 | ui.status(_('created new head\n')) | |
1101 | # The message is not printed for initial roots. For the other |
|
1101 | # The message is not printed for initial roots. For the other | |
1102 | # changesets, it is printed in the following situations: |
|
1102 | # changesets, it is printed in the following situations: | |
1103 | # |
|
1103 | # | |
1104 | # Par column: for the 2 parents with ... |
|
1104 | # Par column: for the 2 parents with ... | |
1105 | # N: null or no parent |
|
1105 | # N: null or no parent | |
1106 | # B: parent is on another named branch |
|
1106 | # B: parent is on another named branch | |
1107 | # C: parent is a regular non head changeset |
|
1107 | # C: parent is a regular non head changeset | |
1108 | # H: parent was a branch head of the current branch |
|
1108 | # H: parent was a branch head of the current branch | |
1109 | # Msg column: whether we print "created new head" message |
|
1109 | # Msg column: whether we print "created new head" message | |
1110 | # In the following, it is assumed that there already exists some |
|
1110 | # In the following, it is assumed that there already exists some | |
1111 | # initial branch heads of the current branch, otherwise nothing is |
|
1111 | # initial branch heads of the current branch, otherwise nothing is | |
1112 | # printed anyway. |
|
1112 | # printed anyway. | |
1113 | # |
|
1113 | # | |
1114 | # Par Msg Comment |
|
1114 | # Par Msg Comment | |
1115 | # NN y additional topo root |
|
1115 | # NN y additional topo root | |
1116 | # |
|
1116 | # | |
1117 | # BN y additional branch root |
|
1117 | # BN y additional branch root | |
1118 | # CN y additional topo head |
|
1118 | # CN y additional topo head | |
1119 | # HN n usual case |
|
1119 | # HN n usual case | |
1120 | # |
|
1120 | # | |
1121 | # BB y weird additional branch root |
|
1121 | # BB y weird additional branch root | |
1122 | # CB y branch merge |
|
1122 | # CB y branch merge | |
1123 | # HB n merge with named branch |
|
1123 | # HB n merge with named branch | |
1124 | # |
|
1124 | # | |
1125 | # CC y additional head from merge |
|
1125 | # CC y additional head from merge | |
1126 | # CH n merge with a head |
|
1126 | # CH n merge with a head | |
1127 | # |
|
1127 | # | |
1128 | # HH n head merge: head count decreases |
|
1128 | # HH n head merge: head count decreases | |
1129 |
|
1129 | |||
1130 | if not opts.get('close_branch'): |
|
1130 | if not opts.get('close_branch'): | |
1131 | for r in parents: |
|
1131 | for r in parents: | |
1132 | if r.extra().get('close') and r.branch() == branch: |
|
1132 | if r.extra().get('close') and r.branch() == branch: | |
1133 | ui.status(_('reopening closed branch head %d\n') % r) |
|
1133 | ui.status(_('reopening closed branch head %d\n') % r) | |
1134 |
|
1134 | |||
1135 | if ui.debugflag: |
|
1135 | if ui.debugflag: | |
1136 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex())) |
|
1136 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex())) | |
1137 | elif ui.verbose: |
|
1137 | elif ui.verbose: | |
1138 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx)) |
|
1138 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx)) | |
1139 |
|
1139 | |||
1140 | @command('copy|cp', |
|
1140 | @command('copy|cp', | |
1141 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
1141 | [('A', 'after', None, _('record a copy that has already occurred')), | |
1142 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
1142 | ('f', 'force', None, _('forcibly copy over an existing managed file')), | |
1143 | ] + walkopts + dryrunopts, |
|
1143 | ] + walkopts + dryrunopts, | |
1144 | _('[OPTION]... [SOURCE]... DEST')) |
|
1144 | _('[OPTION]... [SOURCE]... DEST')) | |
1145 | def copy(ui, repo, *pats, **opts): |
|
1145 | def copy(ui, repo, *pats, **opts): | |
1146 | """mark files as copied for the next commit |
|
1146 | """mark files as copied for the next commit | |
1147 |
|
1147 | |||
1148 | Mark dest as having copies of source files. If dest is a |
|
1148 | Mark dest as having copies of source files. If dest is a | |
1149 | directory, copies are put in that directory. If dest is a file, |
|
1149 | directory, copies are put in that directory. If dest is a file, | |
1150 | the source must be a single file. |
|
1150 | the source must be a single file. | |
1151 |
|
1151 | |||
1152 | By default, this command copies the contents of files as they |
|
1152 | By default, this command copies the contents of files as they | |
1153 | exist in the working directory. If invoked with -A/--after, the |
|
1153 | exist in the working directory. If invoked with -A/--after, the | |
1154 | operation is recorded, but no copying is performed. |
|
1154 | operation is recorded, but no copying is performed. | |
1155 |
|
1155 | |||
1156 | This command takes effect with the next commit. To undo a copy |
|
1156 | This command takes effect with the next commit. To undo a copy | |
1157 | before that, see :hg:`revert`. |
|
1157 | before that, see :hg:`revert`. | |
1158 |
|
1158 | |||
1159 | Returns 0 on success, 1 if errors are encountered. |
|
1159 | Returns 0 on success, 1 if errors are encountered. | |
1160 | """ |
|
1160 | """ | |
1161 | wlock = repo.wlock(False) |
|
1161 | wlock = repo.wlock(False) | |
1162 | try: |
|
1162 | try: | |
1163 | return cmdutil.copy(ui, repo, pats, opts) |
|
1163 | return cmdutil.copy(ui, repo, pats, opts) | |
1164 | finally: |
|
1164 | finally: | |
1165 | wlock.release() |
|
1165 | wlock.release() | |
1166 |
|
1166 | |||
1167 | @command('debugancestor', [], _('[INDEX] REV1 REV2')) |
|
1167 | @command('debugancestor', [], _('[INDEX] REV1 REV2')) | |
1168 | def debugancestor(ui, repo, *args): |
|
1168 | def debugancestor(ui, repo, *args): | |
1169 | """find the ancestor revision of two revisions in a given index""" |
|
1169 | """find the ancestor revision of two revisions in a given index""" | |
1170 | if len(args) == 3: |
|
1170 | if len(args) == 3: | |
1171 | index, rev1, rev2 = args |
|
1171 | index, rev1, rev2 = args | |
1172 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) |
|
1172 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) | |
1173 | lookup = r.lookup |
|
1173 | lookup = r.lookup | |
1174 | elif len(args) == 2: |
|
1174 | elif len(args) == 2: | |
1175 | if not repo: |
|
1175 | if not repo: | |
1176 | raise util.Abort(_("there is no Mercurial repository here " |
|
1176 | raise util.Abort(_("there is no Mercurial repository here " | |
1177 | "(.hg not found)")) |
|
1177 | "(.hg not found)")) | |
1178 | rev1, rev2 = args |
|
1178 | rev1, rev2 = args | |
1179 | r = repo.changelog |
|
1179 | r = repo.changelog | |
1180 | lookup = repo.lookup |
|
1180 | lookup = repo.lookup | |
1181 | else: |
|
1181 | else: | |
1182 | raise util.Abort(_('either two or three arguments required')) |
|
1182 | raise util.Abort(_('either two or three arguments required')) | |
1183 | a = r.ancestor(lookup(rev1), lookup(rev2)) |
|
1183 | a = r.ancestor(lookup(rev1), lookup(rev2)) | |
1184 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1184 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | |
1185 |
|
1185 | |||
1186 | @command('debugbuilddag', |
|
1186 | @command('debugbuilddag', | |
1187 | [('m', 'mergeable-file', None, _('add single file mergeable changes')), |
|
1187 | [('m', 'mergeable-file', None, _('add single file mergeable changes')), | |
1188 | ('o', 'overwritten-file', None, _('add single file all revs overwrite')), |
|
1188 | ('o', 'overwritten-file', None, _('add single file all revs overwrite')), | |
1189 | ('n', 'new-file', None, _('add new file at each rev'))], |
|
1189 | ('n', 'new-file', None, _('add new file at each rev'))], | |
1190 | _('[OPTION]... [TEXT]')) |
|
1190 | _('[OPTION]... [TEXT]')) | |
1191 | def debugbuilddag(ui, repo, text=None, |
|
1191 | def debugbuilddag(ui, repo, text=None, | |
1192 | mergeable_file=False, |
|
1192 | mergeable_file=False, | |
1193 | overwritten_file=False, |
|
1193 | overwritten_file=False, | |
1194 | new_file=False): |
|
1194 | new_file=False): | |
1195 | """builds a repo with a given DAG from scratch in the current empty repo |
|
1195 | """builds a repo with a given DAG from scratch in the current empty repo | |
1196 |
|
1196 | |||
1197 | The description of the DAG is read from stdin if not given on the |
|
1197 | The description of the DAG is read from stdin if not given on the | |
1198 | command line. |
|
1198 | command line. | |
1199 |
|
1199 | |||
1200 | Elements: |
|
1200 | Elements: | |
1201 |
|
1201 | |||
1202 | - "+n" is a linear run of n nodes based on the current default parent |
|
1202 | - "+n" is a linear run of n nodes based on the current default parent | |
1203 | - "." is a single node based on the current default parent |
|
1203 | - "." is a single node based on the current default parent | |
1204 | - "$" resets the default parent to null (implied at the start); |
|
1204 | - "$" resets the default parent to null (implied at the start); | |
1205 | otherwise the default parent is always the last node created |
|
1205 | otherwise the default parent is always the last node created | |
1206 | - "<p" sets the default parent to the backref p |
|
1206 | - "<p" sets the default parent to the backref p | |
1207 | - "*p" is a fork at parent p, which is a backref |
|
1207 | - "*p" is a fork at parent p, which is a backref | |
1208 | - "*p1/p2" is a merge of parents p1 and p2, which are backrefs |
|
1208 | - "*p1/p2" is a merge of parents p1 and p2, which are backrefs | |
1209 | - "/p2" is a merge of the preceding node and p2 |
|
1209 | - "/p2" is a merge of the preceding node and p2 | |
1210 | - ":tag" defines a local tag for the preceding node |
|
1210 | - ":tag" defines a local tag for the preceding node | |
1211 | - "@branch" sets the named branch for subsequent nodes |
|
1211 | - "@branch" sets the named branch for subsequent nodes | |
1212 | - "#...\\n" is a comment up to the end of the line |
|
1212 | - "#...\\n" is a comment up to the end of the line | |
1213 |
|
1213 | |||
1214 | Whitespace between the above elements is ignored. |
|
1214 | Whitespace between the above elements is ignored. | |
1215 |
|
1215 | |||
1216 | A backref is either |
|
1216 | A backref is either | |
1217 |
|
1217 | |||
1218 | - a number n, which references the node curr-n, where curr is the current |
|
1218 | - a number n, which references the node curr-n, where curr is the current | |
1219 | node, or |
|
1219 | node, or | |
1220 | - the name of a local tag you placed earlier using ":tag", or |
|
1220 | - the name of a local tag you placed earlier using ":tag", or | |
1221 | - empty to denote the default parent. |
|
1221 | - empty to denote the default parent. | |
1222 |
|
1222 | |||
1223 | All string valued-elements are either strictly alphanumeric, or must |
|
1223 | All string valued-elements are either strictly alphanumeric, or must | |
1224 | be enclosed in double quotes ("..."), with "\\" as escape character. |
|
1224 | be enclosed in double quotes ("..."), with "\\" as escape character. | |
1225 | """ |
|
1225 | """ | |
1226 |
|
1226 | |||
1227 | if text is None: |
|
1227 | if text is None: | |
1228 | ui.status(_("reading DAG from stdin\n")) |
|
1228 | ui.status(_("reading DAG from stdin\n")) | |
1229 | text = sys.stdin.read() |
|
1229 | text = sys.stdin.read() | |
1230 |
|
1230 | |||
1231 | cl = repo.changelog |
|
1231 | cl = repo.changelog | |
1232 | if len(cl) > 0: |
|
1232 | if len(cl) > 0: | |
1233 | raise util.Abort(_('repository is not empty')) |
|
1233 | raise util.Abort(_('repository is not empty')) | |
1234 |
|
1234 | |||
1235 | # determine number of revs in DAG |
|
1235 | # determine number of revs in DAG | |
1236 | total = 0 |
|
1236 | total = 0 | |
1237 | for type, data in dagparser.parsedag(text): |
|
1237 | for type, data in dagparser.parsedag(text): | |
1238 | if type == 'n': |
|
1238 | if type == 'n': | |
1239 | total += 1 |
|
1239 | total += 1 | |
1240 |
|
1240 | |||
1241 | if mergeable_file: |
|
1241 | if mergeable_file: | |
1242 | linesperrev = 2 |
|
1242 | linesperrev = 2 | |
1243 | # make a file with k lines per rev |
|
1243 | # make a file with k lines per rev | |
1244 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] |
|
1244 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] | |
1245 | initialmergedlines.append("") |
|
1245 | initialmergedlines.append("") | |
1246 |
|
1246 | |||
1247 | tags = [] |
|
1247 | tags = [] | |
1248 |
|
1248 | |||
1249 | tr = repo.transaction("builddag") |
|
1249 | tr = repo.transaction("builddag") | |
1250 | try: |
|
1250 | try: | |
1251 |
|
1251 | |||
1252 | at = -1 |
|
1252 | at = -1 | |
1253 | atbranch = 'default' |
|
1253 | atbranch = 'default' | |
1254 | nodeids = [] |
|
1254 | nodeids = [] | |
1255 | ui.progress(_('building'), 0, unit=_('revisions'), total=total) |
|
1255 | ui.progress(_('building'), 0, unit=_('revisions'), total=total) | |
1256 | for type, data in dagparser.parsedag(text): |
|
1256 | for type, data in dagparser.parsedag(text): | |
1257 | if type == 'n': |
|
1257 | if type == 'n': | |
1258 | ui.note('node %s\n' % str(data)) |
|
1258 | ui.note('node %s\n' % str(data)) | |
1259 | id, ps = data |
|
1259 | id, ps = data | |
1260 |
|
1260 | |||
1261 | files = [] |
|
1261 | files = [] | |
1262 | fctxs = {} |
|
1262 | fctxs = {} | |
1263 |
|
1263 | |||
1264 | p2 = None |
|
1264 | p2 = None | |
1265 | if mergeable_file: |
|
1265 | if mergeable_file: | |
1266 | fn = "mf" |
|
1266 | fn = "mf" | |
1267 | p1 = repo[ps[0]] |
|
1267 | p1 = repo[ps[0]] | |
1268 | if len(ps) > 1: |
|
1268 | if len(ps) > 1: | |
1269 | p2 = repo[ps[1]] |
|
1269 | p2 = repo[ps[1]] | |
1270 | pa = p1.ancestor(p2) |
|
1270 | pa = p1.ancestor(p2) | |
1271 | base, local, other = [x[fn].data() for x in pa, p1, p2] |
|
1271 | base, local, other = [x[fn].data() for x in pa, p1, p2] | |
1272 | m3 = simplemerge.Merge3Text(base, local, other) |
|
1272 | m3 = simplemerge.Merge3Text(base, local, other) | |
1273 | ml = [l.strip() for l in m3.merge_lines()] |
|
1273 | ml = [l.strip() for l in m3.merge_lines()] | |
1274 | ml.append("") |
|
1274 | ml.append("") | |
1275 | elif at > 0: |
|
1275 | elif at > 0: | |
1276 | ml = p1[fn].data().split("\n") |
|
1276 | ml = p1[fn].data().split("\n") | |
1277 | else: |
|
1277 | else: | |
1278 | ml = initialmergedlines |
|
1278 | ml = initialmergedlines | |
1279 | ml[id * linesperrev] += " r%i" % id |
|
1279 | ml[id * linesperrev] += " r%i" % id | |
1280 | mergedtext = "\n".join(ml) |
|
1280 | mergedtext = "\n".join(ml) | |
1281 | files.append(fn) |
|
1281 | files.append(fn) | |
1282 | fctxs[fn] = context.memfilectx(fn, mergedtext) |
|
1282 | fctxs[fn] = context.memfilectx(fn, mergedtext) | |
1283 |
|
1283 | |||
1284 | if overwritten_file: |
|
1284 | if overwritten_file: | |
1285 | fn = "of" |
|
1285 | fn = "of" | |
1286 | files.append(fn) |
|
1286 | files.append(fn) | |
1287 | fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) |
|
1287 | fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) | |
1288 |
|
1288 | |||
1289 | if new_file: |
|
1289 | if new_file: | |
1290 | fn = "nf%i" % id |
|
1290 | fn = "nf%i" % id | |
1291 | files.append(fn) |
|
1291 | files.append(fn) | |
1292 | fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) |
|
1292 | fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) | |
1293 | if len(ps) > 1: |
|
1293 | if len(ps) > 1: | |
1294 | if not p2: |
|
1294 | if not p2: | |
1295 | p2 = repo[ps[1]] |
|
1295 | p2 = repo[ps[1]] | |
1296 | for fn in p2: |
|
1296 | for fn in p2: | |
1297 | if fn.startswith("nf"): |
|
1297 | if fn.startswith("nf"): | |
1298 | files.append(fn) |
|
1298 | files.append(fn) | |
1299 | fctxs[fn] = p2[fn] |
|
1299 | fctxs[fn] = p2[fn] | |
1300 |
|
1300 | |||
1301 | def fctxfn(repo, cx, path): |
|
1301 | def fctxfn(repo, cx, path): | |
1302 | return fctxs.get(path) |
|
1302 | return fctxs.get(path) | |
1303 |
|
1303 | |||
1304 | if len(ps) == 0 or ps[0] < 0: |
|
1304 | if len(ps) == 0 or ps[0] < 0: | |
1305 | pars = [None, None] |
|
1305 | pars = [None, None] | |
1306 | elif len(ps) == 1: |
|
1306 | elif len(ps) == 1: | |
1307 | pars = [nodeids[ps[0]], None] |
|
1307 | pars = [nodeids[ps[0]], None] | |
1308 | else: |
|
1308 | else: | |
1309 | pars = [nodeids[p] for p in ps] |
|
1309 | pars = [nodeids[p] for p in ps] | |
1310 | cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn, |
|
1310 | cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn, | |
1311 | date=(id, 0), |
|
1311 | date=(id, 0), | |
1312 | user="debugbuilddag", |
|
1312 | user="debugbuilddag", | |
1313 | extra={'branch': atbranch}) |
|
1313 | extra={'branch': atbranch}) | |
1314 | nodeid = repo.commitctx(cx) |
|
1314 | nodeid = repo.commitctx(cx) | |
1315 | nodeids.append(nodeid) |
|
1315 | nodeids.append(nodeid) | |
1316 | at = id |
|
1316 | at = id | |
1317 | elif type == 'l': |
|
1317 | elif type == 'l': | |
1318 | id, name = data |
|
1318 | id, name = data | |
1319 | ui.note('tag %s\n' % name) |
|
1319 | ui.note('tag %s\n' % name) | |
1320 | tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) |
|
1320 | tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) | |
1321 | elif type == 'a': |
|
1321 | elif type == 'a': | |
1322 | ui.note('branch %s\n' % data) |
|
1322 | ui.note('branch %s\n' % data) | |
1323 | atbranch = data |
|
1323 | atbranch = data | |
1324 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
1324 | ui.progress(_('building'), id, unit=_('revisions'), total=total) | |
1325 | tr.close() |
|
1325 | tr.close() | |
1326 | finally: |
|
1326 | finally: | |
1327 | ui.progress(_('building'), None) |
|
1327 | ui.progress(_('building'), None) | |
1328 | tr.release() |
|
1328 | tr.release() | |
1329 |
|
1329 | |||
1330 | if tags: |
|
1330 | if tags: | |
1331 | repo.opener.write("localtags", "".join(tags)) |
|
1331 | repo.opener.write("localtags", "".join(tags)) | |
1332 |
|
1332 | |||
1333 | @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE')) |
|
1333 | @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE')) | |
1334 | def debugbundle(ui, bundlepath, all=None, **opts): |
|
1334 | def debugbundle(ui, bundlepath, all=None, **opts): | |
1335 | """lists the contents of a bundle""" |
|
1335 | """lists the contents of a bundle""" | |
1336 | f = url.open(ui, bundlepath) |
|
1336 | f = url.open(ui, bundlepath) | |
1337 | try: |
|
1337 | try: | |
1338 | gen = changegroup.readbundle(f, bundlepath) |
|
1338 | gen = changegroup.readbundle(f, bundlepath) | |
1339 | if all: |
|
1339 | if all: | |
1340 | ui.write("format: id, p1, p2, cset, delta base, len(delta)\n") |
|
1340 | ui.write("format: id, p1, p2, cset, delta base, len(delta)\n") | |
1341 |
|
1341 | |||
1342 | def showchunks(named): |
|
1342 | def showchunks(named): | |
1343 | ui.write("\n%s\n" % named) |
|
1343 | ui.write("\n%s\n" % named) | |
1344 | chain = None |
|
1344 | chain = None | |
1345 | while 1: |
|
1345 | while 1: | |
1346 | chunkdata = gen.deltachunk(chain) |
|
1346 | chunkdata = gen.deltachunk(chain) | |
1347 | if not chunkdata: |
|
1347 | if not chunkdata: | |
1348 | break |
|
1348 | break | |
1349 | node = chunkdata['node'] |
|
1349 | node = chunkdata['node'] | |
1350 | p1 = chunkdata['p1'] |
|
1350 | p1 = chunkdata['p1'] | |
1351 | p2 = chunkdata['p2'] |
|
1351 | p2 = chunkdata['p2'] | |
1352 | cs = chunkdata['cs'] |
|
1352 | cs = chunkdata['cs'] | |
1353 | deltabase = chunkdata['deltabase'] |
|
1353 | deltabase = chunkdata['deltabase'] | |
1354 | delta = chunkdata['delta'] |
|
1354 | delta = chunkdata['delta'] | |
1355 | ui.write("%s %s %s %s %s %s\n" % |
|
1355 | ui.write("%s %s %s %s %s %s\n" % | |
1356 | (hex(node), hex(p1), hex(p2), |
|
1356 | (hex(node), hex(p1), hex(p2), | |
1357 | hex(cs), hex(deltabase), len(delta))) |
|
1357 | hex(cs), hex(deltabase), len(delta))) | |
1358 | chain = node |
|
1358 | chain = node | |
1359 |
|
1359 | |||
1360 | chunkdata = gen.changelogheader() |
|
1360 | chunkdata = gen.changelogheader() | |
1361 | showchunks("changelog") |
|
1361 | showchunks("changelog") | |
1362 | chunkdata = gen.manifestheader() |
|
1362 | chunkdata = gen.manifestheader() | |
1363 | showchunks("manifest") |
|
1363 | showchunks("manifest") | |
1364 | while 1: |
|
1364 | while 1: | |
1365 | chunkdata = gen.filelogheader() |
|
1365 | chunkdata = gen.filelogheader() | |
1366 | if not chunkdata: |
|
1366 | if not chunkdata: | |
1367 | break |
|
1367 | break | |
1368 | fname = chunkdata['filename'] |
|
1368 | fname = chunkdata['filename'] | |
1369 | showchunks(fname) |
|
1369 | showchunks(fname) | |
1370 | else: |
|
1370 | else: | |
1371 | chunkdata = gen.changelogheader() |
|
1371 | chunkdata = gen.changelogheader() | |
1372 | chain = None |
|
1372 | chain = None | |
1373 | while 1: |
|
1373 | while 1: | |
1374 | chunkdata = gen.deltachunk(chain) |
|
1374 | chunkdata = gen.deltachunk(chain) | |
1375 | if not chunkdata: |
|
1375 | if not chunkdata: | |
1376 | break |
|
1376 | break | |
1377 | node = chunkdata['node'] |
|
1377 | node = chunkdata['node'] | |
1378 | ui.write("%s\n" % hex(node)) |
|
1378 | ui.write("%s\n" % hex(node)) | |
1379 | chain = node |
|
1379 | chain = node | |
1380 | finally: |
|
1380 | finally: | |
1381 | f.close() |
|
1381 | f.close() | |
1382 |
|
1382 | |||
1383 | @command('debugcheckstate', [], '') |
|
1383 | @command('debugcheckstate', [], '') | |
1384 | def debugcheckstate(ui, repo): |
|
1384 | def debugcheckstate(ui, repo): | |
1385 | """validate the correctness of the current dirstate""" |
|
1385 | """validate the correctness of the current dirstate""" | |
1386 | parent1, parent2 = repo.dirstate.parents() |
|
1386 | parent1, parent2 = repo.dirstate.parents() | |
1387 | m1 = repo[parent1].manifest() |
|
1387 | m1 = repo[parent1].manifest() | |
1388 | m2 = repo[parent2].manifest() |
|
1388 | m2 = repo[parent2].manifest() | |
1389 | errors = 0 |
|
1389 | errors = 0 | |
1390 | for f in repo.dirstate: |
|
1390 | for f in repo.dirstate: | |
1391 | state = repo.dirstate[f] |
|
1391 | state = repo.dirstate[f] | |
1392 | if state in "nr" and f not in m1: |
|
1392 | if state in "nr" and f not in m1: | |
1393 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1393 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | |
1394 | errors += 1 |
|
1394 | errors += 1 | |
1395 | if state in "a" and f in m1: |
|
1395 | if state in "a" and f in m1: | |
1396 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1396 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | |
1397 | errors += 1 |
|
1397 | errors += 1 | |
1398 | if state in "m" and f not in m1 and f not in m2: |
|
1398 | if state in "m" and f not in m1 and f not in m2: | |
1399 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1399 | ui.warn(_("%s in state %s, but not in either manifest\n") % | |
1400 | (f, state)) |
|
1400 | (f, state)) | |
1401 | errors += 1 |
|
1401 | errors += 1 | |
1402 | for f in m1: |
|
1402 | for f in m1: | |
1403 | state = repo.dirstate[f] |
|
1403 | state = repo.dirstate[f] | |
1404 | if state not in "nrm": |
|
1404 | if state not in "nrm": | |
1405 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1405 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | |
1406 | errors += 1 |
|
1406 | errors += 1 | |
1407 | if errors: |
|
1407 | if errors: | |
1408 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1408 | error = _(".hg/dirstate inconsistent with current parent's manifest") | |
1409 | raise util.Abort(error) |
|
1409 | raise util.Abort(error) | |
1410 |
|
1410 | |||
1411 | @command('debugcommands', [], _('[COMMAND]')) |
|
1411 | @command('debugcommands', [], _('[COMMAND]')) | |
1412 | def debugcommands(ui, cmd='', *args): |
|
1412 | def debugcommands(ui, cmd='', *args): | |
1413 | """list all available commands and options""" |
|
1413 | """list all available commands and options""" | |
1414 | for cmd, vals in sorted(table.iteritems()): |
|
1414 | for cmd, vals in sorted(table.iteritems()): | |
1415 | cmd = cmd.split('|')[0].strip('^') |
|
1415 | cmd = cmd.split('|')[0].strip('^') | |
1416 | opts = ', '.join([i[1] for i in vals[1]]) |
|
1416 | opts = ', '.join([i[1] for i in vals[1]]) | |
1417 | ui.write('%s: %s\n' % (cmd, opts)) |
|
1417 | ui.write('%s: %s\n' % (cmd, opts)) | |
1418 |
|
1418 | |||
1419 | @command('debugcomplete', |
|
1419 | @command('debugcomplete', | |
1420 | [('o', 'options', None, _('show the command options'))], |
|
1420 | [('o', 'options', None, _('show the command options'))], | |
1421 | _('[-o] CMD')) |
|
1421 | _('[-o] CMD')) | |
1422 | def debugcomplete(ui, cmd='', **opts): |
|
1422 | def debugcomplete(ui, cmd='', **opts): | |
1423 | """returns the completion list associated with the given command""" |
|
1423 | """returns the completion list associated with the given command""" | |
1424 |
|
1424 | |||
1425 | if opts.get('options'): |
|
1425 | if opts.get('options'): | |
1426 | options = [] |
|
1426 | options = [] | |
1427 | otables = [globalopts] |
|
1427 | otables = [globalopts] | |
1428 | if cmd: |
|
1428 | if cmd: | |
1429 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
1429 | aliases, entry = cmdutil.findcmd(cmd, table, False) | |
1430 | otables.append(entry[1]) |
|
1430 | otables.append(entry[1]) | |
1431 | for t in otables: |
|
1431 | for t in otables: | |
1432 | for o in t: |
|
1432 | for o in t: | |
1433 | if "(DEPRECATED)" in o[3]: |
|
1433 | if "(DEPRECATED)" in o[3]: | |
1434 | continue |
|
1434 | continue | |
1435 | if o[0]: |
|
1435 | if o[0]: | |
1436 | options.append('-%s' % o[0]) |
|
1436 | options.append('-%s' % o[0]) | |
1437 | options.append('--%s' % o[1]) |
|
1437 | options.append('--%s' % o[1]) | |
1438 | ui.write("%s\n" % "\n".join(options)) |
|
1438 | ui.write("%s\n" % "\n".join(options)) | |
1439 | return |
|
1439 | return | |
1440 |
|
1440 | |||
1441 | cmdlist = cmdutil.findpossible(cmd, table) |
|
1441 | cmdlist = cmdutil.findpossible(cmd, table) | |
1442 | if ui.verbose: |
|
1442 | if ui.verbose: | |
1443 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
1443 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] | |
1444 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
1444 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) | |
1445 |
|
1445 | |||
1446 | @command('debugdag', |
|
1446 | @command('debugdag', | |
1447 | [('t', 'tags', None, _('use tags as labels')), |
|
1447 | [('t', 'tags', None, _('use tags as labels')), | |
1448 | ('b', 'branches', None, _('annotate with branch names')), |
|
1448 | ('b', 'branches', None, _('annotate with branch names')), | |
1449 | ('', 'dots', None, _('use dots for runs')), |
|
1449 | ('', 'dots', None, _('use dots for runs')), | |
1450 | ('s', 'spaces', None, _('separate elements by spaces'))], |
|
1450 | ('s', 'spaces', None, _('separate elements by spaces'))], | |
1451 | _('[OPTION]... [FILE [REV]...]')) |
|
1451 | _('[OPTION]... [FILE [REV]...]')) | |
1452 | def debugdag(ui, repo, file_=None, *revs, **opts): |
|
1452 | def debugdag(ui, repo, file_=None, *revs, **opts): | |
1453 | """format the changelog or an index DAG as a concise textual description |
|
1453 | """format the changelog or an index DAG as a concise textual description | |
1454 |
|
1454 | |||
1455 | If you pass a revlog index, the revlog's DAG is emitted. If you list |
|
1455 | If you pass a revlog index, the revlog's DAG is emitted. If you list | |
1456 | revision numbers, they get labelled in the output as rN. |
|
1456 | revision numbers, they get labelled in the output as rN. | |
1457 |
|
1457 | |||
1458 | Otherwise, the changelog DAG of the current repo is emitted. |
|
1458 | Otherwise, the changelog DAG of the current repo is emitted. | |
1459 | """ |
|
1459 | """ | |
1460 | spaces = opts.get('spaces') |
|
1460 | spaces = opts.get('spaces') | |
1461 | dots = opts.get('dots') |
|
1461 | dots = opts.get('dots') | |
1462 | if file_: |
|
1462 | if file_: | |
1463 | rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
1463 | rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) | |
1464 | revs = set((int(r) for r in revs)) |
|
1464 | revs = set((int(r) for r in revs)) | |
1465 | def events(): |
|
1465 | def events(): | |
1466 | for r in rlog: |
|
1466 | for r in rlog: | |
1467 | yield 'n', (r, list(set(p for p in rlog.parentrevs(r) if p != -1))) |
|
1467 | yield 'n', (r, list(set(p for p in rlog.parentrevs(r) if p != -1))) | |
1468 | if r in revs: |
|
1468 | if r in revs: | |
1469 | yield 'l', (r, "r%i" % r) |
|
1469 | yield 'l', (r, "r%i" % r) | |
1470 | elif repo: |
|
1470 | elif repo: | |
1471 | cl = repo.changelog |
|
1471 | cl = repo.changelog | |
1472 | tags = opts.get('tags') |
|
1472 | tags = opts.get('tags') | |
1473 | branches = opts.get('branches') |
|
1473 | branches = opts.get('branches') | |
1474 | if tags: |
|
1474 | if tags: | |
1475 | labels = {} |
|
1475 | labels = {} | |
1476 | for l, n in repo.tags().items(): |
|
1476 | for l, n in repo.tags().items(): | |
1477 | labels.setdefault(cl.rev(n), []).append(l) |
|
1477 | labels.setdefault(cl.rev(n), []).append(l) | |
1478 | def events(): |
|
1478 | def events(): | |
1479 | b = "default" |
|
1479 | b = "default" | |
1480 | for r in cl: |
|
1480 | for r in cl: | |
1481 | if branches: |
|
1481 | if branches: | |
1482 | newb = cl.read(cl.node(r))[5]['branch'] |
|
1482 | newb = cl.read(cl.node(r))[5]['branch'] | |
1483 | if newb != b: |
|
1483 | if newb != b: | |
1484 | yield 'a', newb |
|
1484 | yield 'a', newb | |
1485 | b = newb |
|
1485 | b = newb | |
1486 | yield 'n', (r, list(set(p for p in cl.parentrevs(r) if p != -1))) |
|
1486 | yield 'n', (r, list(set(p for p in cl.parentrevs(r) if p != -1))) | |
1487 | if tags: |
|
1487 | if tags: | |
1488 | ls = labels.get(r) |
|
1488 | ls = labels.get(r) | |
1489 | if ls: |
|
1489 | if ls: | |
1490 | for l in ls: |
|
1490 | for l in ls: | |
1491 | yield 'l', (r, l) |
|
1491 | yield 'l', (r, l) | |
1492 | else: |
|
1492 | else: | |
1493 | raise util.Abort(_('need repo for changelog dag')) |
|
1493 | raise util.Abort(_('need repo for changelog dag')) | |
1494 |
|
1494 | |||
1495 | for line in dagparser.dagtextlines(events(), |
|
1495 | for line in dagparser.dagtextlines(events(), | |
1496 | addspaces=spaces, |
|
1496 | addspaces=spaces, | |
1497 | wraplabels=True, |
|
1497 | wraplabels=True, | |
1498 | wrapannotations=True, |
|
1498 | wrapannotations=True, | |
1499 | wrapnonlinear=dots, |
|
1499 | wrapnonlinear=dots, | |
1500 | usedots=dots, |
|
1500 | usedots=dots, | |
1501 | maxlinewidth=70): |
|
1501 | maxlinewidth=70): | |
1502 | ui.write(line) |
|
1502 | ui.write(line) | |
1503 | ui.write("\n") |
|
1503 | ui.write("\n") | |
1504 |
|
1504 | |||
1505 | @command('debugdata', [], _('FILE REV')) |
|
1505 | @command('debugdata', [], _('FILE REV')) | |
1506 | def debugdata(ui, repo, file_, rev): |
|
1506 | def debugdata(ui, repo, file_, rev): | |
1507 | """dump the contents of a data file revision""" |
|
1507 | """dump the contents of a data file revision""" | |
1508 | r = None |
|
1508 | r = None | |
1509 | if repo: |
|
1509 | if repo: | |
1510 | filelog = repo.file(file_) |
|
1510 | filelog = repo.file(file_) | |
1511 | if len(filelog): |
|
1511 | if len(filelog): | |
1512 | r = filelog |
|
1512 | r = filelog | |
1513 | if not r: |
|
1513 | if not r: | |
1514 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), |
|
1514 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), | |
1515 | file_[:-2] + ".i") |
|
1515 | file_[:-2] + ".i") | |
1516 | try: |
|
1516 | try: | |
1517 | ui.write(r.revision(r.lookup(rev))) |
|
1517 | ui.write(r.revision(r.lookup(rev))) | |
1518 | except KeyError: |
|
1518 | except KeyError: | |
1519 | raise util.Abort(_('invalid revision identifier %s') % rev) |
|
1519 | raise util.Abort(_('invalid revision identifier %s') % rev) | |
1520 |
|
1520 | |||
1521 | @command('debugdate', |
|
1521 | @command('debugdate', | |
1522 | [('e', 'extended', None, _('try extended date formats'))], |
|
1522 | [('e', 'extended', None, _('try extended date formats'))], | |
1523 | _('[-e] DATE [RANGE]')) |
|
1523 | _('[-e] DATE [RANGE]')) | |
1524 | def debugdate(ui, date, range=None, **opts): |
|
1524 | def debugdate(ui, date, range=None, **opts): | |
1525 | """parse and display a date""" |
|
1525 | """parse and display a date""" | |
1526 | if opts["extended"]: |
|
1526 | if opts["extended"]: | |
1527 | d = util.parsedate(date, util.extendeddateformats) |
|
1527 | d = util.parsedate(date, util.extendeddateformats) | |
1528 | else: |
|
1528 | else: | |
1529 | d = util.parsedate(date) |
|
1529 | d = util.parsedate(date) | |
1530 | ui.write("internal: %s %s\n" % d) |
|
1530 | ui.write("internal: %s %s\n" % d) | |
1531 | ui.write("standard: %s\n" % util.datestr(d)) |
|
1531 | ui.write("standard: %s\n" % util.datestr(d)) | |
1532 | if range: |
|
1532 | if range: | |
1533 | m = util.matchdate(range) |
|
1533 | m = util.matchdate(range) | |
1534 | ui.write("match: %s\n" % m(d[0])) |
|
1534 | ui.write("match: %s\n" % m(d[0])) | |
1535 |
|
1535 | |||
1536 | @command('debugdiscovery', |
|
1536 | @command('debugdiscovery', | |
1537 | [('', 'old', None, _('use old-style discovery')), |
|
1537 | [('', 'old', None, _('use old-style discovery')), | |
1538 | ('', 'nonheads', None, |
|
1538 | ('', 'nonheads', None, | |
1539 | _('use old-style discovery with non-heads included')), |
|
1539 | _('use old-style discovery with non-heads included')), | |
1540 | ] + remoteopts, |
|
1540 | ] + remoteopts, | |
1541 | _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) |
|
1541 | _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) | |
1542 | def debugdiscovery(ui, repo, remoteurl="default", **opts): |
|
1542 | def debugdiscovery(ui, repo, remoteurl="default", **opts): | |
1543 | """runs the changeset discovery protocol in isolation""" |
|
1543 | """runs the changeset discovery protocol in isolation""" | |
1544 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), opts.get('branch')) |
|
1544 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), opts.get('branch')) | |
1545 | remote = hg.repository(hg.remoteui(repo, opts), remoteurl) |
|
1545 | remote = hg.repository(hg.remoteui(repo, opts), remoteurl) | |
1546 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) |
|
1546 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) | |
1547 |
|
1547 | |||
1548 | # make sure tests are repeatable |
|
1548 | # make sure tests are repeatable | |
1549 | random.seed(12323) |
|
1549 | random.seed(12323) | |
1550 |
|
1550 | |||
1551 | def doit(localheads, remoteheads): |
|
1551 | def doit(localheads, remoteheads): | |
1552 | if opts.get('old'): |
|
1552 | if opts.get('old'): | |
1553 | if localheads: |
|
1553 | if localheads: | |
1554 | raise util.Abort('cannot use localheads with old style discovery') |
|
1554 | raise util.Abort('cannot use localheads with old style discovery') | |
1555 | common, _in, hds = treediscovery.findcommonincoming(repo, remote, |
|
1555 | common, _in, hds = treediscovery.findcommonincoming(repo, remote, | |
1556 | force=True) |
|
1556 | force=True) | |
1557 | common = set(common) |
|
1557 | common = set(common) | |
1558 | if not opts.get('nonheads'): |
|
1558 | if not opts.get('nonheads'): | |
1559 | ui.write("unpruned common: %s\n" % " ".join([short(n) |
|
1559 | ui.write("unpruned common: %s\n" % " ".join([short(n) | |
1560 | for n in common])) |
|
1560 | for n in common])) | |
1561 | dag = dagutil.revlogdag(repo.changelog) |
|
1561 | dag = dagutil.revlogdag(repo.changelog) | |
1562 | all = dag.ancestorset(dag.internalizeall(common)) |
|
1562 | all = dag.ancestorset(dag.internalizeall(common)) | |
1563 | common = dag.externalizeall(dag.headsetofconnecteds(all)) |
|
1563 | common = dag.externalizeall(dag.headsetofconnecteds(all)) | |
1564 | else: |
|
1564 | else: | |
1565 | common, any, hds = setdiscovery.findcommonheads(ui, repo, remote) |
|
1565 | common, any, hds = setdiscovery.findcommonheads(ui, repo, remote) | |
1566 | common = set(common) |
|
1566 | common = set(common) | |
1567 | rheads = set(hds) |
|
1567 | rheads = set(hds) | |
1568 | lheads = set(repo.heads()) |
|
1568 | lheads = set(repo.heads()) | |
1569 | ui.write("common heads: %s\n" % " ".join([short(n) for n in common])) |
|
1569 | ui.write("common heads: %s\n" % " ".join([short(n) for n in common])) | |
1570 | if lheads <= common: |
|
1570 | if lheads <= common: | |
1571 | ui.write("local is subset\n") |
|
1571 | ui.write("local is subset\n") | |
1572 | elif rheads <= common: |
|
1572 | elif rheads <= common: | |
1573 | ui.write("remote is subset\n") |
|
1573 | ui.write("remote is subset\n") | |
1574 |
|
1574 | |||
1575 | serverlogs = opts.get('serverlog') |
|
1575 | serverlogs = opts.get('serverlog') | |
1576 | if serverlogs: |
|
1576 | if serverlogs: | |
1577 | for filename in serverlogs: |
|
1577 | for filename in serverlogs: | |
1578 | logfile = open(filename, 'r') |
|
1578 | logfile = open(filename, 'r') | |
1579 | try: |
|
1579 | try: | |
1580 | line = logfile.readline() |
|
1580 | line = logfile.readline() | |
1581 | while line: |
|
1581 | while line: | |
1582 | parts = line.strip().split(';') |
|
1582 | parts = line.strip().split(';') | |
1583 | op = parts[1] |
|
1583 | op = parts[1] | |
1584 | if op == 'cg': |
|
1584 | if op == 'cg': | |
1585 | pass |
|
1585 | pass | |
1586 | elif op == 'cgss': |
|
1586 | elif op == 'cgss': | |
1587 | doit(parts[2].split(' '), parts[3].split(' ')) |
|
1587 | doit(parts[2].split(' '), parts[3].split(' ')) | |
1588 | elif op == 'unb': |
|
1588 | elif op == 'unb': | |
1589 | doit(parts[3].split(' '), parts[2].split(' ')) |
|
1589 | doit(parts[3].split(' '), parts[2].split(' ')) | |
1590 | line = logfile.readline() |
|
1590 | line = logfile.readline() | |
1591 | finally: |
|
1591 | finally: | |
1592 | logfile.close() |
|
1592 | logfile.close() | |
1593 |
|
1593 | |||
1594 | else: |
|
1594 | else: | |
1595 | remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, |
|
1595 | remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, | |
1596 | opts.get('remote_head')) |
|
1596 | opts.get('remote_head')) | |
1597 | localrevs = opts.get('local_head') |
|
1597 | localrevs = opts.get('local_head') | |
1598 | doit(localrevs, remoterevs) |
|
1598 | doit(localrevs, remoterevs) | |
1599 |
|
1599 | |||
1600 | @command('debugfsinfo', [], _('[PATH]')) |
|
1600 | @command('debugfsinfo', [], _('[PATH]')) | |
1601 | def debugfsinfo(ui, path = "."): |
|
1601 | def debugfsinfo(ui, path = "."): | |
1602 | """show information detected about current filesystem""" |
|
1602 | """show information detected about current filesystem""" | |
1603 | util.writefile('.debugfsinfo', '') |
|
1603 | util.writefile('.debugfsinfo', '') | |
1604 | ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) |
|
1604 | ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) | |
1605 | ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) |
|
1605 | ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) | |
1606 | ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') |
|
1606 | ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') | |
1607 | and 'yes' or 'no')) |
|
1607 | and 'yes' or 'no')) | |
1608 | os.unlink('.debugfsinfo') |
|
1608 | os.unlink('.debugfsinfo') | |
1609 |
|
1609 | |||
1610 | @command('debuggetbundle', |
|
1610 | @command('debuggetbundle', | |
1611 | [('H', 'head', [], _('id of head node'), _('ID')), |
|
1611 | [('H', 'head', [], _('id of head node'), _('ID')), | |
1612 | ('C', 'common', [], _('id of common node'), _('ID')), |
|
1612 | ('C', 'common', [], _('id of common node'), _('ID')), | |
1613 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))], |
|
1613 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))], | |
1614 | _('REPO FILE [-H|-C ID]...')) |
|
1614 | _('REPO FILE [-H|-C ID]...')) | |
1615 | def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts): |
|
1615 | def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts): | |
1616 | """retrieves a bundle from a repo |
|
1616 | """retrieves a bundle from a repo | |
1617 |
|
1617 | |||
1618 | Every ID must be a full-length hex node id string. Saves the bundle to the |
|
1618 | Every ID must be a full-length hex node id string. Saves the bundle to the | |
1619 | given file. |
|
1619 | given file. | |
1620 | """ |
|
1620 | """ | |
1621 | repo = hg.repository(ui, repopath) |
|
1621 | repo = hg.repository(ui, repopath) | |
1622 | if not repo.capable('getbundle'): |
|
1622 | if not repo.capable('getbundle'): | |
1623 | raise util.Abort("getbundle() not supported by target repository") |
|
1623 | raise util.Abort("getbundle() not supported by target repository") | |
1624 | args = {} |
|
1624 | args = {} | |
1625 | if common: |
|
1625 | if common: | |
1626 | args['common'] = [bin(s) for s in common] |
|
1626 | args['common'] = [bin(s) for s in common] | |
1627 | if head: |
|
1627 | if head: | |
1628 | args['heads'] = [bin(s) for s in head] |
|
1628 | args['heads'] = [bin(s) for s in head] | |
1629 | bundle = repo.getbundle('debug', **args) |
|
1629 | bundle = repo.getbundle('debug', **args) | |
1630 |
|
1630 | |||
1631 | bundletype = opts.get('type', 'bzip2').lower() |
|
1631 | bundletype = opts.get('type', 'bzip2').lower() | |
1632 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} |
|
1632 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} | |
1633 | bundletype = btypes.get(bundletype) |
|
1633 | bundletype = btypes.get(bundletype) | |
1634 | if bundletype not in changegroup.bundletypes: |
|
1634 | if bundletype not in changegroup.bundletypes: | |
1635 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
1635 | raise util.Abort(_('unknown bundle type specified with --type')) | |
1636 | changegroup.writebundle(bundle, bundlepath, bundletype) |
|
1636 | changegroup.writebundle(bundle, bundlepath, bundletype) | |
1637 |
|
1637 | |||
1638 | @command('debugignore', [], '') |
|
1638 | @command('debugignore', [], '') | |
1639 | def debugignore(ui, repo, *values, **opts): |
|
1639 | def debugignore(ui, repo, *values, **opts): | |
1640 | """display the combined ignore pattern""" |
|
1640 | """display the combined ignore pattern""" | |
1641 | ignore = repo.dirstate._ignore |
|
1641 | ignore = repo.dirstate._ignore | |
1642 | if hasattr(ignore, 'includepat'): |
|
1642 | if hasattr(ignore, 'includepat'): | |
1643 | ui.write("%s\n" % ignore.includepat) |
|
1643 | ui.write("%s\n" % ignore.includepat) | |
1644 | else: |
|
1644 | else: | |
1645 | raise util.Abort(_("no ignore patterns found")) |
|
1645 | raise util.Abort(_("no ignore patterns found")) | |
1646 |
|
1646 | |||
1647 | @command('debugindex', |
|
1647 | @command('debugindex', | |
1648 | [('f', 'format', 0, _('revlog format'), _('FORMAT'))], |
|
1648 | [('f', 'format', 0, _('revlog format'), _('FORMAT'))], | |
1649 | _('FILE')) |
|
1649 | _('FILE')) | |
1650 | def debugindex(ui, repo, file_, **opts): |
|
1650 | def debugindex(ui, repo, file_, **opts): | |
1651 | """dump the contents of an index file""" |
|
1651 | """dump the contents of an index file""" | |
1652 | r = None |
|
1652 | r = None | |
1653 | if repo: |
|
1653 | if repo: | |
1654 | filelog = repo.file(file_) |
|
1654 | filelog = repo.file(file_) | |
1655 | if len(filelog): |
|
1655 | if len(filelog): | |
1656 | r = filelog |
|
1656 | r = filelog | |
1657 |
|
1657 | |||
1658 | format = opts.get('format', 0) |
|
1658 | format = opts.get('format', 0) | |
1659 | if format not in (0, 1): |
|
1659 | if format not in (0, 1): | |
1660 | raise util.Abort(_("unknown format %d") % format) |
|
1660 | raise util.Abort(_("unknown format %d") % format) | |
1661 |
|
1661 | |||
1662 | if not r: |
|
1662 | if not r: | |
1663 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
1663 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) | |
1664 |
|
1664 | |||
1665 | generaldelta = r.version & revlog.REVLOGGENERALDELTA |
|
1665 | generaldelta = r.version & revlog.REVLOGGENERALDELTA | |
1666 | if generaldelta: |
|
1666 | if generaldelta: | |
1667 | basehdr = ' delta' |
|
1667 | basehdr = ' delta' | |
1668 | else: |
|
1668 | else: | |
1669 | basehdr = ' base' |
|
1669 | basehdr = ' base' | |
1670 |
|
1670 | |||
1671 | if format == 0: |
|
1671 | if format == 0: | |
1672 | ui.write(" rev offset length " + basehdr + " linkrev" |
|
1672 | ui.write(" rev offset length " + basehdr + " linkrev" | |
1673 | " nodeid p1 p2\n") |
|
1673 | " nodeid p1 p2\n") | |
1674 | elif format == 1: |
|
1674 | elif format == 1: | |
1675 | ui.write(" rev flag offset length" |
|
1675 | ui.write(" rev flag offset length" | |
1676 | " size " + basehdr + " link p1 p2 nodeid\n") |
|
1676 | " size " + basehdr + " link p1 p2 nodeid\n") | |
1677 |
|
1677 | |||
1678 | for i in r: |
|
1678 | for i in r: | |
1679 | node = r.node(i) |
|
1679 | node = r.node(i) | |
1680 | if generaldelta: |
|
1680 | if generaldelta: | |
1681 | base = r.deltaparent(i) |
|
1681 | base = r.deltaparent(i) | |
1682 | else: |
|
1682 | else: | |
1683 | base = r.chainbase(i) |
|
1683 | base = r.chainbase(i) | |
1684 | if format == 0: |
|
1684 | if format == 0: | |
1685 | try: |
|
1685 | try: | |
1686 | pp = r.parents(node) |
|
1686 | pp = r.parents(node) | |
1687 | except: |
|
1687 | except: | |
1688 | pp = [nullid, nullid] |
|
1688 | pp = [nullid, nullid] | |
1689 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1689 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
1690 | i, r.start(i), r.length(i), base, r.linkrev(i), |
|
1690 | i, r.start(i), r.length(i), base, r.linkrev(i), | |
1691 | short(node), short(pp[0]), short(pp[1]))) |
|
1691 | short(node), short(pp[0]), short(pp[1]))) | |
1692 | elif format == 1: |
|
1692 | elif format == 1: | |
1693 | pr = r.parentrevs(i) |
|
1693 | pr = r.parentrevs(i) | |
1694 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( |
|
1694 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( | |
1695 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), |
|
1695 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), | |
1696 | base, r.linkrev(i), pr[0], pr[1], short(node))) |
|
1696 | base, r.linkrev(i), pr[0], pr[1], short(node))) | |
1697 |
|
1697 | |||
1698 | @command('debugindexdot', [], _('FILE')) |
|
1698 | @command('debugindexdot', [], _('FILE')) | |
1699 | def debugindexdot(ui, repo, file_): |
|
1699 | def debugindexdot(ui, repo, file_): | |
1700 | """dump an index DAG as a graphviz dot file""" |
|
1700 | """dump an index DAG as a graphviz dot file""" | |
1701 | r = None |
|
1701 | r = None | |
1702 | if repo: |
|
1702 | if repo: | |
1703 | filelog = repo.file(file_) |
|
1703 | filelog = repo.file(file_) | |
1704 | if len(filelog): |
|
1704 | if len(filelog): | |
1705 | r = filelog |
|
1705 | r = filelog | |
1706 | if not r: |
|
1706 | if not r: | |
1707 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
1707 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) | |
1708 | ui.write("digraph G {\n") |
|
1708 | ui.write("digraph G {\n") | |
1709 | for i in r: |
|
1709 | for i in r: | |
1710 | node = r.node(i) |
|
1710 | node = r.node(i) | |
1711 | pp = r.parents(node) |
|
1711 | pp = r.parents(node) | |
1712 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
1712 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) | |
1713 | if pp[1] != nullid: |
|
1713 | if pp[1] != nullid: | |
1714 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
1714 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) | |
1715 | ui.write("}\n") |
|
1715 | ui.write("}\n") | |
1716 |
|
1716 | |||
1717 | @command('debuginstall', [], '') |
|
1717 | @command('debuginstall', [], '') | |
1718 | def debuginstall(ui): |
|
1718 | def debuginstall(ui): | |
1719 | '''test Mercurial installation |
|
1719 | '''test Mercurial installation | |
1720 |
|
1720 | |||
1721 | Returns 0 on success. |
|
1721 | Returns 0 on success. | |
1722 | ''' |
|
1722 | ''' | |
1723 |
|
1723 | |||
1724 | def writetemp(contents): |
|
1724 | def writetemp(contents): | |
1725 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") |
|
1725 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") | |
1726 | f = os.fdopen(fd, "wb") |
|
1726 | f = os.fdopen(fd, "wb") | |
1727 | f.write(contents) |
|
1727 | f.write(contents) | |
1728 | f.close() |
|
1728 | f.close() | |
1729 | return name |
|
1729 | return name | |
1730 |
|
1730 | |||
1731 | problems = 0 |
|
1731 | problems = 0 | |
1732 |
|
1732 | |||
1733 | # encoding |
|
1733 | # encoding | |
1734 | ui.status(_("Checking encoding (%s)...\n") % encoding.encoding) |
|
1734 | ui.status(_("Checking encoding (%s)...\n") % encoding.encoding) | |
1735 | try: |
|
1735 | try: | |
1736 | encoding.fromlocal("test") |
|
1736 | encoding.fromlocal("test") | |
1737 | except util.Abort, inst: |
|
1737 | except util.Abort, inst: | |
1738 | ui.write(" %s\n" % inst) |
|
1738 | ui.write(" %s\n" % inst) | |
1739 | ui.write(_(" (check that your locale is properly set)\n")) |
|
1739 | ui.write(_(" (check that your locale is properly set)\n")) | |
1740 | problems += 1 |
|
1740 | problems += 1 | |
1741 |
|
1741 | |||
1742 | # compiled modules |
|
1742 | # compiled modules | |
1743 | ui.status(_("Checking installed modules (%s)...\n") |
|
1743 | ui.status(_("Checking installed modules (%s)...\n") | |
1744 | % os.path.dirname(__file__)) |
|
1744 | % os.path.dirname(__file__)) | |
1745 | try: |
|
1745 | try: | |
1746 | import bdiff, mpatch, base85, osutil |
|
1746 | import bdiff, mpatch, base85, osutil | |
1747 | except Exception, inst: |
|
1747 | except Exception, inst: | |
1748 | ui.write(" %s\n" % inst) |
|
1748 | ui.write(" %s\n" % inst) | |
1749 | ui.write(_(" One or more extensions could not be found")) |
|
1749 | ui.write(_(" One or more extensions could not be found")) | |
1750 | ui.write(_(" (check that you compiled the extensions)\n")) |
|
1750 | ui.write(_(" (check that you compiled the extensions)\n")) | |
1751 | problems += 1 |
|
1751 | problems += 1 | |
1752 |
|
1752 | |||
1753 | # templates |
|
1753 | # templates | |
1754 | ui.status(_("Checking templates...\n")) |
|
1754 | ui.status(_("Checking templates...\n")) | |
1755 | try: |
|
1755 | try: | |
1756 | import templater |
|
1756 | import templater | |
1757 | templater.templater(templater.templatepath("map-cmdline.default")) |
|
1757 | templater.templater(templater.templatepath("map-cmdline.default")) | |
1758 | except Exception, inst: |
|
1758 | except Exception, inst: | |
1759 | ui.write(" %s\n" % inst) |
|
1759 | ui.write(" %s\n" % inst) | |
1760 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) |
|
1760 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) | |
1761 | problems += 1 |
|
1761 | problems += 1 | |
1762 |
|
1762 | |||
1763 | # editor |
|
1763 | # editor | |
1764 | ui.status(_("Checking commit editor...\n")) |
|
1764 | ui.status(_("Checking commit editor...\n")) | |
1765 | editor = ui.geteditor() |
|
1765 | editor = ui.geteditor() | |
1766 | cmdpath = util.findexe(editor) or util.findexe(editor.split()[0]) |
|
1766 | cmdpath = util.findexe(editor) or util.findexe(editor.split()[0]) | |
1767 | if not cmdpath: |
|
1767 | if not cmdpath: | |
1768 | if editor == 'vi': |
|
1768 | if editor == 'vi': | |
1769 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) |
|
1769 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) | |
1770 | ui.write(_(" (specify a commit editor in your configuration" |
|
1770 | ui.write(_(" (specify a commit editor in your configuration" | |
1771 | " file)\n")) |
|
1771 | " file)\n")) | |
1772 | else: |
|
1772 | else: | |
1773 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) |
|
1773 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) | |
1774 | ui.write(_(" (specify a commit editor in your configuration" |
|
1774 | ui.write(_(" (specify a commit editor in your configuration" | |
1775 | " file)\n")) |
|
1775 | " file)\n")) | |
1776 | problems += 1 |
|
1776 | problems += 1 | |
1777 |
|
1777 | |||
1778 | # check username |
|
1778 | # check username | |
1779 | ui.status(_("Checking username...\n")) |
|
1779 | ui.status(_("Checking username...\n")) | |
1780 | try: |
|
1780 | try: | |
1781 | ui.username() |
|
1781 | ui.username() | |
1782 | except util.Abort, e: |
|
1782 | except util.Abort, e: | |
1783 | ui.write(" %s\n" % e) |
|
1783 | ui.write(" %s\n" % e) | |
1784 | ui.write(_(" (specify a username in your configuration file)\n")) |
|
1784 | ui.write(_(" (specify a username in your configuration file)\n")) | |
1785 | problems += 1 |
|
1785 | problems += 1 | |
1786 |
|
1786 | |||
1787 | if not problems: |
|
1787 | if not problems: | |
1788 | ui.status(_("No problems detected\n")) |
|
1788 | ui.status(_("No problems detected\n")) | |
1789 | else: |
|
1789 | else: | |
1790 | ui.write(_("%s problems detected," |
|
1790 | ui.write(_("%s problems detected," | |
1791 | " please check your install!\n") % problems) |
|
1791 | " please check your install!\n") % problems) | |
1792 |
|
1792 | |||
1793 | return problems |
|
1793 | return problems | |
1794 |
|
1794 | |||
1795 | @command('debugknown', [], _('REPO ID...')) |
|
1795 | @command('debugknown', [], _('REPO ID...')) | |
1796 | def debugknown(ui, repopath, *ids, **opts): |
|
1796 | def debugknown(ui, repopath, *ids, **opts): | |
1797 | """test whether node ids are known to a repo |
|
1797 | """test whether node ids are known to a repo | |
1798 |
|
1798 | |||
1799 | Every ID must be a full-length hex node id string. Returns a list of 0s and 1s |
|
1799 | Every ID must be a full-length hex node id string. Returns a list of 0s and 1s | |
1800 | indicating unknown/known. |
|
1800 | indicating unknown/known. | |
1801 | """ |
|
1801 | """ | |
1802 | repo = hg.repository(ui, repopath) |
|
1802 | repo = hg.repository(ui, repopath) | |
1803 | if not repo.capable('known'): |
|
1803 | if not repo.capable('known'): | |
1804 | raise util.Abort("known() not supported by target repository") |
|
1804 | raise util.Abort("known() not supported by target repository") | |
1805 | flags = repo.known([bin(s) for s in ids]) |
|
1805 | flags = repo.known([bin(s) for s in ids]) | |
1806 | ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) |
|
1806 | ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) | |
1807 |
|
1807 | |||
1808 | @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]')) |
|
1808 | @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]')) | |
1809 | def debugpushkey(ui, repopath, namespace, *keyinfo): |
|
1809 | def debugpushkey(ui, repopath, namespace, *keyinfo): | |
1810 | '''access the pushkey key/value protocol |
|
1810 | '''access the pushkey key/value protocol | |
1811 |
|
1811 | |||
1812 | With two args, list the keys in the given namespace. |
|
1812 | With two args, list the keys in the given namespace. | |
1813 |
|
1813 | |||
1814 | With five args, set a key to new if it currently is set to old. |
|
1814 | With five args, set a key to new if it currently is set to old. | |
1815 | Reports success or failure. |
|
1815 | Reports success or failure. | |
1816 | ''' |
|
1816 | ''' | |
1817 |
|
1817 | |||
1818 | target = hg.repository(ui, repopath) |
|
1818 | target = hg.repository(ui, repopath) | |
1819 | if keyinfo: |
|
1819 | if keyinfo: | |
1820 | key, old, new = keyinfo |
|
1820 | key, old, new = keyinfo | |
1821 | r = target.pushkey(namespace, key, old, new) |
|
1821 | r = target.pushkey(namespace, key, old, new) | |
1822 | ui.status(str(r) + '\n') |
|
1822 | ui.status(str(r) + '\n') | |
1823 | return not r |
|
1823 | return not r | |
1824 | else: |
|
1824 | else: | |
1825 | for k, v in target.listkeys(namespace).iteritems(): |
|
1825 | for k, v in target.listkeys(namespace).iteritems(): | |
1826 | ui.write("%s\t%s\n" % (k.encode('string-escape'), |
|
1826 | ui.write("%s\t%s\n" % (k.encode('string-escape'), | |
1827 | v.encode('string-escape'))) |
|
1827 | v.encode('string-escape'))) | |
1828 |
|
1828 | |||
1829 | @command('debugrebuildstate', |
|
1829 | @command('debugrebuildstate', | |
1830 | [('r', 'rev', '', _('revision to rebuild to'), _('REV'))], |
|
1830 | [('r', 'rev', '', _('revision to rebuild to'), _('REV'))], | |
1831 | _('[-r REV] [REV]')) |
|
1831 | _('[-r REV] [REV]')) | |
1832 | def debugrebuildstate(ui, repo, rev="tip"): |
|
1832 | def debugrebuildstate(ui, repo, rev="tip"): | |
1833 | """rebuild the dirstate as it would look like for the given revision""" |
|
1833 | """rebuild the dirstate as it would look like for the given revision""" | |
1834 | ctx = scmutil.revsingle(repo, rev) |
|
1834 | ctx = scmutil.revsingle(repo, rev) | |
1835 | wlock = repo.wlock() |
|
1835 | wlock = repo.wlock() | |
1836 | try: |
|
1836 | try: | |
1837 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
1837 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) | |
1838 | finally: |
|
1838 | finally: | |
1839 | wlock.release() |
|
1839 | wlock.release() | |
1840 |
|
1840 | |||
1841 | @command('debugrename', |
|
1841 | @command('debugrename', | |
1842 | [('r', 'rev', '', _('revision to debug'), _('REV'))], |
|
1842 | [('r', 'rev', '', _('revision to debug'), _('REV'))], | |
1843 | _('[-r REV] FILE')) |
|
1843 | _('[-r REV] FILE')) | |
1844 | def debugrename(ui, repo, file1, *pats, **opts): |
|
1844 | def debugrename(ui, repo, file1, *pats, **opts): | |
1845 | """dump rename information""" |
|
1845 | """dump rename information""" | |
1846 |
|
1846 | |||
1847 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1847 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
1848 | m = cmdutil.match(repo, (file1,) + pats, opts) |
|
1848 | m = cmdutil.match(repo, (file1,) + pats, opts) | |
1849 | for abs in ctx.walk(m): |
|
1849 | for abs in ctx.walk(m): | |
1850 | fctx = ctx[abs] |
|
1850 | fctx = ctx[abs] | |
1851 | o = fctx.filelog().renamed(fctx.filenode()) |
|
1851 | o = fctx.filelog().renamed(fctx.filenode()) | |
1852 | rel = m.rel(abs) |
|
1852 | rel = m.rel(abs) | |
1853 | if o: |
|
1853 | if o: | |
1854 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) |
|
1854 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) | |
1855 | else: |
|
1855 | else: | |
1856 | ui.write(_("%s not renamed\n") % rel) |
|
1856 | ui.write(_("%s not renamed\n") % rel) | |
1857 |
|
1857 | |||
1858 | @command('debugrevlog', [], _('FILE')) |
|
1858 | @command('debugrevlog', [], _('FILE')) | |
1859 | def debugrevlog(ui, repo, file_): |
|
1859 | def debugrevlog(ui, repo, file_): | |
1860 | """show data and statistics about a revlog""" |
|
1860 | """show data and statistics about a revlog""" | |
1861 | r = None |
|
1861 | r = None | |
1862 | if repo: |
|
1862 | if repo: | |
1863 | filelog = repo.file(file_) |
|
1863 | filelog = repo.file(file_) | |
1864 | if len(filelog): |
|
1864 | if len(filelog): | |
1865 | r = filelog |
|
1865 | r = filelog | |
1866 | if not r: |
|
1866 | if not r: | |
1867 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
1867 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) | |
1868 |
|
1868 | |||
1869 | v = r.version |
|
1869 | v = r.version | |
1870 | format = v & 0xFFFF |
|
1870 | format = v & 0xFFFF | |
1871 | flags = [] |
|
1871 | flags = [] | |
1872 | gdelta = False |
|
1872 | gdelta = False | |
1873 | if v & revlog.REVLOGNGINLINEDATA: |
|
1873 | if v & revlog.REVLOGNGINLINEDATA: | |
1874 | flags.append('inline') |
|
1874 | flags.append('inline') | |
1875 | if v & revlog.REVLOGGENERALDELTA: |
|
1875 | if v & revlog.REVLOGGENERALDELTA: | |
1876 | gdelta = True |
|
1876 | gdelta = True | |
1877 | flags.append('generaldelta') |
|
1877 | flags.append('generaldelta') | |
1878 | if not flags: |
|
1878 | if not flags: | |
1879 | flags = ['(none)'] |
|
1879 | flags = ['(none)'] | |
1880 |
|
1880 | |||
1881 | nummerges = 0 |
|
1881 | nummerges = 0 | |
1882 | numfull = 0 |
|
1882 | numfull = 0 | |
1883 | numprev = 0 |
|
1883 | numprev = 0 | |
1884 | nump1 = 0 |
|
1884 | nump1 = 0 | |
1885 | nump2 = 0 |
|
1885 | nump2 = 0 | |
1886 | numother = 0 |
|
1886 | numother = 0 | |
1887 | nump1prev = 0 |
|
1887 | nump1prev = 0 | |
1888 | nump2prev = 0 |
|
1888 | nump2prev = 0 | |
1889 | chainlengths = [] |
|
1889 | chainlengths = [] | |
1890 |
|
1890 | |||
1891 | datasize = [None, 0, 0L] |
|
1891 | datasize = [None, 0, 0L] | |
1892 | fullsize = [None, 0, 0L] |
|
1892 | fullsize = [None, 0, 0L] | |
1893 | deltasize = [None, 0, 0L] |
|
1893 | deltasize = [None, 0, 0L] | |
1894 |
|
1894 | |||
1895 | def addsize(size, l): |
|
1895 | def addsize(size, l): | |
1896 | if l[0] is None or size < l[0]: |
|
1896 | if l[0] is None or size < l[0]: | |
1897 | l[0] = size |
|
1897 | l[0] = size | |
1898 | if size > l[1]: |
|
1898 | if size > l[1]: | |
1899 | l[1] = size |
|
1899 | l[1] = size | |
1900 | l[2] += size |
|
1900 | l[2] += size | |
1901 |
|
1901 | |||
1902 | numrevs = len(r) |
|
1902 | numrevs = len(r) | |
1903 | for rev in xrange(numrevs): |
|
1903 | for rev in xrange(numrevs): | |
1904 | p1, p2 = r.parentrevs(rev) |
|
1904 | p1, p2 = r.parentrevs(rev) | |
1905 | delta = r.deltaparent(rev) |
|
1905 | delta = r.deltaparent(rev) | |
1906 | if format > 0: |
|
1906 | if format > 0: | |
1907 | addsize(r.rawsize(rev), datasize) |
|
1907 | addsize(r.rawsize(rev), datasize) | |
1908 | if p2 != nullrev: |
|
1908 | if p2 != nullrev: | |
1909 | nummerges += 1 |
|
1909 | nummerges += 1 | |
1910 | size = r.length(rev) |
|
1910 | size = r.length(rev) | |
1911 | if delta == nullrev: |
|
1911 | if delta == nullrev: | |
1912 | chainlengths.append(0) |
|
1912 | chainlengths.append(0) | |
1913 | numfull += 1 |
|
1913 | numfull += 1 | |
1914 | addsize(size, fullsize) |
|
1914 | addsize(size, fullsize) | |
1915 | else: |
|
1915 | else: | |
1916 | chainlengths.append(chainlengths[delta] + 1) |
|
1916 | chainlengths.append(chainlengths[delta] + 1) | |
1917 | addsize(size, deltasize) |
|
1917 | addsize(size, deltasize) | |
1918 | if delta == rev - 1: |
|
1918 | if delta == rev - 1: | |
1919 | numprev += 1 |
|
1919 | numprev += 1 | |
1920 | if delta == p1: |
|
1920 | if delta == p1: | |
1921 | nump1prev += 1 |
|
1921 | nump1prev += 1 | |
1922 | elif delta == p2: |
|
1922 | elif delta == p2: | |
1923 | nump2prev += 1 |
|
1923 | nump2prev += 1 | |
1924 | elif delta == p1: |
|
1924 | elif delta == p1: | |
1925 | nump1 += 1 |
|
1925 | nump1 += 1 | |
1926 | elif delta == p2: |
|
1926 | elif delta == p2: | |
1927 | nump2 += 1 |
|
1927 | nump2 += 1 | |
1928 | elif delta != nullrev: |
|
1928 | elif delta != nullrev: | |
1929 | numother += 1 |
|
1929 | numother += 1 | |
1930 |
|
1930 | |||
1931 | numdeltas = numrevs - numfull |
|
1931 | numdeltas = numrevs - numfull | |
1932 | numoprev = numprev - nump1prev - nump2prev |
|
1932 | numoprev = numprev - nump1prev - nump2prev | |
1933 | totalrawsize = datasize[2] |
|
1933 | totalrawsize = datasize[2] | |
1934 | datasize[2] /= numrevs |
|
1934 | datasize[2] /= numrevs | |
1935 | fulltotal = fullsize[2] |
|
1935 | fulltotal = fullsize[2] | |
1936 | fullsize[2] /= numfull |
|
1936 | fullsize[2] /= numfull | |
1937 | deltatotal = deltasize[2] |
|
1937 | deltatotal = deltasize[2] | |
1938 | deltasize[2] /= numrevs - numfull |
|
1938 | deltasize[2] /= numrevs - numfull | |
1939 | totalsize = fulltotal + deltatotal |
|
1939 | totalsize = fulltotal + deltatotal | |
1940 | avgchainlen = sum(chainlengths) / numrevs |
|
1940 | avgchainlen = sum(chainlengths) / numrevs | |
1941 | compratio = totalrawsize / totalsize |
|
1941 | compratio = totalrawsize / totalsize | |
1942 |
|
1942 | |||
1943 | basedfmtstr = '%%%dd\n' |
|
1943 | basedfmtstr = '%%%dd\n' | |
1944 | basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n' |
|
1944 | basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n' | |
1945 |
|
1945 | |||
1946 | def dfmtstr(max): |
|
1946 | def dfmtstr(max): | |
1947 | return basedfmtstr % len(str(max)) |
|
1947 | return basedfmtstr % len(str(max)) | |
1948 | def pcfmtstr(max, padding=0): |
|
1948 | def pcfmtstr(max, padding=0): | |
1949 | return basepcfmtstr % (len(str(max)), ' ' * padding) |
|
1949 | return basepcfmtstr % (len(str(max)), ' ' * padding) | |
1950 |
|
1950 | |||
1951 | def pcfmt(value, total): |
|
1951 | def pcfmt(value, total): | |
1952 | return (value, 100 * float(value) / total) |
|
1952 | return (value, 100 * float(value) / total) | |
1953 |
|
1953 | |||
1954 | ui.write('format : %d\n' % format) |
|
1954 | ui.write('format : %d\n' % format) | |
1955 | ui.write('flags : %s\n' % ', '.join(flags)) |
|
1955 | ui.write('flags : %s\n' % ', '.join(flags)) | |
1956 |
|
1956 | |||
1957 | ui.write('\n') |
|
1957 | ui.write('\n') | |
1958 | fmt = pcfmtstr(totalsize) |
|
1958 | fmt = pcfmtstr(totalsize) | |
1959 | fmt2 = dfmtstr(totalsize) |
|
1959 | fmt2 = dfmtstr(totalsize) | |
1960 | ui.write('revisions : ' + fmt2 % numrevs) |
|
1960 | ui.write('revisions : ' + fmt2 % numrevs) | |
1961 | ui.write(' merges : ' + fmt % pcfmt(nummerges, numrevs)) |
|
1961 | ui.write(' merges : ' + fmt % pcfmt(nummerges, numrevs)) | |
1962 | ui.write(' normal : ' + fmt % pcfmt(numrevs - nummerges, numrevs)) |
|
1962 | ui.write(' normal : ' + fmt % pcfmt(numrevs - nummerges, numrevs)) | |
1963 | ui.write('revisions : ' + fmt2 % numrevs) |
|
1963 | ui.write('revisions : ' + fmt2 % numrevs) | |
1964 | ui.write(' full : ' + fmt % pcfmt(numfull, numrevs)) |
|
1964 | ui.write(' full : ' + fmt % pcfmt(numfull, numrevs)) | |
1965 | ui.write(' deltas : ' + fmt % pcfmt(numdeltas, numrevs)) |
|
1965 | ui.write(' deltas : ' + fmt % pcfmt(numdeltas, numrevs)) | |
1966 | ui.write('revision size : ' + fmt2 % totalsize) |
|
1966 | ui.write('revision size : ' + fmt2 % totalsize) | |
1967 | ui.write(' full : ' + fmt % pcfmt(fulltotal, totalsize)) |
|
1967 | ui.write(' full : ' + fmt % pcfmt(fulltotal, totalsize)) | |
1968 | ui.write(' deltas : ' + fmt % pcfmt(deltatotal, totalsize)) |
|
1968 | ui.write(' deltas : ' + fmt % pcfmt(deltatotal, totalsize)) | |
1969 |
|
1969 | |||
1970 | ui.write('\n') |
|
1970 | ui.write('\n') | |
1971 | fmt = dfmtstr(max(avgchainlen, compratio)) |
|
1971 | fmt = dfmtstr(max(avgchainlen, compratio)) | |
1972 | ui.write('avg chain length : ' + fmt % avgchainlen) |
|
1972 | ui.write('avg chain length : ' + fmt % avgchainlen) | |
1973 | ui.write('compression ratio : ' + fmt % compratio) |
|
1973 | ui.write('compression ratio : ' + fmt % compratio) | |
1974 |
|
1974 | |||
1975 | if format > 0: |
|
1975 | if format > 0: | |
1976 | ui.write('\n') |
|
1976 | ui.write('\n') | |
1977 | ui.write('uncompressed data size (min/max/avg) : %d / %d / %d\n' |
|
1977 | ui.write('uncompressed data size (min/max/avg) : %d / %d / %d\n' | |
1978 | % tuple(datasize)) |
|
1978 | % tuple(datasize)) | |
1979 | ui.write('full revision size (min/max/avg) : %d / %d / %d\n' |
|
1979 | ui.write('full revision size (min/max/avg) : %d / %d / %d\n' | |
1980 | % tuple(fullsize)) |
|
1980 | % tuple(fullsize)) | |
1981 | ui.write('delta size (min/max/avg) : %d / %d / %d\n' |
|
1981 | ui.write('delta size (min/max/avg) : %d / %d / %d\n' | |
1982 | % tuple(deltasize)) |
|
1982 | % tuple(deltasize)) | |
1983 |
|
1983 | |||
1984 | if numdeltas > 0: |
|
1984 | if numdeltas > 0: | |
1985 | ui.write('\n') |
|
1985 | ui.write('\n') | |
1986 | fmt = pcfmtstr(numdeltas) |
|
1986 | fmt = pcfmtstr(numdeltas) | |
1987 | fmt2 = pcfmtstr(numdeltas, 4) |
|
1987 | fmt2 = pcfmtstr(numdeltas, 4) | |
1988 | ui.write('deltas against prev : ' + fmt % pcfmt(numprev, numdeltas)) |
|
1988 | ui.write('deltas against prev : ' + fmt % pcfmt(numprev, numdeltas)) | |
1989 | if numprev > 0: |
|
1989 | if numprev > 0: | |
1990 | ui.write(' where prev = p1 : ' + fmt2 % pcfmt(nump1prev, numprev)) |
|
1990 | ui.write(' where prev = p1 : ' + fmt2 % pcfmt(nump1prev, numprev)) | |
1991 | ui.write(' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, numprev)) |
|
1991 | ui.write(' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, numprev)) | |
1992 | ui.write(' other : ' + fmt2 % pcfmt(numoprev, numprev)) |
|
1992 | ui.write(' other : ' + fmt2 % pcfmt(numoprev, numprev)) | |
1993 | if gdelta: |
|
1993 | if gdelta: | |
1994 | ui.write('deltas against p1 : ' + fmt % pcfmt(nump1, numdeltas)) |
|
1994 | ui.write('deltas against p1 : ' + fmt % pcfmt(nump1, numdeltas)) | |
1995 | ui.write('deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas)) |
|
1995 | ui.write('deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas)) | |
1996 | ui.write('deltas against other : ' + fmt % pcfmt(numother, numdeltas)) |
|
1996 | ui.write('deltas against other : ' + fmt % pcfmt(numother, numdeltas)) | |
1997 |
|
1997 | |||
1998 | @command('debugrevspec', [], ('REVSPEC')) |
|
1998 | @command('debugrevspec', [], ('REVSPEC')) | |
1999 | def debugrevspec(ui, repo, expr): |
|
1999 | def debugrevspec(ui, repo, expr): | |
2000 | '''parse and apply a revision specification''' |
|
2000 | '''parse and apply a revision specification''' | |
2001 | if ui.verbose: |
|
2001 | if ui.verbose: | |
2002 | tree = revset.parse(expr)[0] |
|
2002 | tree = revset.parse(expr)[0] | |
2003 | ui.note(tree, "\n") |
|
2003 | ui.note(tree, "\n") | |
2004 | newtree = revset.findaliases(ui, tree) |
|
2004 | newtree = revset.findaliases(ui, tree) | |
2005 | if newtree != tree: |
|
2005 | if newtree != tree: | |
2006 | ui.note(newtree, "\n") |
|
2006 | ui.note(newtree, "\n") | |
2007 | func = revset.match(ui, expr) |
|
2007 | func = revset.match(ui, expr) | |
2008 | for c in func(repo, range(len(repo))): |
|
2008 | for c in func(repo, range(len(repo))): | |
2009 | ui.write("%s\n" % c) |
|
2009 | ui.write("%s\n" % c) | |
2010 |
|
2010 | |||
2011 | @command('debugsetparents', [], _('REV1 [REV2]')) |
|
2011 | @command('debugsetparents', [], _('REV1 [REV2]')) | |
2012 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
2012 | def debugsetparents(ui, repo, rev1, rev2=None): | |
2013 | """manually set the parents of the current working directory |
|
2013 | """manually set the parents of the current working directory | |
2014 |
|
2014 | |||
2015 | This is useful for writing repository conversion tools, but should |
|
2015 | This is useful for writing repository conversion tools, but should | |
2016 | be used with care. |
|
2016 | be used with care. | |
2017 |
|
2017 | |||
2018 | Returns 0 on success. |
|
2018 | Returns 0 on success. | |
2019 | """ |
|
2019 | """ | |
2020 |
|
2020 | |||
2021 | r1 = scmutil.revsingle(repo, rev1).node() |
|
2021 | r1 = scmutil.revsingle(repo, rev1).node() | |
2022 | r2 = scmutil.revsingle(repo, rev2, 'null').node() |
|
2022 | r2 = scmutil.revsingle(repo, rev2, 'null').node() | |
2023 |
|
2023 | |||
2024 | wlock = repo.wlock() |
|
2024 | wlock = repo.wlock() | |
2025 | try: |
|
2025 | try: | |
2026 | repo.dirstate.setparents(r1, r2) |
|
2026 | repo.dirstate.setparents(r1, r2) | |
2027 | finally: |
|
2027 | finally: | |
2028 | wlock.release() |
|
2028 | wlock.release() | |
2029 |
|
2029 | |||
2030 | @command('debugstate', |
|
2030 | @command('debugstate', | |
2031 | [('', 'nodates', None, _('do not display the saved mtime')), |
|
2031 | [('', 'nodates', None, _('do not display the saved mtime')), | |
2032 | ('', 'datesort', None, _('sort by saved mtime'))], |
|
2032 | ('', 'datesort', None, _('sort by saved mtime'))], | |
2033 | _('[OPTION]...')) |
|
2033 | _('[OPTION]...')) | |
2034 | def debugstate(ui, repo, nodates=None, datesort=None): |
|
2034 | def debugstate(ui, repo, nodates=None, datesort=None): | |
2035 | """show the contents of the current dirstate""" |
|
2035 | """show the contents of the current dirstate""" | |
2036 | timestr = "" |
|
2036 | timestr = "" | |
2037 | showdate = not nodates |
|
2037 | showdate = not nodates | |
2038 | if datesort: |
|
2038 | if datesort: | |
2039 | keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename |
|
2039 | keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename | |
2040 | else: |
|
2040 | else: | |
2041 | keyfunc = None # sort by filename |
|
2041 | keyfunc = None # sort by filename | |
2042 | for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc): |
|
2042 | for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc): | |
2043 | if showdate: |
|
2043 | if showdate: | |
2044 | if ent[3] == -1: |
|
2044 | if ent[3] == -1: | |
2045 | # Pad or slice to locale representation |
|
2045 | # Pad or slice to locale representation | |
2046 | locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", |
|
2046 | locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", | |
2047 | time.localtime(0))) |
|
2047 | time.localtime(0))) | |
2048 | timestr = 'unset' |
|
2048 | timestr = 'unset' | |
2049 | timestr = (timestr[:locale_len] + |
|
2049 | timestr = (timestr[:locale_len] + | |
2050 | ' ' * (locale_len - len(timestr))) |
|
2050 | ' ' * (locale_len - len(timestr))) | |
2051 | else: |
|
2051 | else: | |
2052 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", |
|
2052 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", | |
2053 | time.localtime(ent[3])) |
|
2053 | time.localtime(ent[3])) | |
2054 | if ent[1] & 020000: |
|
2054 | if ent[1] & 020000: | |
2055 | mode = 'lnk' |
|
2055 | mode = 'lnk' | |
2056 | else: |
|
2056 | else: | |
2057 | mode = '%3o' % (ent[1] & 0777) |
|
2057 | mode = '%3o' % (ent[1] & 0777) | |
2058 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
|
2058 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) | |
2059 | for f in repo.dirstate.copies(): |
|
2059 | for f in repo.dirstate.copies(): | |
2060 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
2060 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) | |
2061 |
|
2061 | |||
2062 | @command('debugsub', |
|
2062 | @command('debugsub', | |
2063 | [('r', 'rev', '', |
|
2063 | [('r', 'rev', '', | |
2064 | _('revision to check'), _('REV'))], |
|
2064 | _('revision to check'), _('REV'))], | |
2065 | _('[-r REV] [REV]')) |
|
2065 | _('[-r REV] [REV]')) | |
2066 | def debugsub(ui, repo, rev=None): |
|
2066 | def debugsub(ui, repo, rev=None): | |
2067 | ctx = scmutil.revsingle(repo, rev, None) |
|
2067 | ctx = scmutil.revsingle(repo, rev, None) | |
2068 | for k, v in sorted(ctx.substate.items()): |
|
2068 | for k, v in sorted(ctx.substate.items()): | |
2069 | ui.write('path %s\n' % k) |
|
2069 | ui.write('path %s\n' % k) | |
2070 | ui.write(' source %s\n' % v[0]) |
|
2070 | ui.write(' source %s\n' % v[0]) | |
2071 | ui.write(' revision %s\n' % v[1]) |
|
2071 | ui.write(' revision %s\n' % v[1]) | |
2072 |
|
2072 | |||
2073 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...')) |
|
2073 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...')) | |
2074 | def debugwalk(ui, repo, *pats, **opts): |
|
2074 | def debugwalk(ui, repo, *pats, **opts): | |
2075 | """show how files match on given patterns""" |
|
2075 | """show how files match on given patterns""" | |
2076 | m = cmdutil.match(repo, pats, opts) |
|
2076 | m = cmdutil.match(repo, pats, opts) | |
2077 | items = list(repo.walk(m)) |
|
2077 | items = list(repo.walk(m)) | |
2078 | if not items: |
|
2078 | if not items: | |
2079 | return |
|
2079 | return | |
2080 | fmt = 'f %%-%ds %%-%ds %%s' % ( |
|
2080 | fmt = 'f %%-%ds %%-%ds %%s' % ( | |
2081 | max([len(abs) for abs in items]), |
|
2081 | max([len(abs) for abs in items]), | |
2082 | max([len(m.rel(abs)) for abs in items])) |
|
2082 | max([len(m.rel(abs)) for abs in items])) | |
2083 | for abs in items: |
|
2083 | for abs in items: | |
2084 | line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '') |
|
2084 | line = fmt % (abs, m.rel(abs), m.exact(abs) and 'exact' or '') | |
2085 | ui.write("%s\n" % line.rstrip()) |
|
2085 | ui.write("%s\n" % line.rstrip()) | |
2086 |
|
2086 | |||
2087 | @command('debugwireargs', |
|
2087 | @command('debugwireargs', | |
2088 | [('', 'three', '', 'three'), |
|
2088 | [('', 'three', '', 'three'), | |
2089 | ('', 'four', '', 'four'), |
|
2089 | ('', 'four', '', 'four'), | |
2090 | ('', 'five', '', 'five'), |
|
2090 | ('', 'five', '', 'five'), | |
2091 | ] + remoteopts, |
|
2091 | ] + remoteopts, | |
2092 | _('REPO [OPTIONS]... [ONE [TWO]]')) |
|
2092 | _('REPO [OPTIONS]... [ONE [TWO]]')) | |
2093 | def debugwireargs(ui, repopath, *vals, **opts): |
|
2093 | def debugwireargs(ui, repopath, *vals, **opts): | |
2094 | repo = hg.repository(hg.remoteui(ui, opts), repopath) |
|
2094 | repo = hg.repository(hg.remoteui(ui, opts), repopath) | |
2095 | for opt in remoteopts: |
|
2095 | for opt in remoteopts: | |
2096 | del opts[opt[1]] |
|
2096 | del opts[opt[1]] | |
2097 | args = {} |
|
2097 | args = {} | |
2098 | for k, v in opts.iteritems(): |
|
2098 | for k, v in opts.iteritems(): | |
2099 | if v: |
|
2099 | if v: | |
2100 | args[k] = v |
|
2100 | args[k] = v | |
2101 | # run twice to check that we don't mess up the stream for the next command |
|
2101 | # run twice to check that we don't mess up the stream for the next command | |
2102 | res1 = repo.debugwireargs(*vals, **args) |
|
2102 | res1 = repo.debugwireargs(*vals, **args) | |
2103 | res2 = repo.debugwireargs(*vals, **args) |
|
2103 | res2 = repo.debugwireargs(*vals, **args) | |
2104 | ui.write("%s\n" % res1) |
|
2104 | ui.write("%s\n" % res1) | |
2105 | if res1 != res2: |
|
2105 | if res1 != res2: | |
2106 | ui.warn("%s\n" % res2) |
|
2106 | ui.warn("%s\n" % res2) | |
2107 |
|
2107 | |||
2108 | @command('^diff', |
|
2108 | @command('^diff', | |
2109 | [('r', 'rev', [], _('revision'), _('REV')), |
|
2109 | [('r', 'rev', [], _('revision'), _('REV')), | |
2110 | ('c', 'change', '', _('change made by revision'), _('REV')) |
|
2110 | ('c', 'change', '', _('change made by revision'), _('REV')) | |
2111 | ] + diffopts + diffopts2 + walkopts + subrepoopts, |
|
2111 | ] + diffopts + diffopts2 + walkopts + subrepoopts, | |
2112 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...')) |
|
2112 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...')) | |
2113 | def diff(ui, repo, *pats, **opts): |
|
2113 | def diff(ui, repo, *pats, **opts): | |
2114 | """diff repository (or selected files) |
|
2114 | """diff repository (or selected files) | |
2115 |
|
2115 | |||
2116 | Show differences between revisions for the specified files. |
|
2116 | Show differences between revisions for the specified files. | |
2117 |
|
2117 | |||
2118 | Differences between files are shown using the unified diff format. |
|
2118 | Differences between files are shown using the unified diff format. | |
2119 |
|
2119 | |||
2120 | .. note:: |
|
2120 | .. note:: | |
2121 | diff may generate unexpected results for merges, as it will |
|
2121 | diff may generate unexpected results for merges, as it will | |
2122 | default to comparing against the working directory's first |
|
2122 | default to comparing against the working directory's first | |
2123 | parent changeset if no revisions are specified. |
|
2123 | parent changeset if no revisions are specified. | |
2124 |
|
2124 | |||
2125 | When two revision arguments are given, then changes are shown |
|
2125 | When two revision arguments are given, then changes are shown | |
2126 | between those revisions. If only one revision is specified then |
|
2126 | between those revisions. If only one revision is specified then | |
2127 | that revision is compared to the working directory, and, when no |
|
2127 | that revision is compared to the working directory, and, when no | |
2128 | revisions are specified, the working directory files are compared |
|
2128 | revisions are specified, the working directory files are compared | |
2129 | to its parent. |
|
2129 | to its parent. | |
2130 |
|
2130 | |||
2131 | Alternatively you can specify -c/--change with a revision to see |
|
2131 | Alternatively you can specify -c/--change with a revision to see | |
2132 | the changes in that changeset relative to its first parent. |
|
2132 | the changes in that changeset relative to its first parent. | |
2133 |
|
2133 | |||
2134 | Without the -a/--text option, diff will avoid generating diffs of |
|
2134 | Without the -a/--text option, diff will avoid generating diffs of | |
2135 | files it detects as binary. With -a, diff will generate a diff |
|
2135 | files it detects as binary. With -a, diff will generate a diff | |
2136 | anyway, probably with undesirable results. |
|
2136 | anyway, probably with undesirable results. | |
2137 |
|
2137 | |||
2138 | Use the -g/--git option to generate diffs in the git extended diff |
|
2138 | Use the -g/--git option to generate diffs in the git extended diff | |
2139 | format. For more information, read :hg:`help diffs`. |
|
2139 | format. For more information, read :hg:`help diffs`. | |
2140 |
|
2140 | |||
2141 | Returns 0 on success. |
|
2141 | Returns 0 on success. | |
2142 | """ |
|
2142 | """ | |
2143 |
|
2143 | |||
2144 | revs = opts.get('rev') |
|
2144 | revs = opts.get('rev') | |
2145 | change = opts.get('change') |
|
2145 | change = opts.get('change') | |
2146 | stat = opts.get('stat') |
|
2146 | stat = opts.get('stat') | |
2147 | reverse = opts.get('reverse') |
|
2147 | reverse = opts.get('reverse') | |
2148 |
|
2148 | |||
2149 | if revs and change: |
|
2149 | if revs and change: | |
2150 | msg = _('cannot specify --rev and --change at the same time') |
|
2150 | msg = _('cannot specify --rev and --change at the same time') | |
2151 | raise util.Abort(msg) |
|
2151 | raise util.Abort(msg) | |
2152 | elif change: |
|
2152 | elif change: | |
2153 | node2 = scmutil.revsingle(repo, change, None).node() |
|
2153 | node2 = scmutil.revsingle(repo, change, None).node() | |
2154 | node1 = repo[node2].p1().node() |
|
2154 | node1 = repo[node2].p1().node() | |
2155 | else: |
|
2155 | else: | |
2156 | node1, node2 = scmutil.revpair(repo, revs) |
|
2156 | node1, node2 = scmutil.revpair(repo, revs) | |
2157 |
|
2157 | |||
2158 | if reverse: |
|
2158 | if reverse: | |
2159 | node1, node2 = node2, node1 |
|
2159 | node1, node2 = node2, node1 | |
2160 |
|
2160 | |||
2161 | diffopts = patch.diffopts(ui, opts) |
|
2161 | diffopts = patch.diffopts(ui, opts) | |
2162 | m = cmdutil.match(repo, pats, opts) |
|
2162 | m = cmdutil.match(repo, pats, opts) | |
2163 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, |
|
2163 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, | |
2164 | listsubrepos=opts.get('subrepos')) |
|
2164 | listsubrepos=opts.get('subrepos')) | |
2165 |
|
2165 | |||
2166 | @command('^export', |
|
2166 | @command('^export', | |
2167 | [('o', 'output', '', |
|
2167 | [('o', 'output', '', | |
2168 | _('print output to file with formatted name'), _('FORMAT')), |
|
2168 | _('print output to file with formatted name'), _('FORMAT')), | |
2169 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
2169 | ('', 'switch-parent', None, _('diff against the second parent')), | |
2170 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
2170 | ('r', 'rev', [], _('revisions to export'), _('REV')), | |
2171 | ] + diffopts, |
|
2171 | ] + diffopts, | |
2172 | _('[OPTION]... [-o OUTFILESPEC] REV...')) |
|
2172 | _('[OPTION]... [-o OUTFILESPEC] REV...')) | |
2173 | def export(ui, repo, *changesets, **opts): |
|
2173 | def export(ui, repo, *changesets, **opts): | |
2174 | """dump the header and diffs for one or more changesets |
|
2174 | """dump the header and diffs for one or more changesets | |
2175 |
|
2175 | |||
2176 | Print the changeset header and diffs for one or more revisions. |
|
2176 | Print the changeset header and diffs for one or more revisions. | |
2177 |
|
2177 | |||
2178 | The information shown in the changeset header is: author, date, |
|
2178 | The information shown in the changeset header is: author, date, | |
2179 | branch name (if non-default), changeset hash, parent(s) and commit |
|
2179 | branch name (if non-default), changeset hash, parent(s) and commit | |
2180 | comment. |
|
2180 | comment. | |
2181 |
|
2181 | |||
2182 | .. note:: |
|
2182 | .. note:: | |
2183 | export may generate unexpected diff output for merge |
|
2183 | export may generate unexpected diff output for merge | |
2184 | changesets, as it will compare the merge changeset against its |
|
2184 | changesets, as it will compare the merge changeset against its | |
2185 | first parent only. |
|
2185 | first parent only. | |
2186 |
|
2186 | |||
2187 | Output may be to a file, in which case the name of the file is |
|
2187 | Output may be to a file, in which case the name of the file is | |
2188 | given using a format string. The formatting rules are as follows: |
|
2188 | given using a format string. The formatting rules are as follows: | |
2189 |
|
2189 | |||
2190 | :``%%``: literal "%" character |
|
2190 | :``%%``: literal "%" character | |
2191 | :``%H``: changeset hash (40 hexadecimal digits) |
|
2191 | :``%H``: changeset hash (40 hexadecimal digits) | |
2192 | :``%N``: number of patches being generated |
|
2192 | :``%N``: number of patches being generated | |
2193 | :``%R``: changeset revision number |
|
2193 | :``%R``: changeset revision number | |
2194 | :``%b``: basename of the exporting repository |
|
2194 | :``%b``: basename of the exporting repository | |
2195 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
2195 | :``%h``: short-form changeset hash (12 hexadecimal digits) | |
2196 | :``%n``: zero-padded sequence number, starting at 1 |
|
2196 | :``%n``: zero-padded sequence number, starting at 1 | |
2197 | :``%r``: zero-padded changeset revision number |
|
2197 | :``%r``: zero-padded changeset revision number | |
2198 |
|
2198 | |||
2199 | Without the -a/--text option, export will avoid generating diffs |
|
2199 | Without the -a/--text option, export will avoid generating diffs | |
2200 | of files it detects as binary. With -a, export will generate a |
|
2200 | of files it detects as binary. With -a, export will generate a | |
2201 | diff anyway, probably with undesirable results. |
|
2201 | diff anyway, probably with undesirable results. | |
2202 |
|
2202 | |||
2203 | Use the -g/--git option to generate diffs in the git extended diff |
|
2203 | Use the -g/--git option to generate diffs in the git extended diff | |
2204 | format. See :hg:`help diffs` for more information. |
|
2204 | format. See :hg:`help diffs` for more information. | |
2205 |
|
2205 | |||
2206 | With the --switch-parent option, the diff will be against the |
|
2206 | With the --switch-parent option, the diff will be against the | |
2207 | second parent. It can be useful to review a merge. |
|
2207 | second parent. It can be useful to review a merge. | |
2208 |
|
2208 | |||
2209 | Returns 0 on success. |
|
2209 | Returns 0 on success. | |
2210 | """ |
|
2210 | """ | |
2211 | changesets += tuple(opts.get('rev', [])) |
|
2211 | changesets += tuple(opts.get('rev', [])) | |
2212 | if not changesets: |
|
2212 | if not changesets: | |
2213 | raise util.Abort(_("export requires at least one changeset")) |
|
2213 | raise util.Abort(_("export requires at least one changeset")) | |
2214 | revs = scmutil.revrange(repo, changesets) |
|
2214 | revs = scmutil.revrange(repo, changesets) | |
2215 | if len(revs) > 1: |
|
2215 | if len(revs) > 1: | |
2216 | ui.note(_('exporting patches:\n')) |
|
2216 | ui.note(_('exporting patches:\n')) | |
2217 | else: |
|
2217 | else: | |
2218 | ui.note(_('exporting patch:\n')) |
|
2218 | ui.note(_('exporting patch:\n')) | |
2219 | cmdutil.export(repo, revs, template=opts.get('output'), |
|
2219 | cmdutil.export(repo, revs, template=opts.get('output'), | |
2220 | switch_parent=opts.get('switch_parent'), |
|
2220 | switch_parent=opts.get('switch_parent'), | |
2221 | opts=patch.diffopts(ui, opts)) |
|
2221 | opts=patch.diffopts(ui, opts)) | |
2222 |
|
2222 | |||
2223 | @command('^forget', walkopts, _('[OPTION]... FILE...')) |
|
2223 | @command('^forget', walkopts, _('[OPTION]... FILE...')) | |
2224 | def forget(ui, repo, *pats, **opts): |
|
2224 | def forget(ui, repo, *pats, **opts): | |
2225 | """forget the specified files on the next commit |
|
2225 | """forget the specified files on the next commit | |
2226 |
|
2226 | |||
2227 | Mark the specified files so they will no longer be tracked |
|
2227 | Mark the specified files so they will no longer be tracked | |
2228 | after the next commit. |
|
2228 | after the next commit. | |
2229 |
|
2229 | |||
2230 | This only removes files from the current branch, not from the |
|
2230 | This only removes files from the current branch, not from the | |
2231 | entire project history, and it does not delete them from the |
|
2231 | entire project history, and it does not delete them from the | |
2232 | working directory. |
|
2232 | working directory. | |
2233 |
|
2233 | |||
2234 | To undo a forget before the next commit, see :hg:`add`. |
|
2234 | To undo a forget before the next commit, see :hg:`add`. | |
2235 |
|
2235 | |||
2236 | Returns 0 on success. |
|
2236 | Returns 0 on success. | |
2237 | """ |
|
2237 | """ | |
2238 |
|
2238 | |||
2239 | if not pats: |
|
2239 | if not pats: | |
2240 | raise util.Abort(_('no files specified')) |
|
2240 | raise util.Abort(_('no files specified')) | |
2241 |
|
2241 | |||
2242 | m = cmdutil.match(repo, pats, opts) |
|
2242 | m = cmdutil.match(repo, pats, opts) | |
2243 | s = repo.status(match=m, clean=True) |
|
2243 | s = repo.status(match=m, clean=True) | |
2244 | forget = sorted(s[0] + s[1] + s[3] + s[6]) |
|
2244 | forget = sorted(s[0] + s[1] + s[3] + s[6]) | |
2245 | errs = 0 |
|
2245 | errs = 0 | |
2246 |
|
2246 | |||
2247 | for f in m.files(): |
|
2247 | for f in m.files(): | |
2248 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
|
2248 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): | |
2249 | ui.warn(_('not removing %s: file is already untracked\n') |
|
2249 | ui.warn(_('not removing %s: file is already untracked\n') | |
2250 | % m.rel(f)) |
|
2250 | % m.rel(f)) | |
2251 | errs = 1 |
|
2251 | errs = 1 | |
2252 |
|
2252 | |||
2253 | for f in forget: |
|
2253 | for f in forget: | |
2254 | if ui.verbose or not m.exact(f): |
|
2254 | if ui.verbose or not m.exact(f): | |
2255 | ui.status(_('removing %s\n') % m.rel(f)) |
|
2255 | ui.status(_('removing %s\n') % m.rel(f)) | |
2256 |
|
2256 | |||
2257 | repo[None].remove(forget, unlink=False) |
|
2257 | repo[None].remove(forget, unlink=False) | |
2258 | return errs |
|
2258 | return errs | |
2259 |
|
2259 | |||
2260 | @command('grep', |
|
2260 | @command('grep', | |
2261 | [('0', 'print0', None, _('end fields with NUL')), |
|
2261 | [('0', 'print0', None, _('end fields with NUL')), | |
2262 | ('', 'all', None, _('print all revisions that match')), |
|
2262 | ('', 'all', None, _('print all revisions that match')), | |
2263 | ('a', 'text', None, _('treat all files as text')), |
|
2263 | ('a', 'text', None, _('treat all files as text')), | |
2264 | ('f', 'follow', None, |
|
2264 | ('f', 'follow', None, | |
2265 | _('follow changeset history,' |
|
2265 | _('follow changeset history,' | |
2266 | ' or file history across copies and renames')), |
|
2266 | ' or file history across copies and renames')), | |
2267 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2267 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2268 | ('l', 'files-with-matches', None, |
|
2268 | ('l', 'files-with-matches', None, | |
2269 | _('print only filenames and revisions that match')), |
|
2269 | _('print only filenames and revisions that match')), | |
2270 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2270 | ('n', 'line-number', None, _('print matching line numbers')), | |
2271 | ('r', 'rev', [], |
|
2271 | ('r', 'rev', [], | |
2272 | _('only search files changed within revision range'), _('REV')), |
|
2272 | _('only search files changed within revision range'), _('REV')), | |
2273 | ('u', 'user', None, _('list the author (long with -v)')), |
|
2273 | ('u', 'user', None, _('list the author (long with -v)')), | |
2274 | ('d', 'date', None, _('list the date (short with -q)')), |
|
2274 | ('d', 'date', None, _('list the date (short with -q)')), | |
2275 | ] + walkopts, |
|
2275 | ] + walkopts, | |
2276 | _('[OPTION]... PATTERN [FILE]...')) |
|
2276 | _('[OPTION]... PATTERN [FILE]...')) | |
2277 | def grep(ui, repo, pattern, *pats, **opts): |
|
2277 | def grep(ui, repo, pattern, *pats, **opts): | |
2278 | """search for a pattern in specified files and revisions |
|
2278 | """search for a pattern in specified files and revisions | |
2279 |
|
2279 | |||
2280 | Search revisions of files for a regular expression. |
|
2280 | Search revisions of files for a regular expression. | |
2281 |
|
2281 | |||
2282 | This command behaves differently than Unix grep. It only accepts |
|
2282 | This command behaves differently than Unix grep. It only accepts | |
2283 | Python/Perl regexps. It searches repository history, not the |
|
2283 | Python/Perl regexps. It searches repository history, not the | |
2284 | working directory. It always prints the revision number in which a |
|
2284 | working directory. It always prints the revision number in which a | |
2285 | match appears. |
|
2285 | match appears. | |
2286 |
|
2286 | |||
2287 | By default, grep only prints output for the first revision of a |
|
2287 | By default, grep only prints output for the first revision of a | |
2288 | file in which it finds a match. To get it to print every revision |
|
2288 | file in which it finds a match. To get it to print every revision | |
2289 | that contains a change in match status ("-" for a match that |
|
2289 | that contains a change in match status ("-" for a match that | |
2290 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
2290 | becomes a non-match, or "+" for a non-match that becomes a match), | |
2291 | use the --all flag. |
|
2291 | use the --all flag. | |
2292 |
|
2292 | |||
2293 | Returns 0 if a match is found, 1 otherwise. |
|
2293 | Returns 0 if a match is found, 1 otherwise. | |
2294 | """ |
|
2294 | """ | |
2295 | reflags = 0 |
|
2295 | reflags = 0 | |
2296 | if opts.get('ignore_case'): |
|
2296 | if opts.get('ignore_case'): | |
2297 | reflags |= re.I |
|
2297 | reflags |= re.I | |
2298 | try: |
|
2298 | try: | |
2299 | regexp = re.compile(pattern, reflags) |
|
2299 | regexp = re.compile(pattern, reflags) | |
2300 | except re.error, inst: |
|
2300 | except re.error, inst: | |
2301 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
2301 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) | |
2302 | return 1 |
|
2302 | return 1 | |
2303 | sep, eol = ':', '\n' |
|
2303 | sep, eol = ':', '\n' | |
2304 | if opts.get('print0'): |
|
2304 | if opts.get('print0'): | |
2305 | sep = eol = '\0' |
|
2305 | sep = eol = '\0' | |
2306 |
|
2306 | |||
2307 | getfile = util.lrucachefunc(repo.file) |
|
2307 | getfile = util.lrucachefunc(repo.file) | |
2308 |
|
2308 | |||
2309 | def matchlines(body): |
|
2309 | def matchlines(body): | |
2310 | begin = 0 |
|
2310 | begin = 0 | |
2311 | linenum = 0 |
|
2311 | linenum = 0 | |
2312 | while True: |
|
2312 | while True: | |
2313 | match = regexp.search(body, begin) |
|
2313 | match = regexp.search(body, begin) | |
2314 | if not match: |
|
2314 | if not match: | |
2315 | break |
|
2315 | break | |
2316 | mstart, mend = match.span() |
|
2316 | mstart, mend = match.span() | |
2317 | linenum += body.count('\n', begin, mstart) + 1 |
|
2317 | linenum += body.count('\n', begin, mstart) + 1 | |
2318 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
2318 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
2319 | begin = body.find('\n', mend) + 1 or len(body) |
|
2319 | begin = body.find('\n', mend) + 1 or len(body) | |
2320 | lend = begin - 1 |
|
2320 | lend = begin - 1 | |
2321 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
2321 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
2322 |
|
2322 | |||
2323 | class linestate(object): |
|
2323 | class linestate(object): | |
2324 | def __init__(self, line, linenum, colstart, colend): |
|
2324 | def __init__(self, line, linenum, colstart, colend): | |
2325 | self.line = line |
|
2325 | self.line = line | |
2326 | self.linenum = linenum |
|
2326 | self.linenum = linenum | |
2327 | self.colstart = colstart |
|
2327 | self.colstart = colstart | |
2328 | self.colend = colend |
|
2328 | self.colend = colend | |
2329 |
|
2329 | |||
2330 | def __hash__(self): |
|
2330 | def __hash__(self): | |
2331 | return hash((self.linenum, self.line)) |
|
2331 | return hash((self.linenum, self.line)) | |
2332 |
|
2332 | |||
2333 | def __eq__(self, other): |
|
2333 | def __eq__(self, other): | |
2334 | return self.line == other.line |
|
2334 | return self.line == other.line | |
2335 |
|
2335 | |||
2336 | matches = {} |
|
2336 | matches = {} | |
2337 | copies = {} |
|
2337 | copies = {} | |
2338 | def grepbody(fn, rev, body): |
|
2338 | def grepbody(fn, rev, body): | |
2339 | matches[rev].setdefault(fn, []) |
|
2339 | matches[rev].setdefault(fn, []) | |
2340 | m = matches[rev][fn] |
|
2340 | m = matches[rev][fn] | |
2341 | for lnum, cstart, cend, line in matchlines(body): |
|
2341 | for lnum, cstart, cend, line in matchlines(body): | |
2342 | s = linestate(line, lnum, cstart, cend) |
|
2342 | s = linestate(line, lnum, cstart, cend) | |
2343 | m.append(s) |
|
2343 | m.append(s) | |
2344 |
|
2344 | |||
2345 | def difflinestates(a, b): |
|
2345 | def difflinestates(a, b): | |
2346 | sm = difflib.SequenceMatcher(None, a, b) |
|
2346 | sm = difflib.SequenceMatcher(None, a, b) | |
2347 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
2347 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | |
2348 | if tag == 'insert': |
|
2348 | if tag == 'insert': | |
2349 | for i in xrange(blo, bhi): |
|
2349 | for i in xrange(blo, bhi): | |
2350 | yield ('+', b[i]) |
|
2350 | yield ('+', b[i]) | |
2351 | elif tag == 'delete': |
|
2351 | elif tag == 'delete': | |
2352 | for i in xrange(alo, ahi): |
|
2352 | for i in xrange(alo, ahi): | |
2353 | yield ('-', a[i]) |
|
2353 | yield ('-', a[i]) | |
2354 | elif tag == 'replace': |
|
2354 | elif tag == 'replace': | |
2355 | for i in xrange(alo, ahi): |
|
2355 | for i in xrange(alo, ahi): | |
2356 | yield ('-', a[i]) |
|
2356 | yield ('-', a[i]) | |
2357 | for i in xrange(blo, bhi): |
|
2357 | for i in xrange(blo, bhi): | |
2358 | yield ('+', b[i]) |
|
2358 | yield ('+', b[i]) | |
2359 |
|
2359 | |||
2360 | def display(fn, ctx, pstates, states): |
|
2360 | def display(fn, ctx, pstates, states): | |
2361 | rev = ctx.rev() |
|
2361 | rev = ctx.rev() | |
2362 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
2362 | datefunc = ui.quiet and util.shortdate or util.datestr | |
2363 | found = False |
|
2363 | found = False | |
2364 | filerevmatches = {} |
|
2364 | filerevmatches = {} | |
2365 | def binary(): |
|
2365 | def binary(): | |
2366 | flog = getfile(fn) |
|
2366 | flog = getfile(fn) | |
2367 | return util.binary(flog.read(ctx.filenode(fn))) |
|
2367 | return util.binary(flog.read(ctx.filenode(fn))) | |
2368 |
|
2368 | |||
2369 | if opts.get('all'): |
|
2369 | if opts.get('all'): | |
2370 | iter = difflinestates(pstates, states) |
|
2370 | iter = difflinestates(pstates, states) | |
2371 | else: |
|
2371 | else: | |
2372 | iter = [('', l) for l in states] |
|
2372 | iter = [('', l) for l in states] | |
2373 | for change, l in iter: |
|
2373 | for change, l in iter: | |
2374 | cols = [fn, str(rev)] |
|
2374 | cols = [fn, str(rev)] | |
2375 | before, match, after = None, None, None |
|
2375 | before, match, after = None, None, None | |
2376 | if opts.get('line_number'): |
|
2376 | if opts.get('line_number'): | |
2377 | cols.append(str(l.linenum)) |
|
2377 | cols.append(str(l.linenum)) | |
2378 | if opts.get('all'): |
|
2378 | if opts.get('all'): | |
2379 | cols.append(change) |
|
2379 | cols.append(change) | |
2380 | if opts.get('user'): |
|
2380 | if opts.get('user'): | |
2381 | cols.append(ui.shortuser(ctx.user())) |
|
2381 | cols.append(ui.shortuser(ctx.user())) | |
2382 | if opts.get('date'): |
|
2382 | if opts.get('date'): | |
2383 | cols.append(datefunc(ctx.date())) |
|
2383 | cols.append(datefunc(ctx.date())) | |
2384 | if opts.get('files_with_matches'): |
|
2384 | if opts.get('files_with_matches'): | |
2385 | c = (fn, rev) |
|
2385 | c = (fn, rev) | |
2386 | if c in filerevmatches: |
|
2386 | if c in filerevmatches: | |
2387 | continue |
|
2387 | continue | |
2388 | filerevmatches[c] = 1 |
|
2388 | filerevmatches[c] = 1 | |
2389 | else: |
|
2389 | else: | |
2390 | before = l.line[:l.colstart] |
|
2390 | before = l.line[:l.colstart] | |
2391 | match = l.line[l.colstart:l.colend] |
|
2391 | match = l.line[l.colstart:l.colend] | |
2392 | after = l.line[l.colend:] |
|
2392 | after = l.line[l.colend:] | |
2393 | ui.write(sep.join(cols)) |
|
2393 | ui.write(sep.join(cols)) | |
2394 | if before is not None: |
|
2394 | if before is not None: | |
2395 | if not opts.get('text') and binary(): |
|
2395 | if not opts.get('text') and binary(): | |
2396 | ui.write(sep + " Binary file matches") |
|
2396 | ui.write(sep + " Binary file matches") | |
2397 | else: |
|
2397 | else: | |
2398 | ui.write(sep + before) |
|
2398 | ui.write(sep + before) | |
2399 | ui.write(match, label='grep.match') |
|
2399 | ui.write(match, label='grep.match') | |
2400 | ui.write(after) |
|
2400 | ui.write(after) | |
2401 | ui.write(eol) |
|
2401 | ui.write(eol) | |
2402 | found = True |
|
2402 | found = True | |
2403 | return found |
|
2403 | return found | |
2404 |
|
2404 | |||
2405 | skip = {} |
|
2405 | skip = {} | |
2406 | revfiles = {} |
|
2406 | revfiles = {} | |
2407 | matchfn = cmdutil.match(repo, pats, opts) |
|
2407 | matchfn = cmdutil.match(repo, pats, opts) | |
2408 | found = False |
|
2408 | found = False | |
2409 | follow = opts.get('follow') |
|
2409 | follow = opts.get('follow') | |
2410 |
|
2410 | |||
2411 | def prep(ctx, fns): |
|
2411 | def prep(ctx, fns): | |
2412 | rev = ctx.rev() |
|
2412 | rev = ctx.rev() | |
2413 | pctx = ctx.p1() |
|
2413 | pctx = ctx.p1() | |
2414 | parent = pctx.rev() |
|
2414 | parent = pctx.rev() | |
2415 | matches.setdefault(rev, {}) |
|
2415 | matches.setdefault(rev, {}) | |
2416 | matches.setdefault(parent, {}) |
|
2416 | matches.setdefault(parent, {}) | |
2417 | files = revfiles.setdefault(rev, []) |
|
2417 | files = revfiles.setdefault(rev, []) | |
2418 | for fn in fns: |
|
2418 | for fn in fns: | |
2419 | flog = getfile(fn) |
|
2419 | flog = getfile(fn) | |
2420 | try: |
|
2420 | try: | |
2421 | fnode = ctx.filenode(fn) |
|
2421 | fnode = ctx.filenode(fn) | |
2422 | except error.LookupError: |
|
2422 | except error.LookupError: | |
2423 | continue |
|
2423 | continue | |
2424 |
|
2424 | |||
2425 | copied = flog.renamed(fnode) |
|
2425 | copied = flog.renamed(fnode) | |
2426 | copy = follow and copied and copied[0] |
|
2426 | copy = follow and copied and copied[0] | |
2427 | if copy: |
|
2427 | if copy: | |
2428 | copies.setdefault(rev, {})[fn] = copy |
|
2428 | copies.setdefault(rev, {})[fn] = copy | |
2429 | if fn in skip: |
|
2429 | if fn in skip: | |
2430 | if copy: |
|
2430 | if copy: | |
2431 | skip[copy] = True |
|
2431 | skip[copy] = True | |
2432 | continue |
|
2432 | continue | |
2433 | files.append(fn) |
|
2433 | files.append(fn) | |
2434 |
|
2434 | |||
2435 | if fn not in matches[rev]: |
|
2435 | if fn not in matches[rev]: | |
2436 | grepbody(fn, rev, flog.read(fnode)) |
|
2436 | grepbody(fn, rev, flog.read(fnode)) | |
2437 |
|
2437 | |||
2438 | pfn = copy or fn |
|
2438 | pfn = copy or fn | |
2439 | if pfn not in matches[parent]: |
|
2439 | if pfn not in matches[parent]: | |
2440 | try: |
|
2440 | try: | |
2441 | fnode = pctx.filenode(pfn) |
|
2441 | fnode = pctx.filenode(pfn) | |
2442 | grepbody(pfn, parent, flog.read(fnode)) |
|
2442 | grepbody(pfn, parent, flog.read(fnode)) | |
2443 | except error.LookupError: |
|
2443 | except error.LookupError: | |
2444 | pass |
|
2444 | pass | |
2445 |
|
2445 | |||
2446 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
2446 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): | |
2447 | rev = ctx.rev() |
|
2447 | rev = ctx.rev() | |
2448 | parent = ctx.p1().rev() |
|
2448 | parent = ctx.p1().rev() | |
2449 | for fn in sorted(revfiles.get(rev, [])): |
|
2449 | for fn in sorted(revfiles.get(rev, [])): | |
2450 | states = matches[rev][fn] |
|
2450 | states = matches[rev][fn] | |
2451 | copy = copies.get(rev, {}).get(fn) |
|
2451 | copy = copies.get(rev, {}).get(fn) | |
2452 | if fn in skip: |
|
2452 | if fn in skip: | |
2453 | if copy: |
|
2453 | if copy: | |
2454 | skip[copy] = True |
|
2454 | skip[copy] = True | |
2455 | continue |
|
2455 | continue | |
2456 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
2456 | pstates = matches.get(parent, {}).get(copy or fn, []) | |
2457 | if pstates or states: |
|
2457 | if pstates or states: | |
2458 | r = display(fn, ctx, pstates, states) |
|
2458 | r = display(fn, ctx, pstates, states) | |
2459 | found = found or r |
|
2459 | found = found or r | |
2460 | if r and not opts.get('all'): |
|
2460 | if r and not opts.get('all'): | |
2461 | skip[fn] = True |
|
2461 | skip[fn] = True | |
2462 | if copy: |
|
2462 | if copy: | |
2463 | skip[copy] = True |
|
2463 | skip[copy] = True | |
2464 | del matches[rev] |
|
2464 | del matches[rev] | |
2465 | del revfiles[rev] |
|
2465 | del revfiles[rev] | |
2466 |
|
2466 | |||
2467 | return not found |
|
2467 | return not found | |
2468 |
|
2468 | |||
2469 | @command('heads', |
|
2469 | @command('heads', | |
2470 | [('r', 'rev', '', |
|
2470 | [('r', 'rev', '', | |
2471 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), |
|
2471 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), | |
2472 | ('t', 'topo', False, _('show topological heads only')), |
|
2472 | ('t', 'topo', False, _('show topological heads only')), | |
2473 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), |
|
2473 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), | |
2474 | ('c', 'closed', False, _('show normal and closed branch heads')), |
|
2474 | ('c', 'closed', False, _('show normal and closed branch heads')), | |
2475 | ] + templateopts, |
|
2475 | ] + templateopts, | |
2476 | _('[-ac] [-r STARTREV] [REV]...')) |
|
2476 | _('[-ac] [-r STARTREV] [REV]...')) | |
2477 | def heads(ui, repo, *branchrevs, **opts): |
|
2477 | def heads(ui, repo, *branchrevs, **opts): | |
2478 | """show current repository heads or show branch heads |
|
2478 | """show current repository heads or show branch heads | |
2479 |
|
2479 | |||
2480 | With no arguments, show all repository branch heads. |
|
2480 | With no arguments, show all repository branch heads. | |
2481 |
|
2481 | |||
2482 | Repository "heads" are changesets with no child changesets. They are |
|
2482 | Repository "heads" are changesets with no child changesets. They are | |
2483 | where development generally takes place and are the usual targets |
|
2483 | where development generally takes place and are the usual targets | |
2484 | for update and merge operations. Branch heads are changesets that have |
|
2484 | for update and merge operations. Branch heads are changesets that have | |
2485 | no child changeset on the same branch. |
|
2485 | no child changeset on the same branch. | |
2486 |
|
2486 | |||
2487 | If one or more REVs are given, only branch heads on the branches |
|
2487 | If one or more REVs are given, only branch heads on the branches | |
2488 | associated with the specified changesets are shown. |
|
2488 | associated with the specified changesets are shown. | |
2489 |
|
2489 | |||
2490 | If -c/--closed is specified, also show branch heads marked closed |
|
2490 | If -c/--closed is specified, also show branch heads marked closed | |
2491 | (see :hg:`commit --close-branch`). |
|
2491 | (see :hg:`commit --close-branch`). | |
2492 |
|
2492 | |||
2493 | If STARTREV is specified, only those heads that are descendants of |
|
2493 | If STARTREV is specified, only those heads that are descendants of | |
2494 | STARTREV will be displayed. |
|
2494 | STARTREV will be displayed. | |
2495 |
|
2495 | |||
2496 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
2496 | If -t/--topo is specified, named branch mechanics will be ignored and only | |
2497 | changesets without children will be shown. |
|
2497 | changesets without children will be shown. | |
2498 |
|
2498 | |||
2499 | Returns 0 if matching heads are found, 1 if not. |
|
2499 | Returns 0 if matching heads are found, 1 if not. | |
2500 | """ |
|
2500 | """ | |
2501 |
|
2501 | |||
2502 | start = None |
|
2502 | start = None | |
2503 | if 'rev' in opts: |
|
2503 | if 'rev' in opts: | |
2504 | start = scmutil.revsingle(repo, opts['rev'], None).node() |
|
2504 | start = scmutil.revsingle(repo, opts['rev'], None).node() | |
2505 |
|
2505 | |||
2506 | if opts.get('topo'): |
|
2506 | if opts.get('topo'): | |
2507 | heads = [repo[h] for h in repo.heads(start)] |
|
2507 | heads = [repo[h] for h in repo.heads(start)] | |
2508 | else: |
|
2508 | else: | |
2509 | heads = [] |
|
2509 | heads = [] | |
2510 | for b, ls in repo.branchmap().iteritems(): |
|
2510 | for b, ls in repo.branchmap().iteritems(): | |
2511 | if start is None: |
|
2511 | if start is None: | |
2512 | heads += [repo[h] for h in ls] |
|
2512 | heads += [repo[h] for h in ls] | |
2513 | continue |
|
2513 | continue | |
2514 | startrev = repo.changelog.rev(start) |
|
2514 | startrev = repo.changelog.rev(start) | |
2515 | descendants = set(repo.changelog.descendants(startrev)) |
|
2515 | descendants = set(repo.changelog.descendants(startrev)) | |
2516 | descendants.add(startrev) |
|
2516 | descendants.add(startrev) | |
2517 | rev = repo.changelog.rev |
|
2517 | rev = repo.changelog.rev | |
2518 | heads += [repo[h] for h in ls if rev(h) in descendants] |
|
2518 | heads += [repo[h] for h in ls if rev(h) in descendants] | |
2519 |
|
2519 | |||
2520 | if branchrevs: |
|
2520 | if branchrevs: | |
2521 | branches = set(repo[br].branch() for br in branchrevs) |
|
2521 | branches = set(repo[br].branch() for br in branchrevs) | |
2522 | heads = [h for h in heads if h.branch() in branches] |
|
2522 | heads = [h for h in heads if h.branch() in branches] | |
2523 |
|
2523 | |||
2524 | if not opts.get('closed'): |
|
2524 | if not opts.get('closed'): | |
2525 | heads = [h for h in heads if not h.extra().get('close')] |
|
2525 | heads = [h for h in heads if not h.extra().get('close')] | |
2526 |
|
2526 | |||
2527 | if opts.get('active') and branchrevs: |
|
2527 | if opts.get('active') and branchrevs: | |
2528 | dagheads = repo.heads(start) |
|
2528 | dagheads = repo.heads(start) | |
2529 | heads = [h for h in heads if h.node() in dagheads] |
|
2529 | heads = [h for h in heads if h.node() in dagheads] | |
2530 |
|
2530 | |||
2531 | if branchrevs: |
|
2531 | if branchrevs: | |
2532 | haveheads = set(h.branch() for h in heads) |
|
2532 | haveheads = set(h.branch() for h in heads) | |
2533 | if branches - haveheads: |
|
2533 | if branches - haveheads: | |
2534 | headless = ', '.join(b for b in branches - haveheads) |
|
2534 | headless = ', '.join(b for b in branches - haveheads) | |
2535 | msg = _('no open branch heads found on branches %s') |
|
2535 | msg = _('no open branch heads found on branches %s') | |
2536 | if opts.get('rev'): |
|
2536 | if opts.get('rev'): | |
2537 | msg += _(' (started at %s)' % opts['rev']) |
|
2537 | msg += _(' (started at %s)' % opts['rev']) | |
2538 | ui.warn((msg + '\n') % headless) |
|
2538 | ui.warn((msg + '\n') % headless) | |
2539 |
|
2539 | |||
2540 | if not heads: |
|
2540 | if not heads: | |
2541 | return 1 |
|
2541 | return 1 | |
2542 |
|
2542 | |||
2543 | heads = sorted(heads, key=lambda x: -x.rev()) |
|
2543 | heads = sorted(heads, key=lambda x: -x.rev()) | |
2544 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
2544 | displayer = cmdutil.show_changeset(ui, repo, opts) | |
2545 | for ctx in heads: |
|
2545 | for ctx in heads: | |
2546 | displayer.show(ctx) |
|
2546 | displayer.show(ctx) | |
2547 | displayer.close() |
|
2547 | displayer.close() | |
2548 |
|
2548 | |||
2549 | @command('help', |
|
2549 | @command('help', | |
2550 | [('e', 'extension', None, _('show only help for extensions')), |
|
2550 | [('e', 'extension', None, _('show only help for extensions')), | |
2551 | ('c', 'command', None, _('show only help for commands'))], |
|
2551 | ('c', 'command', None, _('show only help for commands'))], | |
2552 | _('[-ec] [TOPIC]')) |
|
2552 | _('[-ec] [TOPIC]')) | |
2553 | def help_(ui, name=None, with_version=False, unknowncmd=False, full=True, **opts): |
|
2553 | def help_(ui, name=None, with_version=False, unknowncmd=False, full=True, **opts): | |
2554 | """show help for a given topic or a help overview |
|
2554 | """show help for a given topic or a help overview | |
2555 |
|
2555 | |||
2556 | With no arguments, print a list of commands with short help messages. |
|
2556 | With no arguments, print a list of commands with short help messages. | |
2557 |
|
2557 | |||
2558 | Given a topic, extension, or command name, print help for that |
|
2558 | Given a topic, extension, or command name, print help for that | |
2559 | topic. |
|
2559 | topic. | |
2560 |
|
2560 | |||
2561 | Returns 0 if successful. |
|
2561 | Returns 0 if successful. | |
2562 | """ |
|
2562 | """ | |
2563 | option_lists = [] |
|
2563 | option_lists = [] | |
2564 | textwidth = min(ui.termwidth(), 80) - 2 |
|
2564 | textwidth = min(ui.termwidth(), 80) - 2 | |
2565 |
|
2565 | |||
2566 | def addglobalopts(aliases): |
|
2566 | def addglobalopts(aliases): | |
2567 | if ui.verbose: |
|
2567 | if ui.verbose: | |
2568 | option_lists.append((_("global options:"), globalopts)) |
|
2568 | option_lists.append((_("global options:"), globalopts)) | |
2569 | if name == 'shortlist': |
|
2569 | if name == 'shortlist': | |
2570 | option_lists.append((_('use "hg help" for the full list ' |
|
2570 | option_lists.append((_('use "hg help" for the full list ' | |
2571 | 'of commands'), ())) |
|
2571 | 'of commands'), ())) | |
2572 | else: |
|
2572 | else: | |
2573 | if name == 'shortlist': |
|
2573 | if name == 'shortlist': | |
2574 | msg = _('use "hg help" for the full list of commands ' |
|
2574 | msg = _('use "hg help" for the full list of commands ' | |
2575 | 'or "hg -v" for details') |
|
2575 | 'or "hg -v" for details') | |
2576 | elif name and not full: |
|
2576 | elif name and not full: | |
2577 | msg = _('use "hg help %s" to show the full help text' % name) |
|
2577 | msg = _('use "hg help %s" to show the full help text' % name) | |
2578 | elif aliases: |
|
2578 | elif aliases: | |
2579 | msg = _('use "hg -v help%s" to show builtin aliases and ' |
|
2579 | msg = _('use "hg -v help%s" to show builtin aliases and ' | |
2580 | 'global options') % (name and " " + name or "") |
|
2580 | 'global options') % (name and " " + name or "") | |
2581 | else: |
|
2581 | else: | |
2582 | msg = _('use "hg -v help %s" to show global options') % name |
|
2582 | msg = _('use "hg -v help %s" to show global options') % name | |
2583 | option_lists.append((msg, ())) |
|
2583 | option_lists.append((msg, ())) | |
2584 |
|
2584 | |||
2585 | def helpcmd(name): |
|
2585 | def helpcmd(name): | |
2586 | if with_version: |
|
2586 | if with_version: | |
2587 | version_(ui) |
|
2587 | version_(ui) | |
2588 | ui.write('\n') |
|
2588 | ui.write('\n') | |
2589 |
|
2589 | |||
2590 | try: |
|
2590 | try: | |
2591 | aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd) |
|
2591 | aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd) | |
2592 | except error.AmbiguousCommand, inst: |
|
2592 | except error.AmbiguousCommand, inst: | |
2593 | # py3k fix: except vars can't be used outside the scope of the |
|
2593 | # py3k fix: except vars can't be used outside the scope of the | |
2594 | # except block, nor can be used inside a lambda. python issue4617 |
|
2594 | # except block, nor can be used inside a lambda. python issue4617 | |
2595 | prefix = inst.args[0] |
|
2595 | prefix = inst.args[0] | |
2596 | select = lambda c: c.lstrip('^').startswith(prefix) |
|
2596 | select = lambda c: c.lstrip('^').startswith(prefix) | |
2597 | helplist(_('list of commands:\n\n'), select) |
|
2597 | helplist(_('list of commands:\n\n'), select) | |
2598 | return |
|
2598 | return | |
2599 |
|
2599 | |||
2600 | # check if it's an invalid alias and display its error if it is |
|
2600 | # check if it's an invalid alias and display its error if it is | |
2601 | if getattr(entry[0], 'badalias', False): |
|
2601 | if getattr(entry[0], 'badalias', False): | |
2602 | if not unknowncmd: |
|
2602 | if not unknowncmd: | |
2603 | entry[0](ui) |
|
2603 | entry[0](ui) | |
2604 | return |
|
2604 | return | |
2605 |
|
2605 | |||
2606 | # synopsis |
|
2606 | # synopsis | |
2607 | if len(entry) > 2: |
|
2607 | if len(entry) > 2: | |
2608 | if entry[2].startswith('hg'): |
|
2608 | if entry[2].startswith('hg'): | |
2609 | ui.write("%s\n" % entry[2]) |
|
2609 | ui.write("%s\n" % entry[2]) | |
2610 | else: |
|
2610 | else: | |
2611 | ui.write('hg %s %s\n' % (aliases[0], entry[2])) |
|
2611 | ui.write('hg %s %s\n' % (aliases[0], entry[2])) | |
2612 | else: |
|
2612 | else: | |
2613 | ui.write('hg %s\n' % aliases[0]) |
|
2613 | ui.write('hg %s\n' % aliases[0]) | |
2614 |
|
2614 | |||
2615 | # aliases |
|
2615 | # aliases | |
2616 | if full and not ui.quiet and len(aliases) > 1: |
|
2616 | if full and not ui.quiet and len(aliases) > 1: | |
2617 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
2617 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | |
2618 |
|
2618 | |||
2619 | # description |
|
2619 | # description | |
2620 | doc = gettext(entry[0].__doc__) |
|
2620 | doc = gettext(entry[0].__doc__) | |
2621 | if not doc: |
|
2621 | if not doc: | |
2622 | doc = _("(no help text available)") |
|
2622 | doc = _("(no help text available)") | |
2623 | if hasattr(entry[0], 'definition'): # aliased command |
|
2623 | if hasattr(entry[0], 'definition'): # aliased command | |
2624 | if entry[0].definition.startswith('!'): # shell alias |
|
2624 | if entry[0].definition.startswith('!'): # shell alias | |
2625 | doc = _('shell alias for::\n\n %s') % entry[0].definition[1:] |
|
2625 | doc = _('shell alias for::\n\n %s') % entry[0].definition[1:] | |
2626 | else: |
|
2626 | else: | |
2627 | doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc) |
|
2627 | doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc) | |
2628 | if ui.quiet or not full: |
|
2628 | if ui.quiet or not full: | |
2629 | doc = doc.splitlines()[0] |
|
2629 | doc = doc.splitlines()[0] | |
2630 | keep = ui.verbose and ['verbose'] or [] |
|
2630 | keep = ui.verbose and ['verbose'] or [] | |
2631 | formatted, pruned = minirst.format(doc, textwidth, keep=keep) |
|
2631 | formatted, pruned = minirst.format(doc, textwidth, keep=keep) | |
2632 | ui.write("\n%s\n" % formatted) |
|
2632 | ui.write("\n%s\n" % formatted) | |
2633 | if pruned: |
|
2633 | if pruned: | |
2634 | ui.write(_('\nuse "hg -v help %s" to show verbose help\n') % name) |
|
2634 | ui.write(_('\nuse "hg -v help %s" to show verbose help\n') % name) | |
2635 |
|
2635 | |||
2636 | if not ui.quiet: |
|
2636 | if not ui.quiet: | |
2637 | # options |
|
2637 | # options | |
2638 | if entry[1]: |
|
2638 | if entry[1]: | |
2639 | option_lists.append((_("options:\n"), entry[1])) |
|
2639 | option_lists.append((_("options:\n"), entry[1])) | |
2640 |
|
2640 | |||
2641 | addglobalopts(False) |
|
2641 | addglobalopts(False) | |
2642 |
|
2642 | |||
2643 | # check if this command shadows a non-trivial (multi-line) |
|
2643 | # check if this command shadows a non-trivial (multi-line) | |
2644 | # extension help text |
|
2644 | # extension help text | |
2645 | try: |
|
2645 | try: | |
2646 | mod = extensions.find(name) |
|
2646 | mod = extensions.find(name) | |
2647 | doc = gettext(mod.__doc__) or '' |
|
2647 | doc = gettext(mod.__doc__) or '' | |
2648 | if '\n' in doc.strip(): |
|
2648 | if '\n' in doc.strip(): | |
2649 | msg = _('use "hg help -e %s" to show help for ' |
|
2649 | msg = _('use "hg help -e %s" to show help for ' | |
2650 | 'the %s extension') % (name, name) |
|
2650 | 'the %s extension') % (name, name) | |
2651 | ui.write('\n%s\n' % msg) |
|
2651 | ui.write('\n%s\n' % msg) | |
2652 | except KeyError: |
|
2652 | except KeyError: | |
2653 | pass |
|
2653 | pass | |
2654 |
|
2654 | |||
2655 | def helplist(header, select=None): |
|
2655 | def helplist(header, select=None): | |
2656 | h = {} |
|
2656 | h = {} | |
2657 | cmds = {} |
|
2657 | cmds = {} | |
2658 | for c, e in table.iteritems(): |
|
2658 | for c, e in table.iteritems(): | |
2659 | f = c.split("|", 1)[0] |
|
2659 | f = c.split("|", 1)[0] | |
2660 | if select and not select(f): |
|
2660 | if select and not select(f): | |
2661 | continue |
|
2661 | continue | |
2662 | if (not select and name != 'shortlist' and |
|
2662 | if (not select and name != 'shortlist' and | |
2663 | e[0].__module__ != __name__): |
|
2663 | e[0].__module__ != __name__): | |
2664 | continue |
|
2664 | continue | |
2665 | if name == "shortlist" and not f.startswith("^"): |
|
2665 | if name == "shortlist" and not f.startswith("^"): | |
2666 | continue |
|
2666 | continue | |
2667 | f = f.lstrip("^") |
|
2667 | f = f.lstrip("^") | |
2668 | if not ui.debugflag and f.startswith("debug"): |
|
2668 | if not ui.debugflag and f.startswith("debug"): | |
2669 | continue |
|
2669 | continue | |
2670 | doc = e[0].__doc__ |
|
2670 | doc = e[0].__doc__ | |
2671 | if doc and 'DEPRECATED' in doc and not ui.verbose: |
|
2671 | if doc and 'DEPRECATED' in doc and not ui.verbose: | |
2672 | continue |
|
2672 | continue | |
2673 | doc = gettext(doc) |
|
2673 | doc = gettext(doc) | |
2674 | if not doc: |
|
2674 | if not doc: | |
2675 | doc = _("(no help text available)") |
|
2675 | doc = _("(no help text available)") | |
2676 | h[f] = doc.splitlines()[0].rstrip() |
|
2676 | h[f] = doc.splitlines()[0].rstrip() | |
2677 | cmds[f] = c.lstrip("^") |
|
2677 | cmds[f] = c.lstrip("^") | |
2678 |
|
2678 | |||
2679 | if not h: |
|
2679 | if not h: | |
2680 | ui.status(_('no commands defined\n')) |
|
2680 | ui.status(_('no commands defined\n')) | |
2681 | return |
|
2681 | return | |
2682 |
|
2682 | |||
2683 | ui.status(header) |
|
2683 | ui.status(header) | |
2684 | fns = sorted(h) |
|
2684 | fns = sorted(h) | |
2685 | m = max(map(len, fns)) |
|
2685 | m = max(map(len, fns)) | |
2686 | for f in fns: |
|
2686 | for f in fns: | |
2687 | if ui.verbose: |
|
2687 | if ui.verbose: | |
2688 | commands = cmds[f].replace("|",", ") |
|
2688 | commands = cmds[f].replace("|",", ") | |
2689 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
2689 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
2690 | else: |
|
2690 | else: | |
2691 | ui.write('%s\n' % (util.wrap(h[f], textwidth, |
|
2691 | ui.write('%s\n' % (util.wrap(h[f], textwidth, | |
2692 | initindent=' %-*s ' % (m, f), |
|
2692 | initindent=' %-*s ' % (m, f), | |
2693 | hangindent=' ' * (m + 4)))) |
|
2693 | hangindent=' ' * (m + 4)))) | |
2694 |
|
2694 | |||
2695 | if not ui.quiet: |
|
2695 | if not ui.quiet: | |
2696 | addglobalopts(True) |
|
2696 | addglobalopts(True) | |
2697 |
|
2697 | |||
2698 | def helptopic(name): |
|
2698 | def helptopic(name): | |
2699 | for names, header, doc in help.helptable: |
|
2699 | for names, header, doc in help.helptable: | |
2700 | if name in names: |
|
2700 | if name in names: | |
2701 | break |
|
2701 | break | |
2702 | else: |
|
2702 | else: | |
2703 | raise error.UnknownCommand(name) |
|
2703 | raise error.UnknownCommand(name) | |
2704 |
|
2704 | |||
2705 | # description |
|
2705 | # description | |
2706 | if not doc: |
|
2706 | if not doc: | |
2707 | doc = _("(no help text available)") |
|
2707 | doc = _("(no help text available)") | |
2708 | if hasattr(doc, '__call__'): |
|
2708 | if hasattr(doc, '__call__'): | |
2709 | doc = doc() |
|
2709 | doc = doc() | |
2710 |
|
2710 | |||
2711 | ui.write("%s\n\n" % header) |
|
2711 | ui.write("%s\n\n" % header) | |
2712 | ui.write("%s\n" % minirst.format(doc, textwidth, indent=4)) |
|
2712 | ui.write("%s\n" % minirst.format(doc, textwidth, indent=4)) | |
2713 | try: |
|
2713 | try: | |
2714 | cmdutil.findcmd(name, table) |
|
2714 | cmdutil.findcmd(name, table) | |
2715 | ui.write(_('\nuse "hg help -c %s" to see help for ' |
|
2715 | ui.write(_('\nuse "hg help -c %s" to see help for ' | |
2716 | 'the %s command\n') % (name, name)) |
|
2716 | 'the %s command\n') % (name, name)) | |
2717 | except error.UnknownCommand: |
|
2717 | except error.UnknownCommand: | |
2718 | pass |
|
2718 | pass | |
2719 |
|
2719 | |||
2720 | def helpext(name): |
|
2720 | def helpext(name): | |
2721 | try: |
|
2721 | try: | |
2722 | mod = extensions.find(name) |
|
2722 | mod = extensions.find(name) | |
2723 | doc = gettext(mod.__doc__) or _('no help text available') |
|
2723 | doc = gettext(mod.__doc__) or _('no help text available') | |
2724 | except KeyError: |
|
2724 | except KeyError: | |
2725 | mod = None |
|
2725 | mod = None | |
2726 | doc = extensions.disabledext(name) |
|
2726 | doc = extensions.disabledext(name) | |
2727 | if not doc: |
|
2727 | if not doc: | |
2728 | raise error.UnknownCommand(name) |
|
2728 | raise error.UnknownCommand(name) | |
2729 |
|
2729 | |||
2730 | if '\n' not in doc: |
|
2730 | if '\n' not in doc: | |
2731 | head, tail = doc, "" |
|
2731 | head, tail = doc, "" | |
2732 | else: |
|
2732 | else: | |
2733 | head, tail = doc.split('\n', 1) |
|
2733 | head, tail = doc.split('\n', 1) | |
2734 | ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head)) |
|
2734 | ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head)) | |
2735 | if tail: |
|
2735 | if tail: | |
2736 | ui.write(minirst.format(tail, textwidth)) |
|
2736 | ui.write(minirst.format(tail, textwidth)) | |
2737 | ui.status('\n\n') |
|
2737 | ui.status('\n\n') | |
2738 |
|
2738 | |||
2739 | if mod: |
|
2739 | if mod: | |
2740 | try: |
|
2740 | try: | |
2741 | ct = mod.cmdtable |
|
2741 | ct = mod.cmdtable | |
2742 | except AttributeError: |
|
2742 | except AttributeError: | |
2743 | ct = {} |
|
2743 | ct = {} | |
2744 | modcmds = set([c.split('|', 1)[0] for c in ct]) |
|
2744 | modcmds = set([c.split('|', 1)[0] for c in ct]) | |
2745 | helplist(_('list of commands:\n\n'), modcmds.__contains__) |
|
2745 | helplist(_('list of commands:\n\n'), modcmds.__contains__) | |
2746 | else: |
|
2746 | else: | |
2747 | ui.write(_('use "hg help extensions" for information on enabling ' |
|
2747 | ui.write(_('use "hg help extensions" for information on enabling ' | |
2748 | 'extensions\n')) |
|
2748 | 'extensions\n')) | |
2749 |
|
2749 | |||
2750 | def helpextcmd(name): |
|
2750 | def helpextcmd(name): | |
2751 | cmd, ext, mod = extensions.disabledcmd(ui, name, ui.config('ui', 'strict')) |
|
2751 | cmd, ext, mod = extensions.disabledcmd(ui, name, ui.config('ui', 'strict')) | |
2752 | doc = gettext(mod.__doc__).splitlines()[0] |
|
2752 | doc = gettext(mod.__doc__).splitlines()[0] | |
2753 |
|
2753 | |||
2754 | msg = help.listexts(_("'%s' is provided by the following " |
|
2754 | msg = help.listexts(_("'%s' is provided by the following " | |
2755 | "extension:") % cmd, {ext: doc}, indent=4) |
|
2755 | "extension:") % cmd, {ext: doc}, indent=4) | |
2756 | ui.write(minirst.format(msg, textwidth)) |
|
2756 | ui.write(minirst.format(msg, textwidth)) | |
2757 | ui.write('\n\n') |
|
2757 | ui.write('\n\n') | |
2758 | ui.write(_('use "hg help extensions" for information on enabling ' |
|
2758 | ui.write(_('use "hg help extensions" for information on enabling ' | |
2759 | 'extensions\n')) |
|
2759 | 'extensions\n')) | |
2760 |
|
2760 | |||
2761 | if name and name != 'shortlist': |
|
2761 | if name and name != 'shortlist': | |
2762 | i = None |
|
2762 | i = None | |
2763 | if unknowncmd: |
|
2763 | if unknowncmd: | |
2764 | queries = (helpextcmd,) |
|
2764 | queries = (helpextcmd,) | |
2765 | elif opts.get('extension'): |
|
2765 | elif opts.get('extension'): | |
2766 | queries = (helpext,) |
|
2766 | queries = (helpext,) | |
2767 | elif opts.get('command'): |
|
2767 | elif opts.get('command'): | |
2768 | queries = (helpcmd,) |
|
2768 | queries = (helpcmd,) | |
2769 | else: |
|
2769 | else: | |
2770 | queries = (helptopic, helpcmd, helpext, helpextcmd) |
|
2770 | queries = (helptopic, helpcmd, helpext, helpextcmd) | |
2771 | for f in queries: |
|
2771 | for f in queries: | |
2772 | try: |
|
2772 | try: | |
2773 | f(name) |
|
2773 | f(name) | |
2774 | i = None |
|
2774 | i = None | |
2775 | break |
|
2775 | break | |
2776 | except error.UnknownCommand, inst: |
|
2776 | except error.UnknownCommand, inst: | |
2777 | i = inst |
|
2777 | i = inst | |
2778 | if i: |
|
2778 | if i: | |
2779 | raise i |
|
2779 | raise i | |
2780 |
|
2780 | |||
2781 | else: |
|
2781 | else: | |
2782 | # program name |
|
2782 | # program name | |
2783 | if ui.verbose or with_version: |
|
2783 | if ui.verbose or with_version: | |
2784 | version_(ui) |
|
2784 | version_(ui) | |
2785 | else: |
|
2785 | else: | |
2786 | ui.status(_("Mercurial Distributed SCM\n")) |
|
2786 | ui.status(_("Mercurial Distributed SCM\n")) | |
2787 | ui.status('\n') |
|
2787 | ui.status('\n') | |
2788 |
|
2788 | |||
2789 | # list of commands |
|
2789 | # list of commands | |
2790 | if name == "shortlist": |
|
2790 | if name == "shortlist": | |
2791 | header = _('basic commands:\n\n') |
|
2791 | header = _('basic commands:\n\n') | |
2792 | else: |
|
2792 | else: | |
2793 | header = _('list of commands:\n\n') |
|
2793 | header = _('list of commands:\n\n') | |
2794 |
|
2794 | |||
2795 | helplist(header) |
|
2795 | helplist(header) | |
2796 | if name != 'shortlist': |
|
2796 | if name != 'shortlist': | |
2797 | text = help.listexts(_('enabled extensions:'), extensions.enabled()) |
|
2797 | text = help.listexts(_('enabled extensions:'), extensions.enabled()) | |
2798 | if text: |
|
2798 | if text: | |
2799 | ui.write("\n%s\n" % minirst.format(text, textwidth)) |
|
2799 | ui.write("\n%s\n" % minirst.format(text, textwidth)) | |
2800 |
|
2800 | |||
2801 | # list all option lists |
|
2801 | # list all option lists | |
2802 | opt_output = [] |
|
2802 | opt_output = [] | |
2803 | multioccur = False |
|
2803 | multioccur = False | |
2804 | for title, options in option_lists: |
|
2804 | for title, options in option_lists: | |
2805 | opt_output.append(("\n%s" % title, None)) |
|
2805 | opt_output.append(("\n%s" % title, None)) | |
2806 | for option in options: |
|
2806 | for option in options: | |
2807 | if len(option) == 5: |
|
2807 | if len(option) == 5: | |
2808 | shortopt, longopt, default, desc, optlabel = option |
|
2808 | shortopt, longopt, default, desc, optlabel = option | |
2809 | else: |
|
2809 | else: | |
2810 | shortopt, longopt, default, desc = option |
|
2810 | shortopt, longopt, default, desc = option | |
2811 | optlabel = _("VALUE") # default label |
|
2811 | optlabel = _("VALUE") # default label | |
2812 |
|
2812 | |||
2813 | if _("DEPRECATED") in desc and not ui.verbose: |
|
2813 | if _("DEPRECATED") in desc and not ui.verbose: | |
2814 | continue |
|
2814 | continue | |
2815 | if isinstance(default, list): |
|
2815 | if isinstance(default, list): | |
2816 | numqualifier = " %s [+]" % optlabel |
|
2816 | numqualifier = " %s [+]" % optlabel | |
2817 | multioccur = True |
|
2817 | multioccur = True | |
2818 | elif (default is not None) and not isinstance(default, bool): |
|
2818 | elif (default is not None) and not isinstance(default, bool): | |
2819 | numqualifier = " %s" % optlabel |
|
2819 | numqualifier = " %s" % optlabel | |
2820 | else: |
|
2820 | else: | |
2821 | numqualifier = "" |
|
2821 | numqualifier = "" | |
2822 | opt_output.append(("%2s%s" % |
|
2822 | opt_output.append(("%2s%s" % | |
2823 | (shortopt and "-%s" % shortopt, |
|
2823 | (shortopt and "-%s" % shortopt, | |
2824 | longopt and " --%s%s" % |
|
2824 | longopt and " --%s%s" % | |
2825 | (longopt, numqualifier)), |
|
2825 | (longopt, numqualifier)), | |
2826 | "%s%s" % (desc, |
|
2826 | "%s%s" % (desc, | |
2827 | default |
|
2827 | default | |
2828 | and _(" (default: %s)") % default |
|
2828 | and _(" (default: %s)") % default | |
2829 | or ""))) |
|
2829 | or ""))) | |
2830 | if multioccur: |
|
2830 | if multioccur: | |
2831 | msg = _("\n[+] marked option can be specified multiple times") |
|
2831 | msg = _("\n[+] marked option can be specified multiple times") | |
2832 | if ui.verbose and name != 'shortlist': |
|
2832 | if ui.verbose and name != 'shortlist': | |
2833 | opt_output.append((msg, None)) |
|
2833 | opt_output.append((msg, None)) | |
2834 | else: |
|
2834 | else: | |
2835 | opt_output.insert(-1, (msg, None)) |
|
2835 | opt_output.insert(-1, (msg, None)) | |
2836 |
|
2836 | |||
2837 | if not name: |
|
2837 | if not name: | |
2838 | ui.write(_("\nadditional help topics:\n\n")) |
|
2838 | ui.write(_("\nadditional help topics:\n\n")) | |
2839 | topics = [] |
|
2839 | topics = [] | |
2840 | for names, header, doc in help.helptable: |
|
2840 | for names, header, doc in help.helptable: | |
2841 | topics.append((sorted(names, key=len, reverse=True)[0], header)) |
|
2841 | topics.append((sorted(names, key=len, reverse=True)[0], header)) | |
2842 | topics_len = max([len(s[0]) for s in topics]) |
|
2842 | topics_len = max([len(s[0]) for s in topics]) | |
2843 | for t, desc in topics: |
|
2843 | for t, desc in topics: | |
2844 | ui.write(" %-*s %s\n" % (topics_len, t, desc)) |
|
2844 | ui.write(" %-*s %s\n" % (topics_len, t, desc)) | |
2845 |
|
2845 | |||
2846 | if opt_output: |
|
2846 | if opt_output: | |
2847 | colwidth = encoding.colwidth |
|
2847 | colwidth = encoding.colwidth | |
2848 | # normalize: (opt or message, desc or None, width of opt) |
|
2848 | # normalize: (opt or message, desc or None, width of opt) | |
2849 | entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0) |
|
2849 | entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0) | |
2850 | for opt, desc in opt_output] |
|
2850 | for opt, desc in opt_output] | |
2851 | hanging = max([e[2] for e in entries]) |
|
2851 | hanging = max([e[2] for e in entries]) | |
2852 | for opt, desc, width in entries: |
|
2852 | for opt, desc, width in entries: | |
2853 | if desc: |
|
2853 | if desc: | |
2854 | initindent = ' %s%s ' % (opt, ' ' * (hanging - width)) |
|
2854 | initindent = ' %s%s ' % (opt, ' ' * (hanging - width)) | |
2855 | hangindent = ' ' * (hanging + 3) |
|
2855 | hangindent = ' ' * (hanging + 3) | |
2856 | ui.write('%s\n' % (util.wrap(desc, textwidth, |
|
2856 | ui.write('%s\n' % (util.wrap(desc, textwidth, | |
2857 | initindent=initindent, |
|
2857 | initindent=initindent, | |
2858 | hangindent=hangindent))) |
|
2858 | hangindent=hangindent))) | |
2859 | else: |
|
2859 | else: | |
2860 | ui.write("%s\n" % opt) |
|
2860 | ui.write("%s\n" % opt) | |
2861 |
|
2861 | |||
2862 | @command('identify|id', |
|
2862 | @command('identify|id', | |
2863 | [('r', 'rev', '', |
|
2863 | [('r', 'rev', '', | |
2864 | _('identify the specified revision'), _('REV')), |
|
2864 | _('identify the specified revision'), _('REV')), | |
2865 | ('n', 'num', None, _('show local revision number')), |
|
2865 | ('n', 'num', None, _('show local revision number')), | |
2866 | ('i', 'id', None, _('show global revision id')), |
|
2866 | ('i', 'id', None, _('show global revision id')), | |
2867 | ('b', 'branch', None, _('show branch')), |
|
2867 | ('b', 'branch', None, _('show branch')), | |
2868 | ('t', 'tags', None, _('show tags')), |
|
2868 | ('t', 'tags', None, _('show tags')), | |
2869 | ('B', 'bookmarks', None, _('show bookmarks'))], |
|
2869 | ('B', 'bookmarks', None, _('show bookmarks'))], | |
2870 | _('[-nibtB] [-r REV] [SOURCE]')) |
|
2870 | _('[-nibtB] [-r REV] [SOURCE]')) | |
2871 | def identify(ui, repo, source=None, rev=None, |
|
2871 | def identify(ui, repo, source=None, rev=None, | |
2872 | num=None, id=None, branch=None, tags=None, bookmarks=None): |
|
2872 | num=None, id=None, branch=None, tags=None, bookmarks=None): | |
2873 | """identify the working copy or specified revision |
|
2873 | """identify the working copy or specified revision | |
2874 |
|
2874 | |||
2875 | Print a summary identifying the repository state at REV using one or |
|
2875 | Print a summary identifying the repository state at REV using one or | |
2876 | two parent hash identifiers, followed by a "+" if the working |
|
2876 | two parent hash identifiers, followed by a "+" if the working | |
2877 | directory has uncommitted changes, the branch name (if not default), |
|
2877 | directory has uncommitted changes, the branch name (if not default), | |
2878 | a list of tags, and a list of bookmarks. |
|
2878 | a list of tags, and a list of bookmarks. | |
2879 |
|
2879 | |||
2880 | When REV is not given, print a summary of the current state of the |
|
2880 | When REV is not given, print a summary of the current state of the | |
2881 | repository. |
|
2881 | repository. | |
2882 |
|
2882 | |||
2883 | Specifying a path to a repository root or Mercurial bundle will |
|
2883 | Specifying a path to a repository root or Mercurial bundle will | |
2884 | cause lookup to operate on that repository/bundle. |
|
2884 | cause lookup to operate on that repository/bundle. | |
2885 |
|
2885 | |||
2886 | Returns 0 if successful. |
|
2886 | Returns 0 if successful. | |
2887 | """ |
|
2887 | """ | |
2888 |
|
2888 | |||
2889 | if not repo and not source: |
|
2889 | if not repo and not source: | |
2890 | raise util.Abort(_("there is no Mercurial repository here " |
|
2890 | raise util.Abort(_("there is no Mercurial repository here " | |
2891 | "(.hg not found)")) |
|
2891 | "(.hg not found)")) | |
2892 |
|
2892 | |||
2893 | hexfunc = ui.debugflag and hex or short |
|
2893 | hexfunc = ui.debugflag and hex or short | |
2894 | default = not (num or id or branch or tags or bookmarks) |
|
2894 | default = not (num or id or branch or tags or bookmarks) | |
2895 | output = [] |
|
2895 | output = [] | |
2896 | revs = [] |
|
2896 | revs = [] | |
2897 |
|
2897 | |||
2898 | if source: |
|
2898 | if source: | |
2899 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
2899 | source, branches = hg.parseurl(ui.expandpath(source)) | |
2900 | repo = hg.repository(ui, source) |
|
2900 | repo = hg.repository(ui, source) | |
2901 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
2901 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | |
2902 |
|
2902 | |||
2903 | if not repo.local(): |
|
2903 | if not repo.local(): | |
2904 | if num or branch or tags: |
|
2904 | if num or branch or tags: | |
2905 | raise util.Abort( |
|
2905 | raise util.Abort( | |
2906 | _("can't query remote revision number, branch, or tags")) |
|
2906 | _("can't query remote revision number, branch, or tags")) | |
2907 | if not rev and revs: |
|
2907 | if not rev and revs: | |
2908 | rev = revs[0] |
|
2908 | rev = revs[0] | |
2909 | if not rev: |
|
2909 | if not rev: | |
2910 | rev = "tip" |
|
2910 | rev = "tip" | |
2911 |
|
2911 | |||
2912 | remoterev = repo.lookup(rev) |
|
2912 | remoterev = repo.lookup(rev) | |
2913 | if default or id: |
|
2913 | if default or id: | |
2914 | output = [hexfunc(remoterev)] |
|
2914 | output = [hexfunc(remoterev)] | |
2915 |
|
2915 | |||
2916 | def getbms(): |
|
2916 | def getbms(): | |
2917 | bms = [] |
|
2917 | bms = [] | |
2918 |
|
2918 | |||
2919 | if 'bookmarks' in repo.listkeys('namespaces'): |
|
2919 | if 'bookmarks' in repo.listkeys('namespaces'): | |
2920 | hexremoterev = hex(remoterev) |
|
2920 | hexremoterev = hex(remoterev) | |
2921 | bms = [bm for bm, bmr in repo.listkeys('bookmarks').iteritems() |
|
2921 | bms = [bm for bm, bmr in repo.listkeys('bookmarks').iteritems() | |
2922 | if bmr == hexremoterev] |
|
2922 | if bmr == hexremoterev] | |
2923 |
|
2923 | |||
2924 | return bms |
|
2924 | return bms | |
2925 |
|
2925 | |||
2926 | if bookmarks: |
|
2926 | if bookmarks: | |
2927 | output.extend(getbms()) |
|
2927 | output.extend(getbms()) | |
2928 | elif default and not ui.quiet: |
|
2928 | elif default and not ui.quiet: | |
2929 | # multiple bookmarks for a single parent separated by '/' |
|
2929 | # multiple bookmarks for a single parent separated by '/' | |
2930 | bm = '/'.join(getbms()) |
|
2930 | bm = '/'.join(getbms()) | |
2931 | if bm: |
|
2931 | if bm: | |
2932 | output.append(bm) |
|
2932 | output.append(bm) | |
2933 | else: |
|
2933 | else: | |
2934 | if not rev: |
|
2934 | if not rev: | |
2935 | ctx = repo[None] |
|
2935 | ctx = repo[None] | |
2936 | parents = ctx.parents() |
|
2936 | parents = ctx.parents() | |
2937 | changed = "" |
|
2937 | changed = "" | |
2938 | if default or id or num: |
|
2938 | if default or id or num: | |
2939 | changed = util.any(repo.status()) and "+" or "" |
|
2939 | changed = util.any(repo.status()) and "+" or "" | |
2940 | if default or id: |
|
2940 | if default or id: | |
2941 | output = ["%s%s" % |
|
2941 | output = ["%s%s" % | |
2942 | ('+'.join([hexfunc(p.node()) for p in parents]), changed)] |
|
2942 | ('+'.join([hexfunc(p.node()) for p in parents]), changed)] | |
2943 | if num: |
|
2943 | if num: | |
2944 | output.append("%s%s" % |
|
2944 | output.append("%s%s" % | |
2945 | ('+'.join([str(p.rev()) for p in parents]), changed)) |
|
2945 | ('+'.join([str(p.rev()) for p in parents]), changed)) | |
2946 | else: |
|
2946 | else: | |
2947 | ctx = scmutil.revsingle(repo, rev) |
|
2947 | ctx = scmutil.revsingle(repo, rev) | |
2948 | if default or id: |
|
2948 | if default or id: | |
2949 | output = [hexfunc(ctx.node())] |
|
2949 | output = [hexfunc(ctx.node())] | |
2950 | if num: |
|
2950 | if num: | |
2951 | output.append(str(ctx.rev())) |
|
2951 | output.append(str(ctx.rev())) | |
2952 |
|
2952 | |||
2953 | if default and not ui.quiet: |
|
2953 | if default and not ui.quiet: | |
2954 | b = ctx.branch() |
|
2954 | b = ctx.branch() | |
2955 | if b != 'default': |
|
2955 | if b != 'default': | |
2956 | output.append("(%s)" % b) |
|
2956 | output.append("(%s)" % b) | |
2957 |
|
2957 | |||
2958 | # multiple tags for a single parent separated by '/' |
|
2958 | # multiple tags for a single parent separated by '/' | |
2959 | t = '/'.join(ctx.tags()) |
|
2959 | t = '/'.join(ctx.tags()) | |
2960 | if t: |
|
2960 | if t: | |
2961 | output.append(t) |
|
2961 | output.append(t) | |
2962 |
|
2962 | |||
2963 | # multiple bookmarks for a single parent separated by '/' |
|
2963 | # multiple bookmarks for a single parent separated by '/' | |
2964 | bm = '/'.join(ctx.bookmarks()) |
|
2964 | bm = '/'.join(ctx.bookmarks()) | |
2965 | if bm: |
|
2965 | if bm: | |
2966 | output.append(bm) |
|
2966 | output.append(bm) | |
2967 | else: |
|
2967 | else: | |
2968 | if branch: |
|
2968 | if branch: | |
2969 | output.append(ctx.branch()) |
|
2969 | output.append(ctx.branch()) | |
2970 |
|
2970 | |||
2971 | if tags: |
|
2971 | if tags: | |
2972 | output.extend(ctx.tags()) |
|
2972 | output.extend(ctx.tags()) | |
2973 |
|
2973 | |||
2974 | if bookmarks: |
|
2974 | if bookmarks: | |
2975 | output.extend(ctx.bookmarks()) |
|
2975 | output.extend(ctx.bookmarks()) | |
2976 |
|
2976 | |||
2977 | ui.write("%s\n" % ' '.join(output)) |
|
2977 | ui.write("%s\n" % ' '.join(output)) | |
2978 |
|
2978 | |||
2979 | @command('import|patch', |
|
2979 | @command('import|patch', | |
2980 | [('p', 'strip', 1, |
|
2980 | [('p', 'strip', 1, | |
2981 | _('directory strip option for patch. This has the same ' |
|
2981 | _('directory strip option for patch. This has the same ' | |
2982 | 'meaning as the corresponding patch option'), _('NUM')), |
|
2982 | 'meaning as the corresponding patch option'), _('NUM')), | |
2983 | ('b', 'base', '', _('base path'), _('PATH')), |
|
2983 | ('b', 'base', '', _('base path'), _('PATH')), | |
2984 | ('f', 'force', None, _('skip check for outstanding uncommitted changes')), |
|
2984 | ('f', 'force', None, _('skip check for outstanding uncommitted changes')), | |
2985 | ('', 'no-commit', None, |
|
2985 | ('', 'no-commit', None, | |
2986 | _("don't commit, just update the working directory")), |
|
2986 | _("don't commit, just update the working directory")), | |
2987 | ('', 'exact', None, |
|
2987 | ('', 'exact', None, | |
2988 | _('apply patch to the nodes from which it was generated')), |
|
2988 | _('apply patch to the nodes from which it was generated')), | |
2989 | ('', 'import-branch', None, |
|
2989 | ('', 'import-branch', None, | |
2990 | _('use any branch information in patch (implied by --exact)'))] + |
|
2990 | _('use any branch information in patch (implied by --exact)'))] + | |
2991 | commitopts + commitopts2 + similarityopts, |
|
2991 | commitopts + commitopts2 + similarityopts, | |
2992 | _('[OPTION]... PATCH...')) |
|
2992 | _('[OPTION]... PATCH...')) | |
2993 | def import_(ui, repo, patch1, *patches, **opts): |
|
2993 | def import_(ui, repo, patch1, *patches, **opts): | |
2994 | """import an ordered set of patches |
|
2994 | """import an ordered set of patches | |
2995 |
|
2995 | |||
2996 | Import a list of patches and commit them individually (unless |
|
2996 | Import a list of patches and commit them individually (unless | |
2997 | --no-commit is specified). |
|
2997 | --no-commit is specified). | |
2998 |
|
2998 | |||
2999 | If there are outstanding changes in the working directory, import |
|
2999 | If there are outstanding changes in the working directory, import | |
3000 | will abort unless given the -f/--force flag. |
|
3000 | will abort unless given the -f/--force flag. | |
3001 |
|
3001 | |||
3002 | You can import a patch straight from a mail message. Even patches |
|
3002 | You can import a patch straight from a mail message. Even patches | |
3003 | as attachments work (to use the body part, it must have type |
|
3003 | as attachments work (to use the body part, it must have type | |
3004 | text/plain or text/x-patch). From and Subject headers of email |
|
3004 | text/plain or text/x-patch). From and Subject headers of email | |
3005 | message are used as default committer and commit message. All |
|
3005 | message are used as default committer and commit message. All | |
3006 | text/plain body parts before first diff are added to commit |
|
3006 | text/plain body parts before first diff are added to commit | |
3007 | message. |
|
3007 | message. | |
3008 |
|
3008 | |||
3009 | If the imported patch was generated by :hg:`export`, user and |
|
3009 | If the imported patch was generated by :hg:`export`, user and | |
3010 | description from patch override values from message headers and |
|
3010 | description from patch override values from message headers and | |
3011 | body. Values given on command line with -m/--message and -u/--user |
|
3011 | body. Values given on command line with -m/--message and -u/--user | |
3012 | override these. |
|
3012 | override these. | |
3013 |
|
3013 | |||
3014 | If --exact is specified, import will set the working directory to |
|
3014 | If --exact is specified, import will set the working directory to | |
3015 | the parent of each patch before applying it, and will abort if the |
|
3015 | the parent of each patch before applying it, and will abort if the | |
3016 | resulting changeset has a different ID than the one recorded in |
|
3016 | resulting changeset has a different ID than the one recorded in | |
3017 | the patch. This may happen due to character set problems or other |
|
3017 | the patch. This may happen due to character set problems or other | |
3018 | deficiencies in the text patch format. |
|
3018 | deficiencies in the text patch format. | |
3019 |
|
3019 | |||
3020 | With -s/--similarity, hg will attempt to discover renames and |
|
3020 | With -s/--similarity, hg will attempt to discover renames and | |
3021 | copies in the patch in the same way as 'addremove'. |
|
3021 | copies in the patch in the same way as 'addremove'. | |
3022 |
|
3022 | |||
3023 | To read a patch from standard input, use "-" as the patch name. If |
|
3023 | To read a patch from standard input, use "-" as the patch name. If | |
3024 | a URL is specified, the patch will be downloaded from it. |
|
3024 | a URL is specified, the patch will be downloaded from it. | |
3025 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3025 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
3026 |
|
3026 | |||
3027 | Returns 0 on success. |
|
3027 | Returns 0 on success. | |
3028 | """ |
|
3028 | """ | |
3029 | patches = (patch1,) + patches |
|
3029 | patches = (patch1,) + patches | |
3030 |
|
3030 | |||
3031 | date = opts.get('date') |
|
3031 | date = opts.get('date') | |
3032 | if date: |
|
3032 | if date: | |
3033 | opts['date'] = util.parsedate(date) |
|
3033 | opts['date'] = util.parsedate(date) | |
3034 |
|
3034 | |||
3035 | try: |
|
3035 | try: | |
3036 | sim = float(opts.get('similarity') or 0) |
|
3036 | sim = float(opts.get('similarity') or 0) | |
3037 | except ValueError: |
|
3037 | except ValueError: | |
3038 | raise util.Abort(_('similarity must be a number')) |
|
3038 | raise util.Abort(_('similarity must be a number')) | |
3039 | if sim < 0 or sim > 100: |
|
3039 | if sim < 0 or sim > 100: | |
3040 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
3040 | raise util.Abort(_('similarity must be between 0 and 100')) | |
3041 |
|
3041 | |||
3042 | if opts.get('exact') or not opts.get('force'): |
|
3042 | if opts.get('exact') or not opts.get('force'): | |
3043 | cmdutil.bailifchanged(repo) |
|
3043 | cmdutil.bailifchanged(repo) | |
3044 |
|
3044 | |||
3045 | d = opts["base"] |
|
3045 | d = opts["base"] | |
3046 | strip = opts["strip"] |
|
3046 | strip = opts["strip"] | |
3047 | wlock = lock = None |
|
3047 | wlock = lock = None | |
3048 | msgs = [] |
|
3048 | msgs = [] | |
3049 |
|
3049 | |||
3050 | def tryone(ui, hunk): |
|
3050 | def tryone(ui, hunk): | |
3051 | tmpname, message, user, date, branch, nodeid, p1, p2 = \ |
|
3051 | tmpname, message, user, date, branch, nodeid, p1, p2 = \ | |
3052 | patch.extract(ui, hunk) |
|
3052 | patch.extract(ui, hunk) | |
3053 |
|
3053 | |||
3054 | if not tmpname: |
|
3054 | if not tmpname: | |
3055 | return None |
|
3055 | return None | |
3056 | commitid = _('to working directory') |
|
3056 | commitid = _('to working directory') | |
3057 |
|
3057 | |||
3058 | try: |
|
3058 | try: | |
3059 | cmdline_message = cmdutil.logmessage(opts) |
|
3059 | cmdline_message = cmdutil.logmessage(opts) | |
3060 | if cmdline_message: |
|
3060 | if cmdline_message: | |
3061 | # pickup the cmdline msg |
|
3061 | # pickup the cmdline msg | |
3062 | message = cmdline_message |
|
3062 | message = cmdline_message | |
3063 | elif message: |
|
3063 | elif message: | |
3064 | # pickup the patch msg |
|
3064 | # pickup the patch msg | |
3065 | message = message.strip() |
|
3065 | message = message.strip() | |
3066 | else: |
|
3066 | else: | |
3067 | # launch the editor |
|
3067 | # launch the editor | |
3068 | message = None |
|
3068 | message = None | |
3069 | ui.debug('message:\n%s\n' % message) |
|
3069 | ui.debug('message:\n%s\n' % message) | |
3070 |
|
3070 | |||
3071 | wp = repo.parents() |
|
3071 | wp = repo.parents() | |
3072 | if opts.get('exact'): |
|
3072 | if opts.get('exact'): | |
3073 | if not nodeid or not p1: |
|
3073 | if not nodeid or not p1: | |
3074 | raise util.Abort(_('not a Mercurial patch')) |
|
3074 | raise util.Abort(_('not a Mercurial patch')) | |
3075 | p1 = repo.lookup(p1) |
|
3075 | p1 = repo.lookup(p1) | |
3076 | p2 = repo.lookup(p2 or hex(nullid)) |
|
3076 | p2 = repo.lookup(p2 or hex(nullid)) | |
3077 |
|
3077 | |||
3078 | if p1 != wp[0].node(): |
|
3078 | if p1 != wp[0].node(): | |
3079 | hg.clean(repo, p1) |
|
3079 | hg.clean(repo, p1) | |
3080 | repo.dirstate.setparents(p1, p2) |
|
3080 | repo.dirstate.setparents(p1, p2) | |
3081 | elif p2: |
|
3081 | elif p2: | |
3082 | try: |
|
3082 | try: | |
3083 | p1 = repo.lookup(p1) |
|
3083 | p1 = repo.lookup(p1) | |
3084 | p2 = repo.lookup(p2) |
|
3084 | p2 = repo.lookup(p2) | |
3085 | if p1 == wp[0].node(): |
|
3085 | if p1 == wp[0].node(): | |
3086 | repo.dirstate.setparents(p1, p2) |
|
3086 | repo.dirstate.setparents(p1, p2) | |
3087 | except error.RepoError: |
|
3087 | except error.RepoError: | |
3088 | pass |
|
3088 | pass | |
3089 | if opts.get('exact') or opts.get('import_branch'): |
|
3089 | if opts.get('exact') or opts.get('import_branch'): | |
3090 | repo.dirstate.setbranch(branch or 'default') |
|
3090 | repo.dirstate.setbranch(branch or 'default') | |
3091 |
|
3091 | |||
3092 | files = {} |
|
3092 | files = {} | |
3093 | patch.patch(ui, repo, tmpname, strip=strip, cwd=repo.root, |
|
3093 | patch.patch(ui, repo, tmpname, strip=strip, cwd=repo.root, | |
3094 | files=files, eolmode=None, similarity=sim / 100.0) |
|
3094 | files=files, eolmode=None, similarity=sim / 100.0) | |
3095 | files = list(files) |
|
3095 | files = list(files) | |
3096 | if opts.get('no_commit'): |
|
3096 | if opts.get('no_commit'): | |
3097 | if message: |
|
3097 | if message: | |
3098 | msgs.append(message) |
|
3098 | msgs.append(message) | |
3099 | else: |
|
3099 | else: | |
3100 | if opts.get('exact'): |
|
3100 | if opts.get('exact'): | |
3101 | m = None |
|
3101 | m = None | |
3102 | else: |
|
3102 | else: | |
3103 | m = cmdutil.matchfiles(repo, files or []) |
|
3103 | m = cmdutil.matchfiles(repo, files or []) | |
3104 | n = repo.commit(message, opts.get('user') or user, |
|
3104 | n = repo.commit(message, opts.get('user') or user, | |
3105 | opts.get('date') or date, match=m, |
|
3105 | opts.get('date') or date, match=m, | |
3106 | editor=cmdutil.commiteditor) |
|
3106 | editor=cmdutil.commiteditor) | |
3107 | if opts.get('exact'): |
|
3107 | if opts.get('exact'): | |
3108 | if hex(n) != nodeid: |
|
3108 | if hex(n) != nodeid: | |
3109 | repo.rollback() |
|
3109 | repo.rollback() | |
3110 | raise util.Abort(_('patch is damaged' |
|
3110 | raise util.Abort(_('patch is damaged' | |
3111 | ' or loses information')) |
|
3111 | ' or loses information')) | |
3112 | # Force a dirstate write so that the next transaction |
|
3112 | # Force a dirstate write so that the next transaction | |
3113 | # backups an up-do-date file. |
|
3113 | # backups an up-do-date file. | |
3114 | repo.dirstate.write() |
|
3114 | repo.dirstate.write() | |
3115 | if n: |
|
3115 | if n: | |
3116 | commitid = short(n) |
|
3116 | commitid = short(n) | |
3117 |
|
3117 | |||
3118 | return commitid |
|
3118 | return commitid | |
3119 | finally: |
|
3119 | finally: | |
3120 | os.unlink(tmpname) |
|
3120 | os.unlink(tmpname) | |
3121 |
|
3121 | |||
3122 | try: |
|
3122 | try: | |
3123 | wlock = repo.wlock() |
|
3123 | wlock = repo.wlock() | |
3124 | lock = repo.lock() |
|
3124 | lock = repo.lock() | |
3125 | lastcommit = None |
|
3125 | lastcommit = None | |
3126 | for p in patches: |
|
3126 | for p in patches: | |
3127 | pf = os.path.join(d, p) |
|
3127 | pf = os.path.join(d, p) | |
3128 |
|
3128 | |||
3129 | if pf == '-': |
|
3129 | if pf == '-': | |
3130 | ui.status(_("applying patch from stdin\n")) |
|
3130 | ui.status(_("applying patch from stdin\n")) | |
3131 | pf = sys.stdin |
|
3131 | pf = sys.stdin | |
3132 | else: |
|
3132 | else: | |
3133 | ui.status(_("applying %s\n") % p) |
|
3133 | ui.status(_("applying %s\n") % p) | |
3134 | pf = url.open(ui, pf) |
|
3134 | pf = url.open(ui, pf) | |
3135 |
|
3135 | |||
3136 | haspatch = False |
|
3136 | haspatch = False | |
3137 | for hunk in patch.split(pf): |
|
3137 | for hunk in patch.split(pf): | |
3138 | commitid = tryone(ui, hunk) |
|
3138 | commitid = tryone(ui, hunk) | |
3139 | if commitid: |
|
3139 | if commitid: | |
3140 | haspatch = True |
|
3140 | haspatch = True | |
3141 | if lastcommit: |
|
3141 | if lastcommit: | |
3142 | ui.status(_('applied %s\n') % lastcommit) |
|
3142 | ui.status(_('applied %s\n') % lastcommit) | |
3143 | lastcommit = commitid |
|
3143 | lastcommit = commitid | |
3144 |
|
3144 | |||
3145 | if not haspatch: |
|
3145 | if not haspatch: | |
3146 | raise util.Abort(_('no diffs found')) |
|
3146 | raise util.Abort(_('no diffs found')) | |
3147 |
|
3147 | |||
3148 | if msgs: |
|
3148 | if msgs: | |
3149 | repo.opener.write('last-message.txt', '\n* * *\n'.join(msgs)) |
|
3149 | repo.opener.write('last-message.txt', '\n* * *\n'.join(msgs)) | |
3150 | finally: |
|
3150 | finally: | |
3151 | release(lock, wlock) |
|
3151 | release(lock, wlock) | |
3152 |
|
3152 | |||
3153 | @command('incoming|in', |
|
3153 | @command('incoming|in', | |
3154 | [('f', 'force', None, |
|
3154 | [('f', 'force', None, | |
3155 | _('run even if remote repository is unrelated')), |
|
3155 | _('run even if remote repository is unrelated')), | |
3156 | ('n', 'newest-first', None, _('show newest record first')), |
|
3156 | ('n', 'newest-first', None, _('show newest record first')), | |
3157 | ('', 'bundle', '', |
|
3157 | ('', 'bundle', '', | |
3158 | _('file to store the bundles into'), _('FILE')), |
|
3158 | _('file to store the bundles into'), _('FILE')), | |
3159 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3159 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), | |
3160 | ('B', 'bookmarks', False, _("compare bookmarks")), |
|
3160 | ('B', 'bookmarks', False, _("compare bookmarks")), | |
3161 | ('b', 'branch', [], |
|
3161 | ('b', 'branch', [], | |
3162 | _('a specific branch you would like to pull'), _('BRANCH')), |
|
3162 | _('a specific branch you would like to pull'), _('BRANCH')), | |
3163 | ] + logopts + remoteopts + subrepoopts, |
|
3163 | ] + logopts + remoteopts + subrepoopts, | |
3164 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) |
|
3164 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) | |
3165 | def incoming(ui, repo, source="default", **opts): |
|
3165 | def incoming(ui, repo, source="default", **opts): | |
3166 | """show new changesets found in source |
|
3166 | """show new changesets found in source | |
3167 |
|
3167 | |||
3168 | Show new changesets found in the specified path/URL or the default |
|
3168 | Show new changesets found in the specified path/URL or the default | |
3169 | pull location. These are the changesets that would have been pulled |
|
3169 | pull location. These are the changesets that would have been pulled | |
3170 | if a pull at the time you issued this command. |
|
3170 | if a pull at the time you issued this command. | |
3171 |
|
3171 | |||
3172 | For remote repository, using --bundle avoids downloading the |
|
3172 | For remote repository, using --bundle avoids downloading the | |
3173 | changesets twice if the incoming is followed by a pull. |
|
3173 | changesets twice if the incoming is followed by a pull. | |
3174 |
|
3174 | |||
3175 | See pull for valid source format details. |
|
3175 | See pull for valid source format details. | |
3176 |
|
3176 | |||
3177 | Returns 0 if there are incoming changes, 1 otherwise. |
|
3177 | Returns 0 if there are incoming changes, 1 otherwise. | |
3178 | """ |
|
3178 | """ | |
3179 | if opts.get('bundle') and opts.get('subrepos'): |
|
3179 | if opts.get('bundle') and opts.get('subrepos'): | |
3180 | raise util.Abort(_('cannot combine --bundle and --subrepos')) |
|
3180 | raise util.Abort(_('cannot combine --bundle and --subrepos')) | |
3181 |
|
3181 | |||
3182 | if opts.get('bookmarks'): |
|
3182 | if opts.get('bookmarks'): | |
3183 | source, branches = hg.parseurl(ui.expandpath(source), |
|
3183 | source, branches = hg.parseurl(ui.expandpath(source), | |
3184 | opts.get('branch')) |
|
3184 | opts.get('branch')) | |
3185 | other = hg.repository(hg.remoteui(repo, opts), source) |
|
3185 | other = hg.repository(hg.remoteui(repo, opts), source) | |
3186 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3186 | if 'bookmarks' not in other.listkeys('namespaces'): | |
3187 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3187 | ui.warn(_("remote doesn't support bookmarks\n")) | |
3188 | return 0 |
|
3188 | return 0 | |
3189 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
3189 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) | |
3190 | return bookmarks.diff(ui, repo, other) |
|
3190 | return bookmarks.diff(ui, repo, other) | |
3191 |
|
3191 | |||
3192 | ret = hg.incoming(ui, repo, source, opts) |
|
3192 | ret = hg.incoming(ui, repo, source, opts) | |
3193 | return ret |
|
3193 | return ret | |
3194 |
|
3194 | |||
3195 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]')) |
|
3195 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]')) | |
3196 | def init(ui, dest=".", **opts): |
|
3196 | def init(ui, dest=".", **opts): | |
3197 | """create a new repository in the given directory |
|
3197 | """create a new repository in the given directory | |
3198 |
|
3198 | |||
3199 | Initialize a new repository in the given directory. If the given |
|
3199 | Initialize a new repository in the given directory. If the given | |
3200 | directory does not exist, it will be created. |
|
3200 | directory does not exist, it will be created. | |
3201 |
|
3201 | |||
3202 | If no directory is given, the current directory is used. |
|
3202 | If no directory is given, the current directory is used. | |
3203 |
|
3203 | |||
3204 | It is possible to specify an ``ssh://`` URL as the destination. |
|
3204 | It is possible to specify an ``ssh://`` URL as the destination. | |
3205 | See :hg:`help urls` for more information. |
|
3205 | See :hg:`help urls` for more information. | |
3206 |
|
3206 | |||
3207 | Returns 0 on success. |
|
3207 | Returns 0 on success. | |
3208 | """ |
|
3208 | """ | |
3209 | hg.repository(hg.remoteui(ui, opts), ui.expandpath(dest), create=1) |
|
3209 | hg.repository(hg.remoteui(ui, opts), ui.expandpath(dest), create=1) | |
3210 |
|
3210 | |||
3211 | @command('locate', |
|
3211 | @command('locate', | |
3212 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
3212 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), | |
3213 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
3213 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | |
3214 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), |
|
3214 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), | |
3215 | ] + walkopts, |
|
3215 | ] + walkopts, | |
3216 | _('[OPTION]... [PATTERN]...')) |
|
3216 | _('[OPTION]... [PATTERN]...')) | |
3217 | def locate(ui, repo, *pats, **opts): |
|
3217 | def locate(ui, repo, *pats, **opts): | |
3218 | """locate files matching specific patterns |
|
3218 | """locate files matching specific patterns | |
3219 |
|
3219 | |||
3220 | Print files under Mercurial control in the working directory whose |
|
3220 | Print files under Mercurial control in the working directory whose | |
3221 | names match the given patterns. |
|
3221 | names match the given patterns. | |
3222 |
|
3222 | |||
3223 | By default, this command searches all directories in the working |
|
3223 | By default, this command searches all directories in the working | |
3224 | directory. To search just the current directory and its |
|
3224 | directory. To search just the current directory and its | |
3225 | subdirectories, use "--include .". |
|
3225 | subdirectories, use "--include .". | |
3226 |
|
3226 | |||
3227 | If no patterns are given to match, this command prints the names |
|
3227 | If no patterns are given to match, this command prints the names | |
3228 | of all files under Mercurial control in the working directory. |
|
3228 | of all files under Mercurial control in the working directory. | |
3229 |
|
3229 | |||
3230 | If you want to feed the output of this command into the "xargs" |
|
3230 | If you want to feed the output of this command into the "xargs" | |
3231 | command, use the -0 option to both this command and "xargs". This |
|
3231 | command, use the -0 option to both this command and "xargs". This | |
3232 | will avoid the problem of "xargs" treating single filenames that |
|
3232 | will avoid the problem of "xargs" treating single filenames that | |
3233 | contain whitespace as multiple filenames. |
|
3233 | contain whitespace as multiple filenames. | |
3234 |
|
3234 | |||
3235 | Returns 0 if a match is found, 1 otherwise. |
|
3235 | Returns 0 if a match is found, 1 otherwise. | |
3236 | """ |
|
3236 | """ | |
3237 | end = opts.get('print0') and '\0' or '\n' |
|
3237 | end = opts.get('print0') and '\0' or '\n' | |
3238 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() |
|
3238 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() | |
3239 |
|
3239 | |||
3240 | ret = 1 |
|
3240 | ret = 1 | |
3241 | m = cmdutil.match(repo, pats, opts, default='relglob') |
|
3241 | m = cmdutil.match(repo, pats, opts, default='relglob') | |
3242 | m.bad = lambda x, y: False |
|
3242 | m.bad = lambda x, y: False | |
3243 | for abs in repo[rev].walk(m): |
|
3243 | for abs in repo[rev].walk(m): | |
3244 | if not rev and abs not in repo.dirstate: |
|
3244 | if not rev and abs not in repo.dirstate: | |
3245 | continue |
|
3245 | continue | |
3246 | if opts.get('fullpath'): |
|
3246 | if opts.get('fullpath'): | |
3247 | ui.write(repo.wjoin(abs), end) |
|
3247 | ui.write(repo.wjoin(abs), end) | |
3248 | else: |
|
3248 | else: | |
3249 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
3249 | ui.write(((pats and m.rel(abs)) or abs), end) | |
3250 | ret = 0 |
|
3250 | ret = 0 | |
3251 |
|
3251 | |||
3252 | return ret |
|
3252 | return ret | |
3253 |
|
3253 | |||
3254 | @command('^log|history', |
|
3254 | @command('^log|history', | |
3255 | [('f', 'follow', None, |
|
3255 | [('f', 'follow', None, | |
3256 | _('follow changeset history, or file history across copies and renames')), |
|
3256 | _('follow changeset history, or file history across copies and renames')), | |
3257 | ('', 'follow-first', None, |
|
3257 | ('', 'follow-first', None, | |
3258 | _('only follow the first parent of merge changesets')), |
|
3258 | _('only follow the first parent of merge changesets')), | |
3259 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), |
|
3259 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), | |
3260 | ('C', 'copies', None, _('show copied files')), |
|
3260 | ('C', 'copies', None, _('show copied files')), | |
3261 | ('k', 'keyword', [], |
|
3261 | ('k', 'keyword', [], | |
3262 | _('do case-insensitive search for a given text'), _('TEXT')), |
|
3262 | _('do case-insensitive search for a given text'), _('TEXT')), | |
3263 | ('r', 'rev', [], _('show the specified revision or range'), _('REV')), |
|
3263 | ('r', 'rev', [], _('show the specified revision or range'), _('REV')), | |
3264 | ('', 'removed', None, _('include revisions where files were removed')), |
|
3264 | ('', 'removed', None, _('include revisions where files were removed')), | |
3265 | ('m', 'only-merges', None, _('show only merges')), |
|
3265 | ('m', 'only-merges', None, _('show only merges')), | |
3266 | ('u', 'user', [], _('revisions committed by user'), _('USER')), |
|
3266 | ('u', 'user', [], _('revisions committed by user'), _('USER')), | |
3267 | ('', 'only-branch', [], |
|
3267 | ('', 'only-branch', [], | |
3268 | _('show only changesets within the given named branch (DEPRECATED)'), |
|
3268 | _('show only changesets within the given named branch (DEPRECATED)'), | |
3269 | _('BRANCH')), |
|
3269 | _('BRANCH')), | |
3270 | ('b', 'branch', [], |
|
3270 | ('b', 'branch', [], | |
3271 | _('show changesets within the given named branch'), _('BRANCH')), |
|
3271 | _('show changesets within the given named branch'), _('BRANCH')), | |
3272 | ('P', 'prune', [], |
|
3272 | ('P', 'prune', [], | |
3273 | _('do not display revision or any of its ancestors'), _('REV')), |
|
3273 | _('do not display revision or any of its ancestors'), _('REV')), | |
3274 | ] + logopts + walkopts, |
|
3274 | ] + logopts + walkopts, | |
3275 | _('[OPTION]... [FILE]')) |
|
3275 | _('[OPTION]... [FILE]')) | |
3276 | def log(ui, repo, *pats, **opts): |
|
3276 | def log(ui, repo, *pats, **opts): | |
3277 | """show revision history of entire repository or files |
|
3277 | """show revision history of entire repository or files | |
3278 |
|
3278 | |||
3279 | Print the revision history of the specified files or the entire |
|
3279 | Print the revision history of the specified files or the entire | |
3280 | project. |
|
3280 | project. | |
3281 |
|
3281 | |||
3282 | File history is shown without following rename or copy history of |
|
3282 | File history is shown without following rename or copy history of | |
3283 | files. Use -f/--follow with a filename to follow history across |
|
3283 | files. Use -f/--follow with a filename to follow history across | |
3284 | renames and copies. --follow without a filename will only show |
|
3284 | renames and copies. --follow without a filename will only show | |
3285 | ancestors or descendants of the starting revision. --follow-first |
|
3285 | ancestors or descendants of the starting revision. --follow-first | |
3286 | only follows the first parent of merge revisions. |
|
3286 | only follows the first parent of merge revisions. | |
3287 |
|
3287 | |||
3288 | If no revision range is specified, the default is ``tip:0`` unless |
|
3288 | If no revision range is specified, the default is ``tip:0`` unless | |
3289 | --follow is set, in which case the working directory parent is |
|
3289 | --follow is set, in which case the working directory parent is | |
3290 | used as the starting revision. You can specify a revision set for |
|
3290 | used as the starting revision. You can specify a revision set for | |
3291 | log, see :hg:`help revsets` for more information. |
|
3291 | log, see :hg:`help revsets` for more information. | |
3292 |
|
3292 | |||
3293 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3293 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
3294 |
|
3294 | |||
3295 | By default this command prints revision number and changeset id, |
|
3295 | By default this command prints revision number and changeset id, | |
3296 | tags, non-trivial parents, user, date and time, and a summary for |
|
3296 | tags, non-trivial parents, user, date and time, and a summary for | |
3297 | each commit. When the -v/--verbose switch is used, the list of |
|
3297 | each commit. When the -v/--verbose switch is used, the list of | |
3298 | changed files and full commit message are shown. |
|
3298 | changed files and full commit message are shown. | |
3299 |
|
3299 | |||
3300 | .. note:: |
|
3300 | .. note:: | |
3301 | log -p/--patch may generate unexpected diff output for merge |
|
3301 | log -p/--patch may generate unexpected diff output for merge | |
3302 | changesets, as it will only compare the merge changeset against |
|
3302 | changesets, as it will only compare the merge changeset against | |
3303 | its first parent. Also, only files different from BOTH parents |
|
3303 | its first parent. Also, only files different from BOTH parents | |
3304 | will appear in files:. |
|
3304 | will appear in files:. | |
3305 |
|
3305 | |||
3306 | Returns 0 on success. |
|
3306 | Returns 0 on success. | |
3307 | """ |
|
3307 | """ | |
3308 |
|
3308 | |||
3309 | matchfn = cmdutil.match(repo, pats, opts) |
|
3309 | matchfn = cmdutil.match(repo, pats, opts) | |
3310 | limit = cmdutil.loglimit(opts) |
|
3310 | limit = cmdutil.loglimit(opts) | |
3311 | count = 0 |
|
3311 | count = 0 | |
3312 |
|
3312 | |||
3313 | endrev = None |
|
3313 | endrev = None | |
3314 | if opts.get('copies') and opts.get('rev'): |
|
3314 | if opts.get('copies') and opts.get('rev'): | |
3315 | endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1 |
|
3315 | endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1 | |
3316 |
|
3316 | |||
3317 | df = False |
|
3317 | df = False | |
3318 | if opts["date"]: |
|
3318 | if opts["date"]: | |
3319 | df = util.matchdate(opts["date"]) |
|
3319 | df = util.matchdate(opts["date"]) | |
3320 |
|
3320 | |||
3321 | branches = opts.get('branch', []) + opts.get('only_branch', []) |
|
3321 | branches = opts.get('branch', []) + opts.get('only_branch', []) | |
3322 | opts['branch'] = [repo.lookupbranch(b) for b in branches] |
|
3322 | opts['branch'] = [repo.lookupbranch(b) for b in branches] | |
3323 |
|
3323 | |||
3324 | displayer = cmdutil.show_changeset(ui, repo, opts, True) |
|
3324 | displayer = cmdutil.show_changeset(ui, repo, opts, True) | |
3325 | def prep(ctx, fns): |
|
3325 | def prep(ctx, fns): | |
3326 | rev = ctx.rev() |
|
3326 | rev = ctx.rev() | |
3327 | parents = [p for p in repo.changelog.parentrevs(rev) |
|
3327 | parents = [p for p in repo.changelog.parentrevs(rev) | |
3328 | if p != nullrev] |
|
3328 | if p != nullrev] | |
3329 | if opts.get('no_merges') and len(parents) == 2: |
|
3329 | if opts.get('no_merges') and len(parents) == 2: | |
3330 | return |
|
3330 | return | |
3331 | if opts.get('only_merges') and len(parents) != 2: |
|
3331 | if opts.get('only_merges') and len(parents) != 2: | |
3332 | return |
|
3332 | return | |
3333 | if opts.get('branch') and ctx.branch() not in opts['branch']: |
|
3333 | if opts.get('branch') and ctx.branch() not in opts['branch']: | |
3334 | return |
|
3334 | return | |
3335 | if df and not df(ctx.date()[0]): |
|
3335 | if df and not df(ctx.date()[0]): | |
3336 | return |
|
3336 | return | |
3337 | if opts['user'] and not [k for k in opts['user'] |
|
3337 | if opts['user'] and not [k for k in opts['user'] | |
3338 | if k.lower() in ctx.user().lower()]: |
|
3338 | if k.lower() in ctx.user().lower()]: | |
3339 | return |
|
3339 | return | |
3340 | if opts.get('keyword'): |
|
3340 | if opts.get('keyword'): | |
3341 | for k in [kw.lower() for kw in opts['keyword']]: |
|
3341 | for k in [kw.lower() for kw in opts['keyword']]: | |
3342 | if (k in ctx.user().lower() or |
|
3342 | if (k in ctx.user().lower() or | |
3343 | k in ctx.description().lower() or |
|
3343 | k in ctx.description().lower() or | |
3344 | k in " ".join(ctx.files()).lower()): |
|
3344 | k in " ".join(ctx.files()).lower()): | |
3345 | break |
|
3345 | break | |
3346 | else: |
|
3346 | else: | |
3347 | return |
|
3347 | return | |
3348 |
|
3348 | |||
3349 | copies = None |
|
3349 | copies = None | |
3350 | if opts.get('copies') and rev: |
|
3350 | if opts.get('copies') and rev: | |
3351 | copies = [] |
|
3351 | copies = [] | |
3352 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
3352 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) | |
3353 | for fn in ctx.files(): |
|
3353 | for fn in ctx.files(): | |
3354 | rename = getrenamed(fn, rev) |
|
3354 | rename = getrenamed(fn, rev) | |
3355 | if rename: |
|
3355 | if rename: | |
3356 | copies.append((fn, rename[0])) |
|
3356 | copies.append((fn, rename[0])) | |
3357 |
|
3357 | |||
3358 | revmatchfn = None |
|
3358 | revmatchfn = None | |
3359 | if opts.get('patch') or opts.get('stat'): |
|
3359 | if opts.get('patch') or opts.get('stat'): | |
3360 | if opts.get('follow') or opts.get('follow_first'): |
|
3360 | if opts.get('follow') or opts.get('follow_first'): | |
3361 | # note: this might be wrong when following through merges |
|
3361 | # note: this might be wrong when following through merges | |
3362 | revmatchfn = cmdutil.match(repo, fns, default='path') |
|
3362 | revmatchfn = cmdutil.match(repo, fns, default='path') | |
3363 | else: |
|
3363 | else: | |
3364 | revmatchfn = matchfn |
|
3364 | revmatchfn = matchfn | |
3365 |
|
3365 | |||
3366 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
3366 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) | |
3367 |
|
3367 | |||
3368 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
3368 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): | |
3369 | if count == limit: |
|
3369 | if count == limit: | |
3370 | break |
|
3370 | break | |
3371 | if displayer.flush(ctx.rev()): |
|
3371 | if displayer.flush(ctx.rev()): | |
3372 | count += 1 |
|
3372 | count += 1 | |
3373 | displayer.close() |
|
3373 | displayer.close() | |
3374 |
|
3374 | |||
3375 | @command('manifest', |
|
3375 | @command('manifest', | |
3376 | [('r', 'rev', '', _('revision to display'), _('REV'))], |
|
3376 | [('r', 'rev', '', _('revision to display'), _('REV'))], | |
3377 | _('[-r REV]')) |
|
3377 | _('[-r REV]')) | |
3378 | def manifest(ui, repo, node=None, rev=None): |
|
3378 | def manifest(ui, repo, node=None, rev=None): | |
3379 | """output the current or given revision of the project manifest |
|
3379 | """output the current or given revision of the project manifest | |
3380 |
|
3380 | |||
3381 | Print a list of version controlled files for the given revision. |
|
3381 | Print a list of version controlled files for the given revision. | |
3382 | If no revision is given, the first parent of the working directory |
|
3382 | If no revision is given, the first parent of the working directory | |
3383 | is used, or the null revision if no revision is checked out. |
|
3383 | is used, or the null revision if no revision is checked out. | |
3384 |
|
3384 | |||
3385 | With -v, print file permissions, symlink and executable bits. |
|
3385 | With -v, print file permissions, symlink and executable bits. | |
3386 | With --debug, print file revision hashes. |
|
3386 | With --debug, print file revision hashes. | |
3387 |
|
3387 | |||
3388 | Returns 0 on success. |
|
3388 | Returns 0 on success. | |
3389 | """ |
|
3389 | """ | |
3390 |
|
3390 | |||
3391 | if rev and node: |
|
3391 | if rev and node: | |
3392 | raise util.Abort(_("please specify just one revision")) |
|
3392 | raise util.Abort(_("please specify just one revision")) | |
3393 |
|
3393 | |||
3394 | if not node: |
|
3394 | if not node: | |
3395 | node = rev |
|
3395 | node = rev | |
3396 |
|
3396 | |||
3397 | decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} |
|
3397 | decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} | |
3398 | ctx = scmutil.revsingle(repo, node) |
|
3398 | ctx = scmutil.revsingle(repo, node) | |
3399 | for f in ctx: |
|
3399 | for f in ctx: | |
3400 | if ui.debugflag: |
|
3400 | if ui.debugflag: | |
3401 | ui.write("%40s " % hex(ctx.manifest()[f])) |
|
3401 | ui.write("%40s " % hex(ctx.manifest()[f])) | |
3402 | if ui.verbose: |
|
3402 | if ui.verbose: | |
3403 | ui.write(decor[ctx.flags(f)]) |
|
3403 | ui.write(decor[ctx.flags(f)]) | |
3404 | ui.write("%s\n" % f) |
|
3404 | ui.write("%s\n" % f) | |
3405 |
|
3405 | |||
3406 | @command('^merge', |
|
3406 | @command('^merge', | |
3407 | [('f', 'force', None, _('force a merge with outstanding changes')), |
|
3407 | [('f', 'force', None, _('force a merge with outstanding changes')), | |
3408 | ('t', 'tool', '', _('specify merge tool')), |
|
3408 | ('t', 'tool', '', _('specify merge tool')), | |
3409 | ('r', 'rev', '', _('revision to merge'), _('REV')), |
|
3409 | ('r', 'rev', '', _('revision to merge'), _('REV')), | |
3410 | ('P', 'preview', None, |
|
3410 | ('P', 'preview', None, | |
3411 | _('review revisions to merge (no merge is performed)'))], |
|
3411 | _('review revisions to merge (no merge is performed)'))], | |
3412 | _('[-P] [-f] [[-r] REV]')) |
|
3412 | _('[-P] [-f] [[-r] REV]')) | |
3413 | def merge(ui, repo, node=None, **opts): |
|
3413 | def merge(ui, repo, node=None, **opts): | |
3414 | """merge working directory with another revision |
|
3414 | """merge working directory with another revision | |
3415 |
|
3415 | |||
3416 | The current working directory is updated with all changes made in |
|
3416 | The current working directory is updated with all changes made in | |
3417 | the requested revision since the last common predecessor revision. |
|
3417 | the requested revision since the last common predecessor revision. | |
3418 |
|
3418 | |||
3419 | Files that changed between either parent are marked as changed for |
|
3419 | Files that changed between either parent are marked as changed for | |
3420 | the next commit and a commit must be performed before any further |
|
3420 | the next commit and a commit must be performed before any further | |
3421 | updates to the repository are allowed. The next commit will have |
|
3421 | updates to the repository are allowed. The next commit will have | |
3422 | two parents. |
|
3422 | two parents. | |
3423 |
|
3423 | |||
3424 | ``--tool`` can be used to specify the merge tool used for file |
|
3424 | ``--tool`` can be used to specify the merge tool used for file | |
3425 | merges. It overrides the HGMERGE environment variable and your |
|
3425 | merges. It overrides the HGMERGE environment variable and your | |
3426 | configuration files. See :hg:`help merge-tools` for options. |
|
3426 | configuration files. See :hg:`help merge-tools` for options. | |
3427 |
|
3427 | |||
3428 | If no revision is specified, the working directory's parent is a |
|
3428 | If no revision is specified, the working directory's parent is a | |
3429 | head revision, and the current branch contains exactly one other |
|
3429 | head revision, and the current branch contains exactly one other | |
3430 | head, the other head is merged with by default. Otherwise, an |
|
3430 | head, the other head is merged with by default. Otherwise, an | |
3431 | explicit revision with which to merge with must be provided. |
|
3431 | explicit revision with which to merge with must be provided. | |
3432 |
|
3432 | |||
3433 | :hg:`resolve` must be used to resolve unresolved files. |
|
3433 | :hg:`resolve` must be used to resolve unresolved files. | |
3434 |
|
3434 | |||
3435 | To undo an uncommitted merge, use :hg:`update --clean .` which |
|
3435 | To undo an uncommitted merge, use :hg:`update --clean .` which | |
3436 | will check out a clean copy of the original merge parent, losing |
|
3436 | will check out a clean copy of the original merge parent, losing | |
3437 | all changes. |
|
3437 | all changes. | |
3438 |
|
3438 | |||
3439 | Returns 0 on success, 1 if there are unresolved files. |
|
3439 | Returns 0 on success, 1 if there are unresolved files. | |
3440 | """ |
|
3440 | """ | |
3441 |
|
3441 | |||
3442 | if opts.get('rev') and node: |
|
3442 | if opts.get('rev') and node: | |
3443 | raise util.Abort(_("please specify just one revision")) |
|
3443 | raise util.Abort(_("please specify just one revision")) | |
3444 | if not node: |
|
3444 | if not node: | |
3445 | node = opts.get('rev') |
|
3445 | node = opts.get('rev') | |
3446 |
|
3446 | |||
3447 | if not node: |
|
3447 | if not node: | |
3448 | branch = repo[None].branch() |
|
3448 | branch = repo[None].branch() | |
3449 | bheads = repo.branchheads(branch) |
|
3449 | bheads = repo.branchheads(branch) | |
3450 | if len(bheads) > 2: |
|
3450 | if len(bheads) > 2: | |
3451 | raise util.Abort(_("branch '%s' has %d heads - " |
|
3451 | raise util.Abort(_("branch '%s' has %d heads - " | |
3452 | "please merge with an explicit rev") |
|
3452 | "please merge with an explicit rev") | |
3453 | % (branch, len(bheads)), |
|
3453 | % (branch, len(bheads)), | |
3454 | hint=_("run 'hg heads .' to see heads")) |
|
3454 | hint=_("run 'hg heads .' to see heads")) | |
3455 |
|
3455 | |||
3456 | parent = repo.dirstate.p1() |
|
3456 | parent = repo.dirstate.p1() | |
3457 | if len(bheads) == 1: |
|
3457 | if len(bheads) == 1: | |
3458 | if len(repo.heads()) > 1: |
|
3458 | if len(repo.heads()) > 1: | |
3459 | raise util.Abort(_("branch '%s' has one head - " |
|
3459 | raise util.Abort(_("branch '%s' has one head - " | |
3460 | "please merge with an explicit rev") |
|
3460 | "please merge with an explicit rev") | |
3461 | % branch, |
|
3461 | % branch, | |
3462 | hint=_("run 'hg heads' to see all heads")) |
|
3462 | hint=_("run 'hg heads' to see all heads")) | |
3463 | msg = _('there is nothing to merge') |
|
3463 | msg = _('there is nothing to merge') | |
3464 | if parent != repo.lookup(repo[None].branch()): |
|
3464 | if parent != repo.lookup(repo[None].branch()): | |
3465 | msg = _('%s - use "hg update" instead') % msg |
|
3465 | msg = _('%s - use "hg update" instead') % msg | |
3466 | raise util.Abort(msg) |
|
3466 | raise util.Abort(msg) | |
3467 |
|
3467 | |||
3468 | if parent not in bheads: |
|
3468 | if parent not in bheads: | |
3469 | raise util.Abort(_('working directory not at a head revision'), |
|
3469 | raise util.Abort(_('working directory not at a head revision'), | |
3470 | hint=_("use 'hg update' or merge with an " |
|
3470 | hint=_("use 'hg update' or merge with an " | |
3471 | "explicit revision")) |
|
3471 | "explicit revision")) | |
3472 | node = parent == bheads[0] and bheads[-1] or bheads[0] |
|
3472 | node = parent == bheads[0] and bheads[-1] or bheads[0] | |
3473 | else: |
|
3473 | else: | |
3474 | node = scmutil.revsingle(repo, node).node() |
|
3474 | node = scmutil.revsingle(repo, node).node() | |
3475 |
|
3475 | |||
3476 | if opts.get('preview'): |
|
3476 | if opts.get('preview'): | |
3477 | # find nodes that are ancestors of p2 but not of p1 |
|
3477 | # find nodes that are ancestors of p2 but not of p1 | |
3478 | p1 = repo.lookup('.') |
|
3478 | p1 = repo.lookup('.') | |
3479 | p2 = repo.lookup(node) |
|
3479 | p2 = repo.lookup(node) | |
3480 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
3480 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) | |
3481 |
|
3481 | |||
3482 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
3482 | displayer = cmdutil.show_changeset(ui, repo, opts) | |
3483 | for node in nodes: |
|
3483 | for node in nodes: | |
3484 | displayer.show(repo[node]) |
|
3484 | displayer.show(repo[node]) | |
3485 | displayer.close() |
|
3485 | displayer.close() | |
3486 | return 0 |
|
3486 | return 0 | |
3487 |
|
3487 | |||
3488 | try: |
|
3488 | try: | |
3489 | # ui.forcemerge is an internal variable, do not document |
|
3489 | # ui.forcemerge is an internal variable, do not document | |
3490 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
3490 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | |
3491 | return hg.merge(repo, node, force=opts.get('force')) |
|
3491 | return hg.merge(repo, node, force=opts.get('force')) | |
3492 | finally: |
|
3492 | finally: | |
3493 | ui.setconfig('ui', 'forcemerge', '') |
|
3493 | ui.setconfig('ui', 'forcemerge', '') | |
3494 |
|
3494 | |||
3495 | @command('outgoing|out', |
|
3495 | @command('outgoing|out', | |
3496 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
3496 | [('f', 'force', None, _('run even when the destination is unrelated')), | |
3497 | ('r', 'rev', [], |
|
3497 | ('r', 'rev', [], | |
3498 | _('a changeset intended to be included in the destination'), _('REV')), |
|
3498 | _('a changeset intended to be included in the destination'), _('REV')), | |
3499 | ('n', 'newest-first', None, _('show newest record first')), |
|
3499 | ('n', 'newest-first', None, _('show newest record first')), | |
3500 | ('B', 'bookmarks', False, _('compare bookmarks')), |
|
3500 | ('B', 'bookmarks', False, _('compare bookmarks')), | |
3501 | ('b', 'branch', [], _('a specific branch you would like to push'), |
|
3501 | ('b', 'branch', [], _('a specific branch you would like to push'), | |
3502 | _('BRANCH')), |
|
3502 | _('BRANCH')), | |
3503 | ] + logopts + remoteopts + subrepoopts, |
|
3503 | ] + logopts + remoteopts + subrepoopts, | |
3504 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) |
|
3504 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) | |
3505 | def outgoing(ui, repo, dest=None, **opts): |
|
3505 | def outgoing(ui, repo, dest=None, **opts): | |
3506 | """show changesets not found in the destination |
|
3506 | """show changesets not found in the destination | |
3507 |
|
3507 | |||
3508 | Show changesets not found in the specified destination repository |
|
3508 | Show changesets not found in the specified destination repository | |
3509 | or the default push location. These are the changesets that would |
|
3509 | or the default push location. These are the changesets that would | |
3510 | be pushed if a push was requested. |
|
3510 | be pushed if a push was requested. | |
3511 |
|
3511 | |||
3512 | See pull for details of valid destination formats. |
|
3512 | See pull for details of valid destination formats. | |
3513 |
|
3513 | |||
3514 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
3514 | Returns 0 if there are outgoing changes, 1 otherwise. | |
3515 | """ |
|
3515 | """ | |
3516 |
|
3516 | |||
3517 | if opts.get('bookmarks'): |
|
3517 | if opts.get('bookmarks'): | |
3518 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
3518 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
3519 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
3519 | dest, branches = hg.parseurl(dest, opts.get('branch')) | |
3520 | other = hg.repository(hg.remoteui(repo, opts), dest) |
|
3520 | other = hg.repository(hg.remoteui(repo, opts), dest) | |
3521 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3521 | if 'bookmarks' not in other.listkeys('namespaces'): | |
3522 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3522 | ui.warn(_("remote doesn't support bookmarks\n")) | |
3523 | return 0 |
|
3523 | return 0 | |
3524 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
3524 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) | |
3525 | return bookmarks.diff(ui, other, repo) |
|
3525 | return bookmarks.diff(ui, other, repo) | |
3526 |
|
3526 | |||
3527 | ret = hg.outgoing(ui, repo, dest, opts) |
|
3527 | ret = hg.outgoing(ui, repo, dest, opts) | |
3528 | return ret |
|
3528 | return ret | |
3529 |
|
3529 | |||
3530 | @command('parents', |
|
3530 | @command('parents', | |
3531 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), |
|
3531 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), | |
3532 | ] + templateopts, |
|
3532 | ] + templateopts, | |
3533 | _('[-r REV] [FILE]')) |
|
3533 | _('[-r REV] [FILE]')) | |
3534 | def parents(ui, repo, file_=None, **opts): |
|
3534 | def parents(ui, repo, file_=None, **opts): | |
3535 | """show the parents of the working directory or revision |
|
3535 | """show the parents of the working directory or revision | |
3536 |
|
3536 | |||
3537 | Print the working directory's parent revisions. If a revision is |
|
3537 | Print the working directory's parent revisions. If a revision is | |
3538 | given via -r/--rev, the parent of that revision will be printed. |
|
3538 | given via -r/--rev, the parent of that revision will be printed. | |
3539 | If a file argument is given, the revision in which the file was |
|
3539 | If a file argument is given, the revision in which the file was | |
3540 | last changed (before the working directory revision or the |
|
3540 | last changed (before the working directory revision or the | |
3541 | argument to --rev if given) is printed. |
|
3541 | argument to --rev if given) is printed. | |
3542 |
|
3542 | |||
3543 | Returns 0 on success. |
|
3543 | Returns 0 on success. | |
3544 | """ |
|
3544 | """ | |
3545 |
|
3545 | |||
3546 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
3546 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) | |
3547 |
|
3547 | |||
3548 | if file_: |
|
3548 | if file_: | |
3549 | m = cmdutil.match(repo, (file_,), opts) |
|
3549 | m = cmdutil.match(repo, (file_,), opts) | |
3550 | if m.anypats() or len(m.files()) != 1: |
|
3550 | if m.anypats() or len(m.files()) != 1: | |
3551 | raise util.Abort(_('can only specify an explicit filename')) |
|
3551 | raise util.Abort(_('can only specify an explicit filename')) | |
3552 | file_ = m.files()[0] |
|
3552 | file_ = m.files()[0] | |
3553 | filenodes = [] |
|
3553 | filenodes = [] | |
3554 | for cp in ctx.parents(): |
|
3554 | for cp in ctx.parents(): | |
3555 | if not cp: |
|
3555 | if not cp: | |
3556 | continue |
|
3556 | continue | |
3557 | try: |
|
3557 | try: | |
3558 | filenodes.append(cp.filenode(file_)) |
|
3558 | filenodes.append(cp.filenode(file_)) | |
3559 | except error.LookupError: |
|
3559 | except error.LookupError: | |
3560 | pass |
|
3560 | pass | |
3561 | if not filenodes: |
|
3561 | if not filenodes: | |
3562 | raise util.Abort(_("'%s' not found in manifest!") % file_) |
|
3562 | raise util.Abort(_("'%s' not found in manifest!") % file_) | |
3563 | fl = repo.file(file_) |
|
3563 | fl = repo.file(file_) | |
3564 | p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes] |
|
3564 | p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes] | |
3565 | else: |
|
3565 | else: | |
3566 | p = [cp.node() for cp in ctx.parents()] |
|
3566 | p = [cp.node() for cp in ctx.parents()] | |
3567 |
|
3567 | |||
3568 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
3568 | displayer = cmdutil.show_changeset(ui, repo, opts) | |
3569 | for n in p: |
|
3569 | for n in p: | |
3570 | if n != nullid: |
|
3570 | if n != nullid: | |
3571 | displayer.show(repo[n]) |
|
3571 | displayer.show(repo[n]) | |
3572 | displayer.close() |
|
3572 | displayer.close() | |
3573 |
|
3573 | |||
3574 | @command('paths', [], _('[NAME]')) |
|
3574 | @command('paths', [], _('[NAME]')) | |
3575 | def paths(ui, repo, search=None): |
|
3575 | def paths(ui, repo, search=None): | |
3576 | """show aliases for remote repositories |
|
3576 | """show aliases for remote repositories | |
3577 |
|
3577 | |||
3578 | Show definition of symbolic path name NAME. If no name is given, |
|
3578 | Show definition of symbolic path name NAME. If no name is given, | |
3579 | show definition of all available names. |
|
3579 | show definition of all available names. | |
3580 |
|
3580 | |||
3581 | Path names are defined in the [paths] section of your |
|
3581 | Path names are defined in the [paths] section of your | |
3582 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
3582 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a | |
3583 | repository, ``.hg/hgrc`` is used, too. |
|
3583 | repository, ``.hg/hgrc`` is used, too. | |
3584 |
|
3584 | |||
3585 | The path names ``default`` and ``default-push`` have a special |
|
3585 | The path names ``default`` and ``default-push`` have a special | |
3586 | meaning. When performing a push or pull operation, they are used |
|
3586 | meaning. When performing a push or pull operation, they are used | |
3587 | as fallbacks if no location is specified on the command-line. |
|
3587 | as fallbacks if no location is specified on the command-line. | |
3588 | When ``default-push`` is set, it will be used for push and |
|
3588 | When ``default-push`` is set, it will be used for push and | |
3589 | ``default`` will be used for pull; otherwise ``default`` is used |
|
3589 | ``default`` will be used for pull; otherwise ``default`` is used | |
3590 | as the fallback for both. When cloning a repository, the clone |
|
3590 | as the fallback for both. When cloning a repository, the clone | |
3591 | source is written as ``default`` in ``.hg/hgrc``. Note that |
|
3591 | source is written as ``default`` in ``.hg/hgrc``. Note that | |
3592 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
3592 | ``default`` and ``default-push`` apply to all inbound (e.g. | |
3593 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` and |
|
3593 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` and | |
3594 | :hg:`bundle`) operations. |
|
3594 | :hg:`bundle`) operations. | |
3595 |
|
3595 | |||
3596 | See :hg:`help urls` for more information. |
|
3596 | See :hg:`help urls` for more information. | |
3597 |
|
3597 | |||
3598 | Returns 0 on success. |
|
3598 | Returns 0 on success. | |
3599 | """ |
|
3599 | """ | |
3600 | if search: |
|
3600 | if search: | |
3601 | for name, path in ui.configitems("paths"): |
|
3601 | for name, path in ui.configitems("paths"): | |
3602 | if name == search: |
|
3602 | if name == search: | |
3603 | ui.write("%s\n" % util.hidepassword(path)) |
|
3603 | ui.write("%s\n" % util.hidepassword(path)) | |
3604 | return |
|
3604 | return | |
3605 | ui.warn(_("not found!\n")) |
|
3605 | ui.warn(_("not found!\n")) | |
3606 | return 1 |
|
3606 | return 1 | |
3607 | else: |
|
3607 | else: | |
3608 | for name, path in ui.configitems("paths"): |
|
3608 | for name, path in ui.configitems("paths"): | |
3609 | ui.write("%s = %s\n" % (name, util.hidepassword(path))) |
|
3609 | ui.write("%s = %s\n" % (name, util.hidepassword(path))) | |
3610 |
|
3610 | |||
3611 | def postincoming(ui, repo, modheads, optupdate, checkout): |
|
3611 | def postincoming(ui, repo, modheads, optupdate, checkout): | |
3612 | if modheads == 0: |
|
3612 | if modheads == 0: | |
3613 | return |
|
3613 | return | |
3614 | if optupdate: |
|
3614 | if optupdate: | |
3615 | if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout: |
|
3615 | if (modheads <= 1 or len(repo.branchheads()) == 1) or checkout: | |
3616 | return hg.update(repo, checkout) |
|
3616 | return hg.update(repo, checkout) | |
3617 | else: |
|
3617 | else: | |
3618 | ui.status(_("not updating, since new heads added\n")) |
|
3618 | ui.status(_("not updating, since new heads added\n")) | |
3619 | if modheads > 1: |
|
3619 | if modheads > 1: | |
3620 | currentbranchheads = len(repo.branchheads()) |
|
3620 | currentbranchheads = len(repo.branchheads()) | |
3621 | if currentbranchheads == modheads: |
|
3621 | if currentbranchheads == modheads: | |
3622 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
3622 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | |
3623 | elif currentbranchheads > 1: |
|
3623 | elif currentbranchheads > 1: | |
3624 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to merge)\n")) |
|
3624 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to merge)\n")) | |
3625 | else: |
|
3625 | else: | |
3626 | ui.status(_("(run 'hg heads' to see heads)\n")) |
|
3626 | ui.status(_("(run 'hg heads' to see heads)\n")) | |
3627 | else: |
|
3627 | else: | |
3628 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
3628 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
3629 |
|
3629 | |||
3630 | @command('^pull', |
|
3630 | @command('^pull', | |
3631 | [('u', 'update', None, |
|
3631 | [('u', 'update', None, | |
3632 | _('update to new branch head if changesets were pulled')), |
|
3632 | _('update to new branch head if changesets were pulled')), | |
3633 | ('f', 'force', None, _('run even when remote repository is unrelated')), |
|
3633 | ('f', 'force', None, _('run even when remote repository is unrelated')), | |
3634 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3634 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), | |
3635 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), |
|
3635 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), | |
3636 | ('b', 'branch', [], _('a specific branch you would like to pull'), |
|
3636 | ('b', 'branch', [], _('a specific branch you would like to pull'), | |
3637 | _('BRANCH')), |
|
3637 | _('BRANCH')), | |
3638 | ] + remoteopts, |
|
3638 | ] + remoteopts, | |
3639 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
|
3639 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) | |
3640 | def pull(ui, repo, source="default", **opts): |
|
3640 | def pull(ui, repo, source="default", **opts): | |
3641 | """pull changes from the specified source |
|
3641 | """pull changes from the specified source | |
3642 |
|
3642 | |||
3643 | Pull changes from a remote repository to a local one. |
|
3643 | Pull changes from a remote repository to a local one. | |
3644 |
|
3644 | |||
3645 | This finds all changes from the repository at the specified path |
|
3645 | This finds all changes from the repository at the specified path | |
3646 | or URL and adds them to a local repository (the current one unless |
|
3646 | or URL and adds them to a local repository (the current one unless | |
3647 | -R is specified). By default, this does not update the copy of the |
|
3647 | -R is specified). By default, this does not update the copy of the | |
3648 | project in the working directory. |
|
3648 | project in the working directory. | |
3649 |
|
3649 | |||
3650 | Use :hg:`incoming` if you want to see what would have been added |
|
3650 | Use :hg:`incoming` if you want to see what would have been added | |
3651 | by a pull at the time you issued this command. If you then decide |
|
3651 | by a pull at the time you issued this command. If you then decide | |
3652 | to add those changes to the repository, you should use :hg:`pull |
|
3652 | to add those changes to the repository, you should use :hg:`pull | |
3653 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
3653 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. | |
3654 |
|
3654 | |||
3655 | If SOURCE is omitted, the 'default' path will be used. |
|
3655 | If SOURCE is omitted, the 'default' path will be used. | |
3656 | See :hg:`help urls` for more information. |
|
3656 | See :hg:`help urls` for more information. | |
3657 |
|
3657 | |||
3658 | Returns 0 on success, 1 if an update had unresolved files. |
|
3658 | Returns 0 on success, 1 if an update had unresolved files. | |
3659 | """ |
|
3659 | """ | |
3660 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
|
3660 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) | |
3661 | other = hg.repository(hg.remoteui(repo, opts), source) |
|
3661 | other = hg.repository(hg.remoteui(repo, opts), source) | |
3662 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) |
|
3662 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) | |
3663 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) |
|
3663 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) | |
3664 |
|
3664 | |||
3665 | if opts.get('bookmark'): |
|
3665 | if opts.get('bookmark'): | |
3666 | if not revs: |
|
3666 | if not revs: | |
3667 | revs = [] |
|
3667 | revs = [] | |
3668 | rb = other.listkeys('bookmarks') |
|
3668 | rb = other.listkeys('bookmarks') | |
3669 | for b in opts['bookmark']: |
|
3669 | for b in opts['bookmark']: | |
3670 | if b not in rb: |
|
3670 | if b not in rb: | |
3671 | raise util.Abort(_('remote bookmark %s not found!') % b) |
|
3671 | raise util.Abort(_('remote bookmark %s not found!') % b) | |
3672 | revs.append(rb[b]) |
|
3672 | revs.append(rb[b]) | |
3673 |
|
3673 | |||
3674 | if revs: |
|
3674 | if revs: | |
3675 | try: |
|
3675 | try: | |
3676 | revs = [other.lookup(rev) for rev in revs] |
|
3676 | revs = [other.lookup(rev) for rev in revs] | |
3677 | except error.CapabilityError: |
|
3677 | except error.CapabilityError: | |
3678 | err = _("other repository doesn't support revision lookup, " |
|
3678 | err = _("other repository doesn't support revision lookup, " | |
3679 | "so a rev cannot be specified.") |
|
3679 | "so a rev cannot be specified.") | |
3680 | raise util.Abort(err) |
|
3680 | raise util.Abort(err) | |
3681 |
|
3681 | |||
3682 | modheads = repo.pull(other, heads=revs, force=opts.get('force')) |
|
3682 | modheads = repo.pull(other, heads=revs, force=opts.get('force')) | |
3683 | bookmarks.updatefromremote(ui, repo, other) |
|
3683 | bookmarks.updatefromremote(ui, repo, other) | |
3684 | if checkout: |
|
3684 | if checkout: | |
3685 | checkout = str(repo.changelog.rev(other.lookup(checkout))) |
|
3685 | checkout = str(repo.changelog.rev(other.lookup(checkout))) | |
3686 | repo._subtoppath = source |
|
3686 | repo._subtoppath = source | |
3687 | try: |
|
3687 | try: | |
3688 | ret = postincoming(ui, repo, modheads, opts.get('update'), checkout) |
|
3688 | ret = postincoming(ui, repo, modheads, opts.get('update'), checkout) | |
3689 |
|
3689 | |||
3690 | finally: |
|
3690 | finally: | |
3691 | del repo._subtoppath |
|
3691 | del repo._subtoppath | |
3692 |
|
3692 | |||
3693 | # update specified bookmarks |
|
3693 | # update specified bookmarks | |
3694 | if opts.get('bookmark'): |
|
3694 | if opts.get('bookmark'): | |
3695 | for b in opts['bookmark']: |
|
3695 | for b in opts['bookmark']: | |
3696 | # explicit pull overrides local bookmark if any |
|
3696 | # explicit pull overrides local bookmark if any | |
3697 | ui.status(_("importing bookmark %s\n") % b) |
|
3697 | ui.status(_("importing bookmark %s\n") % b) | |
3698 | repo._bookmarks[b] = repo[rb[b]].node() |
|
3698 | repo._bookmarks[b] = repo[rb[b]].node() | |
3699 | bookmarks.write(repo) |
|
3699 | bookmarks.write(repo) | |
3700 |
|
3700 | |||
3701 | return ret |
|
3701 | return ret | |
3702 |
|
3702 | |||
3703 | @command('^push', |
|
3703 | @command('^push', | |
3704 | [('f', 'force', None, _('force push')), |
|
3704 | [('f', 'force', None, _('force push')), | |
3705 | ('r', 'rev', [], |
|
3705 | ('r', 'rev', [], | |
3706 | _('a changeset intended to be included in the destination'), |
|
3706 | _('a changeset intended to be included in the destination'), | |
3707 | _('REV')), |
|
3707 | _('REV')), | |
3708 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), |
|
3708 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), | |
3709 | ('b', 'branch', [], |
|
3709 | ('b', 'branch', [], | |
3710 | _('a specific branch you would like to push'), _('BRANCH')), |
|
3710 | _('a specific branch you would like to push'), _('BRANCH')), | |
3711 | ('', 'new-branch', False, _('allow pushing a new branch')), |
|
3711 | ('', 'new-branch', False, _('allow pushing a new branch')), | |
3712 | ] + remoteopts, |
|
3712 | ] + remoteopts, | |
3713 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) |
|
3713 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) | |
3714 | def push(ui, repo, dest=None, **opts): |
|
3714 | def push(ui, repo, dest=None, **opts): | |
3715 | """push changes to the specified destination |
|
3715 | """push changes to the specified destination | |
3716 |
|
3716 | |||
3717 | Push changesets from the local repository to the specified |
|
3717 | Push changesets from the local repository to the specified | |
3718 | destination. |
|
3718 | destination. | |
3719 |
|
3719 | |||
3720 | This operation is symmetrical to pull: it is identical to a pull |
|
3720 | This operation is symmetrical to pull: it is identical to a pull | |
3721 | in the destination repository from the current one. |
|
3721 | in the destination repository from the current one. | |
3722 |
|
3722 | |||
3723 | By default, push will not allow creation of new heads at the |
|
3723 | By default, push will not allow creation of new heads at the | |
3724 | destination, since multiple heads would make it unclear which head |
|
3724 | destination, since multiple heads would make it unclear which head | |
3725 | to use. In this situation, it is recommended to pull and merge |
|
3725 | to use. In this situation, it is recommended to pull and merge | |
3726 | before pushing. |
|
3726 | before pushing. | |
3727 |
|
3727 | |||
3728 | Use --new-branch if you want to allow push to create a new named |
|
3728 | Use --new-branch if you want to allow push to create a new named | |
3729 | branch that is not present at the destination. This allows you to |
|
3729 | branch that is not present at the destination. This allows you to | |
3730 | only create a new branch without forcing other changes. |
|
3730 | only create a new branch without forcing other changes. | |
3731 |
|
3731 | |||
3732 | Use -f/--force to override the default behavior and push all |
|
3732 | Use -f/--force to override the default behavior and push all | |
3733 | changesets on all branches. |
|
3733 | changesets on all branches. | |
3734 |
|
3734 | |||
3735 | If -r/--rev is used, the specified revision and all its ancestors |
|
3735 | If -r/--rev is used, the specified revision and all its ancestors | |
3736 | will be pushed to the remote repository. |
|
3736 | will be pushed to the remote repository. | |
3737 |
|
3737 | |||
3738 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
3738 | Please see :hg:`help urls` for important details about ``ssh://`` | |
3739 | URLs. If DESTINATION is omitted, a default path will be used. |
|
3739 | URLs. If DESTINATION is omitted, a default path will be used. | |
3740 |
|
3740 | |||
3741 | Returns 0 if push was successful, 1 if nothing to push. |
|
3741 | Returns 0 if push was successful, 1 if nothing to push. | |
3742 | """ |
|
3742 | """ | |
3743 |
|
3743 | |||
3744 | if opts.get('bookmark'): |
|
3744 | if opts.get('bookmark'): | |
3745 | for b in opts['bookmark']: |
|
3745 | for b in opts['bookmark']: | |
3746 | # translate -B options to -r so changesets get pushed |
|
3746 | # translate -B options to -r so changesets get pushed | |
3747 | if b in repo._bookmarks: |
|
3747 | if b in repo._bookmarks: | |
3748 | opts.setdefault('rev', []).append(b) |
|
3748 | opts.setdefault('rev', []).append(b) | |
3749 | else: |
|
3749 | else: | |
3750 | # if we try to push a deleted bookmark, translate it to null |
|
3750 | # if we try to push a deleted bookmark, translate it to null | |
3751 | # this lets simultaneous -r, -b options continue working |
|
3751 | # this lets simultaneous -r, -b options continue working | |
3752 | opts.setdefault('rev', []).append("null") |
|
3752 | opts.setdefault('rev', []).append("null") | |
3753 |
|
3753 | |||
3754 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
3754 | dest = ui.expandpath(dest or 'default-push', dest or 'default') | |
3755 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
3755 | dest, branches = hg.parseurl(dest, opts.get('branch')) | |
3756 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) |
|
3756 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) | |
3757 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
3757 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) | |
3758 | other = hg.repository(hg.remoteui(repo, opts), dest) |
|
3758 | other = hg.repository(hg.remoteui(repo, opts), dest) | |
3759 | if revs: |
|
3759 | if revs: | |
3760 | revs = [repo.lookup(rev) for rev in revs] |
|
3760 | revs = [repo.lookup(rev) for rev in revs] | |
3761 |
|
3761 | |||
3762 | repo._subtoppath = dest |
|
3762 | repo._subtoppath = dest | |
3763 | try: |
|
3763 | try: | |
3764 | # push subrepos depth-first for coherent ordering |
|
3764 | # push subrepos depth-first for coherent ordering | |
3765 | c = repo[''] |
|
3765 | c = repo[''] | |
3766 | subs = c.substate # only repos that are committed |
|
3766 | subs = c.substate # only repos that are committed | |
3767 | for s in sorted(subs): |
|
3767 | for s in sorted(subs): | |
3768 | if not c.sub(s).push(opts.get('force')): |
|
3768 | if not c.sub(s).push(opts.get('force')): | |
3769 | return False |
|
3769 | return False | |
3770 | finally: |
|
3770 | finally: | |
3771 | del repo._subtoppath |
|
3771 | del repo._subtoppath | |
3772 | result = repo.push(other, opts.get('force'), revs=revs, |
|
3772 | result = repo.push(other, opts.get('force'), revs=revs, | |
3773 | newbranch=opts.get('new_branch')) |
|
3773 | newbranch=opts.get('new_branch')) | |
3774 |
|
3774 | |||
3775 | result = (result == 0) |
|
3775 | result = (result == 0) | |
3776 |
|
3776 | |||
3777 | if opts.get('bookmark'): |
|
3777 | if opts.get('bookmark'): | |
3778 | rb = other.listkeys('bookmarks') |
|
3778 | rb = other.listkeys('bookmarks') | |
3779 | for b in opts['bookmark']: |
|
3779 | for b in opts['bookmark']: | |
3780 | # explicit push overrides remote bookmark if any |
|
3780 | # explicit push overrides remote bookmark if any | |
3781 | if b in repo._bookmarks: |
|
3781 | if b in repo._bookmarks: | |
3782 | ui.status(_("exporting bookmark %s\n") % b) |
|
3782 | ui.status(_("exporting bookmark %s\n") % b) | |
3783 | new = repo[b].hex() |
|
3783 | new = repo[b].hex() | |
3784 | elif b in rb: |
|
3784 | elif b in rb: | |
3785 | ui.status(_("deleting remote bookmark %s\n") % b) |
|
3785 | ui.status(_("deleting remote bookmark %s\n") % b) | |
3786 | new = '' # delete |
|
3786 | new = '' # delete | |
3787 | else: |
|
3787 | else: | |
3788 | ui.warn(_('bookmark %s does not exist on the local ' |
|
3788 | ui.warn(_('bookmark %s does not exist on the local ' | |
3789 | 'or remote repository!\n') % b) |
|
3789 | 'or remote repository!\n') % b) | |
3790 | return 2 |
|
3790 | return 2 | |
3791 | old = rb.get(b, '') |
|
3791 | old = rb.get(b, '') | |
3792 | r = other.pushkey('bookmarks', b, old, new) |
|
3792 | r = other.pushkey('bookmarks', b, old, new) | |
3793 | if not r: |
|
3793 | if not r: | |
3794 | ui.warn(_('updating bookmark %s failed!\n') % b) |
|
3794 | ui.warn(_('updating bookmark %s failed!\n') % b) | |
3795 | if not result: |
|
3795 | if not result: | |
3796 | result = 2 |
|
3796 | result = 2 | |
3797 |
|
3797 | |||
3798 | return result |
|
3798 | return result | |
3799 |
|
3799 | |||
3800 | @command('recover', []) |
|
3800 | @command('recover', []) | |
3801 | def recover(ui, repo): |
|
3801 | def recover(ui, repo): | |
3802 | """roll back an interrupted transaction |
|
3802 | """roll back an interrupted transaction | |
3803 |
|
3803 | |||
3804 | Recover from an interrupted commit or pull. |
|
3804 | Recover from an interrupted commit or pull. | |
3805 |
|
3805 | |||
3806 | This command tries to fix the repository status after an |
|
3806 | This command tries to fix the repository status after an | |
3807 | interrupted operation. It should only be necessary when Mercurial |
|
3807 | interrupted operation. It should only be necessary when Mercurial | |
3808 | suggests it. |
|
3808 | suggests it. | |
3809 |
|
3809 | |||
3810 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
3810 | Returns 0 if successful, 1 if nothing to recover or verify fails. | |
3811 | """ |
|
3811 | """ | |
3812 | if repo.recover(): |
|
3812 | if repo.recover(): | |
3813 | return hg.verify(repo) |
|
3813 | return hg.verify(repo) | |
3814 | return 1 |
|
3814 | return 1 | |
3815 |
|
3815 | |||
3816 | @command('^remove|rm', |
|
3816 | @command('^remove|rm', | |
3817 | [('A', 'after', None, _('record delete for missing files')), |
|
3817 | [('A', 'after', None, _('record delete for missing files')), | |
3818 | ('f', 'force', None, |
|
3818 | ('f', 'force', None, | |
3819 | _('remove (and delete) file even if added or modified')), |
|
3819 | _('remove (and delete) file even if added or modified')), | |
3820 | ] + walkopts, |
|
3820 | ] + walkopts, | |
3821 | _('[OPTION]... FILE...')) |
|
3821 | _('[OPTION]... FILE...')) | |
3822 | def remove(ui, repo, *pats, **opts): |
|
3822 | def remove(ui, repo, *pats, **opts): | |
3823 | """remove the specified files on the next commit |
|
3823 | """remove the specified files on the next commit | |
3824 |
|
3824 | |||
3825 | Schedule the indicated files for removal from the repository. |
|
3825 | Schedule the indicated files for removal from the repository. | |
3826 |
|
3826 | |||
3827 | This only removes files from the current branch, not from the |
|
3827 | This only removes files from the current branch, not from the | |
3828 | entire project history. -A/--after can be used to remove only |
|
3828 | entire project history. -A/--after can be used to remove only | |
3829 | files that have already been deleted, -f/--force can be used to |
|
3829 | files that have already been deleted, -f/--force can be used to | |
3830 | force deletion, and -Af can be used to remove files from the next |
|
3830 | force deletion, and -Af can be used to remove files from the next | |
3831 | revision without deleting them from the working directory. |
|
3831 | revision without deleting them from the working directory. | |
3832 |
|
3832 | |||
3833 | The following table details the behavior of remove for different |
|
3833 | The following table details the behavior of remove for different | |
3834 | file states (columns) and option combinations (rows). The file |
|
3834 | file states (columns) and option combinations (rows). The file | |
3835 | states are Added [A], Clean [C], Modified [M] and Missing [!] (as |
|
3835 | states are Added [A], Clean [C], Modified [M] and Missing [!] (as | |
3836 | reported by :hg:`status`). The actions are Warn, Remove (from |
|
3836 | reported by :hg:`status`). The actions are Warn, Remove (from | |
3837 | branch) and Delete (from disk):: |
|
3837 | branch) and Delete (from disk):: | |
3838 |
|
3838 | |||
3839 | A C M ! |
|
3839 | A C M ! | |
3840 | none W RD W R |
|
3840 | none W RD W R | |
3841 | -f R RD RD R |
|
3841 | -f R RD RD R | |
3842 | -A W W W R |
|
3842 | -A W W W R | |
3843 | -Af R R R R |
|
3843 | -Af R R R R | |
3844 |
|
3844 | |||
3845 | This command schedules the files to be removed at the next commit. |
|
3845 | This command schedules the files to be removed at the next commit. | |
3846 | To undo a remove before that, see :hg:`revert`. |
|
3846 | To undo a remove before that, see :hg:`revert`. | |
3847 |
|
3847 | |||
3848 | Returns 0 on success, 1 if any warnings encountered. |
|
3848 | Returns 0 on success, 1 if any warnings encountered. | |
3849 | """ |
|
3849 | """ | |
3850 |
|
3850 | |||
3851 | ret = 0 |
|
3851 | ret = 0 | |
3852 | after, force = opts.get('after'), opts.get('force') |
|
3852 | after, force = opts.get('after'), opts.get('force') | |
3853 | if not pats and not after: |
|
3853 | if not pats and not after: | |
3854 | raise util.Abort(_('no files specified')) |
|
3854 | raise util.Abort(_('no files specified')) | |
3855 |
|
3855 | |||
3856 | m = cmdutil.match(repo, pats, opts) |
|
3856 | m = cmdutil.match(repo, pats, opts) | |
3857 | s = repo.status(match=m, clean=True) |
|
3857 | s = repo.status(match=m, clean=True) | |
3858 | modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
|
3858 | modified, added, deleted, clean = s[0], s[1], s[3], s[6] | |
3859 |
|
3859 | |||
3860 | for f in m.files(): |
|
3860 | for f in m.files(): | |
3861 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
|
3861 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): | |
3862 | ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) |
|
3862 | ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) | |
3863 | ret = 1 |
|
3863 | ret = 1 | |
3864 |
|
3864 | |||
3865 | if force: |
|
3865 | if force: | |
3866 | remove, forget = modified + deleted + clean, added |
|
3866 | remove, forget = modified + deleted + clean, added | |
3867 | elif after: |
|
3867 | elif after: | |
3868 | remove, forget = deleted, [] |
|
3868 | remove, forget = deleted, [] | |
3869 | for f in modified + added + clean: |
|
3869 | for f in modified + added + clean: | |
3870 | ui.warn(_('not removing %s: file still exists (use -f' |
|
3870 | ui.warn(_('not removing %s: file still exists (use -f' | |
3871 | ' to force removal)\n') % m.rel(f)) |
|
3871 | ' to force removal)\n') % m.rel(f)) | |
3872 | ret = 1 |
|
3872 | ret = 1 | |
3873 | else: |
|
3873 | else: | |
3874 | remove, forget = deleted + clean, [] |
|
3874 | remove, forget = deleted + clean, [] | |
3875 | for f in modified: |
|
3875 | for f in modified: | |
3876 | ui.warn(_('not removing %s: file is modified (use -f' |
|
3876 | ui.warn(_('not removing %s: file is modified (use -f' | |
3877 | ' to force removal)\n') % m.rel(f)) |
|
3877 | ' to force removal)\n') % m.rel(f)) | |
3878 | ret = 1 |
|
3878 | ret = 1 | |
3879 | for f in added: |
|
3879 | for f in added: | |
3880 | ui.warn(_('not removing %s: file has been marked for add (use -f' |
|
3880 | ui.warn(_('not removing %s: file has been marked for add (use -f' | |
3881 | ' to force removal)\n') % m.rel(f)) |
|
3881 | ' to force removal)\n') % m.rel(f)) | |
3882 | ret = 1 |
|
3882 | ret = 1 | |
3883 |
|
3883 | |||
3884 | for f in sorted(remove + forget): |
|
3884 | for f in sorted(remove + forget): | |
3885 | if ui.verbose or not m.exact(f): |
|
3885 | if ui.verbose or not m.exact(f): | |
3886 | ui.status(_('removing %s\n') % m.rel(f)) |
|
3886 | ui.status(_('removing %s\n') % m.rel(f)) | |
3887 |
|
3887 | |||
3888 | repo[None].forget(forget) |
|
3888 | repo[None].forget(forget) | |
3889 | repo[None].remove(remove, unlink=not after) |
|
3889 | repo[None].remove(remove, unlink=not after) | |
3890 | return ret |
|
3890 | return ret | |
3891 |
|
3891 | |||
3892 | @command('rename|move|mv', |
|
3892 | @command('rename|move|mv', | |
3893 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
3893 | [('A', 'after', None, _('record a rename that has already occurred')), | |
3894 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
3894 | ('f', 'force', None, _('forcibly copy over an existing managed file')), | |
3895 | ] + walkopts + dryrunopts, |
|
3895 | ] + walkopts + dryrunopts, | |
3896 | _('[OPTION]... SOURCE... DEST')) |
|
3896 | _('[OPTION]... SOURCE... DEST')) | |
3897 | def rename(ui, repo, *pats, **opts): |
|
3897 | def rename(ui, repo, *pats, **opts): | |
3898 | """rename files; equivalent of copy + remove |
|
3898 | """rename files; equivalent of copy + remove | |
3899 |
|
3899 | |||
3900 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
3900 | Mark dest as copies of sources; mark sources for deletion. If dest | |
3901 | is a directory, copies are put in that directory. If dest is a |
|
3901 | is a directory, copies are put in that directory. If dest is a | |
3902 | file, there can only be one source. |
|
3902 | file, there can only be one source. | |
3903 |
|
3903 | |||
3904 | By default, this command copies the contents of files as they |
|
3904 | By default, this command copies the contents of files as they | |
3905 | exist in the working directory. If invoked with -A/--after, the |
|
3905 | exist in the working directory. If invoked with -A/--after, the | |
3906 | operation is recorded, but no copying is performed. |
|
3906 | operation is recorded, but no copying is performed. | |
3907 |
|
3907 | |||
3908 | This command takes effect at the next commit. To undo a rename |
|
3908 | This command takes effect at the next commit. To undo a rename | |
3909 | before that, see :hg:`revert`. |
|
3909 | before that, see :hg:`revert`. | |
3910 |
|
3910 | |||
3911 | Returns 0 on success, 1 if errors are encountered. |
|
3911 | Returns 0 on success, 1 if errors are encountered. | |
3912 | """ |
|
3912 | """ | |
3913 | wlock = repo.wlock(False) |
|
3913 | wlock = repo.wlock(False) | |
3914 | try: |
|
3914 | try: | |
3915 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
3915 | return cmdutil.copy(ui, repo, pats, opts, rename=True) | |
3916 | finally: |
|
3916 | finally: | |
3917 | wlock.release() |
|
3917 | wlock.release() | |
3918 |
|
3918 | |||
3919 | @command('resolve', |
|
3919 | @command('resolve', | |
3920 | [('a', 'all', None, _('select all unresolved files')), |
|
3920 | [('a', 'all', None, _('select all unresolved files')), | |
3921 | ('l', 'list', None, _('list state of files needing merge')), |
|
3921 | ('l', 'list', None, _('list state of files needing merge')), | |
3922 | ('m', 'mark', None, _('mark files as resolved')), |
|
3922 | ('m', 'mark', None, _('mark files as resolved')), | |
3923 | ('u', 'unmark', None, _('mark files as unresolved')), |
|
3923 | ('u', 'unmark', None, _('mark files as unresolved')), | |
3924 | ('t', 'tool', '', _('specify merge tool')), |
|
3924 | ('t', 'tool', '', _('specify merge tool')), | |
3925 | ('n', 'no-status', None, _('hide status prefix'))] |
|
3925 | ('n', 'no-status', None, _('hide status prefix'))] | |
3926 | + walkopts, |
|
3926 | + walkopts, | |
3927 | _('[OPTION]... [FILE]...')) |
|
3927 | _('[OPTION]... [FILE]...')) | |
3928 | def resolve(ui, repo, *pats, **opts): |
|
3928 | def resolve(ui, repo, *pats, **opts): | |
3929 | """redo merges or set/view the merge status of files |
|
3929 | """redo merges or set/view the merge status of files | |
3930 |
|
3930 | |||
3931 | Merges with unresolved conflicts are often the result of |
|
3931 | Merges with unresolved conflicts are often the result of | |
3932 | non-interactive merging using the ``internal:merge`` configuration |
|
3932 | non-interactive merging using the ``internal:merge`` configuration | |
3933 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
3933 | setting, or a command-line merge tool like ``diff3``. The resolve | |
3934 | command is used to manage the files involved in a merge, after |
|
3934 | command is used to manage the files involved in a merge, after | |
3935 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
3935 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the | |
3936 | working directory must have two parents). |
|
3936 | working directory must have two parents). | |
3937 |
|
3937 | |||
3938 | The resolve command can be used in the following ways: |
|
3938 | The resolve command can be used in the following ways: | |
3939 |
|
3939 | |||
3940 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified |
|
3940 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified | |
3941 | files, discarding any previous merge attempts. Re-merging is not |
|
3941 | files, discarding any previous merge attempts. Re-merging is not | |
3942 | performed for files already marked as resolved. Use ``--all/-a`` |
|
3942 | performed for files already marked as resolved. Use ``--all/-a`` | |
3943 | to selects all unresolved files. ``--tool`` can be used to specify |
|
3943 | to selects all unresolved files. ``--tool`` can be used to specify | |
3944 | the merge tool used for the given files. It overrides the HGMERGE |
|
3944 | the merge tool used for the given files. It overrides the HGMERGE | |
3945 | environment variable and your configuration files. |
|
3945 | environment variable and your configuration files. | |
3946 |
|
3946 | |||
3947 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
3947 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved | |
3948 | (e.g. after having manually fixed-up the files). The default is |
|
3948 | (e.g. after having manually fixed-up the files). The default is | |
3949 | to mark all unresolved files. |
|
3949 | to mark all unresolved files. | |
3950 |
|
3950 | |||
3951 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
3951 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The | |
3952 | default is to mark all resolved files. |
|
3952 | default is to mark all resolved files. | |
3953 |
|
3953 | |||
3954 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
3954 | - :hg:`resolve -l`: list files which had or still have conflicts. | |
3955 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
3955 | In the printed list, ``U`` = unresolved and ``R`` = resolved. | |
3956 |
|
3956 | |||
3957 | Note that Mercurial will not let you commit files with unresolved |
|
3957 | Note that Mercurial will not let you commit files with unresolved | |
3958 | merge conflicts. You must use :hg:`resolve -m ...` before you can |
|
3958 | merge conflicts. You must use :hg:`resolve -m ...` before you can | |
3959 | commit after a conflicting merge. |
|
3959 | commit after a conflicting merge. | |
3960 |
|
3960 | |||
3961 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
3961 | Returns 0 on success, 1 if any files fail a resolve attempt. | |
3962 | """ |
|
3962 | """ | |
3963 |
|
3963 | |||
3964 | all, mark, unmark, show, nostatus = \ |
|
3964 | all, mark, unmark, show, nostatus = \ | |
3965 | [opts.get(o) for o in 'all mark unmark list no_status'.split()] |
|
3965 | [opts.get(o) for o in 'all mark unmark list no_status'.split()] | |
3966 |
|
3966 | |||
3967 | if (show and (mark or unmark)) or (mark and unmark): |
|
3967 | if (show and (mark or unmark)) or (mark and unmark): | |
3968 | raise util.Abort(_("too many options specified")) |
|
3968 | raise util.Abort(_("too many options specified")) | |
3969 | if pats and all: |
|
3969 | if pats and all: | |
3970 | raise util.Abort(_("can't specify --all and patterns")) |
|
3970 | raise util.Abort(_("can't specify --all and patterns")) | |
3971 | if not (all or pats or show or mark or unmark): |
|
3971 | if not (all or pats or show or mark or unmark): | |
3972 | raise util.Abort(_('no files or directories specified; ' |
|
3972 | raise util.Abort(_('no files or directories specified; ' | |
3973 | 'use --all to remerge all files')) |
|
3973 | 'use --all to remerge all files')) | |
3974 |
|
3974 | |||
3975 | ms = mergemod.mergestate(repo) |
|
3975 | ms = mergemod.mergestate(repo) | |
3976 | m = cmdutil.match(repo, pats, opts) |
|
3976 | m = cmdutil.match(repo, pats, opts) | |
3977 | ret = 0 |
|
3977 | ret = 0 | |
3978 |
|
3978 | |||
3979 | for f in ms: |
|
3979 | for f in ms: | |
3980 | if m(f): |
|
3980 | if m(f): | |
3981 | if show: |
|
3981 | if show: | |
3982 | if nostatus: |
|
3982 | if nostatus: | |
3983 | ui.write("%s\n" % f) |
|
3983 | ui.write("%s\n" % f) | |
3984 | else: |
|
3984 | else: | |
3985 | ui.write("%s %s\n" % (ms[f].upper(), f), |
|
3985 | ui.write("%s %s\n" % (ms[f].upper(), f), | |
3986 | label='resolve.' + |
|
3986 | label='resolve.' + | |
3987 | {'u': 'unresolved', 'r': 'resolved'}[ms[f]]) |
|
3987 | {'u': 'unresolved', 'r': 'resolved'}[ms[f]]) | |
3988 | elif mark: |
|
3988 | elif mark: | |
3989 | ms.mark(f, "r") |
|
3989 | ms.mark(f, "r") | |
3990 | elif unmark: |
|
3990 | elif unmark: | |
3991 | ms.mark(f, "u") |
|
3991 | ms.mark(f, "u") | |
3992 | else: |
|
3992 | else: | |
3993 | wctx = repo[None] |
|
3993 | wctx = repo[None] | |
3994 | mctx = wctx.parents()[-1] |
|
3994 | mctx = wctx.parents()[-1] | |
3995 |
|
3995 | |||
3996 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
3996 | # backup pre-resolve (merge uses .orig for its own purposes) | |
3997 | a = repo.wjoin(f) |
|
3997 | a = repo.wjoin(f) | |
3998 | util.copyfile(a, a + ".resolve") |
|
3998 | util.copyfile(a, a + ".resolve") | |
3999 |
|
3999 | |||
4000 | try: |
|
4000 | try: | |
4001 | # resolve file |
|
4001 | # resolve file | |
4002 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
4002 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) | |
4003 | if ms.resolve(f, wctx, mctx): |
|
4003 | if ms.resolve(f, wctx, mctx): | |
4004 | ret = 1 |
|
4004 | ret = 1 | |
4005 | finally: |
|
4005 | finally: | |
4006 | ui.setconfig('ui', 'forcemerge', '') |
|
4006 | ui.setconfig('ui', 'forcemerge', '') | |
4007 |
|
4007 | |||
4008 | # replace filemerge's .orig file with our resolve file |
|
4008 | # replace filemerge's .orig file with our resolve file | |
4009 | util.rename(a + ".resolve", a + ".orig") |
|
4009 | util.rename(a + ".resolve", a + ".orig") | |
4010 |
|
4010 | |||
4011 | ms.commit() |
|
4011 | ms.commit() | |
4012 | return ret |
|
4012 | return ret | |
4013 |
|
4013 | |||
4014 | @command('revert', |
|
4014 | @command('revert', | |
4015 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
4015 | [('a', 'all', None, _('revert all changes when no arguments given')), | |
4016 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
4016 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | |
4017 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), |
|
4017 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), | |
4018 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
4018 | ('', 'no-backup', None, _('do not save backup copies of files')), | |
4019 | ] + walkopts + dryrunopts, |
|
4019 | ] + walkopts + dryrunopts, | |
4020 | _('[OPTION]... [-r REV] [NAME]...')) |
|
4020 | _('[OPTION]... [-r REV] [NAME]...')) | |
4021 | def revert(ui, repo, *pats, **opts): |
|
4021 | def revert(ui, repo, *pats, **opts): | |
4022 | """restore individual files or directories to an earlier state |
|
4022 | """restore individual files or directories to an earlier state | |
4023 |
|
4023 | |||
4024 | .. note:: |
|
4024 | .. note:: | |
4025 | This command is most likely not what you are looking for. |
|
4025 | This command is most likely not what you are looking for. | |
4026 | Revert will partially overwrite content in the working |
|
4026 | Revert will partially overwrite content in the working | |
4027 | directory without changing the working directory parents. Use |
|
4027 | directory without changing the working directory parents. Use | |
4028 | :hg:`update -r rev` to check out earlier revisions, or |
|
4028 | :hg:`update -r rev` to check out earlier revisions, or | |
4029 | :hg:`update --clean .` to undo a merge which has added another |
|
4029 | :hg:`update --clean .` to undo a merge which has added another | |
4030 | parent. |
|
4030 | parent. | |
4031 |
|
4031 | |||
4032 | With no revision specified, revert the named files or directories |
|
4032 | With no revision specified, revert the named files or directories | |
4033 | to the contents they had in the parent of the working directory. |
|
4033 | to the contents they had in the parent of the working directory. | |
4034 | This restores the contents of the affected files to an unmodified |
|
4034 | This restores the contents of the affected files to an unmodified | |
4035 | state and unschedules adds, removes, copies, and renames. If the |
|
4035 | state and unschedules adds, removes, copies, and renames. If the | |
4036 | working directory has two parents, you must explicitly specify a |
|
4036 | working directory has two parents, you must explicitly specify a | |
4037 | revision. |
|
4037 | revision. | |
4038 |
|
4038 | |||
4039 | Using the -r/--rev option, revert the given files or directories |
|
4039 | Using the -r/--rev option, revert the given files or directories | |
4040 | to their contents as of a specific revision. This can be helpful |
|
4040 | to their contents as of a specific revision. This can be helpful | |
4041 | to "roll back" some or all of an earlier change. See :hg:`help |
|
4041 | to "roll back" some or all of an earlier change. See :hg:`help | |
4042 | dates` for a list of formats valid for -d/--date. |
|
4042 | dates` for a list of formats valid for -d/--date. | |
4043 |
|
4043 | |||
4044 | Revert modifies the working directory. It does not commit any |
|
4044 | Revert modifies the working directory. It does not commit any | |
4045 | changes, or change the parent of the working directory. If you |
|
4045 | changes, or change the parent of the working directory. If you | |
4046 | revert to a revision other than the parent of the working |
|
4046 | revert to a revision other than the parent of the working | |
4047 | directory, the reverted files will thus appear modified |
|
4047 | directory, the reverted files will thus appear modified | |
4048 | afterwards. |
|
4048 | afterwards. | |
4049 |
|
4049 | |||
4050 | If a file has been deleted, it is restored. Files scheduled for |
|
4050 | If a file has been deleted, it is restored. Files scheduled for | |
4051 | addition are just unscheduled and left as they are. If the |
|
4051 | addition are just unscheduled and left as they are. If the | |
4052 | executable mode of a file was changed, it is reset. |
|
4052 | executable mode of a file was changed, it is reset. | |
4053 |
|
4053 | |||
4054 | If names are given, all files matching the names are reverted. |
|
4054 | If names are given, all files matching the names are reverted. | |
4055 | If no arguments are given, no files are reverted. |
|
4055 | If no arguments are given, no files are reverted. | |
4056 |
|
4056 | |||
4057 | Modified files are saved with a .orig suffix before reverting. |
|
4057 | Modified files are saved with a .orig suffix before reverting. | |
4058 | To disable these backups, use --no-backup. |
|
4058 | To disable these backups, use --no-backup. | |
4059 |
|
4059 | |||
4060 | Returns 0 on success. |
|
4060 | Returns 0 on success. | |
4061 | """ |
|
4061 | """ | |
4062 |
|
4062 | |||
4063 | if opts.get("date"): |
|
4063 | if opts.get("date"): | |
4064 | if opts.get("rev"): |
|
4064 | if opts.get("rev"): | |
4065 | raise util.Abort(_("you can't specify a revision and a date")) |
|
4065 | raise util.Abort(_("you can't specify a revision and a date")) | |
4066 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
4066 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) | |
4067 |
|
4067 | |||
4068 | parent, p2 = repo.dirstate.parents() |
|
4068 | parent, p2 = repo.dirstate.parents() | |
4069 | if not opts.get('rev') and p2 != nullid: |
|
4069 | if not opts.get('rev') and p2 != nullid: | |
4070 | raise util.Abort(_('uncommitted merge - ' |
|
4070 | raise util.Abort(_('uncommitted merge - ' | |
4071 | 'use "hg update", see "hg help revert"')) |
|
4071 | 'use "hg update", see "hg help revert"')) | |
4072 |
|
4072 | |||
4073 | if not pats and not opts.get('all'): |
|
4073 | if not pats and not opts.get('all'): | |
4074 | raise util.Abort(_('no files or directories specified; ' |
|
4074 | raise util.Abort(_('no files or directories specified; ' | |
4075 | 'use --all to revert the whole repo')) |
|
4075 | 'use --all to revert the whole repo')) | |
4076 |
|
4076 | |||
4077 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
4077 | ctx = scmutil.revsingle(repo, opts.get('rev')) | |
4078 | node = ctx.node() |
|
4078 | node = ctx.node() | |
4079 | mf = ctx.manifest() |
|
4079 | mf = ctx.manifest() | |
4080 | if node == parent: |
|
4080 | if node == parent: | |
4081 | pmf = mf |
|
4081 | pmf = mf | |
4082 | else: |
|
4082 | else: | |
4083 | pmf = None |
|
4083 | pmf = None | |
4084 |
|
4084 | |||
4085 | # need all matching names in dirstate and manifest of target rev, |
|
4085 | # need all matching names in dirstate and manifest of target rev, | |
4086 | # so have to walk both. do not print errors if files exist in one |
|
4086 | # so have to walk both. do not print errors if files exist in one | |
4087 | # but not other. |
|
4087 | # but not other. | |
4088 |
|
4088 | |||
4089 | names = {} |
|
4089 | names = {} | |
4090 |
|
4090 | |||
4091 | wlock = repo.wlock() |
|
4091 | wlock = repo.wlock() | |
4092 | try: |
|
4092 | try: | |
4093 | # walk dirstate. |
|
4093 | # walk dirstate. | |
4094 |
|
4094 | |||
4095 | m = cmdutil.match(repo, pats, opts) |
|
4095 | m = cmdutil.match(repo, pats, opts) | |
4096 | m.bad = lambda x, y: False |
|
4096 | m.bad = lambda x, y: False | |
4097 | for abs in repo.walk(m): |
|
4097 | for abs in repo.walk(m): | |
4098 | names[abs] = m.rel(abs), m.exact(abs) |
|
4098 | names[abs] = m.rel(abs), m.exact(abs) | |
4099 |
|
4099 | |||
4100 | # walk target manifest. |
|
4100 | # walk target manifest. | |
4101 |
|
4101 | |||
4102 | def badfn(path, msg): |
|
4102 | def badfn(path, msg): | |
4103 | if path in names: |
|
4103 | if path in names: | |
4104 | return |
|
4104 | return | |
4105 | path_ = path + '/' |
|
4105 | path_ = path + '/' | |
4106 | for f in names: |
|
4106 | for f in names: | |
4107 | if f.startswith(path_): |
|
4107 | if f.startswith(path_): | |
4108 | return |
|
4108 | return | |
4109 | ui.warn("%s: %s\n" % (m.rel(path), msg)) |
|
4109 | ui.warn("%s: %s\n" % (m.rel(path), msg)) | |
4110 |
|
4110 | |||
4111 | m = cmdutil.match(repo, pats, opts) |
|
4111 | m = cmdutil.match(repo, pats, opts) | |
4112 | m.bad = badfn |
|
4112 | m.bad = badfn | |
4113 | for abs in repo[node].walk(m): |
|
4113 | for abs in repo[node].walk(m): | |
4114 | if abs not in names: |
|
4114 | if abs not in names: | |
4115 | names[abs] = m.rel(abs), m.exact(abs) |
|
4115 | names[abs] = m.rel(abs), m.exact(abs) | |
4116 |
|
4116 | |||
4117 | m = cmdutil.matchfiles(repo, names) |
|
4117 | m = cmdutil.matchfiles(repo, names) | |
4118 | changes = repo.status(match=m)[:4] |
|
4118 | changes = repo.status(match=m)[:4] | |
4119 | modified, added, removed, deleted = map(set, changes) |
|
4119 | modified, added, removed, deleted = map(set, changes) | |
4120 |
|
4120 | |||
4121 | # if f is a rename, also revert the source |
|
4121 | # if f is a rename, also revert the source | |
4122 | cwd = repo.getcwd() |
|
4122 | cwd = repo.getcwd() | |
4123 | for f in added: |
|
4123 | for f in added: | |
4124 | src = repo.dirstate.copied(f) |
|
4124 | src = repo.dirstate.copied(f) | |
4125 | if src and src not in names and repo.dirstate[src] == 'r': |
|
4125 | if src and src not in names and repo.dirstate[src] == 'r': | |
4126 | removed.add(src) |
|
4126 | removed.add(src) | |
4127 | names[src] = (repo.pathto(src, cwd), True) |
|
4127 | names[src] = (repo.pathto(src, cwd), True) | |
4128 |
|
4128 | |||
4129 | def removeforget(abs): |
|
4129 | def removeforget(abs): | |
4130 | if repo.dirstate[abs] == 'a': |
|
4130 | if repo.dirstate[abs] == 'a': | |
4131 | return _('forgetting %s\n') |
|
4131 | return _('forgetting %s\n') | |
4132 | return _('removing %s\n') |
|
4132 | return _('removing %s\n') | |
4133 |
|
4133 | |||
4134 | revert = ([], _('reverting %s\n')) |
|
4134 | revert = ([], _('reverting %s\n')) | |
4135 | add = ([], _('adding %s\n')) |
|
4135 | add = ([], _('adding %s\n')) | |
4136 | remove = ([], removeforget) |
|
4136 | remove = ([], removeforget) | |
4137 | undelete = ([], _('undeleting %s\n')) |
|
4137 | undelete = ([], _('undeleting %s\n')) | |
4138 |
|
4138 | |||
4139 | disptable = ( |
|
4139 | disptable = ( | |
4140 | # dispatch table: |
|
4140 | # dispatch table: | |
4141 | # file state |
|
4141 | # file state | |
4142 | # action if in target manifest |
|
4142 | # action if in target manifest | |
4143 | # action if not in target manifest |
|
4143 | # action if not in target manifest | |
4144 | # make backup if in target manifest |
|
4144 | # make backup if in target manifest | |
4145 | # make backup if not in target manifest |
|
4145 | # make backup if not in target manifest | |
4146 | (modified, revert, remove, True, True), |
|
4146 | (modified, revert, remove, True, True), | |
4147 | (added, revert, remove, True, False), |
|
4147 | (added, revert, remove, True, False), | |
4148 | (removed, undelete, None, False, False), |
|
4148 | (removed, undelete, None, False, False), | |
4149 | (deleted, revert, remove, False, False), |
|
4149 | (deleted, revert, remove, False, False), | |
4150 | ) |
|
4150 | ) | |
4151 |
|
4151 | |||
4152 | for abs, (rel, exact) in sorted(names.items()): |
|
4152 | for abs, (rel, exact) in sorted(names.items()): | |
4153 | mfentry = mf.get(abs) |
|
4153 | mfentry = mf.get(abs) | |
4154 | target = repo.wjoin(abs) |
|
4154 | target = repo.wjoin(abs) | |
4155 | def handle(xlist, dobackup): |
|
4155 | def handle(xlist, dobackup): | |
4156 | xlist[0].append(abs) |
|
4156 | xlist[0].append(abs) | |
4157 | if (dobackup and not opts.get('no_backup') and |
|
4157 | if (dobackup and not opts.get('no_backup') and | |
4158 | os.path.lexists(target)): |
|
4158 | os.path.lexists(target)): | |
4159 | bakname = "%s.orig" % rel |
|
4159 | bakname = "%s.orig" % rel | |
4160 | ui.note(_('saving current version of %s as %s\n') % |
|
4160 | ui.note(_('saving current version of %s as %s\n') % | |
4161 | (rel, bakname)) |
|
4161 | (rel, bakname)) | |
4162 | if not opts.get('dry_run'): |
|
4162 | if not opts.get('dry_run'): | |
4163 | util.rename(target, bakname) |
|
4163 | util.rename(target, bakname) | |
4164 | if ui.verbose or not exact: |
|
4164 | if ui.verbose or not exact: | |
4165 | msg = xlist[1] |
|
4165 | msg = xlist[1] | |
4166 | if not isinstance(msg, basestring): |
|
4166 | if not isinstance(msg, basestring): | |
4167 | msg = msg(abs) |
|
4167 | msg = msg(abs) | |
4168 | ui.status(msg % rel) |
|
4168 | ui.status(msg % rel) | |
4169 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
4169 | for table, hitlist, misslist, backuphit, backupmiss in disptable: | |
4170 | if abs not in table: |
|
4170 | if abs not in table: | |
4171 | continue |
|
4171 | continue | |
4172 | # file has changed in dirstate |
|
4172 | # file has changed in dirstate | |
4173 | if mfentry: |
|
4173 | if mfentry: | |
4174 | handle(hitlist, backuphit) |
|
4174 | handle(hitlist, backuphit) | |
4175 | elif misslist is not None: |
|
4175 | elif misslist is not None: | |
4176 | handle(misslist, backupmiss) |
|
4176 | handle(misslist, backupmiss) | |
4177 | break |
|
4177 | break | |
4178 | else: |
|
4178 | else: | |
4179 | if abs not in repo.dirstate: |
|
4179 | if abs not in repo.dirstate: | |
4180 | if mfentry: |
|
4180 | if mfentry: | |
4181 | handle(add, True) |
|
4181 | handle(add, True) | |
4182 | elif exact: |
|
4182 | elif exact: | |
4183 | ui.warn(_('file not managed: %s\n') % rel) |
|
4183 | ui.warn(_('file not managed: %s\n') % rel) | |
4184 | continue |
|
4184 | continue | |
4185 | # file has not changed in dirstate |
|
4185 | # file has not changed in dirstate | |
4186 | if node == parent: |
|
4186 | if node == parent: | |
4187 | if exact: |
|
4187 | if exact: | |
4188 | ui.warn(_('no changes needed to %s\n') % rel) |
|
4188 | ui.warn(_('no changes needed to %s\n') % rel) | |
4189 | continue |
|
4189 | continue | |
4190 | if pmf is None: |
|
4190 | if pmf is None: | |
4191 | # only need parent manifest in this unlikely case, |
|
4191 | # only need parent manifest in this unlikely case, | |
4192 | # so do not read by default |
|
4192 | # so do not read by default | |
4193 | pmf = repo[parent].manifest() |
|
4193 | pmf = repo[parent].manifest() | |
4194 | if abs in pmf: |
|
4194 | if abs in pmf: | |
4195 | if mfentry: |
|
4195 | if mfentry: | |
4196 | # if version of file is same in parent and target |
|
4196 | # if version of file is same in parent and target | |
4197 | # manifests, do nothing |
|
4197 | # manifests, do nothing | |
4198 | if (pmf[abs] != mfentry or |
|
4198 | if (pmf[abs] != mfentry or | |
4199 | pmf.flags(abs) != mf.flags(abs)): |
|
4199 | pmf.flags(abs) != mf.flags(abs)): | |
4200 | handle(revert, False) |
|
4200 | handle(revert, False) | |
4201 | else: |
|
4201 | else: | |
4202 | handle(remove, False) |
|
4202 | handle(remove, False) | |
4203 |
|
4203 | |||
4204 | if not opts.get('dry_run'): |
|
4204 | if not opts.get('dry_run'): | |
4205 | def checkout(f): |
|
4205 | def checkout(f): | |
4206 | fc = ctx[f] |
|
4206 | fc = ctx[f] | |
4207 | repo.wwrite(f, fc.data(), fc.flags()) |
|
4207 | repo.wwrite(f, fc.data(), fc.flags()) | |
4208 |
|
4208 | |||
4209 | audit_path = scmutil.pathauditor(repo.root) |
|
4209 | audit_path = scmutil.pathauditor(repo.root) | |
4210 | for f in remove[0]: |
|
4210 | for f in remove[0]: | |
4211 | if repo.dirstate[f] == 'a': |
|
4211 | if repo.dirstate[f] == 'a': | |
4212 | repo.dirstate.forget(f) |
|
4212 | repo.dirstate.forget(f) | |
4213 | continue |
|
4213 | continue | |
4214 | audit_path(f) |
|
4214 | audit_path(f) | |
4215 | try: |
|
4215 | try: | |
4216 | util.unlinkpath(repo.wjoin(f)) |
|
4216 | util.unlinkpath(repo.wjoin(f)) | |
4217 | except OSError: |
|
4217 | except OSError: | |
4218 | pass |
|
4218 | pass | |
4219 | repo.dirstate.remove(f) |
|
4219 | repo.dirstate.remove(f) | |
4220 |
|
4220 | |||
4221 | normal = None |
|
4221 | normal = None | |
4222 | if node == parent: |
|
4222 | if node == parent: | |
4223 | # We're reverting to our parent. If possible, we'd like status |
|
4223 | # We're reverting to our parent. If possible, we'd like status | |
4224 | # to report the file as clean. We have to use normallookup for |
|
4224 | # to report the file as clean. We have to use normallookup for | |
4225 | # merges to avoid losing information about merged/dirty files. |
|
4225 | # merges to avoid losing information about merged/dirty files. | |
4226 | if p2 != nullid: |
|
4226 | if p2 != nullid: | |
4227 | normal = repo.dirstate.normallookup |
|
4227 | normal = repo.dirstate.normallookup | |
4228 | else: |
|
4228 | else: | |
4229 | normal = repo.dirstate.normal |
|
4229 | normal = repo.dirstate.normal | |
4230 | for f in revert[0]: |
|
4230 | for f in revert[0]: | |
4231 | checkout(f) |
|
4231 | checkout(f) | |
4232 | if normal: |
|
4232 | if normal: | |
4233 | normal(f) |
|
4233 | normal(f) | |
4234 |
|
4234 | |||
4235 | for f in add[0]: |
|
4235 | for f in add[0]: | |
4236 | checkout(f) |
|
4236 | checkout(f) | |
4237 | repo.dirstate.add(f) |
|
4237 | repo.dirstate.add(f) | |
4238 |
|
4238 | |||
4239 | normal = repo.dirstate.normallookup |
|
4239 | normal = repo.dirstate.normallookup | |
4240 | if node == parent and p2 == nullid: |
|
4240 | if node == parent and p2 == nullid: | |
4241 | normal = repo.dirstate.normal |
|
4241 | normal = repo.dirstate.normal | |
4242 | for f in undelete[0]: |
|
4242 | for f in undelete[0]: | |
4243 | checkout(f) |
|
4243 | checkout(f) | |
4244 | normal(f) |
|
4244 | normal(f) | |
4245 |
|
4245 | |||
4246 | finally: |
|
4246 | finally: | |
4247 | wlock.release() |
|
4247 | wlock.release() | |
4248 |
|
4248 | |||
4249 | @command('rollback', dryrunopts) |
|
4249 | @command('rollback', dryrunopts) | |
4250 | def rollback(ui, repo, **opts): |
|
4250 | def rollback(ui, repo, **opts): | |
4251 | """roll back the last transaction (dangerous) |
|
4251 | """roll back the last transaction (dangerous) | |
4252 |
|
4252 | |||
4253 | This command should be used with care. There is only one level of |
|
4253 | This command should be used with care. There is only one level of | |
4254 | rollback, and there is no way to undo a rollback. It will also |
|
4254 | rollback, and there is no way to undo a rollback. It will also | |
4255 | restore the dirstate at the time of the last transaction, losing |
|
4255 | restore the dirstate at the time of the last transaction, losing | |
4256 | any dirstate changes since that time. This command does not alter |
|
4256 | any dirstate changes since that time. This command does not alter | |
4257 | the working directory. |
|
4257 | the working directory. | |
4258 |
|
4258 | |||
4259 | Transactions are used to encapsulate the effects of all commands |
|
4259 | Transactions are used to encapsulate the effects of all commands | |
4260 | that create new changesets or propagate existing changesets into a |
|
4260 | that create new changesets or propagate existing changesets into a | |
4261 | repository. For example, the following commands are transactional, |
|
4261 | repository. For example, the following commands are transactional, | |
4262 | and their effects can be rolled back: |
|
4262 | and their effects can be rolled back: | |
4263 |
|
4263 | |||
4264 | - commit |
|
4264 | - commit | |
4265 | - import |
|
4265 | - import | |
4266 | - pull |
|
4266 | - pull | |
4267 | - push (with this repository as the destination) |
|
4267 | - push (with this repository as the destination) | |
4268 | - unbundle |
|
4268 | - unbundle | |
4269 |
|
4269 | |||
4270 | This command is not intended for use on public repositories. Once |
|
4270 | This command is not intended for use on public repositories. Once | |
4271 | changes are visible for pull by other users, rolling a transaction |
|
4271 | changes are visible for pull by other users, rolling a transaction | |
4272 | back locally is ineffective (someone else may already have pulled |
|
4272 | back locally is ineffective (someone else may already have pulled | |
4273 | the changes). Furthermore, a race is possible with readers of the |
|
4273 | the changes). Furthermore, a race is possible with readers of the | |
4274 | repository; for example an in-progress pull from the repository |
|
4274 | repository; for example an in-progress pull from the repository | |
4275 | may fail if a rollback is performed. |
|
4275 | may fail if a rollback is performed. | |
4276 |
|
4276 | |||
4277 | Returns 0 on success, 1 if no rollback data is available. |
|
4277 | Returns 0 on success, 1 if no rollback data is available. | |
4278 | """ |
|
4278 | """ | |
4279 | return repo.rollback(opts.get('dry_run')) |
|
4279 | return repo.rollback(opts.get('dry_run')) | |
4280 |
|
4280 | |||
4281 | @command('root', []) |
|
4281 | @command('root', []) | |
4282 | def root(ui, repo): |
|
4282 | def root(ui, repo): | |
4283 | """print the root (top) of the current working directory |
|
4283 | """print the root (top) of the current working directory | |
4284 |
|
4284 | |||
4285 | Print the root directory of the current repository. |
|
4285 | Print the root directory of the current repository. | |
4286 |
|
4286 | |||
4287 | Returns 0 on success. |
|
4287 | Returns 0 on success. | |
4288 | """ |
|
4288 | """ | |
4289 | ui.write(repo.root + "\n") |
|
4289 | ui.write(repo.root + "\n") | |
4290 |
|
4290 | |||
4291 | @command('^serve', |
|
4291 | @command('^serve', | |
4292 | [('A', 'accesslog', '', _('name of access log file to write to'), |
|
4292 | [('A', 'accesslog', '', _('name of access log file to write to'), | |
4293 | _('FILE')), |
|
4293 | _('FILE')), | |
4294 | ('d', 'daemon', None, _('run server in background')), |
|
4294 | ('d', 'daemon', None, _('run server in background')), | |
4295 | ('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('NUM')), |
|
4295 | ('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('NUM')), | |
4296 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), |
|
4296 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), | |
4297 | # use string type, then we can check if something was passed |
|
4297 | # use string type, then we can check if something was passed | |
4298 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), |
|
4298 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), | |
4299 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), |
|
4299 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), | |
4300 | _('ADDR')), |
|
4300 | _('ADDR')), | |
4301 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), |
|
4301 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), | |
4302 | _('PREFIX')), |
|
4302 | _('PREFIX')), | |
4303 | ('n', 'name', '', |
|
4303 | ('n', 'name', '', | |
4304 | _('name to show in web pages (default: working directory)'), _('NAME')), |
|
4304 | _('name to show in web pages (default: working directory)'), _('NAME')), | |
4305 | ('', 'web-conf', '', |
|
4305 | ('', 'web-conf', '', | |
4306 | _('name of the hgweb config file (see "hg help hgweb")'), _('FILE')), |
|
4306 | _('name of the hgweb config file (see "hg help hgweb")'), _('FILE')), | |
4307 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), |
|
4307 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), | |
4308 | _('FILE')), |
|
4308 | _('FILE')), | |
4309 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), |
|
4309 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), | |
4310 | ('', 'stdio', None, _('for remote clients')), |
|
4310 | ('', 'stdio', None, _('for remote clients')), | |
4311 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), |
|
4311 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), | |
4312 | ('', 'style', '', _('template style to use'), _('STYLE')), |
|
4312 | ('', 'style', '', _('template style to use'), _('STYLE')), | |
4313 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
4313 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), | |
4314 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))], |
|
4314 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))], | |
4315 | _('[OPTION]...')) |
|
4315 | _('[OPTION]...')) | |
4316 | def serve(ui, repo, **opts): |
|
4316 | def serve(ui, repo, **opts): | |
4317 | """start stand-alone webserver |
|
4317 | """start stand-alone webserver | |
4318 |
|
4318 | |||
4319 | Start a local HTTP repository browser and pull server. You can use |
|
4319 | Start a local HTTP repository browser and pull server. You can use | |
4320 | this for ad-hoc sharing and browsing of repositories. It is |
|
4320 | this for ad-hoc sharing and browsing of repositories. It is | |
4321 | recommended to use a real web server to serve a repository for |
|
4321 | recommended to use a real web server to serve a repository for | |
4322 | longer periods of time. |
|
4322 | longer periods of time. | |
4323 |
|
4323 | |||
4324 | Please note that the server does not implement access control. |
|
4324 | Please note that the server does not implement access control. | |
4325 | This means that, by default, anybody can read from the server and |
|
4325 | This means that, by default, anybody can read from the server and | |
4326 | nobody can write to it by default. Set the ``web.allow_push`` |
|
4326 | nobody can write to it by default. Set the ``web.allow_push`` | |
4327 | option to ``*`` to allow everybody to push to the server. You |
|
4327 | option to ``*`` to allow everybody to push to the server. You | |
4328 | should use a real web server if you need to authenticate users. |
|
4328 | should use a real web server if you need to authenticate users. | |
4329 |
|
4329 | |||
4330 | By default, the server logs accesses to stdout and errors to |
|
4330 | By default, the server logs accesses to stdout and errors to | |
4331 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
4331 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to | |
4332 | files. |
|
4332 | files. | |
4333 |
|
4333 | |||
4334 | To have the server choose a free port number to listen on, specify |
|
4334 | To have the server choose a free port number to listen on, specify | |
4335 | a port number of 0; in this case, the server will print the port |
|
4335 | a port number of 0; in this case, the server will print the port | |
4336 | number it uses. |
|
4336 | number it uses. | |
4337 |
|
4337 | |||
4338 | Returns 0 on success. |
|
4338 | Returns 0 on success. | |
4339 | """ |
|
4339 | """ | |
4340 |
|
4340 | |||
4341 | if opts["stdio"]: |
|
4341 | if opts["stdio"]: | |
4342 | if repo is None: |
|
4342 | if repo is None: | |
4343 | raise error.RepoError(_("There is no Mercurial repository here" |
|
4343 | raise error.RepoError(_("There is no Mercurial repository here" | |
4344 | " (.hg not found)")) |
|
4344 | " (.hg not found)")) | |
4345 | s = sshserver.sshserver(ui, repo) |
|
4345 | s = sshserver.sshserver(ui, repo) | |
4346 | s.serve_forever() |
|
4346 | s.serve_forever() | |
4347 |
|
4347 | |||
4348 | # this way we can check if something was given in the command-line |
|
4348 | # this way we can check if something was given in the command-line | |
4349 | if opts.get('port'): |
|
4349 | if opts.get('port'): | |
4350 | opts['port'] = util.getport(opts.get('port')) |
|
4350 | opts['port'] = util.getport(opts.get('port')) | |
4351 |
|
4351 | |||
4352 | baseui = repo and repo.baseui or ui |
|
4352 | baseui = repo and repo.baseui or ui | |
4353 | optlist = ("name templates style address port prefix ipv6" |
|
4353 | optlist = ("name templates style address port prefix ipv6" | |
4354 | " accesslog errorlog certificate encoding") |
|
4354 | " accesslog errorlog certificate encoding") | |
4355 | for o in optlist.split(): |
|
4355 | for o in optlist.split(): | |
4356 | val = opts.get(o, '') |
|
4356 | val = opts.get(o, '') | |
4357 | if val in (None, ''): # should check against default options instead |
|
4357 | if val in (None, ''): # should check against default options instead | |
4358 | continue |
|
4358 | continue | |
4359 | baseui.setconfig("web", o, val) |
|
4359 | baseui.setconfig("web", o, val) | |
4360 | if repo and repo.ui != baseui: |
|
4360 | if repo and repo.ui != baseui: | |
4361 | repo.ui.setconfig("web", o, val) |
|
4361 | repo.ui.setconfig("web", o, val) | |
4362 |
|
4362 | |||
4363 | o = opts.get('web_conf') or opts.get('webdir_conf') |
|
4363 | o = opts.get('web_conf') or opts.get('webdir_conf') | |
4364 | if not o: |
|
4364 | if not o: | |
4365 | if not repo: |
|
4365 | if not repo: | |
4366 | raise error.RepoError(_("There is no Mercurial repository" |
|
4366 | raise error.RepoError(_("There is no Mercurial repository" | |
4367 | " here (.hg not found)")) |
|
4367 | " here (.hg not found)")) | |
4368 | o = repo.root |
|
4368 | o = repo.root | |
4369 |
|
4369 | |||
4370 | app = hgweb.hgweb(o, baseui=ui) |
|
4370 | app = hgweb.hgweb(o, baseui=ui) | |
4371 |
|
4371 | |||
4372 | class service(object): |
|
4372 | class service(object): | |
4373 | def init(self): |
|
4373 | def init(self): | |
4374 | util.setsignalhandler() |
|
4374 | util.setsignalhandler() | |
4375 | self.httpd = hgweb.server.create_server(ui, app) |
|
4375 | self.httpd = hgweb.server.create_server(ui, app) | |
4376 |
|
4376 | |||
4377 | if opts['port'] and not ui.verbose: |
|
4377 | if opts['port'] and not ui.verbose: | |
4378 | return |
|
4378 | return | |
4379 |
|
4379 | |||
4380 | if self.httpd.prefix: |
|
4380 | if self.httpd.prefix: | |
4381 | prefix = self.httpd.prefix.strip('/') + '/' |
|
4381 | prefix = self.httpd.prefix.strip('/') + '/' | |
4382 | else: |
|
4382 | else: | |
4383 | prefix = '' |
|
4383 | prefix = '' | |
4384 |
|
4384 | |||
4385 | port = ':%d' % self.httpd.port |
|
4385 | port = ':%d' % self.httpd.port | |
4386 | if port == ':80': |
|
4386 | if port == ':80': | |
4387 | port = '' |
|
4387 | port = '' | |
4388 |
|
4388 | |||
4389 | bindaddr = self.httpd.addr |
|
4389 | bindaddr = self.httpd.addr | |
4390 | if bindaddr == '0.0.0.0': |
|
4390 | if bindaddr == '0.0.0.0': | |
4391 | bindaddr = '*' |
|
4391 | bindaddr = '*' | |
4392 | elif ':' in bindaddr: # IPv6 |
|
4392 | elif ':' in bindaddr: # IPv6 | |
4393 | bindaddr = '[%s]' % bindaddr |
|
4393 | bindaddr = '[%s]' % bindaddr | |
4394 |
|
4394 | |||
4395 | fqaddr = self.httpd.fqaddr |
|
4395 | fqaddr = self.httpd.fqaddr | |
4396 | if ':' in fqaddr: |
|
4396 | if ':' in fqaddr: | |
4397 | fqaddr = '[%s]' % fqaddr |
|
4397 | fqaddr = '[%s]' % fqaddr | |
4398 | if opts['port']: |
|
4398 | if opts['port']: | |
4399 | write = ui.status |
|
4399 | write = ui.status | |
4400 | else: |
|
4400 | else: | |
4401 | write = ui.write |
|
4401 | write = ui.write | |
4402 | write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % |
|
4402 | write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % | |
4403 | (fqaddr, port, prefix, bindaddr, self.httpd.port)) |
|
4403 | (fqaddr, port, prefix, bindaddr, self.httpd.port)) | |
4404 |
|
4404 | |||
4405 | def run(self): |
|
4405 | def run(self): | |
4406 | self.httpd.serve_forever() |
|
4406 | self.httpd.serve_forever() | |
4407 |
|
4407 | |||
4408 | service = service() |
|
4408 | service = service() | |
4409 |
|
4409 | |||
4410 | cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
4410 | cmdutil.service(opts, initfn=service.init, runfn=service.run) | |
4411 |
|
4411 | |||
4412 | @command('showconfig|debugconfig', |
|
4412 | @command('showconfig|debugconfig', | |
4413 | [('u', 'untrusted', None, _('show untrusted configuration options'))], |
|
4413 | [('u', 'untrusted', None, _('show untrusted configuration options'))], | |
4414 | _('[-u] [NAME]...')) |
|
4414 | _('[-u] [NAME]...')) | |
4415 | def showconfig(ui, repo, *values, **opts): |
|
4415 | def showconfig(ui, repo, *values, **opts): | |
4416 | """show combined config settings from all hgrc files |
|
4416 | """show combined config settings from all hgrc files | |
4417 |
|
4417 | |||
4418 | With no arguments, print names and values of all config items. |
|
4418 | With no arguments, print names and values of all config items. | |
4419 |
|
4419 | |||
4420 | With one argument of the form section.name, print just the value |
|
4420 | With one argument of the form section.name, print just the value | |
4421 | of that config item. |
|
4421 | of that config item. | |
4422 |
|
4422 | |||
4423 | With multiple arguments, print names and values of all config |
|
4423 | With multiple arguments, print names and values of all config | |
4424 | items with matching section names. |
|
4424 | items with matching section names. | |
4425 |
|
4425 | |||
4426 | With --debug, the source (filename and line number) is printed |
|
4426 | With --debug, the source (filename and line number) is printed | |
4427 | for each config item. |
|
4427 | for each config item. | |
4428 |
|
4428 | |||
4429 | Returns 0 on success. |
|
4429 | Returns 0 on success. | |
4430 | """ |
|
4430 | """ | |
4431 |
|
4431 | |||
4432 | for f in scmutil.rcpath(): |
|
4432 | for f in scmutil.rcpath(): | |
4433 | ui.debug(_('read config from: %s\n') % f) |
|
4433 | ui.debug(_('read config from: %s\n') % f) | |
4434 | untrusted = bool(opts.get('untrusted')) |
|
4434 | untrusted = bool(opts.get('untrusted')) | |
4435 | if values: |
|
4435 | if values: | |
4436 | sections = [v for v in values if '.' not in v] |
|
4436 | sections = [v for v in values if '.' not in v] | |
4437 | items = [v for v in values if '.' in v] |
|
4437 | items = [v for v in values if '.' in v] | |
4438 | if len(items) > 1 or items and sections: |
|
4438 | if len(items) > 1 or items and sections: | |
4439 | raise util.Abort(_('only one config item permitted')) |
|
4439 | raise util.Abort(_('only one config item permitted')) | |
4440 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
4440 | for section, name, value in ui.walkconfig(untrusted=untrusted): | |
4441 | value = str(value).replace('\n', '\\n') |
|
4441 | value = str(value).replace('\n', '\\n') | |
4442 | sectname = section + '.' + name |
|
4442 | sectname = section + '.' + name | |
4443 | if values: |
|
4443 | if values: | |
4444 | for v in values: |
|
4444 | for v in values: | |
4445 | if v == section: |
|
4445 | if v == section: | |
4446 | ui.debug('%s: ' % |
|
4446 | ui.debug('%s: ' % | |
4447 | ui.configsource(section, name, untrusted)) |
|
4447 | ui.configsource(section, name, untrusted)) | |
4448 | ui.write('%s=%s\n' % (sectname, value)) |
|
4448 | ui.write('%s=%s\n' % (sectname, value)) | |
4449 | elif v == sectname: |
|
4449 | elif v == sectname: | |
4450 | ui.debug('%s: ' % |
|
4450 | ui.debug('%s: ' % | |
4451 | ui.configsource(section, name, untrusted)) |
|
4451 | ui.configsource(section, name, untrusted)) | |
4452 | ui.write(value, '\n') |
|
4452 | ui.write(value, '\n') | |
4453 | else: |
|
4453 | else: | |
4454 | ui.debug('%s: ' % |
|
4454 | ui.debug('%s: ' % | |
4455 | ui.configsource(section, name, untrusted)) |
|
4455 | ui.configsource(section, name, untrusted)) | |
4456 | ui.write('%s=%s\n' % (sectname, value)) |
|
4456 | ui.write('%s=%s\n' % (sectname, value)) | |
4457 |
|
4457 | |||
4458 | @command('^status|st', |
|
4458 | @command('^status|st', | |
4459 | [('A', 'all', None, _('show status of all files')), |
|
4459 | [('A', 'all', None, _('show status of all files')), | |
4460 | ('m', 'modified', None, _('show only modified files')), |
|
4460 | ('m', 'modified', None, _('show only modified files')), | |
4461 | ('a', 'added', None, _('show only added files')), |
|
4461 | ('a', 'added', None, _('show only added files')), | |
4462 | ('r', 'removed', None, _('show only removed files')), |
|
4462 | ('r', 'removed', None, _('show only removed files')), | |
4463 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
4463 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
4464 | ('c', 'clean', None, _('show only files without changes')), |
|
4464 | ('c', 'clean', None, _('show only files without changes')), | |
4465 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
4465 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
4466 | ('i', 'ignored', None, _('show only ignored files')), |
|
4466 | ('i', 'ignored', None, _('show only ignored files')), | |
4467 | ('n', 'no-status', None, _('hide status prefix')), |
|
4467 | ('n', 'no-status', None, _('hide status prefix')), | |
4468 | ('C', 'copies', None, _('show source of copied files')), |
|
4468 | ('C', 'copies', None, _('show source of copied files')), | |
4469 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
4469 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), | |
4470 | ('', 'rev', [], _('show difference from revision'), _('REV')), |
|
4470 | ('', 'rev', [], _('show difference from revision'), _('REV')), | |
4471 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), |
|
4471 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), | |
4472 | ] + walkopts + subrepoopts, |
|
4472 | ] + walkopts + subrepoopts, | |
4473 | _('[OPTION]... [FILE]...')) |
|
4473 | _('[OPTION]... [FILE]...')) | |
4474 | def status(ui, repo, *pats, **opts): |
|
4474 | def status(ui, repo, *pats, **opts): | |
4475 | """show changed files in the working directory |
|
4475 | """show changed files in the working directory | |
4476 |
|
4476 | |||
4477 | Show status of files in the repository. If names are given, only |
|
4477 | Show status of files in the repository. If names are given, only | |
4478 | files that match are shown. Files that are clean or ignored or |
|
4478 | files that match are shown. Files that are clean or ignored or | |
4479 | the source of a copy/move operation, are not listed unless |
|
4479 | the source of a copy/move operation, are not listed unless | |
4480 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
4480 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. | |
4481 | Unless options described with "show only ..." are given, the |
|
4481 | Unless options described with "show only ..." are given, the | |
4482 | options -mardu are used. |
|
4482 | options -mardu are used. | |
4483 |
|
4483 | |||
4484 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
4484 | Option -q/--quiet hides untracked (unknown and ignored) files | |
4485 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
4485 | unless explicitly requested with -u/--unknown or -i/--ignored. | |
4486 |
|
4486 | |||
4487 | .. note:: |
|
4487 | .. note:: | |
4488 | status may appear to disagree with diff if permissions have |
|
4488 | status may appear to disagree with diff if permissions have | |
4489 | changed or a merge has occurred. The standard diff format does |
|
4489 | changed or a merge has occurred. The standard diff format does | |
4490 | not report permission changes and diff only reports changes |
|
4490 | not report permission changes and diff only reports changes | |
4491 | relative to one merge parent. |
|
4491 | relative to one merge parent. | |
4492 |
|
4492 | |||
4493 | If one revision is given, it is used as the base revision. |
|
4493 | If one revision is given, it is used as the base revision. | |
4494 | If two revisions are given, the differences between them are |
|
4494 | If two revisions are given, the differences between them are | |
4495 | shown. The --change option can also be used as a shortcut to list |
|
4495 | shown. The --change option can also be used as a shortcut to list | |
4496 | the changed files of a revision from its first parent. |
|
4496 | the changed files of a revision from its first parent. | |
4497 |
|
4497 | |||
4498 | The codes used to show the status of files are:: |
|
4498 | The codes used to show the status of files are:: | |
4499 |
|
4499 | |||
4500 | M = modified |
|
4500 | M = modified | |
4501 | A = added |
|
4501 | A = added | |
4502 | R = removed |
|
4502 | R = removed | |
4503 | C = clean |
|
4503 | C = clean | |
4504 | ! = missing (deleted by non-hg command, but still tracked) |
|
4504 | ! = missing (deleted by non-hg command, but still tracked) | |
4505 | ? = not tracked |
|
4505 | ? = not tracked | |
4506 | I = ignored |
|
4506 | I = ignored | |
4507 | = origin of the previous file listed as A (added) |
|
4507 | = origin of the previous file listed as A (added) | |
4508 |
|
4508 | |||
4509 | Returns 0 on success. |
|
4509 | Returns 0 on success. | |
4510 | """ |
|
4510 | """ | |
4511 |
|
4511 | |||
4512 | revs = opts.get('rev') |
|
4512 | revs = opts.get('rev') | |
4513 | change = opts.get('change') |
|
4513 | change = opts.get('change') | |
4514 |
|
4514 | |||
4515 | if revs and change: |
|
4515 | if revs and change: | |
4516 | msg = _('cannot specify --rev and --change at the same time') |
|
4516 | msg = _('cannot specify --rev and --change at the same time') | |
4517 | raise util.Abort(msg) |
|
4517 | raise util.Abort(msg) | |
4518 | elif change: |
|
4518 | elif change: | |
4519 | node2 = repo.lookup(change) |
|
4519 | node2 = repo.lookup(change) | |
4520 | node1 = repo[node2].p1().node() |
|
4520 | node1 = repo[node2].p1().node() | |
4521 | else: |
|
4521 | else: | |
4522 | node1, node2 = scmutil.revpair(repo, revs) |
|
4522 | node1, node2 = scmutil.revpair(repo, revs) | |
4523 |
|
4523 | |||
4524 | cwd = (pats and repo.getcwd()) or '' |
|
4524 | cwd = (pats and repo.getcwd()) or '' | |
4525 | end = opts.get('print0') and '\0' or '\n' |
|
4525 | end = opts.get('print0') and '\0' or '\n' | |
4526 | copy = {} |
|
4526 | copy = {} | |
4527 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
4527 | states = 'modified added removed deleted unknown ignored clean'.split() | |
4528 | show = [k for k in states if opts.get(k)] |
|
4528 | show = [k for k in states if opts.get(k)] | |
4529 | if opts.get('all'): |
|
4529 | if opts.get('all'): | |
4530 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
4530 | show += ui.quiet and (states[:4] + ['clean']) or states | |
4531 | if not show: |
|
4531 | if not show: | |
4532 | show = ui.quiet and states[:4] or states[:5] |
|
4532 | show = ui.quiet and states[:4] or states[:5] | |
4533 |
|
4533 | |||
4534 | stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts), |
|
4534 | stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts), | |
4535 | 'ignored' in show, 'clean' in show, 'unknown' in show, |
|
4535 | 'ignored' in show, 'clean' in show, 'unknown' in show, | |
4536 | opts.get('subrepos')) |
|
4536 | opts.get('subrepos')) | |
4537 | changestates = zip(states, 'MAR!?IC', stat) |
|
4537 | changestates = zip(states, 'MAR!?IC', stat) | |
4538 |
|
4538 | |||
4539 | if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): |
|
4539 | if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): | |
4540 | ctxn = repo[nullid] |
|
4540 | ctxn = repo[nullid] | |
4541 | ctx1 = repo[node1] |
|
4541 | ctx1 = repo[node1] | |
4542 | ctx2 = repo[node2] |
|
4542 | ctx2 = repo[node2] | |
4543 | added = stat[1] |
|
4543 | added = stat[1] | |
4544 | if node2 is None: |
|
4544 | if node2 is None: | |
4545 | added = stat[0] + stat[1] # merged? |
|
4545 | added = stat[0] + stat[1] # merged? | |
4546 |
|
4546 | |||
4547 | for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems(): |
|
4547 | for k, v in copies.copies(repo, ctx1, ctx2, ctxn)[0].iteritems(): | |
4548 | if k in added: |
|
4548 | if k in added: | |
4549 | copy[k] = v |
|
4549 | copy[k] = v | |
4550 | elif v in added: |
|
4550 | elif v in added: | |
4551 | copy[v] = k |
|
4551 | copy[v] = k | |
4552 |
|
4552 | |||
4553 | for state, char, files in changestates: |
|
4553 | for state, char, files in changestates: | |
4554 | if state in show: |
|
4554 | if state in show: | |
4555 | format = "%s %%s%s" % (char, end) |
|
4555 | format = "%s %%s%s" % (char, end) | |
4556 | if opts.get('no_status'): |
|
4556 | if opts.get('no_status'): | |
4557 | format = "%%s%s" % end |
|
4557 | format = "%%s%s" % end | |
4558 |
|
4558 | |||
4559 | for f in files: |
|
4559 | for f in files: | |
4560 | ui.write(format % repo.pathto(f, cwd), |
|
4560 | ui.write(format % repo.pathto(f, cwd), | |
4561 | label='status.' + state) |
|
4561 | label='status.' + state) | |
4562 | if f in copy: |
|
4562 | if f in copy: | |
4563 | ui.write(' %s%s' % (repo.pathto(copy[f], cwd), end), |
|
4563 | ui.write(' %s%s' % (repo.pathto(copy[f], cwd), end), | |
4564 | label='status.copied') |
|
4564 | label='status.copied') | |
4565 |
|
4565 | |||
4566 | @command('^summary|sum', |
|
4566 | @command('^summary|sum', | |
4567 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') |
|
4567 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') | |
4568 | def summary(ui, repo, **opts): |
|
4568 | def summary(ui, repo, **opts): | |
4569 | """summarize working directory state |
|
4569 | """summarize working directory state | |
4570 |
|
4570 | |||
4571 | This generates a brief summary of the working directory state, |
|
4571 | This generates a brief summary of the working directory state, | |
4572 | including parents, branch, commit status, and available updates. |
|
4572 | including parents, branch, commit status, and available updates. | |
4573 |
|
4573 | |||
4574 | With the --remote option, this will check the default paths for |
|
4574 | With the --remote option, this will check the default paths for | |
4575 | incoming and outgoing changes. This can be time-consuming. |
|
4575 | incoming and outgoing changes. This can be time-consuming. | |
4576 |
|
4576 | |||
4577 | Returns 0 on success. |
|
4577 | Returns 0 on success. | |
4578 | """ |
|
4578 | """ | |
4579 |
|
4579 | |||
4580 | ctx = repo[None] |
|
4580 | ctx = repo[None] | |
4581 | parents = ctx.parents() |
|
4581 | parents = ctx.parents() | |
4582 | pnode = parents[0].node() |
|
4582 | pnode = parents[0].node() | |
4583 |
|
4583 | |||
4584 | for p in parents: |
|
4584 | for p in parents: | |
4585 | # label with log.changeset (instead of log.parent) since this |
|
4585 | # label with log.changeset (instead of log.parent) since this | |
4586 | # shows a working directory parent *changeset*: |
|
4586 | # shows a working directory parent *changeset*: | |
4587 | ui.write(_('parent: %d:%s ') % (p.rev(), str(p)), |
|
4587 | ui.write(_('parent: %d:%s ') % (p.rev(), str(p)), | |
4588 | label='log.changeset') |
|
4588 | label='log.changeset') | |
4589 | ui.write(' '.join(p.tags()), label='log.tag') |
|
4589 | ui.write(' '.join(p.tags()), label='log.tag') | |
4590 | if p.bookmarks(): |
|
4590 | if p.bookmarks(): | |
4591 | ui.write(' ' + ' '.join(p.bookmarks()), label='log.bookmark') |
|
4591 | ui.write(' ' + ' '.join(p.bookmarks()), label='log.bookmark') | |
4592 | if p.rev() == -1: |
|
4592 | if p.rev() == -1: | |
4593 | if not len(repo): |
|
4593 | if not len(repo): | |
4594 | ui.write(_(' (empty repository)')) |
|
4594 | ui.write(_(' (empty repository)')) | |
4595 | else: |
|
4595 | else: | |
4596 | ui.write(_(' (no revision checked out)')) |
|
4596 | ui.write(_(' (no revision checked out)')) | |
4597 | ui.write('\n') |
|
4597 | ui.write('\n') | |
4598 | if p.description(): |
|
4598 | if p.description(): | |
4599 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', |
|
4599 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', | |
4600 | label='log.summary') |
|
4600 | label='log.summary') | |
4601 |
|
4601 | |||
4602 | branch = ctx.branch() |
|
4602 | branch = ctx.branch() | |
4603 | bheads = repo.branchheads(branch) |
|
4603 | bheads = repo.branchheads(branch) | |
4604 | m = _('branch: %s\n') % branch |
|
4604 | m = _('branch: %s\n') % branch | |
4605 | if branch != 'default': |
|
4605 | if branch != 'default': | |
4606 | ui.write(m, label='log.branch') |
|
4606 | ui.write(m, label='log.branch') | |
4607 | else: |
|
4607 | else: | |
4608 | ui.status(m, label='log.branch') |
|
4608 | ui.status(m, label='log.branch') | |
4609 |
|
4609 | |||
4610 | st = list(repo.status(unknown=True))[:6] |
|
4610 | st = list(repo.status(unknown=True))[:6] | |
4611 |
|
4611 | |||
4612 | c = repo.dirstate.copies() |
|
4612 | c = repo.dirstate.copies() | |
4613 | copied, renamed = [], [] |
|
4613 | copied, renamed = [], [] | |
4614 | for d, s in c.iteritems(): |
|
4614 | for d, s in c.iteritems(): | |
4615 | if s in st[2]: |
|
4615 | if s in st[2]: | |
4616 | st[2].remove(s) |
|
4616 | st[2].remove(s) | |
4617 | renamed.append(d) |
|
4617 | renamed.append(d) | |
4618 | else: |
|
4618 | else: | |
4619 | copied.append(d) |
|
4619 | copied.append(d) | |
4620 | if d in st[1]: |
|
4620 | if d in st[1]: | |
4621 | st[1].remove(d) |
|
4621 | st[1].remove(d) | |
4622 | st.insert(3, renamed) |
|
4622 | st.insert(3, renamed) | |
4623 | st.insert(4, copied) |
|
4623 | st.insert(4, copied) | |
4624 |
|
4624 | |||
4625 | ms = mergemod.mergestate(repo) |
|
4625 | ms = mergemod.mergestate(repo) | |
4626 | st.append([f for f in ms if ms[f] == 'u']) |
|
4626 | st.append([f for f in ms if ms[f] == 'u']) | |
4627 |
|
4627 | |||
4628 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
4628 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] | |
4629 | st.append(subs) |
|
4629 | st.append(subs) | |
4630 |
|
4630 | |||
4631 | labels = [ui.label(_('%d modified'), 'status.modified'), |
|
4631 | labels = [ui.label(_('%d modified'), 'status.modified'), | |
4632 | ui.label(_('%d added'), 'status.added'), |
|
4632 | ui.label(_('%d added'), 'status.added'), | |
4633 | ui.label(_('%d removed'), 'status.removed'), |
|
4633 | ui.label(_('%d removed'), 'status.removed'), | |
4634 | ui.label(_('%d renamed'), 'status.copied'), |
|
4634 | ui.label(_('%d renamed'), 'status.copied'), | |
4635 | ui.label(_('%d copied'), 'status.copied'), |
|
4635 | ui.label(_('%d copied'), 'status.copied'), | |
4636 | ui.label(_('%d deleted'), 'status.deleted'), |
|
4636 | ui.label(_('%d deleted'), 'status.deleted'), | |
4637 | ui.label(_('%d unknown'), 'status.unknown'), |
|
4637 | ui.label(_('%d unknown'), 'status.unknown'), | |
4638 | ui.label(_('%d ignored'), 'status.ignored'), |
|
4638 | ui.label(_('%d ignored'), 'status.ignored'), | |
4639 | ui.label(_('%d unresolved'), 'resolve.unresolved'), |
|
4639 | ui.label(_('%d unresolved'), 'resolve.unresolved'), | |
4640 | ui.label(_('%d subrepos'), 'status.modified')] |
|
4640 | ui.label(_('%d subrepos'), 'status.modified')] | |
4641 | t = [] |
|
4641 | t = [] | |
4642 | for s, l in zip(st, labels): |
|
4642 | for s, l in zip(st, labels): | |
4643 | if s: |
|
4643 | if s: | |
4644 | t.append(l % len(s)) |
|
4644 | t.append(l % len(s)) | |
4645 |
|
4645 | |||
4646 | t = ', '.join(t) |
|
4646 | t = ', '.join(t) | |
4647 | cleanworkdir = False |
|
4647 | cleanworkdir = False | |
4648 |
|
4648 | |||
4649 | if len(parents) > 1: |
|
4649 | if len(parents) > 1: | |
4650 | t += _(' (merge)') |
|
4650 | t += _(' (merge)') | |
4651 | elif branch != parents[0].branch(): |
|
4651 | elif branch != parents[0].branch(): | |
4652 | t += _(' (new branch)') |
|
4652 | t += _(' (new branch)') | |
4653 | elif (parents[0].extra().get('close') and |
|
4653 | elif (parents[0].extra().get('close') and | |
4654 | pnode in repo.branchheads(branch, closed=True)): |
|
4654 | pnode in repo.branchheads(branch, closed=True)): | |
4655 | t += _(' (head closed)') |
|
4655 | t += _(' (head closed)') | |
4656 | elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]): |
|
4656 | elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]): | |
4657 | t += _(' (clean)') |
|
4657 | t += _(' (clean)') | |
4658 | cleanworkdir = True |
|
4658 | cleanworkdir = True | |
4659 | elif pnode not in bheads: |
|
4659 | elif pnode not in bheads: | |
4660 | t += _(' (new branch head)') |
|
4660 | t += _(' (new branch head)') | |
4661 |
|
4661 | |||
4662 | if cleanworkdir: |
|
4662 | if cleanworkdir: | |
4663 | ui.status(_('commit: %s\n') % t.strip()) |
|
4663 | ui.status(_('commit: %s\n') % t.strip()) | |
4664 | else: |
|
4664 | else: | |
4665 | ui.write(_('commit: %s\n') % t.strip()) |
|
4665 | ui.write(_('commit: %s\n') % t.strip()) | |
4666 |
|
4666 | |||
4667 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
4667 | # all ancestors of branch heads - all ancestors of parent = new csets | |
4668 | new = [0] * len(repo) |
|
4668 | new = [0] * len(repo) | |
4669 | cl = repo.changelog |
|
4669 | cl = repo.changelog | |
4670 | for a in [cl.rev(n) for n in bheads]: |
|
4670 | for a in [cl.rev(n) for n in bheads]: | |
4671 | new[a] = 1 |
|
4671 | new[a] = 1 | |
4672 | for a in cl.ancestors(*[cl.rev(n) for n in bheads]): |
|
4672 | for a in cl.ancestors(*[cl.rev(n) for n in bheads]): | |
4673 | new[a] = 1 |
|
4673 | new[a] = 1 | |
4674 | for a in [p.rev() for p in parents]: |
|
4674 | for a in [p.rev() for p in parents]: | |
4675 | if a >= 0: |
|
4675 | if a >= 0: | |
4676 | new[a] = 0 |
|
4676 | new[a] = 0 | |
4677 | for a in cl.ancestors(*[p.rev() for p in parents]): |
|
4677 | for a in cl.ancestors(*[p.rev() for p in parents]): | |
4678 | new[a] = 0 |
|
4678 | new[a] = 0 | |
4679 | new = sum(new) |
|
4679 | new = sum(new) | |
4680 |
|
4680 | |||
4681 | if new == 0: |
|
4681 | if new == 0: | |
4682 | ui.status(_('update: (current)\n')) |
|
4682 | ui.status(_('update: (current)\n')) | |
4683 | elif pnode not in bheads: |
|
4683 | elif pnode not in bheads: | |
4684 | ui.write(_('update: %d new changesets (update)\n') % new) |
|
4684 | ui.write(_('update: %d new changesets (update)\n') % new) | |
4685 | else: |
|
4685 | else: | |
4686 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % |
|
4686 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % | |
4687 | (new, len(bheads))) |
|
4687 | (new, len(bheads))) | |
4688 |
|
4688 | |||
4689 | if opts.get('remote'): |
|
4689 | if opts.get('remote'): | |
4690 | t = [] |
|
4690 | t = [] | |
4691 | source, branches = hg.parseurl(ui.expandpath('default')) |
|
4691 | source, branches = hg.parseurl(ui.expandpath('default')) | |
4692 | other = hg.repository(hg.remoteui(repo, {}), source) |
|
4692 | other = hg.repository(hg.remoteui(repo, {}), source) | |
4693 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) |
|
4693 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) | |
4694 | ui.debug('comparing with %s\n' % util.hidepassword(source)) |
|
4694 | ui.debug('comparing with %s\n' % util.hidepassword(source)) | |
4695 | repo.ui.pushbuffer() |
|
4695 | repo.ui.pushbuffer() | |
4696 | commoninc = discovery.findcommonincoming(repo, other) |
|
4696 | commoninc = discovery.findcommonincoming(repo, other) | |
4697 | _common, incoming, _rheads = commoninc |
|
4697 | _common, incoming, _rheads = commoninc | |
4698 | repo.ui.popbuffer() |
|
4698 | repo.ui.popbuffer() | |
4699 | if incoming: |
|
4699 | if incoming: | |
4700 | t.append(_('1 or more incoming')) |
|
4700 | t.append(_('1 or more incoming')) | |
4701 |
|
4701 | |||
4702 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) |
|
4702 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) | |
4703 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
4703 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | |
4704 | if source != dest: |
|
4704 | if source != dest: | |
4705 | other = hg.repository(hg.remoteui(repo, {}), dest) |
|
4705 | other = hg.repository(hg.remoteui(repo, {}), dest) | |
4706 | commoninc = None |
|
4706 | commoninc = None | |
4707 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) |
|
4707 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) | |
4708 | repo.ui.pushbuffer() |
|
4708 | repo.ui.pushbuffer() | |
4709 | common, outheads = discovery.findcommonoutgoing(repo, other, |
|
4709 | common, outheads = discovery.findcommonoutgoing(repo, other, | |
4710 | commoninc=commoninc) |
|
4710 | commoninc=commoninc) | |
4711 | repo.ui.popbuffer() |
|
4711 | repo.ui.popbuffer() | |
4712 | o = repo.changelog.findmissing(common=common, heads=outheads) |
|
4712 | o = repo.changelog.findmissing(common=common, heads=outheads) | |
4713 | if o: |
|
4713 | if o: | |
4714 | t.append(_('%d outgoing') % len(o)) |
|
4714 | t.append(_('%d outgoing') % len(o)) | |
4715 | if 'bookmarks' in other.listkeys('namespaces'): |
|
4715 | if 'bookmarks' in other.listkeys('namespaces'): | |
4716 | lmarks = repo.listkeys('bookmarks') |
|
4716 | lmarks = repo.listkeys('bookmarks') | |
4717 | rmarks = other.listkeys('bookmarks') |
|
4717 | rmarks = other.listkeys('bookmarks') | |
4718 | diff = set(rmarks) - set(lmarks) |
|
4718 | diff = set(rmarks) - set(lmarks) | |
4719 | if len(diff) > 0: |
|
4719 | if len(diff) > 0: | |
4720 | t.append(_('%d incoming bookmarks') % len(diff)) |
|
4720 | t.append(_('%d incoming bookmarks') % len(diff)) | |
4721 | diff = set(lmarks) - set(rmarks) |
|
4721 | diff = set(lmarks) - set(rmarks) | |
4722 | if len(diff) > 0: |
|
4722 | if len(diff) > 0: | |
4723 | t.append(_('%d outgoing bookmarks') % len(diff)) |
|
4723 | t.append(_('%d outgoing bookmarks') % len(diff)) | |
4724 |
|
4724 | |||
4725 | if t: |
|
4725 | if t: | |
4726 | ui.write(_('remote: %s\n') % (', '.join(t))) |
|
4726 | ui.write(_('remote: %s\n') % (', '.join(t))) | |
4727 | else: |
|
4727 | else: | |
4728 | ui.status(_('remote: (synced)\n')) |
|
4728 | ui.status(_('remote: (synced)\n')) | |
4729 |
|
4729 | |||
4730 | @command('tag', |
|
4730 | @command('tag', | |
4731 | [('f', 'force', None, _('force tag')), |
|
4731 | [('f', 'force', None, _('force tag')), | |
4732 | ('l', 'local', None, _('make the tag local')), |
|
4732 | ('l', 'local', None, _('make the tag local')), | |
4733 | ('r', 'rev', '', _('revision to tag'), _('REV')), |
|
4733 | ('r', 'rev', '', _('revision to tag'), _('REV')), | |
4734 | ('', 'remove', None, _('remove a tag')), |
|
4734 | ('', 'remove', None, _('remove a tag')), | |
4735 | # -l/--local is already there, commitopts cannot be used |
|
4735 | # -l/--local is already there, commitopts cannot be used | |
4736 | ('e', 'edit', None, _('edit commit message')), |
|
4736 | ('e', 'edit', None, _('edit commit message')), | |
4737 | ('m', 'message', '', _('use <text> as commit message'), _('TEXT')), |
|
4737 | ('m', 'message', '', _('use <text> as commit message'), _('TEXT')), | |
4738 | ] + commitopts2, |
|
4738 | ] + commitopts2, | |
4739 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) |
|
4739 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) | |
4740 | def tag(ui, repo, name1, *names, **opts): |
|
4740 | def tag(ui, repo, name1, *names, **opts): | |
4741 | """add one or more tags for the current or given revision |
|
4741 | """add one or more tags for the current or given revision | |
4742 |
|
4742 | |||
4743 | Name a particular revision using <name>. |
|
4743 | Name a particular revision using <name>. | |
4744 |
|
4744 | |||
4745 | Tags are used to name particular revisions of the repository and are |
|
4745 | Tags are used to name particular revisions of the repository and are | |
4746 | very useful to compare different revisions, to go back to significant |
|
4746 | very useful to compare different revisions, to go back to significant | |
4747 | earlier versions or to mark branch points as releases, etc. Changing |
|
4747 | earlier versions or to mark branch points as releases, etc. Changing | |
4748 | an existing tag is normally disallowed; use -f/--force to override. |
|
4748 | an existing tag is normally disallowed; use -f/--force to override. | |
4749 |
|
4749 | |||
4750 | If no revision is given, the parent of the working directory is |
|
4750 | If no revision is given, the parent of the working directory is | |
4751 | used, or tip if no revision is checked out. |
|
4751 | used, or tip if no revision is checked out. | |
4752 |
|
4752 | |||
4753 | To facilitate version control, distribution, and merging of tags, |
|
4753 | To facilitate version control, distribution, and merging of tags, | |
4754 | they are stored as a file named ".hgtags" which is managed similarly |
|
4754 | they are stored as a file named ".hgtags" which is managed similarly | |
4755 | to other project files and can be hand-edited if necessary. This |
|
4755 | to other project files and can be hand-edited if necessary. This | |
4756 | also means that tagging creates a new commit. The file |
|
4756 | also means that tagging creates a new commit. The file | |
4757 | ".hg/localtags" is used for local tags (not shared among |
|
4757 | ".hg/localtags" is used for local tags (not shared among | |
4758 | repositories). |
|
4758 | repositories). | |
4759 |
|
4759 | |||
4760 | Tag commits are usually made at the head of a branch. If the parent |
|
4760 | Tag commits are usually made at the head of a branch. If the parent | |
4761 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
4761 | of the working directory is not a branch head, :hg:`tag` aborts; use | |
4762 | -f/--force to force the tag commit to be based on a non-head |
|
4762 | -f/--force to force the tag commit to be based on a non-head | |
4763 | changeset. |
|
4763 | changeset. | |
4764 |
|
4764 | |||
4765 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4765 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
4766 |
|
4766 | |||
4767 | Since tag names have priority over branch names during revision |
|
4767 | Since tag names have priority over branch names during revision | |
4768 | lookup, using an existing branch name as a tag name is discouraged. |
|
4768 | lookup, using an existing branch name as a tag name is discouraged. | |
4769 |
|
4769 | |||
4770 | Returns 0 on success. |
|
4770 | Returns 0 on success. | |
4771 | """ |
|
4771 | """ | |
4772 |
|
4772 | |||
4773 | rev_ = "." |
|
4773 | rev_ = "." | |
4774 | names = [t.strip() for t in (name1,) + names] |
|
4774 | names = [t.strip() for t in (name1,) + names] | |
4775 | if len(names) != len(set(names)): |
|
4775 | if len(names) != len(set(names)): | |
4776 | raise util.Abort(_('tag names must be unique')) |
|
4776 | raise util.Abort(_('tag names must be unique')) | |
4777 | for n in names: |
|
4777 | for n in names: | |
4778 | if n in ['tip', '.', 'null']: |
|
4778 | if n in ['tip', '.', 'null']: | |
4779 | raise util.Abort(_("the name '%s' is reserved") % n) |
|
4779 | raise util.Abort(_("the name '%s' is reserved") % n) | |
4780 | if not n: |
|
4780 | if not n: | |
4781 | raise util.Abort(_('tag names cannot consist entirely of whitespace')) |
|
4781 | raise util.Abort(_('tag names cannot consist entirely of whitespace')) | |
4782 | if opts.get('rev') and opts.get('remove'): |
|
4782 | if opts.get('rev') and opts.get('remove'): | |
4783 | raise util.Abort(_("--rev and --remove are incompatible")) |
|
4783 | raise util.Abort(_("--rev and --remove are incompatible")) | |
4784 | if opts.get('rev'): |
|
4784 | if opts.get('rev'): | |
4785 | rev_ = opts['rev'] |
|
4785 | rev_ = opts['rev'] | |
4786 | message = opts.get('message') |
|
4786 | message = opts.get('message') | |
4787 | if opts.get('remove'): |
|
4787 | if opts.get('remove'): | |
4788 | expectedtype = opts.get('local') and 'local' or 'global' |
|
4788 | expectedtype = opts.get('local') and 'local' or 'global' | |
4789 | for n in names: |
|
4789 | for n in names: | |
4790 | if not repo.tagtype(n): |
|
4790 | if not repo.tagtype(n): | |
4791 | raise util.Abort(_("tag '%s' does not exist") % n) |
|
4791 | raise util.Abort(_("tag '%s' does not exist") % n) | |
4792 | if repo.tagtype(n) != expectedtype: |
|
4792 | if repo.tagtype(n) != expectedtype: | |
4793 | if expectedtype == 'global': |
|
4793 | if expectedtype == 'global': | |
4794 | raise util.Abort(_("tag '%s' is not a global tag") % n) |
|
4794 | raise util.Abort(_("tag '%s' is not a global tag") % n) | |
4795 | else: |
|
4795 | else: | |
4796 | raise util.Abort(_("tag '%s' is not a local tag") % n) |
|
4796 | raise util.Abort(_("tag '%s' is not a local tag") % n) | |
4797 | rev_ = nullid |
|
4797 | rev_ = nullid | |
4798 | if not message: |
|
4798 | if not message: | |
4799 | # we don't translate commit messages |
|
4799 | # we don't translate commit messages | |
4800 | message = 'Removed tag %s' % ', '.join(names) |
|
4800 | message = 'Removed tag %s' % ', '.join(names) | |
4801 | elif not opts.get('force'): |
|
4801 | elif not opts.get('force'): | |
4802 | for n in names: |
|
4802 | for n in names: | |
4803 | if n in repo.tags(): |
|
4803 | if n in repo.tags(): | |
4804 | raise util.Abort(_("tag '%s' already exists " |
|
4804 | raise util.Abort(_("tag '%s' already exists " | |
4805 | "(use -f to force)") % n) |
|
4805 | "(use -f to force)") % n) | |
4806 | if not opts.get('local'): |
|
4806 | if not opts.get('local'): | |
4807 | p1, p2 = repo.dirstate.parents() |
|
4807 | p1, p2 = repo.dirstate.parents() | |
4808 | if p2 != nullid: |
|
4808 | if p2 != nullid: | |
4809 | raise util.Abort(_('uncommitted merge')) |
|
4809 | raise util.Abort(_('uncommitted merge')) | |
4810 | bheads = repo.branchheads() |
|
4810 | bheads = repo.branchheads() | |
4811 | if not opts.get('force') and bheads and p1 not in bheads: |
|
4811 | if not opts.get('force') and bheads and p1 not in bheads: | |
4812 | raise util.Abort(_('not at a branch head (use -f to force)')) |
|
4812 | raise util.Abort(_('not at a branch head (use -f to force)')) | |
4813 | r = scmutil.revsingle(repo, rev_).node() |
|
4813 | r = scmutil.revsingle(repo, rev_).node() | |
4814 |
|
4814 | |||
4815 | if not message: |
|
4815 | if not message: | |
4816 | # we don't translate commit messages |
|
4816 | # we don't translate commit messages | |
4817 | message = ('Added tag %s for changeset %s' % |
|
4817 | message = ('Added tag %s for changeset %s' % | |
4818 | (', '.join(names), short(r))) |
|
4818 | (', '.join(names), short(r))) | |
4819 |
|
4819 | |||
4820 | date = opts.get('date') |
|
4820 | date = opts.get('date') | |
4821 | if date: |
|
4821 | if date: | |
4822 | date = util.parsedate(date) |
|
4822 | date = util.parsedate(date) | |
4823 |
|
4823 | |||
4824 | if opts.get('edit'): |
|
4824 | if opts.get('edit'): | |
4825 | message = ui.edit(message, ui.username()) |
|
4825 | message = ui.edit(message, ui.username()) | |
4826 |
|
4826 | |||
4827 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date) |
|
4827 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date) | |
4828 |
|
4828 | |||
4829 | @command('tags', [], '') |
|
4829 | @command('tags', [], '') | |
4830 | def tags(ui, repo): |
|
4830 | def tags(ui, repo): | |
4831 | """list repository tags |
|
4831 | """list repository tags | |
4832 |
|
4832 | |||
4833 | This lists both regular and local tags. When the -v/--verbose |
|
4833 | This lists both regular and local tags. When the -v/--verbose | |
4834 | switch is used, a third column "local" is printed for local tags. |
|
4834 | switch is used, a third column "local" is printed for local tags. | |
4835 |
|
4835 | |||
4836 | Returns 0 on success. |
|
4836 | Returns 0 on success. | |
4837 | """ |
|
4837 | """ | |
4838 |
|
4838 | |||
4839 | hexfunc = ui.debugflag and hex or short |
|
4839 | hexfunc = ui.debugflag and hex or short | |
4840 | tagtype = "" |
|
4840 | tagtype = "" | |
4841 |
|
4841 | |||
4842 | for t, n in reversed(repo.tagslist()): |
|
4842 | for t, n in reversed(repo.tagslist()): | |
4843 | if ui.quiet: |
|
4843 | if ui.quiet: | |
4844 | ui.write("%s\n" % t) |
|
4844 | ui.write("%s\n" % t) | |
4845 | continue |
|
4845 | continue | |
4846 |
|
4846 | |||
4847 | hn = hexfunc(n) |
|
4847 | hn = hexfunc(n) | |
4848 | r = "%5d:%s" % (repo.changelog.rev(n), hn) |
|
4848 | r = "%5d:%s" % (repo.changelog.rev(n), hn) | |
4849 | spaces = " " * (30 - encoding.colwidth(t)) |
|
4849 | spaces = " " * (30 - encoding.colwidth(t)) | |
4850 |
|
4850 | |||
4851 | if ui.verbose: |
|
4851 | if ui.verbose: | |
4852 | if repo.tagtype(t) == 'local': |
|
4852 | if repo.tagtype(t) == 'local': | |
4853 | tagtype = " local" |
|
4853 | tagtype = " local" | |
4854 | else: |
|
4854 | else: | |
4855 | tagtype = "" |
|
4855 | tagtype = "" | |
4856 | ui.write("%s%s %s%s\n" % (t, spaces, r, tagtype)) |
|
4856 | ui.write("%s%s %s%s\n" % (t, spaces, r, tagtype)) | |
4857 |
|
4857 | |||
4858 | @command('tip', |
|
4858 | @command('tip', | |
4859 | [('p', 'patch', None, _('show patch')), |
|
4859 | [('p', 'patch', None, _('show patch')), | |
4860 | ('g', 'git', None, _('use git extended diff format')), |
|
4860 | ('g', 'git', None, _('use git extended diff format')), | |
4861 | ] + templateopts, |
|
4861 | ] + templateopts, | |
4862 | _('[-p] [-g]')) |
|
4862 | _('[-p] [-g]')) | |
4863 | def tip(ui, repo, **opts): |
|
4863 | def tip(ui, repo, **opts): | |
4864 | """show the tip revision |
|
4864 | """show the tip revision | |
4865 |
|
4865 | |||
4866 | The tip revision (usually just called the tip) is the changeset |
|
4866 | The tip revision (usually just called the tip) is the changeset | |
4867 | most recently added to the repository (and therefore the most |
|
4867 | most recently added to the repository (and therefore the most | |
4868 | recently changed head). |
|
4868 | recently changed head). | |
4869 |
|
4869 | |||
4870 | If you have just made a commit, that commit will be the tip. If |
|
4870 | If you have just made a commit, that commit will be the tip. If | |
4871 | you have just pulled changes from another repository, the tip of |
|
4871 | you have just pulled changes from another repository, the tip of | |
4872 | that repository becomes the current tip. The "tip" tag is special |
|
4872 | that repository becomes the current tip. The "tip" tag is special | |
4873 | and cannot be renamed or assigned to a different changeset. |
|
4873 | and cannot be renamed or assigned to a different changeset. | |
4874 |
|
4874 | |||
4875 | Returns 0 on success. |
|
4875 | Returns 0 on success. | |
4876 | """ |
|
4876 | """ | |
4877 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
4877 | displayer = cmdutil.show_changeset(ui, repo, opts) | |
4878 | displayer.show(repo[len(repo) - 1]) |
|
4878 | displayer.show(repo[len(repo) - 1]) | |
4879 | displayer.close() |
|
4879 | displayer.close() | |
4880 |
|
4880 | |||
4881 | @command('unbundle', |
|
4881 | @command('unbundle', | |
4882 | [('u', 'update', None, |
|
4882 | [('u', 'update', None, | |
4883 | _('update to new branch head if changesets were unbundled'))], |
|
4883 | _('update to new branch head if changesets were unbundled'))], | |
4884 | _('[-u] FILE...')) |
|
4884 | _('[-u] FILE...')) | |
4885 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
4885 | def unbundle(ui, repo, fname1, *fnames, **opts): | |
4886 | """apply one or more changegroup files |
|
4886 | """apply one or more changegroup files | |
4887 |
|
4887 | |||
4888 | Apply one or more compressed changegroup files generated by the |
|
4888 | Apply one or more compressed changegroup files generated by the | |
4889 | bundle command. |
|
4889 | bundle command. | |
4890 |
|
4890 | |||
4891 | Returns 0 on success, 1 if an update has unresolved files. |
|
4891 | Returns 0 on success, 1 if an update has unresolved files. | |
4892 | """ |
|
4892 | """ | |
4893 | fnames = (fname1,) + fnames |
|
4893 | fnames = (fname1,) + fnames | |
4894 |
|
4894 | |||
4895 | lock = repo.lock() |
|
4895 | lock = repo.lock() | |
4896 | wc = repo['.'] |
|
4896 | wc = repo['.'] | |
4897 | try: |
|
4897 | try: | |
4898 | for fname in fnames: |
|
4898 | for fname in fnames: | |
4899 | f = url.open(ui, fname) |
|
4899 | f = url.open(ui, fname) | |
4900 | gen = changegroup.readbundle(f, fname) |
|
4900 | gen = changegroup.readbundle(f, fname) | |
4901 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname, |
|
4901 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname, | |
4902 | lock=lock) |
|
4902 | lock=lock) | |
4903 | bookmarks.updatecurrentbookmark(repo, wc.node(), wc.branch()) |
|
4903 | bookmarks.updatecurrentbookmark(repo, wc.node(), wc.branch()) | |
4904 | finally: |
|
4904 | finally: | |
4905 | lock.release() |
|
4905 | lock.release() | |
4906 | return postincoming(ui, repo, modheads, opts.get('update'), None) |
|
4906 | return postincoming(ui, repo, modheads, opts.get('update'), None) | |
4907 |
|
4907 | |||
4908 | @command('^update|up|checkout|co', |
|
4908 | @command('^update|up|checkout|co', | |
4909 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
|
4909 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), | |
4910 | ('c', 'check', None, |
|
4910 | ('c', 'check', None, | |
4911 | _('update across branches if no uncommitted changes')), |
|
4911 | _('update across branches if no uncommitted changes')), | |
4912 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
4912 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), | |
4913 | ('r', 'rev', '', _('revision'), _('REV'))], |
|
4913 | ('r', 'rev', '', _('revision'), _('REV'))], | |
4914 | _('[-c] [-C] [-d DATE] [[-r] REV]')) |
|
4914 | _('[-c] [-C] [-d DATE] [[-r] REV]')) | |
4915 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False): |
|
4915 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False): | |
4916 | """update working directory (or switch revisions) |
|
4916 | """update working directory (or switch revisions) | |
4917 |
|
4917 | |||
4918 | Update the repository's working directory to the specified |
|
4918 | Update the repository's working directory to the specified | |
4919 | changeset. If no changeset is specified, update to the tip of the |
|
4919 | changeset. If no changeset is specified, update to the tip of the | |
4920 | current named branch. |
|
4920 | current named branch. | |
4921 |
|
4921 | |||
4922 | If the changeset is not a descendant of the working directory's |
|
4922 | If the changeset is not a descendant of the working directory's | |
4923 | parent, the update is aborted. With the -c/--check option, the |
|
4923 | parent, the update is aborted. With the -c/--check option, the | |
4924 | working directory is checked for uncommitted changes; if none are |
|
4924 | working directory is checked for uncommitted changes; if none are | |
4925 | found, the working directory is updated to the specified |
|
4925 | found, the working directory is updated to the specified | |
4926 | changeset. |
|
4926 | changeset. | |
4927 |
|
4927 | |||
4928 | The following rules apply when the working directory contains |
|
4928 | The following rules apply when the working directory contains | |
4929 | uncommitted changes: |
|
4929 | uncommitted changes: | |
4930 |
|
4930 | |||
4931 | 1. If neither -c/--check nor -C/--clean is specified, and if |
|
4931 | 1. If neither -c/--check nor -C/--clean is specified, and if | |
4932 | the requested changeset is an ancestor or descendant of |
|
4932 | the requested changeset is an ancestor or descendant of | |
4933 | the working directory's parent, the uncommitted changes |
|
4933 | the working directory's parent, the uncommitted changes | |
4934 | are merged into the requested changeset and the merged |
|
4934 | are merged into the requested changeset and the merged | |
4935 | result is left uncommitted. If the requested changeset is |
|
4935 | result is left uncommitted. If the requested changeset is | |
4936 | not an ancestor or descendant (that is, it is on another |
|
4936 | not an ancestor or descendant (that is, it is on another | |
4937 | branch), the update is aborted and the uncommitted changes |
|
4937 | branch), the update is aborted and the uncommitted changes | |
4938 | are preserved. |
|
4938 | are preserved. | |
4939 |
|
4939 | |||
4940 | 2. With the -c/--check option, the update is aborted and the |
|
4940 | 2. With the -c/--check option, the update is aborted and the | |
4941 | uncommitted changes are preserved. |
|
4941 | uncommitted changes are preserved. | |
4942 |
|
4942 | |||
4943 | 3. With the -C/--clean option, uncommitted changes are discarded and |
|
4943 | 3. With the -C/--clean option, uncommitted changes are discarded and | |
4944 | the working directory is updated to the requested changeset. |
|
4944 | the working directory is updated to the requested changeset. | |
4945 |
|
4945 | |||
4946 | Use null as the changeset to remove the working directory (like |
|
4946 | Use null as the changeset to remove the working directory (like | |
4947 | :hg:`clone -U`). |
|
4947 | :hg:`clone -U`). | |
4948 |
|
4948 | |||
4949 | If you want to update just one file to an older changeset, use |
|
4949 | If you want to update just one file to an older changeset, use | |
4950 | :hg:`revert`. |
|
4950 | :hg:`revert`. | |
4951 |
|
4951 | |||
4952 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4952 | See :hg:`help dates` for a list of formats valid for -d/--date. | |
4953 |
|
4953 | |||
4954 | Returns 0 on success, 1 if there are unresolved files. |
|
4954 | Returns 0 on success, 1 if there are unresolved files. | |
4955 | """ |
|
4955 | """ | |
4956 | if rev and node: |
|
4956 | if rev and node: | |
4957 | raise util.Abort(_("please specify just one revision")) |
|
4957 | raise util.Abort(_("please specify just one revision")) | |
4958 |
|
4958 | |||
4959 | if rev is None or rev == '': |
|
4959 | if rev is None or rev == '': | |
4960 | rev = node |
|
4960 | rev = node | |
4961 |
|
4961 | |||
4962 | # if we defined a bookmark, we have to remember the original bookmark name |
|
4962 | # if we defined a bookmark, we have to remember the original bookmark name | |
4963 | brev = rev |
|
4963 | brev = rev | |
4964 | rev = scmutil.revsingle(repo, rev, rev).rev() |
|
4964 | rev = scmutil.revsingle(repo, rev, rev).rev() | |
4965 |
|
4965 | |||
4966 | if check and clean: |
|
4966 | if check and clean: | |
4967 | raise util.Abort(_("cannot specify both -c/--check and -C/--clean")) |
|
4967 | raise util.Abort(_("cannot specify both -c/--check and -C/--clean")) | |
4968 |
|
4968 | |||
4969 | if check: |
|
4969 | if check: | |
4970 | # we could use dirty() but we can ignore merge and branch trivia |
|
4970 | # we could use dirty() but we can ignore merge and branch trivia | |
4971 | c = repo[None] |
|
4971 | c = repo[None] | |
4972 | if c.modified() or c.added() or c.removed(): |
|
4972 | if c.modified() or c.added() or c.removed(): | |
4973 | raise util.Abort(_("uncommitted local changes")) |
|
4973 | raise util.Abort(_("uncommitted local changes")) | |
4974 |
|
4974 | |||
4975 | if date: |
|
4975 | if date: | |
4976 | if rev is not None: |
|
4976 | if rev is not None: | |
4977 | raise util.Abort(_("you can't specify a revision and a date")) |
|
4977 | raise util.Abort(_("you can't specify a revision and a date")) | |
4978 | rev = cmdutil.finddate(ui, repo, date) |
|
4978 | rev = cmdutil.finddate(ui, repo, date) | |
4979 |
|
4979 | |||
4980 | if clean or check: |
|
4980 | if clean or check: | |
4981 | ret = hg.clean(repo, rev) |
|
4981 | ret = hg.clean(repo, rev) | |
4982 | else: |
|
4982 | else: | |
4983 | ret = hg.update(repo, rev) |
|
4983 | ret = hg.update(repo, rev) | |
4984 |
|
4984 | |||
4985 | if brev in repo._bookmarks: |
|
4985 | if brev in repo._bookmarks: | |
4986 | bookmarks.setcurrent(repo, brev) |
|
4986 | bookmarks.setcurrent(repo, brev) | |
4987 |
|
4987 | |||
4988 | return ret |
|
4988 | return ret | |
4989 |
|
4989 | |||
4990 | @command('verify', []) |
|
4990 | @command('verify', []) | |
4991 | def verify(ui, repo): |
|
4991 | def verify(ui, repo): | |
4992 | """verify the integrity of the repository |
|
4992 | """verify the integrity of the repository | |
4993 |
|
4993 | |||
4994 | Verify the integrity of the current repository. |
|
4994 | Verify the integrity of the current repository. | |
4995 |
|
4995 | |||
4996 | This will perform an extensive check of the repository's |
|
4996 | This will perform an extensive check of the repository's | |
4997 | integrity, validating the hashes and checksums of each entry in |
|
4997 | integrity, validating the hashes and checksums of each entry in | |
4998 | the changelog, manifest, and tracked files, as well as the |
|
4998 | the changelog, manifest, and tracked files, as well as the | |
4999 | integrity of their crosslinks and indices. |
|
4999 | integrity of their crosslinks and indices. | |
5000 |
|
5000 | |||
5001 | Returns 0 on success, 1 if errors are encountered. |
|
5001 | Returns 0 on success, 1 if errors are encountered. | |
5002 | """ |
|
5002 | """ | |
5003 | return hg.verify(repo) |
|
5003 | return hg.verify(repo) | |
5004 |
|
5004 | |||
5005 | @command('version', []) |
|
5005 | @command('version', []) | |
5006 | def version_(ui): |
|
5006 | def version_(ui): | |
5007 | """output version and copyright information""" |
|
5007 | """output version and copyright information""" | |
5008 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
5008 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | |
5009 | % util.version()) |
|
5009 | % util.version()) | |
5010 | ui.status(_( |
|
5010 | ui.status(_( | |
5011 | "(see http://mercurial.selenic.com for more information)\n" |
|
5011 | "(see http://mercurial.selenic.com for more information)\n" | |
5012 | "\nCopyright (C) 2005-2011 Matt Mackall and others\n" |
|
5012 | "\nCopyright (C) 2005-2011 Matt Mackall and others\n" | |
5013 | "This is free software; see the source for copying conditions. " |
|
5013 | "This is free software; see the source for copying conditions. " | |
5014 | "There is NO\nwarranty; " |
|
5014 | "There is NO\nwarranty; " | |
5015 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
5015 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
5016 | )) |
|
5016 | )) | |
5017 |
|
5017 | |||
5018 | norepo = ("clone init version help debugcommands debugcomplete" |
|
5018 | norepo = ("clone init version help debugcommands debugcomplete" | |
5019 | " debugdate debuginstall debugfsinfo debugpushkey debugwireargs" |
|
5019 | " debugdate debuginstall debugfsinfo debugpushkey debugwireargs" | |
5020 | " debugknown debuggetbundle debugbundle") |
|
5020 | " debugknown debuggetbundle debugbundle") | |
5021 | optionalrepo = ("identify paths serve showconfig debugancestor debugdag" |
|
5021 | optionalrepo = ("identify paths serve showconfig debugancestor debugdag" | |
5022 | " debugdata debugindex debugindexdot") |
|
5022 | " debugdata debugindex debugindexdot") |
@@ -1,1693 +1,1693 b'' | |||||
1 | # patch.py - patch file parsing routines |
|
1 | # patch.py - patch file parsing routines | |
2 | # |
|
2 | # | |
3 | # Copyright 2006 Brendan Cully <brendan@kublai.com> |
|
3 | # Copyright 2006 Brendan Cully <brendan@kublai.com> | |
4 | # Copyright 2007 Chris Mason <chris.mason@oracle.com> |
|
4 | # Copyright 2007 Chris Mason <chris.mason@oracle.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | import cStringIO, email.Parser, os, errno, re |
|
9 | import cStringIO, email.Parser, os, errno, re | |
10 | import tempfile, zlib |
|
10 | import tempfile, zlib | |
11 |
|
11 | |||
12 | from i18n import _ |
|
12 | from i18n import _ | |
13 | from node import hex, nullid, short |
|
13 | from node import hex, nullid, short | |
14 |
import base85, mdiff, scmutil, util, diffhelpers, copies, encoding |
|
14 | import base85, mdiff, scmutil, util, diffhelpers, copies, encoding | |
15 |
|
15 | |||
16 | gitre = re.compile('diff --git a/(.*) b/(.*)') |
|
16 | gitre = re.compile('diff --git a/(.*) b/(.*)') | |
17 |
|
17 | |||
18 | class PatchError(Exception): |
|
18 | class PatchError(Exception): | |
19 | pass |
|
19 | pass | |
20 |
|
20 | |||
21 | # helper functions |
|
21 | # helper functions | |
22 |
|
22 | |||
23 | def copyfile(src, dst, basedir): |
|
23 | def copyfile(src, dst, basedir): | |
24 | abssrc, absdst = [scmutil.canonpath(basedir, basedir, x) |
|
24 | abssrc, absdst = [scmutil.canonpath(basedir, basedir, x) | |
25 | for x in [src, dst]] |
|
25 | for x in [src, dst]] | |
26 | if os.path.lexists(absdst): |
|
26 | if os.path.lexists(absdst): | |
27 | raise util.Abort(_("cannot create %s: destination already exists") % |
|
27 | raise util.Abort(_("cannot create %s: destination already exists") % | |
28 | dst) |
|
28 | dst) | |
29 |
|
29 | |||
30 | dstdir = os.path.dirname(absdst) |
|
30 | dstdir = os.path.dirname(absdst) | |
31 | if dstdir and not os.path.isdir(dstdir): |
|
31 | if dstdir and not os.path.isdir(dstdir): | |
32 | try: |
|
32 | try: | |
33 | os.makedirs(dstdir) |
|
33 | os.makedirs(dstdir) | |
34 | except IOError: |
|
34 | except IOError: | |
35 | raise util.Abort( |
|
35 | raise util.Abort( | |
36 | _("cannot create %s: unable to create destination directory") |
|
36 | _("cannot create %s: unable to create destination directory") | |
37 | % dst) |
|
37 | % dst) | |
38 |
|
38 | |||
39 | util.copyfile(abssrc, absdst) |
|
39 | util.copyfile(abssrc, absdst) | |
40 |
|
40 | |||
41 | # public functions |
|
41 | # public functions | |
42 |
|
42 | |||
43 | def split(stream): |
|
43 | def split(stream): | |
44 | '''return an iterator of individual patches from a stream''' |
|
44 | '''return an iterator of individual patches from a stream''' | |
45 | def isheader(line, inheader): |
|
45 | def isheader(line, inheader): | |
46 | if inheader and line[0] in (' ', '\t'): |
|
46 | if inheader and line[0] in (' ', '\t'): | |
47 | # continuation |
|
47 | # continuation | |
48 | return True |
|
48 | return True | |
49 | if line[0] in (' ', '-', '+'): |
|
49 | if line[0] in (' ', '-', '+'): | |
50 | # diff line - don't check for header pattern in there |
|
50 | # diff line - don't check for header pattern in there | |
51 | return False |
|
51 | return False | |
52 | l = line.split(': ', 1) |
|
52 | l = line.split(': ', 1) | |
53 | return len(l) == 2 and ' ' not in l[0] |
|
53 | return len(l) == 2 and ' ' not in l[0] | |
54 |
|
54 | |||
55 | def chunk(lines): |
|
55 | def chunk(lines): | |
56 | return cStringIO.StringIO(''.join(lines)) |
|
56 | return cStringIO.StringIO(''.join(lines)) | |
57 |
|
57 | |||
58 | def hgsplit(stream, cur): |
|
58 | def hgsplit(stream, cur): | |
59 | inheader = True |
|
59 | inheader = True | |
60 |
|
60 | |||
61 | for line in stream: |
|
61 | for line in stream: | |
62 | if not line.strip(): |
|
62 | if not line.strip(): | |
63 | inheader = False |
|
63 | inheader = False | |
64 | if not inheader and line.startswith('# HG changeset patch'): |
|
64 | if not inheader and line.startswith('# HG changeset patch'): | |
65 | yield chunk(cur) |
|
65 | yield chunk(cur) | |
66 | cur = [] |
|
66 | cur = [] | |
67 | inheader = True |
|
67 | inheader = True | |
68 |
|
68 | |||
69 | cur.append(line) |
|
69 | cur.append(line) | |
70 |
|
70 | |||
71 | if cur: |
|
71 | if cur: | |
72 | yield chunk(cur) |
|
72 | yield chunk(cur) | |
73 |
|
73 | |||
74 | def mboxsplit(stream, cur): |
|
74 | def mboxsplit(stream, cur): | |
75 | for line in stream: |
|
75 | for line in stream: | |
76 | if line.startswith('From '): |
|
76 | if line.startswith('From '): | |
77 | for c in split(chunk(cur[1:])): |
|
77 | for c in split(chunk(cur[1:])): | |
78 | yield c |
|
78 | yield c | |
79 | cur = [] |
|
79 | cur = [] | |
80 |
|
80 | |||
81 | cur.append(line) |
|
81 | cur.append(line) | |
82 |
|
82 | |||
83 | if cur: |
|
83 | if cur: | |
84 | for c in split(chunk(cur[1:])): |
|
84 | for c in split(chunk(cur[1:])): | |
85 | yield c |
|
85 | yield c | |
86 |
|
86 | |||
87 | def mimesplit(stream, cur): |
|
87 | def mimesplit(stream, cur): | |
88 | def msgfp(m): |
|
88 | def msgfp(m): | |
89 | fp = cStringIO.StringIO() |
|
89 | fp = cStringIO.StringIO() | |
90 | g = email.Generator.Generator(fp, mangle_from_=False) |
|
90 | g = email.Generator.Generator(fp, mangle_from_=False) | |
91 | g.flatten(m) |
|
91 | g.flatten(m) | |
92 | fp.seek(0) |
|
92 | fp.seek(0) | |
93 | return fp |
|
93 | return fp | |
94 |
|
94 | |||
95 | for line in stream: |
|
95 | for line in stream: | |
96 | cur.append(line) |
|
96 | cur.append(line) | |
97 | c = chunk(cur) |
|
97 | c = chunk(cur) | |
98 |
|
98 | |||
99 | m = email.Parser.Parser().parse(c) |
|
99 | m = email.Parser.Parser().parse(c) | |
100 | if not m.is_multipart(): |
|
100 | if not m.is_multipart(): | |
101 | yield msgfp(m) |
|
101 | yield msgfp(m) | |
102 | else: |
|
102 | else: | |
103 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') |
|
103 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') | |
104 | for part in m.walk(): |
|
104 | for part in m.walk(): | |
105 | ct = part.get_content_type() |
|
105 | ct = part.get_content_type() | |
106 | if ct not in ok_types: |
|
106 | if ct not in ok_types: | |
107 | continue |
|
107 | continue | |
108 | yield msgfp(part) |
|
108 | yield msgfp(part) | |
109 |
|
109 | |||
110 | def headersplit(stream, cur): |
|
110 | def headersplit(stream, cur): | |
111 | inheader = False |
|
111 | inheader = False | |
112 |
|
112 | |||
113 | for line in stream: |
|
113 | for line in stream: | |
114 | if not inheader and isheader(line, inheader): |
|
114 | if not inheader and isheader(line, inheader): | |
115 | yield chunk(cur) |
|
115 | yield chunk(cur) | |
116 | cur = [] |
|
116 | cur = [] | |
117 | inheader = True |
|
117 | inheader = True | |
118 | if inheader and not isheader(line, inheader): |
|
118 | if inheader and not isheader(line, inheader): | |
119 | inheader = False |
|
119 | inheader = False | |
120 |
|
120 | |||
121 | cur.append(line) |
|
121 | cur.append(line) | |
122 |
|
122 | |||
123 | if cur: |
|
123 | if cur: | |
124 | yield chunk(cur) |
|
124 | yield chunk(cur) | |
125 |
|
125 | |||
126 | def remainder(cur): |
|
126 | def remainder(cur): | |
127 | yield chunk(cur) |
|
127 | yield chunk(cur) | |
128 |
|
128 | |||
129 | class fiter(object): |
|
129 | class fiter(object): | |
130 | def __init__(self, fp): |
|
130 | def __init__(self, fp): | |
131 | self.fp = fp |
|
131 | self.fp = fp | |
132 |
|
132 | |||
133 | def __iter__(self): |
|
133 | def __iter__(self): | |
134 | return self |
|
134 | return self | |
135 |
|
135 | |||
136 | def next(self): |
|
136 | def next(self): | |
137 | l = self.fp.readline() |
|
137 | l = self.fp.readline() | |
138 | if not l: |
|
138 | if not l: | |
139 | raise StopIteration |
|
139 | raise StopIteration | |
140 | return l |
|
140 | return l | |
141 |
|
141 | |||
142 | inheader = False |
|
142 | inheader = False | |
143 | cur = [] |
|
143 | cur = [] | |
144 |
|
144 | |||
145 | mimeheaders = ['content-type'] |
|
145 | mimeheaders = ['content-type'] | |
146 |
|
146 | |||
147 | if not hasattr(stream, 'next'): |
|
147 | if not hasattr(stream, 'next'): | |
148 | # http responses, for example, have readline but not next |
|
148 | # http responses, for example, have readline but not next | |
149 | stream = fiter(stream) |
|
149 | stream = fiter(stream) | |
150 |
|
150 | |||
151 | for line in stream: |
|
151 | for line in stream: | |
152 | cur.append(line) |
|
152 | cur.append(line) | |
153 | if line.startswith('# HG changeset patch'): |
|
153 | if line.startswith('# HG changeset patch'): | |
154 | return hgsplit(stream, cur) |
|
154 | return hgsplit(stream, cur) | |
155 | elif line.startswith('From '): |
|
155 | elif line.startswith('From '): | |
156 | return mboxsplit(stream, cur) |
|
156 | return mboxsplit(stream, cur) | |
157 | elif isheader(line, inheader): |
|
157 | elif isheader(line, inheader): | |
158 | inheader = True |
|
158 | inheader = True | |
159 | if line.split(':', 1)[0].lower() in mimeheaders: |
|
159 | if line.split(':', 1)[0].lower() in mimeheaders: | |
160 | # let email parser handle this |
|
160 | # let email parser handle this | |
161 | return mimesplit(stream, cur) |
|
161 | return mimesplit(stream, cur) | |
162 | elif line.startswith('--- ') and inheader: |
|
162 | elif line.startswith('--- ') and inheader: | |
163 | # No evil headers seen by diff start, split by hand |
|
163 | # No evil headers seen by diff start, split by hand | |
164 | return headersplit(stream, cur) |
|
164 | return headersplit(stream, cur) | |
165 | # Not enough info, keep reading |
|
165 | # Not enough info, keep reading | |
166 |
|
166 | |||
167 | # if we are here, we have a very plain patch |
|
167 | # if we are here, we have a very plain patch | |
168 | return remainder(cur) |
|
168 | return remainder(cur) | |
169 |
|
169 | |||
170 | def extract(ui, fileobj): |
|
170 | def extract(ui, fileobj): | |
171 | '''extract patch from data read from fileobj. |
|
171 | '''extract patch from data read from fileobj. | |
172 |
|
172 | |||
173 | patch can be a normal patch or contained in an email message. |
|
173 | patch can be a normal patch or contained in an email message. | |
174 |
|
174 | |||
175 | return tuple (filename, message, user, date, branch, node, p1, p2). |
|
175 | return tuple (filename, message, user, date, branch, node, p1, p2). | |
176 | Any item in the returned tuple can be None. If filename is None, |
|
176 | Any item in the returned tuple can be None. If filename is None, | |
177 | fileobj did not contain a patch. Caller must unlink filename when done.''' |
|
177 | fileobj did not contain a patch. Caller must unlink filename when done.''' | |
178 |
|
178 | |||
179 | # attempt to detect the start of a patch |
|
179 | # attempt to detect the start of a patch | |
180 | # (this heuristic is borrowed from quilt) |
|
180 | # (this heuristic is borrowed from quilt) | |
181 | diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' |
|
181 | diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' | |
182 | r'retrieving revision [0-9]+(\.[0-9]+)*$|' |
|
182 | r'retrieving revision [0-9]+(\.[0-9]+)*$|' | |
183 | r'---[ \t].*?^\+\+\+[ \t]|' |
|
183 | r'---[ \t].*?^\+\+\+[ \t]|' | |
184 | r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL) |
|
184 | r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL) | |
185 |
|
185 | |||
186 | fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') |
|
186 | fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') | |
187 | tmpfp = os.fdopen(fd, 'w') |
|
187 | tmpfp = os.fdopen(fd, 'w') | |
188 | try: |
|
188 | try: | |
189 | msg = email.Parser.Parser().parse(fileobj) |
|
189 | msg = email.Parser.Parser().parse(fileobj) | |
190 |
|
190 | |||
191 | subject = msg['Subject'] |
|
191 | subject = msg['Subject'] | |
192 | user = msg['From'] |
|
192 | user = msg['From'] | |
193 | if not subject and not user: |
|
193 | if not subject and not user: | |
194 | # Not an email, restore parsed headers if any |
|
194 | # Not an email, restore parsed headers if any | |
195 | subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n' |
|
195 | subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n' | |
196 |
|
196 | |||
197 | gitsendmail = 'git-send-email' in msg.get('X-Mailer', '') |
|
197 | gitsendmail = 'git-send-email' in msg.get('X-Mailer', '') | |
198 | # should try to parse msg['Date'] |
|
198 | # should try to parse msg['Date'] | |
199 | date = None |
|
199 | date = None | |
200 | nodeid = None |
|
200 | nodeid = None | |
201 | branch = None |
|
201 | branch = None | |
202 | parents = [] |
|
202 | parents = [] | |
203 |
|
203 | |||
204 | if subject: |
|
204 | if subject: | |
205 | if subject.startswith('[PATCH'): |
|
205 | if subject.startswith('[PATCH'): | |
206 | pend = subject.find(']') |
|
206 | pend = subject.find(']') | |
207 | if pend >= 0: |
|
207 | if pend >= 0: | |
208 | subject = subject[pend + 1:].lstrip() |
|
208 | subject = subject[pend + 1:].lstrip() | |
209 | subject = subject.replace('\n\t', ' ') |
|
209 | subject = subject.replace('\n\t', ' ') | |
210 | ui.debug('Subject: %s\n' % subject) |
|
210 | ui.debug('Subject: %s\n' % subject) | |
211 | if user: |
|
211 | if user: | |
212 | ui.debug('From: %s\n' % user) |
|
212 | ui.debug('From: %s\n' % user) | |
213 | diffs_seen = 0 |
|
213 | diffs_seen = 0 | |
214 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') |
|
214 | ok_types = ('text/plain', 'text/x-diff', 'text/x-patch') | |
215 | message = '' |
|
215 | message = '' | |
216 | for part in msg.walk(): |
|
216 | for part in msg.walk(): | |
217 | content_type = part.get_content_type() |
|
217 | content_type = part.get_content_type() | |
218 | ui.debug('Content-Type: %s\n' % content_type) |
|
218 | ui.debug('Content-Type: %s\n' % content_type) | |
219 | if content_type not in ok_types: |
|
219 | if content_type not in ok_types: | |
220 | continue |
|
220 | continue | |
221 | payload = part.get_payload(decode=True) |
|
221 | payload = part.get_payload(decode=True) | |
222 | m = diffre.search(payload) |
|
222 | m = diffre.search(payload) | |
223 | if m: |
|
223 | if m: | |
224 | hgpatch = False |
|
224 | hgpatch = False | |
225 | hgpatchheader = False |
|
225 | hgpatchheader = False | |
226 | ignoretext = False |
|
226 | ignoretext = False | |
227 |
|
227 | |||
228 | ui.debug('found patch at byte %d\n' % m.start(0)) |
|
228 | ui.debug('found patch at byte %d\n' % m.start(0)) | |
229 | diffs_seen += 1 |
|
229 | diffs_seen += 1 | |
230 | cfp = cStringIO.StringIO() |
|
230 | cfp = cStringIO.StringIO() | |
231 | for line in payload[:m.start(0)].splitlines(): |
|
231 | for line in payload[:m.start(0)].splitlines(): | |
232 | if line.startswith('# HG changeset patch') and not hgpatch: |
|
232 | if line.startswith('# HG changeset patch') and not hgpatch: | |
233 | ui.debug('patch generated by hg export\n') |
|
233 | ui.debug('patch generated by hg export\n') | |
234 | hgpatch = True |
|
234 | hgpatch = True | |
235 | hgpatchheader = True |
|
235 | hgpatchheader = True | |
236 | # drop earlier commit message content |
|
236 | # drop earlier commit message content | |
237 | cfp.seek(0) |
|
237 | cfp.seek(0) | |
238 | cfp.truncate() |
|
238 | cfp.truncate() | |
239 | subject = None |
|
239 | subject = None | |
240 | elif hgpatchheader: |
|
240 | elif hgpatchheader: | |
241 | if line.startswith('# User '): |
|
241 | if line.startswith('# User '): | |
242 | user = line[7:] |
|
242 | user = line[7:] | |
243 | ui.debug('From: %s\n' % user) |
|
243 | ui.debug('From: %s\n' % user) | |
244 | elif line.startswith("# Date "): |
|
244 | elif line.startswith("# Date "): | |
245 | date = line[7:] |
|
245 | date = line[7:] | |
246 | elif line.startswith("# Branch "): |
|
246 | elif line.startswith("# Branch "): | |
247 | branch = line[9:] |
|
247 | branch = line[9:] | |
248 | elif line.startswith("# Node ID "): |
|
248 | elif line.startswith("# Node ID "): | |
249 | nodeid = line[10:] |
|
249 | nodeid = line[10:] | |
250 | elif line.startswith("# Parent "): |
|
250 | elif line.startswith("# Parent "): | |
251 | parents.append(line[10:]) |
|
251 | parents.append(line[10:]) | |
252 | elif not line.startswith("# "): |
|
252 | elif not line.startswith("# "): | |
253 | hgpatchheader = False |
|
253 | hgpatchheader = False | |
254 | elif line == '---' and gitsendmail: |
|
254 | elif line == '---' and gitsendmail: | |
255 | ignoretext = True |
|
255 | ignoretext = True | |
256 | if not hgpatchheader and not ignoretext: |
|
256 | if not hgpatchheader and not ignoretext: | |
257 | cfp.write(line) |
|
257 | cfp.write(line) | |
258 | cfp.write('\n') |
|
258 | cfp.write('\n') | |
259 | message = cfp.getvalue() |
|
259 | message = cfp.getvalue() | |
260 | if tmpfp: |
|
260 | if tmpfp: | |
261 | tmpfp.write(payload) |
|
261 | tmpfp.write(payload) | |
262 | if not payload.endswith('\n'): |
|
262 | if not payload.endswith('\n'): | |
263 | tmpfp.write('\n') |
|
263 | tmpfp.write('\n') | |
264 | elif not diffs_seen and message and content_type == 'text/plain': |
|
264 | elif not diffs_seen and message and content_type == 'text/plain': | |
265 | message += '\n' + payload |
|
265 | message += '\n' + payload | |
266 | except: |
|
266 | except: | |
267 | tmpfp.close() |
|
267 | tmpfp.close() | |
268 | os.unlink(tmpname) |
|
268 | os.unlink(tmpname) | |
269 | raise |
|
269 | raise | |
270 |
|
270 | |||
271 | if subject and not message.startswith(subject): |
|
271 | if subject and not message.startswith(subject): | |
272 | message = '%s\n%s' % (subject, message) |
|
272 | message = '%s\n%s' % (subject, message) | |
273 | tmpfp.close() |
|
273 | tmpfp.close() | |
274 | if not diffs_seen: |
|
274 | if not diffs_seen: | |
275 | os.unlink(tmpname) |
|
275 | os.unlink(tmpname) | |
276 | return None, message, user, date, branch, None, None, None |
|
276 | return None, message, user, date, branch, None, None, None | |
277 | p1 = parents and parents.pop(0) or None |
|
277 | p1 = parents and parents.pop(0) or None | |
278 | p2 = parents and parents.pop(0) or None |
|
278 | p2 = parents and parents.pop(0) or None | |
279 | return tmpname, message, user, date, branch, nodeid, p1, p2 |
|
279 | return tmpname, message, user, date, branch, nodeid, p1, p2 | |
280 |
|
280 | |||
281 | class patchmeta(object): |
|
281 | class patchmeta(object): | |
282 | """Patched file metadata |
|
282 | """Patched file metadata | |
283 |
|
283 | |||
284 | 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY |
|
284 | 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY | |
285 | or COPY. 'path' is patched file path. 'oldpath' is set to the |
|
285 | or COPY. 'path' is patched file path. 'oldpath' is set to the | |
286 | origin file when 'op' is either COPY or RENAME, None otherwise. If |
|
286 | origin file when 'op' is either COPY or RENAME, None otherwise. If | |
287 | file mode is changed, 'mode' is a tuple (islink, isexec) where |
|
287 | file mode is changed, 'mode' is a tuple (islink, isexec) where | |
288 | 'islink' is True if the file is a symlink and 'isexec' is True if |
|
288 | 'islink' is True if the file is a symlink and 'isexec' is True if | |
289 | the file is executable. Otherwise, 'mode' is None. |
|
289 | the file is executable. Otherwise, 'mode' is None. | |
290 | """ |
|
290 | """ | |
291 | def __init__(self, path): |
|
291 | def __init__(self, path): | |
292 | self.path = path |
|
292 | self.path = path | |
293 | self.oldpath = None |
|
293 | self.oldpath = None | |
294 | self.mode = None |
|
294 | self.mode = None | |
295 | self.op = 'MODIFY' |
|
295 | self.op = 'MODIFY' | |
296 | self.binary = False |
|
296 | self.binary = False | |
297 |
|
297 | |||
298 | def setmode(self, mode): |
|
298 | def setmode(self, mode): | |
299 | islink = mode & 020000 |
|
299 | islink = mode & 020000 | |
300 | isexec = mode & 0100 |
|
300 | isexec = mode & 0100 | |
301 | self.mode = (islink, isexec) |
|
301 | self.mode = (islink, isexec) | |
302 |
|
302 | |||
303 | def __repr__(self): |
|
303 | def __repr__(self): | |
304 | return "<patchmeta %s %r>" % (self.op, self.path) |
|
304 | return "<patchmeta %s %r>" % (self.op, self.path) | |
305 |
|
305 | |||
306 | def readgitpatch(lr): |
|
306 | def readgitpatch(lr): | |
307 | """extract git-style metadata about patches from <patchname>""" |
|
307 | """extract git-style metadata about patches from <patchname>""" | |
308 |
|
308 | |||
309 | # Filter patch for git information |
|
309 | # Filter patch for git information | |
310 | gp = None |
|
310 | gp = None | |
311 | gitpatches = [] |
|
311 | gitpatches = [] | |
312 | for line in lr: |
|
312 | for line in lr: | |
313 | line = line.rstrip(' \r\n') |
|
313 | line = line.rstrip(' \r\n') | |
314 | if line.startswith('diff --git'): |
|
314 | if line.startswith('diff --git'): | |
315 | m = gitre.match(line) |
|
315 | m = gitre.match(line) | |
316 | if m: |
|
316 | if m: | |
317 | if gp: |
|
317 | if gp: | |
318 | gitpatches.append(gp) |
|
318 | gitpatches.append(gp) | |
319 | dst = m.group(2) |
|
319 | dst = m.group(2) | |
320 | gp = patchmeta(dst) |
|
320 | gp = patchmeta(dst) | |
321 | elif gp: |
|
321 | elif gp: | |
322 | if line.startswith('--- '): |
|
322 | if line.startswith('--- '): | |
323 | gitpatches.append(gp) |
|
323 | gitpatches.append(gp) | |
324 | gp = None |
|
324 | gp = None | |
325 | continue |
|
325 | continue | |
326 | if line.startswith('rename from '): |
|
326 | if line.startswith('rename from '): | |
327 | gp.op = 'RENAME' |
|
327 | gp.op = 'RENAME' | |
328 | gp.oldpath = line[12:] |
|
328 | gp.oldpath = line[12:] | |
329 | elif line.startswith('rename to '): |
|
329 | elif line.startswith('rename to '): | |
330 | gp.path = line[10:] |
|
330 | gp.path = line[10:] | |
331 | elif line.startswith('copy from '): |
|
331 | elif line.startswith('copy from '): | |
332 | gp.op = 'COPY' |
|
332 | gp.op = 'COPY' | |
333 | gp.oldpath = line[10:] |
|
333 | gp.oldpath = line[10:] | |
334 | elif line.startswith('copy to '): |
|
334 | elif line.startswith('copy to '): | |
335 | gp.path = line[8:] |
|
335 | gp.path = line[8:] | |
336 | elif line.startswith('deleted file'): |
|
336 | elif line.startswith('deleted file'): | |
337 | gp.op = 'DELETE' |
|
337 | gp.op = 'DELETE' | |
338 | elif line.startswith('new file mode '): |
|
338 | elif line.startswith('new file mode '): | |
339 | gp.op = 'ADD' |
|
339 | gp.op = 'ADD' | |
340 | gp.setmode(int(line[-6:], 8)) |
|
340 | gp.setmode(int(line[-6:], 8)) | |
341 | elif line.startswith('new mode '): |
|
341 | elif line.startswith('new mode '): | |
342 | gp.setmode(int(line[-6:], 8)) |
|
342 | gp.setmode(int(line[-6:], 8)) | |
343 | elif line.startswith('GIT binary patch'): |
|
343 | elif line.startswith('GIT binary patch'): | |
344 | gp.binary = True |
|
344 | gp.binary = True | |
345 | if gp: |
|
345 | if gp: | |
346 | gitpatches.append(gp) |
|
346 | gitpatches.append(gp) | |
347 |
|
347 | |||
348 | return gitpatches |
|
348 | return gitpatches | |
349 |
|
349 | |||
350 | class linereader(object): |
|
350 | class linereader(object): | |
351 | # simple class to allow pushing lines back into the input stream |
|
351 | # simple class to allow pushing lines back into the input stream | |
352 | def __init__(self, fp, textmode=False): |
|
352 | def __init__(self, fp, textmode=False): | |
353 | self.fp = fp |
|
353 | self.fp = fp | |
354 | self.buf = [] |
|
354 | self.buf = [] | |
355 | self.textmode = textmode |
|
355 | self.textmode = textmode | |
356 | self.eol = None |
|
356 | self.eol = None | |
357 |
|
357 | |||
358 | def push(self, line): |
|
358 | def push(self, line): | |
359 | if line is not None: |
|
359 | if line is not None: | |
360 | self.buf.append(line) |
|
360 | self.buf.append(line) | |
361 |
|
361 | |||
362 | def readline(self): |
|
362 | def readline(self): | |
363 | if self.buf: |
|
363 | if self.buf: | |
364 | l = self.buf[0] |
|
364 | l = self.buf[0] | |
365 | del self.buf[0] |
|
365 | del self.buf[0] | |
366 | return l |
|
366 | return l | |
367 | l = self.fp.readline() |
|
367 | l = self.fp.readline() | |
368 | if not self.eol: |
|
368 | if not self.eol: | |
369 | if l.endswith('\r\n'): |
|
369 | if l.endswith('\r\n'): | |
370 | self.eol = '\r\n' |
|
370 | self.eol = '\r\n' | |
371 | elif l.endswith('\n'): |
|
371 | elif l.endswith('\n'): | |
372 | self.eol = '\n' |
|
372 | self.eol = '\n' | |
373 | if self.textmode and l.endswith('\r\n'): |
|
373 | if self.textmode and l.endswith('\r\n'): | |
374 | l = l[:-2] + '\n' |
|
374 | l = l[:-2] + '\n' | |
375 | return l |
|
375 | return l | |
376 |
|
376 | |||
377 | def __iter__(self): |
|
377 | def __iter__(self): | |
378 | while 1: |
|
378 | while 1: | |
379 | l = self.readline() |
|
379 | l = self.readline() | |
380 | if not l: |
|
380 | if not l: | |
381 | break |
|
381 | break | |
382 | yield l |
|
382 | yield l | |
383 |
|
383 | |||
384 | # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1 |
|
384 | # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1 | |
385 | unidesc = re.compile('@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@') |
|
385 | unidesc = re.compile('@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@') | |
386 | contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)') |
|
386 | contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)') | |
387 | eolmodes = ['strict', 'crlf', 'lf', 'auto'] |
|
387 | eolmodes = ['strict', 'crlf', 'lf', 'auto'] | |
388 |
|
388 | |||
389 | class patchfile(object): |
|
389 | class patchfile(object): | |
390 | def __init__(self, ui, fname, opener, missing=False, eolmode='strict'): |
|
390 | def __init__(self, ui, fname, opener, missing=False, eolmode='strict'): | |
391 | self.fname = fname |
|
391 | self.fname = fname | |
392 | self.eolmode = eolmode |
|
392 | self.eolmode = eolmode | |
393 | self.eol = None |
|
393 | self.eol = None | |
394 | self.opener = opener |
|
394 | self.opener = opener | |
395 | self.ui = ui |
|
395 | self.ui = ui | |
396 | self.lines = [] |
|
396 | self.lines = [] | |
397 | self.exists = False |
|
397 | self.exists = False | |
398 | self.missing = missing |
|
398 | self.missing = missing | |
399 | if not missing: |
|
399 | if not missing: | |
400 | try: |
|
400 | try: | |
401 | self.lines = self.readlines(fname) |
|
401 | self.lines = self.readlines(fname) | |
402 | self.exists = True |
|
402 | self.exists = True | |
403 | except IOError: |
|
403 | except IOError: | |
404 | pass |
|
404 | pass | |
405 | else: |
|
405 | else: | |
406 | self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) |
|
406 | self.ui.warn(_("unable to find '%s' for patching\n") % self.fname) | |
407 |
|
407 | |||
408 | self.hash = {} |
|
408 | self.hash = {} | |
409 | self.dirty = False |
|
409 | self.dirty = False | |
410 | self.offset = 0 |
|
410 | self.offset = 0 | |
411 | self.skew = 0 |
|
411 | self.skew = 0 | |
412 | self.rej = [] |
|
412 | self.rej = [] | |
413 | self.fileprinted = False |
|
413 | self.fileprinted = False | |
414 | self.printfile(False) |
|
414 | self.printfile(False) | |
415 | self.hunks = 0 |
|
415 | self.hunks = 0 | |
416 |
|
416 | |||
417 | def readlines(self, fname): |
|
417 | def readlines(self, fname): | |
418 | if os.path.islink(fname): |
|
418 | if os.path.islink(fname): | |
419 | return [os.readlink(fname)] |
|
419 | return [os.readlink(fname)] | |
420 | fp = self.opener(fname, 'r') |
|
420 | fp = self.opener(fname, 'r') | |
421 | try: |
|
421 | try: | |
422 | lr = linereader(fp, self.eolmode != 'strict') |
|
422 | lr = linereader(fp, self.eolmode != 'strict') | |
423 | lines = list(lr) |
|
423 | lines = list(lr) | |
424 | self.eol = lr.eol |
|
424 | self.eol = lr.eol | |
425 | return lines |
|
425 | return lines | |
426 | finally: |
|
426 | finally: | |
427 | fp.close() |
|
427 | fp.close() | |
428 |
|
428 | |||
429 | def writelines(self, fname, lines): |
|
429 | def writelines(self, fname, lines): | |
430 | # Ensure supplied data ends in fname, being a regular file or |
|
430 | # Ensure supplied data ends in fname, being a regular file or | |
431 | # a symlink. _updatedir will -too magically- take care |
|
431 | # a symlink. _updatedir will -too magically- take care | |
432 | # of setting it to the proper type afterwards. |
|
432 | # of setting it to the proper type afterwards. | |
433 | st_mode = None |
|
433 | st_mode = None | |
434 | islink = os.path.islink(fname) |
|
434 | islink = os.path.islink(fname) | |
435 | if islink: |
|
435 | if islink: | |
436 | fp = cStringIO.StringIO() |
|
436 | fp = cStringIO.StringIO() | |
437 | else: |
|
437 | else: | |
438 | try: |
|
438 | try: | |
439 | st_mode = os.lstat(fname).st_mode & 0777 |
|
439 | st_mode = os.lstat(fname).st_mode & 0777 | |
440 | except OSError, e: |
|
440 | except OSError, e: | |
441 | if e.errno != errno.ENOENT: |
|
441 | if e.errno != errno.ENOENT: | |
442 | raise |
|
442 | raise | |
443 | fp = self.opener(fname, 'w') |
|
443 | fp = self.opener(fname, 'w') | |
444 | try: |
|
444 | try: | |
445 | if self.eolmode == 'auto': |
|
445 | if self.eolmode == 'auto': | |
446 | eol = self.eol |
|
446 | eol = self.eol | |
447 | elif self.eolmode == 'crlf': |
|
447 | elif self.eolmode == 'crlf': | |
448 | eol = '\r\n' |
|
448 | eol = '\r\n' | |
449 | else: |
|
449 | else: | |
450 | eol = '\n' |
|
450 | eol = '\n' | |
451 |
|
451 | |||
452 | if self.eolmode != 'strict' and eol and eol != '\n': |
|
452 | if self.eolmode != 'strict' and eol and eol != '\n': | |
453 | for l in lines: |
|
453 | for l in lines: | |
454 | if l and l[-1] == '\n': |
|
454 | if l and l[-1] == '\n': | |
455 | l = l[:-1] + eol |
|
455 | l = l[:-1] + eol | |
456 | fp.write(l) |
|
456 | fp.write(l) | |
457 | else: |
|
457 | else: | |
458 | fp.writelines(lines) |
|
458 | fp.writelines(lines) | |
459 | if islink: |
|
459 | if islink: | |
460 | self.opener.symlink(fp.getvalue(), fname) |
|
460 | self.opener.symlink(fp.getvalue(), fname) | |
461 | if st_mode is not None: |
|
461 | if st_mode is not None: | |
462 | os.chmod(fname, st_mode) |
|
462 | os.chmod(fname, st_mode) | |
463 | finally: |
|
463 | finally: | |
464 | fp.close() |
|
464 | fp.close() | |
465 |
|
465 | |||
466 | def unlink(self, fname): |
|
466 | def unlink(self, fname): | |
467 | os.unlink(fname) |
|
467 | os.unlink(fname) | |
468 |
|
468 | |||
469 | def printfile(self, warn): |
|
469 | def printfile(self, warn): | |
470 | if self.fileprinted: |
|
470 | if self.fileprinted: | |
471 | return |
|
471 | return | |
472 | if warn or self.ui.verbose: |
|
472 | if warn or self.ui.verbose: | |
473 | self.fileprinted = True |
|
473 | self.fileprinted = True | |
474 | s = _("patching file %s\n") % self.fname |
|
474 | s = _("patching file %s\n") % self.fname | |
475 | if warn: |
|
475 | if warn: | |
476 | self.ui.warn(s) |
|
476 | self.ui.warn(s) | |
477 | else: |
|
477 | else: | |
478 | self.ui.note(s) |
|
478 | self.ui.note(s) | |
479 |
|
479 | |||
480 |
|
480 | |||
481 | def findlines(self, l, linenum): |
|
481 | def findlines(self, l, linenum): | |
482 | # looks through the hash and finds candidate lines. The |
|
482 | # looks through the hash and finds candidate lines. The | |
483 | # result is a list of line numbers sorted based on distance |
|
483 | # result is a list of line numbers sorted based on distance | |
484 | # from linenum |
|
484 | # from linenum | |
485 |
|
485 | |||
486 | cand = self.hash.get(l, []) |
|
486 | cand = self.hash.get(l, []) | |
487 | if len(cand) > 1: |
|
487 | if len(cand) > 1: | |
488 | # resort our list of potentials forward then back. |
|
488 | # resort our list of potentials forward then back. | |
489 | cand.sort(key=lambda x: abs(x - linenum)) |
|
489 | cand.sort(key=lambda x: abs(x - linenum)) | |
490 | return cand |
|
490 | return cand | |
491 |
|
491 | |||
492 | def makerejlines(self, fname): |
|
492 | def makerejlines(self, fname): | |
493 | base = os.path.basename(fname) |
|
493 | base = os.path.basename(fname) | |
494 | yield "--- %s\n+++ %s\n" % (base, base) |
|
494 | yield "--- %s\n+++ %s\n" % (base, base) | |
495 | for x in self.rej: |
|
495 | for x in self.rej: | |
496 | for l in x.hunk: |
|
496 | for l in x.hunk: | |
497 | yield l |
|
497 | yield l | |
498 | if l[-1] != '\n': |
|
498 | if l[-1] != '\n': | |
499 | yield "\n\ No newline at end of file\n" |
|
499 | yield "\n\ No newline at end of file\n" | |
500 |
|
500 | |||
501 | def write_rej(self): |
|
501 | def write_rej(self): | |
502 | # our rejects are a little different from patch(1). This always |
|
502 | # our rejects are a little different from patch(1). This always | |
503 | # creates rejects in the same form as the original patch. A file |
|
503 | # creates rejects in the same form as the original patch. A file | |
504 | # header is inserted so that you can run the reject through patch again |
|
504 | # header is inserted so that you can run the reject through patch again | |
505 | # without having to type the filename. |
|
505 | # without having to type the filename. | |
506 |
|
506 | |||
507 | if not self.rej: |
|
507 | if not self.rej: | |
508 | return |
|
508 | return | |
509 |
|
509 | |||
510 | fname = self.fname + ".rej" |
|
510 | fname = self.fname + ".rej" | |
511 | self.ui.warn( |
|
511 | self.ui.warn( | |
512 | _("%d out of %d hunks FAILED -- saving rejects to file %s\n") % |
|
512 | _("%d out of %d hunks FAILED -- saving rejects to file %s\n") % | |
513 | (len(self.rej), self.hunks, fname)) |
|
513 | (len(self.rej), self.hunks, fname)) | |
514 |
|
514 | |||
515 | fp = self.opener(fname, 'w') |
|
515 | fp = self.opener(fname, 'w') | |
516 | fp.writelines(self.makerejlines(self.fname)) |
|
516 | fp.writelines(self.makerejlines(self.fname)) | |
517 | fp.close() |
|
517 | fp.close() | |
518 |
|
518 | |||
519 | def apply(self, h): |
|
519 | def apply(self, h): | |
520 | if not h.complete(): |
|
520 | if not h.complete(): | |
521 | raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") % |
|
521 | raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") % | |
522 | (h.number, h.desc, len(h.a), h.lena, len(h.b), |
|
522 | (h.number, h.desc, len(h.a), h.lena, len(h.b), | |
523 | h.lenb)) |
|
523 | h.lenb)) | |
524 |
|
524 | |||
525 | self.hunks += 1 |
|
525 | self.hunks += 1 | |
526 |
|
526 | |||
527 | if self.missing: |
|
527 | if self.missing: | |
528 | self.rej.append(h) |
|
528 | self.rej.append(h) | |
529 | return -1 |
|
529 | return -1 | |
530 |
|
530 | |||
531 | if self.exists and h.createfile(): |
|
531 | if self.exists and h.createfile(): | |
532 | self.ui.warn(_("file %s already exists\n") % self.fname) |
|
532 | self.ui.warn(_("file %s already exists\n") % self.fname) | |
533 | self.rej.append(h) |
|
533 | self.rej.append(h) | |
534 | return -1 |
|
534 | return -1 | |
535 |
|
535 | |||
536 | if isinstance(h, binhunk): |
|
536 | if isinstance(h, binhunk): | |
537 | if h.rmfile(): |
|
537 | if h.rmfile(): | |
538 | self.unlink(self.fname) |
|
538 | self.unlink(self.fname) | |
539 | else: |
|
539 | else: | |
540 | self.lines[:] = h.new() |
|
540 | self.lines[:] = h.new() | |
541 | self.offset += len(h.new()) |
|
541 | self.offset += len(h.new()) | |
542 | self.dirty = True |
|
542 | self.dirty = True | |
543 | return 0 |
|
543 | return 0 | |
544 |
|
544 | |||
545 | horig = h |
|
545 | horig = h | |
546 | if (self.eolmode in ('crlf', 'lf') |
|
546 | if (self.eolmode in ('crlf', 'lf') | |
547 | or self.eolmode == 'auto' and self.eol): |
|
547 | or self.eolmode == 'auto' and self.eol): | |
548 | # If new eols are going to be normalized, then normalize |
|
548 | # If new eols are going to be normalized, then normalize | |
549 | # hunk data before patching. Otherwise, preserve input |
|
549 | # hunk data before patching. Otherwise, preserve input | |
550 | # line-endings. |
|
550 | # line-endings. | |
551 | h = h.getnormalized() |
|
551 | h = h.getnormalized() | |
552 |
|
552 | |||
553 | # fast case first, no offsets, no fuzz |
|
553 | # fast case first, no offsets, no fuzz | |
554 | old = h.old() |
|
554 | old = h.old() | |
555 | # patch starts counting at 1 unless we are adding the file |
|
555 | # patch starts counting at 1 unless we are adding the file | |
556 | if h.starta == 0: |
|
556 | if h.starta == 0: | |
557 | start = 0 |
|
557 | start = 0 | |
558 | else: |
|
558 | else: | |
559 | start = h.starta + self.offset - 1 |
|
559 | start = h.starta + self.offset - 1 | |
560 | orig_start = start |
|
560 | orig_start = start | |
561 | # if there's skew we want to emit the "(offset %d lines)" even |
|
561 | # if there's skew we want to emit the "(offset %d lines)" even | |
562 | # when the hunk cleanly applies at start + skew, so skip the |
|
562 | # when the hunk cleanly applies at start + skew, so skip the | |
563 | # fast case code |
|
563 | # fast case code | |
564 | if self.skew == 0 and diffhelpers.testhunk(old, self.lines, start) == 0: |
|
564 | if self.skew == 0 and diffhelpers.testhunk(old, self.lines, start) == 0: | |
565 | if h.rmfile(): |
|
565 | if h.rmfile(): | |
566 | self.unlink(self.fname) |
|
566 | self.unlink(self.fname) | |
567 | else: |
|
567 | else: | |
568 | self.lines[start : start + h.lena] = h.new() |
|
568 | self.lines[start : start + h.lena] = h.new() | |
569 | self.offset += h.lenb - h.lena |
|
569 | self.offset += h.lenb - h.lena | |
570 | self.dirty = True |
|
570 | self.dirty = True | |
571 | return 0 |
|
571 | return 0 | |
572 |
|
572 | |||
573 | # ok, we couldn't match the hunk. Lets look for offsets and fuzz it |
|
573 | # ok, we couldn't match the hunk. Lets look for offsets and fuzz it | |
574 | self.hash = {} |
|
574 | self.hash = {} | |
575 | for x, s in enumerate(self.lines): |
|
575 | for x, s in enumerate(self.lines): | |
576 | self.hash.setdefault(s, []).append(x) |
|
576 | self.hash.setdefault(s, []).append(x) | |
577 | if h.hunk[-1][0] != ' ': |
|
577 | if h.hunk[-1][0] != ' ': | |
578 | # if the hunk tried to put something at the bottom of the file |
|
578 | # if the hunk tried to put something at the bottom of the file | |
579 | # override the start line and use eof here |
|
579 | # override the start line and use eof here | |
580 | search_start = len(self.lines) |
|
580 | search_start = len(self.lines) | |
581 | else: |
|
581 | else: | |
582 | search_start = orig_start + self.skew |
|
582 | search_start = orig_start + self.skew | |
583 |
|
583 | |||
584 | for fuzzlen in xrange(3): |
|
584 | for fuzzlen in xrange(3): | |
585 | for toponly in [True, False]: |
|
585 | for toponly in [True, False]: | |
586 | old = h.old(fuzzlen, toponly) |
|
586 | old = h.old(fuzzlen, toponly) | |
587 |
|
587 | |||
588 | cand = self.findlines(old[0][1:], search_start) |
|
588 | cand = self.findlines(old[0][1:], search_start) | |
589 | for l in cand: |
|
589 | for l in cand: | |
590 | if diffhelpers.testhunk(old, self.lines, l) == 0: |
|
590 | if diffhelpers.testhunk(old, self.lines, l) == 0: | |
591 | newlines = h.new(fuzzlen, toponly) |
|
591 | newlines = h.new(fuzzlen, toponly) | |
592 | self.lines[l : l + len(old)] = newlines |
|
592 | self.lines[l : l + len(old)] = newlines | |
593 | self.offset += len(newlines) - len(old) |
|
593 | self.offset += len(newlines) - len(old) | |
594 | self.skew = l - orig_start |
|
594 | self.skew = l - orig_start | |
595 | self.dirty = True |
|
595 | self.dirty = True | |
596 | offset = l - orig_start - fuzzlen |
|
596 | offset = l - orig_start - fuzzlen | |
597 | if fuzzlen: |
|
597 | if fuzzlen: | |
598 | msg = _("Hunk #%d succeeded at %d " |
|
598 | msg = _("Hunk #%d succeeded at %d " | |
599 | "with fuzz %d " |
|
599 | "with fuzz %d " | |
600 | "(offset %d lines).\n") |
|
600 | "(offset %d lines).\n") | |
601 | self.printfile(True) |
|
601 | self.printfile(True) | |
602 | self.ui.warn(msg % |
|
602 | self.ui.warn(msg % | |
603 | (h.number, l + 1, fuzzlen, offset)) |
|
603 | (h.number, l + 1, fuzzlen, offset)) | |
604 | else: |
|
604 | else: | |
605 | msg = _("Hunk #%d succeeded at %d " |
|
605 | msg = _("Hunk #%d succeeded at %d " | |
606 | "(offset %d lines).\n") |
|
606 | "(offset %d lines).\n") | |
607 | self.ui.note(msg % (h.number, l + 1, offset)) |
|
607 | self.ui.note(msg % (h.number, l + 1, offset)) | |
608 | return fuzzlen |
|
608 | return fuzzlen | |
609 | self.printfile(True) |
|
609 | self.printfile(True) | |
610 | self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start)) |
|
610 | self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start)) | |
611 | self.rej.append(horig) |
|
611 | self.rej.append(horig) | |
612 | return -1 |
|
612 | return -1 | |
613 |
|
613 | |||
614 | def close(self): |
|
614 | def close(self): | |
615 | if self.dirty: |
|
615 | if self.dirty: | |
616 | self.writelines(self.fname, self.lines) |
|
616 | self.writelines(self.fname, self.lines) | |
617 | self.write_rej() |
|
617 | self.write_rej() | |
618 | return len(self.rej) |
|
618 | return len(self.rej) | |
619 |
|
619 | |||
620 | class hunk(object): |
|
620 | class hunk(object): | |
621 | def __init__(self, desc, num, lr, context, create=False, remove=False): |
|
621 | def __init__(self, desc, num, lr, context, create=False, remove=False): | |
622 | self.number = num |
|
622 | self.number = num | |
623 | self.desc = desc |
|
623 | self.desc = desc | |
624 | self.hunk = [desc] |
|
624 | self.hunk = [desc] | |
625 | self.a = [] |
|
625 | self.a = [] | |
626 | self.b = [] |
|
626 | self.b = [] | |
627 | self.starta = self.lena = None |
|
627 | self.starta = self.lena = None | |
628 | self.startb = self.lenb = None |
|
628 | self.startb = self.lenb = None | |
629 | if lr is not None: |
|
629 | if lr is not None: | |
630 | if context: |
|
630 | if context: | |
631 | self.read_context_hunk(lr) |
|
631 | self.read_context_hunk(lr) | |
632 | else: |
|
632 | else: | |
633 | self.read_unified_hunk(lr) |
|
633 | self.read_unified_hunk(lr) | |
634 | self.create = create |
|
634 | self.create = create | |
635 | self.remove = remove and not create |
|
635 | self.remove = remove and not create | |
636 |
|
636 | |||
637 | def getnormalized(self): |
|
637 | def getnormalized(self): | |
638 | """Return a copy with line endings normalized to LF.""" |
|
638 | """Return a copy with line endings normalized to LF.""" | |
639 |
|
639 | |||
640 | def normalize(lines): |
|
640 | def normalize(lines): | |
641 | nlines = [] |
|
641 | nlines = [] | |
642 | for line in lines: |
|
642 | for line in lines: | |
643 | if line.endswith('\r\n'): |
|
643 | if line.endswith('\r\n'): | |
644 | line = line[:-2] + '\n' |
|
644 | line = line[:-2] + '\n' | |
645 | nlines.append(line) |
|
645 | nlines.append(line) | |
646 | return nlines |
|
646 | return nlines | |
647 |
|
647 | |||
648 | # Dummy object, it is rebuilt manually |
|
648 | # Dummy object, it is rebuilt manually | |
649 | nh = hunk(self.desc, self.number, None, None, False, False) |
|
649 | nh = hunk(self.desc, self.number, None, None, False, False) | |
650 | nh.number = self.number |
|
650 | nh.number = self.number | |
651 | nh.desc = self.desc |
|
651 | nh.desc = self.desc | |
652 | nh.hunk = self.hunk |
|
652 | nh.hunk = self.hunk | |
653 | nh.a = normalize(self.a) |
|
653 | nh.a = normalize(self.a) | |
654 | nh.b = normalize(self.b) |
|
654 | nh.b = normalize(self.b) | |
655 | nh.starta = self.starta |
|
655 | nh.starta = self.starta | |
656 | nh.startb = self.startb |
|
656 | nh.startb = self.startb | |
657 | nh.lena = self.lena |
|
657 | nh.lena = self.lena | |
658 | nh.lenb = self.lenb |
|
658 | nh.lenb = self.lenb | |
659 | nh.create = self.create |
|
659 | nh.create = self.create | |
660 | nh.remove = self.remove |
|
660 | nh.remove = self.remove | |
661 | return nh |
|
661 | return nh | |
662 |
|
662 | |||
663 | def read_unified_hunk(self, lr): |
|
663 | def read_unified_hunk(self, lr): | |
664 | m = unidesc.match(self.desc) |
|
664 | m = unidesc.match(self.desc) | |
665 | if not m: |
|
665 | if not m: | |
666 | raise PatchError(_("bad hunk #%d") % self.number) |
|
666 | raise PatchError(_("bad hunk #%d") % self.number) | |
667 | self.starta, foo, self.lena, self.startb, foo2, self.lenb = m.groups() |
|
667 | self.starta, foo, self.lena, self.startb, foo2, self.lenb = m.groups() | |
668 | if self.lena is None: |
|
668 | if self.lena is None: | |
669 | self.lena = 1 |
|
669 | self.lena = 1 | |
670 | else: |
|
670 | else: | |
671 | self.lena = int(self.lena) |
|
671 | self.lena = int(self.lena) | |
672 | if self.lenb is None: |
|
672 | if self.lenb is None: | |
673 | self.lenb = 1 |
|
673 | self.lenb = 1 | |
674 | else: |
|
674 | else: | |
675 | self.lenb = int(self.lenb) |
|
675 | self.lenb = int(self.lenb) | |
676 | self.starta = int(self.starta) |
|
676 | self.starta = int(self.starta) | |
677 | self.startb = int(self.startb) |
|
677 | self.startb = int(self.startb) | |
678 | diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a, self.b) |
|
678 | diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a, self.b) | |
679 | # if we hit eof before finishing out the hunk, the last line will |
|
679 | # if we hit eof before finishing out the hunk, the last line will | |
680 | # be zero length. Lets try to fix it up. |
|
680 | # be zero length. Lets try to fix it up. | |
681 | while len(self.hunk[-1]) == 0: |
|
681 | while len(self.hunk[-1]) == 0: | |
682 | del self.hunk[-1] |
|
682 | del self.hunk[-1] | |
683 | del self.a[-1] |
|
683 | del self.a[-1] | |
684 | del self.b[-1] |
|
684 | del self.b[-1] | |
685 | self.lena -= 1 |
|
685 | self.lena -= 1 | |
686 | self.lenb -= 1 |
|
686 | self.lenb -= 1 | |
687 | self._fixnewline(lr) |
|
687 | self._fixnewline(lr) | |
688 |
|
688 | |||
689 | def read_context_hunk(self, lr): |
|
689 | def read_context_hunk(self, lr): | |
690 | self.desc = lr.readline() |
|
690 | self.desc = lr.readline() | |
691 | m = contextdesc.match(self.desc) |
|
691 | m = contextdesc.match(self.desc) | |
692 | if not m: |
|
692 | if not m: | |
693 | raise PatchError(_("bad hunk #%d") % self.number) |
|
693 | raise PatchError(_("bad hunk #%d") % self.number) | |
694 | foo, self.starta, foo2, aend, foo3 = m.groups() |
|
694 | foo, self.starta, foo2, aend, foo3 = m.groups() | |
695 | self.starta = int(self.starta) |
|
695 | self.starta = int(self.starta) | |
696 | if aend is None: |
|
696 | if aend is None: | |
697 | aend = self.starta |
|
697 | aend = self.starta | |
698 | self.lena = int(aend) - self.starta |
|
698 | self.lena = int(aend) - self.starta | |
699 | if self.starta: |
|
699 | if self.starta: | |
700 | self.lena += 1 |
|
700 | self.lena += 1 | |
701 | for x in xrange(self.lena): |
|
701 | for x in xrange(self.lena): | |
702 | l = lr.readline() |
|
702 | l = lr.readline() | |
703 | if l.startswith('---'): |
|
703 | if l.startswith('---'): | |
704 | # lines addition, old block is empty |
|
704 | # lines addition, old block is empty | |
705 | lr.push(l) |
|
705 | lr.push(l) | |
706 | break |
|
706 | break | |
707 | s = l[2:] |
|
707 | s = l[2:] | |
708 | if l.startswith('- ') or l.startswith('! '): |
|
708 | if l.startswith('- ') or l.startswith('! '): | |
709 | u = '-' + s |
|
709 | u = '-' + s | |
710 | elif l.startswith(' '): |
|
710 | elif l.startswith(' '): | |
711 | u = ' ' + s |
|
711 | u = ' ' + s | |
712 | else: |
|
712 | else: | |
713 | raise PatchError(_("bad hunk #%d old text line %d") % |
|
713 | raise PatchError(_("bad hunk #%d old text line %d") % | |
714 | (self.number, x)) |
|
714 | (self.number, x)) | |
715 | self.a.append(u) |
|
715 | self.a.append(u) | |
716 | self.hunk.append(u) |
|
716 | self.hunk.append(u) | |
717 |
|
717 | |||
718 | l = lr.readline() |
|
718 | l = lr.readline() | |
719 | if l.startswith('\ '): |
|
719 | if l.startswith('\ '): | |
720 | s = self.a[-1][:-1] |
|
720 | s = self.a[-1][:-1] | |
721 | self.a[-1] = s |
|
721 | self.a[-1] = s | |
722 | self.hunk[-1] = s |
|
722 | self.hunk[-1] = s | |
723 | l = lr.readline() |
|
723 | l = lr.readline() | |
724 | m = contextdesc.match(l) |
|
724 | m = contextdesc.match(l) | |
725 | if not m: |
|
725 | if not m: | |
726 | raise PatchError(_("bad hunk #%d") % self.number) |
|
726 | raise PatchError(_("bad hunk #%d") % self.number) | |
727 | foo, self.startb, foo2, bend, foo3 = m.groups() |
|
727 | foo, self.startb, foo2, bend, foo3 = m.groups() | |
728 | self.startb = int(self.startb) |
|
728 | self.startb = int(self.startb) | |
729 | if bend is None: |
|
729 | if bend is None: | |
730 | bend = self.startb |
|
730 | bend = self.startb | |
731 | self.lenb = int(bend) - self.startb |
|
731 | self.lenb = int(bend) - self.startb | |
732 | if self.startb: |
|
732 | if self.startb: | |
733 | self.lenb += 1 |
|
733 | self.lenb += 1 | |
734 | hunki = 1 |
|
734 | hunki = 1 | |
735 | for x in xrange(self.lenb): |
|
735 | for x in xrange(self.lenb): | |
736 | l = lr.readline() |
|
736 | l = lr.readline() | |
737 | if l.startswith('\ '): |
|
737 | if l.startswith('\ '): | |
738 | # XXX: the only way to hit this is with an invalid line range. |
|
738 | # XXX: the only way to hit this is with an invalid line range. | |
739 | # The no-eol marker is not counted in the line range, but I |
|
739 | # The no-eol marker is not counted in the line range, but I | |
740 | # guess there are diff(1) out there which behave differently. |
|
740 | # guess there are diff(1) out there which behave differently. | |
741 | s = self.b[-1][:-1] |
|
741 | s = self.b[-1][:-1] | |
742 | self.b[-1] = s |
|
742 | self.b[-1] = s | |
743 | self.hunk[hunki - 1] = s |
|
743 | self.hunk[hunki - 1] = s | |
744 | continue |
|
744 | continue | |
745 | if not l: |
|
745 | if not l: | |
746 | # line deletions, new block is empty and we hit EOF |
|
746 | # line deletions, new block is empty and we hit EOF | |
747 | lr.push(l) |
|
747 | lr.push(l) | |
748 | break |
|
748 | break | |
749 | s = l[2:] |
|
749 | s = l[2:] | |
750 | if l.startswith('+ ') or l.startswith('! '): |
|
750 | if l.startswith('+ ') or l.startswith('! '): | |
751 | u = '+' + s |
|
751 | u = '+' + s | |
752 | elif l.startswith(' '): |
|
752 | elif l.startswith(' '): | |
753 | u = ' ' + s |
|
753 | u = ' ' + s | |
754 | elif len(self.b) == 0: |
|
754 | elif len(self.b) == 0: | |
755 | # line deletions, new block is empty |
|
755 | # line deletions, new block is empty | |
756 | lr.push(l) |
|
756 | lr.push(l) | |
757 | break |
|
757 | break | |
758 | else: |
|
758 | else: | |
759 | raise PatchError(_("bad hunk #%d old text line %d") % |
|
759 | raise PatchError(_("bad hunk #%d old text line %d") % | |
760 | (self.number, x)) |
|
760 | (self.number, x)) | |
761 | self.b.append(s) |
|
761 | self.b.append(s) | |
762 | while True: |
|
762 | while True: | |
763 | if hunki >= len(self.hunk): |
|
763 | if hunki >= len(self.hunk): | |
764 | h = "" |
|
764 | h = "" | |
765 | else: |
|
765 | else: | |
766 | h = self.hunk[hunki] |
|
766 | h = self.hunk[hunki] | |
767 | hunki += 1 |
|
767 | hunki += 1 | |
768 | if h == u: |
|
768 | if h == u: | |
769 | break |
|
769 | break | |
770 | elif h.startswith('-'): |
|
770 | elif h.startswith('-'): | |
771 | continue |
|
771 | continue | |
772 | else: |
|
772 | else: | |
773 | self.hunk.insert(hunki - 1, u) |
|
773 | self.hunk.insert(hunki - 1, u) | |
774 | break |
|
774 | break | |
775 |
|
775 | |||
776 | if not self.a: |
|
776 | if not self.a: | |
777 | # this happens when lines were only added to the hunk |
|
777 | # this happens when lines were only added to the hunk | |
778 | for x in self.hunk: |
|
778 | for x in self.hunk: | |
779 | if x.startswith('-') or x.startswith(' '): |
|
779 | if x.startswith('-') or x.startswith(' '): | |
780 | self.a.append(x) |
|
780 | self.a.append(x) | |
781 | if not self.b: |
|
781 | if not self.b: | |
782 | # this happens when lines were only deleted from the hunk |
|
782 | # this happens when lines were only deleted from the hunk | |
783 | for x in self.hunk: |
|
783 | for x in self.hunk: | |
784 | if x.startswith('+') or x.startswith(' '): |
|
784 | if x.startswith('+') or x.startswith(' '): | |
785 | self.b.append(x[1:]) |
|
785 | self.b.append(x[1:]) | |
786 | # @@ -start,len +start,len @@ |
|
786 | # @@ -start,len +start,len @@ | |
787 | self.desc = "@@ -%d,%d +%d,%d @@\n" % (self.starta, self.lena, |
|
787 | self.desc = "@@ -%d,%d +%d,%d @@\n" % (self.starta, self.lena, | |
788 | self.startb, self.lenb) |
|
788 | self.startb, self.lenb) | |
789 | self.hunk[0] = self.desc |
|
789 | self.hunk[0] = self.desc | |
790 | self._fixnewline(lr) |
|
790 | self._fixnewline(lr) | |
791 |
|
791 | |||
792 | def _fixnewline(self, lr): |
|
792 | def _fixnewline(self, lr): | |
793 | l = lr.readline() |
|
793 | l = lr.readline() | |
794 | if l.startswith('\ '): |
|
794 | if l.startswith('\ '): | |
795 | diffhelpers.fix_newline(self.hunk, self.a, self.b) |
|
795 | diffhelpers.fix_newline(self.hunk, self.a, self.b) | |
796 | else: |
|
796 | else: | |
797 | lr.push(l) |
|
797 | lr.push(l) | |
798 |
|
798 | |||
799 | def complete(self): |
|
799 | def complete(self): | |
800 | return len(self.a) == self.lena and len(self.b) == self.lenb |
|
800 | return len(self.a) == self.lena and len(self.b) == self.lenb | |
801 |
|
801 | |||
802 | def createfile(self): |
|
802 | def createfile(self): | |
803 | return self.starta == 0 and self.lena == 0 and self.create |
|
803 | return self.starta == 0 and self.lena == 0 and self.create | |
804 |
|
804 | |||
805 | def rmfile(self): |
|
805 | def rmfile(self): | |
806 | return self.startb == 0 and self.lenb == 0 and self.remove |
|
806 | return self.startb == 0 and self.lenb == 0 and self.remove | |
807 |
|
807 | |||
808 | def fuzzit(self, l, fuzz, toponly): |
|
808 | def fuzzit(self, l, fuzz, toponly): | |
809 | # this removes context lines from the top and bottom of list 'l'. It |
|
809 | # this removes context lines from the top and bottom of list 'l'. It | |
810 | # checks the hunk to make sure only context lines are removed, and then |
|
810 | # checks the hunk to make sure only context lines are removed, and then | |
811 | # returns a new shortened list of lines. |
|
811 | # returns a new shortened list of lines. | |
812 | fuzz = min(fuzz, len(l)-1) |
|
812 | fuzz = min(fuzz, len(l)-1) | |
813 | if fuzz: |
|
813 | if fuzz: | |
814 | top = 0 |
|
814 | top = 0 | |
815 | bot = 0 |
|
815 | bot = 0 | |
816 | hlen = len(self.hunk) |
|
816 | hlen = len(self.hunk) | |
817 | for x in xrange(hlen - 1): |
|
817 | for x in xrange(hlen - 1): | |
818 | # the hunk starts with the @@ line, so use x+1 |
|
818 | # the hunk starts with the @@ line, so use x+1 | |
819 | if self.hunk[x + 1][0] == ' ': |
|
819 | if self.hunk[x + 1][0] == ' ': | |
820 | top += 1 |
|
820 | top += 1 | |
821 | else: |
|
821 | else: | |
822 | break |
|
822 | break | |
823 | if not toponly: |
|
823 | if not toponly: | |
824 | for x in xrange(hlen - 1): |
|
824 | for x in xrange(hlen - 1): | |
825 | if self.hunk[hlen - bot - 1][0] == ' ': |
|
825 | if self.hunk[hlen - bot - 1][0] == ' ': | |
826 | bot += 1 |
|
826 | bot += 1 | |
827 | else: |
|
827 | else: | |
828 | break |
|
828 | break | |
829 |
|
829 | |||
830 | # top and bot now count context in the hunk |
|
830 | # top and bot now count context in the hunk | |
831 | # adjust them if either one is short |
|
831 | # adjust them if either one is short | |
832 | context = max(top, bot, 3) |
|
832 | context = max(top, bot, 3) | |
833 | if bot < context: |
|
833 | if bot < context: | |
834 | bot = max(0, fuzz - (context - bot)) |
|
834 | bot = max(0, fuzz - (context - bot)) | |
835 | else: |
|
835 | else: | |
836 | bot = min(fuzz, bot) |
|
836 | bot = min(fuzz, bot) | |
837 | if top < context: |
|
837 | if top < context: | |
838 | top = max(0, fuzz - (context - top)) |
|
838 | top = max(0, fuzz - (context - top)) | |
839 | else: |
|
839 | else: | |
840 | top = min(fuzz, top) |
|
840 | top = min(fuzz, top) | |
841 |
|
841 | |||
842 | return l[top:len(l)-bot] |
|
842 | return l[top:len(l)-bot] | |
843 | return l |
|
843 | return l | |
844 |
|
844 | |||
845 | def old(self, fuzz=0, toponly=False): |
|
845 | def old(self, fuzz=0, toponly=False): | |
846 | return self.fuzzit(self.a, fuzz, toponly) |
|
846 | return self.fuzzit(self.a, fuzz, toponly) | |
847 |
|
847 | |||
848 | def new(self, fuzz=0, toponly=False): |
|
848 | def new(self, fuzz=0, toponly=False): | |
849 | return self.fuzzit(self.b, fuzz, toponly) |
|
849 | return self.fuzzit(self.b, fuzz, toponly) | |
850 |
|
850 | |||
851 | class binhunk: |
|
851 | class binhunk: | |
852 | 'A binary patch file. Only understands literals so far.' |
|
852 | 'A binary patch file. Only understands literals so far.' | |
853 | def __init__(self, gitpatch): |
|
853 | def __init__(self, gitpatch): | |
854 | self.gitpatch = gitpatch |
|
854 | self.gitpatch = gitpatch | |
855 | self.text = None |
|
855 | self.text = None | |
856 | self.hunk = ['GIT binary patch\n'] |
|
856 | self.hunk = ['GIT binary patch\n'] | |
857 |
|
857 | |||
858 | def createfile(self): |
|
858 | def createfile(self): | |
859 | return self.gitpatch.op in ('ADD', 'RENAME', 'COPY') |
|
859 | return self.gitpatch.op in ('ADD', 'RENAME', 'COPY') | |
860 |
|
860 | |||
861 | def rmfile(self): |
|
861 | def rmfile(self): | |
862 | return self.gitpatch.op == 'DELETE' |
|
862 | return self.gitpatch.op == 'DELETE' | |
863 |
|
863 | |||
864 | def complete(self): |
|
864 | def complete(self): | |
865 | return self.text is not None |
|
865 | return self.text is not None | |
866 |
|
866 | |||
867 | def new(self): |
|
867 | def new(self): | |
868 | return [self.text] |
|
868 | return [self.text] | |
869 |
|
869 | |||
870 | def extract(self, lr): |
|
870 | def extract(self, lr): | |
871 | line = lr.readline() |
|
871 | line = lr.readline() | |
872 | self.hunk.append(line) |
|
872 | self.hunk.append(line) | |
873 | while line and not line.startswith('literal '): |
|
873 | while line and not line.startswith('literal '): | |
874 | line = lr.readline() |
|
874 | line = lr.readline() | |
875 | self.hunk.append(line) |
|
875 | self.hunk.append(line) | |
876 | if not line: |
|
876 | if not line: | |
877 | raise PatchError(_('could not extract binary patch')) |
|
877 | raise PatchError(_('could not extract binary patch')) | |
878 | size = int(line[8:].rstrip()) |
|
878 | size = int(line[8:].rstrip()) | |
879 | dec = [] |
|
879 | dec = [] | |
880 | line = lr.readline() |
|
880 | line = lr.readline() | |
881 | self.hunk.append(line) |
|
881 | self.hunk.append(line) | |
882 | while len(line) > 1: |
|
882 | while len(line) > 1: | |
883 | l = line[0] |
|
883 | l = line[0] | |
884 | if l <= 'Z' and l >= 'A': |
|
884 | if l <= 'Z' and l >= 'A': | |
885 | l = ord(l) - ord('A') + 1 |
|
885 | l = ord(l) - ord('A') + 1 | |
886 | else: |
|
886 | else: | |
887 | l = ord(l) - ord('a') + 27 |
|
887 | l = ord(l) - ord('a') + 27 | |
888 | dec.append(base85.b85decode(line[1:-1])[:l]) |
|
888 | dec.append(base85.b85decode(line[1:-1])[:l]) | |
889 | line = lr.readline() |
|
889 | line = lr.readline() | |
890 | self.hunk.append(line) |
|
890 | self.hunk.append(line) | |
891 | text = zlib.decompress(''.join(dec)) |
|
891 | text = zlib.decompress(''.join(dec)) | |
892 | if len(text) != size: |
|
892 | if len(text) != size: | |
893 | raise PatchError(_('binary patch is %d bytes, not %d') % |
|
893 | raise PatchError(_('binary patch is %d bytes, not %d') % | |
894 | len(text), size) |
|
894 | len(text), size) | |
895 | self.text = text |
|
895 | self.text = text | |
896 |
|
896 | |||
897 | def parsefilename(str): |
|
897 | def parsefilename(str): | |
898 | # --- filename \t|space stuff |
|
898 | # --- filename \t|space stuff | |
899 | s = str[4:].rstrip('\r\n') |
|
899 | s = str[4:].rstrip('\r\n') | |
900 | i = s.find('\t') |
|
900 | i = s.find('\t') | |
901 | if i < 0: |
|
901 | if i < 0: | |
902 | i = s.find(' ') |
|
902 | i = s.find(' ') | |
903 | if i < 0: |
|
903 | if i < 0: | |
904 | return s |
|
904 | return s | |
905 | return s[:i] |
|
905 | return s[:i] | |
906 |
|
906 | |||
907 | def pathstrip(path, strip): |
|
907 | def pathstrip(path, strip): | |
908 | pathlen = len(path) |
|
908 | pathlen = len(path) | |
909 | i = 0 |
|
909 | i = 0 | |
910 | if strip == 0: |
|
910 | if strip == 0: | |
911 | return '', path.rstrip() |
|
911 | return '', path.rstrip() | |
912 | count = strip |
|
912 | count = strip | |
913 | while count > 0: |
|
913 | while count > 0: | |
914 | i = path.find('/', i) |
|
914 | i = path.find('/', i) | |
915 | if i == -1: |
|
915 | if i == -1: | |
916 | raise PatchError(_("unable to strip away %d of %d dirs from %s") % |
|
916 | raise PatchError(_("unable to strip away %d of %d dirs from %s") % | |
917 | (count, strip, path)) |
|
917 | (count, strip, path)) | |
918 | i += 1 |
|
918 | i += 1 | |
919 | # consume '//' in the path |
|
919 | # consume '//' in the path | |
920 | while i < pathlen - 1 and path[i] == '/': |
|
920 | while i < pathlen - 1 and path[i] == '/': | |
921 | i += 1 |
|
921 | i += 1 | |
922 | count -= 1 |
|
922 | count -= 1 | |
923 | return path[:i].lstrip(), path[i:].rstrip() |
|
923 | return path[:i].lstrip(), path[i:].rstrip() | |
924 |
|
924 | |||
925 | def selectfile(afile_orig, bfile_orig, hunk, strip): |
|
925 | def selectfile(afile_orig, bfile_orig, hunk, strip): | |
926 | nulla = afile_orig == "/dev/null" |
|
926 | nulla = afile_orig == "/dev/null" | |
927 | nullb = bfile_orig == "/dev/null" |
|
927 | nullb = bfile_orig == "/dev/null" | |
928 | abase, afile = pathstrip(afile_orig, strip) |
|
928 | abase, afile = pathstrip(afile_orig, strip) | |
929 | gooda = not nulla and os.path.lexists(afile) |
|
929 | gooda = not nulla and os.path.lexists(afile) | |
930 | bbase, bfile = pathstrip(bfile_orig, strip) |
|
930 | bbase, bfile = pathstrip(bfile_orig, strip) | |
931 | if afile == bfile: |
|
931 | if afile == bfile: | |
932 | goodb = gooda |
|
932 | goodb = gooda | |
933 | else: |
|
933 | else: | |
934 | goodb = not nullb and os.path.lexists(bfile) |
|
934 | goodb = not nullb and os.path.lexists(bfile) | |
935 | createfunc = hunk.createfile |
|
935 | createfunc = hunk.createfile | |
936 | missing = not goodb and not gooda and not createfunc() |
|
936 | missing = not goodb and not gooda and not createfunc() | |
937 |
|
937 | |||
938 | # some diff programs apparently produce patches where the afile is |
|
938 | # some diff programs apparently produce patches where the afile is | |
939 | # not /dev/null, but afile starts with bfile |
|
939 | # not /dev/null, but afile starts with bfile | |
940 | abasedir = afile[:afile.rfind('/') + 1] |
|
940 | abasedir = afile[:afile.rfind('/') + 1] | |
941 | bbasedir = bfile[:bfile.rfind('/') + 1] |
|
941 | bbasedir = bfile[:bfile.rfind('/') + 1] | |
942 | if missing and abasedir == bbasedir and afile.startswith(bfile): |
|
942 | if missing and abasedir == bbasedir and afile.startswith(bfile): | |
943 | # this isn't very pretty |
|
943 | # this isn't very pretty | |
944 | hunk.create = True |
|
944 | hunk.create = True | |
945 | if createfunc(): |
|
945 | if createfunc(): | |
946 | missing = False |
|
946 | missing = False | |
947 | else: |
|
947 | else: | |
948 | hunk.create = False |
|
948 | hunk.create = False | |
949 |
|
949 | |||
950 | # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the |
|
950 | # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the | |
951 | # diff is between a file and its backup. In this case, the original |
|
951 | # diff is between a file and its backup. In this case, the original | |
952 | # file should be patched (see original mpatch code). |
|
952 | # file should be patched (see original mpatch code). | |
953 | isbackup = (abase == bbase and bfile.startswith(afile)) |
|
953 | isbackup = (abase == bbase and bfile.startswith(afile)) | |
954 | fname = None |
|
954 | fname = None | |
955 | if not missing: |
|
955 | if not missing: | |
956 | if gooda and goodb: |
|
956 | if gooda and goodb: | |
957 | fname = isbackup and afile or bfile |
|
957 | fname = isbackup and afile or bfile | |
958 | elif gooda: |
|
958 | elif gooda: | |
959 | fname = afile |
|
959 | fname = afile | |
960 |
|
960 | |||
961 | if not fname: |
|
961 | if not fname: | |
962 | if not nullb: |
|
962 | if not nullb: | |
963 | fname = isbackup and afile or bfile |
|
963 | fname = isbackup and afile or bfile | |
964 | elif not nulla: |
|
964 | elif not nulla: | |
965 | fname = afile |
|
965 | fname = afile | |
966 | else: |
|
966 | else: | |
967 | raise PatchError(_("undefined source and destination files")) |
|
967 | raise PatchError(_("undefined source and destination files")) | |
968 |
|
968 | |||
969 | return fname, missing |
|
969 | return fname, missing | |
970 |
|
970 | |||
971 | def scangitpatch(lr, firstline): |
|
971 | def scangitpatch(lr, firstline): | |
972 | """ |
|
972 | """ | |
973 | Git patches can emit: |
|
973 | Git patches can emit: | |
974 | - rename a to b |
|
974 | - rename a to b | |
975 | - change b |
|
975 | - change b | |
976 | - copy a to c |
|
976 | - copy a to c | |
977 | - change c |
|
977 | - change c | |
978 |
|
978 | |||
979 | We cannot apply this sequence as-is, the renamed 'a' could not be |
|
979 | We cannot apply this sequence as-is, the renamed 'a' could not be | |
980 | found for it would have been renamed already. And we cannot copy |
|
980 | found for it would have been renamed already. And we cannot copy | |
981 | from 'b' instead because 'b' would have been changed already. So |
|
981 | from 'b' instead because 'b' would have been changed already. So | |
982 | we scan the git patch for copy and rename commands so we can |
|
982 | we scan the git patch for copy and rename commands so we can | |
983 | perform the copies ahead of time. |
|
983 | perform the copies ahead of time. | |
984 | """ |
|
984 | """ | |
985 | pos = 0 |
|
985 | pos = 0 | |
986 | try: |
|
986 | try: | |
987 | pos = lr.fp.tell() |
|
987 | pos = lr.fp.tell() | |
988 | fp = lr.fp |
|
988 | fp = lr.fp | |
989 | except IOError: |
|
989 | except IOError: | |
990 | fp = cStringIO.StringIO(lr.fp.read()) |
|
990 | fp = cStringIO.StringIO(lr.fp.read()) | |
991 | gitlr = linereader(fp, lr.textmode) |
|
991 | gitlr = linereader(fp, lr.textmode) | |
992 | gitlr.push(firstline) |
|
992 | gitlr.push(firstline) | |
993 | gitpatches = readgitpatch(gitlr) |
|
993 | gitpatches = readgitpatch(gitlr) | |
994 | fp.seek(pos) |
|
994 | fp.seek(pos) | |
995 | return gitpatches |
|
995 | return gitpatches | |
996 |
|
996 | |||
997 | def iterhunks(fp): |
|
997 | def iterhunks(fp): | |
998 | """Read a patch and yield the following events: |
|
998 | """Read a patch and yield the following events: | |
999 | - ("file", afile, bfile, firsthunk): select a new target file. |
|
999 | - ("file", afile, bfile, firsthunk): select a new target file. | |
1000 | - ("hunk", hunk): a new hunk is ready to be applied, follows a |
|
1000 | - ("hunk", hunk): a new hunk is ready to be applied, follows a | |
1001 | "file" event. |
|
1001 | "file" event. | |
1002 | - ("git", gitchanges): current diff is in git format, gitchanges |
|
1002 | - ("git", gitchanges): current diff is in git format, gitchanges | |
1003 | maps filenames to gitpatch records. Unique event. |
|
1003 | maps filenames to gitpatch records. Unique event. | |
1004 | """ |
|
1004 | """ | |
1005 | changed = {} |
|
1005 | changed = {} | |
1006 | afile = "" |
|
1006 | afile = "" | |
1007 | bfile = "" |
|
1007 | bfile = "" | |
1008 | state = None |
|
1008 | state = None | |
1009 | hunknum = 0 |
|
1009 | hunknum = 0 | |
1010 | emitfile = newfile = False |
|
1010 | emitfile = newfile = False | |
1011 | git = False |
|
1011 | git = False | |
1012 |
|
1012 | |||
1013 | # our states |
|
1013 | # our states | |
1014 | BFILE = 1 |
|
1014 | BFILE = 1 | |
1015 | context = None |
|
1015 | context = None | |
1016 | lr = linereader(fp) |
|
1016 | lr = linereader(fp) | |
1017 |
|
1017 | |||
1018 | while True: |
|
1018 | while True: | |
1019 | x = lr.readline() |
|
1019 | x = lr.readline() | |
1020 | if not x: |
|
1020 | if not x: | |
1021 | break |
|
1021 | break | |
1022 | if (state == BFILE and ((not context and x[0] == '@') or |
|
1022 | if (state == BFILE and ((not context and x[0] == '@') or | |
1023 | ((context is not False) and x.startswith('***************')))): |
|
1023 | ((context is not False) and x.startswith('***************')))): | |
1024 | if context is None and x.startswith('***************'): |
|
1024 | if context is None and x.startswith('***************'): | |
1025 | context = True |
|
1025 | context = True | |
1026 | gpatch = changed.get(bfile) |
|
1026 | gpatch = changed.get(bfile) | |
1027 | create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD' |
|
1027 | create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD' | |
1028 | remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE' |
|
1028 | remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE' | |
1029 | h = hunk(x, hunknum + 1, lr, context, create, remove) |
|
1029 | h = hunk(x, hunknum + 1, lr, context, create, remove) | |
1030 | hunknum += 1 |
|
1030 | hunknum += 1 | |
1031 | if emitfile: |
|
1031 | if emitfile: | |
1032 | emitfile = False |
|
1032 | emitfile = False | |
1033 | yield 'file', (afile, bfile, h) |
|
1033 | yield 'file', (afile, bfile, h) | |
1034 | yield 'hunk', h |
|
1034 | yield 'hunk', h | |
1035 | elif state == BFILE and x.startswith('GIT binary patch'): |
|
1035 | elif state == BFILE and x.startswith('GIT binary patch'): | |
1036 | h = binhunk(changed[bfile]) |
|
1036 | h = binhunk(changed[bfile]) | |
1037 | hunknum += 1 |
|
1037 | hunknum += 1 | |
1038 | if emitfile: |
|
1038 | if emitfile: | |
1039 | emitfile = False |
|
1039 | emitfile = False | |
1040 | yield 'file', ('a/' + afile, 'b/' + bfile, h) |
|
1040 | yield 'file', ('a/' + afile, 'b/' + bfile, h) | |
1041 | h.extract(lr) |
|
1041 | h.extract(lr) | |
1042 | yield 'hunk', h |
|
1042 | yield 'hunk', h | |
1043 | elif x.startswith('diff --git'): |
|
1043 | elif x.startswith('diff --git'): | |
1044 | # check for git diff, scanning the whole patch file if needed |
|
1044 | # check for git diff, scanning the whole patch file if needed | |
1045 | m = gitre.match(x) |
|
1045 | m = gitre.match(x) | |
1046 | if m: |
|
1046 | if m: | |
1047 | afile, bfile = m.group(1, 2) |
|
1047 | afile, bfile = m.group(1, 2) | |
1048 | if not git: |
|
1048 | if not git: | |
1049 | git = True |
|
1049 | git = True | |
1050 | gitpatches = scangitpatch(lr, x) |
|
1050 | gitpatches = scangitpatch(lr, x) | |
1051 | yield 'git', gitpatches |
|
1051 | yield 'git', gitpatches | |
1052 | for gp in gitpatches: |
|
1052 | for gp in gitpatches: | |
1053 | changed[gp.path] = gp |
|
1053 | changed[gp.path] = gp | |
1054 | # else error? |
|
1054 | # else error? | |
1055 | # copy/rename + modify should modify target, not source |
|
1055 | # copy/rename + modify should modify target, not source | |
1056 | gp = changed.get(bfile) |
|
1056 | gp = changed.get(bfile) | |
1057 | if gp and (gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD') |
|
1057 | if gp and (gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD') | |
1058 | or gp.mode): |
|
1058 | or gp.mode): | |
1059 | afile = bfile |
|
1059 | afile = bfile | |
1060 | newfile = True |
|
1060 | newfile = True | |
1061 | elif x.startswith('---'): |
|
1061 | elif x.startswith('---'): | |
1062 | # check for a unified diff |
|
1062 | # check for a unified diff | |
1063 | l2 = lr.readline() |
|
1063 | l2 = lr.readline() | |
1064 | if not l2.startswith('+++'): |
|
1064 | if not l2.startswith('+++'): | |
1065 | lr.push(l2) |
|
1065 | lr.push(l2) | |
1066 | continue |
|
1066 | continue | |
1067 | newfile = True |
|
1067 | newfile = True | |
1068 | context = False |
|
1068 | context = False | |
1069 | afile = parsefilename(x) |
|
1069 | afile = parsefilename(x) | |
1070 | bfile = parsefilename(l2) |
|
1070 | bfile = parsefilename(l2) | |
1071 | elif x.startswith('***'): |
|
1071 | elif x.startswith('***'): | |
1072 | # check for a context diff |
|
1072 | # check for a context diff | |
1073 | l2 = lr.readline() |
|
1073 | l2 = lr.readline() | |
1074 | if not l2.startswith('---'): |
|
1074 | if not l2.startswith('---'): | |
1075 | lr.push(l2) |
|
1075 | lr.push(l2) | |
1076 | continue |
|
1076 | continue | |
1077 | l3 = lr.readline() |
|
1077 | l3 = lr.readline() | |
1078 | lr.push(l3) |
|
1078 | lr.push(l3) | |
1079 | if not l3.startswith("***************"): |
|
1079 | if not l3.startswith("***************"): | |
1080 | lr.push(l2) |
|
1080 | lr.push(l2) | |
1081 | continue |
|
1081 | continue | |
1082 | newfile = True |
|
1082 | newfile = True | |
1083 | context = True |
|
1083 | context = True | |
1084 | afile = parsefilename(x) |
|
1084 | afile = parsefilename(x) | |
1085 | bfile = parsefilename(l2) |
|
1085 | bfile = parsefilename(l2) | |
1086 |
|
1086 | |||
1087 | if newfile: |
|
1087 | if newfile: | |
1088 | newfile = False |
|
1088 | newfile = False | |
1089 | emitfile = True |
|
1089 | emitfile = True | |
1090 | state = BFILE |
|
1090 | state = BFILE | |
1091 | hunknum = 0 |
|
1091 | hunknum = 0 | |
1092 |
|
1092 | |||
1093 | def applydiff(ui, fp, changed, strip=1, eolmode='strict'): |
|
1093 | def applydiff(ui, fp, changed, strip=1, eolmode='strict'): | |
1094 | """Reads a patch from fp and tries to apply it. |
|
1094 | """Reads a patch from fp and tries to apply it. | |
1095 |
|
1095 | |||
1096 | The dict 'changed' is filled in with all of the filenames changed |
|
1096 | The dict 'changed' is filled in with all of the filenames changed | |
1097 | by the patch. Returns 0 for a clean patch, -1 if any rejects were |
|
1097 | by the patch. Returns 0 for a clean patch, -1 if any rejects were | |
1098 | found and 1 if there was any fuzz. |
|
1098 | found and 1 if there was any fuzz. | |
1099 |
|
1099 | |||
1100 | If 'eolmode' is 'strict', the patch content and patched file are |
|
1100 | If 'eolmode' is 'strict', the patch content and patched file are | |
1101 | read in binary mode. Otherwise, line endings are ignored when |
|
1101 | read in binary mode. Otherwise, line endings are ignored when | |
1102 | patching then normalized according to 'eolmode'. |
|
1102 | patching then normalized according to 'eolmode'. | |
1103 |
|
1103 | |||
1104 | Callers probably want to call '_updatedir' after this to |
|
1104 | Callers probably want to call '_updatedir' after this to | |
1105 | apply certain categories of changes not done by this function. |
|
1105 | apply certain categories of changes not done by this function. | |
1106 | """ |
|
1106 | """ | |
1107 | return _applydiff(ui, fp, patchfile, copyfile, changed, strip=strip, |
|
1107 | return _applydiff(ui, fp, patchfile, copyfile, changed, strip=strip, | |
1108 | eolmode=eolmode) |
|
1108 | eolmode=eolmode) | |
1109 |
|
1109 | |||
1110 | def _applydiff(ui, fp, patcher, copyfn, changed, strip=1, eolmode='strict'): |
|
1110 | def _applydiff(ui, fp, patcher, copyfn, changed, strip=1, eolmode='strict'): | |
1111 | rejects = 0 |
|
1111 | rejects = 0 | |
1112 | err = 0 |
|
1112 | err = 0 | |
1113 | current_file = None |
|
1113 | current_file = None | |
1114 | cwd = os.getcwd() |
|
1114 | cwd = os.getcwd() | |
1115 | opener = scmutil.opener(cwd) |
|
1115 | opener = scmutil.opener(cwd) | |
1116 |
|
1116 | |||
1117 | for state, values in iterhunks(fp): |
|
1117 | for state, values in iterhunks(fp): | |
1118 | if state == 'hunk': |
|
1118 | if state == 'hunk': | |
1119 | if not current_file: |
|
1119 | if not current_file: | |
1120 | continue |
|
1120 | continue | |
1121 | ret = current_file.apply(values) |
|
1121 | ret = current_file.apply(values) | |
1122 | if ret >= 0: |
|
1122 | if ret >= 0: | |
1123 | changed.setdefault(current_file.fname, None) |
|
1123 | changed.setdefault(current_file.fname, None) | |
1124 | if ret > 0: |
|
1124 | if ret > 0: | |
1125 | err = 1 |
|
1125 | err = 1 | |
1126 | elif state == 'file': |
|
1126 | elif state == 'file': | |
1127 | if current_file: |
|
1127 | if current_file: | |
1128 | rejects += current_file.close() |
|
1128 | rejects += current_file.close() | |
1129 | afile, bfile, first_hunk = values |
|
1129 | afile, bfile, first_hunk = values | |
1130 | try: |
|
1130 | try: | |
1131 | current_file, missing = selectfile(afile, bfile, |
|
1131 | current_file, missing = selectfile(afile, bfile, | |
1132 | first_hunk, strip) |
|
1132 | first_hunk, strip) | |
1133 | current_file = patcher(ui, current_file, opener, |
|
1133 | current_file = patcher(ui, current_file, opener, | |
1134 | missing=missing, eolmode=eolmode) |
|
1134 | missing=missing, eolmode=eolmode) | |
1135 | except PatchError, inst: |
|
1135 | except PatchError, inst: | |
1136 | ui.warn(str(inst) + '\n') |
|
1136 | ui.warn(str(inst) + '\n') | |
1137 | current_file = None |
|
1137 | current_file = None | |
1138 | rejects += 1 |
|
1138 | rejects += 1 | |
1139 | continue |
|
1139 | continue | |
1140 | elif state == 'git': |
|
1140 | elif state == 'git': | |
1141 | for gp in values: |
|
1141 | for gp in values: | |
1142 | gp.path = pathstrip(gp.path, strip - 1)[1] |
|
1142 | gp.path = pathstrip(gp.path, strip - 1)[1] | |
1143 | if gp.oldpath: |
|
1143 | if gp.oldpath: | |
1144 | gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1] |
|
1144 | gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1] | |
1145 | # Binary patches really overwrite target files, copying them |
|
1145 | # Binary patches really overwrite target files, copying them | |
1146 | # will just make it fails with "target file exists" |
|
1146 | # will just make it fails with "target file exists" | |
1147 | if gp.op in ('COPY', 'RENAME') and not gp.binary: |
|
1147 | if gp.op in ('COPY', 'RENAME') and not gp.binary: | |
1148 | copyfn(gp.oldpath, gp.path, cwd) |
|
1148 | copyfn(gp.oldpath, gp.path, cwd) | |
1149 | changed[gp.path] = gp |
|
1149 | changed[gp.path] = gp | |
1150 | else: |
|
1150 | else: | |
1151 | raise util.Abort(_('unsupported parser state: %s') % state) |
|
1151 | raise util.Abort(_('unsupported parser state: %s') % state) | |
1152 |
|
1152 | |||
1153 | if current_file: |
|
1153 | if current_file: | |
1154 | rejects += current_file.close() |
|
1154 | rejects += current_file.close() | |
1155 |
|
1155 | |||
1156 | if rejects: |
|
1156 | if rejects: | |
1157 | return -1 |
|
1157 | return -1 | |
1158 | return err |
|
1158 | return err | |
1159 |
|
1159 | |||
1160 | def _updatedir(ui, repo, patches, similarity=0): |
|
1160 | def _updatedir(ui, repo, patches, similarity=0): | |
1161 | '''Update dirstate after patch application according to metadata''' |
|
1161 | '''Update dirstate after patch application according to metadata''' | |
1162 | if not patches: |
|
1162 | if not patches: | |
1163 | return [] |
|
1163 | return [] | |
1164 | copies = [] |
|
1164 | copies = [] | |
1165 | removes = set() |
|
1165 | removes = set() | |
1166 | cfiles = patches.keys() |
|
1166 | cfiles = patches.keys() | |
1167 | cwd = repo.getcwd() |
|
1167 | cwd = repo.getcwd() | |
1168 | if cwd: |
|
1168 | if cwd: | |
1169 | cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] |
|
1169 | cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] | |
1170 | for f in patches: |
|
1170 | for f in patches: | |
1171 | gp = patches[f] |
|
1171 | gp = patches[f] | |
1172 | if not gp: |
|
1172 | if not gp: | |
1173 | continue |
|
1173 | continue | |
1174 | if gp.op == 'RENAME': |
|
1174 | if gp.op == 'RENAME': | |
1175 | copies.append((gp.oldpath, gp.path)) |
|
1175 | copies.append((gp.oldpath, gp.path)) | |
1176 | removes.add(gp.oldpath) |
|
1176 | removes.add(gp.oldpath) | |
1177 | elif gp.op == 'COPY': |
|
1177 | elif gp.op == 'COPY': | |
1178 | copies.append((gp.oldpath, gp.path)) |
|
1178 | copies.append((gp.oldpath, gp.path)) | |
1179 | elif gp.op == 'DELETE': |
|
1179 | elif gp.op == 'DELETE': | |
1180 | removes.add(gp.path) |
|
1180 | removes.add(gp.path) | |
1181 |
|
1181 | |||
1182 | wctx = repo[None] |
|
1182 | wctx = repo[None] | |
1183 | for src, dst in copies: |
|
1183 | for src, dst in copies: | |
1184 |
|
|
1184 | scmutil.dirstatecopy(ui, repo, wctx, src, dst, cwd=cwd) | |
1185 | if (not similarity) and removes: |
|
1185 | if (not similarity) and removes: | |
1186 | wctx.remove(sorted(removes), True) |
|
1186 | wctx.remove(sorted(removes), True) | |
1187 |
|
1187 | |||
1188 | for f in patches: |
|
1188 | for f in patches: | |
1189 | gp = patches[f] |
|
1189 | gp = patches[f] | |
1190 | if gp and gp.mode: |
|
1190 | if gp and gp.mode: | |
1191 | islink, isexec = gp.mode |
|
1191 | islink, isexec = gp.mode | |
1192 | dst = repo.wjoin(gp.path) |
|
1192 | dst = repo.wjoin(gp.path) | |
1193 | # patch won't create empty files |
|
1193 | # patch won't create empty files | |
1194 | if gp.op == 'ADD' and not os.path.lexists(dst): |
|
1194 | if gp.op == 'ADD' and not os.path.lexists(dst): | |
1195 | flags = (isexec and 'x' or '') + (islink and 'l' or '') |
|
1195 | flags = (isexec and 'x' or '') + (islink and 'l' or '') | |
1196 | repo.wwrite(gp.path, '', flags) |
|
1196 | repo.wwrite(gp.path, '', flags) | |
1197 | util.setflags(dst, islink, isexec) |
|
1197 | util.setflags(dst, islink, isexec) | |
1198 |
|
|
1198 | scmutil.addremove(repo, cfiles, similarity=similarity) | |
1199 | files = patches.keys() |
|
1199 | files = patches.keys() | |
1200 | files.extend([r for r in removes if r not in files]) |
|
1200 | files.extend([r for r in removes if r not in files]) | |
1201 | return sorted(files) |
|
1201 | return sorted(files) | |
1202 |
|
1202 | |||
1203 | def _externalpatch(patcher, patchname, ui, strip, cwd, files): |
|
1203 | def _externalpatch(patcher, patchname, ui, strip, cwd, files): | |
1204 | """use <patcher> to apply <patchname> to the working directory. |
|
1204 | """use <patcher> to apply <patchname> to the working directory. | |
1205 | returns whether patch was applied with fuzz factor.""" |
|
1205 | returns whether patch was applied with fuzz factor.""" | |
1206 |
|
1206 | |||
1207 | fuzz = False |
|
1207 | fuzz = False | |
1208 | args = [] |
|
1208 | args = [] | |
1209 | if cwd: |
|
1209 | if cwd: | |
1210 | args.append('-d %s' % util.shellquote(cwd)) |
|
1210 | args.append('-d %s' % util.shellquote(cwd)) | |
1211 | fp = util.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, |
|
1211 | fp = util.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, | |
1212 | util.shellquote(patchname))) |
|
1212 | util.shellquote(patchname))) | |
1213 |
|
1213 | |||
1214 | for line in fp: |
|
1214 | for line in fp: | |
1215 | line = line.rstrip() |
|
1215 | line = line.rstrip() | |
1216 | ui.note(line + '\n') |
|
1216 | ui.note(line + '\n') | |
1217 | if line.startswith('patching file '): |
|
1217 | if line.startswith('patching file '): | |
1218 | pf = util.parsepatchoutput(line) |
|
1218 | pf = util.parsepatchoutput(line) | |
1219 | printed_file = False |
|
1219 | printed_file = False | |
1220 | files.setdefault(pf, None) |
|
1220 | files.setdefault(pf, None) | |
1221 | elif line.find('with fuzz') >= 0: |
|
1221 | elif line.find('with fuzz') >= 0: | |
1222 | fuzz = True |
|
1222 | fuzz = True | |
1223 | if not printed_file: |
|
1223 | if not printed_file: | |
1224 | ui.warn(pf + '\n') |
|
1224 | ui.warn(pf + '\n') | |
1225 | printed_file = True |
|
1225 | printed_file = True | |
1226 | ui.warn(line + '\n') |
|
1226 | ui.warn(line + '\n') | |
1227 | elif line.find('saving rejects to file') >= 0: |
|
1227 | elif line.find('saving rejects to file') >= 0: | |
1228 | ui.warn(line + '\n') |
|
1228 | ui.warn(line + '\n') | |
1229 | elif line.find('FAILED') >= 0: |
|
1229 | elif line.find('FAILED') >= 0: | |
1230 | if not printed_file: |
|
1230 | if not printed_file: | |
1231 | ui.warn(pf + '\n') |
|
1231 | ui.warn(pf + '\n') | |
1232 | printed_file = True |
|
1232 | printed_file = True | |
1233 | ui.warn(line + '\n') |
|
1233 | ui.warn(line + '\n') | |
1234 | code = fp.close() |
|
1234 | code = fp.close() | |
1235 | if code: |
|
1235 | if code: | |
1236 | raise PatchError(_("patch command failed: %s") % |
|
1236 | raise PatchError(_("patch command failed: %s") % | |
1237 | util.explainexit(code)[0]) |
|
1237 | util.explainexit(code)[0]) | |
1238 | return fuzz |
|
1238 | return fuzz | |
1239 |
|
1239 | |||
1240 | def internalpatch(ui, repo, patchobj, strip, cwd, files=None, eolmode='strict', |
|
1240 | def internalpatch(ui, repo, patchobj, strip, cwd, files=None, eolmode='strict', | |
1241 | similarity=0): |
|
1241 | similarity=0): | |
1242 | """use builtin patch to apply <patchobj> to the working directory. |
|
1242 | """use builtin patch to apply <patchobj> to the working directory. | |
1243 | returns whether patch was applied with fuzz factor.""" |
|
1243 | returns whether patch was applied with fuzz factor.""" | |
1244 |
|
1244 | |||
1245 | if files is None: |
|
1245 | if files is None: | |
1246 | files = {} |
|
1246 | files = {} | |
1247 | if eolmode is None: |
|
1247 | if eolmode is None: | |
1248 | eolmode = ui.config('patch', 'eol', 'strict') |
|
1248 | eolmode = ui.config('patch', 'eol', 'strict') | |
1249 | if eolmode.lower() not in eolmodes: |
|
1249 | if eolmode.lower() not in eolmodes: | |
1250 | raise util.Abort(_('unsupported line endings type: %s') % eolmode) |
|
1250 | raise util.Abort(_('unsupported line endings type: %s') % eolmode) | |
1251 | eolmode = eolmode.lower() |
|
1251 | eolmode = eolmode.lower() | |
1252 |
|
1252 | |||
1253 | try: |
|
1253 | try: | |
1254 | fp = open(patchobj, 'rb') |
|
1254 | fp = open(patchobj, 'rb') | |
1255 | except TypeError: |
|
1255 | except TypeError: | |
1256 | fp = patchobj |
|
1256 | fp = patchobj | |
1257 | if cwd: |
|
1257 | if cwd: | |
1258 | curdir = os.getcwd() |
|
1258 | curdir = os.getcwd() | |
1259 | os.chdir(cwd) |
|
1259 | os.chdir(cwd) | |
1260 | try: |
|
1260 | try: | |
1261 | ret = applydiff(ui, fp, files, strip=strip, eolmode=eolmode) |
|
1261 | ret = applydiff(ui, fp, files, strip=strip, eolmode=eolmode) | |
1262 | finally: |
|
1262 | finally: | |
1263 | if cwd: |
|
1263 | if cwd: | |
1264 | os.chdir(curdir) |
|
1264 | os.chdir(curdir) | |
1265 | if fp != patchobj: |
|
1265 | if fp != patchobj: | |
1266 | fp.close() |
|
1266 | fp.close() | |
1267 | touched = _updatedir(ui, repo, files, similarity) |
|
1267 | touched = _updatedir(ui, repo, files, similarity) | |
1268 | files.update(dict.fromkeys(touched)) |
|
1268 | files.update(dict.fromkeys(touched)) | |
1269 | if ret < 0: |
|
1269 | if ret < 0: | |
1270 | raise PatchError(_('patch failed to apply')) |
|
1270 | raise PatchError(_('patch failed to apply')) | |
1271 | return ret > 0 |
|
1271 | return ret > 0 | |
1272 |
|
1272 | |||
1273 | def patch(ui, repo, patchname, strip=1, cwd=None, files=None, eolmode='strict', |
|
1273 | def patch(ui, repo, patchname, strip=1, cwd=None, files=None, eolmode='strict', | |
1274 | similarity=0): |
|
1274 | similarity=0): | |
1275 | """Apply <patchname> to the working directory. |
|
1275 | """Apply <patchname> to the working directory. | |
1276 |
|
1276 | |||
1277 | 'eolmode' specifies how end of lines should be handled. It can be: |
|
1277 | 'eolmode' specifies how end of lines should be handled. It can be: | |
1278 | - 'strict': inputs are read in binary mode, EOLs are preserved |
|
1278 | - 'strict': inputs are read in binary mode, EOLs are preserved | |
1279 | - 'crlf': EOLs are ignored when patching and reset to CRLF |
|
1279 | - 'crlf': EOLs are ignored when patching and reset to CRLF | |
1280 | - 'lf': EOLs are ignored when patching and reset to LF |
|
1280 | - 'lf': EOLs are ignored when patching and reset to LF | |
1281 | - None: get it from user settings, default to 'strict' |
|
1281 | - None: get it from user settings, default to 'strict' | |
1282 | 'eolmode' is ignored when using an external patcher program. |
|
1282 | 'eolmode' is ignored when using an external patcher program. | |
1283 |
|
1283 | |||
1284 | Returns whether patch was applied with fuzz factor. |
|
1284 | Returns whether patch was applied with fuzz factor. | |
1285 | """ |
|
1285 | """ | |
1286 | patcher = ui.config('ui', 'patch') |
|
1286 | patcher = ui.config('ui', 'patch') | |
1287 | if files is None: |
|
1287 | if files is None: | |
1288 | files = {} |
|
1288 | files = {} | |
1289 | try: |
|
1289 | try: | |
1290 | if patcher: |
|
1290 | if patcher: | |
1291 | try: |
|
1291 | try: | |
1292 | return _externalpatch(patcher, patchname, ui, strip, cwd, |
|
1292 | return _externalpatch(patcher, patchname, ui, strip, cwd, | |
1293 | files) |
|
1293 | files) | |
1294 | finally: |
|
1294 | finally: | |
1295 | touched = _updatedir(ui, repo, files, similarity) |
|
1295 | touched = _updatedir(ui, repo, files, similarity) | |
1296 | files.update(dict.fromkeys(touched)) |
|
1296 | files.update(dict.fromkeys(touched)) | |
1297 | return internalpatch(ui, repo, patchname, strip, cwd, files, eolmode, |
|
1297 | return internalpatch(ui, repo, patchname, strip, cwd, files, eolmode, | |
1298 | similarity) |
|
1298 | similarity) | |
1299 | except PatchError, err: |
|
1299 | except PatchError, err: | |
1300 | raise util.Abort(str(err)) |
|
1300 | raise util.Abort(str(err)) | |
1301 |
|
1301 | |||
1302 | def changedfiles(patchpath, strip=1): |
|
1302 | def changedfiles(patchpath, strip=1): | |
1303 | fp = open(patchpath, 'rb') |
|
1303 | fp = open(patchpath, 'rb') | |
1304 | try: |
|
1304 | try: | |
1305 | changed = set() |
|
1305 | changed = set() | |
1306 | for state, values in iterhunks(fp): |
|
1306 | for state, values in iterhunks(fp): | |
1307 | if state == 'hunk': |
|
1307 | if state == 'hunk': | |
1308 | continue |
|
1308 | continue | |
1309 | elif state == 'file': |
|
1309 | elif state == 'file': | |
1310 | afile, bfile, first_hunk = values |
|
1310 | afile, bfile, first_hunk = values | |
1311 | current_file, missing = selectfile(afile, bfile, |
|
1311 | current_file, missing = selectfile(afile, bfile, | |
1312 | first_hunk, strip) |
|
1312 | first_hunk, strip) | |
1313 | changed.add(current_file) |
|
1313 | changed.add(current_file) | |
1314 | elif state == 'git': |
|
1314 | elif state == 'git': | |
1315 | for gp in values: |
|
1315 | for gp in values: | |
1316 | gp.path = pathstrip(gp.path, strip - 1)[1] |
|
1316 | gp.path = pathstrip(gp.path, strip - 1)[1] | |
1317 | changed.add(gp.path) |
|
1317 | changed.add(gp.path) | |
1318 | else: |
|
1318 | else: | |
1319 | raise util.Abort(_('unsupported parser state: %s') % state) |
|
1319 | raise util.Abort(_('unsupported parser state: %s') % state) | |
1320 | return changed |
|
1320 | return changed | |
1321 | finally: |
|
1321 | finally: | |
1322 | fp.close() |
|
1322 | fp.close() | |
1323 |
|
1323 | |||
1324 | def b85diff(to, tn): |
|
1324 | def b85diff(to, tn): | |
1325 | '''print base85-encoded binary diff''' |
|
1325 | '''print base85-encoded binary diff''' | |
1326 | def gitindex(text): |
|
1326 | def gitindex(text): | |
1327 | if not text: |
|
1327 | if not text: | |
1328 | return hex(nullid) |
|
1328 | return hex(nullid) | |
1329 | l = len(text) |
|
1329 | l = len(text) | |
1330 | s = util.sha1('blob %d\0' % l) |
|
1330 | s = util.sha1('blob %d\0' % l) | |
1331 | s.update(text) |
|
1331 | s.update(text) | |
1332 | return s.hexdigest() |
|
1332 | return s.hexdigest() | |
1333 |
|
1333 | |||
1334 | def fmtline(line): |
|
1334 | def fmtline(line): | |
1335 | l = len(line) |
|
1335 | l = len(line) | |
1336 | if l <= 26: |
|
1336 | if l <= 26: | |
1337 | l = chr(ord('A') + l - 1) |
|
1337 | l = chr(ord('A') + l - 1) | |
1338 | else: |
|
1338 | else: | |
1339 | l = chr(l - 26 + ord('a') - 1) |
|
1339 | l = chr(l - 26 + ord('a') - 1) | |
1340 | return '%c%s\n' % (l, base85.b85encode(line, True)) |
|
1340 | return '%c%s\n' % (l, base85.b85encode(line, True)) | |
1341 |
|
1341 | |||
1342 | def chunk(text, csize=52): |
|
1342 | def chunk(text, csize=52): | |
1343 | l = len(text) |
|
1343 | l = len(text) | |
1344 | i = 0 |
|
1344 | i = 0 | |
1345 | while i < l: |
|
1345 | while i < l: | |
1346 | yield text[i:i + csize] |
|
1346 | yield text[i:i + csize] | |
1347 | i += csize |
|
1347 | i += csize | |
1348 |
|
1348 | |||
1349 | tohash = gitindex(to) |
|
1349 | tohash = gitindex(to) | |
1350 | tnhash = gitindex(tn) |
|
1350 | tnhash = gitindex(tn) | |
1351 | if tohash == tnhash: |
|
1351 | if tohash == tnhash: | |
1352 | return "" |
|
1352 | return "" | |
1353 |
|
1353 | |||
1354 | # TODO: deltas |
|
1354 | # TODO: deltas | |
1355 | ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' % |
|
1355 | ret = ['index %s..%s\nGIT binary patch\nliteral %s\n' % | |
1356 | (tohash, tnhash, len(tn))] |
|
1356 | (tohash, tnhash, len(tn))] | |
1357 | for l in chunk(zlib.compress(tn)): |
|
1357 | for l in chunk(zlib.compress(tn)): | |
1358 | ret.append(fmtline(l)) |
|
1358 | ret.append(fmtline(l)) | |
1359 | ret.append('\n') |
|
1359 | ret.append('\n') | |
1360 | return ''.join(ret) |
|
1360 | return ''.join(ret) | |
1361 |
|
1361 | |||
1362 | class GitDiffRequired(Exception): |
|
1362 | class GitDiffRequired(Exception): | |
1363 | pass |
|
1363 | pass | |
1364 |
|
1364 | |||
1365 | def diffopts(ui, opts=None, untrusted=False): |
|
1365 | def diffopts(ui, opts=None, untrusted=False): | |
1366 | def get(key, name=None, getter=ui.configbool): |
|
1366 | def get(key, name=None, getter=ui.configbool): | |
1367 | return ((opts and opts.get(key)) or |
|
1367 | return ((opts and opts.get(key)) or | |
1368 | getter('diff', name or key, None, untrusted=untrusted)) |
|
1368 | getter('diff', name or key, None, untrusted=untrusted)) | |
1369 | return mdiff.diffopts( |
|
1369 | return mdiff.diffopts( | |
1370 | text=opts and opts.get('text'), |
|
1370 | text=opts and opts.get('text'), | |
1371 | git=get('git'), |
|
1371 | git=get('git'), | |
1372 | nodates=get('nodates'), |
|
1372 | nodates=get('nodates'), | |
1373 | showfunc=get('show_function', 'showfunc'), |
|
1373 | showfunc=get('show_function', 'showfunc'), | |
1374 | ignorews=get('ignore_all_space', 'ignorews'), |
|
1374 | ignorews=get('ignore_all_space', 'ignorews'), | |
1375 | ignorewsamount=get('ignore_space_change', 'ignorewsamount'), |
|
1375 | ignorewsamount=get('ignore_space_change', 'ignorewsamount'), | |
1376 | ignoreblanklines=get('ignore_blank_lines', 'ignoreblanklines'), |
|
1376 | ignoreblanklines=get('ignore_blank_lines', 'ignoreblanklines'), | |
1377 | context=get('unified', getter=ui.config)) |
|
1377 | context=get('unified', getter=ui.config)) | |
1378 |
|
1378 | |||
1379 | def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, |
|
1379 | def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, | |
1380 | losedatafn=None, prefix=''): |
|
1380 | losedatafn=None, prefix=''): | |
1381 | '''yields diff of changes to files between two nodes, or node and |
|
1381 | '''yields diff of changes to files between two nodes, or node and | |
1382 | working directory. |
|
1382 | working directory. | |
1383 |
|
1383 | |||
1384 | if node1 is None, use first dirstate parent instead. |
|
1384 | if node1 is None, use first dirstate parent instead. | |
1385 | if node2 is None, compare node1 with working directory. |
|
1385 | if node2 is None, compare node1 with working directory. | |
1386 |
|
1386 | |||
1387 | losedatafn(**kwarg) is a callable run when opts.upgrade=True and |
|
1387 | losedatafn(**kwarg) is a callable run when opts.upgrade=True and | |
1388 | every time some change cannot be represented with the current |
|
1388 | every time some change cannot be represented with the current | |
1389 | patch format. Return False to upgrade to git patch format, True to |
|
1389 | patch format. Return False to upgrade to git patch format, True to | |
1390 | accept the loss or raise an exception to abort the diff. It is |
|
1390 | accept the loss or raise an exception to abort the diff. It is | |
1391 | called with the name of current file being diffed as 'fn'. If set |
|
1391 | called with the name of current file being diffed as 'fn'. If set | |
1392 | to None, patches will always be upgraded to git format when |
|
1392 | to None, patches will always be upgraded to git format when | |
1393 | necessary. |
|
1393 | necessary. | |
1394 |
|
1394 | |||
1395 | prefix is a filename prefix that is prepended to all filenames on |
|
1395 | prefix is a filename prefix that is prepended to all filenames on | |
1396 | display (used for subrepos). |
|
1396 | display (used for subrepos). | |
1397 | ''' |
|
1397 | ''' | |
1398 |
|
1398 | |||
1399 | if opts is None: |
|
1399 | if opts is None: | |
1400 | opts = mdiff.defaultopts |
|
1400 | opts = mdiff.defaultopts | |
1401 |
|
1401 | |||
1402 | if not node1 and not node2: |
|
1402 | if not node1 and not node2: | |
1403 | node1 = repo.dirstate.p1() |
|
1403 | node1 = repo.dirstate.p1() | |
1404 |
|
1404 | |||
1405 | def lrugetfilectx(): |
|
1405 | def lrugetfilectx(): | |
1406 | cache = {} |
|
1406 | cache = {} | |
1407 | order = [] |
|
1407 | order = [] | |
1408 | def getfilectx(f, ctx): |
|
1408 | def getfilectx(f, ctx): | |
1409 | fctx = ctx.filectx(f, filelog=cache.get(f)) |
|
1409 | fctx = ctx.filectx(f, filelog=cache.get(f)) | |
1410 | if f not in cache: |
|
1410 | if f not in cache: | |
1411 | if len(cache) > 20: |
|
1411 | if len(cache) > 20: | |
1412 | del cache[order.pop(0)] |
|
1412 | del cache[order.pop(0)] | |
1413 | cache[f] = fctx.filelog() |
|
1413 | cache[f] = fctx.filelog() | |
1414 | else: |
|
1414 | else: | |
1415 | order.remove(f) |
|
1415 | order.remove(f) | |
1416 | order.append(f) |
|
1416 | order.append(f) | |
1417 | return fctx |
|
1417 | return fctx | |
1418 | return getfilectx |
|
1418 | return getfilectx | |
1419 | getfilectx = lrugetfilectx() |
|
1419 | getfilectx = lrugetfilectx() | |
1420 |
|
1420 | |||
1421 | ctx1 = repo[node1] |
|
1421 | ctx1 = repo[node1] | |
1422 | ctx2 = repo[node2] |
|
1422 | ctx2 = repo[node2] | |
1423 |
|
1423 | |||
1424 | if not changes: |
|
1424 | if not changes: | |
1425 | changes = repo.status(ctx1, ctx2, match=match) |
|
1425 | changes = repo.status(ctx1, ctx2, match=match) | |
1426 | modified, added, removed = changes[:3] |
|
1426 | modified, added, removed = changes[:3] | |
1427 |
|
1427 | |||
1428 | if not modified and not added and not removed: |
|
1428 | if not modified and not added and not removed: | |
1429 | return [] |
|
1429 | return [] | |
1430 |
|
1430 | |||
1431 | revs = None |
|
1431 | revs = None | |
1432 | if not repo.ui.quiet: |
|
1432 | if not repo.ui.quiet: | |
1433 | hexfunc = repo.ui.debugflag and hex or short |
|
1433 | hexfunc = repo.ui.debugflag and hex or short | |
1434 | revs = [hexfunc(node) for node in [node1, node2] if node] |
|
1434 | revs = [hexfunc(node) for node in [node1, node2] if node] | |
1435 |
|
1435 | |||
1436 | copy = {} |
|
1436 | copy = {} | |
1437 | if opts.git or opts.upgrade: |
|
1437 | if opts.git or opts.upgrade: | |
1438 | copy = copies.copies(repo, ctx1, ctx2, repo[nullid])[0] |
|
1438 | copy = copies.copies(repo, ctx1, ctx2, repo[nullid])[0] | |
1439 |
|
1439 | |||
1440 | difffn = lambda opts, losedata: trydiff(repo, revs, ctx1, ctx2, |
|
1440 | difffn = lambda opts, losedata: trydiff(repo, revs, ctx1, ctx2, | |
1441 | modified, added, removed, copy, getfilectx, opts, losedata, prefix) |
|
1441 | modified, added, removed, copy, getfilectx, opts, losedata, prefix) | |
1442 | if opts.upgrade and not opts.git: |
|
1442 | if opts.upgrade and not opts.git: | |
1443 | try: |
|
1443 | try: | |
1444 | def losedata(fn): |
|
1444 | def losedata(fn): | |
1445 | if not losedatafn or not losedatafn(fn=fn): |
|
1445 | if not losedatafn or not losedatafn(fn=fn): | |
1446 | raise GitDiffRequired() |
|
1446 | raise GitDiffRequired() | |
1447 | # Buffer the whole output until we are sure it can be generated |
|
1447 | # Buffer the whole output until we are sure it can be generated | |
1448 | return list(difffn(opts.copy(git=False), losedata)) |
|
1448 | return list(difffn(opts.copy(git=False), losedata)) | |
1449 | except GitDiffRequired: |
|
1449 | except GitDiffRequired: | |
1450 | return difffn(opts.copy(git=True), None) |
|
1450 | return difffn(opts.copy(git=True), None) | |
1451 | else: |
|
1451 | else: | |
1452 | return difffn(opts, None) |
|
1452 | return difffn(opts, None) | |
1453 |
|
1453 | |||
1454 | def difflabel(func, *args, **kw): |
|
1454 | def difflabel(func, *args, **kw): | |
1455 | '''yields 2-tuples of (output, label) based on the output of func()''' |
|
1455 | '''yields 2-tuples of (output, label) based on the output of func()''' | |
1456 | prefixes = [('diff', 'diff.diffline'), |
|
1456 | prefixes = [('diff', 'diff.diffline'), | |
1457 | ('copy', 'diff.extended'), |
|
1457 | ('copy', 'diff.extended'), | |
1458 | ('rename', 'diff.extended'), |
|
1458 | ('rename', 'diff.extended'), | |
1459 | ('old', 'diff.extended'), |
|
1459 | ('old', 'diff.extended'), | |
1460 | ('new', 'diff.extended'), |
|
1460 | ('new', 'diff.extended'), | |
1461 | ('deleted', 'diff.extended'), |
|
1461 | ('deleted', 'diff.extended'), | |
1462 | ('---', 'diff.file_a'), |
|
1462 | ('---', 'diff.file_a'), | |
1463 | ('+++', 'diff.file_b'), |
|
1463 | ('+++', 'diff.file_b'), | |
1464 | ('@@', 'diff.hunk'), |
|
1464 | ('@@', 'diff.hunk'), | |
1465 | ('-', 'diff.deleted'), |
|
1465 | ('-', 'diff.deleted'), | |
1466 | ('+', 'diff.inserted')] |
|
1466 | ('+', 'diff.inserted')] | |
1467 |
|
1467 | |||
1468 | for chunk in func(*args, **kw): |
|
1468 | for chunk in func(*args, **kw): | |
1469 | lines = chunk.split('\n') |
|
1469 | lines = chunk.split('\n') | |
1470 | for i, line in enumerate(lines): |
|
1470 | for i, line in enumerate(lines): | |
1471 | if i != 0: |
|
1471 | if i != 0: | |
1472 | yield ('\n', '') |
|
1472 | yield ('\n', '') | |
1473 | stripline = line |
|
1473 | stripline = line | |
1474 | if line and line[0] in '+-': |
|
1474 | if line and line[0] in '+-': | |
1475 | # highlight trailing whitespace, but only in changed lines |
|
1475 | # highlight trailing whitespace, but only in changed lines | |
1476 | stripline = line.rstrip() |
|
1476 | stripline = line.rstrip() | |
1477 | for prefix, label in prefixes: |
|
1477 | for prefix, label in prefixes: | |
1478 | if stripline.startswith(prefix): |
|
1478 | if stripline.startswith(prefix): | |
1479 | yield (stripline, label) |
|
1479 | yield (stripline, label) | |
1480 | break |
|
1480 | break | |
1481 | else: |
|
1481 | else: | |
1482 | yield (line, '') |
|
1482 | yield (line, '') | |
1483 | if line != stripline: |
|
1483 | if line != stripline: | |
1484 | yield (line[len(stripline):], 'diff.trailingwhitespace') |
|
1484 | yield (line[len(stripline):], 'diff.trailingwhitespace') | |
1485 |
|
1485 | |||
1486 | def diffui(*args, **kw): |
|
1486 | def diffui(*args, **kw): | |
1487 | '''like diff(), but yields 2-tuples of (output, label) for ui.write()''' |
|
1487 | '''like diff(), but yields 2-tuples of (output, label) for ui.write()''' | |
1488 | return difflabel(diff, *args, **kw) |
|
1488 | return difflabel(diff, *args, **kw) | |
1489 |
|
1489 | |||
1490 |
|
1490 | |||
1491 | def _addmodehdr(header, omode, nmode): |
|
1491 | def _addmodehdr(header, omode, nmode): | |
1492 | if omode != nmode: |
|
1492 | if omode != nmode: | |
1493 | header.append('old mode %s\n' % omode) |
|
1493 | header.append('old mode %s\n' % omode) | |
1494 | header.append('new mode %s\n' % nmode) |
|
1494 | header.append('new mode %s\n' % nmode) | |
1495 |
|
1495 | |||
1496 | def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, |
|
1496 | def trydiff(repo, revs, ctx1, ctx2, modified, added, removed, | |
1497 | copy, getfilectx, opts, losedatafn, prefix): |
|
1497 | copy, getfilectx, opts, losedatafn, prefix): | |
1498 |
|
1498 | |||
1499 | def join(f): |
|
1499 | def join(f): | |
1500 | return os.path.join(prefix, f) |
|
1500 | return os.path.join(prefix, f) | |
1501 |
|
1501 | |||
1502 | date1 = util.datestr(ctx1.date()) |
|
1502 | date1 = util.datestr(ctx1.date()) | |
1503 | man1 = ctx1.manifest() |
|
1503 | man1 = ctx1.manifest() | |
1504 |
|
1504 | |||
1505 | gone = set() |
|
1505 | gone = set() | |
1506 | gitmode = {'l': '120000', 'x': '100755', '': '100644'} |
|
1506 | gitmode = {'l': '120000', 'x': '100755', '': '100644'} | |
1507 |
|
1507 | |||
1508 | copyto = dict([(v, k) for k, v in copy.items()]) |
|
1508 | copyto = dict([(v, k) for k, v in copy.items()]) | |
1509 |
|
1509 | |||
1510 | if opts.git: |
|
1510 | if opts.git: | |
1511 | revs = None |
|
1511 | revs = None | |
1512 |
|
1512 | |||
1513 | for f in sorted(modified + added + removed): |
|
1513 | for f in sorted(modified + added + removed): | |
1514 | to = None |
|
1514 | to = None | |
1515 | tn = None |
|
1515 | tn = None | |
1516 | dodiff = True |
|
1516 | dodiff = True | |
1517 | header = [] |
|
1517 | header = [] | |
1518 | if f in man1: |
|
1518 | if f in man1: | |
1519 | to = getfilectx(f, ctx1).data() |
|
1519 | to = getfilectx(f, ctx1).data() | |
1520 | if f not in removed: |
|
1520 | if f not in removed: | |
1521 | tn = getfilectx(f, ctx2).data() |
|
1521 | tn = getfilectx(f, ctx2).data() | |
1522 | a, b = f, f |
|
1522 | a, b = f, f | |
1523 | if opts.git or losedatafn: |
|
1523 | if opts.git or losedatafn: | |
1524 | if f in added: |
|
1524 | if f in added: | |
1525 | mode = gitmode[ctx2.flags(f)] |
|
1525 | mode = gitmode[ctx2.flags(f)] | |
1526 | if f in copy or f in copyto: |
|
1526 | if f in copy or f in copyto: | |
1527 | if opts.git: |
|
1527 | if opts.git: | |
1528 | if f in copy: |
|
1528 | if f in copy: | |
1529 | a = copy[f] |
|
1529 | a = copy[f] | |
1530 | else: |
|
1530 | else: | |
1531 | a = copyto[f] |
|
1531 | a = copyto[f] | |
1532 | omode = gitmode[man1.flags(a)] |
|
1532 | omode = gitmode[man1.flags(a)] | |
1533 | _addmodehdr(header, omode, mode) |
|
1533 | _addmodehdr(header, omode, mode) | |
1534 | if a in removed and a not in gone: |
|
1534 | if a in removed and a not in gone: | |
1535 | op = 'rename' |
|
1535 | op = 'rename' | |
1536 | gone.add(a) |
|
1536 | gone.add(a) | |
1537 | else: |
|
1537 | else: | |
1538 | op = 'copy' |
|
1538 | op = 'copy' | |
1539 | header.append('%s from %s\n' % (op, join(a))) |
|
1539 | header.append('%s from %s\n' % (op, join(a))) | |
1540 | header.append('%s to %s\n' % (op, join(f))) |
|
1540 | header.append('%s to %s\n' % (op, join(f))) | |
1541 | to = getfilectx(a, ctx1).data() |
|
1541 | to = getfilectx(a, ctx1).data() | |
1542 | else: |
|
1542 | else: | |
1543 | losedatafn(f) |
|
1543 | losedatafn(f) | |
1544 | else: |
|
1544 | else: | |
1545 | if opts.git: |
|
1545 | if opts.git: | |
1546 | header.append('new file mode %s\n' % mode) |
|
1546 | header.append('new file mode %s\n' % mode) | |
1547 | elif ctx2.flags(f): |
|
1547 | elif ctx2.flags(f): | |
1548 | losedatafn(f) |
|
1548 | losedatafn(f) | |
1549 | # In theory, if tn was copied or renamed we should check |
|
1549 | # In theory, if tn was copied or renamed we should check | |
1550 | # if the source is binary too but the copy record already |
|
1550 | # if the source is binary too but the copy record already | |
1551 | # forces git mode. |
|
1551 | # forces git mode. | |
1552 | if util.binary(tn): |
|
1552 | if util.binary(tn): | |
1553 | if opts.git: |
|
1553 | if opts.git: | |
1554 | dodiff = 'binary' |
|
1554 | dodiff = 'binary' | |
1555 | else: |
|
1555 | else: | |
1556 | losedatafn(f) |
|
1556 | losedatafn(f) | |
1557 | if not opts.git and not tn: |
|
1557 | if not opts.git and not tn: | |
1558 | # regular diffs cannot represent new empty file |
|
1558 | # regular diffs cannot represent new empty file | |
1559 | losedatafn(f) |
|
1559 | losedatafn(f) | |
1560 | elif f in removed: |
|
1560 | elif f in removed: | |
1561 | if opts.git: |
|
1561 | if opts.git: | |
1562 | # have we already reported a copy above? |
|
1562 | # have we already reported a copy above? | |
1563 | if ((f in copy and copy[f] in added |
|
1563 | if ((f in copy and copy[f] in added | |
1564 | and copyto[copy[f]] == f) or |
|
1564 | and copyto[copy[f]] == f) or | |
1565 | (f in copyto and copyto[f] in added |
|
1565 | (f in copyto and copyto[f] in added | |
1566 | and copy[copyto[f]] == f)): |
|
1566 | and copy[copyto[f]] == f)): | |
1567 | dodiff = False |
|
1567 | dodiff = False | |
1568 | else: |
|
1568 | else: | |
1569 | header.append('deleted file mode %s\n' % |
|
1569 | header.append('deleted file mode %s\n' % | |
1570 | gitmode[man1.flags(f)]) |
|
1570 | gitmode[man1.flags(f)]) | |
1571 | elif not to or util.binary(to): |
|
1571 | elif not to or util.binary(to): | |
1572 | # regular diffs cannot represent empty file deletion |
|
1572 | # regular diffs cannot represent empty file deletion | |
1573 | losedatafn(f) |
|
1573 | losedatafn(f) | |
1574 | else: |
|
1574 | else: | |
1575 | oflag = man1.flags(f) |
|
1575 | oflag = man1.flags(f) | |
1576 | nflag = ctx2.flags(f) |
|
1576 | nflag = ctx2.flags(f) | |
1577 | binary = util.binary(to) or util.binary(tn) |
|
1577 | binary = util.binary(to) or util.binary(tn) | |
1578 | if opts.git: |
|
1578 | if opts.git: | |
1579 | _addmodehdr(header, gitmode[oflag], gitmode[nflag]) |
|
1579 | _addmodehdr(header, gitmode[oflag], gitmode[nflag]) | |
1580 | if binary: |
|
1580 | if binary: | |
1581 | dodiff = 'binary' |
|
1581 | dodiff = 'binary' | |
1582 | elif binary or nflag != oflag: |
|
1582 | elif binary or nflag != oflag: | |
1583 | losedatafn(f) |
|
1583 | losedatafn(f) | |
1584 | if opts.git: |
|
1584 | if opts.git: | |
1585 | header.insert(0, mdiff.diffline(revs, join(a), join(b), opts)) |
|
1585 | header.insert(0, mdiff.diffline(revs, join(a), join(b), opts)) | |
1586 |
|
1586 | |||
1587 | if dodiff: |
|
1587 | if dodiff: | |
1588 | if dodiff == 'binary': |
|
1588 | if dodiff == 'binary': | |
1589 | text = b85diff(to, tn) |
|
1589 | text = b85diff(to, tn) | |
1590 | else: |
|
1590 | else: | |
1591 | text = mdiff.unidiff(to, date1, |
|
1591 | text = mdiff.unidiff(to, date1, | |
1592 | # ctx2 date may be dynamic |
|
1592 | # ctx2 date may be dynamic | |
1593 | tn, util.datestr(ctx2.date()), |
|
1593 | tn, util.datestr(ctx2.date()), | |
1594 | join(a), join(b), revs, opts=opts) |
|
1594 | join(a), join(b), revs, opts=opts) | |
1595 | if header and (text or len(header) > 1): |
|
1595 | if header and (text or len(header) > 1): | |
1596 | yield ''.join(header) |
|
1596 | yield ''.join(header) | |
1597 | if text: |
|
1597 | if text: | |
1598 | yield text |
|
1598 | yield text | |
1599 |
|
1599 | |||
1600 | def diffstatdata(lines): |
|
1600 | def diffstatdata(lines): | |
1601 | diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$') |
|
1601 | diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$') | |
1602 |
|
1602 | |||
1603 | filename, adds, removes = None, 0, 0 |
|
1603 | filename, adds, removes = None, 0, 0 | |
1604 | for line in lines: |
|
1604 | for line in lines: | |
1605 | if line.startswith('diff'): |
|
1605 | if line.startswith('diff'): | |
1606 | if filename: |
|
1606 | if filename: | |
1607 | isbinary = adds == 0 and removes == 0 |
|
1607 | isbinary = adds == 0 and removes == 0 | |
1608 | yield (filename, adds, removes, isbinary) |
|
1608 | yield (filename, adds, removes, isbinary) | |
1609 | # set numbers to 0 anyway when starting new file |
|
1609 | # set numbers to 0 anyway when starting new file | |
1610 | adds, removes = 0, 0 |
|
1610 | adds, removes = 0, 0 | |
1611 | if line.startswith('diff --git'): |
|
1611 | if line.startswith('diff --git'): | |
1612 | filename = gitre.search(line).group(1) |
|
1612 | filename = gitre.search(line).group(1) | |
1613 | elif line.startswith('diff -r'): |
|
1613 | elif line.startswith('diff -r'): | |
1614 | # format: "diff -r ... -r ... filename" |
|
1614 | # format: "diff -r ... -r ... filename" | |
1615 | filename = diffre.search(line).group(1) |
|
1615 | filename = diffre.search(line).group(1) | |
1616 | elif line.startswith('+') and not line.startswith('+++'): |
|
1616 | elif line.startswith('+') and not line.startswith('+++'): | |
1617 | adds += 1 |
|
1617 | adds += 1 | |
1618 | elif line.startswith('-') and not line.startswith('---'): |
|
1618 | elif line.startswith('-') and not line.startswith('---'): | |
1619 | removes += 1 |
|
1619 | removes += 1 | |
1620 | if filename: |
|
1620 | if filename: | |
1621 | isbinary = adds == 0 and removes == 0 |
|
1621 | isbinary = adds == 0 and removes == 0 | |
1622 | yield (filename, adds, removes, isbinary) |
|
1622 | yield (filename, adds, removes, isbinary) | |
1623 |
|
1623 | |||
1624 | def diffstat(lines, width=80, git=False): |
|
1624 | def diffstat(lines, width=80, git=False): | |
1625 | output = [] |
|
1625 | output = [] | |
1626 | stats = list(diffstatdata(lines)) |
|
1626 | stats = list(diffstatdata(lines)) | |
1627 |
|
1627 | |||
1628 | maxtotal, maxname = 0, 0 |
|
1628 | maxtotal, maxname = 0, 0 | |
1629 | totaladds, totalremoves = 0, 0 |
|
1629 | totaladds, totalremoves = 0, 0 | |
1630 | hasbinary = False |
|
1630 | hasbinary = False | |
1631 |
|
1631 | |||
1632 | sized = [(filename, adds, removes, isbinary, encoding.colwidth(filename)) |
|
1632 | sized = [(filename, adds, removes, isbinary, encoding.colwidth(filename)) | |
1633 | for filename, adds, removes, isbinary in stats] |
|
1633 | for filename, adds, removes, isbinary in stats] | |
1634 |
|
1634 | |||
1635 | for filename, adds, removes, isbinary, namewidth in sized: |
|
1635 | for filename, adds, removes, isbinary, namewidth in sized: | |
1636 | totaladds += adds |
|
1636 | totaladds += adds | |
1637 | totalremoves += removes |
|
1637 | totalremoves += removes | |
1638 | maxname = max(maxname, namewidth) |
|
1638 | maxname = max(maxname, namewidth) | |
1639 | maxtotal = max(maxtotal, adds + removes) |
|
1639 | maxtotal = max(maxtotal, adds + removes) | |
1640 | if isbinary: |
|
1640 | if isbinary: | |
1641 | hasbinary = True |
|
1641 | hasbinary = True | |
1642 |
|
1642 | |||
1643 | countwidth = len(str(maxtotal)) |
|
1643 | countwidth = len(str(maxtotal)) | |
1644 | if hasbinary and countwidth < 3: |
|
1644 | if hasbinary and countwidth < 3: | |
1645 | countwidth = 3 |
|
1645 | countwidth = 3 | |
1646 | graphwidth = width - countwidth - maxname - 6 |
|
1646 | graphwidth = width - countwidth - maxname - 6 | |
1647 | if graphwidth < 10: |
|
1647 | if graphwidth < 10: | |
1648 | graphwidth = 10 |
|
1648 | graphwidth = 10 | |
1649 |
|
1649 | |||
1650 | def scale(i): |
|
1650 | def scale(i): | |
1651 | if maxtotal <= graphwidth: |
|
1651 | if maxtotal <= graphwidth: | |
1652 | return i |
|
1652 | return i | |
1653 | # If diffstat runs out of room it doesn't print anything, |
|
1653 | # If diffstat runs out of room it doesn't print anything, | |
1654 | # which isn't very useful, so always print at least one + or - |
|
1654 | # which isn't very useful, so always print at least one + or - | |
1655 | # if there were at least some changes. |
|
1655 | # if there were at least some changes. | |
1656 | return max(i * graphwidth // maxtotal, int(bool(i))) |
|
1656 | return max(i * graphwidth // maxtotal, int(bool(i))) | |
1657 |
|
1657 | |||
1658 | for filename, adds, removes, isbinary, namewidth in sized: |
|
1658 | for filename, adds, removes, isbinary, namewidth in sized: | |
1659 | if git and isbinary: |
|
1659 | if git and isbinary: | |
1660 | count = 'Bin' |
|
1660 | count = 'Bin' | |
1661 | else: |
|
1661 | else: | |
1662 | count = adds + removes |
|
1662 | count = adds + removes | |
1663 | pluses = '+' * scale(adds) |
|
1663 | pluses = '+' * scale(adds) | |
1664 | minuses = '-' * scale(removes) |
|
1664 | minuses = '-' * scale(removes) | |
1665 | output.append(' %s%s | %*s %s%s\n' % |
|
1665 | output.append(' %s%s | %*s %s%s\n' % | |
1666 | (filename, ' ' * (maxname - namewidth), |
|
1666 | (filename, ' ' * (maxname - namewidth), | |
1667 | countwidth, count, |
|
1667 | countwidth, count, | |
1668 | pluses, minuses)) |
|
1668 | pluses, minuses)) | |
1669 |
|
1669 | |||
1670 | if stats: |
|
1670 | if stats: | |
1671 | output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n') |
|
1671 | output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n') | |
1672 | % (len(stats), totaladds, totalremoves)) |
|
1672 | % (len(stats), totaladds, totalremoves)) | |
1673 |
|
1673 | |||
1674 | return ''.join(output) |
|
1674 | return ''.join(output) | |
1675 |
|
1675 | |||
1676 | def diffstatui(*args, **kw): |
|
1676 | def diffstatui(*args, **kw): | |
1677 | '''like diffstat(), but yields 2-tuples of (output, label) for |
|
1677 | '''like diffstat(), but yields 2-tuples of (output, label) for | |
1678 | ui.write() |
|
1678 | ui.write() | |
1679 | ''' |
|
1679 | ''' | |
1680 |
|
1680 | |||
1681 | for line in diffstat(*args, **kw).splitlines(): |
|
1681 | for line in diffstat(*args, **kw).splitlines(): | |
1682 | if line and line[-1] in '+-': |
|
1682 | if line and line[-1] in '+-': | |
1683 | name, graph = line.rsplit(' ', 1) |
|
1683 | name, graph = line.rsplit(' ', 1) | |
1684 | yield (name + ' ', '') |
|
1684 | yield (name + ' ', '') | |
1685 | m = re.search(r'\++', graph) |
|
1685 | m = re.search(r'\++', graph) | |
1686 | if m: |
|
1686 | if m: | |
1687 | yield (m.group(0), 'diffstat.inserted') |
|
1687 | yield (m.group(0), 'diffstat.inserted') | |
1688 | m = re.search(r'-+', graph) |
|
1688 | m = re.search(r'-+', graph) | |
1689 | if m: |
|
1689 | if m: | |
1690 | yield (m.group(0), 'diffstat.deleted') |
|
1690 | yield (m.group(0), 'diffstat.deleted') | |
1691 | else: |
|
1691 | else: | |
1692 | yield (line, '') |
|
1692 | yield (line, '') | |
1693 | yield ('\n', '') |
|
1693 | yield ('\n', '') |
General Comments 0
You need to be logged in to leave comments.
Login now