Show More
@@ -1,11 +1,12 b'' | |||||
1 | d40cc5aacc31ed673d9b5b24f98bee78c283062c 0.4f |
|
1 | d40cc5aacc31ed673d9b5b24f98bee78c283062c 0.4f | |
2 | 1c590d34bf61e2ea12c71738e5a746cd74586157 0.4e |
|
2 | 1c590d34bf61e2ea12c71738e5a746cd74586157 0.4e | |
3 | 7eca4cfa8aad5fce9a04f7d8acadcd0452e2f34e 0.4d |
|
3 | 7eca4cfa8aad5fce9a04f7d8acadcd0452e2f34e 0.4d | |
4 | b4d0c3786ad3e47beacf8412157326a32b6d25a4 0.4c |
|
4 | b4d0c3786ad3e47beacf8412157326a32b6d25a4 0.4c | |
5 | f40273b0ad7b3a6d3012fd37736d0611f41ecf54 0.5 |
|
5 | f40273b0ad7b3a6d3012fd37736d0611f41ecf54 0.5 | |
6 | 0a28dfe59f8fab54a5118c5be4f40da34a53cdb7 0.5b |
|
6 | 0a28dfe59f8fab54a5118c5be4f40da34a53cdb7 0.5b | |
7 | 12e0fdbc57a0be78f0e817fd1d170a3615cd35da 0.6 |
|
7 | 12e0fdbc57a0be78f0e817fd1d170a3615cd35da 0.6 | |
8 | 4ccf3de52989b14c3d84e1097f59e39a992e00bd 0.6b |
|
8 | 4ccf3de52989b14c3d84e1097f59e39a992e00bd 0.6b | |
9 | eac9c8efcd9bd8244e72fb6821f769f450457a32 0.6c |
|
9 | eac9c8efcd9bd8244e72fb6821f769f450457a32 0.6c | |
10 | 979c049974485125e1f9357f6bbe9c1b548a64c3 0.7 |
|
10 | 979c049974485125e1f9357f6bbe9c1b548a64c3 0.7 | |
11 | 3a56574f329a368d645853e0f9e09472aee62349 0.8 |
|
11 | 3a56574f329a368d645853e0f9e09472aee62349 0.8 | |
|
12 | 6a03cff2b0f5d30281e6addefe96b993582f2eac 0.8.1 |
@@ -1,1306 +1,1307 b'' | |||||
1 | # queue.py - patch queues for mercurial |
|
1 | # queue.py - patch queues for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 Chris Mason <mason@suse.com> |
|
3 | # Copyright 2005 Chris Mason <mason@suse.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | from mercurial.demandload import * |
|
8 | from mercurial.demandload import * | |
9 | demandload(globals(), "os sys re struct traceback errno bz2") |
|
9 | demandload(globals(), "os sys re struct traceback errno bz2") | |
10 | from mercurial.i18n import gettext as _ |
|
10 | from mercurial.i18n import gettext as _ | |
11 | from mercurial import ui, hg, revlog, commands, util |
|
11 | from mercurial import ui, hg, revlog, commands, util | |
12 |
|
12 | |||
13 | versionstr = "0.45" |
|
13 | versionstr = "0.45" | |
14 |
|
14 | |||
15 | repomap = {} |
|
15 | repomap = {} | |
16 |
|
16 | |||
|
17 | commands.norepo += " qversion" | |||
17 | class queue: |
|
18 | class queue: | |
18 | def __init__(self, ui, path, patchdir=None): |
|
19 | def __init__(self, ui, path, patchdir=None): | |
19 | self.basepath = path |
|
20 | self.basepath = path | |
20 | if patchdir: |
|
21 | if patchdir: | |
21 | self.path = patchdir |
|
22 | self.path = patchdir | |
22 | else: |
|
23 | else: | |
23 | self.path = os.path.join(path, "patches") |
|
24 | self.path = os.path.join(path, "patches") | |
24 | self.opener = util.opener(self.path) |
|
25 | self.opener = util.opener(self.path) | |
25 | self.ui = ui |
|
26 | self.ui = ui | |
26 | self.applied = [] |
|
27 | self.applied = [] | |
27 | self.full_series = [] |
|
28 | self.full_series = [] | |
28 | self.applied_dirty = 0 |
|
29 | self.applied_dirty = 0 | |
29 | self.series_dirty = 0 |
|
30 | self.series_dirty = 0 | |
30 | self.series_path = "series" |
|
31 | self.series_path = "series" | |
31 | self.status_path = "status" |
|
32 | self.status_path = "status" | |
32 |
|
33 | |||
33 | if os.path.exists(os.path.join(self.path, self.series_path)): |
|
34 | if os.path.exists(os.path.join(self.path, self.series_path)): | |
34 | self.full_series = self.opener(self.series_path).read().splitlines() |
|
35 | self.full_series = self.opener(self.series_path).read().splitlines() | |
35 | self.read_series(self.full_series) |
|
36 | self.read_series(self.full_series) | |
36 |
|
37 | |||
37 | if os.path.exists(os.path.join(self.path, self.status_path)): |
|
38 | if os.path.exists(os.path.join(self.path, self.status_path)): | |
38 | self.applied = self.opener(self.status_path).read().splitlines() |
|
39 | self.applied = self.opener(self.status_path).read().splitlines() | |
39 |
|
40 | |||
40 | def find_series(self, patch): |
|
41 | def find_series(self, patch): | |
41 | pre = re.compile("(\s*)([^#]+)") |
|
42 | pre = re.compile("(\s*)([^#]+)") | |
42 | index = 0 |
|
43 | index = 0 | |
43 | for l in self.full_series: |
|
44 | for l in self.full_series: | |
44 | m = pre.match(l) |
|
45 | m = pre.match(l) | |
45 | if m: |
|
46 | if m: | |
46 | s = m.group(2) |
|
47 | s = m.group(2) | |
47 | s = s.rstrip() |
|
48 | s = s.rstrip() | |
48 | if s == patch: |
|
49 | if s == patch: | |
49 | return index |
|
50 | return index | |
50 | index += 1 |
|
51 | index += 1 | |
51 | return None |
|
52 | return None | |
52 |
|
53 | |||
53 | def read_series(self, list): |
|
54 | def read_series(self, list): | |
54 | def matcher(list): |
|
55 | def matcher(list): | |
55 | pre = re.compile("(\s*)([^#]+)") |
|
56 | pre = re.compile("(\s*)([^#]+)") | |
56 | for l in list: |
|
57 | for l in list: | |
57 | m = pre.match(l) |
|
58 | m = pre.match(l) | |
58 | if m: |
|
59 | if m: | |
59 | s = m.group(2) |
|
60 | s = m.group(2) | |
60 | s = s.rstrip() |
|
61 | s = s.rstrip() | |
61 | if len(s) > 0: |
|
62 | if len(s) > 0: | |
62 | yield s |
|
63 | yield s | |
63 | self.series = [] |
|
64 | self.series = [] | |
64 | self.series = [ x for x in matcher(list) ] |
|
65 | self.series = [ x for x in matcher(list) ] | |
65 |
|
66 | |||
66 | def save_dirty(self): |
|
67 | def save_dirty(self): | |
67 | if self.applied_dirty: |
|
68 | if self.applied_dirty: | |
68 | if len(self.applied) > 0: |
|
69 | if len(self.applied) > 0: | |
69 | nl = "\n" |
|
70 | nl = "\n" | |
70 | else: |
|
71 | else: | |
71 | nl = "" |
|
72 | nl = "" | |
72 | f = self.opener(self.status_path, "w") |
|
73 | f = self.opener(self.status_path, "w") | |
73 | f.write("\n".join(self.applied) + nl) |
|
74 | f.write("\n".join(self.applied) + nl) | |
74 | if self.series_dirty: |
|
75 | if self.series_dirty: | |
75 | if len(self.full_series) > 0: |
|
76 | if len(self.full_series) > 0: | |
76 | nl = "\n" |
|
77 | nl = "\n" | |
77 | else: |
|
78 | else: | |
78 | nl = "" |
|
79 | nl = "" | |
79 | f = self.opener(self.series_path, "w") |
|
80 | f = self.opener(self.series_path, "w") | |
80 | f.write("\n".join(self.full_series) + nl) |
|
81 | f.write("\n".join(self.full_series) + nl) | |
81 |
|
82 | |||
82 | def readheaders(self, patch): |
|
83 | def readheaders(self, patch): | |
83 | def eatdiff(lines): |
|
84 | def eatdiff(lines): | |
84 | while lines: |
|
85 | while lines: | |
85 | l = lines[-1] |
|
86 | l = lines[-1] | |
86 | if (l.startswith("diff -") or |
|
87 | if (l.startswith("diff -") or | |
87 | l.startswith("Index:") or |
|
88 | l.startswith("Index:") or | |
88 | l.startswith("===========")): |
|
89 | l.startswith("===========")): | |
89 | del lines[-1] |
|
90 | del lines[-1] | |
90 | else: |
|
91 | else: | |
91 | break |
|
92 | break | |
92 | def eatempty(lines): |
|
93 | def eatempty(lines): | |
93 | while lines: |
|
94 | while lines: | |
94 | l = lines[-1] |
|
95 | l = lines[-1] | |
95 | if re.match('\s*$', l): |
|
96 | if re.match('\s*$', l): | |
96 | del lines[-1] |
|
97 | del lines[-1] | |
97 | else: |
|
98 | else: | |
98 | break |
|
99 | break | |
99 |
|
100 | |||
100 | pf = os.path.join(self.path, patch) |
|
101 | pf = os.path.join(self.path, patch) | |
101 | message = [] |
|
102 | message = [] | |
102 | comments = [] |
|
103 | comments = [] | |
103 | user = None |
|
104 | user = None | |
104 | format = None |
|
105 | format = None | |
105 | subject = None |
|
106 | subject = None | |
106 | diffstart = 0 |
|
107 | diffstart = 0 | |
107 |
|
108 | |||
108 | for line in file(pf): |
|
109 | for line in file(pf): | |
109 | line = line.rstrip() |
|
110 | line = line.rstrip() | |
110 | if diffstart: |
|
111 | if diffstart: | |
111 | if line.startswith('+++ '): |
|
112 | if line.startswith('+++ '): | |
112 | diffstart = 2 |
|
113 | diffstart = 2 | |
113 | break |
|
114 | break | |
114 | if line.startswith("--- "): |
|
115 | if line.startswith("--- "): | |
115 | diffstart = 1 |
|
116 | diffstart = 1 | |
116 | continue |
|
117 | continue | |
117 | elif format == "hgpatch": |
|
118 | elif format == "hgpatch": | |
118 | # parse values when importing the result of an hg export |
|
119 | # parse values when importing the result of an hg export | |
119 | if line.startswith("# User "): |
|
120 | if line.startswith("# User "): | |
120 | user = line[7:] |
|
121 | user = line[7:] | |
121 | elif not line.startswith("# ") and line: |
|
122 | elif not line.startswith("# ") and line: | |
122 | message.append(line) |
|
123 | message.append(line) | |
123 | format = None |
|
124 | format = None | |
124 | elif line == '# HG changeset patch': |
|
125 | elif line == '# HG changeset patch': | |
125 | format = "hgpatch" |
|
126 | format = "hgpatch" | |
126 | elif (format != "tagdone" and (line.startswith("Subject: ") or |
|
127 | elif (format != "tagdone" and (line.startswith("Subject: ") or | |
127 | line.startswith("subject: "))): |
|
128 | line.startswith("subject: "))): | |
128 | subject = line[9:] |
|
129 | subject = line[9:] | |
129 | format = "tag" |
|
130 | format = "tag" | |
130 | elif (format != "tagdone" and (line.startswith("From: ") or |
|
131 | elif (format != "tagdone" and (line.startswith("From: ") or | |
131 | line.startswith("from: "))): |
|
132 | line.startswith("from: "))): | |
132 | user = line[6:] |
|
133 | user = line[6:] | |
133 | format = "tag" |
|
134 | format = "tag" | |
134 | elif format == "tag" and line == "": |
|
135 | elif format == "tag" and line == "": | |
135 | # when looking for tags (subject: from: etc) they |
|
136 | # when looking for tags (subject: from: etc) they | |
136 | # end once you find a blank line in the source |
|
137 | # end once you find a blank line in the source | |
137 | format = "tagdone" |
|
138 | format = "tagdone" | |
138 | else: |
|
139 | else: | |
139 | message.append(line) |
|
140 | message.append(line) | |
140 | comments.append(line) |
|
141 | comments.append(line) | |
141 |
|
142 | |||
142 | eatdiff(message) |
|
143 | eatdiff(message) | |
143 | eatdiff(comments) |
|
144 | eatdiff(comments) | |
144 | eatempty(message) |
|
145 | eatempty(message) | |
145 | eatempty(comments) |
|
146 | eatempty(comments) | |
146 |
|
147 | |||
147 | # make sure message isn't empty |
|
148 | # make sure message isn't empty | |
148 | if format and format.startswith("tag") and subject: |
|
149 | if format and format.startswith("tag") and subject: | |
149 | message.insert(0, "") |
|
150 | message.insert(0, "") | |
150 | message.insert(0, subject) |
|
151 | message.insert(0, subject) | |
151 | return (message, comments, user, diffstart > 1) |
|
152 | return (message, comments, user, diffstart > 1) | |
152 |
|
153 | |||
153 | def mergeone(self, repo, mergeq, head, patch, rev, wlock): |
|
154 | def mergeone(self, repo, mergeq, head, patch, rev, wlock): | |
154 | # first try just applying the patch |
|
155 | # first try just applying the patch | |
155 | (err, n) = self.apply(repo, [ patch ], update_status=False, |
|
156 | (err, n) = self.apply(repo, [ patch ], update_status=False, | |
156 | strict=True, merge=rev, wlock=wlock) |
|
157 | strict=True, merge=rev, wlock=wlock) | |
157 |
|
158 | |||
158 | if err == 0: |
|
159 | if err == 0: | |
159 | return (err, n) |
|
160 | return (err, n) | |
160 |
|
161 | |||
161 | if n is None: |
|
162 | if n is None: | |
162 | self.ui.warn("apply failed for patch %s\n" % patch) |
|
163 | self.ui.warn("apply failed for patch %s\n" % patch) | |
163 | sys.exit(1) |
|
164 | sys.exit(1) | |
164 |
|
165 | |||
165 | self.ui.warn("patch didn't work out, merging %s\n" % patch) |
|
166 | self.ui.warn("patch didn't work out, merging %s\n" % patch) | |
166 |
|
167 | |||
167 | # apply failed, strip away that rev and merge. |
|
168 | # apply failed, strip away that rev and merge. | |
168 | repo.update(head, allow=False, force=True, wlock=wlock) |
|
169 | repo.update(head, allow=False, force=True, wlock=wlock) | |
169 | self.strip(repo, n, update=False, backup='strip', wlock=wlock) |
|
170 | self.strip(repo, n, update=False, backup='strip', wlock=wlock) | |
170 |
|
171 | |||
171 | c = repo.changelog.read(rev) |
|
172 | c = repo.changelog.read(rev) | |
172 | ret = repo.update(rev, allow=True, wlock=wlock) |
|
173 | ret = repo.update(rev, allow=True, wlock=wlock) | |
173 | if ret: |
|
174 | if ret: | |
174 | self.ui.warn("update returned %d\n" % ret) |
|
175 | self.ui.warn("update returned %d\n" % ret) | |
175 | sys.exit(1) |
|
176 | sys.exit(1) | |
176 | n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) |
|
177 | n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) | |
177 | if n == None: |
|
178 | if n == None: | |
178 | self.ui.warn("repo commit failed\n") |
|
179 | self.ui.warn("repo commit failed\n") | |
179 | sys.exit(1) |
|
180 | sys.exit(1) | |
180 | try: |
|
181 | try: | |
181 | message, comments, user, patchfound = mergeq.readheaders(patch) |
|
182 | message, comments, user, patchfound = mergeq.readheaders(patch) | |
182 | except: |
|
183 | except: | |
183 | self.ui.warn("Unable to read %s\n" % patch) |
|
184 | self.ui.warn("Unable to read %s\n" % patch) | |
184 | sys.exit(1) |
|
185 | sys.exit(1) | |
185 |
|
186 | |||
186 | patchf = self.opener(patch, "w") |
|
187 | patchf = self.opener(patch, "w") | |
187 | if comments: |
|
188 | if comments: | |
188 | comments = "\n".join(comments) + '\n\n' |
|
189 | comments = "\n".join(comments) + '\n\n' | |
189 | patchf.write(comments) |
|
190 | patchf.write(comments) | |
190 | commands.dodiff(patchf, self.ui, repo, head, n) |
|
191 | commands.dodiff(patchf, self.ui, repo, head, n) | |
191 | patchf.close() |
|
192 | patchf.close() | |
192 | return (0, n) |
|
193 | return (0, n) | |
193 |
|
194 | |||
194 | def qparents(self, repo, rev=None): |
|
195 | def qparents(self, repo, rev=None): | |
195 | if rev is None: |
|
196 | if rev is None: | |
196 | (p1, p2) = repo.dirstate.parents() |
|
197 | (p1, p2) = repo.dirstate.parents() | |
197 | if p2 == revlog.nullid: |
|
198 | if p2 == revlog.nullid: | |
198 | return p1 |
|
199 | return p1 | |
199 | if len(self.applied) == 0: |
|
200 | if len(self.applied) == 0: | |
200 | return None |
|
201 | return None | |
201 | (top, patch) = self.applied[-1].split(':') |
|
202 | (top, patch) = self.applied[-1].split(':') | |
202 | top = revlog.bin(top) |
|
203 | top = revlog.bin(top) | |
203 | return top |
|
204 | return top | |
204 | pp = repo.changelog.parents(rev) |
|
205 | pp = repo.changelog.parents(rev) | |
205 | if pp[1] != revlog.nullid: |
|
206 | if pp[1] != revlog.nullid: | |
206 | arevs = [ x.split(':')[0] for x in self.applied ] |
|
207 | arevs = [ x.split(':')[0] for x in self.applied ] | |
207 | p0 = revlog.hex(pp[0]) |
|
208 | p0 = revlog.hex(pp[0]) | |
208 | p1 = revlog.hex(pp[1]) |
|
209 | p1 = revlog.hex(pp[1]) | |
209 | if p0 in arevs: |
|
210 | if p0 in arevs: | |
210 | return pp[0] |
|
211 | return pp[0] | |
211 | if p1 in arevs: |
|
212 | if p1 in arevs: | |
212 | return pp[1] |
|
213 | return pp[1] | |
213 | return None |
|
214 | return None | |
214 | return pp[0] |
|
215 | return pp[0] | |
215 |
|
216 | |||
216 | def mergepatch(self, repo, mergeq, series, wlock): |
|
217 | def mergepatch(self, repo, mergeq, series, wlock): | |
217 | if len(self.applied) == 0: |
|
218 | if len(self.applied) == 0: | |
218 | # each of the patches merged in will have two parents. This |
|
219 | # each of the patches merged in will have two parents. This | |
219 | # can confuse the qrefresh, qdiff, and strip code because it |
|
220 | # can confuse the qrefresh, qdiff, and strip code because it | |
220 | # needs to know which parent is actually in the patch queue. |
|
221 | # needs to know which parent is actually in the patch queue. | |
221 | # so, we insert a merge marker with only one parent. This way |
|
222 | # so, we insert a merge marker with only one parent. This way | |
222 | # the first patch in the queue is never a merge patch |
|
223 | # the first patch in the queue is never a merge patch | |
223 | # |
|
224 | # | |
224 | pname = ".hg.patches.merge.marker" |
|
225 | pname = ".hg.patches.merge.marker" | |
225 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1, |
|
226 | n = repo.commit(None, '[mq]: merge marker', user=None, force=1, | |
226 | wlock=wlock) |
|
227 | wlock=wlock) | |
227 | self.applied.append(revlog.hex(n) + ":" + pname) |
|
228 | self.applied.append(revlog.hex(n) + ":" + pname) | |
228 | self.applied_dirty = 1 |
|
229 | self.applied_dirty = 1 | |
229 |
|
230 | |||
230 | head = self.qparents(repo) |
|
231 | head = self.qparents(repo) | |
231 |
|
232 | |||
232 | for patch in series: |
|
233 | for patch in series: | |
233 | patch = mergeq.lookup(patch) |
|
234 | patch = mergeq.lookup(patch) | |
234 | if not patch: |
|
235 | if not patch: | |
235 | self.ui.warn("patch %s does not exist\n" % patch) |
|
236 | self.ui.warn("patch %s does not exist\n" % patch) | |
236 | return (1, None) |
|
237 | return (1, None) | |
237 |
|
238 | |||
238 | info = mergeq.isapplied(patch) |
|
239 | info = mergeq.isapplied(patch) | |
239 | if not info: |
|
240 | if not info: | |
240 | self.ui.warn("patch %s is not applied\n" % patch) |
|
241 | self.ui.warn("patch %s is not applied\n" % patch) | |
241 | return (1, None) |
|
242 | return (1, None) | |
242 | rev = revlog.bin(info[1]) |
|
243 | rev = revlog.bin(info[1]) | |
243 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) |
|
244 | (err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock) | |
244 | if head: |
|
245 | if head: | |
245 | self.applied.append(revlog.hex(head) + ":" + patch) |
|
246 | self.applied.append(revlog.hex(head) + ":" + patch) | |
246 | self.applied_dirty = 1 |
|
247 | self.applied_dirty = 1 | |
247 | if err: |
|
248 | if err: | |
248 | return (err, head) |
|
249 | return (err, head) | |
249 | return (0, head) |
|
250 | return (0, head) | |
250 |
|
251 | |||
251 | def apply(self, repo, series, list=False, update_status=True, |
|
252 | def apply(self, repo, series, list=False, update_status=True, | |
252 | strict=False, patchdir=None, merge=None, wlock=None): |
|
253 | strict=False, patchdir=None, merge=None, wlock=None): | |
253 | # TODO unify with commands.py |
|
254 | # TODO unify with commands.py | |
254 | if not patchdir: |
|
255 | if not patchdir: | |
255 | patchdir = self.path |
|
256 | patchdir = self.path | |
256 | pwd = os.getcwd() |
|
257 | pwd = os.getcwd() | |
257 | os.chdir(repo.root) |
|
258 | os.chdir(repo.root) | |
258 | err = 0 |
|
259 | err = 0 | |
259 | if not wlock: |
|
260 | if not wlock: | |
260 | wlock = repo.wlock() |
|
261 | wlock = repo.wlock() | |
261 | lock = repo.lock() |
|
262 | lock = repo.lock() | |
262 | tr = repo.transaction() |
|
263 | tr = repo.transaction() | |
263 | n = None |
|
264 | n = None | |
264 | for patch in series: |
|
265 | for patch in series: | |
265 | self.ui.warn("applying %s\n" % patch) |
|
266 | self.ui.warn("applying %s\n" % patch) | |
266 | pf = os.path.join(patchdir, patch) |
|
267 | pf = os.path.join(patchdir, patch) | |
267 |
|
268 | |||
268 | try: |
|
269 | try: | |
269 | message, comments, user, patchfound = self.readheaders(patch) |
|
270 | message, comments, user, patchfound = self.readheaders(patch) | |
270 | except: |
|
271 | except: | |
271 | self.ui.warn("Unable to read %s\n" % pf) |
|
272 | self.ui.warn("Unable to read %s\n" % pf) | |
272 | err = 1 |
|
273 | err = 1 | |
273 | break |
|
274 | break | |
274 |
|
275 | |||
275 | if not message: |
|
276 | if not message: | |
276 | message = "imported patch %s\n" % patch |
|
277 | message = "imported patch %s\n" % patch | |
277 | else: |
|
278 | else: | |
278 | if list: |
|
279 | if list: | |
279 | message.append("\nimported patch %s" % patch) |
|
280 | message.append("\nimported patch %s" % patch) | |
280 | message = '\n'.join(message) |
|
281 | message = '\n'.join(message) | |
281 |
|
282 | |||
282 | try: |
|
283 | try: | |
283 | f = os.popen("patch -p1 --no-backup-if-mismatch < '%s'" % (pf)) |
|
284 | f = os.popen("patch -p1 --no-backup-if-mismatch < '%s'" % (pf)) | |
284 | except: |
|
285 | except: | |
285 | self.ui.warn("patch failed, unable to continue (try -v)\n") |
|
286 | self.ui.warn("patch failed, unable to continue (try -v)\n") | |
286 | err = 1 |
|
287 | err = 1 | |
287 | break |
|
288 | break | |
288 | files = [] |
|
289 | files = [] | |
289 | fuzz = False |
|
290 | fuzz = False | |
290 | for l in f: |
|
291 | for l in f: | |
291 | l = l.rstrip('\r\n'); |
|
292 | l = l.rstrip('\r\n'); | |
292 | if self.ui.verbose: |
|
293 | if self.ui.verbose: | |
293 | self.ui.warn(l + "\n") |
|
294 | self.ui.warn(l + "\n") | |
294 | if l[:14] == 'patching file ': |
|
295 | if l[:14] == 'patching file ': | |
295 | pf = os.path.normpath(l[14:]) |
|
296 | pf = os.path.normpath(l[14:]) | |
296 | # when patch finds a space in the file name, it puts |
|
297 | # when patch finds a space in the file name, it puts | |
297 | # single quotes around the filename. strip them off |
|
298 | # single quotes around the filename. strip them off | |
298 | if pf[0] == "'" and pf[-1] == "'": |
|
299 | if pf[0] == "'" and pf[-1] == "'": | |
299 | pf = pf[1:-1] |
|
300 | pf = pf[1:-1] | |
300 | if pf not in files: |
|
301 | if pf not in files: | |
301 | files.append(pf) |
|
302 | files.append(pf) | |
302 | printed_file = False |
|
303 | printed_file = False | |
303 | file_str = l |
|
304 | file_str = l | |
304 | elif l.find('with fuzz') >= 0: |
|
305 | elif l.find('with fuzz') >= 0: | |
305 | if not printed_file: |
|
306 | if not printed_file: | |
306 | self.ui.warn(file_str + '\n') |
|
307 | self.ui.warn(file_str + '\n') | |
307 | printed_file = True |
|
308 | printed_file = True | |
308 | self.ui.warn(l + '\n') |
|
309 | self.ui.warn(l + '\n') | |
309 | fuzz = True |
|
310 | fuzz = True | |
310 | elif l.find('saving rejects to file') >= 0: |
|
311 | elif l.find('saving rejects to file') >= 0: | |
311 | self.ui.warn(l + '\n') |
|
312 | self.ui.warn(l + '\n') | |
312 | elif l.find('FAILED') >= 0: |
|
313 | elif l.find('FAILED') >= 0: | |
313 | if not printed_file: |
|
314 | if not printed_file: | |
314 | self.ui.warn(file_str + '\n') |
|
315 | self.ui.warn(file_str + '\n') | |
315 | printed_file = True |
|
316 | printed_file = True | |
316 | self.ui.warn(l + '\n') |
|
317 | self.ui.warn(l + '\n') | |
317 | patcherr = f.close() |
|
318 | patcherr = f.close() | |
318 |
|
319 | |||
319 | if merge and len(files) > 0: |
|
320 | if merge and len(files) > 0: | |
320 | # Mark as merged and update dirstate parent info |
|
321 | # Mark as merged and update dirstate parent info | |
321 | repo.dirstate.update(repo.dirstate.filterfiles(files), 'm') |
|
322 | repo.dirstate.update(repo.dirstate.filterfiles(files), 'm') | |
322 | p1, p2 = repo.dirstate.parents() |
|
323 | p1, p2 = repo.dirstate.parents() | |
323 | repo.dirstate.setparents(p1, merge) |
|
324 | repo.dirstate.setparents(p1, merge) | |
324 | if len(files) > 0: |
|
325 | if len(files) > 0: | |
325 | commands.addremove_lock(self.ui, repo, files, |
|
326 | commands.addremove_lock(self.ui, repo, files, | |
326 | opts={}, wlock=wlock) |
|
327 | opts={}, wlock=wlock) | |
327 | n = repo.commit(files, message, user, force=1, lock=lock, |
|
328 | n = repo.commit(files, message, user, force=1, lock=lock, | |
328 | wlock=wlock) |
|
329 | wlock=wlock) | |
329 |
|
330 | |||
330 | if n == None: |
|
331 | if n == None: | |
331 | self.ui.warn("repo commit failed\n") |
|
332 | self.ui.warn("repo commit failed\n") | |
332 | sys.exit(1) |
|
333 | sys.exit(1) | |
333 |
|
334 | |||
334 | if update_status: |
|
335 | if update_status: | |
335 | self.applied.append(revlog.hex(n) + ":" + patch) |
|
336 | self.applied.append(revlog.hex(n) + ":" + patch) | |
336 |
|
337 | |||
337 | if patcherr: |
|
338 | if patcherr: | |
338 | if not patchfound: |
|
339 | if not patchfound: | |
339 | self.ui.warn("patch %s is empty\n" % patch) |
|
340 | self.ui.warn("patch %s is empty\n" % patch) | |
340 | err = 0 |
|
341 | err = 0 | |
341 | else: |
|
342 | else: | |
342 | self.ui.warn("patch failed, rejects left in working dir\n") |
|
343 | self.ui.warn("patch failed, rejects left in working dir\n") | |
343 | err = 1 |
|
344 | err = 1 | |
344 | break |
|
345 | break | |
345 |
|
346 | |||
346 | if fuzz and strict: |
|
347 | if fuzz and strict: | |
347 | self.ui.warn("fuzz found when applying patch, stopping\n") |
|
348 | self.ui.warn("fuzz found when applying patch, stopping\n") | |
348 | err = 1 |
|
349 | err = 1 | |
349 | break |
|
350 | break | |
350 | tr.close() |
|
351 | tr.close() | |
351 | os.chdir(pwd) |
|
352 | os.chdir(pwd) | |
352 | return (err, n) |
|
353 | return (err, n) | |
353 |
|
354 | |||
354 | def delete(self, repo, patch): |
|
355 | def delete(self, repo, patch): | |
355 | patch = self.lookup(patch) |
|
356 | patch = self.lookup(patch) | |
356 | info = self.isapplied(patch) |
|
357 | info = self.isapplied(patch) | |
357 | if info: |
|
358 | if info: | |
358 | self.ui.warn("cannot delete applied patch %s\n" % patch) |
|
359 | self.ui.warn("cannot delete applied patch %s\n" % patch) | |
359 | sys.exit(1) |
|
360 | sys.exit(1) | |
360 | if patch not in self.series: |
|
361 | if patch not in self.series: | |
361 | self.ui.warn("patch %s not in series file\n" % patch) |
|
362 | self.ui.warn("patch %s not in series file\n" % patch) | |
362 | sys.exit(1) |
|
363 | sys.exit(1) | |
363 | i = self.find_series(patch) |
|
364 | i = self.find_series(patch) | |
364 | del self.full_series[i] |
|
365 | del self.full_series[i] | |
365 | self.read_series(self.full_series) |
|
366 | self.read_series(self.full_series) | |
366 | self.series_dirty = 1 |
|
367 | self.series_dirty = 1 | |
367 |
|
368 | |||
368 | def check_toppatch(self, repo): |
|
369 | def check_toppatch(self, repo): | |
369 | if len(self.applied) > 0: |
|
370 | if len(self.applied) > 0: | |
370 | (top, patch) = self.applied[-1].split(':') |
|
371 | (top, patch) = self.applied[-1].split(':') | |
371 | top = revlog.bin(top) |
|
372 | top = revlog.bin(top) | |
372 | pp = repo.dirstate.parents() |
|
373 | pp = repo.dirstate.parents() | |
373 | if top not in pp: |
|
374 | if top not in pp: | |
374 | self.ui.warn("queue top not at dirstate parents. top %s dirstate %s %s\n" %( revlog.short(top), revlog.short(pp[0]), revlog.short(pp[1]))) |
|
375 | self.ui.warn("queue top not at dirstate parents. top %s dirstate %s %s\n" %( revlog.short(top), revlog.short(pp[0]), revlog.short(pp[1]))) | |
375 | sys.exit(1) |
|
376 | sys.exit(1) | |
376 | return top |
|
377 | return top | |
377 | return None |
|
378 | return None | |
378 | def check_localchanges(self, repo): |
|
379 | def check_localchanges(self, repo): | |
379 | (c, a, r, d, u) = repo.changes(None, None) |
|
380 | (c, a, r, d, u) = repo.changes(None, None) | |
380 | if c or a or d or r: |
|
381 | if c or a or d or r: | |
381 | self.ui.write("Local changes found, refresh first\n") |
|
382 | self.ui.write("Local changes found, refresh first\n") | |
382 | sys.exit(1) |
|
383 | sys.exit(1) | |
383 | def new(self, repo, patch, msg=None, force=None): |
|
384 | def new(self, repo, patch, msg=None, force=None): | |
384 | if not force: |
|
385 | if not force: | |
385 | self.check_localchanges(repo) |
|
386 | self.check_localchanges(repo) | |
386 | self.check_toppatch(repo) |
|
387 | self.check_toppatch(repo) | |
387 | wlock = repo.wlock() |
|
388 | wlock = repo.wlock() | |
388 | insert = self.series_end() |
|
389 | insert = self.series_end() | |
389 | if msg: |
|
390 | if msg: | |
390 | n = repo.commit([], "[mq]: %s" % msg, force=True, wlock=wlock) |
|
391 | n = repo.commit([], "[mq]: %s" % msg, force=True, wlock=wlock) | |
391 | else: |
|
392 | else: | |
392 | n = repo.commit([], |
|
393 | n = repo.commit([], | |
393 | "New patch: %s" % patch, force=True, wlock=wlock) |
|
394 | "New patch: %s" % patch, force=True, wlock=wlock) | |
394 | if n == None: |
|
395 | if n == None: | |
395 | self.ui.warn("repo commit failed\n") |
|
396 | self.ui.warn("repo commit failed\n") | |
396 | sys.exit(1) |
|
397 | sys.exit(1) | |
397 | self.full_series[insert:insert] = [patch] |
|
398 | self.full_series[insert:insert] = [patch] | |
398 | self.applied.append(revlog.hex(n) + ":" + patch) |
|
399 | self.applied.append(revlog.hex(n) + ":" + patch) | |
399 | self.read_series(self.full_series) |
|
400 | self.read_series(self.full_series) | |
400 | self.series_dirty = 1 |
|
401 | self.series_dirty = 1 | |
401 | self.applied_dirty = 1 |
|
402 | self.applied_dirty = 1 | |
402 | p = self.opener(patch, "w") |
|
403 | p = self.opener(patch, "w") | |
403 | if msg: |
|
404 | if msg: | |
404 | msg = msg + "\n" |
|
405 | msg = msg + "\n" | |
405 | p.write(msg) |
|
406 | p.write(msg) | |
406 | p.close() |
|
407 | p.close() | |
407 | wlock = None |
|
408 | wlock = None | |
408 | r = self.qrepo() |
|
409 | r = self.qrepo() | |
409 | if r: r.add([patch]) |
|
410 | if r: r.add([patch]) | |
410 |
|
411 | |||
411 | def strip(self, repo, rev, update=True, backup="all", wlock=None): |
|
412 | def strip(self, repo, rev, update=True, backup="all", wlock=None): | |
412 | def limitheads(chlog, stop): |
|
413 | def limitheads(chlog, stop): | |
413 | """return the list of all nodes that have no children""" |
|
414 | """return the list of all nodes that have no children""" | |
414 | p = {} |
|
415 | p = {} | |
415 | h = [] |
|
416 | h = [] | |
416 | stoprev = 0 |
|
417 | stoprev = 0 | |
417 | if stop in chlog.nodemap: |
|
418 | if stop in chlog.nodemap: | |
418 | stoprev = chlog.rev(stop) |
|
419 | stoprev = chlog.rev(stop) | |
419 |
|
420 | |||
420 | for r in range(chlog.count() - 1, -1, -1): |
|
421 | for r in range(chlog.count() - 1, -1, -1): | |
421 | n = chlog.node(r) |
|
422 | n = chlog.node(r) | |
422 | if n not in p: |
|
423 | if n not in p: | |
423 | h.append(n) |
|
424 | h.append(n) | |
424 | if n == stop: |
|
425 | if n == stop: | |
425 | break |
|
426 | break | |
426 | if r < stoprev: |
|
427 | if r < stoprev: | |
427 | break |
|
428 | break | |
428 | for pn in chlog.parents(n): |
|
429 | for pn in chlog.parents(n): | |
429 | p[pn] = 1 |
|
430 | p[pn] = 1 | |
430 | return h |
|
431 | return h | |
431 |
|
432 | |||
432 | def bundle(cg): |
|
433 | def bundle(cg): | |
433 | backupdir = repo.join("strip-backup") |
|
434 | backupdir = repo.join("strip-backup") | |
434 | if not os.path.isdir(backupdir): |
|
435 | if not os.path.isdir(backupdir): | |
435 | os.mkdir(backupdir) |
|
436 | os.mkdir(backupdir) | |
436 | name = os.path.join(backupdir, "%s" % revlog.short(rev)) |
|
437 | name = os.path.join(backupdir, "%s" % revlog.short(rev)) | |
437 | name = savename(name) |
|
438 | name = savename(name) | |
438 | self.ui.warn("saving bundle to %s\n" % name) |
|
439 | self.ui.warn("saving bundle to %s\n" % name) | |
439 | # TODO, exclusive open |
|
440 | # TODO, exclusive open | |
440 | f = open(name, "wb") |
|
441 | f = open(name, "wb") | |
441 | try: |
|
442 | try: | |
442 | f.write("HG10") |
|
443 | f.write("HG10") | |
443 | z = bz2.BZ2Compressor(9) |
|
444 | z = bz2.BZ2Compressor(9) | |
444 | while 1: |
|
445 | while 1: | |
445 | chunk = cg.read(4096) |
|
446 | chunk = cg.read(4096) | |
446 | if not chunk: |
|
447 | if not chunk: | |
447 | break |
|
448 | break | |
448 | f.write(z.compress(chunk)) |
|
449 | f.write(z.compress(chunk)) | |
449 | f.write(z.flush()) |
|
450 | f.write(z.flush()) | |
450 | except: |
|
451 | except: | |
451 | os.unlink(name) |
|
452 | os.unlink(name) | |
452 | raise |
|
453 | raise | |
453 | f.close() |
|
454 | f.close() | |
454 | return name |
|
455 | return name | |
455 |
|
456 | |||
456 | def stripall(rev, revnum): |
|
457 | def stripall(rev, revnum): | |
457 | cl = repo.changelog |
|
458 | cl = repo.changelog | |
458 | c = cl.read(rev) |
|
459 | c = cl.read(rev) | |
459 | mm = repo.manifest.read(c[0]) |
|
460 | mm = repo.manifest.read(c[0]) | |
460 | seen = {} |
|
461 | seen = {} | |
461 |
|
462 | |||
462 | for x in xrange(revnum, cl.count()): |
|
463 | for x in xrange(revnum, cl.count()): | |
463 | c = cl.read(cl.node(x)) |
|
464 | c = cl.read(cl.node(x)) | |
464 | for f in c[3]: |
|
465 | for f in c[3]: | |
465 | if f in seen: |
|
466 | if f in seen: | |
466 | continue |
|
467 | continue | |
467 | seen[f] = 1 |
|
468 | seen[f] = 1 | |
468 | if f in mm: |
|
469 | if f in mm: | |
469 | filerev = mm[f] |
|
470 | filerev = mm[f] | |
470 | else: |
|
471 | else: | |
471 | filerev = 0 |
|
472 | filerev = 0 | |
472 | seen[f] = filerev |
|
473 | seen[f] = filerev | |
473 | # we go in two steps here so the strip loop happens in a |
|
474 | # we go in two steps here so the strip loop happens in a | |
474 | # sensible order. When stripping many files, this helps keep |
|
475 | # sensible order. When stripping many files, this helps keep | |
475 | # our disk access patterns under control. |
|
476 | # our disk access patterns under control. | |
476 | list = seen.keys() |
|
477 | list = seen.keys() | |
477 | list.sort() |
|
478 | list.sort() | |
478 | for f in list: |
|
479 | for f in list: | |
479 | ff = repo.file(f) |
|
480 | ff = repo.file(f) | |
480 | filerev = seen[f] |
|
481 | filerev = seen[f] | |
481 | if filerev != 0: |
|
482 | if filerev != 0: | |
482 | if filerev in ff.nodemap: |
|
483 | if filerev in ff.nodemap: | |
483 | filerev = ff.rev(filerev) |
|
484 | filerev = ff.rev(filerev) | |
484 | else: |
|
485 | else: | |
485 | filerev = 0 |
|
486 | filerev = 0 | |
486 | ff.strip(filerev, revnum) |
|
487 | ff.strip(filerev, revnum) | |
487 |
|
488 | |||
488 | if not wlock: |
|
489 | if not wlock: | |
489 | wlock = repo.wlock() |
|
490 | wlock = repo.wlock() | |
490 | lock = repo.lock() |
|
491 | lock = repo.lock() | |
491 | chlog = repo.changelog |
|
492 | chlog = repo.changelog | |
492 | # TODO delete the undo files, and handle undo of merge sets |
|
493 | # TODO delete the undo files, and handle undo of merge sets | |
493 | pp = chlog.parents(rev) |
|
494 | pp = chlog.parents(rev) | |
494 | revnum = chlog.rev(rev) |
|
495 | revnum = chlog.rev(rev) | |
495 |
|
496 | |||
496 | if update: |
|
497 | if update: | |
497 | urev = self.qparents(repo, rev) |
|
498 | urev = self.qparents(repo, rev) | |
498 | repo.update(urev, allow=False, force=True, wlock=wlock) |
|
499 | repo.update(urev, allow=False, force=True, wlock=wlock) | |
499 | repo.dirstate.write() |
|
500 | repo.dirstate.write() | |
500 |
|
501 | |||
501 | # save is a list of all the branches we are truncating away |
|
502 | # save is a list of all the branches we are truncating away | |
502 | # that we actually want to keep. changegroup will be used |
|
503 | # that we actually want to keep. changegroup will be used | |
503 | # to preserve them and add them back after the truncate |
|
504 | # to preserve them and add them back after the truncate | |
504 | saveheads = [] |
|
505 | saveheads = [] | |
505 | savebases = {} |
|
506 | savebases = {} | |
506 |
|
507 | |||
507 | tip = chlog.tip() |
|
508 | tip = chlog.tip() | |
508 | heads = limitheads(chlog, rev) |
|
509 | heads = limitheads(chlog, rev) | |
509 | seen = {} |
|
510 | seen = {} | |
510 |
|
511 | |||
511 | # search through all the heads, finding those where the revision |
|
512 | # search through all the heads, finding those where the revision | |
512 | # we want to strip away is an ancestor. Also look for merges |
|
513 | # we want to strip away is an ancestor. Also look for merges | |
513 | # that might be turned into new heads by the strip. |
|
514 | # that might be turned into new heads by the strip. | |
514 | while heads: |
|
515 | while heads: | |
515 | h = heads.pop() |
|
516 | h = heads.pop() | |
516 | n = h |
|
517 | n = h | |
517 | while True: |
|
518 | while True: | |
518 | seen[n] = 1 |
|
519 | seen[n] = 1 | |
519 | pp = chlog.parents(n) |
|
520 | pp = chlog.parents(n) | |
520 | if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: |
|
521 | if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum: | |
521 | if pp[1] not in seen: |
|
522 | if pp[1] not in seen: | |
522 | heads.append(pp[1]) |
|
523 | heads.append(pp[1]) | |
523 | if pp[0] == revlog.nullid: |
|
524 | if pp[0] == revlog.nullid: | |
524 | break |
|
525 | break | |
525 | if chlog.rev(pp[0]) < revnum: |
|
526 | if chlog.rev(pp[0]) < revnum: | |
526 | break |
|
527 | break | |
527 | n = pp[0] |
|
528 | n = pp[0] | |
528 | if n == rev: |
|
529 | if n == rev: | |
529 | break |
|
530 | break | |
530 | r = chlog.reachable(h, rev) |
|
531 | r = chlog.reachable(h, rev) | |
531 | if rev not in r: |
|
532 | if rev not in r: | |
532 | saveheads.append(h) |
|
533 | saveheads.append(h) | |
533 | for x in r: |
|
534 | for x in r: | |
534 | if chlog.rev(x) > revnum: |
|
535 | if chlog.rev(x) > revnum: | |
535 | savebases[x] = 1 |
|
536 | savebases[x] = 1 | |
536 |
|
537 | |||
537 | # create a changegroup for all the branches we need to keep |
|
538 | # create a changegroup for all the branches we need to keep | |
538 | if backup is "all": |
|
539 | if backup is "all": | |
539 | backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') |
|
540 | backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip') | |
540 | bundle(backupch) |
|
541 | bundle(backupch) | |
541 | if saveheads: |
|
542 | if saveheads: | |
542 | backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') |
|
543 | backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip') | |
543 | chgrpfile = bundle(backupch) |
|
544 | chgrpfile = bundle(backupch) | |
544 |
|
545 | |||
545 | stripall(rev, revnum) |
|
546 | stripall(rev, revnum) | |
546 |
|
547 | |||
547 | change = chlog.read(rev) |
|
548 | change = chlog.read(rev) | |
548 | repo.manifest.strip(repo.manifest.rev(change[0]), revnum) |
|
549 | repo.manifest.strip(repo.manifest.rev(change[0]), revnum) | |
549 | chlog.strip(revnum, revnum) |
|
550 | chlog.strip(revnum, revnum) | |
550 | if saveheads: |
|
551 | if saveheads: | |
551 | self.ui.status("adding branch\n") |
|
552 | self.ui.status("adding branch\n") | |
552 | commands.unbundle(self.ui, repo, chgrpfile, update=False) |
|
553 | commands.unbundle(self.ui, repo, chgrpfile, update=False) | |
553 | if backup is not "strip": |
|
554 | if backup is not "strip": | |
554 | os.unlink(chgrpfile) |
|
555 | os.unlink(chgrpfile) | |
555 |
|
556 | |||
556 | def isapplied(self, patch): |
|
557 | def isapplied(self, patch): | |
557 | """returns (index, rev, patch)""" |
|
558 | """returns (index, rev, patch)""" | |
558 | for i in xrange(len(self.applied)): |
|
559 | for i in xrange(len(self.applied)): | |
559 | p = self.applied[i] |
|
560 | p = self.applied[i] | |
560 | a = p.split(':') |
|
561 | a = p.split(':') | |
561 | if a[1] == patch: |
|
562 | if a[1] == patch: | |
562 | return (i, a[0], a[1]) |
|
563 | return (i, a[0], a[1]) | |
563 | return None |
|
564 | return None | |
564 |
|
565 | |||
565 | def lookup(self, patch): |
|
566 | def lookup(self, patch): | |
566 | if patch == None: |
|
567 | if patch == None: | |
567 | return None |
|
568 | return None | |
568 | if patch in self.series: |
|
569 | if patch in self.series: | |
569 | return patch |
|
570 | return patch | |
570 | if not os.path.isfile(os.path.join(self.path, patch)): |
|
571 | if not os.path.isfile(os.path.join(self.path, patch)): | |
571 | try: |
|
572 | try: | |
572 | sno = int(patch) |
|
573 | sno = int(patch) | |
573 | except(ValueError, OverflowError): |
|
574 | except(ValueError, OverflowError): | |
574 | self.ui.warn("patch %s not in series\n" % patch) |
|
575 | self.ui.warn("patch %s not in series\n" % patch) | |
575 | sys.exit(1) |
|
576 | sys.exit(1) | |
576 | if sno >= len(self.series): |
|
577 | if sno >= len(self.series): | |
577 | self.ui.warn("patch number %d is out of range\n" % sno) |
|
578 | self.ui.warn("patch number %d is out of range\n" % sno) | |
578 | sys.exit(1) |
|
579 | sys.exit(1) | |
579 | patch = self.series[sno] |
|
580 | patch = self.series[sno] | |
580 | else: |
|
581 | else: | |
581 | self.ui.warn("patch %s not in series\n" % patch) |
|
582 | self.ui.warn("patch %s not in series\n" % patch) | |
582 | sys.exit(1) |
|
583 | sys.exit(1) | |
583 | return patch |
|
584 | return patch | |
584 |
|
585 | |||
585 | def push(self, repo, patch=None, force=False, list=False, |
|
586 | def push(self, repo, patch=None, force=False, list=False, | |
586 | mergeq=None, wlock=None): |
|
587 | mergeq=None, wlock=None): | |
587 | if not wlock: |
|
588 | if not wlock: | |
588 | wlock = repo.wlock() |
|
589 | wlock = repo.wlock() | |
589 | patch = self.lookup(patch) |
|
590 | patch = self.lookup(patch) | |
590 | if patch and self.isapplied(patch): |
|
591 | if patch and self.isapplied(patch): | |
591 | self.ui.warn("patch %s is already applied\n" % patch) |
|
592 | self.ui.warn("patch %s is already applied\n" % patch) | |
592 | sys.exit(1) |
|
593 | sys.exit(1) | |
593 | if self.series_end() == len(self.series): |
|
594 | if self.series_end() == len(self.series): | |
594 | self.ui.warn("File series fully applied\n") |
|
595 | self.ui.warn("File series fully applied\n") | |
595 | sys.exit(1) |
|
596 | sys.exit(1) | |
596 | if not force: |
|
597 | if not force: | |
597 | self.check_localchanges(repo) |
|
598 | self.check_localchanges(repo) | |
598 |
|
599 | |||
599 | self.applied_dirty = 1; |
|
600 | self.applied_dirty = 1; | |
600 | start = self.series_end() |
|
601 | start = self.series_end() | |
601 | if start > 0: |
|
602 | if start > 0: | |
602 | self.check_toppatch(repo) |
|
603 | self.check_toppatch(repo) | |
603 | if not patch: |
|
604 | if not patch: | |
604 | patch = self.series[start] |
|
605 | patch = self.series[start] | |
605 | end = start + 1 |
|
606 | end = start + 1 | |
606 | else: |
|
607 | else: | |
607 | end = self.series.index(patch, start) + 1 |
|
608 | end = self.series.index(patch, start) + 1 | |
608 | s = self.series[start:end] |
|
609 | s = self.series[start:end] | |
609 | if mergeq: |
|
610 | if mergeq: | |
610 | ret = self.mergepatch(repo, mergeq, s, wlock) |
|
611 | ret = self.mergepatch(repo, mergeq, s, wlock) | |
611 | else: |
|
612 | else: | |
612 | ret = self.apply(repo, s, list, wlock=wlock) |
|
613 | ret = self.apply(repo, s, list, wlock=wlock) | |
613 | top = self.applied[-1].split(':')[1] |
|
614 | top = self.applied[-1].split(':')[1] | |
614 | if ret[0]: |
|
615 | if ret[0]: | |
615 | self.ui.write("Errors during apply, please fix and refresh %s\n" % |
|
616 | self.ui.write("Errors during apply, please fix and refresh %s\n" % | |
616 | top) |
|
617 | top) | |
617 | else: |
|
618 | else: | |
618 | self.ui.write("Now at: %s\n" % top) |
|
619 | self.ui.write("Now at: %s\n" % top) | |
619 | return ret[0] |
|
620 | return ret[0] | |
620 |
|
621 | |||
621 | def pop(self, repo, patch=None, force=False, update=True, wlock=None): |
|
622 | def pop(self, repo, patch=None, force=False, update=True, wlock=None): | |
622 | def getfile(f, rev): |
|
623 | def getfile(f, rev): | |
623 | t = repo.file(f).read(rev) |
|
624 | t = repo.file(f).read(rev) | |
624 | try: |
|
625 | try: | |
625 | repo.wfile(f, "w").write(t) |
|
626 | repo.wfile(f, "w").write(t) | |
626 | except IOError: |
|
627 | except IOError: | |
627 | os.makedirs(os.path.dirname(repo.wjoin(f))) |
|
628 | os.makedirs(os.path.dirname(repo.wjoin(f))) | |
628 | repo.wfile(f, "w").write(t) |
|
629 | repo.wfile(f, "w").write(t) | |
629 |
|
630 | |||
630 | if not wlock: |
|
631 | if not wlock: | |
631 | wlock = repo.wlock() |
|
632 | wlock = repo.wlock() | |
632 | if patch: |
|
633 | if patch: | |
633 | # index, rev, patch |
|
634 | # index, rev, patch | |
634 | info = self.isapplied(patch) |
|
635 | info = self.isapplied(patch) | |
635 | if not info: |
|
636 | if not info: | |
636 | patch = self.lookup(patch) |
|
637 | patch = self.lookup(patch) | |
637 | info = self.isapplied(patch) |
|
638 | info = self.isapplied(patch) | |
638 | if not info: |
|
639 | if not info: | |
639 | self.ui.warn("patch %s is not applied\n" % patch) |
|
640 | self.ui.warn("patch %s is not applied\n" % patch) | |
640 | sys.exit(1) |
|
641 | sys.exit(1) | |
641 | if len(self.applied) == 0: |
|
642 | if len(self.applied) == 0: | |
642 | self.ui.warn("No patches applied\n") |
|
643 | self.ui.warn("No patches applied\n") | |
643 | sys.exit(1) |
|
644 | sys.exit(1) | |
644 |
|
645 | |||
645 | if not update: |
|
646 | if not update: | |
646 | parents = repo.dirstate.parents() |
|
647 | parents = repo.dirstate.parents() | |
647 | rr = [ revlog.bin(x.split(':')[0]) for x in self.applied ] |
|
648 | rr = [ revlog.bin(x.split(':')[0]) for x in self.applied ] | |
648 | for p in parents: |
|
649 | for p in parents: | |
649 | if p in rr: |
|
650 | if p in rr: | |
650 | self.ui.warn("qpop: forcing dirstate update\n") |
|
651 | self.ui.warn("qpop: forcing dirstate update\n") | |
651 | update = True |
|
652 | update = True | |
652 |
|
653 | |||
653 | if not force and update: |
|
654 | if not force and update: | |
654 | self.check_localchanges(repo) |
|
655 | self.check_localchanges(repo) | |
655 |
|
656 | |||
656 | self.applied_dirty = 1; |
|
657 | self.applied_dirty = 1; | |
657 | end = len(self.applied) |
|
658 | end = len(self.applied) | |
658 | if not patch: |
|
659 | if not patch: | |
659 | info = [len(self.applied) - 1] + self.applied[-1].split(':') |
|
660 | info = [len(self.applied) - 1] + self.applied[-1].split(':') | |
660 | start = info[0] |
|
661 | start = info[0] | |
661 | rev = revlog.bin(info[1]) |
|
662 | rev = revlog.bin(info[1]) | |
662 |
|
663 | |||
663 | # we know there are no local changes, so we can make a simplified |
|
664 | # we know there are no local changes, so we can make a simplified | |
664 | # form of hg.update. |
|
665 | # form of hg.update. | |
665 | if update: |
|
666 | if update: | |
666 | top = self.check_toppatch(repo) |
|
667 | top = self.check_toppatch(repo) | |
667 | qp = self.qparents(repo, rev) |
|
668 | qp = self.qparents(repo, rev) | |
668 | changes = repo.changelog.read(qp) |
|
669 | changes = repo.changelog.read(qp) | |
669 | mf1 = repo.manifest.readflags(changes[0]) |
|
670 | mf1 = repo.manifest.readflags(changes[0]) | |
670 | mmap = repo.manifest.read(changes[0]) |
|
671 | mmap = repo.manifest.read(changes[0]) | |
671 | (c, a, r, d, u) = repo.changes(qp, top) |
|
672 | (c, a, r, d, u) = repo.changes(qp, top) | |
672 | if d: |
|
673 | if d: | |
673 | raise util.Abort("deletions found between repo revs") |
|
674 | raise util.Abort("deletions found between repo revs") | |
674 | for f in c: |
|
675 | for f in c: | |
675 | getfile(f, mmap[f]) |
|
676 | getfile(f, mmap[f]) | |
676 | for f in r: |
|
677 | for f in r: | |
677 | getfile(f, mmap[f]) |
|
678 | getfile(f, mmap[f]) | |
678 | util.set_exec(repo.wjoin(f), mf1[f]) |
|
679 | util.set_exec(repo.wjoin(f), mf1[f]) | |
679 | repo.dirstate.update(c + r, 'n') |
|
680 | repo.dirstate.update(c + r, 'n') | |
680 | for f in a: |
|
681 | for f in a: | |
681 | try: os.unlink(repo.wjoin(f)) |
|
682 | try: os.unlink(repo.wjoin(f)) | |
682 | except: raise |
|
683 | except: raise | |
683 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) |
|
684 | try: os.removedirs(os.path.dirname(repo.wjoin(f))) | |
684 | except: pass |
|
685 | except: pass | |
685 | if a: |
|
686 | if a: | |
686 | repo.dirstate.forget(a) |
|
687 | repo.dirstate.forget(a) | |
687 | repo.dirstate.setparents(qp, revlog.nullid) |
|
688 | repo.dirstate.setparents(qp, revlog.nullid) | |
688 | self.strip(repo, rev, update=False, backup='strip', wlock=wlock) |
|
689 | self.strip(repo, rev, update=False, backup='strip', wlock=wlock) | |
689 | del self.applied[start:end] |
|
690 | del self.applied[start:end] | |
690 | if len(self.applied): |
|
691 | if len(self.applied): | |
691 | self.ui.write("Now at: %s\n" % self.applied[-1].split(':')[1]) |
|
692 | self.ui.write("Now at: %s\n" % self.applied[-1].split(':')[1]) | |
692 | else: |
|
693 | else: | |
693 | self.ui.write("Patch queue now empty\n") |
|
694 | self.ui.write("Patch queue now empty\n") | |
694 |
|
695 | |||
695 | def diff(self, repo, files): |
|
696 | def diff(self, repo, files): | |
696 | top = self.check_toppatch(repo) |
|
697 | top = self.check_toppatch(repo) | |
697 | if not top: |
|
698 | if not top: | |
698 | self.ui.write("No patches applied\n") |
|
699 | self.ui.write("No patches applied\n") | |
699 | return |
|
700 | return | |
700 | qp = self.qparents(repo, top) |
|
701 | qp = self.qparents(repo, top) | |
701 | commands.dodiff(sys.stdout, self.ui, repo, qp, None, files) |
|
702 | commands.dodiff(sys.stdout, self.ui, repo, qp, None, files) | |
702 |
|
703 | |||
703 | def refresh(self, repo, short=False): |
|
704 | def refresh(self, repo, short=False): | |
704 | if len(self.applied) == 0: |
|
705 | if len(self.applied) == 0: | |
705 | self.ui.write("No patches applied\n") |
|
706 | self.ui.write("No patches applied\n") | |
706 | return |
|
707 | return | |
707 | wlock = repo.wlock() |
|
708 | wlock = repo.wlock() | |
708 | self.check_toppatch(repo) |
|
709 | self.check_toppatch(repo) | |
709 | qp = self.qparents(repo) |
|
710 | qp = self.qparents(repo) | |
710 | (top, patch) = self.applied[-1].split(':') |
|
711 | (top, patch) = self.applied[-1].split(':') | |
711 | top = revlog.bin(top) |
|
712 | top = revlog.bin(top) | |
712 | cparents = repo.changelog.parents(top) |
|
713 | cparents = repo.changelog.parents(top) | |
713 | patchparent = self.qparents(repo, top) |
|
714 | patchparent = self.qparents(repo, top) | |
714 | message, comments, user, patchfound = self.readheaders(patch) |
|
715 | message, comments, user, patchfound = self.readheaders(patch) | |
715 |
|
716 | |||
716 | patchf = self.opener(patch, "w") |
|
717 | patchf = self.opener(patch, "w") | |
717 | if comments: |
|
718 | if comments: | |
718 | comments = "\n".join(comments) + '\n\n' |
|
719 | comments = "\n".join(comments) + '\n\n' | |
719 | patchf.write(comments) |
|
720 | patchf.write(comments) | |
720 |
|
721 | |||
721 | tip = repo.changelog.tip() |
|
722 | tip = repo.changelog.tip() | |
722 | if top == tip: |
|
723 | if top == tip: | |
723 | # if the top of our patch queue is also the tip, there is an |
|
724 | # if the top of our patch queue is also the tip, there is an | |
724 | # optimization here. We update the dirstate in place and strip |
|
725 | # optimization here. We update the dirstate in place and strip | |
725 | # off the tip commit. Then just commit the current directory |
|
726 | # off the tip commit. Then just commit the current directory | |
726 | # tree. We can also send repo.commit the list of files |
|
727 | # tree. We can also send repo.commit the list of files | |
727 | # changed to speed up the diff |
|
728 | # changed to speed up the diff | |
728 | # |
|
729 | # | |
729 | # in short mode, we only diff the files included in the |
|
730 | # in short mode, we only diff the files included in the | |
730 | # patch already |
|
731 | # patch already | |
731 | # |
|
732 | # | |
732 | # this should really read: |
|
733 | # this should really read: | |
733 | #(cc, dd, aa, aa2, uu) = repo.changes(tip, patchparent) |
|
734 | #(cc, dd, aa, aa2, uu) = repo.changes(tip, patchparent) | |
734 | # but we do it backwards to take advantage of manifest/chlog |
|
735 | # but we do it backwards to take advantage of manifest/chlog | |
735 | # caching against the next repo.changes call |
|
736 | # caching against the next repo.changes call | |
736 | # |
|
737 | # | |
737 | (cc, aa, dd, aa2, uu) = repo.changes(patchparent, tip) |
|
738 | (cc, aa, dd, aa2, uu) = repo.changes(patchparent, tip) | |
738 | if short: |
|
739 | if short: | |
739 | filelist = cc + aa + dd |
|
740 | filelist = cc + aa + dd | |
740 | else: |
|
741 | else: | |
741 | filelist = None |
|
742 | filelist = None | |
742 | (c, a, r, d, u) = repo.changes(None, None, filelist) |
|
743 | (c, a, r, d, u) = repo.changes(None, None, filelist) | |
743 |
|
744 | |||
744 | # we might end up with files that were added between tip and |
|
745 | # we might end up with files that were added between tip and | |
745 | # the dirstate parent, but then changed in the local dirstate. |
|
746 | # the dirstate parent, but then changed in the local dirstate. | |
746 | # in this case, we want them to only show up in the added section |
|
747 | # in this case, we want them to only show up in the added section | |
747 | for x in c: |
|
748 | for x in c: | |
748 | if x not in aa: |
|
749 | if x not in aa: | |
749 | cc.append(x) |
|
750 | cc.append(x) | |
750 | # we might end up with files added by the local dirstate that |
|
751 | # we might end up with files added by the local dirstate that | |
751 | # were deleted by the patch. In this case, they should only |
|
752 | # were deleted by the patch. In this case, they should only | |
752 | # show up in the changed section. |
|
753 | # show up in the changed section. | |
753 | for x in a: |
|
754 | for x in a: | |
754 | if x in dd: |
|
755 | if x in dd: | |
755 | del dd[dd.index(x)] |
|
756 | del dd[dd.index(x)] | |
756 | cc.append(x) |
|
757 | cc.append(x) | |
757 | else: |
|
758 | else: | |
758 | aa.append(x) |
|
759 | aa.append(x) | |
759 | # make sure any files deleted in the local dirstate |
|
760 | # make sure any files deleted in the local dirstate | |
760 | # are not in the add or change column of the patch |
|
761 | # are not in the add or change column of the patch | |
761 | forget = [] |
|
762 | forget = [] | |
762 | for x in d + r: |
|
763 | for x in d + r: | |
763 | if x in aa: |
|
764 | if x in aa: | |
764 | del aa[aa.index(x)] |
|
765 | del aa[aa.index(x)] | |
765 | forget.append(x) |
|
766 | forget.append(x) | |
766 | continue |
|
767 | continue | |
767 | elif x in cc: |
|
768 | elif x in cc: | |
768 | del cc[cc.index(x)] |
|
769 | del cc[cc.index(x)] | |
769 | dd.append(x) |
|
770 | dd.append(x) | |
770 |
|
771 | |||
771 | c = list(util.unique(cc)) |
|
772 | c = list(util.unique(cc)) | |
772 | r = list(util.unique(dd)) |
|
773 | r = list(util.unique(dd)) | |
773 | a = list(util.unique(aa)) |
|
774 | a = list(util.unique(aa)) | |
774 | filelist = list(util.unique(c + r + a )) |
|
775 | filelist = list(util.unique(c + r + a )) | |
775 | commands.dodiff(patchf, self.ui, repo, patchparent, None, |
|
776 | commands.dodiff(patchf, self.ui, repo, patchparent, None, | |
776 | filelist, changes=(c, a, r, [], u)) |
|
777 | filelist, changes=(c, a, r, [], u)) | |
777 | patchf.close() |
|
778 | patchf.close() | |
778 |
|
779 | |||
779 | changes = repo.changelog.read(tip) |
|
780 | changes = repo.changelog.read(tip) | |
780 | repo.dirstate.setparents(*cparents) |
|
781 | repo.dirstate.setparents(*cparents) | |
781 | repo.dirstate.update(a, 'a') |
|
782 | repo.dirstate.update(a, 'a') | |
782 | repo.dirstate.update(r, 'r') |
|
783 | repo.dirstate.update(r, 'r') | |
783 | repo.dirstate.update(c, 'n') |
|
784 | repo.dirstate.update(c, 'n') | |
784 | repo.dirstate.forget(forget) |
|
785 | repo.dirstate.forget(forget) | |
785 |
|
786 | |||
786 | if not message: |
|
787 | if not message: | |
787 | message = "patch queue: %s\n" % patch |
|
788 | message = "patch queue: %s\n" % patch | |
788 | else: |
|
789 | else: | |
789 | message = "\n".join(message) |
|
790 | message = "\n".join(message) | |
790 | self.strip(repo, top, update=False, backup='strip', wlock=wlock) |
|
791 | self.strip(repo, top, update=False, backup='strip', wlock=wlock) | |
791 | n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) |
|
792 | n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock) | |
792 | self.applied[-1] = revlog.hex(n) + ':' + patch |
|
793 | self.applied[-1] = revlog.hex(n) + ':' + patch | |
793 | self.applied_dirty = 1 |
|
794 | self.applied_dirty = 1 | |
794 | else: |
|
795 | else: | |
795 | commands.dodiff(patchf, self.ui, repo, patchparent, None) |
|
796 | commands.dodiff(patchf, self.ui, repo, patchparent, None) | |
796 | patchf.close() |
|
797 | patchf.close() | |
797 | self.pop(repo, force=True, wlock=wlock) |
|
798 | self.pop(repo, force=True, wlock=wlock) | |
798 | self.push(repo, force=True, wlock=wlock) |
|
799 | self.push(repo, force=True, wlock=wlock) | |
799 |
|
800 | |||
800 | def init(self, repo, create=False): |
|
801 | def init(self, repo, create=False): | |
801 | if os.path.isdir(self.path): |
|
802 | if os.path.isdir(self.path): | |
802 | raise util.Abort("patch queue directory already exists") |
|
803 | raise util.Abort("patch queue directory already exists") | |
803 | os.mkdir(self.path) |
|
804 | os.mkdir(self.path) | |
804 | if create: |
|
805 | if create: | |
805 | return self.qrepo(create=True) |
|
806 | return self.qrepo(create=True) | |
806 |
|
807 | |||
807 | def unapplied(self, repo, patch=None): |
|
808 | def unapplied(self, repo, patch=None): | |
808 | if patch and patch not in self.series: |
|
809 | if patch and patch not in self.series: | |
809 | self.ui.warn("%s not in the series file\n" % patch) |
|
810 | self.ui.warn("%s not in the series file\n" % patch) | |
810 | sys.exit(1) |
|
811 | sys.exit(1) | |
811 | if not patch: |
|
812 | if not patch: | |
812 | start = self.series_end() |
|
813 | start = self.series_end() | |
813 | else: |
|
814 | else: | |
814 | start = self.series.index(patch) + 1 |
|
815 | start = self.series.index(patch) + 1 | |
815 | for p in self.series[start:]: |
|
816 | for p in self.series[start:]: | |
816 | self.ui.write("%s\n" % p) |
|
817 | self.ui.write("%s\n" % p) | |
817 |
|
818 | |||
818 | def qseries(self, repo, missing=None): |
|
819 | def qseries(self, repo, missing=None): | |
819 | start = self.series_end() |
|
820 | start = self.series_end() | |
820 | if not missing: |
|
821 | if not missing: | |
821 | for p in self.series[:start]: |
|
822 | for p in self.series[:start]: | |
822 | if self.ui.verbose: |
|
823 | if self.ui.verbose: | |
823 | self.ui.write("%d A " % self.series.index(p)) |
|
824 | self.ui.write("%d A " % self.series.index(p)) | |
824 | self.ui.write("%s\n" % p) |
|
825 | self.ui.write("%s\n" % p) | |
825 | for p in self.series[start:]: |
|
826 | for p in self.series[start:]: | |
826 | if self.ui.verbose: |
|
827 | if self.ui.verbose: | |
827 | self.ui.write("%d U " % self.series.index(p)) |
|
828 | self.ui.write("%d U " % self.series.index(p)) | |
828 | self.ui.write("%s\n" % p) |
|
829 | self.ui.write("%s\n" % p) | |
829 | else: |
|
830 | else: | |
830 | list = [] |
|
831 | list = [] | |
831 | for root, dirs, files in os.walk(self.path): |
|
832 | for root, dirs, files in os.walk(self.path): | |
832 | d = root[len(self.path) + 1:] |
|
833 | d = root[len(self.path) + 1:] | |
833 | for f in files: |
|
834 | for f in files: | |
834 | fl = os.path.join(d, f) |
|
835 | fl = os.path.join(d, f) | |
835 | if (fl not in self.series and |
|
836 | if (fl not in self.series and | |
836 | fl not in (self.status_path, self.series_path) |
|
837 | fl not in (self.status_path, self.series_path) | |
837 | and not fl.startswith('.')): |
|
838 | and not fl.startswith('.')): | |
838 | list.append(fl) |
|
839 | list.append(fl) | |
839 | list.sort() |
|
840 | list.sort() | |
840 | if list: |
|
841 | if list: | |
841 | for x in list: |
|
842 | for x in list: | |
842 | if self.ui.verbose: |
|
843 | if self.ui.verbose: | |
843 | self.ui.write("D ") |
|
844 | self.ui.write("D ") | |
844 | self.ui.write("%s\n" % x) |
|
845 | self.ui.write("%s\n" % x) | |
845 |
|
846 | |||
846 | def issaveline(self, l): |
|
847 | def issaveline(self, l): | |
847 | name = l.split(':')[1] |
|
848 | name = l.split(':')[1] | |
848 | if name == '.hg.patches.save.line': |
|
849 | if name == '.hg.patches.save.line': | |
849 | return True |
|
850 | return True | |
850 |
|
851 | |||
851 | def qrepo(self, create=False): |
|
852 | def qrepo(self, create=False): | |
852 | if create or os.path.isdir(os.path.join(self.path, ".hg")): |
|
853 | if create or os.path.isdir(os.path.join(self.path, ".hg")): | |
853 | return hg.repository(self.ui, path=self.path, create=create) |
|
854 | return hg.repository(self.ui, path=self.path, create=create) | |
854 |
|
855 | |||
855 | def restore(self, repo, rev, delete=None, qupdate=None): |
|
856 | def restore(self, repo, rev, delete=None, qupdate=None): | |
856 | c = repo.changelog.read(rev) |
|
857 | c = repo.changelog.read(rev) | |
857 | desc = c[4].strip() |
|
858 | desc = c[4].strip() | |
858 | lines = desc.splitlines() |
|
859 | lines = desc.splitlines() | |
859 | i = 0 |
|
860 | i = 0 | |
860 | datastart = None |
|
861 | datastart = None | |
861 | series = [] |
|
862 | series = [] | |
862 | applied = [] |
|
863 | applied = [] | |
863 | qpp = None |
|
864 | qpp = None | |
864 | for i in xrange(0, len(lines)): |
|
865 | for i in xrange(0, len(lines)): | |
865 | if lines[i] == 'Patch Data:': |
|
866 | if lines[i] == 'Patch Data:': | |
866 | datastart = i + 1 |
|
867 | datastart = i + 1 | |
867 | elif lines[i].startswith('Dirstate:'): |
|
868 | elif lines[i].startswith('Dirstate:'): | |
868 | l = lines[i].rstrip() |
|
869 | l = lines[i].rstrip() | |
869 | l = l[10:].split(' ') |
|
870 | l = l[10:].split(' ') | |
870 | qpp = [ hg.bin(x) for x in l ] |
|
871 | qpp = [ hg.bin(x) for x in l ] | |
871 | elif datastart != None: |
|
872 | elif datastart != None: | |
872 | l = lines[i].rstrip() |
|
873 | l = lines[i].rstrip() | |
873 | index = l.index(':') |
|
874 | index = l.index(':') | |
874 | id = l[:index] |
|
875 | id = l[:index] | |
875 | file = l[index + 1:] |
|
876 | file = l[index + 1:] | |
876 | if id: |
|
877 | if id: | |
877 | applied.append(l) |
|
878 | applied.append(l) | |
878 | series.append(file) |
|
879 | series.append(file) | |
879 | if datastart == None: |
|
880 | if datastart == None: | |
880 | self.ui.warn("No saved patch data found\n") |
|
881 | self.ui.warn("No saved patch data found\n") | |
881 | return 1 |
|
882 | return 1 | |
882 | self.ui.warn("restoring status: %s\n" % lines[0]) |
|
883 | self.ui.warn("restoring status: %s\n" % lines[0]) | |
883 | self.full_series = series |
|
884 | self.full_series = series | |
884 | self.applied = applied |
|
885 | self.applied = applied | |
885 | self.read_series(self.full_series) |
|
886 | self.read_series(self.full_series) | |
886 | self.series_dirty = 1 |
|
887 | self.series_dirty = 1 | |
887 | self.applied_dirty = 1 |
|
888 | self.applied_dirty = 1 | |
888 | heads = repo.changelog.heads() |
|
889 | heads = repo.changelog.heads() | |
889 | if delete: |
|
890 | if delete: | |
890 | if rev not in heads: |
|
891 | if rev not in heads: | |
891 | self.ui.warn("save entry has children, leaving it alone\n") |
|
892 | self.ui.warn("save entry has children, leaving it alone\n") | |
892 | else: |
|
893 | else: | |
893 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) |
|
894 | self.ui.warn("removing save entry %s\n" % hg.short(rev)) | |
894 | pp = repo.dirstate.parents() |
|
895 | pp = repo.dirstate.parents() | |
895 | if rev in pp: |
|
896 | if rev in pp: | |
896 | update = True |
|
897 | update = True | |
897 | else: |
|
898 | else: | |
898 | update = False |
|
899 | update = False | |
899 | self.strip(repo, rev, update=update, backup='strip') |
|
900 | self.strip(repo, rev, update=update, backup='strip') | |
900 | if qpp: |
|
901 | if qpp: | |
901 | self.ui.warn("saved queue repository parents: %s %s\n" % |
|
902 | self.ui.warn("saved queue repository parents: %s %s\n" % | |
902 | (hg.short(qpp[0]), hg.short(qpp[1]))) |
|
903 | (hg.short(qpp[0]), hg.short(qpp[1]))) | |
903 | if qupdate: |
|
904 | if qupdate: | |
904 | print "queue directory updating" |
|
905 | print "queue directory updating" | |
905 | r = self.qrepo() |
|
906 | r = self.qrepo() | |
906 | if not r: |
|
907 | if not r: | |
907 | self.ui.warn("Unable to load queue repository\n") |
|
908 | self.ui.warn("Unable to load queue repository\n") | |
908 | return 1 |
|
909 | return 1 | |
909 | r.update(qpp[0], allow=False, force=True) |
|
910 | r.update(qpp[0], allow=False, force=True) | |
910 |
|
911 | |||
911 | def save(self, repo, msg=None): |
|
912 | def save(self, repo, msg=None): | |
912 | if len(self.applied) == 0: |
|
913 | if len(self.applied) == 0: | |
913 | self.ui.warn("save: no patches applied, exiting\n") |
|
914 | self.ui.warn("save: no patches applied, exiting\n") | |
914 | return 1 |
|
915 | return 1 | |
915 | if self.issaveline(self.applied[-1]): |
|
916 | if self.issaveline(self.applied[-1]): | |
916 | self.ui.warn("status is already saved\n") |
|
917 | self.ui.warn("status is already saved\n") | |
917 | return 1 |
|
918 | return 1 | |
918 |
|
919 | |||
919 | ar = [ ':' + x for x in self.full_series ] |
|
920 | ar = [ ':' + x for x in self.full_series ] | |
920 | if not msg: |
|
921 | if not msg: | |
921 | msg = "hg patches saved state" |
|
922 | msg = "hg patches saved state" | |
922 | else: |
|
923 | else: | |
923 | msg = "hg patches: " + msg.rstrip('\r\n') |
|
924 | msg = "hg patches: " + msg.rstrip('\r\n') | |
924 | r = self.qrepo() |
|
925 | r = self.qrepo() | |
925 | if r: |
|
926 | if r: | |
926 | pp = r.dirstate.parents() |
|
927 | pp = r.dirstate.parents() | |
927 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) |
|
928 | msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1])) | |
928 | msg += "\n\nPatch Data:\n" |
|
929 | msg += "\n\nPatch Data:\n" | |
929 | text = msg + "\n".join(self.applied) + '\n' + (ar and "\n".join(ar) |
|
930 | text = msg + "\n".join(self.applied) + '\n' + (ar and "\n".join(ar) | |
930 | + '\n' or "") |
|
931 | + '\n' or "") | |
931 | n = repo.commit(None, text, user=None, force=1) |
|
932 | n = repo.commit(None, text, user=None, force=1) | |
932 | if not n: |
|
933 | if not n: | |
933 | self.ui.warn("repo commit failed\n") |
|
934 | self.ui.warn("repo commit failed\n") | |
934 | return 1 |
|
935 | return 1 | |
935 | self.applied.append(revlog.hex(n) + ":" + '.hg.patches.save.line') |
|
936 | self.applied.append(revlog.hex(n) + ":" + '.hg.patches.save.line') | |
936 | self.applied_dirty = 1 |
|
937 | self.applied_dirty = 1 | |
937 |
|
938 | |||
938 | def series_end(self): |
|
939 | def series_end(self): | |
939 | end = 0 |
|
940 | end = 0 | |
940 | if len(self.applied) > 0: |
|
941 | if len(self.applied) > 0: | |
941 | (top, p) = self.applied[-1].split(':') |
|
942 | (top, p) = self.applied[-1].split(':') | |
942 | try: |
|
943 | try: | |
943 | end = self.series.index(p) |
|
944 | end = self.series.index(p) | |
944 | except ValueError: |
|
945 | except ValueError: | |
945 | return 0 |
|
946 | return 0 | |
946 | return end + 1 |
|
947 | return end + 1 | |
947 | return end |
|
948 | return end | |
948 |
|
949 | |||
949 | def qapplied(self, repo, patch=None): |
|
950 | def qapplied(self, repo, patch=None): | |
950 | if patch and patch not in self.series: |
|
951 | if patch and patch not in self.series: | |
951 | self.ui.warn("%s not in the series file\n" % patch) |
|
952 | self.ui.warn("%s not in the series file\n" % patch) | |
952 | sys.exit(1) |
|
953 | sys.exit(1) | |
953 | if not patch: |
|
954 | if not patch: | |
954 | end = len(self.applied) |
|
955 | end = len(self.applied) | |
955 | else: |
|
956 | else: | |
956 | end = self.series.index(patch) + 1 |
|
957 | end = self.series.index(patch) + 1 | |
957 | for x in xrange(end): |
|
958 | for x in xrange(end): | |
958 | p = self.appliedname(x) |
|
959 | p = self.appliedname(x) | |
959 | self.ui.write("%s\n" % p) |
|
960 | self.ui.write("%s\n" % p) | |
960 |
|
961 | |||
961 | def appliedname(self, index): |
|
962 | def appliedname(self, index): | |
962 | p = self.applied[index] |
|
963 | p = self.applied[index] | |
963 | if not self.ui.verbose: |
|
964 | if not self.ui.verbose: | |
964 | p = p.split(':')[1] |
|
965 | p = p.split(':')[1] | |
965 | return p |
|
966 | return p | |
966 |
|
967 | |||
967 | def top(self, repo): |
|
968 | def top(self, repo): | |
968 | if len(self.applied): |
|
969 | if len(self.applied): | |
969 | p = self.appliedname(-1) |
|
970 | p = self.appliedname(-1) | |
970 | self.ui.write(p + '\n') |
|
971 | self.ui.write(p + '\n') | |
971 | else: |
|
972 | else: | |
972 | self.ui.write("No patches applied\n") |
|
973 | self.ui.write("No patches applied\n") | |
973 |
|
974 | |||
974 | def next(self, repo): |
|
975 | def next(self, repo): | |
975 | end = self.series_end() |
|
976 | end = self.series_end() | |
976 | if end == len(self.series): |
|
977 | if end == len(self.series): | |
977 | self.ui.write("All patches applied\n") |
|
978 | self.ui.write("All patches applied\n") | |
978 | else: |
|
979 | else: | |
979 | self.ui.write(self.series[end] + '\n') |
|
980 | self.ui.write(self.series[end] + '\n') | |
980 |
|
981 | |||
981 | def prev(self, repo): |
|
982 | def prev(self, repo): | |
982 | if len(self.applied) > 1: |
|
983 | if len(self.applied) > 1: | |
983 | p = self.appliedname(-2) |
|
984 | p = self.appliedname(-2) | |
984 | self.ui.write(p + '\n') |
|
985 | self.ui.write(p + '\n') | |
985 | elif len(self.applied) == 1: |
|
986 | elif len(self.applied) == 1: | |
986 | self.ui.write("Only one patch applied\n") |
|
987 | self.ui.write("Only one patch applied\n") | |
987 | else: |
|
988 | else: | |
988 | self.ui.write("No patches applied\n") |
|
989 | self.ui.write("No patches applied\n") | |
989 |
|
990 | |||
990 | def qimport(self, repo, files, patch=None, existing=None, force=None): |
|
991 | def qimport(self, repo, files, patch=None, existing=None, force=None): | |
991 | if len(files) > 1 and patch: |
|
992 | if len(files) > 1 and patch: | |
992 | self.ui.warn("-n option not valid when importing multiple files\n") |
|
993 | self.ui.warn("-n option not valid when importing multiple files\n") | |
993 | sys.exit(1) |
|
994 | sys.exit(1) | |
994 | i = 0 |
|
995 | i = 0 | |
995 | for filename in files: |
|
996 | for filename in files: | |
996 | if existing: |
|
997 | if existing: | |
997 | if not patch: |
|
998 | if not patch: | |
998 | patch = filename |
|
999 | patch = filename | |
999 | if not os.path.isfile(os.path.join(self.path, patch)): |
|
1000 | if not os.path.isfile(os.path.join(self.path, patch)): | |
1000 | self.ui.warn("patch %s does not exist\n" % patch) |
|
1001 | self.ui.warn("patch %s does not exist\n" % patch) | |
1001 | sys.exit(1) |
|
1002 | sys.exit(1) | |
1002 | else: |
|
1003 | else: | |
1003 | try: |
|
1004 | try: | |
1004 | text = file(filename).read() |
|
1005 | text = file(filename).read() | |
1005 | except IOError: |
|
1006 | except IOError: | |
1006 | self.ui.warn("Unable to read %s\n" % patch) |
|
1007 | self.ui.warn("Unable to read %s\n" % patch) | |
1007 | sys.exit(1) |
|
1008 | sys.exit(1) | |
1008 | if not patch: |
|
1009 | if not patch: | |
1009 | patch = os.path.split(filename)[1] |
|
1010 | patch = os.path.split(filename)[1] | |
1010 | if not force and os.path.isfile(os.path.join(self.path, patch)): |
|
1011 | if not force and os.path.isfile(os.path.join(self.path, patch)): | |
1011 | self.ui.warn("patch %s already exists\n" % patch) |
|
1012 | self.ui.warn("patch %s already exists\n" % patch) | |
1012 | sys.exit(1) |
|
1013 | sys.exit(1) | |
1013 | patchf = self.opener(patch, "w") |
|
1014 | patchf = self.opener(patch, "w") | |
1014 | patchf.write(text) |
|
1015 | patchf.write(text) | |
1015 | if patch in self.series: |
|
1016 | if patch in self.series: | |
1016 | self.ui.warn("patch %s is already in the series file\n" % patch) |
|
1017 | self.ui.warn("patch %s is already in the series file\n" % patch) | |
1017 | sys.exit(1) |
|
1018 | sys.exit(1) | |
1018 | index = self.series_end() + i |
|
1019 | index = self.series_end() + i | |
1019 | self.full_series[index:index] = [patch] |
|
1020 | self.full_series[index:index] = [patch] | |
1020 | self.read_series(self.full_series) |
|
1021 | self.read_series(self.full_series) | |
1021 | self.ui.warn("adding %s to series file\n" % patch) |
|
1022 | self.ui.warn("adding %s to series file\n" % patch) | |
1022 | i += 1 |
|
1023 | i += 1 | |
1023 | patch = None |
|
1024 | patch = None | |
1024 | self.series_dirty = 1 |
|
1025 | self.series_dirty = 1 | |
1025 |
|
1026 | |||
1026 | def delete(ui, repo, patch, **opts): |
|
1027 | def delete(ui, repo, patch, **opts): | |
1027 | """remove a patch from the series file""" |
|
1028 | """remove a patch from the series file""" | |
1028 | q = repomap[repo] |
|
1029 | q = repomap[repo] | |
1029 | q.delete(repo, patch) |
|
1030 | q.delete(repo, patch) | |
1030 | q.save_dirty() |
|
1031 | q.save_dirty() | |
1031 | return 0 |
|
1032 | return 0 | |
1032 |
|
1033 | |||
1033 | def applied(ui, repo, patch=None, **opts): |
|
1034 | def applied(ui, repo, patch=None, **opts): | |
1034 | """print the patches already applied""" |
|
1035 | """print the patches already applied""" | |
1035 | repomap[repo].qapplied(repo, patch) |
|
1036 | repomap[repo].qapplied(repo, patch) | |
1036 | return 0 |
|
1037 | return 0 | |
1037 |
|
1038 | |||
1038 | def unapplied(ui, repo, patch=None, **opts): |
|
1039 | def unapplied(ui, repo, patch=None, **opts): | |
1039 | """print the patches not yet applied""" |
|
1040 | """print the patches not yet applied""" | |
1040 | repomap[repo].unapplied(repo, patch) |
|
1041 | repomap[repo].unapplied(repo, patch) | |
1041 | return 0 |
|
1042 | return 0 | |
1042 |
|
1043 | |||
1043 | def qimport(ui, repo, *filename, **opts): |
|
1044 | def qimport(ui, repo, *filename, **opts): | |
1044 | """import a patch""" |
|
1045 | """import a patch""" | |
1045 | q = repomap[repo] |
|
1046 | q = repomap[repo] | |
1046 | q.qimport(repo, filename, patch=opts['name'], |
|
1047 | q.qimport(repo, filename, patch=opts['name'], | |
1047 | existing=opts['existing'], force=opts['force']) |
|
1048 | existing=opts['existing'], force=opts['force']) | |
1048 | q.save_dirty() |
|
1049 | q.save_dirty() | |
1049 | return 0 |
|
1050 | return 0 | |
1050 |
|
1051 | |||
1051 | def init(ui, repo, **opts): |
|
1052 | def init(ui, repo, **opts): | |
1052 | """init a new queue repository""" |
|
1053 | """init a new queue repository""" | |
1053 | q = repomap[repo] |
|
1054 | q = repomap[repo] | |
1054 | r = q.init(repo, create=opts['create_repo']) |
|
1055 | r = q.init(repo, create=opts['create_repo']) | |
1055 | q.save_dirty() |
|
1056 | q.save_dirty() | |
1056 | if r: |
|
1057 | if r: | |
1057 | fp = r.wopener('.hgignore', 'w') |
|
1058 | fp = r.wopener('.hgignore', 'w') | |
1058 | print >> fp, 'syntax: glob' |
|
1059 | print >> fp, 'syntax: glob' | |
1059 | print >> fp, 'status' |
|
1060 | print >> fp, 'status' | |
1060 | fp.close() |
|
1061 | fp.close() | |
1061 | r.wopener('series', 'w').close() |
|
1062 | r.wopener('series', 'w').close() | |
1062 | r.add(['.hgignore', 'series']) |
|
1063 | r.add(['.hgignore', 'series']) | |
1063 | return 0 |
|
1064 | return 0 | |
1064 |
|
1065 | |||
1065 | def commit(ui, repo, *pats, **opts): |
|
1066 | def commit(ui, repo, *pats, **opts): | |
1066 | q = repomap[repo] |
|
1067 | q = repomap[repo] | |
1067 | r = q.qrepo() |
|
1068 | r = q.qrepo() | |
1068 | if not r: raise util.Abort('no queue repository') |
|
1069 | if not r: raise util.Abort('no queue repository') | |
1069 | commands.commit(r.ui, r, *pats, **opts) |
|
1070 | commands.commit(r.ui, r, *pats, **opts) | |
1070 |
|
1071 | |||
1071 | def series(ui, repo, **opts): |
|
1072 | def series(ui, repo, **opts): | |
1072 | """print the entire series file""" |
|
1073 | """print the entire series file""" | |
1073 | repomap[repo].qseries(repo, missing=opts['missing']) |
|
1074 | repomap[repo].qseries(repo, missing=opts['missing']) | |
1074 | return 0 |
|
1075 | return 0 | |
1075 |
|
1076 | |||
1076 | def top(ui, repo, **opts): |
|
1077 | def top(ui, repo, **opts): | |
1077 | """print the name of the current patch""" |
|
1078 | """print the name of the current patch""" | |
1078 | repomap[repo].top(repo) |
|
1079 | repomap[repo].top(repo) | |
1079 | return 0 |
|
1080 | return 0 | |
1080 |
|
1081 | |||
1081 | def next(ui, repo, **opts): |
|
1082 | def next(ui, repo, **opts): | |
1082 | """print the name of the next patch""" |
|
1083 | """print the name of the next patch""" | |
1083 | repomap[repo].next(repo) |
|
1084 | repomap[repo].next(repo) | |
1084 | return 0 |
|
1085 | return 0 | |
1085 |
|
1086 | |||
1086 | def prev(ui, repo, **opts): |
|
1087 | def prev(ui, repo, **opts): | |
1087 | """print the name of the previous patch""" |
|
1088 | """print the name of the previous patch""" | |
1088 | repomap[repo].prev(repo) |
|
1089 | repomap[repo].prev(repo) | |
1089 | return 0 |
|
1090 | return 0 | |
1090 |
|
1091 | |||
1091 | def new(ui, repo, patch, **opts): |
|
1092 | def new(ui, repo, patch, **opts): | |
1092 | """create a new patch""" |
|
1093 | """create a new patch""" | |
1093 | q = repomap[repo] |
|
1094 | q = repomap[repo] | |
1094 | q.new(repo, patch, msg=opts['message'], force=opts['force']) |
|
1095 | q.new(repo, patch, msg=opts['message'], force=opts['force']) | |
1095 | q.save_dirty() |
|
1096 | q.save_dirty() | |
1096 | return 0 |
|
1097 | return 0 | |
1097 |
|
1098 | |||
1098 | def refresh(ui, repo, **opts): |
|
1099 | def refresh(ui, repo, **opts): | |
1099 | """update the current patch""" |
|
1100 | """update the current patch""" | |
1100 | q = repomap[repo] |
|
1101 | q = repomap[repo] | |
1101 | q.refresh(repo, short=opts['short']) |
|
1102 | q.refresh(repo, short=opts['short']) | |
1102 | q.save_dirty() |
|
1103 | q.save_dirty() | |
1103 | return 0 |
|
1104 | return 0 | |
1104 |
|
1105 | |||
1105 | def diff(ui, repo, *files, **opts): |
|
1106 | def diff(ui, repo, *files, **opts): | |
1106 | """diff of the current patch""" |
|
1107 | """diff of the current patch""" | |
1107 | repomap[repo].diff(repo, files) |
|
1108 | repomap[repo].diff(repo, files) | |
1108 | return 0 |
|
1109 | return 0 | |
1109 |
|
1110 | |||
1110 | def lastsavename(path): |
|
1111 | def lastsavename(path): | |
1111 | (dir, base) = os.path.split(path) |
|
1112 | (dir, base) = os.path.split(path) | |
1112 | names = os.listdir(dir) |
|
1113 | names = os.listdir(dir) | |
1113 | namere = re.compile("%s.([0-9]+)" % base) |
|
1114 | namere = re.compile("%s.([0-9]+)" % base) | |
1114 | max = None |
|
1115 | max = None | |
1115 | maxname = None |
|
1116 | maxname = None | |
1116 | for f in names: |
|
1117 | for f in names: | |
1117 | m = namere.match(f) |
|
1118 | m = namere.match(f) | |
1118 | if m: |
|
1119 | if m: | |
1119 | index = int(m.group(1)) |
|
1120 | index = int(m.group(1)) | |
1120 | if max == None or index > max: |
|
1121 | if max == None or index > max: | |
1121 | max = index |
|
1122 | max = index | |
1122 | maxname = f |
|
1123 | maxname = f | |
1123 | if maxname: |
|
1124 | if maxname: | |
1124 | return (os.path.join(dir, maxname), max) |
|
1125 | return (os.path.join(dir, maxname), max) | |
1125 | return (None, None) |
|
1126 | return (None, None) | |
1126 |
|
1127 | |||
1127 | def savename(path): |
|
1128 | def savename(path): | |
1128 | (last, index) = lastsavename(path) |
|
1129 | (last, index) = lastsavename(path) | |
1129 | if last is None: |
|
1130 | if last is None: | |
1130 | index = 0 |
|
1131 | index = 0 | |
1131 | newpath = path + ".%d" % (index + 1) |
|
1132 | newpath = path + ".%d" % (index + 1) | |
1132 | return newpath |
|
1133 | return newpath | |
1133 |
|
1134 | |||
1134 | def push(ui, repo, patch=None, **opts): |
|
1135 | def push(ui, repo, patch=None, **opts): | |
1135 | """push the next patch onto the stack""" |
|
1136 | """push the next patch onto the stack""" | |
1136 | q = repomap[repo] |
|
1137 | q = repomap[repo] | |
1137 | mergeq = None |
|
1138 | mergeq = None | |
1138 |
|
1139 | |||
1139 | if opts['all']: |
|
1140 | if opts['all']: | |
1140 | patch = q.series[-1] |
|
1141 | patch = q.series[-1] | |
1141 | if opts['merge']: |
|
1142 | if opts['merge']: | |
1142 | if opts['name']: |
|
1143 | if opts['name']: | |
1143 | newpath = opts['name'] |
|
1144 | newpath = opts['name'] | |
1144 | else: |
|
1145 | else: | |
1145 | newpath, i = lastsavename(q.path) |
|
1146 | newpath, i = lastsavename(q.path) | |
1146 | if not newpath: |
|
1147 | if not newpath: | |
1147 | ui.warn("no saved queues found, please use -n\n") |
|
1148 | ui.warn("no saved queues found, please use -n\n") | |
1148 | return 1 |
|
1149 | return 1 | |
1149 | mergeq = queue(ui, repo.join(""), newpath) |
|
1150 | mergeq = queue(ui, repo.join(""), newpath) | |
1150 | ui.warn("merging with queue at: %s\n" % mergeq.path) |
|
1151 | ui.warn("merging with queue at: %s\n" % mergeq.path) | |
1151 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
|
1152 | ret = q.push(repo, patch, force=opts['force'], list=opts['list'], | |
1152 | mergeq=mergeq) |
|
1153 | mergeq=mergeq) | |
1153 | q.save_dirty() |
|
1154 | q.save_dirty() | |
1154 | return ret |
|
1155 | return ret | |
1155 |
|
1156 | |||
1156 | def pop(ui, repo, patch=None, **opts): |
|
1157 | def pop(ui, repo, patch=None, **opts): | |
1157 | """pop the current patch off the stack""" |
|
1158 | """pop the current patch off the stack""" | |
1158 | localupdate = True |
|
1159 | localupdate = True | |
1159 | if opts['name']: |
|
1160 | if opts['name']: | |
1160 | q = queue(ui, repo.join(""), repo.join(opts['name'])) |
|
1161 | q = queue(ui, repo.join(""), repo.join(opts['name'])) | |
1161 | ui.warn('using patch queue: %s\n' % q.path) |
|
1162 | ui.warn('using patch queue: %s\n' % q.path) | |
1162 | localupdate = False |
|
1163 | localupdate = False | |
1163 | else: |
|
1164 | else: | |
1164 | q = repomap[repo] |
|
1165 | q = repomap[repo] | |
1165 | if opts['all'] and len(q.applied) > 0: |
|
1166 | if opts['all'] and len(q.applied) > 0: | |
1166 | patch = q.applied[0].split(':')[1] |
|
1167 | patch = q.applied[0].split(':')[1] | |
1167 | q.pop(repo, patch, force=opts['force'], update=localupdate) |
|
1168 | q.pop(repo, patch, force=opts['force'], update=localupdate) | |
1168 | q.save_dirty() |
|
1169 | q.save_dirty() | |
1169 | return 0 |
|
1170 | return 0 | |
1170 |
|
1171 | |||
1171 | def restore(ui, repo, rev, **opts): |
|
1172 | def restore(ui, repo, rev, **opts): | |
1172 | """restore the queue state saved by a rev""" |
|
1173 | """restore the queue state saved by a rev""" | |
1173 | rev = repo.lookup(rev) |
|
1174 | rev = repo.lookup(rev) | |
1174 | q = repomap[repo] |
|
1175 | q = repomap[repo] | |
1175 | q.restore(repo, rev, delete=opts['delete'], |
|
1176 | q.restore(repo, rev, delete=opts['delete'], | |
1176 | qupdate=opts['update']) |
|
1177 | qupdate=opts['update']) | |
1177 | q.save_dirty() |
|
1178 | q.save_dirty() | |
1178 | return 0 |
|
1179 | return 0 | |
1179 |
|
1180 | |||
1180 | def save(ui, repo, **opts): |
|
1181 | def save(ui, repo, **opts): | |
1181 | """save current queue state""" |
|
1182 | """save current queue state""" | |
1182 | q = repomap[repo] |
|
1183 | q = repomap[repo] | |
1183 | ret = q.save(repo, msg=opts['message']) |
|
1184 | ret = q.save(repo, msg=opts['message']) | |
1184 | if ret: |
|
1185 | if ret: | |
1185 | return ret |
|
1186 | return ret | |
1186 | q.save_dirty() |
|
1187 | q.save_dirty() | |
1187 | if opts['copy']: |
|
1188 | if opts['copy']: | |
1188 | path = q.path |
|
1189 | path = q.path | |
1189 | if opts['name']: |
|
1190 | if opts['name']: | |
1190 | newpath = os.path.join(q.basepath, opts['name']) |
|
1191 | newpath = os.path.join(q.basepath, opts['name']) | |
1191 | if os.path.exists(newpath): |
|
1192 | if os.path.exists(newpath): | |
1192 | if not os.path.isdir(newpath): |
|
1193 | if not os.path.isdir(newpath): | |
1193 | ui.warn("destination %s exists and is not a directory\n" % |
|
1194 | ui.warn("destination %s exists and is not a directory\n" % | |
1194 | newpath) |
|
1195 | newpath) | |
1195 | sys.exit(1) |
|
1196 | sys.exit(1) | |
1196 | if not opts['force']: |
|
1197 | if not opts['force']: | |
1197 | ui.warn("destination %s exists, use -f to force\n" % |
|
1198 | ui.warn("destination %s exists, use -f to force\n" % | |
1198 | newpath) |
|
1199 | newpath) | |
1199 | sys.exit(1) |
|
1200 | sys.exit(1) | |
1200 | else: |
|
1201 | else: | |
1201 | newpath = savename(path) |
|
1202 | newpath = savename(path) | |
1202 | ui.warn("copy %s to %s\n" % (path, newpath)) |
|
1203 | ui.warn("copy %s to %s\n" % (path, newpath)) | |
1203 | util.copyfiles(path, newpath) |
|
1204 | util.copyfiles(path, newpath) | |
1204 | if opts['empty']: |
|
1205 | if opts['empty']: | |
1205 | try: |
|
1206 | try: | |
1206 | os.unlink(os.path.join(q.path, q.status_path)) |
|
1207 | os.unlink(os.path.join(q.path, q.status_path)) | |
1207 | except: |
|
1208 | except: | |
1208 | pass |
|
1209 | pass | |
1209 | return 0 |
|
1210 | return 0 | |
1210 |
|
1211 | |||
1211 | def strip(ui, repo, rev, **opts): |
|
1212 | def strip(ui, repo, rev, **opts): | |
1212 | """strip a revision and all later revs on the same branch""" |
|
1213 | """strip a revision and all later revs on the same branch""" | |
1213 | rev = repo.lookup(rev) |
|
1214 | rev = repo.lookup(rev) | |
1214 | backup = 'all' |
|
1215 | backup = 'all' | |
1215 | if opts['backup']: |
|
1216 | if opts['backup']: | |
1216 | backup = 'strip' |
|
1217 | backup = 'strip' | |
1217 | elif opts['nobackup']: |
|
1218 | elif opts['nobackup']: | |
1218 | backup = 'none' |
|
1219 | backup = 'none' | |
1219 | repomap[repo].strip(repo, rev, backup=backup) |
|
1220 | repomap[repo].strip(repo, rev, backup=backup) | |
1220 | return 0 |
|
1221 | return 0 | |
1221 |
|
1222 | |||
1222 | def version(ui, q=None): |
|
1223 | def version(ui, q=None): | |
1223 | """print the version number""" |
|
1224 | """print the version number""" | |
1224 | ui.write("mq version %s\n" % versionstr) |
|
1225 | ui.write("mq version %s\n" % versionstr) | |
1225 | return 0 |
|
1226 | return 0 | |
1226 |
|
1227 | |||
1227 | def reposetup(ui, repo): |
|
1228 | def reposetup(ui, repo): | |
1228 | repomap[repo] = queue(ui, repo.join("")) |
|
1229 | repomap[repo] = queue(ui, repo.join("")) | |
1229 |
|
1230 | |||
1230 | cmdtable = { |
|
1231 | cmdtable = { | |
1231 | "qapplied": (applied, [], 'hg qapplied [patch]'), |
|
1232 | "qapplied": (applied, [], 'hg qapplied [patch]'), | |
1232 | "qcommit|qci": |
|
1233 | "qcommit|qci": | |
1233 | (commit, |
|
1234 | (commit, | |
1234 | [('A', 'addremove', None, _('run addremove during commit')), |
|
1235 | [('A', 'addremove', None, _('run addremove during commit')), | |
1235 | ('I', 'include', [], _('include names matching the given patterns')), |
|
1236 | ('I', 'include', [], _('include names matching the given patterns')), | |
1236 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
1237 | ('X', 'exclude', [], _('exclude names matching the given patterns')), | |
1237 | ('m', 'message', '', _('use <text> as commit message')), |
|
1238 | ('m', 'message', '', _('use <text> as commit message')), | |
1238 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
1239 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
1239 | ('d', 'date', '', _('record datecode as commit date')), |
|
1240 | ('d', 'date', '', _('record datecode as commit date')), | |
1240 | ('u', 'user', '', _('record user as commiter'))], |
|
1241 | ('u', 'user', '', _('record user as commiter'))], | |
1241 | 'hg qcommit [options] [files]'), |
|
1242 | 'hg qcommit [options] [files]'), | |
1242 | "^qdiff": (diff, [], 'hg qdiff [files]'), |
|
1243 | "^qdiff": (diff, [], 'hg qdiff [files]'), | |
1243 | "qdelete": (delete, [], 'hg qdelete [patch]'), |
|
1244 | "qdelete": (delete, [], 'hg qdelete [patch]'), | |
1244 | "^qimport": |
|
1245 | "^qimport": | |
1245 | (qimport, |
|
1246 | (qimport, | |
1246 | [('e', 'existing', None, 'import file in patch dir'), |
|
1247 | [('e', 'existing', None, 'import file in patch dir'), | |
1247 | ('n', 'name', '', 'patch file name'), |
|
1248 | ('n', 'name', '', 'patch file name'), | |
1248 | ('f', 'force', None, 'overwrite existing files')], |
|
1249 | ('f', 'force', None, 'overwrite existing files')], | |
1249 | 'hg qimport'), |
|
1250 | 'hg qimport'), | |
1250 | "^qinit": |
|
1251 | "^qinit": | |
1251 | (init, |
|
1252 | (init, | |
1252 | [('c', 'create-repo', None, 'create patch repository')], |
|
1253 | [('c', 'create-repo', None, 'create patch repository')], | |
1253 | 'hg [-c] qinit'), |
|
1254 | 'hg [-c] qinit'), | |
1254 | "qnew": |
|
1255 | "qnew": | |
1255 | (new, |
|
1256 | (new, | |
1256 | [('m', 'message', '', 'commit message'), |
|
1257 | [('m', 'message', '', 'commit message'), | |
1257 | ('f', 'force', None, 'force')], |
|
1258 | ('f', 'force', None, 'force')], | |
1258 | 'hg qnew [-m message ] patch'), |
|
1259 | 'hg qnew [-m message ] patch'), | |
1259 | "qnext": (next, [], 'hg qnext'), |
|
1260 | "qnext": (next, [], 'hg qnext'), | |
1260 | "qprev": (prev, [], 'hg qprev'), |
|
1261 | "qprev": (prev, [], 'hg qprev'), | |
1261 | "^qpop": |
|
1262 | "^qpop": | |
1262 | (pop, |
|
1263 | (pop, | |
1263 | [('a', 'all', None, 'pop all patches'), |
|
1264 | [('a', 'all', None, 'pop all patches'), | |
1264 | ('n', 'name', '', 'queue name to pop'), |
|
1265 | ('n', 'name', '', 'queue name to pop'), | |
1265 | ('f', 'force', None, 'forget any local changes')], |
|
1266 | ('f', 'force', None, 'forget any local changes')], | |
1266 | 'hg qpop [options] [patch/index]'), |
|
1267 | 'hg qpop [options] [patch/index]'), | |
1267 | "^qpush": |
|
1268 | "^qpush": | |
1268 | (push, |
|
1269 | (push, | |
1269 | [('f', 'force', None, 'apply if the patch has rejects'), |
|
1270 | [('f', 'force', None, 'apply if the patch has rejects'), | |
1270 | ('l', 'list', None, 'list patch name in commit text'), |
|
1271 | ('l', 'list', None, 'list patch name in commit text'), | |
1271 | ('a', 'all', None, 'apply all patches'), |
|
1272 | ('a', 'all', None, 'apply all patches'), | |
1272 | ('m', 'merge', None, 'merge from another queue'), |
|
1273 | ('m', 'merge', None, 'merge from another queue'), | |
1273 | ('n', 'name', '', 'merge queue name')], |
|
1274 | ('n', 'name', '', 'merge queue name')], | |
1274 | 'hg qpush [options] [patch/index]'), |
|
1275 | 'hg qpush [options] [patch/index]'), | |
1275 | "^qrefresh": |
|
1276 | "^qrefresh": | |
1276 | (refresh, |
|
1277 | (refresh, | |
1277 | [('s', 'short', None, 'short refresh')], |
|
1278 | [('s', 'short', None, 'short refresh')], | |
1278 | 'hg qrefresh'), |
|
1279 | 'hg qrefresh'), | |
1279 | "qrestore": |
|
1280 | "qrestore": | |
1280 | (restore, |
|
1281 | (restore, | |
1281 | [('d', 'delete', None, 'delete save entry'), |
|
1282 | [('d', 'delete', None, 'delete save entry'), | |
1282 | ('u', 'update', None, 'update queue working dir')], |
|
1283 | ('u', 'update', None, 'update queue working dir')], | |
1283 | 'hg qrestore rev'), |
|
1284 | 'hg qrestore rev'), | |
1284 | "qsave": |
|
1285 | "qsave": | |
1285 | (save, |
|
1286 | (save, | |
1286 | [('m', 'message', '', 'commit message'), |
|
1287 | [('m', 'message', '', 'commit message'), | |
1287 | ('c', 'copy', None, 'copy patch directory'), |
|
1288 | ('c', 'copy', None, 'copy patch directory'), | |
1288 | ('n', 'name', '', 'copy directory name'), |
|
1289 | ('n', 'name', '', 'copy directory name'), | |
1289 | ('e', 'empty', None, 'clear queue status file'), |
|
1290 | ('e', 'empty', None, 'clear queue status file'), | |
1290 | ('f', 'force', None, 'force copy')], |
|
1291 | ('f', 'force', None, 'force copy')], | |
1291 | 'hg qsave'), |
|
1292 | 'hg qsave'), | |
1292 | "qseries": |
|
1293 | "qseries": | |
1293 | (series, |
|
1294 | (series, | |
1294 | [('m', 'missing', None, 'print patches not in series')], |
|
1295 | [('m', 'missing', None, 'print patches not in series')], | |
1295 | 'hg qseries'), |
|
1296 | 'hg qseries'), | |
1296 | "^strip": |
|
1297 | "^strip": | |
1297 | (strip, |
|
1298 | (strip, | |
1298 | [('f', 'force', None, 'force multi-head removal'), |
|
1299 | [('f', 'force', None, 'force multi-head removal'), | |
1299 | ('b', 'backup', None, 'bundle unrelated changesets'), |
|
1300 | ('b', 'backup', None, 'bundle unrelated changesets'), | |
1300 | ('n', 'nobackup', None, 'no backups')], |
|
1301 | ('n', 'nobackup', None, 'no backups')], | |
1301 | 'hg strip rev'), |
|
1302 | 'hg strip rev'), | |
1302 | "qtop": (top, [], 'hg qtop'), |
|
1303 | "qtop": (top, [], 'hg qtop'), | |
1303 | "qunapplied": (unapplied, [], 'hg qunapplied [patch]'), |
|
1304 | "qunapplied": (unapplied, [], 'hg qunapplied [patch]'), | |
1304 | "qversion": (version, [], 'hg qversion') |
|
1305 | "qversion": (version, [], 'hg qversion') | |
1305 | } |
|
1306 | } | |
1306 |
|
1307 |
@@ -1,183 +1,188 b'' | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 | # |
|
2 | # | |
3 | # hgmerge - default merge helper for Mercurial |
|
3 | # hgmerge - default merge helper for Mercurial | |
4 | # |
|
4 | # | |
5 | # This tries to find a way to do three-way merge on the current system. |
|
5 | # This tries to find a way to do three-way merge on the current system. | |
6 | # The result ought to end up in $1. Script is run in root directory of |
|
6 | # The result ought to end up in $1. Script is run in root directory of | |
7 | # repository. |
|
7 | # repository. | |
8 | # |
|
8 | # | |
9 | # Environment variables set by Mercurial: |
|
9 | # Environment variables set by Mercurial: | |
10 | # HG_FILE name of file within repo |
|
10 | # HG_FILE name of file within repo | |
11 | # HG_MY_NODE revision being merged |
|
11 | # HG_MY_NODE revision being merged | |
12 | # HG_OTHER_NODE revision being merged |
|
12 | # HG_OTHER_NODE revision being merged | |
13 |
|
13 | |||
14 | set -e # bail out quickly on failure |
|
14 | set -e # bail out quickly on failure | |
15 |
|
15 | |||
16 | LOCAL="$1" |
|
16 | LOCAL="$1" | |
17 | BASE="$2" |
|
17 | BASE="$2" | |
18 | OTHER="$3" |
|
18 | OTHER="$3" | |
19 |
|
19 | |||
20 | if [ -z "$EDITOR" ]; then |
|
20 | if [ -z "$EDITOR" ]; then | |
21 | EDITOR="vi" |
|
21 | EDITOR="vi" | |
22 | fi |
|
22 | fi | |
23 |
|
23 | |||
24 | # find decent versions of our utilities, insisting on the GNU versions where we |
|
24 | # find decent versions of our utilities, insisting on the GNU versions where we | |
25 | # need to |
|
25 | # need to | |
26 | MERGE="merge" |
|
26 | MERGE="merge" | |
27 | DIFF3="gdiff3" |
|
27 | DIFF3="gdiff3" | |
28 | DIFF="gdiff" |
|
28 | DIFF="gdiff" | |
29 | PATCH="gpatch" |
|
29 | PATCH="gpatch" | |
30 |
|
30 | |||
31 | type "$MERGE" >/dev/null 2>&1 || MERGE= |
|
31 | type "$MERGE" >/dev/null 2>&1 || MERGE= | |
32 | type "$DIFF3" >/dev/null 2>&1 || DIFF3="diff3" |
|
32 | type "$DIFF3" >/dev/null 2>&1 || DIFF3="diff3" | |
33 | $DIFF3 --version >/dev/null 2>&1 || DIFF3= |
|
33 | $DIFF3 --version >/dev/null 2>&1 || DIFF3= | |
34 | type "$DIFF" >/dev/null 2>&1 || DIFF="diff" |
|
34 | type "$DIFF" >/dev/null 2>&1 || DIFF="diff" | |
35 | type "$DIFF" >/dev/null 2>&1 || DIFF= |
|
35 | type "$DIFF" >/dev/null 2>&1 || DIFF= | |
36 | type "$PATCH" >/dev/null 2>&1 || PATCH="patch" |
|
36 | type "$PATCH" >/dev/null 2>&1 || PATCH="patch" | |
37 | type "$PATCH" >/dev/null 2>&1 || PATCH= |
|
37 | type "$PATCH" >/dev/null 2>&1 || PATCH= | |
38 |
|
38 | |||
39 | # find optional visual utilities |
|
39 | # find optional visual utilities | |
40 | FILEMERGE="/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge" |
|
40 | FILEMERGE="/Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge" | |
41 | KDIFF3="kdiff3" |
|
41 | KDIFF3="kdiff3" | |
42 | TKDIFF="tkdiff" |
|
42 | TKDIFF="tkdiff" | |
43 | MELD="meld" |
|
43 | MELD="meld" | |
44 |
|
44 | |||
45 | type "$FILEMERGE" >/dev/null 2>&1 || FILEMERGE= |
|
45 | type "$FILEMERGE" >/dev/null 2>&1 || FILEMERGE= | |
46 | type "$KDIFF3" >/dev/null 2>&1 || KDIFF3= |
|
46 | type "$KDIFF3" >/dev/null 2>&1 || KDIFF3= | |
47 | type "$TKDIFF" >/dev/null 2>&1 || TKDIFF= |
|
47 | type "$TKDIFF" >/dev/null 2>&1 || TKDIFF= | |
48 | type "$MELD" >/dev/null 2>&1 || MELD= |
|
48 | type "$MELD" >/dev/null 2>&1 || MELD= | |
49 |
|
49 | |||
|
50 | # Hack for Solaris | |||
|
51 | TEST="/usr/bin/test" | |||
|
52 | type "$TEST" >/dev/null 2>&1 || TEST="/bin/test" | |||
|
53 | type "$TEST" >/dev/null 2>&1 || TEST="test" | |||
|
54 | ||||
50 | # random part of names |
|
55 | # random part of names | |
51 | RAND="$RANDOM$RANDOM" |
|
56 | RAND="$RANDOM$RANDOM" | |
52 |
|
57 | |||
53 | # temporary directory for diff+patch merge |
|
58 | # temporary directory for diff+patch merge | |
54 | HGTMP="${TMPDIR-/tmp}/hgmerge.$RAND" |
|
59 | HGTMP="${TMPDIR-/tmp}/hgmerge.$RAND" | |
55 |
|
60 | |||
56 | # backup file |
|
61 | # backup file | |
57 | BACKUP="$LOCAL.orig.$RAND" |
|
62 | BACKUP="$LOCAL.orig.$RAND" | |
58 |
|
63 | |||
59 | # file used to test for file change |
|
64 | # file used to test for file change | |
60 | CHGTEST="$LOCAL.chg.$RAND" |
|
65 | CHGTEST="$LOCAL.chg.$RAND" | |
61 |
|
66 | |||
62 | # put all your required cleanup here |
|
67 | # put all your required cleanup here | |
63 | cleanup() { |
|
68 | cleanup() { | |
64 | rm -f "$BACKUP" "$CHGTEST" |
|
69 | rm -f "$BACKUP" "$CHGTEST" | |
65 | rm -rf "$HGTMP" |
|
70 | rm -rf "$HGTMP" | |
66 | } |
|
71 | } | |
67 |
|
72 | |||
68 | # functions concerning program exit |
|
73 | # functions concerning program exit | |
69 | success() { |
|
74 | success() { | |
70 | cleanup |
|
75 | cleanup | |
71 | exit 0 |
|
76 | exit 0 | |
72 | } |
|
77 | } | |
73 |
|
78 | |||
74 | failure() { |
|
79 | failure() { | |
75 | echo "merge failed" 1>&2 |
|
80 | echo "merge failed" 1>&2 | |
76 | mv "$BACKUP" "$LOCAL" |
|
81 | mv "$BACKUP" "$LOCAL" | |
77 | cleanup |
|
82 | cleanup | |
78 | exit 1 |
|
83 | exit 1 | |
79 | } |
|
84 | } | |
80 |
|
85 | |||
81 | # Ask if the merge was successful |
|
86 | # Ask if the merge was successful | |
82 | ask_if_merged() { |
|
87 | ask_if_merged() { | |
83 | while true; do |
|
88 | while true; do | |
84 | echo "$LOCAL seems unchanged." |
|
89 | echo "$LOCAL seems unchanged." | |
85 | echo "Was the merge successful? [y/n]" |
|
90 | echo "Was the merge successful? [y/n]" | |
86 | read answer |
|
91 | read answer | |
87 | case "$answer" in |
|
92 | case "$answer" in | |
88 | y*|Y*) success;; |
|
93 | y*|Y*) success;; | |
89 | n*|N*) failure;; |
|
94 | n*|N*) failure;; | |
90 | esac |
|
95 | esac | |
91 | done |
|
96 | done | |
92 | } |
|
97 | } | |
93 |
|
98 | |||
94 | # Clean up when interrupted |
|
99 | # Clean up when interrupted | |
95 | trap "failure" 1 2 3 6 15 # HUP INT QUIT ABRT TERM |
|
100 | trap "failure" 1 2 3 6 15 # HUP INT QUIT ABRT TERM | |
96 |
|
101 | |||
97 | # Back up our file (and try hard to keep the mtime unchanged) |
|
102 | # Back up our file (and try hard to keep the mtime unchanged) | |
98 | mv "$LOCAL" "$BACKUP" |
|
103 | mv "$LOCAL" "$BACKUP" | |
99 | cp "$BACKUP" "$LOCAL" |
|
104 | cp "$BACKUP" "$LOCAL" | |
100 |
|
105 | |||
101 | # Attempt to do a non-interactive merge |
|
106 | # Attempt to do a non-interactive merge | |
102 | if [ -n "$MERGE" -o -n "$DIFF3" ]; then |
|
107 | if [ -n "$MERGE" -o -n "$DIFF3" ]; then | |
103 | if [ -n "$MERGE" ]; then |
|
108 | if [ -n "$MERGE" ]; then | |
104 | $MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && success |
|
109 | $MERGE "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && success | |
105 | elif [ -n "$DIFF3" ]; then |
|
110 | elif [ -n "$DIFF3" ]; then | |
106 | $DIFF3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" && success |
|
111 | $DIFF3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" && success | |
107 | fi |
|
112 | fi | |
108 | if [ $? -gt 1 ]; then |
|
113 | if [ $? -gt 1 ]; then | |
109 | echo "automatic merge failed! Exiting." 1>&2 |
|
114 | echo "automatic merge failed! Exiting." 1>&2 | |
110 | failure |
|
115 | failure | |
111 | fi |
|
116 | fi | |
112 | fi |
|
117 | fi | |
113 |
|
118 | |||
114 | # on MacOS X try FileMerge.app, shipped with Apple's developer tools |
|
119 | # on MacOS X try FileMerge.app, shipped with Apple's developer tools | |
115 | if [ -n "$FILEMERGE" ]; then |
|
120 | if [ -n "$FILEMERGE" ]; then | |
116 | cp "$BACKUP" "$LOCAL" |
|
121 | cp "$BACKUP" "$LOCAL" | |
117 | cp "$BACKUP" "$CHGTEST" |
|
122 | cp "$BACKUP" "$CHGTEST" | |
118 | # filemerge prefers the right by default |
|
123 | # filemerge prefers the right by default | |
119 | $FILEMERGE -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL" |
|
124 | $FILEMERGE -left "$OTHER" -right "$LOCAL" -ancestor "$BASE" -merge "$LOCAL" | |
120 | [ $? -ne 0 ] && echo "FileMerge failed to launch" && failure |
|
125 | [ $? -ne 0 ] && echo "FileMerge failed to launch" && failure | |
121 |
|
|
126 | $TEST "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged | |
122 | fi |
|
127 | fi | |
123 |
|
128 | |||
124 | if [ -n "$DISPLAY" ]; then |
|
129 | if [ -n "$DISPLAY" ]; then | |
125 | # try using kdiff3, which is fairly nice |
|
130 | # try using kdiff3, which is fairly nice | |
126 | if [ -n "$KDIFF3" ]; then |
|
131 | if [ -n "$KDIFF3" ]; then | |
127 | $KDIFF3 --auto "$BASE" "$BACKUP" "$OTHER" -o "$LOCAL" || failure |
|
132 | $KDIFF3 --auto "$BASE" "$BACKUP" "$OTHER" -o "$LOCAL" || failure | |
128 | success |
|
133 | success | |
129 | fi |
|
134 | fi | |
130 |
|
135 | |||
131 | # try using tkdiff, which is a bit less sophisticated |
|
136 | # try using tkdiff, which is a bit less sophisticated | |
132 | if [ -n "$TKDIFF" ]; then |
|
137 | if [ -n "$TKDIFF" ]; then | |
133 | $TKDIFF "$BACKUP" "$OTHER" -a "$BASE" -o "$LOCAL" || failure |
|
138 | $TKDIFF "$BACKUP" "$OTHER" -a "$BASE" -o "$LOCAL" || failure | |
134 | success |
|
139 | success | |
135 | fi |
|
140 | fi | |
136 |
|
141 | |||
137 | if [ -n "$MELD" ]; then |
|
142 | if [ -n "$MELD" ]; then | |
138 | cp "$BACKUP" "$CHGTEST" |
|
143 | cp "$BACKUP" "$CHGTEST" | |
139 | # protect our feet - meld allows us to save to the left file |
|
144 | # protect our feet - meld allows us to save to the left file | |
140 | cp "$BACKUP" "$LOCAL.tmp.$RAND" |
|
145 | cp "$BACKUP" "$LOCAL.tmp.$RAND" | |
141 | # Meld doesn't have automatic merging, so to reduce intervention |
|
146 | # Meld doesn't have automatic merging, so to reduce intervention | |
142 | # use the file with conflicts |
|
147 | # use the file with conflicts | |
143 | $MELD "$LOCAL.tmp.$RAND" "$LOCAL" "$OTHER" || failure |
|
148 | $MELD "$LOCAL.tmp.$RAND" "$LOCAL" "$OTHER" || failure | |
144 | # Also it doesn't return good error code |
|
149 | # Also it doesn't return good error code | |
145 |
|
|
150 | $TEST "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged | |
146 | fi |
|
151 | fi | |
147 | fi |
|
152 | fi | |
148 |
|
153 | |||
149 | # Attempt to do a merge with $EDITOR |
|
154 | # Attempt to do a merge with $EDITOR | |
150 | if [ -n "$MERGE" -o -n "$DIFF3" ]; then |
|
155 | if [ -n "$MERGE" -o -n "$DIFF3" ]; then | |
151 | echo "conflicts detected in $LOCAL" |
|
156 | echo "conflicts detected in $LOCAL" | |
152 | cp "$BACKUP" "$CHGTEST" |
|
157 | cp "$BACKUP" "$CHGTEST" | |
153 | $EDITOR "$LOCAL" || failure |
|
158 | $EDITOR "$LOCAL" || failure | |
154 | # Some editors do not return meaningful error codes |
|
159 | # Some editors do not return meaningful error codes | |
155 | # Do not take any chances |
|
160 | # Do not take any chances | |
156 |
|
|
161 | $TEST "$LOCAL" -nt "$CHGTEST" && success || ask_if_merged | |
157 | fi |
|
162 | fi | |
158 |
|
163 | |||
159 | # attempt to manually merge with diff and patch |
|
164 | # attempt to manually merge with diff and patch | |
160 | if [ -n "$DIFF" -a -n "$PATCH" ]; then |
|
165 | if [ -n "$DIFF" -a -n "$PATCH" ]; then | |
161 |
|
166 | |||
162 | (umask 077 && mkdir "$HGTMP") || { |
|
167 | (umask 077 && mkdir "$HGTMP") || { | |
163 | echo "Could not create temporary directory $HGTMP" 1>&2 |
|
168 | echo "Could not create temporary directory $HGTMP" 1>&2 | |
164 | failure |
|
169 | failure | |
165 | } |
|
170 | } | |
166 |
|
171 | |||
167 | $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || : |
|
172 | $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || : | |
168 | if $PATCH "$LOCAL" < "$HGTMP/diff"; then |
|
173 | if $PATCH "$LOCAL" < "$HGTMP/diff"; then | |
169 | success |
|
174 | success | |
170 | else |
|
175 | else | |
171 | # If rejects are empty after using the editor, merge was ok |
|
176 | # If rejects are empty after using the editor, merge was ok | |
172 | $EDITOR "$LOCAL" "$LOCAL.rej" || failure |
|
177 | $EDITOR "$LOCAL" "$LOCAL.rej" || failure | |
173 |
|
|
178 | $TEST -s "$LOCAL.rej" || success | |
174 | fi |
|
179 | fi | |
175 | failure |
|
180 | failure | |
176 | fi |
|
181 | fi | |
177 |
|
182 | |||
178 | echo |
|
183 | echo | |
179 | echo "hgmerge: unable to find any merge utility!" |
|
184 | echo "hgmerge: unable to find any merge utility!" | |
180 | echo "supported programs:" |
|
185 | echo "supported programs:" | |
181 | echo "merge, FileMerge, tkdiff, kdiff3, meld, diff+patch" |
|
186 | echo "merge, FileMerge, tkdiff, kdiff3, meld, diff+patch" | |
182 | echo |
|
187 | echo | |
183 | failure |
|
188 | failure |
@@ -1,3469 +1,3471 b'' | |||||
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 | demandload(globals(), "changegroup") |
|
15 | demandload(globals(), "changegroup") | |
16 |
|
16 | |||
17 | class UnknownCommand(Exception): |
|
17 | class UnknownCommand(Exception): | |
18 | """Exception raised if command is not in the command table.""" |
|
18 | """Exception raised if command is not in the command table.""" | |
19 | class AmbiguousCommand(Exception): |
|
19 | class AmbiguousCommand(Exception): | |
20 | """Exception raised if command shortcut matches more than one command.""" |
|
20 | """Exception raised if command shortcut matches more than one command.""" | |
21 |
|
21 | |||
22 | def filterfiles(filters, files): |
|
22 | def filterfiles(filters, files): | |
23 | l = [x for x in files if x in filters] |
|
23 | l = [x for x in files if x in filters] | |
24 |
|
24 | |||
25 | for t in filters: |
|
25 | for t in filters: | |
26 | if t and t[-1] != "/": |
|
26 | if t and t[-1] != "/": | |
27 | t += "/" |
|
27 | t += "/" | |
28 | l += [x for x in files if x.startswith(t)] |
|
28 | l += [x for x in files if x.startswith(t)] | |
29 | return l |
|
29 | return l | |
30 |
|
30 | |||
31 | def relpath(repo, args): |
|
31 | def relpath(repo, args): | |
32 | cwd = repo.getcwd() |
|
32 | cwd = repo.getcwd() | |
33 | if cwd: |
|
33 | if cwd: | |
34 | return [util.normpath(os.path.join(cwd, x)) for x in args] |
|
34 | return [util.normpath(os.path.join(cwd, x)) for x in args] | |
35 | return args |
|
35 | return args | |
36 |
|
36 | |||
37 | def matchpats(repo, pats=[], opts={}, head=''): |
|
37 | def matchpats(repo, pats=[], opts={}, head=''): | |
38 | cwd = repo.getcwd() |
|
38 | cwd = repo.getcwd() | |
39 | if not pats and cwd: |
|
39 | if not pats and cwd: | |
40 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
|
40 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] | |
41 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
|
41 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] | |
42 | cwd = '' |
|
42 | cwd = '' | |
43 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
43 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), | |
44 | opts.get('exclude'), head) |
|
44 | opts.get('exclude'), head) | |
45 |
|
45 | |||
46 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): |
|
46 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): | |
47 | files, matchfn, anypats = matchpats(repo, pats, opts, head) |
|
47 | files, matchfn, anypats = matchpats(repo, pats, opts, head) | |
48 | exact = dict(zip(files, files)) |
|
48 | exact = dict(zip(files, files)) | |
49 | def walk(): |
|
49 | def walk(): | |
50 | for src, fn in repo.walk(node=node, files=files, match=matchfn, |
|
50 | for src, fn in repo.walk(node=node, files=files, match=matchfn, | |
51 | badmatch=badmatch): |
|
51 | badmatch=badmatch): | |
52 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
52 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact | |
53 | return files, matchfn, walk() |
|
53 | return files, matchfn, walk() | |
54 |
|
54 | |||
55 | def walk(repo, pats, opts, node=None, head='', badmatch=None): |
|
55 | def walk(repo, pats, opts, node=None, head='', badmatch=None): | |
56 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) |
|
56 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) | |
57 | for r in results: |
|
57 | for r in results: | |
58 | yield r |
|
58 | yield r | |
59 |
|
59 | |||
60 | def walkchangerevs(ui, repo, pats, opts): |
|
60 | def walkchangerevs(ui, repo, pats, opts): | |
61 | '''Iterate over files and the revs they changed in. |
|
61 | '''Iterate over files and the revs they changed in. | |
62 |
|
62 | |||
63 | Callers most commonly need to iterate backwards over the history |
|
63 | Callers most commonly need to iterate backwards over the history | |
64 | it is interested in. Doing so has awful (quadratic-looking) |
|
64 | it is interested in. Doing so has awful (quadratic-looking) | |
65 | performance, so we use iterators in a "windowed" way. |
|
65 | performance, so we use iterators in a "windowed" way. | |
66 |
|
66 | |||
67 | We walk a window of revisions in the desired order. Within the |
|
67 | We walk a window of revisions in the desired order. Within the | |
68 | window, we first walk forwards to gather data, then in the desired |
|
68 | window, we first walk forwards to gather data, then in the desired | |
69 | order (usually backwards) to display it. |
|
69 | order (usually backwards) to display it. | |
70 |
|
70 | |||
71 | This function returns an (iterator, getchange, matchfn) tuple. The |
|
71 | This function returns an (iterator, getchange, matchfn) tuple. The | |
72 | getchange function returns the changelog entry for a numeric |
|
72 | getchange function returns the changelog entry for a numeric | |
73 | revision. The iterator yields 3-tuples. They will be of one of |
|
73 | revision. The iterator yields 3-tuples. They will be of one of | |
74 | the following forms: |
|
74 | the following forms: | |
75 |
|
75 | |||
76 | "window", incrementing, lastrev: stepping through a window, |
|
76 | "window", incrementing, lastrev: stepping through a window, | |
77 | positive if walking forwards through revs, last rev in the |
|
77 | positive if walking forwards through revs, last rev in the | |
78 | sequence iterated over - use to reset state for the current window |
|
78 | sequence iterated over - use to reset state for the current window | |
79 |
|
79 | |||
80 | "add", rev, fns: out-of-order traversal of the given file names |
|
80 | "add", rev, fns: out-of-order traversal of the given file names | |
81 | fns, which changed during revision rev - use to gather data for |
|
81 | fns, which changed during revision rev - use to gather data for | |
82 | possible display |
|
82 | possible display | |
83 |
|
83 | |||
84 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
84 | "iter", rev, None: in-order traversal of the revs earlier iterated | |
85 | over with "add" - use to display data''' |
|
85 | over with "add" - use to display data''' | |
86 |
|
86 | |||
87 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
87 | def increasing_windows(start, end, windowsize=8, sizelimit=512): | |
88 | if start < end: |
|
88 | if start < end: | |
89 | while start < end: |
|
89 | while start < end: | |
90 | yield start, min(windowsize, end-start) |
|
90 | yield start, min(windowsize, end-start) | |
91 | start += windowsize |
|
91 | start += windowsize | |
92 | if windowsize < sizelimit: |
|
92 | if windowsize < sizelimit: | |
93 | windowsize *= 2 |
|
93 | windowsize *= 2 | |
94 | else: |
|
94 | else: | |
95 | while start > end: |
|
95 | while start > end: | |
96 | yield start, min(windowsize, start-end-1) |
|
96 | yield start, min(windowsize, start-end-1) | |
97 | start -= windowsize |
|
97 | start -= windowsize | |
98 | if windowsize < sizelimit: |
|
98 | if windowsize < sizelimit: | |
99 | windowsize *= 2 |
|
99 | windowsize *= 2 | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
102 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
103 |
|
103 | |||
104 | if repo.changelog.count() == 0: |
|
104 | if repo.changelog.count() == 0: | |
105 | return [], False, matchfn |
|
105 | return [], False, matchfn | |
106 |
|
106 | |||
107 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
|
107 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) | |
108 | wanted = {} |
|
108 | wanted = {} | |
109 | slowpath = anypats |
|
109 | slowpath = anypats | |
110 | fncache = {} |
|
110 | fncache = {} | |
111 |
|
111 | |||
112 | chcache = {} |
|
112 | chcache = {} | |
113 | def getchange(rev): |
|
113 | def getchange(rev): | |
114 | ch = chcache.get(rev) |
|
114 | ch = chcache.get(rev) | |
115 | if ch is None: |
|
115 | if ch is None: | |
116 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) |
|
116 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) | |
117 | return ch |
|
117 | return ch | |
118 |
|
118 | |||
119 | if not slowpath and not files: |
|
119 | if not slowpath and not files: | |
120 | # No files, no patterns. Display all revs. |
|
120 | # No files, no patterns. Display all revs. | |
121 | wanted = dict(zip(revs, revs)) |
|
121 | wanted = dict(zip(revs, revs)) | |
122 | if not slowpath: |
|
122 | if not slowpath: | |
123 | # Only files, no patterns. Check the history of each file. |
|
123 | # Only files, no patterns. Check the history of each file. | |
124 | def filerevgen(filelog): |
|
124 | def filerevgen(filelog): | |
125 | for i, window in increasing_windows(filelog.count()-1, -1): |
|
125 | for i, window in increasing_windows(filelog.count()-1, -1): | |
126 | revs = [] |
|
126 | revs = [] | |
127 | for j in xrange(i - window, i + 1): |
|
127 | for j in xrange(i - window, i + 1): | |
128 | revs.append(filelog.linkrev(filelog.node(j))) |
|
128 | revs.append(filelog.linkrev(filelog.node(j))) | |
129 | revs.reverse() |
|
129 | revs.reverse() | |
130 | for rev in revs: |
|
130 | for rev in revs: | |
131 | yield rev |
|
131 | yield rev | |
132 |
|
132 | |||
133 | minrev, maxrev = min(revs), max(revs) |
|
133 | minrev, maxrev = min(revs), max(revs) | |
134 | for file_ in files: |
|
134 | for file_ in files: | |
135 | filelog = repo.file(file_) |
|
135 | filelog = repo.file(file_) | |
136 | # A zero count may be a directory or deleted file, so |
|
136 | # A zero count may be a directory or deleted file, so | |
137 | # try to find matching entries on the slow path. |
|
137 | # try to find matching entries on the slow path. | |
138 | if filelog.count() == 0: |
|
138 | if filelog.count() == 0: | |
139 | slowpath = True |
|
139 | slowpath = True | |
140 | break |
|
140 | break | |
141 | for rev in filerevgen(filelog): |
|
141 | for rev in filerevgen(filelog): | |
142 | if rev <= maxrev: |
|
142 | if rev <= maxrev: | |
143 | if rev < minrev: |
|
143 | if rev < minrev: | |
144 | break |
|
144 | break | |
145 | fncache.setdefault(rev, []) |
|
145 | fncache.setdefault(rev, []) | |
146 | fncache[rev].append(file_) |
|
146 | fncache[rev].append(file_) | |
147 | wanted[rev] = 1 |
|
147 | wanted[rev] = 1 | |
148 | if slowpath: |
|
148 | if slowpath: | |
149 | # The slow path checks files modified in every changeset. |
|
149 | # The slow path checks files modified in every changeset. | |
150 | def changerevgen(): |
|
150 | def changerevgen(): | |
151 | for i, window in increasing_windows(repo.changelog.count()-1, -1): |
|
151 | for i, window in increasing_windows(repo.changelog.count()-1, -1): | |
152 | for j in xrange(i - window, i + 1): |
|
152 | for j in xrange(i - window, i + 1): | |
153 | yield j, getchange(j)[3] |
|
153 | yield j, getchange(j)[3] | |
154 |
|
154 | |||
155 | for rev, changefiles in changerevgen(): |
|
155 | for rev, changefiles in changerevgen(): | |
156 | matches = filter(matchfn, changefiles) |
|
156 | matches = filter(matchfn, changefiles) | |
157 | if matches: |
|
157 | if matches: | |
158 | fncache[rev] = matches |
|
158 | fncache[rev] = matches | |
159 | wanted[rev] = 1 |
|
159 | wanted[rev] = 1 | |
160 |
|
160 | |||
161 | def iterate(): |
|
161 | def iterate(): | |
162 | for i, window in increasing_windows(0, len(revs)): |
|
162 | for i, window in increasing_windows(0, len(revs)): | |
163 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
163 | yield 'window', revs[0] < revs[-1], revs[-1] | |
164 | nrevs = [rev for rev in revs[i:i+window] |
|
164 | nrevs = [rev for rev in revs[i:i+window] | |
165 | if rev in wanted] |
|
165 | if rev in wanted] | |
166 | srevs = list(nrevs) |
|
166 | srevs = list(nrevs) | |
167 | srevs.sort() |
|
167 | srevs.sort() | |
168 | for rev in srevs: |
|
168 | for rev in srevs: | |
169 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) |
|
169 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) | |
170 | yield 'add', rev, fns |
|
170 | yield 'add', rev, fns | |
171 | for rev in nrevs: |
|
171 | for rev in nrevs: | |
172 | yield 'iter', rev, None |
|
172 | yield 'iter', rev, None | |
173 | return iterate(), getchange, matchfn |
|
173 | return iterate(), getchange, matchfn | |
174 |
|
174 | |||
175 | revrangesep = ':' |
|
175 | revrangesep = ':' | |
176 |
|
176 | |||
177 | def revrange(ui, repo, revs, revlog=None): |
|
177 | def revrange(ui, repo, revs, revlog=None): | |
178 | """Yield revision as strings from a list of revision specifications.""" |
|
178 | """Yield revision as strings from a list of revision specifications.""" | |
179 | if revlog is None: |
|
179 | if revlog is None: | |
180 | revlog = repo.changelog |
|
180 | revlog = repo.changelog | |
181 | revcount = revlog.count() |
|
181 | revcount = revlog.count() | |
182 | def fix(val, defval): |
|
182 | def fix(val, defval): | |
183 | if not val: |
|
183 | if not val: | |
184 | return defval |
|
184 | return defval | |
185 | try: |
|
185 | try: | |
186 | num = int(val) |
|
186 | num = int(val) | |
187 | if str(num) != val: |
|
187 | if str(num) != val: | |
188 | raise ValueError |
|
188 | raise ValueError | |
189 | if num < 0: |
|
189 | if num < 0: | |
190 | num += revcount |
|
190 | num += revcount | |
191 | if num < 0: |
|
191 | if num < 0: | |
192 | num = 0 |
|
192 | num = 0 | |
193 | elif num >= revcount: |
|
193 | elif num >= revcount: | |
194 | raise ValueError |
|
194 | raise ValueError | |
195 | except ValueError: |
|
195 | except ValueError: | |
196 | try: |
|
196 | try: | |
197 | num = repo.changelog.rev(repo.lookup(val)) |
|
197 | num = repo.changelog.rev(repo.lookup(val)) | |
198 | except KeyError: |
|
198 | except KeyError: | |
199 | try: |
|
199 | try: | |
200 | num = revlog.rev(revlog.lookup(val)) |
|
200 | num = revlog.rev(revlog.lookup(val)) | |
201 | except KeyError: |
|
201 | except KeyError: | |
202 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
202 | raise util.Abort(_('invalid revision identifier %s'), val) | |
203 | return num |
|
203 | return num | |
204 | seen = {} |
|
204 | seen = {} | |
205 | for spec in revs: |
|
205 | for spec in revs: | |
206 | if spec.find(revrangesep) >= 0: |
|
206 | if spec.find(revrangesep) >= 0: | |
207 | start, end = spec.split(revrangesep, 1) |
|
207 | start, end = spec.split(revrangesep, 1) | |
208 | start = fix(start, 0) |
|
208 | start = fix(start, 0) | |
209 | end = fix(end, revcount - 1) |
|
209 | end = fix(end, revcount - 1) | |
210 | step = start > end and -1 or 1 |
|
210 | step = start > end and -1 or 1 | |
211 | for rev in xrange(start, end+step, step): |
|
211 | for rev in xrange(start, end+step, step): | |
212 | if rev in seen: |
|
212 | if rev in seen: | |
213 | continue |
|
213 | continue | |
214 | seen[rev] = 1 |
|
214 | seen[rev] = 1 | |
215 | yield str(rev) |
|
215 | yield str(rev) | |
216 | else: |
|
216 | else: | |
217 | rev = fix(spec, None) |
|
217 | rev = fix(spec, None) | |
218 | if rev in seen: |
|
218 | if rev in seen: | |
219 | continue |
|
219 | continue | |
220 | seen[rev] = 1 |
|
220 | seen[rev] = 1 | |
221 | yield str(rev) |
|
221 | yield str(rev) | |
222 |
|
222 | |||
223 | def make_filename(repo, r, pat, node=None, |
|
223 | def make_filename(repo, r, pat, node=None, | |
224 | total=None, seqno=None, revwidth=None, pathname=None): |
|
224 | total=None, seqno=None, revwidth=None, pathname=None): | |
225 | node_expander = { |
|
225 | node_expander = { | |
226 | 'H': lambda: hex(node), |
|
226 | 'H': lambda: hex(node), | |
227 | 'R': lambda: str(r.rev(node)), |
|
227 | 'R': lambda: str(r.rev(node)), | |
228 | 'h': lambda: short(node), |
|
228 | 'h': lambda: short(node), | |
229 | } |
|
229 | } | |
230 | expander = { |
|
230 | expander = { | |
231 | '%': lambda: '%', |
|
231 | '%': lambda: '%', | |
232 | 'b': lambda: os.path.basename(repo.root), |
|
232 | 'b': lambda: os.path.basename(repo.root), | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | try: |
|
235 | try: | |
236 | if node: |
|
236 | if node: | |
237 | expander.update(node_expander) |
|
237 | expander.update(node_expander) | |
238 | if node and revwidth is not None: |
|
238 | if node and revwidth is not None: | |
239 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) |
|
239 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) | |
240 | if total is not None: |
|
240 | if total is not None: | |
241 | expander['N'] = lambda: str(total) |
|
241 | expander['N'] = lambda: str(total) | |
242 | if seqno is not None: |
|
242 | if seqno is not None: | |
243 | expander['n'] = lambda: str(seqno) |
|
243 | expander['n'] = lambda: str(seqno) | |
244 | if total is not None and seqno is not None: |
|
244 | if total is not None and seqno is not None: | |
245 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) |
|
245 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) | |
246 | if pathname is not None: |
|
246 | if pathname is not None: | |
247 | expander['s'] = lambda: os.path.basename(pathname) |
|
247 | expander['s'] = lambda: os.path.basename(pathname) | |
248 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
248 | expander['d'] = lambda: os.path.dirname(pathname) or '.' | |
249 | expander['p'] = lambda: pathname |
|
249 | expander['p'] = lambda: pathname | |
250 |
|
250 | |||
251 | newname = [] |
|
251 | newname = [] | |
252 | patlen = len(pat) |
|
252 | patlen = len(pat) | |
253 | i = 0 |
|
253 | i = 0 | |
254 | while i < patlen: |
|
254 | while i < patlen: | |
255 | c = pat[i] |
|
255 | c = pat[i] | |
256 | if c == '%': |
|
256 | if c == '%': | |
257 | i += 1 |
|
257 | i += 1 | |
258 | c = pat[i] |
|
258 | c = pat[i] | |
259 | c = expander[c]() |
|
259 | c = expander[c]() | |
260 | newname.append(c) |
|
260 | newname.append(c) | |
261 | i += 1 |
|
261 | i += 1 | |
262 | return ''.join(newname) |
|
262 | return ''.join(newname) | |
263 | except KeyError, inst: |
|
263 | except KeyError, inst: | |
264 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), |
|
264 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), | |
265 | inst.args[0]) |
|
265 | inst.args[0]) | |
266 |
|
266 | |||
267 | def make_file(repo, r, pat, node=None, |
|
267 | def make_file(repo, r, pat, node=None, | |
268 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
268 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): | |
269 | if not pat or pat == '-': |
|
269 | if not pat or pat == '-': | |
270 | return 'w' in mode and sys.stdout or sys.stdin |
|
270 | return 'w' in mode and sys.stdout or sys.stdin | |
271 | if hasattr(pat, 'write') and 'w' in mode: |
|
271 | if hasattr(pat, 'write') and 'w' in mode: | |
272 | return pat |
|
272 | return pat | |
273 | if hasattr(pat, 'read') and 'r' in mode: |
|
273 | if hasattr(pat, 'read') and 'r' in mode: | |
274 | return pat |
|
274 | return pat | |
275 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, |
|
275 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, | |
276 | pathname), |
|
276 | pathname), | |
277 | mode) |
|
277 | mode) | |
278 |
|
278 | |||
279 | def write_bundle(cg, filename=None, compress=True): |
|
279 | def write_bundle(cg, filename=None, compress=True): | |
280 | """Write a bundle file and return its filename. |
|
280 | """Write a bundle file and return its filename. | |
281 |
|
281 | |||
282 | Existing files will not be overwritten. |
|
282 | Existing files will not be overwritten. | |
283 | If no filename is specified, a temporary file is created. |
|
283 | If no filename is specified, a temporary file is created. | |
284 | bz2 compression can be turned off. |
|
284 | bz2 compression can be turned off. | |
285 | The bundle file will be deleted in case of errors. |
|
285 | The bundle file will be deleted in case of errors. | |
286 | """ |
|
286 | """ | |
287 | class nocompress(object): |
|
287 | class nocompress(object): | |
288 | def compress(self, x): |
|
288 | def compress(self, x): | |
289 | return x |
|
289 | return x | |
290 | def flush(self): |
|
290 | def flush(self): | |
291 | return "" |
|
291 | return "" | |
292 |
|
292 | |||
293 | fh = None |
|
293 | fh = None | |
294 | cleanup = None |
|
294 | cleanup = None | |
295 | try: |
|
295 | try: | |
296 | if filename: |
|
296 | if filename: | |
297 | if os.path.exists(filename): |
|
297 | if os.path.exists(filename): | |
298 | raise util.Abort(_("file '%s' already exists"), filename) |
|
298 | raise util.Abort(_("file '%s' already exists"), filename) | |
299 | fh = open(filename, "wb") |
|
299 | fh = open(filename, "wb") | |
300 | else: |
|
300 | else: | |
301 | fd, filename = tempfile.mkstemp(suffix=".hg", prefix="hg-bundle-") |
|
301 | fd, filename = tempfile.mkstemp(suffix=".hg", prefix="hg-bundle-") | |
302 | fh = os.fdopen(fd, "wb") |
|
302 | fh = os.fdopen(fd, "wb") | |
303 | cleanup = filename |
|
303 | cleanup = filename | |
304 |
|
304 | |||
305 | if compress: |
|
305 | if compress: | |
306 | fh.write("HG10") |
|
306 | fh.write("HG10") | |
307 | z = bz2.BZ2Compressor(9) |
|
307 | z = bz2.BZ2Compressor(9) | |
308 | else: |
|
308 | else: | |
309 | fh.write("HG10UN") |
|
309 | fh.write("HG10UN") | |
310 | z = nocompress() |
|
310 | z = nocompress() | |
311 | # parse the changegroup data, otherwise we will block |
|
311 | # parse the changegroup data, otherwise we will block | |
312 | # in case of sshrepo because we don't know the end of the stream |
|
312 | # in case of sshrepo because we don't know the end of the stream | |
313 |
|
313 | |||
314 | # an empty chunkiter is the end of the changegroup |
|
314 | # an empty chunkiter is the end of the changegroup | |
315 | empty = False |
|
315 | empty = False | |
316 | while not empty: |
|
316 | while not empty: | |
317 | empty = True |
|
317 | empty = True | |
318 | for chunk in changegroup.chunkiter(cg): |
|
318 | for chunk in changegroup.chunkiter(cg): | |
319 | empty = False |
|
319 | empty = False | |
320 | fh.write(z.compress(changegroup.genchunk(chunk))) |
|
320 | fh.write(z.compress(changegroup.genchunk(chunk))) | |
321 | fh.write(z.compress(changegroup.closechunk())) |
|
321 | fh.write(z.compress(changegroup.closechunk())) | |
322 | fh.write(z.flush()) |
|
322 | fh.write(z.flush()) | |
323 | cleanup = None |
|
323 | cleanup = None | |
324 | return filename |
|
324 | return filename | |
325 | finally: |
|
325 | finally: | |
326 | if fh is not None: |
|
326 | if fh is not None: | |
327 | fh.close() |
|
327 | fh.close() | |
328 | if cleanup is not None: |
|
328 | if cleanup is not None: | |
329 | os.unlink(cleanup) |
|
329 | os.unlink(cleanup) | |
330 |
|
330 | |||
331 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
331 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | |
332 | changes=None, text=False, opts={}): |
|
332 | changes=None, text=False, opts={}): | |
333 | if not node1: |
|
333 | if not node1: | |
334 | node1 = repo.dirstate.parents()[0] |
|
334 | node1 = repo.dirstate.parents()[0] | |
335 | # reading the data for node1 early allows it to play nicely |
|
335 | # reading the data for node1 early allows it to play nicely | |
336 | # with repo.changes and the revlog cache. |
|
336 | # with repo.changes and the revlog cache. | |
337 | change = repo.changelog.read(node1) |
|
337 | change = repo.changelog.read(node1) | |
338 | mmap = repo.manifest.read(change[0]) |
|
338 | mmap = repo.manifest.read(change[0]) | |
339 | date1 = util.datestr(change[2]) |
|
339 | date1 = util.datestr(change[2]) | |
340 |
|
340 | |||
341 | if not changes: |
|
341 | if not changes: | |
342 | changes = repo.changes(node1, node2, files, match=match) |
|
342 | changes = repo.changes(node1, node2, files, match=match) | |
343 | modified, added, removed, deleted, unknown = changes |
|
343 | modified, added, removed, deleted, unknown = changes | |
344 | if files: |
|
344 | if files: | |
345 | modified, added, removed = map(lambda x: filterfiles(files, x), |
|
345 | modified, added, removed = map(lambda x: filterfiles(files, x), | |
346 | (modified, added, removed)) |
|
346 | (modified, added, removed)) | |
347 |
|
347 | |||
348 | if not modified and not added and not removed: |
|
348 | if not modified and not added and not removed: | |
349 | return |
|
349 | return | |
350 |
|
350 | |||
351 | if node2: |
|
351 | if node2: | |
352 | change = repo.changelog.read(node2) |
|
352 | change = repo.changelog.read(node2) | |
353 | mmap2 = repo.manifest.read(change[0]) |
|
353 | mmap2 = repo.manifest.read(change[0]) | |
354 | date2 = util.datestr(change[2]) |
|
354 | date2 = util.datestr(change[2]) | |
355 | def read(f): |
|
355 | def read(f): | |
356 | return repo.file(f).read(mmap2[f]) |
|
356 | return repo.file(f).read(mmap2[f]) | |
357 | else: |
|
357 | else: | |
358 | date2 = util.datestr() |
|
358 | date2 = util.datestr() | |
359 | def read(f): |
|
359 | def read(f): | |
360 | return repo.wread(f) |
|
360 | return repo.wread(f) | |
361 |
|
361 | |||
362 | if ui.quiet: |
|
362 | if ui.quiet: | |
363 | r = None |
|
363 | r = None | |
364 | else: |
|
364 | else: | |
365 | hexfunc = ui.verbose and hex or short |
|
365 | hexfunc = ui.verbose and hex or short | |
366 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
366 | r = [hexfunc(node) for node in [node1, node2] if node] | |
367 |
|
367 | |||
368 | diffopts = ui.diffopts() |
|
368 | diffopts = ui.diffopts() | |
369 | showfunc = opts.get('show_function') or diffopts['showfunc'] |
|
369 | showfunc = opts.get('show_function') or diffopts['showfunc'] | |
370 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] |
|
370 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] | |
371 | for f in modified: |
|
371 | for f in modified: | |
372 | to = None |
|
372 | to = None | |
373 | if f in mmap: |
|
373 | if f in mmap: | |
374 | to = repo.file(f).read(mmap[f]) |
|
374 | to = repo.file(f).read(mmap[f]) | |
375 | tn = read(f) |
|
375 | tn = read(f) | |
376 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
376 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
377 | showfunc=showfunc, ignorews=ignorews)) |
|
377 | showfunc=showfunc, ignorews=ignorews)) | |
378 | for f in added: |
|
378 | for f in added: | |
379 | to = None |
|
379 | to = None | |
380 | tn = read(f) |
|
380 | tn = read(f) | |
381 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
381 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
382 | showfunc=showfunc, ignorews=ignorews)) |
|
382 | showfunc=showfunc, ignorews=ignorews)) | |
383 | for f in removed: |
|
383 | for f in removed: | |
384 | to = repo.file(f).read(mmap[f]) |
|
384 | to = repo.file(f).read(mmap[f]) | |
385 | tn = None |
|
385 | tn = None | |
386 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, |
|
386 | fp.write(mdiff.unidiff(to, date1, tn, date2, f, r, text=text, | |
387 | showfunc=showfunc, ignorews=ignorews)) |
|
387 | showfunc=showfunc, ignorews=ignorews)) | |
388 |
|
388 | |||
389 | def trimuser(ui, name, rev, revcache): |
|
389 | def trimuser(ui, name, rev, revcache): | |
390 | """trim the name of the user who committed a change""" |
|
390 | """trim the name of the user who committed a change""" | |
391 | user = revcache.get(rev) |
|
391 | user = revcache.get(rev) | |
392 | if user is None: |
|
392 | if user is None: | |
393 | user = revcache[rev] = ui.shortuser(name) |
|
393 | user = revcache[rev] = ui.shortuser(name) | |
394 | return user |
|
394 | return user | |
395 |
|
395 | |||
396 | class changeset_templater(object): |
|
396 | class changeset_templater(object): | |
397 | '''use templater module to format changeset information.''' |
|
397 | '''use templater module to format changeset information.''' | |
398 |
|
398 | |||
399 | def __init__(self, ui, repo, mapfile): |
|
399 | def __init__(self, ui, repo, mapfile): | |
400 | self.t = templater.templater(mapfile, templater.common_filters, |
|
400 | self.t = templater.templater(mapfile, templater.common_filters, | |
401 | cache={'parent': '{rev}:{node|short} ', |
|
401 | cache={'parent': '{rev}:{node|short} ', | |
402 | 'manifest': '{rev}:{node|short}'}) |
|
402 | 'manifest': '{rev}:{node|short}'}) | |
403 | self.ui = ui |
|
403 | self.ui = ui | |
404 | self.repo = repo |
|
404 | self.repo = repo | |
405 |
|
405 | |||
406 | def use_template(self, t): |
|
406 | def use_template(self, t): | |
407 | '''set template string to use''' |
|
407 | '''set template string to use''' | |
408 | self.t.cache['changeset'] = t |
|
408 | self.t.cache['changeset'] = t | |
409 |
|
409 | |||
410 | def write(self, thing, header=False): |
|
410 | def write(self, thing, header=False): | |
411 | '''write expanded template. |
|
411 | '''write expanded template. | |
412 | uses in-order recursive traverse of iterators.''' |
|
412 | uses in-order recursive traverse of iterators.''' | |
413 | for t in thing: |
|
413 | for t in thing: | |
414 | if hasattr(t, '__iter__'): |
|
414 | if hasattr(t, '__iter__'): | |
415 | self.write(t, header=header) |
|
415 | self.write(t, header=header) | |
416 | elif header: |
|
416 | elif header: | |
417 | self.ui.write_header(t) |
|
417 | self.ui.write_header(t) | |
418 | else: |
|
418 | else: | |
419 | self.ui.write(t) |
|
419 | self.ui.write(t) | |
420 |
|
420 | |||
421 | def write_header(self, thing): |
|
421 | def write_header(self, thing): | |
422 | self.write(thing, header=True) |
|
422 | self.write(thing, header=True) | |
423 |
|
423 | |||
424 | def show(self, rev=0, changenode=None, brinfo=None): |
|
424 | def show(self, rev=0, changenode=None, brinfo=None): | |
425 | '''show a single changeset or file revision''' |
|
425 | '''show a single changeset or file revision''' | |
426 | log = self.repo.changelog |
|
426 | log = self.repo.changelog | |
427 | if changenode is None: |
|
427 | if changenode is None: | |
428 | changenode = log.node(rev) |
|
428 | changenode = log.node(rev) | |
429 | elif not rev: |
|
429 | elif not rev: | |
430 | rev = log.rev(changenode) |
|
430 | rev = log.rev(changenode) | |
431 |
|
431 | |||
432 | changes = log.read(changenode) |
|
432 | changes = log.read(changenode) | |
433 |
|
433 | |||
434 | def showlist(name, values, plural=None, **args): |
|
434 | def showlist(name, values, plural=None, **args): | |
435 | '''expand set of values. |
|
435 | '''expand set of values. | |
436 | name is name of key in template map. |
|
436 | name is name of key in template map. | |
437 | values is list of strings or dicts. |
|
437 | values is list of strings or dicts. | |
438 | plural is plural of name, if not simply name + 's'. |
|
438 | plural is plural of name, if not simply name + 's'. | |
439 |
|
439 | |||
440 | expansion works like this, given name 'foo'. |
|
440 | expansion works like this, given name 'foo'. | |
441 |
|
441 | |||
442 | if values is empty, expand 'no_foos'. |
|
442 | if values is empty, expand 'no_foos'. | |
443 |
|
443 | |||
444 | if 'foo' not in template map, return values as a string, |
|
444 | if 'foo' not in template map, return values as a string, | |
445 | joined by space. |
|
445 | joined by space. | |
446 |
|
446 | |||
447 | expand 'start_foos'. |
|
447 | expand 'start_foos'. | |
448 |
|
448 | |||
449 | for each value, expand 'foo'. if 'last_foo' in template |
|
449 | for each value, expand 'foo'. if 'last_foo' in template | |
450 | map, expand it instead of 'foo' for last key. |
|
450 | map, expand it instead of 'foo' for last key. | |
451 |
|
451 | |||
452 | expand 'end_foos'. |
|
452 | expand 'end_foos'. | |
453 | ''' |
|
453 | ''' | |
454 | if plural: names = plural |
|
454 | if plural: names = plural | |
455 | else: names = name + 's' |
|
455 | else: names = name + 's' | |
456 | if not values: |
|
456 | if not values: | |
457 | noname = 'no_' + names |
|
457 | noname = 'no_' + names | |
458 | if noname in self.t: |
|
458 | if noname in self.t: | |
459 | yield self.t(noname, **args) |
|
459 | yield self.t(noname, **args) | |
460 | return |
|
460 | return | |
461 | if name not in self.t: |
|
461 | if name not in self.t: | |
462 | if isinstance(values[0], str): |
|
462 | if isinstance(values[0], str): | |
463 | yield ' '.join(values) |
|
463 | yield ' '.join(values) | |
464 | else: |
|
464 | else: | |
465 | for v in values: |
|
465 | for v in values: | |
466 | yield dict(v, **args) |
|
466 | yield dict(v, **args) | |
467 | return |
|
467 | return | |
468 | startname = 'start_' + names |
|
468 | startname = 'start_' + names | |
469 | if startname in self.t: |
|
469 | if startname in self.t: | |
470 | yield self.t(startname, **args) |
|
470 | yield self.t(startname, **args) | |
471 | vargs = args.copy() |
|
471 | vargs = args.copy() | |
472 | def one(v, tag=name): |
|
472 | def one(v, tag=name): | |
473 | try: |
|
473 | try: | |
474 | vargs.update(v) |
|
474 | vargs.update(v) | |
475 | except (AttributeError, ValueError): |
|
475 | except (AttributeError, ValueError): | |
476 | try: |
|
476 | try: | |
477 | for a, b in v: |
|
477 | for a, b in v: | |
478 | vargs[a] = b |
|
478 | vargs[a] = b | |
479 | except ValueError: |
|
479 | except ValueError: | |
480 | vargs[name] = v |
|
480 | vargs[name] = v | |
481 | return self.t(tag, **vargs) |
|
481 | return self.t(tag, **vargs) | |
482 | lastname = 'last_' + name |
|
482 | lastname = 'last_' + name | |
483 | if lastname in self.t: |
|
483 | if lastname in self.t: | |
484 | last = values.pop() |
|
484 | last = values.pop() | |
485 | else: |
|
485 | else: | |
486 | last = None |
|
486 | last = None | |
487 | for v in values: |
|
487 | for v in values: | |
488 | yield one(v) |
|
488 | yield one(v) | |
489 | if last is not None: |
|
489 | if last is not None: | |
490 | yield one(last, tag=lastname) |
|
490 | yield one(last, tag=lastname) | |
491 | endname = 'end_' + names |
|
491 | endname = 'end_' + names | |
492 | if endname in self.t: |
|
492 | if endname in self.t: | |
493 | yield self.t(endname, **args) |
|
493 | yield self.t(endname, **args) | |
494 |
|
494 | |||
495 | if brinfo: |
|
495 | if brinfo: | |
496 | def showbranches(**args): |
|
496 | def showbranches(**args): | |
497 | if changenode in brinfo: |
|
497 | if changenode in brinfo: | |
498 | for x in showlist('branch', brinfo[changenode], |
|
498 | for x in showlist('branch', brinfo[changenode], | |
499 | plural='branches', **args): |
|
499 | plural='branches', **args): | |
500 | yield x |
|
500 | yield x | |
501 | else: |
|
501 | else: | |
502 | showbranches = '' |
|
502 | showbranches = '' | |
503 |
|
503 | |||
504 | if self.ui.debugflag: |
|
504 | if self.ui.debugflag: | |
505 | def showmanifest(**args): |
|
505 | def showmanifest(**args): | |
506 | args = args.copy() |
|
506 | args = args.copy() | |
507 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), |
|
507 | args.update(dict(rev=self.repo.manifest.rev(changes[0]), | |
508 | node=hex(changes[0]))) |
|
508 | node=hex(changes[0]))) | |
509 | yield self.t('manifest', **args) |
|
509 | yield self.t('manifest', **args) | |
510 | else: |
|
510 | else: | |
511 | showmanifest = '' |
|
511 | showmanifest = '' | |
512 |
|
512 | |||
513 | def showparents(**args): |
|
513 | def showparents(**args): | |
514 | parents = [[('rev', log.rev(p)), ('node', hex(p))] |
|
514 | parents = [[('rev', log.rev(p)), ('node', hex(p))] | |
515 | for p in log.parents(changenode) |
|
515 | for p in log.parents(changenode) | |
516 | if self.ui.debugflag or p != nullid] |
|
516 | if self.ui.debugflag or p != nullid] | |
517 | if (not self.ui.debugflag and len(parents) == 1 and |
|
517 | if (not self.ui.debugflag and len(parents) == 1 and | |
518 | parents[0][0][1] == rev - 1): |
|
518 | parents[0][0][1] == rev - 1): | |
519 | return |
|
519 | return | |
520 | for x in showlist('parent', parents, **args): |
|
520 | for x in showlist('parent', parents, **args): | |
521 | yield x |
|
521 | yield x | |
522 |
|
522 | |||
523 | def showtags(**args): |
|
523 | def showtags(**args): | |
524 | for x in showlist('tag', self.repo.nodetags(changenode), **args): |
|
524 | for x in showlist('tag', self.repo.nodetags(changenode), **args): | |
525 | yield x |
|
525 | yield x | |
526 |
|
526 | |||
527 | if self.ui.debugflag: |
|
527 | if self.ui.debugflag: | |
528 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
528 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
529 | def showfiles(**args): |
|
529 | def showfiles(**args): | |
530 | for x in showlist('file', files[0], **args): yield x |
|
530 | for x in showlist('file', files[0], **args): yield x | |
531 | def showadds(**args): |
|
531 | def showadds(**args): | |
532 | for x in showlist('file_add', files[1], **args): yield x |
|
532 | for x in showlist('file_add', files[1], **args): yield x | |
533 | def showdels(**args): |
|
533 | def showdels(**args): | |
534 | for x in showlist('file_del', files[2], **args): yield x |
|
534 | for x in showlist('file_del', files[2], **args): yield x | |
535 | else: |
|
535 | else: | |
536 | def showfiles(**args): |
|
536 | def showfiles(**args): | |
537 | for x in showlist('file', changes[3], **args): yield x |
|
537 | for x in showlist('file', changes[3], **args): yield x | |
538 | showadds = '' |
|
538 | showadds = '' | |
539 | showdels = '' |
|
539 | showdels = '' | |
540 |
|
540 | |||
541 | props = { |
|
541 | props = { | |
542 | 'author': changes[1], |
|
542 | 'author': changes[1], | |
543 | 'branches': showbranches, |
|
543 | 'branches': showbranches, | |
544 | 'date': changes[2], |
|
544 | 'date': changes[2], | |
545 | 'desc': changes[4], |
|
545 | 'desc': changes[4], | |
546 | 'file_adds': showadds, |
|
546 | 'file_adds': showadds, | |
547 | 'file_dels': showdels, |
|
547 | 'file_dels': showdels, | |
548 | 'files': showfiles, |
|
548 | 'files': showfiles, | |
549 | 'manifest': showmanifest, |
|
549 | 'manifest': showmanifest, | |
550 | 'node': hex(changenode), |
|
550 | 'node': hex(changenode), | |
551 | 'parents': showparents, |
|
551 | 'parents': showparents, | |
552 | 'rev': rev, |
|
552 | 'rev': rev, | |
553 | 'tags': showtags, |
|
553 | 'tags': showtags, | |
554 | } |
|
554 | } | |
555 |
|
555 | |||
556 | try: |
|
556 | try: | |
557 | if self.ui.debugflag and 'header_debug' in self.t: |
|
557 | if self.ui.debugflag and 'header_debug' in self.t: | |
558 | key = 'header_debug' |
|
558 | key = 'header_debug' | |
559 | elif self.ui.quiet and 'header_quiet' in self.t: |
|
559 | elif self.ui.quiet and 'header_quiet' in self.t: | |
560 | key = 'header_quiet' |
|
560 | key = 'header_quiet' | |
561 | elif self.ui.verbose and 'header_verbose' in self.t: |
|
561 | elif self.ui.verbose and 'header_verbose' in self.t: | |
562 | key = 'header_verbose' |
|
562 | key = 'header_verbose' | |
563 | elif 'header' in self.t: |
|
563 | elif 'header' in self.t: | |
564 | key = 'header' |
|
564 | key = 'header' | |
565 | else: |
|
565 | else: | |
566 | key = '' |
|
566 | key = '' | |
567 | if key: |
|
567 | if key: | |
568 | self.write_header(self.t(key, **props)) |
|
568 | self.write_header(self.t(key, **props)) | |
569 | if self.ui.debugflag and 'changeset_debug' in self.t: |
|
569 | if self.ui.debugflag and 'changeset_debug' in self.t: | |
570 | key = 'changeset_debug' |
|
570 | key = 'changeset_debug' | |
571 | elif self.ui.quiet and 'changeset_quiet' in self.t: |
|
571 | elif self.ui.quiet and 'changeset_quiet' in self.t: | |
572 | key = 'changeset_quiet' |
|
572 | key = 'changeset_quiet' | |
573 | elif self.ui.verbose and 'changeset_verbose' in self.t: |
|
573 | elif self.ui.verbose and 'changeset_verbose' in self.t: | |
574 | key = 'changeset_verbose' |
|
574 | key = 'changeset_verbose' | |
575 | else: |
|
575 | else: | |
576 | key = 'changeset' |
|
576 | key = 'changeset' | |
577 | self.write(self.t(key, **props)) |
|
577 | self.write(self.t(key, **props)) | |
578 | except KeyError, inst: |
|
578 | except KeyError, inst: | |
579 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, |
|
579 | raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile, | |
580 | inst.args[0])) |
|
580 | inst.args[0])) | |
581 | except SyntaxError, inst: |
|
581 | except SyntaxError, inst: | |
582 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) |
|
582 | raise util.Abort(_('%s: %s') % (self.t.mapfile, inst.args[0])) | |
583 |
|
583 | |||
584 | class changeset_printer(object): |
|
584 | class changeset_printer(object): | |
585 | '''show changeset information when templating not requested.''' |
|
585 | '''show changeset information when templating not requested.''' | |
586 |
|
586 | |||
587 | def __init__(self, ui, repo): |
|
587 | def __init__(self, ui, repo): | |
588 | self.ui = ui |
|
588 | self.ui = ui | |
589 | self.repo = repo |
|
589 | self.repo = repo | |
590 |
|
590 | |||
591 | def show(self, rev=0, changenode=None, brinfo=None): |
|
591 | def show(self, rev=0, changenode=None, brinfo=None): | |
592 | '''show a single changeset or file revision''' |
|
592 | '''show a single changeset or file revision''' | |
593 | log = self.repo.changelog |
|
593 | log = self.repo.changelog | |
594 | if changenode is None: |
|
594 | if changenode is None: | |
595 | changenode = log.node(rev) |
|
595 | changenode = log.node(rev) | |
596 | elif not rev: |
|
596 | elif not rev: | |
597 | rev = log.rev(changenode) |
|
597 | rev = log.rev(changenode) | |
598 |
|
598 | |||
599 | if self.ui.quiet: |
|
599 | if self.ui.quiet: | |
600 | self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
600 | self.ui.write("%d:%s\n" % (rev, short(changenode))) | |
601 | return |
|
601 | return | |
602 |
|
602 | |||
603 | changes = log.read(changenode) |
|
603 | changes = log.read(changenode) | |
604 | date = util.datestr(changes[2]) |
|
604 | date = util.datestr(changes[2]) | |
605 |
|
605 | |||
606 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) |
|
606 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) | |
607 | for p in log.parents(changenode) |
|
607 | for p in log.parents(changenode) | |
608 | if self.ui.debugflag or p != nullid] |
|
608 | if self.ui.debugflag or p != nullid] | |
609 | if (not self.ui.debugflag and len(parents) == 1 and |
|
609 | if (not self.ui.debugflag and len(parents) == 1 and | |
610 | parents[0][0] == rev-1): |
|
610 | parents[0][0] == rev-1): | |
611 | parents = [] |
|
611 | parents = [] | |
612 |
|
612 | |||
613 | if self.ui.verbose: |
|
613 | if self.ui.verbose: | |
614 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) |
|
614 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) | |
615 | else: |
|
615 | else: | |
616 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) |
|
616 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) | |
617 |
|
617 | |||
618 | for tag in self.repo.nodetags(changenode): |
|
618 | for tag in self.repo.nodetags(changenode): | |
619 | self.ui.status(_("tag: %s\n") % tag) |
|
619 | self.ui.status(_("tag: %s\n") % tag) | |
620 | for parent in parents: |
|
620 | for parent in parents: | |
621 | self.ui.write(_("parent: %d:%s\n") % parent) |
|
621 | self.ui.write(_("parent: %d:%s\n") % parent) | |
622 |
|
622 | |||
623 | if brinfo and changenode in brinfo: |
|
623 | if brinfo and changenode in brinfo: | |
624 | br = brinfo[changenode] |
|
624 | br = brinfo[changenode] | |
625 | self.ui.write(_("branch: %s\n") % " ".join(br)) |
|
625 | self.ui.write(_("branch: %s\n") % " ".join(br)) | |
626 |
|
626 | |||
627 | self.ui.debug(_("manifest: %d:%s\n") % |
|
627 | self.ui.debug(_("manifest: %d:%s\n") % | |
628 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
628 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) | |
629 | self.ui.status(_("user: %s\n") % changes[1]) |
|
629 | self.ui.status(_("user: %s\n") % changes[1]) | |
630 | self.ui.status(_("date: %s\n") % date) |
|
630 | self.ui.status(_("date: %s\n") % date) | |
631 |
|
631 | |||
632 | if self.ui.debugflag: |
|
632 | if self.ui.debugflag: | |
633 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
633 | files = self.repo.changes(log.parents(changenode)[0], changenode) | |
634 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
634 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], | |
635 | files): |
|
635 | files): | |
636 | if value: |
|
636 | if value: | |
637 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) |
|
637 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) | |
638 | else: |
|
638 | else: | |
639 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) |
|
639 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) | |
640 |
|
640 | |||
641 | description = changes[4].strip() |
|
641 | description = changes[4].strip() | |
642 | if description: |
|
642 | if description: | |
643 | if self.ui.verbose: |
|
643 | if self.ui.verbose: | |
644 | self.ui.status(_("description:\n")) |
|
644 | self.ui.status(_("description:\n")) | |
645 | self.ui.status(description) |
|
645 | self.ui.status(description) | |
646 | self.ui.status("\n\n") |
|
646 | self.ui.status("\n\n") | |
647 | else: |
|
647 | else: | |
648 | self.ui.status(_("summary: %s\n") % |
|
648 | self.ui.status(_("summary: %s\n") % | |
649 | description.splitlines()[0]) |
|
649 | description.splitlines()[0]) | |
650 | self.ui.status("\n") |
|
650 | self.ui.status("\n") | |
651 |
|
651 | |||
652 | def show_changeset(ui, repo, opts): |
|
652 | def show_changeset(ui, repo, opts): | |
653 | '''show one changeset. uses template or regular display. caller |
|
653 | '''show one changeset. uses template or regular display. caller | |
654 | can pass in 'style' and 'template' options in opts.''' |
|
654 | can pass in 'style' and 'template' options in opts.''' | |
655 |
|
655 | |||
656 | tmpl = opts.get('template') |
|
656 | tmpl = opts.get('template') | |
657 | if tmpl: |
|
657 | if tmpl: | |
658 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
658 | tmpl = templater.parsestring(tmpl, quoted=False) | |
659 | else: |
|
659 | else: | |
660 | tmpl = ui.config('ui', 'logtemplate') |
|
660 | tmpl = ui.config('ui', 'logtemplate') | |
661 | if tmpl: tmpl = templater.parsestring(tmpl) |
|
661 | if tmpl: tmpl = templater.parsestring(tmpl) | |
662 | mapfile = opts.get('style') or ui.config('ui', 'style') |
|
662 | mapfile = opts.get('style') or ui.config('ui', 'style') | |
663 | if tmpl or mapfile: |
|
663 | if tmpl or mapfile: | |
664 | if mapfile: |
|
664 | if mapfile: | |
665 | if not os.path.isfile(mapfile): |
|
665 | if not os.path.isfile(mapfile): | |
666 | mapname = templater.templatepath('map-cmdline.' + mapfile) |
|
666 | mapname = templater.templatepath('map-cmdline.' + mapfile) | |
667 | if not mapname: mapname = templater.templatepath(mapfile) |
|
667 | if not mapname: mapname = templater.templatepath(mapfile) | |
668 | if mapname: mapfile = mapname |
|
668 | if mapname: mapfile = mapname | |
669 | try: |
|
669 | try: | |
670 | t = changeset_templater(ui, repo, mapfile) |
|
670 | t = changeset_templater(ui, repo, mapfile) | |
671 | except SyntaxError, inst: |
|
671 | except SyntaxError, inst: | |
672 | raise util.Abort(inst.args[0]) |
|
672 | raise util.Abort(inst.args[0]) | |
673 | if tmpl: t.use_template(tmpl) |
|
673 | if tmpl: t.use_template(tmpl) | |
674 | return t |
|
674 | return t | |
675 | return changeset_printer(ui, repo) |
|
675 | return changeset_printer(ui, repo) | |
676 |
|
676 | |||
677 | def show_version(ui): |
|
677 | def show_version(ui): | |
678 | """output version and copyright information""" |
|
678 | """output version and copyright information""" | |
679 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
679 | ui.write(_("Mercurial Distributed SCM (version %s)\n") | |
680 | % version.get_version()) |
|
680 | % version.get_version()) | |
681 | ui.status(_( |
|
681 | ui.status(_( | |
682 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
|
682 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" | |
683 | "This is free software; see the source for copying conditions. " |
|
683 | "This is free software; see the source for copying conditions. " | |
684 | "There is NO\nwarranty; " |
|
684 | "There is NO\nwarranty; " | |
685 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
685 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | |
686 | )) |
|
686 | )) | |
687 |
|
687 | |||
688 | def help_(ui, cmd=None, with_version=False): |
|
688 | def help_(ui, cmd=None, with_version=False): | |
689 | """show help for a given command or all commands""" |
|
689 | """show help for a given command or all commands""" | |
690 | option_lists = [] |
|
690 | option_lists = [] | |
691 | if cmd and cmd != 'shortlist': |
|
691 | if cmd and cmd != 'shortlist': | |
692 | if with_version: |
|
692 | if with_version: | |
693 | show_version(ui) |
|
693 | show_version(ui) | |
694 | ui.write('\n') |
|
694 | ui.write('\n') | |
695 | aliases, i = find(cmd) |
|
695 | aliases, i = find(cmd) | |
696 | # synopsis |
|
696 | # synopsis | |
697 | ui.write("%s\n\n" % i[2]) |
|
697 | ui.write("%s\n\n" % i[2]) | |
698 |
|
698 | |||
699 | # description |
|
699 | # description | |
700 | doc = i[0].__doc__ |
|
700 | doc = i[0].__doc__ | |
701 | if not doc: |
|
701 | if not doc: | |
702 | doc = _("(No help text available)") |
|
702 | doc = _("(No help text available)") | |
703 | if ui.quiet: |
|
703 | if ui.quiet: | |
704 | doc = doc.splitlines(0)[0] |
|
704 | doc = doc.splitlines(0)[0] | |
705 | ui.write("%s\n" % doc.rstrip()) |
|
705 | ui.write("%s\n" % doc.rstrip()) | |
706 |
|
706 | |||
707 | if not ui.quiet: |
|
707 | if not ui.quiet: | |
708 | # aliases |
|
708 | # aliases | |
709 | if len(aliases) > 1: |
|
709 | if len(aliases) > 1: | |
710 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
710 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) | |
711 |
|
711 | |||
712 | # options |
|
712 | # options | |
713 | if i[1]: |
|
713 | if i[1]: | |
714 | option_lists.append(("options", i[1])) |
|
714 | option_lists.append(("options", i[1])) | |
715 |
|
715 | |||
716 | else: |
|
716 | else: | |
717 | # program name |
|
717 | # program name | |
718 | if ui.verbose or with_version: |
|
718 | if ui.verbose or with_version: | |
719 | show_version(ui) |
|
719 | show_version(ui) | |
720 | else: |
|
720 | else: | |
721 | ui.status(_("Mercurial Distributed SCM\n")) |
|
721 | ui.status(_("Mercurial Distributed SCM\n")) | |
722 | ui.status('\n') |
|
722 | ui.status('\n') | |
723 |
|
723 | |||
724 | # list of commands |
|
724 | # list of commands | |
725 | if cmd == "shortlist": |
|
725 | if cmd == "shortlist": | |
726 | ui.status(_('basic commands (use "hg help" ' |
|
726 | ui.status(_('basic commands (use "hg help" ' | |
727 | 'for the full list or option "-v" for details):\n\n')) |
|
727 | 'for the full list or option "-v" for details):\n\n')) | |
728 | elif ui.verbose: |
|
728 | elif ui.verbose: | |
729 | ui.status(_('list of commands:\n\n')) |
|
729 | ui.status(_('list of commands:\n\n')) | |
730 | else: |
|
730 | else: | |
731 | ui.status(_('list of commands (use "hg help -v" ' |
|
731 | ui.status(_('list of commands (use "hg help -v" ' | |
732 | 'to show aliases and global options):\n\n')) |
|
732 | 'to show aliases and global options):\n\n')) | |
733 |
|
733 | |||
734 | h = {} |
|
734 | h = {} | |
735 | cmds = {} |
|
735 | cmds = {} | |
736 | for c, e in table.items(): |
|
736 | for c, e in table.items(): | |
737 | f = c.split("|")[0] |
|
737 | f = c.split("|")[0] | |
738 | if cmd == "shortlist" and not f.startswith("^"): |
|
738 | if cmd == "shortlist" and not f.startswith("^"): | |
739 | continue |
|
739 | continue | |
740 | f = f.lstrip("^") |
|
740 | f = f.lstrip("^") | |
741 | if not ui.debugflag and f.startswith("debug"): |
|
741 | if not ui.debugflag and f.startswith("debug"): | |
742 | continue |
|
742 | continue | |
743 | doc = e[0].__doc__ |
|
743 | doc = e[0].__doc__ | |
744 | if not doc: |
|
744 | if not doc: | |
745 | doc = _("(No help text available)") |
|
745 | doc = _("(No help text available)") | |
746 | h[f] = doc.splitlines(0)[0].rstrip() |
|
746 | h[f] = doc.splitlines(0)[0].rstrip() | |
747 | cmds[f] = c.lstrip("^") |
|
747 | cmds[f] = c.lstrip("^") | |
748 |
|
748 | |||
749 | fns = h.keys() |
|
749 | fns = h.keys() | |
750 | fns.sort() |
|
750 | fns.sort() | |
751 | m = max(map(len, fns)) |
|
751 | m = max(map(len, fns)) | |
752 | for f in fns: |
|
752 | for f in fns: | |
753 | if ui.verbose: |
|
753 | if ui.verbose: | |
754 | commands = cmds[f].replace("|",", ") |
|
754 | commands = cmds[f].replace("|",", ") | |
755 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
755 | ui.write(" %s:\n %s\n"%(commands, h[f])) | |
756 | else: |
|
756 | else: | |
757 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
757 | ui.write(' %-*s %s\n' % (m, f, h[f])) | |
758 |
|
758 | |||
759 | # global options |
|
759 | # global options | |
760 | if ui.verbose: |
|
760 | if ui.verbose: | |
761 | option_lists.append(("global options", globalopts)) |
|
761 | option_lists.append(("global options", globalopts)) | |
762 |
|
762 | |||
763 | # list all option lists |
|
763 | # list all option lists | |
764 | opt_output = [] |
|
764 | opt_output = [] | |
765 | for title, options in option_lists: |
|
765 | for title, options in option_lists: | |
766 | opt_output.append(("\n%s:\n" % title, None)) |
|
766 | opt_output.append(("\n%s:\n" % title, None)) | |
767 | for shortopt, longopt, default, desc in options: |
|
767 | for shortopt, longopt, default, desc in options: | |
768 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
768 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, | |
769 | longopt and " --%s" % longopt), |
|
769 | longopt and " --%s" % longopt), | |
770 | "%s%s" % (desc, |
|
770 | "%s%s" % (desc, | |
771 | default |
|
771 | default | |
772 | and _(" (default: %s)") % default |
|
772 | and _(" (default: %s)") % default | |
773 | or ""))) |
|
773 | or ""))) | |
774 |
|
774 | |||
775 | if opt_output: |
|
775 | if opt_output: | |
776 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
776 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) | |
777 | for first, second in opt_output: |
|
777 | for first, second in opt_output: | |
778 | if second: |
|
778 | if second: | |
779 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
779 | ui.write(" %-*s %s\n" % (opts_len, first, second)) | |
780 | else: |
|
780 | else: | |
781 | ui.write("%s\n" % first) |
|
781 | ui.write("%s\n" % first) | |
782 |
|
782 | |||
783 | # Commands start here, listed alphabetically |
|
783 | # Commands start here, listed alphabetically | |
784 |
|
784 | |||
785 | def add(ui, repo, *pats, **opts): |
|
785 | def add(ui, repo, *pats, **opts): | |
786 | """add the specified files on the next commit |
|
786 | """add the specified files on the next commit | |
787 |
|
787 | |||
788 | Schedule files to be version controlled and added to the repository. |
|
788 | Schedule files to be version controlled and added to the repository. | |
789 |
|
789 | |||
790 | The files will be added to the repository at the next commit. |
|
790 | The files will be added to the repository at the next commit. | |
791 |
|
791 | |||
792 | If no names are given, add all files in the repository. |
|
792 | If no names are given, add all files in the repository. | |
793 | """ |
|
793 | """ | |
794 |
|
794 | |||
795 | names = [] |
|
795 | names = [] | |
796 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
796 | for src, abs, rel, exact in walk(repo, pats, opts): | |
797 | if exact: |
|
797 | if exact: | |
798 | if ui.verbose: |
|
798 | if ui.verbose: | |
799 | ui.status(_('adding %s\n') % rel) |
|
799 | ui.status(_('adding %s\n') % rel) | |
800 | names.append(abs) |
|
800 | names.append(abs) | |
801 | elif repo.dirstate.state(abs) == '?': |
|
801 | elif repo.dirstate.state(abs) == '?': | |
802 | ui.status(_('adding %s\n') % rel) |
|
802 | ui.status(_('adding %s\n') % rel) | |
803 | names.append(abs) |
|
803 | names.append(abs) | |
804 | repo.add(names) |
|
804 | repo.add(names) | |
805 |
|
805 | |||
806 | def addremove(ui, repo, *pats, **opts): |
|
806 | def addremove(ui, repo, *pats, **opts): | |
807 | """add all new files, delete all missing files |
|
807 | """add all new files, delete all missing files | |
808 |
|
808 | |||
809 | Add all new files and remove all missing files from the repository. |
|
809 | Add all new files and remove all missing files from the repository. | |
810 |
|
810 | |||
811 | New files are ignored if they match any of the patterns in .hgignore. As |
|
811 | New files are ignored if they match any of the patterns in .hgignore. As | |
812 | with add, these changes take effect at the next commit. |
|
812 | with add, these changes take effect at the next commit. | |
813 | """ |
|
813 | """ | |
814 | return addremove_lock(ui, repo, pats, opts) |
|
814 | return addremove_lock(ui, repo, pats, opts) | |
815 |
|
815 | |||
816 | def addremove_lock(ui, repo, pats, opts, wlock=None): |
|
816 | def addremove_lock(ui, repo, pats, opts, wlock=None): | |
817 | add, remove = [], [] |
|
817 | add, remove = [], [] | |
818 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
818 | for src, abs, rel, exact in walk(repo, pats, opts): | |
819 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
819 | if src == 'f' and repo.dirstate.state(abs) == '?': | |
820 | add.append(abs) |
|
820 | add.append(abs) | |
821 | if ui.verbose or not exact: |
|
821 | if ui.verbose or not exact: | |
822 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
822 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) | |
823 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
|
823 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): | |
824 | remove.append(abs) |
|
824 | remove.append(abs) | |
825 | if ui.verbose or not exact: |
|
825 | if ui.verbose or not exact: | |
826 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
826 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) | |
827 | repo.add(add, wlock=wlock) |
|
827 | repo.add(add, wlock=wlock) | |
828 | repo.remove(remove, wlock=wlock) |
|
828 | repo.remove(remove, wlock=wlock) | |
829 |
|
829 | |||
830 | def annotate(ui, repo, *pats, **opts): |
|
830 | def annotate(ui, repo, *pats, **opts): | |
831 | """show changeset information per file line |
|
831 | """show changeset information per file line | |
832 |
|
832 | |||
833 | List changes in files, showing the revision id responsible for each line |
|
833 | List changes in files, showing the revision id responsible for each line | |
834 |
|
834 | |||
835 | This command is useful to discover who did a change or when a change took |
|
835 | This command is useful to discover who did a change or when a change took | |
836 | place. |
|
836 | place. | |
837 |
|
837 | |||
838 | Without the -a option, annotate will avoid processing files it |
|
838 | Without the -a option, annotate will avoid processing files it | |
839 | detects as binary. With -a, annotate will generate an annotation |
|
839 | detects as binary. With -a, annotate will generate an annotation | |
840 | anyway, probably with undesirable results. |
|
840 | anyway, probably with undesirable results. | |
841 | """ |
|
841 | """ | |
842 | def getnode(rev): |
|
842 | def getnode(rev): | |
843 | return short(repo.changelog.node(rev)) |
|
843 | return short(repo.changelog.node(rev)) | |
844 |
|
844 | |||
845 | ucache = {} |
|
845 | ucache = {} | |
846 | def getname(rev): |
|
846 | def getname(rev): | |
847 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
847 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
848 | return trimuser(ui, cl[1], rev, ucache) |
|
848 | return trimuser(ui, cl[1], rev, ucache) | |
849 |
|
849 | |||
850 | dcache = {} |
|
850 | dcache = {} | |
851 | def getdate(rev): |
|
851 | def getdate(rev): | |
852 | datestr = dcache.get(rev) |
|
852 | datestr = dcache.get(rev) | |
853 | if datestr is None: |
|
853 | if datestr is None: | |
854 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
854 | cl = repo.changelog.read(repo.changelog.node(rev)) | |
855 | datestr = dcache[rev] = util.datestr(cl[2]) |
|
855 | datestr = dcache[rev] = util.datestr(cl[2]) | |
856 | return datestr |
|
856 | return datestr | |
857 |
|
857 | |||
858 | if not pats: |
|
858 | if not pats: | |
859 | raise util.Abort(_('at least one file name or pattern required')) |
|
859 | raise util.Abort(_('at least one file name or pattern required')) | |
860 |
|
860 | |||
861 | opmap = [['user', getname], ['number', str], ['changeset', getnode], |
|
861 | opmap = [['user', getname], ['number', str], ['changeset', getnode], | |
862 | ['date', getdate]] |
|
862 | ['date', getdate]] | |
863 | if not opts['user'] and not opts['changeset'] and not opts['date']: |
|
863 | if not opts['user'] and not opts['changeset'] and not opts['date']: | |
864 | opts['number'] = 1 |
|
864 | opts['number'] = 1 | |
865 |
|
865 | |||
866 | if opts['rev']: |
|
866 | if opts['rev']: | |
867 | node = repo.changelog.lookup(opts['rev']) |
|
867 | node = repo.changelog.lookup(opts['rev']) | |
868 | else: |
|
868 | else: | |
869 | node = repo.dirstate.parents()[0] |
|
869 | node = repo.dirstate.parents()[0] | |
870 | change = repo.changelog.read(node) |
|
870 | change = repo.changelog.read(node) | |
871 | mmap = repo.manifest.read(change[0]) |
|
871 | mmap = repo.manifest.read(change[0]) | |
872 |
|
872 | |||
873 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): |
|
873 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): | |
874 | f = repo.file(abs) |
|
874 | f = repo.file(abs) | |
875 | if not opts['text'] and util.binary(f.read(mmap[abs])): |
|
875 | if not opts['text'] and util.binary(f.read(mmap[abs])): | |
876 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
876 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) | |
877 | continue |
|
877 | continue | |
878 |
|
878 | |||
879 | lines = f.annotate(mmap[abs]) |
|
879 | lines = f.annotate(mmap[abs]) | |
880 | pieces = [] |
|
880 | pieces = [] | |
881 |
|
881 | |||
882 | for o, f in opmap: |
|
882 | for o, f in opmap: | |
883 | if opts[o]: |
|
883 | if opts[o]: | |
884 | l = [f(n) for n, dummy in lines] |
|
884 | l = [f(n) for n, dummy in lines] | |
885 | if l: |
|
885 | if l: | |
886 | m = max(map(len, l)) |
|
886 | m = max(map(len, l)) | |
887 | pieces.append(["%*s" % (m, x) for x in l]) |
|
887 | pieces.append(["%*s" % (m, x) for x in l]) | |
888 |
|
888 | |||
889 | if pieces: |
|
889 | if pieces: | |
890 | for p, l in zip(zip(*pieces), lines): |
|
890 | for p, l in zip(zip(*pieces), lines): | |
891 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
891 | ui.write("%s: %s" % (" ".join(p), l[1])) | |
892 |
|
892 | |||
893 | def bundle(ui, repo, fname, dest="default-push", **opts): |
|
893 | def bundle(ui, repo, fname, dest="default-push", **opts): | |
894 | """create a changegroup file |
|
894 | """create a changegroup file | |
895 |
|
895 | |||
896 | Generate a compressed changegroup file collecting all changesets |
|
896 | Generate a compressed changegroup file collecting all changesets | |
897 | not found in the other repository. |
|
897 | not found in the other repository. | |
898 |
|
898 | |||
899 | This file can then be transferred using conventional means and |
|
899 | This file can then be transferred using conventional means and | |
900 | applied to another repository with the unbundle command. This is |
|
900 | applied to another repository with the unbundle command. This is | |
901 | useful when native push and pull are not available or when |
|
901 | useful when native push and pull are not available or when | |
902 | exporting an entire repository is undesirable. The standard file |
|
902 | exporting an entire repository is undesirable. The standard file | |
903 | extension is ".hg". |
|
903 | extension is ".hg". | |
904 |
|
904 | |||
905 | Unlike import/export, this exactly preserves all changeset |
|
905 | Unlike import/export, this exactly preserves all changeset | |
906 | contents including permissions, rename data, and revision history. |
|
906 | contents including permissions, rename data, and revision history. | |
907 | """ |
|
907 | """ | |
908 | dest = ui.expandpath(dest) |
|
908 | dest = ui.expandpath(dest) | |
909 | other = hg.repository(ui, dest) |
|
909 | other = hg.repository(ui, dest) | |
910 | o = repo.findoutgoing(other, force=opts['force']) |
|
910 | o = repo.findoutgoing(other, force=opts['force']) | |
911 | cg = repo.changegroup(o, 'bundle') |
|
911 | cg = repo.changegroup(o, 'bundle') | |
912 | write_bundle(cg, fname) |
|
912 | write_bundle(cg, fname) | |
913 |
|
913 | |||
914 | def cat(ui, repo, file1, *pats, **opts): |
|
914 | def cat(ui, repo, file1, *pats, **opts): | |
915 | """output the latest or given revisions of files |
|
915 | """output the latest or given revisions of files | |
916 |
|
916 | |||
917 | Print the specified files as they were at the given revision. |
|
917 | Print the specified files as they were at the given revision. | |
918 | If no revision is given then the tip is used. |
|
918 | If no revision is given then the tip is used. | |
919 |
|
919 | |||
920 | Output may be to a file, in which case the name of the file is |
|
920 | Output may be to a file, in which case the name of the file is | |
921 | given using a format string. The formatting rules are the same as |
|
921 | given using a format string. The formatting rules are the same as | |
922 | for the export command, with the following additions: |
|
922 | for the export command, with the following additions: | |
923 |
|
923 | |||
924 | %s basename of file being printed |
|
924 | %s basename of file being printed | |
925 | %d dirname of file being printed, or '.' if in repo root |
|
925 | %d dirname of file being printed, or '.' if in repo root | |
926 | %p root-relative path name of file being printed |
|
926 | %p root-relative path name of file being printed | |
927 | """ |
|
927 | """ | |
928 | mf = {} |
|
928 | mf = {} | |
929 | rev = opts['rev'] |
|
929 | rev = opts['rev'] | |
930 | if rev: |
|
930 | if rev: | |
931 | node = repo.lookup(rev) |
|
931 | node = repo.lookup(rev) | |
932 | else: |
|
932 | else: | |
933 | node = repo.changelog.tip() |
|
933 | node = repo.changelog.tip() | |
934 | change = repo.changelog.read(node) |
|
934 | change = repo.changelog.read(node) | |
935 | mf = repo.manifest.read(change[0]) |
|
935 | mf = repo.manifest.read(change[0]) | |
936 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): |
|
936 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): | |
937 | r = repo.file(abs) |
|
937 | r = repo.file(abs) | |
938 | n = mf[abs] |
|
938 | n = mf[abs] | |
939 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) |
|
939 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) | |
940 | fp.write(r.read(n)) |
|
940 | fp.write(r.read(n)) | |
941 |
|
941 | |||
942 | def clone(ui, source, dest=None, **opts): |
|
942 | def clone(ui, source, dest=None, **opts): | |
943 | """make a copy of an existing repository |
|
943 | """make a copy of an existing repository | |
944 |
|
944 | |||
945 | Create a copy of an existing repository in a new directory. |
|
945 | Create a copy of an existing repository in a new directory. | |
946 |
|
946 | |||
947 | If no destination directory name is specified, it defaults to the |
|
947 | If no destination directory name is specified, it defaults to the | |
948 | basename of the source. |
|
948 | basename of the source. | |
949 |
|
949 | |||
950 | The location of the source is added to the new repository's |
|
950 | The location of the source is added to the new repository's | |
951 | .hg/hgrc file, as the default to be used for future pulls. |
|
951 | .hg/hgrc file, as the default to be used for future pulls. | |
952 |
|
952 | |||
953 | For efficiency, hardlinks are used for cloning whenever the source |
|
953 | For efficiency, hardlinks are used for cloning whenever the source | |
954 | and destination are on the same filesystem. Some filesystems, |
|
954 | and destination are on the same filesystem. Some filesystems, | |
955 | such as AFS, implement hardlinking incorrectly, but do not report |
|
955 | such as AFS, implement hardlinking incorrectly, but do not report | |
956 | errors. In these cases, use the --pull option to avoid |
|
956 | errors. In these cases, use the --pull option to avoid | |
957 | hardlinking. |
|
957 | hardlinking. | |
958 |
|
958 | |||
959 | See pull for valid source format details. |
|
959 | See pull for valid source format details. | |
960 | """ |
|
960 | """ | |
961 | if dest is None: |
|
961 | if dest is None: | |
962 | dest = os.path.basename(os.path.normpath(source)) |
|
962 | dest = os.path.basename(os.path.normpath(source)) | |
963 |
|
963 | |||
964 | if os.path.exists(dest): |
|
964 | if os.path.exists(dest): | |
965 | raise util.Abort(_("destination '%s' already exists"), dest) |
|
965 | raise util.Abort(_("destination '%s' already exists"), dest) | |
966 |
|
966 | |||
967 | dest = os.path.realpath(dest) |
|
967 | dest = os.path.realpath(dest) | |
968 |
|
968 | |||
969 | class Dircleanup(object): |
|
969 | class Dircleanup(object): | |
970 | def __init__(self, dir_): |
|
970 | def __init__(self, dir_): | |
971 | self.rmtree = shutil.rmtree |
|
971 | self.rmtree = shutil.rmtree | |
972 | self.dir_ = dir_ |
|
972 | self.dir_ = dir_ | |
973 | os.mkdir(dir_) |
|
973 | os.mkdir(dir_) | |
974 | def close(self): |
|
974 | def close(self): | |
975 | self.dir_ = None |
|
975 | self.dir_ = None | |
976 | def __del__(self): |
|
976 | def __del__(self): | |
977 | if self.dir_: |
|
977 | if self.dir_: | |
978 | self.rmtree(self.dir_, True) |
|
978 | self.rmtree(self.dir_, True) | |
979 |
|
979 | |||
980 | if opts['ssh']: |
|
980 | if opts['ssh']: | |
981 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
981 | ui.setconfig("ui", "ssh", opts['ssh']) | |
982 | if opts['remotecmd']: |
|
982 | if opts['remotecmd']: | |
983 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
983 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
984 |
|
984 | |||
985 | source = ui.expandpath(source) |
|
985 | source = ui.expandpath(source) | |
986 |
|
986 | |||
987 | d = Dircleanup(dest) |
|
987 | d = Dircleanup(dest) | |
988 | abspath = source |
|
988 | abspath = source | |
989 | other = hg.repository(ui, source) |
|
989 | other = hg.repository(ui, source) | |
990 |
|
990 | |||
991 | copy = False |
|
991 | copy = False | |
992 | if other.dev() != -1: |
|
992 | if other.dev() != -1: | |
993 | abspath = os.path.abspath(source) |
|
993 | abspath = os.path.abspath(source) | |
994 | if not opts['pull'] and not opts['rev']: |
|
994 | if not opts['pull'] and not opts['rev']: | |
995 | copy = True |
|
995 | copy = True | |
996 |
|
996 | |||
997 | if copy: |
|
997 | if copy: | |
998 | try: |
|
998 | try: | |
999 | # we use a lock here because if we race with commit, we |
|
999 | # we use a lock here because if we race with commit, we | |
1000 | # can end up with extra data in the cloned revlogs that's |
|
1000 | # can end up with extra data in the cloned revlogs that's | |
1001 | # not pointed to by changesets, thus causing verify to |
|
1001 | # not pointed to by changesets, thus causing verify to | |
1002 | # fail |
|
1002 | # fail | |
1003 | l1 = other.lock() |
|
1003 | l1 = other.lock() | |
1004 | except lock.LockException: |
|
1004 | except lock.LockException: | |
1005 | copy = False |
|
1005 | copy = False | |
1006 |
|
1006 | |||
1007 | if copy: |
|
1007 | if copy: | |
1008 | # we lock here to avoid premature writing to the target |
|
1008 | # we lock here to avoid premature writing to the target | |
1009 | os.mkdir(os.path.join(dest, ".hg")) |
|
1009 | os.mkdir(os.path.join(dest, ".hg")) | |
1010 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) |
|
1010 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) | |
1011 |
|
1011 | |||
1012 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" |
|
1012 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" | |
1013 | for f in files.split(): |
|
1013 | for f in files.split(): | |
1014 | src = os.path.join(source, ".hg", f) |
|
1014 | src = os.path.join(source, ".hg", f) | |
1015 | dst = os.path.join(dest, ".hg", f) |
|
1015 | dst = os.path.join(dest, ".hg", f) | |
1016 | try: |
|
1016 | try: | |
1017 | util.copyfiles(src, dst) |
|
1017 | util.copyfiles(src, dst) | |
1018 | except OSError, inst: |
|
1018 | except OSError, inst: | |
1019 | if inst.errno != errno.ENOENT: |
|
1019 | if inst.errno != errno.ENOENT: | |
1020 | raise |
|
1020 | raise | |
1021 |
|
1021 | |||
1022 | repo = hg.repository(ui, dest) |
|
1022 | repo = hg.repository(ui, dest) | |
1023 |
|
1023 | |||
1024 | else: |
|
1024 | else: | |
1025 | revs = None |
|
1025 | revs = None | |
1026 | if opts['rev']: |
|
1026 | if opts['rev']: | |
1027 | if not other.local(): |
|
1027 | if not other.local(): | |
1028 | error = _("clone -r not supported yet for remote repositories.") |
|
1028 | error = _("clone -r not supported yet for remote repositories.") | |
1029 | raise util.Abort(error) |
|
1029 | raise util.Abort(error) | |
1030 | else: |
|
1030 | else: | |
1031 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
1031 | revs = [other.lookup(rev) for rev in opts['rev']] | |
1032 | repo = hg.repository(ui, dest, create=1) |
|
1032 | repo = hg.repository(ui, dest, create=1) | |
1033 | repo.pull(other, heads = revs) |
|
1033 | repo.pull(other, heads = revs) | |
1034 |
|
1034 | |||
1035 | f = repo.opener("hgrc", "w", text=True) |
|
1035 | f = repo.opener("hgrc", "w", text=True) | |
1036 | f.write("[paths]\n") |
|
1036 | f.write("[paths]\n") | |
1037 | f.write("default = %s\n" % abspath) |
|
1037 | f.write("default = %s\n" % abspath) | |
1038 | f.close() |
|
1038 | f.close() | |
1039 |
|
1039 | |||
1040 | if not opts['noupdate']: |
|
1040 | if not opts['noupdate']: | |
1041 | update(repo.ui, repo) |
|
1041 | update(repo.ui, repo) | |
1042 |
|
1042 | |||
1043 | d.close() |
|
1043 | d.close() | |
1044 |
|
1044 | |||
1045 | def commit(ui, repo, *pats, **opts): |
|
1045 | def commit(ui, repo, *pats, **opts): | |
1046 | """commit the specified files or all outstanding changes |
|
1046 | """commit the specified files or all outstanding changes | |
1047 |
|
1047 | |||
1048 | Commit changes to the given files into the repository. |
|
1048 | Commit changes to the given files into the repository. | |
1049 |
|
1049 | |||
1050 | If a list of files is omitted, all changes reported by "hg status" |
|
1050 | If a list of files is omitted, all changes reported by "hg status" | |
1051 | will be committed. |
|
1051 | will be committed. | |
1052 |
|
1052 | |||
1053 | If no commit message is specified, the editor configured in your hgrc |
|
1053 | If no commit message is specified, the editor configured in your hgrc | |
1054 | or in the EDITOR environment variable is started to enter a message. |
|
1054 | or in the EDITOR environment variable is started to enter a message. | |
1055 | """ |
|
1055 | """ | |
1056 | message = opts['message'] |
|
1056 | message = opts['message'] | |
1057 | logfile = opts['logfile'] |
|
1057 | logfile = opts['logfile'] | |
1058 |
|
1058 | |||
1059 | if message and logfile: |
|
1059 | if message and logfile: | |
1060 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
1060 | raise util.Abort(_('options --message and --logfile are mutually ' | |
1061 | 'exclusive')) |
|
1061 | 'exclusive')) | |
1062 | if not message and logfile: |
|
1062 | if not message and logfile: | |
1063 | try: |
|
1063 | try: | |
1064 | if logfile == '-': |
|
1064 | if logfile == '-': | |
1065 | message = sys.stdin.read() |
|
1065 | message = sys.stdin.read() | |
1066 | else: |
|
1066 | else: | |
1067 | message = open(logfile).read() |
|
1067 | message = open(logfile).read() | |
1068 | except IOError, inst: |
|
1068 | except IOError, inst: | |
1069 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
1069 | raise util.Abort(_("can't read commit message '%s': %s") % | |
1070 | (logfile, inst.strerror)) |
|
1070 | (logfile, inst.strerror)) | |
1071 |
|
1071 | |||
1072 | if opts['addremove']: |
|
1072 | if opts['addremove']: | |
1073 | addremove(ui, repo, *pats, **opts) |
|
1073 | addremove(ui, repo, *pats, **opts) | |
1074 | fns, match, anypats = matchpats(repo, pats, opts) |
|
1074 | fns, match, anypats = matchpats(repo, pats, opts) | |
1075 | if pats: |
|
1075 | if pats: | |
1076 | modified, added, removed, deleted, unknown = ( |
|
1076 | modified, added, removed, deleted, unknown = ( | |
1077 | repo.changes(files=fns, match=match)) |
|
1077 | repo.changes(files=fns, match=match)) | |
1078 | files = modified + added + removed |
|
1078 | files = modified + added + removed | |
1079 | else: |
|
1079 | else: | |
1080 | files = [] |
|
1080 | files = [] | |
1081 | try: |
|
1081 | try: | |
1082 | repo.commit(files, message, opts['user'], opts['date'], match) |
|
1082 | repo.commit(files, message, opts['user'], opts['date'], match) | |
1083 | except ValueError, inst: |
|
1083 | except ValueError, inst: | |
1084 | raise util.Abort(str(inst)) |
|
1084 | raise util.Abort(str(inst)) | |
1085 |
|
1085 | |||
1086 | def docopy(ui, repo, pats, opts, wlock): |
|
1086 | def docopy(ui, repo, pats, opts, wlock): | |
1087 | # called with the repo lock held |
|
1087 | # called with the repo lock held | |
1088 | cwd = repo.getcwd() |
|
1088 | cwd = repo.getcwd() | |
1089 | errors = 0 |
|
1089 | errors = 0 | |
1090 | copied = [] |
|
1090 | copied = [] | |
1091 | targets = {} |
|
1091 | targets = {} | |
1092 |
|
1092 | |||
1093 | def okaytocopy(abs, rel, exact): |
|
1093 | def okaytocopy(abs, rel, exact): | |
1094 | reasons = {'?': _('is not managed'), |
|
1094 | reasons = {'?': _('is not managed'), | |
1095 | 'a': _('has been marked for add'), |
|
1095 | 'a': _('has been marked for add'), | |
1096 | 'r': _('has been marked for remove')} |
|
1096 | 'r': _('has been marked for remove')} | |
1097 | state = repo.dirstate.state(abs) |
|
1097 | state = repo.dirstate.state(abs) | |
1098 | reason = reasons.get(state) |
|
1098 | reason = reasons.get(state) | |
1099 | if reason: |
|
1099 | if reason: | |
1100 | if state == 'a': |
|
1100 | if state == 'a': | |
1101 | origsrc = repo.dirstate.copied(abs) |
|
1101 | origsrc = repo.dirstate.copied(abs) | |
1102 | if origsrc is not None: |
|
1102 | if origsrc is not None: | |
1103 | return origsrc |
|
1103 | return origsrc | |
1104 | if exact: |
|
1104 | if exact: | |
1105 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
1105 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) | |
1106 | else: |
|
1106 | else: | |
1107 | return abs |
|
1107 | return abs | |
1108 |
|
1108 | |||
1109 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
1109 | def copy(origsrc, abssrc, relsrc, target, exact): | |
1110 | abstarget = util.canonpath(repo.root, cwd, target) |
|
1110 | abstarget = util.canonpath(repo.root, cwd, target) | |
1111 | reltarget = util.pathto(cwd, abstarget) |
|
1111 | reltarget = util.pathto(cwd, abstarget) | |
1112 | prevsrc = targets.get(abstarget) |
|
1112 | prevsrc = targets.get(abstarget) | |
1113 | if prevsrc is not None: |
|
1113 | if prevsrc is not None: | |
1114 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
1114 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % | |
1115 | (reltarget, abssrc, prevsrc)) |
|
1115 | (reltarget, abssrc, prevsrc)) | |
1116 | return |
|
1116 | return | |
1117 | if (not opts['after'] and os.path.exists(reltarget) or |
|
1117 | if (not opts['after'] and os.path.exists(reltarget) or | |
1118 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
1118 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): | |
1119 | if not opts['force']: |
|
1119 | if not opts['force']: | |
1120 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
1120 | ui.warn(_('%s: not overwriting - file exists\n') % | |
1121 | reltarget) |
|
1121 | reltarget) | |
1122 | return |
|
1122 | return | |
1123 | if not opts['after']: |
|
1123 | if not opts['after']: | |
1124 | os.unlink(reltarget) |
|
1124 | os.unlink(reltarget) | |
1125 | if opts['after']: |
|
1125 | if opts['after']: | |
1126 | if not os.path.exists(reltarget): |
|
1126 | if not os.path.exists(reltarget): | |
1127 | return |
|
1127 | return | |
1128 | else: |
|
1128 | else: | |
1129 | targetdir = os.path.dirname(reltarget) or '.' |
|
1129 | targetdir = os.path.dirname(reltarget) or '.' | |
1130 | if not os.path.isdir(targetdir): |
|
1130 | if not os.path.isdir(targetdir): | |
1131 | os.makedirs(targetdir) |
|
1131 | os.makedirs(targetdir) | |
1132 | try: |
|
1132 | try: | |
1133 | restore = repo.dirstate.state(abstarget) == 'r' |
|
1133 | restore = repo.dirstate.state(abstarget) == 'r' | |
1134 | if restore: |
|
1134 | if restore: | |
1135 | repo.undelete([abstarget], wlock) |
|
1135 | repo.undelete([abstarget], wlock) | |
1136 | try: |
|
1136 | try: | |
1137 | shutil.copyfile(relsrc, reltarget) |
|
1137 | shutil.copyfile(relsrc, reltarget) | |
1138 | shutil.copymode(relsrc, reltarget) |
|
1138 | shutil.copymode(relsrc, reltarget) | |
1139 | restore = False |
|
1139 | restore = False | |
1140 | finally: |
|
1140 | finally: | |
1141 | if restore: |
|
1141 | if restore: | |
1142 | repo.remove([abstarget], wlock) |
|
1142 | repo.remove([abstarget], wlock) | |
1143 | except shutil.Error, inst: |
|
1143 | except shutil.Error, inst: | |
1144 | raise util.Abort(str(inst)) |
|
1144 | raise util.Abort(str(inst)) | |
1145 | except IOError, inst: |
|
1145 | except IOError, inst: | |
1146 | if inst.errno == errno.ENOENT: |
|
1146 | if inst.errno == errno.ENOENT: | |
1147 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
1147 | ui.warn(_('%s: deleted in working copy\n') % relsrc) | |
1148 | else: |
|
1148 | else: | |
1149 | ui.warn(_('%s: cannot copy - %s\n') % |
|
1149 | ui.warn(_('%s: cannot copy - %s\n') % | |
1150 | (relsrc, inst.strerror)) |
|
1150 | (relsrc, inst.strerror)) | |
1151 | errors += 1 |
|
1151 | errors += 1 | |
1152 | return |
|
1152 | return | |
1153 | if ui.verbose or not exact: |
|
1153 | if ui.verbose or not exact: | |
1154 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
1154 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) | |
1155 | targets[abstarget] = abssrc |
|
1155 | targets[abstarget] = abssrc | |
1156 | if abstarget != origsrc: |
|
1156 | if abstarget != origsrc: | |
1157 | repo.copy(origsrc, abstarget, wlock) |
|
1157 | repo.copy(origsrc, abstarget, wlock) | |
1158 | copied.append((abssrc, relsrc, exact)) |
|
1158 | copied.append((abssrc, relsrc, exact)) | |
1159 |
|
1159 | |||
1160 | def targetpathfn(pat, dest, srcs): |
|
1160 | def targetpathfn(pat, dest, srcs): | |
1161 | if os.path.isdir(pat): |
|
1161 | if os.path.isdir(pat): | |
1162 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1162 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1163 | if destdirexists: |
|
1163 | if destdirexists: | |
1164 | striplen = len(os.path.split(abspfx)[0]) |
|
1164 | striplen = len(os.path.split(abspfx)[0]) | |
1165 | else: |
|
1165 | else: | |
1166 | striplen = len(abspfx) |
|
1166 | striplen = len(abspfx) | |
1167 | if striplen: |
|
1167 | if striplen: | |
1168 | striplen += len(os.sep) |
|
1168 | striplen += len(os.sep) | |
1169 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1169 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1170 | elif destdirexists: |
|
1170 | elif destdirexists: | |
1171 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1171 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1172 | else: |
|
1172 | else: | |
1173 | res = lambda p: dest |
|
1173 | res = lambda p: dest | |
1174 | return res |
|
1174 | return res | |
1175 |
|
1175 | |||
1176 | def targetpathafterfn(pat, dest, srcs): |
|
1176 | def targetpathafterfn(pat, dest, srcs): | |
1177 | if util.patkind(pat, None)[0]: |
|
1177 | if util.patkind(pat, None)[0]: | |
1178 | # a mercurial pattern |
|
1178 | # a mercurial pattern | |
1179 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1179 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1180 | else: |
|
1180 | else: | |
1181 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1181 | abspfx = util.canonpath(repo.root, cwd, pat) | |
1182 | if len(abspfx) < len(srcs[0][0]): |
|
1182 | if len(abspfx) < len(srcs[0][0]): | |
1183 | # A directory. Either the target path contains the last |
|
1183 | # A directory. Either the target path contains the last | |
1184 | # component of the source path or it does not. |
|
1184 | # component of the source path or it does not. | |
1185 | def evalpath(striplen): |
|
1185 | def evalpath(striplen): | |
1186 | score = 0 |
|
1186 | score = 0 | |
1187 | for s in srcs: |
|
1187 | for s in srcs: | |
1188 | t = os.path.join(dest, s[0][striplen:]) |
|
1188 | t = os.path.join(dest, s[0][striplen:]) | |
1189 | if os.path.exists(t): |
|
1189 | if os.path.exists(t): | |
1190 | score += 1 |
|
1190 | score += 1 | |
1191 | return score |
|
1191 | return score | |
1192 |
|
1192 | |||
1193 | striplen = len(abspfx) |
|
1193 | striplen = len(abspfx) | |
1194 | if striplen: |
|
1194 | if striplen: | |
1195 | striplen += len(os.sep) |
|
1195 | striplen += len(os.sep) | |
1196 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
1196 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): | |
1197 | score = evalpath(striplen) |
|
1197 | score = evalpath(striplen) | |
1198 | striplen1 = len(os.path.split(abspfx)[0]) |
|
1198 | striplen1 = len(os.path.split(abspfx)[0]) | |
1199 | if striplen1: |
|
1199 | if striplen1: | |
1200 | striplen1 += len(os.sep) |
|
1200 | striplen1 += len(os.sep) | |
1201 | if evalpath(striplen1) > score: |
|
1201 | if evalpath(striplen1) > score: | |
1202 | striplen = striplen1 |
|
1202 | striplen = striplen1 | |
1203 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1203 | res = lambda p: os.path.join(dest, p[striplen:]) | |
1204 | else: |
|
1204 | else: | |
1205 | # a file |
|
1205 | # a file | |
1206 | if destdirexists: |
|
1206 | if destdirexists: | |
1207 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1207 | res = lambda p: os.path.join(dest, os.path.basename(p)) | |
1208 | else: |
|
1208 | else: | |
1209 | res = lambda p: dest |
|
1209 | res = lambda p: dest | |
1210 | return res |
|
1210 | return res | |
1211 |
|
1211 | |||
1212 |
|
1212 | |||
1213 | pats = list(pats) |
|
1213 | pats = list(pats) | |
1214 | if not pats: |
|
1214 | if not pats: | |
1215 | raise util.Abort(_('no source or destination specified')) |
|
1215 | raise util.Abort(_('no source or destination specified')) | |
1216 | if len(pats) == 1: |
|
1216 | if len(pats) == 1: | |
1217 | raise util.Abort(_('no destination specified')) |
|
1217 | raise util.Abort(_('no destination specified')) | |
1218 | dest = pats.pop() |
|
1218 | dest = pats.pop() | |
1219 | destdirexists = os.path.isdir(dest) |
|
1219 | destdirexists = os.path.isdir(dest) | |
1220 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
1220 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: | |
1221 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
1221 | raise util.Abort(_('with multiple sources, destination must be an ' | |
1222 | 'existing directory')) |
|
1222 | 'existing directory')) | |
1223 | if opts['after']: |
|
1223 | if opts['after']: | |
1224 | tfn = targetpathafterfn |
|
1224 | tfn = targetpathafterfn | |
1225 | else: |
|
1225 | else: | |
1226 | tfn = targetpathfn |
|
1226 | tfn = targetpathfn | |
1227 | copylist = [] |
|
1227 | copylist = [] | |
1228 | for pat in pats: |
|
1228 | for pat in pats: | |
1229 | srcs = [] |
|
1229 | srcs = [] | |
1230 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): |
|
1230 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): | |
1231 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
1231 | origsrc = okaytocopy(abssrc, relsrc, exact) | |
1232 | if origsrc: |
|
1232 | if origsrc: | |
1233 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
1233 | srcs.append((origsrc, abssrc, relsrc, exact)) | |
1234 | if not srcs: |
|
1234 | if not srcs: | |
1235 | continue |
|
1235 | continue | |
1236 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
1236 | copylist.append((tfn(pat, dest, srcs), srcs)) | |
1237 | if not copylist: |
|
1237 | if not copylist: | |
1238 | raise util.Abort(_('no files to copy')) |
|
1238 | raise util.Abort(_('no files to copy')) | |
1239 |
|
1239 | |||
1240 | for targetpath, srcs in copylist: |
|
1240 | for targetpath, srcs in copylist: | |
1241 | for origsrc, abssrc, relsrc, exact in srcs: |
|
1241 | for origsrc, abssrc, relsrc, exact in srcs: | |
1242 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
1242 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) | |
1243 |
|
1243 | |||
1244 | if errors: |
|
1244 | if errors: | |
1245 | ui.warn(_('(consider using --after)\n')) |
|
1245 | ui.warn(_('(consider using --after)\n')) | |
1246 | return errors, copied |
|
1246 | return errors, copied | |
1247 |
|
1247 | |||
1248 | def copy(ui, repo, *pats, **opts): |
|
1248 | def copy(ui, repo, *pats, **opts): | |
1249 | """mark files as copied for the next commit |
|
1249 | """mark files as copied for the next commit | |
1250 |
|
1250 | |||
1251 | Mark dest as having copies of source files. If dest is a |
|
1251 | Mark dest as having copies of source files. If dest is a | |
1252 | directory, copies are put in that directory. If dest is a file, |
|
1252 | directory, copies are put in that directory. If dest is a file, | |
1253 | there can only be one source. |
|
1253 | there can only be one source. | |
1254 |
|
1254 | |||
1255 | By default, this command copies the contents of files as they |
|
1255 | By default, this command copies the contents of files as they | |
1256 | stand in the working directory. If invoked with --after, the |
|
1256 | stand in the working directory. If invoked with --after, the | |
1257 | operation is recorded, but no copying is performed. |
|
1257 | operation is recorded, but no copying is performed. | |
1258 |
|
1258 | |||
1259 | This command takes effect in the next commit. |
|
1259 | This command takes effect in the next commit. | |
1260 |
|
1260 | |||
1261 | NOTE: This command should be treated as experimental. While it |
|
1261 | NOTE: This command should be treated as experimental. While it | |
1262 | should properly record copied files, this information is not yet |
|
1262 | should properly record copied files, this information is not yet | |
1263 | fully used by merge, nor fully reported by log. |
|
1263 | fully used by merge, nor fully reported by log. | |
1264 | """ |
|
1264 | """ | |
1265 | wlock = repo.wlock(0) |
|
1265 | wlock = repo.wlock(0) | |
1266 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1266 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
1267 | return errs |
|
1267 | return errs | |
1268 |
|
1268 | |||
1269 | def debugancestor(ui, index, rev1, rev2): |
|
1269 | def debugancestor(ui, index, rev1, rev2): | |
1270 | """find the ancestor revision of two revisions in a given index""" |
|
1270 | """find the ancestor revision of two revisions in a given index""" | |
1271 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) |
|
1271 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) | |
1272 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1272 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) | |
1273 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1273 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) | |
1274 |
|
1274 | |||
1275 | def debugcomplete(ui, cmd='', **opts): |
|
1275 | def debugcomplete(ui, cmd='', **opts): | |
1276 | """returns the completion list associated with the given command""" |
|
1276 | """returns the completion list associated with the given command""" | |
1277 |
|
1277 | |||
1278 | if opts['options']: |
|
1278 | if opts['options']: | |
1279 | options = [] |
|
1279 | options = [] | |
1280 | otables = [globalopts] |
|
1280 | otables = [globalopts] | |
1281 | if cmd: |
|
1281 | if cmd: | |
1282 | aliases, entry = find(cmd) |
|
1282 | aliases, entry = find(cmd) | |
1283 | otables.append(entry[1]) |
|
1283 | otables.append(entry[1]) | |
1284 | for t in otables: |
|
1284 | for t in otables: | |
1285 | for o in t: |
|
1285 | for o in t: | |
1286 | if o[0]: |
|
1286 | if o[0]: | |
1287 | options.append('-%s' % o[0]) |
|
1287 | options.append('-%s' % o[0]) | |
1288 | options.append('--%s' % o[1]) |
|
1288 | options.append('--%s' % o[1]) | |
1289 | ui.write("%s\n" % "\n".join(options)) |
|
1289 | ui.write("%s\n" % "\n".join(options)) | |
1290 | return |
|
1290 | return | |
1291 |
|
1291 | |||
1292 | clist = findpossible(cmd).keys() |
|
1292 | clist = findpossible(cmd).keys() | |
1293 | clist.sort() |
|
1293 | clist.sort() | |
1294 | ui.write("%s\n" % "\n".join(clist)) |
|
1294 | ui.write("%s\n" % "\n".join(clist)) | |
1295 |
|
1295 | |||
1296 | def debugrebuildstate(ui, repo, rev=None): |
|
1296 | def debugrebuildstate(ui, repo, rev=None): | |
1297 | """rebuild the dirstate as it would look like for the given revision""" |
|
1297 | """rebuild the dirstate as it would look like for the given revision""" | |
1298 | if not rev: |
|
1298 | if not rev: | |
1299 | rev = repo.changelog.tip() |
|
1299 | rev = repo.changelog.tip() | |
1300 | else: |
|
1300 | else: | |
1301 | rev = repo.lookup(rev) |
|
1301 | rev = repo.lookup(rev) | |
1302 | change = repo.changelog.read(rev) |
|
1302 | change = repo.changelog.read(rev) | |
1303 | n = change[0] |
|
1303 | n = change[0] | |
1304 | files = repo.manifest.readflags(n) |
|
1304 | files = repo.manifest.readflags(n) | |
1305 | wlock = repo.wlock() |
|
1305 | wlock = repo.wlock() | |
1306 | repo.dirstate.rebuild(rev, files.iteritems()) |
|
1306 | repo.dirstate.rebuild(rev, files.iteritems()) | |
1307 |
|
1307 | |||
1308 | def debugcheckstate(ui, repo): |
|
1308 | def debugcheckstate(ui, repo): | |
1309 | """validate the correctness of the current dirstate""" |
|
1309 | """validate the correctness of the current dirstate""" | |
1310 | parent1, parent2 = repo.dirstate.parents() |
|
1310 | parent1, parent2 = repo.dirstate.parents() | |
1311 | repo.dirstate.read() |
|
1311 | repo.dirstate.read() | |
1312 | dc = repo.dirstate.map |
|
1312 | dc = repo.dirstate.map | |
1313 | keys = dc.keys() |
|
1313 | keys = dc.keys() | |
1314 | keys.sort() |
|
1314 | keys.sort() | |
1315 | m1n = repo.changelog.read(parent1)[0] |
|
1315 | m1n = repo.changelog.read(parent1)[0] | |
1316 | m2n = repo.changelog.read(parent2)[0] |
|
1316 | m2n = repo.changelog.read(parent2)[0] | |
1317 | m1 = repo.manifest.read(m1n) |
|
1317 | m1 = repo.manifest.read(m1n) | |
1318 | m2 = repo.manifest.read(m2n) |
|
1318 | m2 = repo.manifest.read(m2n) | |
1319 | errors = 0 |
|
1319 | errors = 0 | |
1320 | for f in dc: |
|
1320 | for f in dc: | |
1321 | state = repo.dirstate.state(f) |
|
1321 | state = repo.dirstate.state(f) | |
1322 | if state in "nr" and f not in m1: |
|
1322 | if state in "nr" and f not in m1: | |
1323 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1323 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) | |
1324 | errors += 1 |
|
1324 | errors += 1 | |
1325 | if state in "a" and f in m1: |
|
1325 | if state in "a" and f in m1: | |
1326 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1326 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) | |
1327 | errors += 1 |
|
1327 | errors += 1 | |
1328 | if state in "m" and f not in m1 and f not in m2: |
|
1328 | if state in "m" and f not in m1 and f not in m2: | |
1329 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1329 | ui.warn(_("%s in state %s, but not in either manifest\n") % | |
1330 | (f, state)) |
|
1330 | (f, state)) | |
1331 | errors += 1 |
|
1331 | errors += 1 | |
1332 | for f in m1: |
|
1332 | for f in m1: | |
1333 | state = repo.dirstate.state(f) |
|
1333 | state = repo.dirstate.state(f) | |
1334 | if state not in "nrm": |
|
1334 | if state not in "nrm": | |
1335 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1335 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) | |
1336 | errors += 1 |
|
1336 | errors += 1 | |
1337 | if errors: |
|
1337 | if errors: | |
1338 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1338 | error = _(".hg/dirstate inconsistent with current parent's manifest") | |
1339 | raise util.Abort(error) |
|
1339 | raise util.Abort(error) | |
1340 |
|
1340 | |||
1341 | def debugconfig(ui, repo): |
|
1341 | def debugconfig(ui, repo): | |
1342 | """show combined config settings from all hgrc files""" |
|
1342 | """show combined config settings from all hgrc files""" | |
1343 | for section, name, value in ui.walkconfig(): |
|
1343 | for section, name, value in ui.walkconfig(): | |
1344 | ui.write('%s.%s=%s\n' % (section, name, value)) |
|
1344 | ui.write('%s.%s=%s\n' % (section, name, value)) | |
1345 |
|
1345 | |||
1346 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
1346 | def debugsetparents(ui, repo, rev1, rev2=None): | |
1347 | """manually set the parents of the current working directory |
|
1347 | """manually set the parents of the current working directory | |
1348 |
|
1348 | |||
1349 | This is useful for writing repository conversion tools, but should |
|
1349 | This is useful for writing repository conversion tools, but should | |
1350 | be used with care. |
|
1350 | be used with care. | |
1351 | """ |
|
1351 | """ | |
1352 |
|
1352 | |||
1353 | if not rev2: |
|
1353 | if not rev2: | |
1354 | rev2 = hex(nullid) |
|
1354 | rev2 = hex(nullid) | |
1355 |
|
1355 | |||
1356 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
1356 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | |
1357 |
|
1357 | |||
1358 | def debugstate(ui, repo): |
|
1358 | def debugstate(ui, repo): | |
1359 | """show the contents of the current dirstate""" |
|
1359 | """show the contents of the current dirstate""" | |
1360 | repo.dirstate.read() |
|
1360 | repo.dirstate.read() | |
1361 | dc = repo.dirstate.map |
|
1361 | dc = repo.dirstate.map | |
1362 | keys = dc.keys() |
|
1362 | keys = dc.keys() | |
1363 | keys.sort() |
|
1363 | keys.sort() | |
1364 | for file_ in keys: |
|
1364 | for file_ in keys: | |
1365 | ui.write("%c %3o %10d %s %s\n" |
|
1365 | ui.write("%c %3o %10d %s %s\n" | |
1366 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
1366 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], | |
1367 | time.strftime("%x %X", |
|
1367 | time.strftime("%x %X", | |
1368 | time.localtime(dc[file_][3])), file_)) |
|
1368 | time.localtime(dc[file_][3])), file_)) | |
1369 | for f in repo.dirstate.copies: |
|
1369 | for f in repo.dirstate.copies: | |
1370 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) |
|
1370 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) | |
1371 |
|
1371 | |||
1372 | def debugdata(ui, file_, rev): |
|
1372 | def debugdata(ui, file_, rev): | |
1373 | """dump the contents of an data file revision""" |
|
1373 | """dump the contents of an data file revision""" | |
1374 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
1374 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), | |
1375 | file_[:-2] + ".i", file_, 0) |
|
1375 | file_[:-2] + ".i", file_, 0) | |
1376 | try: |
|
1376 | try: | |
1377 | ui.write(r.revision(r.lookup(rev))) |
|
1377 | ui.write(r.revision(r.lookup(rev))) | |
1378 | except KeyError: |
|
1378 | except KeyError: | |
1379 | raise util.Abort(_('invalid revision identifier %s'), rev) |
|
1379 | raise util.Abort(_('invalid revision identifier %s'), rev) | |
1380 |
|
1380 | |||
1381 | def debugindex(ui, file_): |
|
1381 | def debugindex(ui, file_): | |
1382 | """dump the contents of an index file""" |
|
1382 | """dump the contents of an index file""" | |
1383 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
1383 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) | |
1384 | ui.write(" rev offset length base linkrev" + |
|
1384 | ui.write(" rev offset length base linkrev" + | |
1385 | " nodeid p1 p2\n") |
|
1385 | " nodeid p1 p2\n") | |
1386 | for i in range(r.count()): |
|
1386 | for i in range(r.count()): | |
1387 | node = r.node(i) |
|
1387 | node = r.node(i) | |
1388 | pp = r.parents(node) |
|
1388 | pp = r.parents(node) | |
1389 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1389 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
1390 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), |
|
1390 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), | |
1391 | short(node), short(pp[0]), short(pp[1]))) |
|
1391 | short(node), short(pp[0]), short(pp[1]))) | |
1392 |
|
1392 | |||
1393 | def debugindexdot(ui, file_): |
|
1393 | def debugindexdot(ui, file_): | |
1394 | """dump an index DAG as a .dot file""" |
|
1394 | """dump an index DAG as a .dot file""" | |
1395 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
1395 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) | |
1396 | ui.write("digraph G {\n") |
|
1396 | ui.write("digraph G {\n") | |
1397 | for i in range(r.count()): |
|
1397 | for i in range(r.count()): | |
1398 | e = r.index[i] |
|
1398 | e = r.index[i] | |
1399 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) |
|
1399 | ui.write("\t%d -> %d\n" % (r.rev(e[4]), i)) | |
1400 | if e[5] != nullid: |
|
1400 | if e[5] != nullid: | |
1401 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) |
|
1401 | ui.write("\t%d -> %d\n" % (r.rev(e[5]), i)) | |
1402 | ui.write("}\n") |
|
1402 | ui.write("}\n") | |
1403 |
|
1403 | |||
1404 | def debugrename(ui, repo, file, rev=None): |
|
1404 | def debugrename(ui, repo, file, rev=None): | |
1405 | """dump rename information""" |
|
1405 | """dump rename information""" | |
1406 | r = repo.file(relpath(repo, [file])[0]) |
|
1406 | r = repo.file(relpath(repo, [file])[0]) | |
1407 | if rev: |
|
1407 | if rev: | |
1408 | try: |
|
1408 | try: | |
1409 | # assume all revision numbers are for changesets |
|
1409 | # assume all revision numbers are for changesets | |
1410 | n = repo.lookup(rev) |
|
1410 | n = repo.lookup(rev) | |
1411 | change = repo.changelog.read(n) |
|
1411 | change = repo.changelog.read(n) | |
1412 | m = repo.manifest.read(change[0]) |
|
1412 | m = repo.manifest.read(change[0]) | |
1413 | n = m[relpath(repo, [file])[0]] |
|
1413 | n = m[relpath(repo, [file])[0]] | |
1414 | except (hg.RepoError, KeyError): |
|
1414 | except (hg.RepoError, KeyError): | |
1415 | n = r.lookup(rev) |
|
1415 | n = r.lookup(rev) | |
1416 | else: |
|
1416 | else: | |
1417 | n = r.tip() |
|
1417 | n = r.tip() | |
1418 | m = r.renamed(n) |
|
1418 | m = r.renamed(n) | |
1419 | if m: |
|
1419 | if m: | |
1420 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) |
|
1420 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) | |
1421 | else: |
|
1421 | else: | |
1422 | ui.write(_("not renamed\n")) |
|
1422 | ui.write(_("not renamed\n")) | |
1423 |
|
1423 | |||
1424 | def debugwalk(ui, repo, *pats, **opts): |
|
1424 | def debugwalk(ui, repo, *pats, **opts): | |
1425 | """show how files match on given patterns""" |
|
1425 | """show how files match on given patterns""" | |
1426 | items = list(walk(repo, pats, opts)) |
|
1426 | items = list(walk(repo, pats, opts)) | |
1427 | if not items: |
|
1427 | if not items: | |
1428 | return |
|
1428 | return | |
1429 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1429 | fmt = '%%s %%-%ds %%-%ds %%s' % ( | |
1430 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1430 | max([len(abs) for (src, abs, rel, exact) in items]), | |
1431 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1431 | max([len(rel) for (src, abs, rel, exact) in items])) | |
1432 | for src, abs, rel, exact in items: |
|
1432 | for src, abs, rel, exact in items: | |
1433 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1433 | line = fmt % (src, abs, rel, exact and 'exact' or '') | |
1434 | ui.write("%s\n" % line.rstrip()) |
|
1434 | ui.write("%s\n" % line.rstrip()) | |
1435 |
|
1435 | |||
1436 | def diff(ui, repo, *pats, **opts): |
|
1436 | def diff(ui, repo, *pats, **opts): | |
1437 | """diff repository (or selected files) |
|
1437 | """diff repository (or selected files) | |
1438 |
|
1438 | |||
1439 | Show differences between revisions for the specified files. |
|
1439 | Show differences between revisions for the specified files. | |
1440 |
|
1440 | |||
1441 | Differences between files are shown using the unified diff format. |
|
1441 | Differences between files are shown using the unified diff format. | |
1442 |
|
1442 | |||
1443 | When two revision arguments are given, then changes are shown |
|
1443 | When two revision arguments are given, then changes are shown | |
1444 | between those revisions. If only one revision is specified then |
|
1444 | between those revisions. If only one revision is specified then | |
1445 | that revision is compared to the working directory, and, when no |
|
1445 | that revision is compared to the working directory, and, when no | |
1446 | revisions are specified, the working directory files are compared |
|
1446 | revisions are specified, the working directory files are compared | |
1447 | to its parent. |
|
1447 | to its parent. | |
1448 |
|
1448 | |||
1449 | Without the -a option, diff will avoid generating diffs of files |
|
1449 | Without the -a option, diff will avoid generating diffs of files | |
1450 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1450 | it detects as binary. With -a, diff will generate a diff anyway, | |
1451 | probably with undesirable results. |
|
1451 | probably with undesirable results. | |
1452 | """ |
|
1452 | """ | |
1453 | node1, node2 = None, None |
|
1453 | node1, node2 = None, None | |
1454 | revs = [repo.lookup(x) for x in opts['rev']] |
|
1454 | revs = [repo.lookup(x) for x in opts['rev']] | |
1455 |
|
1455 | |||
1456 | if len(revs) > 0: |
|
1456 | if len(revs) > 0: | |
1457 | node1 = revs[0] |
|
1457 | node1 = revs[0] | |
1458 | if len(revs) > 1: |
|
1458 | if len(revs) > 1: | |
1459 | node2 = revs[1] |
|
1459 | node2 = revs[1] | |
1460 | if len(revs) > 2: |
|
1460 | if len(revs) > 2: | |
1461 | raise util.Abort(_("too many revisions to diff")) |
|
1461 | raise util.Abort(_("too many revisions to diff")) | |
1462 |
|
1462 | |||
1463 | fns, matchfn, anypats = matchpats(repo, pats, opts) |
|
1463 | fns, matchfn, anypats = matchpats(repo, pats, opts) | |
1464 |
|
1464 | |||
1465 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
|
1465 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | |
1466 | text=opts['text'], opts=opts) |
|
1466 | text=opts['text'], opts=opts) | |
1467 |
|
1467 | |||
1468 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
|
1468 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): | |
1469 | node = repo.lookup(changeset) |
|
1469 | node = repo.lookup(changeset) | |
1470 | parents = [p for p in repo.changelog.parents(node) if p != nullid] |
|
1470 | parents = [p for p in repo.changelog.parents(node) if p != nullid] | |
1471 | if opts['switch_parent']: |
|
1471 | if opts['switch_parent']: | |
1472 | parents.reverse() |
|
1472 | parents.reverse() | |
1473 | prev = (parents and parents[0]) or nullid |
|
1473 | prev = (parents and parents[0]) or nullid | |
1474 | change = repo.changelog.read(node) |
|
1474 | change = repo.changelog.read(node) | |
1475 |
|
1475 | |||
1476 | fp = make_file(repo, repo.changelog, opts['output'], |
|
1476 | fp = make_file(repo, repo.changelog, opts['output'], | |
1477 | node=node, total=total, seqno=seqno, |
|
1477 | node=node, total=total, seqno=seqno, | |
1478 | revwidth=revwidth) |
|
1478 | revwidth=revwidth) | |
1479 | if fp != sys.stdout: |
|
1479 | if fp != sys.stdout: | |
1480 | ui.note("%s\n" % fp.name) |
|
1480 | ui.note("%s\n" % fp.name) | |
1481 |
|
1481 | |||
1482 | fp.write("# HG changeset patch\n") |
|
1482 | fp.write("# HG changeset patch\n") | |
1483 | fp.write("# User %s\n" % change[1]) |
|
1483 | fp.write("# User %s\n" % change[1]) | |
1484 | fp.write("# Node ID %s\n" % hex(node)) |
|
1484 | fp.write("# Node ID %s\n" % hex(node)) | |
1485 | fp.write("# Parent %s\n" % hex(prev)) |
|
1485 | fp.write("# Parent %s\n" % hex(prev)) | |
1486 | if len(parents) > 1: |
|
1486 | if len(parents) > 1: | |
1487 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
1487 | fp.write("# Parent %s\n" % hex(parents[1])) | |
1488 | fp.write(change[4].rstrip()) |
|
1488 | fp.write(change[4].rstrip()) | |
1489 | fp.write("\n\n") |
|
1489 | fp.write("\n\n") | |
1490 |
|
1490 | |||
1491 | dodiff(fp, ui, repo, prev, node, text=opts['text']) |
|
1491 | dodiff(fp, ui, repo, prev, node, text=opts['text']) | |
1492 | if fp != sys.stdout: |
|
1492 | if fp != sys.stdout: | |
1493 | fp.close() |
|
1493 | fp.close() | |
1494 |
|
1494 | |||
1495 | def export(ui, repo, *changesets, **opts): |
|
1495 | def export(ui, repo, *changesets, **opts): | |
1496 | """dump the header and diffs for one or more changesets |
|
1496 | """dump the header and diffs for one or more changesets | |
1497 |
|
1497 | |||
1498 | Print the changeset header and diffs for one or more revisions. |
|
1498 | Print the changeset header and diffs for one or more revisions. | |
1499 |
|
1499 | |||
1500 | The information shown in the changeset header is: author, |
|
1500 | The information shown in the changeset header is: author, | |
1501 | changeset hash, parent and commit comment. |
|
1501 | changeset hash, parent and commit comment. | |
1502 |
|
1502 | |||
1503 | Output may be to a file, in which case the name of the file is |
|
1503 | Output may be to a file, in which case the name of the file is | |
1504 | given using a format string. The formatting rules are as follows: |
|
1504 | given using a format string. The formatting rules are as follows: | |
1505 |
|
1505 | |||
1506 | %% literal "%" character |
|
1506 | %% literal "%" character | |
1507 | %H changeset hash (40 bytes of hexadecimal) |
|
1507 | %H changeset hash (40 bytes of hexadecimal) | |
1508 | %N number of patches being generated |
|
1508 | %N number of patches being generated | |
1509 | %R changeset revision number |
|
1509 | %R changeset revision number | |
1510 | %b basename of the exporting repository |
|
1510 | %b basename of the exporting repository | |
1511 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1511 | %h short-form changeset hash (12 bytes of hexadecimal) | |
1512 | %n zero-padded sequence number, starting at 1 |
|
1512 | %n zero-padded sequence number, starting at 1 | |
1513 | %r zero-padded changeset revision number |
|
1513 | %r zero-padded changeset revision number | |
1514 |
|
1514 | |||
1515 | Without the -a option, export will avoid generating diffs of files |
|
1515 | Without the -a option, export will avoid generating diffs of files | |
1516 | it detects as binary. With -a, export will generate a diff anyway, |
|
1516 | it detects as binary. With -a, export will generate a diff anyway, | |
1517 | probably with undesirable results. |
|
1517 | probably with undesirable results. | |
1518 |
|
1518 | |||
1519 | With the --switch-parent option, the diff will be against the second |
|
1519 | With the --switch-parent option, the diff will be against the second | |
1520 | parent. It can be useful to review a merge. |
|
1520 | parent. It can be useful to review a merge. | |
1521 | """ |
|
1521 | """ | |
1522 | if not changesets: |
|
1522 | if not changesets: | |
1523 | raise util.Abort(_("export requires at least one changeset")) |
|
1523 | raise util.Abort(_("export requires at least one changeset")) | |
1524 | seqno = 0 |
|
1524 | seqno = 0 | |
1525 | revs = list(revrange(ui, repo, changesets)) |
|
1525 | revs = list(revrange(ui, repo, changesets)) | |
1526 | total = len(revs) |
|
1526 | total = len(revs) | |
1527 | revwidth = max(map(len, revs)) |
|
1527 | revwidth = max(map(len, revs)) | |
1528 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") |
|
1528 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") | |
1529 | ui.note(msg) |
|
1529 | ui.note(msg) | |
1530 | for cset in revs: |
|
1530 | for cset in revs: | |
1531 | seqno += 1 |
|
1531 | seqno += 1 | |
1532 | doexport(ui, repo, cset, seqno, total, revwidth, opts) |
|
1532 | doexport(ui, repo, cset, seqno, total, revwidth, opts) | |
1533 |
|
1533 | |||
1534 | def forget(ui, repo, *pats, **opts): |
|
1534 | def forget(ui, repo, *pats, **opts): | |
1535 | """don't add the specified files on the next commit |
|
1535 | """don't add the specified files on the next commit | |
1536 |
|
1536 | |||
1537 | Undo an 'hg add' scheduled for the next commit. |
|
1537 | Undo an 'hg add' scheduled for the next commit. | |
1538 | """ |
|
1538 | """ | |
1539 | forget = [] |
|
1539 | forget = [] | |
1540 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
1540 | for src, abs, rel, exact in walk(repo, pats, opts): | |
1541 | if repo.dirstate.state(abs) == 'a': |
|
1541 | if repo.dirstate.state(abs) == 'a': | |
1542 | forget.append(abs) |
|
1542 | forget.append(abs) | |
1543 | if ui.verbose or not exact: |
|
1543 | if ui.verbose or not exact: | |
1544 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
|
1544 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) | |
1545 | repo.forget(forget) |
|
1545 | repo.forget(forget) | |
1546 |
|
1546 | |||
1547 | def grep(ui, repo, pattern, *pats, **opts): |
|
1547 | def grep(ui, repo, pattern, *pats, **opts): | |
1548 | """search for a pattern in specified files and revisions |
|
1548 | """search for a pattern in specified files and revisions | |
1549 |
|
1549 | |||
1550 | Search revisions of files for a regular expression. |
|
1550 | Search revisions of files for a regular expression. | |
1551 |
|
1551 | |||
1552 | This command behaves differently than Unix grep. It only accepts |
|
1552 | This command behaves differently than Unix grep. It only accepts | |
1553 | Python/Perl regexps. It searches repository history, not the |
|
1553 | Python/Perl regexps. It searches repository history, not the | |
1554 | working directory. It always prints the revision number in which |
|
1554 | working directory. It always prints the revision number in which | |
1555 | a match appears. |
|
1555 | a match appears. | |
1556 |
|
1556 | |||
1557 | By default, grep only prints output for the first revision of a |
|
1557 | By default, grep only prints output for the first revision of a | |
1558 | file in which it finds a match. To get it to print every revision |
|
1558 | file in which it finds a match. To get it to print every revision | |
1559 | that contains a change in match status ("-" for a match that |
|
1559 | that contains a change in match status ("-" for a match that | |
1560 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1560 | becomes a non-match, or "+" for a non-match that becomes a match), | |
1561 | use the --all flag. |
|
1561 | use the --all flag. | |
1562 | """ |
|
1562 | """ | |
1563 | reflags = 0 |
|
1563 | reflags = 0 | |
1564 | if opts['ignore_case']: |
|
1564 | if opts['ignore_case']: | |
1565 | reflags |= re.I |
|
1565 | reflags |= re.I | |
1566 | regexp = re.compile(pattern, reflags) |
|
1566 | regexp = re.compile(pattern, reflags) | |
1567 | sep, eol = ':', '\n' |
|
1567 | sep, eol = ':', '\n' | |
1568 | if opts['print0']: |
|
1568 | if opts['print0']: | |
1569 | sep = eol = '\0' |
|
1569 | sep = eol = '\0' | |
1570 |
|
1570 | |||
1571 | fcache = {} |
|
1571 | fcache = {} | |
1572 | def getfile(fn): |
|
1572 | def getfile(fn): | |
1573 | if fn not in fcache: |
|
1573 | if fn not in fcache: | |
1574 | fcache[fn] = repo.file(fn) |
|
1574 | fcache[fn] = repo.file(fn) | |
1575 | return fcache[fn] |
|
1575 | return fcache[fn] | |
1576 |
|
1576 | |||
1577 | def matchlines(body): |
|
1577 | def matchlines(body): | |
1578 | begin = 0 |
|
1578 | begin = 0 | |
1579 | linenum = 0 |
|
1579 | linenum = 0 | |
1580 | while True: |
|
1580 | while True: | |
1581 | match = regexp.search(body, begin) |
|
1581 | match = regexp.search(body, begin) | |
1582 | if not match: |
|
1582 | if not match: | |
1583 | break |
|
1583 | break | |
1584 | mstart, mend = match.span() |
|
1584 | mstart, mend = match.span() | |
1585 | linenum += body.count('\n', begin, mstart) + 1 |
|
1585 | linenum += body.count('\n', begin, mstart) + 1 | |
1586 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1586 | lstart = body.rfind('\n', begin, mstart) + 1 or begin | |
1587 | lend = body.find('\n', mend) |
|
1587 | lend = body.find('\n', mend) | |
1588 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1588 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] | |
1589 | begin = lend + 1 |
|
1589 | begin = lend + 1 | |
1590 |
|
1590 | |||
1591 | class linestate(object): |
|
1591 | class linestate(object): | |
1592 | def __init__(self, line, linenum, colstart, colend): |
|
1592 | def __init__(self, line, linenum, colstart, colend): | |
1593 | self.line = line |
|
1593 | self.line = line | |
1594 | self.linenum = linenum |
|
1594 | self.linenum = linenum | |
1595 | self.colstart = colstart |
|
1595 | self.colstart = colstart | |
1596 | self.colend = colend |
|
1596 | self.colend = colend | |
1597 | def __eq__(self, other): |
|
1597 | def __eq__(self, other): | |
1598 | return self.line == other.line |
|
1598 | return self.line == other.line | |
1599 | def __hash__(self): |
|
1599 | def __hash__(self): | |
1600 | return hash(self.line) |
|
1600 | return hash(self.line) | |
1601 |
|
1601 | |||
1602 | matches = {} |
|
1602 | matches = {} | |
1603 | def grepbody(fn, rev, body): |
|
1603 | def grepbody(fn, rev, body): | |
1604 | matches[rev].setdefault(fn, {}) |
|
1604 | matches[rev].setdefault(fn, {}) | |
1605 | m = matches[rev][fn] |
|
1605 | m = matches[rev][fn] | |
1606 | for lnum, cstart, cend, line in matchlines(body): |
|
1606 | for lnum, cstart, cend, line in matchlines(body): | |
1607 | s = linestate(line, lnum, cstart, cend) |
|
1607 | s = linestate(line, lnum, cstart, cend) | |
1608 | m[s] = s |
|
1608 | m[s] = s | |
1609 |
|
1609 | |||
1610 | # FIXME: prev isn't used, why ? |
|
1610 | # FIXME: prev isn't used, why ? | |
1611 | prev = {} |
|
1611 | prev = {} | |
1612 | ucache = {} |
|
1612 | ucache = {} | |
1613 | def display(fn, rev, states, prevstates): |
|
1613 | def display(fn, rev, states, prevstates): | |
1614 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) |
|
1614 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) | |
1615 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) |
|
1615 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) | |
1616 | counts = {'-': 0, '+': 0} |
|
1616 | counts = {'-': 0, '+': 0} | |
1617 | filerevmatches = {} |
|
1617 | filerevmatches = {} | |
1618 | for l in diff: |
|
1618 | for l in diff: | |
1619 | if incrementing or not opts['all']: |
|
1619 | if incrementing or not opts['all']: | |
1620 | change = ((l in prevstates) and '-') or '+' |
|
1620 | change = ((l in prevstates) and '-') or '+' | |
1621 | r = rev |
|
1621 | r = rev | |
1622 | else: |
|
1622 | else: | |
1623 | change = ((l in states) and '-') or '+' |
|
1623 | change = ((l in states) and '-') or '+' | |
1624 | r = prev[fn] |
|
1624 | r = prev[fn] | |
1625 | cols = [fn, str(rev)] |
|
1625 | cols = [fn, str(rev)] | |
1626 | if opts['line_number']: |
|
1626 | if opts['line_number']: | |
1627 | cols.append(str(l.linenum)) |
|
1627 | cols.append(str(l.linenum)) | |
1628 | if opts['all']: |
|
1628 | if opts['all']: | |
1629 | cols.append(change) |
|
1629 | cols.append(change) | |
1630 | if opts['user']: |
|
1630 | if opts['user']: | |
1631 | cols.append(trimuser(ui, getchange(rev)[1], rev, |
|
1631 | cols.append(trimuser(ui, getchange(rev)[1], rev, | |
1632 | ucache)) |
|
1632 | ucache)) | |
1633 | if opts['files_with_matches']: |
|
1633 | if opts['files_with_matches']: | |
1634 | c = (fn, rev) |
|
1634 | c = (fn, rev) | |
1635 | if c in filerevmatches: |
|
1635 | if c in filerevmatches: | |
1636 | continue |
|
1636 | continue | |
1637 | filerevmatches[c] = 1 |
|
1637 | filerevmatches[c] = 1 | |
1638 | else: |
|
1638 | else: | |
1639 | cols.append(l.line) |
|
1639 | cols.append(l.line) | |
1640 | ui.write(sep.join(cols), eol) |
|
1640 | ui.write(sep.join(cols), eol) | |
1641 | counts[change] += 1 |
|
1641 | counts[change] += 1 | |
1642 | return counts['+'], counts['-'] |
|
1642 | return counts['+'], counts['-'] | |
1643 |
|
1643 | |||
1644 | fstate = {} |
|
1644 | fstate = {} | |
1645 | skip = {} |
|
1645 | skip = {} | |
1646 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1646 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1647 | count = 0 |
|
1647 | count = 0 | |
1648 | incrementing = False |
|
1648 | incrementing = False | |
1649 | for st, rev, fns in changeiter: |
|
1649 | for st, rev, fns in changeiter: | |
1650 | if st == 'window': |
|
1650 | if st == 'window': | |
1651 | incrementing = rev |
|
1651 | incrementing = rev | |
1652 | matches.clear() |
|
1652 | matches.clear() | |
1653 | elif st == 'add': |
|
1653 | elif st == 'add': | |
1654 | change = repo.changelog.read(repo.lookup(str(rev))) |
|
1654 | change = repo.changelog.read(repo.lookup(str(rev))) | |
1655 | mf = repo.manifest.read(change[0]) |
|
1655 | mf = repo.manifest.read(change[0]) | |
1656 | matches[rev] = {} |
|
1656 | matches[rev] = {} | |
1657 | for fn in fns: |
|
1657 | for fn in fns: | |
1658 | if fn in skip: |
|
1658 | if fn in skip: | |
1659 | continue |
|
1659 | continue | |
1660 | fstate.setdefault(fn, {}) |
|
1660 | fstate.setdefault(fn, {}) | |
1661 | try: |
|
1661 | try: | |
1662 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1662 | grepbody(fn, rev, getfile(fn).read(mf[fn])) | |
1663 | except KeyError: |
|
1663 | except KeyError: | |
1664 | pass |
|
1664 | pass | |
1665 | elif st == 'iter': |
|
1665 | elif st == 'iter': | |
1666 | states = matches[rev].items() |
|
1666 | states = matches[rev].items() | |
1667 | states.sort() |
|
1667 | states.sort() | |
1668 | for fn, m in states: |
|
1668 | for fn, m in states: | |
1669 | if fn in skip: |
|
1669 | if fn in skip: | |
1670 | continue |
|
1670 | continue | |
1671 | if incrementing or not opts['all'] or fstate[fn]: |
|
1671 | if incrementing or not opts['all'] or fstate[fn]: | |
1672 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1672 | pos, neg = display(fn, rev, m, fstate[fn]) | |
1673 | count += pos + neg |
|
1673 | count += pos + neg | |
1674 | if pos and not opts['all']: |
|
1674 | if pos and not opts['all']: | |
1675 | skip[fn] = True |
|
1675 | skip[fn] = True | |
1676 | fstate[fn] = m |
|
1676 | fstate[fn] = m | |
1677 | prev[fn] = rev |
|
1677 | prev[fn] = rev | |
1678 |
|
1678 | |||
1679 | if not incrementing: |
|
1679 | if not incrementing: | |
1680 | fstate = fstate.items() |
|
1680 | fstate = fstate.items() | |
1681 | fstate.sort() |
|
1681 | fstate.sort() | |
1682 | for fn, state in fstate: |
|
1682 | for fn, state in fstate: | |
1683 | if fn in skip: |
|
1683 | if fn in skip: | |
1684 | continue |
|
1684 | continue | |
1685 | display(fn, rev, {}, state) |
|
1685 | display(fn, rev, {}, state) | |
1686 | return (count == 0 and 1) or 0 |
|
1686 | return (count == 0 and 1) or 0 | |
1687 |
|
1687 | |||
1688 | def heads(ui, repo, **opts): |
|
1688 | def heads(ui, repo, **opts): | |
1689 | """show current repository heads |
|
1689 | """show current repository heads | |
1690 |
|
1690 | |||
1691 | Show all repository head changesets. |
|
1691 | Show all repository head changesets. | |
1692 |
|
1692 | |||
1693 | Repository "heads" are changesets that don't have children |
|
1693 | Repository "heads" are changesets that don't have children | |
1694 | changesets. They are where development generally takes place and |
|
1694 | changesets. They are where development generally takes place and | |
1695 | are the usual targets for update and merge operations. |
|
1695 | are the usual targets for update and merge operations. | |
1696 | """ |
|
1696 | """ | |
1697 | if opts['rev']: |
|
1697 | if opts['rev']: | |
1698 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1698 | heads = repo.heads(repo.lookup(opts['rev'])) | |
1699 | else: |
|
1699 | else: | |
1700 | heads = repo.heads() |
|
1700 | heads = repo.heads() | |
1701 | br = None |
|
1701 | br = None | |
1702 | if opts['branches']: |
|
1702 | if opts['branches']: | |
1703 | br = repo.branchlookup(heads) |
|
1703 | br = repo.branchlookup(heads) | |
1704 | displayer = show_changeset(ui, repo, opts) |
|
1704 | displayer = show_changeset(ui, repo, opts) | |
1705 | for n in heads: |
|
1705 | for n in heads: | |
1706 | displayer.show(changenode=n, brinfo=br) |
|
1706 | displayer.show(changenode=n, brinfo=br) | |
1707 |
|
1707 | |||
1708 | def identify(ui, repo): |
|
1708 | def identify(ui, repo): | |
1709 | """print information about the working copy |
|
1709 | """print information about the working copy | |
1710 |
|
1710 | |||
1711 | Print a short summary of the current state of the repo. |
|
1711 | Print a short summary of the current state of the repo. | |
1712 |
|
1712 | |||
1713 | This summary identifies the repository state using one or two parent |
|
1713 | This summary identifies the repository state using one or two parent | |
1714 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1714 | hash identifiers, followed by a "+" if there are uncommitted changes | |
1715 | in the working directory, followed by a list of tags for this revision. |
|
1715 | in the working directory, followed by a list of tags for this revision. | |
1716 | """ |
|
1716 | """ | |
1717 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1717 | parents = [p for p in repo.dirstate.parents() if p != nullid] | |
1718 | if not parents: |
|
1718 | if not parents: | |
1719 | ui.write(_("unknown\n")) |
|
1719 | ui.write(_("unknown\n")) | |
1720 | return |
|
1720 | return | |
1721 |
|
1721 | |||
1722 | hexfunc = ui.verbose and hex or short |
|
1722 | hexfunc = ui.verbose and hex or short | |
1723 | modified, added, removed, deleted, unknown = repo.changes() |
|
1723 | modified, added, removed, deleted, unknown = repo.changes() | |
1724 | output = ["%s%s" % |
|
1724 | output = ["%s%s" % | |
1725 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1725 | ('+'.join([hexfunc(parent) for parent in parents]), | |
1726 | (modified or added or removed or deleted) and "+" or "")] |
|
1726 | (modified or added or removed or deleted) and "+" or "")] | |
1727 |
|
1727 | |||
1728 | if not ui.quiet: |
|
1728 | if not ui.quiet: | |
1729 | # multiple tags for a single parent separated by '/' |
|
1729 | # multiple tags for a single parent separated by '/' | |
1730 | parenttags = ['/'.join(tags) |
|
1730 | parenttags = ['/'.join(tags) | |
1731 | for tags in map(repo.nodetags, parents) if tags] |
|
1731 | for tags in map(repo.nodetags, parents) if tags] | |
1732 | # tags for multiple parents separated by ' + ' |
|
1732 | # tags for multiple parents separated by ' + ' | |
1733 | if parenttags: |
|
1733 | if parenttags: | |
1734 | output.append(' + '.join(parenttags)) |
|
1734 | output.append(' + '.join(parenttags)) | |
1735 |
|
1735 | |||
1736 | ui.write("%s\n" % ' '.join(output)) |
|
1736 | ui.write("%s\n" % ' '.join(output)) | |
1737 |
|
1737 | |||
1738 | def import_(ui, repo, patch1, *patches, **opts): |
|
1738 | def import_(ui, repo, patch1, *patches, **opts): | |
1739 | """import an ordered set of patches |
|
1739 | """import an ordered set of patches | |
1740 |
|
1740 | |||
1741 | Import a list of patches and commit them individually. |
|
1741 | Import a list of patches and commit them individually. | |
1742 |
|
1742 | |||
1743 | If there are outstanding changes in the working directory, import |
|
1743 | If there are outstanding changes in the working directory, import | |
1744 | will abort unless given the -f flag. |
|
1744 | will abort unless given the -f flag. | |
1745 |
|
1745 | |||
1746 | If a patch looks like a mail message (its first line starts with |
|
1746 | If a patch looks like a mail message (its first line starts with | |
1747 | "From " or looks like an RFC822 header), it will not be applied |
|
1747 | "From " or looks like an RFC822 header), it will not be applied | |
1748 | unless the -f option is used. The importer neither parses nor |
|
1748 | unless the -f option is used. The importer neither parses nor | |
1749 | discards mail headers, so use -f only to override the "mailness" |
|
1749 | discards mail headers, so use -f only to override the "mailness" | |
1750 | safety check, not to import a real mail message. |
|
1750 | safety check, not to import a real mail message. | |
1751 | """ |
|
1751 | """ | |
1752 | patches = (patch1,) + patches |
|
1752 | patches = (patch1,) + patches | |
1753 |
|
1753 | |||
1754 | if not opts['force']: |
|
1754 | if not opts['force']: | |
1755 | modified, added, removed, deleted, unknown = repo.changes() |
|
1755 | modified, added, removed, deleted, unknown = repo.changes() | |
1756 | if modified or added or removed or deleted: |
|
1756 | if modified or added or removed or deleted: | |
1757 | raise util.Abort(_("outstanding uncommitted changes")) |
|
1757 | raise util.Abort(_("outstanding uncommitted changes")) | |
1758 |
|
1758 | |||
1759 | d = opts["base"] |
|
1759 | d = opts["base"] | |
1760 | strip = opts["strip"] |
|
1760 | strip = opts["strip"] | |
1761 |
|
1761 | |||
1762 | mailre = re.compile(r'(?:From |[\w-]+:)') |
|
1762 | mailre = re.compile(r'(?:From |[\w-]+:)') | |
1763 |
|
1763 | |||
1764 | # attempt to detect the start of a patch |
|
1764 | # attempt to detect the start of a patch | |
1765 | # (this heuristic is borrowed from quilt) |
|
1765 | # (this heuristic is borrowed from quilt) | |
1766 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + |
|
1766 | diffre = re.compile(r'(?:Index:[ \t]|diff[ \t]|RCS file: |' + | |
1767 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + |
|
1767 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + | |
1768 | '(---|\*\*\*)[ \t])') |
|
1768 | '(---|\*\*\*)[ \t])') | |
1769 |
|
1769 | |||
1770 | for patch in patches: |
|
1770 | for patch in patches: | |
1771 | ui.status(_("applying %s\n") % patch) |
|
1771 | ui.status(_("applying %s\n") % patch) | |
1772 | pf = os.path.join(d, patch) |
|
1772 | pf = os.path.join(d, patch) | |
1773 |
|
1773 | |||
1774 | message = [] |
|
1774 | message = [] | |
1775 | user = None |
|
1775 | user = None | |
1776 | hgpatch = False |
|
1776 | hgpatch = False | |
1777 | for line in file(pf): |
|
1777 | for line in file(pf): | |
1778 | line = line.rstrip() |
|
1778 | line = line.rstrip() | |
1779 | if (not message and not hgpatch and |
|
1779 | if (not message and not hgpatch and | |
1780 | mailre.match(line) and not opts['force']): |
|
1780 | mailre.match(line) and not opts['force']): | |
1781 | if len(line) > 35: |
|
1781 | if len(line) > 35: | |
1782 | line = line[:32] + '...' |
|
1782 | line = line[:32] + '...' | |
1783 | raise util.Abort(_('first line looks like a ' |
|
1783 | raise util.Abort(_('first line looks like a ' | |
1784 | 'mail header: ') + line) |
|
1784 | 'mail header: ') + line) | |
1785 | if diffre.match(line): |
|
1785 | if diffre.match(line): | |
1786 | break |
|
1786 | break | |
1787 | elif hgpatch: |
|
1787 | elif hgpatch: | |
1788 | # parse values when importing the result of an hg export |
|
1788 | # parse values when importing the result of an hg export | |
1789 | if line.startswith("# User "): |
|
1789 | if line.startswith("# User "): | |
1790 | user = line[7:] |
|
1790 | user = line[7:] | |
1791 | ui.debug(_('User: %s\n') % user) |
|
1791 | ui.debug(_('User: %s\n') % user) | |
1792 | elif not line.startswith("# ") and line: |
|
1792 | elif not line.startswith("# ") and line: | |
1793 | message.append(line) |
|
1793 | message.append(line) | |
1794 | hgpatch = False |
|
1794 | hgpatch = False | |
1795 | elif line == '# HG changeset patch': |
|
1795 | elif line == '# HG changeset patch': | |
1796 | hgpatch = True |
|
1796 | hgpatch = True | |
1797 | message = [] # We may have collected garbage |
|
1797 | message = [] # We may have collected garbage | |
1798 | else: |
|
1798 | else: | |
1799 | message.append(line) |
|
1799 | message.append(line) | |
1800 |
|
1800 | |||
1801 | # make sure message isn't empty |
|
1801 | # make sure message isn't empty | |
1802 | if not message: |
|
1802 | if not message: | |
1803 | message = _("imported patch %s\n") % patch |
|
1803 | message = _("imported patch %s\n") % patch | |
1804 | else: |
|
1804 | else: | |
1805 | message = "%s\n" % '\n'.join(message) |
|
1805 | message = "%s\n" % '\n'.join(message) | |
1806 | ui.debug(_('message:\n%s\n') % message) |
|
1806 | ui.debug(_('message:\n%s\n') % message) | |
1807 |
|
1807 | |||
1808 | files = util.patch(strip, pf, ui) |
|
1808 | files = util.patch(strip, pf, ui) | |
1809 |
|
1809 | |||
1810 | if len(files) > 0: |
|
1810 | if len(files) > 0: | |
1811 | addremove(ui, repo, *files) |
|
1811 | addremove(ui, repo, *files) | |
1812 | repo.commit(files, message, user) |
|
1812 | repo.commit(files, message, user) | |
1813 |
|
1813 | |||
1814 | def incoming(ui, repo, source="default", **opts): |
|
1814 | def incoming(ui, repo, source="default", **opts): | |
1815 | """show new changesets found in source |
|
1815 | """show new changesets found in source | |
1816 |
|
1816 | |||
1817 | Show new changesets found in the specified path/URL or the default |
|
1817 | Show new changesets found in the specified path/URL or the default | |
1818 | pull location. These are the changesets that would be pulled if a pull |
|
1818 | pull location. These are the changesets that would be pulled if a pull | |
1819 | was requested. |
|
1819 | was requested. | |
1820 |
|
1820 | |||
1821 | For remote repository, using --bundle avoids downloading the changesets |
|
1821 | For remote repository, using --bundle avoids downloading the changesets | |
1822 | twice if the incoming is followed by a pull. |
|
1822 | twice if the incoming is followed by a pull. | |
1823 |
|
1823 | |||
1824 | See pull for valid source format details. |
|
1824 | See pull for valid source format details. | |
1825 | """ |
|
1825 | """ | |
1826 | source = ui.expandpath(source) |
|
1826 | source = ui.expandpath(source) | |
1827 | if opts['ssh']: |
|
1827 | if opts['ssh']: | |
1828 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
1828 | ui.setconfig("ui", "ssh", opts['ssh']) | |
1829 | if opts['remotecmd']: |
|
1829 | if opts['remotecmd']: | |
1830 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
1830 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
1831 |
|
1831 | |||
1832 | other = hg.repository(ui, source) |
|
1832 | other = hg.repository(ui, source) | |
1833 | incoming = repo.findincoming(other, force=opts["force"]) |
|
1833 | incoming = repo.findincoming(other, force=opts["force"]) | |
1834 | if not incoming: |
|
1834 | if not incoming: | |
1835 | ui.status(_("no changes found\n")) |
|
1835 | ui.status(_("no changes found\n")) | |
1836 | return |
|
1836 | return | |
1837 |
|
1837 | |||
1838 | cleanup = None |
|
1838 | cleanup = None | |
1839 | try: |
|
1839 | try: | |
1840 | fname = opts["bundle"] |
|
1840 | fname = opts["bundle"] | |
1841 | if fname or not other.local(): |
|
1841 | if fname or not other.local(): | |
1842 | # create a bundle (uncompressed if other repo is not local) |
|
1842 | # create a bundle (uncompressed if other repo is not local) | |
1843 | cg = other.changegroup(incoming, "incoming") |
|
1843 | cg = other.changegroup(incoming, "incoming") | |
1844 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) |
|
1844 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) | |
1845 | # keep written bundle? |
|
1845 | # keep written bundle? | |
1846 | if opts["bundle"]: |
|
1846 | if opts["bundle"]: | |
1847 | cleanup = None |
|
1847 | cleanup = None | |
1848 | if not other.local(): |
|
1848 | if not other.local(): | |
1849 | # use the created uncompressed bundlerepo |
|
1849 | # use the created uncompressed bundlerepo | |
1850 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1850 | other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
1851 |
|
1851 | |||
1852 | o = other.changelog.nodesbetween(incoming)[0] |
|
1852 | o = other.changelog.nodesbetween(incoming)[0] | |
1853 | if opts['newest_first']: |
|
1853 | if opts['newest_first']: | |
1854 | o.reverse() |
|
1854 | o.reverse() | |
1855 | displayer = show_changeset(ui, other, opts) |
|
1855 | displayer = show_changeset(ui, other, opts) | |
1856 | for n in o: |
|
1856 | for n in o: | |
1857 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1857 | parents = [p for p in other.changelog.parents(n) if p != nullid] | |
1858 | if opts['no_merges'] and len(parents) == 2: |
|
1858 | if opts['no_merges'] and len(parents) == 2: | |
1859 | continue |
|
1859 | continue | |
1860 | displayer.show(changenode=n) |
|
1860 | displayer.show(changenode=n) | |
1861 | if opts['patch']: |
|
1861 | if opts['patch']: | |
1862 | prev = (parents and parents[0]) or nullid |
|
1862 | prev = (parents and parents[0]) or nullid | |
1863 | dodiff(ui, ui, other, prev, n) |
|
1863 | dodiff(ui, ui, other, prev, n) | |
1864 | ui.write("\n") |
|
1864 | ui.write("\n") | |
1865 | finally: |
|
1865 | finally: | |
1866 | if hasattr(other, 'close'): |
|
1866 | if hasattr(other, 'close'): | |
1867 | other.close() |
|
1867 | other.close() | |
1868 | if cleanup: |
|
1868 | if cleanup: | |
1869 | os.unlink(cleanup) |
|
1869 | os.unlink(cleanup) | |
1870 |
|
1870 | |||
1871 | def init(ui, dest="."): |
|
1871 | def init(ui, dest="."): | |
1872 | """create a new repository in the given directory |
|
1872 | """create a new repository in the given directory | |
1873 |
|
1873 | |||
1874 | Initialize a new repository in the given directory. If the given |
|
1874 | Initialize a new repository in the given directory. If the given | |
1875 | directory does not exist, it is created. |
|
1875 | directory does not exist, it is created. | |
1876 |
|
1876 | |||
1877 | If no directory is given, the current directory is used. |
|
1877 | If no directory is given, the current directory is used. | |
1878 | """ |
|
1878 | """ | |
1879 | if not os.path.exists(dest): |
|
1879 | if not os.path.exists(dest): | |
1880 | os.mkdir(dest) |
|
1880 | os.mkdir(dest) | |
1881 | hg.repository(ui, dest, create=1) |
|
1881 | hg.repository(ui, dest, create=1) | |
1882 |
|
1882 | |||
1883 | def locate(ui, repo, *pats, **opts): |
|
1883 | def locate(ui, repo, *pats, **opts): | |
1884 | """locate files matching specific patterns |
|
1884 | """locate files matching specific patterns | |
1885 |
|
1885 | |||
1886 | Print all files under Mercurial control whose names match the |
|
1886 | Print all files under Mercurial control whose names match the | |
1887 | given patterns. |
|
1887 | given patterns. | |
1888 |
|
1888 | |||
1889 | This command searches the current directory and its |
|
1889 | This command searches the current directory and its | |
1890 | subdirectories. To search an entire repository, move to the root |
|
1890 | subdirectories. To search an entire repository, move to the root | |
1891 | of the repository. |
|
1891 | of the repository. | |
1892 |
|
1892 | |||
1893 | If no patterns are given to match, this command prints all file |
|
1893 | If no patterns are given to match, this command prints all file | |
1894 | names. |
|
1894 | names. | |
1895 |
|
1895 | |||
1896 | If you want to feed the output of this command into the "xargs" |
|
1896 | If you want to feed the output of this command into the "xargs" | |
1897 | command, use the "-0" option to both this command and "xargs". |
|
1897 | command, use the "-0" option to both this command and "xargs". | |
1898 | This will avoid the problem of "xargs" treating single filenames |
|
1898 | This will avoid the problem of "xargs" treating single filenames | |
1899 | that contain white space as multiple filenames. |
|
1899 | that contain white space as multiple filenames. | |
1900 | """ |
|
1900 | """ | |
1901 | end = opts['print0'] and '\0' or '\n' |
|
1901 | end = opts['print0'] and '\0' or '\n' | |
1902 | rev = opts['rev'] |
|
1902 | rev = opts['rev'] | |
1903 | if rev: |
|
1903 | if rev: | |
1904 | node = repo.lookup(rev) |
|
1904 | node = repo.lookup(rev) | |
1905 | else: |
|
1905 | else: | |
1906 | node = None |
|
1906 | node = None | |
1907 |
|
1907 | |||
1908 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
1908 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
1909 | head='(?:.*/|)'): |
|
1909 | head='(?:.*/|)'): | |
1910 | if not node and repo.dirstate.state(abs) == '?': |
|
1910 | if not node and repo.dirstate.state(abs) == '?': | |
1911 | continue |
|
1911 | continue | |
1912 | if opts['fullpath']: |
|
1912 | if opts['fullpath']: | |
1913 | ui.write(os.path.join(repo.root, abs), end) |
|
1913 | ui.write(os.path.join(repo.root, abs), end) | |
1914 | else: |
|
1914 | else: | |
1915 | ui.write(((pats and rel) or abs), end) |
|
1915 | ui.write(((pats and rel) or abs), end) | |
1916 |
|
1916 | |||
1917 | def log(ui, repo, *pats, **opts): |
|
1917 | def log(ui, repo, *pats, **opts): | |
1918 | """show revision history of entire repository or files |
|
1918 | """show revision history of entire repository or files | |
1919 |
|
1919 | |||
1920 | Print the revision history of the specified files or the entire project. |
|
1920 | Print the revision history of the specified files or the entire project. | |
1921 |
|
1921 | |||
1922 | By default this command outputs: changeset id and hash, tags, |
|
1922 | By default this command outputs: changeset id and hash, tags, | |
1923 | non-trivial parents, user, date and time, and a summary for each |
|
1923 | non-trivial parents, user, date and time, and a summary for each | |
1924 | commit. When the -v/--verbose switch is used, the list of changed |
|
1924 | commit. When the -v/--verbose switch is used, the list of changed | |
1925 | files and full commit message is shown. |
|
1925 | files and full commit message is shown. | |
1926 | """ |
|
1926 | """ | |
1927 | class dui(object): |
|
1927 | class dui(object): | |
1928 | # Implement and delegate some ui protocol. Save hunks of |
|
1928 | # Implement and delegate some ui protocol. Save hunks of | |
1929 | # output for later display in the desired order. |
|
1929 | # output for later display in the desired order. | |
1930 | def __init__(self, ui): |
|
1930 | def __init__(self, ui): | |
1931 | self.ui = ui |
|
1931 | self.ui = ui | |
1932 | self.hunk = {} |
|
1932 | self.hunk = {} | |
1933 | self.header = {} |
|
1933 | self.header = {} | |
1934 | def bump(self, rev): |
|
1934 | def bump(self, rev): | |
1935 | self.rev = rev |
|
1935 | self.rev = rev | |
1936 | self.hunk[rev] = [] |
|
1936 | self.hunk[rev] = [] | |
1937 | self.header[rev] = [] |
|
1937 | self.header[rev] = [] | |
1938 | def note(self, *args): |
|
1938 | def note(self, *args): | |
1939 | if self.verbose: |
|
1939 | if self.verbose: | |
1940 | self.write(*args) |
|
1940 | self.write(*args) | |
1941 | def status(self, *args): |
|
1941 | def status(self, *args): | |
1942 | if not self.quiet: |
|
1942 | if not self.quiet: | |
1943 | self.write(*args) |
|
1943 | self.write(*args) | |
1944 | def write(self, *args): |
|
1944 | def write(self, *args): | |
1945 | self.hunk[self.rev].append(args) |
|
1945 | self.hunk[self.rev].append(args) | |
1946 | def write_header(self, *args): |
|
1946 | def write_header(self, *args): | |
1947 | self.header[self.rev].append(args) |
|
1947 | self.header[self.rev].append(args) | |
1948 | def debug(self, *args): |
|
1948 | def debug(self, *args): | |
1949 | if self.debugflag: |
|
1949 | if self.debugflag: | |
1950 | self.write(*args) |
|
1950 | self.write(*args) | |
1951 | def __getattr__(self, key): |
|
1951 | def __getattr__(self, key): | |
1952 | return getattr(self.ui, key) |
|
1952 | return getattr(self.ui, key) | |
1953 |
|
1953 | |||
1954 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1954 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) | |
1955 |
|
1955 | |||
1956 | if opts['limit']: |
|
1956 | if opts['limit']: | |
1957 | try: |
|
1957 | try: | |
1958 | limit = int(opts['limit']) |
|
1958 | limit = int(opts['limit']) | |
1959 | except ValueError: |
|
1959 | except ValueError: | |
1960 | raise util.Abort(_('limit must be a positive integer')) |
|
1960 | raise util.Abort(_('limit must be a positive integer')) | |
1961 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1961 | if limit <= 0: raise util.Abort(_('limit must be positive')) | |
1962 | else: |
|
1962 | else: | |
1963 | limit = sys.maxint |
|
1963 | limit = sys.maxint | |
1964 | count = 0 |
|
1964 | count = 0 | |
1965 |
|
1965 | |||
1966 | displayer = show_changeset(ui, repo, opts) |
|
1966 | displayer = show_changeset(ui, repo, opts) | |
1967 | for st, rev, fns in changeiter: |
|
1967 | for st, rev, fns in changeiter: | |
1968 | if st == 'window': |
|
1968 | if st == 'window': | |
1969 | du = dui(ui) |
|
1969 | du = dui(ui) | |
1970 | displayer.ui = du |
|
1970 | displayer.ui = du | |
1971 | elif st == 'add': |
|
1971 | elif st == 'add': | |
1972 | du.bump(rev) |
|
1972 | du.bump(rev) | |
1973 | changenode = repo.changelog.node(rev) |
|
1973 | changenode = repo.changelog.node(rev) | |
1974 | parents = [p for p in repo.changelog.parents(changenode) |
|
1974 | parents = [p for p in repo.changelog.parents(changenode) | |
1975 | if p != nullid] |
|
1975 | if p != nullid] | |
1976 | if opts['no_merges'] and len(parents) == 2: |
|
1976 | if opts['no_merges'] and len(parents) == 2: | |
1977 | continue |
|
1977 | continue | |
1978 | if opts['only_merges'] and len(parents) != 2: |
|
1978 | if opts['only_merges'] and len(parents) != 2: | |
1979 | continue |
|
1979 | continue | |
1980 |
|
1980 | |||
1981 | if opts['keyword']: |
|
1981 | if opts['keyword']: | |
1982 | changes = getchange(rev) |
|
1982 | changes = getchange(rev) | |
1983 | miss = 0 |
|
1983 | miss = 0 | |
1984 | for k in [kw.lower() for kw in opts['keyword']]: |
|
1984 | for k in [kw.lower() for kw in opts['keyword']]: | |
1985 | if not (k in changes[1].lower() or |
|
1985 | if not (k in changes[1].lower() or | |
1986 | k in changes[4].lower() or |
|
1986 | k in changes[4].lower() or | |
1987 | k in " ".join(changes[3][:20]).lower()): |
|
1987 | k in " ".join(changes[3][:20]).lower()): | |
1988 | miss = 1 |
|
1988 | miss = 1 | |
1989 | break |
|
1989 | break | |
1990 | if miss: |
|
1990 | if miss: | |
1991 | continue |
|
1991 | continue | |
1992 |
|
1992 | |||
1993 | br = None |
|
1993 | br = None | |
1994 | if opts['branches']: |
|
1994 | if opts['branches']: | |
1995 | br = repo.branchlookup([repo.changelog.node(rev)]) |
|
1995 | br = repo.branchlookup([repo.changelog.node(rev)]) | |
1996 |
|
1996 | |||
1997 | displayer.show(rev, brinfo=br) |
|
1997 | displayer.show(rev, brinfo=br) | |
1998 | if opts['patch']: |
|
1998 | if opts['patch']: | |
1999 | prev = (parents and parents[0]) or nullid |
|
1999 | prev = (parents and parents[0]) or nullid | |
2000 | dodiff(du, du, repo, prev, changenode, match=matchfn) |
|
2000 | dodiff(du, du, repo, prev, changenode, match=matchfn) | |
2001 | du.write("\n\n") |
|
2001 | du.write("\n\n") | |
2002 | elif st == 'iter': |
|
2002 | elif st == 'iter': | |
2003 | if count == limit: break |
|
2003 | if count == limit: break | |
2004 | if du.header[rev]: |
|
2004 | if du.header[rev]: | |
2005 | for args in du.header[rev]: |
|
2005 | for args in du.header[rev]: | |
2006 | ui.write_header(*args) |
|
2006 | ui.write_header(*args) | |
2007 | if du.hunk[rev]: |
|
2007 | if du.hunk[rev]: | |
2008 | count += 1 |
|
2008 | count += 1 | |
2009 | for args in du.hunk[rev]: |
|
2009 | for args in du.hunk[rev]: | |
2010 | ui.write(*args) |
|
2010 | ui.write(*args) | |
2011 |
|
2011 | |||
2012 | def manifest(ui, repo, rev=None): |
|
2012 | def manifest(ui, repo, rev=None): | |
2013 | """output the latest or given revision of the project manifest |
|
2013 | """output the latest or given revision of the project manifest | |
2014 |
|
2014 | |||
2015 | Print a list of version controlled files for the given revision. |
|
2015 | Print a list of version controlled files for the given revision. | |
2016 |
|
2016 | |||
2017 | The manifest is the list of files being version controlled. If no revision |
|
2017 | The manifest is the list of files being version controlled. If no revision | |
2018 | is given then the tip is used. |
|
2018 | is given then the tip is used. | |
2019 | """ |
|
2019 | """ | |
2020 | if rev: |
|
2020 | if rev: | |
2021 | try: |
|
2021 | try: | |
2022 | # assume all revision numbers are for changesets |
|
2022 | # assume all revision numbers are for changesets | |
2023 | n = repo.lookup(rev) |
|
2023 | n = repo.lookup(rev) | |
2024 | change = repo.changelog.read(n) |
|
2024 | change = repo.changelog.read(n) | |
2025 | n = change[0] |
|
2025 | n = change[0] | |
2026 | except hg.RepoError: |
|
2026 | except hg.RepoError: | |
2027 | n = repo.manifest.lookup(rev) |
|
2027 | n = repo.manifest.lookup(rev) | |
2028 | else: |
|
2028 | else: | |
2029 | n = repo.manifest.tip() |
|
2029 | n = repo.manifest.tip() | |
2030 | m = repo.manifest.read(n) |
|
2030 | m = repo.manifest.read(n) | |
2031 | mf = repo.manifest.readflags(n) |
|
2031 | mf = repo.manifest.readflags(n) | |
2032 | files = m.keys() |
|
2032 | files = m.keys() | |
2033 | files.sort() |
|
2033 | files.sort() | |
2034 |
|
2034 | |||
2035 | for f in files: |
|
2035 | for f in files: | |
2036 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) |
|
2036 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) | |
2037 |
|
2037 | |||
2038 | def merge(ui, repo, node=None, **opts): |
|
2038 | def merge(ui, repo, node=None, **opts): | |
2039 | """Merge working directory with another revision |
|
2039 | """Merge working directory with another revision | |
2040 |
|
2040 | |||
2041 | Merge the contents of the current working directory and the |
|
2041 | Merge the contents of the current working directory and the | |
2042 | requested revision. Files that changed between either parent are |
|
2042 | requested revision. Files that changed between either parent are | |
2043 | marked as changed for the next commit and a commit must be |
|
2043 | marked as changed for the next commit and a commit must be | |
2044 | performed before any further updates are allowed. |
|
2044 | performed before any further updates are allowed. | |
2045 | """ |
|
2045 | """ | |
2046 | return update(ui, repo, node=node, merge=True, **opts) |
|
2046 | return update(ui, repo, node=node, merge=True, **opts) | |
2047 |
|
2047 | |||
2048 | def outgoing(ui, repo, dest="default-push", **opts): |
|
2048 | def outgoing(ui, repo, dest="default-push", **opts): | |
2049 | """show changesets not found in destination |
|
2049 | """show changesets not found in destination | |
2050 |
|
2050 | |||
2051 | Show changesets not found in the specified destination repository or |
|
2051 | Show changesets not found in the specified destination repository or | |
2052 | the default push location. These are the changesets that would be pushed |
|
2052 | the default push location. These are the changesets that would be pushed | |
2053 | if a push was requested. |
|
2053 | if a push was requested. | |
2054 |
|
2054 | |||
2055 | See pull for valid destination format details. |
|
2055 | See pull for valid destination format details. | |
2056 | """ |
|
2056 | """ | |
2057 | dest = ui.expandpath(dest) |
|
2057 | dest = ui.expandpath(dest) | |
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, dest) |
|
2063 | other = hg.repository(ui, dest) | |
2064 | o = repo.findoutgoing(other, force=opts['force']) |
|
2064 | o = repo.findoutgoing(other, force=opts['force']) | |
2065 | if not o: |
|
2065 | if not o: | |
2066 | ui.status(_("no changes found\n")) |
|
2066 | ui.status(_("no changes found\n")) | |
2067 | return |
|
2067 | return | |
2068 | o = repo.changelog.nodesbetween(o)[0] |
|
2068 | o = repo.changelog.nodesbetween(o)[0] | |
2069 | if opts['newest_first']: |
|
2069 | if opts['newest_first']: | |
2070 | o.reverse() |
|
2070 | o.reverse() | |
2071 | displayer = show_changeset(ui, repo, opts) |
|
2071 | displayer = show_changeset(ui, repo, opts) | |
2072 | for n in o: |
|
2072 | for n in o: | |
2073 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
2073 | parents = [p for p in repo.changelog.parents(n) if p != nullid] | |
2074 | if opts['no_merges'] and len(parents) == 2: |
|
2074 | if opts['no_merges'] and len(parents) == 2: | |
2075 | continue |
|
2075 | continue | |
2076 | displayer.show(changenode=n) |
|
2076 | displayer.show(changenode=n) | |
2077 | if opts['patch']: |
|
2077 | if opts['patch']: | |
2078 | prev = (parents and parents[0]) or nullid |
|
2078 | prev = (parents and parents[0]) or nullid | |
2079 | dodiff(ui, ui, repo, prev, n) |
|
2079 | dodiff(ui, ui, repo, prev, n) | |
2080 | ui.write("\n") |
|
2080 | ui.write("\n") | |
2081 |
|
2081 | |||
2082 | def parents(ui, repo, rev=None, branches=None, **opts): |
|
2082 | def parents(ui, repo, rev=None, branches=None, **opts): | |
2083 | """show the parents of the working dir or revision |
|
2083 | """show the parents of the working dir or revision | |
2084 |
|
2084 | |||
2085 | Print the working directory's parent revisions. |
|
2085 | Print the working directory's parent revisions. | |
2086 | """ |
|
2086 | """ | |
2087 | if rev: |
|
2087 | if rev: | |
2088 | p = repo.changelog.parents(repo.lookup(rev)) |
|
2088 | p = repo.changelog.parents(repo.lookup(rev)) | |
2089 | else: |
|
2089 | else: | |
2090 | p = repo.dirstate.parents() |
|
2090 | p = repo.dirstate.parents() | |
2091 |
|
2091 | |||
2092 | br = None |
|
2092 | br = None | |
2093 | if branches is not None: |
|
2093 | if branches is not None: | |
2094 | br = repo.branchlookup(p) |
|
2094 | br = repo.branchlookup(p) | |
2095 | displayer = show_changeset(ui, repo, opts) |
|
2095 | displayer = show_changeset(ui, repo, opts) | |
2096 | for n in p: |
|
2096 | for n in p: | |
2097 | if n != nullid: |
|
2097 | if n != nullid: | |
2098 | displayer.show(changenode=n, brinfo=br) |
|
2098 | displayer.show(changenode=n, brinfo=br) | |
2099 |
|
2099 | |||
2100 | def paths(ui, repo, search=None): |
|
2100 | def paths(ui, repo, search=None): | |
2101 | """show definition of symbolic path names |
|
2101 | """show definition of symbolic path names | |
2102 |
|
2102 | |||
2103 | Show definition of symbolic path name NAME. If no name is given, show |
|
2103 | Show definition of symbolic path name NAME. If no name is given, show | |
2104 | definition of available names. |
|
2104 | definition of available names. | |
2105 |
|
2105 | |||
2106 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
2106 | Path names are defined in the [paths] section of /etc/mercurial/hgrc | |
2107 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2107 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. | |
2108 | """ |
|
2108 | """ | |
2109 | if search: |
|
2109 | if search: | |
2110 | for name, path in ui.configitems("paths"): |
|
2110 | for name, path in ui.configitems("paths"): | |
2111 | if name == search: |
|
2111 | if name == search: | |
2112 | ui.write("%s\n" % path) |
|
2112 | ui.write("%s\n" % path) | |
2113 | return |
|
2113 | return | |
2114 | ui.warn(_("not found!\n")) |
|
2114 | ui.warn(_("not found!\n")) | |
2115 | return 1 |
|
2115 | return 1 | |
2116 | else: |
|
2116 | else: | |
2117 | for name, path in ui.configitems("paths"): |
|
2117 | for name, path in ui.configitems("paths"): | |
2118 | ui.write("%s = %s\n" % (name, path)) |
|
2118 | ui.write("%s = %s\n" % (name, path)) | |
2119 |
|
2119 | |||
2120 | def postincoming(ui, repo, modheads, optupdate): |
|
2120 | def postincoming(ui, repo, modheads, optupdate): | |
2121 | if modheads == 0: |
|
2121 | if modheads == 0: | |
2122 | return |
|
2122 | return | |
2123 | if optupdate: |
|
2123 | if optupdate: | |
2124 | if modheads == 1: |
|
2124 | if modheads == 1: | |
2125 | return update(ui, repo) |
|
2125 | return update(ui, repo) | |
2126 | else: |
|
2126 | else: | |
2127 | ui.status(_("not updating, since new heads added\n")) |
|
2127 | ui.status(_("not updating, since new heads added\n")) | |
2128 | if modheads > 1: |
|
2128 | if modheads > 1: | |
2129 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
2129 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) | |
2130 | else: |
|
2130 | else: | |
2131 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2131 | ui.status(_("(run 'hg update' to get a working copy)\n")) | |
2132 |
|
2132 | |||
2133 | def pull(ui, repo, source="default", **opts): |
|
2133 | def pull(ui, repo, source="default", **opts): | |
2134 | """pull changes from the specified source |
|
2134 | """pull changes from the specified source | |
2135 |
|
2135 | |||
2136 | Pull changes from a remote repository to a local one. |
|
2136 | Pull changes from a remote repository to a local one. | |
2137 |
|
2137 | |||
2138 | This finds all changes from the repository at the specified path |
|
2138 | This finds all changes from the repository at the specified path | |
2139 | or URL and adds them to the local repository. By default, this |
|
2139 | or URL and adds them to the local repository. By default, this | |
2140 | does not update the copy of the project in the working directory. |
|
2140 | does not update the copy of the project in the working directory. | |
2141 |
|
2141 | |||
2142 | Valid URLs are of the form: |
|
2142 | Valid URLs are of the form: | |
2143 |
|
2143 | |||
2144 | local/filesystem/path |
|
2144 | local/filesystem/path | |
2145 | http://[user@]host[:port][/path] |
|
2145 | http://[user@]host[:port][/path] | |
2146 | https://[user@]host[:port][/path] |
|
2146 | https://[user@]host[:port][/path] | |
2147 | ssh://[user@]host[:port][/path] |
|
2147 | ssh://[user@]host[:port][/path] | |
2148 |
|
2148 | |||
2149 | Some notes about using SSH with Mercurial: |
|
2149 | Some notes about using SSH with Mercurial: | |
2150 | - SSH requires an accessible shell account on the destination machine |
|
2150 | - SSH requires an accessible shell account on the destination machine | |
2151 | and a copy of hg in the remote path or specified with as remotecmd. |
|
2151 | and a copy of hg in the remote path or specified with as remotecmd. | |
2152 | - /path is relative to the remote user's home directory by default. |
|
2152 | - /path is relative to the remote user's home directory by default. | |
2153 | Use two slashes at the start of a path to specify an absolute path. |
|
2153 | Use two slashes at the start of a path to specify an absolute path. | |
2154 | - Mercurial doesn't use its own compression via SSH; the right thing |
|
2154 | - Mercurial doesn't use its own compression via SSH; the right thing | |
2155 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: |
|
2155 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: | |
2156 | Host *.mylocalnetwork.example.com |
|
2156 | Host *.mylocalnetwork.example.com | |
2157 | Compression off |
|
2157 | Compression off | |
2158 | Host * |
|
2158 | Host * | |
2159 | Compression on |
|
2159 | Compression on | |
2160 | Alternatively specify "ssh -C" as your ssh command in your hgrc or |
|
2160 | Alternatively specify "ssh -C" as your ssh command in your hgrc or | |
2161 | with the --ssh command line option. |
|
2161 | with the --ssh command line option. | |
2162 | """ |
|
2162 | """ | |
2163 | source = ui.expandpath(source) |
|
2163 | source = ui.expandpath(source) | |
2164 | ui.status(_('pulling from %s\n') % (source)) |
|
2164 | ui.status(_('pulling from %s\n') % (source)) | |
2165 |
|
2165 | |||
2166 | if opts['ssh']: |
|
2166 | if opts['ssh']: | |
2167 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2167 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2168 | if opts['remotecmd']: |
|
2168 | if opts['remotecmd']: | |
2169 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2169 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2170 |
|
2170 | |||
2171 | other = hg.repository(ui, source) |
|
2171 | other = hg.repository(ui, source) | |
2172 | revs = None |
|
2172 | revs = None | |
2173 | if opts['rev'] and not other.local(): |
|
2173 | if opts['rev'] and not other.local(): | |
2174 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) |
|
2174 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) | |
2175 | elif opts['rev']: |
|
2175 | elif opts['rev']: | |
2176 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
2176 | revs = [other.lookup(rev) for rev in opts['rev']] | |
2177 | modheads = repo.pull(other, heads=revs, force=opts['force']) |
|
2177 | modheads = repo.pull(other, heads=revs, force=opts['force']) | |
2178 | return postincoming(ui, repo, modheads, opts['update']) |
|
2178 | return postincoming(ui, repo, modheads, opts['update']) | |
2179 |
|
2179 | |||
2180 | def push(ui, repo, dest="default-push", **opts): |
|
2180 | def push(ui, repo, dest="default-push", **opts): | |
2181 | """push changes to the specified destination |
|
2181 | """push changes to the specified destination | |
2182 |
|
2182 | |||
2183 | Push changes from the local repository to the given destination. |
|
2183 | Push changes from the local repository to the given destination. | |
2184 |
|
2184 | |||
2185 | This is the symmetrical operation for pull. It helps to move |
|
2185 | This is the symmetrical operation for pull. It helps to move | |
2186 | changes from the current repository to a different one. If the |
|
2186 | changes from the current repository to a different one. If the | |
2187 | destination is local this is identical to a pull in that directory |
|
2187 | destination is local this is identical to a pull in that directory | |
2188 | from the current one. |
|
2188 | from the current one. | |
2189 |
|
2189 | |||
2190 | By default, push will refuse to run if it detects the result would |
|
2190 | By default, push will refuse to run if it detects the result would | |
2191 | increase the number of remote heads. This generally indicates the |
|
2191 | increase the number of remote heads. This generally indicates the | |
2192 | the client has forgotten to sync and merge before pushing. |
|
2192 | the client has forgotten to sync and merge before pushing. | |
2193 |
|
2193 | |||
2194 | Valid URLs are of the form: |
|
2194 | Valid URLs are of the form: | |
2195 |
|
2195 | |||
2196 | local/filesystem/path |
|
2196 | local/filesystem/path | |
2197 | ssh://[user@]host[:port][/path] |
|
2197 | ssh://[user@]host[:port][/path] | |
2198 |
|
2198 | |||
2199 | Look at the help text for the pull command for important details |
|
2199 | Look at the help text for the pull command for important details | |
2200 | about ssh:// URLs. |
|
2200 | about ssh:// URLs. | |
2201 | """ |
|
2201 | """ | |
2202 | dest = ui.expandpath(dest) |
|
2202 | dest = ui.expandpath(dest) | |
2203 | ui.status('pushing to %s\n' % (dest)) |
|
2203 | ui.status('pushing to %s\n' % (dest)) | |
2204 |
|
2204 | |||
2205 | if opts['ssh']: |
|
2205 | if opts['ssh']: | |
2206 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2206 | ui.setconfig("ui", "ssh", opts['ssh']) | |
2207 | if opts['remotecmd']: |
|
2207 | if opts['remotecmd']: | |
2208 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2208 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) | |
2209 |
|
2209 | |||
2210 | other = hg.repository(ui, dest) |
|
2210 | other = hg.repository(ui, dest) | |
2211 | revs = None |
|
2211 | revs = None | |
2212 | if opts['rev']: |
|
2212 | if opts['rev']: | |
2213 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
2213 | revs = [repo.lookup(rev) for rev in opts['rev']] | |
2214 | r = repo.push(other, opts['force'], revs=revs) |
|
2214 | r = repo.push(other, opts['force'], revs=revs) | |
2215 | return r == 0 |
|
2215 | return r == 0 | |
2216 |
|
2216 | |||
2217 | def rawcommit(ui, repo, *flist, **rc): |
|
2217 | def rawcommit(ui, repo, *flist, **rc): | |
2218 | """raw commit interface (DEPRECATED) |
|
2218 | """raw commit interface (DEPRECATED) | |
2219 |
|
2219 | |||
2220 | (DEPRECATED) |
|
2220 | (DEPRECATED) | |
2221 | Lowlevel commit, for use in helper scripts. |
|
2221 | Lowlevel commit, for use in helper scripts. | |
2222 |
|
2222 | |||
2223 | This command is not intended to be used by normal users, as it is |
|
2223 | This command is not intended to be used by normal users, as it is | |
2224 | primarily useful for importing from other SCMs. |
|
2224 | primarily useful for importing from other SCMs. | |
2225 |
|
2225 | |||
2226 | This command is now deprecated and will be removed in a future |
|
2226 | This command is now deprecated and will be removed in a future | |
2227 | release, please use debugsetparents and commit instead. |
|
2227 | release, please use debugsetparents and commit instead. | |
2228 | """ |
|
2228 | """ | |
2229 |
|
2229 | |||
2230 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
2230 | ui.warn(_("(the rawcommit command is deprecated)\n")) | |
2231 |
|
2231 | |||
2232 | message = rc['message'] |
|
2232 | message = rc['message'] | |
2233 | if not message and rc['logfile']: |
|
2233 | if not message and rc['logfile']: | |
2234 | try: |
|
2234 | try: | |
2235 | message = open(rc['logfile']).read() |
|
2235 | message = open(rc['logfile']).read() | |
2236 | except IOError: |
|
2236 | except IOError: | |
2237 | pass |
|
2237 | pass | |
2238 | if not message and not rc['logfile']: |
|
2238 | if not message and not rc['logfile']: | |
2239 | raise util.Abort(_("missing commit message")) |
|
2239 | raise util.Abort(_("missing commit message")) | |
2240 |
|
2240 | |||
2241 | files = relpath(repo, list(flist)) |
|
2241 | files = relpath(repo, list(flist)) | |
2242 | if rc['files']: |
|
2242 | if rc['files']: | |
2243 | files += open(rc['files']).read().splitlines() |
|
2243 | files += open(rc['files']).read().splitlines() | |
2244 |
|
2244 | |||
2245 | rc['parent'] = map(repo.lookup, rc['parent']) |
|
2245 | rc['parent'] = map(repo.lookup, rc['parent']) | |
2246 |
|
2246 | |||
2247 | try: |
|
2247 | try: | |
2248 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) |
|
2248 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) | |
2249 | except ValueError, inst: |
|
2249 | except ValueError, inst: | |
2250 | raise util.Abort(str(inst)) |
|
2250 | raise util.Abort(str(inst)) | |
2251 |
|
2251 | |||
2252 | def recover(ui, repo): |
|
2252 | def recover(ui, repo): | |
2253 | """roll back an interrupted transaction |
|
2253 | """roll back an interrupted transaction | |
2254 |
|
2254 | |||
2255 | Recover from an interrupted commit or pull. |
|
2255 | Recover from an interrupted commit or pull. | |
2256 |
|
2256 | |||
2257 | This command tries to fix the repository status after an interrupted |
|
2257 | This command tries to fix the repository status after an interrupted | |
2258 | operation. It should only be necessary when Mercurial suggests it. |
|
2258 | operation. It should only be necessary when Mercurial suggests it. | |
2259 | """ |
|
2259 | """ | |
2260 | if repo.recover(): |
|
2260 | if repo.recover(): | |
2261 | return repo.verify() |
|
2261 | return repo.verify() | |
2262 | return False |
|
2262 | return False | |
2263 |
|
2263 | |||
2264 | def remove(ui, repo, pat, *pats, **opts): |
|
2264 | def remove(ui, repo, pat, *pats, **opts): | |
2265 | """remove the specified files on the next commit |
|
2265 | """remove the specified files on the next commit | |
2266 |
|
2266 | |||
2267 | Schedule the indicated files for removal from the repository. |
|
2267 | Schedule the indicated files for removal from the repository. | |
2268 |
|
2268 | |||
2269 | This command schedules the files to be removed at the next commit. |
|
2269 | This command schedules the files to be removed at the next commit. | |
2270 | This only removes files from the current branch, not from the |
|
2270 | This only removes files from the current branch, not from the | |
2271 | entire project history. If the files still exist in the working |
|
2271 | entire project history. If the files still exist in the working | |
2272 | directory, they will be deleted from it. |
|
2272 | directory, they will be deleted from it. | |
2273 | """ |
|
2273 | """ | |
2274 | names = [] |
|
2274 | names = [] | |
2275 | def okaytoremove(abs, rel, exact): |
|
2275 | def okaytoremove(abs, rel, exact): | |
2276 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) |
|
2276 | modified, added, removed, deleted, unknown = repo.changes(files=[abs]) | |
2277 | reason = None |
|
2277 | reason = None | |
2278 | if modified and not opts['force']: |
|
2278 | if modified and not opts['force']: | |
2279 | reason = _('is modified') |
|
2279 | reason = _('is modified') | |
2280 | elif added: |
|
2280 | elif added: | |
2281 | reason = _('has been marked for add') |
|
2281 | reason = _('has been marked for add') | |
2282 | elif unknown: |
|
2282 | elif unknown: | |
2283 | reason = _('is not managed') |
|
2283 | reason = _('is not managed') | |
2284 | if reason: |
|
2284 | if reason: | |
2285 | if exact: |
|
2285 | if exact: | |
2286 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
2286 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | |
2287 | else: |
|
2287 | else: | |
2288 | return True |
|
2288 | return True | |
2289 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): |
|
2289 | for src, abs, rel, exact in walk(repo, (pat,) + pats, opts): | |
2290 | if okaytoremove(abs, rel, exact): |
|
2290 | if okaytoremove(abs, rel, exact): | |
2291 | if ui.verbose or not exact: |
|
2291 | if ui.verbose or not exact: | |
2292 | ui.status(_('removing %s\n') % rel) |
|
2292 | ui.status(_('removing %s\n') % rel) | |
2293 | names.append(abs) |
|
2293 | names.append(abs) | |
2294 | repo.remove(names, unlink=True) |
|
2294 | repo.remove(names, unlink=True) | |
2295 |
|
2295 | |||
2296 | def rename(ui, repo, *pats, **opts): |
|
2296 | def rename(ui, repo, *pats, **opts): | |
2297 | """rename files; equivalent of copy + remove |
|
2297 | """rename files; equivalent of copy + remove | |
2298 |
|
2298 | |||
2299 | Mark dest as copies of sources; mark sources for deletion. If |
|
2299 | Mark dest as copies of sources; mark sources for deletion. If | |
2300 | dest is a directory, copies are put in that directory. If dest is |
|
2300 | dest is a directory, copies are put in that directory. If dest is | |
2301 | a file, there can only be one source. |
|
2301 | a file, there can only be one source. | |
2302 |
|
2302 | |||
2303 | By default, this command copies the contents of files as they |
|
2303 | By default, this command copies the contents of files as they | |
2304 | stand in the working directory. If invoked with --after, the |
|
2304 | stand in the working directory. If invoked with --after, the | |
2305 | operation is recorded, but no copying is performed. |
|
2305 | operation is recorded, but no copying is performed. | |
2306 |
|
2306 | |||
2307 | This command takes effect in the next commit. |
|
2307 | This command takes effect in the next commit. | |
2308 |
|
2308 | |||
2309 | NOTE: This command should be treated as experimental. While it |
|
2309 | NOTE: This command should be treated as experimental. While it | |
2310 | should properly record rename files, this information is not yet |
|
2310 | should properly record rename files, this information is not yet | |
2311 | fully used by merge, nor fully reported by log. |
|
2311 | fully used by merge, nor fully reported by log. | |
2312 | """ |
|
2312 | """ | |
2313 | wlock = repo.wlock(0) |
|
2313 | wlock = repo.wlock(0) | |
2314 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
2314 | errs, copied = docopy(ui, repo, pats, opts, wlock) | |
2315 | names = [] |
|
2315 | names = [] | |
2316 | for abs, rel, exact in copied: |
|
2316 | for abs, rel, exact in copied: | |
2317 | if ui.verbose or not exact: |
|
2317 | if ui.verbose or not exact: | |
2318 | ui.status(_('removing %s\n') % rel) |
|
2318 | ui.status(_('removing %s\n') % rel) | |
2319 | names.append(abs) |
|
2319 | names.append(abs) | |
2320 | repo.remove(names, True, wlock) |
|
2320 | repo.remove(names, True, wlock) | |
2321 | return errs |
|
2321 | return errs | |
2322 |
|
2322 | |||
2323 | def revert(ui, repo, *pats, **opts): |
|
2323 | def revert(ui, repo, *pats, **opts): | |
2324 | """revert modified files or dirs back to their unmodified states |
|
2324 | """revert modified files or dirs back to their unmodified states | |
2325 |
|
2325 | |||
2326 | In its default mode, it reverts any uncommitted modifications made |
|
2326 | In its default mode, it reverts any uncommitted modifications made | |
2327 | to the named files or directories. This restores the contents of |
|
2327 | to the named files or directories. This restores the contents of | |
2328 | the affected files to an unmodified state. |
|
2328 | the affected files to an unmodified state. | |
2329 |
|
2329 | |||
2330 | Modified files are saved with a .orig suffix before reverting. |
|
2330 | Modified files are saved with a .orig suffix before reverting. | |
2331 | To disable these backups, use --no-backup. |
|
2331 | To disable these backups, use --no-backup. | |
2332 |
|
2332 | |||
2333 | Using the -r option, it reverts the given files or directories to |
|
2333 | Using the -r option, it reverts the given files or directories to | |
2334 | their state as of an earlier revision. This can be helpful to "roll |
|
2334 | their state as of an earlier revision. This can be helpful to "roll | |
2335 | back" some or all of a change that should not have been committed. |
|
2335 | back" some or all of a change that should not have been committed. | |
2336 |
|
2336 | |||
2337 | Revert modifies the working directory. It does not commit any |
|
2337 | Revert modifies the working directory. It does not commit any | |
2338 | changes, or change the parent of the current working directory. |
|
2338 | changes, or change the parent of the current working directory. | |
2339 |
|
2339 | |||
2340 | If a file has been deleted, it is recreated. If the executable |
|
2340 | If a file has been deleted, it is recreated. If the executable | |
2341 | mode of a file was changed, it is reset. |
|
2341 | mode of a file was changed, it is reset. | |
2342 |
|
2342 | |||
2343 | If names are given, all files matching the names are reverted. |
|
2343 | If names are given, all files matching the names are reverted. | |
2344 |
|
2344 | |||
2345 | If no arguments are given, all files in the repository are reverted. |
|
2345 | If no arguments are given, all files in the repository are reverted. | |
2346 | """ |
|
2346 | """ | |
2347 | parent = repo.dirstate.parents()[0] |
|
2347 | parent = repo.dirstate.parents()[0] | |
2348 | node = opts['rev'] and repo.lookup(opts['rev']) or parent |
|
2348 | node = opts['rev'] and repo.lookup(opts['rev']) or parent | |
2349 | mf = repo.manifest.read(repo.changelog.read(node)[0]) |
|
2349 | mf = repo.manifest.read(repo.changelog.read(node)[0]) | |
2350 |
|
2350 | |||
2351 | wlock = repo.wlock() |
|
2351 | wlock = repo.wlock() | |
2352 |
|
2352 | |||
2353 | # need all matching names in dirstate and manifest of target rev, |
|
2353 | # need all matching names in dirstate and manifest of target rev, | |
2354 | # so have to walk both. do not print errors if files exist in one |
|
2354 | # so have to walk both. do not print errors if files exist in one | |
2355 | # but not other. |
|
2355 | # but not other. | |
2356 |
|
2356 | |||
2357 | names = {} |
|
2357 | names = {} | |
2358 | target_only = {} |
|
2358 | target_only = {} | |
2359 |
|
2359 | |||
2360 | # walk dirstate. |
|
2360 | # walk dirstate. | |
2361 |
|
2361 | |||
2362 | for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): |
|
2362 | for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): | |
2363 | names[abs] = (rel, exact) |
|
2363 | names[abs] = (rel, exact) | |
2364 | if src == 'b': |
|
2364 | if src == 'b': | |
2365 | target_only[abs] = True |
|
2365 | target_only[abs] = True | |
2366 |
|
2366 | |||
2367 | # walk target manifest. |
|
2367 | # walk target manifest. | |
2368 |
|
2368 | |||
2369 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
2369 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, | |
2370 | badmatch=names.has_key): |
|
2370 | badmatch=names.has_key): | |
2371 | if abs in names: continue |
|
2371 | if abs in names: continue | |
2372 | names[abs] = (rel, exact) |
|
2372 | names[abs] = (rel, exact) | |
2373 | target_only[abs] = True |
|
2373 | target_only[abs] = True | |
2374 |
|
2374 | |||
2375 | changes = repo.changes(match=names.has_key, wlock=wlock) |
|
2375 | changes = repo.changes(match=names.has_key, wlock=wlock) | |
2376 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
|
2376 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) | |
2377 |
|
2377 | |||
2378 | revert = ([], _('reverting %s\n')) |
|
2378 | revert = ([], _('reverting %s\n')) | |
2379 | add = ([], _('adding %s\n')) |
|
2379 | add = ([], _('adding %s\n')) | |
2380 | remove = ([], _('removing %s\n')) |
|
2380 | remove = ([], _('removing %s\n')) | |
2381 | forget = ([], _('forgetting %s\n')) |
|
2381 | forget = ([], _('forgetting %s\n')) | |
2382 | undelete = ([], _('undeleting %s\n')) |
|
2382 | undelete = ([], _('undeleting %s\n')) | |
2383 | update = {} |
|
2383 | update = {} | |
2384 |
|
2384 | |||
2385 | disptable = ( |
|
2385 | disptable = ( | |
2386 | # dispatch table: |
|
2386 | # dispatch table: | |
2387 | # file state |
|
2387 | # file state | |
2388 | # action if in target manifest |
|
2388 | # action if in target manifest | |
2389 | # action if not in target manifest |
|
2389 | # action if not in target manifest | |
2390 | # make backup if in target manifest |
|
2390 | # make backup if in target manifest | |
2391 | # make backup if not in target manifest |
|
2391 | # make backup if not in target manifest | |
2392 | (modified, revert, remove, True, True), |
|
2392 | (modified, revert, remove, True, True), | |
2393 |
(added, revert, forget, True, |
|
2393 | (added, revert, forget, True, False), | |
2394 | (removed, undelete, None, False, False), |
|
2394 | (removed, undelete, None, False, False), | |
2395 | (deleted, revert, remove, False, False), |
|
2395 | (deleted, revert, remove, False, False), | |
2396 | (unknown, add, None, True, False), |
|
2396 | (unknown, add, None, True, False), | |
2397 | (target_only, add, None, False, False), |
|
2397 | (target_only, add, None, False, False), | |
2398 | ) |
|
2398 | ) | |
2399 |
|
2399 | |||
2400 | entries = names.items() |
|
2400 | entries = names.items() | |
2401 | entries.sort() |
|
2401 | entries.sort() | |
2402 |
|
2402 | |||
2403 | for abs, (rel, exact) in entries: |
|
2403 | for abs, (rel, exact) in entries: | |
2404 | in_mf = abs in mf |
|
2404 | in_mf = abs in mf | |
2405 | def handle(xlist, dobackup): |
|
2405 | def handle(xlist, dobackup): | |
2406 | xlist[0].append(abs) |
|
2406 | xlist[0].append(abs) | |
2407 | if dobackup and not opts['no_backup'] and os.path.exists(rel): |
|
2407 | if dobackup and not opts['no_backup'] and os.path.exists(rel): | |
2408 | bakname = "%s.orig" % rel |
|
2408 | bakname = "%s.orig" % rel | |
2409 | ui.note(_('saving current version of %s as %s\n') % |
|
2409 | ui.note(_('saving current version of %s as %s\n') % | |
2410 | (rel, bakname)) |
|
2410 | (rel, bakname)) | |
2411 | shutil.copyfile(rel, bakname) |
|
2411 | shutil.copyfile(rel, bakname) | |
2412 | shutil.copymode(rel, bakname) |
|
2412 | shutil.copymode(rel, bakname) | |
2413 | if ui.verbose or not exact: |
|
2413 | if ui.verbose or not exact: | |
2414 | ui.status(xlist[1] % rel) |
|
2414 | ui.status(xlist[1] % rel) | |
2415 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
2415 | for table, hitlist, misslist, backuphit, backupmiss in disptable: | |
2416 | if abs not in table: continue |
|
2416 | if abs not in table: continue | |
2417 | # file has changed in dirstate |
|
2417 | # file has changed in dirstate | |
2418 | if in_mf: |
|
2418 | if in_mf: | |
2419 | handle(hitlist, backuphit) |
|
2419 | handle(hitlist, backuphit) | |
2420 | elif misslist is not None: |
|
2420 | elif misslist is not None: | |
2421 | handle(misslist, backupmiss) |
|
2421 | handle(misslist, backupmiss) | |
2422 | else: |
|
2422 | else: | |
2423 | if exact: ui.warn(_('file not managed: %s\n' % rel)) |
|
2423 | if exact: ui.warn(_('file not managed: %s\n' % rel)) | |
2424 | break |
|
2424 | break | |
2425 | else: |
|
2425 | else: | |
2426 | # file has not changed in dirstate |
|
2426 | # file has not changed in dirstate | |
2427 | if node == parent: |
|
2427 | if node == parent: | |
2428 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) |
|
2428 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) | |
2429 | continue |
|
2429 | continue | |
2430 | if not in_mf: |
|
2430 | if not in_mf: | |
2431 | handle(remove, False) |
|
2431 | handle(remove, False) | |
2432 | update[abs] = True |
|
2432 | update[abs] = True | |
2433 |
|
2433 | |||
2434 | repo.dirstate.forget(forget[0]) |
|
2434 | repo.dirstate.forget(forget[0]) | |
2435 | r = repo.update(node, False, True, update.has_key, False, wlock=wlock) |
|
2435 | r = repo.update(node, False, True, update.has_key, False, wlock=wlock) | |
2436 | repo.dirstate.update(add[0], 'a') |
|
2436 | repo.dirstate.update(add[0], 'a') | |
2437 | repo.dirstate.update(undelete[0], 'n') |
|
2437 | repo.dirstate.update(undelete[0], 'n') | |
2438 | repo.dirstate.update(remove[0], 'r') |
|
2438 | repo.dirstate.update(remove[0], 'r') | |
2439 | return r |
|
2439 | return r | |
2440 |
|
2440 | |||
2441 | def root(ui, repo): |
|
2441 | def root(ui, repo): | |
2442 | """print the root (top) of the current working dir |
|
2442 | """print the root (top) of the current working dir | |
2443 |
|
2443 | |||
2444 | Print the root directory of the current repository. |
|
2444 | Print the root directory of the current repository. | |
2445 | """ |
|
2445 | """ | |
2446 | ui.write(repo.root + "\n") |
|
2446 | ui.write(repo.root + "\n") | |
2447 |
|
2447 | |||
2448 | def serve(ui, repo, **opts): |
|
2448 | def serve(ui, repo, **opts): | |
2449 | """export the repository via HTTP |
|
2449 | """export the repository via HTTP | |
2450 |
|
2450 | |||
2451 | Start a local HTTP repository browser and pull server. |
|
2451 | Start a local HTTP repository browser and pull server. | |
2452 |
|
2452 | |||
2453 | By default, the server logs accesses to stdout and errors to |
|
2453 | By default, the server logs accesses to stdout and errors to | |
2454 | stderr. Use the "-A" and "-E" options to log to files. |
|
2454 | stderr. Use the "-A" and "-E" options to log to files. | |
2455 | """ |
|
2455 | """ | |
2456 |
|
2456 | |||
2457 | if opts["stdio"]: |
|
2457 | if opts["stdio"]: | |
2458 | fin, fout = sys.stdin, sys.stdout |
|
2458 | fin, fout = sys.stdin, sys.stdout | |
2459 | sys.stdout = sys.stderr |
|
2459 | sys.stdout = sys.stderr | |
2460 |
|
2460 | |||
2461 | # Prevent insertion/deletion of CRs |
|
2461 | # Prevent insertion/deletion of CRs | |
2462 | util.set_binary(fin) |
|
2462 | util.set_binary(fin) | |
2463 | util.set_binary(fout) |
|
2463 | util.set_binary(fout) | |
2464 |
|
2464 | |||
2465 | def getarg(): |
|
2465 | def getarg(): | |
2466 | argline = fin.readline()[:-1] |
|
2466 | argline = fin.readline()[:-1] | |
2467 | arg, l = argline.split() |
|
2467 | arg, l = argline.split() | |
2468 | val = fin.read(int(l)) |
|
2468 | val = fin.read(int(l)) | |
2469 | return arg, val |
|
2469 | return arg, val | |
2470 | def respond(v): |
|
2470 | def respond(v): | |
2471 | fout.write("%d\n" % len(v)) |
|
2471 | fout.write("%d\n" % len(v)) | |
2472 | fout.write(v) |
|
2472 | fout.write(v) | |
2473 | fout.flush() |
|
2473 | fout.flush() | |
2474 |
|
2474 | |||
2475 | lock = None |
|
2475 | lock = None | |
2476 |
|
2476 | |||
2477 | while 1: |
|
2477 | while 1: | |
2478 | cmd = fin.readline()[:-1] |
|
2478 | cmd = fin.readline()[:-1] | |
2479 | if cmd == '': |
|
2479 | if cmd == '': | |
2480 | return |
|
2480 | return | |
2481 | if cmd == "heads": |
|
2481 | if cmd == "heads": | |
2482 | h = repo.heads() |
|
2482 | h = repo.heads() | |
2483 | respond(" ".join(map(hex, h)) + "\n") |
|
2483 | respond(" ".join(map(hex, h)) + "\n") | |
2484 | if cmd == "lock": |
|
2484 | if cmd == "lock": | |
2485 | lock = repo.lock() |
|
2485 | lock = repo.lock() | |
2486 | respond("") |
|
2486 | respond("") | |
2487 | if cmd == "unlock": |
|
2487 | if cmd == "unlock": | |
2488 | if lock: |
|
2488 | if lock: | |
2489 | lock.release() |
|
2489 | lock.release() | |
2490 | lock = None |
|
2490 | lock = None | |
2491 | respond("") |
|
2491 | respond("") | |
2492 | elif cmd == "branches": |
|
2492 | elif cmd == "branches": | |
2493 | arg, nodes = getarg() |
|
2493 | arg, nodes = getarg() | |
2494 | nodes = map(bin, nodes.split(" ")) |
|
2494 | nodes = map(bin, nodes.split(" ")) | |
2495 | r = [] |
|
2495 | r = [] | |
2496 | for b in repo.branches(nodes): |
|
2496 | for b in repo.branches(nodes): | |
2497 | r.append(" ".join(map(hex, b)) + "\n") |
|
2497 | r.append(" ".join(map(hex, b)) + "\n") | |
2498 | respond("".join(r)) |
|
2498 | respond("".join(r)) | |
2499 | elif cmd == "between": |
|
2499 | elif cmd == "between": | |
2500 | arg, pairs = getarg() |
|
2500 | arg, pairs = getarg() | |
2501 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] |
|
2501 | pairs = [map(bin, p.split("-")) for p in pairs.split(" ")] | |
2502 | r = [] |
|
2502 | r = [] | |
2503 | for b in repo.between(pairs): |
|
2503 | for b in repo.between(pairs): | |
2504 | r.append(" ".join(map(hex, b)) + "\n") |
|
2504 | r.append(" ".join(map(hex, b)) + "\n") | |
2505 | respond("".join(r)) |
|
2505 | respond("".join(r)) | |
2506 | elif cmd == "changegroup": |
|
2506 | elif cmd == "changegroup": | |
2507 | nodes = [] |
|
2507 | nodes = [] | |
2508 | arg, roots = getarg() |
|
2508 | arg, roots = getarg() | |
2509 | nodes = map(bin, roots.split(" ")) |
|
2509 | nodes = map(bin, roots.split(" ")) | |
2510 |
|
2510 | |||
2511 | cg = repo.changegroup(nodes, 'serve') |
|
2511 | cg = repo.changegroup(nodes, 'serve') | |
2512 | while 1: |
|
2512 | while 1: | |
2513 | d = cg.read(4096) |
|
2513 | d = cg.read(4096) | |
2514 | if not d: |
|
2514 | if not d: | |
2515 | break |
|
2515 | break | |
2516 | fout.write(d) |
|
2516 | fout.write(d) | |
2517 |
|
2517 | |||
2518 | fout.flush() |
|
2518 | fout.flush() | |
2519 |
|
2519 | |||
2520 | elif cmd == "addchangegroup": |
|
2520 | elif cmd == "addchangegroup": | |
2521 | if not lock: |
|
2521 | if not lock: | |
2522 | respond("not locked") |
|
2522 | respond("not locked") | |
2523 | continue |
|
2523 | continue | |
2524 | respond("") |
|
2524 | respond("") | |
2525 |
|
2525 | |||
2526 | r = repo.addchangegroup(fin) |
|
2526 | r = repo.addchangegroup(fin) | |
2527 | respond(str(r)) |
|
2527 | respond(str(r)) | |
2528 |
|
2528 | |||
2529 | optlist = "name templates style address port ipv6 accesslog errorlog" |
|
2529 | optlist = "name templates style address port ipv6 accesslog errorlog" | |
2530 | for o in optlist.split(): |
|
2530 | for o in optlist.split(): | |
2531 | if opts[o]: |
|
2531 | if opts[o]: | |
2532 | ui.setconfig("web", o, opts[o]) |
|
2532 | ui.setconfig("web", o, opts[o]) | |
2533 |
|
2533 | |||
2534 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2534 | if opts['daemon'] and not opts['daemon_pipefds']: | |
2535 | rfd, wfd = os.pipe() |
|
2535 | rfd, wfd = os.pipe() | |
2536 | args = sys.argv[:] |
|
2536 | args = sys.argv[:] | |
2537 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2537 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) | |
2538 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2538 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), | |
2539 | args[0], args) |
|
2539 | args[0], args) | |
2540 | os.close(wfd) |
|
2540 | os.close(wfd) | |
2541 | os.read(rfd, 1) |
|
2541 | os.read(rfd, 1) | |
2542 | os._exit(0) |
|
2542 | os._exit(0) | |
2543 |
|
2543 | |||
2544 | try: |
|
2544 | try: | |
2545 | httpd = hgweb.create_server(repo) |
|
2545 | httpd = hgweb.create_server(repo) | |
2546 | except socket.error, inst: |
|
2546 | except socket.error, inst: | |
2547 | raise util.Abort(_('cannot start server: ') + inst.args[1]) |
|
2547 | raise util.Abort(_('cannot start server: ') + inst.args[1]) | |
2548 |
|
2548 | |||
2549 | if ui.verbose: |
|
2549 | if ui.verbose: | |
2550 | addr, port = httpd.socket.getsockname() |
|
2550 | addr, port = httpd.socket.getsockname() | |
2551 | if addr == '0.0.0.0': |
|
2551 | if addr == '0.0.0.0': | |
2552 | addr = socket.gethostname() |
|
2552 | addr = socket.gethostname() | |
2553 | else: |
|
2553 | else: | |
2554 | try: |
|
2554 | try: | |
2555 | addr = socket.gethostbyaddr(addr)[0] |
|
2555 | addr = socket.gethostbyaddr(addr)[0] | |
2556 | except socket.error: |
|
2556 | except socket.error: | |
2557 | pass |
|
2557 | pass | |
2558 | if port != 80: |
|
2558 | if port != 80: | |
2559 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) |
|
2559 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) | |
2560 | else: |
|
2560 | else: | |
2561 | ui.status(_('listening at http://%s/\n') % addr) |
|
2561 | ui.status(_('listening at http://%s/\n') % addr) | |
2562 |
|
2562 | |||
2563 | if opts['pid_file']: |
|
2563 | if opts['pid_file']: | |
2564 | fp = open(opts['pid_file'], 'w') |
|
2564 | fp = open(opts['pid_file'], 'w') | |
2565 | fp.write(str(os.getpid())) |
|
2565 | fp.write(str(os.getpid())) | |
2566 | fp.close() |
|
2566 | fp.close() | |
2567 |
|
2567 | |||
2568 | if opts['daemon_pipefds']: |
|
2568 | if opts['daemon_pipefds']: | |
2569 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2569 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] | |
2570 | os.close(rfd) |
|
2570 | os.close(rfd) | |
2571 | os.write(wfd, 'y') |
|
2571 | os.write(wfd, 'y') | |
2572 | os.close(wfd) |
|
2572 | os.close(wfd) | |
2573 | sys.stdout.flush() |
|
2573 | sys.stdout.flush() | |
2574 | sys.stderr.flush() |
|
2574 | sys.stderr.flush() | |
2575 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2575 | fd = os.open(util.nulldev, os.O_RDWR) | |
2576 | if fd != 0: os.dup2(fd, 0) |
|
2576 | if fd != 0: os.dup2(fd, 0) | |
2577 | if fd != 1: os.dup2(fd, 1) |
|
2577 | if fd != 1: os.dup2(fd, 1) | |
2578 | if fd != 2: os.dup2(fd, 2) |
|
2578 | if fd != 2: os.dup2(fd, 2) | |
2579 | if fd not in (0, 1, 2): os.close(fd) |
|
2579 | if fd not in (0, 1, 2): os.close(fd) | |
2580 |
|
2580 | |||
2581 | httpd.serve_forever() |
|
2581 | httpd.serve_forever() | |
2582 |
|
2582 | |||
2583 | def status(ui, repo, *pats, **opts): |
|
2583 | def status(ui, repo, *pats, **opts): | |
2584 | """show changed files in the working directory |
|
2584 | """show changed files in the working directory | |
2585 |
|
2585 | |||
2586 | Show changed files in the repository. If names are |
|
2586 | Show changed files in the repository. If names are | |
2587 | given, only files that match are shown. |
|
2587 | given, only files that match are shown. | |
2588 |
|
2588 | |||
2589 | The codes used to show the status of files are: |
|
2589 | The codes used to show the status of files are: | |
2590 | M = modified |
|
2590 | M = modified | |
2591 | A = added |
|
2591 | A = added | |
2592 | R = removed |
|
2592 | R = removed | |
2593 | ! = deleted, but still tracked |
|
2593 | ! = deleted, but still tracked | |
2594 | ? = not tracked |
|
2594 | ? = not tracked | |
2595 | I = ignored (not shown by default) |
|
2595 | I = ignored (not shown by default) | |
2596 | """ |
|
2596 | """ | |
2597 |
|
2597 | |||
2598 | show_ignored = opts['ignored'] and True or False |
|
2598 | show_ignored = opts['ignored'] and True or False | |
2599 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
2599 | files, matchfn, anypats = matchpats(repo, pats, opts) | |
2600 | cwd = (pats and repo.getcwd()) or '' |
|
2600 | cwd = (pats and repo.getcwd()) or '' | |
2601 | modified, added, removed, deleted, unknown, ignored = [ |
|
2601 | modified, added, removed, deleted, unknown, ignored = [ | |
2602 | [util.pathto(cwd, x) for x in n] |
|
2602 | [util.pathto(cwd, x) for x in n] | |
2603 | for n in repo.changes(files=files, match=matchfn, |
|
2603 | for n in repo.changes(files=files, match=matchfn, | |
2604 | show_ignored=show_ignored)] |
|
2604 | show_ignored=show_ignored)] | |
2605 |
|
2605 | |||
2606 | changetypes = [('modified', 'M', modified), |
|
2606 | changetypes = [('modified', 'M', modified), | |
2607 | ('added', 'A', added), |
|
2607 | ('added', 'A', added), | |
2608 | ('removed', 'R', removed), |
|
2608 | ('removed', 'R', removed), | |
2609 | ('deleted', '!', deleted), |
|
2609 | ('deleted', '!', deleted), | |
2610 | ('unknown', '?', unknown), |
|
2610 | ('unknown', '?', unknown), | |
2611 | ('ignored', 'I', ignored)] |
|
2611 | ('ignored', 'I', ignored)] | |
2612 |
|
2612 | |||
2613 | end = opts['print0'] and '\0' or '\n' |
|
2613 | end = opts['print0'] and '\0' or '\n' | |
2614 |
|
2614 | |||
2615 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] |
|
2615 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] | |
2616 | or changetypes): |
|
2616 | or changetypes): | |
2617 | if opts['no_status']: |
|
2617 | if opts['no_status']: | |
2618 | format = "%%s%s" % end |
|
2618 | format = "%%s%s" % end | |
2619 | else: |
|
2619 | else: | |
2620 | format = "%s %%s%s" % (char, end) |
|
2620 | format = "%s %%s%s" % (char, end) | |
2621 |
|
2621 | |||
2622 | for f in changes: |
|
2622 | for f in changes: | |
2623 | ui.write(format % f) |
|
2623 | ui.write(format % f) | |
2624 |
|
2624 | |||
2625 | def tag(ui, repo, name, rev_=None, **opts): |
|
2625 | def tag(ui, repo, name, rev_=None, **opts): | |
2626 | """add a tag for the current tip or a given revision |
|
2626 | """add a tag for the current tip or a given revision | |
2627 |
|
2627 | |||
2628 | Name a particular revision using <name>. |
|
2628 | Name a particular revision using <name>. | |
2629 |
|
2629 | |||
2630 | Tags are used to name particular revisions of the repository and are |
|
2630 | Tags are used to name particular revisions of the repository and are | |
2631 | very useful to compare different revision, to go back to significant |
|
2631 | very useful to compare different revision, to go back to significant | |
2632 | earlier versions or to mark branch points as releases, etc. |
|
2632 | earlier versions or to mark branch points as releases, etc. | |
2633 |
|
2633 | |||
2634 | If no revision is given, the tip is used. |
|
2634 | If no revision is given, the tip is used. | |
2635 |
|
2635 | |||
2636 | To facilitate version control, distribution, and merging of tags, |
|
2636 | To facilitate version control, distribution, and merging of tags, | |
2637 | they are stored as a file named ".hgtags" which is managed |
|
2637 | they are stored as a file named ".hgtags" which is managed | |
2638 | similarly to other project files and can be hand-edited if |
|
2638 | similarly to other project files and can be hand-edited if | |
2639 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2639 | necessary. The file '.hg/localtags' is used for local tags (not | |
2640 | shared among repositories). |
|
2640 | shared among repositories). | |
2641 | """ |
|
2641 | """ | |
2642 | if name == "tip": |
|
2642 | if name == "tip": | |
2643 | raise util.Abort(_("the name 'tip' is reserved")) |
|
2643 | raise util.Abort(_("the name 'tip' is reserved")) | |
2644 | if rev_ is not None: |
|
2644 | if rev_ is not None: | |
2645 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2645 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " | |
2646 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2646 | "please use 'hg tag [-r REV] NAME' instead\n")) | |
2647 | if opts['rev']: |
|
2647 | if opts['rev']: | |
2648 | raise util.Abort(_("use only one form to specify the revision")) |
|
2648 | raise util.Abort(_("use only one form to specify the revision")) | |
2649 | if opts['rev']: |
|
2649 | if opts['rev']: | |
2650 | rev_ = opts['rev'] |
|
2650 | rev_ = opts['rev'] | |
2651 | if rev_: |
|
2651 | if rev_: | |
2652 | r = hex(repo.lookup(rev_)) |
|
2652 | r = hex(repo.lookup(rev_)) | |
2653 | else: |
|
2653 | else: | |
2654 | r = hex(repo.changelog.tip()) |
|
2654 | r = hex(repo.changelog.tip()) | |
2655 |
|
2655 | |||
2656 | disallowed = (revrangesep, '\r', '\n') |
|
2656 | disallowed = (revrangesep, '\r', '\n') | |
2657 | for c in disallowed: |
|
2657 | for c in disallowed: | |
2658 | if name.find(c) >= 0: |
|
2658 | if name.find(c) >= 0: | |
2659 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) |
|
2659 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) | |
2660 |
|
2660 | |||
2661 | repo.hook('pretag', throw=True, node=r, tag=name, |
|
2661 | repo.hook('pretag', throw=True, node=r, tag=name, | |
2662 | local=int(not not opts['local'])) |
|
2662 | local=int(not not opts['local'])) | |
2663 |
|
2663 | |||
2664 | if opts['local']: |
|
2664 | if opts['local']: | |
2665 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) |
|
2665 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) | |
2666 | repo.hook('tag', node=r, tag=name, local=1) |
|
2666 | repo.hook('tag', node=r, tag=name, local=1) | |
2667 | return |
|
2667 | return | |
2668 |
|
2668 | |||
2669 | for x in repo.changes(): |
|
2669 | for x in repo.changes(): | |
2670 | if ".hgtags" in x: |
|
2670 | if ".hgtags" in x: | |
2671 | raise util.Abort(_("working copy of .hgtags is changed " |
|
2671 | raise util.Abort(_("working copy of .hgtags is changed " | |
2672 | "(please commit .hgtags manually)")) |
|
2672 | "(please commit .hgtags manually)")) | |
2673 |
|
2673 | |||
2674 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) |
|
2674 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) | |
2675 | if repo.dirstate.state(".hgtags") == '?': |
|
2675 | if repo.dirstate.state(".hgtags") == '?': | |
2676 | repo.add([".hgtags"]) |
|
2676 | repo.add([".hgtags"]) | |
2677 |
|
2677 | |||
2678 | message = (opts['message'] or |
|
2678 | message = (opts['message'] or | |
2679 | _("Added tag %s for changeset %s") % (name, r)) |
|
2679 | _("Added tag %s for changeset %s") % (name, r)) | |
2680 | try: |
|
2680 | try: | |
2681 | repo.commit([".hgtags"], message, opts['user'], opts['date']) |
|
2681 | repo.commit([".hgtags"], message, opts['user'], opts['date']) | |
2682 | repo.hook('tag', node=r, tag=name, local=0) |
|
2682 | repo.hook('tag', node=r, tag=name, local=0) | |
2683 | except ValueError, inst: |
|
2683 | except ValueError, inst: | |
2684 | raise util.Abort(str(inst)) |
|
2684 | raise util.Abort(str(inst)) | |
2685 |
|
2685 | |||
2686 | def tags(ui, repo): |
|
2686 | def tags(ui, repo): | |
2687 | """list repository tags |
|
2687 | """list repository tags | |
2688 |
|
2688 | |||
2689 | List the repository tags. |
|
2689 | List the repository tags. | |
2690 |
|
2690 | |||
2691 | This lists both regular and local tags. |
|
2691 | This lists both regular and local tags. | |
2692 | """ |
|
2692 | """ | |
2693 |
|
2693 | |||
2694 | l = repo.tagslist() |
|
2694 | l = repo.tagslist() | |
2695 | l.reverse() |
|
2695 | l.reverse() | |
2696 | for t, n in l: |
|
2696 | for t, n in l: | |
2697 | try: |
|
2697 | try: | |
2698 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) |
|
2698 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) | |
2699 | except KeyError: |
|
2699 | except KeyError: | |
2700 | r = " ?:?" |
|
2700 | r = " ?:?" | |
2701 | if ui.quiet: |
|
2701 | if ui.quiet: | |
2702 | ui.write("%s\n" % t) |
|
2702 | ui.write("%s\n" % t) | |
2703 | else: |
|
2703 | else: | |
2704 | ui.write("%-30s %s\n" % (t, r)) |
|
2704 | ui.write("%-30s %s\n" % (t, r)) | |
2705 |
|
2705 | |||
2706 | def tip(ui, repo, **opts): |
|
2706 | def tip(ui, repo, **opts): | |
2707 | """show the tip revision |
|
2707 | """show the tip revision | |
2708 |
|
2708 | |||
2709 | Show the tip revision. |
|
2709 | Show the tip revision. | |
2710 | """ |
|
2710 | """ | |
2711 | n = repo.changelog.tip() |
|
2711 | n = repo.changelog.tip() | |
2712 | br = None |
|
2712 | br = None | |
2713 | if opts['branches']: |
|
2713 | if opts['branches']: | |
2714 | br = repo.branchlookup([n]) |
|
2714 | br = repo.branchlookup([n]) | |
2715 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
|
2715 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) | |
2716 | if opts['patch']: |
|
2716 | if opts['patch']: | |
2717 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) |
|
2717 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) | |
2718 |
|
2718 | |||
2719 | def unbundle(ui, repo, fname, **opts): |
|
2719 | def unbundle(ui, repo, fname, **opts): | |
2720 | """apply a changegroup file |
|
2720 | """apply a changegroup file | |
2721 |
|
2721 | |||
2722 | Apply a compressed changegroup file generated by the bundle |
|
2722 | Apply a compressed changegroup file generated by the bundle | |
2723 | command. |
|
2723 | command. | |
2724 | """ |
|
2724 | """ | |
2725 | f = urllib.urlopen(fname) |
|
2725 | f = urllib.urlopen(fname) | |
2726 |
|
2726 | |||
2727 | header = f.read(6) |
|
2727 | header = f.read(6) | |
2728 | if not header.startswith("HG"): |
|
2728 | if not header.startswith("HG"): | |
2729 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) |
|
2729 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) | |
2730 | elif not header.startswith("HG10"): |
|
2730 | elif not header.startswith("HG10"): | |
2731 | raise util.Abort(_("%s: unknown bundle version") % fname) |
|
2731 | raise util.Abort(_("%s: unknown bundle version") % fname) | |
2732 | elif header == "HG10BZ": |
|
2732 | elif header == "HG10BZ": | |
2733 | def generator(f): |
|
2733 | def generator(f): | |
2734 | zd = bz2.BZ2Decompressor() |
|
2734 | zd = bz2.BZ2Decompressor() | |
2735 | zd.decompress("BZ") |
|
2735 | zd.decompress("BZ") | |
2736 | for chunk in f: |
|
2736 | for chunk in f: | |
2737 | yield zd.decompress(chunk) |
|
2737 | yield zd.decompress(chunk) | |
2738 | elif header == "HG10UN": |
|
2738 | elif header == "HG10UN": | |
2739 | def generator(f): |
|
2739 | def generator(f): | |
2740 | for chunk in f: |
|
2740 | for chunk in f: | |
2741 | yield chunk |
|
2741 | yield chunk | |
2742 | else: |
|
2742 | else: | |
2743 | raise util.Abort(_("%s: unknown bundle compression type") |
|
2743 | raise util.Abort(_("%s: unknown bundle compression type") | |
2744 | % fname) |
|
2744 | % fname) | |
2745 | gen = generator(util.filechunkiter(f, 4096)) |
|
2745 | gen = generator(util.filechunkiter(f, 4096)) | |
2746 | modheads = repo.addchangegroup(util.chunkbuffer(gen)) |
|
2746 | modheads = repo.addchangegroup(util.chunkbuffer(gen)) | |
2747 | return postincoming(ui, repo, modheads, opts['update']) |
|
2747 | return postincoming(ui, repo, modheads, opts['update']) | |
2748 |
|
2748 | |||
2749 | def undo(ui, repo): |
|
2749 | def undo(ui, repo): | |
2750 | """undo the last commit or pull |
|
2750 | """undo the last commit or pull | |
2751 |
|
2751 | |||
2752 | Roll back the last pull or commit transaction on the |
|
2752 | Roll back the last pull or commit transaction on the | |
2753 | repository, restoring the project to its earlier state. |
|
2753 | repository, restoring the project to its earlier state. | |
2754 |
|
2754 | |||
2755 | This command should be used with care. There is only one level of |
|
2755 | This command should be used with care. There is only one level of | |
2756 | undo and there is no redo. |
|
2756 | undo and there is no redo. | |
2757 |
|
2757 | |||
2758 | This command is not intended for use on public repositories. Once |
|
2758 | This command is not intended for use on public repositories. Once | |
2759 | a change is visible for pull by other users, undoing it locally is |
|
2759 | a change is visible for pull by other users, undoing it locally is | |
2760 | ineffective. |
|
2760 | ineffective. Furthemore a race is possible with readers of the | |
|
2761 | repository, for example an ongoing pull from the repository will | |||
|
2762 | fail and rollback. | |||
2761 | """ |
|
2763 | """ | |
2762 | repo.undo() |
|
2764 | repo.undo() | |
2763 |
|
2765 | |||
2764 | def update(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2766 | def update(ui, repo, node=None, merge=False, clean=False, force=None, | |
2765 | branch=None, **opts): |
|
2767 | branch=None, **opts): | |
2766 | """update or merge working directory |
|
2768 | """update or merge working directory | |
2767 |
|
2769 | |||
2768 | Update the working directory to the specified revision. |
|
2770 | Update the working directory to the specified revision. | |
2769 |
|
2771 | |||
2770 | If there are no outstanding changes in the working directory and |
|
2772 | If there are no outstanding changes in the working directory and | |
2771 | there is a linear relationship between the current version and the |
|
2773 | there is a linear relationship between the current version and the | |
2772 | requested version, the result is the requested version. |
|
2774 | requested version, the result is the requested version. | |
2773 |
|
2775 | |||
2774 | Otherwise the result is a merge between the contents of the |
|
2776 | Otherwise the result is a merge between the contents of the | |
2775 | current working directory and the requested version. Files that |
|
2777 | current working directory and the requested version. Files that | |
2776 | changed between either parent are marked as changed for the next |
|
2778 | changed between either parent are marked as changed for the next | |
2777 | commit and a commit must be performed before any further updates |
|
2779 | commit and a commit must be performed before any further updates | |
2778 | are allowed. |
|
2780 | are allowed. | |
2779 |
|
2781 | |||
2780 | By default, update will refuse to run if doing so would require |
|
2782 | By default, update will refuse to run if doing so would require | |
2781 | merging or discarding local changes. |
|
2783 | merging or discarding local changes. | |
2782 | """ |
|
2784 | """ | |
2783 | if branch: |
|
2785 | if branch: | |
2784 | br = repo.branchlookup(branch=branch) |
|
2786 | br = repo.branchlookup(branch=branch) | |
2785 | found = [] |
|
2787 | found = [] | |
2786 | for x in br: |
|
2788 | for x in br: | |
2787 | if branch in br[x]: |
|
2789 | if branch in br[x]: | |
2788 | found.append(x) |
|
2790 | found.append(x) | |
2789 | if len(found) > 1: |
|
2791 | if len(found) > 1: | |
2790 | ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2792 | ui.warn(_("Found multiple heads for %s\n") % branch) | |
2791 | for x in found: |
|
2793 | for x in found: | |
2792 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) |
|
2794 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) | |
2793 | return 1 |
|
2795 | return 1 | |
2794 | if len(found) == 1: |
|
2796 | if len(found) == 1: | |
2795 | node = found[0] |
|
2797 | node = found[0] | |
2796 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) |
|
2798 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) | |
2797 | else: |
|
2799 | else: | |
2798 | ui.warn(_("branch %s not found\n") % (branch)) |
|
2800 | ui.warn(_("branch %s not found\n") % (branch)) | |
2799 | return 1 |
|
2801 | return 1 | |
2800 | else: |
|
2802 | else: | |
2801 | node = node and repo.lookup(node) or repo.changelog.tip() |
|
2803 | node = node and repo.lookup(node) or repo.changelog.tip() | |
2802 | return repo.update(node, allow=merge, force=clean, forcemerge=force) |
|
2804 | return repo.update(node, allow=merge, force=clean, forcemerge=force) | |
2803 |
|
2805 | |||
2804 | def verify(ui, repo): |
|
2806 | def verify(ui, repo): | |
2805 | """verify the integrity of the repository |
|
2807 | """verify the integrity of the repository | |
2806 |
|
2808 | |||
2807 | Verify the integrity of the current repository. |
|
2809 | Verify the integrity of the current repository. | |
2808 |
|
2810 | |||
2809 | This will perform an extensive check of the repository's |
|
2811 | This will perform an extensive check of the repository's | |
2810 | integrity, validating the hashes and checksums of each entry in |
|
2812 | integrity, validating the hashes and checksums of each entry in | |
2811 | the changelog, manifest, and tracked files, as well as the |
|
2813 | the changelog, manifest, and tracked files, as well as the | |
2812 | integrity of their crosslinks and indices. |
|
2814 | integrity of their crosslinks and indices. | |
2813 | """ |
|
2815 | """ | |
2814 | return repo.verify() |
|
2816 | return repo.verify() | |
2815 |
|
2817 | |||
2816 | # Command options and aliases are listed here, alphabetically |
|
2818 | # Command options and aliases are listed here, alphabetically | |
2817 |
|
2819 | |||
2818 | table = { |
|
2820 | table = { | |
2819 | "^add": |
|
2821 | "^add": | |
2820 | (add, |
|
2822 | (add, | |
2821 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2823 | [('I', 'include', [], _('include names matching the given patterns')), | |
2822 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2824 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2823 | _('hg add [OPTION]... [FILE]...')), |
|
2825 | _('hg add [OPTION]... [FILE]...')), | |
2824 | "addremove": |
|
2826 | "addremove": | |
2825 | (addremove, |
|
2827 | (addremove, | |
2826 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2828 | [('I', 'include', [], _('include names matching the given patterns')), | |
2827 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2829 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2828 | _('hg addremove [OPTION]... [FILE]...')), |
|
2830 | _('hg addremove [OPTION]... [FILE]...')), | |
2829 | "^annotate": |
|
2831 | "^annotate": | |
2830 | (annotate, |
|
2832 | (annotate, | |
2831 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2833 | [('r', 'rev', '', _('annotate the specified revision')), | |
2832 | ('a', 'text', None, _('treat all files as text')), |
|
2834 | ('a', 'text', None, _('treat all files as text')), | |
2833 | ('u', 'user', None, _('list the author')), |
|
2835 | ('u', 'user', None, _('list the author')), | |
2834 | ('d', 'date', None, _('list the date')), |
|
2836 | ('d', 'date', None, _('list the date')), | |
2835 | ('n', 'number', None, _('list the revision number (default)')), |
|
2837 | ('n', 'number', None, _('list the revision number (default)')), | |
2836 | ('c', 'changeset', None, _('list the changeset')), |
|
2838 | ('c', 'changeset', None, _('list the changeset')), | |
2837 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2839 | ('I', 'include', [], _('include names matching the given patterns')), | |
2838 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2840 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2839 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2841 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), | |
2840 | "bundle": |
|
2842 | "bundle": | |
2841 | (bundle, |
|
2843 | (bundle, | |
2842 | [('f', 'force', None, |
|
2844 | [('f', 'force', None, | |
2843 | _('run even when remote repository is unrelated'))], |
|
2845 | _('run even when remote repository is unrelated'))], | |
2844 | _('hg bundle FILE DEST')), |
|
2846 | _('hg bundle FILE DEST')), | |
2845 | "cat": |
|
2847 | "cat": | |
2846 | (cat, |
|
2848 | (cat, | |
2847 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2849 | [('o', 'output', '', _('print output to file with formatted name')), | |
2848 | ('r', 'rev', '', _('print the given revision')), |
|
2850 | ('r', 'rev', '', _('print the given revision')), | |
2849 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2851 | ('I', 'include', [], _('include names matching the given patterns')), | |
2850 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2852 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2851 | _('hg cat [OPTION]... FILE...')), |
|
2853 | _('hg cat [OPTION]... FILE...')), | |
2852 | "^clone": |
|
2854 | "^clone": | |
2853 | (clone, |
|
2855 | (clone, | |
2854 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2856 | [('U', 'noupdate', None, _('do not update the new working directory')), | |
2855 | ('r', 'rev', [], |
|
2857 | ('r', 'rev', [], | |
2856 | _('a changeset you would like to have after cloning')), |
|
2858 | _('a changeset you would like to have after cloning')), | |
2857 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2859 | ('', 'pull', None, _('use pull protocol to copy metadata')), | |
2858 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2860 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2859 | ('', 'remotecmd', '', |
|
2861 | ('', 'remotecmd', '', | |
2860 | _('specify hg command to run on the remote side'))], |
|
2862 | _('specify hg command to run on the remote side'))], | |
2861 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2863 | _('hg clone [OPTION]... SOURCE [DEST]')), | |
2862 | "^commit|ci": |
|
2864 | "^commit|ci": | |
2863 | (commit, |
|
2865 | (commit, | |
2864 | [('A', 'addremove', None, _('run addremove during commit')), |
|
2866 | [('A', 'addremove', None, _('run addremove during commit')), | |
2865 | ('m', 'message', '', _('use <text> as commit message')), |
|
2867 | ('m', 'message', '', _('use <text> as commit message')), | |
2866 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
2868 | ('l', 'logfile', '', _('read the commit message from <file>')), | |
2867 | ('d', 'date', '', _('record datecode as commit date')), |
|
2869 | ('d', 'date', '', _('record datecode as commit date')), | |
2868 | ('u', 'user', '', _('record user as commiter')), |
|
2870 | ('u', 'user', '', _('record user as commiter')), | |
2869 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2871 | ('I', 'include', [], _('include names matching the given patterns')), | |
2870 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2872 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2871 | _('hg commit [OPTION]... [FILE]...')), |
|
2873 | _('hg commit [OPTION]... [FILE]...')), | |
2872 | "copy|cp": |
|
2874 | "copy|cp": | |
2873 | (copy, |
|
2875 | (copy, | |
2874 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2876 | [('A', 'after', None, _('record a copy that has already occurred')), | |
2875 | ('f', 'force', None, |
|
2877 | ('f', 'force', None, | |
2876 | _('forcibly copy over an existing managed file')), |
|
2878 | _('forcibly copy over an existing managed file')), | |
2877 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2879 | ('I', 'include', [], _('include names matching the given patterns')), | |
2878 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2880 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2879 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2881 | _('hg copy [OPTION]... [SOURCE]... DEST')), | |
2880 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2882 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), | |
2881 | "debugcomplete": |
|
2883 | "debugcomplete": | |
2882 | (debugcomplete, |
|
2884 | (debugcomplete, | |
2883 | [('o', 'options', None, _('show the command options'))], |
|
2885 | [('o', 'options', None, _('show the command options'))], | |
2884 | _('debugcomplete [-o] CMD')), |
|
2886 | _('debugcomplete [-o] CMD')), | |
2885 | "debugrebuildstate": |
|
2887 | "debugrebuildstate": | |
2886 | (debugrebuildstate, |
|
2888 | (debugrebuildstate, | |
2887 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2889 | [('r', 'rev', '', _('revision to rebuild to'))], | |
2888 | _('debugrebuildstate [-r REV] [REV]')), |
|
2890 | _('debugrebuildstate [-r REV] [REV]')), | |
2889 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2891 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), | |
2890 | "debugconfig": (debugconfig, [], _('debugconfig')), |
|
2892 | "debugconfig": (debugconfig, [], _('debugconfig')), | |
2891 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2893 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), | |
2892 | "debugstate": (debugstate, [], _('debugstate')), |
|
2894 | "debugstate": (debugstate, [], _('debugstate')), | |
2893 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2895 | "debugdata": (debugdata, [], _('debugdata FILE REV')), | |
2894 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2896 | "debugindex": (debugindex, [], _('debugindex FILE')), | |
2895 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2897 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), | |
2896 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2898 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), | |
2897 | "debugwalk": |
|
2899 | "debugwalk": | |
2898 | (debugwalk, |
|
2900 | (debugwalk, | |
2899 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2901 | [('I', 'include', [], _('include names matching the given patterns')), | |
2900 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2902 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2901 | _('debugwalk [OPTION]... [FILE]...')), |
|
2903 | _('debugwalk [OPTION]... [FILE]...')), | |
2902 | "^diff": |
|
2904 | "^diff": | |
2903 | (diff, |
|
2905 | (diff, | |
2904 | [('r', 'rev', [], _('revision')), |
|
2906 | [('r', 'rev', [], _('revision')), | |
2905 | ('a', 'text', None, _('treat all files as text')), |
|
2907 | ('a', 'text', None, _('treat all files as text')), | |
2906 | ('p', 'show-function', None, |
|
2908 | ('p', 'show-function', None, | |
2907 | _('show which function each change is in')), |
|
2909 | _('show which function each change is in')), | |
2908 | ('w', 'ignore-all-space', None, |
|
2910 | ('w', 'ignore-all-space', None, | |
2909 | _('ignore white space when comparing lines')), |
|
2911 | _('ignore white space when comparing lines')), | |
2910 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2912 | ('I', 'include', [], _('include names matching the given patterns')), | |
2911 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2913 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2912 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), |
|
2914 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), | |
2913 | "^export": |
|
2915 | "^export": | |
2914 | (export, |
|
2916 | (export, | |
2915 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2917 | [('o', 'output', '', _('print output to file with formatted name')), | |
2916 | ('a', 'text', None, _('treat all files as text')), |
|
2918 | ('a', 'text', None, _('treat all files as text')), | |
2917 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2919 | ('', 'switch-parent', None, _('diff against the second parent'))], | |
2918 | _('hg export [-a] [-o OUTFILESPEC] REV...')), |
|
2920 | _('hg export [-a] [-o OUTFILESPEC] REV...')), | |
2919 | "forget": |
|
2921 | "forget": | |
2920 | (forget, |
|
2922 | (forget, | |
2921 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2923 | [('I', 'include', [], _('include names matching the given patterns')), | |
2922 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2924 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2923 | _('hg forget [OPTION]... FILE...')), |
|
2925 | _('hg forget [OPTION]... FILE...')), | |
2924 | "grep": |
|
2926 | "grep": | |
2925 | (grep, |
|
2927 | (grep, | |
2926 | [('0', 'print0', None, _('end fields with NUL')), |
|
2928 | [('0', 'print0', None, _('end fields with NUL')), | |
2927 | ('', 'all', None, _('print all revisions that match')), |
|
2929 | ('', 'all', None, _('print all revisions that match')), | |
2928 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2930 | ('i', 'ignore-case', None, _('ignore case when matching')), | |
2929 | ('l', 'files-with-matches', None, |
|
2931 | ('l', 'files-with-matches', None, | |
2930 | _('print only filenames and revs that match')), |
|
2932 | _('print only filenames and revs that match')), | |
2931 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2933 | ('n', 'line-number', None, _('print matching line numbers')), | |
2932 | ('r', 'rev', [], _('search in given revision range')), |
|
2934 | ('r', 'rev', [], _('search in given revision range')), | |
2933 | ('u', 'user', None, _('print user who committed change')), |
|
2935 | ('u', 'user', None, _('print user who committed change')), | |
2934 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2936 | ('I', 'include', [], _('include names matching the given patterns')), | |
2935 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2937 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2936 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2938 | _('hg grep [OPTION]... PATTERN [FILE]...')), | |
2937 | "heads": |
|
2939 | "heads": | |
2938 | (heads, |
|
2940 | (heads, | |
2939 | [('b', 'branches', None, _('show branches')), |
|
2941 | [('b', 'branches', None, _('show branches')), | |
2940 | ('', 'style', '', _('display using template map file')), |
|
2942 | ('', 'style', '', _('display using template map file')), | |
2941 | ('r', 'rev', '', _('show only heads which are descendants of rev')), |
|
2943 | ('r', 'rev', '', _('show only heads which are descendants of rev')), | |
2942 | ('', 'template', '', _('display with template'))], |
|
2944 | ('', 'template', '', _('display with template'))], | |
2943 | _('hg heads [-b] [-r <rev>]')), |
|
2945 | _('hg heads [-b] [-r <rev>]')), | |
2944 | "help": (help_, [], _('hg help [COMMAND]')), |
|
2946 | "help": (help_, [], _('hg help [COMMAND]')), | |
2945 | "identify|id": (identify, [], _('hg identify')), |
|
2947 | "identify|id": (identify, [], _('hg identify')), | |
2946 | "import|patch": |
|
2948 | "import|patch": | |
2947 | (import_, |
|
2949 | (import_, | |
2948 | [('p', 'strip', 1, |
|
2950 | [('p', 'strip', 1, | |
2949 | _('directory strip option for patch. This has the same\n') + |
|
2951 | _('directory strip option for patch. This has the same\n') + | |
2950 | _('meaning as the corresponding patch option')), |
|
2952 | _('meaning as the corresponding patch option')), | |
2951 | ('b', 'base', '', _('base path')), |
|
2953 | ('b', 'base', '', _('base path')), | |
2952 | ('f', 'force', None, |
|
2954 | ('f', 'force', None, | |
2953 | _('skip check for outstanding uncommitted changes'))], |
|
2955 | _('skip check for outstanding uncommitted changes'))], | |
2954 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), |
|
2956 | _('hg import [-p NUM] [-b BASE] [-f] PATCH...')), | |
2955 | "incoming|in": (incoming, |
|
2957 | "incoming|in": (incoming, | |
2956 | [('M', 'no-merges', None, _('do not show merges')), |
|
2958 | [('M', 'no-merges', None, _('do not show merges')), | |
2957 | ('f', 'force', None, |
|
2959 | ('f', 'force', None, | |
2958 | _('run even when remote repository is unrelated')), |
|
2960 | _('run even when remote repository is unrelated')), | |
2959 | ('', 'style', '', _('display using template map file')), |
|
2961 | ('', 'style', '', _('display using template map file')), | |
2960 | ('n', 'newest-first', None, _('show newest record first')), |
|
2962 | ('n', 'newest-first', None, _('show newest record first')), | |
2961 | ('', 'bundle', '', _('file to store the bundles into')), |
|
2963 | ('', 'bundle', '', _('file to store the bundles into')), | |
2962 | ('p', 'patch', None, _('show patch')), |
|
2964 | ('p', 'patch', None, _('show patch')), | |
2963 | ('', 'template', '', _('display with template')), |
|
2965 | ('', 'template', '', _('display with template')), | |
2964 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2966 | ('e', 'ssh', '', _('specify ssh command to use')), | |
2965 | ('', 'remotecmd', '', |
|
2967 | ('', 'remotecmd', '', | |
2966 | _('specify hg command to run on the remote side'))], |
|
2968 | _('specify hg command to run on the remote side'))], | |
2967 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), |
|
2969 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), | |
2968 | "^init": (init, [], _('hg init [DEST]')), |
|
2970 | "^init": (init, [], _('hg init [DEST]')), | |
2969 | "locate": |
|
2971 | "locate": | |
2970 | (locate, |
|
2972 | (locate, | |
2971 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
2973 | [('r', 'rev', '', _('search the repository as it stood at rev')), | |
2972 | ('0', 'print0', None, |
|
2974 | ('0', 'print0', None, | |
2973 | _('end filenames with NUL, for use with xargs')), |
|
2975 | _('end filenames with NUL, for use with xargs')), | |
2974 | ('f', 'fullpath', None, |
|
2976 | ('f', 'fullpath', None, | |
2975 | _('print complete paths from the filesystem root')), |
|
2977 | _('print complete paths from the filesystem root')), | |
2976 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2978 | ('I', 'include', [], _('include names matching the given patterns')), | |
2977 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2979 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2978 | _('hg locate [OPTION]... [PATTERN]...')), |
|
2980 | _('hg locate [OPTION]... [PATTERN]...')), | |
2979 | "^log|history": |
|
2981 | "^log|history": | |
2980 | (log, |
|
2982 | (log, | |
2981 | [('b', 'branches', None, _('show branches')), |
|
2983 | [('b', 'branches', None, _('show branches')), | |
2982 | ('k', 'keyword', [], _('search for a keyword')), |
|
2984 | ('k', 'keyword', [], _('search for a keyword')), | |
2983 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
2985 | ('l', 'limit', '', _('limit number of changes displayed')), | |
2984 | ('r', 'rev', [], _('show the specified revision or range')), |
|
2986 | ('r', 'rev', [], _('show the specified revision or range')), | |
2985 | ('M', 'no-merges', None, _('do not show merges')), |
|
2987 | ('M', 'no-merges', None, _('do not show merges')), | |
2986 | ('', 'style', '', _('display using template map file')), |
|
2988 | ('', 'style', '', _('display using template map file')), | |
2987 | ('m', 'only-merges', None, _('show only merges')), |
|
2989 | ('m', 'only-merges', None, _('show only merges')), | |
2988 | ('p', 'patch', None, _('show patch')), |
|
2990 | ('p', 'patch', None, _('show patch')), | |
2989 | ('', 'template', '', _('display with template')), |
|
2991 | ('', 'template', '', _('display with template')), | |
2990 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2992 | ('I', 'include', [], _('include names matching the given patterns')), | |
2991 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2993 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
2992 | _('hg log [OPTION]... [FILE]')), |
|
2994 | _('hg log [OPTION]... [FILE]')), | |
2993 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
2995 | "manifest": (manifest, [], _('hg manifest [REV]')), | |
2994 | "merge": |
|
2996 | "merge": | |
2995 | (merge, |
|
2997 | (merge, | |
2996 | [('b', 'branch', '', _('merge with head of a specific branch')), |
|
2998 | [('b', 'branch', '', _('merge with head of a specific branch')), | |
2997 | ('', 'style', '', _('display using template map file')), |
|
2999 | ('f', 'force', None, _('force a merge with outstanding changes'))], | |
2998 | ('f', 'force', None, _('force a merge with outstanding changes')), |
|
3000 | _('hg merge [-b TAG] [-f] [REV]')), | |
2999 | ('', 'template', '', _('display with template'))], |
|
|||
3000 | _('hg merge [-b TAG] [-f] [REV]')), |
|
|||
3001 | "outgoing|out": (outgoing, |
|
3001 | "outgoing|out": (outgoing, | |
3002 | [('M', 'no-merges', None, _('do not show merges')), |
|
3002 | [('M', 'no-merges', None, _('do not show merges')), | |
3003 | ('f', 'force', None, |
|
3003 | ('f', 'force', None, | |
3004 | _('run even when remote repository is unrelated')), |
|
3004 | _('run even when remote repository is unrelated')), | |
3005 | ('p', 'patch', None, _('show patch')), |
|
3005 | ('p', 'patch', None, _('show patch')), | |
3006 | ('', 'style', '', _('display using template map file')), |
|
3006 | ('', 'style', '', _('display using template map file')), | |
3007 | ('n', 'newest-first', None, _('show newest record first')), |
|
3007 | ('n', 'newest-first', None, _('show newest record first')), | |
3008 | ('', 'template', '', _('display with template')), |
|
3008 | ('', 'template', '', _('display with template')), | |
3009 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3009 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3010 | ('', 'remotecmd', '', |
|
3010 | ('', 'remotecmd', '', | |
3011 | _('specify hg command to run on the remote side'))], |
|
3011 | _('specify hg command to run on the remote side'))], | |
3012 | _('hg outgoing [-M] [-p] [-n] [DEST]')), |
|
3012 | _('hg outgoing [-M] [-p] [-n] [DEST]')), | |
3013 | "^parents": |
|
3013 | "^parents": | |
3014 | (parents, |
|
3014 | (parents, | |
3015 | [('b', 'branches', None, _('show branches')), |
|
3015 | [('b', 'branches', None, _('show branches')), | |
3016 | ('', 'style', '', _('display using template map file')), |
|
3016 | ('', 'style', '', _('display using template map file')), | |
3017 | ('', 'template', '', _('display with template'))], |
|
3017 | ('', 'template', '', _('display with template'))], | |
3018 | _('hg parents [-b] [REV]')), |
|
3018 | _('hg parents [-b] [REV]')), | |
3019 | "paths": (paths, [], _('hg paths [NAME]')), |
|
3019 | "paths": (paths, [], _('hg paths [NAME]')), | |
3020 | "^pull": |
|
3020 | "^pull": | |
3021 | (pull, |
|
3021 | (pull, | |
3022 | [('u', 'update', None, |
|
3022 | [('u', 'update', None, | |
3023 | _('update the working directory to tip after pull')), |
|
3023 | _('update the working directory to tip after pull')), | |
3024 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3024 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3025 | ('f', 'force', None, |
|
3025 | ('f', 'force', None, | |
3026 | _('run even when remote repository is unrelated')), |
|
3026 | _('run even when remote repository is unrelated')), | |
3027 | ('r', 'rev', [], _('a specific revision you would like to pull')), |
|
3027 | ('r', 'rev', [], _('a specific revision you would like to pull')), | |
3028 | ('', 'remotecmd', '', |
|
3028 | ('', 'remotecmd', '', | |
3029 | _('specify hg command to run on the remote side'))], |
|
3029 | _('specify hg command to run on the remote side'))], | |
3030 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), |
|
3030 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), | |
3031 | "^push": |
|
3031 | "^push": | |
3032 | (push, |
|
3032 | (push, | |
3033 | [('f', 'force', None, _('force push')), |
|
3033 | [('f', 'force', None, _('force push')), | |
3034 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3034 | ('e', 'ssh', '', _('specify ssh command to use')), | |
3035 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
3035 | ('r', 'rev', [], _('a specific revision you would like to push')), | |
3036 | ('', 'remotecmd', '', |
|
3036 | ('', 'remotecmd', '', | |
3037 | _('specify hg command to run on the remote side'))], |
|
3037 | _('specify hg command to run on the remote side'))], | |
3038 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), |
|
3038 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), | |
3039 | "debugrawcommit|rawcommit": |
|
3039 | "debugrawcommit|rawcommit": | |
3040 | (rawcommit, |
|
3040 | (rawcommit, | |
3041 | [('p', 'parent', [], _('parent')), |
|
3041 | [('p', 'parent', [], _('parent')), | |
3042 | ('d', 'date', '', _('date code')), |
|
3042 | ('d', 'date', '', _('date code')), | |
3043 | ('u', 'user', '', _('user')), |
|
3043 | ('u', 'user', '', _('user')), | |
3044 | ('F', 'files', '', _('file list')), |
|
3044 | ('F', 'files', '', _('file list')), | |
3045 | ('m', 'message', '', _('commit message')), |
|
3045 | ('m', 'message', '', _('commit message')), | |
3046 | ('l', 'logfile', '', _('commit message file'))], |
|
3046 | ('l', 'logfile', '', _('commit message file'))], | |
3047 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
3047 | _('hg debugrawcommit [OPTION]... [FILE]...')), | |
3048 | "recover": (recover, [], _('hg recover')), |
|
3048 | "recover": (recover, [], _('hg recover')), | |
3049 | "^remove|rm": |
|
3049 | "^remove|rm": | |
3050 | (remove, |
|
3050 | (remove, | |
3051 | [('f', 'force', None, _('remove file even if modified')), |
|
3051 | [('f', 'force', None, _('remove file even if modified')), | |
3052 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3052 | ('I', 'include', [], _('include names matching the given patterns')), | |
3053 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3053 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3054 | _('hg remove [OPTION]... FILE...')), |
|
3054 | _('hg remove [OPTION]... FILE...')), | |
3055 | "rename|mv": |
|
3055 | "rename|mv": | |
3056 | (rename, |
|
3056 | (rename, | |
3057 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
3057 | [('A', 'after', None, _('record a rename that has already occurred')), | |
3058 | ('f', 'force', None, |
|
3058 | ('f', 'force', None, | |
3059 | _('forcibly copy over an existing managed file')), |
|
3059 | _('forcibly copy over an existing managed file')), | |
3060 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3060 | ('I', 'include', [], _('include names matching the given patterns')), | |
3061 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3061 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3062 | _('hg rename [OPTION]... SOURCE... DEST')), |
|
3062 | _('hg rename [OPTION]... SOURCE... DEST')), | |
3063 | "^revert": |
|
3063 | "^revert": | |
3064 | (revert, |
|
3064 | (revert, | |
3065 | [('r', 'rev', '', _('revision to revert to')), |
|
3065 | [('r', 'rev', '', _('revision to revert to')), | |
3066 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
3066 | ('', 'no-backup', None, _('do not save backup copies of files')), | |
3067 | ('I', 'include', [], _('include names matching given patterns')), |
|
3067 | ('I', 'include', [], _('include names matching given patterns')), | |
3068 | ('X', 'exclude', [], _('exclude names matching given patterns'))], |
|
3068 | ('X', 'exclude', [], _('exclude names matching given patterns'))], | |
3069 | _('hg revert [-r REV] [NAME]...')), |
|
3069 | _('hg revert [-r REV] [NAME]...')), | |
3070 | "root": (root, [], _('hg root')), |
|
3070 | "root": (root, [], _('hg root')), | |
3071 | "^serve": |
|
3071 | "^serve": | |
3072 | (serve, |
|
3072 | (serve, | |
3073 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
3073 | [('A', 'accesslog', '', _('name of access log file to write to')), | |
3074 | ('d', 'daemon', None, _('run server in background')), |
|
3074 | ('d', 'daemon', None, _('run server in background')), | |
3075 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
3075 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
3076 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
3076 | ('E', 'errorlog', '', _('name of error log file to write to')), | |
3077 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
3077 | ('p', 'port', 0, _('port to use (default: 8000)')), | |
3078 | ('a', 'address', '', _('address to use')), |
|
3078 | ('a', 'address', '', _('address to use')), | |
3079 | ('n', 'name', '', |
|
3079 | ('n', 'name', '', | |
3080 | _('name to show in web pages (default: working dir)')), |
|
3080 | _('name to show in web pages (default: working dir)')), | |
3081 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
3081 | ('', 'pid-file', '', _('name of file to write process ID to')), | |
3082 | ('', 'stdio', None, _('for remote clients')), |
|
3082 | ('', 'stdio', None, _('for remote clients')), | |
3083 | ('t', 'templates', '', _('web templates to use')), |
|
3083 | ('t', 'templates', '', _('web templates to use')), | |
3084 | ('', 'style', '', _('template style to use')), |
|
3084 | ('', 'style', '', _('template style to use')), | |
3085 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
3085 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], | |
3086 | _('hg serve [OPTION]...')), |
|
3086 | _('hg serve [OPTION]...')), | |
3087 | "^status|st": |
|
3087 | "^status|st": | |
3088 | (status, |
|
3088 | (status, | |
3089 | [('m', 'modified', None, _('show only modified files')), |
|
3089 | [('m', 'modified', None, _('show only modified files')), | |
3090 | ('a', 'added', None, _('show only added files')), |
|
3090 | ('a', 'added', None, _('show only added files')), | |
3091 | ('r', 'removed', None, _('show only removed files')), |
|
3091 | ('r', 'removed', None, _('show only removed files')), | |
3092 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
3092 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), | |
3093 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
3093 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), | |
3094 | ('i', 'ignored', None, _('show ignored files')), |
|
3094 | ('i', 'ignored', None, _('show ignored files')), | |
3095 | ('n', 'no-status', None, _('hide status prefix')), |
|
3095 | ('n', 'no-status', None, _('hide status prefix')), | |
3096 | ('0', 'print0', None, |
|
3096 | ('0', 'print0', None, | |
3097 | _('end filenames with NUL, for use with xargs')), |
|
3097 | _('end filenames with NUL, for use with xargs')), | |
3098 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3098 | ('I', 'include', [], _('include names matching the given patterns')), | |
3099 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3099 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], | |
3100 | _('hg status [OPTION]... [FILE]...')), |
|
3100 | _('hg status [OPTION]... [FILE]...')), | |
3101 | "tag": |
|
3101 | "tag": | |
3102 | (tag, |
|
3102 | (tag, | |
3103 | [('l', 'local', None, _('make the tag local')), |
|
3103 | [('l', 'local', None, _('make the tag local')), | |
3104 | ('m', 'message', '', _('message for tag commit log entry')), |
|
3104 | ('m', 'message', '', _('message for tag commit log entry')), | |
3105 | ('d', 'date', '', _('record datecode as commit date')), |
|
3105 | ('d', 'date', '', _('record datecode as commit date')), | |
3106 | ('u', 'user', '', _('record user as commiter')), |
|
3106 | ('u', 'user', '', _('record user as commiter')), | |
3107 | ('r', 'rev', '', _('revision to tag'))], |
|
3107 | ('r', 'rev', '', _('revision to tag'))], | |
3108 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
3108 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), | |
3109 | "tags": (tags, [], _('hg tags')), |
|
3109 | "tags": (tags, [], _('hg tags')), | |
3110 | "tip": |
|
3110 | "tip": | |
3111 | (tip, |
|
3111 | (tip, | |
3112 | [('b', 'branches', None, _('show branches')), |
|
3112 | [('b', 'branches', None, _('show branches')), | |
3113 | ('', 'style', '', _('display using template map file')), |
|
3113 | ('', 'style', '', _('display using template map file')), | |
3114 | ('p', 'patch', None, _('show patch')), |
|
3114 | ('p', 'patch', None, _('show patch')), | |
3115 | ('', 'template', '', _('display with template'))], |
|
3115 | ('', 'template', '', _('display with template'))], | |
3116 | _('hg tip [-b] [-p]')), |
|
3116 | _('hg tip [-b] [-p]')), | |
3117 | "unbundle": |
|
3117 | "unbundle": | |
3118 | (unbundle, |
|
3118 | (unbundle, | |
3119 | [('u', 'update', None, |
|
3119 | [('u', 'update', None, | |
3120 | _('update the working directory to tip after unbundle'))], |
|
3120 | _('update the working directory to tip after unbundle'))], | |
3121 | _('hg unbundle [-u] FILE')), |
|
3121 | _('hg unbundle [-u] FILE')), | |
3122 | "undo": (undo, [], _('hg undo')), |
|
3122 | "undo": (undo, [], _('hg undo')), | |
3123 | "^update|up|checkout|co": |
|
3123 | "^update|up|checkout|co": | |
3124 | (update, |
|
3124 | (update, | |
3125 | [('b', 'branch', '', _('checkout the head of a specific branch')), |
|
3125 | [('b', 'branch', '', _('checkout the head of a specific branch')), | |
3126 | ('', 'style', '', _('display using template map file')), |
|
|||
3127 | ('m', 'merge', None, _('allow merging of branches')), |
|
3126 | ('m', 'merge', None, _('allow merging of branches')), | |
3128 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
3127 | ('C', 'clean', None, _('overwrite locally modified files')), | |
3129 | ('f', 'force', None, _('force a merge with outstanding changes')), |
|
3128 | ('f', 'force', None, _('force a merge with outstanding changes'))], | |
3130 | ('', 'template', '', _('display with template'))], |
|
|||
3131 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), |
|
3129 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), | |
3132 | "verify": (verify, [], _('hg verify')), |
|
3130 | "verify": (verify, [], _('hg verify')), | |
3133 | "version": (show_version, [], _('hg version')), |
|
3131 | "version": (show_version, [], _('hg version')), | |
3134 | } |
|
3132 | } | |
3135 |
|
3133 | |||
3136 | globalopts = [ |
|
3134 | globalopts = [ | |
3137 | ('R', 'repository', '', |
|
3135 | ('R', 'repository', '', | |
3138 | _('repository root directory or symbolic path name')), |
|
3136 | _('repository root directory or symbolic path name')), | |
3139 | ('', 'cwd', '', _('change working directory')), |
|
3137 | ('', 'cwd', '', _('change working directory')), | |
3140 | ('y', 'noninteractive', None, |
|
3138 | ('y', 'noninteractive', None, | |
3141 | _('do not prompt, assume \'yes\' for any required answers')), |
|
3139 | _('do not prompt, assume \'yes\' for any required answers')), | |
3142 | ('q', 'quiet', None, _('suppress output')), |
|
3140 | ('q', 'quiet', None, _('suppress output')), | |
3143 | ('v', 'verbose', None, _('enable additional output')), |
|
3141 | ('v', 'verbose', None, _('enable additional output')), | |
3144 | ('', 'debug', None, _('enable debugging output')), |
|
3142 | ('', 'debug', None, _('enable debugging output')), | |
3145 | ('', 'debugger', None, _('start debugger')), |
|
3143 | ('', 'debugger', None, _('start debugger')), | |
3146 | ('', 'traceback', None, _('print traceback on exception')), |
|
3144 | ('', 'traceback', None, _('print traceback on exception')), | |
3147 | ('', 'time', None, _('time how long the command takes')), |
|
3145 | ('', 'time', None, _('time how long the command takes')), | |
3148 | ('', 'profile', None, _('print command execution profile')), |
|
3146 | ('', 'profile', None, _('print command execution profile')), | |
3149 | ('', 'version', None, _('output version information and exit')), |
|
3147 | ('', 'version', None, _('output version information and exit')), | |
3150 | ('h', 'help', None, _('display help and exit')), |
|
3148 | ('h', 'help', None, _('display help and exit')), | |
3151 | ] |
|
3149 | ] | |
3152 |
|
3150 | |||
3153 | norepo = ("clone init version help debugancestor debugcomplete debugdata" |
|
3151 | norepo = ("clone init version help debugancestor debugcomplete debugdata" | |
3154 | " debugindex debugindexdot") |
|
3152 | " debugindex debugindexdot") | |
3155 | optionalrepo = ("paths debugconfig") |
|
3153 | optionalrepo = ("paths debugconfig") | |
3156 |
|
3154 | |||
3157 | def findpossible(cmd): |
|
3155 | def findpossible(cmd): | |
3158 | """ |
|
3156 | """ | |
3159 | Return cmd -> (aliases, command table entry) |
|
3157 | Return cmd -> (aliases, command table entry) | |
3160 | for each matching command |
|
3158 | for each matching command. | |
|
3159 | Return debug commands (or their aliases) only if no normal command matches. | |||
3161 | """ |
|
3160 | """ | |
3162 | choice = {} |
|
3161 | choice = {} | |
3163 | debugchoice = {} |
|
3162 | debugchoice = {} | |
3164 | for e in table.keys(): |
|
3163 | for e in table.keys(): | |
3165 | aliases = e.lstrip("^").split("|") |
|
3164 | aliases = e.lstrip("^").split("|") | |
|
3165 | found = None | |||
3166 | if cmd in aliases: |
|
3166 | if cmd in aliases: | |
3167 | choice[cmd] = (aliases, table[e]) |
|
3167 | found = cmd | |
3168 | continue |
|
3168 | else: | |
3169 | for a in aliases: |
|
3169 | for a in aliases: | |
3170 | if a.startswith(cmd): |
|
3170 | if a.startswith(cmd): | |
3171 | if aliases[0].startswith("debug"): |
|
3171 | found = a | |
3172 | debugchoice[a] = (aliases, table[e]) |
|
3172 | break | |
3173 | else: |
|
3173 | if found is not None: | |
3174 | choice[a] = (aliases, table[e]) |
|
3174 | if aliases[0].startswith("debug"): | |
3175 | break |
|
3175 | debugchoice[found] = (aliases, table[e]) | |
|
3176 | else: | |||
|
3177 | choice[found] = (aliases, table[e]) | |||
3176 |
|
3178 | |||
3177 | if not choice and debugchoice: |
|
3179 | if not choice and debugchoice: | |
3178 | choice = debugchoice |
|
3180 | choice = debugchoice | |
3179 |
|
3181 | |||
3180 | return choice |
|
3182 | return choice | |
3181 |
|
3183 | |||
3182 | def find(cmd): |
|
3184 | def find(cmd): | |
3183 | """Return (aliases, command table entry) for command string.""" |
|
3185 | """Return (aliases, command table entry) for command string.""" | |
3184 | choice = findpossible(cmd) |
|
3186 | choice = findpossible(cmd) | |
3185 |
|
3187 | |||
3186 | if choice.has_key(cmd): |
|
3188 | if choice.has_key(cmd): | |
3187 | return choice[cmd] |
|
3189 | return choice[cmd] | |
3188 |
|
3190 | |||
3189 | if len(choice) > 1: |
|
3191 | if len(choice) > 1: | |
3190 | clist = choice.keys() |
|
3192 | clist = choice.keys() | |
3191 | clist.sort() |
|
3193 | clist.sort() | |
3192 | raise AmbiguousCommand(cmd, clist) |
|
3194 | raise AmbiguousCommand(cmd, clist) | |
3193 |
|
3195 | |||
3194 | if choice: |
|
3196 | if choice: | |
3195 | return choice.values()[0] |
|
3197 | return choice.values()[0] | |
3196 |
|
3198 | |||
3197 | raise UnknownCommand(cmd) |
|
3199 | raise UnknownCommand(cmd) | |
3198 |
|
3200 | |||
3199 | class SignalInterrupt(Exception): |
|
3201 | class SignalInterrupt(Exception): | |
3200 | """Exception raised on SIGTERM and SIGHUP.""" |
|
3202 | """Exception raised on SIGTERM and SIGHUP.""" | |
3201 |
|
3203 | |||
3202 | def catchterm(*args): |
|
3204 | def catchterm(*args): | |
3203 | raise SignalInterrupt |
|
3205 | raise SignalInterrupt | |
3204 |
|
3206 | |||
3205 | def run(): |
|
3207 | def run(): | |
3206 | sys.exit(dispatch(sys.argv[1:])) |
|
3208 | sys.exit(dispatch(sys.argv[1:])) | |
3207 |
|
3209 | |||
3208 | class ParseError(Exception): |
|
3210 | class ParseError(Exception): | |
3209 | """Exception raised on errors in parsing the command line.""" |
|
3211 | """Exception raised on errors in parsing the command line.""" | |
3210 |
|
3212 | |||
3211 | def parse(ui, args): |
|
3213 | def parse(ui, args): | |
3212 | options = {} |
|
3214 | options = {} | |
3213 | cmdoptions = {} |
|
3215 | cmdoptions = {} | |
3214 |
|
3216 | |||
3215 | try: |
|
3217 | try: | |
3216 | args = fancyopts.fancyopts(args, globalopts, options) |
|
3218 | args = fancyopts.fancyopts(args, globalopts, options) | |
3217 | except fancyopts.getopt.GetoptError, inst: |
|
3219 | except fancyopts.getopt.GetoptError, inst: | |
3218 | raise ParseError(None, inst) |
|
3220 | raise ParseError(None, inst) | |
3219 |
|
3221 | |||
3220 | if args: |
|
3222 | if args: | |
3221 | cmd, args = args[0], args[1:] |
|
3223 | cmd, args = args[0], args[1:] | |
3222 | aliases, i = find(cmd) |
|
3224 | aliases, i = find(cmd) | |
3223 | cmd = aliases[0] |
|
3225 | cmd = aliases[0] | |
3224 | defaults = ui.config("defaults", cmd) |
|
3226 | defaults = ui.config("defaults", cmd) | |
3225 | if defaults: |
|
3227 | if defaults: | |
3226 | args = defaults.split() + args |
|
3228 | args = defaults.split() + args | |
3227 | c = list(i[1]) |
|
3229 | c = list(i[1]) | |
3228 | else: |
|
3230 | else: | |
3229 | cmd = None |
|
3231 | cmd = None | |
3230 | c = [] |
|
3232 | c = [] | |
3231 |
|
3233 | |||
3232 | # combine global options into local |
|
3234 | # combine global options into local | |
3233 | for o in globalopts: |
|
3235 | for o in globalopts: | |
3234 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
3236 | c.append((o[0], o[1], options[o[1]], o[3])) | |
3235 |
|
3237 | |||
3236 | try: |
|
3238 | try: | |
3237 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
3239 | args = fancyopts.fancyopts(args, c, cmdoptions) | |
3238 | except fancyopts.getopt.GetoptError, inst: |
|
3240 | except fancyopts.getopt.GetoptError, inst: | |
3239 | raise ParseError(cmd, inst) |
|
3241 | raise ParseError(cmd, inst) | |
3240 |
|
3242 | |||
3241 | # separate global options back out |
|
3243 | # separate global options back out | |
3242 | for o in globalopts: |
|
3244 | for o in globalopts: | |
3243 | n = o[1] |
|
3245 | n = o[1] | |
3244 | options[n] = cmdoptions[n] |
|
3246 | options[n] = cmdoptions[n] | |
3245 | del cmdoptions[n] |
|
3247 | del cmdoptions[n] | |
3246 |
|
3248 | |||
3247 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
3249 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) | |
3248 |
|
3250 | |||
3249 | def dispatch(args): |
|
3251 | def dispatch(args): | |
3250 | signal.signal(signal.SIGTERM, catchterm) |
|
3252 | signal.signal(signal.SIGTERM, catchterm) | |
3251 | try: |
|
3253 | try: | |
3252 | signal.signal(signal.SIGHUP, catchterm) |
|
3254 | signal.signal(signal.SIGHUP, catchterm) | |
3253 | except AttributeError: |
|
3255 | except AttributeError: | |
3254 | pass |
|
3256 | pass | |
3255 |
|
3257 | |||
3256 | try: |
|
3258 | try: | |
3257 | u = ui.ui() |
|
3259 | u = ui.ui() | |
3258 | except util.Abort, inst: |
|
3260 | except util.Abort, inst: | |
3259 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3261 | sys.stderr.write(_("abort: %s\n") % inst) | |
3260 | sys.exit(1) |
|
3262 | sys.exit(1) | |
3261 |
|
3263 | |||
3262 | external = [] |
|
3264 | external = [] | |
3263 | for x in u.extensions(): |
|
3265 | for x in u.extensions(): | |
3264 | def on_exception(exc, inst): |
|
3266 | def on_exception(exc, inst): | |
3265 | u.warn(_("*** failed to import extension %s\n") % x[1]) |
|
3267 | u.warn(_("*** failed to import extension %s\n") % x[1]) | |
3266 | u.warn("%s\n" % inst) |
|
3268 | u.warn("%s\n" % inst) | |
3267 | if "--traceback" in sys.argv[1:]: |
|
3269 | if "--traceback" in sys.argv[1:]: | |
3268 | traceback.print_exc() |
|
3270 | traceback.print_exc() | |
3269 | if x[1]: |
|
3271 | if x[1]: | |
3270 | try: |
|
3272 | try: | |
3271 | mod = imp.load_source(x[0], x[1]) |
|
3273 | mod = imp.load_source(x[0], x[1]) | |
3272 | except Exception, inst: |
|
3274 | except Exception, inst: | |
3273 | on_exception(Exception, inst) |
|
3275 | on_exception(Exception, inst) | |
3274 | continue |
|
3276 | continue | |
3275 | else: |
|
3277 | else: | |
3276 | def importh(name): |
|
3278 | def importh(name): | |
3277 | mod = __import__(name) |
|
3279 | mod = __import__(name) | |
3278 | components = name.split('.') |
|
3280 | components = name.split('.') | |
3279 | for comp in components[1:]: |
|
3281 | for comp in components[1:]: | |
3280 | mod = getattr(mod, comp) |
|
3282 | mod = getattr(mod, comp) | |
3281 | return mod |
|
3283 | return mod | |
3282 | try: |
|
3284 | try: | |
3283 | try: |
|
3285 | try: | |
3284 | mod = importh("hgext." + x[0]) |
|
3286 | mod = importh("hgext." + x[0]) | |
3285 | except ImportError: |
|
3287 | except ImportError: | |
3286 | mod = importh(x[0]) |
|
3288 | mod = importh(x[0]) | |
3287 | except Exception, inst: |
|
3289 | except Exception, inst: | |
3288 | on_exception(Exception, inst) |
|
3290 | on_exception(Exception, inst) | |
3289 | continue |
|
3291 | continue | |
3290 |
|
3292 | |||
3291 | external.append(mod) |
|
3293 | external.append(mod) | |
3292 | for x in external: |
|
3294 | for x in external: | |
3293 | cmdtable = getattr(x, 'cmdtable', {}) |
|
3295 | cmdtable = getattr(x, 'cmdtable', {}) | |
3294 | for t in cmdtable: |
|
3296 | for t in cmdtable: | |
3295 | if t in table: |
|
3297 | if t in table: | |
3296 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) |
|
3298 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) | |
3297 | table.update(cmdtable) |
|
3299 | table.update(cmdtable) | |
3298 |
|
3300 | |||
3299 | try: |
|
3301 | try: | |
3300 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3302 | cmd, func, args, options, cmdoptions = parse(u, args) | |
3301 | if options["time"]: |
|
3303 | if options["time"]: | |
3302 | def get_times(): |
|
3304 | def get_times(): | |
3303 | t = os.times() |
|
3305 | t = os.times() | |
3304 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
3306 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() | |
3305 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
3307 | t = (t[0], t[1], t[2], t[3], time.clock()) | |
3306 | return t |
|
3308 | return t | |
3307 | s = get_times() |
|
3309 | s = get_times() | |
3308 | def print_time(): |
|
3310 | def print_time(): | |
3309 | t = get_times() |
|
3311 | t = get_times() | |
3310 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
3312 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % | |
3311 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
3313 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) | |
3312 | atexit.register(print_time) |
|
3314 | atexit.register(print_time) | |
3313 |
|
3315 | |||
3314 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3316 | u.updateopts(options["verbose"], options["debug"], options["quiet"], | |
3315 | not options["noninteractive"]) |
|
3317 | not options["noninteractive"]) | |
3316 |
|
3318 | |||
3317 | # enter the debugger before command execution |
|
3319 | # enter the debugger before command execution | |
3318 | if options['debugger']: |
|
3320 | if options['debugger']: | |
3319 | pdb.set_trace() |
|
3321 | pdb.set_trace() | |
3320 |
|
3322 | |||
3321 | try: |
|
3323 | try: | |
3322 | if options['cwd']: |
|
3324 | if options['cwd']: | |
3323 | try: |
|
3325 | try: | |
3324 | os.chdir(options['cwd']) |
|
3326 | os.chdir(options['cwd']) | |
3325 | except OSError, inst: |
|
3327 | except OSError, inst: | |
3326 | raise util.Abort('%s: %s' % |
|
3328 | raise util.Abort('%s: %s' % | |
3327 | (options['cwd'], inst.strerror)) |
|
3329 | (options['cwd'], inst.strerror)) | |
3328 |
|
3330 | |||
3329 | path = u.expandpath(options["repository"]) or "" |
|
3331 | path = u.expandpath(options["repository"]) or "" | |
3330 | repo = path and hg.repository(u, path=path) or None |
|
3332 | repo = path and hg.repository(u, path=path) or None | |
3331 |
|
3333 | |||
3332 | if options['help']: |
|
3334 | if options['help']: | |
3333 | help_(u, cmd, options['version']) |
|
3335 | help_(u, cmd, options['version']) | |
3334 | sys.exit(0) |
|
3336 | sys.exit(0) | |
3335 | elif options['version']: |
|
3337 | elif options['version']: | |
3336 | show_version(u) |
|
3338 | show_version(u) | |
3337 | sys.exit(0) |
|
3339 | sys.exit(0) | |
3338 | elif not cmd: |
|
3340 | elif not cmd: | |
3339 | help_(u, 'shortlist') |
|
3341 | help_(u, 'shortlist') | |
3340 | sys.exit(0) |
|
3342 | sys.exit(0) | |
3341 |
|
3343 | |||
3342 | if cmd not in norepo.split(): |
|
3344 | if cmd not in norepo.split(): | |
3343 | try: |
|
3345 | try: | |
3344 | if not repo: |
|
3346 | if not repo: | |
3345 | repo = hg.repository(u, path=path) |
|
3347 | repo = hg.repository(u, path=path) | |
3346 | u = repo.ui |
|
3348 | u = repo.ui | |
3347 | for x in external: |
|
3349 | for x in external: | |
3348 | if hasattr(x, 'reposetup'): |
|
3350 | if hasattr(x, 'reposetup'): | |
3349 | x.reposetup(u, repo) |
|
3351 | x.reposetup(u, repo) | |
3350 | except hg.RepoError: |
|
3352 | except hg.RepoError: | |
3351 | if cmd not in optionalrepo.split(): |
|
3353 | if cmd not in optionalrepo.split(): | |
3352 | raise |
|
3354 | raise | |
3353 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
3355 | d = lambda: func(u, repo, *args, **cmdoptions) | |
3354 | else: |
|
3356 | else: | |
3355 | d = lambda: func(u, *args, **cmdoptions) |
|
3357 | d = lambda: func(u, *args, **cmdoptions) | |
3356 |
|
3358 | |||
3357 | try: |
|
3359 | try: | |
3358 | if options['profile']: |
|
3360 | if options['profile']: | |
3359 | import hotshot, hotshot.stats |
|
3361 | import hotshot, hotshot.stats | |
3360 | prof = hotshot.Profile("hg.prof") |
|
3362 | prof = hotshot.Profile("hg.prof") | |
3361 | try: |
|
3363 | try: | |
3362 | try: |
|
3364 | try: | |
3363 | return prof.runcall(d) |
|
3365 | return prof.runcall(d) | |
3364 | except: |
|
3366 | except: | |
3365 | try: |
|
3367 | try: | |
3366 | u.warn(_('exception raised - generating ' |
|
3368 | u.warn(_('exception raised - generating ' | |
3367 | 'profile anyway\n')) |
|
3369 | 'profile anyway\n')) | |
3368 | except: |
|
3370 | except: | |
3369 | pass |
|
3371 | pass | |
3370 | raise |
|
3372 | raise | |
3371 | finally: |
|
3373 | finally: | |
3372 | prof.close() |
|
3374 | prof.close() | |
3373 | stats = hotshot.stats.load("hg.prof") |
|
3375 | stats = hotshot.stats.load("hg.prof") | |
3374 | stats.strip_dirs() |
|
3376 | stats.strip_dirs() | |
3375 | stats.sort_stats('time', 'calls') |
|
3377 | stats.sort_stats('time', 'calls') | |
3376 | stats.print_stats(40) |
|
3378 | stats.print_stats(40) | |
3377 | else: |
|
3379 | else: | |
3378 | return d() |
|
3380 | return d() | |
3379 | finally: |
|
3381 | finally: | |
3380 | u.flush() |
|
3382 | u.flush() | |
3381 | except: |
|
3383 | except: | |
3382 | # enter the debugger when we hit an exception |
|
3384 | # enter the debugger when we hit an exception | |
3383 | if options['debugger']: |
|
3385 | if options['debugger']: | |
3384 | pdb.post_mortem(sys.exc_info()[2]) |
|
3386 | pdb.post_mortem(sys.exc_info()[2]) | |
3385 | if options['traceback']: |
|
3387 | if options['traceback']: | |
3386 | traceback.print_exc() |
|
3388 | traceback.print_exc() | |
3387 | raise |
|
3389 | raise | |
3388 | except ParseError, inst: |
|
3390 | except ParseError, inst: | |
3389 | if inst.args[0]: |
|
3391 | if inst.args[0]: | |
3390 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
3392 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) | |
3391 | help_(u, inst.args[0]) |
|
3393 | help_(u, inst.args[0]) | |
3392 | else: |
|
3394 | else: | |
3393 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
3395 | u.warn(_("hg: %s\n") % inst.args[1]) | |
3394 | help_(u, 'shortlist') |
|
3396 | help_(u, 'shortlist') | |
3395 | sys.exit(-1) |
|
3397 | sys.exit(-1) | |
3396 | except AmbiguousCommand, inst: |
|
3398 | except AmbiguousCommand, inst: | |
3397 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
3399 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | |
3398 | (inst.args[0], " ".join(inst.args[1]))) |
|
3400 | (inst.args[0], " ".join(inst.args[1]))) | |
3399 | sys.exit(1) |
|
3401 | sys.exit(1) | |
3400 | except UnknownCommand, inst: |
|
3402 | except UnknownCommand, inst: | |
3401 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
3403 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) | |
3402 | help_(u, 'shortlist') |
|
3404 | help_(u, 'shortlist') | |
3403 | sys.exit(1) |
|
3405 | sys.exit(1) | |
3404 | except hg.RepoError, inst: |
|
3406 | except hg.RepoError, inst: | |
3405 | u.warn(_("abort: "), inst, "!\n") |
|
3407 | u.warn(_("abort: "), inst, "!\n") | |
3406 | except lock.LockHeld, inst: |
|
3408 | except lock.LockHeld, inst: | |
3407 | if inst.errno == errno.ETIMEDOUT: |
|
3409 | if inst.errno == errno.ETIMEDOUT: | |
3408 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
3410 | reason = _('timed out waiting for lock held by %s') % inst.locker | |
3409 | else: |
|
3411 | else: | |
3410 | reason = _('lock held by %s') % inst.locker |
|
3412 | reason = _('lock held by %s') % inst.locker | |
3411 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
3413 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) | |
3412 | except lock.LockUnavailable, inst: |
|
3414 | except lock.LockUnavailable, inst: | |
3413 | u.warn(_("abort: could not lock %s: %s\n") % |
|
3415 | u.warn(_("abort: could not lock %s: %s\n") % | |
3414 | (inst.desc or inst.filename, inst.strerror)) |
|
3416 | (inst.desc or inst.filename, inst.strerror)) | |
3415 | except revlog.RevlogError, inst: |
|
3417 | except revlog.RevlogError, inst: | |
3416 | u.warn(_("abort: "), inst, "!\n") |
|
3418 | u.warn(_("abort: "), inst, "!\n") | |
3417 | except SignalInterrupt: |
|
3419 | except SignalInterrupt: | |
3418 | u.warn(_("killed!\n")) |
|
3420 | u.warn(_("killed!\n")) | |
3419 | except KeyboardInterrupt: |
|
3421 | except KeyboardInterrupt: | |
3420 | try: |
|
3422 | try: | |
3421 | u.warn(_("interrupted!\n")) |
|
3423 | u.warn(_("interrupted!\n")) | |
3422 | except IOError, inst: |
|
3424 | except IOError, inst: | |
3423 | if inst.errno == errno.EPIPE: |
|
3425 | if inst.errno == errno.EPIPE: | |
3424 | if u.debugflag: |
|
3426 | if u.debugflag: | |
3425 | u.warn(_("\nbroken pipe\n")) |
|
3427 | u.warn(_("\nbroken pipe\n")) | |
3426 | else: |
|
3428 | else: | |
3427 | raise |
|
3429 | raise | |
3428 | except IOError, inst: |
|
3430 | except IOError, inst: | |
3429 | if hasattr(inst, "code"): |
|
3431 | if hasattr(inst, "code"): | |
3430 | u.warn(_("abort: %s\n") % inst) |
|
3432 | u.warn(_("abort: %s\n") % inst) | |
3431 | elif hasattr(inst, "reason"): |
|
3433 | elif hasattr(inst, "reason"): | |
3432 | u.warn(_("abort: error: %s\n") % inst.reason[1]) |
|
3434 | u.warn(_("abort: error: %s\n") % inst.reason[1]) | |
3433 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
3435 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: | |
3434 | if u.debugflag: |
|
3436 | if u.debugflag: | |
3435 | u.warn(_("broken pipe\n")) |
|
3437 | u.warn(_("broken pipe\n")) | |
3436 | elif getattr(inst, "strerror", None): |
|
3438 | elif getattr(inst, "strerror", None): | |
3437 | if getattr(inst, "filename", None): |
|
3439 | if getattr(inst, "filename", None): | |
3438 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) |
|
3440 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) | |
3439 | else: |
|
3441 | else: | |
3440 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3442 | u.warn(_("abort: %s\n") % inst.strerror) | |
3441 | else: |
|
3443 | else: | |
3442 | raise |
|
3444 | raise | |
3443 | except OSError, inst: |
|
3445 | except OSError, inst: | |
3444 | if hasattr(inst, "filename"): |
|
3446 | if hasattr(inst, "filename"): | |
3445 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3447 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) | |
3446 | else: |
|
3448 | else: | |
3447 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3449 | u.warn(_("abort: %s\n") % inst.strerror) | |
3448 | except util.Abort, inst: |
|
3450 | except util.Abort, inst: | |
3449 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') |
|
3451 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') | |
3450 | sys.exit(1) |
|
3452 | sys.exit(1) | |
3451 | except TypeError, inst: |
|
3453 | except TypeError, inst: | |
3452 | # was this an argument error? |
|
3454 | # was this an argument error? | |
3453 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
3455 | tb = traceback.extract_tb(sys.exc_info()[2]) | |
3454 | if len(tb) > 2: # no |
|
3456 | if len(tb) > 2: # no | |
3455 | raise |
|
3457 | raise | |
3456 | u.debug(inst, "\n") |
|
3458 | u.debug(inst, "\n") | |
3457 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
3459 | u.warn(_("%s: invalid arguments\n") % cmd) | |
3458 | help_(u, cmd) |
|
3460 | help_(u, cmd) | |
3459 | except SystemExit: |
|
3461 | except SystemExit: | |
3460 | # don't catch this in the catch-all below |
|
3462 | # don't catch this in the catch-all below | |
3461 | raise |
|
3463 | raise | |
3462 | except: |
|
3464 | except: | |
3463 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
3465 | u.warn(_("** unknown exception encountered, details follow\n")) | |
3464 | u.warn(_("** report bug details to mercurial@selenic.com\n")) |
|
3466 | u.warn(_("** report bug details to mercurial@selenic.com\n")) | |
3465 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
3467 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") | |
3466 | % version.get_version()) |
|
3468 | % version.get_version()) | |
3467 | raise |
|
3469 | raise | |
3468 |
|
3470 | |||
3469 | sys.exit(-1) |
|
3471 | sys.exit(-1) |
@@ -1,404 +1,404 b'' | |||||
1 | /* |
|
1 | /* | |
2 | mpatch.c - efficient binary patching for Mercurial |
|
2 | mpatch.c - efficient binary patching for Mercurial | |
3 |
|
3 | |||
4 | This implements a patch algorithm that's O(m + nlog n) where m is the |
|
4 | This implements a patch algorithm that's O(m + nlog n) where m is the | |
5 | size of the output and n is the number of patches. |
|
5 | size of the output and n is the number of patches. | |
6 |
|
6 | |||
7 | Given a list of binary patches, it unpacks each into a hunk list, |
|
7 | Given a list of binary patches, it unpacks each into a hunk list, | |
8 | then combines the hunk lists with a treewise recursion to form a |
|
8 | then combines the hunk lists with a treewise recursion to form a | |
9 | single hunk list. This hunk list is then applied to the original |
|
9 | single hunk list. This hunk list is then applied to the original | |
10 | text. |
|
10 | text. | |
11 |
|
11 | |||
12 | The text (or binary) fragments are copied directly from their source |
|
12 | The text (or binary) fragments are copied directly from their source | |
13 | Python objects into a preallocated output string to avoid the |
|
13 | Python objects into a preallocated output string to avoid the | |
14 | allocation of intermediate Python objects. Working memory is about 2x |
|
14 | allocation of intermediate Python objects. Working memory is about 2x | |
15 | the total number of hunks. |
|
15 | the total number of hunks. | |
16 |
|
16 | |||
17 | Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
17 | Copyright 2005 Matt Mackall <mpm@selenic.com> | |
18 |
|
18 | |||
19 | This software may be used and distributed according to the terms |
|
19 | This software may be used and distributed according to the terms | |
20 | of the GNU General Public License, incorporated herein by reference. |
|
20 | of the GNU General Public License, incorporated herein by reference. | |
21 | */ |
|
21 | */ | |
22 |
|
22 | |||
23 | #include <Python.h> |
|
23 | #include <Python.h> | |
24 | #include <stdlib.h> |
|
24 | #include <stdlib.h> | |
25 | #include <string.h> |
|
25 | #include <string.h> | |
26 | #ifdef _WIN32 |
|
26 | #ifdef _WIN32 | |
27 | #ifdef _MSC_VER |
|
27 | #ifdef _MSC_VER | |
28 | #define inline __inline |
|
28 | #define inline __inline | |
29 | typedef unsigned long uint32_t; |
|
29 | typedef unsigned long uint32_t; | |
30 | #else |
|
30 | #else | |
31 | #include <stdint.h> |
|
31 | #include <stdint.h> | |
32 | #endif |
|
32 | #endif | |
33 | static uint32_t ntohl(uint32_t x) |
|
33 | static uint32_t ntohl(uint32_t x) | |
34 | { |
|
34 | { | |
35 | return ((x & 0x000000ffUL) << 24) | |
|
35 | return ((x & 0x000000ffUL) << 24) | | |
36 | ((x & 0x0000ff00UL) << 8) | |
|
36 | ((x & 0x0000ff00UL) << 8) | | |
37 | ((x & 0x00ff0000UL) >> 8) | |
|
37 | ((x & 0x00ff0000UL) >> 8) | | |
38 | ((x & 0xff000000UL) >> 24); |
|
38 | ((x & 0xff000000UL) >> 24); | |
39 | } |
|
39 | } | |
40 | #else |
|
40 | #else | |
41 | #include <sys/types.h> |
|
41 | #include <sys/types.h> | |
42 | #include <arpa/inet.h> |
|
42 | #include <arpa/inet.h> | |
43 | #endif |
|
43 | #endif | |
44 |
|
44 | |||
45 | static char mpatch_doc[] = "Efficient binary patching."; |
|
45 | static char mpatch_doc[] = "Efficient binary patching."; | |
46 | static PyObject *mpatch_Error; |
|
46 | static PyObject *mpatch_Error; | |
47 |
|
47 | |||
48 | struct frag { |
|
48 | struct frag { | |
49 | int start, end, len; |
|
49 | int start, end, len; | |
50 | char *data; |
|
50 | char *data; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | struct flist { |
|
53 | struct flist { | |
54 | struct frag *base, *head, *tail; |
|
54 | struct frag *base, *head, *tail; | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | static struct flist *lalloc(int size) |
|
57 | static struct flist *lalloc(int size) | |
58 | { |
|
58 | { | |
59 | struct flist *a = NULL; |
|
59 | struct flist *a = NULL; | |
60 |
|
60 | |||
61 | a = (struct flist *)malloc(sizeof(struct flist)); |
|
61 | a = (struct flist *)malloc(sizeof(struct flist)); | |
62 | if (a) { |
|
62 | if (a) { | |
63 | a->base = (struct frag *)malloc(sizeof(struct frag) * size); |
|
63 | a->base = (struct frag *)malloc(sizeof(struct frag) * size); | |
64 |
if ( |
|
64 | if (a->base) { | |
65 | free(a); |
|
|||
66 | a = NULL; |
|
|||
67 | } else |
|
|||
68 | a->head = a->tail = a->base; |
|
65 | a->head = a->tail = a->base; | |
69 | return a; |
|
66 | return a; | |
|
67 | } | |||
|
68 | free(a); | |||
|
69 | a = NULL; | |||
70 | } |
|
70 | } | |
71 | if (!PyErr_Occurred()) |
|
71 | if (!PyErr_Occurred()) | |
72 | PyErr_NoMemory(); |
|
72 | PyErr_NoMemory(); | |
73 | return NULL; |
|
73 | return NULL; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | static void lfree(struct flist *a) |
|
76 | static void lfree(struct flist *a) | |
77 | { |
|
77 | { | |
78 | if (a) { |
|
78 | if (a) { | |
79 | free(a->base); |
|
79 | free(a->base); | |
80 | free(a); |
|
80 | free(a); | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | static int lsize(struct flist *a) |
|
84 | static int lsize(struct flist *a) | |
85 | { |
|
85 | { | |
86 | return a->tail - a->head; |
|
86 | return a->tail - a->head; | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | /* move hunks in source that are less cut to dest, compensating |
|
89 | /* move hunks in source that are less cut to dest, compensating | |
90 | for changes in offset. the last hunk may be split if necessary. |
|
90 | for changes in offset. the last hunk may be split if necessary. | |
91 | */ |
|
91 | */ | |
92 | static int gather(struct flist *dest, struct flist *src, int cut, int offset) |
|
92 | static int gather(struct flist *dest, struct flist *src, int cut, int offset) | |
93 | { |
|
93 | { | |
94 | struct frag *d = dest->tail, *s = src->head; |
|
94 | struct frag *d = dest->tail, *s = src->head; | |
95 | int postend, c, l; |
|
95 | int postend, c, l; | |
96 |
|
96 | |||
97 | while (s != src->tail) { |
|
97 | while (s != src->tail) { | |
98 | if (s->start + offset >= cut) |
|
98 | if (s->start + offset >= cut) | |
99 | break; /* we've gone far enough */ |
|
99 | break; /* we've gone far enough */ | |
100 |
|
100 | |||
101 | postend = offset + s->start + s->len; |
|
101 | postend = offset + s->start + s->len; | |
102 | if (postend <= cut) { |
|
102 | if (postend <= cut) { | |
103 | /* save this hunk */ |
|
103 | /* save this hunk */ | |
104 | offset += s->start + s->len - s->end; |
|
104 | offset += s->start + s->len - s->end; | |
105 | *d++ = *s++; |
|
105 | *d++ = *s++; | |
106 | } |
|
106 | } | |
107 | else { |
|
107 | else { | |
108 | /* break up this hunk */ |
|
108 | /* break up this hunk */ | |
109 | c = cut - offset; |
|
109 | c = cut - offset; | |
110 | if (s->end < c) |
|
110 | if (s->end < c) | |
111 | c = s->end; |
|
111 | c = s->end; | |
112 | l = cut - offset - s->start; |
|
112 | l = cut - offset - s->start; | |
113 | if (s->len < l) |
|
113 | if (s->len < l) | |
114 | l = s->len; |
|
114 | l = s->len; | |
115 |
|
115 | |||
116 | offset += s->start + l - c; |
|
116 | offset += s->start + l - c; | |
117 |
|
117 | |||
118 | d->start = s->start; |
|
118 | d->start = s->start; | |
119 | d->end = c; |
|
119 | d->end = c; | |
120 | d->len = l; |
|
120 | d->len = l; | |
121 | d->data = s->data; |
|
121 | d->data = s->data; | |
122 | d++; |
|
122 | d++; | |
123 | s->start = c; |
|
123 | s->start = c; | |
124 | s->len = s->len - l; |
|
124 | s->len = s->len - l; | |
125 | s->data = s->data + l; |
|
125 | s->data = s->data + l; | |
126 |
|
126 | |||
127 | break; |
|
127 | break; | |
128 | } |
|
128 | } | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | dest->tail = d; |
|
131 | dest->tail = d; | |
132 | src->head = s; |
|
132 | src->head = s; | |
133 | return offset; |
|
133 | return offset; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /* like gather, but with no output list */ |
|
136 | /* like gather, but with no output list */ | |
137 | static int discard(struct flist *src, int cut, int offset) |
|
137 | static int discard(struct flist *src, int cut, int offset) | |
138 | { |
|
138 | { | |
139 | struct frag *s = src->head; |
|
139 | struct frag *s = src->head; | |
140 | int postend, c, l; |
|
140 | int postend, c, l; | |
141 |
|
141 | |||
142 | while (s != src->tail) { |
|
142 | while (s != src->tail) { | |
143 | if (s->start + offset >= cut) |
|
143 | if (s->start + offset >= cut) | |
144 | break; |
|
144 | break; | |
145 |
|
145 | |||
146 | postend = offset + s->start + s->len; |
|
146 | postend = offset + s->start + s->len; | |
147 | if (postend <= cut) { |
|
147 | if (postend <= cut) { | |
148 | offset += s->start + s->len - s->end; |
|
148 | offset += s->start + s->len - s->end; | |
149 | s++; |
|
149 | s++; | |
150 | } |
|
150 | } | |
151 | else { |
|
151 | else { | |
152 | c = cut - offset; |
|
152 | c = cut - offset; | |
153 | if (s->end < c) |
|
153 | if (s->end < c) | |
154 | c = s->end; |
|
154 | c = s->end; | |
155 | l = cut - offset - s->start; |
|
155 | l = cut - offset - s->start; | |
156 | if (s->len < l) |
|
156 | if (s->len < l) | |
157 | l = s->len; |
|
157 | l = s->len; | |
158 |
|
158 | |||
159 | offset += s->start + l - c; |
|
159 | offset += s->start + l - c; | |
160 | s->start = c; |
|
160 | s->start = c; | |
161 | s->len = s->len - l; |
|
161 | s->len = s->len - l; | |
162 | s->data = s->data + l; |
|
162 | s->data = s->data + l; | |
163 |
|
163 | |||
164 | break; |
|
164 | break; | |
165 | } |
|
165 | } | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | src->head = s; |
|
168 | src->head = s; | |
169 | return offset; |
|
169 | return offset; | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /* combine hunk lists a and b, while adjusting b for offset changes in a/ |
|
172 | /* combine hunk lists a and b, while adjusting b for offset changes in a/ | |
173 | this deletes a and b and returns the resultant list. */ |
|
173 | this deletes a and b and returns the resultant list. */ | |
174 | static struct flist *combine(struct flist *a, struct flist *b) |
|
174 | static struct flist *combine(struct flist *a, struct flist *b) | |
175 | { |
|
175 | { | |
176 | struct flist *c = NULL; |
|
176 | struct flist *c = NULL; | |
177 | struct frag *bh, *ct; |
|
177 | struct frag *bh, *ct; | |
178 | int offset = 0, post; |
|
178 | int offset = 0, post; | |
179 |
|
179 | |||
180 | if (a && b) |
|
180 | if (a && b) | |
181 | c = lalloc((lsize(a) + lsize(b)) * 2); |
|
181 | c = lalloc((lsize(a) + lsize(b)) * 2); | |
182 |
|
182 | |||
183 | if (c) { |
|
183 | if (c) { | |
184 |
|
184 | |||
185 | for (bh = b->head; bh != b->tail; bh++) { |
|
185 | for (bh = b->head; bh != b->tail; bh++) { | |
186 | /* save old hunks */ |
|
186 | /* save old hunks */ | |
187 | offset = gather(c, a, bh->start, offset); |
|
187 | offset = gather(c, a, bh->start, offset); | |
188 |
|
188 | |||
189 | /* discard replaced hunks */ |
|
189 | /* discard replaced hunks */ | |
190 | post = discard(a, bh->end, offset); |
|
190 | post = discard(a, bh->end, offset); | |
191 |
|
191 | |||
192 | /* insert new hunk */ |
|
192 | /* insert new hunk */ | |
193 | ct = c->tail; |
|
193 | ct = c->tail; | |
194 | ct->start = bh->start - offset; |
|
194 | ct->start = bh->start - offset; | |
195 | ct->end = bh->end - post; |
|
195 | ct->end = bh->end - post; | |
196 | ct->len = bh->len; |
|
196 | ct->len = bh->len; | |
197 | ct->data = bh->data; |
|
197 | ct->data = bh->data; | |
198 | c->tail++; |
|
198 | c->tail++; | |
199 | offset = post; |
|
199 | offset = post; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | /* hold on to tail from a */ |
|
202 | /* hold on to tail from a */ | |
203 | memcpy(c->tail, a->head, sizeof(struct frag) * lsize(a)); |
|
203 | memcpy(c->tail, a->head, sizeof(struct frag) * lsize(a)); | |
204 | c->tail += lsize(a); |
|
204 | c->tail += lsize(a); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | lfree(a); |
|
207 | lfree(a); | |
208 | lfree(b); |
|
208 | lfree(b); | |
209 | return c; |
|
209 | return c; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /* decode a binary patch into a hunk list */ |
|
212 | /* decode a binary patch into a hunk list */ | |
213 | static struct flist *decode(char *bin, int len) |
|
213 | static struct flist *decode(char *bin, int len) | |
214 | { |
|
214 | { | |
215 | struct flist *l; |
|
215 | struct flist *l; | |
216 | struct frag *lt; |
|
216 | struct frag *lt; | |
217 | char *end = bin + len; |
|
217 | char *end = bin + len; | |
218 | char decode[12]; /* for dealing with alignment issues */ |
|
218 | char decode[12]; /* for dealing with alignment issues */ | |
219 |
|
219 | |||
220 | /* assume worst case size, we won't have many of these lists */ |
|
220 | /* assume worst case size, we won't have many of these lists */ | |
221 | l = lalloc(len / 12); |
|
221 | l = lalloc(len / 12); | |
222 | if (!l) |
|
222 | if (!l) | |
223 | return NULL; |
|
223 | return NULL; | |
224 |
|
224 | |||
225 | lt = l->tail; |
|
225 | lt = l->tail; | |
226 |
|
226 | |||
227 | while (bin < end) { |
|
227 | while (bin < end) { | |
228 | memcpy(decode, bin, 12); |
|
228 | memcpy(decode, bin, 12); | |
229 | lt->start = ntohl(*(uint32_t *)decode); |
|
229 | lt->start = ntohl(*(uint32_t *)decode); | |
230 | lt->end = ntohl(*(uint32_t *)(decode + 4)); |
|
230 | lt->end = ntohl(*(uint32_t *)(decode + 4)); | |
231 | lt->len = ntohl(*(uint32_t *)(decode + 8)); |
|
231 | lt->len = ntohl(*(uint32_t *)(decode + 8)); | |
232 | lt->data = bin + 12; |
|
232 | lt->data = bin + 12; | |
233 | bin += 12 + lt->len; |
|
233 | bin += 12 + lt->len; | |
234 | lt++; |
|
234 | lt++; | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | if (bin != end) { |
|
237 | if (bin != end) { | |
238 | if (!PyErr_Occurred()) |
|
238 | if (!PyErr_Occurred()) | |
239 | PyErr_SetString(mpatch_Error, "patch cannot be decoded"); |
|
239 | PyErr_SetString(mpatch_Error, "patch cannot be decoded"); | |
240 | lfree(l); |
|
240 | lfree(l); | |
241 | return NULL; |
|
241 | return NULL; | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | l->tail = lt; |
|
244 | l->tail = lt; | |
245 | return l; |
|
245 | return l; | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | /* calculate the size of resultant text */ |
|
248 | /* calculate the size of resultant text */ | |
249 | static int calcsize(int len, struct flist *l) |
|
249 | static int calcsize(int len, struct flist *l) | |
250 | { |
|
250 | { | |
251 | int outlen = 0, last = 0; |
|
251 | int outlen = 0, last = 0; | |
252 | struct frag *f = l->head; |
|
252 | struct frag *f = l->head; | |
253 |
|
253 | |||
254 | while (f != l->tail) { |
|
254 | while (f != l->tail) { | |
255 | if (f->start < last || f->end > len) { |
|
255 | if (f->start < last || f->end > len) { | |
256 | if (!PyErr_Occurred()) |
|
256 | if (!PyErr_Occurred()) | |
257 | PyErr_SetString(mpatch_Error, |
|
257 | PyErr_SetString(mpatch_Error, | |
258 | "invalid patch"); |
|
258 | "invalid patch"); | |
259 | return -1; |
|
259 | return -1; | |
260 | } |
|
260 | } | |
261 | outlen += f->start - last; |
|
261 | outlen += f->start - last; | |
262 | last = f->end; |
|
262 | last = f->end; | |
263 | outlen += f->len; |
|
263 | outlen += f->len; | |
264 | f++; |
|
264 | f++; | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | outlen += len - last; |
|
267 | outlen += len - last; | |
268 | return outlen; |
|
268 | return outlen; | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | static int apply(char *buf, char *orig, int len, struct flist *l) |
|
271 | static int apply(char *buf, char *orig, int len, struct flist *l) | |
272 | { |
|
272 | { | |
273 | struct frag *f = l->head; |
|
273 | struct frag *f = l->head; | |
274 | int last = 0; |
|
274 | int last = 0; | |
275 | char *p = buf; |
|
275 | char *p = buf; | |
276 |
|
276 | |||
277 | while (f != l->tail) { |
|
277 | while (f != l->tail) { | |
278 | if (f->start < last || f->end > len) { |
|
278 | if (f->start < last || f->end > len) { | |
279 | if (!PyErr_Occurred()) |
|
279 | if (!PyErr_Occurred()) | |
280 | PyErr_SetString(mpatch_Error, |
|
280 | PyErr_SetString(mpatch_Error, | |
281 | "invalid patch"); |
|
281 | "invalid patch"); | |
282 | return 0; |
|
282 | return 0; | |
283 | } |
|
283 | } | |
284 | memcpy(p, orig + last, f->start - last); |
|
284 | memcpy(p, orig + last, f->start - last); | |
285 | p += f->start - last; |
|
285 | p += f->start - last; | |
286 | memcpy(p, f->data, f->len); |
|
286 | memcpy(p, f->data, f->len); | |
287 | last = f->end; |
|
287 | last = f->end; | |
288 | p += f->len; |
|
288 | p += f->len; | |
289 | f++; |
|
289 | f++; | |
290 | } |
|
290 | } | |
291 | memcpy(p, orig + last, len - last); |
|
291 | memcpy(p, orig + last, len - last); | |
292 | return 1; |
|
292 | return 1; | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | /* recursively generate a patch of all bins between start and end */ |
|
295 | /* recursively generate a patch of all bins between start and end */ | |
296 | static struct flist *fold(PyObject *bins, int start, int end) |
|
296 | static struct flist *fold(PyObject *bins, int start, int end) | |
297 | { |
|
297 | { | |
298 | int len; |
|
298 | int len; | |
299 |
|
299 | |||
300 | if (start + 1 == end) { |
|
300 | if (start + 1 == end) { | |
301 | /* trivial case, output a decoded list */ |
|
301 | /* trivial case, output a decoded list */ | |
302 | PyObject *tmp = PyList_GetItem(bins, start); |
|
302 | PyObject *tmp = PyList_GetItem(bins, start); | |
303 | if (!tmp) |
|
303 | if (!tmp) | |
304 | return NULL; |
|
304 | return NULL; | |
305 | return decode(PyString_AsString(tmp), PyString_Size(tmp)); |
|
305 | return decode(PyString_AsString(tmp), PyString_Size(tmp)); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | /* divide and conquer, memory management is elsewhere */ |
|
308 | /* divide and conquer, memory management is elsewhere */ | |
309 | len = (end - start) / 2; |
|
309 | len = (end - start) / 2; | |
310 | return combine(fold(bins, start, start + len), |
|
310 | return combine(fold(bins, start, start + len), | |
311 | fold(bins, start + len, end)); |
|
311 | fold(bins, start + len, end)); | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | static PyObject * |
|
314 | static PyObject * | |
315 | patches(PyObject *self, PyObject *args) |
|
315 | patches(PyObject *self, PyObject *args) | |
316 | { |
|
316 | { | |
317 | PyObject *text, *bins, *result; |
|
317 | PyObject *text, *bins, *result; | |
318 | struct flist *patch; |
|
318 | struct flist *patch; | |
319 | char *in, *out; |
|
319 | char *in, *out; | |
320 | int len, outlen; |
|
320 | int len, outlen; | |
321 |
|
321 | |||
322 | if (!PyArg_ParseTuple(args, "SO:mpatch", &text, &bins)) |
|
322 | if (!PyArg_ParseTuple(args, "SO:mpatch", &text, &bins)) | |
323 | return NULL; |
|
323 | return NULL; | |
324 |
|
324 | |||
325 | len = PyList_Size(bins); |
|
325 | len = PyList_Size(bins); | |
326 | if (!len) { |
|
326 | if (!len) { | |
327 | /* nothing to do */ |
|
327 | /* nothing to do */ | |
328 | Py_INCREF(text); |
|
328 | Py_INCREF(text); | |
329 | return text; |
|
329 | return text; | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | patch = fold(bins, 0, len); |
|
332 | patch = fold(bins, 0, len); | |
333 | if (!patch) |
|
333 | if (!patch) | |
334 | return NULL; |
|
334 | return NULL; | |
335 |
|
335 | |||
336 | outlen = calcsize(PyString_Size(text), patch); |
|
336 | outlen = calcsize(PyString_Size(text), patch); | |
337 | if (outlen < 0) { |
|
337 | if (outlen < 0) { | |
338 | result = NULL; |
|
338 | result = NULL; | |
339 | goto cleanup; |
|
339 | goto cleanup; | |
340 | } |
|
340 | } | |
341 | result = PyString_FromStringAndSize(NULL, outlen); |
|
341 | result = PyString_FromStringAndSize(NULL, outlen); | |
342 | if (!result) { |
|
342 | if (!result) { | |
343 | result = NULL; |
|
343 | result = NULL; | |
344 | goto cleanup; |
|
344 | goto cleanup; | |
345 | } |
|
345 | } | |
346 | in = PyString_AsString(text); |
|
346 | in = PyString_AsString(text); | |
347 | out = PyString_AsString(result); |
|
347 | out = PyString_AsString(result); | |
348 | if (!apply(out, in, PyString_Size(text), patch)) { |
|
348 | if (!apply(out, in, PyString_Size(text), patch)) { | |
349 | Py_DECREF(result); |
|
349 | Py_DECREF(result); | |
350 | result = NULL; |
|
350 | result = NULL; | |
351 | } |
|
351 | } | |
352 | cleanup: |
|
352 | cleanup: | |
353 | lfree(patch); |
|
353 | lfree(patch); | |
354 | return result; |
|
354 | return result; | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | /* calculate size of a patched file directly */ |
|
357 | /* calculate size of a patched file directly */ | |
358 | static PyObject * |
|
358 | static PyObject * | |
359 | patchedsize(PyObject *self, PyObject *args) |
|
359 | patchedsize(PyObject *self, PyObject *args) | |
360 | { |
|
360 | { | |
361 | long orig, start, end, len, outlen = 0, last = 0; |
|
361 | long orig, start, end, len, outlen = 0, last = 0; | |
362 | int patchlen; |
|
362 | int patchlen; | |
363 | char *bin, *binend; |
|
363 | char *bin, *binend; | |
364 | char decode[12]; /* for dealing with alignment issues */ |
|
364 | char decode[12]; /* for dealing with alignment issues */ | |
365 |
|
365 | |||
366 | if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen)) |
|
366 | if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen)) | |
367 | return NULL; |
|
367 | return NULL; | |
368 |
|
368 | |||
369 | binend = bin + patchlen; |
|
369 | binend = bin + patchlen; | |
370 |
|
370 | |||
371 | while (bin < binend) { |
|
371 | while (bin < binend) { | |
372 | memcpy(decode, bin, 12); |
|
372 | memcpy(decode, bin, 12); | |
373 | start = ntohl(*(uint32_t *)decode); |
|
373 | start = ntohl(*(uint32_t *)decode); | |
374 | end = ntohl(*(uint32_t *)(decode + 4)); |
|
374 | end = ntohl(*(uint32_t *)(decode + 4)); | |
375 | len = ntohl(*(uint32_t *)(decode + 8)); |
|
375 | len = ntohl(*(uint32_t *)(decode + 8)); | |
376 | bin += 12 + len; |
|
376 | bin += 12 + len; | |
377 | outlen += start - last; |
|
377 | outlen += start - last; | |
378 | last = end; |
|
378 | last = end; | |
379 | outlen += len; |
|
379 | outlen += len; | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | if (bin != binend) { |
|
382 | if (bin != binend) { | |
383 | if (!PyErr_Occurred()) |
|
383 | if (!PyErr_Occurred()) | |
384 | PyErr_SetString(mpatch_Error, "patch cannot be decoded"); |
|
384 | PyErr_SetString(mpatch_Error, "patch cannot be decoded"); | |
385 | return NULL; |
|
385 | return NULL; | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | outlen += orig - last; |
|
388 | outlen += orig - last; | |
389 | return Py_BuildValue("l", outlen); |
|
389 | return Py_BuildValue("l", outlen); | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | static PyMethodDef methods[] = { |
|
392 | static PyMethodDef methods[] = { | |
393 | {"patches", patches, METH_VARARGS, "apply a series of patches\n"}, |
|
393 | {"patches", patches, METH_VARARGS, "apply a series of patches\n"}, | |
394 | {"patchedsize", patchedsize, METH_VARARGS, "calculed patched size\n"}, |
|
394 | {"patchedsize", patchedsize, METH_VARARGS, "calculed patched size\n"}, | |
395 | {NULL, NULL} |
|
395 | {NULL, NULL} | |
396 | }; |
|
396 | }; | |
397 |
|
397 | |||
398 | PyMODINIT_FUNC |
|
398 | PyMODINIT_FUNC | |
399 | initmpatch(void) |
|
399 | initmpatch(void) | |
400 | { |
|
400 | { | |
401 | Py_InitModule3("mpatch", methods, mpatch_doc); |
|
401 | Py_InitModule3("mpatch", methods, mpatch_doc); | |
402 | mpatch_Error = PyErr_NewException("mpatch.mpatchError", NULL, NULL); |
|
402 | mpatch_Error = PyErr_NewException("mpatch.mpatchError", NULL, NULL); | |
403 | } |
|
403 | } | |
404 |
|
404 |
@@ -1,155 +1,155 b'' | |||||
1 | # sshrepo.py - ssh repository proxy class for mercurial |
|
1 | # sshrepo.py - ssh repository proxy 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 | from node import * |
|
8 | from node import * | |
9 | from remoterepo import * |
|
9 | from remoterepo import * | |
10 | from i18n import gettext as _ |
|
10 | from i18n import gettext as _ | |
11 | from demandload import * |
|
11 | from demandload import * | |
12 | demandload(globals(), "hg os re stat") |
|
12 | demandload(globals(), "hg os re stat") | |
13 |
|
13 | |||
14 | class sshrepository(remoterepository): |
|
14 | class sshrepository(remoterepository): | |
15 | def __init__(self, ui, path): |
|
15 | def __init__(self, ui, path): | |
16 | self.url = path |
|
16 | self.url = path | |
17 | self.ui = ui |
|
17 | self.ui = ui | |
18 |
|
18 | |||
19 | m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path) |
|
19 | m = re.match(r'ssh://(([^@]+)@)?([^:/]+)(:(\d+))?(/(.*))?', path) | |
20 | if not m: |
|
20 | if not m: | |
21 | raise hg.RepoError(_("couldn't parse destination %s") % path) |
|
21 | raise hg.RepoError(_("couldn't parse destination %s") % path) | |
22 |
|
22 | |||
23 | self.user = m.group(2) |
|
23 | self.user = m.group(2) | |
24 | self.host = m.group(3) |
|
24 | self.host = m.group(3) | |
25 | self.port = m.group(5) |
|
25 | self.port = m.group(5) | |
26 | self.path = m.group(7) or "." |
|
26 | self.path = m.group(7) or "." | |
27 |
|
27 | |||
28 | args = self.user and ("%s@%s" % (self.user, self.host)) or self.host |
|
28 | args = self.user and ("%s@%s" % (self.user, self.host)) or self.host | |
29 | args = self.port and ("%s -p %s") % (args, self.port) or args |
|
29 | args = self.port and ("%s -p %s") % (args, self.port) or args | |
30 |
|
30 | |||
31 | sshcmd = self.ui.config("ui", "ssh", "ssh") |
|
31 | sshcmd = self.ui.config("ui", "ssh", "ssh") | |
32 | remotecmd = self.ui.config("ui", "remotecmd", "hg") |
|
32 | remotecmd = self.ui.config("ui", "remotecmd", "hg") | |
33 | cmd = '%s %s "%s -R %s serve --stdio"' |
|
33 | cmd = '%s %s "%s -R %s serve --stdio"' | |
34 | cmd = cmd % (sshcmd, args, remotecmd, self.path) |
|
34 | cmd = cmd % (sshcmd, args, remotecmd, self.path) | |
35 |
|
35 | |||
36 | ui.note('running %s\n' % cmd) |
|
36 | ui.note('running %s\n' % cmd) | |
37 | self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b') |
|
37 | self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b') | |
38 |
|
38 | |||
39 | # skip any noise generated by remote shell |
|
39 | # skip any noise generated by remote shell | |
40 | r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40))) |
|
40 | r = self.do_cmd("between", pairs=("%s-%s" % ("0"*40, "0"*40))) | |
41 | l1 = "" |
|
41 | l1 = "" | |
42 | l2 = "dummy" |
|
42 | l2 = "dummy" | |
43 |
max_noise = |
|
43 | max_noise = 500 | |
44 | while l2 and max_noise: |
|
44 | while l2 and max_noise: | |
45 | l2 = r.readline() |
|
45 | l2 = r.readline() | |
46 | self.readerr() |
|
46 | self.readerr() | |
47 | if l1 == "1\n" and l2 == "\n": |
|
47 | if l1 == "1\n" and l2 == "\n": | |
48 | break |
|
48 | break | |
49 | if l1: |
|
49 | if l1: | |
50 |
ui. |
|
50 | ui.debug(_("remote: "), l1) | |
51 | l1 = l2 |
|
51 | l1 = l2 | |
52 | max_noise -= 1 |
|
52 | max_noise -= 1 | |
53 | else: |
|
53 | else: | |
54 | if l1: |
|
54 | if l1: | |
55 |
ui. |
|
55 | ui.debug(_("remote: "), l1) | |
56 | raise hg.RepoError(_("no response from remote hg")) |
|
56 | raise hg.RepoError(_("no response from remote hg")) | |
57 |
|
57 | |||
58 | def readerr(self): |
|
58 | def readerr(self): | |
59 | while 1: |
|
59 | while 1: | |
60 | size = os.fstat(self.pipee.fileno())[stat.ST_SIZE] |
|
60 | size = os.fstat(self.pipee.fileno())[stat.ST_SIZE] | |
61 | if size == 0: break |
|
61 | if size == 0: break | |
62 | l = self.pipee.readline() |
|
62 | l = self.pipee.readline() | |
63 | if not l: break |
|
63 | if not l: break | |
64 | self.ui.status(_("remote: "), l) |
|
64 | self.ui.status(_("remote: "), l) | |
65 |
|
65 | |||
66 | def __del__(self): |
|
66 | def __del__(self): | |
67 | try: |
|
67 | try: | |
68 | self.pipeo.close() |
|
68 | self.pipeo.close() | |
69 | self.pipei.close() |
|
69 | self.pipei.close() | |
70 | # read the error descriptor until EOF |
|
70 | # read the error descriptor until EOF | |
71 | for l in self.pipee: |
|
71 | for l in self.pipee: | |
72 | self.ui.status(_("remote: "), l) |
|
72 | self.ui.status(_("remote: "), l) | |
73 | self.pipee.close() |
|
73 | self.pipee.close() | |
74 | except: |
|
74 | except: | |
75 | pass |
|
75 | pass | |
76 |
|
76 | |||
77 | def dev(self): |
|
77 | def dev(self): | |
78 | return -1 |
|
78 | return -1 | |
79 |
|
79 | |||
80 | def do_cmd(self, cmd, **args): |
|
80 | def do_cmd(self, cmd, **args): | |
81 | self.ui.debug(_("sending %s command\n") % cmd) |
|
81 | self.ui.debug(_("sending %s command\n") % cmd) | |
82 | self.pipeo.write("%s\n" % cmd) |
|
82 | self.pipeo.write("%s\n" % cmd) | |
83 | for k, v in args.items(): |
|
83 | for k, v in args.items(): | |
84 | self.pipeo.write("%s %d\n" % (k, len(v))) |
|
84 | self.pipeo.write("%s %d\n" % (k, len(v))) | |
85 | self.pipeo.write(v) |
|
85 | self.pipeo.write(v) | |
86 | self.pipeo.flush() |
|
86 | self.pipeo.flush() | |
87 |
|
87 | |||
88 | return self.pipei |
|
88 | return self.pipei | |
89 |
|
89 | |||
90 | def call(self, cmd, **args): |
|
90 | def call(self, cmd, **args): | |
91 | r = self.do_cmd(cmd, **args) |
|
91 | r = self.do_cmd(cmd, **args) | |
92 | l = r.readline() |
|
92 | l = r.readline() | |
93 | self.readerr() |
|
93 | self.readerr() | |
94 | try: |
|
94 | try: | |
95 | l = int(l) |
|
95 | l = int(l) | |
96 | except: |
|
96 | except: | |
97 | raise hg.RepoError(_("unexpected response '%s'") % l) |
|
97 | raise hg.RepoError(_("unexpected response '%s'") % l) | |
98 | return r.read(l) |
|
98 | return r.read(l) | |
99 |
|
99 | |||
100 | def lock(self): |
|
100 | def lock(self): | |
101 | self.call("lock") |
|
101 | self.call("lock") | |
102 | return remotelock(self) |
|
102 | return remotelock(self) | |
103 |
|
103 | |||
104 | def unlock(self): |
|
104 | def unlock(self): | |
105 | self.call("unlock") |
|
105 | self.call("unlock") | |
106 |
|
106 | |||
107 | def heads(self): |
|
107 | def heads(self): | |
108 | d = self.call("heads") |
|
108 | d = self.call("heads") | |
109 | try: |
|
109 | try: | |
110 | return map(bin, d[:-1].split(" ")) |
|
110 | return map(bin, d[:-1].split(" ")) | |
111 | except: |
|
111 | except: | |
112 | raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")) |
|
112 | raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")) | |
113 |
|
113 | |||
114 | def branches(self, nodes): |
|
114 | def branches(self, nodes): | |
115 | n = " ".join(map(hex, nodes)) |
|
115 | n = " ".join(map(hex, nodes)) | |
116 | d = self.call("branches", nodes=n) |
|
116 | d = self.call("branches", nodes=n) | |
117 | try: |
|
117 | try: | |
118 | br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] |
|
118 | br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] | |
119 | return br |
|
119 | return br | |
120 | except: |
|
120 | except: | |
121 | raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")) |
|
121 | raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")) | |
122 |
|
122 | |||
123 | def between(self, pairs): |
|
123 | def between(self, pairs): | |
124 | n = "\n".join(["-".join(map(hex, p)) for p in pairs]) |
|
124 | n = "\n".join(["-".join(map(hex, p)) for p in pairs]) | |
125 | d = self.call("between", pairs=n) |
|
125 | d = self.call("between", pairs=n) | |
126 | try: |
|
126 | try: | |
127 | p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] |
|
127 | p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] | |
128 | return p |
|
128 | return p | |
129 | except: |
|
129 | except: | |
130 | raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")) |
|
130 | raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "...")) | |
131 |
|
131 | |||
132 | def changegroup(self, nodes, kind): |
|
132 | def changegroup(self, nodes, kind): | |
133 | n = " ".join(map(hex, nodes)) |
|
133 | n = " ".join(map(hex, nodes)) | |
134 | f = self.do_cmd("changegroup", roots=n) |
|
134 | f = self.do_cmd("changegroup", roots=n) | |
135 | return self.pipei |
|
135 | return self.pipei | |
136 |
|
136 | |||
137 | def addchangegroup(self, cg): |
|
137 | def addchangegroup(self, cg): | |
138 | d = self.call("addchangegroup") |
|
138 | d = self.call("addchangegroup") | |
139 | if d: |
|
139 | if d: | |
140 | raise hg.RepoError(_("push refused: %s"), d) |
|
140 | raise hg.RepoError(_("push refused: %s"), d) | |
141 |
|
141 | |||
142 | while 1: |
|
142 | while 1: | |
143 | d = cg.read(4096) |
|
143 | d = cg.read(4096) | |
144 | if not d: break |
|
144 | if not d: break | |
145 | self.pipeo.write(d) |
|
145 | self.pipeo.write(d) | |
146 | self.readerr() |
|
146 | self.readerr() | |
147 |
|
147 | |||
148 | self.pipeo.flush() |
|
148 | self.pipeo.flush() | |
149 |
|
149 | |||
150 | self.readerr() |
|
150 | self.readerr() | |
151 | l = int(self.pipei.readline()) |
|
151 | l = int(self.pipei.readline()) | |
152 | r = self.pipei.read(l) |
|
152 | r = self.pipei.read(l) | |
153 | if not r: |
|
153 | if not r: | |
154 | return 1 |
|
154 | return 1 | |
155 | return int(r) |
|
155 | return int(r) |
@@ -1,832 +1,832 b'' | |||||
1 | """ |
|
1 | """ | |
2 | util.py - Mercurial utility functions and platform specfic implementations |
|
2 | util.py - Mercurial utility functions and platform specfic implementations | |
3 |
|
3 | |||
4 | Copyright 2005 K. Thananchayan <thananck@yahoo.com> |
|
4 | Copyright 2005 K. Thananchayan <thananck@yahoo.com> | |
5 |
|
5 | |||
6 | This software may be used and distributed according to the terms |
|
6 | This software may be used and distributed according to the terms | |
7 | of the GNU General Public License, incorporated herein by reference. |
|
7 | of the GNU General Public License, incorporated herein by reference. | |
8 |
|
8 | |||
9 | This contains helper routines that are independent of the SCM core and hide |
|
9 | This contains helper routines that are independent of the SCM core and hide | |
10 | platform-specific details from the core. |
|
10 | platform-specific details from the core. | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | import os, errno |
|
13 | import os, errno | |
14 | from i18n import gettext as _ |
|
14 | from i18n import gettext as _ | |
15 | from demandload import * |
|
15 | from demandload import * | |
16 | demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") |
|
16 | demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile") | |
17 | demandload(globals(), "threading time") |
|
17 | demandload(globals(), "threading time") | |
18 |
|
18 | |||
19 | def pipefilter(s, cmd): |
|
19 | def pipefilter(s, cmd): | |
20 | '''filter string S through command CMD, returning its output''' |
|
20 | '''filter string S through command CMD, returning its output''' | |
21 | (pout, pin) = popen2.popen2(cmd, -1, 'b') |
|
21 | (pout, pin) = popen2.popen2(cmd, -1, 'b') | |
22 | def writer(): |
|
22 | def writer(): | |
23 | pin.write(s) |
|
23 | pin.write(s) | |
24 | pin.close() |
|
24 | pin.close() | |
25 |
|
25 | |||
26 | # we should use select instead on UNIX, but this will work on most |
|
26 | # we should use select instead on UNIX, but this will work on most | |
27 | # systems, including Windows |
|
27 | # systems, including Windows | |
28 | w = threading.Thread(target=writer) |
|
28 | w = threading.Thread(target=writer) | |
29 | w.start() |
|
29 | w.start() | |
30 | f = pout.read() |
|
30 | f = pout.read() | |
31 | pout.close() |
|
31 | pout.close() | |
32 | w.join() |
|
32 | w.join() | |
33 | return f |
|
33 | return f | |
34 |
|
34 | |||
35 | def tempfilter(s, cmd): |
|
35 | def tempfilter(s, cmd): | |
36 | '''filter string S through a pair of temporary files with CMD. |
|
36 | '''filter string S through a pair of temporary files with CMD. | |
37 | CMD is used as a template to create the real command to be run, |
|
37 | CMD is used as a template to create the real command to be run, | |
38 | with the strings INFILE and OUTFILE replaced by the real names of |
|
38 | with the strings INFILE and OUTFILE replaced by the real names of | |
39 | the temporary files generated.''' |
|
39 | the temporary files generated.''' | |
40 | inname, outname = None, None |
|
40 | inname, outname = None, None | |
41 | try: |
|
41 | try: | |
42 | infd, inname = tempfile.mkstemp(prefix='hgfin') |
|
42 | infd, inname = tempfile.mkstemp(prefix='hgfin') | |
43 | fp = os.fdopen(infd, 'wb') |
|
43 | fp = os.fdopen(infd, 'wb') | |
44 | fp.write(s) |
|
44 | fp.write(s) | |
45 | fp.close() |
|
45 | fp.close() | |
46 | outfd, outname = tempfile.mkstemp(prefix='hgfout') |
|
46 | outfd, outname = tempfile.mkstemp(prefix='hgfout') | |
47 | os.close(outfd) |
|
47 | os.close(outfd) | |
48 | cmd = cmd.replace('INFILE', inname) |
|
48 | cmd = cmd.replace('INFILE', inname) | |
49 | cmd = cmd.replace('OUTFILE', outname) |
|
49 | cmd = cmd.replace('OUTFILE', outname) | |
50 | code = os.system(cmd) |
|
50 | code = os.system(cmd) | |
51 | if code: raise Abort(_("command '%s' failed: %s") % |
|
51 | if code: raise Abort(_("command '%s' failed: %s") % | |
52 | (cmd, explain_exit(code))) |
|
52 | (cmd, explain_exit(code))) | |
53 | return open(outname, 'rb').read() |
|
53 | return open(outname, 'rb').read() | |
54 | finally: |
|
54 | finally: | |
55 | try: |
|
55 | try: | |
56 | if inname: os.unlink(inname) |
|
56 | if inname: os.unlink(inname) | |
57 | except: pass |
|
57 | except: pass | |
58 | try: |
|
58 | try: | |
59 | if outname: os.unlink(outname) |
|
59 | if outname: os.unlink(outname) | |
60 | except: pass |
|
60 | except: pass | |
61 |
|
61 | |||
62 | filtertable = { |
|
62 | filtertable = { | |
63 | 'tempfile:': tempfilter, |
|
63 | 'tempfile:': tempfilter, | |
64 | 'pipe:': pipefilter, |
|
64 | 'pipe:': pipefilter, | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | def filter(s, cmd): |
|
67 | def filter(s, cmd): | |
68 | "filter a string through a command that transforms its input to its output" |
|
68 | "filter a string through a command that transforms its input to its output" | |
69 | for name, fn in filtertable.iteritems(): |
|
69 | for name, fn in filtertable.iteritems(): | |
70 | if cmd.startswith(name): |
|
70 | if cmd.startswith(name): | |
71 | return fn(s, cmd[len(name):].lstrip()) |
|
71 | return fn(s, cmd[len(name):].lstrip()) | |
72 | return pipefilter(s, cmd) |
|
72 | return pipefilter(s, cmd) | |
73 |
|
73 | |||
74 | def patch(strip, patchname, ui): |
|
74 | def patch(strip, patchname, ui): | |
75 | """apply the patch <patchname> to the working directory. |
|
75 | """apply the patch <patchname> to the working directory. | |
76 | a list of patched files is returned""" |
|
76 | a list of patched files is returned""" | |
77 | fp = os.popen('patch -p%d < "%s"' % (strip, patchname)) |
|
77 | fp = os.popen('patch -p%d < "%s"' % (strip, patchname)) | |
78 | files = {} |
|
78 | files = {} | |
79 | for line in fp: |
|
79 | for line in fp: | |
80 | line = line.rstrip() |
|
80 | line = line.rstrip() | |
81 | ui.status("%s\n" % line) |
|
81 | ui.status("%s\n" % line) | |
82 | if line.startswith('patching file '): |
|
82 | if line.startswith('patching file '): | |
83 | pf = parse_patch_output(line) |
|
83 | pf = parse_patch_output(line) | |
84 | files.setdefault(pf, 1) |
|
84 | files.setdefault(pf, 1) | |
85 | code = fp.close() |
|
85 | code = fp.close() | |
86 | if code: |
|
86 | if code: | |
87 | raise Abort(_("patch command failed: %s") % explain_exit(code)[0]) |
|
87 | raise Abort(_("patch command failed: %s") % explain_exit(code)[0]) | |
88 | return files.keys() |
|
88 | return files.keys() | |
89 |
|
89 | |||
90 | def binary(s): |
|
90 | def binary(s): | |
91 | """return true if a string is binary data using diff's heuristic""" |
|
91 | """return true if a string is binary data using diff's heuristic""" | |
92 | if s and '\0' in s[:4096]: |
|
92 | if s and '\0' in s[:4096]: | |
93 | return True |
|
93 | return True | |
94 | return False |
|
94 | return False | |
95 |
|
95 | |||
96 | def unique(g): |
|
96 | def unique(g): | |
97 | """return the uniq elements of iterable g""" |
|
97 | """return the uniq elements of iterable g""" | |
98 | seen = {} |
|
98 | seen = {} | |
99 | for f in g: |
|
99 | for f in g: | |
100 | if f not in seen: |
|
100 | if f not in seen: | |
101 | seen[f] = 1 |
|
101 | seen[f] = 1 | |
102 | yield f |
|
102 | yield f | |
103 |
|
103 | |||
104 | class Abort(Exception): |
|
104 | class Abort(Exception): | |
105 | """Raised if a command needs to print an error and exit.""" |
|
105 | """Raised if a command needs to print an error and exit.""" | |
106 |
|
106 | |||
107 | def always(fn): return True |
|
107 | def always(fn): return True | |
108 | def never(fn): return False |
|
108 | def never(fn): return False | |
109 |
|
109 | |||
110 | def patkind(name, dflt_pat='glob'): |
|
110 | def patkind(name, dflt_pat='glob'): | |
111 | """Split a string into an optional pattern kind prefix and the |
|
111 | """Split a string into an optional pattern kind prefix and the | |
112 | actual pattern.""" |
|
112 | actual pattern.""" | |
113 | for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': |
|
113 | for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': | |
114 | if name.startswith(prefix + ':'): return name.split(':', 1) |
|
114 | if name.startswith(prefix + ':'): return name.split(':', 1) | |
115 | return dflt_pat, name |
|
115 | return dflt_pat, name | |
116 |
|
116 | |||
117 | def globre(pat, head='^', tail='$'): |
|
117 | def globre(pat, head='^', tail='$'): | |
118 | "convert a glob pattern into a regexp" |
|
118 | "convert a glob pattern into a regexp" | |
119 | i, n = 0, len(pat) |
|
119 | i, n = 0, len(pat) | |
120 | res = '' |
|
120 | res = '' | |
121 | group = False |
|
121 | group = False | |
122 | def peek(): return i < n and pat[i] |
|
122 | def peek(): return i < n and pat[i] | |
123 | while i < n: |
|
123 | while i < n: | |
124 | c = pat[i] |
|
124 | c = pat[i] | |
125 | i = i+1 |
|
125 | i = i+1 | |
126 | if c == '*': |
|
126 | if c == '*': | |
127 | if peek() == '*': |
|
127 | if peek() == '*': | |
128 | i += 1 |
|
128 | i += 1 | |
129 | res += '.*' |
|
129 | res += '.*' | |
130 | else: |
|
130 | else: | |
131 | res += '[^/]*' |
|
131 | res += '[^/]*' | |
132 | elif c == '?': |
|
132 | elif c == '?': | |
133 | res += '.' |
|
133 | res += '.' | |
134 | elif c == '[': |
|
134 | elif c == '[': | |
135 | j = i |
|
135 | j = i | |
136 | if j < n and pat[j] in '!]': |
|
136 | if j < n and pat[j] in '!]': | |
137 | j += 1 |
|
137 | j += 1 | |
138 | while j < n and pat[j] != ']': |
|
138 | while j < n and pat[j] != ']': | |
139 | j += 1 |
|
139 | j += 1 | |
140 | if j >= n: |
|
140 | if j >= n: | |
141 | res += '\\[' |
|
141 | res += '\\[' | |
142 | else: |
|
142 | else: | |
143 | stuff = pat[i:j].replace('\\','\\\\') |
|
143 | stuff = pat[i:j].replace('\\','\\\\') | |
144 | i = j + 1 |
|
144 | i = j + 1 | |
145 | if stuff[0] == '!': |
|
145 | if stuff[0] == '!': | |
146 | stuff = '^' + stuff[1:] |
|
146 | stuff = '^' + stuff[1:] | |
147 | elif stuff[0] == '^': |
|
147 | elif stuff[0] == '^': | |
148 | stuff = '\\' + stuff |
|
148 | stuff = '\\' + stuff | |
149 | res = '%s[%s]' % (res, stuff) |
|
149 | res = '%s[%s]' % (res, stuff) | |
150 | elif c == '{': |
|
150 | elif c == '{': | |
151 | group = True |
|
151 | group = True | |
152 | res += '(?:' |
|
152 | res += '(?:' | |
153 | elif c == '}' and group: |
|
153 | elif c == '}' and group: | |
154 | res += ')' |
|
154 | res += ')' | |
155 | group = False |
|
155 | group = False | |
156 | elif c == ',' and group: |
|
156 | elif c == ',' and group: | |
157 | res += '|' |
|
157 | res += '|' | |
158 | elif c == '\\': |
|
158 | elif c == '\\': | |
159 | p = peek() |
|
159 | p = peek() | |
160 | if p: |
|
160 | if p: | |
161 | i += 1 |
|
161 | i += 1 | |
162 | res += re.escape(p) |
|
162 | res += re.escape(p) | |
163 | else: |
|
163 | else: | |
164 | res += re.escape(c) |
|
164 | res += re.escape(c) | |
165 | else: |
|
165 | else: | |
166 | res += re.escape(c) |
|
166 | res += re.escape(c) | |
167 | return head + res + tail |
|
167 | return head + res + tail | |
168 |
|
168 | |||
169 | _globchars = {'[': 1, '{': 1, '*': 1, '?': 1} |
|
169 | _globchars = {'[': 1, '{': 1, '*': 1, '?': 1} | |
170 |
|
170 | |||
171 | def pathto(n1, n2): |
|
171 | def pathto(n1, n2): | |
172 | '''return the relative path from one place to another. |
|
172 | '''return the relative path from one place to another. | |
173 | this returns a path in the form used by the local filesystem, not hg.''' |
|
173 | this returns a path in the form used by the local filesystem, not hg.''' | |
174 | if not n1: return localpath(n2) |
|
174 | if not n1: return localpath(n2) | |
175 | a, b = n1.split('/'), n2.split('/') |
|
175 | a, b = n1.split('/'), n2.split('/') | |
176 | a.reverse() |
|
176 | a.reverse() | |
177 | b.reverse() |
|
177 | b.reverse() | |
178 | while a and b and a[-1] == b[-1]: |
|
178 | while a and b and a[-1] == b[-1]: | |
179 | a.pop() |
|
179 | a.pop() | |
180 | b.pop() |
|
180 | b.pop() | |
181 | b.reverse() |
|
181 | b.reverse() | |
182 | return os.sep.join((['..'] * len(a)) + b) |
|
182 | return os.sep.join((['..'] * len(a)) + b) | |
183 |
|
183 | |||
184 | def canonpath(root, cwd, myname): |
|
184 | def canonpath(root, cwd, myname): | |
185 | """return the canonical path of myname, given cwd and root""" |
|
185 | """return the canonical path of myname, given cwd and root""" | |
186 | if root == os.sep: |
|
186 | if root == os.sep: | |
187 | rootsep = os.sep |
|
187 | rootsep = os.sep | |
188 | else: |
|
188 | else: | |
189 | rootsep = root + os.sep |
|
189 | rootsep = root + os.sep | |
190 | name = myname |
|
190 | name = myname | |
191 | if not name.startswith(os.sep): |
|
191 | if not name.startswith(os.sep): | |
192 | name = os.path.join(root, cwd, name) |
|
192 | name = os.path.join(root, cwd, name) | |
193 | name = os.path.normpath(name) |
|
193 | name = os.path.normpath(name) | |
194 | if name.startswith(rootsep): |
|
194 | if name.startswith(rootsep): | |
195 | name = name[len(rootsep):] |
|
195 | name = name[len(rootsep):] | |
196 | audit_path(name) |
|
196 | audit_path(name) | |
197 | return pconvert(name) |
|
197 | return pconvert(name) | |
198 | elif name == root: |
|
198 | elif name == root: | |
199 | return '' |
|
199 | return '' | |
200 | else: |
|
200 | else: | |
201 | raise Abort('%s not under root' % myname) |
|
201 | raise Abort('%s not under root' % myname) | |
202 |
|
202 | |||
203 | def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): |
|
203 | def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): | |
204 | return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src) |
|
204 | return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src) | |
205 |
|
205 | |||
206 | def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): |
|
206 | def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): | |
207 | if os.name == 'nt': |
|
207 | if os.name == 'nt': | |
208 | dflt_pat = 'glob' |
|
208 | dflt_pat = 'glob' | |
209 | else: |
|
209 | else: | |
210 | dflt_pat = 'relpath' |
|
210 | dflt_pat = 'relpath' | |
211 | return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src) |
|
211 | return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src) | |
212 |
|
212 | |||
213 | def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src): |
|
213 | def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src): | |
214 | """build a function to match a set of file patterns |
|
214 | """build a function to match a set of file patterns | |
215 |
|
215 | |||
216 | arguments: |
|
216 | arguments: | |
217 | canonroot - the canonical root of the tree you're matching against |
|
217 | canonroot - the canonical root of the tree you're matching against | |
218 | cwd - the current working directory, if relevant |
|
218 | cwd - the current working directory, if relevant | |
219 | names - patterns to find |
|
219 | names - patterns to find | |
220 | inc - patterns to include |
|
220 | inc - patterns to include | |
221 | exc - patterns to exclude |
|
221 | exc - patterns to exclude | |
222 | head - a regex to prepend to patterns to control whether a match is rooted |
|
222 | head - a regex to prepend to patterns to control whether a match is rooted | |
223 |
|
223 | |||
224 | a pattern is one of: |
|
224 | a pattern is one of: | |
225 | 'glob:<rooted glob>' |
|
225 | 'glob:<rooted glob>' | |
226 | 're:<rooted regexp>' |
|
226 | 're:<rooted regexp>' | |
227 | 'path:<rooted path>' |
|
227 | 'path:<rooted path>' | |
228 | 'relglob:<relative glob>' |
|
228 | 'relglob:<relative glob>' | |
229 | 'relpath:<relative path>' |
|
229 | 'relpath:<relative path>' | |
230 | 'relre:<relative regexp>' |
|
230 | 'relre:<relative regexp>' | |
231 | '<rooted path or regexp>' |
|
231 | '<rooted path or regexp>' | |
232 |
|
232 | |||
233 | returns: |
|
233 | returns: | |
234 | a 3-tuple containing |
|
234 | a 3-tuple containing | |
235 | - list of explicit non-pattern names passed in |
|
235 | - list of explicit non-pattern names passed in | |
236 | - a bool match(filename) function |
|
236 | - a bool match(filename) function | |
237 | - a bool indicating if any patterns were passed in |
|
237 | - a bool indicating if any patterns were passed in | |
238 |
|
238 | |||
239 | todo: |
|
239 | todo: | |
240 | make head regex a rooted bool |
|
240 | make head regex a rooted bool | |
241 | """ |
|
241 | """ | |
242 |
|
242 | |||
243 | def contains_glob(name): |
|
243 | def contains_glob(name): | |
244 | for c in name: |
|
244 | for c in name: | |
245 | if c in _globchars: return True |
|
245 | if c in _globchars: return True | |
246 | return False |
|
246 | return False | |
247 |
|
247 | |||
248 | def regex(kind, name, tail): |
|
248 | def regex(kind, name, tail): | |
249 | '''convert a pattern into a regular expression''' |
|
249 | '''convert a pattern into a regular expression''' | |
250 | if kind == 're': |
|
250 | if kind == 're': | |
251 | return name |
|
251 | return name | |
252 | elif kind == 'path': |
|
252 | elif kind == 'path': | |
253 | return '^' + re.escape(name) + '(?:/|$)' |
|
253 | return '^' + re.escape(name) + '(?:/|$)' | |
254 | elif kind == 'relglob': |
|
254 | elif kind == 'relglob': | |
255 | return head + globre(name, '(?:|.*/)', tail) |
|
255 | return head + globre(name, '(?:|.*/)', tail) | |
256 | elif kind == 'relpath': |
|
256 | elif kind == 'relpath': | |
257 | return head + re.escape(name) + tail |
|
257 | return head + re.escape(name) + tail | |
258 | elif kind == 'relre': |
|
258 | elif kind == 'relre': | |
259 | if name.startswith('^'): |
|
259 | if name.startswith('^'): | |
260 | return name |
|
260 | return name | |
261 | return '.*' + name |
|
261 | return '.*' + name | |
262 | return head + globre(name, '', tail) |
|
262 | return head + globre(name, '', tail) | |
263 |
|
263 | |||
264 | def matchfn(pats, tail): |
|
264 | def matchfn(pats, tail): | |
265 | """build a matching function from a set of patterns""" |
|
265 | """build a matching function from a set of patterns""" | |
266 | if not pats: |
|
266 | if not pats: | |
267 | return |
|
267 | return | |
268 | matches = [] |
|
268 | matches = [] | |
269 | for k, p in pats: |
|
269 | for k, p in pats: | |
270 | try: |
|
270 | try: | |
271 | pat = '(?:%s)' % regex(k, p, tail) |
|
271 | pat = '(?:%s)' % regex(k, p, tail) | |
272 | matches.append(re.compile(pat).match) |
|
272 | matches.append(re.compile(pat).match) | |
273 | except re.error: |
|
273 | except re.error: | |
274 | if src: raise Abort("%s: invalid pattern (%s): %s" % (src, k, p)) |
|
274 | if src: raise Abort("%s: invalid pattern (%s): %s" % (src, k, p)) | |
275 | else: raise Abort("invalid pattern (%s): %s" % (k, p)) |
|
275 | else: raise Abort("invalid pattern (%s): %s" % (k, p)) | |
276 |
|
276 | |||
277 | def buildfn(text): |
|
277 | def buildfn(text): | |
278 | for m in matches: |
|
278 | for m in matches: | |
279 | r = m(text) |
|
279 | r = m(text) | |
280 | if r: |
|
280 | if r: | |
281 | return r |
|
281 | return r | |
282 |
|
282 | |||
283 | return buildfn |
|
283 | return buildfn | |
284 |
|
284 | |||
285 | def globprefix(pat): |
|
285 | def globprefix(pat): | |
286 | '''return the non-glob prefix of a path, e.g. foo/* -> foo''' |
|
286 | '''return the non-glob prefix of a path, e.g. foo/* -> foo''' | |
287 | root = [] |
|
287 | root = [] | |
288 | for p in pat.split(os.sep): |
|
288 | for p in pat.split(os.sep): | |
289 | if contains_glob(p): break |
|
289 | if contains_glob(p): break | |
290 | root.append(p) |
|
290 | root.append(p) | |
291 | return '/'.join(root) |
|
291 | return '/'.join(root) | |
292 |
|
292 | |||
293 | pats = [] |
|
293 | pats = [] | |
294 | files = [] |
|
294 | files = [] | |
295 | roots = [] |
|
295 | roots = [] | |
296 | for kind, name in [patkind(p, dflt_pat) for p in names]: |
|
296 | for kind, name in [patkind(p, dflt_pat) for p in names]: | |
297 | if kind in ('glob', 'relpath'): |
|
297 | if kind in ('glob', 'relpath'): | |
298 | name = canonpath(canonroot, cwd, name) |
|
298 | name = canonpath(canonroot, cwd, name) | |
299 | if name == '': |
|
299 | if name == '': | |
300 | kind, name = 'glob', '**' |
|
300 | kind, name = 'glob', '**' | |
301 | if kind in ('glob', 'path', 're'): |
|
301 | if kind in ('glob', 'path', 're'): | |
302 | pats.append((kind, name)) |
|
302 | pats.append((kind, name)) | |
303 | if kind == 'glob': |
|
303 | if kind == 'glob': | |
304 | root = globprefix(name) |
|
304 | root = globprefix(name) | |
305 | if root: roots.append(root) |
|
305 | if root: roots.append(root) | |
306 | elif kind == 'relpath': |
|
306 | elif kind == 'relpath': | |
307 | files.append((kind, name)) |
|
307 | files.append((kind, name)) | |
308 | roots.append(name) |
|
308 | roots.append(name) | |
309 |
|
309 | |||
310 | patmatch = matchfn(pats, '$') or always |
|
310 | patmatch = matchfn(pats, '$') or always | |
311 | filematch = matchfn(files, '(?:/|$)') or always |
|
311 | filematch = matchfn(files, '(?:/|$)') or always | |
312 | incmatch = always |
|
312 | incmatch = always | |
313 | if inc: |
|
313 | if inc: | |
314 | incmatch = matchfn(map(patkind, inc), '(?:/|$)') |
|
314 | incmatch = matchfn(map(patkind, inc), '(?:/|$)') | |
315 | excmatch = lambda fn: False |
|
315 | excmatch = lambda fn: False | |
316 | if exc: |
|
316 | if exc: | |
317 | excmatch = matchfn(map(patkind, exc), '(?:/|$)') |
|
317 | excmatch = matchfn(map(patkind, exc), '(?:/|$)') | |
318 |
|
318 | |||
319 | return (roots, |
|
319 | return (roots, | |
320 | lambda fn: (incmatch(fn) and not excmatch(fn) and |
|
320 | lambda fn: (incmatch(fn) and not excmatch(fn) and | |
321 | (fn.endswith('/') or |
|
321 | (fn.endswith('/') or | |
322 | (not pats and not files) or |
|
322 | (not pats and not files) or | |
323 | (pats and patmatch(fn)) or |
|
323 | (pats and patmatch(fn)) or | |
324 | (files and filematch(fn)))), |
|
324 | (files and filematch(fn)))), | |
325 | (inc or exc or (pats and pats != [('glob', '**')])) and True) |
|
325 | (inc or exc or (pats and pats != [('glob', '**')])) and True) | |
326 |
|
326 | |||
327 | def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): |
|
327 | def system(cmd, environ={}, cwd=None, onerr=None, errprefix=None): | |
328 | '''enhanced shell command execution. |
|
328 | '''enhanced shell command execution. | |
329 | run with environment maybe modified, maybe in different dir. |
|
329 | run with environment maybe modified, maybe in different dir. | |
330 |
|
330 | |||
331 | if command fails and onerr is None, return status. if ui object, |
|
331 | if command fails and onerr is None, return status. if ui object, | |
332 | print error message and return status, else raise onerr object as |
|
332 | print error message and return status, else raise onerr object as | |
333 | exception.''' |
|
333 | exception.''' | |
334 | oldenv = {} |
|
334 | oldenv = {} | |
335 | for k in environ: |
|
335 | for k in environ: | |
336 | oldenv[k] = os.environ.get(k) |
|
336 | oldenv[k] = os.environ.get(k) | |
337 | if cwd is not None: |
|
337 | if cwd is not None: | |
338 | oldcwd = os.getcwd() |
|
338 | oldcwd = os.getcwd() | |
339 | try: |
|
339 | try: | |
340 | for k, v in environ.iteritems(): |
|
340 | for k, v in environ.iteritems(): | |
341 | os.environ[k] = str(v) |
|
341 | os.environ[k] = str(v) | |
342 | if cwd is not None and oldcwd != cwd: |
|
342 | if cwd is not None and oldcwd != cwd: | |
343 | os.chdir(cwd) |
|
343 | os.chdir(cwd) | |
344 | rc = os.system(cmd) |
|
344 | rc = os.system(cmd) | |
345 | if rc and onerr: |
|
345 | if rc and onerr: | |
346 | errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), |
|
346 | errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]), | |
347 | explain_exit(rc)[0]) |
|
347 | explain_exit(rc)[0]) | |
348 | if errprefix: |
|
348 | if errprefix: | |
349 | errmsg = '%s: %s' % (errprefix, errmsg) |
|
349 | errmsg = '%s: %s' % (errprefix, errmsg) | |
350 | try: |
|
350 | try: | |
351 | onerr.warn(errmsg + '\n') |
|
351 | onerr.warn(errmsg + '\n') | |
352 | except AttributeError: |
|
352 | except AttributeError: | |
353 | raise onerr(errmsg) |
|
353 | raise onerr(errmsg) | |
354 | return rc |
|
354 | return rc | |
355 | finally: |
|
355 | finally: | |
356 | for k, v in oldenv.iteritems(): |
|
356 | for k, v in oldenv.iteritems(): | |
357 | if v is None: |
|
357 | if v is None: | |
358 | del os.environ[k] |
|
358 | del os.environ[k] | |
359 | else: |
|
359 | else: | |
360 | os.environ[k] = v |
|
360 | os.environ[k] = v | |
361 | if cwd is not None and oldcwd != cwd: |
|
361 | if cwd is not None and oldcwd != cwd: | |
362 | os.chdir(oldcwd) |
|
362 | os.chdir(oldcwd) | |
363 |
|
363 | |||
364 | def rename(src, dst): |
|
364 | def rename(src, dst): | |
365 | """forcibly rename a file""" |
|
365 | """forcibly rename a file""" | |
366 | try: |
|
366 | try: | |
367 | os.rename(src, dst) |
|
367 | os.rename(src, dst) | |
368 | except: |
|
368 | except: | |
369 | os.unlink(dst) |
|
369 | os.unlink(dst) | |
370 | os.rename(src, dst) |
|
370 | os.rename(src, dst) | |
371 |
|
371 | |||
372 | def unlink(f): |
|
372 | def unlink(f): | |
373 | """unlink and remove the directory if it is empty""" |
|
373 | """unlink and remove the directory if it is empty""" | |
374 | os.unlink(f) |
|
374 | os.unlink(f) | |
375 | # try removing directories that might now be empty |
|
375 | # try removing directories that might now be empty | |
376 | try: os.removedirs(os.path.dirname(f)) |
|
376 | try: os.removedirs(os.path.dirname(f)) | |
377 | except: pass |
|
377 | except: pass | |
378 |
|
378 | |||
379 | def copyfiles(src, dst, hardlink=None): |
|
379 | def copyfiles(src, dst, hardlink=None): | |
380 | """Copy a directory tree using hardlinks if possible""" |
|
380 | """Copy a directory tree using hardlinks if possible""" | |
381 |
|
381 | |||
382 | if hardlink is None: |
|
382 | if hardlink is None: | |
383 | hardlink = (os.stat(src).st_dev == |
|
383 | hardlink = (os.stat(src).st_dev == | |
384 | os.stat(os.path.dirname(dst)).st_dev) |
|
384 | os.stat(os.path.dirname(dst)).st_dev) | |
385 |
|
385 | |||
386 | if os.path.isdir(src): |
|
386 | if os.path.isdir(src): | |
387 | os.mkdir(dst) |
|
387 | os.mkdir(dst) | |
388 | for name in os.listdir(src): |
|
388 | for name in os.listdir(src): | |
389 | srcname = os.path.join(src, name) |
|
389 | srcname = os.path.join(src, name) | |
390 | dstname = os.path.join(dst, name) |
|
390 | dstname = os.path.join(dst, name) | |
391 | copyfiles(srcname, dstname, hardlink) |
|
391 | copyfiles(srcname, dstname, hardlink) | |
392 | else: |
|
392 | else: | |
393 | if hardlink: |
|
393 | if hardlink: | |
394 | try: |
|
394 | try: | |
395 | os_link(src, dst) |
|
395 | os_link(src, dst) | |
396 | except: |
|
396 | except (IOError, OSError): | |
397 | hardlink = False |
|
397 | hardlink = False | |
398 | shutil.copy(src, dst) |
|
398 | shutil.copy(src, dst) | |
399 | else: |
|
399 | else: | |
400 | shutil.copy(src, dst) |
|
400 | shutil.copy(src, dst) | |
401 |
|
401 | |||
402 | def audit_path(path): |
|
402 | def audit_path(path): | |
403 | """Abort if path contains dangerous components""" |
|
403 | """Abort if path contains dangerous components""" | |
404 | parts = os.path.normcase(path).split(os.sep) |
|
404 | parts = os.path.normcase(path).split(os.sep) | |
405 | if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '') |
|
405 | if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '') | |
406 | or os.pardir in parts): |
|
406 | or os.pardir in parts): | |
407 | raise Abort(_("path contains illegal component: %s\n") % path) |
|
407 | raise Abort(_("path contains illegal component: %s\n") % path) | |
408 |
|
408 | |||
409 | def opener(base, audit=True): |
|
409 | def opener(base, audit=True): | |
410 | """ |
|
410 | """ | |
411 | return a function that opens files relative to base |
|
411 | return a function that opens files relative to base | |
412 |
|
412 | |||
413 | this function is used to hide the details of COW semantics and |
|
413 | this function is used to hide the details of COW semantics and | |
414 | remote file access from higher level code. |
|
414 | remote file access from higher level code. | |
415 | """ |
|
415 | """ | |
416 | p = base |
|
416 | p = base | |
417 | audit_p = audit |
|
417 | audit_p = audit | |
418 |
|
418 | |||
419 | def mktempcopy(name): |
|
419 | def mktempcopy(name): | |
420 | d, fn = os.path.split(name) |
|
420 | d, fn = os.path.split(name) | |
421 | fd, temp = tempfile.mkstemp(prefix=fn, dir=d) |
|
421 | fd, temp = tempfile.mkstemp(prefix=fn, dir=d) | |
422 | fp = os.fdopen(fd, "wb") |
|
422 | fp = os.fdopen(fd, "wb") | |
423 | try: |
|
423 | try: | |
424 | fp.write(file(name, "rb").read()) |
|
424 | fp.write(file(name, "rb").read()) | |
425 | except: |
|
425 | except: | |
426 | try: os.unlink(temp) |
|
426 | try: os.unlink(temp) | |
427 | except: pass |
|
427 | except: pass | |
428 | raise |
|
428 | raise | |
429 | fp.close() |
|
429 | fp.close() | |
430 | st = os.lstat(name) |
|
430 | st = os.lstat(name) | |
431 | os.chmod(temp, st.st_mode) |
|
431 | os.chmod(temp, st.st_mode) | |
432 | return temp |
|
432 | return temp | |
433 |
|
433 | |||
434 | class atomictempfile(file): |
|
434 | class atomictempfile(file): | |
435 | """the file will only be copied when rename is called""" |
|
435 | """the file will only be copied when rename is called""" | |
436 | def __init__(self, name, mode): |
|
436 | def __init__(self, name, mode): | |
437 | self.__name = name |
|
437 | self.__name = name | |
438 | self.temp = mktempcopy(name) |
|
438 | self.temp = mktempcopy(name) | |
439 | file.__init__(self, self.temp, mode) |
|
439 | file.__init__(self, self.temp, mode) | |
440 | def rename(self): |
|
440 | def rename(self): | |
441 | if not self.closed: |
|
441 | if not self.closed: | |
442 | file.close(self) |
|
442 | file.close(self) | |
443 | rename(self.temp, self.__name) |
|
443 | rename(self.temp, self.__name) | |
444 | def __del__(self): |
|
444 | def __del__(self): | |
445 | if not self.closed: |
|
445 | if not self.closed: | |
446 | try: |
|
446 | try: | |
447 | os.unlink(self.temp) |
|
447 | os.unlink(self.temp) | |
448 | except: pass |
|
448 | except: pass | |
449 | file.close(self) |
|
449 | file.close(self) | |
450 |
|
450 | |||
451 | class atomicfile(atomictempfile): |
|
451 | class atomicfile(atomictempfile): | |
452 | """the file will only be copied on close""" |
|
452 | """the file will only be copied on close""" | |
453 | def __init__(self, name, mode): |
|
453 | def __init__(self, name, mode): | |
454 | atomictempfile.__init__(self, name, mode) |
|
454 | atomictempfile.__init__(self, name, mode) | |
455 | def close(self): |
|
455 | def close(self): | |
456 | self.rename() |
|
456 | self.rename() | |
457 | def __del__(self): |
|
457 | def __del__(self): | |
458 | self.rename() |
|
458 | self.rename() | |
459 |
|
459 | |||
460 | def o(path, mode="r", text=False, atomic=False, atomictemp=False): |
|
460 | def o(path, mode="r", text=False, atomic=False, atomictemp=False): | |
461 | if audit_p: |
|
461 | if audit_p: | |
462 | audit_path(path) |
|
462 | audit_path(path) | |
463 | f = os.path.join(p, path) |
|
463 | f = os.path.join(p, path) | |
464 |
|
464 | |||
465 | if not text: |
|
465 | if not text: | |
466 | mode += "b" # for that other OS |
|
466 | mode += "b" # for that other OS | |
467 |
|
467 | |||
468 | if mode[0] != "r": |
|
468 | if mode[0] != "r": | |
469 | try: |
|
469 | try: | |
470 | nlink = nlinks(f) |
|
470 | nlink = nlinks(f) | |
471 | except OSError: |
|
471 | except OSError: | |
472 | d = os.path.dirname(f) |
|
472 | d = os.path.dirname(f) | |
473 | if not os.path.isdir(d): |
|
473 | if not os.path.isdir(d): | |
474 | os.makedirs(d) |
|
474 | os.makedirs(d) | |
475 | else: |
|
475 | else: | |
476 | if atomic: |
|
476 | if atomic: | |
477 | return atomicfile(f, mode) |
|
477 | return atomicfile(f, mode) | |
478 | elif atomictemp: |
|
478 | elif atomictemp: | |
479 | return atomictempfile(f, mode) |
|
479 | return atomictempfile(f, mode) | |
480 | if nlink > 1: |
|
480 | if nlink > 1: | |
481 | rename(mktempcopy(f), f) |
|
481 | rename(mktempcopy(f), f) | |
482 | return file(f, mode) |
|
482 | return file(f, mode) | |
483 |
|
483 | |||
484 | return o |
|
484 | return o | |
485 |
|
485 | |||
486 | def _makelock_file(info, pathname): |
|
486 | def _makelock_file(info, pathname): | |
487 | ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) |
|
487 | ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) | |
488 | os.write(ld, info) |
|
488 | os.write(ld, info) | |
489 | os.close(ld) |
|
489 | os.close(ld) | |
490 |
|
490 | |||
491 | def _readlock_file(pathname): |
|
491 | def _readlock_file(pathname): | |
492 | return file(pathname).read() |
|
492 | return file(pathname).read() | |
493 |
|
493 | |||
494 | def nlinks(pathname): |
|
494 | def nlinks(pathname): | |
495 | """Return number of hardlinks for the given file.""" |
|
495 | """Return number of hardlinks for the given file.""" | |
496 | return os.stat(pathname).st_nlink |
|
496 | return os.stat(pathname).st_nlink | |
497 |
|
497 | |||
498 | if hasattr(os, 'link'): |
|
498 | if hasattr(os, 'link'): | |
499 | os_link = os.link |
|
499 | os_link = os.link | |
500 | else: |
|
500 | else: | |
501 | def os_link(src, dst): |
|
501 | def os_link(src, dst): | |
502 | raise OSError(0, _("Hardlinks not supported")) |
|
502 | raise OSError(0, _("Hardlinks not supported")) | |
503 |
|
503 | |||
504 | # Platform specific variants |
|
504 | # Platform specific variants | |
505 | if os.name == 'nt': |
|
505 | if os.name == 'nt': | |
506 | demandload(globals(), "msvcrt") |
|
506 | demandload(globals(), "msvcrt") | |
507 | nulldev = 'NUL:' |
|
507 | nulldev = 'NUL:' | |
508 |
|
508 | |||
509 | class winstdout: |
|
509 | class winstdout: | |
510 | '''stdout on windows misbehaves if sent through a pipe''' |
|
510 | '''stdout on windows misbehaves if sent through a pipe''' | |
511 |
|
511 | |||
512 | def __init__(self, fp): |
|
512 | def __init__(self, fp): | |
513 | self.fp = fp |
|
513 | self.fp = fp | |
514 |
|
514 | |||
515 | def __getattr__(self, key): |
|
515 | def __getattr__(self, key): | |
516 | return getattr(self.fp, key) |
|
516 | return getattr(self.fp, key) | |
517 |
|
517 | |||
518 | def close(self): |
|
518 | def close(self): | |
519 | try: |
|
519 | try: | |
520 | self.fp.close() |
|
520 | self.fp.close() | |
521 | except: pass |
|
521 | except: pass | |
522 |
|
522 | |||
523 | def write(self, s): |
|
523 | def write(self, s): | |
524 | try: |
|
524 | try: | |
525 | return self.fp.write(s) |
|
525 | return self.fp.write(s) | |
526 | except IOError, inst: |
|
526 | except IOError, inst: | |
527 | if inst.errno != 0: raise |
|
527 | if inst.errno != 0: raise | |
528 | self.close() |
|
528 | self.close() | |
529 | raise IOError(errno.EPIPE, 'Broken pipe') |
|
529 | raise IOError(errno.EPIPE, 'Broken pipe') | |
530 |
|
530 | |||
531 | sys.stdout = winstdout(sys.stdout) |
|
531 | sys.stdout = winstdout(sys.stdout) | |
532 |
|
532 | |||
533 | def os_rcpath(): |
|
533 | def os_rcpath(): | |
534 | '''return default os-specific hgrc search path''' |
|
534 | '''return default os-specific hgrc search path''' | |
535 | try: |
|
535 | try: | |
536 | import win32api, win32process |
|
536 | import win32api, win32process | |
537 | proc = win32api.GetCurrentProcess() |
|
537 | proc = win32api.GetCurrentProcess() | |
538 | filename = win32process.GetModuleFileNameEx(proc, 0) |
|
538 | filename = win32process.GetModuleFileNameEx(proc, 0) | |
539 | systemrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') |
|
539 | systemrc = os.path.join(os.path.dirname(filename), 'mercurial.ini') | |
540 | except ImportError: |
|
540 | except ImportError: | |
541 | systemrc = r'c:\mercurial\mercurial.ini' |
|
541 | systemrc = r'c:\mercurial\mercurial.ini' | |
542 |
|
542 | |||
543 | return [systemrc, |
|
543 | return [systemrc, | |
544 | os.path.join(os.path.expanduser('~'), 'mercurial.ini')] |
|
544 | os.path.join(os.path.expanduser('~'), 'mercurial.ini')] | |
545 |
|
545 | |||
546 | def parse_patch_output(output_line): |
|
546 | def parse_patch_output(output_line): | |
547 | """parses the output produced by patch and returns the file name""" |
|
547 | """parses the output produced by patch and returns the file name""" | |
548 | pf = output_line[14:] |
|
548 | pf = output_line[14:] | |
549 | if pf[0] == '`': |
|
549 | if pf[0] == '`': | |
550 | pf = pf[1:-1] # Remove the quotes |
|
550 | pf = pf[1:-1] # Remove the quotes | |
551 | return pf |
|
551 | return pf | |
552 |
|
552 | |||
553 | try: # Mark Hammond's win32all package allows better functionality on Windows |
|
553 | try: # Mark Hammond's win32all package allows better functionality on Windows | |
554 | import win32api, win32con, win32file, pywintypes |
|
554 | import win32api, win32con, win32file, pywintypes | |
555 |
|
555 | |||
556 | # create hard links using win32file module |
|
556 | # create hard links using win32file module | |
557 | def os_link(src, dst): # NB will only succeed on NTFS |
|
557 | def os_link(src, dst): # NB will only succeed on NTFS | |
558 | win32file.CreateHardLink(dst, src) |
|
558 | win32file.CreateHardLink(dst, src) | |
559 |
|
559 | |||
560 | def nlinks(pathname): |
|
560 | def nlinks(pathname): | |
561 | """Return number of hardlinks for the given file.""" |
|
561 | """Return number of hardlinks for the given file.""" | |
562 | try: |
|
562 | try: | |
563 | fh = win32file.CreateFile(pathname, |
|
563 | fh = win32file.CreateFile(pathname, | |
564 | win32file.GENERIC_READ, win32file.FILE_SHARE_READ, |
|
564 | win32file.GENERIC_READ, win32file.FILE_SHARE_READ, | |
565 | None, win32file.OPEN_EXISTING, 0, None) |
|
565 | None, win32file.OPEN_EXISTING, 0, None) | |
566 | res = win32file.GetFileInformationByHandle(fh) |
|
566 | res = win32file.GetFileInformationByHandle(fh) | |
567 | fh.Close() |
|
567 | fh.Close() | |
568 | return res[7] |
|
568 | return res[7] | |
569 | except: |
|
569 | except: | |
570 | return os.stat(pathname).st_nlink |
|
570 | return os.stat(pathname).st_nlink | |
571 |
|
571 | |||
572 | def testpid(pid): |
|
572 | def testpid(pid): | |
573 | '''return True if pid is still running or unable to |
|
573 | '''return True if pid is still running or unable to | |
574 | determine, False otherwise''' |
|
574 | determine, False otherwise''' | |
575 | try: |
|
575 | try: | |
576 | import win32process, winerror |
|
576 | import win32process, winerror | |
577 | handle = win32api.OpenProcess( |
|
577 | handle = win32api.OpenProcess( | |
578 | win32con.PROCESS_QUERY_INFORMATION, False, pid) |
|
578 | win32con.PROCESS_QUERY_INFORMATION, False, pid) | |
579 | if handle: |
|
579 | if handle: | |
580 | status = win32process.GetExitCodeProcess(handle) |
|
580 | status = win32process.GetExitCodeProcess(handle) | |
581 | return status == win32con.STILL_ACTIVE |
|
581 | return status == win32con.STILL_ACTIVE | |
582 | except pywintypes.error, details: |
|
582 | except pywintypes.error, details: | |
583 | return details[0] != winerror.ERROR_INVALID_PARAMETER |
|
583 | return details[0] != winerror.ERROR_INVALID_PARAMETER | |
584 | return True |
|
584 | return True | |
585 |
|
585 | |||
586 | except ImportError: |
|
586 | except ImportError: | |
587 | def testpid(pid): |
|
587 | def testpid(pid): | |
588 | '''return False if pid dead, True if running or not known''' |
|
588 | '''return False if pid dead, True if running or not known''' | |
589 | return True |
|
589 | return True | |
590 |
|
590 | |||
591 | def is_exec(f, last): |
|
591 | def is_exec(f, last): | |
592 | return last |
|
592 | return last | |
593 |
|
593 | |||
594 | def set_exec(f, mode): |
|
594 | def set_exec(f, mode): | |
595 | pass |
|
595 | pass | |
596 |
|
596 | |||
597 | def set_binary(fd): |
|
597 | def set_binary(fd): | |
598 | msvcrt.setmode(fd.fileno(), os.O_BINARY) |
|
598 | msvcrt.setmode(fd.fileno(), os.O_BINARY) | |
599 |
|
599 | |||
600 | def pconvert(path): |
|
600 | def pconvert(path): | |
601 | return path.replace("\\", "/") |
|
601 | return path.replace("\\", "/") | |
602 |
|
602 | |||
603 | def localpath(path): |
|
603 | def localpath(path): | |
604 | return path.replace('/', '\\') |
|
604 | return path.replace('/', '\\') | |
605 |
|
605 | |||
606 | def normpath(path): |
|
606 | def normpath(path): | |
607 | return pconvert(os.path.normpath(path)) |
|
607 | return pconvert(os.path.normpath(path)) | |
608 |
|
608 | |||
609 | makelock = _makelock_file |
|
609 | makelock = _makelock_file | |
610 | readlock = _readlock_file |
|
610 | readlock = _readlock_file | |
611 |
|
611 | |||
612 | def explain_exit(code): |
|
612 | def explain_exit(code): | |
613 | return _("exited with status %d") % code, code |
|
613 | return _("exited with status %d") % code, code | |
614 |
|
614 | |||
615 | else: |
|
615 | else: | |
616 | nulldev = '/dev/null' |
|
616 | nulldev = '/dev/null' | |
617 |
|
617 | |||
618 | def rcfiles(path): |
|
618 | def rcfiles(path): | |
619 | rcs = [os.path.join(path, 'hgrc')] |
|
619 | rcs = [os.path.join(path, 'hgrc')] | |
620 | rcdir = os.path.join(path, 'hgrc.d') |
|
620 | rcdir = os.path.join(path, 'hgrc.d') | |
621 | try: |
|
621 | try: | |
622 | rcs.extend([os.path.join(rcdir, f) for f in os.listdir(rcdir) |
|
622 | rcs.extend([os.path.join(rcdir, f) for f in os.listdir(rcdir) | |
623 | if f.endswith(".rc")]) |
|
623 | if f.endswith(".rc")]) | |
624 | except OSError, inst: pass |
|
624 | except OSError, inst: pass | |
625 | return rcs |
|
625 | return rcs | |
626 |
|
626 | |||
627 | def os_rcpath(): |
|
627 | def os_rcpath(): | |
628 | '''return default os-specific hgrc search path''' |
|
628 | '''return default os-specific hgrc search path''' | |
629 | path = [] |
|
629 | path = [] | |
630 | if len(sys.argv) > 0: |
|
630 | if len(sys.argv) > 0: | |
631 | path.extend(rcfiles(os.path.dirname(sys.argv[0]) + |
|
631 | path.extend(rcfiles(os.path.dirname(sys.argv[0]) + | |
632 | '/../etc/mercurial')) |
|
632 | '/../etc/mercurial')) | |
633 | path.extend(rcfiles('/etc/mercurial')) |
|
633 | path.extend(rcfiles('/etc/mercurial')) | |
634 | path.append(os.path.expanduser('~/.hgrc')) |
|
634 | path.append(os.path.expanduser('~/.hgrc')) | |
635 | path = [os.path.normpath(f) for f in path] |
|
635 | path = [os.path.normpath(f) for f in path] | |
636 | return path |
|
636 | return path | |
637 |
|
637 | |||
638 | def parse_patch_output(output_line): |
|
638 | def parse_patch_output(output_line): | |
639 | """parses the output produced by patch and returns the file name""" |
|
639 | """parses the output produced by patch and returns the file name""" | |
640 | pf = output_line[14:] |
|
640 | pf = output_line[14:] | |
641 | if pf.startswith("'") and pf.endswith("'") and pf.find(" ") >= 0: |
|
641 | if pf.startswith("'") and pf.endswith("'") and pf.find(" ") >= 0: | |
642 | pf = pf[1:-1] # Remove the quotes |
|
642 | pf = pf[1:-1] # Remove the quotes | |
643 | return pf |
|
643 | return pf | |
644 |
|
644 | |||
645 | def is_exec(f, last): |
|
645 | def is_exec(f, last): | |
646 | """check whether a file is executable""" |
|
646 | """check whether a file is executable""" | |
647 | return (os.stat(f).st_mode & 0100 != 0) |
|
647 | return (os.stat(f).st_mode & 0100 != 0) | |
648 |
|
648 | |||
649 | def set_exec(f, mode): |
|
649 | def set_exec(f, mode): | |
650 | s = os.stat(f).st_mode |
|
650 | s = os.stat(f).st_mode | |
651 | if (s & 0100 != 0) == mode: |
|
651 | if (s & 0100 != 0) == mode: | |
652 | return |
|
652 | return | |
653 | if mode: |
|
653 | if mode: | |
654 | # Turn on +x for every +r bit when making a file executable |
|
654 | # Turn on +x for every +r bit when making a file executable | |
655 | # and obey umask. |
|
655 | # and obey umask. | |
656 | umask = os.umask(0) |
|
656 | umask = os.umask(0) | |
657 | os.umask(umask) |
|
657 | os.umask(umask) | |
658 | os.chmod(f, s | (s & 0444) >> 2 & ~umask) |
|
658 | os.chmod(f, s | (s & 0444) >> 2 & ~umask) | |
659 | else: |
|
659 | else: | |
660 | os.chmod(f, s & 0666) |
|
660 | os.chmod(f, s & 0666) | |
661 |
|
661 | |||
662 | def set_binary(fd): |
|
662 | def set_binary(fd): | |
663 | pass |
|
663 | pass | |
664 |
|
664 | |||
665 | def pconvert(path): |
|
665 | def pconvert(path): | |
666 | return path |
|
666 | return path | |
667 |
|
667 | |||
668 | def localpath(path): |
|
668 | def localpath(path): | |
669 | return path |
|
669 | return path | |
670 |
|
670 | |||
671 | normpath = os.path.normpath |
|
671 | normpath = os.path.normpath | |
672 |
|
672 | |||
673 | def makelock(info, pathname): |
|
673 | def makelock(info, pathname): | |
674 | try: |
|
674 | try: | |
675 | os.symlink(info, pathname) |
|
675 | os.symlink(info, pathname) | |
676 | except OSError, why: |
|
676 | except OSError, why: | |
677 | if why.errno == errno.EEXIST: |
|
677 | if why.errno == errno.EEXIST: | |
678 | raise |
|
678 | raise | |
679 | else: |
|
679 | else: | |
680 | _makelock_file(info, pathname) |
|
680 | _makelock_file(info, pathname) | |
681 |
|
681 | |||
682 | def readlock(pathname): |
|
682 | def readlock(pathname): | |
683 | try: |
|
683 | try: | |
684 | return os.readlink(pathname) |
|
684 | return os.readlink(pathname) | |
685 | except OSError, why: |
|
685 | except OSError, why: | |
686 | if why.errno == errno.EINVAL: |
|
686 | if why.errno == errno.EINVAL: | |
687 | return _readlock_file(pathname) |
|
687 | return _readlock_file(pathname) | |
688 | else: |
|
688 | else: | |
689 | raise |
|
689 | raise | |
690 |
|
690 | |||
691 | def testpid(pid): |
|
691 | def testpid(pid): | |
692 | '''return False if pid dead, True if running or not sure''' |
|
692 | '''return False if pid dead, True if running or not sure''' | |
693 | try: |
|
693 | try: | |
694 | os.kill(pid, 0) |
|
694 | os.kill(pid, 0) | |
695 | return True |
|
695 | return True | |
696 | except OSError, inst: |
|
696 | except OSError, inst: | |
697 | return inst.errno != errno.ESRCH |
|
697 | return inst.errno != errno.ESRCH | |
698 |
|
698 | |||
699 | def explain_exit(code): |
|
699 | def explain_exit(code): | |
700 | """return a 2-tuple (desc, code) describing a process's status""" |
|
700 | """return a 2-tuple (desc, code) describing a process's status""" | |
701 | if os.WIFEXITED(code): |
|
701 | if os.WIFEXITED(code): | |
702 | val = os.WEXITSTATUS(code) |
|
702 | val = os.WEXITSTATUS(code) | |
703 | return _("exited with status %d") % val, val |
|
703 | return _("exited with status %d") % val, val | |
704 | elif os.WIFSIGNALED(code): |
|
704 | elif os.WIFSIGNALED(code): | |
705 | val = os.WTERMSIG(code) |
|
705 | val = os.WTERMSIG(code) | |
706 | return _("killed by signal %d") % val, val |
|
706 | return _("killed by signal %d") % val, val | |
707 | elif os.WIFSTOPPED(code): |
|
707 | elif os.WIFSTOPPED(code): | |
708 | val = os.WSTOPSIG(code) |
|
708 | val = os.WSTOPSIG(code) | |
709 | return _("stopped by signal %d") % val, val |
|
709 | return _("stopped by signal %d") % val, val | |
710 | raise ValueError(_("invalid exit code")) |
|
710 | raise ValueError(_("invalid exit code")) | |
711 |
|
711 | |||
712 | class chunkbuffer(object): |
|
712 | class chunkbuffer(object): | |
713 | """Allow arbitrary sized chunks of data to be efficiently read from an |
|
713 | """Allow arbitrary sized chunks of data to be efficiently read from an | |
714 | iterator over chunks of arbitrary size.""" |
|
714 | iterator over chunks of arbitrary size.""" | |
715 |
|
715 | |||
716 | def __init__(self, in_iter, targetsize = 2**16): |
|
716 | def __init__(self, in_iter, targetsize = 2**16): | |
717 | """in_iter is the iterator that's iterating over the input chunks. |
|
717 | """in_iter is the iterator that's iterating over the input chunks. | |
718 | targetsize is how big a buffer to try to maintain.""" |
|
718 | targetsize is how big a buffer to try to maintain.""" | |
719 | self.in_iter = iter(in_iter) |
|
719 | self.in_iter = iter(in_iter) | |
720 | self.buf = '' |
|
720 | self.buf = '' | |
721 | self.targetsize = int(targetsize) |
|
721 | self.targetsize = int(targetsize) | |
722 | if self.targetsize <= 0: |
|
722 | if self.targetsize <= 0: | |
723 | raise ValueError(_("targetsize must be greater than 0, was %d") % |
|
723 | raise ValueError(_("targetsize must be greater than 0, was %d") % | |
724 | targetsize) |
|
724 | targetsize) | |
725 | self.iterempty = False |
|
725 | self.iterempty = False | |
726 |
|
726 | |||
727 | def fillbuf(self): |
|
727 | def fillbuf(self): | |
728 | """Ignore target size; read every chunk from iterator until empty.""" |
|
728 | """Ignore target size; read every chunk from iterator until empty.""" | |
729 | if not self.iterempty: |
|
729 | if not self.iterempty: | |
730 | collector = cStringIO.StringIO() |
|
730 | collector = cStringIO.StringIO() | |
731 | collector.write(self.buf) |
|
731 | collector.write(self.buf) | |
732 | for ch in self.in_iter: |
|
732 | for ch in self.in_iter: | |
733 | collector.write(ch) |
|
733 | collector.write(ch) | |
734 | self.buf = collector.getvalue() |
|
734 | self.buf = collector.getvalue() | |
735 | self.iterempty = True |
|
735 | self.iterempty = True | |
736 |
|
736 | |||
737 | def read(self, l): |
|
737 | def read(self, l): | |
738 | """Read L bytes of data from the iterator of chunks of data. |
|
738 | """Read L bytes of data from the iterator of chunks of data. | |
739 | Returns less than L bytes if the iterator runs dry.""" |
|
739 | Returns less than L bytes if the iterator runs dry.""" | |
740 | if l > len(self.buf) and not self.iterempty: |
|
740 | if l > len(self.buf) and not self.iterempty: | |
741 | # Clamp to a multiple of self.targetsize |
|
741 | # Clamp to a multiple of self.targetsize | |
742 | targetsize = self.targetsize * ((l // self.targetsize) + 1) |
|
742 | targetsize = self.targetsize * ((l // self.targetsize) + 1) | |
743 | collector = cStringIO.StringIO() |
|
743 | collector = cStringIO.StringIO() | |
744 | collector.write(self.buf) |
|
744 | collector.write(self.buf) | |
745 | collected = len(self.buf) |
|
745 | collected = len(self.buf) | |
746 | for chunk in self.in_iter: |
|
746 | for chunk in self.in_iter: | |
747 | collector.write(chunk) |
|
747 | collector.write(chunk) | |
748 | collected += len(chunk) |
|
748 | collected += len(chunk) | |
749 | if collected >= targetsize: |
|
749 | if collected >= targetsize: | |
750 | break |
|
750 | break | |
751 | if collected < targetsize: |
|
751 | if collected < targetsize: | |
752 | self.iterempty = True |
|
752 | self.iterempty = True | |
753 | self.buf = collector.getvalue() |
|
753 | self.buf = collector.getvalue() | |
754 | s, self.buf = self.buf[:l], buffer(self.buf, l) |
|
754 | s, self.buf = self.buf[:l], buffer(self.buf, l) | |
755 | return s |
|
755 | return s | |
756 |
|
756 | |||
757 | def filechunkiter(f, size = 65536): |
|
757 | def filechunkiter(f, size = 65536): | |
758 | """Create a generator that produces all the data in the file size |
|
758 | """Create a generator that produces all the data in the file size | |
759 | (default 65536) bytes at a time. Chunks may be less than size |
|
759 | (default 65536) bytes at a time. Chunks may be less than size | |
760 | bytes if the chunk is the last chunk in the file, or the file is a |
|
760 | bytes if the chunk is the last chunk in the file, or the file is a | |
761 | socket or some other type of file that sometimes reads less data |
|
761 | socket or some other type of file that sometimes reads less data | |
762 | than is requested.""" |
|
762 | than is requested.""" | |
763 | s = f.read(size) |
|
763 | s = f.read(size) | |
764 | while len(s) > 0: |
|
764 | while len(s) > 0: | |
765 | yield s |
|
765 | yield s | |
766 | s = f.read(size) |
|
766 | s = f.read(size) | |
767 |
|
767 | |||
768 | def makedate(): |
|
768 | def makedate(): | |
769 | lt = time.localtime() |
|
769 | lt = time.localtime() | |
770 | if lt[8] == 1 and time.daylight: |
|
770 | if lt[8] == 1 and time.daylight: | |
771 | tz = time.altzone |
|
771 | tz = time.altzone | |
772 | else: |
|
772 | else: | |
773 | tz = time.timezone |
|
773 | tz = time.timezone | |
774 | return time.mktime(lt), tz |
|
774 | return time.mktime(lt), tz | |
775 |
|
775 | |||
776 | def datestr(date=None, format='%a %b %d %H:%M:%S %Y', timezone=True): |
|
776 | def datestr(date=None, format='%a %b %d %H:%M:%S %Y', timezone=True): | |
777 | """represent a (unixtime, offset) tuple as a localized time. |
|
777 | """represent a (unixtime, offset) tuple as a localized time. | |
778 | unixtime is seconds since the epoch, and offset is the time zone's |
|
778 | unixtime is seconds since the epoch, and offset is the time zone's | |
779 | number of seconds away from UTC. if timezone is false, do not |
|
779 | number of seconds away from UTC. if timezone is false, do not | |
780 | append time zone to string.""" |
|
780 | append time zone to string.""" | |
781 | t, tz = date or makedate() |
|
781 | t, tz = date or makedate() | |
782 | s = time.strftime(format, time.gmtime(float(t) - tz)) |
|
782 | s = time.strftime(format, time.gmtime(float(t) - tz)) | |
783 | if timezone: |
|
783 | if timezone: | |
784 | s += " %+03d%02d" % (-tz / 3600, ((-tz % 3600) / 60)) |
|
784 | s += " %+03d%02d" % (-tz / 3600, ((-tz % 3600) / 60)) | |
785 | return s |
|
785 | return s | |
786 |
|
786 | |||
787 | def shortuser(user): |
|
787 | def shortuser(user): | |
788 | """Return a short representation of a user name or email address.""" |
|
788 | """Return a short representation of a user name or email address.""" | |
789 | f = user.find('@') |
|
789 | f = user.find('@') | |
790 | if f >= 0: |
|
790 | if f >= 0: | |
791 | user = user[:f] |
|
791 | user = user[:f] | |
792 | f = user.find('<') |
|
792 | f = user.find('<') | |
793 | if f >= 0: |
|
793 | if f >= 0: | |
794 | user = user[f+1:] |
|
794 | user = user[f+1:] | |
795 | return user |
|
795 | return user | |
796 |
|
796 | |||
797 | def walkrepos(path): |
|
797 | def walkrepos(path): | |
798 | '''yield every hg repository under path, recursively.''' |
|
798 | '''yield every hg repository under path, recursively.''' | |
799 | def errhandler(err): |
|
799 | def errhandler(err): | |
800 | if err.filename == path: |
|
800 | if err.filename == path: | |
801 | raise err |
|
801 | raise err | |
802 |
|
802 | |||
803 | for root, dirs, files in os.walk(path, onerror=errhandler): |
|
803 | for root, dirs, files in os.walk(path, onerror=errhandler): | |
804 | for d in dirs: |
|
804 | for d in dirs: | |
805 | if d == '.hg': |
|
805 | if d == '.hg': | |
806 | yield root |
|
806 | yield root | |
807 | dirs[:] = [] |
|
807 | dirs[:] = [] | |
808 | break |
|
808 | break | |
809 |
|
809 | |||
810 | _rcpath = None |
|
810 | _rcpath = None | |
811 |
|
811 | |||
812 | def rcpath(): |
|
812 | def rcpath(): | |
813 | '''return hgrc search path. if env var HGRCPATH is set, use it. |
|
813 | '''return hgrc search path. if env var HGRCPATH is set, use it. | |
814 | for each item in path, if directory, use files ending in .rc, |
|
814 | for each item in path, if directory, use files ending in .rc, | |
815 | else use item. |
|
815 | else use item. | |
816 | make HGRCPATH empty to only look in .hg/hgrc of current repo. |
|
816 | make HGRCPATH empty to only look in .hg/hgrc of current repo. | |
817 | if no HGRCPATH, use default os-specific path.''' |
|
817 | if no HGRCPATH, use default os-specific path.''' | |
818 | global _rcpath |
|
818 | global _rcpath | |
819 | if _rcpath is None: |
|
819 | if _rcpath is None: | |
820 | if 'HGRCPATH' in os.environ: |
|
820 | if 'HGRCPATH' in os.environ: | |
821 | _rcpath = [] |
|
821 | _rcpath = [] | |
822 | for p in os.environ['HGRCPATH'].split(os.pathsep): |
|
822 | for p in os.environ['HGRCPATH'].split(os.pathsep): | |
823 | if not p: continue |
|
823 | if not p: continue | |
824 | if os.path.isdir(p): |
|
824 | if os.path.isdir(p): | |
825 | for f in os.listdir(p): |
|
825 | for f in os.listdir(p): | |
826 | if f.endswith('.rc'): |
|
826 | if f.endswith('.rc'): | |
827 | _rcpath.append(os.path.join(p, f)) |
|
827 | _rcpath.append(os.path.join(p, f)) | |
828 | else: |
|
828 | else: | |
829 | _rcpath.append(p) |
|
829 | _rcpath.append(p) | |
830 | else: |
|
830 | else: | |
831 | _rcpath = os_rcpath() |
|
831 | _rcpath = os_rcpath() | |
832 | return _rcpath |
|
832 | return _rcpath |
@@ -1,24 +1,21 b'' | |||||
1 | %%% should show a removed and b added |
|
1 | %%% should show a removed and b added | |
2 | A b |
|
2 | A b | |
3 | R a |
|
3 | R a | |
4 | reverting... |
|
4 | reverting... | |
5 | undeleting a |
|
5 | undeleting a | |
6 | forgetting b |
|
6 | forgetting b | |
7 | %%% should show b unknown and a back to normal |
|
7 | %%% should show b unknown and a back to normal | |
8 | ? b |
|
8 | ? b | |
9 | ? b.orig |
|
|||
10 | merging a |
|
9 | merging a | |
11 | %%% should show foo-b |
|
10 | %%% should show foo-b | |
12 | foo-b |
|
11 | foo-b | |
13 | %%% should show a removed and b added |
|
12 | %%% should show a removed and b added | |
14 | A b |
|
13 | A b | |
15 | R a |
|
14 | R a | |
16 | ? b.orig |
|
|||
17 | reverting... |
|
15 | reverting... | |
18 | undeleting a |
|
16 | undeleting a | |
19 | forgetting b |
|
17 | forgetting b | |
20 | %%% should show b unknown and a marked modified (merged) |
|
18 | %%% should show b unknown and a marked modified (merged) | |
21 | ? b |
|
19 | ? b | |
22 | ? b.orig |
|
|||
23 | %%% should show foo-b |
|
20 | %%% should show foo-b | |
24 | foo-b |
|
21 | foo-b |
@@ -1,57 +1,57 b'' | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 |
|
2 | |||
3 | hg init |
|
3 | hg init | |
4 | echo 123 > a |
|
4 | echo 123 > a | |
5 | echo 123 > c |
|
5 | echo 123 > c | |
6 | echo 123 > e |
|
6 | echo 123 > e | |
7 | hg add a c e |
|
7 | hg add a c e | |
8 | hg commit -m "first" -d "1000000 0" a c e |
|
8 | hg commit -m "first" -d "1000000 0" a c e | |
9 | echo 123 > b |
|
9 | echo 123 > b | |
10 | echo %% should show b unknown |
|
10 | echo %% should show b unknown | |
11 | hg status |
|
11 | hg status | |
12 | echo 12 > c |
|
12 | echo 12 > c | |
13 | echo %% should show b unknown and c modified |
|
13 | echo %% should show b unknown and c modified | |
14 | hg status |
|
14 | hg status | |
15 | hg add b |
|
15 | hg add b | |
16 | echo %% should show b added and c modified |
|
16 | echo %% should show b added and c modified | |
17 | hg status |
|
17 | hg status | |
18 | hg rm a |
|
18 | hg rm a | |
19 | echo %% should show a removed, b added and c modified |
|
19 | echo %% should show a removed, b added and c modified | |
20 | hg status |
|
20 | hg status | |
21 | hg revert a |
|
21 | hg revert a | |
22 | echo %% should show b added, copy saved, and c modified |
|
22 | echo %% should show b added, copy saved, and c modified | |
23 | hg status |
|
23 | hg status | |
24 | hg revert b |
|
24 | hg revert b | |
25 |
echo %% should show b unknown, |
|
25 | echo %% should show b unknown, and c modified | |
26 | hg status |
|
26 | hg status | |
27 | hg revert --no-backup c |
|
27 | hg revert --no-backup c | |
28 |
echo %% should show unknown: b |
|
28 | echo %% should show unknown: b | |
29 | hg status |
|
29 | hg status | |
30 |
echo %% should show a b |
|
30 | echo %% should show a b c e | |
31 | ls |
|
31 | ls | |
32 | echo %% should verbosely save backup to e.orig |
|
32 | echo %% should verbosely save backup to e.orig | |
33 | echo z > e |
|
33 | echo z > e | |
34 | hg revert -v |
|
34 | hg revert -v | |
35 | echo %% should say no changes needed |
|
35 | echo %% should say no changes needed | |
36 | hg revert a |
|
36 | hg revert a | |
37 | echo %% should say file not managed |
|
37 | echo %% should say file not managed | |
38 | echo q > q |
|
38 | echo q > q | |
39 | hg revert q |
|
39 | hg revert q | |
40 | rm q |
|
40 | rm q | |
41 | echo %% should say file not found |
|
41 | echo %% should say file not found | |
42 | hg revert notfound |
|
42 | hg revert notfound | |
43 | hg rm a |
|
43 | hg rm a | |
44 | hg commit -m "second" -d "1000000 0" |
|
44 | hg commit -m "second" -d "1000000 0" | |
45 | echo z > z |
|
45 | echo z > z | |
46 | hg add z |
|
46 | hg add z | |
47 | hg st |
|
47 | hg st | |
48 | echo %% should add a, forget z |
|
48 | echo %% should add a, forget z | |
49 | hg revert -r0 |
|
49 | hg revert -r0 | |
50 | echo %% should forget a |
|
50 | echo %% should forget a | |
51 | hg revert -rtip |
|
51 | hg revert -rtip | |
52 | rm -f a *.orig |
|
52 | rm -f a *.orig | |
53 | echo %% should silently add a |
|
53 | echo %% should silently add a | |
54 | hg revert -r0 a |
|
54 | hg revert -r0 a | |
55 | hg st a |
|
55 | hg st a | |
56 |
|
56 | |||
57 | true |
|
57 | true |
@@ -1,51 +1,47 b'' | |||||
1 | %% should show b unknown |
|
1 | %% should show b unknown | |
2 | ? b |
|
2 | ? b | |
3 | %% should show b unknown and c modified |
|
3 | %% should show b unknown and c modified | |
4 | M c |
|
4 | M c | |
5 | ? b |
|
5 | ? b | |
6 | %% should show b added and c modified |
|
6 | %% should show b added and c modified | |
7 | M c |
|
7 | M c | |
8 | A b |
|
8 | A b | |
9 | %% should show a removed, b added and c modified |
|
9 | %% should show a removed, b added and c modified | |
10 | M c |
|
10 | M c | |
11 | A b |
|
11 | A b | |
12 | R a |
|
12 | R a | |
13 | %% should show b added, copy saved, and c modified |
|
13 | %% should show b added, copy saved, and c modified | |
14 | M c |
|
14 | M c | |
15 | A b |
|
15 | A b | |
16 |
%% should show b unknown, |
|
16 | %% should show b unknown, and c modified | |
17 | M c |
|
17 | M c | |
18 | ? b |
|
18 | ? b | |
19 | ? b.orig |
|
19 | %% should show unknown: b | |
20 | %% should show unknown: b b.orig |
|
|||
21 | ? b |
|
20 | ? b | |
22 | ? b.orig |
|
21 | %% should show a b c e | |
23 | %% should show a b b.orig c e |
|
|||
24 | a |
|
22 | a | |
25 | b |
|
23 | b | |
26 | b.orig |
|
|||
27 | c |
|
24 | c | |
28 | e |
|
25 | e | |
29 | %% should verbosely save backup to e.orig |
|
26 | %% should verbosely save backup to e.orig | |
30 | saving current version of e as e.orig |
|
27 | saving current version of e as e.orig | |
31 | reverting e |
|
28 | reverting e | |
32 | resolving manifests |
|
29 | resolving manifests | |
33 | getting e |
|
30 | getting e | |
34 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
31 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
35 | %% should say no changes needed |
|
32 | %% should say no changes needed | |
36 | no changes needed to a |
|
33 | no changes needed to a | |
37 | %% should say file not managed |
|
34 | %% should say file not managed | |
38 | file not managed: q |
|
35 | file not managed: q | |
39 | %% should say file not found |
|
36 | %% should say file not found | |
40 | notfound: No such file in rev 095eacd0c0d7 |
|
37 | notfound: No such file in rev 095eacd0c0d7 | |
41 | A z |
|
38 | A z | |
42 | ? b |
|
39 | ? b | |
43 | ? b.orig |
|
|||
44 | ? e.orig |
|
40 | ? e.orig | |
45 | %% should add a, forget z |
|
41 | %% should add a, forget z | |
46 | adding a |
|
42 | adding a | |
47 | forgetting z |
|
43 | forgetting z | |
48 | %% should forget a |
|
44 | %% should forget a | |
49 | forgetting a |
|
45 | forgetting a | |
50 | %% should silently add a |
|
46 | %% should silently add a | |
51 | A a |
|
47 | A a |
General Comments 0
You need to be logged in to leave comments.
Login now