Show More
@@ -1,1246 +1,1250 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, glob, tempfile |
|
10 | import os, sys, errno, re, glob, tempfile | |
11 | import util, templater, patch, error, encoding, templatekw |
|
11 | import util, templater, patch, error, encoding, templatekw | |
12 | import match as _match |
|
12 | import match as _match | |
13 | import similar, revset |
|
13 | import similar, revset | |
14 |
|
14 | |||
15 | revrangesep = ':' |
|
15 | revrangesep = ':' | |
16 |
|
16 | |||
17 | def parsealiases(cmd): |
|
17 | def parsealiases(cmd): | |
18 | return cmd.lstrip("^").split("|") |
|
18 | return cmd.lstrip("^").split("|") | |
19 |
|
19 | |||
20 | def findpossible(cmd, table, strict=False): |
|
20 | def findpossible(cmd, table, strict=False): | |
21 | """ |
|
21 | """ | |
22 | Return cmd -> (aliases, command table entry) |
|
22 | Return cmd -> (aliases, command table entry) | |
23 | for each matching command. |
|
23 | for each matching command. | |
24 | Return debug commands (or their aliases) only if no normal command matches. |
|
24 | Return debug commands (or their aliases) only if no normal command matches. | |
25 | """ |
|
25 | """ | |
26 | choice = {} |
|
26 | choice = {} | |
27 | debugchoice = {} |
|
27 | debugchoice = {} | |
28 | for e in table.keys(): |
|
28 | for e in table.keys(): | |
29 | aliases = parsealiases(e) |
|
29 | aliases = parsealiases(e) | |
30 | found = None |
|
30 | found = None | |
31 | if cmd in aliases: |
|
31 | if cmd in aliases: | |
32 | found = cmd |
|
32 | found = cmd | |
33 | elif not strict: |
|
33 | elif not strict: | |
34 | for a in aliases: |
|
34 | for a in aliases: | |
35 | if a.startswith(cmd): |
|
35 | if a.startswith(cmd): | |
36 | found = a |
|
36 | found = a | |
37 | break |
|
37 | break | |
38 | if found is not None: |
|
38 | if found is not None: | |
39 | if aliases[0].startswith("debug") or found.startswith("debug"): |
|
39 | if aliases[0].startswith("debug") or found.startswith("debug"): | |
40 | debugchoice[found] = (aliases, table[e]) |
|
40 | debugchoice[found] = (aliases, table[e]) | |
41 | else: |
|
41 | else: | |
42 | choice[found] = (aliases, table[e]) |
|
42 | choice[found] = (aliases, table[e]) | |
43 |
|
43 | |||
44 | if not choice and debugchoice: |
|
44 | if not choice and debugchoice: | |
45 | choice = debugchoice |
|
45 | choice = debugchoice | |
46 |
|
46 | |||
47 | return choice |
|
47 | return choice | |
48 |
|
48 | |||
49 | def findcmd(cmd, table, strict=True): |
|
49 | def findcmd(cmd, table, strict=True): | |
50 | """Return (aliases, command table entry) for command string.""" |
|
50 | """Return (aliases, command table entry) for command string.""" | |
51 | choice = findpossible(cmd, table, strict) |
|
51 | choice = findpossible(cmd, table, strict) | |
52 |
|
52 | |||
53 | if cmd in choice: |
|
53 | if cmd in choice: | |
54 | return choice[cmd] |
|
54 | return choice[cmd] | |
55 |
|
55 | |||
56 | if len(choice) > 1: |
|
56 | if len(choice) > 1: | |
57 | clist = choice.keys() |
|
57 | clist = choice.keys() | |
58 | clist.sort() |
|
58 | clist.sort() | |
59 | raise error.AmbiguousCommand(cmd, clist) |
|
59 | raise error.AmbiguousCommand(cmd, clist) | |
60 |
|
60 | |||
61 | if choice: |
|
61 | if choice: | |
62 | return choice.values()[0] |
|
62 | return choice.values()[0] | |
63 |
|
63 | |||
64 | raise error.UnknownCommand(cmd) |
|
64 | raise error.UnknownCommand(cmd) | |
65 |
|
65 | |||
66 | def findrepo(p): |
|
66 | def findrepo(p): | |
67 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
67 | while not os.path.isdir(os.path.join(p, ".hg")): | |
68 | oldp, p = p, os.path.dirname(p) |
|
68 | oldp, p = p, os.path.dirname(p) | |
69 | if p == oldp: |
|
69 | if p == oldp: | |
70 | return None |
|
70 | return None | |
71 |
|
71 | |||
72 | return p |
|
72 | return p | |
73 |
|
73 | |||
74 | def bail_if_changed(repo): |
|
74 | def bail_if_changed(repo): | |
75 | if repo.dirstate.parents()[1] != nullid: |
|
75 | if repo.dirstate.parents()[1] != nullid: | |
76 | raise util.Abort(_('outstanding uncommitted merge')) |
|
76 | raise util.Abort(_('outstanding uncommitted merge')) | |
77 | modified, added, removed, deleted = repo.status()[:4] |
|
77 | modified, added, removed, deleted = repo.status()[:4] | |
78 | if modified or added or removed or deleted: |
|
78 | if modified or added or removed or deleted: | |
79 | raise util.Abort(_("outstanding uncommitted changes")) |
|
79 | raise util.Abort(_("outstanding uncommitted changes")) | |
80 |
|
80 | |||
81 | def logmessage(opts): |
|
81 | def logmessage(opts): | |
82 | """ get the log message according to -m and -l option """ |
|
82 | """ get the log message according to -m and -l option """ | |
83 | message = opts.get('message') |
|
83 | message = opts.get('message') | |
84 | logfile = opts.get('logfile') |
|
84 | logfile = opts.get('logfile') | |
85 |
|
85 | |||
86 | if message and logfile: |
|
86 | if message and logfile: | |
87 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
87 | raise util.Abort(_('options --message and --logfile are mutually ' | |
88 | 'exclusive')) |
|
88 | 'exclusive')) | |
89 | if not message and logfile: |
|
89 | if not message and logfile: | |
90 | try: |
|
90 | try: | |
91 | if logfile == '-': |
|
91 | if logfile == '-': | |
92 | message = sys.stdin.read() |
|
92 | message = sys.stdin.read() | |
93 | else: |
|
93 | else: | |
94 | message = open(logfile).read() |
|
94 | message = open(logfile).read() | |
95 | except IOError, inst: |
|
95 | except IOError, inst: | |
96 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
96 | raise util.Abort(_("can't read commit message '%s': %s") % | |
97 | (logfile, inst.strerror)) |
|
97 | (logfile, inst.strerror)) | |
98 | return message |
|
98 | return message | |
99 |
|
99 | |||
100 | def loglimit(opts): |
|
100 | def loglimit(opts): | |
101 | """get the log limit according to option -l/--limit""" |
|
101 | """get the log limit according to option -l/--limit""" | |
102 | limit = opts.get('limit') |
|
102 | limit = opts.get('limit') | |
103 | if limit: |
|
103 | if limit: | |
104 | try: |
|
104 | try: | |
105 | limit = int(limit) |
|
105 | limit = int(limit) | |
106 | except ValueError: |
|
106 | except ValueError: | |
107 | raise util.Abort(_('limit must be a positive integer')) |
|
107 | raise util.Abort(_('limit must be a positive integer')) | |
108 | if limit <= 0: |
|
108 | if limit <= 0: | |
109 | raise util.Abort(_('limit must be positive')) |
|
109 | raise util.Abort(_('limit must be positive')) | |
110 | else: |
|
110 | else: | |
111 | limit = None |
|
111 | limit = None | |
112 | return limit |
|
112 | return limit | |
113 |
|
113 | |||
114 | def revpair(repo, revs): |
|
114 | def revpair(repo, revs): | |
115 | '''return pair of nodes, given list of revisions. second item can |
|
115 | '''return pair of nodes, given list of revisions. second item can | |
116 | be None, meaning use working dir.''' |
|
116 | be None, meaning use working dir.''' | |
117 |
|
117 | |||
118 | def revfix(repo, val, defval): |
|
118 | def revfix(repo, val, defval): | |
119 | if not val and val != 0 and defval is not None: |
|
119 | if not val and val != 0 and defval is not None: | |
120 | val = defval |
|
120 | val = defval | |
121 | return repo.lookup(val) |
|
121 | return repo.lookup(val) | |
122 |
|
122 | |||
123 | if not revs: |
|
123 | if not revs: | |
124 | return repo.dirstate.parents()[0], None |
|
124 | return repo.dirstate.parents()[0], None | |
125 | end = None |
|
125 | end = None | |
126 | if len(revs) == 1: |
|
126 | if len(revs) == 1: | |
127 | if revrangesep in revs[0]: |
|
127 | if revrangesep in revs[0]: | |
128 | start, end = revs[0].split(revrangesep, 1) |
|
128 | start, end = revs[0].split(revrangesep, 1) | |
129 | start = revfix(repo, start, 0) |
|
129 | start = revfix(repo, start, 0) | |
130 | end = revfix(repo, end, len(repo) - 1) |
|
130 | end = revfix(repo, end, len(repo) - 1) | |
131 | else: |
|
131 | else: | |
132 | start = revfix(repo, revs[0], None) |
|
132 | start = revfix(repo, revs[0], None) | |
133 | elif len(revs) == 2: |
|
133 | elif len(revs) == 2: | |
134 | if revrangesep in revs[0] or revrangesep in revs[1]: |
|
134 | if revrangesep in revs[0] or revrangesep in revs[1]: | |
135 | raise util.Abort(_('too many revisions specified')) |
|
135 | raise util.Abort(_('too many revisions specified')) | |
136 | start = revfix(repo, revs[0], None) |
|
136 | start = revfix(repo, revs[0], None) | |
137 | end = revfix(repo, revs[1], None) |
|
137 | end = revfix(repo, revs[1], None) | |
138 | else: |
|
138 | else: | |
139 | raise util.Abort(_('too many revisions specified')) |
|
139 | raise util.Abort(_('too many revisions specified')) | |
140 | return start, end |
|
140 | return start, end | |
141 |
|
141 | |||
142 | def revrange(repo, revs): |
|
142 | def revrange(repo, revs): | |
143 | """Yield revision as strings from a list of revision specifications.""" |
|
143 | """Yield revision as strings from a list of revision specifications.""" | |
144 |
|
144 | |||
145 | def revfix(repo, val, defval): |
|
145 | def revfix(repo, val, defval): | |
146 | if not val and val != 0 and defval is not None: |
|
146 | if not val and val != 0 and defval is not None: | |
147 | return defval |
|
147 | return defval | |
148 | return repo.changelog.rev(repo.lookup(val)) |
|
148 | return repo.changelog.rev(repo.lookup(val)) | |
149 |
|
149 | |||
150 | seen, l = set(), [] |
|
150 | seen, l = set(), [] | |
151 | for spec in revs: |
|
151 | for spec in revs: | |
152 | # attempt to parse old-style ranges first to deal with |
|
152 | # attempt to parse old-style ranges first to deal with | |
153 | # things like old-tag which contain query metacharacters |
|
153 | # things like old-tag which contain query metacharacters | |
154 | try: |
|
154 | try: | |
155 | if revrangesep in spec: |
|
155 | if revrangesep in spec: | |
156 | start, end = spec.split(revrangesep, 1) |
|
156 | start, end = spec.split(revrangesep, 1) | |
157 | start = revfix(repo, start, 0) |
|
157 | start = revfix(repo, start, 0) | |
158 | end = revfix(repo, end, len(repo) - 1) |
|
158 | end = revfix(repo, end, len(repo) - 1) | |
159 | step = start > end and -1 or 1 |
|
159 | step = start > end and -1 or 1 | |
160 | for rev in xrange(start, end + step, step): |
|
160 | for rev in xrange(start, end + step, step): | |
161 | if rev in seen: |
|
161 | if rev in seen: | |
162 | continue |
|
162 | continue | |
163 | seen.add(rev) |
|
163 | seen.add(rev) | |
164 | l.append(rev) |
|
164 | l.append(rev) | |
165 | continue |
|
165 | continue | |
166 | elif spec and spec in repo: # single unquoted rev |
|
166 | elif spec and spec in repo: # single unquoted rev | |
167 | rev = revfix(repo, spec, None) |
|
167 | rev = revfix(repo, spec, None) | |
168 | if rev in seen: |
|
168 | if rev in seen: | |
169 | continue |
|
169 | continue | |
170 | seen.add(rev) |
|
170 | seen.add(rev) | |
171 | l.append(rev) |
|
171 | l.append(rev) | |
172 | continue |
|
172 | continue | |
173 | except error.RepoLookupError: |
|
173 | except error.RepoLookupError: | |
174 | pass |
|
174 | pass | |
175 |
|
175 | |||
176 | # fall through to new-style queries if old-style fails |
|
176 | # fall through to new-style queries if old-style fails | |
177 | m = revset.match(spec) |
|
177 | m = revset.match(spec) | |
178 | for r in m(repo, range(len(repo))): |
|
178 | for r in m(repo, range(len(repo))): | |
179 | if r not in seen: |
|
179 | if r not in seen: | |
180 | l.append(r) |
|
180 | l.append(r) | |
181 | seen.update(l) |
|
181 | seen.update(l) | |
182 |
|
182 | |||
183 | return l |
|
183 | return l | |
184 |
|
184 | |||
185 | def make_filename(repo, pat, node, |
|
185 | def make_filename(repo, pat, node, | |
186 | total=None, seqno=None, revwidth=None, pathname=None): |
|
186 | total=None, seqno=None, revwidth=None, pathname=None): | |
187 | node_expander = { |
|
187 | node_expander = { | |
188 | 'H': lambda: hex(node), |
|
188 | 'H': lambda: hex(node), | |
189 | 'R': lambda: str(repo.changelog.rev(node)), |
|
189 | 'R': lambda: str(repo.changelog.rev(node)), | |
190 | 'h': lambda: short(node), |
|
190 | 'h': lambda: short(node), | |
191 | } |
|
191 | } | |
192 | expander = { |
|
192 | expander = { | |
193 | '%': lambda: '%', |
|
193 | '%': lambda: '%', | |
194 | 'b': lambda: os.path.basename(repo.root), |
|
194 | 'b': lambda: os.path.basename(repo.root), | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | try: |
|
197 | try: | |
198 | if node: |
|
198 | if node: | |
199 | expander.update(node_expander) |
|
199 | expander.update(node_expander) | |
200 | if node: |
|
200 | if node: | |
201 | expander['r'] = (lambda: |
|
201 | expander['r'] = (lambda: | |
202 | str(repo.changelog.rev(node)).zfill(revwidth or 0)) |
|
202 | str(repo.changelog.rev(node)).zfill(revwidth or 0)) | |
203 | if total is not None: |
|
203 | if total is not None: | |
204 | expander['N'] = lambda: str(total) |
|
204 | expander['N'] = lambda: str(total) | |
205 | if seqno is not None: |
|
205 | if seqno is not None: | |
206 | expander['n'] = lambda: str(seqno) |
|
206 | expander['n'] = lambda: str(seqno) | |
207 | if total is not None and seqno is not None: |
|
207 | if total is not None and seqno is not None: | |
208 | expander['n'] = lambda: str(seqno).zfill(len(str(total))) |
|
208 | expander['n'] = lambda: str(seqno).zfill(len(str(total))) | |
209 | if pathname is not None: |
|
209 | if pathname is not None: | |
210 | expander['s'] = lambda: os.path.basename(pathname) |
|
210 | expander['s'] = lambda: os.path.basename(pathname) | |
211 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
211 | expander['d'] = lambda: os.path.dirname(pathname) or '.' | |
212 | expander['p'] = lambda: pathname |
|
212 | expander['p'] = lambda: pathname | |
213 |
|
213 | |||
214 | newname = [] |
|
214 | newname = [] | |
215 | patlen = len(pat) |
|
215 | patlen = len(pat) | |
216 | i = 0 |
|
216 | i = 0 | |
217 | while i < patlen: |
|
217 | while i < patlen: | |
218 | c = pat[i] |
|
218 | c = pat[i] | |
219 | if c == '%': |
|
219 | if c == '%': | |
220 | i += 1 |
|
220 | i += 1 | |
221 | c = pat[i] |
|
221 | c = pat[i] | |
222 | c = expander[c]() |
|
222 | c = expander[c]() | |
223 | newname.append(c) |
|
223 | newname.append(c) | |
224 | i += 1 |
|
224 | i += 1 | |
225 | return ''.join(newname) |
|
225 | return ''.join(newname) | |
226 | except KeyError, inst: |
|
226 | except KeyError, inst: | |
227 | raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
|
227 | raise util.Abort(_("invalid format spec '%%%s' in output filename") % | |
228 | inst.args[0]) |
|
228 | inst.args[0]) | |
229 |
|
229 | |||
230 | def make_file(repo, pat, node=None, |
|
230 | def make_file(repo, pat, node=None, | |
231 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
231 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): | |
232 |
|
232 | |||
233 | writable = 'w' in mode or 'a' in mode |
|
233 | writable = 'w' in mode or 'a' in mode | |
234 |
|
234 | |||
235 | if not pat or pat == '-': |
|
235 | if not pat or pat == '-': | |
236 | return writable and sys.stdout or sys.stdin |
|
236 | return writable and sys.stdout or sys.stdin | |
237 | if hasattr(pat, 'write') and writable: |
|
237 | if hasattr(pat, 'write') and writable: | |
238 | return pat |
|
238 | return pat | |
239 | if hasattr(pat, 'read') and 'r' in mode: |
|
239 | if hasattr(pat, 'read') and 'r' in mode: | |
240 | return pat |
|
240 | return pat | |
241 | return open(make_filename(repo, pat, node, total, seqno, revwidth, |
|
241 | return open(make_filename(repo, pat, node, total, seqno, revwidth, | |
242 | pathname), |
|
242 | pathname), | |
243 | mode) |
|
243 | mode) | |
244 |
|
244 | |||
245 | def expandpats(pats): |
|
245 | def expandpats(pats): | |
246 | if not util.expandglobs: |
|
246 | if not util.expandglobs: | |
247 | return list(pats) |
|
247 | return list(pats) | |
248 | ret = [] |
|
248 | ret = [] | |
249 | for p in pats: |
|
249 | for p in pats: | |
250 | kind, name = _match._patsplit(p, None) |
|
250 | kind, name = _match._patsplit(p, None) | |
251 | if kind is None: |
|
251 | if kind is None: | |
252 | try: |
|
252 | try: | |
253 | globbed = glob.glob(name) |
|
253 | globbed = glob.glob(name) | |
254 | except re.error: |
|
254 | except re.error: | |
255 | globbed = [name] |
|
255 | globbed = [name] | |
256 | if globbed: |
|
256 | if globbed: | |
257 | ret.extend(globbed) |
|
257 | ret.extend(globbed) | |
258 | continue |
|
258 | continue | |
259 | ret.append(p) |
|
259 | ret.append(p) | |
260 | return ret |
|
260 | return ret | |
261 |
|
261 | |||
262 | def match(repo, pats=[], opts={}, globbed=False, default='relpath'): |
|
262 | def match(repo, pats=[], opts={}, globbed=False, default='relpath'): | |
263 | if not globbed and default == 'relpath': |
|
263 | if not globbed and default == 'relpath': | |
264 | pats = expandpats(pats or []) |
|
264 | pats = expandpats(pats or []) | |
265 | m = _match.match(repo.root, repo.getcwd(), pats, |
|
265 | m = _match.match(repo.root, repo.getcwd(), pats, | |
266 | opts.get('include'), opts.get('exclude'), default) |
|
266 | opts.get('include'), opts.get('exclude'), default) | |
267 | def badfn(f, msg): |
|
267 | def badfn(f, msg): | |
268 | repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) |
|
268 | repo.ui.warn("%s: %s\n" % (m.rel(f), msg)) | |
269 | m.bad = badfn |
|
269 | m.bad = badfn | |
270 | return m |
|
270 | return m | |
271 |
|
271 | |||
272 | def matchall(repo): |
|
272 | def matchall(repo): | |
273 | return _match.always(repo.root, repo.getcwd()) |
|
273 | return _match.always(repo.root, repo.getcwd()) | |
274 |
|
274 | |||
275 | def matchfiles(repo, files): |
|
275 | def matchfiles(repo, files): | |
276 | return _match.exact(repo.root, repo.getcwd(), files) |
|
276 | return _match.exact(repo.root, repo.getcwd(), files) | |
277 |
|
277 | |||
278 | def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): |
|
278 | def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): | |
279 | if dry_run is None: |
|
279 | if dry_run is None: | |
280 | dry_run = opts.get('dry_run') |
|
280 | dry_run = opts.get('dry_run') | |
281 | if similarity is None: |
|
281 | if similarity is None: | |
282 | similarity = float(opts.get('similarity') or 0) |
|
282 | similarity = float(opts.get('similarity') or 0) | |
283 | # we'd use status here, except handling of symlinks and ignore is tricky |
|
283 | # we'd use status here, except handling of symlinks and ignore is tricky | |
284 | added, unknown, deleted, removed = [], [], [], [] |
|
284 | added, unknown, deleted, removed = [], [], [], [] | |
285 | audit_path = util.path_auditor(repo.root) |
|
285 | audit_path = util.path_auditor(repo.root) | |
286 | m = match(repo, pats, opts) |
|
286 | m = match(repo, pats, opts) | |
287 | for abs in repo.walk(m): |
|
287 | for abs in repo.walk(m): | |
288 | target = repo.wjoin(abs) |
|
288 | target = repo.wjoin(abs) | |
289 | good = True |
|
289 | good = True | |
290 | try: |
|
290 | try: | |
291 | audit_path(abs) |
|
291 | audit_path(abs) | |
292 | except: |
|
292 | except: | |
293 | good = False |
|
293 | good = False | |
294 | rel = m.rel(abs) |
|
294 | rel = m.rel(abs) | |
295 | exact = m.exact(abs) |
|
295 | exact = m.exact(abs) | |
296 | if good and abs not in repo.dirstate: |
|
296 | if good and abs not in repo.dirstate: | |
297 | unknown.append(abs) |
|
297 | unknown.append(abs) | |
298 | if repo.ui.verbose or not exact: |
|
298 | if repo.ui.verbose or not exact: | |
299 | repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
299 | repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) | |
300 | elif repo.dirstate[abs] != 'r' and (not good or not util.lexists(target) |
|
300 | elif repo.dirstate[abs] != 'r' and (not good or not util.lexists(target) | |
301 | or (os.path.isdir(target) and not os.path.islink(target))): |
|
301 | or (os.path.isdir(target) and not os.path.islink(target))): | |
302 | deleted.append(abs) |
|
302 | deleted.append(abs) | |
303 | if repo.ui.verbose or not exact: |
|
303 | if repo.ui.verbose or not exact: | |
304 | repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
304 | repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) | |
305 | # for finding renames |
|
305 | # for finding renames | |
306 | elif repo.dirstate[abs] == 'r': |
|
306 | elif repo.dirstate[abs] == 'r': | |
307 | removed.append(abs) |
|
307 | removed.append(abs) | |
308 | elif repo.dirstate[abs] == 'a': |
|
308 | elif repo.dirstate[abs] == 'a': | |
309 | added.append(abs) |
|
309 | added.append(abs) | |
310 | copies = {} |
|
310 | copies = {} | |
311 | if similarity > 0: |
|
311 | if similarity > 0: | |
312 | for old, new, score in similar.findrenames(repo, |
|
312 | for old, new, score in similar.findrenames(repo, | |
313 | added + unknown, removed + deleted, similarity): |
|
313 | added + unknown, removed + deleted, similarity): | |
314 | if repo.ui.verbose or not m.exact(old) or not m.exact(new): |
|
314 | if repo.ui.verbose or not m.exact(old) or not m.exact(new): | |
315 | repo.ui.status(_('recording removal of %s as rename to %s ' |
|
315 | repo.ui.status(_('recording removal of %s as rename to %s ' | |
316 | '(%d%% similar)\n') % |
|
316 | '(%d%% similar)\n') % | |
317 | (m.rel(old), m.rel(new), score * 100)) |
|
317 | (m.rel(old), m.rel(new), score * 100)) | |
318 | copies[new] = old |
|
318 | copies[new] = old | |
319 |
|
319 | |||
320 | if not dry_run: |
|
320 | if not dry_run: | |
321 | wctx = repo[None] |
|
321 | wctx = repo[None] | |
322 | wlock = repo.wlock() |
|
322 | wlock = repo.wlock() | |
323 | try: |
|
323 | try: | |
324 | wctx.remove(deleted) |
|
324 | wctx.remove(deleted) | |
325 | wctx.add(unknown) |
|
325 | wctx.add(unknown) | |
326 | for new, old in copies.iteritems(): |
|
326 | for new, old in copies.iteritems(): | |
327 | wctx.copy(old, new) |
|
327 | wctx.copy(old, new) | |
328 | finally: |
|
328 | finally: | |
329 | wlock.release() |
|
329 | wlock.release() | |
330 |
|
330 | |||
331 | def copy(ui, repo, pats, opts, rename=False): |
|
331 | def copy(ui, repo, pats, opts, rename=False): | |
332 | # called with the repo lock held |
|
332 | # called with the repo lock held | |
333 | # |
|
333 | # | |
334 | # hgsep => pathname that uses "/" to separate directories |
|
334 | # hgsep => pathname that uses "/" to separate directories | |
335 | # ossep => pathname that uses os.sep to separate directories |
|
335 | # ossep => pathname that uses os.sep to separate directories | |
336 | cwd = repo.getcwd() |
|
336 | cwd = repo.getcwd() | |
337 | targets = {} |
|
337 | targets = {} | |
338 | after = opts.get("after") |
|
338 | after = opts.get("after") | |
339 | dryrun = opts.get("dry_run") |
|
339 | dryrun = opts.get("dry_run") | |
340 | wctx = repo[None] |
|
340 | wctx = repo[None] | |
341 |
|
341 | |||
342 | def walkpat(pat): |
|
342 | def walkpat(pat): | |
343 | srcs = [] |
|
343 | srcs = [] | |
344 | badstates = after and '?' or '?r' |
|
344 | badstates = after and '?' or '?r' | |
345 | m = match(repo, [pat], opts, globbed=True) |
|
345 | m = match(repo, [pat], opts, globbed=True) | |
346 | for abs in repo.walk(m): |
|
346 | for abs in repo.walk(m): | |
347 | state = repo.dirstate[abs] |
|
347 | state = repo.dirstate[abs] | |
348 | rel = m.rel(abs) |
|
348 | rel = m.rel(abs) | |
349 | exact = m.exact(abs) |
|
349 | exact = m.exact(abs) | |
350 | if state in badstates: |
|
350 | if state in badstates: | |
351 | if exact and state == '?': |
|
351 | if exact and state == '?': | |
352 | ui.warn(_('%s: not copying - file is not managed\n') % rel) |
|
352 | ui.warn(_('%s: not copying - file is not managed\n') % rel) | |
353 | if exact and state == 'r': |
|
353 | if exact and state == 'r': | |
354 | ui.warn(_('%s: not copying - file has been marked for' |
|
354 | ui.warn(_('%s: not copying - file has been marked for' | |
355 | ' remove\n') % rel) |
|
355 | ' remove\n') % rel) | |
356 | continue |
|
356 | continue | |
357 | # abs: hgsep |
|
357 | # abs: hgsep | |
358 | # rel: ossep |
|
358 | # rel: ossep | |
359 | srcs.append((abs, rel, exact)) |
|
359 | srcs.append((abs, rel, exact)) | |
360 | return srcs |
|
360 | return srcs | |
361 |
|
361 | |||
362 | # abssrc: hgsep |
|
362 | # abssrc: hgsep | |
363 | # relsrc: ossep |
|
363 | # relsrc: ossep | |
364 | # otarget: ossep |
|
364 | # otarget: ossep | |
365 | def copyfile(abssrc, relsrc, otarget, exact): |
|
365 | def copyfile(abssrc, relsrc, otarget, exact): | |
366 | abstarget = util.canonpath(repo.root, cwd, otarget) |
|
366 | abstarget = util.canonpath(repo.root, cwd, otarget) | |
367 | reltarget = repo.pathto(abstarget, cwd) |
|
367 | reltarget = repo.pathto(abstarget, cwd) | |
368 | target = repo.wjoin(abstarget) |
|
368 | target = repo.wjoin(abstarget) | |
369 | src = repo.wjoin(abssrc) |
|
369 | src = repo.wjoin(abssrc) | |
370 | state = repo.dirstate[abstarget] |
|
370 | state = repo.dirstate[abstarget] | |
371 |
|
371 | |||
372 | # check for collisions |
|
372 | # check for collisions | |
373 | prevsrc = targets.get(abstarget) |
|
373 | prevsrc = targets.get(abstarget) | |
374 | if prevsrc is not None: |
|
374 | if prevsrc is not None: | |
375 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
375 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
376 | (reltarget, repo.pathto(abssrc, cwd), |
|
376 | (reltarget, repo.pathto(abssrc, cwd), | |
377 | repo.pathto(prevsrc, cwd))) |
|
377 | repo.pathto(prevsrc, cwd))) | |
378 | return |
|
378 | return | |
379 |
|
379 | |||
380 | # check for overwrites |
|
380 | # check for overwrites | |
381 | exists = os.path.exists(target) |
|
381 | exists = os.path.exists(target) | |
382 | if not after and exists or after and state in 'mn': |
|
382 | if not after and exists or after and state in 'mn': | |
383 | if not opts['force']: |
|
383 | if not opts['force']: | |
384 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
384 | ui.warn(_('%s: not overwriting - file exists\n') % | |
385 | reltarget) |
|
385 | reltarget) | |
386 | return |
|
386 | return | |
387 |
|
387 | |||
388 | if after: |
|
388 | if after: | |
389 | if not exists: |
|
389 | if not exists: | |
390 | if rename: |
|
390 | if rename: | |
391 | ui.warn(_('%s: not recording move - %s does not exist\n') % |
|
391 | ui.warn(_('%s: not recording move - %s does not exist\n') % | |
392 | (relsrc, reltarget)) |
|
392 | (relsrc, reltarget)) | |
393 | else: |
|
393 | else: | |
394 | ui.warn(_('%s: not recording copy - %s does not exist\n') % |
|
394 | ui.warn(_('%s: not recording copy - %s does not exist\n') % | |
395 | (relsrc, reltarget)) |
|
395 | (relsrc, reltarget)) | |
396 | return |
|
396 | return | |
397 | elif not dryrun: |
|
397 | elif not dryrun: | |
398 | try: |
|
398 | try: | |
399 | if exists: |
|
399 | if exists: | |
400 | os.unlink(target) |
|
400 | os.unlink(target) | |
401 | targetdir = os.path.dirname(target) or '.' |
|
401 | targetdir = os.path.dirname(target) or '.' | |
402 | if not os.path.isdir(targetdir): |
|
402 | if not os.path.isdir(targetdir): | |
403 | os.makedirs(targetdir) |
|
403 | os.makedirs(targetdir) | |
404 | util.copyfile(src, target) |
|
404 | util.copyfile(src, target) | |
405 | except IOError, inst: |
|
405 | except IOError, inst: | |
406 | if inst.errno == errno.ENOENT: |
|
406 | if inst.errno == errno.ENOENT: | |
407 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
407 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
408 | else: |
|
408 | else: | |
409 | ui.warn(_('%s: cannot copy - %s\n') % |
|
409 | ui.warn(_('%s: cannot copy - %s\n') % | |
410 | (relsrc, inst.strerror)) |
|
410 | (relsrc, inst.strerror)) | |
411 | return True # report a failure |
|
411 | return True # report a failure | |
412 |
|
412 | |||
413 | if ui.verbose or not exact: |
|
413 | if ui.verbose or not exact: | |
414 | if rename: |
|
414 | if rename: | |
415 | ui.status(_('moving %s to %s\n') % (relsrc, reltarget)) |
|
415 | ui.status(_('moving %s to %s\n') % (relsrc, reltarget)) | |
416 | else: |
|
416 | else: | |
417 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
417 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
418 |
|
418 | |||
419 | targets[abstarget] = abssrc |
|
419 | targets[abstarget] = abssrc | |
420 |
|
420 | |||
421 | # fix up dirstate |
|
421 | # fix up dirstate | |
422 | origsrc = repo.dirstate.copied(abssrc) or abssrc |
|
422 | origsrc = repo.dirstate.copied(abssrc) or abssrc | |
423 | if abstarget == origsrc: # copying back a copy? |
|
423 | if abstarget == origsrc: # copying back a copy? | |
424 | if state not in 'mn' and not dryrun: |
|
424 | if state not in 'mn' and not dryrun: | |
425 | repo.dirstate.normallookup(abstarget) |
|
425 | repo.dirstate.normallookup(abstarget) | |
426 | else: |
|
426 | else: | |
427 | if repo.dirstate[origsrc] == 'a' and origsrc == abssrc: |
|
427 | if repo.dirstate[origsrc] == 'a' and origsrc == abssrc: | |
428 | if not ui.quiet: |
|
428 | if not ui.quiet: | |
429 | ui.warn(_("%s has not been committed yet, so no copy " |
|
429 | ui.warn(_("%s has not been committed yet, so no copy " | |
430 | "data will be stored for %s.\n") |
|
430 | "data will be stored for %s.\n") | |
431 | % (repo.pathto(origsrc, cwd), reltarget)) |
|
431 | % (repo.pathto(origsrc, cwd), reltarget)) | |
432 | if repo.dirstate[abstarget] in '?r' and not dryrun: |
|
432 | if repo.dirstate[abstarget] in '?r' and not dryrun: | |
433 | wctx.add([abstarget]) |
|
433 | wctx.add([abstarget]) | |
434 | elif not dryrun: |
|
434 | elif not dryrun: | |
435 | wctx.copy(origsrc, abstarget) |
|
435 | wctx.copy(origsrc, abstarget) | |
436 |
|
436 | |||
437 | if rename and not dryrun: |
|
437 | if rename and not dryrun: | |
438 | wctx.remove([abssrc], not after) |
|
438 | wctx.remove([abssrc], not after) | |
439 |
|
439 | |||
440 | # pat: ossep |
|
440 | # pat: ossep | |
441 | # dest ossep |
|
441 | # dest ossep | |
442 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
442 | # srcs: list of (hgsep, hgsep, ossep, bool) | |
443 | # return: function that takes hgsep and returns ossep |
|
443 | # return: function that takes hgsep and returns ossep | |
444 | def targetpathfn(pat, dest, srcs): |
|
444 | def targetpathfn(pat, dest, srcs): | |
445 | if os.path.isdir(pat): |
|
445 | if os.path.isdir(pat): | |
446 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
446 | abspfx = util.canonpath(repo.root, cwd, pat) | |
447 | abspfx = util.localpath(abspfx) |
|
447 | abspfx = util.localpath(abspfx) | |
448 | if destdirexists: |
|
448 | if destdirexists: | |
449 | striplen = len(os.path.split(abspfx)[0]) |
|
449 | striplen = len(os.path.split(abspfx)[0]) | |
450 | else: |
|
450 | else: | |
451 | striplen = len(abspfx) |
|
451 | striplen = len(abspfx) | |
452 | if striplen: |
|
452 | if striplen: | |
453 | striplen += len(os.sep) |
|
453 | striplen += len(os.sep) | |
454 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
|
454 | res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) | |
455 | elif destdirexists: |
|
455 | elif destdirexists: | |
456 | res = lambda p: os.path.join(dest, |
|
456 | res = lambda p: os.path.join(dest, | |
457 | os.path.basename(util.localpath(p))) |
|
457 | os.path.basename(util.localpath(p))) | |
458 | else: |
|
458 | else: | |
459 | res = lambda p: dest |
|
459 | res = lambda p: dest | |
460 | return res |
|
460 | return res | |
461 |
|
461 | |||
462 | # pat: ossep |
|
462 | # pat: ossep | |
463 | # dest ossep |
|
463 | # dest ossep | |
464 | # srcs: list of (hgsep, hgsep, ossep, bool) |
|
464 | # srcs: list of (hgsep, hgsep, ossep, bool) | |
465 | # return: function that takes hgsep and returns ossep |
|
465 | # return: function that takes hgsep and returns ossep | |
466 | def targetpathafterfn(pat, dest, srcs): |
|
466 | def targetpathafterfn(pat, dest, srcs): | |
467 | if _match.patkind(pat): |
|
467 | if _match.patkind(pat): | |
468 | # a mercurial pattern |
|
468 | # a mercurial pattern | |
469 | res = lambda p: os.path.join(dest, |
|
469 | res = lambda p: os.path.join(dest, | |
470 | os.path.basename(util.localpath(p))) |
|
470 | os.path.basename(util.localpath(p))) | |
471 | else: |
|
471 | else: | |
472 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
472 | abspfx = util.canonpath(repo.root, cwd, pat) | |
473 | if len(abspfx) < len(srcs[0][0]): |
|
473 | if len(abspfx) < len(srcs[0][0]): | |
474 | # A directory. Either the target path contains the last |
|
474 | # A directory. Either the target path contains the last | |
475 | # component of the source path or it does not. |
|
475 | # component of the source path or it does not. | |
476 | def evalpath(striplen): |
|
476 | def evalpath(striplen): | |
477 | score = 0 |
|
477 | score = 0 | |
478 | for s in srcs: |
|
478 | for s in srcs: | |
479 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
|
479 | t = os.path.join(dest, util.localpath(s[0])[striplen:]) | |
480 | if os.path.exists(t): |
|
480 | if os.path.exists(t): | |
481 | score += 1 |
|
481 | score += 1 | |
482 | return score |
|
482 | return score | |
483 |
|
483 | |||
484 | abspfx = util.localpath(abspfx) |
|
484 | abspfx = util.localpath(abspfx) | |
485 | striplen = len(abspfx) |
|
485 | striplen = len(abspfx) | |
486 | if striplen: |
|
486 | if striplen: | |
487 | striplen += len(os.sep) |
|
487 | striplen += len(os.sep) | |
488 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
488 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
489 | score = evalpath(striplen) |
|
489 | score = evalpath(striplen) | |
490 | striplen1 = len(os.path.split(abspfx)[0]) |
|
490 | striplen1 = len(os.path.split(abspfx)[0]) | |
491 | if striplen1: |
|
491 | if striplen1: | |
492 | striplen1 += len(os.sep) |
|
492 | striplen1 += len(os.sep) | |
493 | if evalpath(striplen1) > score: |
|
493 | if evalpath(striplen1) > score: | |
494 | striplen = striplen1 |
|
494 | striplen = striplen1 | |
495 | res = lambda p: os.path.join(dest, |
|
495 | res = lambda p: os.path.join(dest, | |
496 | util.localpath(p)[striplen:]) |
|
496 | util.localpath(p)[striplen:]) | |
497 | else: |
|
497 | else: | |
498 | # a file |
|
498 | # a file | |
499 | if destdirexists: |
|
499 | if destdirexists: | |
500 | res = lambda p: os.path.join(dest, |
|
500 | res = lambda p: os.path.join(dest, | |
501 | os.path.basename(util.localpath(p))) |
|
501 | os.path.basename(util.localpath(p))) | |
502 | else: |
|
502 | else: | |
503 | res = lambda p: dest |
|
503 | res = lambda p: dest | |
504 | return res |
|
504 | return res | |
505 |
|
505 | |||
506 |
|
506 | |||
507 | pats = expandpats(pats) |
|
507 | pats = expandpats(pats) | |
508 | if not pats: |
|
508 | if not pats: | |
509 | raise util.Abort(_('no source or destination specified')) |
|
509 | raise util.Abort(_('no source or destination specified')) | |
510 | if len(pats) == 1: |
|
510 | if len(pats) == 1: | |
511 | raise util.Abort(_('no destination specified')) |
|
511 | raise util.Abort(_('no destination specified')) | |
512 | dest = pats.pop() |
|
512 | dest = pats.pop() | |
513 | destdirexists = os.path.isdir(dest) and not os.path.islink(dest) |
|
513 | destdirexists = os.path.isdir(dest) and not os.path.islink(dest) | |
514 | if not destdirexists: |
|
514 | if not destdirexists: | |
515 | if len(pats) > 1 or _match.patkind(pats[0]): |
|
515 | if len(pats) > 1 or _match.patkind(pats[0]): | |
516 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
516 | raise util.Abort(_('with multiple sources, destination must be an ' | |
517 | 'existing directory')) |
|
517 | 'existing directory')) | |
518 | if util.endswithsep(dest): |
|
518 | if util.endswithsep(dest): | |
519 | raise util.Abort(_('destination %s is not a directory') % dest) |
|
519 | raise util.Abort(_('destination %s is not a directory') % dest) | |
520 |
|
520 | |||
521 | tfn = targetpathfn |
|
521 | tfn = targetpathfn | |
522 | if after: |
|
522 | if after: | |
523 | tfn = targetpathafterfn |
|
523 | tfn = targetpathafterfn | |
524 | copylist = [] |
|
524 | copylist = [] | |
525 | for pat in pats: |
|
525 | for pat in pats: | |
526 | srcs = walkpat(pat) |
|
526 | srcs = walkpat(pat) | |
527 | if not srcs: |
|
527 | if not srcs: | |
528 | continue |
|
528 | continue | |
529 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
529 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
530 | if not copylist: |
|
530 | if not copylist: | |
531 | raise util.Abort(_('no files to copy')) |
|
531 | raise util.Abort(_('no files to copy')) | |
532 |
|
532 | |||
533 | errors = 0 |
|
533 | errors = 0 | |
534 | for targetpath, srcs in copylist: |
|
534 | for targetpath, srcs in copylist: | |
535 | for abssrc, relsrc, exact in srcs: |
|
535 | for abssrc, relsrc, exact in srcs: | |
536 | if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
|
536 | if copyfile(abssrc, relsrc, targetpath(abssrc), exact): | |
537 | errors += 1 |
|
537 | errors += 1 | |
538 |
|
538 | |||
539 | if errors: |
|
539 | if errors: | |
540 | ui.warn(_('(consider using --after)\n')) |
|
540 | ui.warn(_('(consider using --after)\n')) | |
541 |
|
541 | |||
542 | return errors != 0 |
|
542 | return errors != 0 | |
543 |
|
543 | |||
544 | def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, |
|
544 | def service(opts, parentfn=None, initfn=None, runfn=None, logfile=None, | |
545 | runargs=None, appendpid=False): |
|
545 | runargs=None, appendpid=False): | |
546 | '''Run a command as a service.''' |
|
546 | '''Run a command as a service.''' | |
547 |
|
547 | |||
548 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
548 | if opts['daemon'] and not opts['daemon_pipefds']: | |
549 | # Signal child process startup with file removal |
|
549 | # Signal child process startup with file removal | |
550 | lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') |
|
550 | lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') | |
551 | os.close(lockfd) |
|
551 | os.close(lockfd) | |
552 | try: |
|
552 | try: | |
553 | if not runargs: |
|
553 | if not runargs: | |
554 | runargs = util.hgcmd() + sys.argv[1:] |
|
554 | runargs = util.hgcmd() + sys.argv[1:] | |
555 | runargs.append('--daemon-pipefds=%s' % lockpath) |
|
555 | runargs.append('--daemon-pipefds=%s' % lockpath) | |
556 | # Don't pass --cwd to the child process, because we've already |
|
556 | # Don't pass --cwd to the child process, because we've already | |
557 | # changed directory. |
|
557 | # changed directory. | |
558 | for i in xrange(1, len(runargs)): |
|
558 | for i in xrange(1, len(runargs)): | |
559 | if runargs[i].startswith('--cwd='): |
|
559 | if runargs[i].startswith('--cwd='): | |
560 | del runargs[i] |
|
560 | del runargs[i] | |
561 | break |
|
561 | break | |
562 | elif runargs[i].startswith('--cwd'): |
|
562 | elif runargs[i].startswith('--cwd'): | |
563 | del runargs[i:i + 2] |
|
563 | del runargs[i:i + 2] | |
564 | break |
|
564 | break | |
565 | def condfn(): |
|
565 | def condfn(): | |
566 | return not os.path.exists(lockpath) |
|
566 | return not os.path.exists(lockpath) | |
567 | pid = util.rundetached(runargs, condfn) |
|
567 | pid = util.rundetached(runargs, condfn) | |
568 | if pid < 0: |
|
568 | if pid < 0: | |
569 | raise util.Abort(_('child process failed to start')) |
|
569 | raise util.Abort(_('child process failed to start')) | |
570 | finally: |
|
570 | finally: | |
571 | try: |
|
571 | try: | |
572 | os.unlink(lockpath) |
|
572 | os.unlink(lockpath) | |
573 | except OSError, e: |
|
573 | except OSError, e: | |
574 | if e.errno != errno.ENOENT: |
|
574 | if e.errno != errno.ENOENT: | |
575 | raise |
|
575 | raise | |
576 | if parentfn: |
|
576 | if parentfn: | |
577 | return parentfn(pid) |
|
577 | return parentfn(pid) | |
578 | else: |
|
578 | else: | |
579 | return |
|
579 | return | |
580 |
|
580 | |||
581 | if initfn: |
|
581 | if initfn: | |
582 | initfn() |
|
582 | initfn() | |
583 |
|
583 | |||
584 | if opts['pid_file']: |
|
584 | if opts['pid_file']: | |
585 | mode = appendpid and 'a' or 'w' |
|
585 | mode = appendpid and 'a' or 'w' | |
586 | fp = open(opts['pid_file'], mode) |
|
586 | fp = open(opts['pid_file'], mode) | |
587 | fp.write(str(os.getpid()) + '\n') |
|
587 | fp.write(str(os.getpid()) + '\n') | |
588 | fp.close() |
|
588 | fp.close() | |
589 |
|
589 | |||
590 | if opts['daemon_pipefds']: |
|
590 | if opts['daemon_pipefds']: | |
591 | lockpath = opts['daemon_pipefds'] |
|
591 | lockpath = opts['daemon_pipefds'] | |
592 | try: |
|
592 | try: | |
593 | os.setsid() |
|
593 | os.setsid() | |
594 | except AttributeError: |
|
594 | except AttributeError: | |
595 | pass |
|
595 | pass | |
596 | os.unlink(lockpath) |
|
596 | os.unlink(lockpath) | |
597 | util.hidewindow() |
|
597 | util.hidewindow() | |
598 | sys.stdout.flush() |
|
598 | sys.stdout.flush() | |
599 | sys.stderr.flush() |
|
599 | sys.stderr.flush() | |
600 |
|
600 | |||
601 | nullfd = os.open(util.nulldev, os.O_RDWR) |
|
601 | nullfd = os.open(util.nulldev, os.O_RDWR) | |
602 | logfilefd = nullfd |
|
602 | logfilefd = nullfd | |
603 | if logfile: |
|
603 | if logfile: | |
604 | logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND) |
|
604 | logfilefd = os.open(logfile, os.O_RDWR | os.O_CREAT | os.O_APPEND) | |
605 | os.dup2(nullfd, 0) |
|
605 | os.dup2(nullfd, 0) | |
606 | os.dup2(logfilefd, 1) |
|
606 | os.dup2(logfilefd, 1) | |
607 | os.dup2(logfilefd, 2) |
|
607 | os.dup2(logfilefd, 2) | |
608 | if nullfd not in (0, 1, 2): |
|
608 | if nullfd not in (0, 1, 2): | |
609 | os.close(nullfd) |
|
609 | os.close(nullfd) | |
610 | if logfile and logfilefd not in (0, 1, 2): |
|
610 | if logfile and logfilefd not in (0, 1, 2): | |
611 | os.close(logfilefd) |
|
611 | os.close(logfilefd) | |
612 |
|
612 | |||
613 | if runfn: |
|
613 | if runfn: | |
614 | return runfn() |
|
614 | return runfn() | |
615 |
|
615 | |||
616 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, |
|
616 | def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False, | |
617 | opts=None): |
|
617 | opts=None): | |
618 | '''export changesets as hg patches.''' |
|
618 | '''export changesets as hg patches.''' | |
619 |
|
619 | |||
620 | total = len(revs) |
|
620 | total = len(revs) | |
621 | revwidth = max([len(str(rev)) for rev in revs]) |
|
621 | revwidth = max([len(str(rev)) for rev in revs]) | |
622 |
|
622 | |||
623 | def single(rev, seqno, fp): |
|
623 | def single(rev, seqno, fp): | |
624 | ctx = repo[rev] |
|
624 | ctx = repo[rev] | |
625 | node = ctx.node() |
|
625 | node = ctx.node() | |
626 | parents = [p.node() for p in ctx.parents() if p] |
|
626 | parents = [p.node() for p in ctx.parents() if p] | |
627 | branch = ctx.branch() |
|
627 | branch = ctx.branch() | |
628 | if switch_parent: |
|
628 | if switch_parent: | |
629 | parents.reverse() |
|
629 | parents.reverse() | |
630 | prev = (parents and parents[0]) or nullid |
|
630 | prev = (parents and parents[0]) or nullid | |
631 |
|
631 | |||
632 | if not fp: |
|
632 | if not fp: | |
633 | fp = make_file(repo, template, node, total=total, seqno=seqno, |
|
633 | fp = make_file(repo, template, node, total=total, seqno=seqno, | |
634 | revwidth=revwidth, mode='ab') |
|
634 | revwidth=revwidth, mode='ab') | |
635 | if fp != sys.stdout and hasattr(fp, 'name'): |
|
635 | if fp != sys.stdout and hasattr(fp, 'name'): | |
636 | repo.ui.note("%s\n" % fp.name) |
|
636 | repo.ui.note("%s\n" % fp.name) | |
637 |
|
637 | |||
638 | fp.write("# HG changeset patch\n") |
|
638 | fp.write("# HG changeset patch\n") | |
639 | fp.write("# User %s\n" % ctx.user()) |
|
639 | fp.write("# User %s\n" % ctx.user()) | |
640 | fp.write("# Date %d %d\n" % ctx.date()) |
|
640 | fp.write("# Date %d %d\n" % ctx.date()) | |
641 | if branch and (branch != 'default'): |
|
641 | if branch and (branch != 'default'): | |
642 | fp.write("# Branch %s\n" % branch) |
|
642 | fp.write("# Branch %s\n" % branch) | |
643 | fp.write("# Node ID %s\n" % hex(node)) |
|
643 | fp.write("# Node ID %s\n" % hex(node)) | |
644 | fp.write("# Parent %s\n" % hex(prev)) |
|
644 | fp.write("# Parent %s\n" % hex(prev)) | |
645 | if len(parents) > 1: |
|
645 | if len(parents) > 1: | |
646 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
646 | fp.write("# Parent %s\n" % hex(parents[1])) | |
647 | fp.write(ctx.description().rstrip()) |
|
647 | fp.write(ctx.description().rstrip()) | |
648 | fp.write("\n\n") |
|
648 | fp.write("\n\n") | |
649 |
|
649 | |||
650 | for chunk in patch.diff(repo, prev, node, opts=opts): |
|
650 | for chunk in patch.diff(repo, prev, node, opts=opts): | |
651 | fp.write(chunk) |
|
651 | fp.write(chunk) | |
652 |
|
652 | |||
653 | for seqno, rev in enumerate(revs): |
|
653 | for seqno, rev in enumerate(revs): | |
654 | single(rev, seqno + 1, fp) |
|
654 | single(rev, seqno + 1, fp) | |
655 |
|
655 | |||
656 | def diffordiffstat(ui, repo, diffopts, node1, node2, match, |
|
656 | def diffordiffstat(ui, repo, diffopts, node1, node2, match, | |
657 | changes=None, stat=False, fp=None): |
|
657 | changes=None, stat=False, fp=None): | |
658 | '''show diff or diffstat.''' |
|
658 | '''show diff or diffstat.''' | |
659 | if fp is None: |
|
659 | if fp is None: | |
660 | write = ui.write |
|
660 | write = ui.write | |
661 | else: |
|
661 | else: | |
662 | def write(s, **kw): |
|
662 | def write(s, **kw): | |
663 | fp.write(s) |
|
663 | fp.write(s) | |
664 |
|
664 | |||
665 | if stat: |
|
665 | if stat: | |
666 | diffopts.context = 0 |
|
666 | diffopts.context = 0 | |
667 | width = 80 |
|
667 | width = 80 | |
668 | if not ui.plain(): |
|
668 | if not ui.plain(): | |
669 | width = util.termwidth() |
|
669 | width = util.termwidth() | |
670 | chunks = patch.diff(repo, node1, node2, match, changes, diffopts) |
|
670 | chunks = patch.diff(repo, node1, node2, match, changes, diffopts) | |
671 | for chunk, label in patch.diffstatui(util.iterlines(chunks), |
|
671 | for chunk, label in patch.diffstatui(util.iterlines(chunks), | |
672 | width=width, |
|
672 | width=width, | |
673 | git=diffopts.git): |
|
673 | git=diffopts.git): | |
674 | write(chunk, label=label) |
|
674 | write(chunk, label=label) | |
675 | else: |
|
675 | else: | |
676 | for chunk, label in patch.diffui(repo, node1, node2, match, |
|
676 | for chunk, label in patch.diffui(repo, node1, node2, match, | |
677 | changes, diffopts): |
|
677 | changes, diffopts): | |
678 | write(chunk, label=label) |
|
678 | write(chunk, label=label) | |
679 |
|
679 | |||
680 | class changeset_printer(object): |
|
680 | class changeset_printer(object): | |
681 | '''show changeset information when templating not requested.''' |
|
681 | '''show changeset information when templating not requested.''' | |
682 |
|
682 | |||
683 | def __init__(self, ui, repo, patch, diffopts, buffered): |
|
683 | def __init__(self, ui, repo, patch, diffopts, buffered): | |
684 | self.ui = ui |
|
684 | self.ui = ui | |
685 | self.repo = repo |
|
685 | self.repo = repo | |
686 | self.buffered = buffered |
|
686 | self.buffered = buffered | |
687 | self.patch = patch |
|
687 | self.patch = patch | |
688 | self.diffopts = diffopts |
|
688 | self.diffopts = diffopts | |
689 | self.header = {} |
|
689 | self.header = {} | |
690 | self.hunk = {} |
|
690 | self.hunk = {} | |
691 | self.lastheader = None |
|
691 | self.lastheader = None | |
692 | self.footer = None |
|
692 | self.footer = None | |
693 |
|
693 | |||
694 | def flush(self, rev): |
|
694 | def flush(self, rev): | |
695 | if rev in self.header: |
|
695 | if rev in self.header: | |
696 | h = self.header[rev] |
|
696 | h = self.header[rev] | |
697 | if h != self.lastheader: |
|
697 | if h != self.lastheader: | |
698 | self.lastheader = h |
|
698 | self.lastheader = h | |
699 | self.ui.write(h) |
|
699 | self.ui.write(h) | |
700 | del self.header[rev] |
|
700 | del self.header[rev] | |
701 | if rev in self.hunk: |
|
701 | if rev in self.hunk: | |
702 | self.ui.write(self.hunk[rev]) |
|
702 | self.ui.write(self.hunk[rev]) | |
703 | del self.hunk[rev] |
|
703 | del self.hunk[rev] | |
704 | return 1 |
|
704 | return 1 | |
705 | return 0 |
|
705 | return 0 | |
706 |
|
706 | |||
707 | def close(self): |
|
707 | def close(self): | |
708 | if self.footer: |
|
708 | if self.footer: | |
709 | self.ui.write(self.footer) |
|
709 | self.ui.write(self.footer) | |
710 |
|
710 | |||
711 | def show(self, ctx, copies=None, matchfn=None, **props): |
|
711 | def show(self, ctx, copies=None, matchfn=None, **props): | |
712 | if self.buffered: |
|
712 | if self.buffered: | |
713 | self.ui.pushbuffer() |
|
713 | self.ui.pushbuffer() | |
714 | self._show(ctx, copies, matchfn, props) |
|
714 | self._show(ctx, copies, matchfn, props) | |
715 | self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True) |
|
715 | self.hunk[ctx.rev()] = self.ui.popbuffer(labeled=True) | |
716 | else: |
|
716 | else: | |
717 | self._show(ctx, copies, matchfn, props) |
|
717 | self._show(ctx, copies, matchfn, props) | |
718 |
|
718 | |||
719 | def _show(self, ctx, copies, matchfn, props): |
|
719 | def _show(self, ctx, copies, matchfn, props): | |
720 | '''show a single changeset or file revision''' |
|
720 | '''show a single changeset or file revision''' | |
721 | changenode = ctx.node() |
|
721 | changenode = ctx.node() | |
722 | rev = ctx.rev() |
|
722 | rev = ctx.rev() | |
723 |
|
723 | |||
724 | if self.ui.quiet: |
|
724 | if self.ui.quiet: | |
725 | self.ui.write("%d:%s\n" % (rev, short(changenode)), |
|
725 | self.ui.write("%d:%s\n" % (rev, short(changenode)), | |
726 | label='log.node') |
|
726 | label='log.node') | |
727 | return |
|
727 | return | |
728 |
|
728 | |||
729 | log = self.repo.changelog |
|
729 | log = self.repo.changelog | |
730 | date = util.datestr(ctx.date()) |
|
730 | date = util.datestr(ctx.date()) | |
731 |
|
731 | |||
732 | hexfunc = self.ui.debugflag and hex or short |
|
732 | hexfunc = self.ui.debugflag and hex or short | |
733 |
|
733 | |||
734 | parents = [(p, hexfunc(log.node(p))) |
|
734 | parents = [(p, hexfunc(log.node(p))) | |
735 | for p in self._meaningful_parentrevs(log, rev)] |
|
735 | for p in self._meaningful_parentrevs(log, rev)] | |
736 |
|
736 | |||
737 | self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode)), |
|
737 | self.ui.write(_("changeset: %d:%s\n") % (rev, hexfunc(changenode)), | |
738 | label='log.changeset') |
|
738 | label='log.changeset') | |
739 |
|
739 | |||
740 | branch = ctx.branch() |
|
740 | branch = ctx.branch() | |
741 | # don't show the default branch name |
|
741 | # don't show the default branch name | |
742 | if branch != 'default': |
|
742 | if branch != 'default': | |
743 | branch = encoding.tolocal(branch) |
|
743 | branch = encoding.tolocal(branch) | |
744 | self.ui.write(_("branch: %s\n") % branch, |
|
744 | self.ui.write(_("branch: %s\n") % branch, | |
745 | label='log.branch') |
|
745 | label='log.branch') | |
746 | for tag in self.repo.nodetags(changenode): |
|
746 | for tag in self.repo.nodetags(changenode): | |
747 | self.ui.write(_("tag: %s\n") % tag, |
|
747 | self.ui.write(_("tag: %s\n") % tag, | |
748 | label='log.tag') |
|
748 | label='log.tag') | |
749 | for parent in parents: |
|
749 | for parent in parents: | |
750 | self.ui.write(_("parent: %d:%s\n") % parent, |
|
750 | self.ui.write(_("parent: %d:%s\n") % parent, | |
751 | label='log.parent') |
|
751 | label='log.parent') | |
752 |
|
752 | |||
753 | if self.ui.debugflag: |
|
753 | if self.ui.debugflag: | |
754 | mnode = ctx.manifestnode() |
|
754 | mnode = ctx.manifestnode() | |
755 | self.ui.write(_("manifest: %d:%s\n") % |
|
755 | self.ui.write(_("manifest: %d:%s\n") % | |
756 | (self.repo.manifest.rev(mnode), hex(mnode)), |
|
756 | (self.repo.manifest.rev(mnode), hex(mnode)), | |
757 | label='ui.debug log.manifest') |
|
757 | label='ui.debug log.manifest') | |
758 | self.ui.write(_("user: %s\n") % ctx.user(), |
|
758 | self.ui.write(_("user: %s\n") % ctx.user(), | |
759 | label='log.user') |
|
759 | label='log.user') | |
760 | self.ui.write(_("date: %s\n") % date, |
|
760 | self.ui.write(_("date: %s\n") % date, | |
761 | label='log.date') |
|
761 | label='log.date') | |
762 |
|
762 | |||
763 | if self.ui.debugflag: |
|
763 | if self.ui.debugflag: | |
764 | files = self.repo.status(log.parents(changenode)[0], changenode)[:3] |
|
764 | files = self.repo.status(log.parents(changenode)[0], changenode)[:3] | |
765 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
765 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
766 | files): |
|
766 | files): | |
767 | if value: |
|
767 | if value: | |
768 | self.ui.write("%-12s %s\n" % (key, " ".join(value)), |
|
768 | self.ui.write("%-12s %s\n" % (key, " ".join(value)), | |
769 | label='ui.debug log.files') |
|
769 | label='ui.debug log.files') | |
770 | elif ctx.files() and self.ui.verbose: |
|
770 | elif ctx.files() and self.ui.verbose: | |
771 | self.ui.write(_("files: %s\n") % " ".join(ctx.files()), |
|
771 | self.ui.write(_("files: %s\n") % " ".join(ctx.files()), | |
772 | label='ui.note log.files') |
|
772 | label='ui.note log.files') | |
773 | if copies and self.ui.verbose: |
|
773 | if copies and self.ui.verbose: | |
774 | copies = ['%s (%s)' % c for c in copies] |
|
774 | copies = ['%s (%s)' % c for c in copies] | |
775 | self.ui.write(_("copies: %s\n") % ' '.join(copies), |
|
775 | self.ui.write(_("copies: %s\n") % ' '.join(copies), | |
776 | label='ui.note log.copies') |
|
776 | label='ui.note log.copies') | |
777 |
|
777 | |||
778 | extra = ctx.extra() |
|
778 | extra = ctx.extra() | |
779 | if extra and self.ui.debugflag: |
|
779 | if extra and self.ui.debugflag: | |
780 | for key, value in sorted(extra.items()): |
|
780 | for key, value in sorted(extra.items()): | |
781 | self.ui.write(_("extra: %s=%s\n") |
|
781 | self.ui.write(_("extra: %s=%s\n") | |
782 | % (key, value.encode('string_escape')), |
|
782 | % (key, value.encode('string_escape')), | |
783 | label='ui.debug log.extra') |
|
783 | label='ui.debug log.extra') | |
784 |
|
784 | |||
785 | description = ctx.description().strip() |
|
785 | description = ctx.description().strip() | |
786 | if description: |
|
786 | if description: | |
787 | if self.ui.verbose: |
|
787 | if self.ui.verbose: | |
788 | self.ui.write(_("description:\n"), |
|
788 | self.ui.write(_("description:\n"), | |
789 | label='ui.note log.description') |
|
789 | label='ui.note log.description') | |
790 | self.ui.write(description, |
|
790 | self.ui.write(description, | |
791 | label='ui.note log.description') |
|
791 | label='ui.note log.description') | |
792 | self.ui.write("\n\n") |
|
792 | self.ui.write("\n\n") | |
793 | else: |
|
793 | else: | |
794 | self.ui.write(_("summary: %s\n") % |
|
794 | self.ui.write(_("summary: %s\n") % | |
795 | description.splitlines()[0], |
|
795 | description.splitlines()[0], | |
796 | label='log.summary') |
|
796 | label='log.summary') | |
797 | self.ui.write("\n") |
|
797 | self.ui.write("\n") | |
798 |
|
798 | |||
799 | self.showpatch(changenode, matchfn) |
|
799 | self.showpatch(changenode, matchfn) | |
800 |
|
800 | |||
801 | def showpatch(self, node, matchfn): |
|
801 | def showpatch(self, node, matchfn): | |
802 | if not matchfn: |
|
802 | if not matchfn: | |
803 | matchfn = self.patch |
|
803 | matchfn = self.patch | |
804 | if matchfn: |
|
804 | if matchfn: | |
805 | stat = self.diffopts.get('stat') |
|
805 | stat = self.diffopts.get('stat') | |
806 | diffopts = patch.diffopts(self.ui, self.diffopts) |
|
806 | diffopts = patch.diffopts(self.ui, self.diffopts) | |
807 | prev = self.repo.changelog.parents(node)[0] |
|
807 | prev = self.repo.changelog.parents(node)[0] | |
808 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
|
808 | diffordiffstat(self.ui, self.repo, diffopts, prev, node, | |
809 | match=matchfn, stat=stat) |
|
809 | match=matchfn, stat=stat) | |
810 | self.ui.write("\n") |
|
810 | self.ui.write("\n") | |
811 |
|
811 | |||
812 | def _meaningful_parentrevs(self, log, rev): |
|
812 | def _meaningful_parentrevs(self, log, rev): | |
813 | """Return list of meaningful (or all if debug) parentrevs for rev. |
|
813 | """Return list of meaningful (or all if debug) parentrevs for rev. | |
814 |
|
814 | |||
815 | For merges (two non-nullrev revisions) both parents are meaningful. |
|
815 | For merges (two non-nullrev revisions) both parents are meaningful. | |
816 | Otherwise the first parent revision is considered meaningful if it |
|
816 | Otherwise the first parent revision is considered meaningful if it | |
817 | is not the preceding revision. |
|
817 | is not the preceding revision. | |
818 | """ |
|
818 | """ | |
819 | parents = log.parentrevs(rev) |
|
819 | parents = log.parentrevs(rev) | |
820 | if not self.ui.debugflag and parents[1] == nullrev: |
|
820 | if not self.ui.debugflag and parents[1] == nullrev: | |
821 | if parents[0] >= rev - 1: |
|
821 | if parents[0] >= rev - 1: | |
822 | parents = [] |
|
822 | parents = [] | |
823 | else: |
|
823 | else: | |
824 | parents = [parents[0]] |
|
824 | parents = [parents[0]] | |
825 | return parents |
|
825 | return parents | |
826 |
|
826 | |||
827 |
|
827 | |||
828 | class changeset_templater(changeset_printer): |
|
828 | class changeset_templater(changeset_printer): | |
829 | '''format changeset information.''' |
|
829 | '''format changeset information.''' | |
830 |
|
830 | |||
831 | def __init__(self, ui, repo, patch, diffopts, mapfile, buffered): |
|
831 | def __init__(self, ui, repo, patch, diffopts, mapfile, buffered): | |
832 | changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered) |
|
832 | changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered) | |
833 | formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) |
|
833 | formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) | |
834 | defaulttempl = { |
|
834 | defaulttempl = { | |
835 | 'parent': '{rev}:{node|formatnode} ', |
|
835 | 'parent': '{rev}:{node|formatnode} ', | |
836 | 'manifest': '{rev}:{node|formatnode}', |
|
836 | 'manifest': '{rev}:{node|formatnode}', | |
837 | 'file_copy': '{name} ({source})', |
|
837 | 'file_copy': '{name} ({source})', | |
838 | 'extra': '{key}={value|stringescape}' |
|
838 | 'extra': '{key}={value|stringescape}' | |
839 | } |
|
839 | } | |
840 | # filecopy is preserved for compatibility reasons |
|
840 | # filecopy is preserved for compatibility reasons | |
841 | defaulttempl['filecopy'] = defaulttempl['file_copy'] |
|
841 | defaulttempl['filecopy'] = defaulttempl['file_copy'] | |
842 | self.t = templater.templater(mapfile, {'formatnode': formatnode}, |
|
842 | self.t = templater.templater(mapfile, {'formatnode': formatnode}, | |
843 | cache=defaulttempl) |
|
843 | cache=defaulttempl) | |
844 | self.cache = {} |
|
844 | self.cache = {} | |
845 |
|
845 | |||
846 | def use_template(self, t): |
|
846 | def use_template(self, t): | |
847 | '''set template string to use''' |
|
847 | '''set template string to use''' | |
848 | self.t.cache['changeset'] = t |
|
848 | self.t.cache['changeset'] = t | |
849 |
|
849 | |||
850 | def _meaningful_parentrevs(self, ctx): |
|
850 | def _meaningful_parentrevs(self, ctx): | |
851 | """Return list of meaningful (or all if debug) parentrevs for rev. |
|
851 | """Return list of meaningful (or all if debug) parentrevs for rev. | |
852 | """ |
|
852 | """ | |
853 | parents = ctx.parents() |
|
853 | parents = ctx.parents() | |
854 | if len(parents) > 1: |
|
854 | if len(parents) > 1: | |
855 | return parents |
|
855 | return parents | |
856 | if self.ui.debugflag: |
|
856 | if self.ui.debugflag: | |
857 | return [parents[0], self.repo['null']] |
|
857 | return [parents[0], self.repo['null']] | |
858 | if parents[0].rev() >= ctx.rev() - 1: |
|
858 | if parents[0].rev() >= ctx.rev() - 1: | |
859 | return [] |
|
859 | return [] | |
860 | return parents |
|
860 | return parents | |
861 |
|
861 | |||
862 | def _show(self, ctx, copies, matchfn, props): |
|
862 | def _show(self, ctx, copies, matchfn, props): | |
863 | '''show a single changeset or file revision''' |
|
863 | '''show a single changeset or file revision''' | |
864 |
|
864 | |||
865 | showlist = templatekw.showlist |
|
865 | showlist = templatekw.showlist | |
866 |
|
866 | |||
867 | # showparents() behaviour depends on ui trace level which |
|
867 | # showparents() behaviour depends on ui trace level which | |
868 | # causes unexpected behaviours at templating level and makes |
|
868 | # causes unexpected behaviours at templating level and makes | |
869 | # it harder to extract it in a standalone function. Its |
|
869 | # it harder to extract it in a standalone function. Its | |
870 | # behaviour cannot be changed so leave it here for now. |
|
870 | # behaviour cannot be changed so leave it here for now. | |
871 | def showparents(**args): |
|
871 | def showparents(**args): | |
872 | ctx = args['ctx'] |
|
872 | ctx = args['ctx'] | |
873 | parents = [[('rev', p.rev()), ('node', p.hex())] |
|
873 | parents = [[('rev', p.rev()), ('node', p.hex())] | |
874 | for p in self._meaningful_parentrevs(ctx)] |
|
874 | for p in self._meaningful_parentrevs(ctx)] | |
875 | return showlist('parent', parents, **args) |
|
875 | return showlist('parent', parents, **args) | |
876 |
|
876 | |||
877 | props = props.copy() |
|
877 | props = props.copy() | |
878 | props.update(templatekw.keywords) |
|
878 | props.update(templatekw.keywords) | |
879 | props['parents'] = showparents |
|
879 | props['parents'] = showparents | |
880 | props['templ'] = self.t |
|
880 | props['templ'] = self.t | |
881 | props['ctx'] = ctx |
|
881 | props['ctx'] = ctx | |
882 | props['repo'] = self.repo |
|
882 | props['repo'] = self.repo | |
883 | props['revcache'] = {'copies': copies} |
|
883 | props['revcache'] = {'copies': copies} | |
884 | props['cache'] = self.cache |
|
884 | props['cache'] = self.cache | |
885 |
|
885 | |||
886 | # find correct templates for current mode |
|
886 | # find correct templates for current mode | |
887 |
|
887 | |||
888 | tmplmodes = [ |
|
888 | tmplmodes = [ | |
889 | (True, None), |
|
889 | (True, None), | |
890 | (self.ui.verbose, 'verbose'), |
|
890 | (self.ui.verbose, 'verbose'), | |
891 | (self.ui.quiet, 'quiet'), |
|
891 | (self.ui.quiet, 'quiet'), | |
892 | (self.ui.debugflag, 'debug'), |
|
892 | (self.ui.debugflag, 'debug'), | |
893 | ] |
|
893 | ] | |
894 |
|
894 | |||
895 | types = {'header': '', 'footer':'', 'changeset': 'changeset'} |
|
895 | types = {'header': '', 'footer':'', 'changeset': 'changeset'} | |
896 | for mode, postfix in tmplmodes: |
|
896 | for mode, postfix in tmplmodes: | |
897 | for type in types: |
|
897 | for type in types: | |
898 | cur = postfix and ('%s_%s' % (type, postfix)) or type |
|
898 | cur = postfix and ('%s_%s' % (type, postfix)) or type | |
899 | if mode and cur in self.t: |
|
899 | if mode and cur in self.t: | |
900 | types[type] = cur |
|
900 | types[type] = cur | |
901 |
|
901 | |||
902 | try: |
|
902 | try: | |
903 |
|
903 | |||
904 | # write header |
|
904 | # write header | |
905 | if types['header']: |
|
905 | if types['header']: | |
906 | h = templater.stringify(self.t(types['header'], **props)) |
|
906 | h = templater.stringify(self.t(types['header'], **props)) | |
907 | if self.buffered: |
|
907 | if self.buffered: | |
908 | self.header[ctx.rev()] = h |
|
908 | self.header[ctx.rev()] = h | |
909 | else: |
|
909 | else: | |
910 | if self.lastheader != h: |
|
910 | if self.lastheader != h: | |
911 | self.lastheader = h |
|
911 | self.lastheader = h | |
912 | self.ui.write(h) |
|
912 | self.ui.write(h) | |
913 |
|
913 | |||
914 | # write changeset metadata, then patch if requested |
|
914 | # write changeset metadata, then patch if requested | |
915 | key = types['changeset'] |
|
915 | key = types['changeset'] | |
916 | self.ui.write(templater.stringify(self.t(key, **props))) |
|
916 | self.ui.write(templater.stringify(self.t(key, **props))) | |
917 | self.showpatch(ctx.node(), matchfn) |
|
917 | self.showpatch(ctx.node(), matchfn) | |
918 |
|
918 | |||
919 | if types['footer']: |
|
919 | if types['footer']: | |
920 | if not self.footer: |
|
920 | if not self.footer: | |
921 | self.footer = templater.stringify(self.t(types['footer'], |
|
921 | self.footer = templater.stringify(self.t(types['footer'], | |
922 | **props)) |
|
922 | **props)) | |
923 |
|
923 | |||
924 | except KeyError, inst: |
|
924 | except KeyError, inst: | |
925 | msg = _("%s: no key named '%s'") |
|
925 | msg = _("%s: no key named '%s'") | |
926 | raise util.Abort(msg % (self.t.mapfile, inst.args[0])) |
|
926 | raise util.Abort(msg % (self.t.mapfile, inst.args[0])) | |
927 | except SyntaxError, inst: |
|
927 | except SyntaxError, inst: | |
928 | raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) |
|
928 | raise util.Abort('%s: %s' % (self.t.mapfile, inst.args[0])) | |
929 |
|
929 | |||
930 | def show_changeset(ui, repo, opts, buffered=False): |
|
930 | def show_changeset(ui, repo, opts, buffered=False): | |
931 | """show one changeset using template or regular display. |
|
931 | """show one changeset using template or regular display. | |
932 |
|
932 | |||
933 | Display format will be the first non-empty hit of: |
|
933 | Display format will be the first non-empty hit of: | |
934 | 1. option 'template' |
|
934 | 1. option 'template' | |
935 | 2. option 'style' |
|
935 | 2. option 'style' | |
936 | 3. [ui] setting 'logtemplate' |
|
936 | 3. [ui] setting 'logtemplate' | |
937 | 4. [ui] setting 'style' |
|
937 | 4. [ui] setting 'style' | |
938 | If all of these values are either the unset or the empty string, |
|
938 | If all of these values are either the unset or the empty string, | |
939 | regular display via changeset_printer() is done. |
|
939 | regular display via changeset_printer() is done. | |
940 | """ |
|
940 | """ | |
941 | # options |
|
941 | # options | |
942 | patch = False |
|
942 | patch = False | |
943 | if opts.get('patch') or opts.get('stat'): |
|
943 | if opts.get('patch') or opts.get('stat'): | |
944 | patch = matchall(repo) |
|
944 | patch = matchall(repo) | |
945 |
|
945 | |||
946 | tmpl = opts.get('template') |
|
946 | tmpl = opts.get('template') | |
947 | style = None |
|
947 | style = None | |
948 | if tmpl: |
|
948 | if tmpl: | |
949 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
949 | tmpl = templater.parsestring(tmpl, quoted=False) | |
950 | else: |
|
950 | else: | |
951 | style = opts.get('style') |
|
951 | style = opts.get('style') | |
952 |
|
952 | |||
953 | # ui settings |
|
953 | # ui settings | |
954 | if not (tmpl or style): |
|
954 | if not (tmpl or style): | |
955 | tmpl = ui.config('ui', 'logtemplate') |
|
955 | tmpl = ui.config('ui', 'logtemplate') | |
956 | if tmpl: |
|
956 | if tmpl: | |
957 | tmpl = templater.parsestring(tmpl) |
|
957 | tmpl = templater.parsestring(tmpl) | |
958 | else: |
|
958 | else: | |
959 | style = util.expandpath(ui.config('ui', 'style', '')) |
|
959 | style = util.expandpath(ui.config('ui', 'style', '')) | |
960 |
|
960 | |||
961 | if not (tmpl or style): |
|
961 | if not (tmpl or style): | |
962 | return changeset_printer(ui, repo, patch, opts, buffered) |
|
962 | return changeset_printer(ui, repo, patch, opts, buffered) | |
963 |
|
963 | |||
964 | mapfile = None |
|
964 | mapfile = None | |
965 | if style and not tmpl: |
|
965 | if style and not tmpl: | |
966 | mapfile = style |
|
966 | mapfile = style | |
967 | if not os.path.split(mapfile)[0]: |
|
967 | if not os.path.split(mapfile)[0]: | |
968 | mapname = (templater.templatepath('map-cmdline.' + mapfile) |
|
968 | mapname = (templater.templatepath('map-cmdline.' + mapfile) | |
969 | or templater.templatepath(mapfile)) |
|
969 | or templater.templatepath(mapfile)) | |
970 | if mapname: |
|
970 | if mapname: | |
971 | mapfile = mapname |
|
971 | mapfile = mapname | |
972 |
|
972 | |||
973 | try: |
|
973 | try: | |
974 | t = changeset_templater(ui, repo, patch, opts, mapfile, buffered) |
|
974 | t = changeset_templater(ui, repo, patch, opts, mapfile, buffered) | |
975 | except SyntaxError, inst: |
|
975 | except SyntaxError, inst: | |
976 | raise util.Abort(inst.args[0]) |
|
976 | raise util.Abort(inst.args[0]) | |
977 | if tmpl: |
|
977 | if tmpl: | |
978 | t.use_template(tmpl) |
|
978 | t.use_template(tmpl) | |
979 | return t |
|
979 | return t | |
980 |
|
980 | |||
981 | def finddate(ui, repo, date): |
|
981 | def finddate(ui, repo, date): | |
982 | """Find the tipmost changeset that matches the given date spec""" |
|
982 | """Find the tipmost changeset that matches the given date spec""" | |
983 |
|
983 | |||
984 | df = util.matchdate(date) |
|
984 | df = util.matchdate(date) | |
985 | m = matchall(repo) |
|
985 | m = matchall(repo) | |
986 | results = {} |
|
986 | results = {} | |
987 |
|
987 | |||
988 | def prep(ctx, fns): |
|
988 | def prep(ctx, fns): | |
989 | d = ctx.date() |
|
989 | d = ctx.date() | |
990 | if df(d[0]): |
|
990 | if df(d[0]): | |
991 | results[ctx.rev()] = d |
|
991 | results[ctx.rev()] = d | |
992 |
|
992 | |||
993 | for ctx in walkchangerevs(repo, m, {'rev': None}, prep): |
|
993 | for ctx in walkchangerevs(repo, m, {'rev': None}, prep): | |
994 | rev = ctx.rev() |
|
994 | rev = ctx.rev() | |
995 | if rev in results: |
|
995 | if rev in results: | |
996 | ui.status(_("Found revision %s from %s\n") % |
|
996 | ui.status(_("Found revision %s from %s\n") % | |
997 | (rev, util.datestr(results[rev]))) |
|
997 | (rev, util.datestr(results[rev]))) | |
998 | return str(rev) |
|
998 | return str(rev) | |
999 |
|
999 | |||
1000 | raise util.Abort(_("revision matching date not found")) |
|
1000 | raise util.Abort(_("revision matching date not found")) | |
1001 |
|
1001 | |||
1002 | def walkchangerevs(repo, match, opts, prepare): |
|
1002 | def walkchangerevs(repo, match, opts, prepare): | |
1003 | '''Iterate over files and the revs in which they changed. |
|
1003 | '''Iterate over files and the revs in which they changed. | |
1004 |
|
1004 | |||
1005 | Callers most commonly need to iterate backwards over the history |
|
1005 | Callers most commonly need to iterate backwards over the history | |
1006 | in which they are interested. Doing so has awful (quadratic-looking) |
|
1006 | in which they are interested. Doing so has awful (quadratic-looking) | |
1007 | performance, so we use iterators in a "windowed" way. |
|
1007 | performance, so we use iterators in a "windowed" way. | |
1008 |
|
1008 | |||
1009 | We walk a window of revisions in the desired order. Within the |
|
1009 | We walk a window of revisions in the desired order. Within the | |
1010 | window, we first walk forwards to gather data, then in the desired |
|
1010 | window, we first walk forwards to gather data, then in the desired | |
1011 | order (usually backwards) to display it. |
|
1011 | order (usually backwards) to display it. | |
1012 |
|
1012 | |||
1013 | This function returns an iterator yielding contexts. Before |
|
1013 | This function returns an iterator yielding contexts. Before | |
1014 | yielding each context, the iterator will first call the prepare |
|
1014 | yielding each context, the iterator will first call the prepare | |
1015 | function on each context in the window in forward order.''' |
|
1015 | function on each context in the window in forward order.''' | |
1016 |
|
1016 | |||
1017 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
1017 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
1018 | if start < end: |
|
1018 | if start < end: | |
1019 | while start < end: |
|
1019 | while start < end: | |
1020 | yield start, min(windowsize, end - start) |
|
1020 | yield start, min(windowsize, end - start) | |
1021 | start += windowsize |
|
1021 | start += windowsize | |
1022 | if windowsize < sizelimit: |
|
1022 | if windowsize < sizelimit: | |
1023 | windowsize *= 2 |
|
1023 | windowsize *= 2 | |
1024 | else: |
|
1024 | else: | |
1025 | while start > end: |
|
1025 | while start > end: | |
1026 | yield start, min(windowsize, start - end - 1) |
|
1026 | yield start, min(windowsize, start - end - 1) | |
1027 | start -= windowsize |
|
1027 | start -= windowsize | |
1028 | if windowsize < sizelimit: |
|
1028 | if windowsize < sizelimit: | |
1029 | windowsize *= 2 |
|
1029 | windowsize *= 2 | |
1030 |
|
1030 | |||
1031 | follow = opts.get('follow') or opts.get('follow_first') |
|
1031 | follow = opts.get('follow') or opts.get('follow_first') | |
1032 |
|
1032 | |||
1033 | if not len(repo): |
|
1033 | if not len(repo): | |
1034 | return [] |
|
1034 | return [] | |
1035 |
|
1035 | |||
1036 | if follow: |
|
1036 | if follow: | |
1037 | defrange = '%s:0' % repo['.'].rev() |
|
1037 | defrange = '%s:0' % repo['.'].rev() | |
1038 | else: |
|
1038 | else: | |
1039 | defrange = '-1:0' |
|
1039 | defrange = '-1:0' | |
1040 | revs = revrange(repo, opts['rev'] or [defrange]) |
|
1040 | revs = revrange(repo, opts['rev'] or [defrange]) | |
1041 | if not revs: |
|
1041 | if not revs: | |
1042 | return [] |
|
1042 | return [] | |
1043 | wanted = set() |
|
1043 | wanted = set() | |
1044 | slowpath = match.anypats() or (match.files() and opts.get('removed')) |
|
1044 | slowpath = match.anypats() or (match.files() and opts.get('removed')) | |
1045 | fncache = {} |
|
1045 | fncache = {} | |
1046 | change = util.cachefunc(repo.changectx) |
|
1046 | change = util.cachefunc(repo.changectx) | |
1047 |
|
1047 | |||
1048 | if not slowpath and not match.files(): |
|
1048 | if not slowpath and not match.files(): | |
1049 | # No files, no patterns. Display all revs. |
|
1049 | # No files, no patterns. Display all revs. | |
1050 | wanted = set(revs) |
|
1050 | wanted = set(revs) | |
1051 | copies = [] |
|
1051 | copies = [] | |
1052 |
|
1052 | |||
1053 | if not slowpath: |
|
1053 | if not slowpath: | |
1054 | minrev, maxrev = min(revs), max(revs) |
|
1054 | minrev, maxrev = min(revs), max(revs) | |
1055 | # Only files, no patterns. Check the history of each file. |
|
1055 | # Only files, no patterns. Check the history of each file. | |
1056 | def filerevgen(filelog, last): |
|
1056 | def filerevgen(filelog, last): | |
1057 | cl_count = len(repo) |
|
1057 | cl_count = len(repo) | |
1058 | revs = [] |
|
1058 | revs = [] | |
1059 | for j in xrange(0, last+1): |
|
1059 | for j in xrange(0, last+1): | |
1060 | linkrev = filelog.linkrev(j) |
|
1060 | linkrev = filelog.linkrev(j) | |
1061 | if linkrev < minrev: |
|
1061 | if linkrev < minrev: | |
1062 | continue |
|
1062 | continue | |
1063 | # only yield rev for which we have the changelog, it can |
|
1063 | # only yield rev for which we have the changelog, it can | |
1064 | # happen while doing "hg log" during a pull or commit |
|
1064 | # happen while doing "hg log" during a pull or commit | |
1065 | if linkrev > maxrev or linkrev >= cl_count: |
|
1065 | if linkrev > maxrev or linkrev >= cl_count: | |
1066 | break |
|
1066 | break | |
1067 | n = filelog.node(j) |
|
1067 | n = filelog.node(j) | |
1068 | revs.append((filelog.linkrev(j), |
|
1068 | revs.append((filelog.linkrev(j), | |
1069 | follow and filelog.renamed(n))) |
|
1069 | follow and filelog.renamed(n))) | |
1070 |
|
1070 | |||
1071 | for rev in reversed(revs): |
|
1071 | for rev in reversed(revs): | |
1072 | yield rev |
|
1072 | yield rev | |
1073 | def iterfiles(): |
|
1073 | def iterfiles(): | |
1074 | for filename in match.files(): |
|
1074 | for filename in match.files(): | |
1075 | yield filename, None |
|
1075 | yield filename, None | |
1076 | for filename_node in copies: |
|
1076 | for filename_node in copies: | |
1077 | yield filename_node |
|
1077 | yield filename_node | |
1078 | for file_, node in iterfiles(): |
|
1078 | for file_, node in iterfiles(): | |
1079 | filelog = repo.file(file_) |
|
1079 | filelog = repo.file(file_) | |
1080 | if not len(filelog): |
|
1080 | if not len(filelog): | |
1081 | if node is None: |
|
1081 | if node is None: | |
1082 | # A zero count may be a directory or deleted file, so |
|
1082 | # A zero count may be a directory or deleted file, so | |
1083 | # try to find matching entries on the slow path. |
|
1083 | # try to find matching entries on the slow path. | |
1084 | if follow: |
|
1084 | if follow: | |
1085 | raise util.Abort( |
|
1085 | raise util.Abort( | |
1086 | _('cannot follow nonexistent file: "%s"') % file_) |
|
1086 | _('cannot follow nonexistent file: "%s"') % file_) | |
1087 | slowpath = True |
|
1087 | slowpath = True | |
1088 | break |
|
1088 | break | |
1089 | else: |
|
1089 | else: | |
1090 | continue |
|
1090 | continue | |
1091 |
|
1091 | |||
1092 | if node is None: |
|
1092 | if node is None: | |
1093 | last = len(filelog) - 1 |
|
1093 | last = len(filelog) - 1 | |
1094 | else: |
|
1094 | else: | |
1095 | last = filelog.rev(node) |
|
1095 | last = filelog.rev(node) | |
1096 |
|
1096 | |||
1097 | for rev, copied in filerevgen(filelog, last): |
|
1097 | for rev, copied in filerevgen(filelog, last): | |
1098 | fncache.setdefault(rev, []) |
|
1098 | fncache.setdefault(rev, []) | |
1099 | fncache[rev].append(file_) |
|
1099 | fncache[rev].append(file_) | |
1100 | wanted.add(rev) |
|
1100 | wanted.add(rev) | |
1101 | if copied: |
|
1101 | if copied: | |
1102 | copies.append(copied) |
|
1102 | copies.append(copied) | |
1103 | if slowpath: |
|
1103 | if slowpath: | |
1104 | if follow: |
|
1104 | if follow: | |
1105 | raise util.Abort(_('can only follow copies/renames for explicit ' |
|
1105 | raise util.Abort(_('can only follow copies/renames for explicit ' | |
1106 | 'filenames')) |
|
1106 | 'filenames')) | |
1107 |
|
1107 | |||
1108 | # The slow path checks files modified in every changeset. |
|
1108 | # The slow path checks files modified in every changeset. | |
1109 |
|
|
1109 | if opts.get('removed'): | |
1110 | for i, window in increasing_windows(len(repo) - 1, nullrev): |
|
1110 | # --removed wants to yield the changes where the file | |
1111 | for j in xrange(i - window, i + 1): |
|
1111 | # was removed, this means that we have to explore all | |
1112 | yield change(j) |
|
1112 | # changesets, effectively ignoring the revisions that | |
1113 |
|
1113 | # had been passed as arguments | ||
1114 | for ctx in changerevgen(): |
|
1114 | revrange = xrange(nullrev, len(repo) - 1) | |
|
1115 | else: | |||
|
1116 | revrange = sorted(revs) | |||
|
1117 | for i in revrange: | |||
|
1118 | ctx = change(i) | |||
1115 | matches = filter(match, ctx.files()) |
|
1119 | matches = filter(match, ctx.files()) | |
1116 | if matches: |
|
1120 | if matches: | |
1117 |
fncache[ |
|
1121 | fncache[i] = matches | |
1118 |
wanted.add( |
|
1122 | wanted.add(i) | |
1119 |
|
1123 | |||
1120 | class followfilter(object): |
|
1124 | class followfilter(object): | |
1121 | def __init__(self, onlyfirst=False): |
|
1125 | def __init__(self, onlyfirst=False): | |
1122 | self.startrev = nullrev |
|
1126 | self.startrev = nullrev | |
1123 | self.roots = set() |
|
1127 | self.roots = set() | |
1124 | self.onlyfirst = onlyfirst |
|
1128 | self.onlyfirst = onlyfirst | |
1125 |
|
1129 | |||
1126 | def match(self, rev): |
|
1130 | def match(self, rev): | |
1127 | def realparents(rev): |
|
1131 | def realparents(rev): | |
1128 | if self.onlyfirst: |
|
1132 | if self.onlyfirst: | |
1129 | return repo.changelog.parentrevs(rev)[0:1] |
|
1133 | return repo.changelog.parentrevs(rev)[0:1] | |
1130 | else: |
|
1134 | else: | |
1131 | return filter(lambda x: x != nullrev, |
|
1135 | return filter(lambda x: x != nullrev, | |
1132 | repo.changelog.parentrevs(rev)) |
|
1136 | repo.changelog.parentrevs(rev)) | |
1133 |
|
1137 | |||
1134 | if self.startrev == nullrev: |
|
1138 | if self.startrev == nullrev: | |
1135 | self.startrev = rev |
|
1139 | self.startrev = rev | |
1136 | return True |
|
1140 | return True | |
1137 |
|
1141 | |||
1138 | if rev > self.startrev: |
|
1142 | if rev > self.startrev: | |
1139 | # forward: all descendants |
|
1143 | # forward: all descendants | |
1140 | if not self.roots: |
|
1144 | if not self.roots: | |
1141 | self.roots.add(self.startrev) |
|
1145 | self.roots.add(self.startrev) | |
1142 | for parent in realparents(rev): |
|
1146 | for parent in realparents(rev): | |
1143 | if parent in self.roots: |
|
1147 | if parent in self.roots: | |
1144 | self.roots.add(rev) |
|
1148 | self.roots.add(rev) | |
1145 | return True |
|
1149 | return True | |
1146 | else: |
|
1150 | else: | |
1147 | # backwards: all parents |
|
1151 | # backwards: all parents | |
1148 | if not self.roots: |
|
1152 | if not self.roots: | |
1149 | self.roots.update(realparents(self.startrev)) |
|
1153 | self.roots.update(realparents(self.startrev)) | |
1150 | if rev in self.roots: |
|
1154 | if rev in self.roots: | |
1151 | self.roots.remove(rev) |
|
1155 | self.roots.remove(rev) | |
1152 | self.roots.update(realparents(rev)) |
|
1156 | self.roots.update(realparents(rev)) | |
1153 | return True |
|
1157 | return True | |
1154 |
|
1158 | |||
1155 | return False |
|
1159 | return False | |
1156 |
|
1160 | |||
1157 | # it might be worthwhile to do this in the iterator if the rev range |
|
1161 | # it might be worthwhile to do this in the iterator if the rev range | |
1158 | # is descending and the prune args are all within that range |
|
1162 | # is descending and the prune args are all within that range | |
1159 | for rev in opts.get('prune', ()): |
|
1163 | for rev in opts.get('prune', ()): | |
1160 | rev = repo.changelog.rev(repo.lookup(rev)) |
|
1164 | rev = repo.changelog.rev(repo.lookup(rev)) | |
1161 | ff = followfilter() |
|
1165 | ff = followfilter() | |
1162 | stop = min(revs[0], revs[-1]) |
|
1166 | stop = min(revs[0], revs[-1]) | |
1163 | for x in xrange(rev, stop - 1, -1): |
|
1167 | for x in xrange(rev, stop - 1, -1): | |
1164 | if ff.match(x): |
|
1168 | if ff.match(x): | |
1165 | wanted.discard(x) |
|
1169 | wanted.discard(x) | |
1166 |
|
1170 | |||
1167 | def iterate(): |
|
1171 | def iterate(): | |
1168 | if follow and not match.files(): |
|
1172 | if follow and not match.files(): | |
1169 | ff = followfilter(onlyfirst=opts.get('follow_first')) |
|
1173 | ff = followfilter(onlyfirst=opts.get('follow_first')) | |
1170 | def want(rev): |
|
1174 | def want(rev): | |
1171 | return ff.match(rev) and rev in wanted |
|
1175 | return ff.match(rev) and rev in wanted | |
1172 | else: |
|
1176 | else: | |
1173 | def want(rev): |
|
1177 | def want(rev): | |
1174 | return rev in wanted |
|
1178 | return rev in wanted | |
1175 |
|
1179 | |||
1176 | for i, window in increasing_windows(0, len(revs)): |
|
1180 | for i, window in increasing_windows(0, len(revs)): | |
1177 | change = util.cachefunc(repo.changectx) |
|
1181 | change = util.cachefunc(repo.changectx) | |
1178 | nrevs = [rev for rev in revs[i:i + window] if want(rev)] |
|
1182 | nrevs = [rev for rev in revs[i:i + window] if want(rev)] | |
1179 | for rev in sorted(nrevs): |
|
1183 | for rev in sorted(nrevs): | |
1180 | fns = fncache.get(rev) |
|
1184 | fns = fncache.get(rev) | |
1181 | ctx = change(rev) |
|
1185 | ctx = change(rev) | |
1182 | if not fns: |
|
1186 | if not fns: | |
1183 | def fns_generator(): |
|
1187 | def fns_generator(): | |
1184 | for f in ctx.files(): |
|
1188 | for f in ctx.files(): | |
1185 | if match(f): |
|
1189 | if match(f): | |
1186 | yield f |
|
1190 | yield f | |
1187 | fns = fns_generator() |
|
1191 | fns = fns_generator() | |
1188 | prepare(ctx, fns) |
|
1192 | prepare(ctx, fns) | |
1189 | for rev in nrevs: |
|
1193 | for rev in nrevs: | |
1190 | yield change(rev) |
|
1194 | yield change(rev) | |
1191 | return iterate() |
|
1195 | return iterate() | |
1192 |
|
1196 | |||
1193 | def commit(ui, repo, commitfunc, pats, opts): |
|
1197 | def commit(ui, repo, commitfunc, pats, opts): | |
1194 | '''commit the specified files or all outstanding changes''' |
|
1198 | '''commit the specified files or all outstanding changes''' | |
1195 | date = opts.get('date') |
|
1199 | date = opts.get('date') | |
1196 | if date: |
|
1200 | if date: | |
1197 | opts['date'] = util.parsedate(date) |
|
1201 | opts['date'] = util.parsedate(date) | |
1198 | message = logmessage(opts) |
|
1202 | message = logmessage(opts) | |
1199 |
|
1203 | |||
1200 | # extract addremove carefully -- this function can be called from a command |
|
1204 | # extract addremove carefully -- this function can be called from a command | |
1201 | # that doesn't support addremove |
|
1205 | # that doesn't support addremove | |
1202 | if opts.get('addremove'): |
|
1206 | if opts.get('addremove'): | |
1203 | addremove(repo, pats, opts) |
|
1207 | addremove(repo, pats, opts) | |
1204 |
|
1208 | |||
1205 | return commitfunc(ui, repo, message, match(repo, pats, opts), opts) |
|
1209 | return commitfunc(ui, repo, message, match(repo, pats, opts), opts) | |
1206 |
|
1210 | |||
1207 | def commiteditor(repo, ctx, subs): |
|
1211 | def commiteditor(repo, ctx, subs): | |
1208 | if ctx.description(): |
|
1212 | if ctx.description(): | |
1209 | return ctx.description() |
|
1213 | return ctx.description() | |
1210 | return commitforceeditor(repo, ctx, subs) |
|
1214 | return commitforceeditor(repo, ctx, subs) | |
1211 |
|
1215 | |||
1212 | def commitforceeditor(repo, ctx, subs): |
|
1216 | def commitforceeditor(repo, ctx, subs): | |
1213 | edittext = [] |
|
1217 | edittext = [] | |
1214 | modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() |
|
1218 | modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() | |
1215 | if ctx.description(): |
|
1219 | if ctx.description(): | |
1216 | edittext.append(ctx.description()) |
|
1220 | edittext.append(ctx.description()) | |
1217 | edittext.append("") |
|
1221 | edittext.append("") | |
1218 | edittext.append("") # Empty line between message and comments. |
|
1222 | edittext.append("") # Empty line between message and comments. | |
1219 | edittext.append(_("HG: Enter commit message." |
|
1223 | edittext.append(_("HG: Enter commit message." | |
1220 | " Lines beginning with 'HG:' are removed.")) |
|
1224 | " Lines beginning with 'HG:' are removed.")) | |
1221 | edittext.append(_("HG: Leave message empty to abort commit.")) |
|
1225 | edittext.append(_("HG: Leave message empty to abort commit.")) | |
1222 | edittext.append("HG: --") |
|
1226 | edittext.append("HG: --") | |
1223 | edittext.append(_("HG: user: %s") % ctx.user()) |
|
1227 | edittext.append(_("HG: user: %s") % ctx.user()) | |
1224 | if ctx.p2(): |
|
1228 | if ctx.p2(): | |
1225 | edittext.append(_("HG: branch merge")) |
|
1229 | edittext.append(_("HG: branch merge")) | |
1226 | if ctx.branch(): |
|
1230 | if ctx.branch(): | |
1227 | edittext.append(_("HG: branch '%s'") |
|
1231 | edittext.append(_("HG: branch '%s'") | |
1228 | % encoding.tolocal(ctx.branch())) |
|
1232 | % encoding.tolocal(ctx.branch())) | |
1229 | edittext.extend([_("HG: subrepo %s") % s for s in subs]) |
|
1233 | edittext.extend([_("HG: subrepo %s") % s for s in subs]) | |
1230 | edittext.extend([_("HG: added %s") % f for f in added]) |
|
1234 | edittext.extend([_("HG: added %s") % f for f in added]) | |
1231 | edittext.extend([_("HG: changed %s") % f for f in modified]) |
|
1235 | edittext.extend([_("HG: changed %s") % f for f in modified]) | |
1232 | edittext.extend([_("HG: removed %s") % f for f in removed]) |
|
1236 | edittext.extend([_("HG: removed %s") % f for f in removed]) | |
1233 | if not added and not modified and not removed: |
|
1237 | if not added and not modified and not removed: | |
1234 | edittext.append(_("HG: no files changed")) |
|
1238 | edittext.append(_("HG: no files changed")) | |
1235 | edittext.append("") |
|
1239 | edittext.append("") | |
1236 | # run editor in the repository root |
|
1240 | # run editor in the repository root | |
1237 | olddir = os.getcwd() |
|
1241 | olddir = os.getcwd() | |
1238 | os.chdir(repo.root) |
|
1242 | os.chdir(repo.root) | |
1239 | text = repo.ui.edit("\n".join(edittext), ctx.user()) |
|
1243 | text = repo.ui.edit("\n".join(edittext), ctx.user()) | |
1240 | text = re.sub("(?m)^HG:.*\n", "", text) |
|
1244 | text = re.sub("(?m)^HG:.*\n", "", text) | |
1241 | os.chdir(olddir) |
|
1245 | os.chdir(olddir) | |
1242 |
|
1246 | |||
1243 | if not text.strip(): |
|
1247 | if not text.strip(): | |
1244 | raise util.Abort(_("empty commit message")) |
|
1248 | raise util.Abort(_("empty commit message")) | |
1245 |
|
1249 | |||
1246 | return text |
|
1250 | return text |
General Comments 0
You need to be logged in to leave comments.
Login now