Show More
@@ -1,3242 +1,3249 | |||||
1 | # commands.py - command processing for mercurial |
|
1 | # commands.py - command processing for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from demandload import demandload |
|
8 | from demandload import demandload | |
9 | from node import * |
|
9 | from node import * | |
10 | from i18n import gettext as _ |
|
10 | from i18n import gettext as _ | |
11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") |
|
11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") | |
12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") |
|
12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") | |
13 | demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time") |
|
13 | demandload(globals(), "fnmatch hgweb mdiff random signal tempfile time") | |
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") |
|
14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") | |
15 |
|
15 | |||
16 | class UnknownCommand(Exception): |
|
16 | class UnknownCommand(Exception): | |
17 | """Exception raised if command is not in the command table.""" |
|
17 | """Exception raised if command is not in the command table.""" | |
18 | class AmbiguousCommand(Exception): |
|
18 | class AmbiguousCommand(Exception): | |
19 | """Exception raised if command shortcut matches more than one command.""" |
|
19 | """Exception raised if command shortcut matches more than one command.""" | |
20 |
|
20 | |||
21 | def filterfiles(filters, files): |
|
21 | def filterfiles(filters, files): | |
22 | l = [x for x in files if x in filters] |
|
22 | l = [x for x in files if x in filters] | |
23 |
|
23 | |||
24 | for t in filters: |
|
24 | for t in filters: | |
25 | if t and t[-1] != "/": |
|
25 | if t and t[-1] != "/": | |
26 | t += "/" |
|
26 | t += "/" | |
27 | l += [x for x in files if x.startswith(t)] |
|
27 | l += [x for x in files if x.startswith(t)] | |
28 | return l |
|
28 | return l | |
29 |
|
29 | |||
30 | def relpath(repo, args): |
|
30 | def relpath(repo, args): | |
31 | cwd = repo.getcwd() |
|
31 | cwd = repo.getcwd() | |
32 | if cwd: |
|
32 | if cwd: | |
33 | return [util.normpath(os.path.join(cwd, x)) for x in args] |
|
33 | return [util.normpath(os.path.join(cwd, x)) for x in args] | |
34 | return args |
|
34 | return args | |
35 |
|
35 | |||
36 | def matchpats(repo, pats=[], opts={}, head=''): |
|
36 | def matchpats(repo, pats=[], opts={}, head=''): | |
37 | cwd = repo.getcwd() |
|
37 | cwd = repo.getcwd() | |
38 | if not pats and cwd: |
|
38 | if not pats and cwd: | |
39 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
|
39 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
40 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
|
40 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
41 | cwd = '' |
|
41 | cwd = '' | |
42 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
42 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | |
43 | opts.get('exclude'), head) |
|
43 | opts.get('exclude'), head) | |
44 |
|
44 | |||
45 | def makewalk(repo, pats, opts, node=None, head=''): |
|
45 | def makewalk(repo, pats, opts, node=None, head=''): | |
46 | files, matchfn, anypats = matchpats(repo, pats, opts, head) |
|
46 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | |
47 | exact = dict(zip(files, files)) |
|
47 | exact = dict(zip(files, files)) | |
48 | def walk(): |
|
48 | def walk(): | |
49 | for src, fn in repo.walk(node=node, files=files, match=matchfn): |
|
49 | for src, fn in repo.walk(node=node, files=files, match=matchfn): | |
50 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
50 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
51 | return files, matchfn, walk() |
|
51 | return files, matchfn, walk() | |
52 |
|
52 | |||
53 | def walk(repo, pats, opts, node=None, head=''): |
|
53 | def walk(repo, pats, opts, node=None, head=''): | |
54 | files, matchfn, results = makewalk(repo, pats, opts, node, head) |
|
54 | files, matchfn, results = makewalk(repo, pats, opts, node, head) | |
55 | for r in results: |
|
55 | for r in results: | |
56 | yield r |
|
56 | yield r | |
57 |
|
57 | |||
58 | def walkchangerevs(ui, repo, pats, opts): |
|
58 | def walkchangerevs(ui, repo, pats, opts): | |
59 | '''Iterate over files and the revs they changed in. |
|
59 | '''Iterate over files and the revs they changed in. | |
60 |
|
60 | |||
61 | Callers most commonly need to iterate backwards over the history |
|
61 | Callers most commonly need to iterate backwards over the history | |
62 | it is interested in. Doing so has awful (quadratic-looking) |
|
62 | it is interested in. Doing so has awful (quadratic-looking) | |
63 | performance, so we use iterators in a "windowed" way. |
|
63 | performance, so we use iterators in a "windowed" way. | |
64 |
|
64 | |||
65 | We walk a window of revisions in the desired order. Within the |
|
65 | We walk a window of revisions in the desired order. Within the | |
66 | window, we first walk forwards to gather data, then in the desired |
|
66 | window, we first walk forwards to gather data, then in the desired | |
67 | order (usually backwards) to display it. |
|
67 | order (usually backwards) to display it. | |
68 |
|
68 | |||
69 | This function returns an (iterator, getchange, matchfn) tuple. The |
|
69 | This function returns an (iterator, getchange, matchfn) tuple. The | |
70 | getchange function returns the changelog entry for a numeric |
|
70 | getchange function returns the changelog entry for a numeric | |
71 | revision. The iterator yields 3-tuples. They will be of one of |
|
71 | revision. The iterator yields 3-tuples. They will be of one of | |
72 | the following forms: |
|
72 | the following forms: | |
73 |
|
73 | |||
74 | "window", incrementing, lastrev: stepping through a window, |
|
74 | "window", incrementing, lastrev: stepping through a window, | |
75 | positive if walking forwards through revs, last rev in the |
|
75 | positive if walking forwards through revs, last rev in the | |
76 | sequence iterated over - use to reset state for the current window |
|
76 | sequence iterated over - use to reset state for the current window | |
77 |
|
77 | |||
78 | "add", rev, fns: out-of-order traversal of the given file names |
|
78 | "add", rev, fns: out-of-order traversal of the given file names | |
79 | fns, which changed during revision rev - use to gather data for |
|
79 | fns, which changed during revision rev - use to gather data for | |
80 | possible display |
|
80 | possible display | |
81 |
|
81 | |||
82 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
82 | "iter", rev, None: in-order traversal of the revs earlier iterated | |
83 | over with "add" - use to display data''' |
|
83 | over with "add" - use to display data''' | |
84 |
|
84 | |||
85 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
85 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
86 | if start < end: |
|
86 | if start < end: | |
87 | while start < end: |
|
87 | while start < end: | |
88 | yield start, min(windowsize, end-start) |
|
88 | yield start, min(windowsize, end-start) | |
89 | start += windowsize |
|
89 | start += windowsize | |
90 | if windowsize < sizelimit: |
|
90 | if windowsize < sizelimit: | |
91 | windowsize *= 2 |
|
91 | windowsize *= 2 | |
92 | else: |
|
92 | else: | |
93 | while start > end: |
|
93 | while start > end: | |
94 | yield start, min(windowsize, start-end-1) |
|
94 | yield start, min(windowsize, start-end-1) | |
95 | start -= windowsize |
|
95 | start -= windowsize | |
96 | if windowsize < sizelimit: |
|
96 | if windowsize < sizelimit: | |
97 | windowsize *= 2 |
|
97 | windowsize *= 2 | |
98 |
|
98 | |||
99 |
|
99 | |||
100 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
100 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
101 |
|
101 | |||
102 | if repo.changelog.count() == 0: |
|
102 | if repo.changelog.count() == 0: | |
103 | return [], False, matchfn |
|
103 | return [], False, matchfn | |
104 |
|
104 | |||
105 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
|
105 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | |
106 | wanted = {} |
|
106 | wanted = {} | |
107 | slowpath = anypats |
|
107 | slowpath = anypats | |
108 | fncache = {} |
|
108 | fncache = {} | |
109 |
|
109 | |||
110 | chcache = {} |
|
110 | chcache = {} | |
111 | def getchange(rev): |
|
111 | def getchange(rev): | |
112 | ch = chcache.get(rev) |
|
112 | ch = chcache.get(rev) | |
113 | if ch is None: |
|
113 | if ch is None: | |
114 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) |
|
114 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) | |
115 | return ch |
|
115 | return ch | |
116 |
|
116 | |||
117 | if not slowpath and not files: |
|
117 | if not slowpath and not files: | |
118 | # No files, no patterns. Display all revs. |
|
118 | # No files, no patterns. Display all revs. | |
119 | wanted = dict(zip(revs, revs)) |
|
119 | wanted = dict(zip(revs, revs)) | |
120 | if not slowpath: |
|
120 | if not slowpath: | |
121 | # Only files, no patterns. Check the history of each file. |
|
121 | # Only files, no patterns. Check the history of each file. | |
122 | def filerevgen(filelog): |
|
122 | def filerevgen(filelog): | |
123 | for i, window in increasing_windows(filelog.count()-1, -1): |
|
123 | for i, window in increasing_windows(filelog.count()-1, -1): | |
124 | revs = [] |
|
124 | revs = [] | |
125 | for j in xrange(i - window, i + 1): |
|
125 | for j in xrange(i - window, i + 1): | |
126 | revs.append(filelog.linkrev(filelog.node(j))) |
|
126 | revs.append(filelog.linkrev(filelog.node(j))) | |
127 | revs.reverse() |
|
127 | revs.reverse() | |
128 | for rev in revs: |
|
128 | for rev in revs: | |
129 | yield rev |
|
129 | yield rev | |
130 |
|
130 | |||
131 | minrev, maxrev = min(revs), max(revs) |
|
131 | minrev, maxrev = min(revs), max(revs) | |
132 | for file_ in files: |
|
132 | for file_ in files: | |
133 | filelog = repo.file(file_) |
|
133 | filelog = repo.file(file_) | |
134 | # A zero count may be a directory or deleted file, so |
|
134 | # A zero count may be a directory or deleted file, so | |
135 | # try to find matching entries on the slow path. |
|
135 | # try to find matching entries on the slow path. | |
136 | if filelog.count() == 0: |
|
136 | if filelog.count() == 0: | |
137 | slowpath = True |
|
137 | slowpath = True | |
138 | break |
|
138 | break | |
139 | for rev in filerevgen(filelog): |
|
139 | for rev in filerevgen(filelog): | |
140 | if rev <= maxrev: |
|
140 | if rev <= maxrev: | |
141 | if rev < minrev: |
|
141 | if rev < minrev: | |
142 | break |
|
142 | break | |
143 | fncache.setdefault(rev, []) |
|
143 | fncache.setdefault(rev, []) | |
144 | fncache[rev].append(file_) |
|
144 | fncache[rev].append(file_) | |
145 | wanted[rev] = 1 |
|
145 | wanted[rev] = 1 | |
146 | if slowpath: |
|
146 | if slowpath: | |
147 | # The slow path checks files modified in every changeset. |
|
147 | # The slow path checks files modified in every changeset. | |
148 | def changerevgen(): |
|
148 | def changerevgen(): | |
149 | for i, window in increasing_windows(repo.changelog.count()-1, -1): |
|
149 | for i, window in increasing_windows(repo.changelog.count()-1, -1): | |
150 | for j in xrange(i - window, i + 1): |
|
150 | for j in xrange(i - window, i + 1): | |
151 | yield j, getchange(j)[3] |
|
151 | yield j, getchange(j)[3] | |
152 |
|
152 | |||
153 | for rev, changefiles in changerevgen(): |
|
153 | for rev, changefiles in changerevgen(): | |
154 | matches = filter(matchfn, changefiles) |
|
154 | matches = filter(matchfn, changefiles) | |
155 | if matches: |
|
155 | if matches: | |
156 | fncache[rev] = matches |
|
156 | fncache[rev] = matches | |
157 | wanted[rev] = 1 |
|
157 | wanted[rev] = 1 | |
158 |
|
158 | |||
159 | def iterate(): |
|
159 | def iterate(): | |
160 | for i, window in increasing_windows(0, len(revs)): |
|
160 | for i, window in increasing_windows(0, len(revs)): | |
161 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
161 | yield 'window', revs[0] < revs[-1], revs[-1] | |
162 | nrevs = [rev for rev in revs[i:i+window] |
|
162 | nrevs = [rev for rev in revs[i:i+window] | |
163 | if rev in wanted] |
|
163 | if rev in wanted] | |
164 | srevs = list(nrevs) |
|
164 | srevs = list(nrevs) | |
165 | srevs.sort() |
|
165 | srevs.sort() | |
166 | for rev in srevs: |
|
166 | for rev in srevs: | |
167 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) |
|
167 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) | |
168 | yield 'add', rev, fns |
|
168 | yield 'add', rev, fns | |
169 | for rev in nrevs: |
|
169 | for rev in nrevs: | |
170 | yield 'iter', rev, None |
|
170 | yield 'iter', rev, None | |
171 | return iterate(), getchange, matchfn |
|
171 | return iterate(), getchange, matchfn | |
172 |
|
172 | |||
173 | revrangesep = ':' |
|
173 | revrangesep = ':' | |
174 |
|
174 | |||
175 | def revrange(ui, repo, revs, revlog=None): |
|
175 | def revrange(ui, repo, revs, revlog=None): | |
176 | """Yield revision as strings from a list of revision specifications.""" |
|
176 | """Yield revision as strings from a list of revision specifications.""" | |
177 | if revlog is None: |
|
177 | if revlog is None: | |
178 | revlog = repo.changelog |
|
178 | revlog = repo.changelog | |
179 | revcount = revlog.count() |
|
179 | revcount = revlog.count() | |
180 | def fix(val, defval): |
|
180 | def fix(val, defval): | |
181 | if not val: |
|
181 | if not val: | |
182 | return defval |
|
182 | return defval | |
183 | try: |
|
183 | try: | |
184 | num = int(val) |
|
184 | num = int(val) | |
185 | if str(num) != val: |
|
185 | if str(num) != val: | |
186 | raise ValueError |
|
186 | raise ValueError | |
187 | if num < 0: |
|
187 | if num < 0: | |
188 | num += revcount |
|
188 | num += revcount | |
189 | if num < 0: |
|
189 | if num < 0: | |
190 | num = 0 |
|
190 | num = 0 | |
191 | elif num >= revcount: |
|
191 | elif num >= revcount: | |
192 | raise ValueError |
|
192 | raise ValueError | |
193 | except ValueError: |
|
193 | except ValueError: | |
194 | try: |
|
194 | try: | |
195 | num = repo.changelog.rev(repo.lookup(val)) |
|
195 | num = repo.changelog.rev(repo.lookup(val)) | |
196 | except KeyError: |
|
196 | except KeyError: | |
197 | try: |
|
197 | try: | |
198 | num = revlog.rev(revlog.lookup(val)) |
|
198 | num = revlog.rev(revlog.lookup(val)) | |
199 | except KeyError: |
|
199 | except KeyError: | |
200 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
200 | raise util.Abort(_('invalid revision identifier %s'), val) | |
201 | return num |
|
201 | return num | |
202 | seen = {} |
|
202 | seen = {} | |
203 | for spec in revs: |
|
203 | for spec in revs: | |
204 | if spec.find(revrangesep) >= 0: |
|
204 | if spec.find(revrangesep) >= 0: | |
205 | start, end = spec.split(revrangesep, 1) |
|
205 | start, end = spec.split(revrangesep, 1) | |
206 | start = fix(start, 0) |
|
206 | start = fix(start, 0) | |
207 | end = fix(end, revcount - 1) |
|
207 | end = fix(end, revcount - 1) | |
208 | step = start > end and -1 or 1 |
|
208 | step = start > end and -1 or 1 | |
209 | for rev in xrange(start, end+step, step): |
|
209 | for rev in xrange(start, end+step, step): | |
210 | if rev in seen: |
|
210 | if rev in seen: | |
211 | continue |
|
211 | continue | |
212 | seen[rev] = 1 |
|
212 | seen[rev] = 1 | |
213 | yield str(rev) |
|
213 | yield str(rev) | |
214 | else: |
|
214 | else: | |
215 | rev = fix(spec, None) |
|
215 | rev = fix(spec, None) | |
216 | if rev in seen: |
|
216 | if rev in seen: | |
217 | continue |
|
217 | continue | |
218 | seen[rev] = 1 |
|
218 | seen[rev] = 1 | |
219 | yield str(rev) |
|
219 | yield str(rev) | |
220 |
|
220 | |||
221 | def make_filename(repo, r, pat, node=None, |
|
221 | def make_filename(repo, r, pat, node=None, | |
222 | total=None, seqno=None, revwidth=None, pathname=None): |
|
222 | total=None, seqno=None, revwidth=None, pathname=None): | |
223 | node_expander = { |
|
223 | node_expander = { | |
224 | 'H': lambda: hex(node), |
|
224 | 'H': lambda: hex(node), | |
225 | 'R': lambda: str(r.rev(node)), |
|
225 | 'R': lambda: str(r.rev(node)), | |
226 | 'h': lambda: short(node), |
|
226 | 'h': lambda: short(node), | |
227 | } |
|
227 | } | |
228 | expander = { |
|
228 | expander = { | |
229 | '%': lambda: '%', |
|
229 | '%': lambda: '%', | |
230 | 'b': lambda: os.path.basename(repo.root), |
|
230 | 'b': lambda: os.path.basename(repo.root), | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | try: |
|
233 | try: | |
234 | if node: |
|
234 | if node: | |
235 | expander.update(node_expander) |
|
235 | expander.update(node_expander) | |
236 | if node and revwidth is not None: |
|
236 | if node and revwidth is not None: | |
237 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) |
|
237 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | |
238 | if total is not None: |
|
238 | if total is not None: | |
239 | expander['N'] = lambda: str(total) |
|
239 | expander['N'] = lambda: str(total) | |
240 | if seqno is not None: |
|
240 | if seqno is not None: | |
241 | expander['n'] = lambda: str(seqno) |
|
241 | expander['n'] = lambda: str(seqno) | |
242 | if total is not None and seqno is not None: |
|
242 | if total is not None and seqno is not None: | |
243 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) |
|
243 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) | |
244 | if pathname is not None: |
|
244 | if pathname is not None: | |
245 | expander['s'] = lambda: os.path.basename(pathname) |
|
245 | expander['s'] = lambda: os.path.basename(pathname) | |
246 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
246 | expander['d'] = lambda: os.path.dirname(pathname) or '.' | |
247 | expander['p'] = lambda: pathname |
|
247 | expander['p'] = lambda: pathname | |
248 |
|
248 | |||
249 | newname = [] |
|
249 | newname = [] | |
250 | patlen = len(pat) |
|
250 | patlen = len(pat) | |
251 | i = 0 |
|
251 | i = 0 | |
252 | while i < patlen: |
|
252 | while i < patlen: | |
253 | c = pat[i] |
|
253 | c = pat[i] | |
254 | if c == '%': |
|
254 | if c == '%': | |
255 | i += 1 |
|
255 | i += 1 | |
256 | c = pat[i] |
|
256 | c = pat[i] | |
257 | c = expander[c]() |
|
257 | c = expander[c]() | |
258 | newname.append(c) |
|
258 | newname.append(c) | |
259 | i += 1 |
|
259 | i += 1 | |
260 | return ''.join(newname) |
|
260 | return ''.join(newname) | |
261 | except KeyError, inst: |
|
261 | except KeyError, inst: | |
262 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), |
|
262 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), | |
263 | inst.args[0]) |
|
263 | inst.args[0]) | |
264 |
|
264 | |||
265 | def make_file(repo, r, pat, node=None, |
|
265 | def make_file(repo, r, pat, node=None, | |
266 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
266 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): | |
267 | if not pat or pat == '-': |
|
267 | if not pat or pat == '-': | |
268 | return 'w' in mode and sys.stdout or sys.stdin |
|
268 | return 'w' in mode and sys.stdout or sys.stdin | |
269 | if hasattr(pat, 'write') and 'w' in mode: |
|
269 | if hasattr(pat, 'write') and 'w' in mode: | |
270 | return pat |
|
270 | return pat | |
271 | if hasattr(pat, 'read') and 'r' in mode: |
|
271 | if hasattr(pat, 'read') and 'r' in mode: | |
272 | return pat |
|
272 | return pat | |
273 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, |
|
273 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, | |
274 | pathname), |
|
274 | pathname), | |
275 | mode) |
|
275 | mode) | |
276 |
|
276 | |||
277 | def write_bundle(cg, filename, compress=True, fh=None): |
|
277 | def write_bundle(cg, filename, compress=True, fh=None): | |
278 | if fh is None: |
|
278 | if fh is None: | |
279 | fh = open(filename, "wb") |
|
279 | fh = open(filename, "wb") | |
280 |
|
280 | |||
281 | class nocompress(object): |
|
281 | class nocompress(object): | |
282 | def compress(self, x): |
|
282 | def compress(self, x): | |
283 | return x |
|
283 | return x | |
284 | def flush(self): |
|
284 | def flush(self): | |
285 | return "" |
|
285 | return "" | |
286 | try: |
|
286 | try: | |
287 | if compress: |
|
287 | if compress: | |
288 | fh.write("HG10") |
|
288 | fh.write("HG10") | |
289 | z = bz2.BZ2Compressor(9) |
|
289 | z = bz2.BZ2Compressor(9) | |
290 | else: |
|
290 | else: | |
291 | fh.write("HG11") |
|
291 | fh.write("HG11") | |
292 | z = nocompress() |
|
292 | z = nocompress() | |
293 | while 1: |
|
293 | while 1: | |
294 | chunk = cg.read(4096) |
|
294 | chunk = cg.read(4096) | |
295 | if not chunk: |
|
295 | if not chunk: | |
296 | break |
|
296 | break | |
297 | fh.write(z.compress(chunk)) |
|
297 | fh.write(z.compress(chunk)) | |
298 | fh.write(z.flush()) |
|
298 | fh.write(z.flush()) | |
299 | except: |
|
299 | except: | |
300 | os.unlink(filename) |
|
300 | os.unlink(filename) | |
301 | raise |
|
301 | raise | |
302 |
|
302 | |||
303 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
303 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | |
304 | changes=None, text=False, opts={}): |
|
304 | changes=None, text=False, opts={}): | |
305 | if not node1: |
|
305 | if not node1: | |
306 | node1 = repo.dirstate.parents()[0] |
|
306 | node1 = repo.dirstate.parents()[0] | |
307 | # reading the data for node1 early allows it to play nicely |
|
307 | # reading the data for node1 early allows it to play nicely | |
308 | # with repo.changes and the revlog cache. |
|
308 | # with repo.changes and the revlog cache. | |
309 | change = repo.changelog.read(node1) |
|
309 | change = repo.changelog.read(node1) | |
310 | mmap = repo.manifest.read(change[0]) |
|
310 | mmap = repo.manifest.read(change[0]) | |
311 | date1 = util.datestr(change[2]) |
|
311 | date1 = util.datestr(change[2]) | |
312 |
|
312 | |||
313 | if not changes: |
|
313 | if not changes: | |
314 | changes = repo.changes(node1, node2, files, match=match) |
|
314 | changes = repo.changes(node1, node2, files, match=match) | |
315 | modified, added, removed, deleted, unknown = changes |
|
315 | modified, added, removed, deleted, unknown = changes | |
316 | if files: |
|
316 | if files: | |
317 | modified, added, removed = map(lambda x: filterfiles(files, x), |
|
317 | modified, added, removed = map(lambda x: filterfiles(files, x), | |
318 | (modified, added, removed)) |
|
318 | (modified, added, removed)) | |
319 |
|
319 | |||
320 | if not modified and not added and not removed: |
|
320 | if not modified and not added and not removed: | |
321 | return |
|
321 | return | |
322 |
|
322 | |||
323 | if node2: |
|
323 | if node2: | |
324 | change = repo.changelog.read(node2) |
|
324 | change = repo.changelog.read(node2) | |
325 | mmap2 = repo.manifest.read(change[0]) |
|
325 | mmap2 = repo.manifest.read(change[0]) | |
326 | date2 = util.datestr(change[2]) |
|
326 | date2 = util.datestr(change[2]) | |
327 | def read(f): |
|
327 | def read(f): | |
328 | return repo.file(f).read(mmap2[f]) |
|
328 | return repo.file(f).read(mmap2[f]) | |
329 | else: |
|
329 | else: | |
330 | date2 = util.datestr() |
|
330 | date2 = util.datestr() | |
331 | def read(f): |
|
331 | def read(f): | |
332 | return repo.wread(f) |
|
332 | return repo.wread(f) | |
333 |
|
333 | |||
334 | if ui.quiet: |
|
334 | if ui.quiet: | |
335 | r = None |
|
335 | r = None | |
336 | else: |
|
336 | else: | |
337 | hexfunc = ui.verbose and hex or short |
|
337 | hexfunc = ui.verbose and hex or short | |
338 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
338 | r = [hexfunc(node) for node in [node1, node2] if node] | |
339 |
|
339 | |||
340 | diffopts = ui.diffopts() |
|
340 | diffopts = ui.diffopts() | |
341 | showfunc = opts.get('show_function') or diffopts['showfunc'] |
|
341 | showfunc = opts.get('show_function') or diffopts['showfunc'] | |
342 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] |
|
342 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] | |
343 | for f in modified: |
|
343 | for f in modified: | |
344 | to = None |
|
344 | to = None | |
345 | if f in mmap: |
|
345 | if f in mmap: | |
346 | to = repo.file(f).read(mmap[f]) |
|
346 | to = repo.file(f).read(mmap[f]) | |
347 | tn = read(f) |
|
347 | tn = read(f) | |
348 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
348 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
349 | showfunc=showfunc, ignorews=ignorews)) |
|
349 | showfunc=showfunc, ignorews=ignorews)) | |
350 | for f in added: |
|
350 | for f in added: | |
351 | to = None |
|
351 | to = None | |
352 | tn = read(f) |
|
352 | tn = read(f) | |
353 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
353 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
354 | showfunc=showfunc, ignorews=ignorews)) |
|
354 | showfunc=showfunc, ignorews=ignorews)) | |
355 | for f in removed: |
|
355 | for f in removed: | |
356 | to = repo.file(f).read(mmap[f]) |
|
356 | to = repo.file(f).read(mmap[f]) | |
357 | tn = None |
|
357 | tn = None | |
358 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
358 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
359 | showfunc=showfunc, ignorews=ignorews)) |
|
359 | showfunc=showfunc, ignorews=ignorews)) | |
360 |
|
360 | |||
361 | def trimuser(ui, name, rev, revcache): |
|
361 | def trimuser(ui, name, rev, revcache): | |
362 | """trim the name of the user who committed a change""" |
|
362 | """trim the name of the user who committed a change""" | |
363 | user = revcache.get(rev) |
|
363 | user = revcache.get(rev) | |
364 | if user is None: |
|
364 | if user is None: | |
365 | user = revcache[rev] = ui.shortuser(name) |
|
365 | user = revcache[rev] = ui.shortuser(name) | |
366 | return user |
|
366 | return user | |
367 |
|
367 | |||
368 | class changeset_templater(object): |
|
368 | class changeset_templater(object): | |
369 | '''use templater module to format changeset information.''' |
|
369 | '''use templater module to format changeset information.''' | |
370 |
|
370 | |||
371 | def __init__(self, ui, repo, mapfile): |
|
371 | def __init__(self, ui, repo, mapfile): | |
372 | self.t = templater.templater(mapfile, templater.common_filters, |
|
372 | self.t = templater.templater(mapfile, templater.common_filters, | |
373 | cache={'parent': '{rev}:{node|short} ', |
|
373 | cache={'parent': '{rev}:{node|short} ', | |
374 | 'manifest': '{rev}:{node|short}'}) |
|
374 | 'manifest': '{rev}:{node|short}'}) | |
375 | self.ui = ui |
|
375 | self.ui = ui | |
376 | self.repo = repo |
|
376 | self.repo = repo | |
377 |
|
377 | |||
378 | def use_template(self, t): |
|
378 | def use_template(self, t): | |
379 | '''set template string to use''' |
|
379 | '''set template string to use''' | |
380 | self.t.cache['changeset'] = t |
|
380 | self.t.cache['changeset'] = t | |
381 |
|
381 | |||
382 | def write(self, thing): |
|
382 | def write(self, thing): | |
383 | '''write expanded template. |
|
383 | '''write expanded template. | |
384 | uses in-order recursive traverse of iterators.''' |
|
384 | uses in-order recursive traverse of iterators.''' | |
385 | for t in thing: |
|
385 | for t in thing: | |
386 | if hasattr(t, '__iter__'): |
|
386 | if hasattr(t, '__iter__'): | |
387 | self.write(t) |
|
387 | self.write(t) | |
388 | else: |
|
388 | else: | |
389 | self.ui.write(t) |
|
389 | self.ui.write(t) | |
390 |
|
390 | |||
391 | def show(self, rev=0, changenode=None, brinfo=None): |
|
391 | def show(self, rev=0, changenode=None, brinfo=None): | |
392 | '''show a single changeset or file revision''' |
|
392 | '''show a single changeset or file revision''' | |
393 | log = self.repo.changelog |
|
393 | log = self.repo.changelog | |
394 | if changenode is None: |
|
394 | if changenode is None: | |
395 | changenode = log.node(rev) |
|
395 | changenode = log.node(rev) | |
396 | elif not rev: |
|
396 | elif not rev: | |
397 | rev = log.rev(changenode) |
|
397 | rev = log.rev(changenode) | |
398 |
|
398 | |||
399 | changes = log.read(changenode) |
|
399 | changes = log.read(changenode) | |
400 |
|
400 | |||
401 | def showlist(name, values, plural=None, **args): |
|
401 | def showlist(name, values, plural=None, **args): | |
402 | '''expand set of values. |
|
402 | '''expand set of values. | |
403 | name is name of key in template map. |
|
403 | name is name of key in template map. | |
404 | values is list of strings or dicts. |
|
404 | values is list of strings or dicts. | |
405 | plural is plural of name, if not simply name + 's'. |
|
405 | plural is plural of name, if not simply name + 's'. | |
406 |
|
406 | |||
407 | expansion works like this, given name 'foo'. |
|
407 | expansion works like this, given name 'foo'. | |
408 |
|
408 | |||
409 | if values is empty, expand 'no_foos'. |
|
409 | if values is empty, expand 'no_foos'. | |
410 |
|
410 | |||
411 | if 'foo' not in template map, return values as a string, |
|
411 | if 'foo' not in template map, return values as a string, | |
412 | joined by space. |
|
412 | joined by space. | |
413 |
|
413 | |||
414 | expand 'start_foos'. |
|
414 | expand 'start_foos'. | |
415 |
|
415 | |||
416 | for each value, expand 'foo'. if 'last_foo' in template |
|
416 | for each value, expand 'foo'. if 'last_foo' in template | |
417 | map, expand it instead of 'foo' for last key. |
|
417 | map, expand it instead of 'foo' for last key. | |
418 |
|
418 | |||
419 | expand 'end_foos'. |
|
419 | expand 'end_foos'. | |
420 | ''' |
|
420 | ''' | |
421 | if plural: names = plural |
|
421 | if plural: names = plural | |
422 | else: names = name + 's' |
|
422 | else: names = name + 's' | |
423 | if not values: |
|
423 | if not values: | |
424 | noname = 'no_' + names |
|
424 | noname = 'no_' + names | |
425 | if noname in self.t: |
|
425 | if noname in self.t: | |
426 | yield self.t(noname, **args) |
|
426 | yield self.t(noname, **args) | |
427 | return |
|
427 | return | |
428 | if name not in self.t: |
|
428 | if name not in self.t: | |
429 | if isinstance(values[0], str): |
|
429 | if isinstance(values[0], str): | |
430 | yield ' '.join(values) |
|
430 | yield ' '.join(values) | |
431 | else: |
|
431 | else: | |
432 | for v in values: |
|
432 | for v in values: | |
433 | yield dict(v, **args) |
|
433 | yield dict(v, **args) | |
434 | return |
|
434 | return | |
435 | startname = 'start_' + names |
|
435 | startname = 'start_' + names | |
436 | if startname in self.t: |
|
436 | if startname in self.t: | |
437 | yield self.t(startname, **args) |
|
437 | yield self.t(startname, **args) | |
438 | vargs = args.copy() |
|
438 | vargs = args.copy() | |
439 | def one(v, tag=name): |
|
439 | def one(v, tag=name): | |
440 | try: |
|
440 | try: | |
441 | vargs.update(v) |
|
441 | vargs.update(v) | |
442 | except (AttributeError, ValueError): |
|
442 | except (AttributeError, ValueError): | |
443 | try: |
|
443 | try: | |
444 | for a, b in v: |
|
444 | for a, b in v: | |
445 | vargs[a] = b |
|
445 | vargs[a] = b | |
446 | except ValueError: |
|
446 | except ValueError: | |
447 | vargs[name] = v |
|
447 | vargs[name] = v | |
448 | return self.t(tag, **vargs) |
|
448 | return self.t(tag, **vargs) | |
449 | lastname = 'last_' + name |
|
449 | lastname = 'last_' + name | |
450 | if lastname in self.t: |
|
450 | if lastname in self.t: | |
451 | last = values.pop() |
|
451 | last = values.pop() | |
452 | else: |
|
452 | else: | |
453 | last = None |
|
453 | last = None | |
454 | for v in values: |
|
454 | for v in values: | |
455 | yield one(v) |
|
455 | yield one(v) | |
456 | if last is not None: |
|
456 | if last is not None: | |
457 | yield one(last, tag=lastname) |
|
457 | yield one(last, tag=lastname) | |
458 | endname = 'end_' + names |
|
458 | endname = 'end_' + names | |
459 | if endname in self.t: |
|
459 | if endname in self.t: | |
460 | yield self.t(endname, **args) |
|
460 | yield self.t(endname, **args) | |
461 |
|
461 | |||
462 | if brinfo: |
|
462 | if brinfo: | |
463 | def showbranches(**args): |
|
463 | def showbranches(**args): | |
464 | if changenode in brinfo: |
|
464 | if changenode in brinfo: | |
465 | for x in showlist('branch', brinfo[changenode], |
|
465 | for x in showlist('branch', brinfo[changenode], | |
466 | plural='branches', **args): |
|
466 | plural='branches', **args): | |
467 | yield x |
|
467 | yield x | |
468 | else: |
|
468 | else: | |
469 | showbranches = '' |
|
469 | showbranches = '' | |
470 |
|
470 | |||
471 | if self.ui.debugflag: |
|
471 | if self.ui.debugflag: | |
472 | def showmanifest(**args): |
|
472 | def showmanifest(**args): | |
473 | args = args.copy() |
|
473 | args = args.copy() | |
474 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), |
|
474 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), | |
475 | node=hex(changes[0]))) |
|
475 | node=hex(changes[0]))) | |
476 | yield self.t('manifest', **args) |
|
476 | yield self.t('manifest', **args) | |
477 | else: |
|
477 | else: | |
478 | showmanifest = '' |
|
478 | showmanifest = '' | |
479 |
|
479 | |||
480 | def showparents(**args): |
|
480 | def showparents(**args): | |
481 | parents = [[('rev', log.rev(p)), ('node', hex(p))] |
|
481 | parents = [[('rev', log.rev(p)), ('node', hex(p))] | |
482 | for p in log.parents(changenode) |
|
482 | for p in log.parents(changenode) | |
483 | if self.ui.debugflag or p != nullid] |
|
483 | if self.ui.debugflag or p != nullid] | |
484 | if (not self.ui.debugflag and len(parents) == 1 and |
|
484 | if (not self.ui.debugflag and len(parents) == 1 and | |
485 | parents[0][0][1] == rev - 1): |
|
485 | parents[0][0][1] == rev - 1): | |
486 | return |
|
486 | return | |
487 | for x in showlist('parent', parents, **args): |
|
487 | for x in showlist('parent', parents, **args): | |
488 | yield x |
|
488 | yield x | |
489 |
|
489 | |||
490 | def showtags(**args): |
|
490 | def showtags(**args): | |
491 | for x in showlist('tag', self.repo.nodetags(changenode), **args): |
|
491 | for x in showlist('tag', self.repo.nodetags(changenode), **args): | |
492 | yield x |
|
492 | yield x | |
493 |
|
493 | |||
494 | if self.ui.debugflag: |
|
494 | if self.ui.debugflag: | |
495 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
495 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
496 | def showfiles(**args): |
|
496 | def showfiles(**args): | |
497 | for x in showlist('file', files[0], **args): yield x |
|
497 | for x in showlist('file', files[0], **args): yield x | |
498 | def showadds(**args): |
|
498 | def showadds(**args): | |
499 | for x in showlist('file_add', files[1], **args): yield x |
|
499 | for x in showlist('file_add', files[1], **args): yield x | |
500 | def showdels(**args): |
|
500 | def showdels(**args): | |
501 | for x in showlist('file_del', files[2], **args): yield x |
|
501 | for x in showlist('file_del', files[2], **args): yield x | |
502 | else: |
|
502 | else: | |
503 | def showfiles(**args): |
|
503 | def showfiles(**args): | |
504 | for x in showlist('file', changes[3], **args): yield x |
|
504 | for x in showlist('file', changes[3], **args): yield x | |
505 | showadds = '' |
|
505 | showadds = '' | |
506 | showdels = '' |
|
506 | showdels = '' | |
507 |
|
507 | |||
508 | props = { |
|
508 | props = { | |
509 | 'author': changes[1], |
|
509 | 'author': changes[1], | |
510 | 'branches': showbranches, |
|
510 | 'branches': showbranches, | |
511 | 'date': changes[2], |
|
511 | 'date': changes[2], | |
512 | 'desc': changes[4], |
|
512 | 'desc': changes[4], | |
513 | 'file_adds': showadds, |
|
513 | 'file_adds': showadds, | |
514 | 'file_dels': showdels, |
|
514 | 'file_dels': showdels, | |
515 | 'files': showfiles, |
|
515 | 'files': showfiles, | |
516 | 'manifest': showmanifest, |
|
516 | 'manifest': showmanifest, | |
517 | 'node': hex(changenode), |
|
517 | 'node': hex(changenode), | |
518 | 'parents': showparents, |
|
518 | 'parents': showparents, | |
519 | 'rev': rev, |
|
519 | 'rev': rev, | |
520 | 'tags': showtags, |
|
520 | 'tags': showtags, | |
521 | } |
|
521 | } | |
522 |
|
522 | |||
523 | try: |
|
523 | try: | |
524 | if self.ui.debugflag and 'changeset_debug' in self.t: |
|
524 | if self.ui.debugflag and 'changeset_debug' in self.t: | |
525 | key = 'changeset_debug' |
|
525 | key = 'changeset_debug' | |
526 | elif self.ui.quiet and 'changeset_quiet' in self.t: |
|
526 | elif self.ui.quiet and 'changeset_quiet' in self.t: | |
527 | key = 'changeset_quiet' |
|
527 | key = 'changeset_quiet' | |
528 | elif self.ui.verbose and 'changeset_verbose' in self.t: |
|
528 | elif self.ui.verbose and 'changeset_verbose' in self.t: | |
529 | key = 'changeset_verbose' |
|
529 | key = 'changeset_verbose' | |
530 | else: |
|
530 | else: | |
531 | key = 'changeset' |
|
531 | key = 'changeset' | |
532 | self.write(self.t(key, **props)) |
|
532 | self.write(self.t(key, **props)) | |
533 | except KeyError, inst: |
|
533 | except KeyError, inst: | |
534 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, |
|
534 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, | |
535 | inst.args[0])) |
|
535 | inst.args[0])) | |
536 | except SyntaxError, inst: |
|
536 | except SyntaxError, inst: | |
537 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) |
|
537 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) | |
538 |
|
538 | |||
539 | class changeset_printer(object): |
|
539 | class changeset_printer(object): | |
540 | '''show changeset information when templating not requested.''' |
|
540 | '''show changeset information when templating not requested.''' | |
541 |
|
541 | |||
542 | def __init__(self, ui, repo): |
|
542 | def __init__(self, ui, repo): | |
543 | self.ui = ui |
|
543 | self.ui = ui | |
544 | self.repo = repo |
|
544 | self.repo = repo | |
545 |
|
545 | |||
546 | def show(self, rev=0, changenode=None, brinfo=None): |
|
546 | def show(self, rev=0, changenode=None, brinfo=None): | |
547 | '''show a single changeset or file revision''' |
|
547 | '''show a single changeset or file revision''' | |
548 | log = self.repo.changelog |
|
548 | log = self.repo.changelog | |
549 | if changenode is None: |
|
549 | if changenode is None: | |
550 | changenode = log.node(rev) |
|
550 | changenode = log.node(rev) | |
551 | elif not rev: |
|
551 | elif not rev: | |
552 | rev = log.rev(changenode) |
|
552 | rev = log.rev(changenode) | |
553 |
|
553 | |||
554 | if self.ui.quiet: |
|
554 | if self.ui.quiet: | |
555 | self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
555 | self.ui.write("%d:%s\n" % (rev, short(changenode))) | |
556 | return |
|
556 | return | |
557 |
|
557 | |||
558 | changes = log.read(changenode) |
|
558 | changes = log.read(changenode) | |
559 | date = util.datestr(changes[2]) |
|
559 | date = util.datestr(changes[2]) | |
560 |
|
560 | |||
561 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) |
|
561 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) | |
562 | for p in log.parents(changenode) |
|
562 | for p in log.parents(changenode) | |
563 | if self.ui.debugflag or p != nullid] |
|
563 | if self.ui.debugflag or p != nullid] | |
564 | if (not self.ui.debugflag and len(parents) == 1 and |
|
564 | if (not self.ui.debugflag and len(parents) == 1 and | |
565 | parents[0][0] == rev-1): |
|
565 | parents[0][0] == rev-1): | |
566 | parents = [] |
|
566 | parents = [] | |
567 |
|
567 | |||
568 | if self.ui.verbose: |
|
568 | if self.ui.verbose: | |
569 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) |
|
569 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) | |
570 | else: |
|
570 | else: | |
571 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) |
|
571 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) | |
572 |
|
572 | |||
573 | for tag in self.repo.nodetags(changenode): |
|
573 | for tag in self.repo.nodetags(changenode): | |
574 | self.ui.status(_("tag: %s\n") % tag) |
|
574 | self.ui.status(_("tag: %s\n") % tag) | |
575 | for parent in parents: |
|
575 | for parent in parents: | |
576 | self.ui.write(_("parent: %d:%s\n") % parent) |
|
576 | self.ui.write(_("parent: %d:%s\n") % parent) | |
577 |
|
577 | |||
578 | if brinfo and changenode in brinfo: |
|
578 | if brinfo and changenode in brinfo: | |
579 | br = brinfo[changenode] |
|
579 | br = brinfo[changenode] | |
580 | self.ui.write(_("branch: %s\n") % " ".join(br)) |
|
580 | self.ui.write(_("branch: %s\n") % " ".join(br)) | |
581 |
|
581 | |||
582 | self.ui.debug(_("manifest: %d:%s\n") % |
|
582 | self.ui.debug(_("manifest: %d:%s\n") % | |
583 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
583 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) | |
584 | self.ui.status(_("user: %s\n") % changes[1]) |
|
584 | self.ui.status(_("user: %s\n") % changes[1]) | |
585 | self.ui.status(_("date: %s\n") % date) |
|
585 | self.ui.status(_("date: %s\n") % date) | |
586 |
|
586 | |||
587 | if self.ui.debugflag: |
|
587 | if self.ui.debugflag: | |
588 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
588 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
589 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
589 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
590 | files): |
|
590 | files): | |
591 | if value: |
|
591 | if value: | |
592 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) |
|
592 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) | |
593 | else: |
|
593 | else: | |
594 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) |
|
594 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) | |
595 |
|
595 | |||
596 | description = changes[4].strip() |
|
596 | description = changes[4].strip() | |
597 | if description: |
|
597 | if description: | |
598 | if self.ui.verbose: |
|
598 | if self.ui.verbose: | |
599 | self.ui.status(_("description:\n")) |
|
599 | self.ui.status(_("description:\n")) | |
600 | self.ui.status(description) |
|
600 | self.ui.status(description) | |
601 | self.ui.status("\n\n") |
|
601 | self.ui.status("\n\n") | |
602 | else: |
|
602 | else: | |
603 | self.ui.status(_("summary: %s\n") % |
|
603 | self.ui.status(_("summary: %s\n") % | |
604 | description.splitlines()[0]) |
|
604 | description.splitlines()[0]) | |
605 | self.ui.status("\n") |
|
605 | self.ui.status("\n") | |
606 |
|
606 | |||
607 | def show_changeset(ui, repo, opts): |
|
607 | def show_changeset(ui, repo, opts): | |
608 | '''show one changeset. uses template or regular display. caller |
|
608 | '''show one changeset. uses template or regular display. caller | |
609 | can pass in 'style' and 'template' options in opts.''' |
|
609 | can pass in 'style' and 'template' options in opts.''' | |
610 |
|
610 | |||
611 | tmpl = opts.get('template') |
|
611 | tmpl = opts.get('template') | |
612 | if tmpl: |
|
612 | if tmpl: | |
613 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
613 | tmpl = templater.parsestring(tmpl, quoted=False) | |
614 | else: |
|
614 | else: | |
615 | tmpl = ui.config('ui', 'logtemplate') |
|
615 | tmpl = ui.config('ui', 'logtemplate') | |
616 | if tmpl: tmpl = templater.parsestring(tmpl) |
|
616 | if tmpl: tmpl = templater.parsestring(tmpl) | |
617 | mapfile = opts.get('style') or ui.config('ui', 'style') |
|
617 | mapfile = opts.get('style') or ui.config('ui', 'style') | |
618 | if tmpl or mapfile: |
|
618 | if tmpl or mapfile: | |
619 | if mapfile: |
|
619 | if mapfile: | |
620 | if not os.path.isfile(mapfile): |
|
620 | if not os.path.isfile(mapfile): | |
621 | mapname = templater.templatepath('map-cmdline.' + mapfile) |
|
621 | mapname = templater.templatepath('map-cmdline.' + mapfile) | |
622 | if not mapname: mapname = templater.templatepath(mapfile) |
|
622 | if not mapname: mapname = templater.templatepath(mapfile) | |
623 | if mapname: mapfile = mapname |
|
623 | if mapname: mapfile = mapname | |
624 | try: |
|
624 | try: | |
625 | t = changeset_templater(ui, repo, mapfile) |
|
625 | t = changeset_templater(ui, repo, mapfile) | |
626 | except SyntaxError, inst: |
|
626 | except SyntaxError, inst: | |
627 | raise util.Abort(inst.args[0]) |
|
627 | raise util.Abort(inst.args[0]) | |
628 | if tmpl: t.use_template(tmpl) |
|
628 | if tmpl: t.use_template(tmpl) | |
629 | return t |
|
629 | return t | |
630 | return changeset_printer(ui, repo) |
|
630 | return changeset_printer(ui, repo) | |
631 |
|
631 | |||
632 | def show_version(ui): |
|
632 | def show_version(ui): | |
633 | """output version and copyright information""" |
|
633 | """output version and copyright information""" | |
634 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
634 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | |
635 | % version.get_version()) |
|
635 | % version.get_version()) | |
636 | ui.status(_( |
|
636 | ui.status(_( | |
637 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
|
637 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" | |
638 | "This is free software; see the source for copying conditions. " |
|
638 | "This is free software; see the source for copying conditions. " | |
639 | "There is NO\nwarranty; " |
|
639 | "There is NO\nwarranty; " | |
640 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
640 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
641 | )) |
|
641 | )) | |
642 |
|
642 | |||
643 | def help_(ui, cmd=None, with_version=False): |
|
643 | def help_(ui, cmd=None, with_version=False): | |
644 | """show help for a given command or all commands""" |
|
644 | """show help for a given command or all commands""" | |
645 | option_lists = [] |
|
645 | option_lists = [] | |
646 | if cmd and cmd != 'shortlist': |
|
646 | if cmd and cmd != 'shortlist': | |
647 | if with_version: |
|
647 | if with_version: | |
648 | show_version(ui) |
|
648 | show_version(ui) | |
649 | ui.write('\n') |
|
649 | ui.write('\n') | |
650 | aliases, i = find(cmd) |
|
650 | aliases, i = find(cmd) | |
651 | # synopsis |
|
651 | # synopsis | |
652 | ui.write("%s\n\n" % i[2]) |
|
652 | ui.write("%s\n\n" % i[2]) | |
653 |
|
653 | |||
654 | # description |
|
654 | # description | |
655 | doc = i[0].__doc__ |
|
655 | doc = i[0].__doc__ | |
656 | if not doc: |
|
656 | if not doc: | |
657 | doc = _("(No help text available)") |
|
657 | doc = _("(No help text available)") | |
658 | if ui.quiet: |
|
658 | if ui.quiet: | |
659 | doc = doc.splitlines(0)[0] |
|
659 | doc = doc.splitlines(0)[0] | |
660 | ui.write("%s\n" % doc.rstrip()) |
|
660 | ui.write("%s\n" % doc.rstrip()) | |
661 |
|
661 | |||
662 | if not ui.quiet: |
|
662 | if not ui.quiet: | |
663 | # aliases |
|
663 | # aliases | |
664 | if len(aliases) > 1: |
|
664 | if len(aliases) > 1: | |
665 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
665 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | |
666 |
|
666 | |||
667 | # options |
|
667 | # options | |
668 | if i[1]: |
|
668 | if i[1]: | |
669 | option_lists.append(("options", i[1])) |
|
669 | option_lists.append(("options", i[1])) | |
670 |
|
670 | |||
671 | else: |
|
671 | else: | |
672 | # program name |
|
672 | # program name | |
673 | if ui.verbose or with_version: |
|
673 | if ui.verbose or with_version: | |
674 | show_version(ui) |
|
674 | show_version(ui) | |
675 | else: |
|
675 | else: | |
676 | ui.status(_("Mercurial Distributed SCM\n")) |
|
676 | ui.status(_("Mercurial Distributed SCM\n")) | |
677 | ui.status('\n') |
|
677 | ui.status('\n') | |
678 |
|
678 | |||
679 | # list of commands |
|
679 | # list of commands | |
680 | if cmd == "shortlist": |
|
680 | if cmd == "shortlist": | |
681 | ui.status(_('basic commands (use "hg help" ' |
|
681 | ui.status(_('basic commands (use "hg help" ' | |
682 | 'for the full list or option "-v" for details):\n\n')) |
|
682 | 'for the full list or option "-v" for details):\n\n')) | |
683 | elif ui.verbose: |
|
683 | elif ui.verbose: | |
684 | ui.status(_('list of commands:\n\n')) |
|
684 | ui.status(_('list of commands:\n\n')) | |
685 | else: |
|
685 | else: | |
686 | ui.status(_('list of commands (use "hg help -v" ' |
|
686 | ui.status(_('list of commands (use "hg help -v" ' | |
687 | 'to show aliases and global options):\n\n')) |
|
687 | 'to show aliases and global options):\n\n')) | |
688 |
|
688 | |||
689 | h = {} |
|
689 | h = {} | |
690 | cmds = {} |
|
690 | cmds = {} | |
691 | for c, e in table.items(): |
|
691 | for c, e in table.items(): | |
692 | f = c.split("|")[0] |
|
692 | f = c.split("|")[0] | |
693 | if cmd == "shortlist" and not f.startswith("^"): |
|
693 | if cmd == "shortlist" and not f.startswith("^"): | |
694 | continue |
|
694 | continue | |
695 | f = f.lstrip("^") |
|
695 | f = f.lstrip("^") | |
696 | if not ui.debugflag and f.startswith("debug"): |
|
696 | if not ui.debugflag and f.startswith("debug"): | |
697 | continue |
|
697 | continue | |
698 | doc = e[0].__doc__ |
|
698 | doc = e[0].__doc__ | |
699 | if not doc: |
|
699 | if not doc: | |
700 | doc = _("(No help text available)") |
|
700 | doc = _("(No help text available)") | |
701 | h[f] = doc.splitlines(0)[0].rstrip() |
|
701 | h[f] = doc.splitlines(0)[0].rstrip() | |
702 | cmds[f] = c.lstrip("^") |
|
702 | cmds[f] = c.lstrip("^") | |
703 |
|
703 | |||
704 | fns = h.keys() |
|
704 | fns = h.keys() | |
705 | fns.sort() |
|
705 | fns.sort() | |
706 | m = max(map(len, fns)) |
|
706 | m = max(map(len, fns)) | |
707 | for f in fns: |
|
707 | for f in fns: | |
708 | if ui.verbose: |
|
708 | if ui.verbose: | |
709 | commands = cmds[f].replace("|",", ") |
|
709 | commands = cmds[f].replace("|",", ") | |
710 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
710 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
711 | else: |
|
711 | else: | |
712 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
712 | ui.write(' %-*s %s\n' % (m, f, h[f])) | |
713 |
|
713 | |||
714 | # global options |
|
714 | # global options | |
715 | if ui.verbose: |
|
715 | if ui.verbose: | |
716 | option_lists.append(("global options", globalopts)) |
|
716 | option_lists.append(("global options", globalopts)) | |
717 |
|
717 | |||
718 | # list all option lists |
|
718 | # list all option lists | |
719 | opt_output = [] |
|
719 | opt_output = [] | |
720 | for title, options in option_lists: |
|
720 | for title, options in option_lists: | |
721 | opt_output.append(("\n%s:\n" % title, None)) |
|
721 | opt_output.append(("\n%s:\n" % title, None)) | |
722 | for shortopt, longopt, default, desc in options: |
|
722 | for shortopt, longopt, default, desc in options: | |
723 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
723 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | |
724 | longopt and " --%s" % longopt), |
|
724 | longopt and " --%s" % longopt), | |
725 | "%s%s" % (desc, |
|
725 | "%s%s" % (desc, | |
726 | default |
|
726 | default | |
727 | and _(" (default: %s)") % default |
|
727 | and _(" (default: %s)") % default | |
728 | or ""))) |
|
728 | or ""))) | |
729 |
|
729 | |||
730 | if opt_output: |
|
730 | if opt_output: | |
731 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
731 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) | |
732 | for first, second in opt_output: |
|
732 | for first, second in opt_output: | |
733 | if second: |
|
733 | if second: | |
734 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
734 | ui.write(" %-*s %s\n" % (opts_len, first, second)) | |
735 | else: |
|
735 | else: | |
736 | ui.write("%s\n" % first) |
|
736 | ui.write("%s\n" % first) | |
737 |
|
737 | |||
738 | # Commands start here, listed alphabetically |
|
738 | # Commands start here, listed alphabetically | |
739 |
|
739 | |||
740 | def add(ui, repo, *pats, **opts): |
|
740 | def add(ui, repo, *pats, **opts): | |
741 | """add the specified files on the next commit |
|
741 | """add the specified files on the next commit | |
742 |
|
742 | |||
743 | Schedule files to be version controlled and added to the repository. |
|
743 | Schedule files to be version controlled and added to the repository. | |
744 |
|
744 | |||
745 | The files will be added to the repository at the next commit. |
|
745 | The files will be added to the repository at the next commit. | |
746 |
|
746 | |||
747 | If no names are given, add all files in the repository. |
|
747 | If no names are given, add all files in the repository. | |
748 | """ |
|
748 | """ | |
749 |
|
749 | |||
750 | names = [] |
|
750 | names = [] | |
751 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
751 | for src, abs, rel, exact in walk(repo, pats, opts): | |
752 | if exact: |
|
752 | if exact: | |
753 | if ui.verbose: |
|
753 | if ui.verbose: | |
754 | ui.status(_('adding %s\n') % rel) |
|
754 | ui.status(_('adding %s\n') % rel) | |
755 | names.append(abs) |
|
755 | names.append(abs) | |
756 | elif repo.dirstate.state(abs) == '?': |
|
756 | elif repo.dirstate.state(abs) == '?': | |
757 | ui.status(_('adding %s\n') % rel) |
|
757 | ui.status(_('adding %s\n') % rel) | |
758 | names.append(abs) |
|
758 | names.append(abs) | |
759 | repo.add(names) |
|
759 | repo.add(names) | |
760 |
|
760 | |||
761 | def addremove(ui, repo, *pats, **opts): |
|
761 | def addremove(ui, repo, *pats, **opts): | |
762 | """add all new files, delete all missing files |
|
762 | """add all new files, delete all missing files | |
763 |
|
763 | |||
764 | Add all new files and remove all missing files from the repository. |
|
764 | Add all new files and remove all missing files from the repository. | |
765 |
|
765 | |||
766 | New files are ignored if they match any of the patterns in .hgignore. As |
|
766 | New files are ignored if they match any of the patterns in .hgignore. As | |
767 | with add, these changes take effect at the next commit. |
|
767 | with add, these changes take effect at the next commit. | |
768 | """ |
|
768 | """ | |
769 | return addremove_lock(ui, repo, pats, opts) |
|
769 | return addremove_lock(ui, repo, pats, opts) | |
770 |
|
770 | |||
771 | def addremove_lock(ui, repo, pats, opts, wlock=None): |
|
771 | def addremove_lock(ui, repo, pats, opts, wlock=None): | |
772 | add, remove = [], [] |
|
772 | add, remove = [], [] | |
773 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
773 | for src, abs, rel, exact in walk(repo, pats, opts): | |
774 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
774 | if src == 'f' and repo.dirstate.state(abs) == '?': | |
775 | add.append(abs) |
|
775 | add.append(abs) | |
776 | if ui.verbose or not exact: |
|
776 | if ui.verbose or not exact: | |
777 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
777 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) | |
778 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
|
778 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | |
779 | remove.append(abs) |
|
779 | remove.append(abs) | |
780 | if ui.verbose or not exact: |
|
780 | if ui.verbose or not exact: | |
781 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
781 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) | |
782 | repo.add(add, wlock=wlock) |
|
782 | repo.add(add, wlock=wlock) | |
783 | repo.remove(remove, wlock=wlock) |
|
783 | repo.remove(remove, wlock=wlock) | |
784 |
|
784 | |||
785 | def annotate(ui, repo, *pats, **opts): |
|
785 | def annotate(ui, repo, *pats, **opts): | |
786 | """show changeset information per file line |
|
786 | """show changeset information per file line | |
787 |
|
787 | |||
788 | List changes in files, showing the revision id responsible for each line |
|
788 | List changes in files, showing the revision id responsible for each line | |
789 |
|
789 | |||
790 | This command is useful to discover who did a change or when a change took |
|
790 | This command is useful to discover who did a change or when a change took | |
791 | place. |
|
791 | place. | |
792 |
|
792 | |||
793 | Without the -a option, annotate will avoid processing files it |
|
793 | Without the -a option, annotate will avoid processing files it | |
794 | detects as binary. With -a, annotate will generate an annotation |
|
794 | detects as binary. With -a, annotate will generate an annotation | |
795 | anyway, probably with undesirable results. |
|
795 | anyway, probably with undesirable results. | |
796 | """ |
|
796 | """ | |
797 | def getnode(rev): |
|
797 | def getnode(rev): | |
798 | return short(repo.changelog.node(rev)) |
|
798 | return short(repo.changelog.node(rev)) | |
799 |
|
799 | |||
800 | ucache = {} |
|
800 | ucache = {} | |
801 | def getname(rev): |
|
801 | def getname(rev): | |
802 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
802 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
803 | return trimuser(ui, cl[1], rev, ucache) |
|
803 | return trimuser(ui, cl[1], rev, ucache) | |
804 |
|
804 | |||
805 | dcache = {} |
|
805 | dcache = {} | |
806 | def getdate(rev): |
|
806 | def getdate(rev): | |
807 | datestr = dcache.get(rev) |
|
807 | datestr = dcache.get(rev) | |
808 | if datestr is None: |
|
808 | if datestr is None: | |
809 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
809 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
810 | datestr = dcache[rev] = util.datestr(cl[2]) |
|
810 | datestr = dcache[rev] = util.datestr(cl[2]) | |
811 | return datestr |
|
811 | return datestr | |
812 |
|
812 | |||
813 | if not pats: |
|
813 | if not pats: | |
814 | raise util.Abort(_('at least one file name or pattern required')) |
|
814 | raise util.Abort(_('at least one file name or pattern required')) | |
815 |
|
815 | |||
816 | opmap = [['user', getname], ['number', str], ['changeset', getnode], |
|
816 | opmap = [['user', getname], ['number', str], ['changeset', getnode], | |
817 | ['date', getdate]] |
|
817 | ['date', getdate]] | |
818 | if not opts['user'] and not opts['changeset'] and not opts['date']: |
|
818 | if not opts['user'] and not opts['changeset'] and not opts['date']: | |
819 | opts['number'] = 1 |
|
819 | opts['number'] = 1 | |
820 |
|
820 | |||
821 | if opts['rev']: |
|
821 | if opts['rev']: | |
822 | node = repo.changelog.lookup(opts['rev']) |
|
822 | node = repo.changelog.lookup(opts['rev']) | |
823 | else: |
|
823 | else: | |
824 | node = repo.dirstate.parents()[0] |
|
824 | node = repo.dirstate.parents()[0] | |
825 | change = repo.changelog.read(node) |
|
825 | change = repo.changelog.read(node) | |
826 | mmap = repo.manifest.read(change[0]) |
|
826 | mmap = repo.manifest.read(change[0]) | |
827 |
|
827 | |||
828 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): |
|
828 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): | |
829 | f = repo.file(abs) |
|
829 | f = repo.file(abs) | |
830 | if not opts['text'] and util.binary(f.read(mmap[abs])): |
|
830 | if not opts['text'] and util.binary(f.read(mmap[abs])): | |
831 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
831 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | |
832 | continue |
|
832 | continue | |
833 |
|
833 | |||
834 | lines = f.annotate(mmap[abs]) |
|
834 | lines = f.annotate(mmap[abs]) | |
835 | pieces = [] |
|
835 | pieces = [] | |
836 |
|
836 | |||
837 | for o, f in opmap: |
|
837 | for o, f in opmap: | |
838 | if opts[o]: |
|
838 | if opts[o]: | |
839 | l = [f(n) for n, dummy in lines] |
|
839 | l = [f(n) for n, dummy in lines] | |
840 | if l: |
|
840 | if l: | |
841 | m = max(map(len, l)) |
|
841 | m = max(map(len, l)) | |
842 | pieces.append(["%*s" % (m, x) for x in l]) |
|
842 | pieces.append(["%*s" % (m, x) for x in l]) | |
843 |
|
843 | |||
844 | if pieces: |
|
844 | if pieces: | |
845 | for p, l in zip(zip(*pieces), lines): |
|
845 | for p, l in zip(zip(*pieces), lines): | |
846 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
846 | ui.write("%s: %s" % (" ".join(p), l[1])) | |
847 |
|
847 | |||
848 | def bundle(ui, repo, fname, dest="default-push", **opts): |
|
848 | def bundle(ui, repo, fname, dest="default-push", **opts): | |
849 | """create a changegroup file |
|
849 | """create a changegroup file | |
850 |
|
850 | |||
851 | Generate a compressed changegroup file collecting all changesets |
|
851 | Generate a compressed changegroup file collecting all changesets | |
852 | not found in the other repository. |
|
852 | not found in the other repository. | |
853 |
|
853 | |||
854 | This file can then be transferred using conventional means and |
|
854 | This file can then be transferred using conventional means and | |
855 | applied to another repository with the unbundle command. This is |
|
855 | applied to another repository with the unbundle command. This is | |
856 | useful when native push and pull are not available or when |
|
856 | useful when native push and pull are not available or when | |
857 | exporting an entire repository is undesirable. The standard file |
|
857 | exporting an entire repository is undesirable. The standard file | |
858 | extension is ".hg". |
|
858 | extension is ".hg". | |
859 |
|
859 | |||
860 | Unlike import/export, this exactly preserves all changeset |
|
860 | Unlike import/export, this exactly preserves all changeset | |
861 | contents including permissions, rename data, and revision history. |
|
861 | contents including permissions, rename data, and revision history. | |
862 | """ |
|
862 | """ | |
863 | dest = ui.expandpath(dest) |
|
863 | dest = ui.expandpath(dest) | |
864 | other = hg.repository(ui, dest) |
|
864 | other = hg.repository(ui, dest) | |
865 | o = repo.findoutgoing(other) |
|
865 | o = repo.findoutgoing(other, force=opts['force']) | |
866 | cg = repo.changegroup(o, 'bundle') |
|
866 | cg = repo.changegroup(o, 'bundle') | |
867 | write_bundle(cg, fname) |
|
867 | write_bundle(cg, fname) | |
868 |
|
868 | |||
869 | def cat(ui, repo, file1, *pats, **opts): |
|
869 | def cat(ui, repo, file1, *pats, **opts): | |
870 | """output the latest or given revisions of files |
|
870 | """output the latest or given revisions of files | |
871 |
|
871 | |||
872 | Print the specified files as they were at the given revision. |
|
872 | Print the specified files as they were at the given revision. | |
873 | If no revision is given then the tip is used. |
|
873 | If no revision is given then the tip is used. | |
874 |
|
874 | |||
875 | Output may be to a file, in which case the name of the file is |
|
875 | Output may be to a file, in which case the name of the file is | |
876 | given using a format string. The formatting rules are the same as |
|
876 | given using a format string. The formatting rules are the same as | |
877 | for the export command, with the following additions: |
|
877 | for the export command, with the following additions: | |
878 |
|
878 | |||
879 | %s basename of file being printed |
|
879 | %s basename of file being printed | |
880 | %d dirname of file being printed, or '.' if in repo root |
|
880 | %d dirname of file being printed, or '.' if in repo root | |
881 | %p root-relative path name of file being printed |
|
881 | %p root-relative path name of file being printed | |
882 | """ |
|
882 | """ | |
883 | mf = {} |
|
883 | mf = {} | |
884 | rev = opts['rev'] |
|
884 | rev = opts['rev'] | |
885 | if rev: |
|
885 | if rev: | |
886 | node = repo.lookup(rev) |
|
886 | node = repo.lookup(rev) | |
887 | else: |
|
887 | else: | |
888 | node = repo.changelog.tip() |
|
888 | node = repo.changelog.tip() | |
889 | change = repo.changelog.read(node) |
|
889 | change = repo.changelog.read(node) | |
890 | mf = repo.manifest.read(change[0]) |
|
890 | mf = repo.manifest.read(change[0]) | |
891 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): |
|
891 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): | |
892 | r = repo.file(abs) |
|
892 | r = repo.file(abs) | |
893 | n = mf[abs] |
|
893 | n = mf[abs] | |
894 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) |
|
894 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) | |
895 | fp.write(r.read(n)) |
|
895 | fp.write(r.read(n)) | |
896 |
|
896 | |||
897 | def clone(ui, source, dest=None, **opts): |
|
897 | def clone(ui, source, dest=None, **opts): | |
898 | """make a copy of an existing repository |
|
898 | """make a copy of an existing repository | |
899 |
|
899 | |||
900 | Create a copy of an existing repository in a new directory. |
|
900 | Create a copy of an existing repository in a new directory. | |
901 |
|
901 | |||
902 | If no destination directory name is specified, it defaults to the |
|
902 | If no destination directory name is specified, it defaults to the | |
903 | basename of the source. |
|
903 | basename of the source. | |
904 |
|
904 | |||
905 | The location of the source is added to the new repository's |
|
905 | The location of the source is added to the new repository's | |
906 | .hg/hgrc file, as the default to be used for future pulls. |
|
906 | .hg/hgrc file, as the default to be used for future pulls. | |
907 |
|
907 | |||
908 | For efficiency, hardlinks are used for cloning whenever the source |
|
908 | For efficiency, hardlinks are used for cloning whenever the source | |
909 | and destination are on the same filesystem. Some filesystems, |
|
909 | and destination are on the same filesystem. Some filesystems, | |
910 | such as AFS, implement hardlinking incorrectly, but do not report |
|
910 | such as AFS, implement hardlinking incorrectly, but do not report | |
911 | errors. In these cases, use the --pull option to avoid |
|
911 | errors. In these cases, use the --pull option to avoid | |
912 | hardlinking. |
|
912 | hardlinking. | |
913 |
|
913 | |||
914 | See pull for valid source format details. |
|
914 | See pull for valid source format details. | |
915 | """ |
|
915 | """ | |
916 | if dest is None: |
|
916 | if dest is None: | |
917 | dest = os.path.basename(os.path.normpath(source)) |
|
917 | dest = os.path.basename(os.path.normpath(source)) | |
918 |
|
918 | |||
919 | if os.path.exists(dest): |
|
919 | if os.path.exists(dest): | |
920 | raise util.Abort(_("destination '%s' already exists"), dest) |
|
920 | raise util.Abort(_("destination '%s' already exists"), dest) | |
921 |
|
921 | |||
922 | dest = os.path.realpath(dest) |
|
922 | dest = os.path.realpath(dest) | |
923 |
|
923 | |||
924 | class Dircleanup(object): |
|
924 | class Dircleanup(object): | |
925 | def __init__(self, dir_): |
|
925 | def __init__(self, dir_): | |
926 | self.rmtree = shutil.rmtree |
|
926 | self.rmtree = shutil.rmtree | |
927 | self.dir_ = dir_ |
|
927 | self.dir_ = dir_ | |
928 | os.mkdir(dir_) |
|
928 | os.mkdir(dir_) | |
929 | def close(self): |
|
929 | def close(self): | |
930 | self.dir_ = None |
|
930 | self.dir_ = None | |
931 | def __del__(self): |
|
931 | def __del__(self): | |
932 | if self.dir_: |
|
932 | if self.dir_: | |
933 | self.rmtree(self.dir_, True) |
|
933 | self.rmtree(self.dir_, True) | |
934 |
|
934 | |||
935 | if opts['ssh']: |
|
935 | if opts['ssh']: | |
936 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
936 | ui.setconfig("ui", "ssh", opts['ssh']) | |
937 | if opts['remotecmd']: |
|
937 | if opts['remotecmd']: | |
938 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
938 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
939 |
|
939 | |||
940 | source = ui.expandpath(source) |
|
940 | source = ui.expandpath(source) | |
941 |
|
941 | |||
942 | d = Dircleanup(dest) |
|
942 | d = Dircleanup(dest) | |
943 | abspath = source |
|
943 | abspath = source | |
944 | other = hg.repository(ui, source) |
|
944 | other = hg.repository(ui, source) | |
945 |
|
945 | |||
946 | copy = False |
|
946 | copy = False | |
947 | if other.dev() != -1: |
|
947 | if other.dev() != -1: | |
948 | abspath = os.path.abspath(source) |
|
948 | abspath = os.path.abspath(source) | |
949 | if not opts['pull'] and not opts['rev']: |
|
949 | if not opts['pull'] and not opts['rev']: | |
950 | copy = True |
|
950 | copy = True | |
951 |
|
951 | |||
952 | if copy: |
|
952 | if copy: | |
953 | try: |
|
953 | try: | |
954 | # we use a lock here because if we race with commit, we |
|
954 | # we use a lock here because if we race with commit, we | |
955 | # can end up with extra data in the cloned revlogs that's |
|
955 | # can end up with extra data in the cloned revlogs that's | |
956 | # not pointed to by changesets, thus causing verify to |
|
956 | # not pointed to by changesets, thus causing verify to | |
957 | # fail |
|
957 | # fail | |
958 | l1 = other.lock() |
|
958 | l1 = other.lock() | |
959 | except lock.LockException: |
|
959 | except lock.LockException: | |
960 | copy = False |
|
960 | copy = False | |
961 |
|
961 | |||
962 | if copy: |
|
962 | if copy: | |
963 | # we lock here to avoid premature writing to the target |
|
963 | # we lock here to avoid premature writing to the target | |
964 | os.mkdir(os.path.join(dest, ".hg")) |
|
964 | os.mkdir(os.path.join(dest, ".hg")) | |
965 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) |
|
965 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) | |
966 |
|
966 | |||
967 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" |
|
967 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" | |
968 | for f in files.split(): |
|
968 | for f in files.split(): | |
969 | src = os.path.join(source, ".hg", f) |
|
969 | src = os.path.join(source, ".hg", f) | |
970 | dst = os.path.join(dest, ".hg", f) |
|
970 | dst = os.path.join(dest, ".hg", f) | |
971 | try: |
|
971 | try: | |
972 | util.copyfiles(src, dst) |
|
972 | util.copyfiles(src, dst) | |
973 | except OSError, inst: |
|
973 | except OSError, inst: | |
974 | if inst.errno != errno.ENOENT: |
|
974 | if inst.errno != errno.ENOENT: | |
975 | raise |
|
975 | raise | |
976 |
|
976 | |||
977 | repo = hg.repository(ui, dest) |
|
977 | repo = hg.repository(ui, dest) | |
978 |
|
978 | |||
979 | else: |
|
979 | else: | |
980 | revs = None |
|
980 | revs = None | |
981 | if opts['rev']: |
|
981 | if opts['rev']: | |
982 | if not other.local(): |
|
982 | if not other.local(): | |
983 | error = _("clone -r not supported yet for remote repositories.") |
|
983 | error = _("clone -r not supported yet for remote repositories.") | |
984 | raise util.Abort(error) |
|
984 | raise util.Abort(error) | |
985 | else: |
|
985 | else: | |
986 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
986 | revs = [other.lookup(rev) for rev in opts['rev']] | |
987 | repo = hg.repository(ui, dest, create=1) |
|
987 | repo = hg.repository(ui, dest, create=1) | |
988 | repo.pull(other, heads = revs) |
|
988 | repo.pull(other, heads = revs) | |
989 |
|
989 | |||
990 | f = repo.opener("hgrc", "w", text=True) |
|
990 | f = repo.opener("hgrc", "w", text=True) | |
991 | f.write("[paths]\n") |
|
991 | f.write("[paths]\n") | |
992 | f.write("default = %s\n" % abspath) |
|
992 | f.write("default = %s\n" % abspath) | |
993 | f.close() |
|
993 | f.close() | |
994 |
|
994 | |||
995 | if not opts['noupdate']: |
|
995 | if not opts['noupdate']: | |
996 | update(repo.ui, repo) |
|
996 | update(repo.ui, repo) | |
997 |
|
997 | |||
998 | d.close() |
|
998 | d.close() | |
999 |
|
999 | |||
1000 | def commit(ui, repo, *pats, **opts): |
|
1000 | def commit(ui, repo, *pats, **opts): | |
1001 | """commit the specified files or all outstanding changes |
|
1001 | """commit the specified files or all outstanding changes | |
1002 |
|
1002 | |||
1003 | Commit changes to the given files into the repository. |
|
1003 | Commit changes to the given files into the repository. | |
1004 |
|
1004 | |||
1005 | If a list of files is omitted, all changes reported by "hg status" |
|
1005 | If a list of files is omitted, all changes reported by "hg status" | |
1006 | will be commited. |
|
1006 | will be commited. | |
1007 |
|
1007 | |||
1008 | The HGEDITOR or EDITOR environment variables are used to start an |
|
1008 | The HGEDITOR or EDITOR environment variables are used to start an | |
1009 | editor to add a commit comment. |
|
1009 | editor to add a commit comment. | |
1010 | """ |
|
1010 | """ | |
1011 | message = opts['message'] |
|
1011 | message = opts['message'] | |
1012 | logfile = opts['logfile'] |
|
1012 | logfile = opts['logfile'] | |
1013 |
|
1013 | |||
1014 | if message and logfile: |
|
1014 | if message and logfile: | |
1015 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
1015 | raise util.Abort(_('options --message and --logfile are mutually ' | |
1016 | 'exclusive')) |
|
1016 | 'exclusive')) | |
1017 | if not message and logfile: |
|
1017 | if not message and logfile: | |
1018 | try: |
|
1018 | try: | |
1019 | if logfile == '-': |
|
1019 | if logfile == '-': | |
1020 | message = sys.stdin.read() |
|
1020 | message = sys.stdin.read() | |
1021 | else: |
|
1021 | else: | |
1022 | message = open(logfile).read() |
|
1022 | message = open(logfile).read() | |
1023 | except IOError, inst: |
|
1023 | except IOError, inst: | |
1024 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
1024 | raise util.Abort(_("can't read commit message '%s': %s") % | |
1025 | (logfile, inst.strerror)) |
|
1025 | (logfile, inst.strerror)) | |
1026 |
|
1026 | |||
1027 | if opts['addremove']: |
|
1027 | if opts['addremove']: | |
1028 | addremove(ui, repo, *pats, **opts) |
|
1028 | addremove(ui, repo, *pats, **opts) | |
1029 | fns, match, anypats = matchpats(repo, pats, opts) |
|
1029 | fns, match, anypats = matchpats(repo, pats, opts) | |
1030 | if pats: |
|
1030 | if pats: | |
1031 | modified, added, removed, deleted, unknown = ( |
|
1031 | modified, added, removed, deleted, unknown = ( | |
1032 | repo.changes(files=fns, match=match)) |
|
1032 | repo.changes(files=fns, match=match)) | |
1033 | files = modified + added + removed |
|
1033 | files = modified + added + removed | |
1034 | else: |
|
1034 | else: | |
1035 | files = [] |
|
1035 | files = [] | |
1036 | try: |
|
1036 | try: | |
1037 | repo.commit(files, message, opts['user'], opts['date'], match) |
|
1037 | repo.commit(files, message, opts['user'], opts['date'], match) | |
1038 | except ValueError, inst: |
|
1038 | except ValueError, inst: | |
1039 | raise util.Abort(str(inst)) |
|
1039 | raise util.Abort(str(inst)) | |
1040 |
|
1040 | |||
1041 | def docopy(ui, repo, pats, opts, wlock): |
|
1041 | def docopy(ui, repo, pats, opts, wlock): | |
1042 | # called with the repo lock held |
|
1042 | # called with the repo lock held | |
1043 | cwd = repo.getcwd() |
|
1043 | cwd = repo.getcwd() | |
1044 | errors = 0 |
|
1044 | errors = 0 | |
1045 | copied = [] |
|
1045 | copied = [] | |
1046 | targets = {} |
|
1046 | targets = {} | |
1047 |
|
1047 | |||
1048 | def okaytocopy(abs, rel, exact): |
|
1048 | def okaytocopy(abs, rel, exact): | |
1049 | reasons = {'?': _('is not managed'), |
|
1049 | reasons = {'?': _('is not managed'), | |
1050 | 'a': _('has been marked for add'), |
|
1050 | 'a': _('has been marked for add'), | |
1051 | 'r': _('has been marked for remove')} |
|
1051 | 'r': _('has been marked for remove')} | |
1052 | state = repo.dirstate.state(abs) |
|
1052 | state = repo.dirstate.state(abs) | |
1053 | reason = reasons.get(state) |
|
1053 | reason = reasons.get(state) | |
1054 | if reason: |
|
1054 | if reason: | |
1055 | if state == 'a': |
|
1055 | if state == 'a': | |
1056 | origsrc = repo.dirstate.copied(abs) |
|
1056 | origsrc = repo.dirstate.copied(abs) | |
1057 | if origsrc is not None: |
|
1057 | if origsrc is not None: | |
1058 | return origsrc |
|
1058 | return origsrc | |
1059 | if exact: |
|
1059 | if exact: | |
1060 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
1060 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | |
1061 | else: |
|
1061 | else: | |
1062 | return abs |
|
1062 | return abs | |
1063 |
|
1063 | |||
1064 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
1064 | def copy(origsrc, abssrc, relsrc, target, exact): | |
1065 | abstarget = util.canonpath(repo.root, cwd, target) |
|
1065 | abstarget = util.canonpath(repo.root, cwd, target) | |
1066 | reltarget = util.pathto(cwd, abstarget) |
|
1066 | reltarget = util.pathto(cwd, abstarget) | |
1067 | prevsrc = targets.get(abstarget) |
|
1067 | prevsrc = targets.get(abstarget) | |
1068 | if prevsrc is not None: |
|
1068 | if prevsrc is not None: | |
1069 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
1069 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
1070 | (reltarget, abssrc, prevsrc)) |
|
1070 | (reltarget, abssrc, prevsrc)) | |
1071 | return |
|
1071 | return | |
1072 | if (not opts['after'] and os.path.exists(reltarget) or |
|
1072 | if (not opts['after'] and os.path.exists(reltarget) or | |
1073 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
1073 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | |
1074 | if not opts['force']: |
|
1074 | if not opts['force']: | |
1075 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
1075 | ui.warn(_('%s: not overwriting - file exists\n') % | |
1076 | reltarget) |
|
1076 | reltarget) | |
1077 | return |
|
1077 | return | |
1078 | if not opts['after']: |
|
1078 | if not opts['after']: | |
1079 | os.unlink(reltarget) |
|
1079 | os.unlink(reltarget) | |
1080 | if opts['after']: |
|
1080 | if opts['after']: | |
1081 | if not os.path.exists(reltarget): |
|
1081 | if not os.path.exists(reltarget): | |
1082 | return |
|
1082 | return | |
1083 | else: |
|
1083 | else: | |
1084 | targetdir = os.path.dirname(reltarget) or '.' |
|
1084 | targetdir = os.path.dirname(reltarget) or '.' | |
1085 | if not os.path.isdir(targetdir): |
|
1085 | if not os.path.isdir(targetdir): | |
1086 | os.makedirs(targetdir) |
|
1086 | os.makedirs(targetdir) | |
1087 | try: |
|
1087 | try: | |
1088 | restore = repo.dirstate.state(abstarget) == 'r' |
|
1088 | restore = repo.dirstate.state(abstarget) == 'r' | |
1089 | if restore: |
|
1089 | if restore: | |
1090 | repo.undelete([abstarget], wlock) |
|
1090 | repo.undelete([abstarget], wlock) | |
1091 | try: |
|
1091 | try: | |
1092 | shutil.copyfile(relsrc, reltarget) |
|
1092 | shutil.copyfile(relsrc, reltarget) | |
1093 | shutil.copymode(relsrc, reltarget) |
|
1093 | shutil.copymode(relsrc, reltarget) | |
1094 | restore = False |
|
1094 | restore = False | |
1095 | finally: |
|
1095 | finally: | |
1096 | if restore: |
|
1096 | if restore: | |
1097 | repo.remove([abstarget], wlock) |
|
1097 | repo.remove([abstarget], wlock) | |
1098 | except shutil.Error, inst: |
|
1098 | except shutil.Error, inst: | |
1099 | raise util.Abort(str(inst)) |
|
1099 | raise util.Abort(str(inst)) | |
1100 | except IOError, inst: |
|
1100 | except IOError, inst: | |
1101 | if inst.errno == errno.ENOENT: |
|
1101 | if inst.errno == errno.ENOENT: | |
1102 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
1102 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
1103 | else: |
|
1103 | else: | |
1104 | ui.warn(_('%s: cannot copy - %s\n') % |
|
1104 | ui.warn(_('%s: cannot copy - %s\n') % | |
1105 | (relsrc, inst.strerror)) |
|
1105 | (relsrc, inst.strerror)) | |
1106 | errors += 1 |
|
1106 | errors += 1 | |
1107 | return |
|
1107 | return | |
1108 | if ui.verbose or not exact: |
|
1108 | if ui.verbose or not exact: | |
1109 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
1109 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
1110 | targets[abstarget] = abssrc |
|
1110 | targets[abstarget] = abssrc | |
1111 | if abstarget != origsrc: |
|
1111 | if abstarget != origsrc: | |
1112 | repo.copy(origsrc, abstarget, wlock) |
|
1112 | repo.copy(origsrc, abstarget, wlock) | |
1113 | copied.append((abssrc, relsrc, exact)) |
|
1113 | copied.append((abssrc, relsrc, exact)) | |
1114 |
|
1114 | |||
1115 | def targetpathfn(pat, dest, srcs): |
|
1115 | def targetpathfn(pat, dest, srcs): | |
1116 | if os.path.isdir(pat): |
|
1116 | if os.path.isdir(pat): | |
1117 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1117 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1118 | if destdirexists: |
|
1118 | if destdirexists: | |
1119 | striplen = len(os.path.split(abspfx)[0]) |
|
1119 | striplen = len(os.path.split(abspfx)[0]) | |
1120 | else: |
|
1120 | else: | |
1121 | striplen = len(abspfx) |
|
1121 | striplen = len(abspfx) | |
1122 | if striplen: |
|
1122 | if striplen: | |
1123 | striplen += len(os.sep) |
|
1123 | striplen += len(os.sep) | |
1124 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1124 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1125 | elif destdirexists: |
|
1125 | elif destdirexists: | |
1126 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1126 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1127 | else: |
|
1127 | else: | |
1128 | res = lambda p: dest |
|
1128 | res = lambda p: dest | |
1129 | return res |
|
1129 | return res | |
1130 |
|
1130 | |||
1131 | def targetpathafterfn(pat, dest, srcs): |
|
1131 | def targetpathafterfn(pat, dest, srcs): | |
1132 | if util.patkind(pat, None)[0]: |
|
1132 | if util.patkind(pat, None)[0]: | |
1133 | # a mercurial pattern |
|
1133 | # a mercurial pattern | |
1134 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1134 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1135 | else: |
|
1135 | else: | |
1136 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1136 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1137 | if len(abspfx) < len(srcs[0][0]): |
|
1137 | if len(abspfx) < len(srcs[0][0]): | |
1138 | # A directory. Either the target path contains the last |
|
1138 | # A directory. Either the target path contains the last | |
1139 | # component of the source path or it does not. |
|
1139 | # component of the source path or it does not. | |
1140 | def evalpath(striplen): |
|
1140 | def evalpath(striplen): | |
1141 | score = 0 |
|
1141 | score = 0 | |
1142 | for s in srcs: |
|
1142 | for s in srcs: | |
1143 | t = os.path.join(dest, s[0][striplen:]) |
|
1143 | t = os.path.join(dest, s[0][striplen:]) | |
1144 | if os.path.exists(t): |
|
1144 | if os.path.exists(t): | |
1145 | score += 1 |
|
1145 | score += 1 | |
1146 | return score |
|
1146 | return score | |
1147 |
|
1147 | |||
1148 | striplen = len(abspfx) |
|
1148 | striplen = len(abspfx) | |
1149 | if striplen: |
|
1149 | if striplen: | |
1150 | striplen += len(os.sep) |
|
1150 | striplen += len(os.sep) | |
1151 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
1151 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
1152 | score = evalpath(striplen) |
|
1152 | score = evalpath(striplen) | |
1153 | striplen1 = len(os.path.split(abspfx)[0]) |
|
1153 | striplen1 = len(os.path.split(abspfx)[0]) | |
1154 | if striplen1: |
|
1154 | if striplen1: | |
1155 | striplen1 += len(os.sep) |
|
1155 | striplen1 += len(os.sep) | |
1156 | if evalpath(striplen1) > score: |
|
1156 | if evalpath(striplen1) > score: | |
1157 | striplen = striplen1 |
|
1157 | striplen = striplen1 | |
1158 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1158 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1159 | else: |
|
1159 | else: | |
1160 | # a file |
|
1160 | # a file | |
1161 | if destdirexists: |
|
1161 | if destdirexists: | |
1162 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1162 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1163 | else: |
|
1163 | else: | |
1164 | res = lambda p: dest |
|
1164 | res = lambda p: dest | |
1165 | return res |
|
1165 | return res | |
1166 |
|
1166 | |||
1167 |
|
1167 | |||
1168 | pats = list(pats) |
|
1168 | pats = list(pats) | |
1169 | if not pats: |
|
1169 | if not pats: | |
1170 | raise util.Abort(_('no source or destination specified')) |
|
1170 | raise util.Abort(_('no source or destination specified')) | |
1171 | if len(pats) == 1: |
|
1171 | if len(pats) == 1: | |
1172 | raise util.Abort(_('no destination specified')) |
|
1172 | raise util.Abort(_('no destination specified')) | |
1173 | dest = pats.pop() |
|
1173 | dest = pats.pop() | |
1174 | destdirexists = os.path.isdir(dest) |
|
1174 | destdirexists = os.path.isdir(dest) | |
1175 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
1175 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | |
1176 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
1176 | raise util.Abort(_('with multiple sources, destination must be an ' | |
1177 | 'existing directory')) |
|
1177 | 'existing directory')) | |
1178 | if opts['after']: |
|
1178 | if opts['after']: | |
1179 | tfn = targetpathafterfn |
|
1179 | tfn = targetpathafterfn | |
1180 | else: |
|
1180 | else: | |
1181 | tfn = targetpathfn |
|
1181 | tfn = targetpathfn | |
1182 | copylist = [] |
|
1182 | copylist = [] | |
1183 | for pat in pats: |
|
1183 | for pat in pats: | |
1184 | srcs = [] |
|
1184 | srcs = [] | |
1185 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): |
|
1185 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | |
1186 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
1186 | origsrc = okaytocopy(abssrc, relsrc, exact) | |
1187 | if origsrc: |
|
1187 | if origsrc: | |
1188 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
1188 | srcs.append((origsrc, abssrc, relsrc, exact)) | |
1189 | if not srcs: |
|
1189 | if not srcs: | |
1190 | continue |
|
1190 | continue | |
1191 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
1191 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
1192 | if not copylist: |
|
1192 | if not copylist: | |
1193 | raise util.Abort(_('no files to copy')) |
|
1193 | raise util.Abort(_('no files to copy')) | |
1194 |
|
1194 | |||
1195 | for targetpath, srcs in copylist: |
|
1195 | for targetpath, srcs in copylist: | |
1196 | for origsrc, abssrc, relsrc, exact in srcs: |
|
1196 | for origsrc, abssrc, relsrc, exact in srcs: | |
1197 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
1197 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | |
1198 |
|
1198 | |||
1199 | if errors: |
|
1199 | if errors: | |
1200 | ui.warn(_('(consider using --after)\n')) |
|
1200 | ui.warn(_('(consider using --after)\n')) | |
1201 | return errors, copied |
|
1201 | return errors, copied | |
1202 |
|
1202 | |||
1203 | def copy(ui, repo, *pats, **opts): |
|
1203 | def copy(ui, repo, *pats, **opts): | |
1204 | """mark files as copied for the next commit |
|
1204 | """mark files as copied for the next commit | |
1205 |
|
1205 | |||
1206 | Mark dest as having copies of source files. If dest is a |
|
1206 | Mark dest as having copies of source files. If dest is a | |
1207 | directory, copies are put in that directory. If dest is a file, |
|
1207 | directory, copies are put in that directory. If dest is a file, | |
1208 | there can only be one source. |
|
1208 | there can only be one source. | |
1209 |
|
1209 | |||
1210 | By default, this command copies the contents of files as they |
|
1210 | By default, this command copies the contents of files as they | |
1211 | stand in the working directory. If invoked with --after, the |
|
1211 | stand in the working directory. If invoked with --after, the | |
1212 | operation is recorded, but no copying is performed. |
|
1212 | operation is recorded, but no copying is performed. | |
1213 |
|
1213 | |||
1214 | This command takes effect in the next commit. |
|
1214 | This command takes effect in the next commit. | |
1215 |
|
1215 | |||
1216 | NOTE: This command should be treated as experimental. While it |
|
1216 | NOTE: This command should be treated as experimental. While it | |
1217 | should properly record copied files, this information is not yet |
|
1217 | should properly record copied files, this information is not yet | |
1218 | fully used by merge, nor fully reported by log. |
|
1218 | fully used by merge, nor fully reported by log. | |
1219 | """ |
|
1219 | """ | |
1220 | try: |
|
1220 | try: | |
1221 | wlock = repo.wlock(0) |
|
1221 | wlock = repo.wlock(0) | |
1222 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1222 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
1223 | except lock.LockHeld, inst: |
|
1223 | except lock.LockHeld, inst: | |
1224 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) |
|
1224 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) | |
1225 | errs = 1 |
|
1225 | errs = 1 | |
1226 | return errs |
|
1226 | return errs | |
1227 |
|
1227 | |||
1228 | def debugancestor(ui, index, rev1, rev2): |
|
1228 | def debugancestor(ui, index, rev1, rev2): | |
1229 | """find the ancestor revision of two revisions in a given index""" |
|
1229 | """find the ancestor revision of two revisions in a given index""" | |
1230 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") |
|
1230 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "") | |
1231 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1231 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | |
1232 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1232 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | |
1233 |
|
1233 | |||
1234 | def debugcomplete(ui, cmd): |
|
1234 | def debugcomplete(ui, cmd): | |
1235 | """returns the completion list associated with the given command""" |
|
1235 | """returns the completion list associated with the given command""" | |
1236 | clist = findpossible(cmd).keys() |
|
1236 | clist = findpossible(cmd).keys() | |
1237 | clist.sort() |
|
1237 | clist.sort() | |
1238 | ui.write("%s\n" % " ".join(clist)) |
|
1238 | ui.write("%s\n" % " ".join(clist)) | |
1239 |
|
1239 | |||
1240 | def debugrebuildstate(ui, repo, rev=None): |
|
1240 | def debugrebuildstate(ui, repo, rev=None): | |
1241 | """rebuild the dirstate as it would look like for the given revision""" |
|
1241 | """rebuild the dirstate as it would look like for the given revision""" | |
1242 | if not rev: |
|
1242 | if not rev: | |
1243 | rev = repo.changelog.tip() |
|
1243 | rev = repo.changelog.tip() | |
1244 | else: |
|
1244 | else: | |
1245 | rev = repo.lookup(rev) |
|
1245 | rev = repo.lookup(rev) | |
1246 | change = repo.changelog.read(rev) |
|
1246 | change = repo.changelog.read(rev) | |
1247 | n = change[0] |
|
1247 | n = change[0] | |
1248 | files = repo.manifest.readflags(n) |
|
1248 | files = repo.manifest.readflags(n) | |
1249 | wlock = repo.wlock() |
|
1249 | wlock = repo.wlock() | |
1250 | repo.dirstate.rebuild(rev, files.iteritems()) |
|
1250 | repo.dirstate.rebuild(rev, files.iteritems()) | |
1251 |
|
1251 | |||
1252 | def debugcheckstate(ui, repo): |
|
1252 | def debugcheckstate(ui, repo): | |
1253 | """validate the correctness of the current dirstate""" |
|
1253 | """validate the correctness of the current dirstate""" | |
1254 | parent1, parent2 = repo.dirstate.parents() |
|
1254 | parent1, parent2 = repo.dirstate.parents() | |
1255 | repo.dirstate.read() |
|
1255 | repo.dirstate.read() | |
1256 | dc = repo.dirstate.map |
|
1256 | dc = repo.dirstate.map | |
1257 | keys = dc.keys() |
|
1257 | keys = dc.keys() | |
1258 | keys.sort() |
|
1258 | keys.sort() | |
1259 | m1n = repo.changelog.read(parent1)[0] |
|
1259 | m1n = repo.changelog.read(parent1)[0] | |
1260 | m2n = repo.changelog.read(parent2)[0] |
|
1260 | m2n = repo.changelog.read(parent2)[0] | |
1261 | m1 = repo.manifest.read(m1n) |
|
1261 | m1 = repo.manifest.read(m1n) | |
1262 | m2 = repo.manifest.read(m2n) |
|
1262 | m2 = repo.manifest.read(m2n) | |
1263 | errors = 0 |
|
1263 | errors = 0 | |
1264 | for f in dc: |
|
1264 | for f in dc: | |
1265 | state = repo.dirstate.state(f) |
|
1265 | state = repo.dirstate.state(f) | |
1266 | if state in "nr" and f not in m1: |
|
1266 | if state in "nr" and f not in m1: | |
1267 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1267 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | |
1268 | errors += 1 |
|
1268 | errors += 1 | |
1269 | if state in "a" and f in m1: |
|
1269 | if state in "a" and f in m1: | |
1270 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1270 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | |
1271 | errors += 1 |
|
1271 | errors += 1 | |
1272 | if state in "m" and f not in m1 and f not in m2: |
|
1272 | if state in "m" and f not in m1 and f not in m2: | |
1273 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1273 | ui.warn(_("%s in state %s, but not in either manifest\n") % | |
1274 | (f, state)) |
|
1274 | (f, state)) | |
1275 | errors += 1 |
|
1275 | errors += 1 | |
1276 | for f in m1: |
|
1276 | for f in m1: | |
1277 | state = repo.dirstate.state(f) |
|
1277 | state = repo.dirstate.state(f) | |
1278 | if state not in "nrm": |
|
1278 | if state not in "nrm": | |
1279 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1279 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | |
1280 | errors += 1 |
|
1280 | errors += 1 | |
1281 | if errors: |
|
1281 | if errors: | |
1282 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1282 | error = _(".hg/dirstate inconsistent with current parent's manifest") | |
1283 | raise util.Abort(error) |
|
1283 | raise util.Abort(error) | |
1284 |
|
1284 | |||
1285 | def debugconfig(ui, repo): |
|
1285 | def debugconfig(ui, repo): | |
1286 | """show combined config settings from all hgrc files""" |
|
1286 | """show combined config settings from all hgrc files""" | |
1287 | for section, name, value in ui.walkconfig(): |
|
1287 | for section, name, value in ui.walkconfig(): | |
1288 | ui.write('%s.%s=%s\n' % (section, name, value)) |
|
1288 | ui.write('%s.%s=%s\n' % (section, name, value)) | |
1289 |
|
1289 | |||
1290 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
1290 | def debugsetparents(ui, repo, rev1, rev2=None): | |
1291 | """manually set the parents of the current working directory |
|
1291 | """manually set the parents of the current working directory | |
1292 |
|
1292 | |||
1293 | This is useful for writing repository conversion tools, but should |
|
1293 | This is useful for writing repository conversion tools, but should | |
1294 | be used with care. |
|
1294 | be used with care. | |
1295 | """ |
|
1295 | """ | |
1296 |
|
1296 | |||
1297 | if not rev2: |
|
1297 | if not rev2: | |
1298 | rev2 = hex(nullid) |
|
1298 | rev2 = hex(nullid) | |
1299 |
|
1299 | |||
1300 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
1300 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | |
1301 |
|
1301 | |||
1302 | def debugstate(ui, repo): |
|
1302 | def debugstate(ui, repo): | |
1303 | """show the contents of the current dirstate""" |
|
1303 | """show the contents of the current dirstate""" | |
1304 | repo.dirstate.read() |
|
1304 | repo.dirstate.read() | |
1305 | dc = repo.dirstate.map |
|
1305 | dc = repo.dirstate.map | |
1306 | keys = dc.keys() |
|
1306 | keys = dc.keys() | |
1307 | keys.sort() |
|
1307 | keys.sort() | |
1308 | for file_ in keys: |
|
1308 | for file_ in keys: | |
1309 | ui.write("%c %3o %10d %s %s\n" |
|
1309 | ui.write("%c %3o %10d %s %s\n" | |
1310 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
1310 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | |
1311 | time.strftime("%x %X", |
|
1311 | time.strftime("%x %X", | |
1312 | time.localtime(dc[file_][3])), file_)) |
|
1312 | time.localtime(dc[file_][3])), file_)) | |
1313 | for f in repo.dirstate.copies: |
|
1313 | for f in repo.dirstate.copies: | |
1314 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) |
|
1314 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) | |
1315 |
|
1315 | |||
1316 | def debugdata(ui, file_, rev): |
|
1316 | def debugdata(ui, file_, rev): | |
1317 | """dump the contents of an data file revision""" |
|
1317 | """dump the contents of an data file revision""" | |
1318 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
1318 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | |
1319 | file_[:-2] + ".i", file_) |
|
1319 | file_[:-2] + ".i", file_) | |
1320 | try: |
|
1320 | try: | |
1321 | ui.write(r.revision(r.lookup(rev))) |
|
1321 | ui.write(r.revision(r.lookup(rev))) | |
1322 | except KeyError: |
|
1322 | except KeyError: | |
1323 | raise util.Abort(_('invalid revision identifier %s'), rev) |
|
1323 | raise util.Abort(_('invalid revision identifier %s'), rev) | |
1324 |
|
1324 | |||
1325 | def debugindex(ui, file_): |
|
1325 | def debugindex(ui, file_): | |
1326 | """dump the contents of an index file""" |
|
1326 | """dump the contents of an index file""" | |
1327 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") |
|
1327 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | |
1328 | ui.write(" rev offset length base linkrev" + |
|
1328 | ui.write(" rev offset length base linkrev" + | |
1329 | " nodeid p1 p2\n") |
|
1329 | " nodeid p1 p2\n") | |
1330 | for i in range(r.count()): |
|
1330 | for i in range(r.count()): | |
1331 | e = r.index[i] |
|
1331 | e = r.index[i] | |
1332 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1332 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
1333 | i, e[0], e[1], e[2], e[3], |
|
1333 | i, e[0], e[1], e[2], e[3], | |
1334 | short(e[6]), short(e[4]), short(e[5]))) |
|
1334 | short(e[6]), short(e[4]), short(e[5]))) | |
1335 |
|
1335 | |||
1336 | def debugindexdot(ui, file_): |
|
1336 | def debugindexdot(ui, file_): | |
1337 | """dump an index DAG as a .dot file""" |
|
1337 | """dump an index DAG as a .dot file""" | |
1338 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") |
|
1338 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "") | |
1339 | ui.write("digraph G {\n") |
|
1339 | ui.write("digraph G {\n") | |
1340 | for i in range(r.count()): |
|
1340 | for i in range(r.count()): | |
1341 | e = r.index[i] |
|
1341 | e = r.index[i] | |
1342 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) |
|
1342 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) | |
1343 | if e[5] != nullid: |
|
1343 | if e[5] != nullid: | |
1344 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) |
|
1344 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) | |
1345 | ui.write("}\n") |
|
1345 | ui.write("}\n") | |
1346 |
|
1346 | |||
1347 | def debugrename(ui, repo, file, rev=None): |
|
1347 | def debugrename(ui, repo, file, rev=None): | |
1348 | """dump rename information""" |
|
1348 | """dump rename information""" | |
1349 | r = repo.file(relpath(repo, [file])[0]) |
|
1349 | r = repo.file(relpath(repo, [file])[0]) | |
1350 | if rev: |
|
1350 | if rev: | |
1351 | try: |
|
1351 | try: | |
1352 | # assume all revision numbers are for changesets |
|
1352 | # assume all revision numbers are for changesets | |
1353 | n = repo.lookup(rev) |
|
1353 | n = repo.lookup(rev) | |
1354 | change = repo.changelog.read(n) |
|
1354 | change = repo.changelog.read(n) | |
1355 | m = repo.manifest.read(change[0]) |
|
1355 | m = repo.manifest.read(change[0]) | |
1356 | n = m[relpath(repo, [file])[0]] |
|
1356 | n = m[relpath(repo, [file])[0]] | |
1357 | except (hg.RepoError, KeyError): |
|
1357 | except (hg.RepoError, KeyError): | |
1358 | n = r.lookup(rev) |
|
1358 | n = r.lookup(rev) | |
1359 | else: |
|
1359 | else: | |
1360 | n = r.tip() |
|
1360 | n = r.tip() | |
1361 | m = r.renamed(n) |
|
1361 | m = r.renamed(n) | |
1362 | if m: |
|
1362 | if m: | |
1363 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) |
|
1363 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) | |
1364 | else: |
|
1364 | else: | |
1365 | ui.write(_("not renamed\n")) |
|
1365 | ui.write(_("not renamed\n")) | |
1366 |
|
1366 | |||
1367 | def debugwalk(ui, repo, *pats, **opts): |
|
1367 | def debugwalk(ui, repo, *pats, **opts): | |
1368 | """show how files match on given patterns""" |
|
1368 | """show how files match on given patterns""" | |
1369 | items = list(walk(repo, pats, opts)) |
|
1369 | items = list(walk(repo, pats, opts)) | |
1370 | if not items: |
|
1370 | if not items: | |
1371 | return |
|
1371 | return | |
1372 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1372 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | |
1373 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1373 | max([len(abs) for (src, abs, rel, exact) in items]), | |
1374 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1374 | max([len(rel) for (src, abs, rel, exact) in items])) | |
1375 | for src, abs, rel, exact in items: |
|
1375 | for src, abs, rel, exact in items: | |
1376 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1376 | line = fmt % (src, abs, rel, exact and 'exact' or '') | |
1377 | ui.write("%s\n" % line.rstrip()) |
|
1377 | ui.write("%s\n" % line.rstrip()) | |
1378 |
|
1378 | |||
1379 | def diff(ui, repo, *pats, **opts): |
|
1379 | def diff(ui, repo, *pats, **opts): | |
1380 | """diff repository (or selected files) |
|
1380 | """diff repository (or selected files) | |
1381 |
|
1381 | |||
1382 | Show differences between revisions for the specified files. |
|
1382 | Show differences between revisions for the specified files. | |
1383 |
|
1383 | |||
1384 | Differences between files are shown using the unified diff format. |
|
1384 | Differences between files are shown using the unified diff format. | |
1385 |
|
1385 | |||
1386 | When two revision arguments are given, then changes are shown |
|
1386 | When two revision arguments are given, then changes are shown | |
1387 | between those revisions. If only one revision is specified then |
|
1387 | between those revisions. If only one revision is specified then | |
1388 | that revision is compared to the working directory, and, when no |
|
1388 | that revision is compared to the working directory, and, when no | |
1389 | revisions are specified, the working directory files are compared |
|
1389 | revisions are specified, the working directory files are compared | |
1390 | to its parent. |
|
1390 | to its parent. | |
1391 |
|
1391 | |||
1392 | Without the -a option, diff will avoid generating diffs of files |
|
1392 | Without the -a option, diff will avoid generating diffs of files | |
1393 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1393 | it detects as binary. With -a, diff will generate a diff anyway, | |
1394 | probably with undesirable results. |
|
1394 | probably with undesirable results. | |
1395 | """ |
|
1395 | """ | |
1396 | node1, node2 = None, None |
|
1396 | node1, node2 = None, None | |
1397 | revs = [repo.lookup(x) for x in opts['rev']] |
|
1397 | revs = [repo.lookup(x) for x in opts['rev']] | |
1398 |
|
1398 | |||
1399 | if len(revs) > 0: |
|
1399 | if len(revs) > 0: | |
1400 | node1 = revs[0] |
|
1400 | node1 = revs[0] | |
1401 | if len(revs) > 1: |
|
1401 | if len(revs) > 1: | |
1402 | node2 = revs[1] |
|
1402 | node2 = revs[1] | |
1403 | if len(revs) > 2: |
|
1403 | if len(revs) > 2: | |
1404 | raise util.Abort(_("too many revisions to diff")) |
|
1404 | raise util.Abort(_("too many revisions to diff")) | |
1405 |
|
1405 | |||
1406 | fns, matchfn, anypats = matchpats(repo, pats, opts) |
|
1406 | fns, matchfn, anypats = matchpats(repo, pats, opts) | |
1407 |
|
1407 | |||
1408 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
|
1408 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | |
1409 | text=opts['text'], opts=opts) |
|
1409 | text=opts['text'], opts=opts) | |
1410 |
|
1410 | |||
1411 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
|
1411 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | |
1412 | node = repo.lookup(changeset) |
|
1412 | node = repo.lookup(changeset) | |
1413 | parents = [p for p in repo.changelog.parents(node) if p != nullid] |
|
1413 | parents = [p for p in repo.changelog.parents(node) if p != nullid] | |
1414 | if opts['switch_parent']: |
|
1414 | if opts['switch_parent']: | |
1415 | parents.reverse() |
|
1415 | parents.reverse() | |
1416 | prev = (parents and parents[0]) or nullid |
|
1416 | prev = (parents and parents[0]) or nullid | |
1417 | change = repo.changelog.read(node) |
|
1417 | change = repo.changelog.read(node) | |
1418 |
|
1418 | |||
1419 | fp = make_file(repo, repo.changelog, opts['output'], |
|
1419 | fp = make_file(repo, repo.changelog, opts['output'], | |
1420 | node=node, total=total, seqno=seqno, |
|
1420 | node=node, total=total, seqno=seqno, | |
1421 | revwidth=revwidth) |
|
1421 | revwidth=revwidth) | |
1422 | if fp != sys.stdout: |
|
1422 | if fp != sys.stdout: | |
1423 | ui.note("%s\n" % fp.name) |
|
1423 | ui.note("%s\n" % fp.name) | |
1424 |
|
1424 | |||
1425 | fp.write("# HG changeset patch\n") |
|
1425 | fp.write("# HG changeset patch\n") | |
1426 | fp.write("# User %s\n" % change[1]) |
|
1426 | fp.write("# User %s\n" % change[1]) | |
1427 | fp.write("# Node ID %s\n" % hex(node)) |
|
1427 | fp.write("# Node ID %s\n" % hex(node)) | |
1428 | fp.write("# Parent %s\n" % hex(prev)) |
|
1428 | fp.write("# Parent %s\n" % hex(prev)) | |
1429 | if len(parents) > 1: |
|
1429 | if len(parents) > 1: | |
1430 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
1430 | fp.write("# Parent %s\n" % hex(parents[1])) | |
1431 | fp.write(change[4].rstrip()) |
|
1431 | fp.write(change[4].rstrip()) | |
1432 | fp.write("\n\n") |
|
1432 | fp.write("\n\n") | |
1433 |
|
1433 | |||
1434 | dodiff(fp, ui, repo, prev, node, text=opts['text']) |
|
1434 | dodiff(fp, ui, repo, prev, node, text=opts['text']) | |
1435 | if fp != sys.stdout: |
|
1435 | if fp != sys.stdout: | |
1436 | fp.close() |
|
1436 | fp.close() | |
1437 |
|
1437 | |||
1438 | def export(ui, repo, *changesets, **opts): |
|
1438 | def export(ui, repo, *changesets, **opts): | |
1439 | """dump the header and diffs for one or more changesets |
|
1439 | """dump the header and diffs for one or more changesets | |
1440 |
|
1440 | |||
1441 | Print the changeset header and diffs for one or more revisions. |
|
1441 | Print the changeset header and diffs for one or more revisions. | |
1442 |
|
1442 | |||
1443 | The information shown in the changeset header is: author, |
|
1443 | The information shown in the changeset header is: author, | |
1444 | changeset hash, parent and commit comment. |
|
1444 | changeset hash, parent and commit comment. | |
1445 |
|
1445 | |||
1446 | Output may be to a file, in which case the name of the file is |
|
1446 | Output may be to a file, in which case the name of the file is | |
1447 | given using a format string. The formatting rules are as follows: |
|
1447 | given using a format string. The formatting rules are as follows: | |
1448 |
|
1448 | |||
1449 | %% literal "%" character |
|
1449 | %% literal "%" character | |
1450 | %H changeset hash (40 bytes of hexadecimal) |
|
1450 | %H changeset hash (40 bytes of hexadecimal) | |
1451 | %N number of patches being generated |
|
1451 | %N number of patches being generated | |
1452 | %R changeset revision number |
|
1452 | %R changeset revision number | |
1453 | %b basename of the exporting repository |
|
1453 | %b basename of the exporting repository | |
1454 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1454 | %h short-form changeset hash (12 bytes of hexadecimal) | |
1455 | %n zero-padded sequence number, starting at 1 |
|
1455 | %n zero-padded sequence number, starting at 1 | |
1456 | %r zero-padded changeset revision number |
|
1456 | %r zero-padded changeset revision number | |
1457 |
|
1457 | |||
1458 | Without the -a option, export will avoid generating diffs of files |
|
1458 | Without the -a option, export will avoid generating diffs of files | |
1459 | it detects as binary. With -a, export will generate a diff anyway, |
|
1459 | it detects as binary. With -a, export will generate a diff anyway, | |
1460 | probably with undesirable results. |
|
1460 | probably with undesirable results. | |
1461 |
|
1461 | |||
1462 | With the --switch-parent option, the diff will be against the second |
|
1462 | With the --switch-parent option, the diff will be against the second | |
1463 | parent. It can be useful to review a merge. |
|
1463 | parent. It can be useful to review a merge. | |
1464 | """ |
|
1464 | """ | |
1465 | if not changesets: |
|
1465 | if not changesets: | |
1466 | raise util.Abort(_("export requires at least one changeset")) |
|
1466 | raise util.Abort(_("export requires at least one changeset")) | |
1467 | seqno = 0 |
|
1467 | seqno = 0 | |
1468 | revs = list(revrange(ui, repo, changesets)) |
|
1468 | revs = list(revrange(ui, repo, changesets)) | |
1469 | total = len(revs) |
|
1469 | total = len(revs) | |
1470 | revwidth = max(map(len, revs)) |
|
1470 | revwidth = max(map(len, revs)) | |
1471 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") |
|
1471 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") | |
1472 | ui.note(msg) |
|
1472 | ui.note(msg) | |
1473 | for cset in revs: |
|
1473 | for cset in revs: | |
1474 | seqno += 1 |
|
1474 | seqno += 1 | |
1475 | doexport(ui, repo, cset, seqno, total, revwidth, opts) |
|
1475 | doexport(ui, repo, cset, seqno, total, revwidth, opts) | |
1476 |
|
1476 | |||
1477 | def forget(ui, repo, *pats, **opts): |
|
1477 | def forget(ui, repo, *pats, **opts): | |
1478 | """don't add the specified files on the next commit |
|
1478 | """don't add the specified files on the next commit | |
1479 |
|
1479 | |||
1480 | Undo an 'hg add' scheduled for the next commit. |
|
1480 | Undo an 'hg add' scheduled for the next commit. | |
1481 | """ |
|
1481 | """ | |
1482 | forget = [] |
|
1482 | forget = [] | |
1483 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
1483 | for src, abs, rel, exact in walk(repo, pats, opts): | |
1484 | if repo.dirstate.state(abs) == 'a': |
|
1484 | if repo.dirstate.state(abs) == 'a': | |
1485 | forget.append(abs) |
|
1485 | forget.append(abs) | |
1486 | if ui.verbose or not exact: |
|
1486 | if ui.verbose or not exact: | |
1487 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
|
1487 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) | |
1488 | repo.forget(forget) |
|
1488 | repo.forget(forget) | |
1489 |
|
1489 | |||
1490 | def grep(ui, repo, pattern, *pats, **opts): |
|
1490 | def grep(ui, repo, pattern, *pats, **opts): | |
1491 | """search for a pattern in specified files and revisions |
|
1491 | """search for a pattern in specified files and revisions | |
1492 |
|
1492 | |||
1493 | Search revisions of files for a regular expression. |
|
1493 | Search revisions of files for a regular expression. | |
1494 |
|
1494 | |||
1495 | This command behaves differently than Unix grep. It only accepts |
|
1495 | This command behaves differently than Unix grep. It only accepts | |
1496 | Python/Perl regexps. It searches repository history, not the |
|
1496 | Python/Perl regexps. It searches repository history, not the | |
1497 | working directory. It always prints the revision number in which |
|
1497 | working directory. It always prints the revision number in which | |
1498 | a match appears. |
|
1498 | a match appears. | |
1499 |
|
1499 | |||
1500 | By default, grep only prints output for the first revision of a |
|
1500 | By default, grep only prints output for the first revision of a | |
1501 | file in which it finds a match. To get it to print every revision |
|
1501 | file in which it finds a match. To get it to print every revision | |
1502 | that contains a change in match status ("-" for a match that |
|
1502 | that contains a change in match status ("-" for a match that | |
1503 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1503 | becomes a non-match, or "+" for a non-match that becomes a match), | |
1504 | use the --all flag. |
|
1504 | use the --all flag. | |
1505 | """ |
|
1505 | """ | |
1506 | reflags = 0 |
|
1506 | reflags = 0 | |
1507 | if opts['ignore_case']: |
|
1507 | if opts['ignore_case']: | |
1508 | reflags |= re.I |
|
1508 | reflags |= re.I | |
1509 | regexp = re.compile(pattern, reflags) |
|
1509 | regexp = re.compile(pattern, reflags) | |
1510 | sep, eol = ':', '\n' |
|
1510 | sep, eol = ':', '\n' | |
1511 | if opts['print0']: |
|
1511 | if opts['print0']: | |
1512 | sep = eol = '\0' |
|
1512 | sep = eol = '\0' | |
1513 |
|
1513 | |||
1514 | fcache = {} |
|
1514 | fcache = {} | |
1515 | def getfile(fn): |
|
1515 | def getfile(fn): | |
1516 | if fn not in fcache: |
|
1516 | if fn not in fcache: | |
1517 | fcache[fn] = repo.file(fn) |
|
1517 | fcache[fn] = repo.file(fn) | |
1518 | return fcache[fn] |
|
1518 | return fcache[fn] | |
1519 |
|
1519 | |||
1520 | def matchlines(body): |
|
1520 | def matchlines(body): | |
1521 | begin = 0 |
|
1521 | begin = 0 | |
1522 | linenum = 0 |
|
1522 | linenum = 0 | |
1523 | while True: |
|
1523 | while True: | |
1524 | match = regexp.search(body, begin) |
|
1524 | match = regexp.search(body, begin) | |
1525 | if not match: |
|
1525 | if not match: | |
1526 | break |
|
1526 | break | |
1527 | mstart, mend = match.span() |
|
1527 | mstart, mend = match.span() | |
1528 | linenum += body.count('\n', begin, mstart) + 1 |
|
1528 | linenum += body.count('\n', begin, mstart) + 1 | |
1529 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1529 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
1530 | lend = body.find('\n', mend) |
|
1530 | lend = body.find('\n', mend) | |
1531 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1531 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
1532 | begin = lend + 1 |
|
1532 | begin = lend + 1 | |
1533 |
|
1533 | |||
1534 | class linestate(object): |
|
1534 | class linestate(object): | |
1535 | def __init__(self, line, linenum, colstart, colend): |
|
1535 | def __init__(self, line, linenum, colstart, colend): | |
1536 | self.line = line |
|
1536 | self.line = line | |
1537 | self.linenum = linenum |
|
1537 | self.linenum = linenum | |
1538 | self.colstart = colstart |
|
1538 | self.colstart = colstart | |
1539 | self.colend = colend |
|
1539 | self.colend = colend | |
1540 | def __eq__(self, other): |
|
1540 | def __eq__(self, other): | |
1541 | return self.line == other.line |
|
1541 | return self.line == other.line | |
1542 | def __hash__(self): |
|
1542 | def __hash__(self): | |
1543 | return hash(self.line) |
|
1543 | return hash(self.line) | |
1544 |
|
1544 | |||
1545 | matches = {} |
|
1545 | matches = {} | |
1546 | def grepbody(fn, rev, body): |
|
1546 | def grepbody(fn, rev, body): | |
1547 | matches[rev].setdefault(fn, {}) |
|
1547 | matches[rev].setdefault(fn, {}) | |
1548 | m = matches[rev][fn] |
|
1548 | m = matches[rev][fn] | |
1549 | for lnum, cstart, cend, line in matchlines(body): |
|
1549 | for lnum, cstart, cend, line in matchlines(body): | |
1550 | s = linestate(line, lnum, cstart, cend) |
|
1550 | s = linestate(line, lnum, cstart, cend) | |
1551 | m[s] = s |
|
1551 | m[s] = s | |
1552 |
|
1552 | |||
1553 | # FIXME: prev isn't used, why ? |
|
1553 | # FIXME: prev isn't used, why ? | |
1554 | prev = {} |
|
1554 | prev = {} | |
1555 | ucache = {} |
|
1555 | ucache = {} | |
1556 | def display(fn, rev, states, prevstates): |
|
1556 | def display(fn, rev, states, prevstates): | |
1557 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) |
|
1557 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) | |
1558 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) |
|
1558 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) | |
1559 | counts = {'-': 0, '+': 0} |
|
1559 | counts = {'-': 0, '+': 0} | |
1560 | filerevmatches = {} |
|
1560 | filerevmatches = {} | |
1561 | for l in diff: |
|
1561 | for l in diff: | |
1562 | if incrementing or not opts['all']: |
|
1562 | if incrementing or not opts['all']: | |
1563 | change = ((l in prevstates) and '-') or '+' |
|
1563 | change = ((l in prevstates) and '-') or '+' | |
1564 | r = rev |
|
1564 | r = rev | |
1565 | else: |
|
1565 | else: | |
1566 | change = ((l in states) and '-') or '+' |
|
1566 | change = ((l in states) and '-') or '+' | |
1567 | r = prev[fn] |
|
1567 | r = prev[fn] | |
1568 | cols = [fn, str(rev)] |
|
1568 | cols = [fn, str(rev)] | |
1569 | if opts['line_number']: |
|
1569 | if opts['line_number']: | |
1570 | cols.append(str(l.linenum)) |
|
1570 | cols.append(str(l.linenum)) | |
1571 | if opts['all']: |
|
1571 | if opts['all']: | |
1572 | cols.append(change) |
|
1572 | cols.append(change) | |
1573 | if opts['user']: |
|
1573 | if opts['user']: | |
1574 | cols.append(trimuser(ui, getchange(rev)[1], rev, |
|
1574 | cols.append(trimuser(ui, getchange(rev)[1], rev, | |
1575 | ucache)) |
|
1575 | ucache)) | |
1576 | if opts['files_with_matches']: |
|
1576 | if opts['files_with_matches']: | |
1577 | c = (fn, rev) |
|
1577 | c = (fn, rev) | |
1578 | if c in filerevmatches: |
|
1578 | if c in filerevmatches: | |
1579 | continue |
|
1579 | continue | |
1580 | filerevmatches[c] = 1 |
|
1580 | filerevmatches[c] = 1 | |
1581 | else: |
|
1581 | else: | |
1582 | cols.append(l.line) |
|
1582 | cols.append(l.line) | |
1583 | ui.write(sep.join(cols), eol) |
|
1583 | ui.write(sep.join(cols), eol) | |
1584 | counts[change] += 1 |
|
1584 | counts[change] += 1 | |
1585 | return counts['+'], counts['-'] |
|
1585 | return counts['+'], counts['-'] | |
1586 |
|
1586 | |||
1587 | fstate = {} |
|
1587 | fstate = {} | |
1588 | skip = {} |
|
1588 | skip = {} | |
1589 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1589 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1590 | count = 0 |
|
1590 | count = 0 | |
1591 | incrementing = False |
|
1591 | incrementing = False | |
1592 | for st, rev, fns in changeiter: |
|
1592 | for st, rev, fns in changeiter: | |
1593 | if st == 'window': |
|
1593 | if st == 'window': | |
1594 | incrementing = rev |
|
1594 | incrementing = rev | |
1595 | matches.clear() |
|
1595 | matches.clear() | |
1596 | elif st == 'add': |
|
1596 | elif st == 'add': | |
1597 | change = repo.changelog.read(repo.lookup(str(rev))) |
|
1597 | change = repo.changelog.read(repo.lookup(str(rev))) | |
1598 | mf = repo.manifest.read(change[0]) |
|
1598 | mf = repo.manifest.read(change[0]) | |
1599 | matches[rev] = {} |
|
1599 | matches[rev] = {} | |
1600 | for fn in fns: |
|
1600 | for fn in fns: | |
1601 | if fn in skip: |
|
1601 | if fn in skip: | |
1602 | continue |
|
1602 | continue | |
1603 | fstate.setdefault(fn, {}) |
|
1603 | fstate.setdefault(fn, {}) | |
1604 | try: |
|
1604 | try: | |
1605 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1605 | grepbody(fn, rev, getfile(fn).read(mf[fn])) | |
1606 | except KeyError: |
|
1606 | except KeyError: | |
1607 | pass |
|
1607 | pass | |
1608 | elif st == 'iter': |
|
1608 | elif st == 'iter': | |
1609 | states = matches[rev].items() |
|
1609 | states = matches[rev].items() | |
1610 | states.sort() |
|
1610 | states.sort() | |
1611 | for fn, m in states: |
|
1611 | for fn, m in states: | |
1612 | if fn in skip: |
|
1612 | if fn in skip: | |
1613 | continue |
|
1613 | continue | |
1614 | if incrementing or not opts['all'] or fstate[fn]: |
|
1614 | if incrementing or not opts['all'] or fstate[fn]: | |
1615 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1615 | pos, neg = display(fn, rev, m, fstate[fn]) | |
1616 | count += pos + neg |
|
1616 | count += pos + neg | |
1617 | if pos and not opts['all']: |
|
1617 | if pos and not opts['all']: | |
1618 | skip[fn] = True |
|
1618 | skip[fn] = True | |
1619 | fstate[fn] = m |
|
1619 | fstate[fn] = m | |
1620 | prev[fn] = rev |
|
1620 | prev[fn] = rev | |
1621 |
|
1621 | |||
1622 | if not incrementing: |
|
1622 | if not incrementing: | |
1623 | fstate = fstate.items() |
|
1623 | fstate = fstate.items() | |
1624 | fstate.sort() |
|
1624 | fstate.sort() | |
1625 | for fn, state in fstate: |
|
1625 | for fn, state in fstate: | |
1626 | if fn in skip: |
|
1626 | if fn in skip: | |
1627 | continue |
|
1627 | continue | |
1628 | display(fn, rev, {}, state) |
|
1628 | display(fn, rev, {}, state) | |
1629 | return (count == 0 and 1) or 0 |
|
1629 | return (count == 0 and 1) or 0 | |
1630 |
|
1630 | |||
1631 | def heads(ui, repo, **opts): |
|
1631 | def heads(ui, repo, **opts): | |
1632 | """show current repository heads |
|
1632 | """show current repository heads | |
1633 |
|
1633 | |||
1634 | Show all repository head changesets. |
|
1634 | Show all repository head changesets. | |
1635 |
|
1635 | |||
1636 | Repository "heads" are changesets that don't have children |
|
1636 | Repository "heads" are changesets that don't have children | |
1637 | changesets. They are where development generally takes place and |
|
1637 | changesets. They are where development generally takes place and | |
1638 | are the usual targets for update and merge operations. |
|
1638 | are the usual targets for update and merge operations. | |
1639 | """ |
|
1639 | """ | |
1640 | if opts['rev']: |
|
1640 | if opts['rev']: | |
1641 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1641 | heads = repo.heads(repo.lookup(opts['rev'])) | |
1642 | else: |
|
1642 | else: | |
1643 | heads = repo.heads() |
|
1643 | heads = repo.heads() | |
1644 | br = None |
|
1644 | br = None | |
1645 | if opts['branches']: |
|
1645 | if opts['branches']: | |
1646 | br = repo.branchlookup(heads) |
|
1646 | br = repo.branchlookup(heads) | |
1647 | displayer = show_changeset(ui, repo, opts) |
|
1647 | displayer = show_changeset(ui, repo, opts) | |
1648 | for n in heads: |
|
1648 | for n in heads: | |
1649 | displayer.show(changenode=n, brinfo=br) |
|
1649 | displayer.show(changenode=n, brinfo=br) | |
1650 |
|
1650 | |||
1651 | def identify(ui, repo): |
|
1651 | def identify(ui, repo): | |
1652 | """print information about the working copy |
|
1652 | """print information about the working copy | |
1653 |
|
1653 | |||
1654 | Print a short summary of the current state of the repo. |
|
1654 | Print a short summary of the current state of the repo. | |
1655 |
|
1655 | |||
1656 | This summary identifies the repository state using one or two parent |
|
1656 | This summary identifies the repository state using one or two parent | |
1657 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1657 | hash identifiers, followed by a "+" if there are uncommitted changes | |
1658 | in the working directory, followed by a list of tags for this revision. |
|
1658 | in the working directory, followed by a list of tags for this revision. | |
1659 | """ |
|
1659 | """ | |
1660 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1660 | parents = [p for p in repo.dirstate.parents() if p != nullid] | |
1661 | if not parents: |
|
1661 | if not parents: | |
1662 | ui.write(_("unknown\n")) |
|
1662 | ui.write(_("unknown\n")) | |
1663 | return |
|
1663 | return | |
1664 |
|
1664 | |||
1665 | hexfunc = ui.verbose and hex or short |
|
1665 | hexfunc = ui.verbose and hex or short | |
1666 | modified, added, removed, deleted, unknown = repo.changes() |
|
1666 | modified, added, removed, deleted, unknown = repo.changes() | |
1667 | output = ["%s%s" % |
|
1667 | output = ["%s%s" % | |
1668 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1668 | ('+'.join([hexfunc(parent) for parent in parents]), | |
1669 | (modified or added or removed or deleted) and "+" or "")] |
|
1669 | (modified or added or removed or deleted) and "+" or "")] | |
1670 |
|
1670 | |||
1671 | if not ui.quiet: |
|
1671 | if not ui.quiet: | |
1672 | # multiple tags for a single parent separated by '/' |
|
1672 | # multiple tags for a single parent separated by '/' | |
1673 | parenttags = ['/'.join(tags) |
|
1673 | parenttags = ['/'.join(tags) | |
1674 | for tags in map(repo.nodetags, parents) if tags] |
|
1674 | for tags in map(repo.nodetags, parents) if tags] | |
1675 | # tags for multiple parents separated by ' + ' |
|
1675 | # tags for multiple parents separated by ' + ' | |
1676 | if parenttags: |
|
1676 | if parenttags: | |
1677 | output.append(' + '.join(parenttags)) |
|
1677 | output.append(' + '.join(parenttags)) | |
1678 |
|
1678 | |||
1679 | ui.write("%s\n" % ' '.join(output)) |
|
1679 | ui.write("%s\n" % ' '.join(output)) | |
1680 |
|
1680 | |||
1681 | def import_(ui, repo, patch1, *patches, **opts): |
|
1681 | def import_(ui, repo, patch1, *patches, **opts): | |
1682 | """import an ordered set of patches |
|
1682 | """import an ordered set of patches | |
1683 |
|
1683 | |||
1684 | Import a list of patches and commit them individually. |
|
1684 | Import a list of patches and commit them individually. | |
1685 |
|
1685 | |||
1686 | If there are outstanding changes in the working directory, import |
|
1686 | If there are outstanding changes in the working directory, import | |
1687 | will abort unless given the -f flag. |
|
1687 | will abort unless given the -f flag. | |
1688 |
|
1688 | |||
1689 | If a patch looks like a mail message (its first line starts with |
|
1689 | If a patch looks like a mail message (its first line starts with | |
1690 | "From " or looks like an RFC822 header), it will not be applied |
|
1690 | "From " or looks like an RFC822 header), it will not be applied | |
1691 | unless the -f option is used. The importer neither parses nor |
|
1691 | unless the -f option is used. The importer neither parses nor | |
1692 | discards mail headers, so use -f only to override the "mailness" |
|
1692 | discards mail headers, so use -f only to override the "mailness" | |
1693 | safety check, not to import a real mail message. |
|
1693 | safety check, not to import a real mail message. | |
1694 | """ |
|
1694 | """ | |
1695 | patches = (patch1,) + patches |
|
1695 | patches = (patch1,) + patches | |
1696 |
|
1696 | |||
1697 | if not opts['force']: |
|
1697 | if not opts['force']: | |
1698 | modified, added, removed, deleted, unknown = repo.changes() |
|
1698 | modified, added, removed, deleted, unknown = repo.changes() | |
1699 | if modified or added or removed or deleted: |
|
1699 | if modified or added or removed or deleted: | |
1700 | raise util.Abort(_("outstanding uncommitted changes")) |
|
1700 | raise util.Abort(_("outstanding uncommitted changes")) | |
1701 |
|
1701 | |||
1702 | d = opts["base"] |
|
1702 | d = opts["base"] | |
1703 | strip = opts["strip"] |
|
1703 | strip = opts["strip"] | |
1704 |
|
1704 | |||
1705 | mailre = re.compile(r'(?:From |[\w-]+:)') |
|
1705 | mailre = re.compile(r'(?:From |[\w-]+:)') | |
1706 |
|
1706 | |||
1707 | # attempt to detect the start of a patch |
|
1707 | # attempt to detect the start of a patch | |
1708 | # (this heuristic is borrowed from quilt) |
|
1708 | # (this heuristic is borrowed from quilt) | |
1709 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + |
|
1709 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + | |
1710 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + |
|
1710 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + | |
1711 | '(---|\*\*\*)[ \t])') |
|
1711 | '(---|\*\*\*)[ \t])') | |
1712 |
|
1712 | |||
1713 | for patch in patches: |
|
1713 | for patch in patches: | |
1714 | ui.status(_("applying %s\n") % patch) |
|
1714 | ui.status(_("applying %s\n") % patch) | |
1715 | pf = os.path.join(d, patch) |
|
1715 | pf = os.path.join(d, patch) | |
1716 |
|
1716 | |||
1717 | message = [] |
|
1717 | message = [] | |
1718 | user = None |
|
1718 | user = None | |
1719 | hgpatch = False |
|
1719 | hgpatch = False | |
1720 | for line in file(pf): |
|
1720 | for line in file(pf): | |
1721 | line = line.rstrip() |
|
1721 | line = line.rstrip() | |
1722 | if (not message and not hgpatch and |
|
1722 | if (not message and not hgpatch and | |
1723 | mailre.match(line) and not opts['force']): |
|
1723 | mailre.match(line) and not opts['force']): | |
1724 | if len(line) > 35: |
|
1724 | if len(line) > 35: | |
1725 | line = line[:32] + '...' |
|
1725 | line = line[:32] + '...' | |
1726 | raise util.Abort(_('first line looks like a ' |
|
1726 | raise util.Abort(_('first line looks like a ' | |
1727 | 'mail header: ') + line) |
|
1727 | 'mail header: ') + line) | |
1728 | if diffre.match(line): |
|
1728 | if diffre.match(line): | |
1729 | break |
|
1729 | break | |
1730 | elif hgpatch: |
|
1730 | elif hgpatch: | |
1731 | # parse values when importing the result of an hg export |
|
1731 | # parse values when importing the result of an hg export | |
1732 | if line.startswith("# User "): |
|
1732 | if line.startswith("# User "): | |
1733 | user = line[7:] |
|
1733 | user = line[7:] | |
1734 | ui.debug(_('User: %s\n') % user) |
|
1734 | ui.debug(_('User: %s\n') % user) | |
1735 | elif not line.startswith("# ") and line: |
|
1735 | elif not line.startswith("# ") and line: | |
1736 | message.append(line) |
|
1736 | message.append(line) | |
1737 | hgpatch = False |
|
1737 | hgpatch = False | |
1738 | elif line == '# HG changeset patch': |
|
1738 | elif line == '# HG changeset patch': | |
1739 | hgpatch = True |
|
1739 | hgpatch = True | |
1740 | message = [] # We may have collected garbage |
|
1740 | message = [] # We may have collected garbage | |
1741 | else: |
|
1741 | else: | |
1742 | message.append(line) |
|
1742 | message.append(line) | |
1743 |
|
1743 | |||
1744 | # make sure message isn't empty |
|
1744 | # make sure message isn't empty | |
1745 | if not message: |
|
1745 | if not message: | |
1746 | message = _("imported patch %s\n") % patch |
|
1746 | message = _("imported patch %s\n") % patch | |
1747 | else: |
|
1747 | else: | |
1748 | message = "%s\n" % '\n'.join(message) |
|
1748 | message = "%s\n" % '\n'.join(message) | |
1749 | ui.debug(_('message:\n%s\n') % message) |
|
1749 | ui.debug(_('message:\n%s\n') % message) | |
1750 |
|
1750 | |||
1751 | files = util.patch(strip, pf, ui) |
|
1751 | files = util.patch(strip, pf, ui) | |
1752 |
|
1752 | |||
1753 | if len(files) > 0: |
|
1753 | if len(files) > 0: | |
1754 | addremove(ui, repo, *files) |
|
1754 | addremove(ui, repo, *files) | |
1755 | repo.commit(files, message, user) |
|
1755 | repo.commit(files, message, user) | |
1756 |
|
1756 | |||
1757 | def incoming(ui, repo, source="default", **opts): |
|
1757 | def incoming(ui, repo, source="default", **opts): | |
1758 | """show new changesets found in source |
|
1758 | """show new changesets found in source | |
1759 |
|
1759 | |||
1760 | Show new changesets found in the specified repo or the default |
|
1760 | Show new changesets found in the specified repo or the default | |
1761 | pull repo. These are the changesets that would be pulled if a pull |
|
1761 | pull repo. These are the changesets that would be pulled if a pull | |
1762 | was requested. |
|
1762 | was requested. | |
1763 |
|
1763 | |||
1764 | For remote repository, using --bundle avoids downloading the changesets |
|
1764 | For remote repository, using --bundle avoids downloading the changesets | |
1765 | twice if the incoming is followed by a pull. |
|
1765 | twice if the incoming is followed by a pull. | |
1766 | """ |
|
1766 | """ | |
1767 | source = ui.expandpath(source) |
|
1767 | source = ui.expandpath(source) | |
1768 | other = hg.repository(ui, source) |
|
1768 | other = hg.repository(ui, source) | |
1769 | incoming = repo.findincoming(other) |
|
1769 | incoming = repo.findincoming(other, force=opts["force"]) | |
1770 | if not incoming: |
|
1770 | if not incoming: | |
1771 | return |
|
1771 | return | |
1772 |
|
1772 | |||
1773 | cleanup = None |
|
1773 | cleanup = None | |
1774 | if not other.local() or opts["bundle"]: |
|
1774 | if not other.local() or opts["bundle"]: | |
1775 | # create an uncompressed bundle |
|
1775 | # create an uncompressed bundle | |
1776 | if not opts["bundle"]: |
|
1776 | if not opts["bundle"]: | |
1777 | # create a temporary bundle |
|
1777 | # create a temporary bundle | |
1778 | fd, fname = tempfile.mkstemp(suffix=".hg", |
|
1778 | fd, fname = tempfile.mkstemp(suffix=".hg", | |
1779 | prefix="tmp-hg-incoming") |
|
1779 | prefix="tmp-hg-incoming") | |
1780 | f = os.fdopen(fd, "wb") |
|
1780 | f = os.fdopen(fd, "wb") | |
1781 | cleanup = fname |
|
1781 | cleanup = fname | |
1782 | else: |
|
1782 | else: | |
1783 | fname = opts["bundle"] |
|
1783 | fname = opts["bundle"] | |
1784 | f = open(fname, "wb") |
|
1784 | f = open(fname, "wb") | |
1785 |
|
1785 | |||
1786 | cg = other.changegroup(incoming, "incoming") |
|
1786 | cg = other.changegroup(incoming, "incoming") | |
1787 | write_bundle(cg, fname, compress=other.local(), fh=f) |
|
1787 | write_bundle(cg, fname, compress=other.local(), fh=f) | |
1788 | f.close() |
|
1788 | f.close() | |
1789 | if not other.local(): |
|
1789 | if not other.local(): | |
1790 | # use a bundlerepo |
|
1790 | # use a bundlerepo | |
1791 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1791 | other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
1792 |
|
1792 | |||
1793 | o = other.changelog.nodesbetween(incoming)[0] |
|
1793 | o = other.changelog.nodesbetween(incoming)[0] | |
1794 | if opts['newest_first']: |
|
1794 | if opts['newest_first']: | |
1795 | o.reverse() |
|
1795 | o.reverse() | |
1796 | displayer = show_changeset(ui, other, opts) |
|
1796 | displayer = show_changeset(ui, other, opts) | |
1797 | for n in o: |
|
1797 | for n in o: | |
1798 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1798 | parents = [p for p in other.changelog.parents(n) if p != nullid] | |
1799 | if opts['no_merges'] and len(parents) == 2: |
|
1799 | if opts['no_merges'] and len(parents) == 2: | |
1800 | continue |
|
1800 | continue | |
1801 | displayer.show(changenode=n) |
|
1801 | displayer.show(changenode=n) | |
1802 | if opts['patch']: |
|
1802 | if opts['patch']: | |
1803 | prev = (parents and parents[0]) or nullid |
|
1803 | prev = (parents and parents[0]) or nullid | |
1804 | dodiff(ui, ui, other, prev, n) |
|
1804 | dodiff(ui, ui, other, prev, n) | |
1805 | ui.write("\n") |
|
1805 | ui.write("\n") | |
1806 |
|
1806 | |||
1807 | if cleanup: |
|
1807 | if cleanup: | |
1808 | os.unlink(cleanup) |
|
1808 | os.unlink(cleanup) | |
1809 |
|
1809 | |||
1810 | def init(ui, dest="."): |
|
1810 | def init(ui, dest="."): | |
1811 | """create a new repository in the given directory |
|
1811 | """create a new repository in the given directory | |
1812 |
|
1812 | |||
1813 | Initialize a new repository in the given directory. If the given |
|
1813 | Initialize a new repository in the given directory. If the given | |
1814 | directory does not exist, it is created. |
|
1814 | directory does not exist, it is created. | |
1815 |
|
1815 | |||
1816 | If no directory is given, the current directory is used. |
|
1816 | If no directory is given, the current directory is used. | |
1817 | """ |
|
1817 | """ | |
1818 | if not os.path.exists(dest): |
|
1818 | if not os.path.exists(dest): | |
1819 | os.mkdir(dest) |
|
1819 | os.mkdir(dest) | |
1820 | hg.repository(ui, dest, create=1) |
|
1820 | hg.repository(ui, dest, create=1) | |
1821 |
|
1821 | |||
1822 | def locate(ui, repo, *pats, **opts): |
|
1822 | def locate(ui, repo, *pats, **opts): | |
1823 | """locate files matching specific patterns |
|
1823 | """locate files matching specific patterns | |
1824 |
|
1824 | |||
1825 | Print all files under Mercurial control whose names match the |
|
1825 | Print all files under Mercurial control whose names match the | |
1826 | given patterns. |
|
1826 | given patterns. | |
1827 |
|
1827 | |||
1828 | This command searches the current directory and its |
|
1828 | This command searches the current directory and its | |
1829 | subdirectories. To search an entire repository, move to the root |
|
1829 | subdirectories. To search an entire repository, move to the root | |
1830 | of the repository. |
|
1830 | of the repository. | |
1831 |
|
1831 | |||
1832 | If no patterns are given to match, this command prints all file |
|
1832 | If no patterns are given to match, this command prints all file | |
1833 | names. |
|
1833 | names. | |
1834 |
|
1834 | |||
1835 | If you want to feed the output of this command into the "xargs" |
|
1835 | If you want to feed the output of this command into the "xargs" | |
1836 | command, use the "-0" option to both this command and "xargs". |
|
1836 | command, use the "-0" option to both this command and "xargs". | |
1837 | This will avoid the problem of "xargs" treating single filenames |
|
1837 | This will avoid the problem of "xargs" treating single filenames | |
1838 | that contain white space as multiple filenames. |
|
1838 | that contain white space as multiple filenames. | |
1839 | """ |
|
1839 | """ | |
1840 | end = opts['print0'] and '\0' or '\n' |
|
1840 | end = opts['print0'] and '\0' or '\n' | |
1841 | rev = opts['rev'] |
|
1841 | rev = opts['rev'] | |
1842 | if rev: |
|
1842 | if rev: | |
1843 | node = repo.lookup(rev) |
|
1843 | node = repo.lookup(rev) | |
1844 | else: |
|
1844 | else: | |
1845 | node = None |
|
1845 | node = None | |
1846 |
|
1846 | |||
1847 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
1847 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
1848 | head='(?:.*/|)'): |
|
1848 | head='(?:.*/|)'): | |
1849 | if not node and repo.dirstate.state(abs) == '?': |
|
1849 | if not node and repo.dirstate.state(abs) == '?': | |
1850 | continue |
|
1850 | continue | |
1851 | if opts['fullpath']: |
|
1851 | if opts['fullpath']: | |
1852 | ui.write(os.path.join(repo.root, abs), end) |
|
1852 | ui.write(os.path.join(repo.root, abs), end) | |
1853 | else: |
|
1853 | else: | |
1854 | ui.write(((pats and rel) or abs), end) |
|
1854 | ui.write(((pats and rel) or abs), end) | |
1855 |
|
1855 | |||
1856 | def log(ui, repo, *pats, **opts): |
|
1856 | def log(ui, repo, *pats, **opts): | |
1857 | """show revision history of entire repository or files |
|
1857 | """show revision history of entire repository or files | |
1858 |
|
1858 | |||
1859 | Print the revision history of the specified files or the entire project. |
|
1859 | Print the revision history of the specified files or the entire project. | |
1860 |
|
1860 | |||
1861 | By default this command outputs: changeset id and hash, tags, |
|
1861 | By default this command outputs: changeset id and hash, tags, | |
1862 | non-trivial parents, user, date and time, and a summary for each |
|
1862 | non-trivial parents, user, date and time, and a summary for each | |
1863 | commit. When the -v/--verbose switch is used, the list of changed |
|
1863 | commit. When the -v/--verbose switch is used, the list of changed | |
1864 | files and full commit message is shown. |
|
1864 | files and full commit message is shown. | |
1865 | """ |
|
1865 | """ | |
1866 | class dui(object): |
|
1866 | class dui(object): | |
1867 | # Implement and delegate some ui protocol. Save hunks of |
|
1867 | # Implement and delegate some ui protocol. Save hunks of | |
1868 | # output for later display in the desired order. |
|
1868 | # output for later display in the desired order. | |
1869 | def __init__(self, ui): |
|
1869 | def __init__(self, ui): | |
1870 | self.ui = ui |
|
1870 | self.ui = ui | |
1871 | self.hunk = {} |
|
1871 | self.hunk = {} | |
1872 | def bump(self, rev): |
|
1872 | def bump(self, rev): | |
1873 | self.rev = rev |
|
1873 | self.rev = rev | |
1874 | self.hunk[rev] = [] |
|
1874 | self.hunk[rev] = [] | |
1875 | def note(self, *args): |
|
1875 | def note(self, *args): | |
1876 | if self.verbose: |
|
1876 | if self.verbose: | |
1877 | self.write(*args) |
|
1877 | self.write(*args) | |
1878 | def status(self, *args): |
|
1878 | def status(self, *args): | |
1879 | if not self.quiet: |
|
1879 | if not self.quiet: | |
1880 | self.write(*args) |
|
1880 | self.write(*args) | |
1881 | def write(self, *args): |
|
1881 | def write(self, *args): | |
1882 | self.hunk[self.rev].append(args) |
|
1882 | self.hunk[self.rev].append(args) | |
1883 | def debug(self, *args): |
|
1883 | def debug(self, *args): | |
1884 | if self.debugflag: |
|
1884 | if self.debugflag: | |
1885 | self.write(*args) |
|
1885 | self.write(*args) | |
1886 | def __getattr__(self, key): |
|
1886 | def __getattr__(self, key): | |
1887 | return getattr(self.ui, key) |
|
1887 | return getattr(self.ui, key) | |
1888 |
|
1888 | |||
1889 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1889 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1890 |
|
1890 | |||
1891 | if opts['limit']: |
|
1891 | if opts['limit']: | |
1892 | try: |
|
1892 | try: | |
1893 | limit = int(opts['limit']) |
|
1893 | limit = int(opts['limit']) | |
1894 | except ValueError: |
|
1894 | except ValueError: | |
1895 | raise util.Abort(_('limit must be a positive integer')) |
|
1895 | raise util.Abort(_('limit must be a positive integer')) | |
1896 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1896 | if limit <= 0: raise util.Abort(_('limit must be positive')) | |
1897 | else: |
|
1897 | else: | |
1898 | limit = sys.maxint |
|
1898 | limit = sys.maxint | |
1899 | count = 0 |
|
1899 | count = 0 | |
1900 |
|
1900 | |||
1901 | displayer = show_changeset(ui, repo, opts) |
|
1901 | displayer = show_changeset(ui, repo, opts) | |
1902 | for st, rev, fns in changeiter: |
|
1902 | for st, rev, fns in changeiter: | |
1903 | if st == 'window': |
|
1903 | if st == 'window': | |
1904 | du = dui(ui) |
|
1904 | du = dui(ui) | |
1905 | displayer.ui = du |
|
1905 | displayer.ui = du | |
1906 | elif st == 'add': |
|
1906 | elif st == 'add': | |
1907 | du.bump(rev) |
|
1907 | du.bump(rev) | |
1908 | changenode = repo.changelog.node(rev) |
|
1908 | changenode = repo.changelog.node(rev) | |
1909 | parents = [p for p in repo.changelog.parents(changenode) |
|
1909 | parents = [p for p in repo.changelog.parents(changenode) | |
1910 | if p != nullid] |
|
1910 | if p != nullid] | |
1911 | if opts['no_merges'] and len(parents) == 2: |
|
1911 | if opts['no_merges'] and len(parents) == 2: | |
1912 | continue |
|
1912 | continue | |
1913 | if opts['only_merges'] and len(parents) != 2: |
|
1913 | if opts['only_merges'] and len(parents) != 2: | |
1914 | continue |
|
1914 | continue | |
1915 |
|
1915 | |||
1916 | if opts['keyword']: |
|
1916 | if opts['keyword']: | |
1917 | changes = getchange(rev) |
|
1917 | changes = getchange(rev) | |
1918 | miss = 0 |
|
1918 | miss = 0 | |
1919 | for k in [kw.lower() for kw in opts['keyword']]: |
|
1919 | for k in [kw.lower() for kw in opts['keyword']]: | |
1920 | if not (k in changes[1].lower() or |
|
1920 | if not (k in changes[1].lower() or | |
1921 | k in changes[4].lower() or |
|
1921 | k in changes[4].lower() or | |
1922 | k in " ".join(changes[3][:20]).lower()): |
|
1922 | k in " ".join(changes[3][:20]).lower()): | |
1923 | miss = 1 |
|
1923 | miss = 1 | |
1924 | break |
|
1924 | break | |
1925 | if miss: |
|
1925 | if miss: | |
1926 | continue |
|
1926 | continue | |
1927 |
|
1927 | |||
1928 | br = None |
|
1928 | br = None | |
1929 | if opts['branches']: |
|
1929 | if opts['branches']: | |
1930 | br = repo.branchlookup([repo.changelog.node(rev)]) |
|
1930 | br = repo.branchlookup([repo.changelog.node(rev)]) | |
1931 |
|
1931 | |||
1932 | displayer.show(rev, brinfo=br) |
|
1932 | displayer.show(rev, brinfo=br) | |
1933 | if opts['patch']: |
|
1933 | if opts['patch']: | |
1934 | prev = (parents and parents[0]) or nullid |
|
1934 | prev = (parents and parents[0]) or nullid | |
1935 | dodiff(du, du, repo, prev, changenode, match=matchfn) |
|
1935 | dodiff(du, du, repo, prev, changenode, match=matchfn) | |
1936 | du.write("\n\n") |
|
1936 | du.write("\n\n") | |
1937 | elif st == 'iter': |
|
1937 | elif st == 'iter': | |
1938 | if count == limit: break |
|
1938 | if count == limit: break | |
1939 | if du.hunk[rev]: |
|
1939 | if du.hunk[rev]: | |
1940 | count += 1 |
|
1940 | count += 1 | |
1941 | for args in du.hunk[rev]: |
|
1941 | for args in du.hunk[rev]: | |
1942 | ui.write(*args) |
|
1942 | ui.write(*args) | |
1943 |
|
1943 | |||
1944 | def manifest(ui, repo, rev=None): |
|
1944 | def manifest(ui, repo, rev=None): | |
1945 | """output the latest or given revision of the project manifest |
|
1945 | """output the latest or given revision of the project manifest | |
1946 |
|
1946 | |||
1947 | Print a list of version controlled files for the given revision. |
|
1947 | Print a list of version controlled files for the given revision. | |
1948 |
|
1948 | |||
1949 | The manifest is the list of files being version controlled. If no revision |
|
1949 | The manifest is the list of files being version controlled. If no revision | |
1950 | is given then the tip is used. |
|
1950 | is given then the tip is used. | |
1951 | """ |
|
1951 | """ | |
1952 | if rev: |
|
1952 | if rev: | |
1953 | try: |
|
1953 | try: | |
1954 | # assume all revision numbers are for changesets |
|
1954 | # assume all revision numbers are for changesets | |
1955 | n = repo.lookup(rev) |
|
1955 | n = repo.lookup(rev) | |
1956 | change = repo.changelog.read(n) |
|
1956 | change = repo.changelog.read(n) | |
1957 | n = change[0] |
|
1957 | n = change[0] | |
1958 | except hg.RepoError: |
|
1958 | except hg.RepoError: | |
1959 | n = repo.manifest.lookup(rev) |
|
1959 | n = repo.manifest.lookup(rev) | |
1960 | else: |
|
1960 | else: | |
1961 | n = repo.manifest.tip() |
|
1961 | n = repo.manifest.tip() | |
1962 | m = repo.manifest.read(n) |
|
1962 | m = repo.manifest.read(n) | |
1963 | mf = repo.manifest.readflags(n) |
|
1963 | mf = repo.manifest.readflags(n) | |
1964 | files = m.keys() |
|
1964 | files = m.keys() | |
1965 | files.sort() |
|
1965 | files.sort() | |
1966 |
|
1966 | |||
1967 | for f in files: |
|
1967 | for f in files: | |
1968 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) |
|
1968 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) | |
1969 |
|
1969 | |||
1970 | def outgoing(ui, repo, dest="default-push", **opts): |
|
1970 | def outgoing(ui, repo, dest="default-push", **opts): | |
1971 | """show changesets not found in destination |
|
1971 | """show changesets not found in destination | |
1972 |
|
1972 | |||
1973 | Show changesets not found in the specified destination repo or the |
|
1973 | Show changesets not found in the specified destination repo or the | |
1974 | default push repo. These are the changesets that would be pushed |
|
1974 | default push repo. These are the changesets that would be pushed | |
1975 | if a push was requested. |
|
1975 | if a push was requested. | |
1976 |
|
1976 | |||
1977 | See pull for valid source format details. |
|
1977 | See pull for valid source format details. | |
1978 | """ |
|
1978 | """ | |
1979 | dest = ui.expandpath(dest) |
|
1979 | dest = ui.expandpath(dest) | |
1980 | other = hg.repository(ui, dest) |
|
1980 | other = hg.repository(ui, dest) | |
1981 | o = repo.findoutgoing(other) |
|
1981 | o = repo.findoutgoing(other, force=opts['force']) | |
1982 | o = repo.changelog.nodesbetween(o)[0] |
|
1982 | o = repo.changelog.nodesbetween(o)[0] | |
1983 | if opts['newest_first']: |
|
1983 | if opts['newest_first']: | |
1984 | o.reverse() |
|
1984 | o.reverse() | |
1985 | displayer = show_changeset(ui, repo, opts) |
|
1985 | displayer = show_changeset(ui, repo, opts) | |
1986 | for n in o: |
|
1986 | for n in o: | |
1987 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
1987 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | |
1988 | if opts['no_merges'] and len(parents) == 2: |
|
1988 | if opts['no_merges'] and len(parents) == 2: | |
1989 | continue |
|
1989 | continue | |
1990 | displayer.show(changenode=n) |
|
1990 | displayer.show(changenode=n) | |
1991 | if opts['patch']: |
|
1991 | if opts['patch']: | |
1992 | prev = (parents and parents[0]) or nullid |
|
1992 | prev = (parents and parents[0]) or nullid | |
1993 | dodiff(ui, ui, repo, prev, n) |
|
1993 | dodiff(ui, ui, repo, prev, n) | |
1994 | ui.write("\n") |
|
1994 | ui.write("\n") | |
1995 |
|
1995 | |||
1996 | def parents(ui, repo, rev=None, branches=None, **opts): |
|
1996 | def parents(ui, repo, rev=None, branches=None, **opts): | |
1997 | """show the parents of the working dir or revision |
|
1997 | """show the parents of the working dir or revision | |
1998 |
|
1998 | |||
1999 | Print the working directory's parent revisions. |
|
1999 | Print the working directory's parent revisions. | |
2000 | """ |
|
2000 | """ | |
2001 | if rev: |
|
2001 | if rev: | |
2002 | p = repo.changelog.parents(repo.lookup(rev)) |
|
2002 | p = repo.changelog.parents(repo.lookup(rev)) | |
2003 | else: |
|
2003 | else: | |
2004 | p = repo.dirstate.parents() |
|
2004 | p = repo.dirstate.parents() | |
2005 |
|
2005 | |||
2006 | br = None |
|
2006 | br = None | |
2007 | if branches is not None: |
|
2007 | if branches is not None: | |
2008 | br = repo.branchlookup(p) |
|
2008 | br = repo.branchlookup(p) | |
2009 | displayer = show_changeset(ui, repo, opts) |
|
2009 | displayer = show_changeset(ui, repo, opts) | |
2010 | for n in p: |
|
2010 | for n in p: | |
2011 | if n != nullid: |
|
2011 | if n != nullid: | |
2012 | displayer.show(changenode=n, brinfo=br) |
|
2012 | displayer.show(changenode=n, brinfo=br) | |
2013 |
|
2013 | |||
2014 | def paths(ui, repo, search=None): |
|
2014 | def paths(ui, repo, search=None): | |
2015 | """show definition of symbolic path names |
|
2015 | """show definition of symbolic path names | |
2016 |
|
2016 | |||
2017 | Show definition of symbolic path name NAME. If no name is given, show |
|
2017 | Show definition of symbolic path name NAME. If no name is given, show | |
2018 | definition of available names. |
|
2018 | definition of available names. | |
2019 |
|
2019 | |||
2020 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
2020 | Path names are defined in the [paths] section of /etc/mercurial/hgrc | |
2021 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2021 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. | |
2022 | """ |
|
2022 | """ | |
2023 | if search: |
|
2023 | if search: | |
2024 | for name, path in ui.configitems("paths"): |
|
2024 | for name, path in ui.configitems("paths"): | |
2025 | if name == search: |
|
2025 | if name == search: | |
2026 | ui.write("%s\n" % path) |
|
2026 | ui.write("%s\n" % path) | |
2027 | return |
|
2027 | return | |
2028 | ui.warn(_("not found!\n")) |
|
2028 | ui.warn(_("not found!\n")) | |
2029 | return 1 |
|
2029 | return 1 | |
2030 | else: |
|
2030 | else: | |
2031 | for name, path in ui.configitems("paths"): |
|
2031 | for name, path in ui.configitems("paths"): | |
2032 | ui.write("%s = %s\n" % (name, path)) |
|
2032 | ui.write("%s = %s\n" % (name, path)) | |
2033 |
|
2033 | |||
2034 | def pull(ui, repo, source="default", **opts): |
|
2034 | def pull(ui, repo, source="default", **opts): | |
2035 | """pull changes from the specified source |
|
2035 | """pull changes from the specified source | |
2036 |
|
2036 | |||
2037 | Pull changes from a remote repository to a local one. |
|
2037 | Pull changes from a remote repository to a local one. | |
2038 |
|
2038 | |||
2039 | This finds all changes from the repository at the specified path |
|
2039 | This finds all changes from the repository at the specified path | |
2040 | or URL and adds them to the local repository. By default, this |
|
2040 | or URL and adds them to the local repository. By default, this | |
2041 | does not update the copy of the project in the working directory. |
|
2041 | does not update the copy of the project in the working directory. | |
2042 |
|
2042 | |||
2043 | Valid URLs are of the form: |
|
2043 | Valid URLs are of the form: | |
2044 |
|
2044 | |||
2045 | local/filesystem/path |
|
2045 | local/filesystem/path | |
2046 | http://[user@]host[:port][/path] |
|
2046 | http://[user@]host[:port][/path] | |
2047 | https://[user@]host[:port][/path] |
|
2047 | https://[user@]host[:port][/path] | |
2048 | ssh://[user@]host[:port][/path] |
|
2048 | ssh://[user@]host[:port][/path] | |
2049 |
|
2049 | |||
2050 | SSH requires an accessible shell account on the destination machine |
|
2050 | SSH requires an accessible shell account on the destination machine | |
2051 | and a copy of hg in the remote path. With SSH, paths are relative |
|
2051 | and a copy of hg in the remote path. With SSH, paths are relative | |
2052 | to the remote user's home directory by default; use two slashes at |
|
2052 | to the remote user's home directory by default; use two slashes at | |
2053 | the start of a path to specify it as relative to the filesystem root. |
|
2053 | the start of a path to specify it as relative to the filesystem root. | |
2054 | """ |
|
2054 | """ | |
2055 | source = ui.expandpath(source) |
|
2055 | source = ui.expandpath(source) | |
2056 | ui.status(_('pulling from %s\n') % (source)) |
|
2056 | ui.status(_('pulling from %s\n') % (source)) | |
2057 |
|
2057 | |||
2058 | if opts['ssh']: |
|
2058 | if opts['ssh']: | |
2059 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2059 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2060 | if opts['remotecmd']: |
|
2060 | if opts['remotecmd']: | |
2061 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2061 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2062 |
|
2062 | |||
2063 | other = hg.repository(ui, source) |
|
2063 | other = hg.repository(ui, source) | |
2064 | revs = None |
|
2064 | revs = None | |
2065 | if opts['rev'] and not other.local(): |
|
2065 | if opts['rev'] and not other.local(): | |
2066 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) |
|
2066 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) | |
2067 | elif opts['rev']: |
|
2067 | elif opts['rev']: | |
2068 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
2068 | revs = [other.lookup(rev) for rev in opts['rev']] | |
2069 | r = repo.pull(other, heads=revs) |
|
2069 | r = repo.pull(other, heads=revs, force=opts['force']) | |
2070 | if not r: |
|
2070 | if not r: | |
2071 | if opts['update']: |
|
2071 | if opts['update']: | |
2072 | return update(ui, repo) |
|
2072 | return update(ui, repo) | |
2073 | else: |
|
2073 | else: | |
2074 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2074 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2075 |
|
2075 | |||
2076 | return r |
|
2076 | return r | |
2077 |
|
2077 | |||
2078 | def push(ui, repo, dest="default-push", **opts): |
|
2078 | def push(ui, repo, dest="default-push", **opts): | |
2079 | """push changes to the specified destination |
|
2079 | """push changes to the specified destination | |
2080 |
|
2080 | |||
2081 | Push changes from the local repository to the given destination. |
|
2081 | Push changes from the local repository to the given destination. | |
2082 |
|
2082 | |||
2083 | This is the symmetrical operation for pull. It helps to move |
|
2083 | This is the symmetrical operation for pull. It helps to move | |
2084 | changes from the current repository to a different one. If the |
|
2084 | changes from the current repository to a different one. If the | |
2085 | destination is local this is identical to a pull in that directory |
|
2085 | destination is local this is identical to a pull in that directory | |
2086 | from the current one. |
|
2086 | from the current one. | |
2087 |
|
2087 | |||
2088 | By default, push will refuse to run if it detects the result would |
|
2088 | By default, push will refuse to run if it detects the result would | |
2089 | increase the number of remote heads. This generally indicates the |
|
2089 | increase the number of remote heads. This generally indicates the | |
2090 | the client has forgotten to sync and merge before pushing. |
|
2090 | the client has forgotten to sync and merge before pushing. | |
2091 |
|
2091 | |||
2092 | Valid URLs are of the form: |
|
2092 | Valid URLs are of the form: | |
2093 |
|
2093 | |||
2094 | local/filesystem/path |
|
2094 | local/filesystem/path | |
2095 | ssh://[user@]host[:port][/path] |
|
2095 | ssh://[user@]host[:port][/path] | |
2096 |
|
2096 | |||
2097 | SSH requires an accessible shell account on the destination |
|
2097 | SSH requires an accessible shell account on the destination | |
2098 | machine and a copy of hg in the remote path. |
|
2098 | machine and a copy of hg in the remote path. | |
2099 | """ |
|
2099 | """ | |
2100 | dest = ui.expandpath(dest) |
|
2100 | dest = ui.expandpath(dest) | |
2101 | ui.status('pushing to %s\n' % (dest)) |
|
2101 | ui.status('pushing to %s\n' % (dest)) | |
2102 |
|
2102 | |||
2103 | if opts['ssh']: |
|
2103 | if opts['ssh']: | |
2104 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2104 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2105 | if opts['remotecmd']: |
|
2105 | if opts['remotecmd']: | |
2106 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2106 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2107 |
|
2107 | |||
2108 | other = hg.repository(ui, dest) |
|
2108 | other = hg.repository(ui, dest) | |
2109 | revs = None |
|
2109 | revs = None | |
2110 | if opts['rev']: |
|
2110 | if opts['rev']: | |
2111 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
2111 | revs = [repo.lookup(rev) for rev in opts['rev']] | |
2112 | r = repo.push(other, opts['force'], revs=revs) |
|
2112 | r = repo.push(other, opts['force'], revs=revs) | |
2113 | return r |
|
2113 | return r | |
2114 |
|
2114 | |||
2115 | def rawcommit(ui, repo, *flist, **rc): |
|
2115 | def rawcommit(ui, repo, *flist, **rc): | |
2116 | """raw commit interface (DEPRECATED) |
|
2116 | """raw commit interface (DEPRECATED) | |
2117 |
|
2117 | |||
2118 | (DEPRECATED) |
|
2118 | (DEPRECATED) | |
2119 | Lowlevel commit, for use in helper scripts. |
|
2119 | Lowlevel commit, for use in helper scripts. | |
2120 |
|
2120 | |||
2121 | This command is not intended to be used by normal users, as it is |
|
2121 | This command is not intended to be used by normal users, as it is | |
2122 | primarily useful for importing from other SCMs. |
|
2122 | primarily useful for importing from other SCMs. | |
2123 |
|
2123 | |||
2124 | This command is now deprecated and will be removed in a future |
|
2124 | This command is now deprecated and will be removed in a future | |
2125 | release, please use debugsetparents and commit instead. |
|
2125 | release, please use debugsetparents and commit instead. | |
2126 | """ |
|
2126 | """ | |
2127 |
|
2127 | |||
2128 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
2128 | ui.warn(_("(the rawcommit command is deprecated)\n")) | |
2129 |
|
2129 | |||
2130 | message = rc['message'] |
|
2130 | message = rc['message'] | |
2131 | if not message and rc['logfile']: |
|
2131 | if not message and rc['logfile']: | |
2132 | try: |
|
2132 | try: | |
2133 | message = open(rc['logfile']).read() |
|
2133 | message = open(rc['logfile']).read() | |
2134 | except IOError: |
|
2134 | except IOError: | |
2135 | pass |
|
2135 | pass | |
2136 | if not message and not rc['logfile']: |
|
2136 | if not message and not rc['logfile']: | |
2137 | raise util.Abort(_("missing commit message")) |
|
2137 | raise util.Abort(_("missing commit message")) | |
2138 |
|
2138 | |||
2139 | files = relpath(repo, list(flist)) |
|
2139 | files = relpath(repo, list(flist)) | |
2140 | if rc['files']: |
|
2140 | if rc['files']: | |
2141 | files += open(rc['files']).read().splitlines() |
|
2141 | files += open(rc['files']).read().splitlines() | |
2142 |
|
2142 | |||
2143 | rc['parent'] = map(repo.lookup, rc['parent']) |
|
2143 | rc['parent'] = map(repo.lookup, rc['parent']) | |
2144 |
|
2144 | |||
2145 | try: |
|
2145 | try: | |
2146 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) |
|
2146 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) | |
2147 | except ValueError, inst: |
|
2147 | except ValueError, inst: | |
2148 | raise util.Abort(str(inst)) |
|
2148 | raise util.Abort(str(inst)) | |
2149 |
|
2149 | |||
2150 | def recover(ui, repo): |
|
2150 | def recover(ui, repo): | |
2151 | """roll back an interrupted transaction |
|
2151 | """roll back an interrupted transaction | |
2152 |
|
2152 | |||
2153 | Recover from an interrupted commit or pull. |
|
2153 | Recover from an interrupted commit or pull. | |
2154 |
|
2154 | |||
2155 | This command tries to fix the repository status after an interrupted |
|
2155 | This command tries to fix the repository status after an interrupted | |
2156 | operation. It should only be necessary when Mercurial suggests it. |
|
2156 | operation. It should only be necessary when Mercurial suggests it. | |
2157 | """ |
|
2157 | """ | |
2158 | if repo.recover(): |
|
2158 | if repo.recover(): | |
2159 | return repo.verify() |
|
2159 | return repo.verify() | |
2160 | return False |
|
2160 | return False | |
2161 |
|
2161 | |||
2162 | def remove(ui, repo, pat, *pats, **opts): |
|
2162 | def remove(ui, repo, pat, *pats, **opts): | |
2163 | """remove the specified files on the next commit |
|
2163 | """remove the specified files on the next commit | |
2164 |
|
2164 | |||
2165 | Schedule the indicated files for removal from the repository. |
|
2165 | Schedule the indicated files for removal from the repository. | |
2166 |
|
2166 | |||
2167 | This command schedules the files to be removed at the next commit. |
|
2167 | This command schedules the files to be removed at the next commit. | |
2168 | This only removes files from the current branch, not from the |
|
2168 | This only removes files from the current branch, not from the | |
2169 | entire project history. If the files still exist in the working |
|
2169 | entire project history. If the files still exist in the working | |
2170 | directory, they will be deleted from it. |
|
2170 | directory, they will be deleted from it. | |
2171 | """ |
|
2171 | """ | |
2172 | names = [] |
|
2172 | names = [] | |
2173 | def okaytoremove(abs, rel, exact): |
|
2173 | def okaytoremove(abs, rel, exact): | |
2174 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) |
|
2174 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) | |
2175 | reason = None |
|
2175 | reason = None | |
2176 | if modified and not opts['force']: |
|
2176 | if modified and not opts['force']: | |
2177 | reason = _('is modified') |
|
2177 | reason = _('is modified') | |
2178 | elif added: |
|
2178 | elif added: | |
2179 | reason = _('has been marked for add') |
|
2179 | reason = _('has been marked for add') | |
2180 | elif unknown: |
|
2180 | elif unknown: | |
2181 | reason = _('is not managed') |
|
2181 | reason = _('is not managed') | |
2182 | if reason: |
|
2182 | if reason: | |
2183 | if exact: |
|
2183 | if exact: | |
2184 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
2184 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | |
2185 | else: |
|
2185 | else: | |
2186 | return True |
|
2186 | return True | |
2187 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): |
|
2187 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): | |
2188 | if okaytoremove(abs, rel, exact): |
|
2188 | if okaytoremove(abs, rel, exact): | |
2189 | if ui.verbose or not exact: |
|
2189 | if ui.verbose or not exact: | |
2190 | ui.status(_('removing %s\n') % rel) |
|
2190 | ui.status(_('removing %s\n') % rel) | |
2191 | names.append(abs) |
|
2191 | names.append(abs) | |
2192 | repo.remove(names, unlink=True) |
|
2192 | repo.remove(names, unlink=True) | |
2193 |
|
2193 | |||
2194 | def rename(ui, repo, *pats, **opts): |
|
2194 | def rename(ui, repo, *pats, **opts): | |
2195 | """rename files; equivalent of copy + remove |
|
2195 | """rename files; equivalent of copy + remove | |
2196 |
|
2196 | |||
2197 | Mark dest as copies of sources; mark sources for deletion. If |
|
2197 | Mark dest as copies of sources; mark sources for deletion. If | |
2198 | dest is a directory, copies are put in that directory. If dest is |
|
2198 | dest is a directory, copies are put in that directory. If dest is | |
2199 | a file, there can only be one source. |
|
2199 | a file, there can only be one source. | |
2200 |
|
2200 | |||
2201 | By default, this command copies the contents of files as they |
|
2201 | By default, this command copies the contents of files as they | |
2202 | stand in the working directory. If invoked with --after, the |
|
2202 | stand in the working directory. If invoked with --after, the | |
2203 | operation is recorded, but no copying is performed. |
|
2203 | operation is recorded, but no copying is performed. | |
2204 |
|
2204 | |||
2205 | This command takes effect in the next commit. |
|
2205 | This command takes effect in the next commit. | |
2206 |
|
2206 | |||
2207 | NOTE: This command should be treated as experimental. While it |
|
2207 | NOTE: This command should be treated as experimental. While it | |
2208 | should properly record rename files, this information is not yet |
|
2208 | should properly record rename files, this information is not yet | |
2209 | fully used by merge, nor fully reported by log. |
|
2209 | fully used by merge, nor fully reported by log. | |
2210 | """ |
|
2210 | """ | |
2211 | try: |
|
2211 | try: | |
2212 | wlock = repo.wlock(0) |
|
2212 | wlock = repo.wlock(0) | |
2213 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
2213 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
2214 | names = [] |
|
2214 | names = [] | |
2215 | for abs, rel, exact in copied: |
|
2215 | for abs, rel, exact in copied: | |
2216 | if ui.verbose or not exact: |
|
2216 | if ui.verbose or not exact: | |
2217 | ui.status(_('removing %s\n') % rel) |
|
2217 | ui.status(_('removing %s\n') % rel) | |
2218 | names.append(abs) |
|
2218 | names.append(abs) | |
2219 | repo.remove(names, True, wlock) |
|
2219 | repo.remove(names, True, wlock) | |
2220 | except lock.LockHeld, inst: |
|
2220 | except lock.LockHeld, inst: | |
2221 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) |
|
2221 | ui.warn(_("repository lock held by %s\n") % inst.args[0]) | |
2222 | errs = 1 |
|
2222 | errs = 1 | |
2223 | return errs |
|
2223 | return errs | |
2224 |
|
2224 | |||
2225 | def revert(ui, repo, *pats, **opts): |
|
2225 | def revert(ui, repo, *pats, **opts): | |
2226 | """revert modified files or dirs back to their unmodified states |
|
2226 | """revert modified files or dirs back to their unmodified states | |
2227 |
|
2227 | |||
2228 | In its default mode, it reverts any uncommitted modifications made |
|
2228 | In its default mode, it reverts any uncommitted modifications made | |
2229 | to the named files or directories. This restores the contents of |
|
2229 | to the named files or directories. This restores the contents of | |
2230 | the affected files to an unmodified state. |
|
2230 | the affected files to an unmodified state. | |
2231 |
|
2231 | |||
2232 | Using the -r option, it reverts the given files or directories to |
|
2232 | Using the -r option, it reverts the given files or directories to | |
2233 | their state as of an earlier revision. This can be helpful to "roll |
|
2233 | their state as of an earlier revision. This can be helpful to "roll | |
2234 | back" some or all of a change that should not have been committed. |
|
2234 | back" some or all of a change that should not have been committed. | |
2235 |
|
2235 | |||
2236 | Revert modifies the working directory. It does not commit any |
|
2236 | Revert modifies the working directory. It does not commit any | |
2237 | changes, or change the parent of the current working directory. |
|
2237 | changes, or change the parent of the current working directory. | |
2238 |
|
2238 | |||
2239 | If a file has been deleted, it is recreated. If the executable |
|
2239 | If a file has been deleted, it is recreated. If the executable | |
2240 | mode of a file was changed, it is reset. |
|
2240 | mode of a file was changed, it is reset. | |
2241 |
|
2241 | |||
2242 | If names are given, all files matching the names are reverted. |
|
2242 | If names are given, all files matching the names are reverted. | |
2243 |
|
2243 | |||
2244 | If no arguments are given, all files in the repository are reverted. |
|
2244 | If no arguments are given, all files in the repository are reverted. | |
2245 | """ |
|
2245 | """ | |
2246 | node = opts['rev'] and repo.lookup(opts['rev']) or \ |
|
2246 | node = opts['rev'] and repo.lookup(opts['rev']) or \ | |
2247 | repo.dirstate.parents()[0] |
|
2247 | repo.dirstate.parents()[0] | |
2248 |
|
2248 | |||
2249 | files, choose, anypats = matchpats(repo, pats, opts) |
|
2249 | files, choose, anypats = matchpats(repo, pats, opts) | |
2250 | modified, added, removed, deleted, unknown = repo.changes(match=choose) |
|
2250 | modified, added, removed, deleted, unknown = repo.changes(match=choose) | |
2251 | repo.forget(added) |
|
2251 | repo.forget(added) | |
2252 | repo.undelete(removed) |
|
2252 | repo.undelete(removed) | |
2253 |
|
2253 | |||
2254 | return repo.update(node, False, True, choose, False) |
|
2254 | return repo.update(node, False, True, choose, False) | |
2255 |
|
2255 | |||
2256 | def root(ui, repo): |
|
2256 | def root(ui, repo): | |
2257 | """print the root (top) of the current working dir |
|
2257 | """print the root (top) of the current working dir | |
2258 |
|
2258 | |||
2259 | Print the root directory of the current repository. |
|
2259 | Print the root directory of the current repository. | |
2260 | """ |
|
2260 | """ | |
2261 | ui.write(repo.root + "\n") |
|
2261 | ui.write(repo.root + "\n") | |
2262 |
|
2262 | |||
2263 | def serve(ui, repo, **opts): |
|
2263 | def serve(ui, repo, **opts): | |
2264 | """export the repository via HTTP |
|
2264 | """export the repository via HTTP | |
2265 |
|
2265 | |||
2266 | Start a local HTTP repository browser and pull server. |
|
2266 | Start a local HTTP repository browser and pull server. | |
2267 |
|
2267 | |||
2268 | By default, the server logs accesses to stdout and errors to |
|
2268 | By default, the server logs accesses to stdout and errors to | |
2269 | stderr. Use the "-A" and "-E" options to log to files. |
|
2269 | stderr. Use the "-A" and "-E" options to log to files. | |
2270 | """ |
|
2270 | """ | |
2271 |
|
2271 | |||
2272 | if opts["stdio"]: |
|
2272 | if opts["stdio"]: | |
2273 | fin, fout = sys.stdin, sys.stdout |
|
2273 | fin, fout = sys.stdin, sys.stdout | |
2274 | sys.stdout = sys.stderr |
|
2274 | sys.stdout = sys.stderr | |
2275 |
|
2275 | |||
2276 | # Prevent insertion/deletion of CRs |
|
2276 | # Prevent insertion/deletion of CRs | |
2277 | util.set_binary(fin) |
|
2277 | util.set_binary(fin) | |
2278 | util.set_binary(fout) |
|
2278 | util.set_binary(fout) | |
2279 |
|
2279 | |||
2280 | def getarg(): |
|
2280 | def getarg(): | |
2281 | argline = fin.readline()[:-1] |
|
2281 | argline = fin.readline()[:-1] | |
2282 | arg, l = argline.split() |
|
2282 | arg, l = argline.split() | |
2283 | val = fin.read(int(l)) |
|
2283 | val = fin.read(int(l)) | |
2284 | return arg, val |
|
2284 | return arg, val | |
2285 | def respond(v): |
|
2285 | def respond(v): | |
2286 | fout.write("%d\n" % len(v)) |
|
2286 | fout.write("%d\n" % len(v)) | |
2287 | fout.write(v) |
|
2287 | fout.write(v) | |
2288 | fout.flush() |
|
2288 | fout.flush() | |
2289 |
|
2289 | |||
2290 | lock = None |
|
2290 | lock = None | |
2291 |
|
2291 | |||
2292 | while 1: |
|
2292 | while 1: | |
2293 | cmd = fin.readline()[:-1] |
|
2293 | cmd = fin.readline()[:-1] | |
2294 | if cmd == '': |
|
2294 | if cmd == '': | |
2295 | return |
|
2295 | return | |
2296 | if cmd == "heads": |
|
2296 | if cmd == "heads": | |
2297 | h = repo.heads() |
|
2297 | h = repo.heads() | |
2298 | respond(" ".join(map(hex, h)) + "\n") |
|
2298 | respond(" ".join(map(hex, h)) + "\n") | |
2299 | if cmd == "lock": |
|
2299 | if cmd == "lock": | |
2300 | lock = repo.lock() |
|
2300 | lock = repo.lock() | |
2301 | respond("") |
|
2301 | respond("") | |
2302 | if cmd == "unlock": |
|
2302 | if cmd == "unlock": | |
2303 | if lock: |
|
2303 | if lock: | |
2304 | lock.release() |
|
2304 | lock.release() | |
2305 | lock = None |
|
2305 | lock = None | |
2306 | respond("") |
|
2306 | respond("") | |
2307 | elif cmd == "branches": |
|
2307 | elif cmd == "branches": | |
2308 | arg, nodes = getarg() |
|
2308 | arg, nodes = getarg() | |
2309 | nodes = map(bin, nodes.split(" ")) |
|
2309 | nodes = map(bin, nodes.split(" ")) | |
2310 | r = [] |
|
2310 | r = [] | |
2311 | for b in repo.branches(nodes): |
|
2311 | for b in repo.branches(nodes): | |
2312 | r.append(" ".join(map(hex, b)) + "\n") |
|
2312 | r.append(" ".join(map(hex, b)) + "\n") | |
2313 | respond("".join(r)) |
|
2313 | respond("".join(r)) | |
2314 | elif cmd == "between": |
|
2314 | elif cmd == "between": | |
2315 | arg, pairs = getarg() |
|
2315 | arg, pairs = getarg() | |
2316 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
2316 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | |
2317 | r = [] |
|
2317 | r = [] | |
2318 | for b in repo.between(pairs): |
|
2318 | for b in repo.between(pairs): | |
2319 | r.append(" ".join(map(hex, b)) + "\n") |
|
2319 | r.append(" ".join(map(hex, b)) + "\n") | |
2320 | respond("".join(r)) |
|
2320 | respond("".join(r)) | |
2321 | elif cmd == "changegroup": |
|
2321 | elif cmd == "changegroup": | |
2322 | nodes = [] |
|
2322 | nodes = [] | |
2323 | arg, roots = getarg() |
|
2323 | arg, roots = getarg() | |
2324 | nodes = map(bin, roots.split(" ")) |
|
2324 | nodes = map(bin, roots.split(" ")) | |
2325 |
|
2325 | |||
2326 | cg = repo.changegroup(nodes, 'serve') |
|
2326 | cg = repo.changegroup(nodes, 'serve') | |
2327 | while 1: |
|
2327 | while 1: | |
2328 | d = cg.read(4096) |
|
2328 | d = cg.read(4096) | |
2329 | if not d: |
|
2329 | if not d: | |
2330 | break |
|
2330 | break | |
2331 | fout.write(d) |
|
2331 | fout.write(d) | |
2332 |
|
2332 | |||
2333 | fout.flush() |
|
2333 | fout.flush() | |
2334 |
|
2334 | |||
2335 | elif cmd == "addchangegroup": |
|
2335 | elif cmd == "addchangegroup": | |
2336 | if not lock: |
|
2336 | if not lock: | |
2337 | respond("not locked") |
|
2337 | respond("not locked") | |
2338 | continue |
|
2338 | continue | |
2339 | respond("") |
|
2339 | respond("") | |
2340 |
|
2340 | |||
2341 | r = repo.addchangegroup(fin) |
|
2341 | r = repo.addchangegroup(fin) | |
2342 | respond("") |
|
2342 | respond("") | |
2343 |
|
2343 | |||
2344 | optlist = "name templates style address port ipv6 accesslog errorlog" |
|
2344 | optlist = "name templates style address port ipv6 accesslog errorlog" | |
2345 | for o in optlist.split(): |
|
2345 | for o in optlist.split(): | |
2346 | if opts[o]: |
|
2346 | if opts[o]: | |
2347 | ui.setconfig("web", o, opts[o]) |
|
2347 | ui.setconfig("web", o, opts[o]) | |
2348 |
|
2348 | |||
2349 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2349 | if opts['daemon'] and not opts['daemon_pipefds']: | |
2350 | rfd, wfd = os.pipe() |
|
2350 | rfd, wfd = os.pipe() | |
2351 | args = sys.argv[:] |
|
2351 | args = sys.argv[:] | |
2352 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2352 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | |
2353 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2353 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | |
2354 | args[0], args) |
|
2354 | args[0], args) | |
2355 | os.close(wfd) |
|
2355 | os.close(wfd) | |
2356 | os.read(rfd, 1) |
|
2356 | os.read(rfd, 1) | |
2357 | os._exit(0) |
|
2357 | os._exit(0) | |
2358 |
|
2358 | |||
2359 | try: |
|
2359 | try: | |
2360 | httpd = hgweb.create_server(repo) |
|
2360 | httpd = hgweb.create_server(repo) | |
2361 | except socket.error, inst: |
|
2361 | except socket.error, inst: | |
2362 | raise util.Abort(_('cannot start server: ') + inst.args[1]) |
|
2362 | raise util.Abort(_('cannot start server: ') + inst.args[1]) | |
2363 |
|
2363 | |||
2364 | if ui.verbose: |
|
2364 | if ui.verbose: | |
2365 | addr, port = httpd.socket.getsockname() |
|
2365 | addr, port = httpd.socket.getsockname() | |
2366 | if addr == '0.0.0.0': |
|
2366 | if addr == '0.0.0.0': | |
2367 | addr = socket.gethostname() |
|
2367 | addr = socket.gethostname() | |
2368 | else: |
|
2368 | else: | |
2369 | try: |
|
2369 | try: | |
2370 | addr = socket.gethostbyaddr(addr)[0] |
|
2370 | addr = socket.gethostbyaddr(addr)[0] | |
2371 | except socket.error: |
|
2371 | except socket.error: | |
2372 | pass |
|
2372 | pass | |
2373 | if port != 80: |
|
2373 | if port != 80: | |
2374 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) |
|
2374 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) | |
2375 | else: |
|
2375 | else: | |
2376 | ui.status(_('listening at http://%s/\n') % addr) |
|
2376 | ui.status(_('listening at http://%s/\n') % addr) | |
2377 |
|
2377 | |||
2378 | if opts['pid_file']: |
|
2378 | if opts['pid_file']: | |
2379 | fp = open(opts['pid_file'], 'w') |
|
2379 | fp = open(opts['pid_file'], 'w') | |
2380 | fp.write(str(os.getpid())) |
|
2380 | fp.write(str(os.getpid())) | |
2381 | fp.close() |
|
2381 | fp.close() | |
2382 |
|
2382 | |||
2383 | if opts['daemon_pipefds']: |
|
2383 | if opts['daemon_pipefds']: | |
2384 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2384 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | |
2385 | os.close(rfd) |
|
2385 | os.close(rfd) | |
2386 | os.write(wfd, 'y') |
|
2386 | os.write(wfd, 'y') | |
2387 | os.close(wfd) |
|
2387 | os.close(wfd) | |
2388 | sys.stdout.flush() |
|
2388 | sys.stdout.flush() | |
2389 | sys.stderr.flush() |
|
2389 | sys.stderr.flush() | |
2390 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2390 | fd = os.open(util.nulldev, os.O_RDWR) | |
2391 | if fd != 0: os.dup2(fd, 0) |
|
2391 | if fd != 0: os.dup2(fd, 0) | |
2392 | if fd != 1: os.dup2(fd, 1) |
|
2392 | if fd != 1: os.dup2(fd, 1) | |
2393 | if fd != 2: os.dup2(fd, 2) |
|
2393 | if fd != 2: os.dup2(fd, 2) | |
2394 | if fd not in (0, 1, 2): os.close(fd) |
|
2394 | if fd not in (0, 1, 2): os.close(fd) | |
2395 |
|
2395 | |||
2396 | httpd.serve_forever() |
|
2396 | httpd.serve_forever() | |
2397 |
|
2397 | |||
2398 | def status(ui, repo, *pats, **opts): |
|
2398 | def status(ui, repo, *pats, **opts): | |
2399 | """show changed files in the working directory |
|
2399 | """show changed files in the working directory | |
2400 |
|
2400 | |||
2401 | Show changed files in the repository. If names are |
|
2401 | Show changed files in the repository. If names are | |
2402 | given, only files that match are shown. |
|
2402 | given, only files that match are shown. | |
2403 |
|
2403 | |||
2404 | The codes used to show the status of files are: |
|
2404 | The codes used to show the status of files are: | |
2405 | M = modified |
|
2405 | M = modified | |
2406 | A = added |
|
2406 | A = added | |
2407 | R = removed |
|
2407 | R = removed | |
2408 | ! = deleted, but still tracked |
|
2408 | ! = deleted, but still tracked | |
2409 | ? = not tracked |
|
2409 | ? = not tracked | |
2410 | """ |
|
2410 | """ | |
2411 |
|
2411 | |||
2412 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
2412 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
2413 | cwd = (pats and repo.getcwd()) or '' |
|
2413 | cwd = (pats and repo.getcwd()) or '' | |
2414 | modified, added, removed, deleted, unknown = [ |
|
2414 | modified, added, removed, deleted, unknown = [ | |
2415 | [util.pathto(cwd, x) for x in n] |
|
2415 | [util.pathto(cwd, x) for x in n] | |
2416 | for n in repo.changes(files=files, match=matchfn)] |
|
2416 | for n in repo.changes(files=files, match=matchfn)] | |
2417 |
|
2417 | |||
2418 | changetypes = [(_('modified'), 'M', modified), |
|
2418 | changetypes = [(_('modified'), 'M', modified), | |
2419 | (_('added'), 'A', added), |
|
2419 | (_('added'), 'A', added), | |
2420 | (_('removed'), 'R', removed), |
|
2420 | (_('removed'), 'R', removed), | |
2421 | (_('deleted'), '!', deleted), |
|
2421 | (_('deleted'), '!', deleted), | |
2422 | (_('unknown'), '?', unknown)] |
|
2422 | (_('unknown'), '?', unknown)] | |
2423 |
|
2423 | |||
2424 | end = opts['print0'] and '\0' or '\n' |
|
2424 | end = opts['print0'] and '\0' or '\n' | |
2425 |
|
2425 | |||
2426 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] |
|
2426 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] | |
2427 | or changetypes): |
|
2427 | or changetypes): | |
2428 | if opts['no_status']: |
|
2428 | if opts['no_status']: | |
2429 | format = "%%s%s" % end |
|
2429 | format = "%%s%s" % end | |
2430 | else: |
|
2430 | else: | |
2431 | format = "%s %%s%s" % (char, end); |
|
2431 | format = "%s %%s%s" % (char, end); | |
2432 |
|
2432 | |||
2433 | for f in changes: |
|
2433 | for f in changes: | |
2434 | ui.write(format % f) |
|
2434 | ui.write(format % f) | |
2435 |
|
2435 | |||
2436 | def tag(ui, repo, name, rev_=None, **opts): |
|
2436 | def tag(ui, repo, name, rev_=None, **opts): | |
2437 | """add a tag for the current tip or a given revision |
|
2437 | """add a tag for the current tip or a given revision | |
2438 |
|
2438 | |||
2439 | Name a particular revision using <name>. |
|
2439 | Name a particular revision using <name>. | |
2440 |
|
2440 | |||
2441 | Tags are used to name particular revisions of the repository and are |
|
2441 | Tags are used to name particular revisions of the repository and are | |
2442 | very useful to compare different revision, to go back to significant |
|
2442 | very useful to compare different revision, to go back to significant | |
2443 | earlier versions or to mark branch points as releases, etc. |
|
2443 | earlier versions or to mark branch points as releases, etc. | |
2444 |
|
2444 | |||
2445 | If no revision is given, the tip is used. |
|
2445 | If no revision is given, the tip is used. | |
2446 |
|
2446 | |||
2447 | To facilitate version control, distribution, and merging of tags, |
|
2447 | To facilitate version control, distribution, and merging of tags, | |
2448 | they are stored as a file named ".hgtags" which is managed |
|
2448 | they are stored as a file named ".hgtags" which is managed | |
2449 | similarly to other project files and can be hand-edited if |
|
2449 | similarly to other project files and can be hand-edited if | |
2450 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2450 | necessary. The file '.hg/localtags' is used for local tags (not | |
2451 | shared among repositories). |
|
2451 | shared among repositories). | |
2452 | """ |
|
2452 | """ | |
2453 | if name == "tip": |
|
2453 | if name == "tip": | |
2454 | raise util.Abort(_("the name 'tip' is reserved")) |
|
2454 | raise util.Abort(_("the name 'tip' is reserved")) | |
2455 | if rev_ is not None: |
|
2455 | if rev_ is not None: | |
2456 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2456 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | |
2457 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2457 | "please use 'hg tag [-r REV] NAME' instead\n")) | |
2458 | if opts['rev']: |
|
2458 | if opts['rev']: | |
2459 | raise util.Abort(_("use only one form to specify the revision")) |
|
2459 | raise util.Abort(_("use only one form to specify the revision")) | |
2460 | if opts['rev']: |
|
2460 | if opts['rev']: | |
2461 | rev_ = opts['rev'] |
|
2461 | rev_ = opts['rev'] | |
2462 | if rev_: |
|
2462 | if rev_: | |
2463 | r = hex(repo.lookup(rev_)) |
|
2463 | r = hex(repo.lookup(rev_)) | |
2464 | else: |
|
2464 | else: | |
2465 | r = hex(repo.changelog.tip()) |
|
2465 | r = hex(repo.changelog.tip()) | |
2466 |
|
2466 | |||
2467 | disallowed = (revrangesep, '\r', '\n') |
|
2467 | disallowed = (revrangesep, '\r', '\n') | |
2468 | for c in disallowed: |
|
2468 | for c in disallowed: | |
2469 | if name.find(c) >= 0: |
|
2469 | if name.find(c) >= 0: | |
2470 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) |
|
2470 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) | |
2471 |
|
2471 | |||
2472 | repo.hook('pretag', throw=True, node=r, tag=name, |
|
2472 | repo.hook('pretag', throw=True, node=r, tag=name, | |
2473 | local=int(not not opts['local'])) |
|
2473 | local=int(not not opts['local'])) | |
2474 |
|
2474 | |||
2475 | if opts['local']: |
|
2475 | if opts['local']: | |
2476 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) |
|
2476 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) | |
2477 | repo.hook('tag', node=r, tag=name, local=1) |
|
2477 | repo.hook('tag', node=r, tag=name, local=1) | |
2478 | return |
|
2478 | return | |
2479 |
|
2479 | |||
2480 | for x in repo.changes(): |
|
2480 | for x in repo.changes(): | |
2481 | if ".hgtags" in x: |
|
2481 | if ".hgtags" in x: | |
2482 | raise util.Abort(_("working copy of .hgtags is changed " |
|
2482 | raise util.Abort(_("working copy of .hgtags is changed " | |
2483 | "(please commit .hgtags manually)")) |
|
2483 | "(please commit .hgtags manually)")) | |
2484 |
|
2484 | |||
2485 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) |
|
2485 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) | |
2486 | if repo.dirstate.state(".hgtags") == '?': |
|
2486 | if repo.dirstate.state(".hgtags") == '?': | |
2487 | repo.add([".hgtags"]) |
|
2487 | repo.add([".hgtags"]) | |
2488 |
|
2488 | |||
2489 | message = (opts['message'] or |
|
2489 | message = (opts['message'] or | |
2490 | _("Added tag %s for changeset %s") % (name, r)) |
|
2490 | _("Added tag %s for changeset %s") % (name, r)) | |
2491 | try: |
|
2491 | try: | |
2492 | repo.commit([".hgtags"], message, opts['user'], opts['date']) |
|
2492 | repo.commit([".hgtags"], message, opts['user'], opts['date']) | |
2493 | repo.hook('tag', node=r, tag=name, local=0) |
|
2493 | repo.hook('tag', node=r, tag=name, local=0) | |
2494 | except ValueError, inst: |
|
2494 | except ValueError, inst: | |
2495 | raise util.Abort(str(inst)) |
|
2495 | raise util.Abort(str(inst)) | |
2496 |
|
2496 | |||
2497 | def tags(ui, repo): |
|
2497 | def tags(ui, repo): | |
2498 | """list repository tags |
|
2498 | """list repository tags | |
2499 |
|
2499 | |||
2500 | List the repository tags. |
|
2500 | List the repository tags. | |
2501 |
|
2501 | |||
2502 | This lists both regular and local tags. |
|
2502 | This lists both regular and local tags. | |
2503 | """ |
|
2503 | """ | |
2504 |
|
2504 | |||
2505 | l = repo.tagslist() |
|
2505 | l = repo.tagslist() | |
2506 | l.reverse() |
|
2506 | l.reverse() | |
2507 | for t, n in l: |
|
2507 | for t, n in l: | |
2508 | try: |
|
2508 | try: | |
2509 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) |
|
2509 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) | |
2510 | except KeyError: |
|
2510 | except KeyError: | |
2511 | r = " ?:?" |
|
2511 | r = " ?:?" | |
2512 | ui.write("%-30s %s\n" % (t, r)) |
|
2512 | ui.write("%-30s %s\n" % (t, r)) | |
2513 |
|
2513 | |||
2514 | def tip(ui, repo, **opts): |
|
2514 | def tip(ui, repo, **opts): | |
2515 | """show the tip revision |
|
2515 | """show the tip revision | |
2516 |
|
2516 | |||
2517 | Show the tip revision. |
|
2517 | Show the tip revision. | |
2518 | """ |
|
2518 | """ | |
2519 | n = repo.changelog.tip() |
|
2519 | n = repo.changelog.tip() | |
2520 | br = None |
|
2520 | br = None | |
2521 | if opts['branches']: |
|
2521 | if opts['branches']: | |
2522 | br = repo.branchlookup([n]) |
|
2522 | br = repo.branchlookup([n]) | |
2523 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
|
2523 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) | |
2524 | if opts['patch']: |
|
2524 | if opts['patch']: | |
2525 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) |
|
2525 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) | |
2526 |
|
2526 | |||
2527 | def unbundle(ui, repo, fname, **opts): |
|
2527 | def unbundle(ui, repo, fname, **opts): | |
2528 | """apply a changegroup file |
|
2528 | """apply a changegroup file | |
2529 |
|
2529 | |||
2530 | Apply a compressed changegroup file generated by the bundle |
|
2530 | Apply a compressed changegroup file generated by the bundle | |
2531 | command. |
|
2531 | command. | |
2532 | """ |
|
2532 | """ | |
2533 | f = urllib.urlopen(fname) |
|
2533 | f = urllib.urlopen(fname) | |
2534 |
|
2534 | |||
2535 | header = f.read(4) |
|
2535 | header = f.read(4) | |
2536 | if header == "HG10": |
|
2536 | if header == "HG10": | |
2537 | def generator(f): |
|
2537 | def generator(f): | |
2538 | zd = bz2.BZ2Decompressor() |
|
2538 | zd = bz2.BZ2Decompressor() | |
2539 | for chunk in f: |
|
2539 | for chunk in f: | |
2540 | yield zd.decompress(chunk) |
|
2540 | yield zd.decompress(chunk) | |
2541 | elif header == "HG11": |
|
2541 | elif header == "HG11": | |
2542 | def generator(f): |
|
2542 | def generator(f): | |
2543 | for chunk in f: |
|
2543 | for chunk in f: | |
2544 | yield chunk |
|
2544 | yield chunk | |
2545 | else: |
|
2545 | else: | |
2546 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) |
|
2546 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) | |
2547 | gen = generator(util.filechunkiter(f, 4096)) |
|
2547 | gen = generator(util.filechunkiter(f, 4096)) | |
2548 | if repo.addchangegroup(util.chunkbuffer(gen)): |
|
2548 | if repo.addchangegroup(util.chunkbuffer(gen)): | |
2549 | return 1 |
|
2549 | return 1 | |
2550 |
|
2550 | |||
2551 | if opts['update']: |
|
2551 | if opts['update']: | |
2552 | return update(ui, repo) |
|
2552 | return update(ui, repo) | |
2553 | else: |
|
2553 | else: | |
2554 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2554 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2555 |
|
2555 | |||
2556 | def undo(ui, repo): |
|
2556 | def undo(ui, repo): | |
2557 | """undo the last commit or pull |
|
2557 | """undo the last commit or pull | |
2558 |
|
2558 | |||
2559 | Roll back the last pull or commit transaction on the |
|
2559 | Roll back the last pull or commit transaction on the | |
2560 | repository, restoring the project to its earlier state. |
|
2560 | repository, restoring the project to its earlier state. | |
2561 |
|
2561 | |||
2562 | This command should be used with care. There is only one level of |
|
2562 | This command should be used with care. There is only one level of | |
2563 | undo and there is no redo. |
|
2563 | undo and there is no redo. | |
2564 |
|
2564 | |||
2565 | This command is not intended for use on public repositories. Once |
|
2565 | This command is not intended for use on public repositories. Once | |
2566 | a change is visible for pull by other users, undoing it locally is |
|
2566 | a change is visible for pull by other users, undoing it locally is | |
2567 | ineffective. |
|
2567 | ineffective. | |
2568 | """ |
|
2568 | """ | |
2569 | repo.undo() |
|
2569 | repo.undo() | |
2570 |
|
2570 | |||
2571 | def update(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2571 | def update(ui, repo, node=None, merge=False, clean=False, force=None, | |
2572 | branch=None, **opts): |
|
2572 | branch=None, **opts): | |
2573 | """update or merge working directory |
|
2573 | """update or merge working directory | |
2574 |
|
2574 | |||
2575 | Update the working directory to the specified revision. |
|
2575 | Update the working directory to the specified revision. | |
2576 |
|
2576 | |||
2577 | If there are no outstanding changes in the working directory and |
|
2577 | If there are no outstanding changes in the working directory and | |
2578 | there is a linear relationship between the current version and the |
|
2578 | there is a linear relationship between the current version and the | |
2579 | requested version, the result is the requested version. |
|
2579 | requested version, the result is the requested version. | |
2580 |
|
2580 | |||
2581 | Otherwise the result is a merge between the contents of the |
|
2581 | Otherwise the result is a merge between the contents of the | |
2582 | current working directory and the requested version. Files that |
|
2582 | current working directory and the requested version. Files that | |
2583 | changed between either parent are marked as changed for the next |
|
2583 | changed between either parent are marked as changed for the next | |
2584 | commit and a commit must be performed before any further updates |
|
2584 | commit and a commit must be performed before any further updates | |
2585 | are allowed. |
|
2585 | are allowed. | |
2586 |
|
2586 | |||
2587 | By default, update will refuse to run if doing so would require |
|
2587 | By default, update will refuse to run if doing so would require | |
2588 | merging or discarding local changes. |
|
2588 | merging or discarding local changes. | |
2589 | """ |
|
2589 | """ | |
2590 | if branch: |
|
2590 | if branch: | |
2591 | br = repo.branchlookup(branch=branch) |
|
2591 | br = repo.branchlookup(branch=branch) | |
2592 | found = [] |
|
2592 | found = [] | |
2593 | for x in br: |
|
2593 | for x in br: | |
2594 | if branch in br[x]: |
|
2594 | if branch in br[x]: | |
2595 | found.append(x) |
|
2595 | found.append(x) | |
2596 | if len(found) > 1: |
|
2596 | if len(found) > 1: | |
2597 | ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2597 | ui.warn(_("Found multiple heads for %s\n") % branch) | |
2598 | for x in found: |
|
2598 | for x in found: | |
2599 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) |
|
2599 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) | |
2600 | return 1 |
|
2600 | return 1 | |
2601 | if len(found) == 1: |
|
2601 | if len(found) == 1: | |
2602 | node = found[0] |
|
2602 | node = found[0] | |
2603 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) |
|
2603 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) | |
2604 | else: |
|
2604 | else: | |
2605 | ui.warn(_("branch %s not found\n") % (branch)) |
|
2605 | ui.warn(_("branch %s not found\n") % (branch)) | |
2606 | return 1 |
|
2606 | return 1 | |
2607 | else: |
|
2607 | else: | |
2608 | node = node and repo.lookup(node) or repo.changelog.tip() |
|
2608 | node = node and repo.lookup(node) or repo.changelog.tip() | |
2609 | return repo.update(node, allow=merge, force=clean, forcemerge=force) |
|
2609 | return repo.update(node, allow=merge, force=clean, forcemerge=force) | |
2610 |
|
2610 | |||
2611 | def verify(ui, repo): |
|
2611 | def verify(ui, repo): | |
2612 | """verify the integrity of the repository |
|
2612 | """verify the integrity of the repository | |
2613 |
|
2613 | |||
2614 | Verify the integrity of the current repository. |
|
2614 | Verify the integrity of the current repository. | |
2615 |
|
2615 | |||
2616 | This will perform an extensive check of the repository's |
|
2616 | This will perform an extensive check of the repository's | |
2617 | integrity, validating the hashes and checksums of each entry in |
|
2617 | integrity, validating the hashes and checksums of each entry in | |
2618 | the changelog, manifest, and tracked files, as well as the |
|
2618 | the changelog, manifest, and tracked files, as well as the | |
2619 | integrity of their crosslinks and indices. |
|
2619 | integrity of their crosslinks and indices. | |
2620 | """ |
|
2620 | """ | |
2621 | return repo.verify() |
|
2621 | return repo.verify() | |
2622 |
|
2622 | |||
2623 | # Command options and aliases are listed here, alphabetically |
|
2623 | # Command options and aliases are listed here, alphabetically | |
2624 |
|
2624 | |||
2625 | table = { |
|
2625 | table = { | |
2626 | "^add": |
|
2626 | "^add": | |
2627 | (add, |
|
2627 | (add, | |
2628 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2628 | [('I', 'include', [], _('include names matching the given patterns')), | |
2629 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2629 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2630 | _('hg add [OPTION]... [FILE]...')), |
|
2630 | _('hg add [OPTION]... [FILE]...')), | |
2631 | "addremove": |
|
2631 | "addremove": | |
2632 | (addremove, |
|
2632 | (addremove, | |
2633 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2633 | [('I', 'include', [], _('include names matching the given patterns')), | |
2634 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2634 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2635 | _('hg addremove [OPTION]... [FILE]...')), |
|
2635 | _('hg addremove [OPTION]... [FILE]...')), | |
2636 | "^annotate": |
|
2636 | "^annotate": | |
2637 | (annotate, |
|
2637 | (annotate, | |
2638 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2638 | [('r', 'rev', '', _('annotate the specified revision')), | |
2639 | ('a', 'text', None, _('treat all files as text')), |
|
2639 | ('a', 'text', None, _('treat all files as text')), | |
2640 | ('u', 'user', None, _('list the author')), |
|
2640 | ('u', 'user', None, _('list the author')), | |
2641 | ('d', 'date', None, _('list the date')), |
|
2641 | ('d', 'date', None, _('list the date')), | |
2642 | ('n', 'number', None, _('list the revision number (default)')), |
|
2642 | ('n', 'number', None, _('list the revision number (default)')), | |
2643 | ('c', 'changeset', None, _('list the changeset')), |
|
2643 | ('c', 'changeset', None, _('list the changeset')), | |
2644 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2644 | ('I', 'include', [], _('include names matching the given patterns')), | |
2645 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2645 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2646 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2646 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | |
2647 | "bundle": |
|
2647 | "bundle": | |
2648 | (bundle, |
|
2648 | (bundle, | |
2649 | [], |
|
2649 | [('f', 'force', None, | |
|
2650 | _('run even when remote repository is unrelated'))], | |||
2650 | _('hg bundle FILE DEST')), |
|
2651 | _('hg bundle FILE DEST')), | |
2651 | "cat": |
|
2652 | "cat": | |
2652 | (cat, |
|
2653 | (cat, | |
2653 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2654 | [('o', 'output', '', _('print output to file with formatted name')), | |
2654 | ('r', 'rev', '', _('print the given revision')), |
|
2655 | ('r', 'rev', '', _('print the given revision')), | |
2655 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2656 | ('I', 'include', [], _('include names matching the given patterns')), | |
2656 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2657 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2657 | _('hg cat [OPTION]... FILE...')), |
|
2658 | _('hg cat [OPTION]... FILE...')), | |
2658 | "^clone": |
|
2659 | "^clone": | |
2659 | (clone, |
|
2660 | (clone, | |
2660 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2661 | [('U', 'noupdate', None, _('do not update the new working directory')), | |
2661 | ('r', 'rev', [], |
|
2662 | ('r', 'rev', [], | |
2662 | _('a changeset you would like to have after cloning')), |
|
2663 | _('a changeset you would like to have after cloning')), | |
2663 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2664 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
2664 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2665 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2665 | ('', 'remotecmd', '', |
|
2666 | ('', 'remotecmd', '', | |
2666 | _('specify hg command to run on the remote side'))], |
|
2667 | _('specify hg command to run on the remote side'))], | |
2667 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2668 | _('hg clone [OPTION]... SOURCE [DEST]')), | |
2668 | "^commit|ci": |
|
2669 | "^commit|ci": | |
2669 | (commit, |
|
2670 | (commit, | |
2670 | [('A', 'addremove', None, _('run addremove during commit')), |
|
2671 | [('A', 'addremove', None, _('run addremove during commit')), | |
2671 | ('m', 'message', '', _('use <text> as commit message')), |
|
2672 | ('m', 'message', '', _('use <text> as commit message')), | |
2672 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
2673 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
2673 | ('d', 'date', '', _('record datecode as commit date')), |
|
2674 | ('d', 'date', '', _('record datecode as commit date')), | |
2674 | ('u', 'user', '', _('record user as commiter')), |
|
2675 | ('u', 'user', '', _('record user as commiter')), | |
2675 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2676 | ('I', 'include', [], _('include names matching the given patterns')), | |
2676 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2677 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2677 | _('hg commit [OPTION]... [FILE]...')), |
|
2678 | _('hg commit [OPTION]... [FILE]...')), | |
2678 | "copy|cp": |
|
2679 | "copy|cp": | |
2679 | (copy, |
|
2680 | (copy, | |
2680 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2681 | [('A', 'after', None, _('record a copy that has already occurred')), | |
2681 | ('f', 'force', None, |
|
2682 | ('f', 'force', None, | |
2682 | _('forcibly copy over an existing managed file')), |
|
2683 | _('forcibly copy over an existing managed file')), | |
2683 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2684 | ('I', 'include', [], _('include names matching the given patterns')), | |
2684 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2685 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2685 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2686 | _('hg copy [OPTION]... [SOURCE]... DEST')), | |
2686 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2687 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | |
2687 | "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')), |
|
2688 | "debugcomplete": (debugcomplete, [], _('debugcomplete CMD')), | |
2688 | "debugrebuildstate": |
|
2689 | "debugrebuildstate": | |
2689 | (debugrebuildstate, |
|
2690 | (debugrebuildstate, | |
2690 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2691 | [('r', 'rev', '', _('revision to rebuild to'))], | |
2691 | _('debugrebuildstate [-r REV] [REV]')), |
|
2692 | _('debugrebuildstate [-r REV] [REV]')), | |
2692 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2693 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | |
2693 | "debugconfig": (debugconfig, [], _('debugconfig')), |
|
2694 | "debugconfig": (debugconfig, [], _('debugconfig')), | |
2694 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2695 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | |
2695 | "debugstate": (debugstate, [], _('debugstate')), |
|
2696 | "debugstate": (debugstate, [], _('debugstate')), | |
2696 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2697 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | |
2697 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2698 | "debugindex": (debugindex, [], _('debugindex FILE')), | |
2698 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2699 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | |
2699 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2700 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), | |
2700 | "debugwalk": |
|
2701 | "debugwalk": | |
2701 | (debugwalk, |
|
2702 | (debugwalk, | |
2702 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2703 | [('I', 'include', [], _('include names matching the given patterns')), | |
2703 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2704 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2704 | _('debugwalk [OPTION]... [FILE]...')), |
|
2705 | _('debugwalk [OPTION]... [FILE]...')), | |
2705 | "^diff": |
|
2706 | "^diff": | |
2706 | (diff, |
|
2707 | (diff, | |
2707 | [('r', 'rev', [], _('revision')), |
|
2708 | [('r', 'rev', [], _('revision')), | |
2708 | ('a', 'text', None, _('treat all files as text')), |
|
2709 | ('a', 'text', None, _('treat all files as text')), | |
2709 | ('p', 'show-function', None, |
|
2710 | ('p', 'show-function', None, | |
2710 | _('show which function each change is in')), |
|
2711 | _('show which function each change is in')), | |
2711 | ('w', 'ignore-all-space', None, |
|
2712 | ('w', 'ignore-all-space', None, | |
2712 | _('ignore white space when comparing lines')), |
|
2713 | _('ignore white space when comparing lines')), | |
2713 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2714 | ('I', 'include', [], _('include names matching the given patterns')), | |
2714 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2715 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2715 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), |
|
2716 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), | |
2716 | "^export": |
|
2717 | "^export": | |
2717 | (export, |
|
2718 | (export, | |
2718 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2719 | [('o', 'output', '', _('print output to file with formatted name')), | |
2719 | ('a', 'text', None, _('treat all files as text')), |
|
2720 | ('a', 'text', None, _('treat all files as text')), | |
2720 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2721 | ('', 'switch-parent', None, _('diff against the second parent'))], | |
2721 | _('hg export [-a] [-o OUTFILESPEC] REV...')), |
|
2722 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | |
2722 | "forget": |
|
2723 | "forget": | |
2723 | (forget, |
|
2724 | (forget, | |
2724 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2725 | [('I', 'include', [], _('include names matching the given patterns')), | |
2725 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2726 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2726 | _('hg forget [OPTION]... FILE...')), |
|
2727 | _('hg forget [OPTION]... FILE...')), | |
2727 | "grep": |
|
2728 | "grep": | |
2728 | (grep, |
|
2729 | (grep, | |
2729 | [('0', 'print0', None, _('end fields with NUL')), |
|
2730 | [('0', 'print0', None, _('end fields with NUL')), | |
2730 | ('', 'all', None, _('print all revisions that match')), |
|
2731 | ('', 'all', None, _('print all revisions that match')), | |
2731 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2732 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2732 | ('l', 'files-with-matches', None, |
|
2733 | ('l', 'files-with-matches', None, | |
2733 | _('print only filenames and revs that match')), |
|
2734 | _('print only filenames and revs that match')), | |
2734 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2735 | ('n', 'line-number', None, _('print matching line numbers')), | |
2735 | ('r', 'rev', [], _('search in given revision range')), |
|
2736 | ('r', 'rev', [], _('search in given revision range')), | |
2736 | ('u', 'user', None, _('print user who committed change')), |
|
2737 | ('u', 'user', None, _('print user who committed change')), | |
2737 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2738 | ('I', 'include', [], _('include names matching the given patterns')), | |
2738 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2739 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2739 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2740 | _('hg grep [OPTION]... PATTERN [FILE]...')), | |
2740 | "heads": |
|
2741 | "heads": | |
2741 | (heads, |
|
2742 | (heads, | |
2742 | [('b', 'branches', None, _('show branches')), |
|
2743 | [('b', 'branches', None, _('show branches')), | |
2743 | ('', 'style', '', _('display using template map file')), |
|
2744 | ('', 'style', '', _('display using template map file')), | |
2744 | ('r', 'rev', '', _('show only heads which are descendants of rev')), |
|
2745 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | |
2745 | ('', 'template', '', _('display with template'))], |
|
2746 | ('', 'template', '', _('display with template'))], | |
2746 | _('hg heads [-b] [-r <rev>]')), |
|
2747 | _('hg heads [-b] [-r <rev>]')), | |
2747 | "help": (help_, [], _('hg help [COMMAND]')), |
|
2748 | "help": (help_, [], _('hg help [COMMAND]')), | |
2748 | "identify|id": (identify, [], _('hg identify')), |
|
2749 | "identify|id": (identify, [], _('hg identify')), | |
2749 | "import|patch": |
|
2750 | "import|patch": | |
2750 | (import_, |
|
2751 | (import_, | |
2751 | [('p', 'strip', 1, |
|
2752 | [('p', 'strip', 1, | |
2752 | _('directory strip option for patch. This has the same\n') + |
|
2753 | _('directory strip option for patch. This has the same\n') + | |
2753 | _('meaning as the corresponding patch option')), |
|
2754 | _('meaning as the corresponding patch option')), | |
2754 | ('b', 'base', '', _('base path')), |
|
2755 | ('b', 'base', '', _('base path')), | |
2755 | ('f', 'force', None, |
|
2756 | ('f', 'force', None, | |
2756 | _('skip check for outstanding uncommitted changes'))], |
|
2757 | _('skip check for outstanding uncommitted changes'))], | |
2757 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), |
|
2758 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), | |
2758 | "incoming|in": (incoming, |
|
2759 | "incoming|in": (incoming, | |
2759 | [('M', 'no-merges', None, _('do not show merges')), |
|
2760 | [('M', 'no-merges', None, _('do not show merges')), | |
|
2761 | ('f', 'force', None, | |||
|
2762 | _('run even when remote repository is unrelated')), | |||
2760 | ('', 'style', '', _('display using template map file')), |
|
2763 | ('', 'style', '', _('display using template map file')), | |
2761 | ('n', 'newest-first', None, _('show newest record first')), |
|
2764 | ('n', 'newest-first', None, _('show newest record first')), | |
2762 | ('', 'bundle', '', _('file to store the bundles into')), |
|
2765 | ('', 'bundle', '', _('file to store the bundles into')), | |
2763 | ('p', 'patch', None, _('show patch')), |
|
2766 | ('p', 'patch', None, _('show patch')), | |
2764 | ('', 'template', '', _('display with template'))], |
|
2767 | ('', 'template', '', _('display with template'))], | |
2765 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), |
|
2768 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), | |
2766 | "^init": (init, [], _('hg init [DEST]')), |
|
2769 | "^init": (init, [], _('hg init [DEST]')), | |
2767 | "locate": |
|
2770 | "locate": | |
2768 | (locate, |
|
2771 | (locate, | |
2769 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
2772 | [('r', 'rev', '', _('search the repository as it stood at rev')), | |
2770 | ('0', 'print0', None, |
|
2773 | ('0', 'print0', None, | |
2771 | _('end filenames with NUL, for use with xargs')), |
|
2774 | _('end filenames with NUL, for use with xargs')), | |
2772 | ('f', 'fullpath', None, |
|
2775 | ('f', 'fullpath', None, | |
2773 | _('print complete paths from the filesystem root')), |
|
2776 | _('print complete paths from the filesystem root')), | |
2774 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2777 | ('I', 'include', [], _('include names matching the given patterns')), | |
2775 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2778 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2776 | _('hg locate [OPTION]... [PATTERN]...')), |
|
2779 | _('hg locate [OPTION]... [PATTERN]...')), | |
2777 | "^log|history": |
|
2780 | "^log|history": | |
2778 | (log, |
|
2781 | (log, | |
2779 | [('b', 'branches', None, _('show branches')), |
|
2782 | [('b', 'branches', None, _('show branches')), | |
2780 | ('k', 'keyword', [], _('search for a keyword')), |
|
2783 | ('k', 'keyword', [], _('search for a keyword')), | |
2781 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
2784 | ('l', 'limit', '', _('limit number of changes displayed')), | |
2782 | ('r', 'rev', [], _('show the specified revision or range')), |
|
2785 | ('r', 'rev', [], _('show the specified revision or range')), | |
2783 | ('M', 'no-merges', None, _('do not show merges')), |
|
2786 | ('M', 'no-merges', None, _('do not show merges')), | |
2784 | ('', 'style', '', _('display using template map file')), |
|
2787 | ('', 'style', '', _('display using template map file')), | |
2785 | ('m', 'only-merges', None, _('show only merges')), |
|
2788 | ('m', 'only-merges', None, _('show only merges')), | |
2786 | ('p', 'patch', None, _('show patch')), |
|
2789 | ('p', 'patch', None, _('show patch')), | |
2787 | ('', 'template', '', _('display with template')), |
|
2790 | ('', 'template', '', _('display with template')), | |
2788 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2791 | ('I', 'include', [], _('include names matching the given patterns')), | |
2789 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2792 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2790 | _('hg log [OPTION]... [FILE]')), |
|
2793 | _('hg log [OPTION]... [FILE]')), | |
2791 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
2794 | "manifest": (manifest, [], _('hg manifest [REV]')), | |
2792 | "outgoing|out": (outgoing, |
|
2795 | "outgoing|out": (outgoing, | |
2793 | [('M', 'no-merges', None, _('do not show merges')), |
|
2796 | [('M', 'no-merges', None, _('do not show merges')), | |
|
2797 | ('f', 'force', None, | |||
|
2798 | _('run even when remote repository is unrelated')), | |||
2794 | ('p', 'patch', None, _('show patch')), |
|
2799 | ('p', 'patch', None, _('show patch')), | |
2795 | ('', 'style', '', _('display using template map file')), |
|
2800 | ('', 'style', '', _('display using template map file')), | |
2796 | ('n', 'newest-first', None, _('show newest record first')), |
|
2801 | ('n', 'newest-first', None, _('show newest record first')), | |
2797 | ('', 'template', '', _('display with template'))], |
|
2802 | ('', 'template', '', _('display with template'))], | |
2798 | _('hg outgoing [-M] [-p] [-n] [DEST]')), |
|
2803 | _('hg outgoing [-M] [-p] [-n] [DEST]')), | |
2799 | "^parents": |
|
2804 | "^parents": | |
2800 | (parents, |
|
2805 | (parents, | |
2801 | [('b', 'branches', None, _('show branches')), |
|
2806 | [('b', 'branches', None, _('show branches')), | |
2802 | ('', 'style', '', _('display using template map file')), |
|
2807 | ('', 'style', '', _('display using template map file')), | |
2803 | ('', 'template', '', _('display with template'))], |
|
2808 | ('', 'template', '', _('display with template'))], | |
2804 | _('hg parents [-b] [REV]')), |
|
2809 | _('hg parents [-b] [REV]')), | |
2805 | "paths": (paths, [], _('hg paths [NAME]')), |
|
2810 | "paths": (paths, [], _('hg paths [NAME]')), | |
2806 | "^pull": |
|
2811 | "^pull": | |
2807 | (pull, |
|
2812 | (pull, | |
2808 | [('u', 'update', None, |
|
2813 | [('u', 'update', None, | |
2809 | _('update the working directory to tip after pull')), |
|
2814 | _('update the working directory to tip after pull')), | |
2810 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2815 | ('e', 'ssh', '', _('specify ssh command to use')), | |
|
2816 | ('f', 'force', None, | |||
|
2817 | _('run even when remote repository is unrelated')), | |||
2811 | ('r', 'rev', [], _('a specific revision you would like to pull')), |
|
2818 | ('r', 'rev', [], _('a specific revision you would like to pull')), | |
2812 | ('', 'remotecmd', '', |
|
2819 | ('', 'remotecmd', '', | |
2813 | _('specify hg command to run on the remote side'))], |
|
2820 | _('specify hg command to run on the remote side'))], | |
2814 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), |
|
2821 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), | |
2815 | "^push": |
|
2822 | "^push": | |
2816 | (push, |
|
2823 | (push, | |
2817 | [('f', 'force', None, _('force push')), |
|
2824 | [('f', 'force', None, _('force push')), | |
2818 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2825 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2819 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
2826 | ('r', 'rev', [], _('a specific revision you would like to push')), | |
2820 | ('', 'remotecmd', '', |
|
2827 | ('', 'remotecmd', '', | |
2821 | _('specify hg command to run on the remote side'))], |
|
2828 | _('specify hg command to run on the remote side'))], | |
2822 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), |
|
2829 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), | |
2823 | "debugrawcommit|rawcommit": |
|
2830 | "debugrawcommit|rawcommit": | |
2824 | (rawcommit, |
|
2831 | (rawcommit, | |
2825 | [('p', 'parent', [], _('parent')), |
|
2832 | [('p', 'parent', [], _('parent')), | |
2826 | ('d', 'date', '', _('date code')), |
|
2833 | ('d', 'date', '', _('date code')), | |
2827 | ('u', 'user', '', _('user')), |
|
2834 | ('u', 'user', '', _('user')), | |
2828 | ('F', 'files', '', _('file list')), |
|
2835 | ('F', 'files', '', _('file list')), | |
2829 | ('m', 'message', '', _('commit message')), |
|
2836 | ('m', 'message', '', _('commit message')), | |
2830 | ('l', 'logfile', '', _('commit message file'))], |
|
2837 | ('l', 'logfile', '', _('commit message file'))], | |
2831 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
2838 | _('hg debugrawcommit [OPTION]... [FILE]...')), | |
2832 | "recover": (recover, [], _('hg recover')), |
|
2839 | "recover": (recover, [], _('hg recover')), | |
2833 | "^remove|rm": |
|
2840 | "^remove|rm": | |
2834 | (remove, |
|
2841 | (remove, | |
2835 | [('f', 'force', None, _('remove file even if modified')), |
|
2842 | [('f', 'force', None, _('remove file even if modified')), | |
2836 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2843 | ('I', 'include', [], _('include names matching the given patterns')), | |
2837 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2844 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2838 | _('hg remove [OPTION]... FILE...')), |
|
2845 | _('hg remove [OPTION]... FILE...')), | |
2839 | "rename|mv": |
|
2846 | "rename|mv": | |
2840 | (rename, |
|
2847 | (rename, | |
2841 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
2848 | [('A', 'after', None, _('record a rename that has already occurred')), | |
2842 | ('f', 'force', None, |
|
2849 | ('f', 'force', None, | |
2843 | _('forcibly copy over an existing managed file')), |
|
2850 | _('forcibly copy over an existing managed file')), | |
2844 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2851 | ('I', 'include', [], _('include names matching the given patterns')), | |
2845 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2852 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2846 | _('hg rename [OPTION]... SOURCE... DEST')), |
|
2853 | _('hg rename [OPTION]... SOURCE... DEST')), | |
2847 | "^revert": |
|
2854 | "^revert": | |
2848 | (revert, |
|
2855 | (revert, | |
2849 | [('r', 'rev', '', _('revision to revert to')), |
|
2856 | [('r', 'rev', '', _('revision to revert to')), | |
2850 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2857 | ('I', 'include', [], _('include names matching the given patterns')), | |
2851 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2858 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2852 | _('hg revert [-r REV] [NAME]...')), |
|
2859 | _('hg revert [-r REV] [NAME]...')), | |
2853 | "root": (root, [], _('hg root')), |
|
2860 | "root": (root, [], _('hg root')), | |
2854 | "^serve": |
|
2861 | "^serve": | |
2855 | (serve, |
|
2862 | (serve, | |
2856 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
2863 | [('A', 'accesslog', '', _('name of access log file to write to')), | |
2857 | ('d', 'daemon', None, _('run server in background')), |
|
2864 | ('d', 'daemon', None, _('run server in background')), | |
2858 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
2865 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
2859 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
2866 | ('E', 'errorlog', '', _('name of error log file to write to')), | |
2860 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
2867 | ('p', 'port', 0, _('port to use (default: 8000)')), | |
2861 | ('a', 'address', '', _('address to use')), |
|
2868 | ('a', 'address', '', _('address to use')), | |
2862 | ('n', 'name', '', |
|
2869 | ('n', 'name', '', | |
2863 | _('name to show in web pages (default: working dir)')), |
|
2870 | _('name to show in web pages (default: working dir)')), | |
2864 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
2871 | ('', 'pid-file', '', _('name of file to write process ID to')), | |
2865 | ('', 'stdio', None, _('for remote clients')), |
|
2872 | ('', 'stdio', None, _('for remote clients')), | |
2866 | ('t', 'templates', '', _('web templates to use')), |
|
2873 | ('t', 'templates', '', _('web templates to use')), | |
2867 | ('', 'style', '', _('template style to use')), |
|
2874 | ('', 'style', '', _('template style to use')), | |
2868 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
2875 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | |
2869 | _('hg serve [OPTION]...')), |
|
2876 | _('hg serve [OPTION]...')), | |
2870 | "^status|st": |
|
2877 | "^status|st": | |
2871 | (status, |
|
2878 | (status, | |
2872 | [('m', 'modified', None, _('show only modified files')), |
|
2879 | [('m', 'modified', None, _('show only modified files')), | |
2873 | ('a', 'added', None, _('show only added files')), |
|
2880 | ('a', 'added', None, _('show only added files')), | |
2874 | ('r', 'removed', None, _('show only removed files')), |
|
2881 | ('r', 'removed', None, _('show only removed files')), | |
2875 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
2882 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
2876 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
2883 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
2877 | ('n', 'no-status', None, _('hide status prefix')), |
|
2884 | ('n', 'no-status', None, _('hide status prefix')), | |
2878 | ('0', 'print0', None, |
|
2885 | ('0', 'print0', None, | |
2879 | _('end filenames with NUL, for use with xargs')), |
|
2886 | _('end filenames with NUL, for use with xargs')), | |
2880 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2887 | ('I', 'include', [], _('include names matching the given patterns')), | |
2881 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2888 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2882 | _('hg status [OPTION]... [FILE]...')), |
|
2889 | _('hg status [OPTION]... [FILE]...')), | |
2883 | "tag": |
|
2890 | "tag": | |
2884 | (tag, |
|
2891 | (tag, | |
2885 | [('l', 'local', None, _('make the tag local')), |
|
2892 | [('l', 'local', None, _('make the tag local')), | |
2886 | ('m', 'message', '', _('message for tag commit log entry')), |
|
2893 | ('m', 'message', '', _('message for tag commit log entry')), | |
2887 | ('d', 'date', '', _('record datecode as commit date')), |
|
2894 | ('d', 'date', '', _('record datecode as commit date')), | |
2888 | ('u', 'user', '', _('record user as commiter')), |
|
2895 | ('u', 'user', '', _('record user as commiter')), | |
2889 | ('r', 'rev', '', _('revision to tag'))], |
|
2896 | ('r', 'rev', '', _('revision to tag'))], | |
2890 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
2897 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | |
2891 | "tags": (tags, [], _('hg tags')), |
|
2898 | "tags": (tags, [], _('hg tags')), | |
2892 | "tip": |
|
2899 | "tip": | |
2893 | (tip, |
|
2900 | (tip, | |
2894 | [('b', 'branches', None, _('show branches')), |
|
2901 | [('b', 'branches', None, _('show branches')), | |
2895 | ('', 'style', '', _('display using template map file')), |
|
2902 | ('', 'style', '', _('display using template map file')), | |
2896 | ('p', 'patch', None, _('show patch')), |
|
2903 | ('p', 'patch', None, _('show patch')), | |
2897 | ('', 'template', '', _('display with template'))], |
|
2904 | ('', 'template', '', _('display with template'))], | |
2898 | _('hg tip [-b] [-p]')), |
|
2905 | _('hg tip [-b] [-p]')), | |
2899 | "unbundle": |
|
2906 | "unbundle": | |
2900 | (unbundle, |
|
2907 | (unbundle, | |
2901 | [('u', 'update', None, |
|
2908 | [('u', 'update', None, | |
2902 | _('update the working directory to tip after unbundle'))], |
|
2909 | _('update the working directory to tip after unbundle'))], | |
2903 | _('hg unbundle [-u] FILE')), |
|
2910 | _('hg unbundle [-u] FILE')), | |
2904 | "undo": (undo, [], _('hg undo')), |
|
2911 | "undo": (undo, [], _('hg undo')), | |
2905 | "^update|up|checkout|co": |
|
2912 | "^update|up|checkout|co": | |
2906 | (update, |
|
2913 | (update, | |
2907 | [('b', 'branch', '', _('checkout the head of a specific branch')), |
|
2914 | [('b', 'branch', '', _('checkout the head of a specific branch')), | |
2908 | ('', 'style', '', _('display using template map file')), |
|
2915 | ('', 'style', '', _('display using template map file')), | |
2909 | ('m', 'merge', None, _('allow merging of branches')), |
|
2916 | ('m', 'merge', None, _('allow merging of branches')), | |
2910 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
2917 | ('C', 'clean', None, _('overwrite locally modified files')), | |
2911 | ('f', 'force', None, _('force a merge with outstanding changes')), |
|
2918 | ('f', 'force', None, _('force a merge with outstanding changes')), | |
2912 | ('', 'template', '', _('display with template'))], |
|
2919 | ('', 'template', '', _('display with template'))], | |
2913 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), |
|
2920 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), | |
2914 | "verify": (verify, [], _('hg verify')), |
|
2921 | "verify": (verify, [], _('hg verify')), | |
2915 | "version": (show_version, [], _('hg version')), |
|
2922 | "version": (show_version, [], _('hg version')), | |
2916 | } |
|
2923 | } | |
2917 |
|
2924 | |||
2918 | globalopts = [ |
|
2925 | globalopts = [ | |
2919 | ('R', 'repository', '', |
|
2926 | ('R', 'repository', '', | |
2920 | _('repository root directory or symbolic path name')), |
|
2927 | _('repository root directory or symbolic path name')), | |
2921 | ('', 'cwd', '', _('change working directory')), |
|
2928 | ('', 'cwd', '', _('change working directory')), | |
2922 | ('y', 'noninteractive', None, |
|
2929 | ('y', 'noninteractive', None, | |
2923 | _('do not prompt, assume \'yes\' for any required answers')), |
|
2930 | _('do not prompt, assume \'yes\' for any required answers')), | |
2924 | ('q', 'quiet', None, _('suppress output')), |
|
2931 | ('q', 'quiet', None, _('suppress output')), | |
2925 | ('v', 'verbose', None, _('enable additional output')), |
|
2932 | ('v', 'verbose', None, _('enable additional output')), | |
2926 | ('', 'debug', None, _('enable debugging output')), |
|
2933 | ('', 'debug', None, _('enable debugging output')), | |
2927 | ('', 'debugger', None, _('start debugger')), |
|
2934 | ('', 'debugger', None, _('start debugger')), | |
2928 | ('', 'traceback', None, _('print traceback on exception')), |
|
2935 | ('', 'traceback', None, _('print traceback on exception')), | |
2929 | ('', 'time', None, _('time how long the command takes')), |
|
2936 | ('', 'time', None, _('time how long the command takes')), | |
2930 | ('', 'profile', None, _('print command execution profile')), |
|
2937 | ('', 'profile', None, _('print command execution profile')), | |
2931 | ('', 'version', None, _('output version information and exit')), |
|
2938 | ('', 'version', None, _('output version information and exit')), | |
2932 | ('h', 'help', None, _('display help and exit')), |
|
2939 | ('h', 'help', None, _('display help and exit')), | |
2933 | ] |
|
2940 | ] | |
2934 |
|
2941 | |||
2935 | norepo = ("clone init version help debugancestor debugcomplete debugdata" |
|
2942 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | |
2936 | " debugindex debugindexdot") |
|
2943 | " debugindex debugindexdot") | |
2937 | optionalrepo = ("paths debugconfig") |
|
2944 | optionalrepo = ("paths debugconfig") | |
2938 |
|
2945 | |||
2939 | def findpossible(cmd): |
|
2946 | def findpossible(cmd): | |
2940 | """ |
|
2947 | """ | |
2941 | Return cmd -> (aliases, command table entry) |
|
2948 | Return cmd -> (aliases, command table entry) | |
2942 | for each matching command |
|
2949 | for each matching command | |
2943 | """ |
|
2950 | """ | |
2944 | choice = {} |
|
2951 | choice = {} | |
2945 | debugchoice = {} |
|
2952 | debugchoice = {} | |
2946 | for e in table.keys(): |
|
2953 | for e in table.keys(): | |
2947 | aliases = e.lstrip("^").split("|") |
|
2954 | aliases = e.lstrip("^").split("|") | |
2948 | if cmd in aliases: |
|
2955 | if cmd in aliases: | |
2949 | choice[cmd] = (aliases, table[e]) |
|
2956 | choice[cmd] = (aliases, table[e]) | |
2950 | continue |
|
2957 | continue | |
2951 | for a in aliases: |
|
2958 | for a in aliases: | |
2952 | if a.startswith(cmd): |
|
2959 | if a.startswith(cmd): | |
2953 | if aliases[0].startswith("debug"): |
|
2960 | if aliases[0].startswith("debug"): | |
2954 | debugchoice[a] = (aliases, table[e]) |
|
2961 | debugchoice[a] = (aliases, table[e]) | |
2955 | else: |
|
2962 | else: | |
2956 | choice[a] = (aliases, table[e]) |
|
2963 | choice[a] = (aliases, table[e]) | |
2957 | break |
|
2964 | break | |
2958 |
|
2965 | |||
2959 | if not choice and debugchoice: |
|
2966 | if not choice and debugchoice: | |
2960 | choice = debugchoice |
|
2967 | choice = debugchoice | |
2961 |
|
2968 | |||
2962 | return choice |
|
2969 | return choice | |
2963 |
|
2970 | |||
2964 | def find(cmd): |
|
2971 | def find(cmd): | |
2965 | """Return (aliases, command table entry) for command string.""" |
|
2972 | """Return (aliases, command table entry) for command string.""" | |
2966 | choice = findpossible(cmd) |
|
2973 | choice = findpossible(cmd) | |
2967 |
|
2974 | |||
2968 | if choice.has_key(cmd): |
|
2975 | if choice.has_key(cmd): | |
2969 | return choice[cmd] |
|
2976 | return choice[cmd] | |
2970 |
|
2977 | |||
2971 | if len(choice) > 1: |
|
2978 | if len(choice) > 1: | |
2972 | clist = choice.keys() |
|
2979 | clist = choice.keys() | |
2973 | clist.sort() |
|
2980 | clist.sort() | |
2974 | raise AmbiguousCommand(cmd, clist) |
|
2981 | raise AmbiguousCommand(cmd, clist) | |
2975 |
|
2982 | |||
2976 | if choice: |
|
2983 | if choice: | |
2977 | return choice.values()[0] |
|
2984 | return choice.values()[0] | |
2978 |
|
2985 | |||
2979 | raise UnknownCommand(cmd) |
|
2986 | raise UnknownCommand(cmd) | |
2980 |
|
2987 | |||
2981 | class SignalInterrupt(Exception): |
|
2988 | class SignalInterrupt(Exception): | |
2982 | """Exception raised on SIGTERM and SIGHUP.""" |
|
2989 | """Exception raised on SIGTERM and SIGHUP.""" | |
2983 |
|
2990 | |||
2984 | def catchterm(*args): |
|
2991 | def catchterm(*args): | |
2985 | raise SignalInterrupt |
|
2992 | raise SignalInterrupt | |
2986 |
|
2993 | |||
2987 | def run(): |
|
2994 | def run(): | |
2988 | sys.exit(dispatch(sys.argv[1:])) |
|
2995 | sys.exit(dispatch(sys.argv[1:])) | |
2989 |
|
2996 | |||
2990 | class ParseError(Exception): |
|
2997 | class ParseError(Exception): | |
2991 | """Exception raised on errors in parsing the command line.""" |
|
2998 | """Exception raised on errors in parsing the command line.""" | |
2992 |
|
2999 | |||
2993 | def parse(ui, args): |
|
3000 | def parse(ui, args): | |
2994 | options = {} |
|
3001 | options = {} | |
2995 | cmdoptions = {} |
|
3002 | cmdoptions = {} | |
2996 |
|
3003 | |||
2997 | try: |
|
3004 | try: | |
2998 | args = fancyopts.fancyopts(args, globalopts, options) |
|
3005 | args = fancyopts.fancyopts(args, globalopts, options) | |
2999 | except fancyopts.getopt.GetoptError, inst: |
|
3006 | except fancyopts.getopt.GetoptError, inst: | |
3000 | raise ParseError(None, inst) |
|
3007 | raise ParseError(None, inst) | |
3001 |
|
3008 | |||
3002 | if args: |
|
3009 | if args: | |
3003 | cmd, args = args[0], args[1:] |
|
3010 | cmd, args = args[0], args[1:] | |
3004 | aliases, i = find(cmd) |
|
3011 | aliases, i = find(cmd) | |
3005 | cmd = aliases[0] |
|
3012 | cmd = aliases[0] | |
3006 | defaults = ui.config("defaults", cmd) |
|
3013 | defaults = ui.config("defaults", cmd) | |
3007 | if defaults: |
|
3014 | if defaults: | |
3008 | args = defaults.split() + args |
|
3015 | args = defaults.split() + args | |
3009 | c = list(i[1]) |
|
3016 | c = list(i[1]) | |
3010 | else: |
|
3017 | else: | |
3011 | cmd = None |
|
3018 | cmd = None | |
3012 | c = [] |
|
3019 | c = [] | |
3013 |
|
3020 | |||
3014 | # combine global options into local |
|
3021 | # combine global options into local | |
3015 | for o in globalopts: |
|
3022 | for o in globalopts: | |
3016 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
3023 | c.append((o[0], o[1], options[o[1]], o[3])) | |
3017 |
|
3024 | |||
3018 | try: |
|
3025 | try: | |
3019 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
3026 | args = fancyopts.fancyopts(args, c, cmdoptions) | |
3020 | except fancyopts.getopt.GetoptError, inst: |
|
3027 | except fancyopts.getopt.GetoptError, inst: | |
3021 | raise ParseError(cmd, inst) |
|
3028 | raise ParseError(cmd, inst) | |
3022 |
|
3029 | |||
3023 | # separate global options back out |
|
3030 | # separate global options back out | |
3024 | for o in globalopts: |
|
3031 | for o in globalopts: | |
3025 | n = o[1] |
|
3032 | n = o[1] | |
3026 | options[n] = cmdoptions[n] |
|
3033 | options[n] = cmdoptions[n] | |
3027 | del cmdoptions[n] |
|
3034 | del cmdoptions[n] | |
3028 |
|
3035 | |||
3029 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
3036 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | |
3030 |
|
3037 | |||
3031 | def dispatch(args): |
|
3038 | def dispatch(args): | |
3032 | signal.signal(signal.SIGTERM, catchterm) |
|
3039 | signal.signal(signal.SIGTERM, catchterm) | |
3033 | try: |
|
3040 | try: | |
3034 | signal.signal(signal.SIGHUP, catchterm) |
|
3041 | signal.signal(signal.SIGHUP, catchterm) | |
3035 | except AttributeError: |
|
3042 | except AttributeError: | |
3036 | pass |
|
3043 | pass | |
3037 |
|
3044 | |||
3038 | try: |
|
3045 | try: | |
3039 | u = ui.ui() |
|
3046 | u = ui.ui() | |
3040 | except util.Abort, inst: |
|
3047 | except util.Abort, inst: | |
3041 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3048 | sys.stderr.write(_("abort: %s\n") % inst) | |
3042 | sys.exit(1) |
|
3049 | sys.exit(1) | |
3043 |
|
3050 | |||
3044 | external = [] |
|
3051 | external = [] | |
3045 | for x in u.extensions(): |
|
3052 | for x in u.extensions(): | |
3046 | def on_exception(exc, inst): |
|
3053 | def on_exception(exc, inst): | |
3047 | u.warn(_("*** failed to import extension %s\n") % x[1]) |
|
3054 | u.warn(_("*** failed to import extension %s\n") % x[1]) | |
3048 | u.warn("%s\n" % inst) |
|
3055 | u.warn("%s\n" % inst) | |
3049 | if "--traceback" in sys.argv[1:]: |
|
3056 | if "--traceback" in sys.argv[1:]: | |
3050 | traceback.print_exc() |
|
3057 | traceback.print_exc() | |
3051 | if x[1]: |
|
3058 | if x[1]: | |
3052 | try: |
|
3059 | try: | |
3053 | mod = imp.load_source(x[0], x[1]) |
|
3060 | mod = imp.load_source(x[0], x[1]) | |
3054 | except Exception, inst: |
|
3061 | except Exception, inst: | |
3055 | on_exception(Exception, inst) |
|
3062 | on_exception(Exception, inst) | |
3056 | continue |
|
3063 | continue | |
3057 | else: |
|
3064 | else: | |
3058 | def importh(name): |
|
3065 | def importh(name): | |
3059 | mod = __import__(name) |
|
3066 | mod = __import__(name) | |
3060 | components = name.split('.') |
|
3067 | components = name.split('.') | |
3061 | for comp in components[1:]: |
|
3068 | for comp in components[1:]: | |
3062 | mod = getattr(mod, comp) |
|
3069 | mod = getattr(mod, comp) | |
3063 | return mod |
|
3070 | return mod | |
3064 | try: |
|
3071 | try: | |
3065 | try: |
|
3072 | try: | |
3066 | mod = importh("hgext." + x[0]) |
|
3073 | mod = importh("hgext." + x[0]) | |
3067 | except ImportError: |
|
3074 | except ImportError: | |
3068 | mod = importh(x[0]) |
|
3075 | mod = importh(x[0]) | |
3069 | except Exception, inst: |
|
3076 | except Exception, inst: | |
3070 | on_exception(Exception, inst) |
|
3077 | on_exception(Exception, inst) | |
3071 | continue |
|
3078 | continue | |
3072 |
|
3079 | |||
3073 | external.append(mod) |
|
3080 | external.append(mod) | |
3074 | for x in external: |
|
3081 | for x in external: | |
3075 | cmdtable = getattr(x, 'cmdtable', {}) |
|
3082 | cmdtable = getattr(x, 'cmdtable', {}) | |
3076 | for t in cmdtable: |
|
3083 | for t in cmdtable: | |
3077 | if t in table: |
|
3084 | if t in table: | |
3078 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) |
|
3085 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) | |
3079 | table.update(cmdtable) |
|
3086 | table.update(cmdtable) | |
3080 |
|
3087 | |||
3081 | try: |
|
3088 | try: | |
3082 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3089 | cmd, func, args, options, cmdoptions = parse(u, args) | |
3083 | if options["time"]: |
|
3090 | if options["time"]: | |
3084 | def get_times(): |
|
3091 | def get_times(): | |
3085 | t = os.times() |
|
3092 | t = os.times() | |
3086 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
3093 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | |
3087 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
3094 | t = (t[0], t[1], t[2], t[3], time.clock()) | |
3088 | return t |
|
3095 | return t | |
3089 | s = get_times() |
|
3096 | s = get_times() | |
3090 | def print_time(): |
|
3097 | def print_time(): | |
3091 | t = get_times() |
|
3098 | t = get_times() | |
3092 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
3099 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | |
3093 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
3100 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | |
3094 | atexit.register(print_time) |
|
3101 | atexit.register(print_time) | |
3095 |
|
3102 | |||
3096 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3103 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
3097 | not options["noninteractive"]) |
|
3104 | not options["noninteractive"]) | |
3098 |
|
3105 | |||
3099 | # enter the debugger before command execution |
|
3106 | # enter the debugger before command execution | |
3100 | if options['debugger']: |
|
3107 | if options['debugger']: | |
3101 | pdb.set_trace() |
|
3108 | pdb.set_trace() | |
3102 |
|
3109 | |||
3103 | try: |
|
3110 | try: | |
3104 | if options['cwd']: |
|
3111 | if options['cwd']: | |
3105 | try: |
|
3112 | try: | |
3106 | os.chdir(options['cwd']) |
|
3113 | os.chdir(options['cwd']) | |
3107 | except OSError, inst: |
|
3114 | except OSError, inst: | |
3108 | raise util.Abort('%s: %s' % |
|
3115 | raise util.Abort('%s: %s' % | |
3109 | (options['cwd'], inst.strerror)) |
|
3116 | (options['cwd'], inst.strerror)) | |
3110 |
|
3117 | |||
3111 | path = u.expandpath(options["repository"]) or "" |
|
3118 | path = u.expandpath(options["repository"]) or "" | |
3112 | repo = path and hg.repository(u, path=path) or None |
|
3119 | repo = path and hg.repository(u, path=path) or None | |
3113 |
|
3120 | |||
3114 | if options['help']: |
|
3121 | if options['help']: | |
3115 | help_(u, cmd, options['version']) |
|
3122 | help_(u, cmd, options['version']) | |
3116 | sys.exit(0) |
|
3123 | sys.exit(0) | |
3117 | elif options['version']: |
|
3124 | elif options['version']: | |
3118 | show_version(u) |
|
3125 | show_version(u) | |
3119 | sys.exit(0) |
|
3126 | sys.exit(0) | |
3120 | elif not cmd: |
|
3127 | elif not cmd: | |
3121 | help_(u, 'shortlist') |
|
3128 | help_(u, 'shortlist') | |
3122 | sys.exit(0) |
|
3129 | sys.exit(0) | |
3123 |
|
3130 | |||
3124 | if cmd not in norepo.split(): |
|
3131 | if cmd not in norepo.split(): | |
3125 | try: |
|
3132 | try: | |
3126 | if not repo: |
|
3133 | if not repo: | |
3127 | repo = hg.repository(u, path=path) |
|
3134 | repo = hg.repository(u, path=path) | |
3128 | u = repo.ui |
|
3135 | u = repo.ui | |
3129 | for x in external: |
|
3136 | for x in external: | |
3130 | if hasattr(x, 'reposetup'): |
|
3137 | if hasattr(x, 'reposetup'): | |
3131 | x.reposetup(u, repo) |
|
3138 | x.reposetup(u, repo) | |
3132 | except hg.RepoError: |
|
3139 | except hg.RepoError: | |
3133 | if cmd not in optionalrepo.split(): |
|
3140 | if cmd not in optionalrepo.split(): | |
3134 | raise |
|
3141 | raise | |
3135 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
3142 | d = lambda: func(u, repo, *args, **cmdoptions) | |
3136 | else: |
|
3143 | else: | |
3137 | d = lambda: func(u, *args, **cmdoptions) |
|
3144 | d = lambda: func(u, *args, **cmdoptions) | |
3138 |
|
3145 | |||
3139 | try: |
|
3146 | try: | |
3140 | if options['profile']: |
|
3147 | if options['profile']: | |
3141 | import hotshot, hotshot.stats |
|
3148 | import hotshot, hotshot.stats | |
3142 | prof = hotshot.Profile("hg.prof") |
|
3149 | prof = hotshot.Profile("hg.prof") | |
3143 | try: |
|
3150 | try: | |
3144 | try: |
|
3151 | try: | |
3145 | return prof.runcall(d) |
|
3152 | return prof.runcall(d) | |
3146 | except: |
|
3153 | except: | |
3147 | try: |
|
3154 | try: | |
3148 | u.warn(_('exception raised - generating ' |
|
3155 | u.warn(_('exception raised - generating ' | |
3149 | 'profile anyway\n')) |
|
3156 | 'profile anyway\n')) | |
3150 | except: |
|
3157 | except: | |
3151 | pass |
|
3158 | pass | |
3152 | raise |
|
3159 | raise | |
3153 | finally: |
|
3160 | finally: | |
3154 | prof.close() |
|
3161 | prof.close() | |
3155 | stats = hotshot.stats.load("hg.prof") |
|
3162 | stats = hotshot.stats.load("hg.prof") | |
3156 | stats.strip_dirs() |
|
3163 | stats.strip_dirs() | |
3157 | stats.sort_stats('time', 'calls') |
|
3164 | stats.sort_stats('time', 'calls') | |
3158 | stats.print_stats(40) |
|
3165 | stats.print_stats(40) | |
3159 | else: |
|
3166 | else: | |
3160 | return d() |
|
3167 | return d() | |
3161 | finally: |
|
3168 | finally: | |
3162 | u.flush() |
|
3169 | u.flush() | |
3163 | except: |
|
3170 | except: | |
3164 | # enter the debugger when we hit an exception |
|
3171 | # enter the debugger when we hit an exception | |
3165 | if options['debugger']: |
|
3172 | if options['debugger']: | |
3166 | pdb.post_mortem(sys.exc_info()[2]) |
|
3173 | pdb.post_mortem(sys.exc_info()[2]) | |
3167 | if options['traceback']: |
|
3174 | if options['traceback']: | |
3168 | traceback.print_exc() |
|
3175 | traceback.print_exc() | |
3169 | raise |
|
3176 | raise | |
3170 | except ParseError, inst: |
|
3177 | except ParseError, inst: | |
3171 | if inst.args[0]: |
|
3178 | if inst.args[0]: | |
3172 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
3179 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
3173 | help_(u, inst.args[0]) |
|
3180 | help_(u, inst.args[0]) | |
3174 | else: |
|
3181 | else: | |
3175 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
3182 | u.warn(_("hg: %s\n") % inst.args[1]) | |
3176 | help_(u, 'shortlist') |
|
3183 | help_(u, 'shortlist') | |
3177 | sys.exit(-1) |
|
3184 | sys.exit(-1) | |
3178 | except AmbiguousCommand, inst: |
|
3185 | except AmbiguousCommand, inst: | |
3179 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
3186 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
3180 | (inst.args[0], " ".join(inst.args[1]))) |
|
3187 | (inst.args[0], " ".join(inst.args[1]))) | |
3181 | sys.exit(1) |
|
3188 | sys.exit(1) | |
3182 | except UnknownCommand, inst: |
|
3189 | except UnknownCommand, inst: | |
3183 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
3190 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
3184 | help_(u, 'shortlist') |
|
3191 | help_(u, 'shortlist') | |
3185 | sys.exit(1) |
|
3192 | sys.exit(1) | |
3186 | except hg.RepoError, inst: |
|
3193 | except hg.RepoError, inst: | |
3187 | u.warn(_("abort: "), inst, "!\n") |
|
3194 | u.warn(_("abort: "), inst, "!\n") | |
3188 | except revlog.RevlogError, inst: |
|
3195 | except revlog.RevlogError, inst: | |
3189 | u.warn(_("abort: "), inst, "!\n") |
|
3196 | u.warn(_("abort: "), inst, "!\n") | |
3190 | except SignalInterrupt: |
|
3197 | except SignalInterrupt: | |
3191 | u.warn(_("killed!\n")) |
|
3198 | u.warn(_("killed!\n")) | |
3192 | except KeyboardInterrupt: |
|
3199 | except KeyboardInterrupt: | |
3193 | try: |
|
3200 | try: | |
3194 | u.warn(_("interrupted!\n")) |
|
3201 | u.warn(_("interrupted!\n")) | |
3195 | except IOError, inst: |
|
3202 | except IOError, inst: | |
3196 | if inst.errno == errno.EPIPE: |
|
3203 | if inst.errno == errno.EPIPE: | |
3197 | if u.debugflag: |
|
3204 | if u.debugflag: | |
3198 | u.warn(_("\nbroken pipe\n")) |
|
3205 | u.warn(_("\nbroken pipe\n")) | |
3199 | else: |
|
3206 | else: | |
3200 | raise |
|
3207 | raise | |
3201 | except IOError, inst: |
|
3208 | except IOError, inst: | |
3202 | if hasattr(inst, "code"): |
|
3209 | if hasattr(inst, "code"): | |
3203 | u.warn(_("abort: %s\n") % inst) |
|
3210 | u.warn(_("abort: %s\n") % inst) | |
3204 | elif hasattr(inst, "reason"): |
|
3211 | elif hasattr(inst, "reason"): | |
3205 | u.warn(_("abort: error: %s\n") % inst.reason[1]) |
|
3212 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | |
3206 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
3213 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | |
3207 | if u.debugflag: |
|
3214 | if u.debugflag: | |
3208 | u.warn(_("broken pipe\n")) |
|
3215 | u.warn(_("broken pipe\n")) | |
3209 | elif getattr(inst, "strerror", None): |
|
3216 | elif getattr(inst, "strerror", None): | |
3210 | if getattr(inst, "filename", None): |
|
3217 | if getattr(inst, "filename", None): | |
3211 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) |
|
3218 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) | |
3212 | else: |
|
3219 | else: | |
3213 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3220 | u.warn(_("abort: %s\n") % inst.strerror) | |
3214 | else: |
|
3221 | else: | |
3215 | raise |
|
3222 | raise | |
3216 | except OSError, inst: |
|
3223 | except OSError, inst: | |
3217 | if hasattr(inst, "filename"): |
|
3224 | if hasattr(inst, "filename"): | |
3218 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3225 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | |
3219 | else: |
|
3226 | else: | |
3220 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3227 | u.warn(_("abort: %s\n") % inst.strerror) | |
3221 | except util.Abort, inst: |
|
3228 | except util.Abort, inst: | |
3222 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') |
|
3229 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') | |
3223 | sys.exit(1) |
|
3230 | sys.exit(1) | |
3224 | except TypeError, inst: |
|
3231 | except TypeError, inst: | |
3225 | # was this an argument error? |
|
3232 | # was this an argument error? | |
3226 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
3233 | tb = traceback.extract_tb(sys.exc_info()[2]) | |
3227 | if len(tb) > 2: # no |
|
3234 | if len(tb) > 2: # no | |
3228 | raise |
|
3235 | raise | |
3229 | u.debug(inst, "\n") |
|
3236 | u.debug(inst, "\n") | |
3230 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
3237 | u.warn(_("%s: invalid arguments\n") % cmd) | |
3231 | help_(u, cmd) |
|
3238 | help_(u, cmd) | |
3232 | except SystemExit: |
|
3239 | except SystemExit: | |
3233 | # don't catch this in the catch-all below |
|
3240 | # don't catch this in the catch-all below | |
3234 | raise |
|
3241 | raise | |
3235 | except: |
|
3242 | except: | |
3236 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
3243 | u.warn(_("** unknown exception encountered, details follow\n")) | |
3237 | u.warn(_("** report bug details to mercurial@selenic.com\n")) |
|
3244 | u.warn(_("** report bug details to mercurial@selenic.com\n")) | |
3238 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
3245 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | |
3239 | % version.get_version()) |
|
3246 | % version.get_version()) | |
3240 | raise |
|
3247 | raise | |
3241 |
|
3248 | |||
3242 | sys.exit(-1) |
|
3249 | sys.exit(-1) |
@@ -1,1907 +1,1910 | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | import struct, os, util |
|
8 | import struct, os, util | |
9 | import filelog, manifest, changelog, dirstate, repo |
|
9 | import filelog, manifest, changelog, dirstate, repo | |
10 | from node import * |
|
10 | from node import * | |
11 | from i18n import gettext as _ |
|
11 | from i18n import gettext as _ | |
12 | from demandload import * |
|
12 | from demandload import * | |
13 | demandload(globals(), "re lock transaction tempfile stat mdiff errno ui") |
|
13 | demandload(globals(), "re lock transaction tempfile stat mdiff errno ui") | |
14 |
|
14 | |||
15 | class localrepository(object): |
|
15 | class localrepository(object): | |
16 | def __del__(self): |
|
16 | def __del__(self): | |
17 | self.transhandle = None |
|
17 | self.transhandle = None | |
18 | def __init__(self, parentui, path=None, create=0): |
|
18 | def __init__(self, parentui, path=None, create=0): | |
19 | if not path: |
|
19 | if not path: | |
20 | p = os.getcwd() |
|
20 | p = os.getcwd() | |
21 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
21 | while not os.path.isdir(os.path.join(p, ".hg")): | |
22 | oldp = p |
|
22 | oldp = p | |
23 | p = os.path.dirname(p) |
|
23 | p = os.path.dirname(p) | |
24 | if p == oldp: |
|
24 | if p == oldp: | |
25 | raise repo.RepoError(_("no repo found")) |
|
25 | raise repo.RepoError(_("no repo found")) | |
26 | path = p |
|
26 | path = p | |
27 | self.path = os.path.join(path, ".hg") |
|
27 | self.path = os.path.join(path, ".hg") | |
28 |
|
28 | |||
29 | if not create and not os.path.isdir(self.path): |
|
29 | if not create and not os.path.isdir(self.path): | |
30 | raise repo.RepoError(_("repository %s not found") % path) |
|
30 | raise repo.RepoError(_("repository %s not found") % path) | |
31 |
|
31 | |||
32 | self.root = os.path.abspath(path) |
|
32 | self.root = os.path.abspath(path) | |
33 | self.ui = ui.ui(parentui=parentui) |
|
33 | self.ui = ui.ui(parentui=parentui) | |
34 | self.opener = util.opener(self.path) |
|
34 | self.opener = util.opener(self.path) | |
35 | self.wopener = util.opener(self.root) |
|
35 | self.wopener = util.opener(self.root) | |
36 | self.manifest = manifest.manifest(self.opener) |
|
36 | self.manifest = manifest.manifest(self.opener) | |
37 | self.changelog = changelog.changelog(self.opener) |
|
37 | self.changelog = changelog.changelog(self.opener) | |
38 | self.tagscache = None |
|
38 | self.tagscache = None | |
39 | self.nodetagscache = None |
|
39 | self.nodetagscache = None | |
40 | self.encodepats = None |
|
40 | self.encodepats = None | |
41 | self.decodepats = None |
|
41 | self.decodepats = None | |
42 | self.transhandle = None |
|
42 | self.transhandle = None | |
43 |
|
43 | |||
44 | if create: |
|
44 | if create: | |
45 | os.mkdir(self.path) |
|
45 | os.mkdir(self.path) | |
46 | os.mkdir(self.join("data")) |
|
46 | os.mkdir(self.join("data")) | |
47 |
|
47 | |||
48 | self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root) |
|
48 | self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root) | |
49 | try: |
|
49 | try: | |
50 | self.ui.readconfig(self.join("hgrc"), self.root) |
|
50 | self.ui.readconfig(self.join("hgrc"), self.root) | |
51 | except IOError: |
|
51 | except IOError: | |
52 | pass |
|
52 | pass | |
53 |
|
53 | |||
54 | def hook(self, name, throw=False, **args): |
|
54 | def hook(self, name, throw=False, **args): | |
55 | def runhook(name, cmd): |
|
55 | def runhook(name, cmd): | |
56 | self.ui.note(_("running hook %s: %s\n") % (name, cmd)) |
|
56 | self.ui.note(_("running hook %s: %s\n") % (name, cmd)) | |
57 | env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()]) |
|
57 | env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()]) | |
58 | r = util.system(cmd, environ=env, cwd=self.root) |
|
58 | r = util.system(cmd, environ=env, cwd=self.root) | |
59 | if r: |
|
59 | if r: | |
60 | desc, r = util.explain_exit(r) |
|
60 | desc, r = util.explain_exit(r) | |
61 | if throw: |
|
61 | if throw: | |
62 | raise util.Abort(_('%s hook %s') % (name, desc)) |
|
62 | raise util.Abort(_('%s hook %s') % (name, desc)) | |
63 | self.ui.warn(_('error: %s hook %s\n') % (name, desc)) |
|
63 | self.ui.warn(_('error: %s hook %s\n') % (name, desc)) | |
64 | return False |
|
64 | return False | |
65 | return True |
|
65 | return True | |
66 |
|
66 | |||
67 | r = True |
|
67 | r = True | |
68 | hooks = [(hname, cmd) for hname, cmd in self.ui.configitems("hooks") |
|
68 | hooks = [(hname, cmd) for hname, cmd in self.ui.configitems("hooks") | |
69 | if hname.split(".", 1)[0] == name and cmd] |
|
69 | if hname.split(".", 1)[0] == name and cmd] | |
70 | hooks.sort() |
|
70 | hooks.sort() | |
71 | for hname, cmd in hooks: |
|
71 | for hname, cmd in hooks: | |
72 | r = runhook(hname, cmd) and r |
|
72 | r = runhook(hname, cmd) and r | |
73 | return r |
|
73 | return r | |
74 |
|
74 | |||
75 | def tags(self): |
|
75 | def tags(self): | |
76 | '''return a mapping of tag to node''' |
|
76 | '''return a mapping of tag to node''' | |
77 | if not self.tagscache: |
|
77 | if not self.tagscache: | |
78 | self.tagscache = {} |
|
78 | self.tagscache = {} | |
79 | def addtag(self, k, n): |
|
79 | def addtag(self, k, n): | |
80 | try: |
|
80 | try: | |
81 | bin_n = bin(n) |
|
81 | bin_n = bin(n) | |
82 | except TypeError: |
|
82 | except TypeError: | |
83 | bin_n = '' |
|
83 | bin_n = '' | |
84 | self.tagscache[k.strip()] = bin_n |
|
84 | self.tagscache[k.strip()] = bin_n | |
85 |
|
85 | |||
86 | try: |
|
86 | try: | |
87 | # read each head of the tags file, ending with the tip |
|
87 | # read each head of the tags file, ending with the tip | |
88 | # and add each tag found to the map, with "newer" ones |
|
88 | # and add each tag found to the map, with "newer" ones | |
89 | # taking precedence |
|
89 | # taking precedence | |
90 | fl = self.file(".hgtags") |
|
90 | fl = self.file(".hgtags") | |
91 | h = fl.heads() |
|
91 | h = fl.heads() | |
92 | h.reverse() |
|
92 | h.reverse() | |
93 | for r in h: |
|
93 | for r in h: | |
94 | for l in fl.read(r).splitlines(): |
|
94 | for l in fl.read(r).splitlines(): | |
95 | if l: |
|
95 | if l: | |
96 | n, k = l.split(" ", 1) |
|
96 | n, k = l.split(" ", 1) | |
97 | addtag(self, k, n) |
|
97 | addtag(self, k, n) | |
98 | except KeyError: |
|
98 | except KeyError: | |
99 | pass |
|
99 | pass | |
100 |
|
100 | |||
101 | try: |
|
101 | try: | |
102 | f = self.opener("localtags") |
|
102 | f = self.opener("localtags") | |
103 | for l in f: |
|
103 | for l in f: | |
104 | n, k = l.split(" ", 1) |
|
104 | n, k = l.split(" ", 1) | |
105 | addtag(self, k, n) |
|
105 | addtag(self, k, n) | |
106 | except IOError: |
|
106 | except IOError: | |
107 | pass |
|
107 | pass | |
108 |
|
108 | |||
109 | self.tagscache['tip'] = self.changelog.tip() |
|
109 | self.tagscache['tip'] = self.changelog.tip() | |
110 |
|
110 | |||
111 | return self.tagscache |
|
111 | return self.tagscache | |
112 |
|
112 | |||
113 | def tagslist(self): |
|
113 | def tagslist(self): | |
114 | '''return a list of tags ordered by revision''' |
|
114 | '''return a list of tags ordered by revision''' | |
115 | l = [] |
|
115 | l = [] | |
116 | for t, n in self.tags().items(): |
|
116 | for t, n in self.tags().items(): | |
117 | try: |
|
117 | try: | |
118 | r = self.changelog.rev(n) |
|
118 | r = self.changelog.rev(n) | |
119 | except: |
|
119 | except: | |
120 | r = -2 # sort to the beginning of the list if unknown |
|
120 | r = -2 # sort to the beginning of the list if unknown | |
121 | l.append((r, t, n)) |
|
121 | l.append((r, t, n)) | |
122 | l.sort() |
|
122 | l.sort() | |
123 | return [(t, n) for r, t, n in l] |
|
123 | return [(t, n) for r, t, n in l] | |
124 |
|
124 | |||
125 | def nodetags(self, node): |
|
125 | def nodetags(self, node): | |
126 | '''return the tags associated with a node''' |
|
126 | '''return the tags associated with a node''' | |
127 | if not self.nodetagscache: |
|
127 | if not self.nodetagscache: | |
128 | self.nodetagscache = {} |
|
128 | self.nodetagscache = {} | |
129 | for t, n in self.tags().items(): |
|
129 | for t, n in self.tags().items(): | |
130 | self.nodetagscache.setdefault(n, []).append(t) |
|
130 | self.nodetagscache.setdefault(n, []).append(t) | |
131 | return self.nodetagscache.get(node, []) |
|
131 | return self.nodetagscache.get(node, []) | |
132 |
|
132 | |||
133 | def lookup(self, key): |
|
133 | def lookup(self, key): | |
134 | try: |
|
134 | try: | |
135 | return self.tags()[key] |
|
135 | return self.tags()[key] | |
136 | except KeyError: |
|
136 | except KeyError: | |
137 | try: |
|
137 | try: | |
138 | return self.changelog.lookup(key) |
|
138 | return self.changelog.lookup(key) | |
139 | except: |
|
139 | except: | |
140 | raise repo.RepoError(_("unknown revision '%s'") % key) |
|
140 | raise repo.RepoError(_("unknown revision '%s'") % key) | |
141 |
|
141 | |||
142 | def dev(self): |
|
142 | def dev(self): | |
143 | return os.stat(self.path).st_dev |
|
143 | return os.stat(self.path).st_dev | |
144 |
|
144 | |||
145 | def local(self): |
|
145 | def local(self): | |
146 | return True |
|
146 | return True | |
147 |
|
147 | |||
148 | def join(self, f): |
|
148 | def join(self, f): | |
149 | return os.path.join(self.path, f) |
|
149 | return os.path.join(self.path, f) | |
150 |
|
150 | |||
151 | def wjoin(self, f): |
|
151 | def wjoin(self, f): | |
152 | return os.path.join(self.root, f) |
|
152 | return os.path.join(self.root, f) | |
153 |
|
153 | |||
154 | def file(self, f): |
|
154 | def file(self, f): | |
155 | if f[0] == '/': |
|
155 | if f[0] == '/': | |
156 | f = f[1:] |
|
156 | f = f[1:] | |
157 | return filelog.filelog(self.opener, f) |
|
157 | return filelog.filelog(self.opener, f) | |
158 |
|
158 | |||
159 | def getcwd(self): |
|
159 | def getcwd(self): | |
160 | return self.dirstate.getcwd() |
|
160 | return self.dirstate.getcwd() | |
161 |
|
161 | |||
162 | def wfile(self, f, mode='r'): |
|
162 | def wfile(self, f, mode='r'): | |
163 | return self.wopener(f, mode) |
|
163 | return self.wopener(f, mode) | |
164 |
|
164 | |||
165 | def wread(self, filename): |
|
165 | def wread(self, filename): | |
166 | if self.encodepats == None: |
|
166 | if self.encodepats == None: | |
167 | l = [] |
|
167 | l = [] | |
168 | for pat, cmd in self.ui.configitems("encode"): |
|
168 | for pat, cmd in self.ui.configitems("encode"): | |
169 | mf = util.matcher(self.root, "", [pat], [], [])[1] |
|
169 | mf = util.matcher(self.root, "", [pat], [], [])[1] | |
170 | l.append((mf, cmd)) |
|
170 | l.append((mf, cmd)) | |
171 | self.encodepats = l |
|
171 | self.encodepats = l | |
172 |
|
172 | |||
173 | data = self.wopener(filename, 'r').read() |
|
173 | data = self.wopener(filename, 'r').read() | |
174 |
|
174 | |||
175 | for mf, cmd in self.encodepats: |
|
175 | for mf, cmd in self.encodepats: | |
176 | if mf(filename): |
|
176 | if mf(filename): | |
177 | self.ui.debug(_("filtering %s through %s\n") % (filename, cmd)) |
|
177 | self.ui.debug(_("filtering %s through %s\n") % (filename, cmd)) | |
178 | data = util.filter(data, cmd) |
|
178 | data = util.filter(data, cmd) | |
179 | break |
|
179 | break | |
180 |
|
180 | |||
181 | return data |
|
181 | return data | |
182 |
|
182 | |||
183 | def wwrite(self, filename, data, fd=None): |
|
183 | def wwrite(self, filename, data, fd=None): | |
184 | if self.decodepats == None: |
|
184 | if self.decodepats == None: | |
185 | l = [] |
|
185 | l = [] | |
186 | for pat, cmd in self.ui.configitems("decode"): |
|
186 | for pat, cmd in self.ui.configitems("decode"): | |
187 | mf = util.matcher(self.root, "", [pat], [], [])[1] |
|
187 | mf = util.matcher(self.root, "", [pat], [], [])[1] | |
188 | l.append((mf, cmd)) |
|
188 | l.append((mf, cmd)) | |
189 | self.decodepats = l |
|
189 | self.decodepats = l | |
190 |
|
190 | |||
191 | for mf, cmd in self.decodepats: |
|
191 | for mf, cmd in self.decodepats: | |
192 | if mf(filename): |
|
192 | if mf(filename): | |
193 | self.ui.debug(_("filtering %s through %s\n") % (filename, cmd)) |
|
193 | self.ui.debug(_("filtering %s through %s\n") % (filename, cmd)) | |
194 | data = util.filter(data, cmd) |
|
194 | data = util.filter(data, cmd) | |
195 | break |
|
195 | break | |
196 |
|
196 | |||
197 | if fd: |
|
197 | if fd: | |
198 | return fd.write(data) |
|
198 | return fd.write(data) | |
199 | return self.wopener(filename, 'w').write(data) |
|
199 | return self.wopener(filename, 'w').write(data) | |
200 |
|
200 | |||
201 | def transaction(self): |
|
201 | def transaction(self): | |
202 | tr = self.transhandle |
|
202 | tr = self.transhandle | |
203 | if tr != None and tr.running(): |
|
203 | if tr != None and tr.running(): | |
204 | return tr.nest() |
|
204 | return tr.nest() | |
205 |
|
205 | |||
206 | # save dirstate for undo |
|
206 | # save dirstate for undo | |
207 | try: |
|
207 | try: | |
208 | ds = self.opener("dirstate").read() |
|
208 | ds = self.opener("dirstate").read() | |
209 | except IOError: |
|
209 | except IOError: | |
210 | ds = "" |
|
210 | ds = "" | |
211 | self.opener("journal.dirstate", "w").write(ds) |
|
211 | self.opener("journal.dirstate", "w").write(ds) | |
212 |
|
212 | |||
213 | tr = transaction.transaction(self.ui.warn, self.opener, |
|
213 | tr = transaction.transaction(self.ui.warn, self.opener, | |
214 | self.join("journal"), |
|
214 | self.join("journal"), | |
215 | aftertrans(self.path)) |
|
215 | aftertrans(self.path)) | |
216 | self.transhandle = tr |
|
216 | self.transhandle = tr | |
217 | return tr |
|
217 | return tr | |
218 |
|
218 | |||
219 | def recover(self): |
|
219 | def recover(self): | |
220 | l = self.lock() |
|
220 | l = self.lock() | |
221 | if os.path.exists(self.join("journal")): |
|
221 | if os.path.exists(self.join("journal")): | |
222 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
222 | self.ui.status(_("rolling back interrupted transaction\n")) | |
223 | transaction.rollback(self.opener, self.join("journal")) |
|
223 | transaction.rollback(self.opener, self.join("journal")) | |
224 | self.reload() |
|
224 | self.reload() | |
225 | return True |
|
225 | return True | |
226 | else: |
|
226 | else: | |
227 | self.ui.warn(_("no interrupted transaction available\n")) |
|
227 | self.ui.warn(_("no interrupted transaction available\n")) | |
228 | return False |
|
228 | return False | |
229 |
|
229 | |||
230 | def undo(self, wlock=None): |
|
230 | def undo(self, wlock=None): | |
231 | if not wlock: |
|
231 | if not wlock: | |
232 | wlock = self.wlock() |
|
232 | wlock = self.wlock() | |
233 | l = self.lock() |
|
233 | l = self.lock() | |
234 | if os.path.exists(self.join("undo")): |
|
234 | if os.path.exists(self.join("undo")): | |
235 | self.ui.status(_("rolling back last transaction\n")) |
|
235 | self.ui.status(_("rolling back last transaction\n")) | |
236 | transaction.rollback(self.opener, self.join("undo")) |
|
236 | transaction.rollback(self.opener, self.join("undo")) | |
237 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) |
|
237 | util.rename(self.join("undo.dirstate"), self.join("dirstate")) | |
238 | self.reload() |
|
238 | self.reload() | |
239 | self.wreload() |
|
239 | self.wreload() | |
240 | else: |
|
240 | else: | |
241 | self.ui.warn(_("no undo information available\n")) |
|
241 | self.ui.warn(_("no undo information available\n")) | |
242 |
|
242 | |||
243 | def wreload(self): |
|
243 | def wreload(self): | |
244 | self.dirstate.read() |
|
244 | self.dirstate.read() | |
245 |
|
245 | |||
246 | def reload(self): |
|
246 | def reload(self): | |
247 | self.changelog.load() |
|
247 | self.changelog.load() | |
248 | self.manifest.load() |
|
248 | self.manifest.load() | |
249 | self.tagscache = None |
|
249 | self.tagscache = None | |
250 | self.nodetagscache = None |
|
250 | self.nodetagscache = None | |
251 |
|
251 | |||
252 | def do_lock(self, lockname, wait, releasefn=None, acquirefn=None): |
|
252 | def do_lock(self, lockname, wait, releasefn=None, acquirefn=None): | |
253 | try: |
|
253 | try: | |
254 | l = lock.lock(self.join(lockname), 0, releasefn) |
|
254 | l = lock.lock(self.join(lockname), 0, releasefn) | |
255 | except lock.LockHeld, inst: |
|
255 | except lock.LockHeld, inst: | |
256 | if not wait: |
|
256 | if not wait: | |
257 | raise inst |
|
257 | raise inst | |
258 | self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0]) |
|
258 | self.ui.warn(_("waiting for lock held by %s\n") % inst.args[0]) | |
259 | try: |
|
259 | try: | |
260 | # default to 600 seconds timeout |
|
260 | # default to 600 seconds timeout | |
261 | l = lock.lock(self.join(lockname), |
|
261 | l = lock.lock(self.join(lockname), | |
262 | int(self.ui.config("ui", "timeout") or 600), |
|
262 | int(self.ui.config("ui", "timeout") or 600), | |
263 | releasefn) |
|
263 | releasefn) | |
264 | except lock.LockHeld, inst: |
|
264 | except lock.LockHeld, inst: | |
265 | raise util.Abort(_("timeout while waiting for " |
|
265 | raise util.Abort(_("timeout while waiting for " | |
266 | "lock held by %s") % inst.args[0]) |
|
266 | "lock held by %s") % inst.args[0]) | |
267 | if acquirefn: |
|
267 | if acquirefn: | |
268 | acquirefn() |
|
268 | acquirefn() | |
269 | return l |
|
269 | return l | |
270 |
|
270 | |||
271 | def lock(self, wait=1): |
|
271 | def lock(self, wait=1): | |
272 | return self.do_lock("lock", wait, acquirefn=self.reload) |
|
272 | return self.do_lock("lock", wait, acquirefn=self.reload) | |
273 |
|
273 | |||
274 | def wlock(self, wait=1): |
|
274 | def wlock(self, wait=1): | |
275 | return self.do_lock("wlock", wait, |
|
275 | return self.do_lock("wlock", wait, | |
276 | self.dirstate.write, |
|
276 | self.dirstate.write, | |
277 | self.wreload) |
|
277 | self.wreload) | |
278 |
|
278 | |||
279 | def checkfilemerge(self, filename, text, filelog, manifest1, manifest2): |
|
279 | def checkfilemerge(self, filename, text, filelog, manifest1, manifest2): | |
280 | "determine whether a new filenode is needed" |
|
280 | "determine whether a new filenode is needed" | |
281 | fp1 = manifest1.get(filename, nullid) |
|
281 | fp1 = manifest1.get(filename, nullid) | |
282 | fp2 = manifest2.get(filename, nullid) |
|
282 | fp2 = manifest2.get(filename, nullid) | |
283 |
|
283 | |||
284 | if fp2 != nullid: |
|
284 | if fp2 != nullid: | |
285 | # is one parent an ancestor of the other? |
|
285 | # is one parent an ancestor of the other? | |
286 | fpa = filelog.ancestor(fp1, fp2) |
|
286 | fpa = filelog.ancestor(fp1, fp2) | |
287 | if fpa == fp1: |
|
287 | if fpa == fp1: | |
288 | fp1, fp2 = fp2, nullid |
|
288 | fp1, fp2 = fp2, nullid | |
289 | elif fpa == fp2: |
|
289 | elif fpa == fp2: | |
290 | fp2 = nullid |
|
290 | fp2 = nullid | |
291 |
|
291 | |||
292 | # is the file unmodified from the parent? report existing entry |
|
292 | # is the file unmodified from the parent? report existing entry | |
293 | if fp2 == nullid and text == filelog.read(fp1): |
|
293 | if fp2 == nullid and text == filelog.read(fp1): | |
294 | return (fp1, None, None) |
|
294 | return (fp1, None, None) | |
295 |
|
295 | |||
296 | return (None, fp1, fp2) |
|
296 | return (None, fp1, fp2) | |
297 |
|
297 | |||
298 | def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None): |
|
298 | def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None): | |
299 | orig_parent = self.dirstate.parents()[0] or nullid |
|
299 | orig_parent = self.dirstate.parents()[0] or nullid | |
300 | p1 = p1 or self.dirstate.parents()[0] or nullid |
|
300 | p1 = p1 or self.dirstate.parents()[0] or nullid | |
301 | p2 = p2 or self.dirstate.parents()[1] or nullid |
|
301 | p2 = p2 or self.dirstate.parents()[1] or nullid | |
302 | c1 = self.changelog.read(p1) |
|
302 | c1 = self.changelog.read(p1) | |
303 | c2 = self.changelog.read(p2) |
|
303 | c2 = self.changelog.read(p2) | |
304 | m1 = self.manifest.read(c1[0]) |
|
304 | m1 = self.manifest.read(c1[0]) | |
305 | mf1 = self.manifest.readflags(c1[0]) |
|
305 | mf1 = self.manifest.readflags(c1[0]) | |
306 | m2 = self.manifest.read(c2[0]) |
|
306 | m2 = self.manifest.read(c2[0]) | |
307 | changed = [] |
|
307 | changed = [] | |
308 |
|
308 | |||
309 | if orig_parent == p1: |
|
309 | if orig_parent == p1: | |
310 | update_dirstate = 1 |
|
310 | update_dirstate = 1 | |
311 | else: |
|
311 | else: | |
312 | update_dirstate = 0 |
|
312 | update_dirstate = 0 | |
313 |
|
313 | |||
314 | if not wlock: |
|
314 | if not wlock: | |
315 | wlock = self.wlock() |
|
315 | wlock = self.wlock() | |
316 | l = self.lock() |
|
316 | l = self.lock() | |
317 | tr = self.transaction() |
|
317 | tr = self.transaction() | |
318 | mm = m1.copy() |
|
318 | mm = m1.copy() | |
319 | mfm = mf1.copy() |
|
319 | mfm = mf1.copy() | |
320 | linkrev = self.changelog.count() |
|
320 | linkrev = self.changelog.count() | |
321 | for f in files: |
|
321 | for f in files: | |
322 | try: |
|
322 | try: | |
323 | t = self.wread(f) |
|
323 | t = self.wread(f) | |
324 | tm = util.is_exec(self.wjoin(f), mfm.get(f, False)) |
|
324 | tm = util.is_exec(self.wjoin(f), mfm.get(f, False)) | |
325 | r = self.file(f) |
|
325 | r = self.file(f) | |
326 | mfm[f] = tm |
|
326 | mfm[f] = tm | |
327 |
|
327 | |||
328 | (entry, fp1, fp2) = self.checkfilemerge(f, t, r, m1, m2) |
|
328 | (entry, fp1, fp2) = self.checkfilemerge(f, t, r, m1, m2) | |
329 | if entry: |
|
329 | if entry: | |
330 | mm[f] = entry |
|
330 | mm[f] = entry | |
331 | continue |
|
331 | continue | |
332 |
|
332 | |||
333 | mm[f] = r.add(t, {}, tr, linkrev, fp1, fp2) |
|
333 | mm[f] = r.add(t, {}, tr, linkrev, fp1, fp2) | |
334 | changed.append(f) |
|
334 | changed.append(f) | |
335 | if update_dirstate: |
|
335 | if update_dirstate: | |
336 | self.dirstate.update([f], "n") |
|
336 | self.dirstate.update([f], "n") | |
337 | except IOError: |
|
337 | except IOError: | |
338 | try: |
|
338 | try: | |
339 | del mm[f] |
|
339 | del mm[f] | |
340 | del mfm[f] |
|
340 | del mfm[f] | |
341 | if update_dirstate: |
|
341 | if update_dirstate: | |
342 | self.dirstate.forget([f]) |
|
342 | self.dirstate.forget([f]) | |
343 | except: |
|
343 | except: | |
344 | # deleted from p2? |
|
344 | # deleted from p2? | |
345 | pass |
|
345 | pass | |
346 |
|
346 | |||
347 | mnode = self.manifest.add(mm, mfm, tr, linkrev, c1[0], c2[0]) |
|
347 | mnode = self.manifest.add(mm, mfm, tr, linkrev, c1[0], c2[0]) | |
348 | user = user or self.ui.username() |
|
348 | user = user or self.ui.username() | |
349 | n = self.changelog.add(mnode, changed, text, tr, p1, p2, user, date) |
|
349 | n = self.changelog.add(mnode, changed, text, tr, p1, p2, user, date) | |
350 | tr.close() |
|
350 | tr.close() | |
351 | if update_dirstate: |
|
351 | if update_dirstate: | |
352 | self.dirstate.setparents(n, nullid) |
|
352 | self.dirstate.setparents(n, nullid) | |
353 |
|
353 | |||
354 | def commit(self, files=None, text="", user=None, date=None, |
|
354 | def commit(self, files=None, text="", user=None, date=None, | |
355 | match=util.always, force=False, lock=None, wlock=None): |
|
355 | match=util.always, force=False, lock=None, wlock=None): | |
356 | commit = [] |
|
356 | commit = [] | |
357 | remove = [] |
|
357 | remove = [] | |
358 | changed = [] |
|
358 | changed = [] | |
359 |
|
359 | |||
360 | if files: |
|
360 | if files: | |
361 | for f in files: |
|
361 | for f in files: | |
362 | s = self.dirstate.state(f) |
|
362 | s = self.dirstate.state(f) | |
363 | if s in 'nmai': |
|
363 | if s in 'nmai': | |
364 | commit.append(f) |
|
364 | commit.append(f) | |
365 | elif s == 'r': |
|
365 | elif s == 'r': | |
366 | remove.append(f) |
|
366 | remove.append(f) | |
367 | else: |
|
367 | else: | |
368 | self.ui.warn(_("%s not tracked!\n") % f) |
|
368 | self.ui.warn(_("%s not tracked!\n") % f) | |
369 | else: |
|
369 | else: | |
370 | modified, added, removed, deleted, unknown = self.changes(match=match) |
|
370 | modified, added, removed, deleted, unknown = self.changes(match=match) | |
371 | commit = modified + added |
|
371 | commit = modified + added | |
372 | remove = removed |
|
372 | remove = removed | |
373 |
|
373 | |||
374 | p1, p2 = self.dirstate.parents() |
|
374 | p1, p2 = self.dirstate.parents() | |
375 | c1 = self.changelog.read(p1) |
|
375 | c1 = self.changelog.read(p1) | |
376 | c2 = self.changelog.read(p2) |
|
376 | c2 = self.changelog.read(p2) | |
377 | m1 = self.manifest.read(c1[0]) |
|
377 | m1 = self.manifest.read(c1[0]) | |
378 | mf1 = self.manifest.readflags(c1[0]) |
|
378 | mf1 = self.manifest.readflags(c1[0]) | |
379 | m2 = self.manifest.read(c2[0]) |
|
379 | m2 = self.manifest.read(c2[0]) | |
380 |
|
380 | |||
381 | if not commit and not remove and not force and p2 == nullid: |
|
381 | if not commit and not remove and not force and p2 == nullid: | |
382 | self.ui.status(_("nothing changed\n")) |
|
382 | self.ui.status(_("nothing changed\n")) | |
383 | return None |
|
383 | return None | |
384 |
|
384 | |||
385 | xp1 = hex(p1) |
|
385 | xp1 = hex(p1) | |
386 | if p2 == nullid: xp2 = '' |
|
386 | if p2 == nullid: xp2 = '' | |
387 | else: xp2 = hex(p2) |
|
387 | else: xp2 = hex(p2) | |
388 |
|
388 | |||
389 | self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) |
|
389 | self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) | |
390 |
|
390 | |||
391 | if not wlock: |
|
391 | if not wlock: | |
392 | wlock = self.wlock() |
|
392 | wlock = self.wlock() | |
393 | if not lock: |
|
393 | if not lock: | |
394 | lock = self.lock() |
|
394 | lock = self.lock() | |
395 | tr = self.transaction() |
|
395 | tr = self.transaction() | |
396 |
|
396 | |||
397 | # check in files |
|
397 | # check in files | |
398 | new = {} |
|
398 | new = {} | |
399 | linkrev = self.changelog.count() |
|
399 | linkrev = self.changelog.count() | |
400 | commit.sort() |
|
400 | commit.sort() | |
401 | for f in commit: |
|
401 | for f in commit: | |
402 | self.ui.note(f + "\n") |
|
402 | self.ui.note(f + "\n") | |
403 | try: |
|
403 | try: | |
404 | mf1[f] = util.is_exec(self.wjoin(f), mf1.get(f, False)) |
|
404 | mf1[f] = util.is_exec(self.wjoin(f), mf1.get(f, False)) | |
405 | t = self.wread(f) |
|
405 | t = self.wread(f) | |
406 | except IOError: |
|
406 | except IOError: | |
407 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
407 | self.ui.warn(_("trouble committing %s!\n") % f) | |
408 | raise |
|
408 | raise | |
409 |
|
409 | |||
410 | r = self.file(f) |
|
410 | r = self.file(f) | |
411 |
|
411 | |||
412 | meta = {} |
|
412 | meta = {} | |
413 | cp = self.dirstate.copied(f) |
|
413 | cp = self.dirstate.copied(f) | |
414 | if cp: |
|
414 | if cp: | |
415 | meta["copy"] = cp |
|
415 | meta["copy"] = cp | |
416 | meta["copyrev"] = hex(m1.get(cp, m2.get(cp, nullid))) |
|
416 | meta["copyrev"] = hex(m1.get(cp, m2.get(cp, nullid))) | |
417 | self.ui.debug(_(" %s: copy %s:%s\n") % (f, cp, meta["copyrev"])) |
|
417 | self.ui.debug(_(" %s: copy %s:%s\n") % (f, cp, meta["copyrev"])) | |
418 | fp1, fp2 = nullid, nullid |
|
418 | fp1, fp2 = nullid, nullid | |
419 | else: |
|
419 | else: | |
420 | entry, fp1, fp2 = self.checkfilemerge(f, t, r, m1, m2) |
|
420 | entry, fp1, fp2 = self.checkfilemerge(f, t, r, m1, m2) | |
421 | if entry: |
|
421 | if entry: | |
422 | new[f] = entry |
|
422 | new[f] = entry | |
423 | continue |
|
423 | continue | |
424 |
|
424 | |||
425 | new[f] = r.add(t, meta, tr, linkrev, fp1, fp2) |
|
425 | new[f] = r.add(t, meta, tr, linkrev, fp1, fp2) | |
426 | # remember what we've added so that we can later calculate |
|
426 | # remember what we've added so that we can later calculate | |
427 | # the files to pull from a set of changesets |
|
427 | # the files to pull from a set of changesets | |
428 | changed.append(f) |
|
428 | changed.append(f) | |
429 |
|
429 | |||
430 | # update manifest |
|
430 | # update manifest | |
431 | m1 = m1.copy() |
|
431 | m1 = m1.copy() | |
432 | m1.update(new) |
|
432 | m1.update(new) | |
433 | for f in remove: |
|
433 | for f in remove: | |
434 | if f in m1: |
|
434 | if f in m1: | |
435 | del m1[f] |
|
435 | del m1[f] | |
436 | mn = self.manifest.add(m1, mf1, tr, linkrev, c1[0], c2[0], |
|
436 | mn = self.manifest.add(m1, mf1, tr, linkrev, c1[0], c2[0], | |
437 | (new, remove)) |
|
437 | (new, remove)) | |
438 |
|
438 | |||
439 | # add changeset |
|
439 | # add changeset | |
440 | new = new.keys() |
|
440 | new = new.keys() | |
441 | new.sort() |
|
441 | new.sort() | |
442 |
|
442 | |||
443 | if not text: |
|
443 | if not text: | |
444 | edittext = [""] |
|
444 | edittext = [""] | |
445 | if p2 != nullid: |
|
445 | if p2 != nullid: | |
446 | edittext.append("HG: branch merge") |
|
446 | edittext.append("HG: branch merge") | |
447 | edittext.extend(["HG: changed %s" % f for f in changed]) |
|
447 | edittext.extend(["HG: changed %s" % f for f in changed]) | |
448 | edittext.extend(["HG: removed %s" % f for f in remove]) |
|
448 | edittext.extend(["HG: removed %s" % f for f in remove]) | |
449 | if not changed and not remove: |
|
449 | if not changed and not remove: | |
450 | edittext.append("HG: no files changed") |
|
450 | edittext.append("HG: no files changed") | |
451 | edittext.append("") |
|
451 | edittext.append("") | |
452 | # run editor in the repository root |
|
452 | # run editor in the repository root | |
453 | olddir = os.getcwd() |
|
453 | olddir = os.getcwd() | |
454 | os.chdir(self.root) |
|
454 | os.chdir(self.root) | |
455 | edittext = self.ui.edit("\n".join(edittext)) |
|
455 | edittext = self.ui.edit("\n".join(edittext)) | |
456 | os.chdir(olddir) |
|
456 | os.chdir(olddir) | |
457 | if not edittext.rstrip(): |
|
457 | if not edittext.rstrip(): | |
458 | return None |
|
458 | return None | |
459 | text = edittext |
|
459 | text = edittext | |
460 |
|
460 | |||
461 | user = user or self.ui.username() |
|
461 | user = user or self.ui.username() | |
462 | n = self.changelog.add(mn, changed + remove, text, tr, p1, p2, user, date) |
|
462 | n = self.changelog.add(mn, changed + remove, text, tr, p1, p2, user, date) | |
463 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
463 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
464 | parent2=xp2) |
|
464 | parent2=xp2) | |
465 | tr.close() |
|
465 | tr.close() | |
466 |
|
466 | |||
467 | self.dirstate.setparents(n) |
|
467 | self.dirstate.setparents(n) | |
468 | self.dirstate.update(new, "n") |
|
468 | self.dirstate.update(new, "n") | |
469 | self.dirstate.forget(remove) |
|
469 | self.dirstate.forget(remove) | |
470 |
|
470 | |||
471 | self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) |
|
471 | self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2) | |
472 | return n |
|
472 | return n | |
473 |
|
473 | |||
474 | def walk(self, node=None, files=[], match=util.always): |
|
474 | def walk(self, node=None, files=[], match=util.always): | |
475 | if node: |
|
475 | if node: | |
476 | fdict = dict.fromkeys(files) |
|
476 | fdict = dict.fromkeys(files) | |
477 | for fn in self.manifest.read(self.changelog.read(node)[0]): |
|
477 | for fn in self.manifest.read(self.changelog.read(node)[0]): | |
478 | fdict.pop(fn, None) |
|
478 | fdict.pop(fn, None) | |
479 | if match(fn): |
|
479 | if match(fn): | |
480 | yield 'm', fn |
|
480 | yield 'm', fn | |
481 | for fn in fdict: |
|
481 | for fn in fdict: | |
482 | self.ui.warn(_('%s: No such file in rev %s\n') % ( |
|
482 | self.ui.warn(_('%s: No such file in rev %s\n') % ( | |
483 | util.pathto(self.getcwd(), fn), short(node))) |
|
483 | util.pathto(self.getcwd(), fn), short(node))) | |
484 | else: |
|
484 | else: | |
485 | for src, fn in self.dirstate.walk(files, match): |
|
485 | for src, fn in self.dirstate.walk(files, match): | |
486 | yield src, fn |
|
486 | yield src, fn | |
487 |
|
487 | |||
488 | def changes(self, node1=None, node2=None, files=[], match=util.always, |
|
488 | def changes(self, node1=None, node2=None, files=[], match=util.always, | |
489 | wlock=None): |
|
489 | wlock=None): | |
490 | """return changes between two nodes or node and working directory |
|
490 | """return changes between two nodes or node and working directory | |
491 |
|
491 | |||
492 | If node1 is None, use the first dirstate parent instead. |
|
492 | If node1 is None, use the first dirstate parent instead. | |
493 | If node2 is None, compare node1 with working directory. |
|
493 | If node2 is None, compare node1 with working directory. | |
494 | """ |
|
494 | """ | |
495 |
|
495 | |||
496 | def fcmp(fn, mf): |
|
496 | def fcmp(fn, mf): | |
497 | t1 = self.wread(fn) |
|
497 | t1 = self.wread(fn) | |
498 | t2 = self.file(fn).read(mf.get(fn, nullid)) |
|
498 | t2 = self.file(fn).read(mf.get(fn, nullid)) | |
499 | return cmp(t1, t2) |
|
499 | return cmp(t1, t2) | |
500 |
|
500 | |||
501 | def mfmatches(node): |
|
501 | def mfmatches(node): | |
502 | change = self.changelog.read(node) |
|
502 | change = self.changelog.read(node) | |
503 | mf = dict(self.manifest.read(change[0])) |
|
503 | mf = dict(self.manifest.read(change[0])) | |
504 | for fn in mf.keys(): |
|
504 | for fn in mf.keys(): | |
505 | if not match(fn): |
|
505 | if not match(fn): | |
506 | del mf[fn] |
|
506 | del mf[fn] | |
507 | return mf |
|
507 | return mf | |
508 |
|
508 | |||
509 | if node1: |
|
509 | if node1: | |
510 | # read the manifest from node1 before the manifest from node2, |
|
510 | # read the manifest from node1 before the manifest from node2, | |
511 | # so that we'll hit the manifest cache if we're going through |
|
511 | # so that we'll hit the manifest cache if we're going through | |
512 | # all the revisions in parent->child order. |
|
512 | # all the revisions in parent->child order. | |
513 | mf1 = mfmatches(node1) |
|
513 | mf1 = mfmatches(node1) | |
514 |
|
514 | |||
515 | # are we comparing the working directory? |
|
515 | # are we comparing the working directory? | |
516 | if not node2: |
|
516 | if not node2: | |
517 | if not wlock: |
|
517 | if not wlock: | |
518 | try: |
|
518 | try: | |
519 | wlock = self.wlock(wait=0) |
|
519 | wlock = self.wlock(wait=0) | |
520 | except lock.LockException: |
|
520 | except lock.LockException: | |
521 | wlock = None |
|
521 | wlock = None | |
522 | lookup, modified, added, removed, deleted, unknown = ( |
|
522 | lookup, modified, added, removed, deleted, unknown = ( | |
523 | self.dirstate.changes(files, match)) |
|
523 | self.dirstate.changes(files, match)) | |
524 |
|
524 | |||
525 | # are we comparing working dir against its parent? |
|
525 | # are we comparing working dir against its parent? | |
526 | if not node1: |
|
526 | if not node1: | |
527 | if lookup: |
|
527 | if lookup: | |
528 | # do a full compare of any files that might have changed |
|
528 | # do a full compare of any files that might have changed | |
529 | mf2 = mfmatches(self.dirstate.parents()[0]) |
|
529 | mf2 = mfmatches(self.dirstate.parents()[0]) | |
530 | for f in lookup: |
|
530 | for f in lookup: | |
531 | if fcmp(f, mf2): |
|
531 | if fcmp(f, mf2): | |
532 | modified.append(f) |
|
532 | modified.append(f) | |
533 | elif wlock is not None: |
|
533 | elif wlock is not None: | |
534 | self.dirstate.update([f], "n") |
|
534 | self.dirstate.update([f], "n") | |
535 | else: |
|
535 | else: | |
536 | # we are comparing working dir against non-parent |
|
536 | # we are comparing working dir against non-parent | |
537 | # generate a pseudo-manifest for the working dir |
|
537 | # generate a pseudo-manifest for the working dir | |
538 | mf2 = mfmatches(self.dirstate.parents()[0]) |
|
538 | mf2 = mfmatches(self.dirstate.parents()[0]) | |
539 | for f in lookup + modified + added: |
|
539 | for f in lookup + modified + added: | |
540 | mf2[f] = "" |
|
540 | mf2[f] = "" | |
541 | for f in removed: |
|
541 | for f in removed: | |
542 | if f in mf2: |
|
542 | if f in mf2: | |
543 | del mf2[f] |
|
543 | del mf2[f] | |
544 | else: |
|
544 | else: | |
545 | # we are comparing two revisions |
|
545 | # we are comparing two revisions | |
546 | deleted, unknown = [], [] |
|
546 | deleted, unknown = [], [] | |
547 | mf2 = mfmatches(node2) |
|
547 | mf2 = mfmatches(node2) | |
548 |
|
548 | |||
549 | if node1: |
|
549 | if node1: | |
550 | # flush lists from dirstate before comparing manifests |
|
550 | # flush lists from dirstate before comparing manifests | |
551 | modified, added = [], [] |
|
551 | modified, added = [], [] | |
552 |
|
552 | |||
553 | for fn in mf2: |
|
553 | for fn in mf2: | |
554 | if mf1.has_key(fn): |
|
554 | if mf1.has_key(fn): | |
555 | if mf1[fn] != mf2[fn] and (mf2[fn] != "" or fcmp(fn, mf1)): |
|
555 | if mf1[fn] != mf2[fn] and (mf2[fn] != "" or fcmp(fn, mf1)): | |
556 | modified.append(fn) |
|
556 | modified.append(fn) | |
557 | del mf1[fn] |
|
557 | del mf1[fn] | |
558 | else: |
|
558 | else: | |
559 | added.append(fn) |
|
559 | added.append(fn) | |
560 |
|
560 | |||
561 | removed = mf1.keys() |
|
561 | removed = mf1.keys() | |
562 |
|
562 | |||
563 | # sort and return results: |
|
563 | # sort and return results: | |
564 | for l in modified, added, removed, deleted, unknown: |
|
564 | for l in modified, added, removed, deleted, unknown: | |
565 | l.sort() |
|
565 | l.sort() | |
566 | return (modified, added, removed, deleted, unknown) |
|
566 | return (modified, added, removed, deleted, unknown) | |
567 |
|
567 | |||
568 | def add(self, list, wlock=None): |
|
568 | def add(self, list, wlock=None): | |
569 | if not wlock: |
|
569 | if not wlock: | |
570 | wlock = self.wlock() |
|
570 | wlock = self.wlock() | |
571 | for f in list: |
|
571 | for f in list: | |
572 | p = self.wjoin(f) |
|
572 | p = self.wjoin(f) | |
573 | if not os.path.exists(p): |
|
573 | if not os.path.exists(p): | |
574 | self.ui.warn(_("%s does not exist!\n") % f) |
|
574 | self.ui.warn(_("%s does not exist!\n") % f) | |
575 | elif not os.path.isfile(p): |
|
575 | elif not os.path.isfile(p): | |
576 | self.ui.warn(_("%s not added: only files supported currently\n") |
|
576 | self.ui.warn(_("%s not added: only files supported currently\n") | |
577 | % f) |
|
577 | % f) | |
578 | elif self.dirstate.state(f) in 'an': |
|
578 | elif self.dirstate.state(f) in 'an': | |
579 | self.ui.warn(_("%s already tracked!\n") % f) |
|
579 | self.ui.warn(_("%s already tracked!\n") % f) | |
580 | else: |
|
580 | else: | |
581 | self.dirstate.update([f], "a") |
|
581 | self.dirstate.update([f], "a") | |
582 |
|
582 | |||
583 | def forget(self, list, wlock=None): |
|
583 | def forget(self, list, wlock=None): | |
584 | if not wlock: |
|
584 | if not wlock: | |
585 | wlock = self.wlock() |
|
585 | wlock = self.wlock() | |
586 | for f in list: |
|
586 | for f in list: | |
587 | if self.dirstate.state(f) not in 'ai': |
|
587 | if self.dirstate.state(f) not in 'ai': | |
588 | self.ui.warn(_("%s not added!\n") % f) |
|
588 | self.ui.warn(_("%s not added!\n") % f) | |
589 | else: |
|
589 | else: | |
590 | self.dirstate.forget([f]) |
|
590 | self.dirstate.forget([f]) | |
591 |
|
591 | |||
592 | def remove(self, list, unlink=False, wlock=None): |
|
592 | def remove(self, list, unlink=False, wlock=None): | |
593 | if unlink: |
|
593 | if unlink: | |
594 | for f in list: |
|
594 | for f in list: | |
595 | try: |
|
595 | try: | |
596 | util.unlink(self.wjoin(f)) |
|
596 | util.unlink(self.wjoin(f)) | |
597 | except OSError, inst: |
|
597 | except OSError, inst: | |
598 | if inst.errno != errno.ENOENT: |
|
598 | if inst.errno != errno.ENOENT: | |
599 | raise |
|
599 | raise | |
600 | if not wlock: |
|
600 | if not wlock: | |
601 | wlock = self.wlock() |
|
601 | wlock = self.wlock() | |
602 | for f in list: |
|
602 | for f in list: | |
603 | p = self.wjoin(f) |
|
603 | p = self.wjoin(f) | |
604 | if os.path.exists(p): |
|
604 | if os.path.exists(p): | |
605 | self.ui.warn(_("%s still exists!\n") % f) |
|
605 | self.ui.warn(_("%s still exists!\n") % f) | |
606 | elif self.dirstate.state(f) == 'a': |
|
606 | elif self.dirstate.state(f) == 'a': | |
607 | self.dirstate.forget([f]) |
|
607 | self.dirstate.forget([f]) | |
608 | elif f not in self.dirstate: |
|
608 | elif f not in self.dirstate: | |
609 | self.ui.warn(_("%s not tracked!\n") % f) |
|
609 | self.ui.warn(_("%s not tracked!\n") % f) | |
610 | else: |
|
610 | else: | |
611 | self.dirstate.update([f], "r") |
|
611 | self.dirstate.update([f], "r") | |
612 |
|
612 | |||
613 | def undelete(self, list, wlock=None): |
|
613 | def undelete(self, list, wlock=None): | |
614 | p = self.dirstate.parents()[0] |
|
614 | p = self.dirstate.parents()[0] | |
615 | mn = self.changelog.read(p)[0] |
|
615 | mn = self.changelog.read(p)[0] | |
616 | mf = self.manifest.readflags(mn) |
|
616 | mf = self.manifest.readflags(mn) | |
617 | m = self.manifest.read(mn) |
|
617 | m = self.manifest.read(mn) | |
618 | if not wlock: |
|
618 | if not wlock: | |
619 | wlock = self.wlock() |
|
619 | wlock = self.wlock() | |
620 | for f in list: |
|
620 | for f in list: | |
621 | if self.dirstate.state(f) not in "r": |
|
621 | if self.dirstate.state(f) not in "r": | |
622 | self.ui.warn("%s not removed!\n" % f) |
|
622 | self.ui.warn("%s not removed!\n" % f) | |
623 | else: |
|
623 | else: | |
624 | t = self.file(f).read(m[f]) |
|
624 | t = self.file(f).read(m[f]) | |
625 | self.wwrite(f, t) |
|
625 | self.wwrite(f, t) | |
626 | util.set_exec(self.wjoin(f), mf[f]) |
|
626 | util.set_exec(self.wjoin(f), mf[f]) | |
627 | self.dirstate.update([f], "n") |
|
627 | self.dirstate.update([f], "n") | |
628 |
|
628 | |||
629 | def copy(self, source, dest, wlock=None): |
|
629 | def copy(self, source, dest, wlock=None): | |
630 | p = self.wjoin(dest) |
|
630 | p = self.wjoin(dest) | |
631 | if not os.path.exists(p): |
|
631 | if not os.path.exists(p): | |
632 | self.ui.warn(_("%s does not exist!\n") % dest) |
|
632 | self.ui.warn(_("%s does not exist!\n") % dest) | |
633 | elif not os.path.isfile(p): |
|
633 | elif not os.path.isfile(p): | |
634 | self.ui.warn(_("copy failed: %s is not a file\n") % dest) |
|
634 | self.ui.warn(_("copy failed: %s is not a file\n") % dest) | |
635 | else: |
|
635 | else: | |
636 | if not wlock: |
|
636 | if not wlock: | |
637 | wlock = self.wlock() |
|
637 | wlock = self.wlock() | |
638 | if self.dirstate.state(dest) == '?': |
|
638 | if self.dirstate.state(dest) == '?': | |
639 | self.dirstate.update([dest], "a") |
|
639 | self.dirstate.update([dest], "a") | |
640 | self.dirstate.copy(source, dest) |
|
640 | self.dirstate.copy(source, dest) | |
641 |
|
641 | |||
642 | def heads(self, start=None): |
|
642 | def heads(self, start=None): | |
643 | heads = self.changelog.heads(start) |
|
643 | heads = self.changelog.heads(start) | |
644 | # sort the output in rev descending order |
|
644 | # sort the output in rev descending order | |
645 | heads = [(-self.changelog.rev(h), h) for h in heads] |
|
645 | heads = [(-self.changelog.rev(h), h) for h in heads] | |
646 | heads.sort() |
|
646 | heads.sort() | |
647 | return [n for (r, n) in heads] |
|
647 | return [n for (r, n) in heads] | |
648 |
|
648 | |||
649 | # branchlookup returns a dict giving a list of branches for |
|
649 | # branchlookup returns a dict giving a list of branches for | |
650 | # each head. A branch is defined as the tag of a node or |
|
650 | # each head. A branch is defined as the tag of a node or | |
651 | # the branch of the node's parents. If a node has multiple |
|
651 | # the branch of the node's parents. If a node has multiple | |
652 | # branch tags, tags are eliminated if they are visible from other |
|
652 | # branch tags, tags are eliminated if they are visible from other | |
653 | # branch tags. |
|
653 | # branch tags. | |
654 | # |
|
654 | # | |
655 | # So, for this graph: a->b->c->d->e |
|
655 | # So, for this graph: a->b->c->d->e | |
656 | # \ / |
|
656 | # \ / | |
657 | # aa -----/ |
|
657 | # aa -----/ | |
658 | # a has tag 2.6.12 |
|
658 | # a has tag 2.6.12 | |
659 | # d has tag 2.6.13 |
|
659 | # d has tag 2.6.13 | |
660 | # e would have branch tags for 2.6.12 and 2.6.13. Because the node |
|
660 | # e would have branch tags for 2.6.12 and 2.6.13. Because the node | |
661 | # for 2.6.12 can be reached from the node 2.6.13, that is eliminated |
|
661 | # for 2.6.12 can be reached from the node 2.6.13, that is eliminated | |
662 | # from the list. |
|
662 | # from the list. | |
663 | # |
|
663 | # | |
664 | # It is possible that more than one head will have the same branch tag. |
|
664 | # It is possible that more than one head will have the same branch tag. | |
665 | # callers need to check the result for multiple heads under the same |
|
665 | # callers need to check the result for multiple heads under the same | |
666 | # branch tag if that is a problem for them (ie checkout of a specific |
|
666 | # branch tag if that is a problem for them (ie checkout of a specific | |
667 | # branch). |
|
667 | # branch). | |
668 | # |
|
668 | # | |
669 | # passing in a specific branch will limit the depth of the search |
|
669 | # passing in a specific branch will limit the depth of the search | |
670 | # through the parents. It won't limit the branches returned in the |
|
670 | # through the parents. It won't limit the branches returned in the | |
671 | # result though. |
|
671 | # result though. | |
672 | def branchlookup(self, heads=None, branch=None): |
|
672 | def branchlookup(self, heads=None, branch=None): | |
673 | if not heads: |
|
673 | if not heads: | |
674 | heads = self.heads() |
|
674 | heads = self.heads() | |
675 | headt = [ h for h in heads ] |
|
675 | headt = [ h for h in heads ] | |
676 | chlog = self.changelog |
|
676 | chlog = self.changelog | |
677 | branches = {} |
|
677 | branches = {} | |
678 | merges = [] |
|
678 | merges = [] | |
679 | seenmerge = {} |
|
679 | seenmerge = {} | |
680 |
|
680 | |||
681 | # traverse the tree once for each head, recording in the branches |
|
681 | # traverse the tree once for each head, recording in the branches | |
682 | # dict which tags are visible from this head. The branches |
|
682 | # dict which tags are visible from this head. The branches | |
683 | # dict also records which tags are visible from each tag |
|
683 | # dict also records which tags are visible from each tag | |
684 | # while we traverse. |
|
684 | # while we traverse. | |
685 | while headt or merges: |
|
685 | while headt or merges: | |
686 | if merges: |
|
686 | if merges: | |
687 | n, found = merges.pop() |
|
687 | n, found = merges.pop() | |
688 | visit = [n] |
|
688 | visit = [n] | |
689 | else: |
|
689 | else: | |
690 | h = headt.pop() |
|
690 | h = headt.pop() | |
691 | visit = [h] |
|
691 | visit = [h] | |
692 | found = [h] |
|
692 | found = [h] | |
693 | seen = {} |
|
693 | seen = {} | |
694 | while visit: |
|
694 | while visit: | |
695 | n = visit.pop() |
|
695 | n = visit.pop() | |
696 | if n in seen: |
|
696 | if n in seen: | |
697 | continue |
|
697 | continue | |
698 | pp = chlog.parents(n) |
|
698 | pp = chlog.parents(n) | |
699 | tags = self.nodetags(n) |
|
699 | tags = self.nodetags(n) | |
700 | if tags: |
|
700 | if tags: | |
701 | for x in tags: |
|
701 | for x in tags: | |
702 | if x == 'tip': |
|
702 | if x == 'tip': | |
703 | continue |
|
703 | continue | |
704 | for f in found: |
|
704 | for f in found: | |
705 | branches.setdefault(f, {})[n] = 1 |
|
705 | branches.setdefault(f, {})[n] = 1 | |
706 | branches.setdefault(n, {})[n] = 1 |
|
706 | branches.setdefault(n, {})[n] = 1 | |
707 | break |
|
707 | break | |
708 | if n not in found: |
|
708 | if n not in found: | |
709 | found.append(n) |
|
709 | found.append(n) | |
710 | if branch in tags: |
|
710 | if branch in tags: | |
711 | continue |
|
711 | continue | |
712 | seen[n] = 1 |
|
712 | seen[n] = 1 | |
713 | if pp[1] != nullid and n not in seenmerge: |
|
713 | if pp[1] != nullid and n not in seenmerge: | |
714 | merges.append((pp[1], [x for x in found])) |
|
714 | merges.append((pp[1], [x for x in found])) | |
715 | seenmerge[n] = 1 |
|
715 | seenmerge[n] = 1 | |
716 | if pp[0] != nullid: |
|
716 | if pp[0] != nullid: | |
717 | visit.append(pp[0]) |
|
717 | visit.append(pp[0]) | |
718 | # traverse the branches dict, eliminating branch tags from each |
|
718 | # traverse the branches dict, eliminating branch tags from each | |
719 | # head that are visible from another branch tag for that head. |
|
719 | # head that are visible from another branch tag for that head. | |
720 | out = {} |
|
720 | out = {} | |
721 | viscache = {} |
|
721 | viscache = {} | |
722 | for h in heads: |
|
722 | for h in heads: | |
723 | def visible(node): |
|
723 | def visible(node): | |
724 | if node in viscache: |
|
724 | if node in viscache: | |
725 | return viscache[node] |
|
725 | return viscache[node] | |
726 | ret = {} |
|
726 | ret = {} | |
727 | visit = [node] |
|
727 | visit = [node] | |
728 | while visit: |
|
728 | while visit: | |
729 | x = visit.pop() |
|
729 | x = visit.pop() | |
730 | if x in viscache: |
|
730 | if x in viscache: | |
731 | ret.update(viscache[x]) |
|
731 | ret.update(viscache[x]) | |
732 | elif x not in ret: |
|
732 | elif x not in ret: | |
733 | ret[x] = 1 |
|
733 | ret[x] = 1 | |
734 | if x in branches: |
|
734 | if x in branches: | |
735 | visit[len(visit):] = branches[x].keys() |
|
735 | visit[len(visit):] = branches[x].keys() | |
736 | viscache[node] = ret |
|
736 | viscache[node] = ret | |
737 | return ret |
|
737 | return ret | |
738 | if h not in branches: |
|
738 | if h not in branches: | |
739 | continue |
|
739 | continue | |
740 | # O(n^2), but somewhat limited. This only searches the |
|
740 | # O(n^2), but somewhat limited. This only searches the | |
741 | # tags visible from a specific head, not all the tags in the |
|
741 | # tags visible from a specific head, not all the tags in the | |
742 | # whole repo. |
|
742 | # whole repo. | |
743 | for b in branches[h]: |
|
743 | for b in branches[h]: | |
744 | vis = False |
|
744 | vis = False | |
745 | for bb in branches[h].keys(): |
|
745 | for bb in branches[h].keys(): | |
746 | if b != bb: |
|
746 | if b != bb: | |
747 | if b in visible(bb): |
|
747 | if b in visible(bb): | |
748 | vis = True |
|
748 | vis = True | |
749 | break |
|
749 | break | |
750 | if not vis: |
|
750 | if not vis: | |
751 | l = out.setdefault(h, []) |
|
751 | l = out.setdefault(h, []) | |
752 | l[len(l):] = self.nodetags(b) |
|
752 | l[len(l):] = self.nodetags(b) | |
753 | return out |
|
753 | return out | |
754 |
|
754 | |||
755 | def branches(self, nodes): |
|
755 | def branches(self, nodes): | |
756 | if not nodes: |
|
756 | if not nodes: | |
757 | nodes = [self.changelog.tip()] |
|
757 | nodes = [self.changelog.tip()] | |
758 | b = [] |
|
758 | b = [] | |
759 | for n in nodes: |
|
759 | for n in nodes: | |
760 | t = n |
|
760 | t = n | |
761 | while n: |
|
761 | while n: | |
762 | p = self.changelog.parents(n) |
|
762 | p = self.changelog.parents(n) | |
763 | if p[1] != nullid or p[0] == nullid: |
|
763 | if p[1] != nullid or p[0] == nullid: | |
764 | b.append((t, n, p[0], p[1])) |
|
764 | b.append((t, n, p[0], p[1])) | |
765 | break |
|
765 | break | |
766 | n = p[0] |
|
766 | n = p[0] | |
767 | return b |
|
767 | return b | |
768 |
|
768 | |||
769 | def between(self, pairs): |
|
769 | def between(self, pairs): | |
770 | r = [] |
|
770 | r = [] | |
771 |
|
771 | |||
772 | for top, bottom in pairs: |
|
772 | for top, bottom in pairs: | |
773 | n, l, i = top, [], 0 |
|
773 | n, l, i = top, [], 0 | |
774 | f = 1 |
|
774 | f = 1 | |
775 |
|
775 | |||
776 | while n != bottom: |
|
776 | while n != bottom: | |
777 | p = self.changelog.parents(n)[0] |
|
777 | p = self.changelog.parents(n)[0] | |
778 | if i == f: |
|
778 | if i == f: | |
779 | l.append(n) |
|
779 | l.append(n) | |
780 | f = f * 2 |
|
780 | f = f * 2 | |
781 | n = p |
|
781 | n = p | |
782 | i += 1 |
|
782 | i += 1 | |
783 |
|
783 | |||
784 | r.append(l) |
|
784 | r.append(l) | |
785 |
|
785 | |||
786 | return r |
|
786 | return r | |
787 |
|
787 | |||
788 | def findincoming(self, remote, base=None, heads=None): |
|
788 | def findincoming(self, remote, base=None, heads=None, force=False): | |
789 | m = self.changelog.nodemap |
|
789 | m = self.changelog.nodemap | |
790 | search = [] |
|
790 | search = [] | |
791 | fetch = {} |
|
791 | fetch = {} | |
792 | seen = {} |
|
792 | seen = {} | |
793 | seenbranch = {} |
|
793 | seenbranch = {} | |
794 | if base == None: |
|
794 | if base == None: | |
795 | base = {} |
|
795 | base = {} | |
796 |
|
796 | |||
797 | # assume we're closer to the tip than the root |
|
797 | # assume we're closer to the tip than the root | |
798 | # and start by examining the heads |
|
798 | # and start by examining the heads | |
799 | self.ui.status(_("searching for changes\n")) |
|
799 | self.ui.status(_("searching for changes\n")) | |
800 |
|
800 | |||
801 | if not heads: |
|
801 | if not heads: | |
802 | heads = remote.heads() |
|
802 | heads = remote.heads() | |
803 |
|
803 | |||
804 | unknown = [] |
|
804 | unknown = [] | |
805 | for h in heads: |
|
805 | for h in heads: | |
806 | if h not in m: |
|
806 | if h not in m: | |
807 | unknown.append(h) |
|
807 | unknown.append(h) | |
808 | else: |
|
808 | else: | |
809 | base[h] = 1 |
|
809 | base[h] = 1 | |
810 |
|
810 | |||
811 | if not unknown: |
|
811 | if not unknown: | |
812 | return [] |
|
812 | return [] | |
813 |
|
813 | |||
814 | rep = {} |
|
814 | rep = {} | |
815 | reqcnt = 0 |
|
815 | reqcnt = 0 | |
816 |
|
816 | |||
817 | # search through remote branches |
|
817 | # search through remote branches | |
818 | # a 'branch' here is a linear segment of history, with four parts: |
|
818 | # a 'branch' here is a linear segment of history, with four parts: | |
819 | # head, root, first parent, second parent |
|
819 | # head, root, first parent, second parent | |
820 | # (a branch always has two parents (or none) by definition) |
|
820 | # (a branch always has two parents (or none) by definition) | |
821 | unknown = remote.branches(unknown) |
|
821 | unknown = remote.branches(unknown) | |
822 | while unknown: |
|
822 | while unknown: | |
823 | r = [] |
|
823 | r = [] | |
824 | while unknown: |
|
824 | while unknown: | |
825 | n = unknown.pop(0) |
|
825 | n = unknown.pop(0) | |
826 | if n[0] in seen: |
|
826 | if n[0] in seen: | |
827 | continue |
|
827 | continue | |
828 |
|
828 | |||
829 | self.ui.debug(_("examining %s:%s\n") |
|
829 | self.ui.debug(_("examining %s:%s\n") | |
830 | % (short(n[0]), short(n[1]))) |
|
830 | % (short(n[0]), short(n[1]))) | |
831 | if n[0] == nullid: |
|
831 | if n[0] == nullid: | |
832 | break |
|
832 | break | |
833 | if n in seenbranch: |
|
833 | if n in seenbranch: | |
834 | self.ui.debug(_("branch already found\n")) |
|
834 | self.ui.debug(_("branch already found\n")) | |
835 | continue |
|
835 | continue | |
836 | if n[1] and n[1] in m: # do we know the base? |
|
836 | if n[1] and n[1] in m: # do we know the base? | |
837 | self.ui.debug(_("found incomplete branch %s:%s\n") |
|
837 | self.ui.debug(_("found incomplete branch %s:%s\n") | |
838 | % (short(n[0]), short(n[1]))) |
|
838 | % (short(n[0]), short(n[1]))) | |
839 | search.append(n) # schedule branch range for scanning |
|
839 | search.append(n) # schedule branch range for scanning | |
840 | seenbranch[n] = 1 |
|
840 | seenbranch[n] = 1 | |
841 | else: |
|
841 | else: | |
842 | if n[1] not in seen and n[1] not in fetch: |
|
842 | if n[1] not in seen and n[1] not in fetch: | |
843 | if n[2] in m and n[3] in m: |
|
843 | if n[2] in m and n[3] in m: | |
844 | self.ui.debug(_("found new changeset %s\n") % |
|
844 | self.ui.debug(_("found new changeset %s\n") % | |
845 | short(n[1])) |
|
845 | short(n[1])) | |
846 | fetch[n[1]] = 1 # earliest unknown |
|
846 | fetch[n[1]] = 1 # earliest unknown | |
847 | base[n[2]] = 1 # latest known |
|
847 | base[n[2]] = 1 # latest known | |
848 | continue |
|
848 | continue | |
849 |
|
849 | |||
850 | for a in n[2:4]: |
|
850 | for a in n[2:4]: | |
851 | if a not in rep: |
|
851 | if a not in rep: | |
852 | r.append(a) |
|
852 | r.append(a) | |
853 | rep[a] = 1 |
|
853 | rep[a] = 1 | |
854 |
|
854 | |||
855 | seen[n[0]] = 1 |
|
855 | seen[n[0]] = 1 | |
856 |
|
856 | |||
857 | if r: |
|
857 | if r: | |
858 | reqcnt += 1 |
|
858 | reqcnt += 1 | |
859 | self.ui.debug(_("request %d: %s\n") % |
|
859 | self.ui.debug(_("request %d: %s\n") % | |
860 | (reqcnt, " ".join(map(short, r)))) |
|
860 | (reqcnt, " ".join(map(short, r)))) | |
861 | for p in range(0, len(r), 10): |
|
861 | for p in range(0, len(r), 10): | |
862 | for b in remote.branches(r[p:p+10]): |
|
862 | for b in remote.branches(r[p:p+10]): | |
863 | self.ui.debug(_("received %s:%s\n") % |
|
863 | self.ui.debug(_("received %s:%s\n") % | |
864 | (short(b[0]), short(b[1]))) |
|
864 | (short(b[0]), short(b[1]))) | |
865 | if b[0] in m: |
|
865 | if b[0] in m: | |
866 | self.ui.debug(_("found base node %s\n") |
|
866 | self.ui.debug(_("found base node %s\n") | |
867 | % short(b[0])) |
|
867 | % short(b[0])) | |
868 | base[b[0]] = 1 |
|
868 | base[b[0]] = 1 | |
869 | elif b[0] not in seen: |
|
869 | elif b[0] not in seen: | |
870 | unknown.append(b) |
|
870 | unknown.append(b) | |
871 |
|
871 | |||
872 | # do binary search on the branches we found |
|
872 | # do binary search on the branches we found | |
873 | while search: |
|
873 | while search: | |
874 | n = search.pop(0) |
|
874 | n = search.pop(0) | |
875 | reqcnt += 1 |
|
875 | reqcnt += 1 | |
876 | l = remote.between([(n[0], n[1])])[0] |
|
876 | l = remote.between([(n[0], n[1])])[0] | |
877 | l.append(n[1]) |
|
877 | l.append(n[1]) | |
878 | p = n[0] |
|
878 | p = n[0] | |
879 | f = 1 |
|
879 | f = 1 | |
880 | for i in l: |
|
880 | for i in l: | |
881 | self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i))) |
|
881 | self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i))) | |
882 | if i in m: |
|
882 | if i in m: | |
883 | if f <= 2: |
|
883 | if f <= 2: | |
884 | self.ui.debug(_("found new branch changeset %s\n") % |
|
884 | self.ui.debug(_("found new branch changeset %s\n") % | |
885 | short(p)) |
|
885 | short(p)) | |
886 | fetch[p] = 1 |
|
886 | fetch[p] = 1 | |
887 | base[i] = 1 |
|
887 | base[i] = 1 | |
888 | else: |
|
888 | else: | |
889 | self.ui.debug(_("narrowed branch search to %s:%s\n") |
|
889 | self.ui.debug(_("narrowed branch search to %s:%s\n") | |
890 | % (short(p), short(i))) |
|
890 | % (short(p), short(i))) | |
891 | search.append((p, i)) |
|
891 | search.append((p, i)) | |
892 | break |
|
892 | break | |
893 | p, f = i, f * 2 |
|
893 | p, f = i, f * 2 | |
894 |
|
894 | |||
895 | # sanity check our fetch list |
|
895 | # sanity check our fetch list | |
896 | for f in fetch.keys(): |
|
896 | for f in fetch.keys(): | |
897 | if f in m: |
|
897 | if f in m: | |
898 | raise repo.RepoError(_("already have changeset ") + short(f[:4])) |
|
898 | raise repo.RepoError(_("already have changeset ") + short(f[:4])) | |
899 |
|
899 | |||
900 | if base.keys() == [nullid]: |
|
900 | if base.keys() == [nullid]: | |
901 | self.ui.warn(_("warning: pulling from an unrelated repository!\n")) |
|
901 | if force: | |
|
902 | self.ui.warn(_("warning: repository is unrelated\n")) | |||
|
903 | else: | |||
|
904 | raise util.Abort(_("repository is unrelated")) | |||
902 |
|
905 | |||
903 | self.ui.note(_("found new changesets starting at ") + |
|
906 | self.ui.note(_("found new changesets starting at ") + | |
904 | " ".join([short(f) for f in fetch]) + "\n") |
|
907 | " ".join([short(f) for f in fetch]) + "\n") | |
905 |
|
908 | |||
906 | self.ui.debug(_("%d total queries\n") % reqcnt) |
|
909 | self.ui.debug(_("%d total queries\n") % reqcnt) | |
907 |
|
910 | |||
908 | return fetch.keys() |
|
911 | return fetch.keys() | |
909 |
|
912 | |||
910 | def findoutgoing(self, remote, base=None, heads=None): |
|
913 | def findoutgoing(self, remote, base=None, heads=None, force=False): | |
911 | if base == None: |
|
914 | if base == None: | |
912 | base = {} |
|
915 | base = {} | |
913 | self.findincoming(remote, base, heads) |
|
916 | self.findincoming(remote, base, heads, force=force) | |
914 |
|
917 | |||
915 | self.ui.debug(_("common changesets up to ") |
|
918 | self.ui.debug(_("common changesets up to ") | |
916 | + " ".join(map(short, base.keys())) + "\n") |
|
919 | + " ".join(map(short, base.keys())) + "\n") | |
917 |
|
920 | |||
918 | remain = dict.fromkeys(self.changelog.nodemap) |
|
921 | remain = dict.fromkeys(self.changelog.nodemap) | |
919 |
|
922 | |||
920 | # prune everything remote has from the tree |
|
923 | # prune everything remote has from the tree | |
921 | del remain[nullid] |
|
924 | del remain[nullid] | |
922 | remove = base.keys() |
|
925 | remove = base.keys() | |
923 | while remove: |
|
926 | while remove: | |
924 | n = remove.pop(0) |
|
927 | n = remove.pop(0) | |
925 | if n in remain: |
|
928 | if n in remain: | |
926 | del remain[n] |
|
929 | del remain[n] | |
927 | for p in self.changelog.parents(n): |
|
930 | for p in self.changelog.parents(n): | |
928 | remove.append(p) |
|
931 | remove.append(p) | |
929 |
|
932 | |||
930 | # find every node whose parents have been pruned |
|
933 | # find every node whose parents have been pruned | |
931 | subset = [] |
|
934 | subset = [] | |
932 | for n in remain: |
|
935 | for n in remain: | |
933 | p1, p2 = self.changelog.parents(n) |
|
936 | p1, p2 = self.changelog.parents(n) | |
934 | if p1 not in remain and p2 not in remain: |
|
937 | if p1 not in remain and p2 not in remain: | |
935 | subset.append(n) |
|
938 | subset.append(n) | |
936 |
|
939 | |||
937 | # this is the set of all roots we have to push |
|
940 | # this is the set of all roots we have to push | |
938 | return subset |
|
941 | return subset | |
939 |
|
942 | |||
940 | def pull(self, remote, heads=None): |
|
943 | def pull(self, remote, heads=None, force=False): | |
941 | l = self.lock() |
|
944 | l = self.lock() | |
942 |
|
945 | |||
943 | # if we have an empty repo, fetch everything |
|
946 | # if we have an empty repo, fetch everything | |
944 | if self.changelog.tip() == nullid: |
|
947 | if self.changelog.tip() == nullid: | |
945 | self.ui.status(_("requesting all changes\n")) |
|
948 | self.ui.status(_("requesting all changes\n")) | |
946 | fetch = [nullid] |
|
949 | fetch = [nullid] | |
947 | else: |
|
950 | else: | |
948 | fetch = self.findincoming(remote) |
|
951 | fetch = self.findincoming(remote, force=force) | |
949 |
|
952 | |||
950 | if not fetch: |
|
953 | if not fetch: | |
951 | self.ui.status(_("no changes found\n")) |
|
954 | self.ui.status(_("no changes found\n")) | |
952 | return 1 |
|
955 | return 1 | |
953 |
|
956 | |||
954 | if heads is None: |
|
957 | if heads is None: | |
955 | cg = remote.changegroup(fetch, 'pull') |
|
958 | cg = remote.changegroup(fetch, 'pull') | |
956 | else: |
|
959 | else: | |
957 | cg = remote.changegroupsubset(fetch, heads, 'pull') |
|
960 | cg = remote.changegroupsubset(fetch, heads, 'pull') | |
958 | return self.addchangegroup(cg) |
|
961 | return self.addchangegroup(cg) | |
959 |
|
962 | |||
960 | def push(self, remote, force=False, revs=None): |
|
963 | def push(self, remote, force=False, revs=None): | |
961 | lock = remote.lock() |
|
964 | lock = remote.lock() | |
962 |
|
965 | |||
963 | base = {} |
|
966 | base = {} | |
964 | heads = remote.heads() |
|
967 | heads = remote.heads() | |
965 | inc = self.findincoming(remote, base, heads) |
|
968 | inc = self.findincoming(remote, base, heads, force=force) | |
966 | if not force and inc: |
|
969 | if not force and inc: | |
967 | self.ui.warn(_("abort: unsynced remote changes!\n")) |
|
970 | self.ui.warn(_("abort: unsynced remote changes!\n")) | |
968 | self.ui.status(_("(did you forget to sync? use push -f to force)\n")) |
|
971 | self.ui.status(_("(did you forget to sync? use push -f to force)\n")) | |
969 | return 1 |
|
972 | return 1 | |
970 |
|
973 | |||
971 | update = self.findoutgoing(remote, base) |
|
974 | update = self.findoutgoing(remote, base) | |
972 | if revs is not None: |
|
975 | if revs is not None: | |
973 | msng_cl, bases, heads = self.changelog.nodesbetween(update, revs) |
|
976 | msng_cl, bases, heads = self.changelog.nodesbetween(update, revs) | |
974 | else: |
|
977 | else: | |
975 | bases, heads = update, self.changelog.heads() |
|
978 | bases, heads = update, self.changelog.heads() | |
976 |
|
979 | |||
977 | if not bases: |
|
980 | if not bases: | |
978 | self.ui.status(_("no changes found\n")) |
|
981 | self.ui.status(_("no changes found\n")) | |
979 | return 1 |
|
982 | return 1 | |
980 | elif not force: |
|
983 | elif not force: | |
981 | if len(bases) < len(heads): |
|
984 | if len(bases) < len(heads): | |
982 | self.ui.warn(_("abort: push creates new remote branches!\n")) |
|
985 | self.ui.warn(_("abort: push creates new remote branches!\n")) | |
983 | self.ui.status(_("(did you forget to merge?" |
|
986 | self.ui.status(_("(did you forget to merge?" | |
984 | " use push -f to force)\n")) |
|
987 | " use push -f to force)\n")) | |
985 | return 1 |
|
988 | return 1 | |
986 |
|
989 | |||
987 | if revs is None: |
|
990 | if revs is None: | |
988 | cg = self.changegroup(update, 'push') |
|
991 | cg = self.changegroup(update, 'push') | |
989 | else: |
|
992 | else: | |
990 | cg = self.changegroupsubset(update, revs, 'push') |
|
993 | cg = self.changegroupsubset(update, revs, 'push') | |
991 | return remote.addchangegroup(cg) |
|
994 | return remote.addchangegroup(cg) | |
992 |
|
995 | |||
993 | def changegroupsubset(self, bases, heads, source): |
|
996 | def changegroupsubset(self, bases, heads, source): | |
994 | """This function generates a changegroup consisting of all the nodes |
|
997 | """This function generates a changegroup consisting of all the nodes | |
995 | that are descendents of any of the bases, and ancestors of any of |
|
998 | that are descendents of any of the bases, and ancestors of any of | |
996 | the heads. |
|
999 | the heads. | |
997 |
|
1000 | |||
998 | It is fairly complex as determining which filenodes and which |
|
1001 | It is fairly complex as determining which filenodes and which | |
999 | manifest nodes need to be included for the changeset to be complete |
|
1002 | manifest nodes need to be included for the changeset to be complete | |
1000 | is non-trivial. |
|
1003 | is non-trivial. | |
1001 |
|
1004 | |||
1002 | Another wrinkle is doing the reverse, figuring out which changeset in |
|
1005 | Another wrinkle is doing the reverse, figuring out which changeset in | |
1003 | the changegroup a particular filenode or manifestnode belongs to.""" |
|
1006 | the changegroup a particular filenode or manifestnode belongs to.""" | |
1004 |
|
1007 | |||
1005 | self.hook('preoutgoing', throw=True, source=source) |
|
1008 | self.hook('preoutgoing', throw=True, source=source) | |
1006 |
|
1009 | |||
1007 | # Set up some initial variables |
|
1010 | # Set up some initial variables | |
1008 | # Make it easy to refer to self.changelog |
|
1011 | # Make it easy to refer to self.changelog | |
1009 | cl = self.changelog |
|
1012 | cl = self.changelog | |
1010 | # msng is short for missing - compute the list of changesets in this |
|
1013 | # msng is short for missing - compute the list of changesets in this | |
1011 | # changegroup. |
|
1014 | # changegroup. | |
1012 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) |
|
1015 | msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads) | |
1013 | # Some bases may turn out to be superfluous, and some heads may be |
|
1016 | # Some bases may turn out to be superfluous, and some heads may be | |
1014 | # too. nodesbetween will return the minimal set of bases and heads |
|
1017 | # too. nodesbetween will return the minimal set of bases and heads | |
1015 | # necessary to re-create the changegroup. |
|
1018 | # necessary to re-create the changegroup. | |
1016 |
|
1019 | |||
1017 | # Known heads are the list of heads that it is assumed the recipient |
|
1020 | # Known heads are the list of heads that it is assumed the recipient | |
1018 | # of this changegroup will know about. |
|
1021 | # of this changegroup will know about. | |
1019 | knownheads = {} |
|
1022 | knownheads = {} | |
1020 | # We assume that all parents of bases are known heads. |
|
1023 | # We assume that all parents of bases are known heads. | |
1021 | for n in bases: |
|
1024 | for n in bases: | |
1022 | for p in cl.parents(n): |
|
1025 | for p in cl.parents(n): | |
1023 | if p != nullid: |
|
1026 | if p != nullid: | |
1024 | knownheads[p] = 1 |
|
1027 | knownheads[p] = 1 | |
1025 | knownheads = knownheads.keys() |
|
1028 | knownheads = knownheads.keys() | |
1026 | if knownheads: |
|
1029 | if knownheads: | |
1027 | # Now that we know what heads are known, we can compute which |
|
1030 | # Now that we know what heads are known, we can compute which | |
1028 | # changesets are known. The recipient must know about all |
|
1031 | # changesets are known. The recipient must know about all | |
1029 | # changesets required to reach the known heads from the null |
|
1032 | # changesets required to reach the known heads from the null | |
1030 | # changeset. |
|
1033 | # changeset. | |
1031 | has_cl_set, junk, junk = cl.nodesbetween(None, knownheads) |
|
1034 | has_cl_set, junk, junk = cl.nodesbetween(None, knownheads) | |
1032 | junk = None |
|
1035 | junk = None | |
1033 | # Transform the list into an ersatz set. |
|
1036 | # Transform the list into an ersatz set. | |
1034 | has_cl_set = dict.fromkeys(has_cl_set) |
|
1037 | has_cl_set = dict.fromkeys(has_cl_set) | |
1035 | else: |
|
1038 | else: | |
1036 | # If there were no known heads, the recipient cannot be assumed to |
|
1039 | # If there were no known heads, the recipient cannot be assumed to | |
1037 | # know about any changesets. |
|
1040 | # know about any changesets. | |
1038 | has_cl_set = {} |
|
1041 | has_cl_set = {} | |
1039 |
|
1042 | |||
1040 | # Make it easy to refer to self.manifest |
|
1043 | # Make it easy to refer to self.manifest | |
1041 | mnfst = self.manifest |
|
1044 | mnfst = self.manifest | |
1042 | # We don't know which manifests are missing yet |
|
1045 | # We don't know which manifests are missing yet | |
1043 | msng_mnfst_set = {} |
|
1046 | msng_mnfst_set = {} | |
1044 | # Nor do we know which filenodes are missing. |
|
1047 | # Nor do we know which filenodes are missing. | |
1045 | msng_filenode_set = {} |
|
1048 | msng_filenode_set = {} | |
1046 |
|
1049 | |||
1047 | junk = mnfst.index[mnfst.count() - 1] # Get around a bug in lazyindex |
|
1050 | junk = mnfst.index[mnfst.count() - 1] # Get around a bug in lazyindex | |
1048 | junk = None |
|
1051 | junk = None | |
1049 |
|
1052 | |||
1050 | # A changeset always belongs to itself, so the changenode lookup |
|
1053 | # A changeset always belongs to itself, so the changenode lookup | |
1051 | # function for a changenode is identity. |
|
1054 | # function for a changenode is identity. | |
1052 | def identity(x): |
|
1055 | def identity(x): | |
1053 | return x |
|
1056 | return x | |
1054 |
|
1057 | |||
1055 | # A function generating function. Sets up an environment for the |
|
1058 | # A function generating function. Sets up an environment for the | |
1056 | # inner function. |
|
1059 | # inner function. | |
1057 | def cmp_by_rev_func(revlog): |
|
1060 | def cmp_by_rev_func(revlog): | |
1058 | # Compare two nodes by their revision number in the environment's |
|
1061 | # Compare two nodes by their revision number in the environment's | |
1059 | # revision history. Since the revision number both represents the |
|
1062 | # revision history. Since the revision number both represents the | |
1060 | # most efficient order to read the nodes in, and represents a |
|
1063 | # most efficient order to read the nodes in, and represents a | |
1061 | # topological sorting of the nodes, this function is often useful. |
|
1064 | # topological sorting of the nodes, this function is often useful. | |
1062 | def cmp_by_rev(a, b): |
|
1065 | def cmp_by_rev(a, b): | |
1063 | return cmp(revlog.rev(a), revlog.rev(b)) |
|
1066 | return cmp(revlog.rev(a), revlog.rev(b)) | |
1064 | return cmp_by_rev |
|
1067 | return cmp_by_rev | |
1065 |
|
1068 | |||
1066 | # If we determine that a particular file or manifest node must be a |
|
1069 | # If we determine that a particular file or manifest node must be a | |
1067 | # node that the recipient of the changegroup will already have, we can |
|
1070 | # node that the recipient of the changegroup will already have, we can | |
1068 | # also assume the recipient will have all the parents. This function |
|
1071 | # also assume the recipient will have all the parents. This function | |
1069 | # prunes them from the set of missing nodes. |
|
1072 | # prunes them from the set of missing nodes. | |
1070 | def prune_parents(revlog, hasset, msngset): |
|
1073 | def prune_parents(revlog, hasset, msngset): | |
1071 | haslst = hasset.keys() |
|
1074 | haslst = hasset.keys() | |
1072 | haslst.sort(cmp_by_rev_func(revlog)) |
|
1075 | haslst.sort(cmp_by_rev_func(revlog)) | |
1073 | for node in haslst: |
|
1076 | for node in haslst: | |
1074 | parentlst = [p for p in revlog.parents(node) if p != nullid] |
|
1077 | parentlst = [p for p in revlog.parents(node) if p != nullid] | |
1075 | while parentlst: |
|
1078 | while parentlst: | |
1076 | n = parentlst.pop() |
|
1079 | n = parentlst.pop() | |
1077 | if n not in hasset: |
|
1080 | if n not in hasset: | |
1078 | hasset[n] = 1 |
|
1081 | hasset[n] = 1 | |
1079 | p = [p for p in revlog.parents(n) if p != nullid] |
|
1082 | p = [p for p in revlog.parents(n) if p != nullid] | |
1080 | parentlst.extend(p) |
|
1083 | parentlst.extend(p) | |
1081 | for n in hasset: |
|
1084 | for n in hasset: | |
1082 | msngset.pop(n, None) |
|
1085 | msngset.pop(n, None) | |
1083 |
|
1086 | |||
1084 | # This is a function generating function used to set up an environment |
|
1087 | # This is a function generating function used to set up an environment | |
1085 | # for the inner function to execute in. |
|
1088 | # for the inner function to execute in. | |
1086 | def manifest_and_file_collector(changedfileset): |
|
1089 | def manifest_and_file_collector(changedfileset): | |
1087 | # This is an information gathering function that gathers |
|
1090 | # This is an information gathering function that gathers | |
1088 | # information from each changeset node that goes out as part of |
|
1091 | # information from each changeset node that goes out as part of | |
1089 | # the changegroup. The information gathered is a list of which |
|
1092 | # the changegroup. The information gathered is a list of which | |
1090 | # manifest nodes are potentially required (the recipient may |
|
1093 | # manifest nodes are potentially required (the recipient may | |
1091 | # already have them) and total list of all files which were |
|
1094 | # already have them) and total list of all files which were | |
1092 | # changed in any changeset in the changegroup. |
|
1095 | # changed in any changeset in the changegroup. | |
1093 | # |
|
1096 | # | |
1094 | # We also remember the first changenode we saw any manifest |
|
1097 | # We also remember the first changenode we saw any manifest | |
1095 | # referenced by so we can later determine which changenode 'owns' |
|
1098 | # referenced by so we can later determine which changenode 'owns' | |
1096 | # the manifest. |
|
1099 | # the manifest. | |
1097 | def collect_manifests_and_files(clnode): |
|
1100 | def collect_manifests_and_files(clnode): | |
1098 | c = cl.read(clnode) |
|
1101 | c = cl.read(clnode) | |
1099 | for f in c[3]: |
|
1102 | for f in c[3]: | |
1100 | # This is to make sure we only have one instance of each |
|
1103 | # This is to make sure we only have one instance of each | |
1101 | # filename string for each filename. |
|
1104 | # filename string for each filename. | |
1102 | changedfileset.setdefault(f, f) |
|
1105 | changedfileset.setdefault(f, f) | |
1103 | msng_mnfst_set.setdefault(c[0], clnode) |
|
1106 | msng_mnfst_set.setdefault(c[0], clnode) | |
1104 | return collect_manifests_and_files |
|
1107 | return collect_manifests_and_files | |
1105 |
|
1108 | |||
1106 | # Figure out which manifest nodes (of the ones we think might be part |
|
1109 | # Figure out which manifest nodes (of the ones we think might be part | |
1107 | # of the changegroup) the recipient must know about and remove them |
|
1110 | # of the changegroup) the recipient must know about and remove them | |
1108 | # from the changegroup. |
|
1111 | # from the changegroup. | |
1109 | def prune_manifests(): |
|
1112 | def prune_manifests(): | |
1110 | has_mnfst_set = {} |
|
1113 | has_mnfst_set = {} | |
1111 | for n in msng_mnfst_set: |
|
1114 | for n in msng_mnfst_set: | |
1112 | # If a 'missing' manifest thinks it belongs to a changenode |
|
1115 | # If a 'missing' manifest thinks it belongs to a changenode | |
1113 | # the recipient is assumed to have, obviously the recipient |
|
1116 | # the recipient is assumed to have, obviously the recipient | |
1114 | # must have that manifest. |
|
1117 | # must have that manifest. | |
1115 | linknode = cl.node(mnfst.linkrev(n)) |
|
1118 | linknode = cl.node(mnfst.linkrev(n)) | |
1116 | if linknode in has_cl_set: |
|
1119 | if linknode in has_cl_set: | |
1117 | has_mnfst_set[n] = 1 |
|
1120 | has_mnfst_set[n] = 1 | |
1118 | prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) |
|
1121 | prune_parents(mnfst, has_mnfst_set, msng_mnfst_set) | |
1119 |
|
1122 | |||
1120 | # Use the information collected in collect_manifests_and_files to say |
|
1123 | # Use the information collected in collect_manifests_and_files to say | |
1121 | # which changenode any manifestnode belongs to. |
|
1124 | # which changenode any manifestnode belongs to. | |
1122 | def lookup_manifest_link(mnfstnode): |
|
1125 | def lookup_manifest_link(mnfstnode): | |
1123 | return msng_mnfst_set[mnfstnode] |
|
1126 | return msng_mnfst_set[mnfstnode] | |
1124 |
|
1127 | |||
1125 | # A function generating function that sets up the initial environment |
|
1128 | # A function generating function that sets up the initial environment | |
1126 | # the inner function. |
|
1129 | # the inner function. | |
1127 | def filenode_collector(changedfiles): |
|
1130 | def filenode_collector(changedfiles): | |
1128 | next_rev = [0] |
|
1131 | next_rev = [0] | |
1129 | # This gathers information from each manifestnode included in the |
|
1132 | # This gathers information from each manifestnode included in the | |
1130 | # changegroup about which filenodes the manifest node references |
|
1133 | # changegroup about which filenodes the manifest node references | |
1131 | # so we can include those in the changegroup too. |
|
1134 | # so we can include those in the changegroup too. | |
1132 | # |
|
1135 | # | |
1133 | # It also remembers which changenode each filenode belongs to. It |
|
1136 | # It also remembers which changenode each filenode belongs to. It | |
1134 | # does this by assuming the a filenode belongs to the changenode |
|
1137 | # does this by assuming the a filenode belongs to the changenode | |
1135 | # the first manifest that references it belongs to. |
|
1138 | # the first manifest that references it belongs to. | |
1136 | def collect_msng_filenodes(mnfstnode): |
|
1139 | def collect_msng_filenodes(mnfstnode): | |
1137 | r = mnfst.rev(mnfstnode) |
|
1140 | r = mnfst.rev(mnfstnode) | |
1138 | if r == next_rev[0]: |
|
1141 | if r == next_rev[0]: | |
1139 | # If the last rev we looked at was the one just previous, |
|
1142 | # If the last rev we looked at was the one just previous, | |
1140 | # we only need to see a diff. |
|
1143 | # we only need to see a diff. | |
1141 | delta = mdiff.patchtext(mnfst.delta(mnfstnode)) |
|
1144 | delta = mdiff.patchtext(mnfst.delta(mnfstnode)) | |
1142 | # For each line in the delta |
|
1145 | # For each line in the delta | |
1143 | for dline in delta.splitlines(): |
|
1146 | for dline in delta.splitlines(): | |
1144 | # get the filename and filenode for that line |
|
1147 | # get the filename and filenode for that line | |
1145 | f, fnode = dline.split('\0') |
|
1148 | f, fnode = dline.split('\0') | |
1146 | fnode = bin(fnode[:40]) |
|
1149 | fnode = bin(fnode[:40]) | |
1147 | f = changedfiles.get(f, None) |
|
1150 | f = changedfiles.get(f, None) | |
1148 | # And if the file is in the list of files we care |
|
1151 | # And if the file is in the list of files we care | |
1149 | # about. |
|
1152 | # about. | |
1150 | if f is not None: |
|
1153 | if f is not None: | |
1151 | # Get the changenode this manifest belongs to |
|
1154 | # Get the changenode this manifest belongs to | |
1152 | clnode = msng_mnfst_set[mnfstnode] |
|
1155 | clnode = msng_mnfst_set[mnfstnode] | |
1153 | # Create the set of filenodes for the file if |
|
1156 | # Create the set of filenodes for the file if | |
1154 | # there isn't one already. |
|
1157 | # there isn't one already. | |
1155 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1158 | ndset = msng_filenode_set.setdefault(f, {}) | |
1156 | # And set the filenode's changelog node to the |
|
1159 | # And set the filenode's changelog node to the | |
1157 | # manifest's if it hasn't been set already. |
|
1160 | # manifest's if it hasn't been set already. | |
1158 | ndset.setdefault(fnode, clnode) |
|
1161 | ndset.setdefault(fnode, clnode) | |
1159 | else: |
|
1162 | else: | |
1160 | # Otherwise we need a full manifest. |
|
1163 | # Otherwise we need a full manifest. | |
1161 | m = mnfst.read(mnfstnode) |
|
1164 | m = mnfst.read(mnfstnode) | |
1162 | # For every file in we care about. |
|
1165 | # For every file in we care about. | |
1163 | for f in changedfiles: |
|
1166 | for f in changedfiles: | |
1164 | fnode = m.get(f, None) |
|
1167 | fnode = m.get(f, None) | |
1165 | # If it's in the manifest |
|
1168 | # If it's in the manifest | |
1166 | if fnode is not None: |
|
1169 | if fnode is not None: | |
1167 | # See comments above. |
|
1170 | # See comments above. | |
1168 | clnode = msng_mnfst_set[mnfstnode] |
|
1171 | clnode = msng_mnfst_set[mnfstnode] | |
1169 | ndset = msng_filenode_set.setdefault(f, {}) |
|
1172 | ndset = msng_filenode_set.setdefault(f, {}) | |
1170 | ndset.setdefault(fnode, clnode) |
|
1173 | ndset.setdefault(fnode, clnode) | |
1171 | # Remember the revision we hope to see next. |
|
1174 | # Remember the revision we hope to see next. | |
1172 | next_rev[0] = r + 1 |
|
1175 | next_rev[0] = r + 1 | |
1173 | return collect_msng_filenodes |
|
1176 | return collect_msng_filenodes | |
1174 |
|
1177 | |||
1175 | # We have a list of filenodes we think we need for a file, lets remove |
|
1178 | # We have a list of filenodes we think we need for a file, lets remove | |
1176 | # all those we now the recipient must have. |
|
1179 | # all those we now the recipient must have. | |
1177 | def prune_filenodes(f, filerevlog): |
|
1180 | def prune_filenodes(f, filerevlog): | |
1178 | msngset = msng_filenode_set[f] |
|
1181 | msngset = msng_filenode_set[f] | |
1179 | hasset = {} |
|
1182 | hasset = {} | |
1180 | # If a 'missing' filenode thinks it belongs to a changenode we |
|
1183 | # If a 'missing' filenode thinks it belongs to a changenode we | |
1181 | # assume the recipient must have, then the recipient must have |
|
1184 | # assume the recipient must have, then the recipient must have | |
1182 | # that filenode. |
|
1185 | # that filenode. | |
1183 | for n in msngset: |
|
1186 | for n in msngset: | |
1184 | clnode = cl.node(filerevlog.linkrev(n)) |
|
1187 | clnode = cl.node(filerevlog.linkrev(n)) | |
1185 | if clnode in has_cl_set: |
|
1188 | if clnode in has_cl_set: | |
1186 | hasset[n] = 1 |
|
1189 | hasset[n] = 1 | |
1187 | prune_parents(filerevlog, hasset, msngset) |
|
1190 | prune_parents(filerevlog, hasset, msngset) | |
1188 |
|
1191 | |||
1189 | # A function generator function that sets up the a context for the |
|
1192 | # A function generator function that sets up the a context for the | |
1190 | # inner function. |
|
1193 | # inner function. | |
1191 | def lookup_filenode_link_func(fname): |
|
1194 | def lookup_filenode_link_func(fname): | |
1192 | msngset = msng_filenode_set[fname] |
|
1195 | msngset = msng_filenode_set[fname] | |
1193 | # Lookup the changenode the filenode belongs to. |
|
1196 | # Lookup the changenode the filenode belongs to. | |
1194 | def lookup_filenode_link(fnode): |
|
1197 | def lookup_filenode_link(fnode): | |
1195 | return msngset[fnode] |
|
1198 | return msngset[fnode] | |
1196 | return lookup_filenode_link |
|
1199 | return lookup_filenode_link | |
1197 |
|
1200 | |||
1198 | # Now that we have all theses utility functions to help out and |
|
1201 | # Now that we have all theses utility functions to help out and | |
1199 | # logically divide up the task, generate the group. |
|
1202 | # logically divide up the task, generate the group. | |
1200 | def gengroup(): |
|
1203 | def gengroup(): | |
1201 | # The set of changed files starts empty. |
|
1204 | # The set of changed files starts empty. | |
1202 | changedfiles = {} |
|
1205 | changedfiles = {} | |
1203 | # Create a changenode group generator that will call our functions |
|
1206 | # Create a changenode group generator that will call our functions | |
1204 | # back to lookup the owning changenode and collect information. |
|
1207 | # back to lookup the owning changenode and collect information. | |
1205 | group = cl.group(msng_cl_lst, identity, |
|
1208 | group = cl.group(msng_cl_lst, identity, | |
1206 | manifest_and_file_collector(changedfiles)) |
|
1209 | manifest_and_file_collector(changedfiles)) | |
1207 | for chnk in group: |
|
1210 | for chnk in group: | |
1208 | yield chnk |
|
1211 | yield chnk | |
1209 |
|
1212 | |||
1210 | # The list of manifests has been collected by the generator |
|
1213 | # The list of manifests has been collected by the generator | |
1211 | # calling our functions back. |
|
1214 | # calling our functions back. | |
1212 | prune_manifests() |
|
1215 | prune_manifests() | |
1213 | msng_mnfst_lst = msng_mnfst_set.keys() |
|
1216 | msng_mnfst_lst = msng_mnfst_set.keys() | |
1214 | # Sort the manifestnodes by revision number. |
|
1217 | # Sort the manifestnodes by revision number. | |
1215 | msng_mnfst_lst.sort(cmp_by_rev_func(mnfst)) |
|
1218 | msng_mnfst_lst.sort(cmp_by_rev_func(mnfst)) | |
1216 | # Create a generator for the manifestnodes that calls our lookup |
|
1219 | # Create a generator for the manifestnodes that calls our lookup | |
1217 | # and data collection functions back. |
|
1220 | # and data collection functions back. | |
1218 | group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, |
|
1221 | group = mnfst.group(msng_mnfst_lst, lookup_manifest_link, | |
1219 | filenode_collector(changedfiles)) |
|
1222 | filenode_collector(changedfiles)) | |
1220 | for chnk in group: |
|
1223 | for chnk in group: | |
1221 | yield chnk |
|
1224 | yield chnk | |
1222 |
|
1225 | |||
1223 | # These are no longer needed, dereference and toss the memory for |
|
1226 | # These are no longer needed, dereference and toss the memory for | |
1224 | # them. |
|
1227 | # them. | |
1225 | msng_mnfst_lst = None |
|
1228 | msng_mnfst_lst = None | |
1226 | msng_mnfst_set.clear() |
|
1229 | msng_mnfst_set.clear() | |
1227 |
|
1230 | |||
1228 | changedfiles = changedfiles.keys() |
|
1231 | changedfiles = changedfiles.keys() | |
1229 | changedfiles.sort() |
|
1232 | changedfiles.sort() | |
1230 | # Go through all our files in order sorted by name. |
|
1233 | # Go through all our files in order sorted by name. | |
1231 | for fname in changedfiles: |
|
1234 | for fname in changedfiles: | |
1232 | filerevlog = self.file(fname) |
|
1235 | filerevlog = self.file(fname) | |
1233 | # Toss out the filenodes that the recipient isn't really |
|
1236 | # Toss out the filenodes that the recipient isn't really | |
1234 | # missing. |
|
1237 | # missing. | |
1235 | if msng_filenode_set.has_key(fname): |
|
1238 | if msng_filenode_set.has_key(fname): | |
1236 | prune_filenodes(fname, filerevlog) |
|
1239 | prune_filenodes(fname, filerevlog) | |
1237 | msng_filenode_lst = msng_filenode_set[fname].keys() |
|
1240 | msng_filenode_lst = msng_filenode_set[fname].keys() | |
1238 | else: |
|
1241 | else: | |
1239 | msng_filenode_lst = [] |
|
1242 | msng_filenode_lst = [] | |
1240 | # If any filenodes are left, generate the group for them, |
|
1243 | # If any filenodes are left, generate the group for them, | |
1241 | # otherwise don't bother. |
|
1244 | # otherwise don't bother. | |
1242 | if len(msng_filenode_lst) > 0: |
|
1245 | if len(msng_filenode_lst) > 0: | |
1243 | yield struct.pack(">l", len(fname) + 4) + fname |
|
1246 | yield struct.pack(">l", len(fname) + 4) + fname | |
1244 | # Sort the filenodes by their revision # |
|
1247 | # Sort the filenodes by their revision # | |
1245 | msng_filenode_lst.sort(cmp_by_rev_func(filerevlog)) |
|
1248 | msng_filenode_lst.sort(cmp_by_rev_func(filerevlog)) | |
1246 | # Create a group generator and only pass in a changenode |
|
1249 | # Create a group generator and only pass in a changenode | |
1247 | # lookup function as we need to collect no information |
|
1250 | # lookup function as we need to collect no information | |
1248 | # from filenodes. |
|
1251 | # from filenodes. | |
1249 | group = filerevlog.group(msng_filenode_lst, |
|
1252 | group = filerevlog.group(msng_filenode_lst, | |
1250 | lookup_filenode_link_func(fname)) |
|
1253 | lookup_filenode_link_func(fname)) | |
1251 | for chnk in group: |
|
1254 | for chnk in group: | |
1252 | yield chnk |
|
1255 | yield chnk | |
1253 | if msng_filenode_set.has_key(fname): |
|
1256 | if msng_filenode_set.has_key(fname): | |
1254 | # Don't need this anymore, toss it to free memory. |
|
1257 | # Don't need this anymore, toss it to free memory. | |
1255 | del msng_filenode_set[fname] |
|
1258 | del msng_filenode_set[fname] | |
1256 | # Signal that no more groups are left. |
|
1259 | # Signal that no more groups are left. | |
1257 | yield struct.pack(">l", 0) |
|
1260 | yield struct.pack(">l", 0) | |
1258 |
|
1261 | |||
1259 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) |
|
1262 | self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source) | |
1260 |
|
1263 | |||
1261 | return util.chunkbuffer(gengroup()) |
|
1264 | return util.chunkbuffer(gengroup()) | |
1262 |
|
1265 | |||
1263 | def changegroup(self, basenodes, source): |
|
1266 | def changegroup(self, basenodes, source): | |
1264 | """Generate a changegroup of all nodes that we have that a recipient |
|
1267 | """Generate a changegroup of all nodes that we have that a recipient | |
1265 | doesn't. |
|
1268 | doesn't. | |
1266 |
|
1269 | |||
1267 | This is much easier than the previous function as we can assume that |
|
1270 | This is much easier than the previous function as we can assume that | |
1268 | the recipient has any changenode we aren't sending them.""" |
|
1271 | the recipient has any changenode we aren't sending them.""" | |
1269 |
|
1272 | |||
1270 | self.hook('preoutgoing', throw=True, source=source) |
|
1273 | self.hook('preoutgoing', throw=True, source=source) | |
1271 |
|
1274 | |||
1272 | cl = self.changelog |
|
1275 | cl = self.changelog | |
1273 | nodes = cl.nodesbetween(basenodes, None)[0] |
|
1276 | nodes = cl.nodesbetween(basenodes, None)[0] | |
1274 | revset = dict.fromkeys([cl.rev(n) for n in nodes]) |
|
1277 | revset = dict.fromkeys([cl.rev(n) for n in nodes]) | |
1275 |
|
1278 | |||
1276 | def identity(x): |
|
1279 | def identity(x): | |
1277 | return x |
|
1280 | return x | |
1278 |
|
1281 | |||
1279 | def gennodelst(revlog): |
|
1282 | def gennodelst(revlog): | |
1280 | for r in xrange(0, revlog.count()): |
|
1283 | for r in xrange(0, revlog.count()): | |
1281 | n = revlog.node(r) |
|
1284 | n = revlog.node(r) | |
1282 | if revlog.linkrev(n) in revset: |
|
1285 | if revlog.linkrev(n) in revset: | |
1283 | yield n |
|
1286 | yield n | |
1284 |
|
1287 | |||
1285 | def changed_file_collector(changedfileset): |
|
1288 | def changed_file_collector(changedfileset): | |
1286 | def collect_changed_files(clnode): |
|
1289 | def collect_changed_files(clnode): | |
1287 | c = cl.read(clnode) |
|
1290 | c = cl.read(clnode) | |
1288 | for fname in c[3]: |
|
1291 | for fname in c[3]: | |
1289 | changedfileset[fname] = 1 |
|
1292 | changedfileset[fname] = 1 | |
1290 | return collect_changed_files |
|
1293 | return collect_changed_files | |
1291 |
|
1294 | |||
1292 | def lookuprevlink_func(revlog): |
|
1295 | def lookuprevlink_func(revlog): | |
1293 | def lookuprevlink(n): |
|
1296 | def lookuprevlink(n): | |
1294 | return cl.node(revlog.linkrev(n)) |
|
1297 | return cl.node(revlog.linkrev(n)) | |
1295 | return lookuprevlink |
|
1298 | return lookuprevlink | |
1296 |
|
1299 | |||
1297 | def gengroup(): |
|
1300 | def gengroup(): | |
1298 | # construct a list of all changed files |
|
1301 | # construct a list of all changed files | |
1299 | changedfiles = {} |
|
1302 | changedfiles = {} | |
1300 |
|
1303 | |||
1301 | for chnk in cl.group(nodes, identity, |
|
1304 | for chnk in cl.group(nodes, identity, | |
1302 | changed_file_collector(changedfiles)): |
|
1305 | changed_file_collector(changedfiles)): | |
1303 | yield chnk |
|
1306 | yield chnk | |
1304 | changedfiles = changedfiles.keys() |
|
1307 | changedfiles = changedfiles.keys() | |
1305 | changedfiles.sort() |
|
1308 | changedfiles.sort() | |
1306 |
|
1309 | |||
1307 | mnfst = self.manifest |
|
1310 | mnfst = self.manifest | |
1308 | nodeiter = gennodelst(mnfst) |
|
1311 | nodeiter = gennodelst(mnfst) | |
1309 | for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)): |
|
1312 | for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)): | |
1310 | yield chnk |
|
1313 | yield chnk | |
1311 |
|
1314 | |||
1312 | for fname in changedfiles: |
|
1315 | for fname in changedfiles: | |
1313 | filerevlog = self.file(fname) |
|
1316 | filerevlog = self.file(fname) | |
1314 | nodeiter = gennodelst(filerevlog) |
|
1317 | nodeiter = gennodelst(filerevlog) | |
1315 | nodeiter = list(nodeiter) |
|
1318 | nodeiter = list(nodeiter) | |
1316 | if nodeiter: |
|
1319 | if nodeiter: | |
1317 | yield struct.pack(">l", len(fname) + 4) + fname |
|
1320 | yield struct.pack(">l", len(fname) + 4) + fname | |
1318 | lookup = lookuprevlink_func(filerevlog) |
|
1321 | lookup = lookuprevlink_func(filerevlog) | |
1319 | for chnk in filerevlog.group(nodeiter, lookup): |
|
1322 | for chnk in filerevlog.group(nodeiter, lookup): | |
1320 | yield chnk |
|
1323 | yield chnk | |
1321 |
|
1324 | |||
1322 | yield struct.pack(">l", 0) |
|
1325 | yield struct.pack(">l", 0) | |
1323 | self.hook('outgoing', node=hex(nodes[0]), source=source) |
|
1326 | self.hook('outgoing', node=hex(nodes[0]), source=source) | |
1324 |
|
1327 | |||
1325 | return util.chunkbuffer(gengroup()) |
|
1328 | return util.chunkbuffer(gengroup()) | |
1326 |
|
1329 | |||
1327 | def addchangegroup(self, source): |
|
1330 | def addchangegroup(self, source): | |
1328 |
|
1331 | |||
1329 | def getchunk(): |
|
1332 | def getchunk(): | |
1330 | d = source.read(4) |
|
1333 | d = source.read(4) | |
1331 | if not d: |
|
1334 | if not d: | |
1332 | return "" |
|
1335 | return "" | |
1333 | l = struct.unpack(">l", d)[0] |
|
1336 | l = struct.unpack(">l", d)[0] | |
1334 | if l <= 4: |
|
1337 | if l <= 4: | |
1335 | return "" |
|
1338 | return "" | |
1336 | d = source.read(l - 4) |
|
1339 | d = source.read(l - 4) | |
1337 | if len(d) < l - 4: |
|
1340 | if len(d) < l - 4: | |
1338 | raise repo.RepoError(_("premature EOF reading chunk" |
|
1341 | raise repo.RepoError(_("premature EOF reading chunk" | |
1339 | " (got %d bytes, expected %d)") |
|
1342 | " (got %d bytes, expected %d)") | |
1340 | % (len(d), l - 4)) |
|
1343 | % (len(d), l - 4)) | |
1341 | return d |
|
1344 | return d | |
1342 |
|
1345 | |||
1343 | def getgroup(): |
|
1346 | def getgroup(): | |
1344 | while 1: |
|
1347 | while 1: | |
1345 | c = getchunk() |
|
1348 | c = getchunk() | |
1346 | if not c: |
|
1349 | if not c: | |
1347 | break |
|
1350 | break | |
1348 | yield c |
|
1351 | yield c | |
1349 |
|
1352 | |||
1350 | def csmap(x): |
|
1353 | def csmap(x): | |
1351 | self.ui.debug(_("add changeset %s\n") % short(x)) |
|
1354 | self.ui.debug(_("add changeset %s\n") % short(x)) | |
1352 | return self.changelog.count() |
|
1355 | return self.changelog.count() | |
1353 |
|
1356 | |||
1354 | def revmap(x): |
|
1357 | def revmap(x): | |
1355 | return self.changelog.rev(x) |
|
1358 | return self.changelog.rev(x) | |
1356 |
|
1359 | |||
1357 | if not source: |
|
1360 | if not source: | |
1358 | return |
|
1361 | return | |
1359 |
|
1362 | |||
1360 | self.hook('prechangegroup', throw=True) |
|
1363 | self.hook('prechangegroup', throw=True) | |
1361 |
|
1364 | |||
1362 | changesets = files = revisions = 0 |
|
1365 | changesets = files = revisions = 0 | |
1363 |
|
1366 | |||
1364 | tr = self.transaction() |
|
1367 | tr = self.transaction() | |
1365 |
|
1368 | |||
1366 | oldheads = len(self.changelog.heads()) |
|
1369 | oldheads = len(self.changelog.heads()) | |
1367 |
|
1370 | |||
1368 | # pull off the changeset group |
|
1371 | # pull off the changeset group | |
1369 | self.ui.status(_("adding changesets\n")) |
|
1372 | self.ui.status(_("adding changesets\n")) | |
1370 | co = self.changelog.tip() |
|
1373 | co = self.changelog.tip() | |
1371 | cn = self.changelog.addgroup(getgroup(), csmap, tr, 1) # unique |
|
1374 | cn = self.changelog.addgroup(getgroup(), csmap, tr, 1) # unique | |
1372 | cnr, cor = map(self.changelog.rev, (cn, co)) |
|
1375 | cnr, cor = map(self.changelog.rev, (cn, co)) | |
1373 | if cn == nullid: |
|
1376 | if cn == nullid: | |
1374 | cnr = cor |
|
1377 | cnr = cor | |
1375 | changesets = cnr - cor |
|
1378 | changesets = cnr - cor | |
1376 |
|
1379 | |||
1377 | # pull off the manifest group |
|
1380 | # pull off the manifest group | |
1378 | self.ui.status(_("adding manifests\n")) |
|
1381 | self.ui.status(_("adding manifests\n")) | |
1379 | mm = self.manifest.tip() |
|
1382 | mm = self.manifest.tip() | |
1380 | mo = self.manifest.addgroup(getgroup(), revmap, tr) |
|
1383 | mo = self.manifest.addgroup(getgroup(), revmap, tr) | |
1381 |
|
1384 | |||
1382 | # process the files |
|
1385 | # process the files | |
1383 | self.ui.status(_("adding file changes\n")) |
|
1386 | self.ui.status(_("adding file changes\n")) | |
1384 | while 1: |
|
1387 | while 1: | |
1385 | f = getchunk() |
|
1388 | f = getchunk() | |
1386 | if not f: |
|
1389 | if not f: | |
1387 | break |
|
1390 | break | |
1388 | self.ui.debug(_("adding %s revisions\n") % f) |
|
1391 | self.ui.debug(_("adding %s revisions\n") % f) | |
1389 | fl = self.file(f) |
|
1392 | fl = self.file(f) | |
1390 | o = fl.count() |
|
1393 | o = fl.count() | |
1391 | n = fl.addgroup(getgroup(), revmap, tr) |
|
1394 | n = fl.addgroup(getgroup(), revmap, tr) | |
1392 | revisions += fl.count() - o |
|
1395 | revisions += fl.count() - o | |
1393 | files += 1 |
|
1396 | files += 1 | |
1394 |
|
1397 | |||
1395 | newheads = len(self.changelog.heads()) |
|
1398 | newheads = len(self.changelog.heads()) | |
1396 | heads = "" |
|
1399 | heads = "" | |
1397 | if oldheads and newheads > oldheads: |
|
1400 | if oldheads and newheads > oldheads: | |
1398 | heads = _(" (+%d heads)") % (newheads - oldheads) |
|
1401 | heads = _(" (+%d heads)") % (newheads - oldheads) | |
1399 |
|
1402 | |||
1400 | self.ui.status(_("added %d changesets" |
|
1403 | self.ui.status(_("added %d changesets" | |
1401 | " with %d changes to %d files%s\n") |
|
1404 | " with %d changes to %d files%s\n") | |
1402 | % (changesets, revisions, files, heads)) |
|
1405 | % (changesets, revisions, files, heads)) | |
1403 |
|
1406 | |||
1404 | self.hook('pretxnchangegroup', throw=True, |
|
1407 | self.hook('pretxnchangegroup', throw=True, | |
1405 | node=hex(self.changelog.node(cor+1))) |
|
1408 | node=hex(self.changelog.node(cor+1))) | |
1406 |
|
1409 | |||
1407 | tr.close() |
|
1410 | tr.close() | |
1408 |
|
1411 | |||
1409 | if changesets > 0: |
|
1412 | if changesets > 0: | |
1410 | self.hook("changegroup", node=hex(self.changelog.node(cor+1))) |
|
1413 | self.hook("changegroup", node=hex(self.changelog.node(cor+1))) | |
1411 |
|
1414 | |||
1412 | for i in range(cor + 1, cnr + 1): |
|
1415 | for i in range(cor + 1, cnr + 1): | |
1413 | self.hook("incoming", node=hex(self.changelog.node(i))) |
|
1416 | self.hook("incoming", node=hex(self.changelog.node(i))) | |
1414 |
|
1417 | |||
1415 | def update(self, node, allow=False, force=False, choose=None, |
|
1418 | def update(self, node, allow=False, force=False, choose=None, | |
1416 | moddirstate=True, forcemerge=False, wlock=None): |
|
1419 | moddirstate=True, forcemerge=False, wlock=None): | |
1417 | pl = self.dirstate.parents() |
|
1420 | pl = self.dirstate.parents() | |
1418 | if not force and pl[1] != nullid: |
|
1421 | if not force and pl[1] != nullid: | |
1419 | self.ui.warn(_("aborting: outstanding uncommitted merges\n")) |
|
1422 | self.ui.warn(_("aborting: outstanding uncommitted merges\n")) | |
1420 | return 1 |
|
1423 | return 1 | |
1421 |
|
1424 | |||
1422 | err = False |
|
1425 | err = False | |
1423 |
|
1426 | |||
1424 | p1, p2 = pl[0], node |
|
1427 | p1, p2 = pl[0], node | |
1425 | pa = self.changelog.ancestor(p1, p2) |
|
1428 | pa = self.changelog.ancestor(p1, p2) | |
1426 | m1n = self.changelog.read(p1)[0] |
|
1429 | m1n = self.changelog.read(p1)[0] | |
1427 | m2n = self.changelog.read(p2)[0] |
|
1430 | m2n = self.changelog.read(p2)[0] | |
1428 | man = self.manifest.ancestor(m1n, m2n) |
|
1431 | man = self.manifest.ancestor(m1n, m2n) | |
1429 | m1 = self.manifest.read(m1n) |
|
1432 | m1 = self.manifest.read(m1n) | |
1430 | mf1 = self.manifest.readflags(m1n) |
|
1433 | mf1 = self.manifest.readflags(m1n) | |
1431 | m2 = self.manifest.read(m2n).copy() |
|
1434 | m2 = self.manifest.read(m2n).copy() | |
1432 | mf2 = self.manifest.readflags(m2n) |
|
1435 | mf2 = self.manifest.readflags(m2n) | |
1433 | ma = self.manifest.read(man) |
|
1436 | ma = self.manifest.read(man) | |
1434 | mfa = self.manifest.readflags(man) |
|
1437 | mfa = self.manifest.readflags(man) | |
1435 |
|
1438 | |||
1436 | modified, added, removed, deleted, unknown = self.changes() |
|
1439 | modified, added, removed, deleted, unknown = self.changes() | |
1437 |
|
1440 | |||
1438 | # is this a jump, or a merge? i.e. is there a linear path |
|
1441 | # is this a jump, or a merge? i.e. is there a linear path | |
1439 | # from p1 to p2? |
|
1442 | # from p1 to p2? | |
1440 | linear_path = (pa == p1 or pa == p2) |
|
1443 | linear_path = (pa == p1 or pa == p2) | |
1441 |
|
1444 | |||
1442 | if allow and linear_path: |
|
1445 | if allow and linear_path: | |
1443 | raise util.Abort(_("there is nothing to merge, " |
|
1446 | raise util.Abort(_("there is nothing to merge, " | |
1444 | "just use 'hg update'")) |
|
1447 | "just use 'hg update'")) | |
1445 | if allow and not forcemerge: |
|
1448 | if allow and not forcemerge: | |
1446 | if modified or added or removed: |
|
1449 | if modified or added or removed: | |
1447 | raise util.Abort(_("outstanding uncommited changes")) |
|
1450 | raise util.Abort(_("outstanding uncommited changes")) | |
1448 | if not forcemerge and not force: |
|
1451 | if not forcemerge and not force: | |
1449 | for f in unknown: |
|
1452 | for f in unknown: | |
1450 | if f in m2: |
|
1453 | if f in m2: | |
1451 | t1 = self.wread(f) |
|
1454 | t1 = self.wread(f) | |
1452 | t2 = self.file(f).read(m2[f]) |
|
1455 | t2 = self.file(f).read(m2[f]) | |
1453 | if cmp(t1, t2) != 0: |
|
1456 | if cmp(t1, t2) != 0: | |
1454 | raise util.Abort(_("'%s' already exists in the working" |
|
1457 | raise util.Abort(_("'%s' already exists in the working" | |
1455 | " dir and differs from remote") % f) |
|
1458 | " dir and differs from remote") % f) | |
1456 |
|
1459 | |||
1457 | # resolve the manifest to determine which files |
|
1460 | # resolve the manifest to determine which files | |
1458 | # we care about merging |
|
1461 | # we care about merging | |
1459 | self.ui.note(_("resolving manifests\n")) |
|
1462 | self.ui.note(_("resolving manifests\n")) | |
1460 | self.ui.debug(_(" force %s allow %s moddirstate %s linear %s\n") % |
|
1463 | self.ui.debug(_(" force %s allow %s moddirstate %s linear %s\n") % | |
1461 | (force, allow, moddirstate, linear_path)) |
|
1464 | (force, allow, moddirstate, linear_path)) | |
1462 | self.ui.debug(_(" ancestor %s local %s remote %s\n") % |
|
1465 | self.ui.debug(_(" ancestor %s local %s remote %s\n") % | |
1463 | (short(man), short(m1n), short(m2n))) |
|
1466 | (short(man), short(m1n), short(m2n))) | |
1464 |
|
1467 | |||
1465 | merge = {} |
|
1468 | merge = {} | |
1466 | get = {} |
|
1469 | get = {} | |
1467 | remove = [] |
|
1470 | remove = [] | |
1468 |
|
1471 | |||
1469 | # construct a working dir manifest |
|
1472 | # construct a working dir manifest | |
1470 | mw = m1.copy() |
|
1473 | mw = m1.copy() | |
1471 | mfw = mf1.copy() |
|
1474 | mfw = mf1.copy() | |
1472 | umap = dict.fromkeys(unknown) |
|
1475 | umap = dict.fromkeys(unknown) | |
1473 |
|
1476 | |||
1474 | for f in added + modified + unknown: |
|
1477 | for f in added + modified + unknown: | |
1475 | mw[f] = "" |
|
1478 | mw[f] = "" | |
1476 | mfw[f] = util.is_exec(self.wjoin(f), mfw.get(f, False)) |
|
1479 | mfw[f] = util.is_exec(self.wjoin(f), mfw.get(f, False)) | |
1477 |
|
1480 | |||
1478 | if moddirstate and not wlock: |
|
1481 | if moddirstate and not wlock: | |
1479 | wlock = self.wlock() |
|
1482 | wlock = self.wlock() | |
1480 |
|
1483 | |||
1481 | for f in deleted + removed: |
|
1484 | for f in deleted + removed: | |
1482 | if f in mw: |
|
1485 | if f in mw: | |
1483 | del mw[f] |
|
1486 | del mw[f] | |
1484 |
|
1487 | |||
1485 | # If we're jumping between revisions (as opposed to merging), |
|
1488 | # If we're jumping between revisions (as opposed to merging), | |
1486 | # and if neither the working directory nor the target rev has |
|
1489 | # and if neither the working directory nor the target rev has | |
1487 | # the file, then we need to remove it from the dirstate, to |
|
1490 | # the file, then we need to remove it from the dirstate, to | |
1488 | # prevent the dirstate from listing the file when it is no |
|
1491 | # prevent the dirstate from listing the file when it is no | |
1489 | # longer in the manifest. |
|
1492 | # longer in the manifest. | |
1490 | if moddirstate and linear_path and f not in m2: |
|
1493 | if moddirstate and linear_path and f not in m2: | |
1491 | self.dirstate.forget((f,)) |
|
1494 | self.dirstate.forget((f,)) | |
1492 |
|
1495 | |||
1493 | # Compare manifests |
|
1496 | # Compare manifests | |
1494 | for f, n in mw.iteritems(): |
|
1497 | for f, n in mw.iteritems(): | |
1495 | if choose and not choose(f): |
|
1498 | if choose and not choose(f): | |
1496 | continue |
|
1499 | continue | |
1497 | if f in m2: |
|
1500 | if f in m2: | |
1498 | s = 0 |
|
1501 | s = 0 | |
1499 |
|
1502 | |||
1500 | # is the wfile new since m1, and match m2? |
|
1503 | # is the wfile new since m1, and match m2? | |
1501 | if f not in m1: |
|
1504 | if f not in m1: | |
1502 | t1 = self.wread(f) |
|
1505 | t1 = self.wread(f) | |
1503 | t2 = self.file(f).read(m2[f]) |
|
1506 | t2 = self.file(f).read(m2[f]) | |
1504 | if cmp(t1, t2) == 0: |
|
1507 | if cmp(t1, t2) == 0: | |
1505 | n = m2[f] |
|
1508 | n = m2[f] | |
1506 | del t1, t2 |
|
1509 | del t1, t2 | |
1507 |
|
1510 | |||
1508 | # are files different? |
|
1511 | # are files different? | |
1509 | if n != m2[f]: |
|
1512 | if n != m2[f]: | |
1510 | a = ma.get(f, nullid) |
|
1513 | a = ma.get(f, nullid) | |
1511 | # are both different from the ancestor? |
|
1514 | # are both different from the ancestor? | |
1512 | if n != a and m2[f] != a: |
|
1515 | if n != a and m2[f] != a: | |
1513 | self.ui.debug(_(" %s versions differ, resolve\n") % f) |
|
1516 | self.ui.debug(_(" %s versions differ, resolve\n") % f) | |
1514 | # merge executable bits |
|
1517 | # merge executable bits | |
1515 | # "if we changed or they changed, change in merge" |
|
1518 | # "if we changed or they changed, change in merge" | |
1516 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] |
|
1519 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] | |
1517 | mode = ((a^b) | (a^c)) ^ a |
|
1520 | mode = ((a^b) | (a^c)) ^ a | |
1518 | merge[f] = (m1.get(f, nullid), m2[f], mode) |
|
1521 | merge[f] = (m1.get(f, nullid), m2[f], mode) | |
1519 | s = 1 |
|
1522 | s = 1 | |
1520 | # are we clobbering? |
|
1523 | # are we clobbering? | |
1521 | # is remote's version newer? |
|
1524 | # is remote's version newer? | |
1522 | # or are we going back in time? |
|
1525 | # or are we going back in time? | |
1523 | elif force or m2[f] != a or (p2 == pa and mw[f] == m1[f]): |
|
1526 | elif force or m2[f] != a or (p2 == pa and mw[f] == m1[f]): | |
1524 | self.ui.debug(_(" remote %s is newer, get\n") % f) |
|
1527 | self.ui.debug(_(" remote %s is newer, get\n") % f) | |
1525 | get[f] = m2[f] |
|
1528 | get[f] = m2[f] | |
1526 | s = 1 |
|
1529 | s = 1 | |
1527 | elif f in umap: |
|
1530 | elif f in umap: | |
1528 | # this unknown file is the same as the checkout |
|
1531 | # this unknown file is the same as the checkout | |
1529 | get[f] = m2[f] |
|
1532 | get[f] = m2[f] | |
1530 |
|
1533 | |||
1531 | if not s and mfw[f] != mf2[f]: |
|
1534 | if not s and mfw[f] != mf2[f]: | |
1532 | if force: |
|
1535 | if force: | |
1533 | self.ui.debug(_(" updating permissions for %s\n") % f) |
|
1536 | self.ui.debug(_(" updating permissions for %s\n") % f) | |
1534 | util.set_exec(self.wjoin(f), mf2[f]) |
|
1537 | util.set_exec(self.wjoin(f), mf2[f]) | |
1535 | else: |
|
1538 | else: | |
1536 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] |
|
1539 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] | |
1537 | mode = ((a^b) | (a^c)) ^ a |
|
1540 | mode = ((a^b) | (a^c)) ^ a | |
1538 | if mode != b: |
|
1541 | if mode != b: | |
1539 | self.ui.debug(_(" updating permissions for %s\n") |
|
1542 | self.ui.debug(_(" updating permissions for %s\n") | |
1540 | % f) |
|
1543 | % f) | |
1541 | util.set_exec(self.wjoin(f), mode) |
|
1544 | util.set_exec(self.wjoin(f), mode) | |
1542 | del m2[f] |
|
1545 | del m2[f] | |
1543 | elif f in ma: |
|
1546 | elif f in ma: | |
1544 | if n != ma[f]: |
|
1547 | if n != ma[f]: | |
1545 | r = _("d") |
|
1548 | r = _("d") | |
1546 | if not force and (linear_path or allow): |
|
1549 | if not force and (linear_path or allow): | |
1547 | r = self.ui.prompt( |
|
1550 | r = self.ui.prompt( | |
1548 | (_(" local changed %s which remote deleted\n") % f) + |
|
1551 | (_(" local changed %s which remote deleted\n") % f) + | |
1549 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) |
|
1552 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) | |
1550 | if r == _("d"): |
|
1553 | if r == _("d"): | |
1551 | remove.append(f) |
|
1554 | remove.append(f) | |
1552 | else: |
|
1555 | else: | |
1553 | self.ui.debug(_("other deleted %s\n") % f) |
|
1556 | self.ui.debug(_("other deleted %s\n") % f) | |
1554 | remove.append(f) # other deleted it |
|
1557 | remove.append(f) # other deleted it | |
1555 | else: |
|
1558 | else: | |
1556 | # file is created on branch or in working directory |
|
1559 | # file is created on branch or in working directory | |
1557 | if force and f not in umap: |
|
1560 | if force and f not in umap: | |
1558 | self.ui.debug(_("remote deleted %s, clobbering\n") % f) |
|
1561 | self.ui.debug(_("remote deleted %s, clobbering\n") % f) | |
1559 | remove.append(f) |
|
1562 | remove.append(f) | |
1560 | elif n == m1.get(f, nullid): # same as parent |
|
1563 | elif n == m1.get(f, nullid): # same as parent | |
1561 | if p2 == pa: # going backwards? |
|
1564 | if p2 == pa: # going backwards? | |
1562 | self.ui.debug(_("remote deleted %s\n") % f) |
|
1565 | self.ui.debug(_("remote deleted %s\n") % f) | |
1563 | remove.append(f) |
|
1566 | remove.append(f) | |
1564 | else: |
|
1567 | else: | |
1565 | self.ui.debug(_("local modified %s, keeping\n") % f) |
|
1568 | self.ui.debug(_("local modified %s, keeping\n") % f) | |
1566 | else: |
|
1569 | else: | |
1567 | self.ui.debug(_("working dir created %s, keeping\n") % f) |
|
1570 | self.ui.debug(_("working dir created %s, keeping\n") % f) | |
1568 |
|
1571 | |||
1569 | for f, n in m2.iteritems(): |
|
1572 | for f, n in m2.iteritems(): | |
1570 | if choose and not choose(f): |
|
1573 | if choose and not choose(f): | |
1571 | continue |
|
1574 | continue | |
1572 | if f[0] == "/": |
|
1575 | if f[0] == "/": | |
1573 | continue |
|
1576 | continue | |
1574 | if f in ma and n != ma[f]: |
|
1577 | if f in ma and n != ma[f]: | |
1575 | r = _("k") |
|
1578 | r = _("k") | |
1576 | if not force and (linear_path or allow): |
|
1579 | if not force and (linear_path or allow): | |
1577 | r = self.ui.prompt( |
|
1580 | r = self.ui.prompt( | |
1578 | (_("remote changed %s which local deleted\n") % f) + |
|
1581 | (_("remote changed %s which local deleted\n") % f) + | |
1579 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) |
|
1582 | _("(k)eep or (d)elete?"), _("[kd]"), _("k")) | |
1580 | if r == _("k"): |
|
1583 | if r == _("k"): | |
1581 | get[f] = n |
|
1584 | get[f] = n | |
1582 | elif f not in ma: |
|
1585 | elif f not in ma: | |
1583 | self.ui.debug(_("remote created %s\n") % f) |
|
1586 | self.ui.debug(_("remote created %s\n") % f) | |
1584 | get[f] = n |
|
1587 | get[f] = n | |
1585 | else: |
|
1588 | else: | |
1586 | if force or p2 == pa: # going backwards? |
|
1589 | if force or p2 == pa: # going backwards? | |
1587 | self.ui.debug(_("local deleted %s, recreating\n") % f) |
|
1590 | self.ui.debug(_("local deleted %s, recreating\n") % f) | |
1588 | get[f] = n |
|
1591 | get[f] = n | |
1589 | else: |
|
1592 | else: | |
1590 | self.ui.debug(_("local deleted %s\n") % f) |
|
1593 | self.ui.debug(_("local deleted %s\n") % f) | |
1591 |
|
1594 | |||
1592 | del mw, m1, m2, ma |
|
1595 | del mw, m1, m2, ma | |
1593 |
|
1596 | |||
1594 | if force: |
|
1597 | if force: | |
1595 | for f in merge: |
|
1598 | for f in merge: | |
1596 | get[f] = merge[f][1] |
|
1599 | get[f] = merge[f][1] | |
1597 | merge = {} |
|
1600 | merge = {} | |
1598 |
|
1601 | |||
1599 | if linear_path or force: |
|
1602 | if linear_path or force: | |
1600 | # we don't need to do any magic, just jump to the new rev |
|
1603 | # we don't need to do any magic, just jump to the new rev | |
1601 | branch_merge = False |
|
1604 | branch_merge = False | |
1602 | p1, p2 = p2, nullid |
|
1605 | p1, p2 = p2, nullid | |
1603 | else: |
|
1606 | else: | |
1604 | if not allow: |
|
1607 | if not allow: | |
1605 | self.ui.status(_("this update spans a branch" |
|
1608 | self.ui.status(_("this update spans a branch" | |
1606 | " affecting the following files:\n")) |
|
1609 | " affecting the following files:\n")) | |
1607 | fl = merge.keys() + get.keys() |
|
1610 | fl = merge.keys() + get.keys() | |
1608 | fl.sort() |
|
1611 | fl.sort() | |
1609 | for f in fl: |
|
1612 | for f in fl: | |
1610 | cf = "" |
|
1613 | cf = "" | |
1611 | if f in merge: |
|
1614 | if f in merge: | |
1612 | cf = _(" (resolve)") |
|
1615 | cf = _(" (resolve)") | |
1613 | self.ui.status(" %s%s\n" % (f, cf)) |
|
1616 | self.ui.status(" %s%s\n" % (f, cf)) | |
1614 | self.ui.warn(_("aborting update spanning branches!\n")) |
|
1617 | self.ui.warn(_("aborting update spanning branches!\n")) | |
1615 | self.ui.status(_("(use update -m to merge across branches" |
|
1618 | self.ui.status(_("(use update -m to merge across branches" | |
1616 | " or -C to lose changes)\n")) |
|
1619 | " or -C to lose changes)\n")) | |
1617 | return 1 |
|
1620 | return 1 | |
1618 | branch_merge = True |
|
1621 | branch_merge = True | |
1619 |
|
1622 | |||
1620 | # get the files we don't need to change |
|
1623 | # get the files we don't need to change | |
1621 | files = get.keys() |
|
1624 | files = get.keys() | |
1622 | files.sort() |
|
1625 | files.sort() | |
1623 | for f in files: |
|
1626 | for f in files: | |
1624 | if f[0] == "/": |
|
1627 | if f[0] == "/": | |
1625 | continue |
|
1628 | continue | |
1626 | self.ui.note(_("getting %s\n") % f) |
|
1629 | self.ui.note(_("getting %s\n") % f) | |
1627 | t = self.file(f).read(get[f]) |
|
1630 | t = self.file(f).read(get[f]) | |
1628 | self.wwrite(f, t) |
|
1631 | self.wwrite(f, t) | |
1629 | util.set_exec(self.wjoin(f), mf2[f]) |
|
1632 | util.set_exec(self.wjoin(f), mf2[f]) | |
1630 | if moddirstate: |
|
1633 | if moddirstate: | |
1631 | if branch_merge: |
|
1634 | if branch_merge: | |
1632 | self.dirstate.update([f], 'n', st_mtime=-1) |
|
1635 | self.dirstate.update([f], 'n', st_mtime=-1) | |
1633 | else: |
|
1636 | else: | |
1634 | self.dirstate.update([f], 'n') |
|
1637 | self.dirstate.update([f], 'n') | |
1635 |
|
1638 | |||
1636 | # merge the tricky bits |
|
1639 | # merge the tricky bits | |
1637 | failedmerge = [] |
|
1640 | failedmerge = [] | |
1638 | files = merge.keys() |
|
1641 | files = merge.keys() | |
1639 | files.sort() |
|
1642 | files.sort() | |
1640 | xp1 = hex(p1) |
|
1643 | xp1 = hex(p1) | |
1641 | xp2 = hex(p2) |
|
1644 | xp2 = hex(p2) | |
1642 | for f in files: |
|
1645 | for f in files: | |
1643 | self.ui.status(_("merging %s\n") % f) |
|
1646 | self.ui.status(_("merging %s\n") % f) | |
1644 | my, other, flag = merge[f] |
|
1647 | my, other, flag = merge[f] | |
1645 | ret = self.merge3(f, my, other, xp1, xp2) |
|
1648 | ret = self.merge3(f, my, other, xp1, xp2) | |
1646 | if ret: |
|
1649 | if ret: | |
1647 | err = True |
|
1650 | err = True | |
1648 | failedmerge.append(f) |
|
1651 | failedmerge.append(f) | |
1649 | util.set_exec(self.wjoin(f), flag) |
|
1652 | util.set_exec(self.wjoin(f), flag) | |
1650 | if moddirstate: |
|
1653 | if moddirstate: | |
1651 | if branch_merge: |
|
1654 | if branch_merge: | |
1652 | # We've done a branch merge, mark this file as merged |
|
1655 | # We've done a branch merge, mark this file as merged | |
1653 | # so that we properly record the merger later |
|
1656 | # so that we properly record the merger later | |
1654 | self.dirstate.update([f], 'm') |
|
1657 | self.dirstate.update([f], 'm') | |
1655 | else: |
|
1658 | else: | |
1656 | # We've update-merged a locally modified file, so |
|
1659 | # We've update-merged a locally modified file, so | |
1657 | # we set the dirstate to emulate a normal checkout |
|
1660 | # we set the dirstate to emulate a normal checkout | |
1658 | # of that file some time in the past. Thus our |
|
1661 | # of that file some time in the past. Thus our | |
1659 | # merge will appear as a normal local file |
|
1662 | # merge will appear as a normal local file | |
1660 | # modification. |
|
1663 | # modification. | |
1661 | f_len = len(self.file(f).read(other)) |
|
1664 | f_len = len(self.file(f).read(other)) | |
1662 | self.dirstate.update([f], 'n', st_size=f_len, st_mtime=-1) |
|
1665 | self.dirstate.update([f], 'n', st_size=f_len, st_mtime=-1) | |
1663 |
|
1666 | |||
1664 | remove.sort() |
|
1667 | remove.sort() | |
1665 | for f in remove: |
|
1668 | for f in remove: | |
1666 | self.ui.note(_("removing %s\n") % f) |
|
1669 | self.ui.note(_("removing %s\n") % f) | |
1667 | util.audit_path(f) |
|
1670 | util.audit_path(f) | |
1668 | try: |
|
1671 | try: | |
1669 | util.unlink(self.wjoin(f)) |
|
1672 | util.unlink(self.wjoin(f)) | |
1670 | except OSError, inst: |
|
1673 | except OSError, inst: | |
1671 | if inst.errno != errno.ENOENT: |
|
1674 | if inst.errno != errno.ENOENT: | |
1672 | self.ui.warn(_("update failed to remove %s: %s!\n") % |
|
1675 | self.ui.warn(_("update failed to remove %s: %s!\n") % | |
1673 | (f, inst.strerror)) |
|
1676 | (f, inst.strerror)) | |
1674 | if moddirstate: |
|
1677 | if moddirstate: | |
1675 | if branch_merge: |
|
1678 | if branch_merge: | |
1676 | self.dirstate.update(remove, 'r') |
|
1679 | self.dirstate.update(remove, 'r') | |
1677 | else: |
|
1680 | else: | |
1678 | self.dirstate.forget(remove) |
|
1681 | self.dirstate.forget(remove) | |
1679 |
|
1682 | |||
1680 | if moddirstate: |
|
1683 | if moddirstate: | |
1681 | self.dirstate.setparents(p1, p2) |
|
1684 | self.dirstate.setparents(p1, p2) | |
1682 |
|
1685 | |||
1683 | stat = ((len(get), _("updated")), |
|
1686 | stat = ((len(get), _("updated")), | |
1684 | (len(merge) - len(failedmerge), _("merged")), |
|
1687 | (len(merge) - len(failedmerge), _("merged")), | |
1685 | (len(remove), _("removed")), |
|
1688 | (len(remove), _("removed")), | |
1686 | (len(failedmerge), _("unresolved"))) |
|
1689 | (len(failedmerge), _("unresolved"))) | |
1687 | note = ", ".join([_("%d files %s") % s for s in stat]) |
|
1690 | note = ", ".join([_("%d files %s") % s for s in stat]) | |
1688 | self.ui.note("%s\n" % note) |
|
1691 | self.ui.note("%s\n" % note) | |
1689 | if moddirstate and branch_merge: |
|
1692 | if moddirstate and branch_merge: | |
1690 | self.ui.note(_("(branch merge, don't forget to commit)\n")) |
|
1693 | self.ui.note(_("(branch merge, don't forget to commit)\n")) | |
1691 |
|
1694 | |||
1692 | return err |
|
1695 | return err | |
1693 |
|
1696 | |||
1694 | def merge3(self, fn, my, other, p1, p2): |
|
1697 | def merge3(self, fn, my, other, p1, p2): | |
1695 | """perform a 3-way merge in the working directory""" |
|
1698 | """perform a 3-way merge in the working directory""" | |
1696 |
|
1699 | |||
1697 | def temp(prefix, node): |
|
1700 | def temp(prefix, node): | |
1698 | pre = "%s~%s." % (os.path.basename(fn), prefix) |
|
1701 | pre = "%s~%s." % (os.path.basename(fn), prefix) | |
1699 | (fd, name) = tempfile.mkstemp("", pre) |
|
1702 | (fd, name) = tempfile.mkstemp("", pre) | |
1700 | f = os.fdopen(fd, "wb") |
|
1703 | f = os.fdopen(fd, "wb") | |
1701 | self.wwrite(fn, fl.read(node), f) |
|
1704 | self.wwrite(fn, fl.read(node), f) | |
1702 | f.close() |
|
1705 | f.close() | |
1703 | return name |
|
1706 | return name | |
1704 |
|
1707 | |||
1705 | fl = self.file(fn) |
|
1708 | fl = self.file(fn) | |
1706 | base = fl.ancestor(my, other) |
|
1709 | base = fl.ancestor(my, other) | |
1707 | a = self.wjoin(fn) |
|
1710 | a = self.wjoin(fn) | |
1708 | b = temp("base", base) |
|
1711 | b = temp("base", base) | |
1709 | c = temp("other", other) |
|
1712 | c = temp("other", other) | |
1710 |
|
1713 | |||
1711 | self.ui.note(_("resolving %s\n") % fn) |
|
1714 | self.ui.note(_("resolving %s\n") % fn) | |
1712 | self.ui.debug(_("file %s: my %s other %s ancestor %s\n") % |
|
1715 | self.ui.debug(_("file %s: my %s other %s ancestor %s\n") % | |
1713 | (fn, short(my), short(other), short(base))) |
|
1716 | (fn, short(my), short(other), short(base))) | |
1714 |
|
1717 | |||
1715 | cmd = (os.environ.get("HGMERGE") or self.ui.config("ui", "merge") |
|
1718 | cmd = (os.environ.get("HGMERGE") or self.ui.config("ui", "merge") | |
1716 | or "hgmerge") |
|
1719 | or "hgmerge") | |
1717 | r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=self.root, |
|
1720 | r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=self.root, | |
1718 | environ={'HG_FILE': fn, |
|
1721 | environ={'HG_FILE': fn, | |
1719 | 'HG_MY_NODE': p1, |
|
1722 | 'HG_MY_NODE': p1, | |
1720 | 'HG_OTHER_NODE': p2, |
|
1723 | 'HG_OTHER_NODE': p2, | |
1721 | 'HG_FILE_MY_NODE': hex(my), |
|
1724 | 'HG_FILE_MY_NODE': hex(my), | |
1722 | 'HG_FILE_OTHER_NODE': hex(other), |
|
1725 | 'HG_FILE_OTHER_NODE': hex(other), | |
1723 | 'HG_FILE_BASE_NODE': hex(base)}) |
|
1726 | 'HG_FILE_BASE_NODE': hex(base)}) | |
1724 | if r: |
|
1727 | if r: | |
1725 | self.ui.warn(_("merging %s failed!\n") % fn) |
|
1728 | self.ui.warn(_("merging %s failed!\n") % fn) | |
1726 |
|
1729 | |||
1727 | os.unlink(b) |
|
1730 | os.unlink(b) | |
1728 | os.unlink(c) |
|
1731 | os.unlink(c) | |
1729 | return r |
|
1732 | return r | |
1730 |
|
1733 | |||
1731 | def verify(self): |
|
1734 | def verify(self): | |
1732 | filelinkrevs = {} |
|
1735 | filelinkrevs = {} | |
1733 | filenodes = {} |
|
1736 | filenodes = {} | |
1734 | changesets = revisions = files = 0 |
|
1737 | changesets = revisions = files = 0 | |
1735 | errors = [0] |
|
1738 | errors = [0] | |
1736 | neededmanifests = {} |
|
1739 | neededmanifests = {} | |
1737 |
|
1740 | |||
1738 | def err(msg): |
|
1741 | def err(msg): | |
1739 | self.ui.warn(msg + "\n") |
|
1742 | self.ui.warn(msg + "\n") | |
1740 | errors[0] += 1 |
|
1743 | errors[0] += 1 | |
1741 |
|
1744 | |||
1742 | def checksize(obj, name): |
|
1745 | def checksize(obj, name): | |
1743 | d = obj.checksize() |
|
1746 | d = obj.checksize() | |
1744 | if d[0]: |
|
1747 | if d[0]: | |
1745 | err(_("%s data length off by %d bytes") % (name, d[0])) |
|
1748 | err(_("%s data length off by %d bytes") % (name, d[0])) | |
1746 | if d[1]: |
|
1749 | if d[1]: | |
1747 | err(_("%s index contains %d extra bytes") % (name, d[1])) |
|
1750 | err(_("%s index contains %d extra bytes") % (name, d[1])) | |
1748 |
|
1751 | |||
1749 | seen = {} |
|
1752 | seen = {} | |
1750 | self.ui.status(_("checking changesets\n")) |
|
1753 | self.ui.status(_("checking changesets\n")) | |
1751 | checksize(self.changelog, "changelog") |
|
1754 | checksize(self.changelog, "changelog") | |
1752 |
|
1755 | |||
1753 | for i in range(self.changelog.count()): |
|
1756 | for i in range(self.changelog.count()): | |
1754 | changesets += 1 |
|
1757 | changesets += 1 | |
1755 | n = self.changelog.node(i) |
|
1758 | n = self.changelog.node(i) | |
1756 | l = self.changelog.linkrev(n) |
|
1759 | l = self.changelog.linkrev(n) | |
1757 | if l != i: |
|
1760 | if l != i: | |
1758 | err(_("incorrect link (%d) for changeset revision %d") %(l, i)) |
|
1761 | err(_("incorrect link (%d) for changeset revision %d") %(l, i)) | |
1759 | if n in seen: |
|
1762 | if n in seen: | |
1760 | err(_("duplicate changeset at revision %d") % i) |
|
1763 | err(_("duplicate changeset at revision %d") % i) | |
1761 | seen[n] = 1 |
|
1764 | seen[n] = 1 | |
1762 |
|
1765 | |||
1763 | for p in self.changelog.parents(n): |
|
1766 | for p in self.changelog.parents(n): | |
1764 | if p not in self.changelog.nodemap: |
|
1767 | if p not in self.changelog.nodemap: | |
1765 | err(_("changeset %s has unknown parent %s") % |
|
1768 | err(_("changeset %s has unknown parent %s") % | |
1766 | (short(n), short(p))) |
|
1769 | (short(n), short(p))) | |
1767 | try: |
|
1770 | try: | |
1768 | changes = self.changelog.read(n) |
|
1771 | changes = self.changelog.read(n) | |
1769 | except KeyboardInterrupt: |
|
1772 | except KeyboardInterrupt: | |
1770 | self.ui.warn(_("interrupted")) |
|
1773 | self.ui.warn(_("interrupted")) | |
1771 | raise |
|
1774 | raise | |
1772 | except Exception, inst: |
|
1775 | except Exception, inst: | |
1773 | err(_("unpacking changeset %s: %s") % (short(n), inst)) |
|
1776 | err(_("unpacking changeset %s: %s") % (short(n), inst)) | |
1774 | continue |
|
1777 | continue | |
1775 |
|
1778 | |||
1776 | neededmanifests[changes[0]] = n |
|
1779 | neededmanifests[changes[0]] = n | |
1777 |
|
1780 | |||
1778 | for f in changes[3]: |
|
1781 | for f in changes[3]: | |
1779 | filelinkrevs.setdefault(f, []).append(i) |
|
1782 | filelinkrevs.setdefault(f, []).append(i) | |
1780 |
|
1783 | |||
1781 | seen = {} |
|
1784 | seen = {} | |
1782 | self.ui.status(_("checking manifests\n")) |
|
1785 | self.ui.status(_("checking manifests\n")) | |
1783 | checksize(self.manifest, "manifest") |
|
1786 | checksize(self.manifest, "manifest") | |
1784 |
|
1787 | |||
1785 | for i in range(self.manifest.count()): |
|
1788 | for i in range(self.manifest.count()): | |
1786 | n = self.manifest.node(i) |
|
1789 | n = self.manifest.node(i) | |
1787 | l = self.manifest.linkrev(n) |
|
1790 | l = self.manifest.linkrev(n) | |
1788 |
|
1791 | |||
1789 | if l < 0 or l >= self.changelog.count(): |
|
1792 | if l < 0 or l >= self.changelog.count(): | |
1790 | err(_("bad manifest link (%d) at revision %d") % (l, i)) |
|
1793 | err(_("bad manifest link (%d) at revision %d") % (l, i)) | |
1791 |
|
1794 | |||
1792 | if n in neededmanifests: |
|
1795 | if n in neededmanifests: | |
1793 | del neededmanifests[n] |
|
1796 | del neededmanifests[n] | |
1794 |
|
1797 | |||
1795 | if n in seen: |
|
1798 | if n in seen: | |
1796 | err(_("duplicate manifest at revision %d") % i) |
|
1799 | err(_("duplicate manifest at revision %d") % i) | |
1797 |
|
1800 | |||
1798 | seen[n] = 1 |
|
1801 | seen[n] = 1 | |
1799 |
|
1802 | |||
1800 | for p in self.manifest.parents(n): |
|
1803 | for p in self.manifest.parents(n): | |
1801 | if p not in self.manifest.nodemap: |
|
1804 | if p not in self.manifest.nodemap: | |
1802 | err(_("manifest %s has unknown parent %s") % |
|
1805 | err(_("manifest %s has unknown parent %s") % | |
1803 | (short(n), short(p))) |
|
1806 | (short(n), short(p))) | |
1804 |
|
1807 | |||
1805 | try: |
|
1808 | try: | |
1806 | delta = mdiff.patchtext(self.manifest.delta(n)) |
|
1809 | delta = mdiff.patchtext(self.manifest.delta(n)) | |
1807 | except KeyboardInterrupt: |
|
1810 | except KeyboardInterrupt: | |
1808 | self.ui.warn(_("interrupted")) |
|
1811 | self.ui.warn(_("interrupted")) | |
1809 | raise |
|
1812 | raise | |
1810 | except Exception, inst: |
|
1813 | except Exception, inst: | |
1811 | err(_("unpacking manifest %s: %s") % (short(n), inst)) |
|
1814 | err(_("unpacking manifest %s: %s") % (short(n), inst)) | |
1812 | continue |
|
1815 | continue | |
1813 |
|
1816 | |||
1814 | try: |
|
1817 | try: | |
1815 | ff = [ l.split('\0') for l in delta.splitlines() ] |
|
1818 | ff = [ l.split('\0') for l in delta.splitlines() ] | |
1816 | for f, fn in ff: |
|
1819 | for f, fn in ff: | |
1817 | filenodes.setdefault(f, {})[bin(fn[:40])] = 1 |
|
1820 | filenodes.setdefault(f, {})[bin(fn[:40])] = 1 | |
1818 | except (ValueError, TypeError), inst: |
|
1821 | except (ValueError, TypeError), inst: | |
1819 | err(_("broken delta in manifest %s: %s") % (short(n), inst)) |
|
1822 | err(_("broken delta in manifest %s: %s") % (short(n), inst)) | |
1820 |
|
1823 | |||
1821 | self.ui.status(_("crosschecking files in changesets and manifests\n")) |
|
1824 | self.ui.status(_("crosschecking files in changesets and manifests\n")) | |
1822 |
|
1825 | |||
1823 | for m, c in neededmanifests.items(): |
|
1826 | for m, c in neededmanifests.items(): | |
1824 | err(_("Changeset %s refers to unknown manifest %s") % |
|
1827 | err(_("Changeset %s refers to unknown manifest %s") % | |
1825 | (short(m), short(c))) |
|
1828 | (short(m), short(c))) | |
1826 | del neededmanifests |
|
1829 | del neededmanifests | |
1827 |
|
1830 | |||
1828 | for f in filenodes: |
|
1831 | for f in filenodes: | |
1829 | if f not in filelinkrevs: |
|
1832 | if f not in filelinkrevs: | |
1830 | err(_("file %s in manifest but not in changesets") % f) |
|
1833 | err(_("file %s in manifest but not in changesets") % f) | |
1831 |
|
1834 | |||
1832 | for f in filelinkrevs: |
|
1835 | for f in filelinkrevs: | |
1833 | if f not in filenodes: |
|
1836 | if f not in filenodes: | |
1834 | err(_("file %s in changeset but not in manifest") % f) |
|
1837 | err(_("file %s in changeset but not in manifest") % f) | |
1835 |
|
1838 | |||
1836 | self.ui.status(_("checking files\n")) |
|
1839 | self.ui.status(_("checking files\n")) | |
1837 | ff = filenodes.keys() |
|
1840 | ff = filenodes.keys() | |
1838 | ff.sort() |
|
1841 | ff.sort() | |
1839 | for f in ff: |
|
1842 | for f in ff: | |
1840 | if f == "/dev/null": |
|
1843 | if f == "/dev/null": | |
1841 | continue |
|
1844 | continue | |
1842 | files += 1 |
|
1845 | files += 1 | |
1843 | if not f: |
|
1846 | if not f: | |
1844 | err(_("file without name in manifest %s") % short(n)) |
|
1847 | err(_("file without name in manifest %s") % short(n)) | |
1845 | continue |
|
1848 | continue | |
1846 | fl = self.file(f) |
|
1849 | fl = self.file(f) | |
1847 | checksize(fl, f) |
|
1850 | checksize(fl, f) | |
1848 |
|
1851 | |||
1849 | nodes = {nullid: 1} |
|
1852 | nodes = {nullid: 1} | |
1850 | seen = {} |
|
1853 | seen = {} | |
1851 | for i in range(fl.count()): |
|
1854 | for i in range(fl.count()): | |
1852 | revisions += 1 |
|
1855 | revisions += 1 | |
1853 | n = fl.node(i) |
|
1856 | n = fl.node(i) | |
1854 |
|
1857 | |||
1855 | if n in seen: |
|
1858 | if n in seen: | |
1856 | err(_("%s: duplicate revision %d") % (f, i)) |
|
1859 | err(_("%s: duplicate revision %d") % (f, i)) | |
1857 | if n not in filenodes[f]: |
|
1860 | if n not in filenodes[f]: | |
1858 | err(_("%s: %d:%s not in manifests") % (f, i, short(n))) |
|
1861 | err(_("%s: %d:%s not in manifests") % (f, i, short(n))) | |
1859 | else: |
|
1862 | else: | |
1860 | del filenodes[f][n] |
|
1863 | del filenodes[f][n] | |
1861 |
|
1864 | |||
1862 | flr = fl.linkrev(n) |
|
1865 | flr = fl.linkrev(n) | |
1863 | if flr not in filelinkrevs.get(f, []): |
|
1866 | if flr not in filelinkrevs.get(f, []): | |
1864 | err(_("%s:%s points to unexpected changeset %d") |
|
1867 | err(_("%s:%s points to unexpected changeset %d") | |
1865 | % (f, short(n), flr)) |
|
1868 | % (f, short(n), flr)) | |
1866 | else: |
|
1869 | else: | |
1867 | filelinkrevs[f].remove(flr) |
|
1870 | filelinkrevs[f].remove(flr) | |
1868 |
|
1871 | |||
1869 | # verify contents |
|
1872 | # verify contents | |
1870 | try: |
|
1873 | try: | |
1871 | t = fl.read(n) |
|
1874 | t = fl.read(n) | |
1872 | except KeyboardInterrupt: |
|
1875 | except KeyboardInterrupt: | |
1873 | self.ui.warn(_("interrupted")) |
|
1876 | self.ui.warn(_("interrupted")) | |
1874 | raise |
|
1877 | raise | |
1875 | except Exception, inst: |
|
1878 | except Exception, inst: | |
1876 | err(_("unpacking file %s %s: %s") % (f, short(n), inst)) |
|
1879 | err(_("unpacking file %s %s: %s") % (f, short(n), inst)) | |
1877 |
|
1880 | |||
1878 | # verify parents |
|
1881 | # verify parents | |
1879 | (p1, p2) = fl.parents(n) |
|
1882 | (p1, p2) = fl.parents(n) | |
1880 | if p1 not in nodes: |
|
1883 | if p1 not in nodes: | |
1881 | err(_("file %s:%s unknown parent 1 %s") % |
|
1884 | err(_("file %s:%s unknown parent 1 %s") % | |
1882 | (f, short(n), short(p1))) |
|
1885 | (f, short(n), short(p1))) | |
1883 | if p2 not in nodes: |
|
1886 | if p2 not in nodes: | |
1884 | err(_("file %s:%s unknown parent 2 %s") % |
|
1887 | err(_("file %s:%s unknown parent 2 %s") % | |
1885 | (f, short(n), short(p1))) |
|
1888 | (f, short(n), short(p1))) | |
1886 | nodes[n] = 1 |
|
1889 | nodes[n] = 1 | |
1887 |
|
1890 | |||
1888 | # cross-check |
|
1891 | # cross-check | |
1889 | for node in filenodes[f]: |
|
1892 | for node in filenodes[f]: | |
1890 | err(_("node %s in manifests not in %s") % (hex(node), f)) |
|
1893 | err(_("node %s in manifests not in %s") % (hex(node), f)) | |
1891 |
|
1894 | |||
1892 | self.ui.status(_("%d files, %d changesets, %d total revisions\n") % |
|
1895 | self.ui.status(_("%d files, %d changesets, %d total revisions\n") % | |
1893 | (files, changesets, revisions)) |
|
1896 | (files, changesets, revisions)) | |
1894 |
|
1897 | |||
1895 | if errors[0]: |
|
1898 | if errors[0]: | |
1896 | self.ui.warn(_("%d integrity errors encountered!\n") % errors[0]) |
|
1899 | self.ui.warn(_("%d integrity errors encountered!\n") % errors[0]) | |
1897 | return 1 |
|
1900 | return 1 | |
1898 |
|
1901 | |||
1899 | # used to avoid circular references so destructors work |
|
1902 | # used to avoid circular references so destructors work | |
1900 | def aftertrans(base): |
|
1903 | def aftertrans(base): | |
1901 | p = base |
|
1904 | p = base | |
1902 | def a(): |
|
1905 | def a(): | |
1903 | util.rename(os.path.join(p, "journal"), os.path.join(p, "undo")) |
|
1906 | util.rename(os.path.join(p, "journal"), os.path.join(p, "undo")) | |
1904 | util.rename(os.path.join(p, "journal.dirstate"), |
|
1907 | util.rename(os.path.join(p, "journal.dirstate"), | |
1905 | os.path.join(p, "undo.dirstate")) |
|
1908 | os.path.join(p, "undo.dirstate")) | |
1906 | return a |
|
1909 | return a | |
1907 |
|
1910 |
General Comments 0
You need to be logged in to leave comments.
Login now