Show More
@@ -1,695 +1,695 | |||
|
1 | 1 | # histedit.py - interactive history editing for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2009 Augie Fackler <raf@durin42.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | """interactive history editing |
|
8 | 8 | |
|
9 | 9 | With this extension installed, Mercurial gains one new command: histedit. Usage |
|
10 | 10 | is as follows, assuming the following history:: |
|
11 | 11 | |
|
12 | 12 | @ 3[tip] 7c2fd3b9020c 2009-04-27 18:04 -0500 durin42 |
|
13 | 13 | | Add delta |
|
14 | 14 | | |
|
15 | 15 | o 2 030b686bedc4 2009-04-27 18:04 -0500 durin42 |
|
16 | 16 | | Add gamma |
|
17 | 17 | | |
|
18 | 18 | o 1 c561b4e977df 2009-04-27 18:04 -0500 durin42 |
|
19 | 19 | | Add beta |
|
20 | 20 | | |
|
21 | 21 | o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42 |
|
22 | 22 | Add alpha |
|
23 | 23 | |
|
24 | 24 | If you were to run ``hg histedit c561b4e977df``, you would see the following |
|
25 | 25 | file open in your editor:: |
|
26 | 26 | |
|
27 | 27 | pick c561b4e977df Add beta |
|
28 | 28 | pick 030b686bedc4 Add gamma |
|
29 | 29 | pick 7c2fd3b9020c Add delta |
|
30 | 30 | |
|
31 | 31 | # Edit history between 633536316234 and 7c2fd3b9020c |
|
32 | 32 | # |
|
33 | 33 | # Commands: |
|
34 | 34 | # p, pick = use commit |
|
35 | 35 | # e, edit = use commit, but stop for amending |
|
36 | 36 | # f, fold = use commit, but fold into previous commit |
|
37 | 37 | # d, drop = remove commit from history |
|
38 | 38 | # m, mess = edit message without changing commit content |
|
39 | 39 | # |
|
40 | 40 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
41 | 41 | |
|
42 | 42 | In this file, lines beginning with ``#`` are ignored. You must specify a rule |
|
43 | 43 | for each revision in your history. For example, if you had meant to add gamma |
|
44 | 44 | before beta, and then wanted to add delta in the same revision as beta, you |
|
45 | 45 | would reorganize the file to look like this:: |
|
46 | 46 | |
|
47 | 47 | pick 030b686bedc4 Add gamma |
|
48 | 48 | pick c561b4e977df Add beta |
|
49 | 49 | fold 7c2fd3b9020c Add delta |
|
50 | 50 | |
|
51 | 51 | # Edit history between 633536316234 and 7c2fd3b9020c |
|
52 | 52 | # |
|
53 | 53 | # Commands: |
|
54 | 54 | # p, pick = use commit |
|
55 | 55 | # e, edit = use commit, but stop for amending |
|
56 | 56 | # f, fold = use commit, but fold into previous commit |
|
57 | 57 | # d, drop = remove commit from history |
|
58 | 58 | # m, mess = edit message without changing commit content |
|
59 | 59 | # |
|
60 | 60 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
61 | 61 | |
|
62 | 62 | At which point you close the editor and ``histedit`` starts working. When you |
|
63 | 63 | specify a ``fold`` operation, ``histedit`` will open an editor when it folds |
|
64 | 64 | those revisions together, offering you a chance to clean up the commit message:: |
|
65 | 65 | |
|
66 | 66 | Add beta |
|
67 | 67 | *** |
|
68 | 68 | Add delta |
|
69 | 69 | |
|
70 | 70 | Edit the commit message to your liking, then close the editor. For |
|
71 | 71 | this example, let's assume that the commit message was changed to |
|
72 | 72 | ``Add beta and delta.`` After histedit has run and had a chance to |
|
73 | 73 | remove any old or temporary revisions it needed, the history looks |
|
74 | 74 | like this:: |
|
75 | 75 | |
|
76 | 76 | @ 2[tip] 989b4d060121 2009-04-27 18:04 -0500 durin42 |
|
77 | 77 | | Add beta and delta. |
|
78 | 78 | | |
|
79 | 79 | o 1 081603921c3f 2009-04-27 18:04 -0500 durin42 |
|
80 | 80 | | Add gamma |
|
81 | 81 | | |
|
82 | 82 | o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42 |
|
83 | 83 | Add alpha |
|
84 | 84 | |
|
85 | 85 | Note that ``histedit`` does *not* remove any revisions (even its own temporary |
|
86 | 86 | ones) until after it has completed all the editing operations, so it will |
|
87 | 87 | probably perform several strip operations when it's done. For the above example, |
|
88 | 88 | it had to run strip twice. Strip can be slow depending on a variety of factors, |
|
89 | 89 | so you might need to be a little patient. You can choose to keep the original |
|
90 | 90 | revisions by passing the ``--keep`` flag. |
|
91 | 91 | |
|
92 | 92 | The ``edit`` operation will drop you back to a command prompt, |
|
93 | 93 | allowing you to edit files freely, or even use ``hg record`` to commit |
|
94 | 94 | some changes as a separate commit. When you're done, any remaining |
|
95 | 95 | uncommitted changes will be committed as well. When done, run ``hg |
|
96 | 96 | histedit --continue`` to finish this step. You'll be prompted for a |
|
97 | 97 | new commit message, but the default commit message will be the |
|
98 | 98 | original message for the ``edit`` ed revision. |
|
99 | 99 | |
|
100 | 100 | The ``message`` operation will give you a chance to revise a commit |
|
101 | 101 | message without changing the contents. It's a shortcut for doing |
|
102 | 102 | ``edit`` immediately followed by `hg histedit --continue``. |
|
103 | 103 | |
|
104 | 104 | If ``histedit`` encounters a conflict when moving a revision (while |
|
105 | 105 | handling ``pick`` or ``fold``), it'll stop in a similar manner to |
|
106 | 106 | ``edit`` with the difference that it won't prompt you for a commit |
|
107 | 107 | message when done. If you decide at this point that you don't like how |
|
108 | 108 | much work it will be to rearrange history, or that you made a mistake, |
|
109 | 109 | you can use ``hg histedit --abort`` to abandon the new changes you |
|
110 | 110 | have made and return to the state before you attempted to edit your |
|
111 | 111 | history. |
|
112 | 112 | |
|
113 | 113 | If we clone the example repository above and add three more changes, such that |
|
114 | 114 | we have the following history:: |
|
115 | 115 | |
|
116 | 116 | @ 6[tip] 038383181893 2009-04-27 18:04 -0500 stefan |
|
117 | 117 | | Add theta |
|
118 | 118 | | |
|
119 | 119 | o 5 140988835471 2009-04-27 18:04 -0500 stefan |
|
120 | 120 | | Add eta |
|
121 | 121 | | |
|
122 | 122 | o 4 122930637314 2009-04-27 18:04 -0500 stefan |
|
123 | 123 | | Add zeta |
|
124 | 124 | | |
|
125 | 125 | o 3 836302820282 2009-04-27 18:04 -0500 stefan |
|
126 | 126 | | Add epsilon |
|
127 | 127 | | |
|
128 | 128 | o 2 989b4d060121 2009-04-27 18:04 -0500 durin42 |
|
129 | 129 | | Add beta and delta. |
|
130 | 130 | | |
|
131 | 131 | o 1 081603921c3f 2009-04-27 18:04 -0500 durin42 |
|
132 | 132 | | Add gamma |
|
133 | 133 | | |
|
134 | 134 | o 0 d8d2fcd0e319 2009-04-27 18:04 -0500 durin42 |
|
135 | 135 | Add alpha |
|
136 | 136 | |
|
137 | 137 | If you run ``hg histedit --outgoing`` on the clone then it is the same |
|
138 | 138 | as running ``hg histedit 836302820282``. If you need plan to push to a |
|
139 | 139 | repository that Mercurial does not detect to be related to the source |
|
140 | 140 | repo, you can add a ``--force`` option. |
|
141 | 141 | """ |
|
142 | 142 | |
|
143 | 143 | try: |
|
144 | 144 | import cPickle as pickle |
|
145 | 145 | except ImportError: |
|
146 | 146 | import pickle |
|
147 | 147 | import tempfile |
|
148 | 148 | import os |
|
149 | 149 | |
|
150 | 150 | from mercurial import bookmarks |
|
151 | 151 | from mercurial import cmdutil |
|
152 | 152 | from mercurial import discovery |
|
153 | 153 | from mercurial import error |
|
154 | 154 | from mercurial import hg |
|
155 | 155 | from mercurial import node |
|
156 | 156 | from mercurial import patch |
|
157 | 157 | from mercurial import repair |
|
158 | 158 | from mercurial import scmutil |
|
159 | 159 | from mercurial import util |
|
160 | 160 | from mercurial.i18n import _ |
|
161 | 161 | |
|
162 | 162 | cmdtable = {} |
|
163 | 163 | command = cmdutil.command(cmdtable) |
|
164 | 164 | |
|
165 | 165 | testedwith = 'internal' |
|
166 | 166 | |
|
167 | 167 | editcomment = """ |
|
168 | 168 | |
|
169 | 169 | # Edit history between %s and %s |
|
170 | 170 | # |
|
171 | 171 | # Commands: |
|
172 | 172 | # p, pick = use commit |
|
173 | 173 | # e, edit = use commit, but stop for amending |
|
174 | 174 | # f, fold = use commit, but fold into previous commit (combines N and N-1) |
|
175 | 175 | # d, drop = remove commit from history |
|
176 | 176 | # m, mess = edit message without changing commit content |
|
177 | 177 | # |
|
178 | 178 | """ |
|
179 | 179 | |
|
180 | 180 | def between(repo, old, new, keep): |
|
181 | 181 | revs = [old] |
|
182 | 182 | current = old |
|
183 | 183 | while current != new: |
|
184 | 184 | ctx = repo[current] |
|
185 | 185 | if not keep and len(ctx.children()) > 1: |
|
186 | 186 | raise util.Abort(_('cannot edit history that would orphan nodes')) |
|
187 | 187 | if len(ctx.parents()) != 1 and ctx.parents()[1] != node.nullid: |
|
188 | 188 | raise util.Abort(_("can't edit history with merges")) |
|
189 | 189 | if not ctx.children(): |
|
190 | 190 | current = new |
|
191 | 191 | else: |
|
192 | 192 | current = ctx.children()[0].node() |
|
193 | 193 | revs.append(current) |
|
194 | 194 | if len(repo[current].children()) and not keep: |
|
195 | 195 | raise util.Abort(_('cannot edit history that would orphan nodes')) |
|
196 | 196 | return revs |
|
197 | 197 | |
|
198 | 198 | |
|
199 | 199 | def pick(ui, repo, ctx, ha, opts): |
|
200 | 200 | oldctx = repo[ha] |
|
201 | 201 | if oldctx.parents()[0] == ctx: |
|
202 | 202 | ui.debug('node %s unchanged\n' % ha) |
|
203 | 203 | return oldctx, [], [], [] |
|
204 | 204 | hg.update(repo, ctx.node()) |
|
205 | 205 | fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-') |
|
206 | 206 | fp = os.fdopen(fd, 'w') |
|
207 | 207 | diffopts = patch.diffopts(ui, opts) |
|
208 | 208 | diffopts.git = True |
|
209 | 209 | diffopts.ignorews = False |
|
210 | 210 | diffopts.ignorewsamount = False |
|
211 | 211 | diffopts.ignoreblanklines = False |
|
212 | 212 | gen = patch.diff(repo, oldctx.parents()[0].node(), ha, opts=diffopts) |
|
213 | 213 | for chunk in gen: |
|
214 | 214 | fp.write(chunk) |
|
215 | 215 | fp.close() |
|
216 | 216 | try: |
|
217 | 217 | files = set() |
|
218 | 218 | try: |
|
219 | 219 | patch.patch(ui, repo, patchfile, files=files, eolmode=None) |
|
220 | 220 | if not files: |
|
221 | 221 | ui.warn(_('%s: empty changeset') |
|
222 | 222 | % node.hex(ha)) |
|
223 | 223 | return ctx, [], [], [] |
|
224 | 224 | finally: |
|
225 | 225 | os.unlink(patchfile) |
|
226 | 226 | except Exception: |
|
227 | 227 | raise util.Abort(_('Fix up the change and run ' |
|
228 | 228 | 'hg histedit --continue')) |
|
229 | 229 | n = repo.commit(text=oldctx.description(), user=oldctx.user(), |
|
230 | 230 | date=oldctx.date(), extra=oldctx.extra()) |
|
231 | 231 | return repo[n], [n], [oldctx.node()], [] |
|
232 | 232 | |
|
233 | 233 | |
|
234 | 234 | def edit(ui, repo, ctx, ha, opts): |
|
235 | 235 | oldctx = repo[ha] |
|
236 | 236 | hg.update(repo, ctx.node()) |
|
237 | 237 | fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-') |
|
238 | 238 | fp = os.fdopen(fd, 'w') |
|
239 | 239 | diffopts = patch.diffopts(ui, opts) |
|
240 | 240 | diffopts.git = True |
|
241 | 241 | diffopts.ignorews = False |
|
242 | 242 | diffopts.ignorewsamount = False |
|
243 | 243 | diffopts.ignoreblanklines = False |
|
244 | 244 | gen = patch.diff(repo, oldctx.parents()[0].node(), ha, opts=diffopts) |
|
245 | 245 | for chunk in gen: |
|
246 | 246 | fp.write(chunk) |
|
247 | 247 | fp.close() |
|
248 | 248 | try: |
|
249 | 249 | files = set() |
|
250 | 250 | try: |
|
251 | 251 | patch.patch(ui, repo, patchfile, files=files, eolmode=None) |
|
252 | 252 | finally: |
|
253 | 253 | os.unlink(patchfile) |
|
254 | 254 | except Exception: |
|
255 | 255 | pass |
|
256 | 256 | raise util.Abort(_('Make changes as needed, you may commit or record as ' |
|
257 | 257 | 'needed now.\nWhen you are finished, run hg' |
|
258 | 258 | ' histedit --continue to resume.')) |
|
259 | 259 | |
|
260 | 260 | def fold(ui, repo, ctx, ha, opts): |
|
261 | 261 | oldctx = repo[ha] |
|
262 | 262 | hg.update(repo, ctx.node()) |
|
263 | 263 | fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-') |
|
264 | 264 | fp = os.fdopen(fd, 'w') |
|
265 | 265 | diffopts = patch.diffopts(ui, opts) |
|
266 | 266 | diffopts.git = True |
|
267 | 267 | diffopts.ignorews = False |
|
268 | 268 | diffopts.ignorewsamount = False |
|
269 | 269 | diffopts.ignoreblanklines = False |
|
270 | 270 | gen = patch.diff(repo, oldctx.parents()[0].node(), ha, opts=diffopts) |
|
271 | 271 | for chunk in gen: |
|
272 | 272 | fp.write(chunk) |
|
273 | 273 | fp.close() |
|
274 | 274 | try: |
|
275 | 275 | files = set() |
|
276 | 276 | try: |
|
277 | 277 | patch.patch(ui, repo, patchfile, files=files, eolmode=None) |
|
278 | 278 | if not files: |
|
279 | 279 | ui.warn(_('%s: empty changeset') |
|
280 | 280 | % node.hex(ha)) |
|
281 | 281 | return ctx, [], [], [] |
|
282 | 282 | finally: |
|
283 | 283 | os.unlink(patchfile) |
|
284 | 284 | except Exception: |
|
285 | 285 | raise util.Abort(_('Fix up the change and run ' |
|
286 | 286 | 'hg histedit --continue')) |
|
287 | 287 | n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(), |
|
288 | 288 | date=oldctx.date(), extra=oldctx.extra()) |
|
289 | 289 | return finishfold(ui, repo, ctx, oldctx, n, opts, []) |
|
290 | 290 | |
|
291 | 291 | def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges): |
|
292 | 292 | parent = ctx.parents()[0].node() |
|
293 | 293 | hg.update(repo, parent) |
|
294 | 294 | fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-') |
|
295 | 295 | fp = os.fdopen(fd, 'w') |
|
296 | 296 | diffopts = patch.diffopts(ui, opts) |
|
297 | 297 | diffopts.git = True |
|
298 | 298 | diffopts.ignorews = False |
|
299 | 299 | diffopts.ignorewsamount = False |
|
300 | 300 | diffopts.ignoreblanklines = False |
|
301 | 301 | gen = patch.diff(repo, parent, newnode, opts=diffopts) |
|
302 | 302 | for chunk in gen: |
|
303 | 303 | fp.write(chunk) |
|
304 | 304 | fp.close() |
|
305 | 305 | files = set() |
|
306 | 306 | try: |
|
307 | 307 | patch.patch(ui, repo, patchfile, files=files, eolmode=None) |
|
308 | 308 | finally: |
|
309 | 309 | os.unlink(patchfile) |
|
310 | 310 | newmessage = '\n***\n'.join( |
|
311 | 311 | [ctx.description()] + |
|
312 | 312 | [repo[r].description() for r in internalchanges] + |
|
313 | 313 | [oldctx.description()]) |
|
314 | 314 | # If the changesets are from the same author, keep it. |
|
315 | 315 | if ctx.user() == oldctx.user(): |
|
316 | 316 | username = ctx.user() |
|
317 | 317 | else: |
|
318 | 318 | username = ui.username() |
|
319 | 319 | newmessage = ui.edit(newmessage, username) |
|
320 | 320 | n = repo.commit(text=newmessage, user=username, |
|
321 | 321 | date=max(ctx.date(), oldctx.date()), extra=oldctx.extra()) |
|
322 | 322 | return repo[n], [n], [oldctx.node(), ctx.node()], [newnode] |
|
323 | 323 | |
|
324 | 324 | def drop(ui, repo, ctx, ha, opts): |
|
325 | 325 | return ctx, [], [repo[ha].node()], [] |
|
326 | 326 | |
|
327 | 327 | |
|
328 | 328 | def message(ui, repo, ctx, ha, opts): |
|
329 | 329 | oldctx = repo[ha] |
|
330 | 330 | hg.update(repo, ctx.node()) |
|
331 | 331 | fd, patchfile = tempfile.mkstemp(prefix='hg-histedit-') |
|
332 | 332 | fp = os.fdopen(fd, 'w') |
|
333 | 333 | diffopts = patch.diffopts(ui, opts) |
|
334 | 334 | diffopts.git = True |
|
335 | 335 | diffopts.ignorews = False |
|
336 | 336 | diffopts.ignorewsamount = False |
|
337 | 337 | diffopts.ignoreblanklines = False |
|
338 | 338 | gen = patch.diff(repo, oldctx.parents()[0].node(), ha, opts=diffopts) |
|
339 | 339 | for chunk in gen: |
|
340 | 340 | fp.write(chunk) |
|
341 | 341 | fp.close() |
|
342 | 342 | try: |
|
343 | 343 | files = set() |
|
344 | 344 | try: |
|
345 | 345 | patch.patch(ui, repo, patchfile, files=files, eolmode=None) |
|
346 | 346 | finally: |
|
347 | 347 | os.unlink(patchfile) |
|
348 | 348 | except Exception: |
|
349 | 349 | raise util.Abort(_('Fix up the change and run ' |
|
350 | 350 | 'hg histedit --continue')) |
|
351 | 351 | message = oldctx.description() |
|
352 | 352 | message = ui.edit(message, ui.username()) |
|
353 | 353 | new = repo.commit(text=message, user=oldctx.user(), date=oldctx.date(), |
|
354 | 354 | extra=oldctx.extra()) |
|
355 | 355 | newctx = repo[new] |
|
356 | 356 | if oldctx.node() != newctx.node(): |
|
357 | 357 | return newctx, [new], [oldctx.node()], [] |
|
358 | 358 | # We didn't make an edit, so just indicate no replaced nodes |
|
359 | 359 | return newctx, [new], [], [] |
|
360 | 360 | |
|
361 | 361 | |
|
362 | 362 | def makedesc(c): |
|
363 | 363 | summary = '' |
|
364 | 364 | if c.description(): |
|
365 | 365 | summary = c.description().splitlines()[0] |
|
366 | 366 | line = 'pick %s %d %s' % (c.hex()[:12], c.rev(), summary) |
|
367 | 367 | return line[:80] # trim to 80 chars so it's not stupidly wide in my editor |
|
368 | 368 | |
|
369 | 369 | actiontable = {'p': pick, |
|
370 | 370 | 'pick': pick, |
|
371 | 371 | 'e': edit, |
|
372 | 372 | 'edit': edit, |
|
373 | 373 | 'f': fold, |
|
374 | 374 | 'fold': fold, |
|
375 | 375 | 'd': drop, |
|
376 | 376 | 'drop': drop, |
|
377 | 377 | 'm': message, |
|
378 | 378 | 'mess': message, |
|
379 | 379 | } |
|
380 | 380 | |
|
381 | 381 | @command('histedit', |
|
382 | 382 | [('', 'commands', '', |
|
383 | 383 | _('Read history edits from the specified file.')), |
|
384 | 384 | ('c', 'continue', False, _('continue an edit already in progress')), |
|
385 | 385 | ('k', 'keep', False, |
|
386 | 386 | _("don't strip old nodes after edit is complete")), |
|
387 | 387 | ('', 'abort', False, _('abort an edit in progress')), |
|
388 | 388 | ('o', 'outgoing', False, _('changesets not found in destination')), |
|
389 | 389 | ('f', 'force', False, |
|
390 | 390 | _('force outgoing even for unrelated repositories')), |
|
391 | 391 | ('r', 'rev', [], _('first revision to be edited'))], |
|
392 | 392 | _("[PARENT]")) |
|
393 | 393 | def histedit(ui, repo, *parent, **opts): |
|
394 | 394 | """interactively edit changeset history |
|
395 | 395 | """ |
|
396 | 396 | # TODO only abort if we try and histedit mq patches, not just |
|
397 | 397 | # blanket if mq patches are applied somewhere |
|
398 | 398 | mq = getattr(repo, 'mq', None) |
|
399 | 399 | if mq and mq.applied: |
|
400 | 400 | raise util.Abort(_('source has mq patches applied')) |
|
401 | 401 | |
|
402 | 402 | parent = list(parent) + opts.get('rev', []) |
|
403 | 403 | if opts.get('outgoing'): |
|
404 | 404 | if len(parent) > 1: |
|
405 | 405 | raise util.Abort( |
|
406 | 406 | _('only one repo argument allowed with --outgoing')) |
|
407 | 407 | elif parent: |
|
408 | 408 | parent = parent[0] |
|
409 | 409 | |
|
410 | 410 | dest = ui.expandpath(parent or 'default-push', parent or 'default') |
|
411 | 411 | dest, revs = hg.parseurl(dest, None)[:2] |
|
412 | 412 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
413 | 413 | |
|
414 | 414 | revs, checkout = hg.addbranchrevs(repo, repo, revs, None) |
|
415 |
other = hg. |
|
|
415 | other = hg.peer(repo, opts, dest) | |
|
416 | 416 | |
|
417 | 417 | if revs: |
|
418 | 418 | revs = [repo.lookup(rev) for rev in revs] |
|
419 | 419 | |
|
420 | 420 | parent = discovery.findcommonoutgoing( |
|
421 | 421 | repo, other, [], force=opts.get('force')).missing[0:1] |
|
422 | 422 | else: |
|
423 | 423 | if opts.get('force'): |
|
424 | 424 | raise util.Abort(_('--force only allowed with --outgoing')) |
|
425 | 425 | |
|
426 | 426 | if opts.get('continue', False): |
|
427 | 427 | if len(parent) != 0: |
|
428 | 428 | raise util.Abort(_('no arguments allowed with --continue')) |
|
429 | 429 | (parentctxnode, created, replaced, |
|
430 | 430 | tmpnodes, existing, rules, keep, tip, replacemap) = readstate(repo) |
|
431 | 431 | currentparent, wantnull = repo.dirstate.parents() |
|
432 | 432 | parentctx = repo[parentctxnode] |
|
433 | 433 | # discover any nodes the user has added in the interim |
|
434 | 434 | newchildren = [c for c in parentctx.children() |
|
435 | 435 | if c.node() not in existing] |
|
436 | 436 | action, currentnode = rules.pop(0) |
|
437 | 437 | while newchildren: |
|
438 | 438 | if action in ('f', 'fold'): |
|
439 | 439 | tmpnodes.extend([n.node() for n in newchildren]) |
|
440 | 440 | else: |
|
441 | 441 | created.extend([n.node() for n in newchildren]) |
|
442 | 442 | filtered = [] |
|
443 | 443 | for r in newchildren: |
|
444 | 444 | filtered += [c for c in r.children() if c.node not in existing] |
|
445 | 445 | newchildren = filtered |
|
446 | 446 | m, a, r, d = repo.status()[:4] |
|
447 | 447 | oldctx = repo[currentnode] |
|
448 | 448 | message = oldctx.description() |
|
449 | 449 | if action in ('e', 'edit', 'm', 'mess'): |
|
450 | 450 | message = ui.edit(message, ui.username()) |
|
451 | 451 | elif action in ('f', 'fold'): |
|
452 | 452 | message = 'fold-temp-revision %s' % currentnode |
|
453 | 453 | new = None |
|
454 | 454 | if m or a or r or d: |
|
455 | 455 | new = repo.commit(text=message, user=oldctx.user(), |
|
456 | 456 | date=oldctx.date(), extra=oldctx.extra()) |
|
457 | 457 | |
|
458 | 458 | # If we're resuming a fold and we have new changes, mark the |
|
459 | 459 | # replacements and finish the fold. If not, it's more like a |
|
460 | 460 | # drop of the changesets that disappeared, and we can skip |
|
461 | 461 | # this step. |
|
462 | 462 | if action in ('f', 'fold') and (new or newchildren): |
|
463 | 463 | if new: |
|
464 | 464 | tmpnodes.append(new) |
|
465 | 465 | else: |
|
466 | 466 | new = newchildren[-1] |
|
467 | 467 | (parentctx, created_, replaced_, tmpnodes_) = finishfold( |
|
468 | 468 | ui, repo, parentctx, oldctx, new, opts, newchildren) |
|
469 | 469 | replaced.extend(replaced_) |
|
470 | 470 | created.extend(created_) |
|
471 | 471 | tmpnodes.extend(tmpnodes_) |
|
472 | 472 | elif action not in ('d', 'drop'): |
|
473 | 473 | if new != oldctx.node(): |
|
474 | 474 | replaced.append(oldctx.node()) |
|
475 | 475 | if new: |
|
476 | 476 | if new != oldctx.node(): |
|
477 | 477 | created.append(new) |
|
478 | 478 | parentctx = repo[new] |
|
479 | 479 | |
|
480 | 480 | elif opts.get('abort', False): |
|
481 | 481 | if len(parent) != 0: |
|
482 | 482 | raise util.Abort(_('no arguments allowed with --abort')) |
|
483 | 483 | (parentctxnode, created, replaced, tmpnodes, |
|
484 | 484 | existing, rules, keep, tip, replacemap) = readstate(repo) |
|
485 | 485 | ui.debug('restore wc to old tip %s\n' % node.hex(tip)) |
|
486 | 486 | hg.clean(repo, tip) |
|
487 | 487 | ui.debug('should strip created nodes %s\n' % |
|
488 | 488 | ', '.join([node.hex(n)[:12] for n in created])) |
|
489 | 489 | ui.debug('should strip temp nodes %s\n' % |
|
490 | 490 | ', '.join([node.hex(n)[:12] for n in tmpnodes])) |
|
491 | 491 | for nodes in (created, tmpnodes): |
|
492 | 492 | for n in reversed(nodes): |
|
493 | 493 | try: |
|
494 | 494 | repair.strip(ui, repo, n) |
|
495 | 495 | except error.LookupError: |
|
496 | 496 | pass |
|
497 | 497 | os.unlink(os.path.join(repo.path, 'histedit-state')) |
|
498 | 498 | return |
|
499 | 499 | else: |
|
500 | 500 | cmdutil.bailifchanged(repo) |
|
501 | 501 | if os.path.exists(os.path.join(repo.path, 'histedit-state')): |
|
502 | 502 | raise util.Abort(_('history edit already in progress, try ' |
|
503 | 503 | '--continue or --abort')) |
|
504 | 504 | |
|
505 | 505 | tip, empty = repo.dirstate.parents() |
|
506 | 506 | |
|
507 | 507 | |
|
508 | 508 | if len(parent) != 1: |
|
509 | 509 | raise util.Abort(_('histedit requires exactly one parent revision')) |
|
510 | 510 | parent = scmutil.revsingle(repo, parent[0]).node() |
|
511 | 511 | |
|
512 | 512 | keep = opts.get('keep', False) |
|
513 | 513 | revs = between(repo, parent, tip, keep) |
|
514 | 514 | |
|
515 | 515 | ctxs = [repo[r] for r in revs] |
|
516 | 516 | existing = [r.node() for r in ctxs] |
|
517 | 517 | rules = opts.get('commands', '') |
|
518 | 518 | if not rules: |
|
519 | 519 | rules = '\n'.join([makedesc(c) for c in ctxs]) |
|
520 | 520 | rules += editcomment % (node.hex(parent)[:12], node.hex(tip)[:12]) |
|
521 | 521 | rules = ui.edit(rules, ui.username()) |
|
522 | 522 | # Save edit rules in .hg/histedit-last-edit.txt in case |
|
523 | 523 | # the user needs to ask for help after something |
|
524 | 524 | # surprising happens. |
|
525 | 525 | f = open(repo.join('histedit-last-edit.txt'), 'w') |
|
526 | 526 | f.write(rules) |
|
527 | 527 | f.close() |
|
528 | 528 | else: |
|
529 | 529 | f = open(rules) |
|
530 | 530 | rules = f.read() |
|
531 | 531 | f.close() |
|
532 | 532 | rules = [l for l in (r.strip() for r in rules.splitlines()) |
|
533 | 533 | if l and not l[0] == '#'] |
|
534 | 534 | rules = verifyrules(rules, repo, ctxs) |
|
535 | 535 | |
|
536 | 536 | parentctx = repo[parent].parents()[0] |
|
537 | 537 | keep = opts.get('keep', False) |
|
538 | 538 | replaced = [] |
|
539 | 539 | replacemap = {} |
|
540 | 540 | tmpnodes = [] |
|
541 | 541 | created = [] |
|
542 | 542 | |
|
543 | 543 | |
|
544 | 544 | while rules: |
|
545 | 545 | writestate(repo, parentctx.node(), created, replaced, |
|
546 | 546 | tmpnodes, existing, rules, keep, tip, replacemap) |
|
547 | 547 | action, ha = rules.pop(0) |
|
548 | 548 | (parentctx, created_, replaced_, tmpnodes_) = actiontable[action]( |
|
549 | 549 | ui, repo, parentctx, ha, opts) |
|
550 | 550 | |
|
551 | 551 | if replaced_: |
|
552 | 552 | clen, rlen = len(created_), len(replaced_) |
|
553 | 553 | if clen == rlen == 1: |
|
554 | 554 | ui.debug('histedit: exact replacement of %s with %s\n' % ( |
|
555 | 555 | node.short(replaced_[0]), node.short(created_[0]))) |
|
556 | 556 | |
|
557 | 557 | replacemap[replaced_[0]] = created_[0] |
|
558 | 558 | elif clen > rlen: |
|
559 | 559 | assert rlen == 1, ('unexpected replacement of ' |
|
560 | 560 | '%d changes with %d changes' % (rlen, clen)) |
|
561 | 561 | # made more changesets than we're replacing |
|
562 | 562 | # TODO synthesize patch names for created patches |
|
563 | 563 | replacemap[replaced_[0]] = created_[-1] |
|
564 | 564 | ui.debug('histedit: created many, assuming %s replaced by %s' % |
|
565 | 565 | (node.short(replaced_[0]), node.short(created_[-1]))) |
|
566 | 566 | elif rlen > clen: |
|
567 | 567 | if not created_: |
|
568 | 568 | # This must be a drop. Try and put our metadata on |
|
569 | 569 | # the parent change. |
|
570 | 570 | assert rlen == 1 |
|
571 | 571 | r = replaced_[0] |
|
572 | 572 | ui.debug('histedit: %s seems replaced with nothing, ' |
|
573 | 573 | 'finding a parent\n' % (node.short(r))) |
|
574 | 574 | pctx = repo[r].parents()[0] |
|
575 | 575 | if pctx.node() in replacemap: |
|
576 | 576 | ui.debug('histedit: parent is already replaced\n') |
|
577 | 577 | replacemap[r] = replacemap[pctx.node()] |
|
578 | 578 | else: |
|
579 | 579 | replacemap[r] = pctx.node() |
|
580 | 580 | ui.debug('histedit: %s best replaced by %s\n' % ( |
|
581 | 581 | node.short(r), node.short(replacemap[r]))) |
|
582 | 582 | else: |
|
583 | 583 | assert len(created_) == 1 |
|
584 | 584 | for r in replaced_: |
|
585 | 585 | ui.debug('histedit: %s replaced by %s\n' % ( |
|
586 | 586 | node.short(r), node.short(created_[0]))) |
|
587 | 587 | replacemap[r] = created_[0] |
|
588 | 588 | else: |
|
589 | 589 | assert False, ( |
|
590 | 590 | 'Unhandled case in replacement mapping! ' |
|
591 | 591 | 'replacing %d changes with %d changes' % (rlen, clen)) |
|
592 | 592 | created.extend(created_) |
|
593 | 593 | replaced.extend(replaced_) |
|
594 | 594 | tmpnodes.extend(tmpnodes_) |
|
595 | 595 | |
|
596 | 596 | hg.update(repo, parentctx.node()) |
|
597 | 597 | |
|
598 | 598 | if not keep: |
|
599 | 599 | if replacemap: |
|
600 | 600 | ui.note(_('histedit: Should update metadata for the following ' |
|
601 | 601 | 'changes:\n')) |
|
602 | 602 | |
|
603 | 603 | def copybms(old, new): |
|
604 | 604 | if old in tmpnodes or old in created: |
|
605 | 605 | # can't have any metadata we'd want to update |
|
606 | 606 | return |
|
607 | 607 | while new in replacemap: |
|
608 | 608 | new = replacemap[new] |
|
609 | 609 | ui.note(_('histedit: %s to %s\n') % (node.short(old), |
|
610 | 610 | node.short(new))) |
|
611 | 611 | octx = repo[old] |
|
612 | 612 | marks = octx.bookmarks() |
|
613 | 613 | if marks: |
|
614 | 614 | ui.note(_('histedit: moving bookmarks %s\n') % |
|
615 | 615 | ', '.join(marks)) |
|
616 | 616 | for mark in marks: |
|
617 | 617 | repo._bookmarks[mark] = new |
|
618 | 618 | bookmarks.write(repo) |
|
619 | 619 | |
|
620 | 620 | # We assume that bookmarks on the tip should remain |
|
621 | 621 | # tipmost, but bookmarks on non-tip changesets should go |
|
622 | 622 | # to their most reasonable successor. As a result, find |
|
623 | 623 | # the old tip and new tip and copy those bookmarks first, |
|
624 | 624 | # then do the rest of the bookmark copies. |
|
625 | 625 | oldtip = sorted(replacemap.keys(), key=repo.changelog.rev)[-1] |
|
626 | 626 | newtip = sorted(replacemap.values(), key=repo.changelog.rev)[-1] |
|
627 | 627 | copybms(oldtip, newtip) |
|
628 | 628 | |
|
629 | 629 | for old, new in sorted(replacemap.iteritems()): |
|
630 | 630 | copybms(old, new) |
|
631 | 631 | # TODO update mq state |
|
632 | 632 | |
|
633 | 633 | ui.debug('should strip replaced nodes %s\n' % |
|
634 | 634 | ', '.join([node.hex(n)[:12] for n in replaced])) |
|
635 | 635 | for n in sorted(replaced, key=lambda x: repo[x].rev()): |
|
636 | 636 | try: |
|
637 | 637 | repair.strip(ui, repo, n) |
|
638 | 638 | except error.LookupError: |
|
639 | 639 | pass |
|
640 | 640 | |
|
641 | 641 | ui.debug('should strip temp nodes %s\n' % |
|
642 | 642 | ', '.join([node.hex(n)[:12] for n in tmpnodes])) |
|
643 | 643 | for n in reversed(tmpnodes): |
|
644 | 644 | try: |
|
645 | 645 | repair.strip(ui, repo, n) |
|
646 | 646 | except error.LookupError: |
|
647 | 647 | pass |
|
648 | 648 | os.unlink(os.path.join(repo.path, 'histedit-state')) |
|
649 | 649 | if os.path.exists(repo.sjoin('undo')): |
|
650 | 650 | os.unlink(repo.sjoin('undo')) |
|
651 | 651 | |
|
652 | 652 | |
|
653 | 653 | def writestate(repo, parentctxnode, created, replaced, |
|
654 | 654 | tmpnodes, existing, rules, keep, oldtip, replacemap): |
|
655 | 655 | fp = open(os.path.join(repo.path, 'histedit-state'), 'w') |
|
656 | 656 | pickle.dump((parentctxnode, created, replaced, |
|
657 | 657 | tmpnodes, existing, rules, keep, oldtip, replacemap), |
|
658 | 658 | fp) |
|
659 | 659 | fp.close() |
|
660 | 660 | |
|
661 | 661 | def readstate(repo): |
|
662 | 662 | """Returns a tuple of (parentnode, created, replaced, tmp, existing, rules, |
|
663 | 663 | keep, oldtip, replacemap ). |
|
664 | 664 | """ |
|
665 | 665 | fp = open(os.path.join(repo.path, 'histedit-state')) |
|
666 | 666 | return pickle.load(fp) |
|
667 | 667 | |
|
668 | 668 | |
|
669 | 669 | def verifyrules(rules, repo, ctxs): |
|
670 | 670 | """Verify that there exists exactly one edit rule per given changeset. |
|
671 | 671 | |
|
672 | 672 | Will abort if there are to many or too few rules, a malformed rule, |
|
673 | 673 | or a rule on a changeset outside of the user-given range. |
|
674 | 674 | """ |
|
675 | 675 | parsed = [] |
|
676 | 676 | if len(rules) != len(ctxs): |
|
677 | 677 | raise util.Abort(_('must specify a rule for each changeset once')) |
|
678 | 678 | for r in rules: |
|
679 | 679 | if ' ' not in r: |
|
680 | 680 | raise util.Abort(_('malformed line "%s"') % r) |
|
681 | 681 | action, rest = r.split(' ', 1) |
|
682 | 682 | if ' ' in rest.strip(): |
|
683 | 683 | ha, rest = rest.split(' ', 1) |
|
684 | 684 | else: |
|
685 | 685 | ha = r.strip() |
|
686 | 686 | try: |
|
687 | 687 | if repo[ha] not in ctxs: |
|
688 | 688 | raise util.Abort( |
|
689 | 689 | _('may not use changesets other than the ones listed')) |
|
690 | 690 | except error.RepoError: |
|
691 | 691 | raise util.Abort(_('unknown changeset %s listed') % ha) |
|
692 | 692 | if action not in actiontable: |
|
693 | 693 | raise util.Abort(_('unknown action "%s"') % action) |
|
694 | 694 | parsed.append([action, ha]) |
|
695 | 695 | return parsed |
@@ -1,82 +1,82 | |||
|
1 | 1 | # Copyright 2009-2010 Gregory P. Ward |
|
2 | 2 | # Copyright 2009-2010 Intelerad Medical Systems Incorporated |
|
3 | 3 | # Copyright 2010-2011 Fog Creek Software |
|
4 | 4 | # Copyright 2010-2011 Unity Technologies |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2 or any later version. |
|
8 | 8 | |
|
9 | 9 | '''store class for local filesystem''' |
|
10 | 10 | |
|
11 | 11 | import os |
|
12 | 12 | |
|
13 | 13 | from mercurial import util |
|
14 | 14 | from mercurial.i18n import _ |
|
15 | 15 | |
|
16 | 16 | import lfutil |
|
17 | 17 | import basestore |
|
18 | 18 | |
|
19 | 19 | class localstore(basestore.basestore): |
|
20 | 20 | '''localstore first attempts to grab files out of the store in the remote |
|
21 | 21 | Mercurial repository. Failling that, it attempts to grab the files from |
|
22 | 22 | the user cache.''' |
|
23 | 23 | |
|
24 | 24 | def __init__(self, ui, repo, remote): |
|
25 | url = os.path.join(remote.path, '.hg', lfutil.longname) | |
|
25 | url = os.path.join(remote.local().path, '.hg', lfutil.longname) | |
|
26 | 26 | super(localstore, self).__init__(ui, repo, util.expandpath(url)) |
|
27 | self.remote = remote | |
|
27 | self.remote = remote.local() | |
|
28 | 28 | |
|
29 | 29 | def put(self, source, hash): |
|
30 | 30 | util.makedirs(os.path.dirname(lfutil.storepath(self.remote, hash))) |
|
31 | 31 | if lfutil.instore(self.remote, hash): |
|
32 | 32 | return |
|
33 | 33 | lfutil.link(lfutil.storepath(self.repo, hash), |
|
34 | 34 | lfutil.storepath(self.remote, hash)) |
|
35 | 35 | |
|
36 | 36 | def exists(self, hash): |
|
37 | 37 | return lfutil.instore(self.remote, hash) |
|
38 | 38 | |
|
39 | 39 | def _getfile(self, tmpfile, filename, hash): |
|
40 | 40 | if lfutil.instore(self.remote, hash): |
|
41 | 41 | path = lfutil.storepath(self.remote, hash) |
|
42 | 42 | elif lfutil.inusercache(self.ui, hash): |
|
43 | 43 | path = lfutil.usercachepath(self.ui, hash) |
|
44 | 44 | else: |
|
45 | 45 | raise basestore.StoreError(filename, hash, '', |
|
46 | 46 | _("can't get file locally")) |
|
47 | 47 | fd = open(path, 'rb') |
|
48 | 48 | try: |
|
49 | 49 | return lfutil.copyandhash(fd, tmpfile) |
|
50 | 50 | finally: |
|
51 | 51 | fd.close() |
|
52 | 52 | |
|
53 | 53 | def _verifyfile(self, cctx, cset, contents, standin, verified): |
|
54 | 54 | filename = lfutil.splitstandin(standin) |
|
55 | 55 | if not filename: |
|
56 | 56 | return False |
|
57 | 57 | fctx = cctx[standin] |
|
58 | 58 | key = (filename, fctx.filenode()) |
|
59 | 59 | if key in verified: |
|
60 | 60 | return False |
|
61 | 61 | |
|
62 | 62 | expecthash = fctx.data()[0:40] |
|
63 | 63 | verified.add(key) |
|
64 | 64 | if not lfutil.instore(self.remote, expecthash): |
|
65 | 65 | self.ui.warn( |
|
66 | 66 | _('changeset %s: %s missing\n' |
|
67 | 67 | ' (looked for hash %s)\n') |
|
68 | 68 | % (cset, filename, expecthash)) |
|
69 | 69 | return True # failed |
|
70 | 70 | |
|
71 | 71 | if contents: |
|
72 | 72 | storepath = lfutil.storepath(self.remote, expecthash) |
|
73 | 73 | actualhash = lfutil.hashfile(storepath) |
|
74 | 74 | if actualhash != expecthash: |
|
75 | 75 | self.ui.warn( |
|
76 | 76 | _('changeset %s: %s: contents differ\n' |
|
77 | 77 | ' (%s:\n' |
|
78 | 78 | ' expected hash %s,\n' |
|
79 | 79 | ' but got %s)\n') |
|
80 | 80 | % (cset, filename, storepath, expecthash, actualhash)) |
|
81 | 81 | return True # failed |
|
82 | 82 | return False |
@@ -1,1072 +1,1072 | |||
|
1 | 1 | # Copyright 2009-2010 Gregory P. Ward |
|
2 | 2 | # Copyright 2009-2010 Intelerad Medical Systems Incorporated |
|
3 | 3 | # Copyright 2010-2011 Fog Creek Software |
|
4 | 4 | # Copyright 2010-2011 Unity Technologies |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2 or any later version. |
|
8 | 8 | |
|
9 | 9 | '''Overridden Mercurial commands and functions for the largefiles extension''' |
|
10 | 10 | |
|
11 | 11 | import os |
|
12 | 12 | import copy |
|
13 | 13 | |
|
14 | 14 | from mercurial import hg, commands, util, cmdutil, scmutil, match as match_, \ |
|
15 | 15 | node, archival, error, merge |
|
16 | 16 | from mercurial.i18n import _ |
|
17 | 17 | from mercurial.node import hex |
|
18 | 18 | from hgext import rebase |
|
19 | 19 | |
|
20 | 20 | import lfutil |
|
21 | 21 | import lfcommands |
|
22 | 22 | |
|
23 | 23 | # -- Utility functions: commonly/repeatedly needed functionality --------------- |
|
24 | 24 | |
|
25 | 25 | def installnormalfilesmatchfn(manifest): |
|
26 | 26 | '''overrides scmutil.match so that the matcher it returns will ignore all |
|
27 | 27 | largefiles''' |
|
28 | 28 | oldmatch = None # for the closure |
|
29 | 29 | def overridematch(ctx, pats=[], opts={}, globbed=False, |
|
30 | 30 | default='relpath'): |
|
31 | 31 | match = oldmatch(ctx, pats, opts, globbed, default) |
|
32 | 32 | m = copy.copy(match) |
|
33 | 33 | notlfile = lambda f: not (lfutil.isstandin(f) or lfutil.standin(f) in |
|
34 | 34 | manifest) |
|
35 | 35 | m._files = filter(notlfile, m._files) |
|
36 | 36 | m._fmap = set(m._files) |
|
37 | 37 | origmatchfn = m.matchfn |
|
38 | 38 | m.matchfn = lambda f: notlfile(f) and origmatchfn(f) or None |
|
39 | 39 | return m |
|
40 | 40 | oldmatch = installmatchfn(overridematch) |
|
41 | 41 | |
|
42 | 42 | def installmatchfn(f): |
|
43 | 43 | oldmatch = scmutil.match |
|
44 | 44 | setattr(f, 'oldmatch', oldmatch) |
|
45 | 45 | scmutil.match = f |
|
46 | 46 | return oldmatch |
|
47 | 47 | |
|
48 | 48 | def restorematchfn(): |
|
49 | 49 | '''restores scmutil.match to what it was before installnormalfilesmatchfn |
|
50 | 50 | was called. no-op if scmutil.match is its original function. |
|
51 | 51 | |
|
52 | 52 | Note that n calls to installnormalfilesmatchfn will require n calls to |
|
53 | 53 | restore matchfn to reverse''' |
|
54 | 54 | scmutil.match = getattr(scmutil.match, 'oldmatch', scmutil.match) |
|
55 | 55 | |
|
56 | 56 | def addlargefiles(ui, repo, *pats, **opts): |
|
57 | 57 | large = opts.pop('large', None) |
|
58 | 58 | lfsize = lfutil.getminsize( |
|
59 | 59 | ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None)) |
|
60 | 60 | |
|
61 | 61 | lfmatcher = None |
|
62 | 62 | if lfutil.islfilesrepo(repo): |
|
63 | 63 | lfpats = ui.configlist(lfutil.longname, 'patterns', default=[]) |
|
64 | 64 | if lfpats: |
|
65 | 65 | lfmatcher = match_.match(repo.root, '', list(lfpats)) |
|
66 | 66 | |
|
67 | 67 | lfnames = [] |
|
68 | 68 | m = scmutil.match(repo[None], pats, opts) |
|
69 | 69 | m.bad = lambda x, y: None |
|
70 | 70 | wctx = repo[None] |
|
71 | 71 | for f in repo.walk(m): |
|
72 | 72 | exact = m.exact(f) |
|
73 | 73 | lfile = lfutil.standin(f) in wctx |
|
74 | 74 | nfile = f in wctx |
|
75 | 75 | exists = lfile or nfile |
|
76 | 76 | |
|
77 | 77 | # Don't warn the user when they attempt to add a normal tracked file. |
|
78 | 78 | # The normal add code will do that for us. |
|
79 | 79 | if exact and exists: |
|
80 | 80 | if lfile: |
|
81 | 81 | ui.warn(_('%s already a largefile\n') % f) |
|
82 | 82 | continue |
|
83 | 83 | |
|
84 | 84 | if exact or not exists: |
|
85 | 85 | abovemin = (lfsize and |
|
86 | 86 | os.lstat(repo.wjoin(f)).st_size >= lfsize * 1024 * 1024) |
|
87 | 87 | if large or abovemin or (lfmatcher and lfmatcher(f)): |
|
88 | 88 | lfnames.append(f) |
|
89 | 89 | if ui.verbose or not exact: |
|
90 | 90 | ui.status(_('adding %s as a largefile\n') % m.rel(f)) |
|
91 | 91 | |
|
92 | 92 | bad = [] |
|
93 | 93 | standins = [] |
|
94 | 94 | |
|
95 | 95 | # Need to lock, otherwise there could be a race condition between |
|
96 | 96 | # when standins are created and added to the repo. |
|
97 | 97 | wlock = repo.wlock() |
|
98 | 98 | try: |
|
99 | 99 | if not opts.get('dry_run'): |
|
100 | 100 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
101 | 101 | for f in lfnames: |
|
102 | 102 | standinname = lfutil.standin(f) |
|
103 | 103 | lfutil.writestandin(repo, standinname, hash='', |
|
104 | 104 | executable=lfutil.getexecutable(repo.wjoin(f))) |
|
105 | 105 | standins.append(standinname) |
|
106 | 106 | if lfdirstate[f] == 'r': |
|
107 | 107 | lfdirstate.normallookup(f) |
|
108 | 108 | else: |
|
109 | 109 | lfdirstate.add(f) |
|
110 | 110 | lfdirstate.write() |
|
111 | 111 | bad += [lfutil.splitstandin(f) |
|
112 | 112 | for f in lfutil.repoadd(repo, standins) |
|
113 | 113 | if f in m.files()] |
|
114 | 114 | finally: |
|
115 | 115 | wlock.release() |
|
116 | 116 | return bad |
|
117 | 117 | |
|
118 | 118 | def removelargefiles(ui, repo, *pats, **opts): |
|
119 | 119 | after = opts.get('after') |
|
120 | 120 | if not pats and not after: |
|
121 | 121 | raise util.Abort(_('no files specified')) |
|
122 | 122 | m = scmutil.match(repo[None], pats, opts) |
|
123 | 123 | try: |
|
124 | 124 | repo.lfstatus = True |
|
125 | 125 | s = repo.status(match=m, clean=True) |
|
126 | 126 | finally: |
|
127 | 127 | repo.lfstatus = False |
|
128 | 128 | manifest = repo[None].manifest() |
|
129 | 129 | modified, added, deleted, clean = [[f for f in list |
|
130 | 130 | if lfutil.standin(f) in manifest] |
|
131 | 131 | for list in [s[0], s[1], s[3], s[6]]] |
|
132 | 132 | |
|
133 | 133 | def warn(files, reason): |
|
134 | 134 | for f in files: |
|
135 | 135 | ui.warn(_('not removing %s: %s (use forget to undo)\n') |
|
136 | 136 | % (m.rel(f), reason)) |
|
137 | 137 | |
|
138 | 138 | if after: |
|
139 | 139 | remove, forget = deleted, [] |
|
140 | 140 | warn(modified + added + clean, _('file still exists')) |
|
141 | 141 | else: |
|
142 | 142 | remove, forget = deleted + clean, [] |
|
143 | 143 | warn(modified, _('file is modified')) |
|
144 | 144 | warn(added, _('file has been marked for add')) |
|
145 | 145 | |
|
146 | 146 | for f in sorted(remove + forget): |
|
147 | 147 | if ui.verbose or not m.exact(f): |
|
148 | 148 | ui.status(_('removing %s\n') % m.rel(f)) |
|
149 | 149 | |
|
150 | 150 | # Need to lock because standin files are deleted then removed from the |
|
151 | 151 | # repository and we could race inbetween. |
|
152 | 152 | wlock = repo.wlock() |
|
153 | 153 | try: |
|
154 | 154 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
155 | 155 | for f in remove: |
|
156 | 156 | if not after: |
|
157 | 157 | # If this is being called by addremove, notify the user that we |
|
158 | 158 | # are removing the file. |
|
159 | 159 | if getattr(repo, "_isaddremove", False): |
|
160 | 160 | ui.status(_('removing %s\n') % f) |
|
161 | 161 | if os.path.exists(repo.wjoin(f)): |
|
162 | 162 | util.unlinkpath(repo.wjoin(f)) |
|
163 | 163 | lfdirstate.remove(f) |
|
164 | 164 | lfdirstate.write() |
|
165 | 165 | forget = [lfutil.standin(f) for f in forget] |
|
166 | 166 | remove = [lfutil.standin(f) for f in remove] |
|
167 | 167 | lfutil.repoforget(repo, forget) |
|
168 | 168 | # If this is being called by addremove, let the original addremove |
|
169 | 169 | # function handle this. |
|
170 | 170 | if not getattr(repo, "_isaddremove", False): |
|
171 | 171 | lfutil.reporemove(repo, remove, unlink=True) |
|
172 | 172 | else: |
|
173 | 173 | lfutil.reporemove(repo, remove, unlink=False) |
|
174 | 174 | finally: |
|
175 | 175 | wlock.release() |
|
176 | 176 | |
|
177 | 177 | # For overriding mercurial.hgweb.webcommands so that largefiles will |
|
178 | 178 | # appear at their right place in the manifests. |
|
179 | 179 | def decodepath(orig, path): |
|
180 | 180 | return lfutil.splitstandin(path) or path |
|
181 | 181 | |
|
182 | 182 | # -- Wrappers: modify existing commands -------------------------------- |
|
183 | 183 | |
|
184 | 184 | # Add works by going through the files that the user wanted to add and |
|
185 | 185 | # checking if they should be added as largefiles. Then it makes a new |
|
186 | 186 | # matcher which matches only the normal files and runs the original |
|
187 | 187 | # version of add. |
|
188 | 188 | def overrideadd(orig, ui, repo, *pats, **opts): |
|
189 | 189 | normal = opts.pop('normal') |
|
190 | 190 | if normal: |
|
191 | 191 | if opts.get('large'): |
|
192 | 192 | raise util.Abort(_('--normal cannot be used with --large')) |
|
193 | 193 | return orig(ui, repo, *pats, **opts) |
|
194 | 194 | bad = addlargefiles(ui, repo, *pats, **opts) |
|
195 | 195 | installnormalfilesmatchfn(repo[None].manifest()) |
|
196 | 196 | result = orig(ui, repo, *pats, **opts) |
|
197 | 197 | restorematchfn() |
|
198 | 198 | |
|
199 | 199 | return (result == 1 or bad) and 1 or 0 |
|
200 | 200 | |
|
201 | 201 | def overrideremove(orig, ui, repo, *pats, **opts): |
|
202 | 202 | installnormalfilesmatchfn(repo[None].manifest()) |
|
203 | 203 | orig(ui, repo, *pats, **opts) |
|
204 | 204 | restorematchfn() |
|
205 | 205 | removelargefiles(ui, repo, *pats, **opts) |
|
206 | 206 | |
|
207 | 207 | def overridestatusfn(orig, repo, rev2, **opts): |
|
208 | 208 | try: |
|
209 | 209 | repo._repo.lfstatus = True |
|
210 | 210 | return orig(repo, rev2, **opts) |
|
211 | 211 | finally: |
|
212 | 212 | repo._repo.lfstatus = False |
|
213 | 213 | |
|
214 | 214 | def overridestatus(orig, ui, repo, *pats, **opts): |
|
215 | 215 | try: |
|
216 | 216 | repo.lfstatus = True |
|
217 | 217 | return orig(ui, repo, *pats, **opts) |
|
218 | 218 | finally: |
|
219 | 219 | repo.lfstatus = False |
|
220 | 220 | |
|
221 | 221 | def overridedirty(orig, repo, ignoreupdate=False): |
|
222 | 222 | try: |
|
223 | 223 | repo._repo.lfstatus = True |
|
224 | 224 | return orig(repo, ignoreupdate) |
|
225 | 225 | finally: |
|
226 | 226 | repo._repo.lfstatus = False |
|
227 | 227 | |
|
228 | 228 | def overridelog(orig, ui, repo, *pats, **opts): |
|
229 | 229 | try: |
|
230 | 230 | repo.lfstatus = True |
|
231 | 231 | orig(ui, repo, *pats, **opts) |
|
232 | 232 | finally: |
|
233 | 233 | repo.lfstatus = False |
|
234 | 234 | |
|
235 | 235 | def overrideverify(orig, ui, repo, *pats, **opts): |
|
236 | 236 | large = opts.pop('large', False) |
|
237 | 237 | all = opts.pop('lfa', False) |
|
238 | 238 | contents = opts.pop('lfc', False) |
|
239 | 239 | |
|
240 | 240 | result = orig(ui, repo, *pats, **opts) |
|
241 | 241 | if large: |
|
242 | 242 | result = result or lfcommands.verifylfiles(ui, repo, all, contents) |
|
243 | 243 | return result |
|
244 | 244 | |
|
245 | 245 | # Override needs to refresh standins so that update's normal merge |
|
246 | 246 | # will go through properly. Then the other update hook (overriding repo.update) |
|
247 | 247 | # will get the new files. Filemerge is also overriden so that the merge |
|
248 | 248 | # will merge standins correctly. |
|
249 | 249 | def overrideupdate(orig, ui, repo, *pats, **opts): |
|
250 | 250 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
251 | 251 | s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False, |
|
252 | 252 | False, False) |
|
253 | 253 | (unsure, modified, added, removed, missing, unknown, ignored, clean) = s |
|
254 | 254 | |
|
255 | 255 | # Need to lock between the standins getting updated and their |
|
256 | 256 | # largefiles getting updated |
|
257 | 257 | wlock = repo.wlock() |
|
258 | 258 | try: |
|
259 | 259 | if opts['check']: |
|
260 | 260 | mod = len(modified) > 0 |
|
261 | 261 | for lfile in unsure: |
|
262 | 262 | standin = lfutil.standin(lfile) |
|
263 | 263 | if repo['.'][standin].data().strip() != \ |
|
264 | 264 | lfutil.hashfile(repo.wjoin(lfile)): |
|
265 | 265 | mod = True |
|
266 | 266 | else: |
|
267 | 267 | lfdirstate.normal(lfile) |
|
268 | 268 | lfdirstate.write() |
|
269 | 269 | if mod: |
|
270 | 270 | raise util.Abort(_('uncommitted local changes')) |
|
271 | 271 | # XXX handle removed differently |
|
272 | 272 | if not opts['clean']: |
|
273 | 273 | for lfile in unsure + modified + added: |
|
274 | 274 | lfutil.updatestandin(repo, lfutil.standin(lfile)) |
|
275 | 275 | finally: |
|
276 | 276 | wlock.release() |
|
277 | 277 | return orig(ui, repo, *pats, **opts) |
|
278 | 278 | |
|
279 | 279 | # Before starting the manifest merge, merge.updates will call |
|
280 | 280 | # _checkunknown to check if there are any files in the merged-in |
|
281 | 281 | # changeset that collide with unknown files in the working copy. |
|
282 | 282 | # |
|
283 | 283 | # The largefiles are seen as unknown, so this prevents us from merging |
|
284 | 284 | # in a file 'foo' if we already have a largefile with the same name. |
|
285 | 285 | # |
|
286 | 286 | # The overridden function filters the unknown files by removing any |
|
287 | 287 | # largefiles. This makes the merge proceed and we can then handle this |
|
288 | 288 | # case further in the overridden manifestmerge function below. |
|
289 | 289 | def overridecheckunknownfile(origfn, repo, wctx, mctx, f): |
|
290 | 290 | if lfutil.standin(f) in wctx: |
|
291 | 291 | return False |
|
292 | 292 | return origfn(repo, wctx, mctx, f) |
|
293 | 293 | |
|
294 | 294 | # The manifest merge handles conflicts on the manifest level. We want |
|
295 | 295 | # to handle changes in largefile-ness of files at this level too. |
|
296 | 296 | # |
|
297 | 297 | # The strategy is to run the original manifestmerge and then process |
|
298 | 298 | # the action list it outputs. There are two cases we need to deal with: |
|
299 | 299 | # |
|
300 | 300 | # 1. Normal file in p1, largefile in p2. Here the largefile is |
|
301 | 301 | # detected via its standin file, which will enter the working copy |
|
302 | 302 | # with a "get" action. It is not "merge" since the standin is all |
|
303 | 303 | # Mercurial is concerned with at this level -- the link to the |
|
304 | 304 | # existing normal file is not relevant here. |
|
305 | 305 | # |
|
306 | 306 | # 2. Largefile in p1, normal file in p2. Here we get a "merge" action |
|
307 | 307 | # since the largefile will be present in the working copy and |
|
308 | 308 | # different from the normal file in p2. Mercurial therefore |
|
309 | 309 | # triggers a merge action. |
|
310 | 310 | # |
|
311 | 311 | # In both cases, we prompt the user and emit new actions to either |
|
312 | 312 | # remove the standin (if the normal file was kept) or to remove the |
|
313 | 313 | # normal file and get the standin (if the largefile was kept). The |
|
314 | 314 | # default prompt answer is to use the largefile version since it was |
|
315 | 315 | # presumably changed on purpose. |
|
316 | 316 | # |
|
317 | 317 | # Finally, the merge.applyupdates function will then take care of |
|
318 | 318 | # writing the files into the working copy and lfcommands.updatelfiles |
|
319 | 319 | # will update the largefiles. |
|
320 | 320 | def overridemanifestmerge(origfn, repo, p1, p2, pa, overwrite, partial): |
|
321 | 321 | actions = origfn(repo, p1, p2, pa, overwrite, partial) |
|
322 | 322 | processed = [] |
|
323 | 323 | |
|
324 | 324 | for action in actions: |
|
325 | 325 | if overwrite: |
|
326 | 326 | processed.append(action) |
|
327 | 327 | continue |
|
328 | 328 | f, m = action[:2] |
|
329 | 329 | |
|
330 | 330 | choices = (_('&Largefile'), _('&Normal file')) |
|
331 | 331 | if m == "g" and lfutil.splitstandin(f) in p1 and f in p2: |
|
332 | 332 | # Case 1: normal file in the working copy, largefile in |
|
333 | 333 | # the second parent |
|
334 | 334 | lfile = lfutil.splitstandin(f) |
|
335 | 335 | standin = f |
|
336 | 336 | msg = _('%s has been turned into a largefile\n' |
|
337 | 337 | 'use (l)argefile or keep as (n)ormal file?') % lfile |
|
338 | 338 | if repo.ui.promptchoice(msg, choices, 0) == 0: |
|
339 | 339 | processed.append((lfile, "r")) |
|
340 | 340 | processed.append((standin, "g", p2.flags(standin))) |
|
341 | 341 | else: |
|
342 | 342 | processed.append((standin, "r")) |
|
343 | 343 | elif m == "g" and lfutil.standin(f) in p1 and f in p2: |
|
344 | 344 | # Case 2: largefile in the working copy, normal file in |
|
345 | 345 | # the second parent |
|
346 | 346 | standin = lfutil.standin(f) |
|
347 | 347 | lfile = f |
|
348 | 348 | msg = _('%s has been turned into a normal file\n' |
|
349 | 349 | 'keep as (l)argefile or use (n)ormal file?') % lfile |
|
350 | 350 | if repo.ui.promptchoice(msg, choices, 0) == 0: |
|
351 | 351 | processed.append((lfile, "r")) |
|
352 | 352 | else: |
|
353 | 353 | processed.append((standin, "r")) |
|
354 | 354 | processed.append((lfile, "g", p2.flags(lfile))) |
|
355 | 355 | else: |
|
356 | 356 | processed.append(action) |
|
357 | 357 | |
|
358 | 358 | return processed |
|
359 | 359 | |
|
360 | 360 | # Override filemerge to prompt the user about how they wish to merge |
|
361 | 361 | # largefiles. This will handle identical edits, and copy/rename + |
|
362 | 362 | # edit without prompting the user. |
|
363 | 363 | def overridefilemerge(origfn, repo, mynode, orig, fcd, fco, fca): |
|
364 | 364 | # Use better variable names here. Because this is a wrapper we cannot |
|
365 | 365 | # change the variable names in the function declaration. |
|
366 | 366 | fcdest, fcother, fcancestor = fcd, fco, fca |
|
367 | 367 | if not lfutil.isstandin(orig): |
|
368 | 368 | return origfn(repo, mynode, orig, fcdest, fcother, fcancestor) |
|
369 | 369 | else: |
|
370 | 370 | if not fcother.cmp(fcdest): # files identical? |
|
371 | 371 | return None |
|
372 | 372 | |
|
373 | 373 | # backwards, use working dir parent as ancestor |
|
374 | 374 | if fcancestor == fcother: |
|
375 | 375 | fcancestor = fcdest.parents()[0] |
|
376 | 376 | |
|
377 | 377 | if orig != fcother.path(): |
|
378 | 378 | repo.ui.status(_('merging %s and %s to %s\n') |
|
379 | 379 | % (lfutil.splitstandin(orig), |
|
380 | 380 | lfutil.splitstandin(fcother.path()), |
|
381 | 381 | lfutil.splitstandin(fcdest.path()))) |
|
382 | 382 | else: |
|
383 | 383 | repo.ui.status(_('merging %s\n') |
|
384 | 384 | % lfutil.splitstandin(fcdest.path())) |
|
385 | 385 | |
|
386 | 386 | if fcancestor.path() != fcother.path() and fcother.data() == \ |
|
387 | 387 | fcancestor.data(): |
|
388 | 388 | return 0 |
|
389 | 389 | if fcancestor.path() != fcdest.path() and fcdest.data() == \ |
|
390 | 390 | fcancestor.data(): |
|
391 | 391 | repo.wwrite(fcdest.path(), fcother.data(), fcother.flags()) |
|
392 | 392 | return 0 |
|
393 | 393 | |
|
394 | 394 | if repo.ui.promptchoice(_('largefile %s has a merge conflict\n' |
|
395 | 395 | 'keep (l)ocal or take (o)ther?') % |
|
396 | 396 | lfutil.splitstandin(orig), |
|
397 | 397 | (_('&Local'), _('&Other')), 0) == 0: |
|
398 | 398 | return 0 |
|
399 | 399 | else: |
|
400 | 400 | repo.wwrite(fcdest.path(), fcother.data(), fcother.flags()) |
|
401 | 401 | return 0 |
|
402 | 402 | |
|
403 | 403 | # Copy first changes the matchers to match standins instead of |
|
404 | 404 | # largefiles. Then it overrides util.copyfile in that function it |
|
405 | 405 | # checks if the destination largefile already exists. It also keeps a |
|
406 | 406 | # list of copied files so that the largefiles can be copied and the |
|
407 | 407 | # dirstate updated. |
|
408 | 408 | def overridecopy(orig, ui, repo, pats, opts, rename=False): |
|
409 | 409 | # doesn't remove largefile on rename |
|
410 | 410 | if len(pats) < 2: |
|
411 | 411 | # this isn't legal, let the original function deal with it |
|
412 | 412 | return orig(ui, repo, pats, opts, rename) |
|
413 | 413 | |
|
414 | 414 | def makestandin(relpath): |
|
415 | 415 | path = scmutil.canonpath(repo.root, repo.getcwd(), relpath) |
|
416 | 416 | return os.path.join(repo.wjoin(lfutil.standin(path))) |
|
417 | 417 | |
|
418 | 418 | fullpats = scmutil.expandpats(pats) |
|
419 | 419 | dest = fullpats[-1] |
|
420 | 420 | |
|
421 | 421 | if os.path.isdir(dest): |
|
422 | 422 | if not os.path.isdir(makestandin(dest)): |
|
423 | 423 | os.makedirs(makestandin(dest)) |
|
424 | 424 | # This could copy both lfiles and normal files in one command, |
|
425 | 425 | # but we don't want to do that. First replace their matcher to |
|
426 | 426 | # only match normal files and run it, then replace it to just |
|
427 | 427 | # match largefiles and run it again. |
|
428 | 428 | nonormalfiles = False |
|
429 | 429 | nolfiles = False |
|
430 | 430 | try: |
|
431 | 431 | try: |
|
432 | 432 | installnormalfilesmatchfn(repo[None].manifest()) |
|
433 | 433 | result = orig(ui, repo, pats, opts, rename) |
|
434 | 434 | except util.Abort, e: |
|
435 | 435 | if str(e) != 'no files to copy': |
|
436 | 436 | raise e |
|
437 | 437 | else: |
|
438 | 438 | nonormalfiles = True |
|
439 | 439 | result = 0 |
|
440 | 440 | finally: |
|
441 | 441 | restorematchfn() |
|
442 | 442 | |
|
443 | 443 | # The first rename can cause our current working directory to be removed. |
|
444 | 444 | # In that case there is nothing left to copy/rename so just quit. |
|
445 | 445 | try: |
|
446 | 446 | repo.getcwd() |
|
447 | 447 | except OSError: |
|
448 | 448 | return result |
|
449 | 449 | |
|
450 | 450 | try: |
|
451 | 451 | try: |
|
452 | 452 | # When we call orig below it creates the standins but we don't add |
|
453 | 453 | # them to the dir state until later so lock during that time. |
|
454 | 454 | wlock = repo.wlock() |
|
455 | 455 | |
|
456 | 456 | manifest = repo[None].manifest() |
|
457 | 457 | oldmatch = None # for the closure |
|
458 | 458 | def overridematch(ctx, pats=[], opts={}, globbed=False, |
|
459 | 459 | default='relpath'): |
|
460 | 460 | newpats = [] |
|
461 | 461 | # The patterns were previously mangled to add the standin |
|
462 | 462 | # directory; we need to remove that now |
|
463 | 463 | for pat in pats: |
|
464 | 464 | if match_.patkind(pat) is None and lfutil.shortname in pat: |
|
465 | 465 | newpats.append(pat.replace(lfutil.shortname, '')) |
|
466 | 466 | else: |
|
467 | 467 | newpats.append(pat) |
|
468 | 468 | match = oldmatch(ctx, newpats, opts, globbed, default) |
|
469 | 469 | m = copy.copy(match) |
|
470 | 470 | lfile = lambda f: lfutil.standin(f) in manifest |
|
471 | 471 | m._files = [lfutil.standin(f) for f in m._files if lfile(f)] |
|
472 | 472 | m._fmap = set(m._files) |
|
473 | 473 | origmatchfn = m.matchfn |
|
474 | 474 | m.matchfn = lambda f: (lfutil.isstandin(f) and |
|
475 | 475 | (f in manifest) and |
|
476 | 476 | origmatchfn(lfutil.splitstandin(f)) or |
|
477 | 477 | None) |
|
478 | 478 | return m |
|
479 | 479 | oldmatch = installmatchfn(overridematch) |
|
480 | 480 | listpats = [] |
|
481 | 481 | for pat in pats: |
|
482 | 482 | if match_.patkind(pat) is not None: |
|
483 | 483 | listpats.append(pat) |
|
484 | 484 | else: |
|
485 | 485 | listpats.append(makestandin(pat)) |
|
486 | 486 | |
|
487 | 487 | try: |
|
488 | 488 | origcopyfile = util.copyfile |
|
489 | 489 | copiedfiles = [] |
|
490 | 490 | def overridecopyfile(src, dest): |
|
491 | 491 | if (lfutil.shortname in src and |
|
492 | 492 | dest.startswith(repo.wjoin(lfutil.shortname))): |
|
493 | 493 | destlfile = dest.replace(lfutil.shortname, '') |
|
494 | 494 | if not opts['force'] and os.path.exists(destlfile): |
|
495 | 495 | raise IOError('', |
|
496 | 496 | _('destination largefile already exists')) |
|
497 | 497 | copiedfiles.append((src, dest)) |
|
498 | 498 | origcopyfile(src, dest) |
|
499 | 499 | |
|
500 | 500 | util.copyfile = overridecopyfile |
|
501 | 501 | result += orig(ui, repo, listpats, opts, rename) |
|
502 | 502 | finally: |
|
503 | 503 | util.copyfile = origcopyfile |
|
504 | 504 | |
|
505 | 505 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
506 | 506 | for (src, dest) in copiedfiles: |
|
507 | 507 | if (lfutil.shortname in src and |
|
508 | 508 | dest.startswith(repo.wjoin(lfutil.shortname))): |
|
509 | 509 | srclfile = src.replace(repo.wjoin(lfutil.standin('')), '') |
|
510 | 510 | destlfile = dest.replace(repo.wjoin(lfutil.standin('')), '') |
|
511 | 511 | destlfiledir = os.path.dirname(destlfile) or '.' |
|
512 | 512 | if not os.path.isdir(destlfiledir): |
|
513 | 513 | os.makedirs(destlfiledir) |
|
514 | 514 | if rename: |
|
515 | 515 | os.rename(repo.wjoin(srclfile), repo.wjoin(destlfile)) |
|
516 | 516 | lfdirstate.remove(srclfile) |
|
517 | 517 | else: |
|
518 | 518 | util.copyfile(srclfile, destlfile) |
|
519 | 519 | lfdirstate.add(destlfile) |
|
520 | 520 | lfdirstate.write() |
|
521 | 521 | except util.Abort, e: |
|
522 | 522 | if str(e) != 'no files to copy': |
|
523 | 523 | raise e |
|
524 | 524 | else: |
|
525 | 525 | nolfiles = True |
|
526 | 526 | finally: |
|
527 | 527 | restorematchfn() |
|
528 | 528 | wlock.release() |
|
529 | 529 | |
|
530 | 530 | if nolfiles and nonormalfiles: |
|
531 | 531 | raise util.Abort(_('no files to copy')) |
|
532 | 532 | |
|
533 | 533 | return result |
|
534 | 534 | |
|
535 | 535 | # When the user calls revert, we have to be careful to not revert any |
|
536 | 536 | # changes to other largefiles accidentally. This means we have to keep |
|
537 | 537 | # track of the largefiles that are being reverted so we only pull down |
|
538 | 538 | # the necessary largefiles. |
|
539 | 539 | # |
|
540 | 540 | # Standins are only updated (to match the hash of largefiles) before |
|
541 | 541 | # commits. Update the standins then run the original revert, changing |
|
542 | 542 | # the matcher to hit standins instead of largefiles. Based on the |
|
543 | 543 | # resulting standins update the largefiles. Then return the standins |
|
544 | 544 | # to their proper state |
|
545 | 545 | def overriderevert(orig, ui, repo, *pats, **opts): |
|
546 | 546 | # Because we put the standins in a bad state (by updating them) |
|
547 | 547 | # and then return them to a correct state we need to lock to |
|
548 | 548 | # prevent others from changing them in their incorrect state. |
|
549 | 549 | wlock = repo.wlock() |
|
550 | 550 | try: |
|
551 | 551 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
552 | 552 | (modified, added, removed, missing, unknown, ignored, clean) = \ |
|
553 | 553 | lfutil.lfdirstatestatus(lfdirstate, repo, repo['.'].rev()) |
|
554 | 554 | for lfile in modified: |
|
555 | 555 | lfutil.updatestandin(repo, lfutil.standin(lfile)) |
|
556 | 556 | for lfile in missing: |
|
557 | 557 | if (os.path.exists(repo.wjoin(lfutil.standin(lfile)))): |
|
558 | 558 | os.unlink(repo.wjoin(lfutil.standin(lfile))) |
|
559 | 559 | |
|
560 | 560 | try: |
|
561 | 561 | ctx = repo[opts.get('rev')] |
|
562 | 562 | oldmatch = None # for the closure |
|
563 | 563 | def overridematch(ctx, pats=[], opts={}, globbed=False, |
|
564 | 564 | default='relpath'): |
|
565 | 565 | match = oldmatch(ctx, pats, opts, globbed, default) |
|
566 | 566 | m = copy.copy(match) |
|
567 | 567 | def tostandin(f): |
|
568 | 568 | if lfutil.standin(f) in ctx: |
|
569 | 569 | return lfutil.standin(f) |
|
570 | 570 | elif lfutil.standin(f) in repo[None]: |
|
571 | 571 | return None |
|
572 | 572 | return f |
|
573 | 573 | m._files = [tostandin(f) for f in m._files] |
|
574 | 574 | m._files = [f for f in m._files if f is not None] |
|
575 | 575 | m._fmap = set(m._files) |
|
576 | 576 | origmatchfn = m.matchfn |
|
577 | 577 | def matchfn(f): |
|
578 | 578 | if lfutil.isstandin(f): |
|
579 | 579 | # We need to keep track of what largefiles are being |
|
580 | 580 | # matched so we know which ones to update later -- |
|
581 | 581 | # otherwise we accidentally revert changes to other |
|
582 | 582 | # largefiles. This is repo-specific, so duckpunch the |
|
583 | 583 | # repo object to keep the list of largefiles for us |
|
584 | 584 | # later. |
|
585 | 585 | if origmatchfn(lfutil.splitstandin(f)) and \ |
|
586 | 586 | (f in repo[None] or f in ctx): |
|
587 | 587 | lfileslist = getattr(repo, '_lfilestoupdate', []) |
|
588 | 588 | lfileslist.append(lfutil.splitstandin(f)) |
|
589 | 589 | repo._lfilestoupdate = lfileslist |
|
590 | 590 | return True |
|
591 | 591 | else: |
|
592 | 592 | return False |
|
593 | 593 | return origmatchfn(f) |
|
594 | 594 | m.matchfn = matchfn |
|
595 | 595 | return m |
|
596 | 596 | oldmatch = installmatchfn(overridematch) |
|
597 | 597 | scmutil.match |
|
598 | 598 | matches = overridematch(repo[None], pats, opts) |
|
599 | 599 | orig(ui, repo, *pats, **opts) |
|
600 | 600 | finally: |
|
601 | 601 | restorematchfn() |
|
602 | 602 | lfileslist = getattr(repo, '_lfilestoupdate', []) |
|
603 | 603 | lfcommands.updatelfiles(ui, repo, filelist=lfileslist, |
|
604 | 604 | printmessage=False) |
|
605 | 605 | |
|
606 | 606 | # empty out the largefiles list so we start fresh next time |
|
607 | 607 | repo._lfilestoupdate = [] |
|
608 | 608 | for lfile in modified: |
|
609 | 609 | if lfile in lfileslist: |
|
610 | 610 | if os.path.exists(repo.wjoin(lfutil.standin(lfile))) and lfile\ |
|
611 | 611 | in repo['.']: |
|
612 | 612 | lfutil.writestandin(repo, lfutil.standin(lfile), |
|
613 | 613 | repo['.'][lfile].data().strip(), |
|
614 | 614 | 'x' in repo['.'][lfile].flags()) |
|
615 | 615 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
616 | 616 | for lfile in added: |
|
617 | 617 | standin = lfutil.standin(lfile) |
|
618 | 618 | if standin not in ctx and (standin in matches or opts.get('all')): |
|
619 | 619 | if lfile in lfdirstate: |
|
620 | 620 | lfdirstate.drop(lfile) |
|
621 | 621 | util.unlinkpath(repo.wjoin(standin)) |
|
622 | 622 | lfdirstate.write() |
|
623 | 623 | finally: |
|
624 | 624 | wlock.release() |
|
625 | 625 | |
|
626 | 626 | def hgupdate(orig, repo, node): |
|
627 | 627 | # Only call updatelfiles the standins that have changed to save time |
|
628 | 628 | oldstandins = lfutil.getstandinsstate(repo) |
|
629 | 629 | result = orig(repo, node) |
|
630 | 630 | newstandins = lfutil.getstandinsstate(repo) |
|
631 | 631 | filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) |
|
632 | 632 | lfcommands.updatelfiles(repo.ui, repo, filelist=filelist, printmessage=True) |
|
633 | 633 | return result |
|
634 | 634 | |
|
635 | 635 | def hgclean(orig, repo, node, show_stats=True): |
|
636 | 636 | result = orig(repo, node, show_stats) |
|
637 | 637 | lfcommands.updatelfiles(repo.ui, repo) |
|
638 | 638 | return result |
|
639 | 639 | |
|
640 | 640 | def hgmerge(orig, repo, node, force=None, remind=True): |
|
641 | 641 | # Mark the repo as being in the middle of a merge, so that |
|
642 | 642 | # updatelfiles() will know that it needs to trust the standins in |
|
643 | 643 | # the working copy, not in the standins in the current node |
|
644 | 644 | repo._ismerging = True |
|
645 | 645 | try: |
|
646 | 646 | result = orig(repo, node, force, remind) |
|
647 | 647 | lfcommands.updatelfiles(repo.ui, repo) |
|
648 | 648 | finally: |
|
649 | 649 | repo._ismerging = False |
|
650 | 650 | return result |
|
651 | 651 | |
|
652 | 652 | # When we rebase a repository with remotely changed largefiles, we need to |
|
653 | 653 | # take some extra care so that the largefiles are correctly updated in the |
|
654 | 654 | # working copy |
|
655 | 655 | def overridepull(orig, ui, repo, source=None, **opts): |
|
656 | 656 | revsprepull = len(repo) |
|
657 | 657 | if opts.get('rebase', False): |
|
658 | 658 | repo._isrebasing = True |
|
659 | 659 | try: |
|
660 | 660 | if opts.get('update'): |
|
661 | 661 | del opts['update'] |
|
662 | 662 | ui.debug('--update and --rebase are not compatible, ignoring ' |
|
663 | 663 | 'the update flag\n') |
|
664 | 664 | del opts['rebase'] |
|
665 | 665 | cmdutil.bailifchanged(repo) |
|
666 | 666 | origpostincoming = commands.postincoming |
|
667 | 667 | def _dummy(*args, **kwargs): |
|
668 | 668 | pass |
|
669 | 669 | commands.postincoming = _dummy |
|
670 | 670 | repo.lfpullsource = source |
|
671 | 671 | if not source: |
|
672 | 672 | source = 'default' |
|
673 | 673 | try: |
|
674 | 674 | result = commands.pull(ui, repo, source, **opts) |
|
675 | 675 | finally: |
|
676 | 676 | commands.postincoming = origpostincoming |
|
677 | 677 | revspostpull = len(repo) |
|
678 | 678 | if revspostpull > revsprepull: |
|
679 | 679 | result = result or rebase.rebase(ui, repo) |
|
680 | 680 | finally: |
|
681 | 681 | repo._isrebasing = False |
|
682 | 682 | else: |
|
683 | 683 | repo.lfpullsource = source |
|
684 | 684 | if not source: |
|
685 | 685 | source = 'default' |
|
686 | 686 | oldheads = lfutil.getcurrentheads(repo) |
|
687 | 687 | result = orig(ui, repo, source, **opts) |
|
688 | 688 | # If we do not have the new largefiles for any new heads we pulled, we |
|
689 | 689 | # will run into a problem later if we try to merge or rebase with one of |
|
690 | 690 | # these heads, so cache the largefiles now direclty into the system |
|
691 | 691 | # cache. |
|
692 | 692 | ui.status(_("caching new largefiles\n")) |
|
693 | 693 | numcached = 0 |
|
694 | 694 | heads = lfutil.getcurrentheads(repo) |
|
695 | 695 | newheads = set(heads).difference(set(oldheads)) |
|
696 | 696 | for head in newheads: |
|
697 | 697 | (cached, missing) = lfcommands.cachelfiles(ui, repo, head) |
|
698 | 698 | numcached += len(cached) |
|
699 | 699 | ui.status(_("%d largefiles cached\n") % numcached) |
|
700 | 700 | if opts.get('all_largefiles'): |
|
701 | 701 | revspostpull = len(repo) |
|
702 | 702 | revs = [] |
|
703 | 703 | for rev in xrange(revsprepull + 1, revspostpull): |
|
704 | 704 | revs.append(repo[rev].rev()) |
|
705 | 705 | lfcommands.downloadlfiles(ui, repo, revs) |
|
706 | 706 | return result |
|
707 | 707 | |
|
708 | 708 | def overrideclone(orig, ui, source, dest=None, **opts): |
|
709 | 709 | if dest is None: |
|
710 | 710 | dest = hg.defaultdest(source) |
|
711 | 711 | if opts.get('all_largefiles') and not hg.islocal(dest): |
|
712 | 712 | raise util.Abort(_( |
|
713 | 713 | '--all-largefiles is incompatible with non-local destination %s' % |
|
714 | 714 | dest)) |
|
715 | 715 | result = hg.clone(ui, opts, source, dest, |
|
716 | 716 | pull=opts.get('pull'), |
|
717 | 717 | stream=opts.get('uncompressed'), |
|
718 | 718 | rev=opts.get('rev'), |
|
719 | 719 | update=True, # required for successful walkchangerevs |
|
720 | 720 | branch=opts.get('branch')) |
|
721 | 721 | if result is None: |
|
722 | 722 | return True |
|
723 | 723 | if opts.get('all_largefiles'): |
|
724 | 724 | sourcerepo, destrepo = result |
|
725 | success, missing = lfcommands.downloadlfiles(ui, destrepo, None) | |
|
725 | success, missing = lfcommands.downloadlfiles(ui, destrepo.local(), None) | |
|
726 | 726 | return missing != 0 |
|
727 | 727 | return result is None |
|
728 | 728 | |
|
729 | 729 | def overriderebase(orig, ui, repo, **opts): |
|
730 | 730 | repo._isrebasing = True |
|
731 | 731 | try: |
|
732 | 732 | orig(ui, repo, **opts) |
|
733 | 733 | finally: |
|
734 | 734 | repo._isrebasing = False |
|
735 | 735 | |
|
736 | 736 | def overridearchive(orig, repo, dest, node, kind, decode=True, matchfn=None, |
|
737 | 737 | prefix=None, mtime=None, subrepos=None): |
|
738 | 738 | # No need to lock because we are only reading history and |
|
739 | 739 | # largefile caches, neither of which are modified. |
|
740 | 740 | lfcommands.cachelfiles(repo.ui, repo, node) |
|
741 | 741 | |
|
742 | 742 | if kind not in archival.archivers: |
|
743 | 743 | raise util.Abort(_("unknown archive type '%s'") % kind) |
|
744 | 744 | |
|
745 | 745 | ctx = repo[node] |
|
746 | 746 | |
|
747 | 747 | if kind == 'files': |
|
748 | 748 | if prefix: |
|
749 | 749 | raise util.Abort( |
|
750 | 750 | _('cannot give prefix when archiving to files')) |
|
751 | 751 | else: |
|
752 | 752 | prefix = archival.tidyprefix(dest, kind, prefix) |
|
753 | 753 | |
|
754 | 754 | def write(name, mode, islink, getdata): |
|
755 | 755 | if matchfn and not matchfn(name): |
|
756 | 756 | return |
|
757 | 757 | data = getdata() |
|
758 | 758 | if decode: |
|
759 | 759 | data = repo.wwritedata(name, data) |
|
760 | 760 | archiver.addfile(prefix + name, mode, islink, data) |
|
761 | 761 | |
|
762 | 762 | archiver = archival.archivers[kind](dest, mtime or ctx.date()[0]) |
|
763 | 763 | |
|
764 | 764 | if repo.ui.configbool("ui", "archivemeta", True): |
|
765 | 765 | def metadata(): |
|
766 | 766 | base = 'repo: %s\nnode: %s\nbranch: %s\n' % ( |
|
767 | 767 | hex(repo.changelog.node(0)), hex(node), ctx.branch()) |
|
768 | 768 | |
|
769 | 769 | tags = ''.join('tag: %s\n' % t for t in ctx.tags() |
|
770 | 770 | if repo.tagtype(t) == 'global') |
|
771 | 771 | if not tags: |
|
772 | 772 | repo.ui.pushbuffer() |
|
773 | 773 | opts = {'template': '{latesttag}\n{latesttagdistance}', |
|
774 | 774 | 'style': '', 'patch': None, 'git': None} |
|
775 | 775 | cmdutil.show_changeset(repo.ui, repo, opts).show(ctx) |
|
776 | 776 | ltags, dist = repo.ui.popbuffer().split('\n') |
|
777 | 777 | tags = ''.join('latesttag: %s\n' % t for t in ltags.split(':')) |
|
778 | 778 | tags += 'latesttagdistance: %s\n' % dist |
|
779 | 779 | |
|
780 | 780 | return base + tags |
|
781 | 781 | |
|
782 | 782 | write('.hg_archival.txt', 0644, False, metadata) |
|
783 | 783 | |
|
784 | 784 | for f in ctx: |
|
785 | 785 | ff = ctx.flags(f) |
|
786 | 786 | getdata = ctx[f].data |
|
787 | 787 | if lfutil.isstandin(f): |
|
788 | 788 | path = lfutil.findfile(repo, getdata().strip()) |
|
789 | 789 | if path is None: |
|
790 | 790 | raise util.Abort( |
|
791 | 791 | _('largefile %s not found in repo store or system cache') |
|
792 | 792 | % lfutil.splitstandin(f)) |
|
793 | 793 | f = lfutil.splitstandin(f) |
|
794 | 794 | |
|
795 | 795 | def getdatafn(): |
|
796 | 796 | fd = None |
|
797 | 797 | try: |
|
798 | 798 | fd = open(path, 'rb') |
|
799 | 799 | return fd.read() |
|
800 | 800 | finally: |
|
801 | 801 | if fd: |
|
802 | 802 | fd.close() |
|
803 | 803 | |
|
804 | 804 | getdata = getdatafn |
|
805 | 805 | write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata) |
|
806 | 806 | |
|
807 | 807 | if subrepos: |
|
808 | 808 | for subpath in ctx.substate: |
|
809 | 809 | sub = ctx.sub(subpath) |
|
810 | 810 | submatch = match_.narrowmatcher(subpath, matchfn) |
|
811 | 811 | sub.archive(repo.ui, archiver, prefix, submatch) |
|
812 | 812 | |
|
813 | 813 | archiver.done() |
|
814 | 814 | |
|
815 | 815 | def hgsubrepoarchive(orig, repo, ui, archiver, prefix, match=None): |
|
816 | 816 | rev = repo._state[1] |
|
817 | 817 | ctx = repo._repo[rev] |
|
818 | 818 | |
|
819 | 819 | lfcommands.cachelfiles(ui, repo._repo, ctx.node()) |
|
820 | 820 | |
|
821 | 821 | def write(name, mode, islink, getdata): |
|
822 | 822 | # At this point, the standin has been replaced with the largefile name, |
|
823 | 823 | # so the normal matcher works here without the lfutil variants. |
|
824 | 824 | if match and not match(f): |
|
825 | 825 | return |
|
826 | 826 | data = getdata() |
|
827 | 827 | |
|
828 | 828 | archiver.addfile(prefix + repo._path + '/' + name, mode, islink, data) |
|
829 | 829 | |
|
830 | 830 | for f in ctx: |
|
831 | 831 | ff = ctx.flags(f) |
|
832 | 832 | getdata = ctx[f].data |
|
833 | 833 | if lfutil.isstandin(f): |
|
834 | 834 | path = lfutil.findfile(repo._repo, getdata().strip()) |
|
835 | 835 | if path is None: |
|
836 | 836 | raise util.Abort( |
|
837 | 837 | _('largefile %s not found in repo store or system cache') |
|
838 | 838 | % lfutil.splitstandin(f)) |
|
839 | 839 | f = lfutil.splitstandin(f) |
|
840 | 840 | |
|
841 | 841 | def getdatafn(): |
|
842 | 842 | fd = None |
|
843 | 843 | try: |
|
844 | 844 | fd = open(os.path.join(prefix, path), 'rb') |
|
845 | 845 | return fd.read() |
|
846 | 846 | finally: |
|
847 | 847 | if fd: |
|
848 | 848 | fd.close() |
|
849 | 849 | |
|
850 | 850 | getdata = getdatafn |
|
851 | 851 | |
|
852 | 852 | write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata) |
|
853 | 853 | |
|
854 | 854 | for subpath in ctx.substate: |
|
855 | 855 | sub = ctx.sub(subpath) |
|
856 | 856 | submatch = match_.narrowmatcher(subpath, match) |
|
857 | 857 | sub.archive(ui, archiver, os.path.join(prefix, repo._path) + '/', |
|
858 | 858 | submatch) |
|
859 | 859 | |
|
860 | 860 | # If a largefile is modified, the change is not reflected in its |
|
861 | 861 | # standin until a commit. cmdutil.bailifchanged() raises an exception |
|
862 | 862 | # if the repo has uncommitted changes. Wrap it to also check if |
|
863 | 863 | # largefiles were changed. This is used by bisect and backout. |
|
864 | 864 | def overridebailifchanged(orig, repo): |
|
865 | 865 | orig(repo) |
|
866 | 866 | repo.lfstatus = True |
|
867 | 867 | modified, added, removed, deleted = repo.status()[:4] |
|
868 | 868 | repo.lfstatus = False |
|
869 | 869 | if modified or added or removed or deleted: |
|
870 | 870 | raise util.Abort(_('outstanding uncommitted changes')) |
|
871 | 871 | |
|
872 | 872 | # Fetch doesn't use cmdutil.bailifchanged so override it to add the check |
|
873 | 873 | def overridefetch(orig, ui, repo, *pats, **opts): |
|
874 | 874 | repo.lfstatus = True |
|
875 | 875 | modified, added, removed, deleted = repo.status()[:4] |
|
876 | 876 | repo.lfstatus = False |
|
877 | 877 | if modified or added or removed or deleted: |
|
878 | 878 | raise util.Abort(_('outstanding uncommitted changes')) |
|
879 | 879 | return orig(ui, repo, *pats, **opts) |
|
880 | 880 | |
|
881 | 881 | def overrideforget(orig, ui, repo, *pats, **opts): |
|
882 | 882 | installnormalfilesmatchfn(repo[None].manifest()) |
|
883 | 883 | orig(ui, repo, *pats, **opts) |
|
884 | 884 | restorematchfn() |
|
885 | 885 | m = scmutil.match(repo[None], pats, opts) |
|
886 | 886 | |
|
887 | 887 | try: |
|
888 | 888 | repo.lfstatus = True |
|
889 | 889 | s = repo.status(match=m, clean=True) |
|
890 | 890 | finally: |
|
891 | 891 | repo.lfstatus = False |
|
892 | 892 | forget = sorted(s[0] + s[1] + s[3] + s[6]) |
|
893 | 893 | forget = [f for f in forget if lfutil.standin(f) in repo[None].manifest()] |
|
894 | 894 | |
|
895 | 895 | for f in forget: |
|
896 | 896 | if lfutil.standin(f) not in repo.dirstate and not \ |
|
897 | 897 | os.path.isdir(m.rel(lfutil.standin(f))): |
|
898 | 898 | ui.warn(_('not removing %s: file is already untracked\n') |
|
899 | 899 | % m.rel(f)) |
|
900 | 900 | |
|
901 | 901 | for f in forget: |
|
902 | 902 | if ui.verbose or not m.exact(f): |
|
903 | 903 | ui.status(_('removing %s\n') % m.rel(f)) |
|
904 | 904 | |
|
905 | 905 | # Need to lock because standin files are deleted then removed from the |
|
906 | 906 | # repository and we could race inbetween. |
|
907 | 907 | wlock = repo.wlock() |
|
908 | 908 | try: |
|
909 | 909 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
910 | 910 | for f in forget: |
|
911 | 911 | if lfdirstate[f] == 'a': |
|
912 | 912 | lfdirstate.drop(f) |
|
913 | 913 | else: |
|
914 | 914 | lfdirstate.remove(f) |
|
915 | 915 | lfdirstate.write() |
|
916 | 916 | lfutil.reporemove(repo, [lfutil.standin(f) for f in forget], |
|
917 | 917 | unlink=True) |
|
918 | 918 | finally: |
|
919 | 919 | wlock.release() |
|
920 | 920 | |
|
921 | 921 | def getoutgoinglfiles(ui, repo, dest=None, **opts): |
|
922 | 922 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
923 | 923 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
924 | 924 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
925 | 925 | if revs: |
|
926 | 926 | revs = [repo.lookup(rev) for rev in revs] |
|
927 | 927 | |
|
928 | 928 | remoteui = hg.remoteui |
|
929 | 929 | |
|
930 | 930 | try: |
|
931 | 931 | remote = hg.repository(remoteui(repo, opts), dest) |
|
932 | 932 | except error.RepoError: |
|
933 | 933 | return None |
|
934 | 934 | o = lfutil.findoutgoing(repo, remote, False) |
|
935 | 935 | if not o: |
|
936 | 936 | return None |
|
937 | 937 | o = repo.changelog.nodesbetween(o, revs)[0] |
|
938 | 938 | if opts.get('newest_first'): |
|
939 | 939 | o.reverse() |
|
940 | 940 | |
|
941 | 941 | toupload = set() |
|
942 | 942 | for n in o: |
|
943 | 943 | parents = [p for p in repo.changelog.parents(n) if p != node.nullid] |
|
944 | 944 | ctx = repo[n] |
|
945 | 945 | files = set(ctx.files()) |
|
946 | 946 | if len(parents) == 2: |
|
947 | 947 | mc = ctx.manifest() |
|
948 | 948 | mp1 = ctx.parents()[0].manifest() |
|
949 | 949 | mp2 = ctx.parents()[1].manifest() |
|
950 | 950 | for f in mp1: |
|
951 | 951 | if f not in mc: |
|
952 | 952 | files.add(f) |
|
953 | 953 | for f in mp2: |
|
954 | 954 | if f not in mc: |
|
955 | 955 | files.add(f) |
|
956 | 956 | for f in mc: |
|
957 | 957 | if mc[f] != mp1.get(f, None) or mc[f] != mp2.get(f, None): |
|
958 | 958 | files.add(f) |
|
959 | 959 | toupload = toupload.union( |
|
960 | 960 | set([f for f in files if lfutil.isstandin(f) and f in ctx])) |
|
961 | 961 | return toupload |
|
962 | 962 | |
|
963 | 963 | def overrideoutgoing(orig, ui, repo, dest=None, **opts): |
|
964 | 964 | orig(ui, repo, dest, **opts) |
|
965 | 965 | |
|
966 | 966 | if opts.pop('large', None): |
|
967 | 967 | toupload = getoutgoinglfiles(ui, repo, dest, **opts) |
|
968 | 968 | if toupload is None: |
|
969 | 969 | ui.status(_('largefiles: No remote repo\n')) |
|
970 | 970 | else: |
|
971 | 971 | ui.status(_('largefiles to upload:\n')) |
|
972 | 972 | for file in toupload: |
|
973 | 973 | ui.status(lfutil.splitstandin(file) + '\n') |
|
974 | 974 | ui.status('\n') |
|
975 | 975 | |
|
976 | 976 | def overridesummary(orig, ui, repo, *pats, **opts): |
|
977 | 977 | try: |
|
978 | 978 | repo.lfstatus = True |
|
979 | 979 | orig(ui, repo, *pats, **opts) |
|
980 | 980 | finally: |
|
981 | 981 | repo.lfstatus = False |
|
982 | 982 | |
|
983 | 983 | if opts.pop('large', None): |
|
984 | 984 | toupload = getoutgoinglfiles(ui, repo, None, **opts) |
|
985 | 985 | if toupload is None: |
|
986 | 986 | ui.status(_('largefiles: No remote repo\n')) |
|
987 | 987 | else: |
|
988 | 988 | ui.status(_('largefiles: %d to upload\n') % len(toupload)) |
|
989 | 989 | |
|
990 | 990 | def overrideaddremove(orig, ui, repo, *pats, **opts): |
|
991 | 991 | if not lfutil.islfilesrepo(repo): |
|
992 | 992 | return orig(ui, repo, *pats, **opts) |
|
993 | 993 | # Get the list of missing largefiles so we can remove them |
|
994 | 994 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
995 | 995 | s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [], False, |
|
996 | 996 | False, False) |
|
997 | 997 | (unsure, modified, added, removed, missing, unknown, ignored, clean) = s |
|
998 | 998 | |
|
999 | 999 | # Call into the normal remove code, but the removing of the standin, we want |
|
1000 | 1000 | # to have handled by original addremove. Monkey patching here makes sure |
|
1001 | 1001 | # we don't remove the standin in the largefiles code, preventing a very |
|
1002 | 1002 | # confused state later. |
|
1003 | 1003 | if missing: |
|
1004 | 1004 | repo._isaddremove = True |
|
1005 | 1005 | removelargefiles(ui, repo, *missing, **opts) |
|
1006 | 1006 | repo._isaddremove = False |
|
1007 | 1007 | # Call into the normal add code, and any files that *should* be added as |
|
1008 | 1008 | # largefiles will be |
|
1009 | 1009 | addlargefiles(ui, repo, *pats, **opts) |
|
1010 | 1010 | # Now that we've handled largefiles, hand off to the original addremove |
|
1011 | 1011 | # function to take care of the rest. Make sure it doesn't do anything with |
|
1012 | 1012 | # largefiles by installing a matcher that will ignore them. |
|
1013 | 1013 | installnormalfilesmatchfn(repo[None].manifest()) |
|
1014 | 1014 | result = orig(ui, repo, *pats, **opts) |
|
1015 | 1015 | restorematchfn() |
|
1016 | 1016 | return result |
|
1017 | 1017 | |
|
1018 | 1018 | # Calling purge with --all will cause the largefiles to be deleted. |
|
1019 | 1019 | # Override repo.status to prevent this from happening. |
|
1020 | 1020 | def overridepurge(orig, ui, repo, *dirs, **opts): |
|
1021 | 1021 | oldstatus = repo.status |
|
1022 | 1022 | def overridestatus(node1='.', node2=None, match=None, ignored=False, |
|
1023 | 1023 | clean=False, unknown=False, listsubrepos=False): |
|
1024 | 1024 | r = oldstatus(node1, node2, match, ignored, clean, unknown, |
|
1025 | 1025 | listsubrepos) |
|
1026 | 1026 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
1027 | 1027 | modified, added, removed, deleted, unknown, ignored, clean = r |
|
1028 | 1028 | unknown = [f for f in unknown if lfdirstate[f] == '?'] |
|
1029 | 1029 | ignored = [f for f in ignored if lfdirstate[f] == '?'] |
|
1030 | 1030 | return modified, added, removed, deleted, unknown, ignored, clean |
|
1031 | 1031 | repo.status = overridestatus |
|
1032 | 1032 | orig(ui, repo, *dirs, **opts) |
|
1033 | 1033 | repo.status = oldstatus |
|
1034 | 1034 | |
|
1035 | 1035 | def overriderollback(orig, ui, repo, **opts): |
|
1036 | 1036 | result = orig(ui, repo, **opts) |
|
1037 | 1037 | merge.update(repo, node=None, branchmerge=False, force=True, |
|
1038 | 1038 | partial=lfutil.isstandin) |
|
1039 | 1039 | wlock = repo.wlock() |
|
1040 | 1040 | try: |
|
1041 | 1041 | lfdirstate = lfutil.openlfdirstate(ui, repo) |
|
1042 | 1042 | lfiles = lfutil.listlfiles(repo) |
|
1043 | 1043 | oldlfiles = lfutil.listlfiles(repo, repo[None].parents()[0].rev()) |
|
1044 | 1044 | for file in lfiles: |
|
1045 | 1045 | if file in oldlfiles: |
|
1046 | 1046 | lfdirstate.normallookup(file) |
|
1047 | 1047 | else: |
|
1048 | 1048 | lfdirstate.add(file) |
|
1049 | 1049 | lfdirstate.write() |
|
1050 | 1050 | finally: |
|
1051 | 1051 | wlock.release() |
|
1052 | 1052 | return result |
|
1053 | 1053 | |
|
1054 | 1054 | def overridetransplant(orig, ui, repo, *revs, **opts): |
|
1055 | 1055 | try: |
|
1056 | 1056 | oldstandins = lfutil.getstandinsstate(repo) |
|
1057 | 1057 | repo._istransplanting = True |
|
1058 | 1058 | result = orig(ui, repo, *revs, **opts) |
|
1059 | 1059 | newstandins = lfutil.getstandinsstate(repo) |
|
1060 | 1060 | filelist = lfutil.getlfilestoupdate(oldstandins, newstandins) |
|
1061 | 1061 | lfcommands.updatelfiles(repo.ui, repo, filelist=filelist, |
|
1062 | 1062 | printmessage=True) |
|
1063 | 1063 | finally: |
|
1064 | 1064 | repo._istransplanting = False |
|
1065 | 1065 | return result |
|
1066 | 1066 | |
|
1067 | 1067 | def overridecat(orig, ui, repo, file1, *pats, **opts): |
|
1068 | 1068 | rev = opts.get('rev') |
|
1069 | 1069 | if not lfutil.standin(file1) in repo[rev]: |
|
1070 | 1070 | result = orig(ui, repo, file1, *pats, **opts) |
|
1071 | 1071 | return result |
|
1072 | 1072 | return lfcommands.catlfile(repo, file1, opts.get('rev'), opts.get('output')) |
@@ -1,3595 +1,3597 | |||
|
1 | 1 | # mq.py - patch queues for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Chris Mason <mason@suse.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | '''manage a stack of patches |
|
9 | 9 | |
|
10 | 10 | This extension lets you work with a stack of patches in a Mercurial |
|
11 | 11 | repository. It manages two stacks of patches - all known patches, and |
|
12 | 12 | applied patches (subset of known patches). |
|
13 | 13 | |
|
14 | 14 | Known patches are represented as patch files in the .hg/patches |
|
15 | 15 | directory. Applied patches are both patch files and changesets. |
|
16 | 16 | |
|
17 | 17 | Common tasks (use :hg:`help command` for more details):: |
|
18 | 18 | |
|
19 | 19 | create new patch qnew |
|
20 | 20 | import existing patch qimport |
|
21 | 21 | |
|
22 | 22 | print patch series qseries |
|
23 | 23 | print applied patches qapplied |
|
24 | 24 | |
|
25 | 25 | add known patch to applied stack qpush |
|
26 | 26 | remove patch from applied stack qpop |
|
27 | 27 | refresh contents of top applied patch qrefresh |
|
28 | 28 | |
|
29 | 29 | By default, mq will automatically use git patches when required to |
|
30 | 30 | avoid losing file mode changes, copy records, binary files or empty |
|
31 | 31 | files creations or deletions. This behaviour can be configured with:: |
|
32 | 32 | |
|
33 | 33 | [mq] |
|
34 | 34 | git = auto/keep/yes/no |
|
35 | 35 | |
|
36 | 36 | If set to 'keep', mq will obey the [diff] section configuration while |
|
37 | 37 | preserving existing git patches upon qrefresh. If set to 'yes' or |
|
38 | 38 | 'no', mq will override the [diff] section and always generate git or |
|
39 | 39 | regular patches, possibly losing data in the second case. |
|
40 | 40 | |
|
41 | 41 | It may be desirable for mq changesets to be kept in the secret phase (see |
|
42 | 42 | :hg:`help phases`), which can be enabled with the following setting:: |
|
43 | 43 | |
|
44 | 44 | [mq] |
|
45 | 45 | secret = True |
|
46 | 46 | |
|
47 | 47 | You will by default be managing a patch queue named "patches". You can |
|
48 | 48 | create other, independent patch queues with the :hg:`qqueue` command. |
|
49 | 49 | |
|
50 | 50 | If the working directory contains uncommitted files, qpush, qpop and |
|
51 | 51 | qgoto abort immediately. If -f/--force is used, the changes are |
|
52 | 52 | discarded. Setting:: |
|
53 | 53 | |
|
54 | 54 | [mq] |
|
55 | 55 | keepchanges = True |
|
56 | 56 | |
|
57 | 57 | make them behave as if --keep-changes were passed, and non-conflicting |
|
58 | 58 | local changes will be tolerated and preserved. If incompatible options |
|
59 | 59 | such as -f/--force or --exact are passed, this setting is ignored. |
|
60 | 60 | ''' |
|
61 | 61 | |
|
62 | 62 | from mercurial.i18n import _ |
|
63 | 63 | from mercurial.node import bin, hex, short, nullid, nullrev |
|
64 | 64 | from mercurial.lock import release |
|
65 | 65 | from mercurial import commands, cmdutil, hg, scmutil, util, revset |
|
66 | 66 | from mercurial import repair, extensions, url, error, phases |
|
67 | 67 | from mercurial import patch as patchmod |
|
68 | 68 | import os, re, errno, shutil |
|
69 | 69 | |
|
70 | 70 | commands.norepo += " qclone" |
|
71 | 71 | |
|
72 | 72 | seriesopts = [('s', 'summary', None, _('print first line of patch header'))] |
|
73 | 73 | |
|
74 | 74 | cmdtable = {} |
|
75 | 75 | command = cmdutil.command(cmdtable) |
|
76 | 76 | testedwith = 'internal' |
|
77 | 77 | |
|
78 | 78 | # Patch names looks like unix-file names. |
|
79 | 79 | # They must be joinable with queue directory and result in the patch path. |
|
80 | 80 | normname = util.normpath |
|
81 | 81 | |
|
82 | 82 | class statusentry(object): |
|
83 | 83 | def __init__(self, node, name): |
|
84 | 84 | self.node, self.name = node, name |
|
85 | 85 | def __repr__(self): |
|
86 | 86 | return hex(self.node) + ':' + self.name |
|
87 | 87 | |
|
88 | 88 | class patchheader(object): |
|
89 | 89 | def __init__(self, pf, plainmode=False): |
|
90 | 90 | def eatdiff(lines): |
|
91 | 91 | while lines: |
|
92 | 92 | l = lines[-1] |
|
93 | 93 | if (l.startswith("diff -") or |
|
94 | 94 | l.startswith("Index:") or |
|
95 | 95 | l.startswith("===========")): |
|
96 | 96 | del lines[-1] |
|
97 | 97 | else: |
|
98 | 98 | break |
|
99 | 99 | def eatempty(lines): |
|
100 | 100 | while lines: |
|
101 | 101 | if not lines[-1].strip(): |
|
102 | 102 | del lines[-1] |
|
103 | 103 | else: |
|
104 | 104 | break |
|
105 | 105 | |
|
106 | 106 | message = [] |
|
107 | 107 | comments = [] |
|
108 | 108 | user = None |
|
109 | 109 | date = None |
|
110 | 110 | parent = None |
|
111 | 111 | format = None |
|
112 | 112 | subject = None |
|
113 | 113 | branch = None |
|
114 | 114 | nodeid = None |
|
115 | 115 | diffstart = 0 |
|
116 | 116 | |
|
117 | 117 | for line in file(pf): |
|
118 | 118 | line = line.rstrip() |
|
119 | 119 | if (line.startswith('diff --git') |
|
120 | 120 | or (diffstart and line.startswith('+++ '))): |
|
121 | 121 | diffstart = 2 |
|
122 | 122 | break |
|
123 | 123 | diffstart = 0 # reset |
|
124 | 124 | if line.startswith("--- "): |
|
125 | 125 | diffstart = 1 |
|
126 | 126 | continue |
|
127 | 127 | elif format == "hgpatch": |
|
128 | 128 | # parse values when importing the result of an hg export |
|
129 | 129 | if line.startswith("# User "): |
|
130 | 130 | user = line[7:] |
|
131 | 131 | elif line.startswith("# Date "): |
|
132 | 132 | date = line[7:] |
|
133 | 133 | elif line.startswith("# Parent "): |
|
134 | 134 | parent = line[9:].lstrip() |
|
135 | 135 | elif line.startswith("# Branch "): |
|
136 | 136 | branch = line[9:] |
|
137 | 137 | elif line.startswith("# Node ID "): |
|
138 | 138 | nodeid = line[10:] |
|
139 | 139 | elif not line.startswith("# ") and line: |
|
140 | 140 | message.append(line) |
|
141 | 141 | format = None |
|
142 | 142 | elif line == '# HG changeset patch': |
|
143 | 143 | message = [] |
|
144 | 144 | format = "hgpatch" |
|
145 | 145 | elif (format != "tagdone" and (line.startswith("Subject: ") or |
|
146 | 146 | line.startswith("subject: "))): |
|
147 | 147 | subject = line[9:] |
|
148 | 148 | format = "tag" |
|
149 | 149 | elif (format != "tagdone" and (line.startswith("From: ") or |
|
150 | 150 | line.startswith("from: "))): |
|
151 | 151 | user = line[6:] |
|
152 | 152 | format = "tag" |
|
153 | 153 | elif (format != "tagdone" and (line.startswith("Date: ") or |
|
154 | 154 | line.startswith("date: "))): |
|
155 | 155 | date = line[6:] |
|
156 | 156 | format = "tag" |
|
157 | 157 | elif format == "tag" and line == "": |
|
158 | 158 | # when looking for tags (subject: from: etc) they |
|
159 | 159 | # end once you find a blank line in the source |
|
160 | 160 | format = "tagdone" |
|
161 | 161 | elif message or line: |
|
162 | 162 | message.append(line) |
|
163 | 163 | comments.append(line) |
|
164 | 164 | |
|
165 | 165 | eatdiff(message) |
|
166 | 166 | eatdiff(comments) |
|
167 | 167 | # Remember the exact starting line of the patch diffs before consuming |
|
168 | 168 | # empty lines, for external use by TortoiseHg and others |
|
169 | 169 | self.diffstartline = len(comments) |
|
170 | 170 | eatempty(message) |
|
171 | 171 | eatempty(comments) |
|
172 | 172 | |
|
173 | 173 | # make sure message isn't empty |
|
174 | 174 | if format and format.startswith("tag") and subject: |
|
175 | 175 | message.insert(0, "") |
|
176 | 176 | message.insert(0, subject) |
|
177 | 177 | |
|
178 | 178 | self.message = message |
|
179 | 179 | self.comments = comments |
|
180 | 180 | self.user = user |
|
181 | 181 | self.date = date |
|
182 | 182 | self.parent = parent |
|
183 | 183 | # nodeid and branch are for external use by TortoiseHg and others |
|
184 | 184 | self.nodeid = nodeid |
|
185 | 185 | self.branch = branch |
|
186 | 186 | self.haspatch = diffstart > 1 |
|
187 | 187 | self.plainmode = plainmode |
|
188 | 188 | |
|
189 | 189 | def setuser(self, user): |
|
190 | 190 | if not self.updateheader(['From: ', '# User '], user): |
|
191 | 191 | try: |
|
192 | 192 | patchheaderat = self.comments.index('# HG changeset patch') |
|
193 | 193 | self.comments.insert(patchheaderat + 1, '# User ' + user) |
|
194 | 194 | except ValueError: |
|
195 | 195 | if self.plainmode or self._hasheader(['Date: ']): |
|
196 | 196 | self.comments = ['From: ' + user] + self.comments |
|
197 | 197 | else: |
|
198 | 198 | tmp = ['# HG changeset patch', '# User ' + user, ''] |
|
199 | 199 | self.comments = tmp + self.comments |
|
200 | 200 | self.user = user |
|
201 | 201 | |
|
202 | 202 | def setdate(self, date): |
|
203 | 203 | if not self.updateheader(['Date: ', '# Date '], date): |
|
204 | 204 | try: |
|
205 | 205 | patchheaderat = self.comments.index('# HG changeset patch') |
|
206 | 206 | self.comments.insert(patchheaderat + 1, '# Date ' + date) |
|
207 | 207 | except ValueError: |
|
208 | 208 | if self.plainmode or self._hasheader(['From: ']): |
|
209 | 209 | self.comments = ['Date: ' + date] + self.comments |
|
210 | 210 | else: |
|
211 | 211 | tmp = ['# HG changeset patch', '# Date ' + date, ''] |
|
212 | 212 | self.comments = tmp + self.comments |
|
213 | 213 | self.date = date |
|
214 | 214 | |
|
215 | 215 | def setparent(self, parent): |
|
216 | 216 | if not self.updateheader(['# Parent '], parent): |
|
217 | 217 | try: |
|
218 | 218 | patchheaderat = self.comments.index('# HG changeset patch') |
|
219 | 219 | self.comments.insert(patchheaderat + 1, '# Parent ' + parent) |
|
220 | 220 | except ValueError: |
|
221 | 221 | pass |
|
222 | 222 | self.parent = parent |
|
223 | 223 | |
|
224 | 224 | def setmessage(self, message): |
|
225 | 225 | if self.comments: |
|
226 | 226 | self._delmsg() |
|
227 | 227 | self.message = [message] |
|
228 | 228 | self.comments += self.message |
|
229 | 229 | |
|
230 | 230 | def updateheader(self, prefixes, new): |
|
231 | 231 | '''Update all references to a field in the patch header. |
|
232 | 232 | Return whether the field is present.''' |
|
233 | 233 | res = False |
|
234 | 234 | for prefix in prefixes: |
|
235 | 235 | for i in xrange(len(self.comments)): |
|
236 | 236 | if self.comments[i].startswith(prefix): |
|
237 | 237 | self.comments[i] = prefix + new |
|
238 | 238 | res = True |
|
239 | 239 | break |
|
240 | 240 | return res |
|
241 | 241 | |
|
242 | 242 | def _hasheader(self, prefixes): |
|
243 | 243 | '''Check if a header starts with any of the given prefixes.''' |
|
244 | 244 | for prefix in prefixes: |
|
245 | 245 | for comment in self.comments: |
|
246 | 246 | if comment.startswith(prefix): |
|
247 | 247 | return True |
|
248 | 248 | return False |
|
249 | 249 | |
|
250 | 250 | def __str__(self): |
|
251 | 251 | if not self.comments: |
|
252 | 252 | return '' |
|
253 | 253 | return '\n'.join(self.comments) + '\n\n' |
|
254 | 254 | |
|
255 | 255 | def _delmsg(self): |
|
256 | 256 | '''Remove existing message, keeping the rest of the comments fields. |
|
257 | 257 | If comments contains 'subject: ', message will prepend |
|
258 | 258 | the field and a blank line.''' |
|
259 | 259 | if self.message: |
|
260 | 260 | subj = 'subject: ' + self.message[0].lower() |
|
261 | 261 | for i in xrange(len(self.comments)): |
|
262 | 262 | if subj == self.comments[i].lower(): |
|
263 | 263 | del self.comments[i] |
|
264 | 264 | self.message = self.message[2:] |
|
265 | 265 | break |
|
266 | 266 | ci = 0 |
|
267 | 267 | for mi in self.message: |
|
268 | 268 | while mi != self.comments[ci]: |
|
269 | 269 | ci += 1 |
|
270 | 270 | del self.comments[ci] |
|
271 | 271 | |
|
272 | 272 | def newcommit(repo, phase, *args, **kwargs): |
|
273 | 273 | """helper dedicated to ensure a commit respect mq.secret setting |
|
274 | 274 | |
|
275 | 275 | It should be used instead of repo.commit inside the mq source for operation |
|
276 | 276 | creating new changeset. |
|
277 | 277 | """ |
|
278 | 278 | if phase is None: |
|
279 | 279 | if repo.ui.configbool('mq', 'secret', False): |
|
280 | 280 | phase = phases.secret |
|
281 | 281 | if phase is not None: |
|
282 | 282 | backup = repo.ui.backupconfig('phases', 'new-commit') |
|
283 | 283 | # Marking the repository as committing an mq patch can be used |
|
284 | 284 | # to optimize operations like _branchtags(). |
|
285 | 285 | repo._committingpatch = True |
|
286 | 286 | try: |
|
287 | 287 | if phase is not None: |
|
288 | 288 | repo.ui.setconfig('phases', 'new-commit', phase) |
|
289 | 289 | return repo.commit(*args, **kwargs) |
|
290 | 290 | finally: |
|
291 | 291 | repo._committingpatch = False |
|
292 | 292 | if phase is not None: |
|
293 | 293 | repo.ui.restoreconfig(backup) |
|
294 | 294 | |
|
295 | 295 | class AbortNoCleanup(error.Abort): |
|
296 | 296 | pass |
|
297 | 297 | |
|
298 | 298 | class queue(object): |
|
299 | 299 | def __init__(self, ui, path, patchdir=None): |
|
300 | 300 | self.basepath = path |
|
301 | 301 | try: |
|
302 | 302 | fh = open(os.path.join(path, 'patches.queue')) |
|
303 | 303 | cur = fh.read().rstrip() |
|
304 | 304 | fh.close() |
|
305 | 305 | if not cur: |
|
306 | 306 | curpath = os.path.join(path, 'patches') |
|
307 | 307 | else: |
|
308 | 308 | curpath = os.path.join(path, 'patches-' + cur) |
|
309 | 309 | except IOError: |
|
310 | 310 | curpath = os.path.join(path, 'patches') |
|
311 | 311 | self.path = patchdir or curpath |
|
312 | 312 | self.opener = scmutil.opener(self.path) |
|
313 | 313 | self.ui = ui |
|
314 | 314 | self.applieddirty = False |
|
315 | 315 | self.seriesdirty = False |
|
316 | 316 | self.added = [] |
|
317 | 317 | self.seriespath = "series" |
|
318 | 318 | self.statuspath = "status" |
|
319 | 319 | self.guardspath = "guards" |
|
320 | 320 | self.activeguards = None |
|
321 | 321 | self.guardsdirty = False |
|
322 | 322 | # Handle mq.git as a bool with extended values |
|
323 | 323 | try: |
|
324 | 324 | gitmode = ui.configbool('mq', 'git', None) |
|
325 | 325 | if gitmode is None: |
|
326 | 326 | raise error.ConfigError |
|
327 | 327 | self.gitmode = gitmode and 'yes' or 'no' |
|
328 | 328 | except error.ConfigError: |
|
329 | 329 | self.gitmode = ui.config('mq', 'git', 'auto').lower() |
|
330 | 330 | self.plainmode = ui.configbool('mq', 'plain', False) |
|
331 | 331 | |
|
332 | 332 | @util.propertycache |
|
333 | 333 | def applied(self): |
|
334 | 334 | def parselines(lines): |
|
335 | 335 | for l in lines: |
|
336 | 336 | entry = l.split(':', 1) |
|
337 | 337 | if len(entry) > 1: |
|
338 | 338 | n, name = entry |
|
339 | 339 | yield statusentry(bin(n), name) |
|
340 | 340 | elif l.strip(): |
|
341 | 341 | self.ui.warn(_('malformated mq status line: %s\n') % entry) |
|
342 | 342 | # else we ignore empty lines |
|
343 | 343 | try: |
|
344 | 344 | lines = self.opener.read(self.statuspath).splitlines() |
|
345 | 345 | return list(parselines(lines)) |
|
346 | 346 | except IOError, e: |
|
347 | 347 | if e.errno == errno.ENOENT: |
|
348 | 348 | return [] |
|
349 | 349 | raise |
|
350 | 350 | |
|
351 | 351 | @util.propertycache |
|
352 | 352 | def fullseries(self): |
|
353 | 353 | try: |
|
354 | 354 | return self.opener.read(self.seriespath).splitlines() |
|
355 | 355 | except IOError, e: |
|
356 | 356 | if e.errno == errno.ENOENT: |
|
357 | 357 | return [] |
|
358 | 358 | raise |
|
359 | 359 | |
|
360 | 360 | @util.propertycache |
|
361 | 361 | def series(self): |
|
362 | 362 | self.parseseries() |
|
363 | 363 | return self.series |
|
364 | 364 | |
|
365 | 365 | @util.propertycache |
|
366 | 366 | def seriesguards(self): |
|
367 | 367 | self.parseseries() |
|
368 | 368 | return self.seriesguards |
|
369 | 369 | |
|
370 | 370 | def invalidate(self): |
|
371 | 371 | for a in 'applied fullseries series seriesguards'.split(): |
|
372 | 372 | if a in self.__dict__: |
|
373 | 373 | delattr(self, a) |
|
374 | 374 | self.applieddirty = False |
|
375 | 375 | self.seriesdirty = False |
|
376 | 376 | self.guardsdirty = False |
|
377 | 377 | self.activeguards = None |
|
378 | 378 | |
|
379 | 379 | def diffopts(self, opts={}, patchfn=None): |
|
380 | 380 | diffopts = patchmod.diffopts(self.ui, opts) |
|
381 | 381 | if self.gitmode == 'auto': |
|
382 | 382 | diffopts.upgrade = True |
|
383 | 383 | elif self.gitmode == 'keep': |
|
384 | 384 | pass |
|
385 | 385 | elif self.gitmode in ('yes', 'no'): |
|
386 | 386 | diffopts.git = self.gitmode == 'yes' |
|
387 | 387 | else: |
|
388 | 388 | raise util.Abort(_('mq.git option can be auto/keep/yes/no' |
|
389 | 389 | ' got %s') % self.gitmode) |
|
390 | 390 | if patchfn: |
|
391 | 391 | diffopts = self.patchopts(diffopts, patchfn) |
|
392 | 392 | return diffopts |
|
393 | 393 | |
|
394 | 394 | def patchopts(self, diffopts, *patches): |
|
395 | 395 | """Return a copy of input diff options with git set to true if |
|
396 | 396 | referenced patch is a git patch and should be preserved as such. |
|
397 | 397 | """ |
|
398 | 398 | diffopts = diffopts.copy() |
|
399 | 399 | if not diffopts.git and self.gitmode == 'keep': |
|
400 | 400 | for patchfn in patches: |
|
401 | 401 | patchf = self.opener(patchfn, 'r') |
|
402 | 402 | # if the patch was a git patch, refresh it as a git patch |
|
403 | 403 | for line in patchf: |
|
404 | 404 | if line.startswith('diff --git'): |
|
405 | 405 | diffopts.git = True |
|
406 | 406 | break |
|
407 | 407 | patchf.close() |
|
408 | 408 | return diffopts |
|
409 | 409 | |
|
410 | 410 | def join(self, *p): |
|
411 | 411 | return os.path.join(self.path, *p) |
|
412 | 412 | |
|
413 | 413 | def findseries(self, patch): |
|
414 | 414 | def matchpatch(l): |
|
415 | 415 | l = l.split('#', 1)[0] |
|
416 | 416 | return l.strip() == patch |
|
417 | 417 | for index, l in enumerate(self.fullseries): |
|
418 | 418 | if matchpatch(l): |
|
419 | 419 | return index |
|
420 | 420 | return None |
|
421 | 421 | |
|
422 | 422 | guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') |
|
423 | 423 | |
|
424 | 424 | def parseseries(self): |
|
425 | 425 | self.series = [] |
|
426 | 426 | self.seriesguards = [] |
|
427 | 427 | for l in self.fullseries: |
|
428 | 428 | h = l.find('#') |
|
429 | 429 | if h == -1: |
|
430 | 430 | patch = l |
|
431 | 431 | comment = '' |
|
432 | 432 | elif h == 0: |
|
433 | 433 | continue |
|
434 | 434 | else: |
|
435 | 435 | patch = l[:h] |
|
436 | 436 | comment = l[h:] |
|
437 | 437 | patch = patch.strip() |
|
438 | 438 | if patch: |
|
439 | 439 | if patch in self.series: |
|
440 | 440 | raise util.Abort(_('%s appears more than once in %s') % |
|
441 | 441 | (patch, self.join(self.seriespath))) |
|
442 | 442 | self.series.append(patch) |
|
443 | 443 | self.seriesguards.append(self.guard_re.findall(comment)) |
|
444 | 444 | |
|
445 | 445 | def checkguard(self, guard): |
|
446 | 446 | if not guard: |
|
447 | 447 | return _('guard cannot be an empty string') |
|
448 | 448 | bad_chars = '# \t\r\n\f' |
|
449 | 449 | first = guard[0] |
|
450 | 450 | if first in '-+': |
|
451 | 451 | return (_('guard %r starts with invalid character: %r') % |
|
452 | 452 | (guard, first)) |
|
453 | 453 | for c in bad_chars: |
|
454 | 454 | if c in guard: |
|
455 | 455 | return _('invalid character in guard %r: %r') % (guard, c) |
|
456 | 456 | |
|
457 | 457 | def setactive(self, guards): |
|
458 | 458 | for guard in guards: |
|
459 | 459 | bad = self.checkguard(guard) |
|
460 | 460 | if bad: |
|
461 | 461 | raise util.Abort(bad) |
|
462 | 462 | guards = sorted(set(guards)) |
|
463 | 463 | self.ui.debug('active guards: %s\n' % ' '.join(guards)) |
|
464 | 464 | self.activeguards = guards |
|
465 | 465 | self.guardsdirty = True |
|
466 | 466 | |
|
467 | 467 | def active(self): |
|
468 | 468 | if self.activeguards is None: |
|
469 | 469 | self.activeguards = [] |
|
470 | 470 | try: |
|
471 | 471 | guards = self.opener.read(self.guardspath).split() |
|
472 | 472 | except IOError, err: |
|
473 | 473 | if err.errno != errno.ENOENT: |
|
474 | 474 | raise |
|
475 | 475 | guards = [] |
|
476 | 476 | for i, guard in enumerate(guards): |
|
477 | 477 | bad = self.checkguard(guard) |
|
478 | 478 | if bad: |
|
479 | 479 | self.ui.warn('%s:%d: %s\n' % |
|
480 | 480 | (self.join(self.guardspath), i + 1, bad)) |
|
481 | 481 | else: |
|
482 | 482 | self.activeguards.append(guard) |
|
483 | 483 | return self.activeguards |
|
484 | 484 | |
|
485 | 485 | def setguards(self, idx, guards): |
|
486 | 486 | for g in guards: |
|
487 | 487 | if len(g) < 2: |
|
488 | 488 | raise util.Abort(_('guard %r too short') % g) |
|
489 | 489 | if g[0] not in '-+': |
|
490 | 490 | raise util.Abort(_('guard %r starts with invalid char') % g) |
|
491 | 491 | bad = self.checkguard(g[1:]) |
|
492 | 492 | if bad: |
|
493 | 493 | raise util.Abort(bad) |
|
494 | 494 | drop = self.guard_re.sub('', self.fullseries[idx]) |
|
495 | 495 | self.fullseries[idx] = drop + ''.join([' #' + g for g in guards]) |
|
496 | 496 | self.parseseries() |
|
497 | 497 | self.seriesdirty = True |
|
498 | 498 | |
|
499 | 499 | def pushable(self, idx): |
|
500 | 500 | if isinstance(idx, str): |
|
501 | 501 | idx = self.series.index(idx) |
|
502 | 502 | patchguards = self.seriesguards[idx] |
|
503 | 503 | if not patchguards: |
|
504 | 504 | return True, None |
|
505 | 505 | guards = self.active() |
|
506 | 506 | exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards] |
|
507 | 507 | if exactneg: |
|
508 | 508 | return False, repr(exactneg[0]) |
|
509 | 509 | pos = [g for g in patchguards if g[0] == '+'] |
|
510 | 510 | exactpos = [g for g in pos if g[1:] in guards] |
|
511 | 511 | if pos: |
|
512 | 512 | if exactpos: |
|
513 | 513 | return True, repr(exactpos[0]) |
|
514 | 514 | return False, ' '.join(map(repr, pos)) |
|
515 | 515 | return True, '' |
|
516 | 516 | |
|
517 | 517 | def explainpushable(self, idx, all_patches=False): |
|
518 | 518 | write = all_patches and self.ui.write or self.ui.warn |
|
519 | 519 | if all_patches or self.ui.verbose: |
|
520 | 520 | if isinstance(idx, str): |
|
521 | 521 | idx = self.series.index(idx) |
|
522 | 522 | pushable, why = self.pushable(idx) |
|
523 | 523 | if all_patches and pushable: |
|
524 | 524 | if why is None: |
|
525 | 525 | write(_('allowing %s - no guards in effect\n') % |
|
526 | 526 | self.series[idx]) |
|
527 | 527 | else: |
|
528 | 528 | if not why: |
|
529 | 529 | write(_('allowing %s - no matching negative guards\n') % |
|
530 | 530 | self.series[idx]) |
|
531 | 531 | else: |
|
532 | 532 | write(_('allowing %s - guarded by %s\n') % |
|
533 | 533 | (self.series[idx], why)) |
|
534 | 534 | if not pushable: |
|
535 | 535 | if why: |
|
536 | 536 | write(_('skipping %s - guarded by %s\n') % |
|
537 | 537 | (self.series[idx], why)) |
|
538 | 538 | else: |
|
539 | 539 | write(_('skipping %s - no matching guards\n') % |
|
540 | 540 | self.series[idx]) |
|
541 | 541 | |
|
542 | 542 | def savedirty(self): |
|
543 | 543 | def writelist(items, path): |
|
544 | 544 | fp = self.opener(path, 'w') |
|
545 | 545 | for i in items: |
|
546 | 546 | fp.write("%s\n" % i) |
|
547 | 547 | fp.close() |
|
548 | 548 | if self.applieddirty: |
|
549 | 549 | writelist(map(str, self.applied), self.statuspath) |
|
550 | 550 | self.applieddirty = False |
|
551 | 551 | if self.seriesdirty: |
|
552 | 552 | writelist(self.fullseries, self.seriespath) |
|
553 | 553 | self.seriesdirty = False |
|
554 | 554 | if self.guardsdirty: |
|
555 | 555 | writelist(self.activeguards, self.guardspath) |
|
556 | 556 | self.guardsdirty = False |
|
557 | 557 | if self.added: |
|
558 | 558 | qrepo = self.qrepo() |
|
559 | 559 | if qrepo: |
|
560 | 560 | qrepo[None].add(f for f in self.added if f not in qrepo[None]) |
|
561 | 561 | self.added = [] |
|
562 | 562 | |
|
563 | 563 | def removeundo(self, repo): |
|
564 | 564 | undo = repo.sjoin('undo') |
|
565 | 565 | if not os.path.exists(undo): |
|
566 | 566 | return |
|
567 | 567 | try: |
|
568 | 568 | os.unlink(undo) |
|
569 | 569 | except OSError, inst: |
|
570 | 570 | self.ui.warn(_('error removing undo: %s\n') % str(inst)) |
|
571 | 571 | |
|
572 | 572 | def backup(self, repo, files, copy=False): |
|
573 | 573 | # backup local changes in --force case |
|
574 | 574 | for f in sorted(files): |
|
575 | 575 | absf = repo.wjoin(f) |
|
576 | 576 | if os.path.lexists(absf): |
|
577 | 577 | self.ui.note(_('saving current version of %s as %s\n') % |
|
578 | 578 | (f, f + '.orig')) |
|
579 | 579 | if copy: |
|
580 | 580 | util.copyfile(absf, absf + '.orig') |
|
581 | 581 | else: |
|
582 | 582 | util.rename(absf, absf + '.orig') |
|
583 | 583 | |
|
584 | 584 | def printdiff(self, repo, diffopts, node1, node2=None, files=None, |
|
585 | 585 | fp=None, changes=None, opts={}): |
|
586 | 586 | stat = opts.get('stat') |
|
587 | 587 | m = scmutil.match(repo[node1], files, opts) |
|
588 | 588 | cmdutil.diffordiffstat(self.ui, repo, diffopts, node1, node2, m, |
|
589 | 589 | changes, stat, fp) |
|
590 | 590 | |
|
591 | 591 | def mergeone(self, repo, mergeq, head, patch, rev, diffopts): |
|
592 | 592 | # first try just applying the patch |
|
593 | 593 | (err, n) = self.apply(repo, [patch], update_status=False, |
|
594 | 594 | strict=True, merge=rev) |
|
595 | 595 | |
|
596 | 596 | if err == 0: |
|
597 | 597 | return (err, n) |
|
598 | 598 | |
|
599 | 599 | if n is None: |
|
600 | 600 | raise util.Abort(_("apply failed for patch %s") % patch) |
|
601 | 601 | |
|
602 | 602 | self.ui.warn(_("patch didn't work out, merging %s\n") % patch) |
|
603 | 603 | |
|
604 | 604 | # apply failed, strip away that rev and merge. |
|
605 | 605 | hg.clean(repo, head) |
|
606 | 606 | self.strip(repo, [n], update=False, backup='strip') |
|
607 | 607 | |
|
608 | 608 | ctx = repo[rev] |
|
609 | 609 | ret = hg.merge(repo, rev) |
|
610 | 610 | if ret: |
|
611 | 611 | raise util.Abort(_("update returned %d") % ret) |
|
612 | 612 | n = newcommit(repo, None, ctx.description(), ctx.user(), force=True) |
|
613 | 613 | if n is None: |
|
614 | 614 | raise util.Abort(_("repo commit failed")) |
|
615 | 615 | try: |
|
616 | 616 | ph = patchheader(mergeq.join(patch), self.plainmode) |
|
617 | 617 | except Exception: |
|
618 | 618 | raise util.Abort(_("unable to read %s") % patch) |
|
619 | 619 | |
|
620 | 620 | diffopts = self.patchopts(diffopts, patch) |
|
621 | 621 | patchf = self.opener(patch, "w") |
|
622 | 622 | comments = str(ph) |
|
623 | 623 | if comments: |
|
624 | 624 | patchf.write(comments) |
|
625 | 625 | self.printdiff(repo, diffopts, head, n, fp=patchf) |
|
626 | 626 | patchf.close() |
|
627 | 627 | self.removeundo(repo) |
|
628 | 628 | return (0, n) |
|
629 | 629 | |
|
630 | 630 | def qparents(self, repo, rev=None): |
|
631 | 631 | if rev is None: |
|
632 | 632 | (p1, p2) = repo.dirstate.parents() |
|
633 | 633 | if p2 == nullid: |
|
634 | 634 | return p1 |
|
635 | 635 | if not self.applied: |
|
636 | 636 | return None |
|
637 | 637 | return self.applied[-1].node |
|
638 | 638 | p1, p2 = repo.changelog.parents(rev) |
|
639 | 639 | if p2 != nullid and p2 in [x.node for x in self.applied]: |
|
640 | 640 | return p2 |
|
641 | 641 | return p1 |
|
642 | 642 | |
|
643 | 643 | def mergepatch(self, repo, mergeq, series, diffopts): |
|
644 | 644 | if not self.applied: |
|
645 | 645 | # each of the patches merged in will have two parents. This |
|
646 | 646 | # can confuse the qrefresh, qdiff, and strip code because it |
|
647 | 647 | # needs to know which parent is actually in the patch queue. |
|
648 | 648 | # so, we insert a merge marker with only one parent. This way |
|
649 | 649 | # the first patch in the queue is never a merge patch |
|
650 | 650 | # |
|
651 | 651 | pname = ".hg.patches.merge.marker" |
|
652 | 652 | n = newcommit(repo, None, '[mq]: merge marker', force=True) |
|
653 | 653 | self.removeundo(repo) |
|
654 | 654 | self.applied.append(statusentry(n, pname)) |
|
655 | 655 | self.applieddirty = True |
|
656 | 656 | |
|
657 | 657 | head = self.qparents(repo) |
|
658 | 658 | |
|
659 | 659 | for patch in series: |
|
660 | 660 | patch = mergeq.lookup(patch, strict=True) |
|
661 | 661 | if not patch: |
|
662 | 662 | self.ui.warn(_("patch %s does not exist\n") % patch) |
|
663 | 663 | return (1, None) |
|
664 | 664 | pushable, reason = self.pushable(patch) |
|
665 | 665 | if not pushable: |
|
666 | 666 | self.explainpushable(patch, all_patches=True) |
|
667 | 667 | continue |
|
668 | 668 | info = mergeq.isapplied(patch) |
|
669 | 669 | if not info: |
|
670 | 670 | self.ui.warn(_("patch %s is not applied\n") % patch) |
|
671 | 671 | return (1, None) |
|
672 | 672 | rev = info[1] |
|
673 | 673 | err, head = self.mergeone(repo, mergeq, head, patch, rev, diffopts) |
|
674 | 674 | if head: |
|
675 | 675 | self.applied.append(statusentry(head, patch)) |
|
676 | 676 | self.applieddirty = True |
|
677 | 677 | if err: |
|
678 | 678 | return (err, head) |
|
679 | 679 | self.savedirty() |
|
680 | 680 | return (0, head) |
|
681 | 681 | |
|
682 | 682 | def patch(self, repo, patchfile): |
|
683 | 683 | '''Apply patchfile to the working directory. |
|
684 | 684 | patchfile: name of patch file''' |
|
685 | 685 | files = set() |
|
686 | 686 | try: |
|
687 | 687 | fuzz = patchmod.patch(self.ui, repo, patchfile, strip=1, |
|
688 | 688 | files=files, eolmode=None) |
|
689 | 689 | return (True, list(files), fuzz) |
|
690 | 690 | except Exception, inst: |
|
691 | 691 | self.ui.note(str(inst) + '\n') |
|
692 | 692 | if not self.ui.verbose: |
|
693 | 693 | self.ui.warn(_("patch failed, unable to continue (try -v)\n")) |
|
694 | 694 | self.ui.traceback() |
|
695 | 695 | return (False, list(files), False) |
|
696 | 696 | |
|
697 | 697 | def apply(self, repo, series, list=False, update_status=True, |
|
698 | 698 | strict=False, patchdir=None, merge=None, all_files=None, |
|
699 | 699 | tobackup=None, keepchanges=False): |
|
700 | 700 | wlock = lock = tr = None |
|
701 | 701 | try: |
|
702 | 702 | wlock = repo.wlock() |
|
703 | 703 | lock = repo.lock() |
|
704 | 704 | tr = repo.transaction("qpush") |
|
705 | 705 | try: |
|
706 | 706 | ret = self._apply(repo, series, list, update_status, |
|
707 | 707 | strict, patchdir, merge, all_files=all_files, |
|
708 | 708 | tobackup=tobackup, keepchanges=keepchanges) |
|
709 | 709 | tr.close() |
|
710 | 710 | self.savedirty() |
|
711 | 711 | return ret |
|
712 | 712 | except AbortNoCleanup: |
|
713 | 713 | tr.close() |
|
714 | 714 | self.savedirty() |
|
715 | 715 | return 2, repo.dirstate.p1() |
|
716 | 716 | except: # re-raises |
|
717 | 717 | try: |
|
718 | 718 | tr.abort() |
|
719 | 719 | finally: |
|
720 | 720 | repo.invalidate() |
|
721 | 721 | repo.dirstate.invalidate() |
|
722 | 722 | self.invalidate() |
|
723 | 723 | raise |
|
724 | 724 | finally: |
|
725 | 725 | release(tr, lock, wlock) |
|
726 | 726 | self.removeundo(repo) |
|
727 | 727 | |
|
728 | 728 | def _apply(self, repo, series, list=False, update_status=True, |
|
729 | 729 | strict=False, patchdir=None, merge=None, all_files=None, |
|
730 | 730 | tobackup=None, keepchanges=False): |
|
731 | 731 | """returns (error, hash) |
|
732 | 732 | |
|
733 | 733 | error = 1 for unable to read, 2 for patch failed, 3 for patch |
|
734 | 734 | fuzz. tobackup is None or a set of files to backup before they |
|
735 | 735 | are modified by a patch. |
|
736 | 736 | """ |
|
737 | 737 | # TODO unify with commands.py |
|
738 | 738 | if not patchdir: |
|
739 | 739 | patchdir = self.path |
|
740 | 740 | err = 0 |
|
741 | 741 | n = None |
|
742 | 742 | for patchname in series: |
|
743 | 743 | pushable, reason = self.pushable(patchname) |
|
744 | 744 | if not pushable: |
|
745 | 745 | self.explainpushable(patchname, all_patches=True) |
|
746 | 746 | continue |
|
747 | 747 | self.ui.status(_("applying %s\n") % patchname) |
|
748 | 748 | pf = os.path.join(patchdir, patchname) |
|
749 | 749 | |
|
750 | 750 | try: |
|
751 | 751 | ph = patchheader(self.join(patchname), self.plainmode) |
|
752 | 752 | except IOError: |
|
753 | 753 | self.ui.warn(_("unable to read %s\n") % patchname) |
|
754 | 754 | err = 1 |
|
755 | 755 | break |
|
756 | 756 | |
|
757 | 757 | message = ph.message |
|
758 | 758 | if not message: |
|
759 | 759 | # The commit message should not be translated |
|
760 | 760 | message = "imported patch %s\n" % patchname |
|
761 | 761 | else: |
|
762 | 762 | if list: |
|
763 | 763 | # The commit message should not be translated |
|
764 | 764 | message.append("\nimported patch %s" % patchname) |
|
765 | 765 | message = '\n'.join(message) |
|
766 | 766 | |
|
767 | 767 | if ph.haspatch: |
|
768 | 768 | if tobackup: |
|
769 | 769 | touched = patchmod.changedfiles(self.ui, repo, pf) |
|
770 | 770 | touched = set(touched) & tobackup |
|
771 | 771 | if touched and keepchanges: |
|
772 | 772 | raise AbortNoCleanup( |
|
773 | 773 | _("local changes found, refresh first")) |
|
774 | 774 | self.backup(repo, touched, copy=True) |
|
775 | 775 | tobackup = tobackup - touched |
|
776 | 776 | (patcherr, files, fuzz) = self.patch(repo, pf) |
|
777 | 777 | if all_files is not None: |
|
778 | 778 | all_files.update(files) |
|
779 | 779 | patcherr = not patcherr |
|
780 | 780 | else: |
|
781 | 781 | self.ui.warn(_("patch %s is empty\n") % patchname) |
|
782 | 782 | patcherr, files, fuzz = 0, [], 0 |
|
783 | 783 | |
|
784 | 784 | if merge and files: |
|
785 | 785 | # Mark as removed/merged and update dirstate parent info |
|
786 | 786 | removed = [] |
|
787 | 787 | merged = [] |
|
788 | 788 | for f in files: |
|
789 | 789 | if os.path.lexists(repo.wjoin(f)): |
|
790 | 790 | merged.append(f) |
|
791 | 791 | else: |
|
792 | 792 | removed.append(f) |
|
793 | 793 | for f in removed: |
|
794 | 794 | repo.dirstate.remove(f) |
|
795 | 795 | for f in merged: |
|
796 | 796 | repo.dirstate.merge(f) |
|
797 | 797 | p1, p2 = repo.dirstate.parents() |
|
798 | 798 | repo.setparents(p1, merge) |
|
799 | 799 | |
|
800 | 800 | match = scmutil.matchfiles(repo, files or []) |
|
801 | 801 | oldtip = repo['tip'] |
|
802 | 802 | n = newcommit(repo, None, message, ph.user, ph.date, match=match, |
|
803 | 803 | force=True) |
|
804 | 804 | if repo['tip'] == oldtip: |
|
805 | 805 | raise util.Abort(_("qpush exactly duplicates child changeset")) |
|
806 | 806 | if n is None: |
|
807 | 807 | raise util.Abort(_("repository commit failed")) |
|
808 | 808 | |
|
809 | 809 | if update_status: |
|
810 | 810 | self.applied.append(statusentry(n, patchname)) |
|
811 | 811 | |
|
812 | 812 | if patcherr: |
|
813 | 813 | self.ui.warn(_("patch failed, rejects left in working dir\n")) |
|
814 | 814 | err = 2 |
|
815 | 815 | break |
|
816 | 816 | |
|
817 | 817 | if fuzz and strict: |
|
818 | 818 | self.ui.warn(_("fuzz found when applying patch, stopping\n")) |
|
819 | 819 | err = 3 |
|
820 | 820 | break |
|
821 | 821 | return (err, n) |
|
822 | 822 | |
|
823 | 823 | def _cleanup(self, patches, numrevs, keep=False): |
|
824 | 824 | if not keep: |
|
825 | 825 | r = self.qrepo() |
|
826 | 826 | if r: |
|
827 | 827 | r[None].forget(patches) |
|
828 | 828 | for p in patches: |
|
829 | 829 | os.unlink(self.join(p)) |
|
830 | 830 | |
|
831 | 831 | qfinished = [] |
|
832 | 832 | if numrevs: |
|
833 | 833 | qfinished = self.applied[:numrevs] |
|
834 | 834 | del self.applied[:numrevs] |
|
835 | 835 | self.applieddirty = True |
|
836 | 836 | |
|
837 | 837 | unknown = [] |
|
838 | 838 | |
|
839 | 839 | for (i, p) in sorted([(self.findseries(p), p) for p in patches], |
|
840 | 840 | reverse=True): |
|
841 | 841 | if i is not None: |
|
842 | 842 | del self.fullseries[i] |
|
843 | 843 | else: |
|
844 | 844 | unknown.append(p) |
|
845 | 845 | |
|
846 | 846 | if unknown: |
|
847 | 847 | if numrevs: |
|
848 | 848 | rev = dict((entry.name, entry.node) for entry in qfinished) |
|
849 | 849 | for p in unknown: |
|
850 | 850 | msg = _('revision %s refers to unknown patches: %s\n') |
|
851 | 851 | self.ui.warn(msg % (short(rev[p]), p)) |
|
852 | 852 | else: |
|
853 | 853 | msg = _('unknown patches: %s\n') |
|
854 | 854 | raise util.Abort(''.join(msg % p for p in unknown)) |
|
855 | 855 | |
|
856 | 856 | self.parseseries() |
|
857 | 857 | self.seriesdirty = True |
|
858 | 858 | return [entry.node for entry in qfinished] |
|
859 | 859 | |
|
860 | 860 | def _revpatches(self, repo, revs): |
|
861 | 861 | firstrev = repo[self.applied[0].node].rev() |
|
862 | 862 | patches = [] |
|
863 | 863 | for i, rev in enumerate(revs): |
|
864 | 864 | |
|
865 | 865 | if rev < firstrev: |
|
866 | 866 | raise util.Abort(_('revision %d is not managed') % rev) |
|
867 | 867 | |
|
868 | 868 | ctx = repo[rev] |
|
869 | 869 | base = self.applied[i].node |
|
870 | 870 | if ctx.node() != base: |
|
871 | 871 | msg = _('cannot delete revision %d above applied patches') |
|
872 | 872 | raise util.Abort(msg % rev) |
|
873 | 873 | |
|
874 | 874 | patch = self.applied[i].name |
|
875 | 875 | for fmt in ('[mq]: %s', 'imported patch %s'): |
|
876 | 876 | if ctx.description() == fmt % patch: |
|
877 | 877 | msg = _('patch %s finalized without changeset message\n') |
|
878 | 878 | repo.ui.status(msg % patch) |
|
879 | 879 | break |
|
880 | 880 | |
|
881 | 881 | patches.append(patch) |
|
882 | 882 | return patches |
|
883 | 883 | |
|
884 | 884 | def finish(self, repo, revs): |
|
885 | 885 | # Manually trigger phase computation to ensure phasedefaults is |
|
886 | 886 | # executed before we remove the patches. |
|
887 | 887 | repo._phasecache |
|
888 | 888 | patches = self._revpatches(repo, sorted(revs)) |
|
889 | 889 | qfinished = self._cleanup(patches, len(patches)) |
|
890 | 890 | if qfinished and repo.ui.configbool('mq', 'secret', False): |
|
891 | 891 | # only use this logic when the secret option is added |
|
892 | 892 | oldqbase = repo[qfinished[0]] |
|
893 | 893 | tphase = repo.ui.config('phases', 'new-commit', phases.draft) |
|
894 | 894 | if oldqbase.phase() > tphase and oldqbase.p1().phase() <= tphase: |
|
895 | 895 | phases.advanceboundary(repo, tphase, qfinished) |
|
896 | 896 | |
|
897 | 897 | def delete(self, repo, patches, opts): |
|
898 | 898 | if not patches and not opts.get('rev'): |
|
899 | 899 | raise util.Abort(_('qdelete requires at least one revision or ' |
|
900 | 900 | 'patch name')) |
|
901 | 901 | |
|
902 | 902 | realpatches = [] |
|
903 | 903 | for patch in patches: |
|
904 | 904 | patch = self.lookup(patch, strict=True) |
|
905 | 905 | info = self.isapplied(patch) |
|
906 | 906 | if info: |
|
907 | 907 | raise util.Abort(_("cannot delete applied patch %s") % patch) |
|
908 | 908 | if patch not in self.series: |
|
909 | 909 | raise util.Abort(_("patch %s not in series file") % patch) |
|
910 | 910 | if patch not in realpatches: |
|
911 | 911 | realpatches.append(patch) |
|
912 | 912 | |
|
913 | 913 | numrevs = 0 |
|
914 | 914 | if opts.get('rev'): |
|
915 | 915 | if not self.applied: |
|
916 | 916 | raise util.Abort(_('no patches applied')) |
|
917 | 917 | revs = scmutil.revrange(repo, opts.get('rev')) |
|
918 | 918 | if len(revs) > 1 and revs[0] > revs[1]: |
|
919 | 919 | revs.reverse() |
|
920 | 920 | revpatches = self._revpatches(repo, revs) |
|
921 | 921 | realpatches += revpatches |
|
922 | 922 | numrevs = len(revpatches) |
|
923 | 923 | |
|
924 | 924 | self._cleanup(realpatches, numrevs, opts.get('keep')) |
|
925 | 925 | |
|
926 | 926 | def checktoppatch(self, repo): |
|
927 | 927 | if self.applied: |
|
928 | 928 | top = self.applied[-1].node |
|
929 | 929 | patch = self.applied[-1].name |
|
930 | 930 | pp = repo.dirstate.parents() |
|
931 | 931 | if top not in pp: |
|
932 | 932 | raise util.Abort(_("working directory revision is not qtip")) |
|
933 | 933 | return top, patch |
|
934 | 934 | return None, None |
|
935 | 935 | |
|
936 | 936 | def checksubstate(self, repo, baserev=None): |
|
937 | 937 | '''return list of subrepos at a different revision than substate. |
|
938 | 938 | Abort if any subrepos have uncommitted changes.''' |
|
939 | 939 | inclsubs = [] |
|
940 | 940 | wctx = repo[None] |
|
941 | 941 | if baserev: |
|
942 | 942 | bctx = repo[baserev] |
|
943 | 943 | else: |
|
944 | 944 | bctx = wctx.parents()[0] |
|
945 | 945 | for s in wctx.substate: |
|
946 | 946 | if wctx.sub(s).dirty(True): |
|
947 | 947 | raise util.Abort( |
|
948 | 948 | _("uncommitted changes in subrepository %s") % s) |
|
949 | 949 | elif s not in bctx.substate or bctx.sub(s).dirty(): |
|
950 | 950 | inclsubs.append(s) |
|
951 | 951 | return inclsubs |
|
952 | 952 | |
|
953 | 953 | def putsubstate2changes(self, substatestate, changes): |
|
954 | 954 | for files in changes[:3]: |
|
955 | 955 | if '.hgsubstate' in files: |
|
956 | 956 | return # already listed up |
|
957 | 957 | # not yet listed up |
|
958 | 958 | if substatestate in 'a?': |
|
959 | 959 | changes[1].append('.hgsubstate') |
|
960 | 960 | elif substatestate in 'r': |
|
961 | 961 | changes[2].append('.hgsubstate') |
|
962 | 962 | else: # modified |
|
963 | 963 | changes[0].append('.hgsubstate') |
|
964 | 964 | |
|
965 | 965 | def localchangesfound(self, refresh=True): |
|
966 | 966 | if refresh: |
|
967 | 967 | raise util.Abort(_("local changes found, refresh first")) |
|
968 | 968 | else: |
|
969 | 969 | raise util.Abort(_("local changes found")) |
|
970 | 970 | |
|
971 | 971 | def checklocalchanges(self, repo, force=False, refresh=True): |
|
972 | 972 | m, a, r, d = repo.status()[:4] |
|
973 | 973 | if (m or a or r or d) and not force: |
|
974 | 974 | self.localchangesfound(refresh) |
|
975 | 975 | return m, a, r, d |
|
976 | 976 | |
|
977 | 977 | _reserved = ('series', 'status', 'guards', '.', '..') |
|
978 | 978 | def checkreservedname(self, name): |
|
979 | 979 | if name in self._reserved: |
|
980 | 980 | raise util.Abort(_('"%s" cannot be used as the name of a patch') |
|
981 | 981 | % name) |
|
982 | 982 | for prefix in ('.hg', '.mq'): |
|
983 | 983 | if name.startswith(prefix): |
|
984 | 984 | raise util.Abort(_('patch name cannot begin with "%s"') |
|
985 | 985 | % prefix) |
|
986 | 986 | for c in ('#', ':'): |
|
987 | 987 | if c in name: |
|
988 | 988 | raise util.Abort(_('"%s" cannot be used in the name of a patch') |
|
989 | 989 | % c) |
|
990 | 990 | |
|
991 | 991 | def checkpatchname(self, name, force=False): |
|
992 | 992 | self.checkreservedname(name) |
|
993 | 993 | if not force and os.path.exists(self.join(name)): |
|
994 | 994 | if os.path.isdir(self.join(name)): |
|
995 | 995 | raise util.Abort(_('"%s" already exists as a directory') |
|
996 | 996 | % name) |
|
997 | 997 | else: |
|
998 | 998 | raise util.Abort(_('patch "%s" already exists') % name) |
|
999 | 999 | |
|
1000 | 1000 | def checkkeepchanges(self, keepchanges, force): |
|
1001 | 1001 | if force and keepchanges: |
|
1002 | 1002 | raise util.Abort(_('cannot use both --force and --keep-changes')) |
|
1003 | 1003 | |
|
1004 | 1004 | def new(self, repo, patchfn, *pats, **opts): |
|
1005 | 1005 | """options: |
|
1006 | 1006 | msg: a string or a no-argument function returning a string |
|
1007 | 1007 | """ |
|
1008 | 1008 | msg = opts.get('msg') |
|
1009 | 1009 | user = opts.get('user') |
|
1010 | 1010 | date = opts.get('date') |
|
1011 | 1011 | if date: |
|
1012 | 1012 | date = util.parsedate(date) |
|
1013 | 1013 | diffopts = self.diffopts({'git': opts.get('git')}) |
|
1014 | 1014 | if opts.get('checkname', True): |
|
1015 | 1015 | self.checkpatchname(patchfn) |
|
1016 | 1016 | inclsubs = self.checksubstate(repo) |
|
1017 | 1017 | if inclsubs: |
|
1018 | 1018 | inclsubs.append('.hgsubstate') |
|
1019 | 1019 | substatestate = repo.dirstate['.hgsubstate'] |
|
1020 | 1020 | if opts.get('include') or opts.get('exclude') or pats: |
|
1021 | 1021 | if inclsubs: |
|
1022 | 1022 | pats = list(pats or []) + inclsubs |
|
1023 | 1023 | match = scmutil.match(repo[None], pats, opts) |
|
1024 | 1024 | # detect missing files in pats |
|
1025 | 1025 | def badfn(f, msg): |
|
1026 | 1026 | if f != '.hgsubstate': # .hgsubstate is auto-created |
|
1027 | 1027 | raise util.Abort('%s: %s' % (f, msg)) |
|
1028 | 1028 | match.bad = badfn |
|
1029 | 1029 | changes = repo.status(match=match) |
|
1030 | 1030 | m, a, r, d = changes[:4] |
|
1031 | 1031 | else: |
|
1032 | 1032 | changes = self.checklocalchanges(repo, force=True) |
|
1033 | 1033 | m, a, r, d = changes |
|
1034 | 1034 | match = scmutil.matchfiles(repo, m + a + r + inclsubs) |
|
1035 | 1035 | if len(repo[None].parents()) > 1: |
|
1036 | 1036 | raise util.Abort(_('cannot manage merge changesets')) |
|
1037 | 1037 | commitfiles = m + a + r |
|
1038 | 1038 | self.checktoppatch(repo) |
|
1039 | 1039 | insert = self.fullseriesend() |
|
1040 | 1040 | wlock = repo.wlock() |
|
1041 | 1041 | try: |
|
1042 | 1042 | try: |
|
1043 | 1043 | # if patch file write fails, abort early |
|
1044 | 1044 | p = self.opener(patchfn, "w") |
|
1045 | 1045 | except IOError, e: |
|
1046 | 1046 | raise util.Abort(_('cannot write patch "%s": %s') |
|
1047 | 1047 | % (patchfn, e.strerror)) |
|
1048 | 1048 | try: |
|
1049 | 1049 | if self.plainmode: |
|
1050 | 1050 | if user: |
|
1051 | 1051 | p.write("From: " + user + "\n") |
|
1052 | 1052 | if not date: |
|
1053 | 1053 | p.write("\n") |
|
1054 | 1054 | if date: |
|
1055 | 1055 | p.write("Date: %d %d\n\n" % date) |
|
1056 | 1056 | else: |
|
1057 | 1057 | p.write("# HG changeset patch\n") |
|
1058 | 1058 | p.write("# Parent " |
|
1059 | 1059 | + hex(repo[None].p1().node()) + "\n") |
|
1060 | 1060 | if user: |
|
1061 | 1061 | p.write("# User " + user + "\n") |
|
1062 | 1062 | if date: |
|
1063 | 1063 | p.write("# Date %s %s\n\n" % date) |
|
1064 | 1064 | if util.safehasattr(msg, '__call__'): |
|
1065 | 1065 | msg = msg() |
|
1066 | 1066 | commitmsg = msg and msg or ("[mq]: %s" % patchfn) |
|
1067 | 1067 | n = newcommit(repo, None, commitmsg, user, date, match=match, |
|
1068 | 1068 | force=True) |
|
1069 | 1069 | if n is None: |
|
1070 | 1070 | raise util.Abort(_("repo commit failed")) |
|
1071 | 1071 | try: |
|
1072 | 1072 | self.fullseries[insert:insert] = [patchfn] |
|
1073 | 1073 | self.applied.append(statusentry(n, patchfn)) |
|
1074 | 1074 | self.parseseries() |
|
1075 | 1075 | self.seriesdirty = True |
|
1076 | 1076 | self.applieddirty = True |
|
1077 | 1077 | if msg: |
|
1078 | 1078 | msg = msg + "\n\n" |
|
1079 | 1079 | p.write(msg) |
|
1080 | 1080 | if commitfiles: |
|
1081 | 1081 | parent = self.qparents(repo, n) |
|
1082 | 1082 | if inclsubs: |
|
1083 | 1083 | self.putsubstate2changes(substatestate, changes) |
|
1084 | 1084 | chunks = patchmod.diff(repo, node1=parent, node2=n, |
|
1085 | 1085 | changes=changes, opts=diffopts) |
|
1086 | 1086 | for chunk in chunks: |
|
1087 | 1087 | p.write(chunk) |
|
1088 | 1088 | p.close() |
|
1089 | 1089 | r = self.qrepo() |
|
1090 | 1090 | if r: |
|
1091 | 1091 | r[None].add([patchfn]) |
|
1092 | 1092 | except: # re-raises |
|
1093 | 1093 | repo.rollback() |
|
1094 | 1094 | raise |
|
1095 | 1095 | except Exception: |
|
1096 | 1096 | patchpath = self.join(patchfn) |
|
1097 | 1097 | try: |
|
1098 | 1098 | os.unlink(patchpath) |
|
1099 | 1099 | except OSError: |
|
1100 | 1100 | self.ui.warn(_('error unlinking %s\n') % patchpath) |
|
1101 | 1101 | raise |
|
1102 | 1102 | self.removeundo(repo) |
|
1103 | 1103 | finally: |
|
1104 | 1104 | release(wlock) |
|
1105 | 1105 | |
|
1106 | 1106 | def strip(self, repo, revs, update=True, backup="all", force=None): |
|
1107 | 1107 | wlock = lock = None |
|
1108 | 1108 | try: |
|
1109 | 1109 | wlock = repo.wlock() |
|
1110 | 1110 | lock = repo.lock() |
|
1111 | 1111 | |
|
1112 | 1112 | if update: |
|
1113 | 1113 | self.checklocalchanges(repo, force=force, refresh=False) |
|
1114 | 1114 | urev = self.qparents(repo, revs[0]) |
|
1115 | 1115 | hg.clean(repo, urev) |
|
1116 | 1116 | repo.dirstate.write() |
|
1117 | 1117 | |
|
1118 | 1118 | repair.strip(self.ui, repo, revs, backup) |
|
1119 | 1119 | finally: |
|
1120 | 1120 | release(lock, wlock) |
|
1121 | 1121 | |
|
1122 | 1122 | def isapplied(self, patch): |
|
1123 | 1123 | """returns (index, rev, patch)""" |
|
1124 | 1124 | for i, a in enumerate(self.applied): |
|
1125 | 1125 | if a.name == patch: |
|
1126 | 1126 | return (i, a.node, a.name) |
|
1127 | 1127 | return None |
|
1128 | 1128 | |
|
1129 | 1129 | # if the exact patch name does not exist, we try a few |
|
1130 | 1130 | # variations. If strict is passed, we try only #1 |
|
1131 | 1131 | # |
|
1132 | 1132 | # 1) a number (as string) to indicate an offset in the series file |
|
1133 | 1133 | # 2) a unique substring of the patch name was given |
|
1134 | 1134 | # 3) patchname[-+]num to indicate an offset in the series file |
|
1135 | 1135 | def lookup(self, patch, strict=False): |
|
1136 | 1136 | def partialname(s): |
|
1137 | 1137 | if s in self.series: |
|
1138 | 1138 | return s |
|
1139 | 1139 | matches = [x for x in self.series if s in x] |
|
1140 | 1140 | if len(matches) > 1: |
|
1141 | 1141 | self.ui.warn(_('patch name "%s" is ambiguous:\n') % s) |
|
1142 | 1142 | for m in matches: |
|
1143 | 1143 | self.ui.warn(' %s\n' % m) |
|
1144 | 1144 | return None |
|
1145 | 1145 | if matches: |
|
1146 | 1146 | return matches[0] |
|
1147 | 1147 | if self.series and self.applied: |
|
1148 | 1148 | if s == 'qtip': |
|
1149 | 1149 | return self.series[self.seriesend(True)-1] |
|
1150 | 1150 | if s == 'qbase': |
|
1151 | 1151 | return self.series[0] |
|
1152 | 1152 | return None |
|
1153 | 1153 | |
|
1154 | 1154 | if patch in self.series: |
|
1155 | 1155 | return patch |
|
1156 | 1156 | |
|
1157 | 1157 | if not os.path.isfile(self.join(patch)): |
|
1158 | 1158 | try: |
|
1159 | 1159 | sno = int(patch) |
|
1160 | 1160 | except (ValueError, OverflowError): |
|
1161 | 1161 | pass |
|
1162 | 1162 | else: |
|
1163 | 1163 | if -len(self.series) <= sno < len(self.series): |
|
1164 | 1164 | return self.series[sno] |
|
1165 | 1165 | |
|
1166 | 1166 | if not strict: |
|
1167 | 1167 | res = partialname(patch) |
|
1168 | 1168 | if res: |
|
1169 | 1169 | return res |
|
1170 | 1170 | minus = patch.rfind('-') |
|
1171 | 1171 | if minus >= 0: |
|
1172 | 1172 | res = partialname(patch[:minus]) |
|
1173 | 1173 | if res: |
|
1174 | 1174 | i = self.series.index(res) |
|
1175 | 1175 | try: |
|
1176 | 1176 | off = int(patch[minus + 1:] or 1) |
|
1177 | 1177 | except (ValueError, OverflowError): |
|
1178 | 1178 | pass |
|
1179 | 1179 | else: |
|
1180 | 1180 | if i - off >= 0: |
|
1181 | 1181 | return self.series[i - off] |
|
1182 | 1182 | plus = patch.rfind('+') |
|
1183 | 1183 | if plus >= 0: |
|
1184 | 1184 | res = partialname(patch[:plus]) |
|
1185 | 1185 | if res: |
|
1186 | 1186 | i = self.series.index(res) |
|
1187 | 1187 | try: |
|
1188 | 1188 | off = int(patch[plus + 1:] or 1) |
|
1189 | 1189 | except (ValueError, OverflowError): |
|
1190 | 1190 | pass |
|
1191 | 1191 | else: |
|
1192 | 1192 | if i + off < len(self.series): |
|
1193 | 1193 | return self.series[i + off] |
|
1194 | 1194 | raise util.Abort(_("patch %s not in series") % patch) |
|
1195 | 1195 | |
|
1196 | 1196 | def push(self, repo, patch=None, force=False, list=False, mergeq=None, |
|
1197 | 1197 | all=False, move=False, exact=False, nobackup=False, |
|
1198 | 1198 | keepchanges=False): |
|
1199 | 1199 | self.checkkeepchanges(keepchanges, force) |
|
1200 | 1200 | diffopts = self.diffopts() |
|
1201 | 1201 | wlock = repo.wlock() |
|
1202 | 1202 | try: |
|
1203 | 1203 | heads = [] |
|
1204 | 1204 | for b, ls in repo.branchmap().iteritems(): |
|
1205 | 1205 | heads += ls |
|
1206 | 1206 | if not heads: |
|
1207 | 1207 | heads = [nullid] |
|
1208 | 1208 | if repo.dirstate.p1() not in heads and not exact: |
|
1209 | 1209 | self.ui.status(_("(working directory not at a head)\n")) |
|
1210 | 1210 | |
|
1211 | 1211 | if not self.series: |
|
1212 | 1212 | self.ui.warn(_('no patches in series\n')) |
|
1213 | 1213 | return 0 |
|
1214 | 1214 | |
|
1215 | 1215 | # Suppose our series file is: A B C and the current 'top' |
|
1216 | 1216 | # patch is B. qpush C should be performed (moving forward) |
|
1217 | 1217 | # qpush B is a NOP (no change) qpush A is an error (can't |
|
1218 | 1218 | # go backwards with qpush) |
|
1219 | 1219 | if patch: |
|
1220 | 1220 | patch = self.lookup(patch) |
|
1221 | 1221 | info = self.isapplied(patch) |
|
1222 | 1222 | if info and info[0] >= len(self.applied) - 1: |
|
1223 | 1223 | self.ui.warn( |
|
1224 | 1224 | _('qpush: %s is already at the top\n') % patch) |
|
1225 | 1225 | return 0 |
|
1226 | 1226 | |
|
1227 | 1227 | pushable, reason = self.pushable(patch) |
|
1228 | 1228 | if pushable: |
|
1229 | 1229 | if self.series.index(patch) < self.seriesend(): |
|
1230 | 1230 | raise util.Abort( |
|
1231 | 1231 | _("cannot push to a previous patch: %s") % patch) |
|
1232 | 1232 | else: |
|
1233 | 1233 | if reason: |
|
1234 | 1234 | reason = _('guarded by %s') % reason |
|
1235 | 1235 | else: |
|
1236 | 1236 | reason = _('no matching guards') |
|
1237 | 1237 | self.ui.warn(_("cannot push '%s' - %s\n") % (patch, reason)) |
|
1238 | 1238 | return 1 |
|
1239 | 1239 | elif all: |
|
1240 | 1240 | patch = self.series[-1] |
|
1241 | 1241 | if self.isapplied(patch): |
|
1242 | 1242 | self.ui.warn(_('all patches are currently applied\n')) |
|
1243 | 1243 | return 0 |
|
1244 | 1244 | |
|
1245 | 1245 | # Following the above example, starting at 'top' of B: |
|
1246 | 1246 | # qpush should be performed (pushes C), but a subsequent |
|
1247 | 1247 | # qpush without an argument is an error (nothing to |
|
1248 | 1248 | # apply). This allows a loop of "...while hg qpush..." to |
|
1249 | 1249 | # work as it detects an error when done |
|
1250 | 1250 | start = self.seriesend() |
|
1251 | 1251 | if start == len(self.series): |
|
1252 | 1252 | self.ui.warn(_('patch series already fully applied\n')) |
|
1253 | 1253 | return 1 |
|
1254 | 1254 | if not force and not keepchanges: |
|
1255 | 1255 | self.checklocalchanges(repo, refresh=self.applied) |
|
1256 | 1256 | |
|
1257 | 1257 | if exact: |
|
1258 | 1258 | if keepchanges: |
|
1259 | 1259 | raise util.Abort( |
|
1260 | 1260 | _("cannot use --exact and --keep-changes together")) |
|
1261 | 1261 | if move: |
|
1262 | 1262 | raise util.Abort(_('cannot use --exact and --move ' |
|
1263 | 1263 | 'together')) |
|
1264 | 1264 | if self.applied: |
|
1265 | 1265 | raise util.Abort(_('cannot push --exact with applied ' |
|
1266 | 1266 | 'patches')) |
|
1267 | 1267 | root = self.series[start] |
|
1268 | 1268 | target = patchheader(self.join(root), self.plainmode).parent |
|
1269 | 1269 | if not target: |
|
1270 | 1270 | raise util.Abort( |
|
1271 | 1271 | _("%s does not have a parent recorded") % root) |
|
1272 | 1272 | if not repo[target] == repo['.']: |
|
1273 | 1273 | hg.update(repo, target) |
|
1274 | 1274 | |
|
1275 | 1275 | if move: |
|
1276 | 1276 | if not patch: |
|
1277 | 1277 | raise util.Abort(_("please specify the patch to move")) |
|
1278 | 1278 | for fullstart, rpn in enumerate(self.fullseries): |
|
1279 | 1279 | # strip markers for patch guards |
|
1280 | 1280 | if self.guard_re.split(rpn, 1)[0] == self.series[start]: |
|
1281 | 1281 | break |
|
1282 | 1282 | for i, rpn in enumerate(self.fullseries[fullstart:]): |
|
1283 | 1283 | # strip markers for patch guards |
|
1284 | 1284 | if self.guard_re.split(rpn, 1)[0] == patch: |
|
1285 | 1285 | break |
|
1286 | 1286 | index = fullstart + i |
|
1287 | 1287 | assert index < len(self.fullseries) |
|
1288 | 1288 | fullpatch = self.fullseries[index] |
|
1289 | 1289 | del self.fullseries[index] |
|
1290 | 1290 | self.fullseries.insert(fullstart, fullpatch) |
|
1291 | 1291 | self.parseseries() |
|
1292 | 1292 | self.seriesdirty = True |
|
1293 | 1293 | |
|
1294 | 1294 | self.applieddirty = True |
|
1295 | 1295 | if start > 0: |
|
1296 | 1296 | self.checktoppatch(repo) |
|
1297 | 1297 | if not patch: |
|
1298 | 1298 | patch = self.series[start] |
|
1299 | 1299 | end = start + 1 |
|
1300 | 1300 | else: |
|
1301 | 1301 | end = self.series.index(patch, start) + 1 |
|
1302 | 1302 | |
|
1303 | 1303 | tobackup = set() |
|
1304 | 1304 | if (not nobackup and force) or keepchanges: |
|
1305 | 1305 | m, a, r, d = self.checklocalchanges(repo, force=True) |
|
1306 | 1306 | if keepchanges: |
|
1307 | 1307 | tobackup.update(m + a + r + d) |
|
1308 | 1308 | else: |
|
1309 | 1309 | tobackup.update(m + a) |
|
1310 | 1310 | |
|
1311 | 1311 | s = self.series[start:end] |
|
1312 | 1312 | all_files = set() |
|
1313 | 1313 | try: |
|
1314 | 1314 | if mergeq: |
|
1315 | 1315 | ret = self.mergepatch(repo, mergeq, s, diffopts) |
|
1316 | 1316 | else: |
|
1317 | 1317 | ret = self.apply(repo, s, list, all_files=all_files, |
|
1318 | 1318 | tobackup=tobackup, keepchanges=keepchanges) |
|
1319 | 1319 | except: # re-raises |
|
1320 | 1320 | self.ui.warn(_('cleaning up working directory...')) |
|
1321 | 1321 | node = repo.dirstate.p1() |
|
1322 | 1322 | hg.revert(repo, node, None) |
|
1323 | 1323 | # only remove unknown files that we know we touched or |
|
1324 | 1324 | # created while patching |
|
1325 | 1325 | for f in all_files: |
|
1326 | 1326 | if f not in repo.dirstate: |
|
1327 | 1327 | try: |
|
1328 | 1328 | util.unlinkpath(repo.wjoin(f)) |
|
1329 | 1329 | except OSError, inst: |
|
1330 | 1330 | if inst.errno != errno.ENOENT: |
|
1331 | 1331 | raise |
|
1332 | 1332 | self.ui.warn(_('done\n')) |
|
1333 | 1333 | raise |
|
1334 | 1334 | |
|
1335 | 1335 | if not self.applied: |
|
1336 | 1336 | return ret[0] |
|
1337 | 1337 | top = self.applied[-1].name |
|
1338 | 1338 | if ret[0] and ret[0] > 1: |
|
1339 | 1339 | msg = _("errors during apply, please fix and refresh %s\n") |
|
1340 | 1340 | self.ui.write(msg % top) |
|
1341 | 1341 | else: |
|
1342 | 1342 | self.ui.write(_("now at: %s\n") % top) |
|
1343 | 1343 | return ret[0] |
|
1344 | 1344 | |
|
1345 | 1345 | finally: |
|
1346 | 1346 | wlock.release() |
|
1347 | 1347 | |
|
1348 | 1348 | def pop(self, repo, patch=None, force=False, update=True, all=False, |
|
1349 | 1349 | nobackup=False, keepchanges=False): |
|
1350 | 1350 | self.checkkeepchanges(keepchanges, force) |
|
1351 | 1351 | wlock = repo.wlock() |
|
1352 | 1352 | try: |
|
1353 | 1353 | if patch: |
|
1354 | 1354 | # index, rev, patch |
|
1355 | 1355 | info = self.isapplied(patch) |
|
1356 | 1356 | if not info: |
|
1357 | 1357 | patch = self.lookup(patch) |
|
1358 | 1358 | info = self.isapplied(patch) |
|
1359 | 1359 | if not info: |
|
1360 | 1360 | raise util.Abort(_("patch %s is not applied") % patch) |
|
1361 | 1361 | |
|
1362 | 1362 | if not self.applied: |
|
1363 | 1363 | # Allow qpop -a to work repeatedly, |
|
1364 | 1364 | # but not qpop without an argument |
|
1365 | 1365 | self.ui.warn(_("no patches applied\n")) |
|
1366 | 1366 | return not all |
|
1367 | 1367 | |
|
1368 | 1368 | if all: |
|
1369 | 1369 | start = 0 |
|
1370 | 1370 | elif patch: |
|
1371 | 1371 | start = info[0] + 1 |
|
1372 | 1372 | else: |
|
1373 | 1373 | start = len(self.applied) - 1 |
|
1374 | 1374 | |
|
1375 | 1375 | if start >= len(self.applied): |
|
1376 | 1376 | self.ui.warn(_("qpop: %s is already at the top\n") % patch) |
|
1377 | 1377 | return |
|
1378 | 1378 | |
|
1379 | 1379 | if not update: |
|
1380 | 1380 | parents = repo.dirstate.parents() |
|
1381 | 1381 | rr = [x.node for x in self.applied] |
|
1382 | 1382 | for p in parents: |
|
1383 | 1383 | if p in rr: |
|
1384 | 1384 | self.ui.warn(_("qpop: forcing dirstate update\n")) |
|
1385 | 1385 | update = True |
|
1386 | 1386 | else: |
|
1387 | 1387 | parents = [p.node() for p in repo[None].parents()] |
|
1388 | 1388 | needupdate = False |
|
1389 | 1389 | for entry in self.applied[start:]: |
|
1390 | 1390 | if entry.node in parents: |
|
1391 | 1391 | needupdate = True |
|
1392 | 1392 | break |
|
1393 | 1393 | update = needupdate |
|
1394 | 1394 | |
|
1395 | 1395 | tobackup = set() |
|
1396 | 1396 | if update: |
|
1397 | 1397 | m, a, r, d = self.checklocalchanges( |
|
1398 | 1398 | repo, force=force or keepchanges) |
|
1399 | 1399 | if force: |
|
1400 | 1400 | if not nobackup: |
|
1401 | 1401 | tobackup.update(m + a) |
|
1402 | 1402 | elif keepchanges: |
|
1403 | 1403 | tobackup.update(m + a + r + d) |
|
1404 | 1404 | |
|
1405 | 1405 | self.applieddirty = True |
|
1406 | 1406 | end = len(self.applied) |
|
1407 | 1407 | rev = self.applied[start].node |
|
1408 | 1408 | if update: |
|
1409 | 1409 | top = self.checktoppatch(repo)[0] |
|
1410 | 1410 | |
|
1411 | 1411 | try: |
|
1412 | 1412 | heads = repo.changelog.heads(rev) |
|
1413 | 1413 | except error.LookupError: |
|
1414 | 1414 | node = short(rev) |
|
1415 | 1415 | raise util.Abort(_('trying to pop unknown node %s') % node) |
|
1416 | 1416 | |
|
1417 | 1417 | if heads != [self.applied[-1].node]: |
|
1418 | 1418 | raise util.Abort(_("popping would remove a revision not " |
|
1419 | 1419 | "managed by this patch queue")) |
|
1420 | 1420 | if not repo[self.applied[-1].node].mutable(): |
|
1421 | 1421 | raise util.Abort( |
|
1422 | 1422 | _("popping would remove an immutable revision"), |
|
1423 | 1423 | hint=_('see "hg help phases" for details')) |
|
1424 | 1424 | |
|
1425 | 1425 | # we know there are no local changes, so we can make a simplified |
|
1426 | 1426 | # form of hg.update. |
|
1427 | 1427 | if update: |
|
1428 | 1428 | qp = self.qparents(repo, rev) |
|
1429 | 1429 | ctx = repo[qp] |
|
1430 | 1430 | m, a, r, d = repo.status(qp, top)[:4] |
|
1431 | 1431 | if d: |
|
1432 | 1432 | raise util.Abort(_("deletions found between repo revs")) |
|
1433 | 1433 | |
|
1434 | 1434 | tobackup = set(a + m + r) & tobackup |
|
1435 | 1435 | if keepchanges and tobackup: |
|
1436 | 1436 | self.localchangesfound() |
|
1437 | 1437 | self.backup(repo, tobackup) |
|
1438 | 1438 | |
|
1439 | 1439 | for f in a: |
|
1440 | 1440 | try: |
|
1441 | 1441 | util.unlinkpath(repo.wjoin(f)) |
|
1442 | 1442 | except OSError, e: |
|
1443 | 1443 | if e.errno != errno.ENOENT: |
|
1444 | 1444 | raise |
|
1445 | 1445 | repo.dirstate.drop(f) |
|
1446 | 1446 | for f in m + r: |
|
1447 | 1447 | fctx = ctx[f] |
|
1448 | 1448 | repo.wwrite(f, fctx.data(), fctx.flags()) |
|
1449 | 1449 | repo.dirstate.normal(f) |
|
1450 | 1450 | repo.setparents(qp, nullid) |
|
1451 | 1451 | for patch in reversed(self.applied[start:end]): |
|
1452 | 1452 | self.ui.status(_("popping %s\n") % patch.name) |
|
1453 | 1453 | del self.applied[start:end] |
|
1454 | 1454 | self.strip(repo, [rev], update=False, backup='strip') |
|
1455 | 1455 | if self.applied: |
|
1456 | 1456 | self.ui.write(_("now at: %s\n") % self.applied[-1].name) |
|
1457 | 1457 | else: |
|
1458 | 1458 | self.ui.write(_("patch queue now empty\n")) |
|
1459 | 1459 | finally: |
|
1460 | 1460 | wlock.release() |
|
1461 | 1461 | |
|
1462 | 1462 | def diff(self, repo, pats, opts): |
|
1463 | 1463 | top, patch = self.checktoppatch(repo) |
|
1464 | 1464 | if not top: |
|
1465 | 1465 | self.ui.write(_("no patches applied\n")) |
|
1466 | 1466 | return |
|
1467 | 1467 | qp = self.qparents(repo, top) |
|
1468 | 1468 | if opts.get('reverse'): |
|
1469 | 1469 | node1, node2 = None, qp |
|
1470 | 1470 | else: |
|
1471 | 1471 | node1, node2 = qp, None |
|
1472 | 1472 | diffopts = self.diffopts(opts, patch) |
|
1473 | 1473 | self.printdiff(repo, diffopts, node1, node2, files=pats, opts=opts) |
|
1474 | 1474 | |
|
1475 | 1475 | def refresh(self, repo, pats=None, **opts): |
|
1476 | 1476 | if not self.applied: |
|
1477 | 1477 | self.ui.write(_("no patches applied\n")) |
|
1478 | 1478 | return 1 |
|
1479 | 1479 | msg = opts.get('msg', '').rstrip() |
|
1480 | 1480 | newuser = opts.get('user') |
|
1481 | 1481 | newdate = opts.get('date') |
|
1482 | 1482 | if newdate: |
|
1483 | 1483 | newdate = '%d %d' % util.parsedate(newdate) |
|
1484 | 1484 | wlock = repo.wlock() |
|
1485 | 1485 | |
|
1486 | 1486 | try: |
|
1487 | 1487 | self.checktoppatch(repo) |
|
1488 | 1488 | (top, patchfn) = (self.applied[-1].node, self.applied[-1].name) |
|
1489 | 1489 | if repo.changelog.heads(top) != [top]: |
|
1490 | 1490 | raise util.Abort(_("cannot refresh a revision with children")) |
|
1491 | 1491 | if not repo[top].mutable(): |
|
1492 | 1492 | raise util.Abort(_("cannot refresh immutable revision"), |
|
1493 | 1493 | hint=_('see "hg help phases" for details')) |
|
1494 | 1494 | |
|
1495 | 1495 | cparents = repo.changelog.parents(top) |
|
1496 | 1496 | patchparent = self.qparents(repo, top) |
|
1497 | 1497 | |
|
1498 | 1498 | inclsubs = self.checksubstate(repo, hex(patchparent)) |
|
1499 | 1499 | if inclsubs: |
|
1500 | 1500 | inclsubs.append('.hgsubstate') |
|
1501 | 1501 | substatestate = repo.dirstate['.hgsubstate'] |
|
1502 | 1502 | |
|
1503 | 1503 | ph = patchheader(self.join(patchfn), self.plainmode) |
|
1504 | 1504 | diffopts = self.diffopts({'git': opts.get('git')}, patchfn) |
|
1505 | 1505 | if msg: |
|
1506 | 1506 | ph.setmessage(msg) |
|
1507 | 1507 | if newuser: |
|
1508 | 1508 | ph.setuser(newuser) |
|
1509 | 1509 | if newdate: |
|
1510 | 1510 | ph.setdate(newdate) |
|
1511 | 1511 | ph.setparent(hex(patchparent)) |
|
1512 | 1512 | |
|
1513 | 1513 | # only commit new patch when write is complete |
|
1514 | 1514 | patchf = self.opener(patchfn, 'w', atomictemp=True) |
|
1515 | 1515 | |
|
1516 | 1516 | comments = str(ph) |
|
1517 | 1517 | if comments: |
|
1518 | 1518 | patchf.write(comments) |
|
1519 | 1519 | |
|
1520 | 1520 | # update the dirstate in place, strip off the qtip commit |
|
1521 | 1521 | # and then commit. |
|
1522 | 1522 | # |
|
1523 | 1523 | # this should really read: |
|
1524 | 1524 | # mm, dd, aa = repo.status(top, patchparent)[:3] |
|
1525 | 1525 | # but we do it backwards to take advantage of manifest/chlog |
|
1526 | 1526 | # caching against the next repo.status call |
|
1527 | 1527 | mm, aa, dd = repo.status(patchparent, top)[:3] |
|
1528 | 1528 | changes = repo.changelog.read(top) |
|
1529 | 1529 | man = repo.manifest.read(changes[0]) |
|
1530 | 1530 | aaa = aa[:] |
|
1531 | 1531 | matchfn = scmutil.match(repo[None], pats, opts) |
|
1532 | 1532 | # in short mode, we only diff the files included in the |
|
1533 | 1533 | # patch already plus specified files |
|
1534 | 1534 | if opts.get('short'): |
|
1535 | 1535 | # if amending a patch, we start with existing |
|
1536 | 1536 | # files plus specified files - unfiltered |
|
1537 | 1537 | match = scmutil.matchfiles(repo, mm + aa + dd + matchfn.files()) |
|
1538 | 1538 | # filter with inc/exl options |
|
1539 | 1539 | matchfn = scmutil.match(repo[None], opts=opts) |
|
1540 | 1540 | else: |
|
1541 | 1541 | match = scmutil.matchall(repo) |
|
1542 | 1542 | m, a, r, d = repo.status(match=match)[:4] |
|
1543 | 1543 | mm = set(mm) |
|
1544 | 1544 | aa = set(aa) |
|
1545 | 1545 | dd = set(dd) |
|
1546 | 1546 | |
|
1547 | 1547 | # we might end up with files that were added between |
|
1548 | 1548 | # qtip and the dirstate parent, but then changed in the |
|
1549 | 1549 | # local dirstate. in this case, we want them to only |
|
1550 | 1550 | # show up in the added section |
|
1551 | 1551 | for x in m: |
|
1552 | 1552 | if x not in aa: |
|
1553 | 1553 | mm.add(x) |
|
1554 | 1554 | # we might end up with files added by the local dirstate that |
|
1555 | 1555 | # were deleted by the patch. In this case, they should only |
|
1556 | 1556 | # show up in the changed section. |
|
1557 | 1557 | for x in a: |
|
1558 | 1558 | if x in dd: |
|
1559 | 1559 | dd.remove(x) |
|
1560 | 1560 | mm.add(x) |
|
1561 | 1561 | else: |
|
1562 | 1562 | aa.add(x) |
|
1563 | 1563 | # make sure any files deleted in the local dirstate |
|
1564 | 1564 | # are not in the add or change column of the patch |
|
1565 | 1565 | forget = [] |
|
1566 | 1566 | for x in d + r: |
|
1567 | 1567 | if x in aa: |
|
1568 | 1568 | aa.remove(x) |
|
1569 | 1569 | forget.append(x) |
|
1570 | 1570 | continue |
|
1571 | 1571 | else: |
|
1572 | 1572 | mm.discard(x) |
|
1573 | 1573 | dd.add(x) |
|
1574 | 1574 | |
|
1575 | 1575 | m = list(mm) |
|
1576 | 1576 | r = list(dd) |
|
1577 | 1577 | a = list(aa) |
|
1578 | 1578 | c = [filter(matchfn, l) for l in (m, a, r)] |
|
1579 | 1579 | match = scmutil.matchfiles(repo, set(c[0] + c[1] + c[2] + inclsubs)) |
|
1580 | 1580 | |
|
1581 | 1581 | try: |
|
1582 | 1582 | if diffopts.git or diffopts.upgrade: |
|
1583 | 1583 | copies = {} |
|
1584 | 1584 | for dst in a: |
|
1585 | 1585 | src = repo.dirstate.copied(dst) |
|
1586 | 1586 | # during qfold, the source file for copies may |
|
1587 | 1587 | # be removed. Treat this as a simple add. |
|
1588 | 1588 | if src is not None and src in repo.dirstate: |
|
1589 | 1589 | copies.setdefault(src, []).append(dst) |
|
1590 | 1590 | repo.dirstate.add(dst) |
|
1591 | 1591 | # remember the copies between patchparent and qtip |
|
1592 | 1592 | for dst in aaa: |
|
1593 | 1593 | f = repo.file(dst) |
|
1594 | 1594 | src = f.renamed(man[dst]) |
|
1595 | 1595 | if src: |
|
1596 | 1596 | copies.setdefault(src[0], []).extend( |
|
1597 | 1597 | copies.get(dst, [])) |
|
1598 | 1598 | if dst in a: |
|
1599 | 1599 | copies[src[0]].append(dst) |
|
1600 | 1600 | # we can't copy a file created by the patch itself |
|
1601 | 1601 | if dst in copies: |
|
1602 | 1602 | del copies[dst] |
|
1603 | 1603 | for src, dsts in copies.iteritems(): |
|
1604 | 1604 | for dst in dsts: |
|
1605 | 1605 | repo.dirstate.copy(src, dst) |
|
1606 | 1606 | else: |
|
1607 | 1607 | for dst in a: |
|
1608 | 1608 | repo.dirstate.add(dst) |
|
1609 | 1609 | # Drop useless copy information |
|
1610 | 1610 | for f in list(repo.dirstate.copies()): |
|
1611 | 1611 | repo.dirstate.copy(None, f) |
|
1612 | 1612 | for f in r: |
|
1613 | 1613 | repo.dirstate.remove(f) |
|
1614 | 1614 | # if the patch excludes a modified file, mark that |
|
1615 | 1615 | # file with mtime=0 so status can see it. |
|
1616 | 1616 | mm = [] |
|
1617 | 1617 | for i in xrange(len(m)-1, -1, -1): |
|
1618 | 1618 | if not matchfn(m[i]): |
|
1619 | 1619 | mm.append(m[i]) |
|
1620 | 1620 | del m[i] |
|
1621 | 1621 | for f in m: |
|
1622 | 1622 | repo.dirstate.normal(f) |
|
1623 | 1623 | for f in mm: |
|
1624 | 1624 | repo.dirstate.normallookup(f) |
|
1625 | 1625 | for f in forget: |
|
1626 | 1626 | repo.dirstate.drop(f) |
|
1627 | 1627 | |
|
1628 | 1628 | if not msg: |
|
1629 | 1629 | if not ph.message: |
|
1630 | 1630 | message = "[mq]: %s\n" % patchfn |
|
1631 | 1631 | else: |
|
1632 | 1632 | message = "\n".join(ph.message) |
|
1633 | 1633 | else: |
|
1634 | 1634 | message = msg |
|
1635 | 1635 | |
|
1636 | 1636 | user = ph.user or changes[1] |
|
1637 | 1637 | |
|
1638 | 1638 | oldphase = repo[top].phase() |
|
1639 | 1639 | |
|
1640 | 1640 | # assumes strip can roll itself back if interrupted |
|
1641 | 1641 | repo.setparents(*cparents) |
|
1642 | 1642 | self.applied.pop() |
|
1643 | 1643 | self.applieddirty = True |
|
1644 | 1644 | self.strip(repo, [top], update=False, |
|
1645 | 1645 | backup='strip') |
|
1646 | 1646 | except: # re-raises |
|
1647 | 1647 | repo.dirstate.invalidate() |
|
1648 | 1648 | raise |
|
1649 | 1649 | |
|
1650 | 1650 | try: |
|
1651 | 1651 | # might be nice to attempt to roll back strip after this |
|
1652 | 1652 | |
|
1653 | 1653 | # Ensure we create a new changeset in the same phase than |
|
1654 | 1654 | # the old one. |
|
1655 | 1655 | n = newcommit(repo, oldphase, message, user, ph.date, |
|
1656 | 1656 | match=match, force=True) |
|
1657 | 1657 | # only write patch after a successful commit |
|
1658 | 1658 | if inclsubs: |
|
1659 | 1659 | self.putsubstate2changes(substatestate, c) |
|
1660 | 1660 | chunks = patchmod.diff(repo, patchparent, |
|
1661 | 1661 | changes=c, opts=diffopts) |
|
1662 | 1662 | for chunk in chunks: |
|
1663 | 1663 | patchf.write(chunk) |
|
1664 | 1664 | patchf.close() |
|
1665 | 1665 | self.applied.append(statusentry(n, patchfn)) |
|
1666 | 1666 | except: # re-raises |
|
1667 | 1667 | ctx = repo[cparents[0]] |
|
1668 | 1668 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
1669 | 1669 | self.savedirty() |
|
1670 | 1670 | self.ui.warn(_('refresh interrupted while patch was popped! ' |
|
1671 | 1671 | '(revert --all, qpush to recover)\n')) |
|
1672 | 1672 | raise |
|
1673 | 1673 | finally: |
|
1674 | 1674 | wlock.release() |
|
1675 | 1675 | self.removeundo(repo) |
|
1676 | 1676 | |
|
1677 | 1677 | def init(self, repo, create=False): |
|
1678 | 1678 | if not create and os.path.isdir(self.path): |
|
1679 | 1679 | raise util.Abort(_("patch queue directory already exists")) |
|
1680 | 1680 | try: |
|
1681 | 1681 | os.mkdir(self.path) |
|
1682 | 1682 | except OSError, inst: |
|
1683 | 1683 | if inst.errno != errno.EEXIST or not create: |
|
1684 | 1684 | raise |
|
1685 | 1685 | if create: |
|
1686 | 1686 | return self.qrepo(create=True) |
|
1687 | 1687 | |
|
1688 | 1688 | def unapplied(self, repo, patch=None): |
|
1689 | 1689 | if patch and patch not in self.series: |
|
1690 | 1690 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
1691 | 1691 | if not patch: |
|
1692 | 1692 | start = self.seriesend() |
|
1693 | 1693 | else: |
|
1694 | 1694 | start = self.series.index(patch) + 1 |
|
1695 | 1695 | unapplied = [] |
|
1696 | 1696 | for i in xrange(start, len(self.series)): |
|
1697 | 1697 | pushable, reason = self.pushable(i) |
|
1698 | 1698 | if pushable: |
|
1699 | 1699 | unapplied.append((i, self.series[i])) |
|
1700 | 1700 | self.explainpushable(i) |
|
1701 | 1701 | return unapplied |
|
1702 | 1702 | |
|
1703 | 1703 | def qseries(self, repo, missing=None, start=0, length=None, status=None, |
|
1704 | 1704 | summary=False): |
|
1705 | 1705 | def displayname(pfx, patchname, state): |
|
1706 | 1706 | if pfx: |
|
1707 | 1707 | self.ui.write(pfx) |
|
1708 | 1708 | if summary: |
|
1709 | 1709 | ph = patchheader(self.join(patchname), self.plainmode) |
|
1710 | 1710 | msg = ph.message and ph.message[0] or '' |
|
1711 | 1711 | if self.ui.formatted(): |
|
1712 | 1712 | width = self.ui.termwidth() - len(pfx) - len(patchname) - 2 |
|
1713 | 1713 | if width > 0: |
|
1714 | 1714 | msg = util.ellipsis(msg, width) |
|
1715 | 1715 | else: |
|
1716 | 1716 | msg = '' |
|
1717 | 1717 | self.ui.write(patchname, label='qseries.' + state) |
|
1718 | 1718 | self.ui.write(': ') |
|
1719 | 1719 | self.ui.write(msg, label='qseries.message.' + state) |
|
1720 | 1720 | else: |
|
1721 | 1721 | self.ui.write(patchname, label='qseries.' + state) |
|
1722 | 1722 | self.ui.write('\n') |
|
1723 | 1723 | |
|
1724 | 1724 | applied = set([p.name for p in self.applied]) |
|
1725 | 1725 | if length is None: |
|
1726 | 1726 | length = len(self.series) - start |
|
1727 | 1727 | if not missing: |
|
1728 | 1728 | if self.ui.verbose: |
|
1729 | 1729 | idxwidth = len(str(start + length - 1)) |
|
1730 | 1730 | for i in xrange(start, start + length): |
|
1731 | 1731 | patch = self.series[i] |
|
1732 | 1732 | if patch in applied: |
|
1733 | 1733 | char, state = 'A', 'applied' |
|
1734 | 1734 | elif self.pushable(i)[0]: |
|
1735 | 1735 | char, state = 'U', 'unapplied' |
|
1736 | 1736 | else: |
|
1737 | 1737 | char, state = 'G', 'guarded' |
|
1738 | 1738 | pfx = '' |
|
1739 | 1739 | if self.ui.verbose: |
|
1740 | 1740 | pfx = '%*d %s ' % (idxwidth, i, char) |
|
1741 | 1741 | elif status and status != char: |
|
1742 | 1742 | continue |
|
1743 | 1743 | displayname(pfx, patch, state) |
|
1744 | 1744 | else: |
|
1745 | 1745 | msng_list = [] |
|
1746 | 1746 | for root, dirs, files in os.walk(self.path): |
|
1747 | 1747 | d = root[len(self.path) + 1:] |
|
1748 | 1748 | for f in files: |
|
1749 | 1749 | fl = os.path.join(d, f) |
|
1750 | 1750 | if (fl not in self.series and |
|
1751 | 1751 | fl not in (self.statuspath, self.seriespath, |
|
1752 | 1752 | self.guardspath) |
|
1753 | 1753 | and not fl.startswith('.')): |
|
1754 | 1754 | msng_list.append(fl) |
|
1755 | 1755 | for x in sorted(msng_list): |
|
1756 | 1756 | pfx = self.ui.verbose and ('D ') or '' |
|
1757 | 1757 | displayname(pfx, x, 'missing') |
|
1758 | 1758 | |
|
1759 | 1759 | def issaveline(self, l): |
|
1760 | 1760 | if l.name == '.hg.patches.save.line': |
|
1761 | 1761 | return True |
|
1762 | 1762 | |
|
1763 | 1763 | def qrepo(self, create=False): |
|
1764 | 1764 | ui = self.ui.copy() |
|
1765 | 1765 | ui.setconfig('paths', 'default', '', overlay=False) |
|
1766 | 1766 | ui.setconfig('paths', 'default-push', '', overlay=False) |
|
1767 | 1767 | if create or os.path.isdir(self.join(".hg")): |
|
1768 | 1768 | return hg.repository(ui, path=self.path, create=create) |
|
1769 | 1769 | |
|
1770 | 1770 | def restore(self, repo, rev, delete=None, qupdate=None): |
|
1771 | 1771 | desc = repo[rev].description().strip() |
|
1772 | 1772 | lines = desc.splitlines() |
|
1773 | 1773 | i = 0 |
|
1774 | 1774 | datastart = None |
|
1775 | 1775 | series = [] |
|
1776 | 1776 | applied = [] |
|
1777 | 1777 | qpp = None |
|
1778 | 1778 | for i, line in enumerate(lines): |
|
1779 | 1779 | if line == 'Patch Data:': |
|
1780 | 1780 | datastart = i + 1 |
|
1781 | 1781 | elif line.startswith('Dirstate:'): |
|
1782 | 1782 | l = line.rstrip() |
|
1783 | 1783 | l = l[10:].split(' ') |
|
1784 | 1784 | qpp = [bin(x) for x in l] |
|
1785 | 1785 | elif datastart is not None: |
|
1786 | 1786 | l = line.rstrip() |
|
1787 | 1787 | n, name = l.split(':', 1) |
|
1788 | 1788 | if n: |
|
1789 | 1789 | applied.append(statusentry(bin(n), name)) |
|
1790 | 1790 | else: |
|
1791 | 1791 | series.append(l) |
|
1792 | 1792 | if datastart is None: |
|
1793 | 1793 | self.ui.warn(_("no saved patch data found\n")) |
|
1794 | 1794 | return 1 |
|
1795 | 1795 | self.ui.warn(_("restoring status: %s\n") % lines[0]) |
|
1796 | 1796 | self.fullseries = series |
|
1797 | 1797 | self.applied = applied |
|
1798 | 1798 | self.parseseries() |
|
1799 | 1799 | self.seriesdirty = True |
|
1800 | 1800 | self.applieddirty = True |
|
1801 | 1801 | heads = repo.changelog.heads() |
|
1802 | 1802 | if delete: |
|
1803 | 1803 | if rev not in heads: |
|
1804 | 1804 | self.ui.warn(_("save entry has children, leaving it alone\n")) |
|
1805 | 1805 | else: |
|
1806 | 1806 | self.ui.warn(_("removing save entry %s\n") % short(rev)) |
|
1807 | 1807 | pp = repo.dirstate.parents() |
|
1808 | 1808 | if rev in pp: |
|
1809 | 1809 | update = True |
|
1810 | 1810 | else: |
|
1811 | 1811 | update = False |
|
1812 | 1812 | self.strip(repo, [rev], update=update, backup='strip') |
|
1813 | 1813 | if qpp: |
|
1814 | 1814 | self.ui.warn(_("saved queue repository parents: %s %s\n") % |
|
1815 | 1815 | (short(qpp[0]), short(qpp[1]))) |
|
1816 | 1816 | if qupdate: |
|
1817 | 1817 | self.ui.status(_("updating queue directory\n")) |
|
1818 | 1818 | r = self.qrepo() |
|
1819 | 1819 | if not r: |
|
1820 | 1820 | self.ui.warn(_("unable to load queue repository\n")) |
|
1821 | 1821 | return 1 |
|
1822 | 1822 | hg.clean(r, qpp[0]) |
|
1823 | 1823 | |
|
1824 | 1824 | def save(self, repo, msg=None): |
|
1825 | 1825 | if not self.applied: |
|
1826 | 1826 | self.ui.warn(_("save: no patches applied, exiting\n")) |
|
1827 | 1827 | return 1 |
|
1828 | 1828 | if self.issaveline(self.applied[-1]): |
|
1829 | 1829 | self.ui.warn(_("status is already saved\n")) |
|
1830 | 1830 | return 1 |
|
1831 | 1831 | |
|
1832 | 1832 | if not msg: |
|
1833 | 1833 | msg = _("hg patches saved state") |
|
1834 | 1834 | else: |
|
1835 | 1835 | msg = "hg patches: " + msg.rstrip('\r\n') |
|
1836 | 1836 | r = self.qrepo() |
|
1837 | 1837 | if r: |
|
1838 | 1838 | pp = r.dirstate.parents() |
|
1839 | 1839 | msg += "\nDirstate: %s %s" % (hex(pp[0]), hex(pp[1])) |
|
1840 | 1840 | msg += "\n\nPatch Data:\n" |
|
1841 | 1841 | msg += ''.join('%s\n' % x for x in self.applied) |
|
1842 | 1842 | msg += ''.join(':%s\n' % x for x in self.fullseries) |
|
1843 | 1843 | n = repo.commit(msg, force=True) |
|
1844 | 1844 | if not n: |
|
1845 | 1845 | self.ui.warn(_("repo commit failed\n")) |
|
1846 | 1846 | return 1 |
|
1847 | 1847 | self.applied.append(statusentry(n, '.hg.patches.save.line')) |
|
1848 | 1848 | self.applieddirty = True |
|
1849 | 1849 | self.removeundo(repo) |
|
1850 | 1850 | |
|
1851 | 1851 | def fullseriesend(self): |
|
1852 | 1852 | if self.applied: |
|
1853 | 1853 | p = self.applied[-1].name |
|
1854 | 1854 | end = self.findseries(p) |
|
1855 | 1855 | if end is None: |
|
1856 | 1856 | return len(self.fullseries) |
|
1857 | 1857 | return end + 1 |
|
1858 | 1858 | return 0 |
|
1859 | 1859 | |
|
1860 | 1860 | def seriesend(self, all_patches=False): |
|
1861 | 1861 | """If all_patches is False, return the index of the next pushable patch |
|
1862 | 1862 | in the series, or the series length. If all_patches is True, return the |
|
1863 | 1863 | index of the first patch past the last applied one. |
|
1864 | 1864 | """ |
|
1865 | 1865 | end = 0 |
|
1866 | 1866 | def next(start): |
|
1867 | 1867 | if all_patches or start >= len(self.series): |
|
1868 | 1868 | return start |
|
1869 | 1869 | for i in xrange(start, len(self.series)): |
|
1870 | 1870 | p, reason = self.pushable(i) |
|
1871 | 1871 | if p: |
|
1872 | 1872 | return i |
|
1873 | 1873 | self.explainpushable(i) |
|
1874 | 1874 | return len(self.series) |
|
1875 | 1875 | if self.applied: |
|
1876 | 1876 | p = self.applied[-1].name |
|
1877 | 1877 | try: |
|
1878 | 1878 | end = self.series.index(p) |
|
1879 | 1879 | except ValueError: |
|
1880 | 1880 | return 0 |
|
1881 | 1881 | return next(end + 1) |
|
1882 | 1882 | return next(end) |
|
1883 | 1883 | |
|
1884 | 1884 | def appliedname(self, index): |
|
1885 | 1885 | pname = self.applied[index].name |
|
1886 | 1886 | if not self.ui.verbose: |
|
1887 | 1887 | p = pname |
|
1888 | 1888 | else: |
|
1889 | 1889 | p = str(self.series.index(pname)) + " " + pname |
|
1890 | 1890 | return p |
|
1891 | 1891 | |
|
1892 | 1892 | def qimport(self, repo, files, patchname=None, rev=None, existing=None, |
|
1893 | 1893 | force=None, git=False): |
|
1894 | 1894 | def checkseries(patchname): |
|
1895 | 1895 | if patchname in self.series: |
|
1896 | 1896 | raise util.Abort(_('patch %s is already in the series file') |
|
1897 | 1897 | % patchname) |
|
1898 | 1898 | |
|
1899 | 1899 | if rev: |
|
1900 | 1900 | if files: |
|
1901 | 1901 | raise util.Abort(_('option "-r" not valid when importing ' |
|
1902 | 1902 | 'files')) |
|
1903 | 1903 | rev = scmutil.revrange(repo, rev) |
|
1904 | 1904 | rev.sort(reverse=True) |
|
1905 | 1905 | elif not files: |
|
1906 | 1906 | raise util.Abort(_('no files or revisions specified')) |
|
1907 | 1907 | if (len(files) > 1 or len(rev) > 1) and patchname: |
|
1908 | 1908 | raise util.Abort(_('option "-n" not valid when importing multiple ' |
|
1909 | 1909 | 'patches')) |
|
1910 | 1910 | imported = [] |
|
1911 | 1911 | if rev: |
|
1912 | 1912 | # If mq patches are applied, we can only import revisions |
|
1913 | 1913 | # that form a linear path to qbase. |
|
1914 | 1914 | # Otherwise, they should form a linear path to a head. |
|
1915 | 1915 | heads = repo.changelog.heads(repo.changelog.node(rev[-1])) |
|
1916 | 1916 | if len(heads) > 1: |
|
1917 | 1917 | raise util.Abort(_('revision %d is the root of more than one ' |
|
1918 | 1918 | 'branch') % rev[-1]) |
|
1919 | 1919 | if self.applied: |
|
1920 | 1920 | base = repo.changelog.node(rev[0]) |
|
1921 | 1921 | if base in [n.node for n in self.applied]: |
|
1922 | 1922 | raise util.Abort(_('revision %d is already managed') |
|
1923 | 1923 | % rev[0]) |
|
1924 | 1924 | if heads != [self.applied[-1].node]: |
|
1925 | 1925 | raise util.Abort(_('revision %d is not the parent of ' |
|
1926 | 1926 | 'the queue') % rev[0]) |
|
1927 | 1927 | base = repo.changelog.rev(self.applied[0].node) |
|
1928 | 1928 | lastparent = repo.changelog.parentrevs(base)[0] |
|
1929 | 1929 | else: |
|
1930 | 1930 | if heads != [repo.changelog.node(rev[0])]: |
|
1931 | 1931 | raise util.Abort(_('revision %d has unmanaged children') |
|
1932 | 1932 | % rev[0]) |
|
1933 | 1933 | lastparent = None |
|
1934 | 1934 | |
|
1935 | 1935 | diffopts = self.diffopts({'git': git}) |
|
1936 | 1936 | for r in rev: |
|
1937 | 1937 | if not repo[r].mutable(): |
|
1938 | 1938 | raise util.Abort(_('revision %d is not mutable') % r, |
|
1939 | 1939 | hint=_('see "hg help phases" for details')) |
|
1940 | 1940 | p1, p2 = repo.changelog.parentrevs(r) |
|
1941 | 1941 | n = repo.changelog.node(r) |
|
1942 | 1942 | if p2 != nullrev: |
|
1943 | 1943 | raise util.Abort(_('cannot import merge revision %d') % r) |
|
1944 | 1944 | if lastparent and lastparent != r: |
|
1945 | 1945 | raise util.Abort(_('revision %d is not the parent of %d') |
|
1946 | 1946 | % (r, lastparent)) |
|
1947 | 1947 | lastparent = p1 |
|
1948 | 1948 | |
|
1949 | 1949 | if not patchname: |
|
1950 | 1950 | patchname = normname('%d.diff' % r) |
|
1951 | 1951 | checkseries(patchname) |
|
1952 | 1952 | self.checkpatchname(patchname, force) |
|
1953 | 1953 | self.fullseries.insert(0, patchname) |
|
1954 | 1954 | |
|
1955 | 1955 | patchf = self.opener(patchname, "w") |
|
1956 | 1956 | cmdutil.export(repo, [n], fp=patchf, opts=diffopts) |
|
1957 | 1957 | patchf.close() |
|
1958 | 1958 | |
|
1959 | 1959 | se = statusentry(n, patchname) |
|
1960 | 1960 | self.applied.insert(0, se) |
|
1961 | 1961 | |
|
1962 | 1962 | self.added.append(patchname) |
|
1963 | 1963 | imported.append(patchname) |
|
1964 | 1964 | patchname = None |
|
1965 | 1965 | if rev and repo.ui.configbool('mq', 'secret', False): |
|
1966 | 1966 | # if we added anything with --rev, we must move the secret root |
|
1967 | 1967 | phases.retractboundary(repo, phases.secret, [n]) |
|
1968 | 1968 | self.parseseries() |
|
1969 | 1969 | self.applieddirty = True |
|
1970 | 1970 | self.seriesdirty = True |
|
1971 | 1971 | |
|
1972 | 1972 | for i, filename in enumerate(files): |
|
1973 | 1973 | if existing: |
|
1974 | 1974 | if filename == '-': |
|
1975 | 1975 | raise util.Abort(_('-e is incompatible with import from -')) |
|
1976 | 1976 | filename = normname(filename) |
|
1977 | 1977 | self.checkreservedname(filename) |
|
1978 | 1978 | originpath = self.join(filename) |
|
1979 | 1979 | if not os.path.isfile(originpath): |
|
1980 | 1980 | raise util.Abort(_("patch %s does not exist") % filename) |
|
1981 | 1981 | |
|
1982 | 1982 | if patchname: |
|
1983 | 1983 | self.checkpatchname(patchname, force) |
|
1984 | 1984 | |
|
1985 | 1985 | self.ui.write(_('renaming %s to %s\n') |
|
1986 | 1986 | % (filename, patchname)) |
|
1987 | 1987 | util.rename(originpath, self.join(patchname)) |
|
1988 | 1988 | else: |
|
1989 | 1989 | patchname = filename |
|
1990 | 1990 | |
|
1991 | 1991 | else: |
|
1992 | 1992 | if filename == '-' and not patchname: |
|
1993 | 1993 | raise util.Abort(_('need --name to import a patch from -')) |
|
1994 | 1994 | elif not patchname: |
|
1995 | 1995 | patchname = normname(os.path.basename(filename.rstrip('/'))) |
|
1996 | 1996 | self.checkpatchname(patchname, force) |
|
1997 | 1997 | try: |
|
1998 | 1998 | if filename == '-': |
|
1999 | 1999 | text = self.ui.fin.read() |
|
2000 | 2000 | else: |
|
2001 | 2001 | fp = url.open(self.ui, filename) |
|
2002 | 2002 | text = fp.read() |
|
2003 | 2003 | fp.close() |
|
2004 | 2004 | except (OSError, IOError): |
|
2005 | 2005 | raise util.Abort(_("unable to read file %s") % filename) |
|
2006 | 2006 | patchf = self.opener(patchname, "w") |
|
2007 | 2007 | patchf.write(text) |
|
2008 | 2008 | patchf.close() |
|
2009 | 2009 | if not force: |
|
2010 | 2010 | checkseries(patchname) |
|
2011 | 2011 | if patchname not in self.series: |
|
2012 | 2012 | index = self.fullseriesend() + i |
|
2013 | 2013 | self.fullseries[index:index] = [patchname] |
|
2014 | 2014 | self.parseseries() |
|
2015 | 2015 | self.seriesdirty = True |
|
2016 | 2016 | self.ui.warn(_("adding %s to series file\n") % patchname) |
|
2017 | 2017 | self.added.append(patchname) |
|
2018 | 2018 | imported.append(patchname) |
|
2019 | 2019 | patchname = None |
|
2020 | 2020 | |
|
2021 | 2021 | self.removeundo(repo) |
|
2022 | 2022 | return imported |
|
2023 | 2023 | |
|
2024 | 2024 | def fixkeepchangesopts(ui, opts): |
|
2025 | 2025 | if (not ui.configbool('mq', 'keepchanges') or opts.get('force') |
|
2026 | 2026 | or opts.get('exact')): |
|
2027 | 2027 | return opts |
|
2028 | 2028 | opts = dict(opts) |
|
2029 | 2029 | opts['keep_changes'] = True |
|
2030 | 2030 | return opts |
|
2031 | 2031 | |
|
2032 | 2032 | @command("qdelete|qremove|qrm", |
|
2033 | 2033 | [('k', 'keep', None, _('keep patch file')), |
|
2034 | 2034 | ('r', 'rev', [], |
|
2035 | 2035 | _('stop managing a revision (DEPRECATED)'), _('REV'))], |
|
2036 | 2036 | _('hg qdelete [-k] [PATCH]...')) |
|
2037 | 2037 | def delete(ui, repo, *patches, **opts): |
|
2038 | 2038 | """remove patches from queue |
|
2039 | 2039 | |
|
2040 | 2040 | The patches must not be applied, and at least one patch is required. Exact |
|
2041 | 2041 | patch identifiers must be given. With -k/--keep, the patch files are |
|
2042 | 2042 | preserved in the patch directory. |
|
2043 | 2043 | |
|
2044 | 2044 | To stop managing a patch and move it into permanent history, |
|
2045 | 2045 | use the :hg:`qfinish` command.""" |
|
2046 | 2046 | q = repo.mq |
|
2047 | 2047 | q.delete(repo, patches, opts) |
|
2048 | 2048 | q.savedirty() |
|
2049 | 2049 | return 0 |
|
2050 | 2050 | |
|
2051 | 2051 | @command("qapplied", |
|
2052 | 2052 | [('1', 'last', None, _('show only the preceding applied patch')) |
|
2053 | 2053 | ] + seriesopts, |
|
2054 | 2054 | _('hg qapplied [-1] [-s] [PATCH]')) |
|
2055 | 2055 | def applied(ui, repo, patch=None, **opts): |
|
2056 | 2056 | """print the patches already applied |
|
2057 | 2057 | |
|
2058 | 2058 | Returns 0 on success.""" |
|
2059 | 2059 | |
|
2060 | 2060 | q = repo.mq |
|
2061 | 2061 | |
|
2062 | 2062 | if patch: |
|
2063 | 2063 | if patch not in q.series: |
|
2064 | 2064 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
2065 | 2065 | end = q.series.index(patch) + 1 |
|
2066 | 2066 | else: |
|
2067 | 2067 | end = q.seriesend(True) |
|
2068 | 2068 | |
|
2069 | 2069 | if opts.get('last') and not end: |
|
2070 | 2070 | ui.write(_("no patches applied\n")) |
|
2071 | 2071 | return 1 |
|
2072 | 2072 | elif opts.get('last') and end == 1: |
|
2073 | 2073 | ui.write(_("only one patch applied\n")) |
|
2074 | 2074 | return 1 |
|
2075 | 2075 | elif opts.get('last'): |
|
2076 | 2076 | start = end - 2 |
|
2077 | 2077 | end = 1 |
|
2078 | 2078 | else: |
|
2079 | 2079 | start = 0 |
|
2080 | 2080 | |
|
2081 | 2081 | q.qseries(repo, length=end, start=start, status='A', |
|
2082 | 2082 | summary=opts.get('summary')) |
|
2083 | 2083 | |
|
2084 | 2084 | |
|
2085 | 2085 | @command("qunapplied", |
|
2086 | 2086 | [('1', 'first', None, _('show only the first patch'))] + seriesopts, |
|
2087 | 2087 | _('hg qunapplied [-1] [-s] [PATCH]')) |
|
2088 | 2088 | def unapplied(ui, repo, patch=None, **opts): |
|
2089 | 2089 | """print the patches not yet applied |
|
2090 | 2090 | |
|
2091 | 2091 | Returns 0 on success.""" |
|
2092 | 2092 | |
|
2093 | 2093 | q = repo.mq |
|
2094 | 2094 | if patch: |
|
2095 | 2095 | if patch not in q.series: |
|
2096 | 2096 | raise util.Abort(_("patch %s is not in series file") % patch) |
|
2097 | 2097 | start = q.series.index(patch) + 1 |
|
2098 | 2098 | else: |
|
2099 | 2099 | start = q.seriesend(True) |
|
2100 | 2100 | |
|
2101 | 2101 | if start == len(q.series) and opts.get('first'): |
|
2102 | 2102 | ui.write(_("all patches applied\n")) |
|
2103 | 2103 | return 1 |
|
2104 | 2104 | |
|
2105 | 2105 | length = opts.get('first') and 1 or None |
|
2106 | 2106 | q.qseries(repo, start=start, length=length, status='U', |
|
2107 | 2107 | summary=opts.get('summary')) |
|
2108 | 2108 | |
|
2109 | 2109 | @command("qimport", |
|
2110 | 2110 | [('e', 'existing', None, _('import file in patch directory')), |
|
2111 | 2111 | ('n', 'name', '', |
|
2112 | 2112 | _('name of patch file'), _('NAME')), |
|
2113 | 2113 | ('f', 'force', None, _('overwrite existing files')), |
|
2114 | 2114 | ('r', 'rev', [], |
|
2115 | 2115 | _('place existing revisions under mq control'), _('REV')), |
|
2116 | 2116 | ('g', 'git', None, _('use git extended diff format')), |
|
2117 | 2117 | ('P', 'push', None, _('qpush after importing'))], |
|
2118 | 2118 | _('hg qimport [-e] [-n NAME] [-f] [-g] [-P] [-r REV]... [FILE]...')) |
|
2119 | 2119 | def qimport(ui, repo, *filename, **opts): |
|
2120 | 2120 | """import a patch or existing changeset |
|
2121 | 2121 | |
|
2122 | 2122 | The patch is inserted into the series after the last applied |
|
2123 | 2123 | patch. If no patches have been applied, qimport prepends the patch |
|
2124 | 2124 | to the series. |
|
2125 | 2125 | |
|
2126 | 2126 | The patch will have the same name as its source file unless you |
|
2127 | 2127 | give it a new one with -n/--name. |
|
2128 | 2128 | |
|
2129 | 2129 | You can register an existing patch inside the patch directory with |
|
2130 | 2130 | the -e/--existing flag. |
|
2131 | 2131 | |
|
2132 | 2132 | With -f/--force, an existing patch of the same name will be |
|
2133 | 2133 | overwritten. |
|
2134 | 2134 | |
|
2135 | 2135 | An existing changeset may be placed under mq control with -r/--rev |
|
2136 | 2136 | (e.g. qimport --rev tip -n patch will place tip under mq control). |
|
2137 | 2137 | With -g/--git, patches imported with --rev will use the git diff |
|
2138 | 2138 | format. See the diffs help topic for information on why this is |
|
2139 | 2139 | important for preserving rename/copy information and permission |
|
2140 | 2140 | changes. Use :hg:`qfinish` to remove changesets from mq control. |
|
2141 | 2141 | |
|
2142 | 2142 | To import a patch from standard input, pass - as the patch file. |
|
2143 | 2143 | When importing from standard input, a patch name must be specified |
|
2144 | 2144 | using the --name flag. |
|
2145 | 2145 | |
|
2146 | 2146 | To import an existing patch while renaming it:: |
|
2147 | 2147 | |
|
2148 | 2148 | hg qimport -e existing-patch -n new-name |
|
2149 | 2149 | |
|
2150 | 2150 | Returns 0 if import succeeded. |
|
2151 | 2151 | """ |
|
2152 | 2152 | lock = repo.lock() # cause this may move phase |
|
2153 | 2153 | try: |
|
2154 | 2154 | q = repo.mq |
|
2155 | 2155 | try: |
|
2156 | 2156 | imported = q.qimport( |
|
2157 | 2157 | repo, filename, patchname=opts.get('name'), |
|
2158 | 2158 | existing=opts.get('existing'), force=opts.get('force'), |
|
2159 | 2159 | rev=opts.get('rev'), git=opts.get('git')) |
|
2160 | 2160 | finally: |
|
2161 | 2161 | q.savedirty() |
|
2162 | 2162 | finally: |
|
2163 | 2163 | lock.release() |
|
2164 | 2164 | |
|
2165 | 2165 | if imported and opts.get('push') and not opts.get('rev'): |
|
2166 | 2166 | return q.push(repo, imported[-1]) |
|
2167 | 2167 | return 0 |
|
2168 | 2168 | |
|
2169 | 2169 | def qinit(ui, repo, create): |
|
2170 | 2170 | """initialize a new queue repository |
|
2171 | 2171 | |
|
2172 | 2172 | This command also creates a series file for ordering patches, and |
|
2173 | 2173 | an mq-specific .hgignore file in the queue repository, to exclude |
|
2174 | 2174 | the status and guards files (these contain mostly transient state). |
|
2175 | 2175 | |
|
2176 | 2176 | Returns 0 if initialization succeeded.""" |
|
2177 | 2177 | q = repo.mq |
|
2178 | 2178 | r = q.init(repo, create) |
|
2179 | 2179 | q.savedirty() |
|
2180 | 2180 | if r: |
|
2181 | 2181 | if not os.path.exists(r.wjoin('.hgignore')): |
|
2182 | 2182 | fp = r.wopener('.hgignore', 'w') |
|
2183 | 2183 | fp.write('^\\.hg\n') |
|
2184 | 2184 | fp.write('^\\.mq\n') |
|
2185 | 2185 | fp.write('syntax: glob\n') |
|
2186 | 2186 | fp.write('status\n') |
|
2187 | 2187 | fp.write('guards\n') |
|
2188 | 2188 | fp.close() |
|
2189 | 2189 | if not os.path.exists(r.wjoin('series')): |
|
2190 | 2190 | r.wopener('series', 'w').close() |
|
2191 | 2191 | r[None].add(['.hgignore', 'series']) |
|
2192 | 2192 | commands.add(ui, r) |
|
2193 | 2193 | return 0 |
|
2194 | 2194 | |
|
2195 | 2195 | @command("^qinit", |
|
2196 | 2196 | [('c', 'create-repo', None, _('create queue repository'))], |
|
2197 | 2197 | _('hg qinit [-c]')) |
|
2198 | 2198 | def init(ui, repo, **opts): |
|
2199 | 2199 | """init a new queue repository (DEPRECATED) |
|
2200 | 2200 | |
|
2201 | 2201 | The queue repository is unversioned by default. If |
|
2202 | 2202 | -c/--create-repo is specified, qinit will create a separate nested |
|
2203 | 2203 | repository for patches (qinit -c may also be run later to convert |
|
2204 | 2204 | an unversioned patch repository into a versioned one). You can use |
|
2205 | 2205 | qcommit to commit changes to this queue repository. |
|
2206 | 2206 | |
|
2207 | 2207 | This command is deprecated. Without -c, it's implied by other relevant |
|
2208 | 2208 | commands. With -c, use :hg:`init --mq` instead.""" |
|
2209 | 2209 | return qinit(ui, repo, create=opts.get('create_repo')) |
|
2210 | 2210 | |
|
2211 | 2211 | @command("qclone", |
|
2212 | 2212 | [('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2213 | 2213 | ('U', 'noupdate', None, |
|
2214 | 2214 | _('do not update the new working directories')), |
|
2215 | 2215 | ('', 'uncompressed', None, |
|
2216 | 2216 | _('use uncompressed transfer (fast over LAN)')), |
|
2217 | 2217 | ('p', 'patches', '', |
|
2218 | 2218 | _('location of source patch repository'), _('REPO')), |
|
2219 | 2219 | ] + commands.remoteopts, |
|
2220 | 2220 | _('hg qclone [OPTION]... SOURCE [DEST]')) |
|
2221 | 2221 | def clone(ui, source, dest=None, **opts): |
|
2222 | 2222 | '''clone main and patch repository at same time |
|
2223 | 2223 | |
|
2224 | 2224 | If source is local, destination will have no patches applied. If |
|
2225 | 2225 | source is remote, this command can not check if patches are |
|
2226 | 2226 | applied in source, so cannot guarantee that patches are not |
|
2227 | 2227 | applied in destination. If you clone remote repository, be sure |
|
2228 | 2228 | before that it has no patches applied. |
|
2229 | 2229 | |
|
2230 | 2230 | Source patch repository is looked for in <src>/.hg/patches by |
|
2231 | 2231 | default. Use -p <url> to change. |
|
2232 | 2232 | |
|
2233 | 2233 | The patch directory must be a nested Mercurial repository, as |
|
2234 | 2234 | would be created by :hg:`init --mq`. |
|
2235 | 2235 | |
|
2236 | 2236 | Return 0 on success. |
|
2237 | 2237 | ''' |
|
2238 | 2238 | def patchdir(repo): |
|
2239 | 2239 | """compute a patch repo url from a repo object""" |
|
2240 | 2240 | url = repo.url() |
|
2241 | 2241 | if url.endswith('/'): |
|
2242 | 2242 | url = url[:-1] |
|
2243 | 2243 | return url + '/.hg/patches' |
|
2244 | 2244 | |
|
2245 | 2245 | # main repo (destination and sources) |
|
2246 | 2246 | if dest is None: |
|
2247 | 2247 | dest = hg.defaultdest(source) |
|
2248 |
sr = hg. |
|
|
2248 | sr = hg.peer(ui, opts, ui.expandpath(source)) | |
|
2249 | 2249 | |
|
2250 | 2250 | # patches repo (source only) |
|
2251 | 2251 | if opts.get('patches'): |
|
2252 | 2252 | patchespath = ui.expandpath(opts.get('patches')) |
|
2253 | 2253 | else: |
|
2254 | 2254 | patchespath = patchdir(sr) |
|
2255 | 2255 | try: |
|
2256 |
hg. |
|
|
2256 | hg.peer(ui, opts, patchespath) | |
|
2257 | 2257 | except error.RepoError: |
|
2258 | 2258 | raise util.Abort(_('versioned patch repository not found' |
|
2259 | 2259 | ' (see init --mq)')) |
|
2260 | 2260 | qbase, destrev = None, None |
|
2261 | 2261 | if sr.local(): |
|
2262 | if sr.mq.applied and sr[qbase].phase() != phases.secret: | |
|
2263 | qbase = sr.mq.applied[0].node | |
|
2262 | repo = sr.local() | |
|
2263 | if repo.mq.applied and repo[qbase].phase() != phases.secret: | |
|
2264 | qbase = repo.mq.applied[0].node | |
|
2264 | 2265 | if not hg.islocal(dest): |
|
2265 |
heads = set( |
|
|
2266 |
destrev = list(heads.difference( |
|
|
2267 |
destrev.append( |
|
|
2266 | heads = set(repo.heads()) | |
|
2267 | destrev = list(heads.difference(repo.heads(qbase))) | |
|
2268 | destrev.append(repo.changelog.parents(qbase)[0]) | |
|
2268 | 2269 | elif sr.capable('lookup'): |
|
2269 | 2270 | try: |
|
2270 | 2271 | qbase = sr.lookup('qbase') |
|
2271 | 2272 | except error.RepoError: |
|
2272 | 2273 | pass |
|
2273 | 2274 | |
|
2274 | 2275 | ui.note(_('cloning main repository\n')) |
|
2275 | 2276 | sr, dr = hg.clone(ui, opts, sr.url(), dest, |
|
2276 | 2277 | pull=opts.get('pull'), |
|
2277 | 2278 | rev=destrev, |
|
2278 | 2279 | update=False, |
|
2279 | 2280 | stream=opts.get('uncompressed')) |
|
2280 | 2281 | |
|
2281 | 2282 | ui.note(_('cloning patch repository\n')) |
|
2282 | 2283 | hg.clone(ui, opts, opts.get('patches') or patchdir(sr), patchdir(dr), |
|
2283 | 2284 | pull=opts.get('pull'), update=not opts.get('noupdate'), |
|
2284 | 2285 | stream=opts.get('uncompressed')) |
|
2285 | 2286 | |
|
2286 | 2287 | if dr.local(): |
|
2288 | repo = dr.local() | |
|
2287 | 2289 | if qbase: |
|
2288 | 2290 | ui.note(_('stripping applied patches from destination ' |
|
2289 | 2291 | 'repository\n')) |
|
2290 |
|
|
|
2292 | repo.mq.strip(repo, [qbase], update=False, backup=None) | |
|
2291 | 2293 | if not opts.get('noupdate'): |
|
2292 | 2294 | ui.note(_('updating destination repository\n')) |
|
2293 |
hg.update( |
|
|
2295 | hg.update(repo, repo.changelog.tip()) | |
|
2294 | 2296 | |
|
2295 | 2297 | @command("qcommit|qci", |
|
2296 | 2298 | commands.table["^commit|ci"][1], |
|
2297 | 2299 | _('hg qcommit [OPTION]... [FILE]...')) |
|
2298 | 2300 | def commit(ui, repo, *pats, **opts): |
|
2299 | 2301 | """commit changes in the queue repository (DEPRECATED) |
|
2300 | 2302 | |
|
2301 | 2303 | This command is deprecated; use :hg:`commit --mq` instead.""" |
|
2302 | 2304 | q = repo.mq |
|
2303 | 2305 | r = q.qrepo() |
|
2304 | 2306 | if not r: |
|
2305 | 2307 | raise util.Abort('no queue repository') |
|
2306 | 2308 | commands.commit(r.ui, r, *pats, **opts) |
|
2307 | 2309 | |
|
2308 | 2310 | @command("qseries", |
|
2309 | 2311 | [('m', 'missing', None, _('print patches not in series')), |
|
2310 | 2312 | ] + seriesopts, |
|
2311 | 2313 | _('hg qseries [-ms]')) |
|
2312 | 2314 | def series(ui, repo, **opts): |
|
2313 | 2315 | """print the entire series file |
|
2314 | 2316 | |
|
2315 | 2317 | Returns 0 on success.""" |
|
2316 | 2318 | repo.mq.qseries(repo, missing=opts.get('missing'), |
|
2317 | 2319 | summary=opts.get('summary')) |
|
2318 | 2320 | return 0 |
|
2319 | 2321 | |
|
2320 | 2322 | @command("qtop", seriesopts, _('hg qtop [-s]')) |
|
2321 | 2323 | def top(ui, repo, **opts): |
|
2322 | 2324 | """print the name of the current patch |
|
2323 | 2325 | |
|
2324 | 2326 | Returns 0 on success.""" |
|
2325 | 2327 | q = repo.mq |
|
2326 | 2328 | t = q.applied and q.seriesend(True) or 0 |
|
2327 | 2329 | if t: |
|
2328 | 2330 | q.qseries(repo, start=t - 1, length=1, status='A', |
|
2329 | 2331 | summary=opts.get('summary')) |
|
2330 | 2332 | else: |
|
2331 | 2333 | ui.write(_("no patches applied\n")) |
|
2332 | 2334 | return 1 |
|
2333 | 2335 | |
|
2334 | 2336 | @command("qnext", seriesopts, _('hg qnext [-s]')) |
|
2335 | 2337 | def next(ui, repo, **opts): |
|
2336 | 2338 | """print the name of the next pushable patch |
|
2337 | 2339 | |
|
2338 | 2340 | Returns 0 on success.""" |
|
2339 | 2341 | q = repo.mq |
|
2340 | 2342 | end = q.seriesend() |
|
2341 | 2343 | if end == len(q.series): |
|
2342 | 2344 | ui.write(_("all patches applied\n")) |
|
2343 | 2345 | return 1 |
|
2344 | 2346 | q.qseries(repo, start=end, length=1, summary=opts.get('summary')) |
|
2345 | 2347 | |
|
2346 | 2348 | @command("qprev", seriesopts, _('hg qprev [-s]')) |
|
2347 | 2349 | def prev(ui, repo, **opts): |
|
2348 | 2350 | """print the name of the preceding applied patch |
|
2349 | 2351 | |
|
2350 | 2352 | Returns 0 on success.""" |
|
2351 | 2353 | q = repo.mq |
|
2352 | 2354 | l = len(q.applied) |
|
2353 | 2355 | if l == 1: |
|
2354 | 2356 | ui.write(_("only one patch applied\n")) |
|
2355 | 2357 | return 1 |
|
2356 | 2358 | if not l: |
|
2357 | 2359 | ui.write(_("no patches applied\n")) |
|
2358 | 2360 | return 1 |
|
2359 | 2361 | idx = q.series.index(q.applied[-2].name) |
|
2360 | 2362 | q.qseries(repo, start=idx, length=1, status='A', |
|
2361 | 2363 | summary=opts.get('summary')) |
|
2362 | 2364 | |
|
2363 | 2365 | def setupheaderopts(ui, opts): |
|
2364 | 2366 | if not opts.get('user') and opts.get('currentuser'): |
|
2365 | 2367 | opts['user'] = ui.username() |
|
2366 | 2368 | if not opts.get('date') and opts.get('currentdate'): |
|
2367 | 2369 | opts['date'] = "%d %d" % util.makedate() |
|
2368 | 2370 | |
|
2369 | 2371 | @command("^qnew", |
|
2370 | 2372 | [('e', 'edit', None, _('edit commit message')), |
|
2371 | 2373 | ('f', 'force', None, _('import uncommitted changes (DEPRECATED)')), |
|
2372 | 2374 | ('g', 'git', None, _('use git extended diff format')), |
|
2373 | 2375 | ('U', 'currentuser', None, _('add "From: <current user>" to patch')), |
|
2374 | 2376 | ('u', 'user', '', |
|
2375 | 2377 | _('add "From: <USER>" to patch'), _('USER')), |
|
2376 | 2378 | ('D', 'currentdate', None, _('add "Date: <current date>" to patch')), |
|
2377 | 2379 | ('d', 'date', '', |
|
2378 | 2380 | _('add "Date: <DATE>" to patch'), _('DATE')) |
|
2379 | 2381 | ] + commands.walkopts + commands.commitopts, |
|
2380 | 2382 | _('hg qnew [-e] [-m TEXT] [-l FILE] PATCH [FILE]...')) |
|
2381 | 2383 | def new(ui, repo, patch, *args, **opts): |
|
2382 | 2384 | """create a new patch |
|
2383 | 2385 | |
|
2384 | 2386 | qnew creates a new patch on top of the currently-applied patch (if |
|
2385 | 2387 | any). The patch will be initialized with any outstanding changes |
|
2386 | 2388 | in the working directory. You may also use -I/--include, |
|
2387 | 2389 | -X/--exclude, and/or a list of files after the patch name to add |
|
2388 | 2390 | only changes to matching files to the new patch, leaving the rest |
|
2389 | 2391 | as uncommitted modifications. |
|
2390 | 2392 | |
|
2391 | 2393 | -u/--user and -d/--date can be used to set the (given) user and |
|
2392 | 2394 | date, respectively. -U/--currentuser and -D/--currentdate set user |
|
2393 | 2395 | to current user and date to current date. |
|
2394 | 2396 | |
|
2395 | 2397 | -e/--edit, -m/--message or -l/--logfile set the patch header as |
|
2396 | 2398 | well as the commit message. If none is specified, the header is |
|
2397 | 2399 | empty and the commit message is '[mq]: PATCH'. |
|
2398 | 2400 | |
|
2399 | 2401 | Use the -g/--git option to keep the patch in the git extended diff |
|
2400 | 2402 | format. Read the diffs help topic for more information on why this |
|
2401 | 2403 | is important for preserving permission changes and copy/rename |
|
2402 | 2404 | information. |
|
2403 | 2405 | |
|
2404 | 2406 | Returns 0 on successful creation of a new patch. |
|
2405 | 2407 | """ |
|
2406 | 2408 | msg = cmdutil.logmessage(ui, opts) |
|
2407 | 2409 | def getmsg(): |
|
2408 | 2410 | return ui.edit(msg, opts.get('user') or ui.username()) |
|
2409 | 2411 | q = repo.mq |
|
2410 | 2412 | opts['msg'] = msg |
|
2411 | 2413 | if opts.get('edit'): |
|
2412 | 2414 | opts['msg'] = getmsg |
|
2413 | 2415 | else: |
|
2414 | 2416 | opts['msg'] = msg |
|
2415 | 2417 | setupheaderopts(ui, opts) |
|
2416 | 2418 | q.new(repo, patch, *args, **opts) |
|
2417 | 2419 | q.savedirty() |
|
2418 | 2420 | return 0 |
|
2419 | 2421 | |
|
2420 | 2422 | @command("^qrefresh", |
|
2421 | 2423 | [('e', 'edit', None, _('edit commit message')), |
|
2422 | 2424 | ('g', 'git', None, _('use git extended diff format')), |
|
2423 | 2425 | ('s', 'short', None, |
|
2424 | 2426 | _('refresh only files already in the patch and specified files')), |
|
2425 | 2427 | ('U', 'currentuser', None, |
|
2426 | 2428 | _('add/update author field in patch with current user')), |
|
2427 | 2429 | ('u', 'user', '', |
|
2428 | 2430 | _('add/update author field in patch with given user'), _('USER')), |
|
2429 | 2431 | ('D', 'currentdate', None, |
|
2430 | 2432 | _('add/update date field in patch with current date')), |
|
2431 | 2433 | ('d', 'date', '', |
|
2432 | 2434 | _('add/update date field in patch with given date'), _('DATE')) |
|
2433 | 2435 | ] + commands.walkopts + commands.commitopts, |
|
2434 | 2436 | _('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...')) |
|
2435 | 2437 | def refresh(ui, repo, *pats, **opts): |
|
2436 | 2438 | """update the current patch |
|
2437 | 2439 | |
|
2438 | 2440 | If any file patterns are provided, the refreshed patch will |
|
2439 | 2441 | contain only the modifications that match those patterns; the |
|
2440 | 2442 | remaining modifications will remain in the working directory. |
|
2441 | 2443 | |
|
2442 | 2444 | If -s/--short is specified, files currently included in the patch |
|
2443 | 2445 | will be refreshed just like matched files and remain in the patch. |
|
2444 | 2446 | |
|
2445 | 2447 | If -e/--edit is specified, Mercurial will start your configured editor for |
|
2446 | 2448 | you to enter a message. In case qrefresh fails, you will find a backup of |
|
2447 | 2449 | your message in ``.hg/last-message.txt``. |
|
2448 | 2450 | |
|
2449 | 2451 | hg add/remove/copy/rename work as usual, though you might want to |
|
2450 | 2452 | use git-style patches (-g/--git or [diff] git=1) to track copies |
|
2451 | 2453 | and renames. See the diffs help topic for more information on the |
|
2452 | 2454 | git diff format. |
|
2453 | 2455 | |
|
2454 | 2456 | Returns 0 on success. |
|
2455 | 2457 | """ |
|
2456 | 2458 | q = repo.mq |
|
2457 | 2459 | message = cmdutil.logmessage(ui, opts) |
|
2458 | 2460 | if opts.get('edit'): |
|
2459 | 2461 | if not q.applied: |
|
2460 | 2462 | ui.write(_("no patches applied\n")) |
|
2461 | 2463 | return 1 |
|
2462 | 2464 | if message: |
|
2463 | 2465 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
2464 | 2466 | patch = q.applied[-1].name |
|
2465 | 2467 | ph = patchheader(q.join(patch), q.plainmode) |
|
2466 | 2468 | message = ui.edit('\n'.join(ph.message), ph.user or ui.username()) |
|
2467 | 2469 | # We don't want to lose the patch message if qrefresh fails (issue2062) |
|
2468 | 2470 | repo.savecommitmessage(message) |
|
2469 | 2471 | setupheaderopts(ui, opts) |
|
2470 | 2472 | wlock = repo.wlock() |
|
2471 | 2473 | try: |
|
2472 | 2474 | ret = q.refresh(repo, pats, msg=message, **opts) |
|
2473 | 2475 | q.savedirty() |
|
2474 | 2476 | return ret |
|
2475 | 2477 | finally: |
|
2476 | 2478 | wlock.release() |
|
2477 | 2479 | |
|
2478 | 2480 | @command("^qdiff", |
|
2479 | 2481 | commands.diffopts + commands.diffopts2 + commands.walkopts, |
|
2480 | 2482 | _('hg qdiff [OPTION]... [FILE]...')) |
|
2481 | 2483 | def diff(ui, repo, *pats, **opts): |
|
2482 | 2484 | """diff of the current patch and subsequent modifications |
|
2483 | 2485 | |
|
2484 | 2486 | Shows a diff which includes the current patch as well as any |
|
2485 | 2487 | changes which have been made in the working directory since the |
|
2486 | 2488 | last refresh (thus showing what the current patch would become |
|
2487 | 2489 | after a qrefresh). |
|
2488 | 2490 | |
|
2489 | 2491 | Use :hg:`diff` if you only want to see the changes made since the |
|
2490 | 2492 | last qrefresh, or :hg:`export qtip` if you want to see changes |
|
2491 | 2493 | made by the current patch without including changes made since the |
|
2492 | 2494 | qrefresh. |
|
2493 | 2495 | |
|
2494 | 2496 | Returns 0 on success. |
|
2495 | 2497 | """ |
|
2496 | 2498 | repo.mq.diff(repo, pats, opts) |
|
2497 | 2499 | return 0 |
|
2498 | 2500 | |
|
2499 | 2501 | @command('qfold', |
|
2500 | 2502 | [('e', 'edit', None, _('edit patch header')), |
|
2501 | 2503 | ('k', 'keep', None, _('keep folded patch files')), |
|
2502 | 2504 | ] + commands.commitopts, |
|
2503 | 2505 | _('hg qfold [-e] [-k] [-m TEXT] [-l FILE] PATCH...')) |
|
2504 | 2506 | def fold(ui, repo, *files, **opts): |
|
2505 | 2507 | """fold the named patches into the current patch |
|
2506 | 2508 | |
|
2507 | 2509 | Patches must not yet be applied. Each patch will be successively |
|
2508 | 2510 | applied to the current patch in the order given. If all the |
|
2509 | 2511 | patches apply successfully, the current patch will be refreshed |
|
2510 | 2512 | with the new cumulative patch, and the folded patches will be |
|
2511 | 2513 | deleted. With -k/--keep, the folded patch files will not be |
|
2512 | 2514 | removed afterwards. |
|
2513 | 2515 | |
|
2514 | 2516 | The header for each folded patch will be concatenated with the |
|
2515 | 2517 | current patch header, separated by a line of ``* * *``. |
|
2516 | 2518 | |
|
2517 | 2519 | Returns 0 on success.""" |
|
2518 | 2520 | q = repo.mq |
|
2519 | 2521 | if not files: |
|
2520 | 2522 | raise util.Abort(_('qfold requires at least one patch name')) |
|
2521 | 2523 | if not q.checktoppatch(repo)[0]: |
|
2522 | 2524 | raise util.Abort(_('no patches applied')) |
|
2523 | 2525 | q.checklocalchanges(repo) |
|
2524 | 2526 | |
|
2525 | 2527 | message = cmdutil.logmessage(ui, opts) |
|
2526 | 2528 | if opts.get('edit'): |
|
2527 | 2529 | if message: |
|
2528 | 2530 | raise util.Abort(_('option "-e" incompatible with "-m" or "-l"')) |
|
2529 | 2531 | |
|
2530 | 2532 | parent = q.lookup('qtip') |
|
2531 | 2533 | patches = [] |
|
2532 | 2534 | messages = [] |
|
2533 | 2535 | for f in files: |
|
2534 | 2536 | p = q.lookup(f) |
|
2535 | 2537 | if p in patches or p == parent: |
|
2536 | 2538 | ui.warn(_('skipping already folded patch %s\n') % p) |
|
2537 | 2539 | if q.isapplied(p): |
|
2538 | 2540 | raise util.Abort(_('qfold cannot fold already applied patch %s') |
|
2539 | 2541 | % p) |
|
2540 | 2542 | patches.append(p) |
|
2541 | 2543 | |
|
2542 | 2544 | for p in patches: |
|
2543 | 2545 | if not message: |
|
2544 | 2546 | ph = patchheader(q.join(p), q.plainmode) |
|
2545 | 2547 | if ph.message: |
|
2546 | 2548 | messages.append(ph.message) |
|
2547 | 2549 | pf = q.join(p) |
|
2548 | 2550 | (patchsuccess, files, fuzz) = q.patch(repo, pf) |
|
2549 | 2551 | if not patchsuccess: |
|
2550 | 2552 | raise util.Abort(_('error folding patch %s') % p) |
|
2551 | 2553 | |
|
2552 | 2554 | if not message: |
|
2553 | 2555 | ph = patchheader(q.join(parent), q.plainmode) |
|
2554 | 2556 | message, user = ph.message, ph.user |
|
2555 | 2557 | for msg in messages: |
|
2556 | 2558 | message.append('* * *') |
|
2557 | 2559 | message.extend(msg) |
|
2558 | 2560 | message = '\n'.join(message) |
|
2559 | 2561 | |
|
2560 | 2562 | if opts.get('edit'): |
|
2561 | 2563 | message = ui.edit(message, user or ui.username()) |
|
2562 | 2564 | |
|
2563 | 2565 | diffopts = q.patchopts(q.diffopts(), *patches) |
|
2564 | 2566 | wlock = repo.wlock() |
|
2565 | 2567 | try: |
|
2566 | 2568 | q.refresh(repo, msg=message, git=diffopts.git) |
|
2567 | 2569 | q.delete(repo, patches, opts) |
|
2568 | 2570 | q.savedirty() |
|
2569 | 2571 | finally: |
|
2570 | 2572 | wlock.release() |
|
2571 | 2573 | |
|
2572 | 2574 | @command("qgoto", |
|
2573 | 2575 | [('', 'keep-changes', None, |
|
2574 | 2576 | _('tolerate non-conflicting local changes')), |
|
2575 | 2577 | ('f', 'force', None, _('overwrite any local changes')), |
|
2576 | 2578 | ('', 'no-backup', None, _('do not save backup copies of files'))], |
|
2577 | 2579 | _('hg qgoto [OPTION]... PATCH')) |
|
2578 | 2580 | def goto(ui, repo, patch, **opts): |
|
2579 | 2581 | '''push or pop patches until named patch is at top of stack |
|
2580 | 2582 | |
|
2581 | 2583 | Returns 0 on success.''' |
|
2582 | 2584 | opts = fixkeepchangesopts(ui, opts) |
|
2583 | 2585 | q = repo.mq |
|
2584 | 2586 | patch = q.lookup(patch) |
|
2585 | 2587 | nobackup = opts.get('no_backup') |
|
2586 | 2588 | keepchanges = opts.get('keep_changes') |
|
2587 | 2589 | if q.isapplied(patch): |
|
2588 | 2590 | ret = q.pop(repo, patch, force=opts.get('force'), nobackup=nobackup, |
|
2589 | 2591 | keepchanges=keepchanges) |
|
2590 | 2592 | else: |
|
2591 | 2593 | ret = q.push(repo, patch, force=opts.get('force'), nobackup=nobackup, |
|
2592 | 2594 | keepchanges=keepchanges) |
|
2593 | 2595 | q.savedirty() |
|
2594 | 2596 | return ret |
|
2595 | 2597 | |
|
2596 | 2598 | @command("qguard", |
|
2597 | 2599 | [('l', 'list', None, _('list all patches and guards')), |
|
2598 | 2600 | ('n', 'none', None, _('drop all guards'))], |
|
2599 | 2601 | _('hg qguard [-l] [-n] [PATCH] [-- [+GUARD]... [-GUARD]...]')) |
|
2600 | 2602 | def guard(ui, repo, *args, **opts): |
|
2601 | 2603 | '''set or print guards for a patch |
|
2602 | 2604 | |
|
2603 | 2605 | Guards control whether a patch can be pushed. A patch with no |
|
2604 | 2606 | guards is always pushed. A patch with a positive guard ("+foo") is |
|
2605 | 2607 | pushed only if the :hg:`qselect` command has activated it. A patch with |
|
2606 | 2608 | a negative guard ("-foo") is never pushed if the :hg:`qselect` command |
|
2607 | 2609 | has activated it. |
|
2608 | 2610 | |
|
2609 | 2611 | With no arguments, print the currently active guards. |
|
2610 | 2612 | With arguments, set guards for the named patch. |
|
2611 | 2613 | |
|
2612 | 2614 | .. note:: |
|
2613 | 2615 | Specifying negative guards now requires '--'. |
|
2614 | 2616 | |
|
2615 | 2617 | To set guards on another patch:: |
|
2616 | 2618 | |
|
2617 | 2619 | hg qguard other.patch -- +2.6.17 -stable |
|
2618 | 2620 | |
|
2619 | 2621 | Returns 0 on success. |
|
2620 | 2622 | ''' |
|
2621 | 2623 | def status(idx): |
|
2622 | 2624 | guards = q.seriesguards[idx] or ['unguarded'] |
|
2623 | 2625 | if q.series[idx] in applied: |
|
2624 | 2626 | state = 'applied' |
|
2625 | 2627 | elif q.pushable(idx)[0]: |
|
2626 | 2628 | state = 'unapplied' |
|
2627 | 2629 | else: |
|
2628 | 2630 | state = 'guarded' |
|
2629 | 2631 | label = 'qguard.patch qguard.%s qseries.%s' % (state, state) |
|
2630 | 2632 | ui.write('%s: ' % ui.label(q.series[idx], label)) |
|
2631 | 2633 | |
|
2632 | 2634 | for i, guard in enumerate(guards): |
|
2633 | 2635 | if guard.startswith('+'): |
|
2634 | 2636 | ui.write(guard, label='qguard.positive') |
|
2635 | 2637 | elif guard.startswith('-'): |
|
2636 | 2638 | ui.write(guard, label='qguard.negative') |
|
2637 | 2639 | else: |
|
2638 | 2640 | ui.write(guard, label='qguard.unguarded') |
|
2639 | 2641 | if i != len(guards) - 1: |
|
2640 | 2642 | ui.write(' ') |
|
2641 | 2643 | ui.write('\n') |
|
2642 | 2644 | q = repo.mq |
|
2643 | 2645 | applied = set(p.name for p in q.applied) |
|
2644 | 2646 | patch = None |
|
2645 | 2647 | args = list(args) |
|
2646 | 2648 | if opts.get('list'): |
|
2647 | 2649 | if args or opts.get('none'): |
|
2648 | 2650 | raise util.Abort(_('cannot mix -l/--list with options or ' |
|
2649 | 2651 | 'arguments')) |
|
2650 | 2652 | for i in xrange(len(q.series)): |
|
2651 | 2653 | status(i) |
|
2652 | 2654 | return |
|
2653 | 2655 | if not args or args[0][0:1] in '-+': |
|
2654 | 2656 | if not q.applied: |
|
2655 | 2657 | raise util.Abort(_('no patches applied')) |
|
2656 | 2658 | patch = q.applied[-1].name |
|
2657 | 2659 | if patch is None and args[0][0:1] not in '-+': |
|
2658 | 2660 | patch = args.pop(0) |
|
2659 | 2661 | if patch is None: |
|
2660 | 2662 | raise util.Abort(_('no patch to work with')) |
|
2661 | 2663 | if args or opts.get('none'): |
|
2662 | 2664 | idx = q.findseries(patch) |
|
2663 | 2665 | if idx is None: |
|
2664 | 2666 | raise util.Abort(_('no patch named %s') % patch) |
|
2665 | 2667 | q.setguards(idx, args) |
|
2666 | 2668 | q.savedirty() |
|
2667 | 2669 | else: |
|
2668 | 2670 | status(q.series.index(q.lookup(patch))) |
|
2669 | 2671 | |
|
2670 | 2672 | @command("qheader", [], _('hg qheader [PATCH]')) |
|
2671 | 2673 | def header(ui, repo, patch=None): |
|
2672 | 2674 | """print the header of the topmost or specified patch |
|
2673 | 2675 | |
|
2674 | 2676 | Returns 0 on success.""" |
|
2675 | 2677 | q = repo.mq |
|
2676 | 2678 | |
|
2677 | 2679 | if patch: |
|
2678 | 2680 | patch = q.lookup(patch) |
|
2679 | 2681 | else: |
|
2680 | 2682 | if not q.applied: |
|
2681 | 2683 | ui.write(_('no patches applied\n')) |
|
2682 | 2684 | return 1 |
|
2683 | 2685 | patch = q.lookup('qtip') |
|
2684 | 2686 | ph = patchheader(q.join(patch), q.plainmode) |
|
2685 | 2687 | |
|
2686 | 2688 | ui.write('\n'.join(ph.message) + '\n') |
|
2687 | 2689 | |
|
2688 | 2690 | def lastsavename(path): |
|
2689 | 2691 | (directory, base) = os.path.split(path) |
|
2690 | 2692 | names = os.listdir(directory) |
|
2691 | 2693 | namere = re.compile("%s.([0-9]+)" % base) |
|
2692 | 2694 | maxindex = None |
|
2693 | 2695 | maxname = None |
|
2694 | 2696 | for f in names: |
|
2695 | 2697 | m = namere.match(f) |
|
2696 | 2698 | if m: |
|
2697 | 2699 | index = int(m.group(1)) |
|
2698 | 2700 | if maxindex is None or index > maxindex: |
|
2699 | 2701 | maxindex = index |
|
2700 | 2702 | maxname = f |
|
2701 | 2703 | if maxname: |
|
2702 | 2704 | return (os.path.join(directory, maxname), maxindex) |
|
2703 | 2705 | return (None, None) |
|
2704 | 2706 | |
|
2705 | 2707 | def savename(path): |
|
2706 | 2708 | (last, index) = lastsavename(path) |
|
2707 | 2709 | if last is None: |
|
2708 | 2710 | index = 0 |
|
2709 | 2711 | newpath = path + ".%d" % (index + 1) |
|
2710 | 2712 | return newpath |
|
2711 | 2713 | |
|
2712 | 2714 | @command("^qpush", |
|
2713 | 2715 | [('', 'keep-changes', None, |
|
2714 | 2716 | _('tolerate non-conflicting local changes')), |
|
2715 | 2717 | ('f', 'force', None, _('apply on top of local changes')), |
|
2716 | 2718 | ('e', 'exact', None, |
|
2717 | 2719 | _('apply the target patch to its recorded parent')), |
|
2718 | 2720 | ('l', 'list', None, _('list patch name in commit text')), |
|
2719 | 2721 | ('a', 'all', None, _('apply all patches')), |
|
2720 | 2722 | ('m', 'merge', None, _('merge from another queue (DEPRECATED)')), |
|
2721 | 2723 | ('n', 'name', '', |
|
2722 | 2724 | _('merge queue name (DEPRECATED)'), _('NAME')), |
|
2723 | 2725 | ('', 'move', None, |
|
2724 | 2726 | _('reorder patch series and apply only the patch')), |
|
2725 | 2727 | ('', 'no-backup', None, _('do not save backup copies of files'))], |
|
2726 | 2728 | _('hg qpush [-f] [-l] [-a] [--move] [PATCH | INDEX]')) |
|
2727 | 2729 | def push(ui, repo, patch=None, **opts): |
|
2728 | 2730 | """push the next patch onto the stack |
|
2729 | 2731 | |
|
2730 | 2732 | By default, abort if the working directory contains uncommitted |
|
2731 | 2733 | changes. With --keep-changes, abort only if the uncommitted files |
|
2732 | 2734 | overlap with patched files. With -f/--force, backup and patch over |
|
2733 | 2735 | uncommitted changes. |
|
2734 | 2736 | |
|
2735 | 2737 | Return 0 on success. |
|
2736 | 2738 | """ |
|
2737 | 2739 | q = repo.mq |
|
2738 | 2740 | mergeq = None |
|
2739 | 2741 | |
|
2740 | 2742 | opts = fixkeepchangesopts(ui, opts) |
|
2741 | 2743 | if opts.get('merge'): |
|
2742 | 2744 | if opts.get('name'): |
|
2743 | 2745 | newpath = repo.join(opts.get('name')) |
|
2744 | 2746 | else: |
|
2745 | 2747 | newpath, i = lastsavename(q.path) |
|
2746 | 2748 | if not newpath: |
|
2747 | 2749 | ui.warn(_("no saved queues found, please use -n\n")) |
|
2748 | 2750 | return 1 |
|
2749 | 2751 | mergeq = queue(ui, repo.path, newpath) |
|
2750 | 2752 | ui.warn(_("merging with queue at: %s\n") % mergeq.path) |
|
2751 | 2753 | ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'), |
|
2752 | 2754 | mergeq=mergeq, all=opts.get('all'), move=opts.get('move'), |
|
2753 | 2755 | exact=opts.get('exact'), nobackup=opts.get('no_backup'), |
|
2754 | 2756 | keepchanges=opts.get('keep_changes')) |
|
2755 | 2757 | return ret |
|
2756 | 2758 | |
|
2757 | 2759 | @command("^qpop", |
|
2758 | 2760 | [('a', 'all', None, _('pop all patches')), |
|
2759 | 2761 | ('n', 'name', '', |
|
2760 | 2762 | _('queue name to pop (DEPRECATED)'), _('NAME')), |
|
2761 | 2763 | ('', 'keep-changes', None, |
|
2762 | 2764 | _('tolerate non-conflicting local changes')), |
|
2763 | 2765 | ('f', 'force', None, _('forget any local changes to patched files')), |
|
2764 | 2766 | ('', 'no-backup', None, _('do not save backup copies of files'))], |
|
2765 | 2767 | _('hg qpop [-a] [-f] [PATCH | INDEX]')) |
|
2766 | 2768 | def pop(ui, repo, patch=None, **opts): |
|
2767 | 2769 | """pop the current patch off the stack |
|
2768 | 2770 | |
|
2769 | 2771 | Without argument, pops off the top of the patch stack. If given a |
|
2770 | 2772 | patch name, keeps popping off patches until the named patch is at |
|
2771 | 2773 | the top of the stack. |
|
2772 | 2774 | |
|
2773 | 2775 | By default, abort if the working directory contains uncommitted |
|
2774 | 2776 | changes. With --keep-changes, abort only if the uncommitted files |
|
2775 | 2777 | overlap with patched files. With -f/--force, backup and discard |
|
2776 | 2778 | changes made to such files. |
|
2777 | 2779 | |
|
2778 | 2780 | Return 0 on success. |
|
2779 | 2781 | """ |
|
2780 | 2782 | opts = fixkeepchangesopts(ui, opts) |
|
2781 | 2783 | localupdate = True |
|
2782 | 2784 | if opts.get('name'): |
|
2783 | 2785 | q = queue(ui, repo.path, repo.join(opts.get('name'))) |
|
2784 | 2786 | ui.warn(_('using patch queue: %s\n') % q.path) |
|
2785 | 2787 | localupdate = False |
|
2786 | 2788 | else: |
|
2787 | 2789 | q = repo.mq |
|
2788 | 2790 | ret = q.pop(repo, patch, force=opts.get('force'), update=localupdate, |
|
2789 | 2791 | all=opts.get('all'), nobackup=opts.get('no_backup'), |
|
2790 | 2792 | keepchanges=opts.get('keep_changes')) |
|
2791 | 2793 | q.savedirty() |
|
2792 | 2794 | return ret |
|
2793 | 2795 | |
|
2794 | 2796 | @command("qrename|qmv", [], _('hg qrename PATCH1 [PATCH2]')) |
|
2795 | 2797 | def rename(ui, repo, patch, name=None, **opts): |
|
2796 | 2798 | """rename a patch |
|
2797 | 2799 | |
|
2798 | 2800 | With one argument, renames the current patch to PATCH1. |
|
2799 | 2801 | With two arguments, renames PATCH1 to PATCH2. |
|
2800 | 2802 | |
|
2801 | 2803 | Returns 0 on success.""" |
|
2802 | 2804 | q = repo.mq |
|
2803 | 2805 | if not name: |
|
2804 | 2806 | name = patch |
|
2805 | 2807 | patch = None |
|
2806 | 2808 | |
|
2807 | 2809 | if patch: |
|
2808 | 2810 | patch = q.lookup(patch) |
|
2809 | 2811 | else: |
|
2810 | 2812 | if not q.applied: |
|
2811 | 2813 | ui.write(_('no patches applied\n')) |
|
2812 | 2814 | return |
|
2813 | 2815 | patch = q.lookup('qtip') |
|
2814 | 2816 | absdest = q.join(name) |
|
2815 | 2817 | if os.path.isdir(absdest): |
|
2816 | 2818 | name = normname(os.path.join(name, os.path.basename(patch))) |
|
2817 | 2819 | absdest = q.join(name) |
|
2818 | 2820 | q.checkpatchname(name) |
|
2819 | 2821 | |
|
2820 | 2822 | ui.note(_('renaming %s to %s\n') % (patch, name)) |
|
2821 | 2823 | i = q.findseries(patch) |
|
2822 | 2824 | guards = q.guard_re.findall(q.fullseries[i]) |
|
2823 | 2825 | q.fullseries[i] = name + ''.join([' #' + g for g in guards]) |
|
2824 | 2826 | q.parseseries() |
|
2825 | 2827 | q.seriesdirty = True |
|
2826 | 2828 | |
|
2827 | 2829 | info = q.isapplied(patch) |
|
2828 | 2830 | if info: |
|
2829 | 2831 | q.applied[info[0]] = statusentry(info[1], name) |
|
2830 | 2832 | q.applieddirty = True |
|
2831 | 2833 | |
|
2832 | 2834 | destdir = os.path.dirname(absdest) |
|
2833 | 2835 | if not os.path.isdir(destdir): |
|
2834 | 2836 | os.makedirs(destdir) |
|
2835 | 2837 | util.rename(q.join(patch), absdest) |
|
2836 | 2838 | r = q.qrepo() |
|
2837 | 2839 | if r and patch in r.dirstate: |
|
2838 | 2840 | wctx = r[None] |
|
2839 | 2841 | wlock = r.wlock() |
|
2840 | 2842 | try: |
|
2841 | 2843 | if r.dirstate[patch] == 'a': |
|
2842 | 2844 | r.dirstate.drop(patch) |
|
2843 | 2845 | r.dirstate.add(name) |
|
2844 | 2846 | else: |
|
2845 | 2847 | wctx.copy(patch, name) |
|
2846 | 2848 | wctx.forget([patch]) |
|
2847 | 2849 | finally: |
|
2848 | 2850 | wlock.release() |
|
2849 | 2851 | |
|
2850 | 2852 | q.savedirty() |
|
2851 | 2853 | |
|
2852 | 2854 | @command("qrestore", |
|
2853 | 2855 | [('d', 'delete', None, _('delete save entry')), |
|
2854 | 2856 | ('u', 'update', None, _('update queue working directory'))], |
|
2855 | 2857 | _('hg qrestore [-d] [-u] REV')) |
|
2856 | 2858 | def restore(ui, repo, rev, **opts): |
|
2857 | 2859 | """restore the queue state saved by a revision (DEPRECATED) |
|
2858 | 2860 | |
|
2859 | 2861 | This command is deprecated, use :hg:`rebase` instead.""" |
|
2860 | 2862 | rev = repo.lookup(rev) |
|
2861 | 2863 | q = repo.mq |
|
2862 | 2864 | q.restore(repo, rev, delete=opts.get('delete'), |
|
2863 | 2865 | qupdate=opts.get('update')) |
|
2864 | 2866 | q.savedirty() |
|
2865 | 2867 | return 0 |
|
2866 | 2868 | |
|
2867 | 2869 | @command("qsave", |
|
2868 | 2870 | [('c', 'copy', None, _('copy patch directory')), |
|
2869 | 2871 | ('n', 'name', '', |
|
2870 | 2872 | _('copy directory name'), _('NAME')), |
|
2871 | 2873 | ('e', 'empty', None, _('clear queue status file')), |
|
2872 | 2874 | ('f', 'force', None, _('force copy'))] + commands.commitopts, |
|
2873 | 2875 | _('hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]')) |
|
2874 | 2876 | def save(ui, repo, **opts): |
|
2875 | 2877 | """save current queue state (DEPRECATED) |
|
2876 | 2878 | |
|
2877 | 2879 | This command is deprecated, use :hg:`rebase` instead.""" |
|
2878 | 2880 | q = repo.mq |
|
2879 | 2881 | message = cmdutil.logmessage(ui, opts) |
|
2880 | 2882 | ret = q.save(repo, msg=message) |
|
2881 | 2883 | if ret: |
|
2882 | 2884 | return ret |
|
2883 | 2885 | q.savedirty() # save to .hg/patches before copying |
|
2884 | 2886 | if opts.get('copy'): |
|
2885 | 2887 | path = q.path |
|
2886 | 2888 | if opts.get('name'): |
|
2887 | 2889 | newpath = os.path.join(q.basepath, opts.get('name')) |
|
2888 | 2890 | if os.path.exists(newpath): |
|
2889 | 2891 | if not os.path.isdir(newpath): |
|
2890 | 2892 | raise util.Abort(_('destination %s exists and is not ' |
|
2891 | 2893 | 'a directory') % newpath) |
|
2892 | 2894 | if not opts.get('force'): |
|
2893 | 2895 | raise util.Abort(_('destination %s exists, ' |
|
2894 | 2896 | 'use -f to force') % newpath) |
|
2895 | 2897 | else: |
|
2896 | 2898 | newpath = savename(path) |
|
2897 | 2899 | ui.warn(_("copy %s to %s\n") % (path, newpath)) |
|
2898 | 2900 | util.copyfiles(path, newpath) |
|
2899 | 2901 | if opts.get('empty'): |
|
2900 | 2902 | del q.applied[:] |
|
2901 | 2903 | q.applieddirty = True |
|
2902 | 2904 | q.savedirty() |
|
2903 | 2905 | return 0 |
|
2904 | 2906 | |
|
2905 | 2907 | @command("strip", |
|
2906 | 2908 | [ |
|
2907 | 2909 | ('r', 'rev', [], _('strip specified revision (optional, ' |
|
2908 | 2910 | 'can specify revisions without this ' |
|
2909 | 2911 | 'option)'), _('REV')), |
|
2910 | 2912 | ('f', 'force', None, _('force removal of changesets, discard ' |
|
2911 | 2913 | 'uncommitted changes (no backup)')), |
|
2912 | 2914 | ('b', 'backup', None, _('bundle only changesets with local revision' |
|
2913 | 2915 | ' number greater than REV which are not' |
|
2914 | 2916 | ' descendants of REV (DEPRECATED)')), |
|
2915 | 2917 | ('', 'no-backup', None, _('no backups')), |
|
2916 | 2918 | ('', 'nobackup', None, _('no backups (DEPRECATED)')), |
|
2917 | 2919 | ('n', '', None, _('ignored (DEPRECATED)')), |
|
2918 | 2920 | ('k', 'keep', None, _("do not modify working copy during strip")), |
|
2919 | 2921 | ('B', 'bookmark', '', _("remove revs only reachable from given" |
|
2920 | 2922 | " bookmark"))], |
|
2921 | 2923 | _('hg strip [-k] [-f] [-n] [-B bookmark] [-r] REV...')) |
|
2922 | 2924 | def strip(ui, repo, *revs, **opts): |
|
2923 | 2925 | """strip changesets and all their descendants from the repository |
|
2924 | 2926 | |
|
2925 | 2927 | The strip command removes the specified changesets and all their |
|
2926 | 2928 | descendants. If the working directory has uncommitted changes, the |
|
2927 | 2929 | operation is aborted unless the --force flag is supplied, in which |
|
2928 | 2930 | case changes will be discarded. |
|
2929 | 2931 | |
|
2930 | 2932 | If a parent of the working directory is stripped, then the working |
|
2931 | 2933 | directory will automatically be updated to the most recent |
|
2932 | 2934 | available ancestor of the stripped parent after the operation |
|
2933 | 2935 | completes. |
|
2934 | 2936 | |
|
2935 | 2937 | Any stripped changesets are stored in ``.hg/strip-backup`` as a |
|
2936 | 2938 | bundle (see :hg:`help bundle` and :hg:`help unbundle`). They can |
|
2937 | 2939 | be restored by running :hg:`unbundle .hg/strip-backup/BUNDLE`, |
|
2938 | 2940 | where BUNDLE is the bundle file created by the strip. Note that |
|
2939 | 2941 | the local revision numbers will in general be different after the |
|
2940 | 2942 | restore. |
|
2941 | 2943 | |
|
2942 | 2944 | Use the --no-backup option to discard the backup bundle once the |
|
2943 | 2945 | operation completes. |
|
2944 | 2946 | |
|
2945 | 2947 | Strip is not a history-rewriting operation and can be used on |
|
2946 | 2948 | changesets in the public phase. But if the stripped changesets have |
|
2947 | 2949 | been pushed to a remote repository you will likely pull them again. |
|
2948 | 2950 | |
|
2949 | 2951 | Return 0 on success. |
|
2950 | 2952 | """ |
|
2951 | 2953 | backup = 'all' |
|
2952 | 2954 | if opts.get('backup'): |
|
2953 | 2955 | backup = 'strip' |
|
2954 | 2956 | elif opts.get('no_backup') or opts.get('nobackup'): |
|
2955 | 2957 | backup = 'none' |
|
2956 | 2958 | |
|
2957 | 2959 | cl = repo.changelog |
|
2958 | 2960 | revs = list(revs) + opts.get('rev') |
|
2959 | 2961 | revs = set(scmutil.revrange(repo, revs)) |
|
2960 | 2962 | |
|
2961 | 2963 | if opts.get('bookmark'): |
|
2962 | 2964 | mark = opts.get('bookmark') |
|
2963 | 2965 | marks = repo._bookmarks |
|
2964 | 2966 | if mark not in marks: |
|
2965 | 2967 | raise util.Abort(_("bookmark '%s' not found") % mark) |
|
2966 | 2968 | |
|
2967 | 2969 | # If the requested bookmark is not the only one pointing to a |
|
2968 | 2970 | # a revision we have to only delete the bookmark and not strip |
|
2969 | 2971 | # anything. revsets cannot detect that case. |
|
2970 | 2972 | uniquebm = True |
|
2971 | 2973 | for m, n in marks.iteritems(): |
|
2972 | 2974 | if m != mark and n == repo[mark].node(): |
|
2973 | 2975 | uniquebm = False |
|
2974 | 2976 | break |
|
2975 | 2977 | if uniquebm: |
|
2976 | 2978 | rsrevs = repo.revs("ancestors(bookmark(%s)) - " |
|
2977 | 2979 | "ancestors(head() and not bookmark(%s)) - " |
|
2978 | 2980 | "ancestors(bookmark() and not bookmark(%s))", |
|
2979 | 2981 | mark, mark, mark) |
|
2980 | 2982 | revs.update(set(rsrevs)) |
|
2981 | 2983 | if not revs: |
|
2982 | 2984 | del marks[mark] |
|
2983 | 2985 | repo._writebookmarks(mark) |
|
2984 | 2986 | ui.write(_("bookmark '%s' deleted\n") % mark) |
|
2985 | 2987 | |
|
2986 | 2988 | if not revs: |
|
2987 | 2989 | raise util.Abort(_('empty revision set')) |
|
2988 | 2990 | |
|
2989 | 2991 | descendants = set(cl.descendants(revs)) |
|
2990 | 2992 | strippedrevs = revs.union(descendants) |
|
2991 | 2993 | roots = revs.difference(descendants) |
|
2992 | 2994 | |
|
2993 | 2995 | update = False |
|
2994 | 2996 | # if one of the wdir parent is stripped we'll need |
|
2995 | 2997 | # to update away to an earlier revision |
|
2996 | 2998 | for p in repo.dirstate.parents(): |
|
2997 | 2999 | if p != nullid and cl.rev(p) in strippedrevs: |
|
2998 | 3000 | update = True |
|
2999 | 3001 | break |
|
3000 | 3002 | |
|
3001 | 3003 | rootnodes = set(cl.node(r) for r in roots) |
|
3002 | 3004 | |
|
3003 | 3005 | q = repo.mq |
|
3004 | 3006 | if q.applied: |
|
3005 | 3007 | # refresh queue state if we're about to strip |
|
3006 | 3008 | # applied patches |
|
3007 | 3009 | if cl.rev(repo.lookup('qtip')) in strippedrevs: |
|
3008 | 3010 | q.applieddirty = True |
|
3009 | 3011 | start = 0 |
|
3010 | 3012 | end = len(q.applied) |
|
3011 | 3013 | for i, statusentry in enumerate(q.applied): |
|
3012 | 3014 | if statusentry.node in rootnodes: |
|
3013 | 3015 | # if one of the stripped roots is an applied |
|
3014 | 3016 | # patch, only part of the queue is stripped |
|
3015 | 3017 | start = i |
|
3016 | 3018 | break |
|
3017 | 3019 | del q.applied[start:end] |
|
3018 | 3020 | q.savedirty() |
|
3019 | 3021 | |
|
3020 | 3022 | revs = list(rootnodes) |
|
3021 | 3023 | if update and opts.get('keep'): |
|
3022 | 3024 | wlock = repo.wlock() |
|
3023 | 3025 | try: |
|
3024 | 3026 | urev = repo.mq.qparents(repo, revs[0]) |
|
3025 | 3027 | repo.dirstate.rebuild(urev, repo[urev].manifest()) |
|
3026 | 3028 | repo.dirstate.write() |
|
3027 | 3029 | update = False |
|
3028 | 3030 | finally: |
|
3029 | 3031 | wlock.release() |
|
3030 | 3032 | |
|
3031 | 3033 | if opts.get('bookmark'): |
|
3032 | 3034 | del marks[mark] |
|
3033 | 3035 | repo._writebookmarks(marks) |
|
3034 | 3036 | ui.write(_("bookmark '%s' deleted\n") % mark) |
|
3035 | 3037 | |
|
3036 | 3038 | repo.mq.strip(repo, revs, backup=backup, update=update, |
|
3037 | 3039 | force=opts.get('force')) |
|
3038 | 3040 | |
|
3039 | 3041 | return 0 |
|
3040 | 3042 | |
|
3041 | 3043 | @command("qselect", |
|
3042 | 3044 | [('n', 'none', None, _('disable all guards')), |
|
3043 | 3045 | ('s', 'series', None, _('list all guards in series file')), |
|
3044 | 3046 | ('', 'pop', None, _('pop to before first guarded applied patch')), |
|
3045 | 3047 | ('', 'reapply', None, _('pop, then reapply patches'))], |
|
3046 | 3048 | _('hg qselect [OPTION]... [GUARD]...')) |
|
3047 | 3049 | def select(ui, repo, *args, **opts): |
|
3048 | 3050 | '''set or print guarded patches to push |
|
3049 | 3051 | |
|
3050 | 3052 | Use the :hg:`qguard` command to set or print guards on patch, then use |
|
3051 | 3053 | qselect to tell mq which guards to use. A patch will be pushed if |
|
3052 | 3054 | it has no guards or any positive guards match the currently |
|
3053 | 3055 | selected guard, but will not be pushed if any negative guards |
|
3054 | 3056 | match the current guard. For example:: |
|
3055 | 3057 | |
|
3056 | 3058 | qguard foo.patch -- -stable (negative guard) |
|
3057 | 3059 | qguard bar.patch +stable (positive guard) |
|
3058 | 3060 | qselect stable |
|
3059 | 3061 | |
|
3060 | 3062 | This activates the "stable" guard. mq will skip foo.patch (because |
|
3061 | 3063 | it has a negative match) but push bar.patch (because it has a |
|
3062 | 3064 | positive match). |
|
3063 | 3065 | |
|
3064 | 3066 | With no arguments, prints the currently active guards. |
|
3065 | 3067 | With one argument, sets the active guard. |
|
3066 | 3068 | |
|
3067 | 3069 | Use -n/--none to deactivate guards (no other arguments needed). |
|
3068 | 3070 | When no guards are active, patches with positive guards are |
|
3069 | 3071 | skipped and patches with negative guards are pushed. |
|
3070 | 3072 | |
|
3071 | 3073 | qselect can change the guards on applied patches. It does not pop |
|
3072 | 3074 | guarded patches by default. Use --pop to pop back to the last |
|
3073 | 3075 | applied patch that is not guarded. Use --reapply (which implies |
|
3074 | 3076 | --pop) to push back to the current patch afterwards, but skip |
|
3075 | 3077 | guarded patches. |
|
3076 | 3078 | |
|
3077 | 3079 | Use -s/--series to print a list of all guards in the series file |
|
3078 | 3080 | (no other arguments needed). Use -v for more information. |
|
3079 | 3081 | |
|
3080 | 3082 | Returns 0 on success.''' |
|
3081 | 3083 | |
|
3082 | 3084 | q = repo.mq |
|
3083 | 3085 | guards = q.active() |
|
3084 | 3086 | if args or opts.get('none'): |
|
3085 | 3087 | old_unapplied = q.unapplied(repo) |
|
3086 | 3088 | old_guarded = [i for i in xrange(len(q.applied)) if |
|
3087 | 3089 | not q.pushable(i)[0]] |
|
3088 | 3090 | q.setactive(args) |
|
3089 | 3091 | q.savedirty() |
|
3090 | 3092 | if not args: |
|
3091 | 3093 | ui.status(_('guards deactivated\n')) |
|
3092 | 3094 | if not opts.get('pop') and not opts.get('reapply'): |
|
3093 | 3095 | unapplied = q.unapplied(repo) |
|
3094 | 3096 | guarded = [i for i in xrange(len(q.applied)) |
|
3095 | 3097 | if not q.pushable(i)[0]] |
|
3096 | 3098 | if len(unapplied) != len(old_unapplied): |
|
3097 | 3099 | ui.status(_('number of unguarded, unapplied patches has ' |
|
3098 | 3100 | 'changed from %d to %d\n') % |
|
3099 | 3101 | (len(old_unapplied), len(unapplied))) |
|
3100 | 3102 | if len(guarded) != len(old_guarded): |
|
3101 | 3103 | ui.status(_('number of guarded, applied patches has changed ' |
|
3102 | 3104 | 'from %d to %d\n') % |
|
3103 | 3105 | (len(old_guarded), len(guarded))) |
|
3104 | 3106 | elif opts.get('series'): |
|
3105 | 3107 | guards = {} |
|
3106 | 3108 | noguards = 0 |
|
3107 | 3109 | for gs in q.seriesguards: |
|
3108 | 3110 | if not gs: |
|
3109 | 3111 | noguards += 1 |
|
3110 | 3112 | for g in gs: |
|
3111 | 3113 | guards.setdefault(g, 0) |
|
3112 | 3114 | guards[g] += 1 |
|
3113 | 3115 | if ui.verbose: |
|
3114 | 3116 | guards['NONE'] = noguards |
|
3115 | 3117 | guards = guards.items() |
|
3116 | 3118 | guards.sort(key=lambda x: x[0][1:]) |
|
3117 | 3119 | if guards: |
|
3118 | 3120 | ui.note(_('guards in series file:\n')) |
|
3119 | 3121 | for guard, count in guards: |
|
3120 | 3122 | ui.note('%2d ' % count) |
|
3121 | 3123 | ui.write(guard, '\n') |
|
3122 | 3124 | else: |
|
3123 | 3125 | ui.note(_('no guards in series file\n')) |
|
3124 | 3126 | else: |
|
3125 | 3127 | if guards: |
|
3126 | 3128 | ui.note(_('active guards:\n')) |
|
3127 | 3129 | for g in guards: |
|
3128 | 3130 | ui.write(g, '\n') |
|
3129 | 3131 | else: |
|
3130 | 3132 | ui.write(_('no active guards\n')) |
|
3131 | 3133 | reapply = opts.get('reapply') and q.applied and q.appliedname(-1) |
|
3132 | 3134 | popped = False |
|
3133 | 3135 | if opts.get('pop') or opts.get('reapply'): |
|
3134 | 3136 | for i in xrange(len(q.applied)): |
|
3135 | 3137 | pushable, reason = q.pushable(i) |
|
3136 | 3138 | if not pushable: |
|
3137 | 3139 | ui.status(_('popping guarded patches\n')) |
|
3138 | 3140 | popped = True |
|
3139 | 3141 | if i == 0: |
|
3140 | 3142 | q.pop(repo, all=True) |
|
3141 | 3143 | else: |
|
3142 | 3144 | q.pop(repo, str(i - 1)) |
|
3143 | 3145 | break |
|
3144 | 3146 | if popped: |
|
3145 | 3147 | try: |
|
3146 | 3148 | if reapply: |
|
3147 | 3149 | ui.status(_('reapplying unguarded patches\n')) |
|
3148 | 3150 | q.push(repo, reapply) |
|
3149 | 3151 | finally: |
|
3150 | 3152 | q.savedirty() |
|
3151 | 3153 | |
|
3152 | 3154 | @command("qfinish", |
|
3153 | 3155 | [('a', 'applied', None, _('finish all applied changesets'))], |
|
3154 | 3156 | _('hg qfinish [-a] [REV]...')) |
|
3155 | 3157 | def finish(ui, repo, *revrange, **opts): |
|
3156 | 3158 | """move applied patches into repository history |
|
3157 | 3159 | |
|
3158 | 3160 | Finishes the specified revisions (corresponding to applied |
|
3159 | 3161 | patches) by moving them out of mq control into regular repository |
|
3160 | 3162 | history. |
|
3161 | 3163 | |
|
3162 | 3164 | Accepts a revision range or the -a/--applied option. If --applied |
|
3163 | 3165 | is specified, all applied mq revisions are removed from mq |
|
3164 | 3166 | control. Otherwise, the given revisions must be at the base of the |
|
3165 | 3167 | stack of applied patches. |
|
3166 | 3168 | |
|
3167 | 3169 | This can be especially useful if your changes have been applied to |
|
3168 | 3170 | an upstream repository, or if you are about to push your changes |
|
3169 | 3171 | to upstream. |
|
3170 | 3172 | |
|
3171 | 3173 | Returns 0 on success. |
|
3172 | 3174 | """ |
|
3173 | 3175 | if not opts.get('applied') and not revrange: |
|
3174 | 3176 | raise util.Abort(_('no revisions specified')) |
|
3175 | 3177 | elif opts.get('applied'): |
|
3176 | 3178 | revrange = ('qbase::qtip',) + revrange |
|
3177 | 3179 | |
|
3178 | 3180 | q = repo.mq |
|
3179 | 3181 | if not q.applied: |
|
3180 | 3182 | ui.status(_('no patches applied\n')) |
|
3181 | 3183 | return 0 |
|
3182 | 3184 | |
|
3183 | 3185 | revs = scmutil.revrange(repo, revrange) |
|
3184 | 3186 | if repo['.'].rev() in revs and repo[None].files(): |
|
3185 | 3187 | ui.warn(_('warning: uncommitted changes in the working directory\n')) |
|
3186 | 3188 | # queue.finish may changes phases but leave the responsability to lock the |
|
3187 | 3189 | # repo to the caller to avoid deadlock with wlock. This command code is |
|
3188 | 3190 | # responsability for this locking. |
|
3189 | 3191 | lock = repo.lock() |
|
3190 | 3192 | try: |
|
3191 | 3193 | q.finish(repo, revs) |
|
3192 | 3194 | q.savedirty() |
|
3193 | 3195 | finally: |
|
3194 | 3196 | lock.release() |
|
3195 | 3197 | return 0 |
|
3196 | 3198 | |
|
3197 | 3199 | @command("qqueue", |
|
3198 | 3200 | [('l', 'list', False, _('list all available queues')), |
|
3199 | 3201 | ('', 'active', False, _('print name of active queue')), |
|
3200 | 3202 | ('c', 'create', False, _('create new queue')), |
|
3201 | 3203 | ('', 'rename', False, _('rename active queue')), |
|
3202 | 3204 | ('', 'delete', False, _('delete reference to queue')), |
|
3203 | 3205 | ('', 'purge', False, _('delete queue, and remove patch dir')), |
|
3204 | 3206 | ], |
|
3205 | 3207 | _('[OPTION] [QUEUE]')) |
|
3206 | 3208 | def qqueue(ui, repo, name=None, **opts): |
|
3207 | 3209 | '''manage multiple patch queues |
|
3208 | 3210 | |
|
3209 | 3211 | Supports switching between different patch queues, as well as creating |
|
3210 | 3212 | new patch queues and deleting existing ones. |
|
3211 | 3213 | |
|
3212 | 3214 | Omitting a queue name or specifying -l/--list will show you the registered |
|
3213 | 3215 | queues - by default the "normal" patches queue is registered. The currently |
|
3214 | 3216 | active queue will be marked with "(active)". Specifying --active will print |
|
3215 | 3217 | only the name of the active queue. |
|
3216 | 3218 | |
|
3217 | 3219 | To create a new queue, use -c/--create. The queue is automatically made |
|
3218 | 3220 | active, except in the case where there are applied patches from the |
|
3219 | 3221 | currently active queue in the repository. Then the queue will only be |
|
3220 | 3222 | created and switching will fail. |
|
3221 | 3223 | |
|
3222 | 3224 | To delete an existing queue, use --delete. You cannot delete the currently |
|
3223 | 3225 | active queue. |
|
3224 | 3226 | |
|
3225 | 3227 | Returns 0 on success. |
|
3226 | 3228 | ''' |
|
3227 | 3229 | q = repo.mq |
|
3228 | 3230 | _defaultqueue = 'patches' |
|
3229 | 3231 | _allqueues = 'patches.queues' |
|
3230 | 3232 | _activequeue = 'patches.queue' |
|
3231 | 3233 | |
|
3232 | 3234 | def _getcurrent(): |
|
3233 | 3235 | cur = os.path.basename(q.path) |
|
3234 | 3236 | if cur.startswith('patches-'): |
|
3235 | 3237 | cur = cur[8:] |
|
3236 | 3238 | return cur |
|
3237 | 3239 | |
|
3238 | 3240 | def _noqueues(): |
|
3239 | 3241 | try: |
|
3240 | 3242 | fh = repo.opener(_allqueues, 'r') |
|
3241 | 3243 | fh.close() |
|
3242 | 3244 | except IOError: |
|
3243 | 3245 | return True |
|
3244 | 3246 | |
|
3245 | 3247 | return False |
|
3246 | 3248 | |
|
3247 | 3249 | def _getqueues(): |
|
3248 | 3250 | current = _getcurrent() |
|
3249 | 3251 | |
|
3250 | 3252 | try: |
|
3251 | 3253 | fh = repo.opener(_allqueues, 'r') |
|
3252 | 3254 | queues = [queue.strip() for queue in fh if queue.strip()] |
|
3253 | 3255 | fh.close() |
|
3254 | 3256 | if current not in queues: |
|
3255 | 3257 | queues.append(current) |
|
3256 | 3258 | except IOError: |
|
3257 | 3259 | queues = [_defaultqueue] |
|
3258 | 3260 | |
|
3259 | 3261 | return sorted(queues) |
|
3260 | 3262 | |
|
3261 | 3263 | def _setactive(name): |
|
3262 | 3264 | if q.applied: |
|
3263 | 3265 | raise util.Abort(_('patches applied - cannot set new queue active')) |
|
3264 | 3266 | _setactivenocheck(name) |
|
3265 | 3267 | |
|
3266 | 3268 | def _setactivenocheck(name): |
|
3267 | 3269 | fh = repo.opener(_activequeue, 'w') |
|
3268 | 3270 | if name != 'patches': |
|
3269 | 3271 | fh.write(name) |
|
3270 | 3272 | fh.close() |
|
3271 | 3273 | |
|
3272 | 3274 | def _addqueue(name): |
|
3273 | 3275 | fh = repo.opener(_allqueues, 'a') |
|
3274 | 3276 | fh.write('%s\n' % (name,)) |
|
3275 | 3277 | fh.close() |
|
3276 | 3278 | |
|
3277 | 3279 | def _queuedir(name): |
|
3278 | 3280 | if name == 'patches': |
|
3279 | 3281 | return repo.join('patches') |
|
3280 | 3282 | else: |
|
3281 | 3283 | return repo.join('patches-' + name) |
|
3282 | 3284 | |
|
3283 | 3285 | def _validname(name): |
|
3284 | 3286 | for n in name: |
|
3285 | 3287 | if n in ':\\/.': |
|
3286 | 3288 | return False |
|
3287 | 3289 | return True |
|
3288 | 3290 | |
|
3289 | 3291 | def _delete(name): |
|
3290 | 3292 | if name not in existing: |
|
3291 | 3293 | raise util.Abort(_('cannot delete queue that does not exist')) |
|
3292 | 3294 | |
|
3293 | 3295 | current = _getcurrent() |
|
3294 | 3296 | |
|
3295 | 3297 | if name == current: |
|
3296 | 3298 | raise util.Abort(_('cannot delete currently active queue')) |
|
3297 | 3299 | |
|
3298 | 3300 | fh = repo.opener('patches.queues.new', 'w') |
|
3299 | 3301 | for queue in existing: |
|
3300 | 3302 | if queue == name: |
|
3301 | 3303 | continue |
|
3302 | 3304 | fh.write('%s\n' % (queue,)) |
|
3303 | 3305 | fh.close() |
|
3304 | 3306 | util.rename(repo.join('patches.queues.new'), repo.join(_allqueues)) |
|
3305 | 3307 | |
|
3306 | 3308 | if not name or opts.get('list') or opts.get('active'): |
|
3307 | 3309 | current = _getcurrent() |
|
3308 | 3310 | if opts.get('active'): |
|
3309 | 3311 | ui.write('%s\n' % (current,)) |
|
3310 | 3312 | return |
|
3311 | 3313 | for queue in _getqueues(): |
|
3312 | 3314 | ui.write('%s' % (queue,)) |
|
3313 | 3315 | if queue == current and not ui.quiet: |
|
3314 | 3316 | ui.write(_(' (active)\n')) |
|
3315 | 3317 | else: |
|
3316 | 3318 | ui.write('\n') |
|
3317 | 3319 | return |
|
3318 | 3320 | |
|
3319 | 3321 | if not _validname(name): |
|
3320 | 3322 | raise util.Abort( |
|
3321 | 3323 | _('invalid queue name, may not contain the characters ":\\/."')) |
|
3322 | 3324 | |
|
3323 | 3325 | existing = _getqueues() |
|
3324 | 3326 | |
|
3325 | 3327 | if opts.get('create'): |
|
3326 | 3328 | if name in existing: |
|
3327 | 3329 | raise util.Abort(_('queue "%s" already exists') % name) |
|
3328 | 3330 | if _noqueues(): |
|
3329 | 3331 | _addqueue(_defaultqueue) |
|
3330 | 3332 | _addqueue(name) |
|
3331 | 3333 | _setactive(name) |
|
3332 | 3334 | elif opts.get('rename'): |
|
3333 | 3335 | current = _getcurrent() |
|
3334 | 3336 | if name == current: |
|
3335 | 3337 | raise util.Abort(_('can\'t rename "%s" to its current name') % name) |
|
3336 | 3338 | if name in existing: |
|
3337 | 3339 | raise util.Abort(_('queue "%s" already exists') % name) |
|
3338 | 3340 | |
|
3339 | 3341 | olddir = _queuedir(current) |
|
3340 | 3342 | newdir = _queuedir(name) |
|
3341 | 3343 | |
|
3342 | 3344 | if os.path.exists(newdir): |
|
3343 | 3345 | raise util.Abort(_('non-queue directory "%s" already exists') % |
|
3344 | 3346 | newdir) |
|
3345 | 3347 | |
|
3346 | 3348 | fh = repo.opener('patches.queues.new', 'w') |
|
3347 | 3349 | for queue in existing: |
|
3348 | 3350 | if queue == current: |
|
3349 | 3351 | fh.write('%s\n' % (name,)) |
|
3350 | 3352 | if os.path.exists(olddir): |
|
3351 | 3353 | util.rename(olddir, newdir) |
|
3352 | 3354 | else: |
|
3353 | 3355 | fh.write('%s\n' % (queue,)) |
|
3354 | 3356 | fh.close() |
|
3355 | 3357 | util.rename(repo.join('patches.queues.new'), repo.join(_allqueues)) |
|
3356 | 3358 | _setactivenocheck(name) |
|
3357 | 3359 | elif opts.get('delete'): |
|
3358 | 3360 | _delete(name) |
|
3359 | 3361 | elif opts.get('purge'): |
|
3360 | 3362 | if name in existing: |
|
3361 | 3363 | _delete(name) |
|
3362 | 3364 | qdir = _queuedir(name) |
|
3363 | 3365 | if os.path.exists(qdir): |
|
3364 | 3366 | shutil.rmtree(qdir) |
|
3365 | 3367 | else: |
|
3366 | 3368 | if name not in existing: |
|
3367 | 3369 | raise util.Abort(_('use --create to create a new queue')) |
|
3368 | 3370 | _setactive(name) |
|
3369 | 3371 | |
|
3370 | 3372 | def mqphasedefaults(repo, roots): |
|
3371 | 3373 | """callback used to set mq changeset as secret when no phase data exists""" |
|
3372 | 3374 | if repo.mq.applied: |
|
3373 | 3375 | if repo.ui.configbool('mq', 'secret', False): |
|
3374 | 3376 | mqphase = phases.secret |
|
3375 | 3377 | else: |
|
3376 | 3378 | mqphase = phases.draft |
|
3377 | 3379 | qbase = repo[repo.mq.applied[0].node] |
|
3378 | 3380 | roots[mqphase].add(qbase.node()) |
|
3379 | 3381 | return roots |
|
3380 | 3382 | |
|
3381 | 3383 | def reposetup(ui, repo): |
|
3382 | 3384 | class mqrepo(repo.__class__): |
|
3383 | 3385 | @util.propertycache |
|
3384 | 3386 | def mq(self): |
|
3385 | 3387 | return queue(self.ui, self.path) |
|
3386 | 3388 | |
|
3387 | 3389 | def abortifwdirpatched(self, errmsg, force=False): |
|
3388 | 3390 | if self.mq.applied and not force: |
|
3389 | 3391 | parents = self.dirstate.parents() |
|
3390 | 3392 | patches = [s.node for s in self.mq.applied] |
|
3391 | 3393 | if parents[0] in patches or parents[1] in patches: |
|
3392 | 3394 | raise util.Abort(errmsg) |
|
3393 | 3395 | |
|
3394 | 3396 | def commit(self, text="", user=None, date=None, match=None, |
|
3395 | 3397 | force=False, editor=False, extra={}): |
|
3396 | 3398 | self.abortifwdirpatched( |
|
3397 | 3399 | _('cannot commit over an applied mq patch'), |
|
3398 | 3400 | force) |
|
3399 | 3401 | |
|
3400 | 3402 | return super(mqrepo, self).commit(text, user, date, match, force, |
|
3401 | 3403 | editor, extra) |
|
3402 | 3404 | |
|
3403 | 3405 | def checkpush(self, force, revs): |
|
3404 | 3406 | if self.mq.applied and not force: |
|
3405 | 3407 | outapplied = [e.node for e in self.mq.applied] |
|
3406 | 3408 | if revs: |
|
3407 | 3409 | # Assume applied patches have no non-patch descendants and |
|
3408 | 3410 | # are not on remote already. Filtering any changeset not |
|
3409 | 3411 | # pushed. |
|
3410 | 3412 | heads = set(revs) |
|
3411 | 3413 | for node in reversed(outapplied): |
|
3412 | 3414 | if node in heads: |
|
3413 | 3415 | break |
|
3414 | 3416 | else: |
|
3415 | 3417 | outapplied.pop() |
|
3416 | 3418 | # looking for pushed and shared changeset |
|
3417 | 3419 | for node in outapplied: |
|
3418 | 3420 | if repo[node].phase() < phases.secret: |
|
3419 | 3421 | raise util.Abort(_('source has mq patches applied')) |
|
3420 | 3422 | # no non-secret patches pushed |
|
3421 | 3423 | super(mqrepo, self).checkpush(force, revs) |
|
3422 | 3424 | |
|
3423 | 3425 | def _findtags(self): |
|
3424 | 3426 | '''augment tags from base class with patch tags''' |
|
3425 | 3427 | result = super(mqrepo, self)._findtags() |
|
3426 | 3428 | |
|
3427 | 3429 | q = self.mq |
|
3428 | 3430 | if not q.applied: |
|
3429 | 3431 | return result |
|
3430 | 3432 | |
|
3431 | 3433 | mqtags = [(patch.node, patch.name) for patch in q.applied] |
|
3432 | 3434 | |
|
3433 | 3435 | try: |
|
3434 | 3436 | self.changelog.rev(mqtags[-1][0]) |
|
3435 | 3437 | except error.LookupError: |
|
3436 | 3438 | self.ui.warn(_('mq status file refers to unknown node %s\n') |
|
3437 | 3439 | % short(mqtags[-1][0])) |
|
3438 | 3440 | return result |
|
3439 | 3441 | |
|
3440 | 3442 | mqtags.append((mqtags[-1][0], 'qtip')) |
|
3441 | 3443 | mqtags.append((mqtags[0][0], 'qbase')) |
|
3442 | 3444 | mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) |
|
3443 | 3445 | tags = result[0] |
|
3444 | 3446 | for patch in mqtags: |
|
3445 | 3447 | if patch[1] in tags: |
|
3446 | 3448 | self.ui.warn(_('tag %s overrides mq patch of the same ' |
|
3447 | 3449 | 'name\n') % patch[1]) |
|
3448 | 3450 | else: |
|
3449 | 3451 | tags[patch[1]] = patch[0] |
|
3450 | 3452 | |
|
3451 | 3453 | return result |
|
3452 | 3454 | |
|
3453 | 3455 | def _branchtags(self, partial, lrev): |
|
3454 | 3456 | q = self.mq |
|
3455 | 3457 | cl = self.changelog |
|
3456 | 3458 | qbase = None |
|
3457 | 3459 | if not q.applied: |
|
3458 | 3460 | if getattr(self, '_committingpatch', False): |
|
3459 | 3461 | # Committing a new patch, must be tip |
|
3460 | 3462 | qbase = len(cl) - 1 |
|
3461 | 3463 | else: |
|
3462 | 3464 | qbasenode = q.applied[0].node |
|
3463 | 3465 | try: |
|
3464 | 3466 | qbase = cl.rev(qbasenode) |
|
3465 | 3467 | except error.LookupError: |
|
3466 | 3468 | self.ui.warn(_('mq status file refers to unknown node %s\n') |
|
3467 | 3469 | % short(qbasenode)) |
|
3468 | 3470 | if qbase is None: |
|
3469 | 3471 | return super(mqrepo, self)._branchtags(partial, lrev) |
|
3470 | 3472 | |
|
3471 | 3473 | start = lrev + 1 |
|
3472 | 3474 | if start < qbase: |
|
3473 | 3475 | # update the cache (excluding the patches) and save it |
|
3474 | 3476 | ctxgen = (self[r] for r in xrange(lrev + 1, qbase)) |
|
3475 | 3477 | self._updatebranchcache(partial, ctxgen) |
|
3476 | 3478 | self._writebranchcache(partial, cl.node(qbase - 1), qbase - 1) |
|
3477 | 3479 | start = qbase |
|
3478 | 3480 | # if start = qbase, the cache is as updated as it should be. |
|
3479 | 3481 | # if start > qbase, the cache includes (part of) the patches. |
|
3480 | 3482 | # we might as well use it, but we won't save it. |
|
3481 | 3483 | |
|
3482 | 3484 | # update the cache up to the tip |
|
3483 | 3485 | ctxgen = (self[r] for r in xrange(start, len(cl))) |
|
3484 | 3486 | self._updatebranchcache(partial, ctxgen) |
|
3485 | 3487 | |
|
3486 | 3488 | return partial |
|
3487 | 3489 | |
|
3488 | 3490 | if repo.local(): |
|
3489 | 3491 | repo.__class__ = mqrepo |
|
3490 | 3492 | |
|
3491 | 3493 | repo._phasedefaults.append(mqphasedefaults) |
|
3492 | 3494 | |
|
3493 | 3495 | def mqimport(orig, ui, repo, *args, **kwargs): |
|
3494 | 3496 | if (util.safehasattr(repo, 'abortifwdirpatched') |
|
3495 | 3497 | and not kwargs.get('no_commit', False)): |
|
3496 | 3498 | repo.abortifwdirpatched(_('cannot import over an applied patch'), |
|
3497 | 3499 | kwargs.get('force')) |
|
3498 | 3500 | return orig(ui, repo, *args, **kwargs) |
|
3499 | 3501 | |
|
3500 | 3502 | def mqinit(orig, ui, *args, **kwargs): |
|
3501 | 3503 | mq = kwargs.pop('mq', None) |
|
3502 | 3504 | |
|
3503 | 3505 | if not mq: |
|
3504 | 3506 | return orig(ui, *args, **kwargs) |
|
3505 | 3507 | |
|
3506 | 3508 | if args: |
|
3507 | 3509 | repopath = args[0] |
|
3508 | 3510 | if not hg.islocal(repopath): |
|
3509 | 3511 | raise util.Abort(_('only a local queue repository ' |
|
3510 | 3512 | 'may be initialized')) |
|
3511 | 3513 | else: |
|
3512 | 3514 | repopath = cmdutil.findrepo(os.getcwd()) |
|
3513 | 3515 | if not repopath: |
|
3514 | 3516 | raise util.Abort(_('there is no Mercurial repository here ' |
|
3515 | 3517 | '(.hg not found)')) |
|
3516 | 3518 | repo = hg.repository(ui, repopath) |
|
3517 | 3519 | return qinit(ui, repo, True) |
|
3518 | 3520 | |
|
3519 | 3521 | def mqcommand(orig, ui, repo, *args, **kwargs): |
|
3520 | 3522 | """Add --mq option to operate on patch repository instead of main""" |
|
3521 | 3523 | |
|
3522 | 3524 | # some commands do not like getting unknown options |
|
3523 | 3525 | mq = kwargs.pop('mq', None) |
|
3524 | 3526 | |
|
3525 | 3527 | if not mq: |
|
3526 | 3528 | return orig(ui, repo, *args, **kwargs) |
|
3527 | 3529 | |
|
3528 | 3530 | q = repo.mq |
|
3529 | 3531 | r = q.qrepo() |
|
3530 | 3532 | if not r: |
|
3531 | 3533 | raise util.Abort(_('no queue repository')) |
|
3532 | 3534 | return orig(r.ui, r, *args, **kwargs) |
|
3533 | 3535 | |
|
3534 | 3536 | def summary(orig, ui, repo, *args, **kwargs): |
|
3535 | 3537 | r = orig(ui, repo, *args, **kwargs) |
|
3536 | 3538 | q = repo.mq |
|
3537 | 3539 | m = [] |
|
3538 | 3540 | a, u = len(q.applied), len(q.unapplied(repo)) |
|
3539 | 3541 | if a: |
|
3540 | 3542 | m.append(ui.label(_("%d applied"), 'qseries.applied') % a) |
|
3541 | 3543 | if u: |
|
3542 | 3544 | m.append(ui.label(_("%d unapplied"), 'qseries.unapplied') % u) |
|
3543 | 3545 | if m: |
|
3544 | 3546 | ui.write("mq: %s\n" % ', '.join(m)) |
|
3545 | 3547 | else: |
|
3546 | 3548 | ui.note(_("mq: (empty queue)\n")) |
|
3547 | 3549 | return r |
|
3548 | 3550 | |
|
3549 | 3551 | def revsetmq(repo, subset, x): |
|
3550 | 3552 | """``mq()`` |
|
3551 | 3553 | Changesets managed by MQ. |
|
3552 | 3554 | """ |
|
3553 | 3555 | revset.getargs(x, 0, 0, _("mq takes no arguments")) |
|
3554 | 3556 | applied = set([repo[r.node].rev() for r in repo.mq.applied]) |
|
3555 | 3557 | return [r for r in subset if r in applied] |
|
3556 | 3558 | |
|
3557 | 3559 | # tell hggettext to extract docstrings from these functions: |
|
3558 | 3560 | i18nfunctions = [revsetmq] |
|
3559 | 3561 | |
|
3560 | 3562 | def extsetup(ui): |
|
3561 | 3563 | # Ensure mq wrappers are called first, regardless of extension load order by |
|
3562 | 3564 | # NOT wrapping in uisetup() and instead deferring to init stage two here. |
|
3563 | 3565 | mqopt = [('', 'mq', None, _("operate on patch repository"))] |
|
3564 | 3566 | |
|
3565 | 3567 | extensions.wrapcommand(commands.table, 'import', mqimport) |
|
3566 | 3568 | extensions.wrapcommand(commands.table, 'summary', summary) |
|
3567 | 3569 | |
|
3568 | 3570 | entry = extensions.wrapcommand(commands.table, 'init', mqinit) |
|
3569 | 3571 | entry[1].extend(mqopt) |
|
3570 | 3572 | |
|
3571 | 3573 | nowrap = set(commands.norepo.split(" ")) |
|
3572 | 3574 | |
|
3573 | 3575 | def dotable(cmdtable): |
|
3574 | 3576 | for cmd in cmdtable.keys(): |
|
3575 | 3577 | cmd = cmdutil.parsealiases(cmd)[0] |
|
3576 | 3578 | if cmd in nowrap: |
|
3577 | 3579 | continue |
|
3578 | 3580 | entry = extensions.wrapcommand(cmdtable, cmd, mqcommand) |
|
3579 | 3581 | entry[1].extend(mqopt) |
|
3580 | 3582 | |
|
3581 | 3583 | dotable(commands.table) |
|
3582 | 3584 | |
|
3583 | 3585 | for extname, extmodule in extensions.extensions(): |
|
3584 | 3586 | if extmodule.__file__ != __file__: |
|
3585 | 3587 | dotable(getattr(extmodule, 'cmdtable', {})) |
|
3586 | 3588 | |
|
3587 | 3589 | revset.symbols['mq'] = revsetmq |
|
3588 | 3590 | |
|
3589 | 3591 | colortable = {'qguard.negative': 'red', |
|
3590 | 3592 | 'qguard.positive': 'yellow', |
|
3591 | 3593 | 'qguard.unguarded': 'green', |
|
3592 | 3594 | 'qseries.applied': 'blue bold underline', |
|
3593 | 3595 | 'qseries.guarded': 'black bold', |
|
3594 | 3596 | 'qseries.missing': 'red bold', |
|
3595 | 3597 | 'qseries.unapplied': 'black bold'} |
@@ -1,186 +1,184 | |||
|
1 | 1 | # Mercurial extension to provide 'hg relink' command |
|
2 | 2 | # |
|
3 | 3 | # Copyright (C) 2007 Brendan Cully <brendan@kublai.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | """recreates hardlinks between repository clones""" |
|
9 | 9 | |
|
10 | 10 | from mercurial import hg, util |
|
11 | 11 | from mercurial.i18n import _ |
|
12 | 12 | import os, stat |
|
13 | 13 | |
|
14 | 14 | testedwith = 'internal' |
|
15 | 15 | |
|
16 | 16 | def relink(ui, repo, origin=None, **opts): |
|
17 | 17 | """recreate hardlinks between two repositories |
|
18 | 18 | |
|
19 | 19 | When repositories are cloned locally, their data files will be |
|
20 | 20 | hardlinked so that they only use the space of a single repository. |
|
21 | 21 | |
|
22 | 22 | Unfortunately, subsequent pulls into either repository will break |
|
23 | 23 | hardlinks for any files touched by the new changesets, even if |
|
24 | 24 | both repositories end up pulling the same changes. |
|
25 | 25 | |
|
26 | 26 | Similarly, passing --rev to "hg clone" will fail to use any |
|
27 | 27 | hardlinks, falling back to a complete copy of the source |
|
28 | 28 | repository. |
|
29 | 29 | |
|
30 | 30 | This command lets you recreate those hardlinks and reclaim that |
|
31 | 31 | wasted space. |
|
32 | 32 | |
|
33 | 33 | This repository will be relinked to share space with ORIGIN, which |
|
34 | 34 | must be on the same local disk. If ORIGIN is omitted, looks for |
|
35 | 35 | "default-relink", then "default", in [paths]. |
|
36 | 36 | |
|
37 | 37 | Do not attempt any read operations on this repository while the |
|
38 | 38 | command is running. (Both repositories will be locked against |
|
39 | 39 | writes.) |
|
40 | 40 | """ |
|
41 | 41 | if (not util.safehasattr(util, 'samefile') or |
|
42 | 42 | not util.safehasattr(util, 'samedevice')): |
|
43 | 43 | raise util.Abort(_('hardlinks are not supported on this system')) |
|
44 | 44 | src = hg.repository(ui, ui.expandpath(origin or 'default-relink', |
|
45 | 45 | origin or 'default')) |
|
46 | if not src.local(): | |
|
47 | raise util.Abort(_('must specify local origin repository')) | |
|
48 | 46 | ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path)) |
|
49 | 47 | if repo.root == src.root: |
|
50 | 48 | ui.status(_('there is nothing to relink\n')) |
|
51 | 49 | return |
|
52 | 50 | |
|
53 | 51 | locallock = repo.lock() |
|
54 | 52 | try: |
|
55 | 53 | remotelock = src.lock() |
|
56 | 54 | try: |
|
57 | 55 | candidates = sorted(collect(src, ui)) |
|
58 | 56 | targets = prune(candidates, src.store.path, repo.store.path, ui) |
|
59 | 57 | do_relink(src.store.path, repo.store.path, targets, ui) |
|
60 | 58 | finally: |
|
61 | 59 | remotelock.release() |
|
62 | 60 | finally: |
|
63 | 61 | locallock.release() |
|
64 | 62 | |
|
65 | 63 | def collect(src, ui): |
|
66 | 64 | seplen = len(os.path.sep) |
|
67 | 65 | candidates = [] |
|
68 | 66 | live = len(src['tip'].manifest()) |
|
69 | 67 | # Your average repository has some files which were deleted before |
|
70 | 68 | # the tip revision. We account for that by assuming that there are |
|
71 | 69 | # 3 tracked files for every 2 live files as of the tip version of |
|
72 | 70 | # the repository. |
|
73 | 71 | # |
|
74 | 72 | # mozilla-central as of 2010-06-10 had a ratio of just over 7:5. |
|
75 | 73 | total = live * 3 // 2 |
|
76 | 74 | src = src.store.path |
|
77 | 75 | pos = 0 |
|
78 | 76 | ui.status(_("tip has %d files, estimated total number of files: %s\n") |
|
79 | 77 | % (live, total)) |
|
80 | 78 | for dirpath, dirnames, filenames in os.walk(src): |
|
81 | 79 | dirnames.sort() |
|
82 | 80 | relpath = dirpath[len(src) + seplen:] |
|
83 | 81 | for filename in sorted(filenames): |
|
84 | 82 | if filename[-2:] not in ('.d', '.i'): |
|
85 | 83 | continue |
|
86 | 84 | st = os.stat(os.path.join(dirpath, filename)) |
|
87 | 85 | if not stat.S_ISREG(st.st_mode): |
|
88 | 86 | continue |
|
89 | 87 | pos += 1 |
|
90 | 88 | candidates.append((os.path.join(relpath, filename), st)) |
|
91 | 89 | ui.progress(_('collecting'), pos, filename, _('files'), total) |
|
92 | 90 | |
|
93 | 91 | ui.progress(_('collecting'), None) |
|
94 | 92 | ui.status(_('collected %d candidate storage files\n') % len(candidates)) |
|
95 | 93 | return candidates |
|
96 | 94 | |
|
97 | 95 | def prune(candidates, src, dst, ui): |
|
98 | 96 | def linkfilter(src, dst, st): |
|
99 | 97 | try: |
|
100 | 98 | ts = os.stat(dst) |
|
101 | 99 | except OSError: |
|
102 | 100 | # Destination doesn't have this file? |
|
103 | 101 | return False |
|
104 | 102 | if util.samefile(src, dst): |
|
105 | 103 | return False |
|
106 | 104 | if not util.samedevice(src, dst): |
|
107 | 105 | # No point in continuing |
|
108 | 106 | raise util.Abort( |
|
109 | 107 | _('source and destination are on different devices')) |
|
110 | 108 | if st.st_size != ts.st_size: |
|
111 | 109 | return False |
|
112 | 110 | return st |
|
113 | 111 | |
|
114 | 112 | targets = [] |
|
115 | 113 | total = len(candidates) |
|
116 | 114 | pos = 0 |
|
117 | 115 | for fn, st in candidates: |
|
118 | 116 | pos += 1 |
|
119 | 117 | srcpath = os.path.join(src, fn) |
|
120 | 118 | tgt = os.path.join(dst, fn) |
|
121 | 119 | ts = linkfilter(srcpath, tgt, st) |
|
122 | 120 | if not ts: |
|
123 | 121 | ui.debug('not linkable: %s\n' % fn) |
|
124 | 122 | continue |
|
125 | 123 | targets.append((fn, ts.st_size)) |
|
126 | 124 | ui.progress(_('pruning'), pos, fn, _('files'), total) |
|
127 | 125 | |
|
128 | 126 | ui.progress(_('pruning'), None) |
|
129 | 127 | ui.status(_('pruned down to %d probably relinkable files\n') % len(targets)) |
|
130 | 128 | return targets |
|
131 | 129 | |
|
132 | 130 | def do_relink(src, dst, files, ui): |
|
133 | 131 | def relinkfile(src, dst): |
|
134 | 132 | bak = dst + '.bak' |
|
135 | 133 | os.rename(dst, bak) |
|
136 | 134 | try: |
|
137 | 135 | util.oslink(src, dst) |
|
138 | 136 | except OSError: |
|
139 | 137 | os.rename(bak, dst) |
|
140 | 138 | raise |
|
141 | 139 | os.remove(bak) |
|
142 | 140 | |
|
143 | 141 | CHUNKLEN = 65536 |
|
144 | 142 | relinked = 0 |
|
145 | 143 | savedbytes = 0 |
|
146 | 144 | |
|
147 | 145 | pos = 0 |
|
148 | 146 | total = len(files) |
|
149 | 147 | for f, sz in files: |
|
150 | 148 | pos += 1 |
|
151 | 149 | source = os.path.join(src, f) |
|
152 | 150 | tgt = os.path.join(dst, f) |
|
153 | 151 | # Binary mode, so that read() works correctly, especially on Windows |
|
154 | 152 | sfp = file(source, 'rb') |
|
155 | 153 | dfp = file(tgt, 'rb') |
|
156 | 154 | sin = sfp.read(CHUNKLEN) |
|
157 | 155 | while sin: |
|
158 | 156 | din = dfp.read(CHUNKLEN) |
|
159 | 157 | if sin != din: |
|
160 | 158 | break |
|
161 | 159 | sin = sfp.read(CHUNKLEN) |
|
162 | 160 | sfp.close() |
|
163 | 161 | dfp.close() |
|
164 | 162 | if sin: |
|
165 | 163 | ui.debug('not linkable: %s\n' % f) |
|
166 | 164 | continue |
|
167 | 165 | try: |
|
168 | 166 | relinkfile(source, tgt) |
|
169 | 167 | ui.progress(_('relinking'), pos, f, _('files'), total) |
|
170 | 168 | relinked += 1 |
|
171 | 169 | savedbytes += sz |
|
172 | 170 | except OSError, inst: |
|
173 | 171 | ui.warn('%s: %s\n' % (tgt, str(inst))) |
|
174 | 172 | |
|
175 | 173 | ui.progress(_('relinking'), None) |
|
176 | 174 | |
|
177 | 175 | ui.status(_('relinked %d files (%s reclaimed)\n') % |
|
178 | 176 | (relinked, util.bytecount(savedbytes))) |
|
179 | 177 | |
|
180 | 178 | cmdtable = { |
|
181 | 179 | 'relink': ( |
|
182 | 180 | relink, |
|
183 | 181 | [], |
|
184 | 182 | _('[ORIGIN]') |
|
185 | 183 | ) |
|
186 | 184 | } |
@@ -1,685 +1,685 | |||
|
1 | 1 | # Patch transplanting extension for Mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006, 2007 Brendan Cully <brendan@kublai.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | '''command to transplant changesets from another branch |
|
9 | 9 | |
|
10 | 10 | This extension allows you to transplant patches from another branch. |
|
11 | 11 | |
|
12 | 12 | Transplanted patches are recorded in .hg/transplant/transplants, as a |
|
13 | 13 | map from a changeset hash to its hash in the source repository. |
|
14 | 14 | ''' |
|
15 | 15 | |
|
16 | 16 | from mercurial.i18n import _ |
|
17 | 17 | import os, tempfile |
|
18 | 18 | from mercurial.node import short |
|
19 | 19 | from mercurial import bundlerepo, hg, merge, match |
|
20 | 20 | from mercurial import patch, revlog, scmutil, util, error, cmdutil |
|
21 | 21 | from mercurial import revset, templatekw |
|
22 | 22 | |
|
23 | 23 | class TransplantError(error.Abort): |
|
24 | 24 | pass |
|
25 | 25 | |
|
26 | 26 | cmdtable = {} |
|
27 | 27 | command = cmdutil.command(cmdtable) |
|
28 | 28 | testedwith = 'internal' |
|
29 | 29 | |
|
30 | 30 | class transplantentry(object): |
|
31 | 31 | def __init__(self, lnode, rnode): |
|
32 | 32 | self.lnode = lnode |
|
33 | 33 | self.rnode = rnode |
|
34 | 34 | |
|
35 | 35 | class transplants(object): |
|
36 | 36 | def __init__(self, path=None, transplantfile=None, opener=None): |
|
37 | 37 | self.path = path |
|
38 | 38 | self.transplantfile = transplantfile |
|
39 | 39 | self.opener = opener |
|
40 | 40 | |
|
41 | 41 | if not opener: |
|
42 | 42 | self.opener = scmutil.opener(self.path) |
|
43 | 43 | self.transplants = {} |
|
44 | 44 | self.dirty = False |
|
45 | 45 | self.read() |
|
46 | 46 | |
|
47 | 47 | def read(self): |
|
48 | 48 | abspath = os.path.join(self.path, self.transplantfile) |
|
49 | 49 | if self.transplantfile and os.path.exists(abspath): |
|
50 | 50 | for line in self.opener.read(self.transplantfile).splitlines(): |
|
51 | 51 | lnode, rnode = map(revlog.bin, line.split(':')) |
|
52 | 52 | list = self.transplants.setdefault(rnode, []) |
|
53 | 53 | list.append(transplantentry(lnode, rnode)) |
|
54 | 54 | |
|
55 | 55 | def write(self): |
|
56 | 56 | if self.dirty and self.transplantfile: |
|
57 | 57 | if not os.path.isdir(self.path): |
|
58 | 58 | os.mkdir(self.path) |
|
59 | 59 | fp = self.opener(self.transplantfile, 'w') |
|
60 | 60 | for list in self.transplants.itervalues(): |
|
61 | 61 | for t in list: |
|
62 | 62 | l, r = map(revlog.hex, (t.lnode, t.rnode)) |
|
63 | 63 | fp.write(l + ':' + r + '\n') |
|
64 | 64 | fp.close() |
|
65 | 65 | self.dirty = False |
|
66 | 66 | |
|
67 | 67 | def get(self, rnode): |
|
68 | 68 | return self.transplants.get(rnode) or [] |
|
69 | 69 | |
|
70 | 70 | def set(self, lnode, rnode): |
|
71 | 71 | list = self.transplants.setdefault(rnode, []) |
|
72 | 72 | list.append(transplantentry(lnode, rnode)) |
|
73 | 73 | self.dirty = True |
|
74 | 74 | |
|
75 | 75 | def remove(self, transplant): |
|
76 | 76 | list = self.transplants.get(transplant.rnode) |
|
77 | 77 | if list: |
|
78 | 78 | del list[list.index(transplant)] |
|
79 | 79 | self.dirty = True |
|
80 | 80 | |
|
81 | 81 | class transplanter(object): |
|
82 | 82 | def __init__(self, ui, repo): |
|
83 | 83 | self.ui = ui |
|
84 | 84 | self.path = repo.join('transplant') |
|
85 | 85 | self.opener = scmutil.opener(self.path) |
|
86 | 86 | self.transplants = transplants(self.path, 'transplants', |
|
87 | 87 | opener=self.opener) |
|
88 | 88 | self.editor = None |
|
89 | 89 | |
|
90 | 90 | def applied(self, repo, node, parent): |
|
91 | 91 | '''returns True if a node is already an ancestor of parent |
|
92 | 92 | or is parent or has already been transplanted''' |
|
93 | 93 | if hasnode(repo, parent): |
|
94 | 94 | parentrev = repo.changelog.rev(parent) |
|
95 | 95 | if hasnode(repo, node): |
|
96 | 96 | rev = repo.changelog.rev(node) |
|
97 | 97 | reachable = repo.changelog.incancestors([parentrev], rev) |
|
98 | 98 | if rev in reachable: |
|
99 | 99 | return True |
|
100 | 100 | for t in self.transplants.get(node): |
|
101 | 101 | # it might have been stripped |
|
102 | 102 | if not hasnode(repo, t.lnode): |
|
103 | 103 | self.transplants.remove(t) |
|
104 | 104 | return False |
|
105 | 105 | lnoderev = repo.changelog.rev(t.lnode) |
|
106 | 106 | if lnoderev in repo.changelog.incancestors([parentrev], lnoderev): |
|
107 | 107 | return True |
|
108 | 108 | return False |
|
109 | 109 | |
|
110 | 110 | def apply(self, repo, source, revmap, merges, opts={}): |
|
111 | 111 | '''apply the revisions in revmap one by one in revision order''' |
|
112 | 112 | revs = sorted(revmap) |
|
113 | 113 | p1, p2 = repo.dirstate.parents() |
|
114 | 114 | pulls = [] |
|
115 | 115 | diffopts = patch.diffopts(self.ui, opts) |
|
116 | 116 | diffopts.git = True |
|
117 | 117 | |
|
118 | 118 | lock = wlock = tr = None |
|
119 | 119 | try: |
|
120 | 120 | wlock = repo.wlock() |
|
121 | 121 | lock = repo.lock() |
|
122 | 122 | tr = repo.transaction('transplant') |
|
123 | 123 | for rev in revs: |
|
124 | 124 | node = revmap[rev] |
|
125 | 125 | revstr = '%s:%s' % (rev, short(node)) |
|
126 | 126 | |
|
127 | 127 | if self.applied(repo, node, p1): |
|
128 | 128 | self.ui.warn(_('skipping already applied revision %s\n') % |
|
129 | 129 | revstr) |
|
130 | 130 | continue |
|
131 | 131 | |
|
132 | 132 | parents = source.changelog.parents(node) |
|
133 | 133 | if not (opts.get('filter') or opts.get('log')): |
|
134 | 134 | # If the changeset parent is the same as the |
|
135 | 135 | # wdir's parent, just pull it. |
|
136 | 136 | if parents[0] == p1: |
|
137 | 137 | pulls.append(node) |
|
138 | 138 | p1 = node |
|
139 | 139 | continue |
|
140 | 140 | if pulls: |
|
141 | 141 | if source != repo: |
|
142 | repo.pull(source, heads=pulls) | |
|
142 | repo.pull(source.peer(), heads=pulls) | |
|
143 | 143 | merge.update(repo, pulls[-1], False, False, None) |
|
144 | 144 | p1, p2 = repo.dirstate.parents() |
|
145 | 145 | pulls = [] |
|
146 | 146 | |
|
147 | 147 | domerge = False |
|
148 | 148 | if node in merges: |
|
149 | 149 | # pulling all the merge revs at once would mean we |
|
150 | 150 | # couldn't transplant after the latest even if |
|
151 | 151 | # transplants before them fail. |
|
152 | 152 | domerge = True |
|
153 | 153 | if not hasnode(repo, node): |
|
154 | 154 | repo.pull(source, heads=[node]) |
|
155 | 155 | |
|
156 | 156 | skipmerge = False |
|
157 | 157 | if parents[1] != revlog.nullid: |
|
158 | 158 | if not opts.get('parent'): |
|
159 | 159 | self.ui.note(_('skipping merge changeset %s:%s\n') |
|
160 | 160 | % (rev, short(node))) |
|
161 | 161 | skipmerge = True |
|
162 | 162 | else: |
|
163 | 163 | parent = source.lookup(opts['parent']) |
|
164 | 164 | if parent not in parents: |
|
165 | 165 | raise util.Abort(_('%s is not a parent of %s') % |
|
166 | 166 | (short(parent), short(node))) |
|
167 | 167 | else: |
|
168 | 168 | parent = parents[0] |
|
169 | 169 | |
|
170 | 170 | if skipmerge: |
|
171 | 171 | patchfile = None |
|
172 | 172 | else: |
|
173 | 173 | fd, patchfile = tempfile.mkstemp(prefix='hg-transplant-') |
|
174 | 174 | fp = os.fdopen(fd, 'w') |
|
175 | 175 | gen = patch.diff(source, parent, node, opts=diffopts) |
|
176 | 176 | for chunk in gen: |
|
177 | 177 | fp.write(chunk) |
|
178 | 178 | fp.close() |
|
179 | 179 | |
|
180 | 180 | del revmap[rev] |
|
181 | 181 | if patchfile or domerge: |
|
182 | 182 | try: |
|
183 | 183 | try: |
|
184 | 184 | n = self.applyone(repo, node, |
|
185 | 185 | source.changelog.read(node), |
|
186 | 186 | patchfile, merge=domerge, |
|
187 | 187 | log=opts.get('log'), |
|
188 | 188 | filter=opts.get('filter')) |
|
189 | 189 | except TransplantError: |
|
190 | 190 | # Do not rollback, it is up to the user to |
|
191 | 191 | # fix the merge or cancel everything |
|
192 | 192 | tr.close() |
|
193 | 193 | raise |
|
194 | 194 | if n and domerge: |
|
195 | 195 | self.ui.status(_('%s merged at %s\n') % (revstr, |
|
196 | 196 | short(n))) |
|
197 | 197 | elif n: |
|
198 | 198 | self.ui.status(_('%s transplanted to %s\n') |
|
199 | 199 | % (short(node), |
|
200 | 200 | short(n))) |
|
201 | 201 | finally: |
|
202 | 202 | if patchfile: |
|
203 | 203 | os.unlink(patchfile) |
|
204 | 204 | tr.close() |
|
205 | 205 | if pulls: |
|
206 | repo.pull(source, heads=pulls) | |
|
206 | repo.pull(source.peer(), heads=pulls) | |
|
207 | 207 | merge.update(repo, pulls[-1], False, False, None) |
|
208 | 208 | finally: |
|
209 | 209 | self.saveseries(revmap, merges) |
|
210 | 210 | self.transplants.write() |
|
211 | 211 | if tr: |
|
212 | 212 | tr.release() |
|
213 | 213 | lock.release() |
|
214 | 214 | wlock.release() |
|
215 | 215 | |
|
216 | 216 | def filter(self, filter, node, changelog, patchfile): |
|
217 | 217 | '''arbitrarily rewrite changeset before applying it''' |
|
218 | 218 | |
|
219 | 219 | self.ui.status(_('filtering %s\n') % patchfile) |
|
220 | 220 | user, date, msg = (changelog[1], changelog[2], changelog[4]) |
|
221 | 221 | fd, headerfile = tempfile.mkstemp(prefix='hg-transplant-') |
|
222 | 222 | fp = os.fdopen(fd, 'w') |
|
223 | 223 | fp.write("# HG changeset patch\n") |
|
224 | 224 | fp.write("# User %s\n" % user) |
|
225 | 225 | fp.write("# Date %d %d\n" % date) |
|
226 | 226 | fp.write(msg + '\n') |
|
227 | 227 | fp.close() |
|
228 | 228 | |
|
229 | 229 | try: |
|
230 | 230 | util.system('%s %s %s' % (filter, util.shellquote(headerfile), |
|
231 | 231 | util.shellquote(patchfile)), |
|
232 | 232 | environ={'HGUSER': changelog[1], |
|
233 | 233 | 'HGREVISION': revlog.hex(node), |
|
234 | 234 | }, |
|
235 | 235 | onerr=util.Abort, errprefix=_('filter failed'), |
|
236 | 236 | out=self.ui.fout) |
|
237 | 237 | user, date, msg = self.parselog(file(headerfile))[1:4] |
|
238 | 238 | finally: |
|
239 | 239 | os.unlink(headerfile) |
|
240 | 240 | |
|
241 | 241 | return (user, date, msg) |
|
242 | 242 | |
|
243 | 243 | def applyone(self, repo, node, cl, patchfile, merge=False, log=False, |
|
244 | 244 | filter=None): |
|
245 | 245 | '''apply the patch in patchfile to the repository as a transplant''' |
|
246 | 246 | (manifest, user, (time, timezone), files, message) = cl[:5] |
|
247 | 247 | date = "%d %d" % (time, timezone) |
|
248 | 248 | extra = {'transplant_source': node} |
|
249 | 249 | if filter: |
|
250 | 250 | (user, date, message) = self.filter(filter, node, cl, patchfile) |
|
251 | 251 | |
|
252 | 252 | if log: |
|
253 | 253 | # we don't translate messages inserted into commits |
|
254 | 254 | message += '\n(transplanted from %s)' % revlog.hex(node) |
|
255 | 255 | |
|
256 | 256 | self.ui.status(_('applying %s\n') % short(node)) |
|
257 | 257 | self.ui.note('%s %s\n%s\n' % (user, date, message)) |
|
258 | 258 | |
|
259 | 259 | if not patchfile and not merge: |
|
260 | 260 | raise util.Abort(_('can only omit patchfile if merging')) |
|
261 | 261 | if patchfile: |
|
262 | 262 | try: |
|
263 | 263 | files = set() |
|
264 | 264 | patch.patch(self.ui, repo, patchfile, files=files, eolmode=None) |
|
265 | 265 | files = list(files) |
|
266 | 266 | if not files: |
|
267 | 267 | self.ui.warn(_('%s: empty changeset') % revlog.hex(node)) |
|
268 | 268 | return None |
|
269 | 269 | except Exception, inst: |
|
270 | 270 | seriespath = os.path.join(self.path, 'series') |
|
271 | 271 | if os.path.exists(seriespath): |
|
272 | 272 | os.unlink(seriespath) |
|
273 | 273 | p1 = repo.dirstate.p1() |
|
274 | 274 | p2 = node |
|
275 | 275 | self.log(user, date, message, p1, p2, merge=merge) |
|
276 | 276 | self.ui.write(str(inst) + '\n') |
|
277 | 277 | raise TransplantError(_('fix up the merge and run ' |
|
278 | 278 | 'hg transplant --continue')) |
|
279 | 279 | else: |
|
280 | 280 | files = None |
|
281 | 281 | if merge: |
|
282 | 282 | p1, p2 = repo.dirstate.parents() |
|
283 | 283 | repo.setparents(p1, node) |
|
284 | 284 | m = match.always(repo.root, '') |
|
285 | 285 | else: |
|
286 | 286 | m = match.exact(repo.root, '', files) |
|
287 | 287 | |
|
288 | 288 | n = repo.commit(message, user, date, extra=extra, match=m, |
|
289 | 289 | editor=self.editor) |
|
290 | 290 | if not n: |
|
291 | 291 | # Crash here to prevent an unclear crash later, in |
|
292 | 292 | # transplants.write(). This can happen if patch.patch() |
|
293 | 293 | # does nothing but claims success or if repo.status() fails |
|
294 | 294 | # to report changes done by patch.patch(). These both |
|
295 | 295 | # appear to be bugs in other parts of Mercurial, but dying |
|
296 | 296 | # here, as soon as we can detect the problem, is preferable |
|
297 | 297 | # to silently dropping changesets on the floor. |
|
298 | 298 | raise RuntimeError('nothing committed after transplant') |
|
299 | 299 | if not merge: |
|
300 | 300 | self.transplants.set(n, node) |
|
301 | 301 | |
|
302 | 302 | return n |
|
303 | 303 | |
|
304 | 304 | def resume(self, repo, source, opts=None): |
|
305 | 305 | '''recover last transaction and apply remaining changesets''' |
|
306 | 306 | if os.path.exists(os.path.join(self.path, 'journal')): |
|
307 | 307 | n, node = self.recover(repo) |
|
308 | 308 | self.ui.status(_('%s transplanted as %s\n') % (short(node), |
|
309 | 309 | short(n))) |
|
310 | 310 | seriespath = os.path.join(self.path, 'series') |
|
311 | 311 | if not os.path.exists(seriespath): |
|
312 | 312 | self.transplants.write() |
|
313 | 313 | return |
|
314 | 314 | nodes, merges = self.readseries() |
|
315 | 315 | revmap = {} |
|
316 | 316 | for n in nodes: |
|
317 | 317 | revmap[source.changelog.rev(n)] = n |
|
318 | 318 | os.unlink(seriespath) |
|
319 | 319 | |
|
320 | 320 | self.apply(repo, source, revmap, merges, opts) |
|
321 | 321 | |
|
322 | 322 | def recover(self, repo): |
|
323 | 323 | '''commit working directory using journal metadata''' |
|
324 | 324 | node, user, date, message, parents = self.readlog() |
|
325 | 325 | merge = False |
|
326 | 326 | |
|
327 | 327 | if not user or not date or not message or not parents[0]: |
|
328 | 328 | raise util.Abort(_('transplant log file is corrupt')) |
|
329 | 329 | |
|
330 | 330 | parent = parents[0] |
|
331 | 331 | if len(parents) > 1: |
|
332 | 332 | if opts.get('parent'): |
|
333 | 333 | parent = source.lookup(opts['parent']) |
|
334 | 334 | if parent not in parents: |
|
335 | 335 | raise util.Abort(_('%s is not a parent of %s') % |
|
336 | 336 | (short(parent), short(node))) |
|
337 | 337 | else: |
|
338 | 338 | merge = True |
|
339 | 339 | |
|
340 | 340 | extra = {'transplant_source': node} |
|
341 | 341 | wlock = repo.wlock() |
|
342 | 342 | try: |
|
343 | 343 | p1, p2 = repo.dirstate.parents() |
|
344 | 344 | if p1 != parent: |
|
345 | 345 | raise util.Abort( |
|
346 | 346 | _('working dir not at transplant parent %s') % |
|
347 | 347 | revlog.hex(parent)) |
|
348 | 348 | if merge: |
|
349 | 349 | repo.setparents(p1, parents[1]) |
|
350 | 350 | n = repo.commit(message, user, date, extra=extra, |
|
351 | 351 | editor=self.editor) |
|
352 | 352 | if not n: |
|
353 | 353 | raise util.Abort(_('commit failed')) |
|
354 | 354 | if not merge: |
|
355 | 355 | self.transplants.set(n, node) |
|
356 | 356 | self.unlog() |
|
357 | 357 | |
|
358 | 358 | return n, node |
|
359 | 359 | finally: |
|
360 | 360 | wlock.release() |
|
361 | 361 | |
|
362 | 362 | def readseries(self): |
|
363 | 363 | nodes = [] |
|
364 | 364 | merges = [] |
|
365 | 365 | cur = nodes |
|
366 | 366 | for line in self.opener.read('series').splitlines(): |
|
367 | 367 | if line.startswith('# Merges'): |
|
368 | 368 | cur = merges |
|
369 | 369 | continue |
|
370 | 370 | cur.append(revlog.bin(line)) |
|
371 | 371 | |
|
372 | 372 | return (nodes, merges) |
|
373 | 373 | |
|
374 | 374 | def saveseries(self, revmap, merges): |
|
375 | 375 | if not revmap: |
|
376 | 376 | return |
|
377 | 377 | |
|
378 | 378 | if not os.path.isdir(self.path): |
|
379 | 379 | os.mkdir(self.path) |
|
380 | 380 | series = self.opener('series', 'w') |
|
381 | 381 | for rev in sorted(revmap): |
|
382 | 382 | series.write(revlog.hex(revmap[rev]) + '\n') |
|
383 | 383 | if merges: |
|
384 | 384 | series.write('# Merges\n') |
|
385 | 385 | for m in merges: |
|
386 | 386 | series.write(revlog.hex(m) + '\n') |
|
387 | 387 | series.close() |
|
388 | 388 | |
|
389 | 389 | def parselog(self, fp): |
|
390 | 390 | parents = [] |
|
391 | 391 | message = [] |
|
392 | 392 | node = revlog.nullid |
|
393 | 393 | inmsg = False |
|
394 | 394 | user = None |
|
395 | 395 | date = None |
|
396 | 396 | for line in fp.read().splitlines(): |
|
397 | 397 | if inmsg: |
|
398 | 398 | message.append(line) |
|
399 | 399 | elif line.startswith('# User '): |
|
400 | 400 | user = line[7:] |
|
401 | 401 | elif line.startswith('# Date '): |
|
402 | 402 | date = line[7:] |
|
403 | 403 | elif line.startswith('# Node ID '): |
|
404 | 404 | node = revlog.bin(line[10:]) |
|
405 | 405 | elif line.startswith('# Parent '): |
|
406 | 406 | parents.append(revlog.bin(line[9:])) |
|
407 | 407 | elif not line.startswith('# '): |
|
408 | 408 | inmsg = True |
|
409 | 409 | message.append(line) |
|
410 | 410 | if None in (user, date): |
|
411 | 411 | raise util.Abort(_("filter corrupted changeset (no user or date)")) |
|
412 | 412 | return (node, user, date, '\n'.join(message), parents) |
|
413 | 413 | |
|
414 | 414 | def log(self, user, date, message, p1, p2, merge=False): |
|
415 | 415 | '''journal changelog metadata for later recover''' |
|
416 | 416 | |
|
417 | 417 | if not os.path.isdir(self.path): |
|
418 | 418 | os.mkdir(self.path) |
|
419 | 419 | fp = self.opener('journal', 'w') |
|
420 | 420 | fp.write('# User %s\n' % user) |
|
421 | 421 | fp.write('# Date %s\n' % date) |
|
422 | 422 | fp.write('# Node ID %s\n' % revlog.hex(p2)) |
|
423 | 423 | fp.write('# Parent ' + revlog.hex(p1) + '\n') |
|
424 | 424 | if merge: |
|
425 | 425 | fp.write('# Parent ' + revlog.hex(p2) + '\n') |
|
426 | 426 | fp.write(message.rstrip() + '\n') |
|
427 | 427 | fp.close() |
|
428 | 428 | |
|
429 | 429 | def readlog(self): |
|
430 | 430 | return self.parselog(self.opener('journal')) |
|
431 | 431 | |
|
432 | 432 | def unlog(self): |
|
433 | 433 | '''remove changelog journal''' |
|
434 | 434 | absdst = os.path.join(self.path, 'journal') |
|
435 | 435 | if os.path.exists(absdst): |
|
436 | 436 | os.unlink(absdst) |
|
437 | 437 | |
|
438 | 438 | def transplantfilter(self, repo, source, root): |
|
439 | 439 | def matchfn(node): |
|
440 | 440 | if self.applied(repo, node, root): |
|
441 | 441 | return False |
|
442 | 442 | if source.changelog.parents(node)[1] != revlog.nullid: |
|
443 | 443 | return False |
|
444 | 444 | extra = source.changelog.read(node)[5] |
|
445 | 445 | cnode = extra.get('transplant_source') |
|
446 | 446 | if cnode and self.applied(repo, cnode, root): |
|
447 | 447 | return False |
|
448 | 448 | return True |
|
449 | 449 | |
|
450 | 450 | return matchfn |
|
451 | 451 | |
|
452 | 452 | def hasnode(repo, node): |
|
453 | 453 | try: |
|
454 | 454 | return repo.changelog.rev(node) is not None |
|
455 | 455 | except error.RevlogError: |
|
456 | 456 | return False |
|
457 | 457 | |
|
458 | 458 | def browserevs(ui, repo, nodes, opts): |
|
459 | 459 | '''interactively transplant changesets''' |
|
460 | 460 | def browsehelp(ui): |
|
461 | 461 | ui.write(_('y: transplant this changeset\n' |
|
462 | 462 | 'n: skip this changeset\n' |
|
463 | 463 | 'm: merge at this changeset\n' |
|
464 | 464 | 'p: show patch\n' |
|
465 | 465 | 'c: commit selected changesets\n' |
|
466 | 466 | 'q: cancel transplant\n' |
|
467 | 467 | '?: show this help\n')) |
|
468 | 468 | |
|
469 | 469 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
470 | 470 | transplants = [] |
|
471 | 471 | merges = [] |
|
472 | 472 | for node in nodes: |
|
473 | 473 | displayer.show(repo[node]) |
|
474 | 474 | action = None |
|
475 | 475 | while not action: |
|
476 | 476 | action = ui.prompt(_('apply changeset? [ynmpcq?]:')) |
|
477 | 477 | if action == '?': |
|
478 | 478 | browsehelp(ui) |
|
479 | 479 | action = None |
|
480 | 480 | elif action == 'p': |
|
481 | 481 | parent = repo.changelog.parents(node)[0] |
|
482 | 482 | for chunk in patch.diff(repo, parent, node): |
|
483 | 483 | ui.write(chunk) |
|
484 | 484 | action = None |
|
485 | 485 | elif action not in ('y', 'n', 'm', 'c', 'q'): |
|
486 | 486 | ui.write(_('no such option\n')) |
|
487 | 487 | action = None |
|
488 | 488 | if action == 'y': |
|
489 | 489 | transplants.append(node) |
|
490 | 490 | elif action == 'm': |
|
491 | 491 | merges.append(node) |
|
492 | 492 | elif action == 'c': |
|
493 | 493 | break |
|
494 | 494 | elif action == 'q': |
|
495 | 495 | transplants = () |
|
496 | 496 | merges = () |
|
497 | 497 | break |
|
498 | 498 | displayer.close() |
|
499 | 499 | return (transplants, merges) |
|
500 | 500 | |
|
501 | 501 | @command('transplant', |
|
502 | 502 | [('s', 'source', '', _('pull patches from REPO'), _('REPO')), |
|
503 | 503 | ('b', 'branch', [], |
|
504 | 504 | _('pull patches from branch BRANCH'), _('BRANCH')), |
|
505 | 505 | ('a', 'all', None, _('pull all changesets up to BRANCH')), |
|
506 | 506 | ('p', 'prune', [], _('skip over REV'), _('REV')), |
|
507 | 507 | ('m', 'merge', [], _('merge at REV'), _('REV')), |
|
508 | 508 | ('', 'parent', '', |
|
509 | 509 | _('parent to choose when transplanting merge'), _('REV')), |
|
510 | 510 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
511 | 511 | ('', 'log', None, _('append transplant info to log message')), |
|
512 | 512 | ('c', 'continue', None, _('continue last transplant session ' |
|
513 | 513 | 'after repair')), |
|
514 | 514 | ('', 'filter', '', |
|
515 | 515 | _('filter changesets through command'), _('CMD'))], |
|
516 | 516 | _('hg transplant [-s REPO] [-b BRANCH [-a]] [-p REV] ' |
|
517 | 517 | '[-m REV] [REV]...')) |
|
518 | 518 | def transplant(ui, repo, *revs, **opts): |
|
519 | 519 | '''transplant changesets from another branch |
|
520 | 520 | |
|
521 | 521 | Selected changesets will be applied on top of the current working |
|
522 | 522 | directory with the log of the original changeset. The changesets |
|
523 | 523 | are copied and will thus appear twice in the history. Use the |
|
524 | 524 | rebase extension instead if you want to move a whole branch of |
|
525 | 525 | unpublished changesets. |
|
526 | 526 | |
|
527 | 527 | If --log is specified, log messages will have a comment appended |
|
528 | 528 | of the form:: |
|
529 | 529 | |
|
530 | 530 | (transplanted from CHANGESETHASH) |
|
531 | 531 | |
|
532 | 532 | You can rewrite the changelog message with the --filter option. |
|
533 | 533 | Its argument will be invoked with the current changelog message as |
|
534 | 534 | $1 and the patch as $2. |
|
535 | 535 | |
|
536 | 536 | If --source/-s is specified, selects changesets from the named |
|
537 | 537 | repository. If --branch/-b is specified, selects changesets from |
|
538 | 538 | the branch holding the named revision, up to that revision. If |
|
539 | 539 | --all/-a is specified, all changesets on the branch will be |
|
540 | 540 | transplanted, otherwise you will be prompted to select the |
|
541 | 541 | changesets you want. |
|
542 | 542 | |
|
543 | 543 | :hg:`transplant --branch REV --all` will transplant the |
|
544 | 544 | selected branch (up to the named revision) onto your current |
|
545 | 545 | working directory. |
|
546 | 546 | |
|
547 | 547 | You can optionally mark selected transplanted changesets as merge |
|
548 | 548 | changesets. You will not be prompted to transplant any ancestors |
|
549 | 549 | of a merged transplant, and you can merge descendants of them |
|
550 | 550 | normally instead of transplanting them. |
|
551 | 551 | |
|
552 | 552 | Merge changesets may be transplanted directly by specifying the |
|
553 | 553 | proper parent changeset by calling :hg:`transplant --parent`. |
|
554 | 554 | |
|
555 | 555 | If no merges or revisions are provided, :hg:`transplant` will |
|
556 | 556 | start an interactive changeset browser. |
|
557 | 557 | |
|
558 | 558 | If a changeset application fails, you can fix the merge by hand |
|
559 | 559 | and then resume where you left off by calling :hg:`transplant |
|
560 | 560 | --continue/-c`. |
|
561 | 561 | ''' |
|
562 | 562 | def incwalk(repo, csets, match=util.always): |
|
563 | 563 | for node in csets: |
|
564 | 564 | if match(node): |
|
565 | 565 | yield node |
|
566 | 566 | |
|
567 | 567 | def transplantwalk(repo, root, branches, match=util.always): |
|
568 | 568 | if not branches: |
|
569 | 569 | branches = repo.heads() |
|
570 | 570 | ancestors = [] |
|
571 | 571 | for branch in branches: |
|
572 | 572 | ancestors.append(repo.changelog.ancestor(root, branch)) |
|
573 | 573 | for node in repo.changelog.nodesbetween(ancestors, branches)[0]: |
|
574 | 574 | if match(node): |
|
575 | 575 | yield node |
|
576 | 576 | |
|
577 | 577 | def checkopts(opts, revs): |
|
578 | 578 | if opts.get('continue'): |
|
579 | 579 | if opts.get('branch') or opts.get('all') or opts.get('merge'): |
|
580 | 580 | raise util.Abort(_('--continue is incompatible with ' |
|
581 | 581 | 'branch, all or merge')) |
|
582 | 582 | return |
|
583 | 583 | if not (opts.get('source') or revs or |
|
584 | 584 | opts.get('merge') or opts.get('branch')): |
|
585 | 585 | raise util.Abort(_('no source URL, branch tag or revision ' |
|
586 | 586 | 'list provided')) |
|
587 | 587 | if opts.get('all'): |
|
588 | 588 | if not opts.get('branch'): |
|
589 | 589 | raise util.Abort(_('--all requires a branch revision')) |
|
590 | 590 | if revs: |
|
591 | 591 | raise util.Abort(_('--all is incompatible with a ' |
|
592 | 592 | 'revision list')) |
|
593 | 593 | |
|
594 | 594 | checkopts(opts, revs) |
|
595 | 595 | |
|
596 | 596 | if not opts.get('log'): |
|
597 | 597 | opts['log'] = ui.config('transplant', 'log') |
|
598 | 598 | if not opts.get('filter'): |
|
599 | 599 | opts['filter'] = ui.config('transplant', 'filter') |
|
600 | 600 | |
|
601 | 601 | tp = transplanter(ui, repo) |
|
602 | 602 | if opts.get('edit'): |
|
603 | 603 | tp.editor = cmdutil.commitforceeditor |
|
604 | 604 | |
|
605 | 605 | p1, p2 = repo.dirstate.parents() |
|
606 | 606 | if len(repo) > 0 and p1 == revlog.nullid: |
|
607 | 607 | raise util.Abort(_('no revision checked out')) |
|
608 | 608 | if not opts.get('continue'): |
|
609 | 609 | if p2 != revlog.nullid: |
|
610 | 610 | raise util.Abort(_('outstanding uncommitted merges')) |
|
611 | 611 | m, a, r, d = repo.status()[:4] |
|
612 | 612 | if m or a or r or d: |
|
613 | 613 | raise util.Abort(_('outstanding local changes')) |
|
614 | 614 | |
|
615 | 615 | sourcerepo = opts.get('source') |
|
616 | 616 | if sourcerepo: |
|
617 |
|
|
|
618 |
branches = map( |
|
|
619 |
source, csets, cleanupfn = bundlerepo.getremotechanges(ui, repo, |
|
|
617 | peer = hg.peer(ui, opts, ui.expandpath(sourcerepo)) | |
|
618 | branches = map(peer.lookup, opts.get('branch', ())) | |
|
619 | source, csets, cleanupfn = bundlerepo.getremotechanges(ui, repo, peer, | |
|
620 | 620 | onlyheads=branches, force=True) |
|
621 | 621 | else: |
|
622 | 622 | source = repo |
|
623 | 623 | branches = map(source.lookup, opts.get('branch', ())) |
|
624 | 624 | cleanupfn = None |
|
625 | 625 | |
|
626 | 626 | try: |
|
627 | 627 | if opts.get('continue'): |
|
628 | 628 | tp.resume(repo, source, opts) |
|
629 | 629 | return |
|
630 | 630 | |
|
631 | 631 | tf = tp.transplantfilter(repo, source, p1) |
|
632 | 632 | if opts.get('prune'): |
|
633 | 633 | prune = [source.lookup(r) |
|
634 | 634 | for r in scmutil.revrange(source, opts.get('prune'))] |
|
635 | 635 | matchfn = lambda x: tf(x) and x not in prune |
|
636 | 636 | else: |
|
637 | 637 | matchfn = tf |
|
638 | 638 | merges = map(source.lookup, opts.get('merge', ())) |
|
639 | 639 | revmap = {} |
|
640 | 640 | if revs: |
|
641 | 641 | for r in scmutil.revrange(source, revs): |
|
642 | 642 | revmap[int(r)] = source.lookup(r) |
|
643 | 643 | elif opts.get('all') or not merges: |
|
644 | 644 | if source != repo: |
|
645 | 645 | alltransplants = incwalk(source, csets, match=matchfn) |
|
646 | 646 | else: |
|
647 | 647 | alltransplants = transplantwalk(source, p1, branches, |
|
648 | 648 | match=matchfn) |
|
649 | 649 | if opts.get('all'): |
|
650 | 650 | revs = alltransplants |
|
651 | 651 | else: |
|
652 | 652 | revs, newmerges = browserevs(ui, source, alltransplants, opts) |
|
653 | 653 | merges.extend(newmerges) |
|
654 | 654 | for r in revs: |
|
655 | 655 | revmap[source.changelog.rev(r)] = r |
|
656 | 656 | for r in merges: |
|
657 | 657 | revmap[source.changelog.rev(r)] = r |
|
658 | 658 | |
|
659 | 659 | tp.apply(repo, source, revmap, merges, opts) |
|
660 | 660 | finally: |
|
661 | 661 | if cleanupfn: |
|
662 | 662 | cleanupfn() |
|
663 | 663 | |
|
664 | 664 | def revsettransplanted(repo, subset, x): |
|
665 | 665 | """``transplanted([set])`` |
|
666 | 666 | Transplanted changesets in set, or all transplanted changesets. |
|
667 | 667 | """ |
|
668 | 668 | if x: |
|
669 | 669 | s = revset.getset(repo, subset, x) |
|
670 | 670 | else: |
|
671 | 671 | s = subset |
|
672 | 672 | return [r for r in s if repo[r].extra().get('transplant_source')] |
|
673 | 673 | |
|
674 | 674 | def kwtransplanted(repo, ctx, **args): |
|
675 | 675 | """:transplanted: String. The node identifier of the transplanted |
|
676 | 676 | changeset if any.""" |
|
677 | 677 | n = ctx.extra().get('transplant_source') |
|
678 | 678 | return n and revlog.hex(n) or '' |
|
679 | 679 | |
|
680 | 680 | def extsetup(ui): |
|
681 | 681 | revset.symbols['transplanted'] = revsettransplanted |
|
682 | 682 | templatekw.keywords['transplanted'] = kwtransplanted |
|
683 | 683 | |
|
684 | 684 | # tell hggettext to extract docstrings from these functions: |
|
685 | 685 | i18nfunctions = [revsettransplanted, kwtransplanted] |
@@ -1,380 +1,380 | |||
|
1 | 1 | # bundlerepo.py - repository class for viewing uncompressed bundles |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006, 2007 Benoit Boissinot <bboissin@gmail.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | """Repository class for viewing uncompressed bundles. |
|
9 | 9 | |
|
10 | 10 | This provides a read-only repository interface to bundles as if they |
|
11 | 11 | were part of the actual repository. |
|
12 | 12 | """ |
|
13 | 13 | |
|
14 | 14 | from node import nullid |
|
15 | 15 | from i18n import _ |
|
16 | 16 | import os, tempfile, shutil |
|
17 | 17 | import changegroup, util, mdiff, discovery, cmdutil |
|
18 | 18 | import localrepo, changelog, manifest, filelog, revlog, error |
|
19 | 19 | |
|
20 | 20 | class bundlerevlog(revlog.revlog): |
|
21 | 21 | def __init__(self, opener, indexfile, bundle, linkmapper): |
|
22 | 22 | # How it works: |
|
23 | 23 | # to retrieve a revision, we need to know the offset of |
|
24 | 24 | # the revision in the bundle (an unbundle object). |
|
25 | 25 | # |
|
26 | 26 | # We store this offset in the index (start), to differentiate a |
|
27 | 27 | # rev in the bundle and from a rev in the revlog, we check |
|
28 | 28 | # len(index[r]). If the tuple is bigger than 7, it is a bundle |
|
29 | 29 | # (it is bigger since we store the node to which the delta is) |
|
30 | 30 | # |
|
31 | 31 | revlog.revlog.__init__(self, opener, indexfile) |
|
32 | 32 | self.bundle = bundle |
|
33 | 33 | self.basemap = {} |
|
34 | 34 | n = len(self) |
|
35 | 35 | chain = None |
|
36 | 36 | while True: |
|
37 | 37 | chunkdata = bundle.deltachunk(chain) |
|
38 | 38 | if not chunkdata: |
|
39 | 39 | break |
|
40 | 40 | node = chunkdata['node'] |
|
41 | 41 | p1 = chunkdata['p1'] |
|
42 | 42 | p2 = chunkdata['p2'] |
|
43 | 43 | cs = chunkdata['cs'] |
|
44 | 44 | deltabase = chunkdata['deltabase'] |
|
45 | 45 | delta = chunkdata['delta'] |
|
46 | 46 | |
|
47 | 47 | size = len(delta) |
|
48 | 48 | start = bundle.tell() - size |
|
49 | 49 | |
|
50 | 50 | link = linkmapper(cs) |
|
51 | 51 | if node in self.nodemap: |
|
52 | 52 | # this can happen if two branches make the same change |
|
53 | 53 | chain = node |
|
54 | 54 | continue |
|
55 | 55 | |
|
56 | 56 | for p in (p1, p2): |
|
57 | 57 | if p not in self.nodemap: |
|
58 | 58 | raise error.LookupError(p, self.indexfile, |
|
59 | 59 | _("unknown parent")) |
|
60 | 60 | # start, size, full unc. size, base (unused), link, p1, p2, node |
|
61 | 61 | e = (revlog.offset_type(start, 0), size, -1, -1, link, |
|
62 | 62 | self.rev(p1), self.rev(p2), node) |
|
63 | 63 | self.basemap[n] = deltabase |
|
64 | 64 | self.index.insert(-1, e) |
|
65 | 65 | self.nodemap[node] = n |
|
66 | 66 | chain = node |
|
67 | 67 | n += 1 |
|
68 | 68 | |
|
69 | 69 | def inbundle(self, rev): |
|
70 | 70 | """is rev from the bundle""" |
|
71 | 71 | if rev < 0: |
|
72 | 72 | return False |
|
73 | 73 | return rev in self.basemap |
|
74 | 74 | def bundlebase(self, rev): |
|
75 | 75 | return self.basemap[rev] |
|
76 | 76 | def _chunk(self, rev): |
|
77 | 77 | # Warning: in case of bundle, the diff is against bundlebase, |
|
78 | 78 | # not against rev - 1 |
|
79 | 79 | # XXX: could use some caching |
|
80 | 80 | if not self.inbundle(rev): |
|
81 | 81 | return revlog.revlog._chunk(self, rev) |
|
82 | 82 | self.bundle.seek(self.start(rev)) |
|
83 | 83 | return self.bundle.read(self.length(rev)) |
|
84 | 84 | |
|
85 | 85 | def revdiff(self, rev1, rev2): |
|
86 | 86 | """return or calculate a delta between two revisions""" |
|
87 | 87 | if self.inbundle(rev1) and self.inbundle(rev2): |
|
88 | 88 | # hot path for bundle |
|
89 | 89 | revb = self.rev(self.bundlebase(rev2)) |
|
90 | 90 | if revb == rev1: |
|
91 | 91 | return self._chunk(rev2) |
|
92 | 92 | elif not self.inbundle(rev1) and not self.inbundle(rev2): |
|
93 | 93 | return revlog.revlog.revdiff(self, rev1, rev2) |
|
94 | 94 | |
|
95 | 95 | return mdiff.textdiff(self.revision(self.node(rev1)), |
|
96 | 96 | self.revision(self.node(rev2))) |
|
97 | 97 | |
|
98 | 98 | def revision(self, nodeorrev): |
|
99 | 99 | """return an uncompressed revision of a given node or revision |
|
100 | 100 | number. |
|
101 | 101 | """ |
|
102 | 102 | if isinstance(nodeorrev, int): |
|
103 | 103 | rev = nodeorrev |
|
104 | 104 | node = self.node(rev) |
|
105 | 105 | else: |
|
106 | 106 | node = nodeorrev |
|
107 | 107 | rev = self.rev(node) |
|
108 | 108 | |
|
109 | 109 | if node == nullid: |
|
110 | 110 | return "" |
|
111 | 111 | |
|
112 | 112 | text = None |
|
113 | 113 | chain = [] |
|
114 | 114 | iter_node = node |
|
115 | 115 | # reconstruct the revision if it is from a changegroup |
|
116 | 116 | while self.inbundle(rev): |
|
117 | 117 | if self._cache and self._cache[0] == iter_node: |
|
118 | 118 | text = self._cache[2] |
|
119 | 119 | break |
|
120 | 120 | chain.append(rev) |
|
121 | 121 | iter_node = self.bundlebase(rev) |
|
122 | 122 | rev = self.rev(iter_node) |
|
123 | 123 | if text is None: |
|
124 | 124 | text = revlog.revlog.revision(self, iter_node) |
|
125 | 125 | |
|
126 | 126 | while chain: |
|
127 | 127 | delta = self._chunk(chain.pop()) |
|
128 | 128 | text = mdiff.patches(text, [delta]) |
|
129 | 129 | |
|
130 | 130 | p1, p2 = self.parents(node) |
|
131 | 131 | if node != revlog.hash(text, p1, p2): |
|
132 | 132 | raise error.RevlogError(_("integrity check failed on %s:%d") |
|
133 | 133 | % (self.datafile, self.rev(node))) |
|
134 | 134 | |
|
135 | 135 | self._cache = (node, self.rev(node), text) |
|
136 | 136 | return text |
|
137 | 137 | |
|
138 | 138 | def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): |
|
139 | 139 | raise NotImplementedError |
|
140 | 140 | def addgroup(self, revs, linkmapper, transaction): |
|
141 | 141 | raise NotImplementedError |
|
142 | 142 | def strip(self, rev, minlink): |
|
143 | 143 | raise NotImplementedError |
|
144 | 144 | def checksize(self): |
|
145 | 145 | raise NotImplementedError |
|
146 | 146 | |
|
147 | 147 | class bundlechangelog(bundlerevlog, changelog.changelog): |
|
148 | 148 | def __init__(self, opener, bundle): |
|
149 | 149 | changelog.changelog.__init__(self, opener) |
|
150 | 150 | linkmapper = lambda x: x |
|
151 | 151 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, |
|
152 | 152 | linkmapper) |
|
153 | 153 | |
|
154 | 154 | class bundlemanifest(bundlerevlog, manifest.manifest): |
|
155 | 155 | def __init__(self, opener, bundle, linkmapper): |
|
156 | 156 | manifest.manifest.__init__(self, opener) |
|
157 | 157 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, |
|
158 | 158 | linkmapper) |
|
159 | 159 | |
|
160 | 160 | class bundlefilelog(bundlerevlog, filelog.filelog): |
|
161 | 161 | def __init__(self, opener, path, bundle, linkmapper, repo): |
|
162 | 162 | filelog.filelog.__init__(self, opener, path) |
|
163 | 163 | bundlerevlog.__init__(self, opener, self.indexfile, bundle, |
|
164 | 164 | linkmapper) |
|
165 | 165 | self._repo = repo |
|
166 | 166 | |
|
167 | 167 | def _file(self, f): |
|
168 | 168 | self._repo.file(f) |
|
169 | 169 | |
|
170 | 170 | class bundlerepository(localrepo.localrepository): |
|
171 | 171 | def __init__(self, ui, path, bundlename): |
|
172 | 172 | self._tempparent = None |
|
173 | 173 | try: |
|
174 | 174 | localrepo.localrepository.__init__(self, ui, path) |
|
175 | 175 | except error.RepoError: |
|
176 | 176 | self._tempparent = tempfile.mkdtemp() |
|
177 | 177 | localrepo.instance(ui, self._tempparent, 1) |
|
178 | 178 | localrepo.localrepository.__init__(self, ui, self._tempparent) |
|
179 | 179 | self.ui.setconfig('phases', 'publish', False) |
|
180 | 180 | |
|
181 | 181 | if path: |
|
182 | 182 | self._url = 'bundle:' + util.expandpath(path) + '+' + bundlename |
|
183 | 183 | else: |
|
184 | 184 | self._url = 'bundle:' + bundlename |
|
185 | 185 | |
|
186 | 186 | self.tempfile = None |
|
187 | 187 | f = util.posixfile(bundlename, "rb") |
|
188 | 188 | self.bundle = changegroup.readbundle(f, bundlename) |
|
189 | 189 | if self.bundle.compressed(): |
|
190 | 190 | fdtemp, temp = tempfile.mkstemp(prefix="hg-bundle-", |
|
191 | 191 | suffix=".hg10un", dir=self.path) |
|
192 | 192 | self.tempfile = temp |
|
193 | 193 | fptemp = os.fdopen(fdtemp, 'wb') |
|
194 | 194 | |
|
195 | 195 | try: |
|
196 | 196 | fptemp.write("HG10UN") |
|
197 | 197 | while True: |
|
198 | 198 | chunk = self.bundle.read(2**18) |
|
199 | 199 | if not chunk: |
|
200 | 200 | break |
|
201 | 201 | fptemp.write(chunk) |
|
202 | 202 | finally: |
|
203 | 203 | fptemp.close() |
|
204 | 204 | |
|
205 | 205 | f = util.posixfile(self.tempfile, "rb") |
|
206 | 206 | self.bundle = changegroup.readbundle(f, bundlename) |
|
207 | 207 | |
|
208 | 208 | # dict with the mapping 'filename' -> position in the bundle |
|
209 | 209 | self.bundlefilespos = {} |
|
210 | 210 | |
|
211 | 211 | @util.propertycache |
|
212 | 212 | def changelog(self): |
|
213 | 213 | # consume the header if it exists |
|
214 | 214 | self.bundle.changelogheader() |
|
215 | 215 | c = bundlechangelog(self.sopener, self.bundle) |
|
216 | 216 | self.manstart = self.bundle.tell() |
|
217 | 217 | return c |
|
218 | 218 | |
|
219 | 219 | @util.propertycache |
|
220 | 220 | def manifest(self): |
|
221 | 221 | self.bundle.seek(self.manstart) |
|
222 | 222 | # consume the header if it exists |
|
223 | 223 | self.bundle.manifestheader() |
|
224 | 224 | m = bundlemanifest(self.sopener, self.bundle, self.changelog.rev) |
|
225 | 225 | self.filestart = self.bundle.tell() |
|
226 | 226 | return m |
|
227 | 227 | |
|
228 | 228 | @util.propertycache |
|
229 | 229 | def manstart(self): |
|
230 | 230 | self.changelog |
|
231 | 231 | return self.manstart |
|
232 | 232 | |
|
233 | 233 | @util.propertycache |
|
234 | 234 | def filestart(self): |
|
235 | 235 | self.manifest |
|
236 | 236 | return self.filestart |
|
237 | 237 | |
|
238 | 238 | def url(self): |
|
239 | 239 | return self._url |
|
240 | 240 | |
|
241 | 241 | def file(self, f): |
|
242 | 242 | if not self.bundlefilespos: |
|
243 | 243 | self.bundle.seek(self.filestart) |
|
244 | 244 | while True: |
|
245 | 245 | chunkdata = self.bundle.filelogheader() |
|
246 | 246 | if not chunkdata: |
|
247 | 247 | break |
|
248 | 248 | fname = chunkdata['filename'] |
|
249 | 249 | self.bundlefilespos[fname] = self.bundle.tell() |
|
250 | 250 | while True: |
|
251 | 251 | c = self.bundle.deltachunk(None) |
|
252 | 252 | if not c: |
|
253 | 253 | break |
|
254 | 254 | |
|
255 | 255 | if f[0] == '/': |
|
256 | 256 | f = f[1:] |
|
257 | 257 | if f in self.bundlefilespos: |
|
258 | 258 | self.bundle.seek(self.bundlefilespos[f]) |
|
259 | 259 | return bundlefilelog(self.sopener, f, self.bundle, |
|
260 | 260 | self.changelog.rev, self) |
|
261 | 261 | else: |
|
262 | 262 | return filelog.filelog(self.sopener, f) |
|
263 | 263 | |
|
264 | 264 | def close(self): |
|
265 | 265 | """Close assigned bundle file immediately.""" |
|
266 | 266 | self.bundle.close() |
|
267 | 267 | if self.tempfile is not None: |
|
268 | 268 | os.unlink(self.tempfile) |
|
269 | 269 | if self._tempparent: |
|
270 | 270 | shutil.rmtree(self._tempparent, True) |
|
271 | 271 | |
|
272 | 272 | def cancopy(self): |
|
273 | 273 | return False |
|
274 | 274 | |
|
275 | 275 | def getcwd(self): |
|
276 | 276 | return os.getcwd() # always outside the repo |
|
277 | 277 | |
|
278 | 278 | def _writebranchcache(self, branches, tip, tiprev): |
|
279 | 279 | # don't overwrite the disk cache with bundle-augmented data |
|
280 | 280 | pass |
|
281 | 281 | |
|
282 | 282 | def instance(ui, path, create): |
|
283 | 283 | if create: |
|
284 | 284 | raise util.Abort(_('cannot create new bundle repository')) |
|
285 | 285 | parentpath = ui.config("bundle", "mainreporoot", "") |
|
286 | 286 | if not parentpath: |
|
287 | 287 | # try to find the correct path to the working directory repo |
|
288 | 288 | parentpath = cmdutil.findrepo(os.getcwd()) |
|
289 | 289 | if parentpath is None: |
|
290 | 290 | parentpath = '' |
|
291 | 291 | if parentpath: |
|
292 | 292 | # Try to make the full path relative so we get a nice, short URL. |
|
293 | 293 | # In particular, we don't want temp dir names in test outputs. |
|
294 | 294 | cwd = os.getcwd() |
|
295 | 295 | if parentpath == cwd: |
|
296 | 296 | parentpath = '' |
|
297 | 297 | else: |
|
298 | 298 | cwd = os.path.join(cwd,'') |
|
299 | 299 | if parentpath.startswith(cwd): |
|
300 | 300 | parentpath = parentpath[len(cwd):] |
|
301 | 301 | u = util.url(path) |
|
302 | 302 | path = u.localpath() |
|
303 | 303 | if u.scheme == 'bundle': |
|
304 | 304 | s = path.split("+", 1) |
|
305 | 305 | if len(s) == 1: |
|
306 | 306 | repopath, bundlename = parentpath, s[0] |
|
307 | 307 | else: |
|
308 | 308 | repopath, bundlename = s |
|
309 | 309 | else: |
|
310 | 310 | repopath, bundlename = parentpath, path |
|
311 | 311 | return bundlerepository(ui, repopath, bundlename) |
|
312 | 312 | |
|
313 | 313 | def getremotechanges(ui, repo, other, onlyheads=None, bundlename=None, |
|
314 | 314 | force=False): |
|
315 | 315 | '''obtains a bundle of changes incoming from other |
|
316 | 316 | |
|
317 | 317 | "onlyheads" restricts the returned changes to those reachable from the |
|
318 | 318 | specified heads. |
|
319 | 319 | "bundlename", if given, stores the bundle to this file path permanently; |
|
320 | 320 | otherwise it's stored to a temp file and gets deleted again when you call |
|
321 | 321 | the returned "cleanupfn". |
|
322 | 322 | "force" indicates whether to proceed on unrelated repos. |
|
323 | 323 | |
|
324 | 324 | Returns a tuple (local, csets, cleanupfn): |
|
325 | 325 | |
|
326 | 326 | "local" is a local repo from which to obtain the actual incoming |
|
327 | 327 | changesets; it is a bundlerepo for the obtained bundle when the |
|
328 | 328 | original "other" is remote. |
|
329 | 329 | "csets" lists the incoming changeset node ids. |
|
330 | 330 | "cleanupfn" must be called without arguments when you're done processing |
|
331 | 331 | the changes; it closes both the original "other" and the one returned |
|
332 | 332 | here. |
|
333 | 333 | ''' |
|
334 | 334 | tmp = discovery.findcommonincoming(repo, other, heads=onlyheads, |
|
335 | 335 | force=force) |
|
336 | 336 | common, incoming, rheads = tmp |
|
337 | 337 | if not incoming: |
|
338 | 338 | try: |
|
339 | 339 | if bundlename: |
|
340 | 340 | os.unlink(bundlename) |
|
341 | 341 | except OSError: |
|
342 | 342 | pass |
|
343 | 343 | return other, [], other.close |
|
344 | 344 | |
|
345 | 345 | bundle = None |
|
346 | 346 | bundlerepo = None |
|
347 | localrepo = other | |
|
348 |
if bundlename or not |
|
|
347 | localrepo = other.local() | |
|
348 | if bundlename or not localrepo: | |
|
349 | 349 | # create a bundle (uncompressed if other repo is not local) |
|
350 | 350 | |
|
351 | 351 | if other.capable('getbundle'): |
|
352 | 352 | cg = other.getbundle('incoming', common=common, heads=rheads) |
|
353 | 353 | elif onlyheads is None and not other.capable('changegroupsubset'): |
|
354 | 354 | # compat with older servers when pulling all remote heads |
|
355 | 355 | cg = other.changegroup(incoming, "incoming") |
|
356 | 356 | rheads = None |
|
357 | 357 | else: |
|
358 | 358 | cg = other.changegroupsubset(incoming, rheads, 'incoming') |
|
359 |
bundletype = |
|
|
359 | bundletype = localrepo and "HG10BZ" or "HG10UN" | |
|
360 | 360 | fname = bundle = changegroup.writebundle(cg, bundlename, bundletype) |
|
361 | 361 | # keep written bundle? |
|
362 | 362 | if bundlename: |
|
363 | 363 | bundle = None |
|
364 |
if not |
|
|
364 | if not localrepo: | |
|
365 | 365 | # use the created uncompressed bundlerepo |
|
366 | 366 | localrepo = bundlerepo = bundlerepository(ui, repo.root, fname) |
|
367 | 367 | # this repo contains local and other now, so filter out local again |
|
368 | 368 | common = repo.heads() |
|
369 | 369 | |
|
370 | 370 | csets = localrepo.changelog.findmissing(common, rheads) |
|
371 | 371 | |
|
372 | 372 | def cleanup(): |
|
373 | 373 | if bundlerepo: |
|
374 | 374 | bundlerepo.close() |
|
375 | 375 | if bundle: |
|
376 | 376 | os.unlink(bundle) |
|
377 | 377 | other.close() |
|
378 | 378 | |
|
379 | 379 | return (localrepo, csets, cleanup) |
|
380 | 380 |
@@ -1,5858 +1,5859 | |||
|
1 | 1 | # commands.py - command processing for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from node import hex, bin, nullid, nullrev, short |
|
9 | 9 | from lock import release |
|
10 | 10 | from i18n import _, gettext |
|
11 | 11 | import os, re, difflib, time, tempfile, errno |
|
12 | 12 | import hg, scmutil, util, revlog, extensions, copies, error, bookmarks |
|
13 | 13 | import patch, help, url, encoding, templatekw, discovery |
|
14 | 14 | import archival, changegroup, cmdutil, hbisect |
|
15 | 15 | import sshserver, hgweb, hgweb.server, commandserver |
|
16 | 16 | import merge as mergemod |
|
17 | 17 | import minirst, revset, fileset |
|
18 | 18 | import dagparser, context, simplemerge, graphmod |
|
19 | 19 | import random, setdiscovery, treediscovery, dagutil, pvec |
|
20 | 20 | import phases, obsolete |
|
21 | 21 | |
|
22 | 22 | table = {} |
|
23 | 23 | |
|
24 | 24 | command = cmdutil.command(table) |
|
25 | 25 | |
|
26 | 26 | # common command options |
|
27 | 27 | |
|
28 | 28 | globalopts = [ |
|
29 | 29 | ('R', 'repository', '', |
|
30 | 30 | _('repository root directory or name of overlay bundle file'), |
|
31 | 31 | _('REPO')), |
|
32 | 32 | ('', 'cwd', '', |
|
33 | 33 | _('change working directory'), _('DIR')), |
|
34 | 34 | ('y', 'noninteractive', None, |
|
35 | 35 | _('do not prompt, automatically pick the first choice for all prompts')), |
|
36 | 36 | ('q', 'quiet', None, _('suppress output')), |
|
37 | 37 | ('v', 'verbose', None, _('enable additional output')), |
|
38 | 38 | ('', 'config', [], |
|
39 | 39 | _('set/override config option (use \'section.name=value\')'), |
|
40 | 40 | _('CONFIG')), |
|
41 | 41 | ('', 'debug', None, _('enable debugging output')), |
|
42 | 42 | ('', 'debugger', None, _('start debugger')), |
|
43 | 43 | ('', 'encoding', encoding.encoding, _('set the charset encoding'), |
|
44 | 44 | _('ENCODE')), |
|
45 | 45 | ('', 'encodingmode', encoding.encodingmode, |
|
46 | 46 | _('set the charset encoding mode'), _('MODE')), |
|
47 | 47 | ('', 'traceback', None, _('always print a traceback on exception')), |
|
48 | 48 | ('', 'time', None, _('time how long the command takes')), |
|
49 | 49 | ('', 'profile', None, _('print command execution profile')), |
|
50 | 50 | ('', 'version', None, _('output version information and exit')), |
|
51 | 51 | ('h', 'help', None, _('display help and exit')), |
|
52 | 52 | ] |
|
53 | 53 | |
|
54 | 54 | dryrunopts = [('n', 'dry-run', None, |
|
55 | 55 | _('do not perform actions, just print output'))] |
|
56 | 56 | |
|
57 | 57 | remoteopts = [ |
|
58 | 58 | ('e', 'ssh', '', |
|
59 | 59 | _('specify ssh command to use'), _('CMD')), |
|
60 | 60 | ('', 'remotecmd', '', |
|
61 | 61 | _('specify hg command to run on the remote side'), _('CMD')), |
|
62 | 62 | ('', 'insecure', None, |
|
63 | 63 | _('do not verify server certificate (ignoring web.cacerts config)')), |
|
64 | 64 | ] |
|
65 | 65 | |
|
66 | 66 | walkopts = [ |
|
67 | 67 | ('I', 'include', [], |
|
68 | 68 | _('include names matching the given patterns'), _('PATTERN')), |
|
69 | 69 | ('X', 'exclude', [], |
|
70 | 70 | _('exclude names matching the given patterns'), _('PATTERN')), |
|
71 | 71 | ] |
|
72 | 72 | |
|
73 | 73 | commitopts = [ |
|
74 | 74 | ('m', 'message', '', |
|
75 | 75 | _('use text as commit message'), _('TEXT')), |
|
76 | 76 | ('l', 'logfile', '', |
|
77 | 77 | _('read commit message from file'), _('FILE')), |
|
78 | 78 | ] |
|
79 | 79 | |
|
80 | 80 | commitopts2 = [ |
|
81 | 81 | ('d', 'date', '', |
|
82 | 82 | _('record the specified date as commit date'), _('DATE')), |
|
83 | 83 | ('u', 'user', '', |
|
84 | 84 | _('record the specified user as committer'), _('USER')), |
|
85 | 85 | ] |
|
86 | 86 | |
|
87 | 87 | templateopts = [ |
|
88 | 88 | ('', 'style', '', |
|
89 | 89 | _('display using template map file'), _('STYLE')), |
|
90 | 90 | ('', 'template', '', |
|
91 | 91 | _('display with template'), _('TEMPLATE')), |
|
92 | 92 | ] |
|
93 | 93 | |
|
94 | 94 | logopts = [ |
|
95 | 95 | ('p', 'patch', None, _('show patch')), |
|
96 | 96 | ('g', 'git', None, _('use git extended diff format')), |
|
97 | 97 | ('l', 'limit', '', |
|
98 | 98 | _('limit number of changes displayed'), _('NUM')), |
|
99 | 99 | ('M', 'no-merges', None, _('do not show merges')), |
|
100 | 100 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
101 | 101 | ('G', 'graph', None, _("show the revision DAG")), |
|
102 | 102 | ] + templateopts |
|
103 | 103 | |
|
104 | 104 | diffopts = [ |
|
105 | 105 | ('a', 'text', None, _('treat all files as text')), |
|
106 | 106 | ('g', 'git', None, _('use git extended diff format')), |
|
107 | 107 | ('', 'nodates', None, _('omit dates from diff headers')) |
|
108 | 108 | ] |
|
109 | 109 | |
|
110 | 110 | diffwsopts = [ |
|
111 | 111 | ('w', 'ignore-all-space', None, |
|
112 | 112 | _('ignore white space when comparing lines')), |
|
113 | 113 | ('b', 'ignore-space-change', None, |
|
114 | 114 | _('ignore changes in the amount of white space')), |
|
115 | 115 | ('B', 'ignore-blank-lines', None, |
|
116 | 116 | _('ignore changes whose lines are all blank')), |
|
117 | 117 | ] |
|
118 | 118 | |
|
119 | 119 | diffopts2 = [ |
|
120 | 120 | ('p', 'show-function', None, _('show which function each change is in')), |
|
121 | 121 | ('', 'reverse', None, _('produce a diff that undoes the changes')), |
|
122 | 122 | ] + diffwsopts + [ |
|
123 | 123 | ('U', 'unified', '', |
|
124 | 124 | _('number of lines of context to show'), _('NUM')), |
|
125 | 125 | ('', 'stat', None, _('output diffstat-style summary of changes')), |
|
126 | 126 | ] |
|
127 | 127 | |
|
128 | 128 | mergetoolopts = [ |
|
129 | 129 | ('t', 'tool', '', _('specify merge tool')), |
|
130 | 130 | ] |
|
131 | 131 | |
|
132 | 132 | similarityopts = [ |
|
133 | 133 | ('s', 'similarity', '', |
|
134 | 134 | _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY')) |
|
135 | 135 | ] |
|
136 | 136 | |
|
137 | 137 | subrepoopts = [ |
|
138 | 138 | ('S', 'subrepos', None, |
|
139 | 139 | _('recurse into subrepositories')) |
|
140 | 140 | ] |
|
141 | 141 | |
|
142 | 142 | # Commands start here, listed alphabetically |
|
143 | 143 | |
|
144 | 144 | @command('^add', |
|
145 | 145 | walkopts + subrepoopts + dryrunopts, |
|
146 | 146 | _('[OPTION]... [FILE]...')) |
|
147 | 147 | def add(ui, repo, *pats, **opts): |
|
148 | 148 | """add the specified files on the next commit |
|
149 | 149 | |
|
150 | 150 | Schedule files to be version controlled and added to the |
|
151 | 151 | repository. |
|
152 | 152 | |
|
153 | 153 | The files will be added to the repository at the next commit. To |
|
154 | 154 | undo an add before that, see :hg:`forget`. |
|
155 | 155 | |
|
156 | 156 | If no names are given, add all files to the repository. |
|
157 | 157 | |
|
158 | 158 | .. container:: verbose |
|
159 | 159 | |
|
160 | 160 | An example showing how new (unknown) files are added |
|
161 | 161 | automatically by :hg:`add`:: |
|
162 | 162 | |
|
163 | 163 | $ ls |
|
164 | 164 | foo.c |
|
165 | 165 | $ hg status |
|
166 | 166 | ? foo.c |
|
167 | 167 | $ hg add |
|
168 | 168 | adding foo.c |
|
169 | 169 | $ hg status |
|
170 | 170 | A foo.c |
|
171 | 171 | |
|
172 | 172 | Returns 0 if all files are successfully added. |
|
173 | 173 | """ |
|
174 | 174 | |
|
175 | 175 | m = scmutil.match(repo[None], pats, opts) |
|
176 | 176 | rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'), |
|
177 | 177 | opts.get('subrepos'), prefix="", explicitonly=False) |
|
178 | 178 | return rejected and 1 or 0 |
|
179 | 179 | |
|
180 | 180 | @command('addremove', |
|
181 | 181 | similarityopts + walkopts + dryrunopts, |
|
182 | 182 | _('[OPTION]... [FILE]...')) |
|
183 | 183 | def addremove(ui, repo, *pats, **opts): |
|
184 | 184 | """add all new files, delete all missing files |
|
185 | 185 | |
|
186 | 186 | Add all new files and remove all missing files from the |
|
187 | 187 | repository. |
|
188 | 188 | |
|
189 | 189 | New files are ignored if they match any of the patterns in |
|
190 | 190 | ``.hgignore``. As with add, these changes take effect at the next |
|
191 | 191 | commit. |
|
192 | 192 | |
|
193 | 193 | Use the -s/--similarity option to detect renamed files. With a |
|
194 | 194 | parameter greater than 0, this compares every removed file with |
|
195 | 195 | every added file and records those similar enough as renames. This |
|
196 | 196 | option takes a percentage between 0 (disabled) and 100 (files must |
|
197 | 197 | be identical) as its parameter. Detecting renamed files this way |
|
198 | 198 | can be expensive. After using this option, :hg:`status -C` can be |
|
199 | 199 | used to check which files were identified as moved or renamed. |
|
200 | 200 | If this option is not specified, only renames of identical files |
|
201 | 201 | are detected. |
|
202 | 202 | |
|
203 | 203 | Returns 0 if all files are successfully added. |
|
204 | 204 | """ |
|
205 | 205 | try: |
|
206 | 206 | sim = float(opts.get('similarity') or 100) |
|
207 | 207 | except ValueError: |
|
208 | 208 | raise util.Abort(_('similarity must be a number')) |
|
209 | 209 | if sim < 0 or sim > 100: |
|
210 | 210 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
211 | 211 | return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0) |
|
212 | 212 | |
|
213 | 213 | @command('^annotate|blame', |
|
214 | 214 | [('r', 'rev', '', _('annotate the specified revision'), _('REV')), |
|
215 | 215 | ('', 'follow', None, |
|
216 | 216 | _('follow copies/renames and list the filename (DEPRECATED)')), |
|
217 | 217 | ('', 'no-follow', None, _("don't follow copies and renames")), |
|
218 | 218 | ('a', 'text', None, _('treat all files as text')), |
|
219 | 219 | ('u', 'user', None, _('list the author (long with -v)')), |
|
220 | 220 | ('f', 'file', None, _('list the filename')), |
|
221 | 221 | ('d', 'date', None, _('list the date (short with -q)')), |
|
222 | 222 | ('n', 'number', None, _('list the revision number (default)')), |
|
223 | 223 | ('c', 'changeset', None, _('list the changeset')), |
|
224 | 224 | ('l', 'line-number', None, _('show line number at the first appearance')) |
|
225 | 225 | ] + diffwsopts + walkopts, |
|
226 | 226 | _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')) |
|
227 | 227 | def annotate(ui, repo, *pats, **opts): |
|
228 | 228 | """show changeset information by line for each file |
|
229 | 229 | |
|
230 | 230 | List changes in files, showing the revision id responsible for |
|
231 | 231 | each line |
|
232 | 232 | |
|
233 | 233 | This command is useful for discovering when a change was made and |
|
234 | 234 | by whom. |
|
235 | 235 | |
|
236 | 236 | Without the -a/--text option, annotate will avoid processing files |
|
237 | 237 | it detects as binary. With -a, annotate will annotate the file |
|
238 | 238 | anyway, although the results will probably be neither useful |
|
239 | 239 | nor desirable. |
|
240 | 240 | |
|
241 | 241 | Returns 0 on success. |
|
242 | 242 | """ |
|
243 | 243 | if opts.get('follow'): |
|
244 | 244 | # --follow is deprecated and now just an alias for -f/--file |
|
245 | 245 | # to mimic the behavior of Mercurial before version 1.5 |
|
246 | 246 | opts['file'] = True |
|
247 | 247 | |
|
248 | 248 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
249 | 249 | getdate = util.cachefunc(lambda x: datefunc(x[0].date())) |
|
250 | 250 | |
|
251 | 251 | if not pats: |
|
252 | 252 | raise util.Abort(_('at least one filename or pattern is required')) |
|
253 | 253 | |
|
254 | 254 | hexfn = ui.debugflag and hex or short |
|
255 | 255 | |
|
256 | 256 | opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())), |
|
257 | 257 | ('number', ' ', lambda x: str(x[0].rev())), |
|
258 | 258 | ('changeset', ' ', lambda x: hexfn(x[0].node())), |
|
259 | 259 | ('date', ' ', getdate), |
|
260 | 260 | ('file', ' ', lambda x: x[0].path()), |
|
261 | 261 | ('line_number', ':', lambda x: str(x[1])), |
|
262 | 262 | ] |
|
263 | 263 | |
|
264 | 264 | if (not opts.get('user') and not opts.get('changeset') |
|
265 | 265 | and not opts.get('date') and not opts.get('file')): |
|
266 | 266 | opts['number'] = True |
|
267 | 267 | |
|
268 | 268 | linenumber = opts.get('line_number') is not None |
|
269 | 269 | if linenumber and (not opts.get('changeset')) and (not opts.get('number')): |
|
270 | 270 | raise util.Abort(_('at least one of -n/-c is required for -l')) |
|
271 | 271 | |
|
272 | 272 | funcmap = [(func, sep) for op, sep, func in opmap if opts.get(op)] |
|
273 | 273 | funcmap[0] = (funcmap[0][0], '') # no separator in front of first column |
|
274 | 274 | |
|
275 | 275 | def bad(x, y): |
|
276 | 276 | raise util.Abort("%s: %s" % (x, y)) |
|
277 | 277 | |
|
278 | 278 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
279 | 279 | m = scmutil.match(ctx, pats, opts) |
|
280 | 280 | m.bad = bad |
|
281 | 281 | follow = not opts.get('no_follow') |
|
282 | 282 | diffopts = patch.diffopts(ui, opts, section='annotate') |
|
283 | 283 | for abs in ctx.walk(m): |
|
284 | 284 | fctx = ctx[abs] |
|
285 | 285 | if not opts.get('text') and util.binary(fctx.data()): |
|
286 | 286 | ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) |
|
287 | 287 | continue |
|
288 | 288 | |
|
289 | 289 | lines = fctx.annotate(follow=follow, linenumber=linenumber, |
|
290 | 290 | diffopts=diffopts) |
|
291 | 291 | pieces = [] |
|
292 | 292 | |
|
293 | 293 | for f, sep in funcmap: |
|
294 | 294 | l = [f(n) for n, dummy in lines] |
|
295 | 295 | if l: |
|
296 | 296 | sized = [(x, encoding.colwidth(x)) for x in l] |
|
297 | 297 | ml = max([w for x, w in sized]) |
|
298 | 298 | pieces.append(["%s%s%s" % (sep, ' ' * (ml - w), x) |
|
299 | 299 | for x, w in sized]) |
|
300 | 300 | |
|
301 | 301 | if pieces: |
|
302 | 302 | for p, l in zip(zip(*pieces), lines): |
|
303 | 303 | ui.write("%s: %s" % ("".join(p), l[1])) |
|
304 | 304 | |
|
305 | 305 | if lines and not lines[-1][1].endswith('\n'): |
|
306 | 306 | ui.write('\n') |
|
307 | 307 | |
|
308 | 308 | @command('archive', |
|
309 | 309 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
310 | 310 | ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
311 | 311 | _('PREFIX')), |
|
312 | 312 | ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
313 | 313 | ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
314 | 314 | ] + subrepoopts + walkopts, |
|
315 | 315 | _('[OPTION]... DEST')) |
|
316 | 316 | def archive(ui, repo, dest, **opts): |
|
317 | 317 | '''create an unversioned archive of a repository revision |
|
318 | 318 | |
|
319 | 319 | By default, the revision used is the parent of the working |
|
320 | 320 | directory; use -r/--rev to specify a different revision. |
|
321 | 321 | |
|
322 | 322 | The archive type is automatically detected based on file |
|
323 | 323 | extension (or override using -t/--type). |
|
324 | 324 | |
|
325 | 325 | .. container:: verbose |
|
326 | 326 | |
|
327 | 327 | Examples: |
|
328 | 328 | |
|
329 | 329 | - create a zip file containing the 1.0 release:: |
|
330 | 330 | |
|
331 | 331 | hg archive -r 1.0 project-1.0.zip |
|
332 | 332 | |
|
333 | 333 | - create a tarball excluding .hg files:: |
|
334 | 334 | |
|
335 | 335 | hg archive project.tar.gz -X ".hg*" |
|
336 | 336 | |
|
337 | 337 | Valid types are: |
|
338 | 338 | |
|
339 | 339 | :``files``: a directory full of files (default) |
|
340 | 340 | :``tar``: tar archive, uncompressed |
|
341 | 341 | :``tbz2``: tar archive, compressed using bzip2 |
|
342 | 342 | :``tgz``: tar archive, compressed using gzip |
|
343 | 343 | :``uzip``: zip archive, uncompressed |
|
344 | 344 | :``zip``: zip archive, compressed using deflate |
|
345 | 345 | |
|
346 | 346 | The exact name of the destination archive or directory is given |
|
347 | 347 | using a format string; see :hg:`help export` for details. |
|
348 | 348 | |
|
349 | 349 | Each member added to an archive file has a directory prefix |
|
350 | 350 | prepended. Use -p/--prefix to specify a format string for the |
|
351 | 351 | prefix. The default is the basename of the archive, with suffixes |
|
352 | 352 | removed. |
|
353 | 353 | |
|
354 | 354 | Returns 0 on success. |
|
355 | 355 | ''' |
|
356 | 356 | |
|
357 | 357 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
358 | 358 | if not ctx: |
|
359 | 359 | raise util.Abort(_('no working directory: please specify a revision')) |
|
360 | 360 | node = ctx.node() |
|
361 | 361 | dest = cmdutil.makefilename(repo, dest, node) |
|
362 | 362 | if os.path.realpath(dest) == repo.root: |
|
363 | 363 | raise util.Abort(_('repository root cannot be destination')) |
|
364 | 364 | |
|
365 | 365 | kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
366 | 366 | prefix = opts.get('prefix') |
|
367 | 367 | |
|
368 | 368 | if dest == '-': |
|
369 | 369 | if kind == 'files': |
|
370 | 370 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
371 | 371 | dest = cmdutil.makefileobj(repo, dest) |
|
372 | 372 | if not prefix: |
|
373 | 373 | prefix = os.path.basename(repo.root) + '-%h' |
|
374 | 374 | |
|
375 | 375 | prefix = cmdutil.makefilename(repo, prefix, node) |
|
376 | 376 | matchfn = scmutil.match(ctx, [], opts) |
|
377 | 377 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
378 | 378 | matchfn, prefix, subrepos=opts.get('subrepos')) |
|
379 | 379 | |
|
380 | 380 | @command('backout', |
|
381 | 381 | [('', 'merge', None, _('merge with old dirstate parent after backout')), |
|
382 | 382 | ('', 'parent', '', |
|
383 | 383 | _('parent to choose when backing out merge (DEPRECATED)'), _('REV')), |
|
384 | 384 | ('r', 'rev', '', _('revision to backout'), _('REV')), |
|
385 | 385 | ] + mergetoolopts + walkopts + commitopts + commitopts2, |
|
386 | 386 | _('[OPTION]... [-r] REV')) |
|
387 | 387 | def backout(ui, repo, node=None, rev=None, **opts): |
|
388 | 388 | '''reverse effect of earlier changeset |
|
389 | 389 | |
|
390 | 390 | Prepare a new changeset with the effect of REV undone in the |
|
391 | 391 | current working directory. |
|
392 | 392 | |
|
393 | 393 | If REV is the parent of the working directory, then this new changeset |
|
394 | 394 | is committed automatically. Otherwise, hg needs to merge the |
|
395 | 395 | changes and the merged result is left uncommitted. |
|
396 | 396 | |
|
397 | 397 | .. note:: |
|
398 | 398 | backout cannot be used to fix either an unwanted or |
|
399 | 399 | incorrect merge. |
|
400 | 400 | |
|
401 | 401 | .. container:: verbose |
|
402 | 402 | |
|
403 | 403 | By default, the pending changeset will have one parent, |
|
404 | 404 | maintaining a linear history. With --merge, the pending |
|
405 | 405 | changeset will instead have two parents: the old parent of the |
|
406 | 406 | working directory and a new child of REV that simply undoes REV. |
|
407 | 407 | |
|
408 | 408 | Before version 1.7, the behavior without --merge was equivalent |
|
409 | 409 | to specifying --merge followed by :hg:`update --clean .` to |
|
410 | 410 | cancel the merge and leave the child of REV as a head to be |
|
411 | 411 | merged separately. |
|
412 | 412 | |
|
413 | 413 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
414 | 414 | |
|
415 | 415 | Returns 0 on success. |
|
416 | 416 | ''' |
|
417 | 417 | if rev and node: |
|
418 | 418 | raise util.Abort(_("please specify just one revision")) |
|
419 | 419 | |
|
420 | 420 | if not rev: |
|
421 | 421 | rev = node |
|
422 | 422 | |
|
423 | 423 | if not rev: |
|
424 | 424 | raise util.Abort(_("please specify a revision to backout")) |
|
425 | 425 | |
|
426 | 426 | date = opts.get('date') |
|
427 | 427 | if date: |
|
428 | 428 | opts['date'] = util.parsedate(date) |
|
429 | 429 | |
|
430 | 430 | cmdutil.bailifchanged(repo) |
|
431 | 431 | node = scmutil.revsingle(repo, rev).node() |
|
432 | 432 | |
|
433 | 433 | op1, op2 = repo.dirstate.parents() |
|
434 | 434 | a = repo.changelog.ancestor(op1, node) |
|
435 | 435 | if a != node: |
|
436 | 436 | raise util.Abort(_('cannot backout change on a different branch')) |
|
437 | 437 | |
|
438 | 438 | p1, p2 = repo.changelog.parents(node) |
|
439 | 439 | if p1 == nullid: |
|
440 | 440 | raise util.Abort(_('cannot backout a change with no parents')) |
|
441 | 441 | if p2 != nullid: |
|
442 | 442 | if not opts.get('parent'): |
|
443 | 443 | raise util.Abort(_('cannot backout a merge changeset')) |
|
444 | 444 | p = repo.lookup(opts['parent']) |
|
445 | 445 | if p not in (p1, p2): |
|
446 | 446 | raise util.Abort(_('%s is not a parent of %s') % |
|
447 | 447 | (short(p), short(node))) |
|
448 | 448 | parent = p |
|
449 | 449 | else: |
|
450 | 450 | if opts.get('parent'): |
|
451 | 451 | raise util.Abort(_('cannot use --parent on non-merge changeset')) |
|
452 | 452 | parent = p1 |
|
453 | 453 | |
|
454 | 454 | # the backout should appear on the same branch |
|
455 | 455 | wlock = repo.wlock() |
|
456 | 456 | try: |
|
457 | 457 | branch = repo.dirstate.branch() |
|
458 | 458 | hg.clean(repo, node, show_stats=False) |
|
459 | 459 | repo.dirstate.setbranch(branch) |
|
460 | 460 | revert_opts = opts.copy() |
|
461 | 461 | revert_opts['date'] = None |
|
462 | 462 | revert_opts['all'] = True |
|
463 | 463 | revert_opts['rev'] = hex(parent) |
|
464 | 464 | revert_opts['no_backup'] = None |
|
465 | 465 | revert(ui, repo, **revert_opts) |
|
466 | 466 | if not opts.get('merge') and op1 != node: |
|
467 | 467 | try: |
|
468 | 468 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
469 | 469 | return hg.update(repo, op1) |
|
470 | 470 | finally: |
|
471 | 471 | ui.setconfig('ui', 'forcemerge', '') |
|
472 | 472 | |
|
473 | 473 | commit_opts = opts.copy() |
|
474 | 474 | commit_opts['addremove'] = False |
|
475 | 475 | if not commit_opts['message'] and not commit_opts['logfile']: |
|
476 | 476 | # we don't translate commit messages |
|
477 | 477 | commit_opts['message'] = "Backed out changeset %s" % short(node) |
|
478 | 478 | commit_opts['force_editor'] = True |
|
479 | 479 | commit(ui, repo, **commit_opts) |
|
480 | 480 | def nice(node): |
|
481 | 481 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
482 | 482 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
483 | 483 | (nice(repo.changelog.tip()), nice(node))) |
|
484 | 484 | if opts.get('merge') and op1 != node: |
|
485 | 485 | hg.clean(repo, op1, show_stats=False) |
|
486 | 486 | ui.status(_('merging with changeset %s\n') |
|
487 | 487 | % nice(repo.changelog.tip())) |
|
488 | 488 | try: |
|
489 | 489 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
490 | 490 | return hg.merge(repo, hex(repo.changelog.tip())) |
|
491 | 491 | finally: |
|
492 | 492 | ui.setconfig('ui', 'forcemerge', '') |
|
493 | 493 | finally: |
|
494 | 494 | wlock.release() |
|
495 | 495 | return 0 |
|
496 | 496 | |
|
497 | 497 | @command('bisect', |
|
498 | 498 | [('r', 'reset', False, _('reset bisect state')), |
|
499 | 499 | ('g', 'good', False, _('mark changeset good')), |
|
500 | 500 | ('b', 'bad', False, _('mark changeset bad')), |
|
501 | 501 | ('s', 'skip', False, _('skip testing changeset')), |
|
502 | 502 | ('e', 'extend', False, _('extend the bisect range')), |
|
503 | 503 | ('c', 'command', '', _('use command to check changeset state'), _('CMD')), |
|
504 | 504 | ('U', 'noupdate', False, _('do not update to target'))], |
|
505 | 505 | _("[-gbsr] [-U] [-c CMD] [REV]")) |
|
506 | 506 | def bisect(ui, repo, rev=None, extra=None, command=None, |
|
507 | 507 | reset=None, good=None, bad=None, skip=None, extend=None, |
|
508 | 508 | noupdate=None): |
|
509 | 509 | """subdivision search of changesets |
|
510 | 510 | |
|
511 | 511 | This command helps to find changesets which introduce problems. To |
|
512 | 512 | use, mark the earliest changeset you know exhibits the problem as |
|
513 | 513 | bad, then mark the latest changeset which is free from the problem |
|
514 | 514 | as good. Bisect will update your working directory to a revision |
|
515 | 515 | for testing (unless the -U/--noupdate option is specified). Once |
|
516 | 516 | you have performed tests, mark the working directory as good or |
|
517 | 517 | bad, and bisect will either update to another candidate changeset |
|
518 | 518 | or announce that it has found the bad revision. |
|
519 | 519 | |
|
520 | 520 | As a shortcut, you can also use the revision argument to mark a |
|
521 | 521 | revision as good or bad without checking it out first. |
|
522 | 522 | |
|
523 | 523 | If you supply a command, it will be used for automatic bisection. |
|
524 | 524 | The environment variable HG_NODE will contain the ID of the |
|
525 | 525 | changeset being tested. The exit status of the command will be |
|
526 | 526 | used to mark revisions as good or bad: status 0 means good, 125 |
|
527 | 527 | means to skip the revision, 127 (command not found) will abort the |
|
528 | 528 | bisection, and any other non-zero exit status means the revision |
|
529 | 529 | is bad. |
|
530 | 530 | |
|
531 | 531 | .. container:: verbose |
|
532 | 532 | |
|
533 | 533 | Some examples: |
|
534 | 534 | |
|
535 | 535 | - start a bisection with known bad revision 12, and good revision 34:: |
|
536 | 536 | |
|
537 | 537 | hg bisect --bad 34 |
|
538 | 538 | hg bisect --good 12 |
|
539 | 539 | |
|
540 | 540 | - advance the current bisection by marking current revision as good or |
|
541 | 541 | bad:: |
|
542 | 542 | |
|
543 | 543 | hg bisect --good |
|
544 | 544 | hg bisect --bad |
|
545 | 545 | |
|
546 | 546 | - mark the current revision, or a known revision, to be skipped (eg. if |
|
547 | 547 | that revision is not usable because of another issue):: |
|
548 | 548 | |
|
549 | 549 | hg bisect --skip |
|
550 | 550 | hg bisect --skip 23 |
|
551 | 551 | |
|
552 | 552 | - forget the current bisection:: |
|
553 | 553 | |
|
554 | 554 | hg bisect --reset |
|
555 | 555 | |
|
556 | 556 | - use 'make && make tests' to automatically find the first broken |
|
557 | 557 | revision:: |
|
558 | 558 | |
|
559 | 559 | hg bisect --reset |
|
560 | 560 | hg bisect --bad 34 |
|
561 | 561 | hg bisect --good 12 |
|
562 | 562 | hg bisect --command 'make && make tests' |
|
563 | 563 | |
|
564 | 564 | - see all changesets whose states are already known in the current |
|
565 | 565 | bisection:: |
|
566 | 566 | |
|
567 | 567 | hg log -r "bisect(pruned)" |
|
568 | 568 | |
|
569 | 569 | - see the changeset currently being bisected (especially useful |
|
570 | 570 | if running with -U/--noupdate):: |
|
571 | 571 | |
|
572 | 572 | hg log -r "bisect(current)" |
|
573 | 573 | |
|
574 | 574 | - see all changesets that took part in the current bisection:: |
|
575 | 575 | |
|
576 | 576 | hg log -r "bisect(range)" |
|
577 | 577 | |
|
578 | 578 | - with the graphlog extension, you can even get a nice graph:: |
|
579 | 579 | |
|
580 | 580 | hg log --graph -r "bisect(range)" |
|
581 | 581 | |
|
582 | 582 | See :hg:`help revsets` for more about the `bisect()` keyword. |
|
583 | 583 | |
|
584 | 584 | Returns 0 on success. |
|
585 | 585 | """ |
|
586 | 586 | def extendbisectrange(nodes, good): |
|
587 | 587 | # bisect is incomplete when it ends on a merge node and |
|
588 | 588 | # one of the parent was not checked. |
|
589 | 589 | parents = repo[nodes[0]].parents() |
|
590 | 590 | if len(parents) > 1: |
|
591 | 591 | side = good and state['bad'] or state['good'] |
|
592 | 592 | num = len(set(i.node() for i in parents) & set(side)) |
|
593 | 593 | if num == 1: |
|
594 | 594 | return parents[0].ancestor(parents[1]) |
|
595 | 595 | return None |
|
596 | 596 | |
|
597 | 597 | def print_result(nodes, good): |
|
598 | 598 | displayer = cmdutil.show_changeset(ui, repo, {}) |
|
599 | 599 | if len(nodes) == 1: |
|
600 | 600 | # narrowed it down to a single revision |
|
601 | 601 | if good: |
|
602 | 602 | ui.write(_("The first good revision is:\n")) |
|
603 | 603 | else: |
|
604 | 604 | ui.write(_("The first bad revision is:\n")) |
|
605 | 605 | displayer.show(repo[nodes[0]]) |
|
606 | 606 | extendnode = extendbisectrange(nodes, good) |
|
607 | 607 | if extendnode is not None: |
|
608 | 608 | ui.write(_('Not all ancestors of this changeset have been' |
|
609 | 609 | ' checked.\nUse bisect --extend to continue the ' |
|
610 | 610 | 'bisection from\nthe common ancestor, %s.\n') |
|
611 | 611 | % extendnode) |
|
612 | 612 | else: |
|
613 | 613 | # multiple possible revisions |
|
614 | 614 | if good: |
|
615 | 615 | ui.write(_("Due to skipped revisions, the first " |
|
616 | 616 | "good revision could be any of:\n")) |
|
617 | 617 | else: |
|
618 | 618 | ui.write(_("Due to skipped revisions, the first " |
|
619 | 619 | "bad revision could be any of:\n")) |
|
620 | 620 | for n in nodes: |
|
621 | 621 | displayer.show(repo[n]) |
|
622 | 622 | displayer.close() |
|
623 | 623 | |
|
624 | 624 | def check_state(state, interactive=True): |
|
625 | 625 | if not state['good'] or not state['bad']: |
|
626 | 626 | if (good or bad or skip or reset) and interactive: |
|
627 | 627 | return |
|
628 | 628 | if not state['good']: |
|
629 | 629 | raise util.Abort(_('cannot bisect (no known good revisions)')) |
|
630 | 630 | else: |
|
631 | 631 | raise util.Abort(_('cannot bisect (no known bad revisions)')) |
|
632 | 632 | return True |
|
633 | 633 | |
|
634 | 634 | # backward compatibility |
|
635 | 635 | if rev in "good bad reset init".split(): |
|
636 | 636 | ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n")) |
|
637 | 637 | cmd, rev, extra = rev, extra, None |
|
638 | 638 | if cmd == "good": |
|
639 | 639 | good = True |
|
640 | 640 | elif cmd == "bad": |
|
641 | 641 | bad = True |
|
642 | 642 | else: |
|
643 | 643 | reset = True |
|
644 | 644 | elif extra or good + bad + skip + reset + extend + bool(command) > 1: |
|
645 | 645 | raise util.Abort(_('incompatible arguments')) |
|
646 | 646 | |
|
647 | 647 | if reset: |
|
648 | 648 | p = repo.join("bisect.state") |
|
649 | 649 | if os.path.exists(p): |
|
650 | 650 | os.unlink(p) |
|
651 | 651 | return |
|
652 | 652 | |
|
653 | 653 | state = hbisect.load_state(repo) |
|
654 | 654 | |
|
655 | 655 | if command: |
|
656 | 656 | changesets = 1 |
|
657 | 657 | try: |
|
658 | 658 | node = state['current'][0] |
|
659 | 659 | except LookupError: |
|
660 | 660 | if noupdate: |
|
661 | 661 | raise util.Abort(_('current bisect revision is unknown - ' |
|
662 | 662 | 'start a new bisect to fix')) |
|
663 | 663 | node, p2 = repo.dirstate.parents() |
|
664 | 664 | if p2 != nullid: |
|
665 | 665 | raise util.Abort(_('current bisect revision is a merge')) |
|
666 | 666 | try: |
|
667 | 667 | while changesets: |
|
668 | 668 | # update state |
|
669 | 669 | state['current'] = [node] |
|
670 | 670 | hbisect.save_state(repo, state) |
|
671 | 671 | status = util.system(command, |
|
672 | 672 | environ={'HG_NODE': hex(node)}, |
|
673 | 673 | out=ui.fout) |
|
674 | 674 | if status == 125: |
|
675 | 675 | transition = "skip" |
|
676 | 676 | elif status == 0: |
|
677 | 677 | transition = "good" |
|
678 | 678 | # status < 0 means process was killed |
|
679 | 679 | elif status == 127: |
|
680 | 680 | raise util.Abort(_("failed to execute %s") % command) |
|
681 | 681 | elif status < 0: |
|
682 | 682 | raise util.Abort(_("%s killed") % command) |
|
683 | 683 | else: |
|
684 | 684 | transition = "bad" |
|
685 | 685 | ctx = scmutil.revsingle(repo, rev, node) |
|
686 | 686 | rev = None # clear for future iterations |
|
687 | 687 | state[transition].append(ctx.node()) |
|
688 | 688 | ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
|
689 | 689 | check_state(state, interactive=False) |
|
690 | 690 | # bisect |
|
691 | 691 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
692 | 692 | # update to next check |
|
693 | 693 | node = nodes[0] |
|
694 | 694 | if not noupdate: |
|
695 | 695 | cmdutil.bailifchanged(repo) |
|
696 | 696 | hg.clean(repo, node, show_stats=False) |
|
697 | 697 | finally: |
|
698 | 698 | state['current'] = [node] |
|
699 | 699 | hbisect.save_state(repo, state) |
|
700 | 700 | print_result(nodes, good) |
|
701 | 701 | return |
|
702 | 702 | |
|
703 | 703 | # update state |
|
704 | 704 | |
|
705 | 705 | if rev: |
|
706 | 706 | nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])] |
|
707 | 707 | else: |
|
708 | 708 | nodes = [repo.lookup('.')] |
|
709 | 709 | |
|
710 | 710 | if good or bad or skip: |
|
711 | 711 | if good: |
|
712 | 712 | state['good'] += nodes |
|
713 | 713 | elif bad: |
|
714 | 714 | state['bad'] += nodes |
|
715 | 715 | elif skip: |
|
716 | 716 | state['skip'] += nodes |
|
717 | 717 | hbisect.save_state(repo, state) |
|
718 | 718 | |
|
719 | 719 | if not check_state(state): |
|
720 | 720 | return |
|
721 | 721 | |
|
722 | 722 | # actually bisect |
|
723 | 723 | nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
|
724 | 724 | if extend: |
|
725 | 725 | if not changesets: |
|
726 | 726 | extendnode = extendbisectrange(nodes, good) |
|
727 | 727 | if extendnode is not None: |
|
728 | 728 | ui.write(_("Extending search to changeset %d:%s\n" |
|
729 | 729 | % (extendnode.rev(), extendnode))) |
|
730 | 730 | state['current'] = [extendnode.node()] |
|
731 | 731 | hbisect.save_state(repo, state) |
|
732 | 732 | if noupdate: |
|
733 | 733 | return |
|
734 | 734 | cmdutil.bailifchanged(repo) |
|
735 | 735 | return hg.clean(repo, extendnode.node()) |
|
736 | 736 | raise util.Abort(_("nothing to extend")) |
|
737 | 737 | |
|
738 | 738 | if changesets == 0: |
|
739 | 739 | print_result(nodes, good) |
|
740 | 740 | else: |
|
741 | 741 | assert len(nodes) == 1 # only a single node can be tested next |
|
742 | 742 | node = nodes[0] |
|
743 | 743 | # compute the approximate number of remaining tests |
|
744 | 744 | tests, size = 0, 2 |
|
745 | 745 | while size <= changesets: |
|
746 | 746 | tests, size = tests + 1, size * 2 |
|
747 | 747 | rev = repo.changelog.rev(node) |
|
748 | 748 | ui.write(_("Testing changeset %d:%s " |
|
749 | 749 | "(%d changesets remaining, ~%d tests)\n") |
|
750 | 750 | % (rev, short(node), changesets, tests)) |
|
751 | 751 | state['current'] = [node] |
|
752 | 752 | hbisect.save_state(repo, state) |
|
753 | 753 | if not noupdate: |
|
754 | 754 | cmdutil.bailifchanged(repo) |
|
755 | 755 | return hg.clean(repo, node) |
|
756 | 756 | |
|
757 | 757 | @command('bookmarks', |
|
758 | 758 | [('f', 'force', False, _('force')), |
|
759 | 759 | ('r', 'rev', '', _('revision'), _('REV')), |
|
760 | 760 | ('d', 'delete', False, _('delete a given bookmark')), |
|
761 | 761 | ('m', 'rename', '', _('rename a given bookmark'), _('NAME')), |
|
762 | 762 | ('i', 'inactive', False, _('mark a bookmark inactive'))], |
|
763 | 763 | _('hg bookmarks [-f] [-d] [-i] [-m NAME] [-r REV] [NAME]')) |
|
764 | 764 | def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, |
|
765 | 765 | rename=None, inactive=False): |
|
766 | 766 | '''track a line of development with movable markers |
|
767 | 767 | |
|
768 | 768 | Bookmarks are pointers to certain commits that move when committing. |
|
769 | 769 | Bookmarks are local. They can be renamed, copied and deleted. It is |
|
770 | 770 | possible to use :hg:`merge NAME` to merge from a given bookmark, and |
|
771 | 771 | :hg:`update NAME` to update to a given bookmark. |
|
772 | 772 | |
|
773 | 773 | You can use :hg:`bookmark NAME` to set a bookmark on the working |
|
774 | 774 | directory's parent revision with the given name. If you specify |
|
775 | 775 | a revision using -r REV (where REV may be an existing bookmark), |
|
776 | 776 | the bookmark is assigned to that revision. |
|
777 | 777 | |
|
778 | 778 | Bookmarks can be pushed and pulled between repositories (see :hg:`help |
|
779 | 779 | push` and :hg:`help pull`). This requires both the local and remote |
|
780 | 780 | repositories to support bookmarks. For versions prior to 1.8, this means |
|
781 | 781 | the bookmarks extension must be enabled. |
|
782 | 782 | |
|
783 | 783 | With -i/--inactive, the new bookmark will not be made the active |
|
784 | 784 | bookmark. If -r/--rev is given, the new bookmark will not be made |
|
785 | 785 | active even if -i/--inactive is not given. If no NAME is given, the |
|
786 | 786 | current active bookmark will be marked inactive. |
|
787 | 787 | ''' |
|
788 | 788 | hexfn = ui.debugflag and hex or short |
|
789 | 789 | marks = repo._bookmarks |
|
790 | 790 | cur = repo.changectx('.').node() |
|
791 | 791 | |
|
792 | 792 | if delete: |
|
793 | 793 | if mark is None: |
|
794 | 794 | raise util.Abort(_("bookmark name required")) |
|
795 | 795 | if mark not in marks: |
|
796 | 796 | raise util.Abort(_("bookmark '%s' does not exist") % mark) |
|
797 | 797 | if mark == repo._bookmarkcurrent: |
|
798 | 798 | bookmarks.setcurrent(repo, None) |
|
799 | 799 | del marks[mark] |
|
800 | 800 | bookmarks.write(repo) |
|
801 | 801 | return |
|
802 | 802 | |
|
803 | 803 | if rename: |
|
804 | 804 | if rename not in marks: |
|
805 | 805 | raise util.Abort(_("bookmark '%s' does not exist") % rename) |
|
806 | 806 | if mark in marks and not force: |
|
807 | 807 | raise util.Abort(_("bookmark '%s' already exists " |
|
808 | 808 | "(use -f to force)") % mark) |
|
809 | 809 | if mark is None: |
|
810 | 810 | raise util.Abort(_("new bookmark name required")) |
|
811 | 811 | marks[mark] = marks[rename] |
|
812 | 812 | if repo._bookmarkcurrent == rename and not inactive: |
|
813 | 813 | bookmarks.setcurrent(repo, mark) |
|
814 | 814 | del marks[rename] |
|
815 | 815 | bookmarks.write(repo) |
|
816 | 816 | return |
|
817 | 817 | |
|
818 | 818 | if mark is not None: |
|
819 | 819 | if "\n" in mark: |
|
820 | 820 | raise util.Abort(_("bookmark name cannot contain newlines")) |
|
821 | 821 | mark = mark.strip() |
|
822 | 822 | if not mark: |
|
823 | 823 | raise util.Abort(_("bookmark names cannot consist entirely of " |
|
824 | 824 | "whitespace")) |
|
825 | 825 | if inactive and mark == repo._bookmarkcurrent: |
|
826 | 826 | bookmarks.setcurrent(repo, None) |
|
827 | 827 | return |
|
828 | 828 | if mark in marks and not force: |
|
829 | 829 | raise util.Abort(_("bookmark '%s' already exists " |
|
830 | 830 | "(use -f to force)") % mark) |
|
831 | 831 | if ((mark in repo.branchmap() or mark == repo.dirstate.branch()) |
|
832 | 832 | and not force): |
|
833 | 833 | raise util.Abort( |
|
834 | 834 | _("a bookmark cannot have the name of an existing branch")) |
|
835 | 835 | if rev: |
|
836 | 836 | marks[mark] = repo.lookup(rev) |
|
837 | 837 | else: |
|
838 | 838 | marks[mark] = cur |
|
839 | 839 | if not inactive and cur == marks[mark]: |
|
840 | 840 | bookmarks.setcurrent(repo, mark) |
|
841 | 841 | bookmarks.write(repo) |
|
842 | 842 | return |
|
843 | 843 | |
|
844 | 844 | if mark is None: |
|
845 | 845 | if rev: |
|
846 | 846 | raise util.Abort(_("bookmark name required")) |
|
847 | 847 | if len(marks) == 0: |
|
848 | 848 | ui.status(_("no bookmarks set\n")) |
|
849 | 849 | else: |
|
850 | 850 | for bmark, n in sorted(marks.iteritems()): |
|
851 | 851 | current = repo._bookmarkcurrent |
|
852 | 852 | if bmark == current and n == cur: |
|
853 | 853 | prefix, label = '*', 'bookmarks.current' |
|
854 | 854 | else: |
|
855 | 855 | prefix, label = ' ', '' |
|
856 | 856 | |
|
857 | 857 | if ui.quiet: |
|
858 | 858 | ui.write("%s\n" % bmark, label=label) |
|
859 | 859 | else: |
|
860 | 860 | ui.write(" %s %-25s %d:%s\n" % ( |
|
861 | 861 | prefix, bmark, repo.changelog.rev(n), hexfn(n)), |
|
862 | 862 | label=label) |
|
863 | 863 | return |
|
864 | 864 | |
|
865 | 865 | @command('branch', |
|
866 | 866 | [('f', 'force', None, |
|
867 | 867 | _('set branch name even if it shadows an existing branch')), |
|
868 | 868 | ('C', 'clean', None, _('reset branch name to parent branch name'))], |
|
869 | 869 | _('[-fC] [NAME]')) |
|
870 | 870 | def branch(ui, repo, label=None, **opts): |
|
871 | 871 | """set or show the current branch name |
|
872 | 872 | |
|
873 | 873 | .. note:: |
|
874 | 874 | Branch names are permanent and global. Use :hg:`bookmark` to create a |
|
875 | 875 | light-weight bookmark instead. See :hg:`help glossary` for more |
|
876 | 876 | information about named branches and bookmarks. |
|
877 | 877 | |
|
878 | 878 | With no argument, show the current branch name. With one argument, |
|
879 | 879 | set the working directory branch name (the branch will not exist |
|
880 | 880 | in the repository until the next commit). Standard practice |
|
881 | 881 | recommends that primary development take place on the 'default' |
|
882 | 882 | branch. |
|
883 | 883 | |
|
884 | 884 | Unless -f/--force is specified, branch will not let you set a |
|
885 | 885 | branch name that already exists, even if it's inactive. |
|
886 | 886 | |
|
887 | 887 | Use -C/--clean to reset the working directory branch to that of |
|
888 | 888 | the parent of the working directory, negating a previous branch |
|
889 | 889 | change. |
|
890 | 890 | |
|
891 | 891 | Use the command :hg:`update` to switch to an existing branch. Use |
|
892 | 892 | :hg:`commit --close-branch` to mark this branch as closed. |
|
893 | 893 | |
|
894 | 894 | Returns 0 on success. |
|
895 | 895 | """ |
|
896 | 896 | if not opts.get('clean') and not label: |
|
897 | 897 | ui.write("%s\n" % repo.dirstate.branch()) |
|
898 | 898 | return |
|
899 | 899 | |
|
900 | 900 | wlock = repo.wlock() |
|
901 | 901 | try: |
|
902 | 902 | if opts.get('clean'): |
|
903 | 903 | label = repo[None].p1().branch() |
|
904 | 904 | repo.dirstate.setbranch(label) |
|
905 | 905 | ui.status(_('reset working directory to branch %s\n') % label) |
|
906 | 906 | elif label: |
|
907 | 907 | if not opts.get('force') and label in repo.branchmap(): |
|
908 | 908 | if label not in [p.branch() for p in repo.parents()]: |
|
909 | 909 | raise util.Abort(_('a branch of the same name already' |
|
910 | 910 | ' exists'), |
|
911 | 911 | # i18n: "it" refers to an existing branch |
|
912 | 912 | hint=_("use 'hg update' to switch to it")) |
|
913 | 913 | repo.dirstate.setbranch(label) |
|
914 | 914 | ui.status(_('marked working directory as branch %s\n') % label) |
|
915 | 915 | ui.status(_('(branches are permanent and global, ' |
|
916 | 916 | 'did you want a bookmark?)\n')) |
|
917 | 917 | finally: |
|
918 | 918 | wlock.release() |
|
919 | 919 | |
|
920 | 920 | @command('branches', |
|
921 | 921 | [('a', 'active', False, _('show only branches that have unmerged heads')), |
|
922 | 922 | ('c', 'closed', False, _('show normal and closed branches'))], |
|
923 | 923 | _('[-ac]')) |
|
924 | 924 | def branches(ui, repo, active=False, closed=False): |
|
925 | 925 | """list repository named branches |
|
926 | 926 | |
|
927 | 927 | List the repository's named branches, indicating which ones are |
|
928 | 928 | inactive. If -c/--closed is specified, also list branches which have |
|
929 | 929 | been marked closed (see :hg:`commit --close-branch`). |
|
930 | 930 | |
|
931 | 931 | If -a/--active is specified, only show active branches. A branch |
|
932 | 932 | is considered active if it contains repository heads. |
|
933 | 933 | |
|
934 | 934 | Use the command :hg:`update` to switch to an existing branch. |
|
935 | 935 | |
|
936 | 936 | Returns 0. |
|
937 | 937 | """ |
|
938 | 938 | |
|
939 | 939 | hexfunc = ui.debugflag and hex or short |
|
940 | 940 | |
|
941 | 941 | activebranches = set([repo[n].branch() for n in repo.heads()]) |
|
942 | 942 | branches = [] |
|
943 | 943 | for tag, heads in repo.branchmap().iteritems(): |
|
944 | 944 | for h in reversed(heads): |
|
945 | 945 | ctx = repo[h] |
|
946 | 946 | isopen = not ctx.closesbranch() |
|
947 | 947 | if isopen: |
|
948 | 948 | tip = ctx |
|
949 | 949 | break |
|
950 | 950 | else: |
|
951 | 951 | tip = repo[heads[-1]] |
|
952 | 952 | isactive = tag in activebranches and isopen |
|
953 | 953 | branches.append((tip, isactive, isopen)) |
|
954 | 954 | branches.sort(key=lambda i: (i[1], i[0].rev(), i[0].branch(), i[2]), |
|
955 | 955 | reverse=True) |
|
956 | 956 | |
|
957 | 957 | for ctx, isactive, isopen in branches: |
|
958 | 958 | if (not active) or isactive: |
|
959 | 959 | if isactive: |
|
960 | 960 | label = 'branches.active' |
|
961 | 961 | notice = '' |
|
962 | 962 | elif not isopen: |
|
963 | 963 | if not closed: |
|
964 | 964 | continue |
|
965 | 965 | label = 'branches.closed' |
|
966 | 966 | notice = _(' (closed)') |
|
967 | 967 | else: |
|
968 | 968 | label = 'branches.inactive' |
|
969 | 969 | notice = _(' (inactive)') |
|
970 | 970 | if ctx.branch() == repo.dirstate.branch(): |
|
971 | 971 | label = 'branches.current' |
|
972 | 972 | rev = str(ctx.rev()).rjust(31 - encoding.colwidth(ctx.branch())) |
|
973 | 973 | rev = ui.label('%s:%s' % (rev, hexfunc(ctx.node())), |
|
974 | 974 | 'log.changeset') |
|
975 | 975 | tag = ui.label(ctx.branch(), label) |
|
976 | 976 | if ui.quiet: |
|
977 | 977 | ui.write("%s\n" % tag) |
|
978 | 978 | else: |
|
979 | 979 | ui.write("%s %s%s\n" % (tag, rev, notice)) |
|
980 | 980 | |
|
981 | 981 | @command('bundle', |
|
982 | 982 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
983 | 983 | ('r', 'rev', [], _('a changeset intended to be added to the destination'), |
|
984 | 984 | _('REV')), |
|
985 | 985 | ('b', 'branch', [], _('a specific branch you would like to bundle'), |
|
986 | 986 | _('BRANCH')), |
|
987 | 987 | ('', 'base', [], |
|
988 | 988 | _('a base changeset assumed to be available at the destination'), |
|
989 | 989 | _('REV')), |
|
990 | 990 | ('a', 'all', None, _('bundle all changesets in the repository')), |
|
991 | 991 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')), |
|
992 | 992 | ] + remoteopts, |
|
993 | 993 | _('[-f] [-t TYPE] [-a] [-r REV]... [--base REV]... FILE [DEST]')) |
|
994 | 994 | def bundle(ui, repo, fname, dest=None, **opts): |
|
995 | 995 | """create a changegroup file |
|
996 | 996 | |
|
997 | 997 | Generate a compressed changegroup file collecting changesets not |
|
998 | 998 | known to be in another repository. |
|
999 | 999 | |
|
1000 | 1000 | If you omit the destination repository, then hg assumes the |
|
1001 | 1001 | destination will have all the nodes you specify with --base |
|
1002 | 1002 | parameters. To create a bundle containing all changesets, use |
|
1003 | 1003 | -a/--all (or --base null). |
|
1004 | 1004 | |
|
1005 | 1005 | You can change compression method with the -t/--type option. |
|
1006 | 1006 | The available compression methods are: none, bzip2, and |
|
1007 | 1007 | gzip (by default, bundles are compressed using bzip2). |
|
1008 | 1008 | |
|
1009 | 1009 | The bundle file can then be transferred using conventional means |
|
1010 | 1010 | and applied to another repository with the unbundle or pull |
|
1011 | 1011 | command. This is useful when direct push and pull are not |
|
1012 | 1012 | available or when exporting an entire repository is undesirable. |
|
1013 | 1013 | |
|
1014 | 1014 | Applying bundles preserves all changeset contents including |
|
1015 | 1015 | permissions, copy/rename information, and revision history. |
|
1016 | 1016 | |
|
1017 | 1017 | Returns 0 on success, 1 if no changes found. |
|
1018 | 1018 | """ |
|
1019 | 1019 | revs = None |
|
1020 | 1020 | if 'rev' in opts: |
|
1021 | 1021 | revs = scmutil.revrange(repo, opts['rev']) |
|
1022 | 1022 | |
|
1023 | 1023 | bundletype = opts.get('type', 'bzip2').lower() |
|
1024 | 1024 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} |
|
1025 | 1025 | bundletype = btypes.get(bundletype) |
|
1026 | 1026 | if bundletype not in changegroup.bundletypes: |
|
1027 | 1027 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
1028 | 1028 | |
|
1029 | 1029 | if opts.get('all'): |
|
1030 | 1030 | base = ['null'] |
|
1031 | 1031 | else: |
|
1032 | 1032 | base = scmutil.revrange(repo, opts.get('base')) |
|
1033 | 1033 | if base: |
|
1034 | 1034 | if dest: |
|
1035 | 1035 | raise util.Abort(_("--base is incompatible with specifying " |
|
1036 | 1036 | "a destination")) |
|
1037 | 1037 | common = [repo.lookup(rev) for rev in base] |
|
1038 | 1038 | heads = revs and map(repo.lookup, revs) or revs |
|
1039 | 1039 | cg = repo.getbundle('bundle', heads=heads, common=common) |
|
1040 | 1040 | outgoing = None |
|
1041 | 1041 | else: |
|
1042 | 1042 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
1043 | 1043 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
1044 | 1044 | other = hg.peer(repo, opts, dest) |
|
1045 | 1045 | revs, checkout = hg.addbranchrevs(repo, other, branches, revs) |
|
1046 | 1046 | heads = revs and map(repo.lookup, revs) or revs |
|
1047 | 1047 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
1048 | 1048 | onlyheads=heads, |
|
1049 | 1049 | force=opts.get('force'), |
|
1050 | 1050 | portable=True) |
|
1051 | 1051 | cg = repo.getlocalbundle('bundle', outgoing) |
|
1052 | 1052 | if not cg: |
|
1053 | 1053 | scmutil.nochangesfound(ui, outgoing and outgoing.excluded) |
|
1054 | 1054 | return 1 |
|
1055 | 1055 | |
|
1056 | 1056 | changegroup.writebundle(cg, fname, bundletype) |
|
1057 | 1057 | |
|
1058 | 1058 | @command('cat', |
|
1059 | 1059 | [('o', 'output', '', |
|
1060 | 1060 | _('print output to file with formatted name'), _('FORMAT')), |
|
1061 | 1061 | ('r', 'rev', '', _('print the given revision'), _('REV')), |
|
1062 | 1062 | ('', 'decode', None, _('apply any matching decode filter')), |
|
1063 | 1063 | ] + walkopts, |
|
1064 | 1064 | _('[OPTION]... FILE...')) |
|
1065 | 1065 | def cat(ui, repo, file1, *pats, **opts): |
|
1066 | 1066 | """output the current or given revision of files |
|
1067 | 1067 | |
|
1068 | 1068 | Print the specified files as they were at the given revision. If |
|
1069 | 1069 | no revision is given, the parent of the working directory is used, |
|
1070 | 1070 | or tip if no revision is checked out. |
|
1071 | 1071 | |
|
1072 | 1072 | Output may be to a file, in which case the name of the file is |
|
1073 | 1073 | given using a format string. The formatting rules are the same as |
|
1074 | 1074 | for the export command, with the following additions: |
|
1075 | 1075 | |
|
1076 | 1076 | :``%s``: basename of file being printed |
|
1077 | 1077 | :``%d``: dirname of file being printed, or '.' if in repository root |
|
1078 | 1078 | :``%p``: root-relative path name of file being printed |
|
1079 | 1079 | |
|
1080 | 1080 | Returns 0 on success. |
|
1081 | 1081 | """ |
|
1082 | 1082 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1083 | 1083 | err = 1 |
|
1084 | 1084 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1085 | 1085 | for abs in ctx.walk(m): |
|
1086 | 1086 | fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(), |
|
1087 | 1087 | pathname=abs) |
|
1088 | 1088 | data = ctx[abs].data() |
|
1089 | 1089 | if opts.get('decode'): |
|
1090 | 1090 | data = repo.wwritedata(abs, data) |
|
1091 | 1091 | fp.write(data) |
|
1092 | 1092 | fp.close() |
|
1093 | 1093 | err = 0 |
|
1094 | 1094 | return err |
|
1095 | 1095 | |
|
1096 | 1096 | @command('^clone', |
|
1097 | 1097 | [('U', 'noupdate', None, |
|
1098 | 1098 | _('the clone will include an empty working copy (only a repository)')), |
|
1099 | 1099 | ('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')), |
|
1100 | 1100 | ('r', 'rev', [], _('include the specified changeset'), _('REV')), |
|
1101 | 1101 | ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')), |
|
1102 | 1102 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
1103 | 1103 | ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')), |
|
1104 | 1104 | ] + remoteopts, |
|
1105 | 1105 | _('[OPTION]... SOURCE [DEST]')) |
|
1106 | 1106 | def clone(ui, source, dest=None, **opts): |
|
1107 | 1107 | """make a copy of an existing repository |
|
1108 | 1108 | |
|
1109 | 1109 | Create a copy of an existing repository in a new directory. |
|
1110 | 1110 | |
|
1111 | 1111 | If no destination directory name is specified, it defaults to the |
|
1112 | 1112 | basename of the source. |
|
1113 | 1113 | |
|
1114 | 1114 | The location of the source is added to the new repository's |
|
1115 | 1115 | ``.hg/hgrc`` file, as the default to be used for future pulls. |
|
1116 | 1116 | |
|
1117 | 1117 | Only local paths and ``ssh://`` URLs are supported as |
|
1118 | 1118 | destinations. For ``ssh://`` destinations, no working directory or |
|
1119 | 1119 | ``.hg/hgrc`` will be created on the remote side. |
|
1120 | 1120 | |
|
1121 | 1121 | To pull only a subset of changesets, specify one or more revisions |
|
1122 | 1122 | identifiers with -r/--rev or branches with -b/--branch. The |
|
1123 | 1123 | resulting clone will contain only the specified changesets and |
|
1124 | 1124 | their ancestors. These options (or 'clone src#rev dest') imply |
|
1125 | 1125 | --pull, even for local source repositories. Note that specifying a |
|
1126 | 1126 | tag will include the tagged changeset but not the changeset |
|
1127 | 1127 | containing the tag. |
|
1128 | 1128 | |
|
1129 | 1129 | To check out a particular version, use -u/--update, or |
|
1130 | 1130 | -U/--noupdate to create a clone with no working directory. |
|
1131 | 1131 | |
|
1132 | 1132 | .. container:: verbose |
|
1133 | 1133 | |
|
1134 | 1134 | For efficiency, hardlinks are used for cloning whenever the |
|
1135 | 1135 | source and destination are on the same filesystem (note this |
|
1136 | 1136 | applies only to the repository data, not to the working |
|
1137 | 1137 | directory). Some filesystems, such as AFS, implement hardlinking |
|
1138 | 1138 | incorrectly, but do not report errors. In these cases, use the |
|
1139 | 1139 | --pull option to avoid hardlinking. |
|
1140 | 1140 | |
|
1141 | 1141 | In some cases, you can clone repositories and the working |
|
1142 | 1142 | directory using full hardlinks with :: |
|
1143 | 1143 | |
|
1144 | 1144 | $ cp -al REPO REPOCLONE |
|
1145 | 1145 | |
|
1146 | 1146 | This is the fastest way to clone, but it is not always safe. The |
|
1147 | 1147 | operation is not atomic (making sure REPO is not modified during |
|
1148 | 1148 | the operation is up to you) and you have to make sure your |
|
1149 | 1149 | editor breaks hardlinks (Emacs and most Linux Kernel tools do |
|
1150 | 1150 | so). Also, this is not compatible with certain extensions that |
|
1151 | 1151 | place their metadata under the .hg directory, such as mq. |
|
1152 | 1152 | |
|
1153 | 1153 | Mercurial will update the working directory to the first applicable |
|
1154 | 1154 | revision from this list: |
|
1155 | 1155 | |
|
1156 | 1156 | a) null if -U or the source repository has no changesets |
|
1157 | 1157 | b) if -u . and the source repository is local, the first parent of |
|
1158 | 1158 | the source repository's working directory |
|
1159 | 1159 | c) the changeset specified with -u (if a branch name, this means the |
|
1160 | 1160 | latest head of that branch) |
|
1161 | 1161 | d) the changeset specified with -r |
|
1162 | 1162 | e) the tipmost head specified with -b |
|
1163 | 1163 | f) the tipmost head specified with the url#branch source syntax |
|
1164 | 1164 | g) the tipmost head of the default branch |
|
1165 | 1165 | h) tip |
|
1166 | 1166 | |
|
1167 | 1167 | Examples: |
|
1168 | 1168 | |
|
1169 | 1169 | - clone a remote repository to a new directory named hg/:: |
|
1170 | 1170 | |
|
1171 | 1171 | hg clone http://selenic.com/hg |
|
1172 | 1172 | |
|
1173 | 1173 | - create a lightweight local clone:: |
|
1174 | 1174 | |
|
1175 | 1175 | hg clone project/ project-feature/ |
|
1176 | 1176 | |
|
1177 | 1177 | - clone from an absolute path on an ssh server (note double-slash):: |
|
1178 | 1178 | |
|
1179 | 1179 | hg clone ssh://user@server//home/projects/alpha/ |
|
1180 | 1180 | |
|
1181 | 1181 | - do a high-speed clone over a LAN while checking out a |
|
1182 | 1182 | specified version:: |
|
1183 | 1183 | |
|
1184 | 1184 | hg clone --uncompressed http://server/repo -u 1.5 |
|
1185 | 1185 | |
|
1186 | 1186 | - create a repository without changesets after a particular revision:: |
|
1187 | 1187 | |
|
1188 | 1188 | hg clone -r 04e544 experimental/ good/ |
|
1189 | 1189 | |
|
1190 | 1190 | - clone (and track) a particular named branch:: |
|
1191 | 1191 | |
|
1192 | 1192 | hg clone http://selenic.com/hg#stable |
|
1193 | 1193 | |
|
1194 | 1194 | See :hg:`help urls` for details on specifying URLs. |
|
1195 | 1195 | |
|
1196 | 1196 | Returns 0 on success. |
|
1197 | 1197 | """ |
|
1198 | 1198 | if opts.get('noupdate') and opts.get('updaterev'): |
|
1199 | 1199 | raise util.Abort(_("cannot specify both --noupdate and --updaterev")) |
|
1200 | 1200 | |
|
1201 | 1201 | r = hg.clone(ui, opts, source, dest, |
|
1202 | 1202 | pull=opts.get('pull'), |
|
1203 | 1203 | stream=opts.get('uncompressed'), |
|
1204 | 1204 | rev=opts.get('rev'), |
|
1205 | 1205 | update=opts.get('updaterev') or not opts.get('noupdate'), |
|
1206 | 1206 | branch=opts.get('branch')) |
|
1207 | 1207 | |
|
1208 | 1208 | return r is None |
|
1209 | 1209 | |
|
1210 | 1210 | @command('^commit|ci', |
|
1211 | 1211 | [('A', 'addremove', None, |
|
1212 | 1212 | _('mark new/missing files as added/removed before committing')), |
|
1213 | 1213 | ('', 'close-branch', None, |
|
1214 | 1214 | _('mark a branch as closed, hiding it from the branch list')), |
|
1215 | 1215 | ('', 'amend', None, _('amend the parent of the working dir')), |
|
1216 | 1216 | ] + walkopts + commitopts + commitopts2 + subrepoopts, |
|
1217 | 1217 | _('[OPTION]... [FILE]...')) |
|
1218 | 1218 | def commit(ui, repo, *pats, **opts): |
|
1219 | 1219 | """commit the specified files or all outstanding changes |
|
1220 | 1220 | |
|
1221 | 1221 | Commit changes to the given files into the repository. Unlike a |
|
1222 | 1222 | centralized SCM, this operation is a local operation. See |
|
1223 | 1223 | :hg:`push` for a way to actively distribute your changes. |
|
1224 | 1224 | |
|
1225 | 1225 | If a list of files is omitted, all changes reported by :hg:`status` |
|
1226 | 1226 | will be committed. |
|
1227 | 1227 | |
|
1228 | 1228 | If you are committing the result of a merge, do not provide any |
|
1229 | 1229 | filenames or -I/-X filters. |
|
1230 | 1230 | |
|
1231 | 1231 | If no commit message is specified, Mercurial starts your |
|
1232 | 1232 | configured editor where you can enter a message. In case your |
|
1233 | 1233 | commit fails, you will find a backup of your message in |
|
1234 | 1234 | ``.hg/last-message.txt``. |
|
1235 | 1235 | |
|
1236 | 1236 | The --amend flag can be used to amend the parent of the |
|
1237 | 1237 | working directory with a new commit that contains the changes |
|
1238 | 1238 | in the parent in addition to those currently reported by :hg:`status`, |
|
1239 | 1239 | if there are any. The old commit is stored in a backup bundle in |
|
1240 | 1240 | ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle` |
|
1241 | 1241 | on how to restore it). |
|
1242 | 1242 | |
|
1243 | 1243 | Message, user and date are taken from the amended commit unless |
|
1244 | 1244 | specified. When a message isn't specified on the command line, |
|
1245 | 1245 | the editor will open with the message of the amended commit. |
|
1246 | 1246 | |
|
1247 | 1247 | It is not possible to amend public changesets (see :hg:`help phases`) |
|
1248 | 1248 | or changesets that have children. |
|
1249 | 1249 | |
|
1250 | 1250 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
1251 | 1251 | |
|
1252 | 1252 | Returns 0 on success, 1 if nothing changed. |
|
1253 | 1253 | """ |
|
1254 | 1254 | if opts.get('subrepos'): |
|
1255 | 1255 | # Let --subrepos on the command line overide config setting. |
|
1256 | 1256 | ui.setconfig('ui', 'commitsubrepos', True) |
|
1257 | 1257 | |
|
1258 | 1258 | extra = {} |
|
1259 | 1259 | if opts.get('close_branch'): |
|
1260 | 1260 | if repo['.'].node() not in repo.branchheads(): |
|
1261 | 1261 | # The topo heads set is included in the branch heads set of the |
|
1262 | 1262 | # current branch, so it's sufficient to test branchheads |
|
1263 | 1263 | raise util.Abort(_('can only close branch heads')) |
|
1264 | 1264 | extra['close'] = 1 |
|
1265 | 1265 | |
|
1266 | 1266 | branch = repo[None].branch() |
|
1267 | 1267 | bheads = repo.branchheads(branch) |
|
1268 | 1268 | |
|
1269 | 1269 | if opts.get('amend'): |
|
1270 | 1270 | if ui.configbool('ui', 'commitsubrepos'): |
|
1271 | 1271 | raise util.Abort(_('cannot amend recursively')) |
|
1272 | 1272 | |
|
1273 | 1273 | old = repo['.'] |
|
1274 | 1274 | if old.phase() == phases.public: |
|
1275 | 1275 | raise util.Abort(_('cannot amend public changesets')) |
|
1276 | 1276 | if len(old.parents()) > 1: |
|
1277 | 1277 | raise util.Abort(_('cannot amend merge changesets')) |
|
1278 | 1278 | if len(repo[None].parents()) > 1: |
|
1279 | 1279 | raise util.Abort(_('cannot amend while merging')) |
|
1280 | 1280 | if old.children(): |
|
1281 | 1281 | raise util.Abort(_('cannot amend changeset with children')) |
|
1282 | 1282 | |
|
1283 | 1283 | e = cmdutil.commiteditor |
|
1284 | 1284 | if opts.get('force_editor'): |
|
1285 | 1285 | e = cmdutil.commitforceeditor |
|
1286 | 1286 | |
|
1287 | 1287 | def commitfunc(ui, repo, message, match, opts): |
|
1288 | 1288 | editor = e |
|
1289 | 1289 | # message contains text from -m or -l, if it's empty, |
|
1290 | 1290 | # open the editor with the old message |
|
1291 | 1291 | if not message: |
|
1292 | 1292 | message = old.description() |
|
1293 | 1293 | editor = cmdutil.commitforceeditor |
|
1294 | 1294 | return repo.commit(message, |
|
1295 | 1295 | opts.get('user') or old.user(), |
|
1296 | 1296 | opts.get('date') or old.date(), |
|
1297 | 1297 | match, |
|
1298 | 1298 | editor=editor, |
|
1299 | 1299 | extra=extra) |
|
1300 | 1300 | |
|
1301 | 1301 | node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts) |
|
1302 | 1302 | if node == old.node(): |
|
1303 | 1303 | ui.status(_("nothing changed\n")) |
|
1304 | 1304 | return 1 |
|
1305 | 1305 | else: |
|
1306 | 1306 | e = cmdutil.commiteditor |
|
1307 | 1307 | if opts.get('force_editor'): |
|
1308 | 1308 | e = cmdutil.commitforceeditor |
|
1309 | 1309 | |
|
1310 | 1310 | def commitfunc(ui, repo, message, match, opts): |
|
1311 | 1311 | return repo.commit(message, opts.get('user'), opts.get('date'), |
|
1312 | 1312 | match, editor=e, extra=extra) |
|
1313 | 1313 | |
|
1314 | 1314 | node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
|
1315 | 1315 | |
|
1316 | 1316 | if not node: |
|
1317 | 1317 | stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |
|
1318 | 1318 | if stat[3]: |
|
1319 | 1319 | ui.status(_("nothing changed (%d missing files, see " |
|
1320 | 1320 | "'hg status')\n") % len(stat[3])) |
|
1321 | 1321 | else: |
|
1322 | 1322 | ui.status(_("nothing changed\n")) |
|
1323 | 1323 | return 1 |
|
1324 | 1324 | |
|
1325 | 1325 | ctx = repo[node] |
|
1326 | 1326 | parents = ctx.parents() |
|
1327 | 1327 | |
|
1328 | 1328 | if (not opts.get('amend') and bheads and node not in bheads and not |
|
1329 | 1329 | [x for x in parents if x.node() in bheads and x.branch() == branch]): |
|
1330 | 1330 | ui.status(_('created new head\n')) |
|
1331 | 1331 | # The message is not printed for initial roots. For the other |
|
1332 | 1332 | # changesets, it is printed in the following situations: |
|
1333 | 1333 | # |
|
1334 | 1334 | # Par column: for the 2 parents with ... |
|
1335 | 1335 | # N: null or no parent |
|
1336 | 1336 | # B: parent is on another named branch |
|
1337 | 1337 | # C: parent is a regular non head changeset |
|
1338 | 1338 | # H: parent was a branch head of the current branch |
|
1339 | 1339 | # Msg column: whether we print "created new head" message |
|
1340 | 1340 | # In the following, it is assumed that there already exists some |
|
1341 | 1341 | # initial branch heads of the current branch, otherwise nothing is |
|
1342 | 1342 | # printed anyway. |
|
1343 | 1343 | # |
|
1344 | 1344 | # Par Msg Comment |
|
1345 | 1345 | # NN y additional topo root |
|
1346 | 1346 | # |
|
1347 | 1347 | # BN y additional branch root |
|
1348 | 1348 | # CN y additional topo head |
|
1349 | 1349 | # HN n usual case |
|
1350 | 1350 | # |
|
1351 | 1351 | # BB y weird additional branch root |
|
1352 | 1352 | # CB y branch merge |
|
1353 | 1353 | # HB n merge with named branch |
|
1354 | 1354 | # |
|
1355 | 1355 | # CC y additional head from merge |
|
1356 | 1356 | # CH n merge with a head |
|
1357 | 1357 | # |
|
1358 | 1358 | # HH n head merge: head count decreases |
|
1359 | 1359 | |
|
1360 | 1360 | if not opts.get('close_branch'): |
|
1361 | 1361 | for r in parents: |
|
1362 | 1362 | if r.closesbranch() and r.branch() == branch: |
|
1363 | 1363 | ui.status(_('reopening closed branch head %d\n') % r) |
|
1364 | 1364 | |
|
1365 | 1365 | if ui.debugflag: |
|
1366 | 1366 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx.hex())) |
|
1367 | 1367 | elif ui.verbose: |
|
1368 | 1368 | ui.write(_('committed changeset %d:%s\n') % (int(ctx), ctx)) |
|
1369 | 1369 | |
|
1370 | 1370 | @command('copy|cp', |
|
1371 | 1371 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
1372 | 1372 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
1373 | 1373 | ] + walkopts + dryrunopts, |
|
1374 | 1374 | _('[OPTION]... [SOURCE]... DEST')) |
|
1375 | 1375 | def copy(ui, repo, *pats, **opts): |
|
1376 | 1376 | """mark files as copied for the next commit |
|
1377 | 1377 | |
|
1378 | 1378 | Mark dest as having copies of source files. If dest is a |
|
1379 | 1379 | directory, copies are put in that directory. If dest is a file, |
|
1380 | 1380 | the source must be a single file. |
|
1381 | 1381 | |
|
1382 | 1382 | By default, this command copies the contents of files as they |
|
1383 | 1383 | exist in the working directory. If invoked with -A/--after, the |
|
1384 | 1384 | operation is recorded, but no copying is performed. |
|
1385 | 1385 | |
|
1386 | 1386 | This command takes effect with the next commit. To undo a copy |
|
1387 | 1387 | before that, see :hg:`revert`. |
|
1388 | 1388 | |
|
1389 | 1389 | Returns 0 on success, 1 if errors are encountered. |
|
1390 | 1390 | """ |
|
1391 | 1391 | wlock = repo.wlock(False) |
|
1392 | 1392 | try: |
|
1393 | 1393 | return cmdutil.copy(ui, repo, pats, opts) |
|
1394 | 1394 | finally: |
|
1395 | 1395 | wlock.release() |
|
1396 | 1396 | |
|
1397 | 1397 | @command('debugancestor', [], _('[INDEX] REV1 REV2')) |
|
1398 | 1398 | def debugancestor(ui, repo, *args): |
|
1399 | 1399 | """find the ancestor revision of two revisions in a given index""" |
|
1400 | 1400 | if len(args) == 3: |
|
1401 | 1401 | index, rev1, rev2 = args |
|
1402 | 1402 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index) |
|
1403 | 1403 | lookup = r.lookup |
|
1404 | 1404 | elif len(args) == 2: |
|
1405 | 1405 | if not repo: |
|
1406 | 1406 | raise util.Abort(_("there is no Mercurial repository here " |
|
1407 | 1407 | "(.hg not found)")) |
|
1408 | 1408 | rev1, rev2 = args |
|
1409 | 1409 | r = repo.changelog |
|
1410 | 1410 | lookup = repo.lookup |
|
1411 | 1411 | else: |
|
1412 | 1412 | raise util.Abort(_('either two or three arguments required')) |
|
1413 | 1413 | a = r.ancestor(lookup(rev1), lookup(rev2)) |
|
1414 | 1414 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1415 | 1415 | |
|
1416 | 1416 | @command('debugbuilddag', |
|
1417 | 1417 | [('m', 'mergeable-file', None, _('add single file mergeable changes')), |
|
1418 | 1418 | ('o', 'overwritten-file', None, _('add single file all revs overwrite')), |
|
1419 | 1419 | ('n', 'new-file', None, _('add new file at each rev'))], |
|
1420 | 1420 | _('[OPTION]... [TEXT]')) |
|
1421 | 1421 | def debugbuilddag(ui, repo, text=None, |
|
1422 | 1422 | mergeable_file=False, |
|
1423 | 1423 | overwritten_file=False, |
|
1424 | 1424 | new_file=False): |
|
1425 | 1425 | """builds a repo with a given DAG from scratch in the current empty repo |
|
1426 | 1426 | |
|
1427 | 1427 | The description of the DAG is read from stdin if not given on the |
|
1428 | 1428 | command line. |
|
1429 | 1429 | |
|
1430 | 1430 | Elements: |
|
1431 | 1431 | |
|
1432 | 1432 | - "+n" is a linear run of n nodes based on the current default parent |
|
1433 | 1433 | - "." is a single node based on the current default parent |
|
1434 | 1434 | - "$" resets the default parent to null (implied at the start); |
|
1435 | 1435 | otherwise the default parent is always the last node created |
|
1436 | 1436 | - "<p" sets the default parent to the backref p |
|
1437 | 1437 | - "*p" is a fork at parent p, which is a backref |
|
1438 | 1438 | - "*p1/p2" is a merge of parents p1 and p2, which are backrefs |
|
1439 | 1439 | - "/p2" is a merge of the preceding node and p2 |
|
1440 | 1440 | - ":tag" defines a local tag for the preceding node |
|
1441 | 1441 | - "@branch" sets the named branch for subsequent nodes |
|
1442 | 1442 | - "#...\\n" is a comment up to the end of the line |
|
1443 | 1443 | |
|
1444 | 1444 | Whitespace between the above elements is ignored. |
|
1445 | 1445 | |
|
1446 | 1446 | A backref is either |
|
1447 | 1447 | |
|
1448 | 1448 | - a number n, which references the node curr-n, where curr is the current |
|
1449 | 1449 | node, or |
|
1450 | 1450 | - the name of a local tag you placed earlier using ":tag", or |
|
1451 | 1451 | - empty to denote the default parent. |
|
1452 | 1452 | |
|
1453 | 1453 | All string valued-elements are either strictly alphanumeric, or must |
|
1454 | 1454 | be enclosed in double quotes ("..."), with "\\" as escape character. |
|
1455 | 1455 | """ |
|
1456 | 1456 | |
|
1457 | 1457 | if text is None: |
|
1458 | 1458 | ui.status(_("reading DAG from stdin\n")) |
|
1459 | 1459 | text = ui.fin.read() |
|
1460 | 1460 | |
|
1461 | 1461 | cl = repo.changelog |
|
1462 | 1462 | if len(cl) > 0: |
|
1463 | 1463 | raise util.Abort(_('repository is not empty')) |
|
1464 | 1464 | |
|
1465 | 1465 | # determine number of revs in DAG |
|
1466 | 1466 | total = 0 |
|
1467 | 1467 | for type, data in dagparser.parsedag(text): |
|
1468 | 1468 | if type == 'n': |
|
1469 | 1469 | total += 1 |
|
1470 | 1470 | |
|
1471 | 1471 | if mergeable_file: |
|
1472 | 1472 | linesperrev = 2 |
|
1473 | 1473 | # make a file with k lines per rev |
|
1474 | 1474 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] |
|
1475 | 1475 | initialmergedlines.append("") |
|
1476 | 1476 | |
|
1477 | 1477 | tags = [] |
|
1478 | 1478 | |
|
1479 | 1479 | lock = tr = None |
|
1480 | 1480 | try: |
|
1481 | 1481 | lock = repo.lock() |
|
1482 | 1482 | tr = repo.transaction("builddag") |
|
1483 | 1483 | |
|
1484 | 1484 | at = -1 |
|
1485 | 1485 | atbranch = 'default' |
|
1486 | 1486 | nodeids = [] |
|
1487 | 1487 | id = 0 |
|
1488 | 1488 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
1489 | 1489 | for type, data in dagparser.parsedag(text): |
|
1490 | 1490 | if type == 'n': |
|
1491 | 1491 | ui.note('node %s\n' % str(data)) |
|
1492 | 1492 | id, ps = data |
|
1493 | 1493 | |
|
1494 | 1494 | files = [] |
|
1495 | 1495 | fctxs = {} |
|
1496 | 1496 | |
|
1497 | 1497 | p2 = None |
|
1498 | 1498 | if mergeable_file: |
|
1499 | 1499 | fn = "mf" |
|
1500 | 1500 | p1 = repo[ps[0]] |
|
1501 | 1501 | if len(ps) > 1: |
|
1502 | 1502 | p2 = repo[ps[1]] |
|
1503 | 1503 | pa = p1.ancestor(p2) |
|
1504 | 1504 | base, local, other = [x[fn].data() for x in pa, p1, p2] |
|
1505 | 1505 | m3 = simplemerge.Merge3Text(base, local, other) |
|
1506 | 1506 | ml = [l.strip() for l in m3.merge_lines()] |
|
1507 | 1507 | ml.append("") |
|
1508 | 1508 | elif at > 0: |
|
1509 | 1509 | ml = p1[fn].data().split("\n") |
|
1510 | 1510 | else: |
|
1511 | 1511 | ml = initialmergedlines |
|
1512 | 1512 | ml[id * linesperrev] += " r%i" % id |
|
1513 | 1513 | mergedtext = "\n".join(ml) |
|
1514 | 1514 | files.append(fn) |
|
1515 | 1515 | fctxs[fn] = context.memfilectx(fn, mergedtext) |
|
1516 | 1516 | |
|
1517 | 1517 | if overwritten_file: |
|
1518 | 1518 | fn = "of" |
|
1519 | 1519 | files.append(fn) |
|
1520 | 1520 | fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) |
|
1521 | 1521 | |
|
1522 | 1522 | if new_file: |
|
1523 | 1523 | fn = "nf%i" % id |
|
1524 | 1524 | files.append(fn) |
|
1525 | 1525 | fctxs[fn] = context.memfilectx(fn, "r%i\n" % id) |
|
1526 | 1526 | if len(ps) > 1: |
|
1527 | 1527 | if not p2: |
|
1528 | 1528 | p2 = repo[ps[1]] |
|
1529 | 1529 | for fn in p2: |
|
1530 | 1530 | if fn.startswith("nf"): |
|
1531 | 1531 | files.append(fn) |
|
1532 | 1532 | fctxs[fn] = p2[fn] |
|
1533 | 1533 | |
|
1534 | 1534 | def fctxfn(repo, cx, path): |
|
1535 | 1535 | return fctxs.get(path) |
|
1536 | 1536 | |
|
1537 | 1537 | if len(ps) == 0 or ps[0] < 0: |
|
1538 | 1538 | pars = [None, None] |
|
1539 | 1539 | elif len(ps) == 1: |
|
1540 | 1540 | pars = [nodeids[ps[0]], None] |
|
1541 | 1541 | else: |
|
1542 | 1542 | pars = [nodeids[p] for p in ps] |
|
1543 | 1543 | cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn, |
|
1544 | 1544 | date=(id, 0), |
|
1545 | 1545 | user="debugbuilddag", |
|
1546 | 1546 | extra={'branch': atbranch}) |
|
1547 | 1547 | nodeid = repo.commitctx(cx) |
|
1548 | 1548 | nodeids.append(nodeid) |
|
1549 | 1549 | at = id |
|
1550 | 1550 | elif type == 'l': |
|
1551 | 1551 | id, name = data |
|
1552 | 1552 | ui.note('tag %s\n' % name) |
|
1553 | 1553 | tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) |
|
1554 | 1554 | elif type == 'a': |
|
1555 | 1555 | ui.note('branch %s\n' % data) |
|
1556 | 1556 | atbranch = data |
|
1557 | 1557 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
1558 | 1558 | tr.close() |
|
1559 | 1559 | |
|
1560 | 1560 | if tags: |
|
1561 | 1561 | repo.opener.write("localtags", "".join(tags)) |
|
1562 | 1562 | finally: |
|
1563 | 1563 | ui.progress(_('building'), None) |
|
1564 | 1564 | release(tr, lock) |
|
1565 | 1565 | |
|
1566 | 1566 | @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE')) |
|
1567 | 1567 | def debugbundle(ui, bundlepath, all=None, **opts): |
|
1568 | 1568 | """lists the contents of a bundle""" |
|
1569 | 1569 | f = url.open(ui, bundlepath) |
|
1570 | 1570 | try: |
|
1571 | 1571 | gen = changegroup.readbundle(f, bundlepath) |
|
1572 | 1572 | if all: |
|
1573 | 1573 | ui.write("format: id, p1, p2, cset, delta base, len(delta)\n") |
|
1574 | 1574 | |
|
1575 | 1575 | def showchunks(named): |
|
1576 | 1576 | ui.write("\n%s\n" % named) |
|
1577 | 1577 | chain = None |
|
1578 | 1578 | while True: |
|
1579 | 1579 | chunkdata = gen.deltachunk(chain) |
|
1580 | 1580 | if not chunkdata: |
|
1581 | 1581 | break |
|
1582 | 1582 | node = chunkdata['node'] |
|
1583 | 1583 | p1 = chunkdata['p1'] |
|
1584 | 1584 | p2 = chunkdata['p2'] |
|
1585 | 1585 | cs = chunkdata['cs'] |
|
1586 | 1586 | deltabase = chunkdata['deltabase'] |
|
1587 | 1587 | delta = chunkdata['delta'] |
|
1588 | 1588 | ui.write("%s %s %s %s %s %s\n" % |
|
1589 | 1589 | (hex(node), hex(p1), hex(p2), |
|
1590 | 1590 | hex(cs), hex(deltabase), len(delta))) |
|
1591 | 1591 | chain = node |
|
1592 | 1592 | |
|
1593 | 1593 | chunkdata = gen.changelogheader() |
|
1594 | 1594 | showchunks("changelog") |
|
1595 | 1595 | chunkdata = gen.manifestheader() |
|
1596 | 1596 | showchunks("manifest") |
|
1597 | 1597 | while True: |
|
1598 | 1598 | chunkdata = gen.filelogheader() |
|
1599 | 1599 | if not chunkdata: |
|
1600 | 1600 | break |
|
1601 | 1601 | fname = chunkdata['filename'] |
|
1602 | 1602 | showchunks(fname) |
|
1603 | 1603 | else: |
|
1604 | 1604 | chunkdata = gen.changelogheader() |
|
1605 | 1605 | chain = None |
|
1606 | 1606 | while True: |
|
1607 | 1607 | chunkdata = gen.deltachunk(chain) |
|
1608 | 1608 | if not chunkdata: |
|
1609 | 1609 | break |
|
1610 | 1610 | node = chunkdata['node'] |
|
1611 | 1611 | ui.write("%s\n" % hex(node)) |
|
1612 | 1612 | chain = node |
|
1613 | 1613 | finally: |
|
1614 | 1614 | f.close() |
|
1615 | 1615 | |
|
1616 | 1616 | @command('debugcheckstate', [], '') |
|
1617 | 1617 | def debugcheckstate(ui, repo): |
|
1618 | 1618 | """validate the correctness of the current dirstate""" |
|
1619 | 1619 | parent1, parent2 = repo.dirstate.parents() |
|
1620 | 1620 | m1 = repo[parent1].manifest() |
|
1621 | 1621 | m2 = repo[parent2].manifest() |
|
1622 | 1622 | errors = 0 |
|
1623 | 1623 | for f in repo.dirstate: |
|
1624 | 1624 | state = repo.dirstate[f] |
|
1625 | 1625 | if state in "nr" and f not in m1: |
|
1626 | 1626 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1627 | 1627 | errors += 1 |
|
1628 | 1628 | if state in "a" and f in m1: |
|
1629 | 1629 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1630 | 1630 | errors += 1 |
|
1631 | 1631 | if state in "m" and f not in m1 and f not in m2: |
|
1632 | 1632 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1633 | 1633 | (f, state)) |
|
1634 | 1634 | errors += 1 |
|
1635 | 1635 | for f in m1: |
|
1636 | 1636 | state = repo.dirstate[f] |
|
1637 | 1637 | if state not in "nrm": |
|
1638 | 1638 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1639 | 1639 | errors += 1 |
|
1640 | 1640 | if errors: |
|
1641 | 1641 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1642 | 1642 | raise util.Abort(error) |
|
1643 | 1643 | |
|
1644 | 1644 | @command('debugcommands', [], _('[COMMAND]')) |
|
1645 | 1645 | def debugcommands(ui, cmd='', *args): |
|
1646 | 1646 | """list all available commands and options""" |
|
1647 | 1647 | for cmd, vals in sorted(table.iteritems()): |
|
1648 | 1648 | cmd = cmd.split('|')[0].strip('^') |
|
1649 | 1649 | opts = ', '.join([i[1] for i in vals[1]]) |
|
1650 | 1650 | ui.write('%s: %s\n' % (cmd, opts)) |
|
1651 | 1651 | |
|
1652 | 1652 | @command('debugcomplete', |
|
1653 | 1653 | [('o', 'options', None, _('show the command options'))], |
|
1654 | 1654 | _('[-o] CMD')) |
|
1655 | 1655 | def debugcomplete(ui, cmd='', **opts): |
|
1656 | 1656 | """returns the completion list associated with the given command""" |
|
1657 | 1657 | |
|
1658 | 1658 | if opts.get('options'): |
|
1659 | 1659 | options = [] |
|
1660 | 1660 | otables = [globalopts] |
|
1661 | 1661 | if cmd: |
|
1662 | 1662 | aliases, entry = cmdutil.findcmd(cmd, table, False) |
|
1663 | 1663 | otables.append(entry[1]) |
|
1664 | 1664 | for t in otables: |
|
1665 | 1665 | for o in t: |
|
1666 | 1666 | if "(DEPRECATED)" in o[3]: |
|
1667 | 1667 | continue |
|
1668 | 1668 | if o[0]: |
|
1669 | 1669 | options.append('-%s' % o[0]) |
|
1670 | 1670 | options.append('--%s' % o[1]) |
|
1671 | 1671 | ui.write("%s\n" % "\n".join(options)) |
|
1672 | 1672 | return |
|
1673 | 1673 | |
|
1674 | 1674 | cmdlist = cmdutil.findpossible(cmd, table) |
|
1675 | 1675 | if ui.verbose: |
|
1676 | 1676 | cmdlist = [' '.join(c[0]) for c in cmdlist.values()] |
|
1677 | 1677 | ui.write("%s\n" % "\n".join(sorted(cmdlist))) |
|
1678 | 1678 | |
|
1679 | 1679 | @command('debugdag', |
|
1680 | 1680 | [('t', 'tags', None, _('use tags as labels')), |
|
1681 | 1681 | ('b', 'branches', None, _('annotate with branch names')), |
|
1682 | 1682 | ('', 'dots', None, _('use dots for runs')), |
|
1683 | 1683 | ('s', 'spaces', None, _('separate elements by spaces'))], |
|
1684 | 1684 | _('[OPTION]... [FILE [REV]...]')) |
|
1685 | 1685 | def debugdag(ui, repo, file_=None, *revs, **opts): |
|
1686 | 1686 | """format the changelog or an index DAG as a concise textual description |
|
1687 | 1687 | |
|
1688 | 1688 | If you pass a revlog index, the revlog's DAG is emitted. If you list |
|
1689 | 1689 | revision numbers, they get labelled in the output as rN. |
|
1690 | 1690 | |
|
1691 | 1691 | Otherwise, the changelog DAG of the current repo is emitted. |
|
1692 | 1692 | """ |
|
1693 | 1693 | spaces = opts.get('spaces') |
|
1694 | 1694 | dots = opts.get('dots') |
|
1695 | 1695 | if file_: |
|
1696 | 1696 | rlog = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
1697 | 1697 | revs = set((int(r) for r in revs)) |
|
1698 | 1698 | def events(): |
|
1699 | 1699 | for r in rlog: |
|
1700 | 1700 | yield 'n', (r, list(set(p for p in rlog.parentrevs(r) |
|
1701 | 1701 | if p != -1))) |
|
1702 | 1702 | if r in revs: |
|
1703 | 1703 | yield 'l', (r, "r%i" % r) |
|
1704 | 1704 | elif repo: |
|
1705 | 1705 | cl = repo.changelog |
|
1706 | 1706 | tags = opts.get('tags') |
|
1707 | 1707 | branches = opts.get('branches') |
|
1708 | 1708 | if tags: |
|
1709 | 1709 | labels = {} |
|
1710 | 1710 | for l, n in repo.tags().items(): |
|
1711 | 1711 | labels.setdefault(cl.rev(n), []).append(l) |
|
1712 | 1712 | def events(): |
|
1713 | 1713 | b = "default" |
|
1714 | 1714 | for r in cl: |
|
1715 | 1715 | if branches: |
|
1716 | 1716 | newb = cl.read(cl.node(r))[5]['branch'] |
|
1717 | 1717 | if newb != b: |
|
1718 | 1718 | yield 'a', newb |
|
1719 | 1719 | b = newb |
|
1720 | 1720 | yield 'n', (r, list(set(p for p in cl.parentrevs(r) |
|
1721 | 1721 | if p != -1))) |
|
1722 | 1722 | if tags: |
|
1723 | 1723 | ls = labels.get(r) |
|
1724 | 1724 | if ls: |
|
1725 | 1725 | for l in ls: |
|
1726 | 1726 | yield 'l', (r, l) |
|
1727 | 1727 | else: |
|
1728 | 1728 | raise util.Abort(_('need repo for changelog dag')) |
|
1729 | 1729 | |
|
1730 | 1730 | for line in dagparser.dagtextlines(events(), |
|
1731 | 1731 | addspaces=spaces, |
|
1732 | 1732 | wraplabels=True, |
|
1733 | 1733 | wrapannotations=True, |
|
1734 | 1734 | wrapnonlinear=dots, |
|
1735 | 1735 | usedots=dots, |
|
1736 | 1736 | maxlinewidth=70): |
|
1737 | 1737 | ui.write(line) |
|
1738 | 1738 | ui.write("\n") |
|
1739 | 1739 | |
|
1740 | 1740 | @command('debugdata', |
|
1741 | 1741 | [('c', 'changelog', False, _('open changelog')), |
|
1742 | 1742 | ('m', 'manifest', False, _('open manifest'))], |
|
1743 | 1743 | _('-c|-m|FILE REV')) |
|
1744 | 1744 | def debugdata(ui, repo, file_, rev = None, **opts): |
|
1745 | 1745 | """dump the contents of a data file revision""" |
|
1746 | 1746 | if opts.get('changelog') or opts.get('manifest'): |
|
1747 | 1747 | file_, rev = None, file_ |
|
1748 | 1748 | elif rev is None: |
|
1749 | 1749 | raise error.CommandError('debugdata', _('invalid arguments')) |
|
1750 | 1750 | r = cmdutil.openrevlog(repo, 'debugdata', file_, opts) |
|
1751 | 1751 | try: |
|
1752 | 1752 | ui.write(r.revision(r.lookup(rev))) |
|
1753 | 1753 | except KeyError: |
|
1754 | 1754 | raise util.Abort(_('invalid revision identifier %s') % rev) |
|
1755 | 1755 | |
|
1756 | 1756 | @command('debugdate', |
|
1757 | 1757 | [('e', 'extended', None, _('try extended date formats'))], |
|
1758 | 1758 | _('[-e] DATE [RANGE]')) |
|
1759 | 1759 | def debugdate(ui, date, range=None, **opts): |
|
1760 | 1760 | """parse and display a date""" |
|
1761 | 1761 | if opts["extended"]: |
|
1762 | 1762 | d = util.parsedate(date, util.extendeddateformats) |
|
1763 | 1763 | else: |
|
1764 | 1764 | d = util.parsedate(date) |
|
1765 | 1765 | ui.write("internal: %s %s\n" % d) |
|
1766 | 1766 | ui.write("standard: %s\n" % util.datestr(d)) |
|
1767 | 1767 | if range: |
|
1768 | 1768 | m = util.matchdate(range) |
|
1769 | 1769 | ui.write("match: %s\n" % m(d[0])) |
|
1770 | 1770 | |
|
1771 | 1771 | @command('debugdiscovery', |
|
1772 | 1772 | [('', 'old', None, _('use old-style discovery')), |
|
1773 | 1773 | ('', 'nonheads', None, |
|
1774 | 1774 | _('use old-style discovery with non-heads included')), |
|
1775 | 1775 | ] + remoteopts, |
|
1776 | 1776 | _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) |
|
1777 | 1777 | def debugdiscovery(ui, repo, remoteurl="default", **opts): |
|
1778 | 1778 | """runs the changeset discovery protocol in isolation""" |
|
1779 | 1779 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), |
|
1780 | 1780 | opts.get('branch')) |
|
1781 | 1781 | remote = hg.peer(repo, opts, remoteurl) |
|
1782 | 1782 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) |
|
1783 | 1783 | |
|
1784 | 1784 | # make sure tests are repeatable |
|
1785 | 1785 | random.seed(12323) |
|
1786 | 1786 | |
|
1787 | def doit(localheads, remoteheads): | |
|
1787 | def doit(localheads, remoteheads, remote=remote): | |
|
1788 | 1788 | if opts.get('old'): |
|
1789 | 1789 | if localheads: |
|
1790 | 1790 | raise util.Abort('cannot use localheads with old style ' |
|
1791 | 1791 | 'discovery') |
|
1792 | 1792 | common, _in, hds = treediscovery.findcommonincoming(repo, remote, |
|
1793 | 1793 | force=True) |
|
1794 | 1794 | common = set(common) |
|
1795 | 1795 | if not opts.get('nonheads'): |
|
1796 | 1796 | ui.write("unpruned common: %s\n" % " ".join([short(n) |
|
1797 | 1797 | for n in common])) |
|
1798 | 1798 | dag = dagutil.revlogdag(repo.changelog) |
|
1799 | 1799 | all = dag.ancestorset(dag.internalizeall(common)) |
|
1800 | 1800 | common = dag.externalizeall(dag.headsetofconnecteds(all)) |
|
1801 | 1801 | else: |
|
1802 | 1802 | common, any, hds = setdiscovery.findcommonheads(ui, repo, remote) |
|
1803 | 1803 | common = set(common) |
|
1804 | 1804 | rheads = set(hds) |
|
1805 | 1805 | lheads = set(repo.heads()) |
|
1806 | 1806 | ui.write("common heads: %s\n" % " ".join([short(n) for n in common])) |
|
1807 | 1807 | if lheads <= common: |
|
1808 | 1808 | ui.write("local is subset\n") |
|
1809 | 1809 | elif rheads <= common: |
|
1810 | 1810 | ui.write("remote is subset\n") |
|
1811 | 1811 | |
|
1812 | 1812 | serverlogs = opts.get('serverlog') |
|
1813 | 1813 | if serverlogs: |
|
1814 | 1814 | for filename in serverlogs: |
|
1815 | 1815 | logfile = open(filename, 'r') |
|
1816 | 1816 | try: |
|
1817 | 1817 | line = logfile.readline() |
|
1818 | 1818 | while line: |
|
1819 | 1819 | parts = line.strip().split(';') |
|
1820 | 1820 | op = parts[1] |
|
1821 | 1821 | if op == 'cg': |
|
1822 | 1822 | pass |
|
1823 | 1823 | elif op == 'cgss': |
|
1824 | 1824 | doit(parts[2].split(' '), parts[3].split(' ')) |
|
1825 | 1825 | elif op == 'unb': |
|
1826 | 1826 | doit(parts[3].split(' '), parts[2].split(' ')) |
|
1827 | 1827 | line = logfile.readline() |
|
1828 | 1828 | finally: |
|
1829 | 1829 | logfile.close() |
|
1830 | 1830 | |
|
1831 | 1831 | else: |
|
1832 | 1832 | remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, |
|
1833 | 1833 | opts.get('remote_head')) |
|
1834 | 1834 | localrevs = opts.get('local_head') |
|
1835 | 1835 | doit(localrevs, remoterevs) |
|
1836 | 1836 | |
|
1837 | 1837 | @command('debugfileset', [], ('REVSPEC')) |
|
1838 | 1838 | def debugfileset(ui, repo, expr): |
|
1839 | 1839 | '''parse and apply a fileset specification''' |
|
1840 | 1840 | if ui.verbose: |
|
1841 | 1841 | tree = fileset.parse(expr)[0] |
|
1842 | 1842 | ui.note(tree, "\n") |
|
1843 | 1843 | |
|
1844 | 1844 | for f in fileset.getfileset(repo[None], expr): |
|
1845 | 1845 | ui.write("%s\n" % f) |
|
1846 | 1846 | |
|
1847 | 1847 | @command('debugfsinfo', [], _('[PATH]')) |
|
1848 | 1848 | def debugfsinfo(ui, path = "."): |
|
1849 | 1849 | """show information detected about current filesystem""" |
|
1850 | 1850 | util.writefile('.debugfsinfo', '') |
|
1851 | 1851 | ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no')) |
|
1852 | 1852 | ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) |
|
1853 | 1853 | ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo') |
|
1854 | 1854 | and 'yes' or 'no')) |
|
1855 | 1855 | os.unlink('.debugfsinfo') |
|
1856 | 1856 | |
|
1857 | 1857 | @command('debuggetbundle', |
|
1858 | 1858 | [('H', 'head', [], _('id of head node'), _('ID')), |
|
1859 | 1859 | ('C', 'common', [], _('id of common node'), _('ID')), |
|
1860 | 1860 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))], |
|
1861 | 1861 | _('REPO FILE [-H|-C ID]...')) |
|
1862 | 1862 | def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts): |
|
1863 | 1863 | """retrieves a bundle from a repo |
|
1864 | 1864 | |
|
1865 | 1865 | Every ID must be a full-length hex node id string. Saves the bundle to the |
|
1866 | 1866 | given file. |
|
1867 | 1867 | """ |
|
1868 | 1868 | repo = hg.peer(ui, opts, repopath) |
|
1869 | 1869 | if not repo.capable('getbundle'): |
|
1870 | 1870 | raise util.Abort("getbundle() not supported by target repository") |
|
1871 | 1871 | args = {} |
|
1872 | 1872 | if common: |
|
1873 | 1873 | args['common'] = [bin(s) for s in common] |
|
1874 | 1874 | if head: |
|
1875 | 1875 | args['heads'] = [bin(s) for s in head] |
|
1876 | 1876 | bundle = repo.getbundle('debug', **args) |
|
1877 | 1877 | |
|
1878 | 1878 | bundletype = opts.get('type', 'bzip2').lower() |
|
1879 | 1879 | btypes = {'none': 'HG10UN', 'bzip2': 'HG10BZ', 'gzip': 'HG10GZ'} |
|
1880 | 1880 | bundletype = btypes.get(bundletype) |
|
1881 | 1881 | if bundletype not in changegroup.bundletypes: |
|
1882 | 1882 | raise util.Abort(_('unknown bundle type specified with --type')) |
|
1883 | 1883 | changegroup.writebundle(bundle, bundlepath, bundletype) |
|
1884 | 1884 | |
|
1885 | 1885 | @command('debugignore', [], '') |
|
1886 | 1886 | def debugignore(ui, repo, *values, **opts): |
|
1887 | 1887 | """display the combined ignore pattern""" |
|
1888 | 1888 | ignore = repo.dirstate._ignore |
|
1889 | 1889 | includepat = getattr(ignore, 'includepat', None) |
|
1890 | 1890 | if includepat is not None: |
|
1891 | 1891 | ui.write("%s\n" % includepat) |
|
1892 | 1892 | else: |
|
1893 | 1893 | raise util.Abort(_("no ignore patterns found")) |
|
1894 | 1894 | |
|
1895 | 1895 | @command('debugindex', |
|
1896 | 1896 | [('c', 'changelog', False, _('open changelog')), |
|
1897 | 1897 | ('m', 'manifest', False, _('open manifest')), |
|
1898 | 1898 | ('f', 'format', 0, _('revlog format'), _('FORMAT'))], |
|
1899 | 1899 | _('[-f FORMAT] -c|-m|FILE')) |
|
1900 | 1900 | def debugindex(ui, repo, file_ = None, **opts): |
|
1901 | 1901 | """dump the contents of an index file""" |
|
1902 | 1902 | r = cmdutil.openrevlog(repo, 'debugindex', file_, opts) |
|
1903 | 1903 | format = opts.get('format', 0) |
|
1904 | 1904 | if format not in (0, 1): |
|
1905 | 1905 | raise util.Abort(_("unknown format %d") % format) |
|
1906 | 1906 | |
|
1907 | 1907 | generaldelta = r.version & revlog.REVLOGGENERALDELTA |
|
1908 | 1908 | if generaldelta: |
|
1909 | 1909 | basehdr = ' delta' |
|
1910 | 1910 | else: |
|
1911 | 1911 | basehdr = ' base' |
|
1912 | 1912 | |
|
1913 | 1913 | if format == 0: |
|
1914 | 1914 | ui.write(" rev offset length " + basehdr + " linkrev" |
|
1915 | 1915 | " nodeid p1 p2\n") |
|
1916 | 1916 | elif format == 1: |
|
1917 | 1917 | ui.write(" rev flag offset length" |
|
1918 | 1918 | " size " + basehdr + " link p1 p2" |
|
1919 | 1919 | " nodeid\n") |
|
1920 | 1920 | |
|
1921 | 1921 | for i in r: |
|
1922 | 1922 | node = r.node(i) |
|
1923 | 1923 | if generaldelta: |
|
1924 | 1924 | base = r.deltaparent(i) |
|
1925 | 1925 | else: |
|
1926 | 1926 | base = r.chainbase(i) |
|
1927 | 1927 | if format == 0: |
|
1928 | 1928 | try: |
|
1929 | 1929 | pp = r.parents(node) |
|
1930 | 1930 | except Exception: |
|
1931 | 1931 | pp = [nullid, nullid] |
|
1932 | 1932 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1933 | 1933 | i, r.start(i), r.length(i), base, r.linkrev(i), |
|
1934 | 1934 | short(node), short(pp[0]), short(pp[1]))) |
|
1935 | 1935 | elif format == 1: |
|
1936 | 1936 | pr = r.parentrevs(i) |
|
1937 | 1937 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( |
|
1938 | 1938 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), |
|
1939 | 1939 | base, r.linkrev(i), pr[0], pr[1], short(node))) |
|
1940 | 1940 | |
|
1941 | 1941 | @command('debugindexdot', [], _('FILE')) |
|
1942 | 1942 | def debugindexdot(ui, repo, file_): |
|
1943 | 1943 | """dump an index DAG as a graphviz dot file""" |
|
1944 | 1944 | r = None |
|
1945 | 1945 | if repo: |
|
1946 | 1946 | filelog = repo.file(file_) |
|
1947 | 1947 | if len(filelog): |
|
1948 | 1948 | r = filelog |
|
1949 | 1949 | if not r: |
|
1950 | 1950 | r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), file_) |
|
1951 | 1951 | ui.write("digraph G {\n") |
|
1952 | 1952 | for i in r: |
|
1953 | 1953 | node = r.node(i) |
|
1954 | 1954 | pp = r.parents(node) |
|
1955 | 1955 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
1956 | 1956 | if pp[1] != nullid: |
|
1957 | 1957 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
1958 | 1958 | ui.write("}\n") |
|
1959 | 1959 | |
|
1960 | 1960 | @command('debuginstall', [], '') |
|
1961 | 1961 | def debuginstall(ui): |
|
1962 | 1962 | '''test Mercurial installation |
|
1963 | 1963 | |
|
1964 | 1964 | Returns 0 on success. |
|
1965 | 1965 | ''' |
|
1966 | 1966 | |
|
1967 | 1967 | def writetemp(contents): |
|
1968 | 1968 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") |
|
1969 | 1969 | f = os.fdopen(fd, "wb") |
|
1970 | 1970 | f.write(contents) |
|
1971 | 1971 | f.close() |
|
1972 | 1972 | return name |
|
1973 | 1973 | |
|
1974 | 1974 | problems = 0 |
|
1975 | 1975 | |
|
1976 | 1976 | # encoding |
|
1977 | 1977 | ui.status(_("checking encoding (%s)...\n") % encoding.encoding) |
|
1978 | 1978 | try: |
|
1979 | 1979 | encoding.fromlocal("test") |
|
1980 | 1980 | except util.Abort, inst: |
|
1981 | 1981 | ui.write(" %s\n" % inst) |
|
1982 | 1982 | ui.write(_(" (check that your locale is properly set)\n")) |
|
1983 | 1983 | problems += 1 |
|
1984 | 1984 | |
|
1985 | 1985 | # compiled modules |
|
1986 | 1986 | ui.status(_("checking installed modules (%s)...\n") |
|
1987 | 1987 | % os.path.dirname(__file__)) |
|
1988 | 1988 | try: |
|
1989 | 1989 | import bdiff, mpatch, base85, osutil |
|
1990 | 1990 | dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes |
|
1991 | 1991 | except Exception, inst: |
|
1992 | 1992 | ui.write(" %s\n" % inst) |
|
1993 | 1993 | ui.write(_(" One or more extensions could not be found")) |
|
1994 | 1994 | ui.write(_(" (check that you compiled the extensions)\n")) |
|
1995 | 1995 | problems += 1 |
|
1996 | 1996 | |
|
1997 | 1997 | # templates |
|
1998 | 1998 | import templater |
|
1999 | 1999 | p = templater.templatepath() |
|
2000 | 2000 | ui.status(_("checking templates (%s)...\n") % ' '.join(p)) |
|
2001 | 2001 | try: |
|
2002 | 2002 | templater.templater(templater.templatepath("map-cmdline.default")) |
|
2003 | 2003 | except Exception, inst: |
|
2004 | 2004 | ui.write(" %s\n" % inst) |
|
2005 | 2005 | ui.write(_(" (templates seem to have been installed incorrectly)\n")) |
|
2006 | 2006 | problems += 1 |
|
2007 | 2007 | |
|
2008 | 2008 | # editor |
|
2009 | 2009 | ui.status(_("checking commit editor...\n")) |
|
2010 | 2010 | editor = ui.geteditor() |
|
2011 | 2011 | cmdpath = util.findexe(editor) or util.findexe(editor.split()[0]) |
|
2012 | 2012 | if not cmdpath: |
|
2013 | 2013 | if editor == 'vi': |
|
2014 | 2014 | ui.write(_(" No commit editor set and can't find vi in PATH\n")) |
|
2015 | 2015 | ui.write(_(" (specify a commit editor in your configuration" |
|
2016 | 2016 | " file)\n")) |
|
2017 | 2017 | else: |
|
2018 | 2018 | ui.write(_(" Can't find editor '%s' in PATH\n") % editor) |
|
2019 | 2019 | ui.write(_(" (specify a commit editor in your configuration" |
|
2020 | 2020 | " file)\n")) |
|
2021 | 2021 | problems += 1 |
|
2022 | 2022 | |
|
2023 | 2023 | # check username |
|
2024 | 2024 | ui.status(_("checking username...\n")) |
|
2025 | 2025 | try: |
|
2026 | 2026 | ui.username() |
|
2027 | 2027 | except util.Abort, e: |
|
2028 | 2028 | ui.write(" %s\n" % e) |
|
2029 | 2029 | ui.write(_(" (specify a username in your configuration file)\n")) |
|
2030 | 2030 | problems += 1 |
|
2031 | 2031 | |
|
2032 | 2032 | if not problems: |
|
2033 | 2033 | ui.status(_("no problems detected\n")) |
|
2034 | 2034 | else: |
|
2035 | 2035 | ui.write(_("%s problems detected," |
|
2036 | 2036 | " please check your install!\n") % problems) |
|
2037 | 2037 | |
|
2038 | 2038 | return problems |
|
2039 | 2039 | |
|
2040 | 2040 | @command('debugknown', [], _('REPO ID...')) |
|
2041 | 2041 | def debugknown(ui, repopath, *ids, **opts): |
|
2042 | 2042 | """test whether node ids are known to a repo |
|
2043 | 2043 | |
|
2044 | 2044 | Every ID must be a full-length hex node id string. Returns a list of 0s |
|
2045 | 2045 | and 1s indicating unknown/known. |
|
2046 | 2046 | """ |
|
2047 | 2047 | repo = hg.peer(ui, opts, repopath) |
|
2048 | 2048 | if not repo.capable('known'): |
|
2049 | 2049 | raise util.Abort("known() not supported by target repository") |
|
2050 | 2050 | flags = repo.known([bin(s) for s in ids]) |
|
2051 | 2051 | ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) |
|
2052 | 2052 | |
|
2053 | 2053 | @command('debugobsolete', [] + commitopts2, |
|
2054 | 2054 | _('[OBSOLETED [REPLACEMENT] [REPL... ]')) |
|
2055 | 2055 | def debugobsolete(ui, repo, precursor=None, *successors, **opts): |
|
2056 | 2056 | """create arbitrary obsolete marker""" |
|
2057 | 2057 | if precursor is not None: |
|
2058 | 2058 | metadata = {} |
|
2059 | 2059 | if 'date' in opts: |
|
2060 | 2060 | metadata['date'] = opts['date'] |
|
2061 | 2061 | metadata['user'] = opts['user'] or ui.username() |
|
2062 | 2062 | succs = tuple(bin(succ) for succ in successors) |
|
2063 | 2063 | l = repo.lock() |
|
2064 | 2064 | try: |
|
2065 | 2065 | tr = repo.transaction('debugobsolete') |
|
2066 | 2066 | try: |
|
2067 | 2067 | repo.obsstore.create(tr, bin(precursor), succs, 0, metadata) |
|
2068 | 2068 | tr.close() |
|
2069 | 2069 | finally: |
|
2070 | 2070 | tr.release() |
|
2071 | 2071 | finally: |
|
2072 | 2072 | l.release() |
|
2073 | 2073 | else: |
|
2074 | 2074 | for m in obsolete.allmarkers(repo): |
|
2075 | 2075 | ui.write(hex(m.precnode())) |
|
2076 | 2076 | for repl in m.succnodes(): |
|
2077 | 2077 | ui.write(' ') |
|
2078 | 2078 | ui.write(hex(repl)) |
|
2079 | 2079 | ui.write(' %X ' % m._data[2]) |
|
2080 | 2080 | ui.write(m.metadata()) |
|
2081 | 2081 | ui.write('\n') |
|
2082 | 2082 | |
|
2083 | 2083 | @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]')) |
|
2084 | 2084 | def debugpushkey(ui, repopath, namespace, *keyinfo, **opts): |
|
2085 | 2085 | '''access the pushkey key/value protocol |
|
2086 | 2086 | |
|
2087 | 2087 | With two args, list the keys in the given namespace. |
|
2088 | 2088 | |
|
2089 | 2089 | With five args, set a key to new if it currently is set to old. |
|
2090 | 2090 | Reports success or failure. |
|
2091 | 2091 | ''' |
|
2092 | 2092 | |
|
2093 | 2093 | target = hg.peer(ui, {}, repopath) |
|
2094 | 2094 | if keyinfo: |
|
2095 | 2095 | key, old, new = keyinfo |
|
2096 | 2096 | r = target.pushkey(namespace, key, old, new) |
|
2097 | 2097 | ui.status(str(r) + '\n') |
|
2098 | 2098 | return not r |
|
2099 | 2099 | else: |
|
2100 | 2100 | for k, v in target.listkeys(namespace).iteritems(): |
|
2101 | 2101 | ui.write("%s\t%s\n" % (k.encode('string-escape'), |
|
2102 | 2102 | v.encode('string-escape'))) |
|
2103 | 2103 | |
|
2104 | 2104 | @command('debugpvec', [], _('A B')) |
|
2105 | 2105 | def debugpvec(ui, repo, a, b=None): |
|
2106 | 2106 | ca = scmutil.revsingle(repo, a) |
|
2107 | 2107 | cb = scmutil.revsingle(repo, b) |
|
2108 | 2108 | pa = pvec.ctxpvec(ca) |
|
2109 | 2109 | pb = pvec.ctxpvec(cb) |
|
2110 | 2110 | if pa == pb: |
|
2111 | 2111 | rel = "=" |
|
2112 | 2112 | elif pa > pb: |
|
2113 | 2113 | rel = ">" |
|
2114 | 2114 | elif pa < pb: |
|
2115 | 2115 | rel = "<" |
|
2116 | 2116 | elif pa | pb: |
|
2117 | 2117 | rel = "|" |
|
2118 | 2118 | ui.write(_("a: %s\n") % pa) |
|
2119 | 2119 | ui.write(_("b: %s\n") % pb) |
|
2120 | 2120 | ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth)) |
|
2121 | 2121 | ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") % |
|
2122 | 2122 | (abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec), |
|
2123 | 2123 | pa.distance(pb), rel)) |
|
2124 | 2124 | |
|
2125 | 2125 | @command('debugrebuildstate', |
|
2126 | 2126 | [('r', 'rev', '', _('revision to rebuild to'), _('REV'))], |
|
2127 | 2127 | _('[-r REV] [REV]')) |
|
2128 | 2128 | def debugrebuildstate(ui, repo, rev="tip"): |
|
2129 | 2129 | """rebuild the dirstate as it would look like for the given revision""" |
|
2130 | 2130 | ctx = scmutil.revsingle(repo, rev) |
|
2131 | 2131 | wlock = repo.wlock() |
|
2132 | 2132 | try: |
|
2133 | 2133 | repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
|
2134 | 2134 | finally: |
|
2135 | 2135 | wlock.release() |
|
2136 | 2136 | |
|
2137 | 2137 | @command('debugrename', |
|
2138 | 2138 | [('r', 'rev', '', _('revision to debug'), _('REV'))], |
|
2139 | 2139 | _('[-r REV] FILE')) |
|
2140 | 2140 | def debugrename(ui, repo, file1, *pats, **opts): |
|
2141 | 2141 | """dump rename information""" |
|
2142 | 2142 | |
|
2143 | 2143 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
2144 | 2144 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
2145 | 2145 | for abs in ctx.walk(m): |
|
2146 | 2146 | fctx = ctx[abs] |
|
2147 | 2147 | o = fctx.filelog().renamed(fctx.filenode()) |
|
2148 | 2148 | rel = m.rel(abs) |
|
2149 | 2149 | if o: |
|
2150 | 2150 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) |
|
2151 | 2151 | else: |
|
2152 | 2152 | ui.write(_("%s not renamed\n") % rel) |
|
2153 | 2153 | |
|
2154 | 2154 | @command('debugrevlog', |
|
2155 | 2155 | [('c', 'changelog', False, _('open changelog')), |
|
2156 | 2156 | ('m', 'manifest', False, _('open manifest')), |
|
2157 | 2157 | ('d', 'dump', False, _('dump index data'))], |
|
2158 | 2158 | _('-c|-m|FILE')) |
|
2159 | 2159 | def debugrevlog(ui, repo, file_ = None, **opts): |
|
2160 | 2160 | """show data and statistics about a revlog""" |
|
2161 | 2161 | r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts) |
|
2162 | 2162 | |
|
2163 | 2163 | if opts.get("dump"): |
|
2164 | 2164 | numrevs = len(r) |
|
2165 | 2165 | ui.write("# rev p1rev p2rev start end deltastart base p1 p2" |
|
2166 | 2166 | " rawsize totalsize compression heads\n") |
|
2167 | 2167 | ts = 0 |
|
2168 | 2168 | heads = set() |
|
2169 | 2169 | for rev in xrange(numrevs): |
|
2170 | 2170 | dbase = r.deltaparent(rev) |
|
2171 | 2171 | if dbase == -1: |
|
2172 | 2172 | dbase = rev |
|
2173 | 2173 | cbase = r.chainbase(rev) |
|
2174 | 2174 | p1, p2 = r.parentrevs(rev) |
|
2175 | 2175 | rs = r.rawsize(rev) |
|
2176 | 2176 | ts = ts + rs |
|
2177 | 2177 | heads -= set(r.parentrevs(rev)) |
|
2178 | 2178 | heads.add(rev) |
|
2179 | 2179 | ui.write("%d %d %d %d %d %d %d %d %d %d %d %d %d\n" % |
|
2180 | 2180 | (rev, p1, p2, r.start(rev), r.end(rev), |
|
2181 | 2181 | r.start(dbase), r.start(cbase), |
|
2182 | 2182 | r.start(p1), r.start(p2), |
|
2183 | 2183 | rs, ts, ts / r.end(rev), len(heads))) |
|
2184 | 2184 | return 0 |
|
2185 | 2185 | |
|
2186 | 2186 | v = r.version |
|
2187 | 2187 | format = v & 0xFFFF |
|
2188 | 2188 | flags = [] |
|
2189 | 2189 | gdelta = False |
|
2190 | 2190 | if v & revlog.REVLOGNGINLINEDATA: |
|
2191 | 2191 | flags.append('inline') |
|
2192 | 2192 | if v & revlog.REVLOGGENERALDELTA: |
|
2193 | 2193 | gdelta = True |
|
2194 | 2194 | flags.append('generaldelta') |
|
2195 | 2195 | if not flags: |
|
2196 | 2196 | flags = ['(none)'] |
|
2197 | 2197 | |
|
2198 | 2198 | nummerges = 0 |
|
2199 | 2199 | numfull = 0 |
|
2200 | 2200 | numprev = 0 |
|
2201 | 2201 | nump1 = 0 |
|
2202 | 2202 | nump2 = 0 |
|
2203 | 2203 | numother = 0 |
|
2204 | 2204 | nump1prev = 0 |
|
2205 | 2205 | nump2prev = 0 |
|
2206 | 2206 | chainlengths = [] |
|
2207 | 2207 | |
|
2208 | 2208 | datasize = [None, 0, 0L] |
|
2209 | 2209 | fullsize = [None, 0, 0L] |
|
2210 | 2210 | deltasize = [None, 0, 0L] |
|
2211 | 2211 | |
|
2212 | 2212 | def addsize(size, l): |
|
2213 | 2213 | if l[0] is None or size < l[0]: |
|
2214 | 2214 | l[0] = size |
|
2215 | 2215 | if size > l[1]: |
|
2216 | 2216 | l[1] = size |
|
2217 | 2217 | l[2] += size |
|
2218 | 2218 | |
|
2219 | 2219 | numrevs = len(r) |
|
2220 | 2220 | for rev in xrange(numrevs): |
|
2221 | 2221 | p1, p2 = r.parentrevs(rev) |
|
2222 | 2222 | delta = r.deltaparent(rev) |
|
2223 | 2223 | if format > 0: |
|
2224 | 2224 | addsize(r.rawsize(rev), datasize) |
|
2225 | 2225 | if p2 != nullrev: |
|
2226 | 2226 | nummerges += 1 |
|
2227 | 2227 | size = r.length(rev) |
|
2228 | 2228 | if delta == nullrev: |
|
2229 | 2229 | chainlengths.append(0) |
|
2230 | 2230 | numfull += 1 |
|
2231 | 2231 | addsize(size, fullsize) |
|
2232 | 2232 | else: |
|
2233 | 2233 | chainlengths.append(chainlengths[delta] + 1) |
|
2234 | 2234 | addsize(size, deltasize) |
|
2235 | 2235 | if delta == rev - 1: |
|
2236 | 2236 | numprev += 1 |
|
2237 | 2237 | if delta == p1: |
|
2238 | 2238 | nump1prev += 1 |
|
2239 | 2239 | elif delta == p2: |
|
2240 | 2240 | nump2prev += 1 |
|
2241 | 2241 | elif delta == p1: |
|
2242 | 2242 | nump1 += 1 |
|
2243 | 2243 | elif delta == p2: |
|
2244 | 2244 | nump2 += 1 |
|
2245 | 2245 | elif delta != nullrev: |
|
2246 | 2246 | numother += 1 |
|
2247 | 2247 | |
|
2248 | 2248 | # Adjust size min value for empty cases |
|
2249 | 2249 | for size in (datasize, fullsize, deltasize): |
|
2250 | 2250 | if size[0] is None: |
|
2251 | 2251 | size[0] = 0 |
|
2252 | 2252 | |
|
2253 | 2253 | numdeltas = numrevs - numfull |
|
2254 | 2254 | numoprev = numprev - nump1prev - nump2prev |
|
2255 | 2255 | totalrawsize = datasize[2] |
|
2256 | 2256 | datasize[2] /= numrevs |
|
2257 | 2257 | fulltotal = fullsize[2] |
|
2258 | 2258 | fullsize[2] /= numfull |
|
2259 | 2259 | deltatotal = deltasize[2] |
|
2260 | 2260 | if numrevs - numfull > 0: |
|
2261 | 2261 | deltasize[2] /= numrevs - numfull |
|
2262 | 2262 | totalsize = fulltotal + deltatotal |
|
2263 | 2263 | avgchainlen = sum(chainlengths) / numrevs |
|
2264 | 2264 | compratio = totalrawsize / totalsize |
|
2265 | 2265 | |
|
2266 | 2266 | basedfmtstr = '%%%dd\n' |
|
2267 | 2267 | basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n' |
|
2268 | 2268 | |
|
2269 | 2269 | def dfmtstr(max): |
|
2270 | 2270 | return basedfmtstr % len(str(max)) |
|
2271 | 2271 | def pcfmtstr(max, padding=0): |
|
2272 | 2272 | return basepcfmtstr % (len(str(max)), ' ' * padding) |
|
2273 | 2273 | |
|
2274 | 2274 | def pcfmt(value, total): |
|
2275 | 2275 | return (value, 100 * float(value) / total) |
|
2276 | 2276 | |
|
2277 | 2277 | ui.write('format : %d\n' % format) |
|
2278 | 2278 | ui.write('flags : %s\n' % ', '.join(flags)) |
|
2279 | 2279 | |
|
2280 | 2280 | ui.write('\n') |
|
2281 | 2281 | fmt = pcfmtstr(totalsize) |
|
2282 | 2282 | fmt2 = dfmtstr(totalsize) |
|
2283 | 2283 | ui.write('revisions : ' + fmt2 % numrevs) |
|
2284 | 2284 | ui.write(' merges : ' + fmt % pcfmt(nummerges, numrevs)) |
|
2285 | 2285 | ui.write(' normal : ' + fmt % pcfmt(numrevs - nummerges, numrevs)) |
|
2286 | 2286 | ui.write('revisions : ' + fmt2 % numrevs) |
|
2287 | 2287 | ui.write(' full : ' + fmt % pcfmt(numfull, numrevs)) |
|
2288 | 2288 | ui.write(' deltas : ' + fmt % pcfmt(numdeltas, numrevs)) |
|
2289 | 2289 | ui.write('revision size : ' + fmt2 % totalsize) |
|
2290 | 2290 | ui.write(' full : ' + fmt % pcfmt(fulltotal, totalsize)) |
|
2291 | 2291 | ui.write(' deltas : ' + fmt % pcfmt(deltatotal, totalsize)) |
|
2292 | 2292 | |
|
2293 | 2293 | ui.write('\n') |
|
2294 | 2294 | fmt = dfmtstr(max(avgchainlen, compratio)) |
|
2295 | 2295 | ui.write('avg chain length : ' + fmt % avgchainlen) |
|
2296 | 2296 | ui.write('compression ratio : ' + fmt % compratio) |
|
2297 | 2297 | |
|
2298 | 2298 | if format > 0: |
|
2299 | 2299 | ui.write('\n') |
|
2300 | 2300 | ui.write('uncompressed data size (min/max/avg) : %d / %d / %d\n' |
|
2301 | 2301 | % tuple(datasize)) |
|
2302 | 2302 | ui.write('full revision size (min/max/avg) : %d / %d / %d\n' |
|
2303 | 2303 | % tuple(fullsize)) |
|
2304 | 2304 | ui.write('delta size (min/max/avg) : %d / %d / %d\n' |
|
2305 | 2305 | % tuple(deltasize)) |
|
2306 | 2306 | |
|
2307 | 2307 | if numdeltas > 0: |
|
2308 | 2308 | ui.write('\n') |
|
2309 | 2309 | fmt = pcfmtstr(numdeltas) |
|
2310 | 2310 | fmt2 = pcfmtstr(numdeltas, 4) |
|
2311 | 2311 | ui.write('deltas against prev : ' + fmt % pcfmt(numprev, numdeltas)) |
|
2312 | 2312 | if numprev > 0: |
|
2313 | 2313 | ui.write(' where prev = p1 : ' + fmt2 % pcfmt(nump1prev, |
|
2314 | 2314 | numprev)) |
|
2315 | 2315 | ui.write(' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, |
|
2316 | 2316 | numprev)) |
|
2317 | 2317 | ui.write(' other : ' + fmt2 % pcfmt(numoprev, |
|
2318 | 2318 | numprev)) |
|
2319 | 2319 | if gdelta: |
|
2320 | 2320 | ui.write('deltas against p1 : ' + fmt % pcfmt(nump1, numdeltas)) |
|
2321 | 2321 | ui.write('deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas)) |
|
2322 | 2322 | ui.write('deltas against other : ' + fmt % pcfmt(numother, |
|
2323 | 2323 | numdeltas)) |
|
2324 | 2324 | |
|
2325 | 2325 | @command('debugrevspec', [], ('REVSPEC')) |
|
2326 | 2326 | def debugrevspec(ui, repo, expr): |
|
2327 | 2327 | """parse and apply a revision specification |
|
2328 | 2328 | |
|
2329 | 2329 | Use --verbose to print the parsed tree before and after aliases |
|
2330 | 2330 | expansion. |
|
2331 | 2331 | """ |
|
2332 | 2332 | if ui.verbose: |
|
2333 | 2333 | tree = revset.parse(expr)[0] |
|
2334 | 2334 | ui.note(revset.prettyformat(tree), "\n") |
|
2335 | 2335 | newtree = revset.findaliases(ui, tree) |
|
2336 | 2336 | if newtree != tree: |
|
2337 | 2337 | ui.note(revset.prettyformat(newtree), "\n") |
|
2338 | 2338 | func = revset.match(ui, expr) |
|
2339 | 2339 | for c in func(repo, range(len(repo))): |
|
2340 | 2340 | ui.write("%s\n" % c) |
|
2341 | 2341 | |
|
2342 | 2342 | @command('debugsetparents', [], _('REV1 [REV2]')) |
|
2343 | 2343 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
2344 | 2344 | """manually set the parents of the current working directory |
|
2345 | 2345 | |
|
2346 | 2346 | This is useful for writing repository conversion tools, but should |
|
2347 | 2347 | be used with care. |
|
2348 | 2348 | |
|
2349 | 2349 | Returns 0 on success. |
|
2350 | 2350 | """ |
|
2351 | 2351 | |
|
2352 | 2352 | r1 = scmutil.revsingle(repo, rev1).node() |
|
2353 | 2353 | r2 = scmutil.revsingle(repo, rev2, 'null').node() |
|
2354 | 2354 | |
|
2355 | 2355 | wlock = repo.wlock() |
|
2356 | 2356 | try: |
|
2357 | 2357 | repo.setparents(r1, r2) |
|
2358 | 2358 | finally: |
|
2359 | 2359 | wlock.release() |
|
2360 | 2360 | |
|
2361 | 2361 | @command('debugstate', |
|
2362 | 2362 | [('', 'nodates', None, _('do not display the saved mtime')), |
|
2363 | 2363 | ('', 'datesort', None, _('sort by saved mtime'))], |
|
2364 | 2364 | _('[OPTION]...')) |
|
2365 | 2365 | def debugstate(ui, repo, nodates=None, datesort=None): |
|
2366 | 2366 | """show the contents of the current dirstate""" |
|
2367 | 2367 | timestr = "" |
|
2368 | 2368 | showdate = not nodates |
|
2369 | 2369 | if datesort: |
|
2370 | 2370 | keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename |
|
2371 | 2371 | else: |
|
2372 | 2372 | keyfunc = None # sort by filename |
|
2373 | 2373 | for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc): |
|
2374 | 2374 | if showdate: |
|
2375 | 2375 | if ent[3] == -1: |
|
2376 | 2376 | # Pad or slice to locale representation |
|
2377 | 2377 | locale_len = len(time.strftime("%Y-%m-%d %H:%M:%S ", |
|
2378 | 2378 | time.localtime(0))) |
|
2379 | 2379 | timestr = 'unset' |
|
2380 | 2380 | timestr = (timestr[:locale_len] + |
|
2381 | 2381 | ' ' * (locale_len - len(timestr))) |
|
2382 | 2382 | else: |
|
2383 | 2383 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", |
|
2384 | 2384 | time.localtime(ent[3])) |
|
2385 | 2385 | if ent[1] & 020000: |
|
2386 | 2386 | mode = 'lnk' |
|
2387 | 2387 | else: |
|
2388 | 2388 | mode = '%3o' % (ent[1] & 0777 & ~util.umask) |
|
2389 | 2389 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
|
2390 | 2390 | for f in repo.dirstate.copies(): |
|
2391 | 2391 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
2392 | 2392 | |
|
2393 | 2393 | @command('debugsub', |
|
2394 | 2394 | [('r', 'rev', '', |
|
2395 | 2395 | _('revision to check'), _('REV'))], |
|
2396 | 2396 | _('[-r REV] [REV]')) |
|
2397 | 2397 | def debugsub(ui, repo, rev=None): |
|
2398 | 2398 | ctx = scmutil.revsingle(repo, rev, None) |
|
2399 | 2399 | for k, v in sorted(ctx.substate.items()): |
|
2400 | 2400 | ui.write('path %s\n' % k) |
|
2401 | 2401 | ui.write(' source %s\n' % v[0]) |
|
2402 | 2402 | ui.write(' revision %s\n' % v[1]) |
|
2403 | 2403 | |
|
2404 | 2404 | @command('debugwalk', walkopts, _('[OPTION]... [FILE]...')) |
|
2405 | 2405 | def debugwalk(ui, repo, *pats, **opts): |
|
2406 | 2406 | """show how files match on given patterns""" |
|
2407 | 2407 | m = scmutil.match(repo[None], pats, opts) |
|
2408 | 2408 | items = list(repo.walk(m)) |
|
2409 | 2409 | if not items: |
|
2410 | 2410 | return |
|
2411 | 2411 | f = lambda fn: fn |
|
2412 | 2412 | if ui.configbool('ui', 'slash') and os.sep != '/': |
|
2413 | 2413 | f = lambda fn: util.normpath(fn) |
|
2414 | 2414 | fmt = 'f %%-%ds %%-%ds %%s' % ( |
|
2415 | 2415 | max([len(abs) for abs in items]), |
|
2416 | 2416 | max([len(m.rel(abs)) for abs in items])) |
|
2417 | 2417 | for abs in items: |
|
2418 | 2418 | line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '') |
|
2419 | 2419 | ui.write("%s\n" % line.rstrip()) |
|
2420 | 2420 | |
|
2421 | 2421 | @command('debugwireargs', |
|
2422 | 2422 | [('', 'three', '', 'three'), |
|
2423 | 2423 | ('', 'four', '', 'four'), |
|
2424 | 2424 | ('', 'five', '', 'five'), |
|
2425 | 2425 | ] + remoteopts, |
|
2426 | 2426 | _('REPO [OPTIONS]... [ONE [TWO]]')) |
|
2427 | 2427 | def debugwireargs(ui, repopath, *vals, **opts): |
|
2428 | 2428 | repo = hg.peer(ui, opts, repopath) |
|
2429 | 2429 | for opt in remoteopts: |
|
2430 | 2430 | del opts[opt[1]] |
|
2431 | 2431 | args = {} |
|
2432 | 2432 | for k, v in opts.iteritems(): |
|
2433 | 2433 | if v: |
|
2434 | 2434 | args[k] = v |
|
2435 | 2435 | # run twice to check that we don't mess up the stream for the next command |
|
2436 | 2436 | res1 = repo.debugwireargs(*vals, **args) |
|
2437 | 2437 | res2 = repo.debugwireargs(*vals, **args) |
|
2438 | 2438 | ui.write("%s\n" % res1) |
|
2439 | 2439 | if res1 != res2: |
|
2440 | 2440 | ui.warn("%s\n" % res2) |
|
2441 | 2441 | |
|
2442 | 2442 | @command('^diff', |
|
2443 | 2443 | [('r', 'rev', [], _('revision'), _('REV')), |
|
2444 | 2444 | ('c', 'change', '', _('change made by revision'), _('REV')) |
|
2445 | 2445 | ] + diffopts + diffopts2 + walkopts + subrepoopts, |
|
2446 | 2446 | _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...')) |
|
2447 | 2447 | def diff(ui, repo, *pats, **opts): |
|
2448 | 2448 | """diff repository (or selected files) |
|
2449 | 2449 | |
|
2450 | 2450 | Show differences between revisions for the specified files. |
|
2451 | 2451 | |
|
2452 | 2452 | Differences between files are shown using the unified diff format. |
|
2453 | 2453 | |
|
2454 | 2454 | .. note:: |
|
2455 | 2455 | diff may generate unexpected results for merges, as it will |
|
2456 | 2456 | default to comparing against the working directory's first |
|
2457 | 2457 | parent changeset if no revisions are specified. |
|
2458 | 2458 | |
|
2459 | 2459 | When two revision arguments are given, then changes are shown |
|
2460 | 2460 | between those revisions. If only one revision is specified then |
|
2461 | 2461 | that revision is compared to the working directory, and, when no |
|
2462 | 2462 | revisions are specified, the working directory files are compared |
|
2463 | 2463 | to its parent. |
|
2464 | 2464 | |
|
2465 | 2465 | Alternatively you can specify -c/--change with a revision to see |
|
2466 | 2466 | the changes in that changeset relative to its first parent. |
|
2467 | 2467 | |
|
2468 | 2468 | Without the -a/--text option, diff will avoid generating diffs of |
|
2469 | 2469 | files it detects as binary. With -a, diff will generate a diff |
|
2470 | 2470 | anyway, probably with undesirable results. |
|
2471 | 2471 | |
|
2472 | 2472 | Use the -g/--git option to generate diffs in the git extended diff |
|
2473 | 2473 | format. For more information, read :hg:`help diffs`. |
|
2474 | 2474 | |
|
2475 | 2475 | .. container:: verbose |
|
2476 | 2476 | |
|
2477 | 2477 | Examples: |
|
2478 | 2478 | |
|
2479 | 2479 | - compare a file in the current working directory to its parent:: |
|
2480 | 2480 | |
|
2481 | 2481 | hg diff foo.c |
|
2482 | 2482 | |
|
2483 | 2483 | - compare two historical versions of a directory, with rename info:: |
|
2484 | 2484 | |
|
2485 | 2485 | hg diff --git -r 1.0:1.2 lib/ |
|
2486 | 2486 | |
|
2487 | 2487 | - get change stats relative to the last change on some date:: |
|
2488 | 2488 | |
|
2489 | 2489 | hg diff --stat -r "date('may 2')" |
|
2490 | 2490 | |
|
2491 | 2491 | - diff all newly-added files that contain a keyword:: |
|
2492 | 2492 | |
|
2493 | 2493 | hg diff "set:added() and grep(GNU)" |
|
2494 | 2494 | |
|
2495 | 2495 | - compare a revision and its parents:: |
|
2496 | 2496 | |
|
2497 | 2497 | hg diff -c 9353 # compare against first parent |
|
2498 | 2498 | hg diff -r 9353^:9353 # same using revset syntax |
|
2499 | 2499 | hg diff -r 9353^2:9353 # compare against the second parent |
|
2500 | 2500 | |
|
2501 | 2501 | Returns 0 on success. |
|
2502 | 2502 | """ |
|
2503 | 2503 | |
|
2504 | 2504 | revs = opts.get('rev') |
|
2505 | 2505 | change = opts.get('change') |
|
2506 | 2506 | stat = opts.get('stat') |
|
2507 | 2507 | reverse = opts.get('reverse') |
|
2508 | 2508 | |
|
2509 | 2509 | if revs and change: |
|
2510 | 2510 | msg = _('cannot specify --rev and --change at the same time') |
|
2511 | 2511 | raise util.Abort(msg) |
|
2512 | 2512 | elif change: |
|
2513 | 2513 | node2 = scmutil.revsingle(repo, change, None).node() |
|
2514 | 2514 | node1 = repo[node2].p1().node() |
|
2515 | 2515 | else: |
|
2516 | 2516 | node1, node2 = scmutil.revpair(repo, revs) |
|
2517 | 2517 | |
|
2518 | 2518 | if reverse: |
|
2519 | 2519 | node1, node2 = node2, node1 |
|
2520 | 2520 | |
|
2521 | 2521 | diffopts = patch.diffopts(ui, opts) |
|
2522 | 2522 | m = scmutil.match(repo[node2], pats, opts) |
|
2523 | 2523 | cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat, |
|
2524 | 2524 | listsubrepos=opts.get('subrepos')) |
|
2525 | 2525 | |
|
2526 | 2526 | @command('^export', |
|
2527 | 2527 | [('o', 'output', '', |
|
2528 | 2528 | _('print output to file with formatted name'), _('FORMAT')), |
|
2529 | 2529 | ('', 'switch-parent', None, _('diff against the second parent')), |
|
2530 | 2530 | ('r', 'rev', [], _('revisions to export'), _('REV')), |
|
2531 | 2531 | ] + diffopts, |
|
2532 | 2532 | _('[OPTION]... [-o OUTFILESPEC] [-r] REV...')) |
|
2533 | 2533 | def export(ui, repo, *changesets, **opts): |
|
2534 | 2534 | """dump the header and diffs for one or more changesets |
|
2535 | 2535 | |
|
2536 | 2536 | Print the changeset header and diffs for one or more revisions. |
|
2537 | 2537 | |
|
2538 | 2538 | The information shown in the changeset header is: author, date, |
|
2539 | 2539 | branch name (if non-default), changeset hash, parent(s) and commit |
|
2540 | 2540 | comment. |
|
2541 | 2541 | |
|
2542 | 2542 | .. note:: |
|
2543 | 2543 | export may generate unexpected diff output for merge |
|
2544 | 2544 | changesets, as it will compare the merge changeset against its |
|
2545 | 2545 | first parent only. |
|
2546 | 2546 | |
|
2547 | 2547 | Output may be to a file, in which case the name of the file is |
|
2548 | 2548 | given using a format string. The formatting rules are as follows: |
|
2549 | 2549 | |
|
2550 | 2550 | :``%%``: literal "%" character |
|
2551 | 2551 | :``%H``: changeset hash (40 hexadecimal digits) |
|
2552 | 2552 | :``%N``: number of patches being generated |
|
2553 | 2553 | :``%R``: changeset revision number |
|
2554 | 2554 | :``%b``: basename of the exporting repository |
|
2555 | 2555 | :``%h``: short-form changeset hash (12 hexadecimal digits) |
|
2556 | 2556 | :``%m``: first line of the commit message (only alphanumeric characters) |
|
2557 | 2557 | :``%n``: zero-padded sequence number, starting at 1 |
|
2558 | 2558 | :``%r``: zero-padded changeset revision number |
|
2559 | 2559 | |
|
2560 | 2560 | Without the -a/--text option, export will avoid generating diffs |
|
2561 | 2561 | of files it detects as binary. With -a, export will generate a |
|
2562 | 2562 | diff anyway, probably with undesirable results. |
|
2563 | 2563 | |
|
2564 | 2564 | Use the -g/--git option to generate diffs in the git extended diff |
|
2565 | 2565 | format. See :hg:`help diffs` for more information. |
|
2566 | 2566 | |
|
2567 | 2567 | With the --switch-parent option, the diff will be against the |
|
2568 | 2568 | second parent. It can be useful to review a merge. |
|
2569 | 2569 | |
|
2570 | 2570 | .. container:: verbose |
|
2571 | 2571 | |
|
2572 | 2572 | Examples: |
|
2573 | 2573 | |
|
2574 | 2574 | - use export and import to transplant a bugfix to the current |
|
2575 | 2575 | branch:: |
|
2576 | 2576 | |
|
2577 | 2577 | hg export -r 9353 | hg import - |
|
2578 | 2578 | |
|
2579 | 2579 | - export all the changesets between two revisions to a file with |
|
2580 | 2580 | rename information:: |
|
2581 | 2581 | |
|
2582 | 2582 | hg export --git -r 123:150 > changes.txt |
|
2583 | 2583 | |
|
2584 | 2584 | - split outgoing changes into a series of patches with |
|
2585 | 2585 | descriptive names:: |
|
2586 | 2586 | |
|
2587 | 2587 | hg export -r "outgoing()" -o "%n-%m.patch" |
|
2588 | 2588 | |
|
2589 | 2589 | Returns 0 on success. |
|
2590 | 2590 | """ |
|
2591 | 2591 | changesets += tuple(opts.get('rev', [])) |
|
2592 | 2592 | revs = scmutil.revrange(repo, changesets) |
|
2593 | 2593 | if not revs: |
|
2594 | 2594 | raise util.Abort(_("export requires at least one changeset")) |
|
2595 | 2595 | if len(revs) > 1: |
|
2596 | 2596 | ui.note(_('exporting patches:\n')) |
|
2597 | 2597 | else: |
|
2598 | 2598 | ui.note(_('exporting patch:\n')) |
|
2599 | 2599 | cmdutil.export(repo, revs, template=opts.get('output'), |
|
2600 | 2600 | switch_parent=opts.get('switch_parent'), |
|
2601 | 2601 | opts=patch.diffopts(ui, opts)) |
|
2602 | 2602 | |
|
2603 | 2603 | @command('^forget', walkopts, _('[OPTION]... FILE...')) |
|
2604 | 2604 | def forget(ui, repo, *pats, **opts): |
|
2605 | 2605 | """forget the specified files on the next commit |
|
2606 | 2606 | |
|
2607 | 2607 | Mark the specified files so they will no longer be tracked |
|
2608 | 2608 | after the next commit. |
|
2609 | 2609 | |
|
2610 | 2610 | This only removes files from the current branch, not from the |
|
2611 | 2611 | entire project history, and it does not delete them from the |
|
2612 | 2612 | working directory. |
|
2613 | 2613 | |
|
2614 | 2614 | To undo a forget before the next commit, see :hg:`add`. |
|
2615 | 2615 | |
|
2616 | 2616 | .. container:: verbose |
|
2617 | 2617 | |
|
2618 | 2618 | Examples: |
|
2619 | 2619 | |
|
2620 | 2620 | - forget newly-added binary files:: |
|
2621 | 2621 | |
|
2622 | 2622 | hg forget "set:added() and binary()" |
|
2623 | 2623 | |
|
2624 | 2624 | - forget files that would be excluded by .hgignore:: |
|
2625 | 2625 | |
|
2626 | 2626 | hg forget "set:hgignore()" |
|
2627 | 2627 | |
|
2628 | 2628 | Returns 0 on success. |
|
2629 | 2629 | """ |
|
2630 | 2630 | |
|
2631 | 2631 | if not pats: |
|
2632 | 2632 | raise util.Abort(_('no files specified')) |
|
2633 | 2633 | |
|
2634 | 2634 | m = scmutil.match(repo[None], pats, opts) |
|
2635 | 2635 | rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0] |
|
2636 | 2636 | return rejected and 1 or 0 |
|
2637 | 2637 | |
|
2638 | 2638 | @command( |
|
2639 | 2639 | 'graft', |
|
2640 | 2640 | [('r', 'rev', [], _('revisions to graft'), _('REV')), |
|
2641 | 2641 | ('c', 'continue', False, _('resume interrupted graft')), |
|
2642 | 2642 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
2643 | 2643 | ('', 'log', None, _('append graft info to log message')), |
|
2644 | 2644 | ('D', 'currentdate', False, |
|
2645 | 2645 | _('record the current date as commit date')), |
|
2646 | 2646 | ('U', 'currentuser', False, |
|
2647 | 2647 | _('record the current user as committer'), _('DATE'))] |
|
2648 | 2648 | + commitopts2 + mergetoolopts + dryrunopts, |
|
2649 | 2649 | _('[OPTION]... [-r] REV...')) |
|
2650 | 2650 | def graft(ui, repo, *revs, **opts): |
|
2651 | 2651 | '''copy changes from other branches onto the current branch |
|
2652 | 2652 | |
|
2653 | 2653 | This command uses Mercurial's merge logic to copy individual |
|
2654 | 2654 | changes from other branches without merging branches in the |
|
2655 | 2655 | history graph. This is sometimes known as 'backporting' or |
|
2656 | 2656 | 'cherry-picking'. By default, graft will copy user, date, and |
|
2657 | 2657 | description from the source changesets. |
|
2658 | 2658 | |
|
2659 | 2659 | Changesets that are ancestors of the current revision, that have |
|
2660 | 2660 | already been grafted, or that are merges will be skipped. |
|
2661 | 2661 | |
|
2662 | 2662 | If --log is specified, log messages will have a comment appended |
|
2663 | 2663 | of the form:: |
|
2664 | 2664 | |
|
2665 | 2665 | (grafted from CHANGESETHASH) |
|
2666 | 2666 | |
|
2667 | 2667 | If a graft merge results in conflicts, the graft process is |
|
2668 | 2668 | interrupted so that the current merge can be manually resolved. |
|
2669 | 2669 | Once all conflicts are addressed, the graft process can be |
|
2670 | 2670 | continued with the -c/--continue option. |
|
2671 | 2671 | |
|
2672 | 2672 | .. note:: |
|
2673 | 2673 | The -c/--continue option does not reapply earlier options. |
|
2674 | 2674 | |
|
2675 | 2675 | .. container:: verbose |
|
2676 | 2676 | |
|
2677 | 2677 | Examples: |
|
2678 | 2678 | |
|
2679 | 2679 | - copy a single change to the stable branch and edit its description:: |
|
2680 | 2680 | |
|
2681 | 2681 | hg update stable |
|
2682 | 2682 | hg graft --edit 9393 |
|
2683 | 2683 | |
|
2684 | 2684 | - graft a range of changesets with one exception, updating dates:: |
|
2685 | 2685 | |
|
2686 | 2686 | hg graft -D "2085::2093 and not 2091" |
|
2687 | 2687 | |
|
2688 | 2688 | - continue a graft after resolving conflicts:: |
|
2689 | 2689 | |
|
2690 | 2690 | hg graft -c |
|
2691 | 2691 | |
|
2692 | 2692 | - show the source of a grafted changeset:: |
|
2693 | 2693 | |
|
2694 | 2694 | hg log --debug -r tip |
|
2695 | 2695 | |
|
2696 | 2696 | Returns 0 on successful completion. |
|
2697 | 2697 | ''' |
|
2698 | 2698 | |
|
2699 | 2699 | revs = list(revs) |
|
2700 | 2700 | revs.extend(opts['rev']) |
|
2701 | 2701 | |
|
2702 | 2702 | if not opts.get('user') and opts.get('currentuser'): |
|
2703 | 2703 | opts['user'] = ui.username() |
|
2704 | 2704 | if not opts.get('date') and opts.get('currentdate'): |
|
2705 | 2705 | opts['date'] = "%d %d" % util.makedate() |
|
2706 | 2706 | |
|
2707 | 2707 | editor = None |
|
2708 | 2708 | if opts.get('edit'): |
|
2709 | 2709 | editor = cmdutil.commitforceeditor |
|
2710 | 2710 | |
|
2711 | 2711 | cont = False |
|
2712 | 2712 | if opts['continue']: |
|
2713 | 2713 | cont = True |
|
2714 | 2714 | if revs: |
|
2715 | 2715 | raise util.Abort(_("can't specify --continue and revisions")) |
|
2716 | 2716 | # read in unfinished revisions |
|
2717 | 2717 | try: |
|
2718 | 2718 | nodes = repo.opener.read('graftstate').splitlines() |
|
2719 | 2719 | revs = [repo[node].rev() for node in nodes] |
|
2720 | 2720 | except IOError, inst: |
|
2721 | 2721 | if inst.errno != errno.ENOENT: |
|
2722 | 2722 | raise |
|
2723 | 2723 | raise util.Abort(_("no graft state found, can't continue")) |
|
2724 | 2724 | else: |
|
2725 | 2725 | cmdutil.bailifchanged(repo) |
|
2726 | 2726 | if not revs: |
|
2727 | 2727 | raise util.Abort(_('no revisions specified')) |
|
2728 | 2728 | revs = scmutil.revrange(repo, revs) |
|
2729 | 2729 | |
|
2730 | 2730 | # check for merges |
|
2731 | 2731 | for rev in repo.revs('%ld and merge()', revs): |
|
2732 | 2732 | ui.warn(_('skipping ungraftable merge revision %s\n') % rev) |
|
2733 | 2733 | revs.remove(rev) |
|
2734 | 2734 | if not revs: |
|
2735 | 2735 | return -1 |
|
2736 | 2736 | |
|
2737 | 2737 | # check for ancestors of dest branch |
|
2738 | 2738 | for rev in repo.revs('::. and %ld', revs): |
|
2739 | 2739 | ui.warn(_('skipping ancestor revision %s\n') % rev) |
|
2740 | 2740 | revs.remove(rev) |
|
2741 | 2741 | if not revs: |
|
2742 | 2742 | return -1 |
|
2743 | 2743 | |
|
2744 | 2744 | # analyze revs for earlier grafts |
|
2745 | 2745 | ids = {} |
|
2746 | 2746 | for ctx in repo.set("%ld", revs): |
|
2747 | 2747 | ids[ctx.hex()] = ctx.rev() |
|
2748 | 2748 | n = ctx.extra().get('source') |
|
2749 | 2749 | if n: |
|
2750 | 2750 | ids[n] = ctx.rev() |
|
2751 | 2751 | |
|
2752 | 2752 | # check ancestors for earlier grafts |
|
2753 | 2753 | ui.debug('scanning for duplicate grafts\n') |
|
2754 | 2754 | for ctx in repo.set("::. - ::%ld", revs): |
|
2755 | 2755 | n = ctx.extra().get('source') |
|
2756 | 2756 | if n in ids: |
|
2757 | 2757 | r = repo[n].rev() |
|
2758 | 2758 | if r in revs: |
|
2759 | 2759 | ui.warn(_('skipping already grafted revision %s\n') % r) |
|
2760 | 2760 | revs.remove(r) |
|
2761 | 2761 | elif ids[n] in revs: |
|
2762 | 2762 | ui.warn(_('skipping already grafted revision %s ' |
|
2763 | 2763 | '(same origin %d)\n') % (ids[n], r)) |
|
2764 | 2764 | revs.remove(ids[n]) |
|
2765 | 2765 | elif ctx.hex() in ids: |
|
2766 | 2766 | r = ids[ctx.hex()] |
|
2767 | 2767 | ui.warn(_('skipping already grafted revision %s ' |
|
2768 | 2768 | '(was grafted from %d)\n') % (r, ctx.rev())) |
|
2769 | 2769 | revs.remove(r) |
|
2770 | 2770 | if not revs: |
|
2771 | 2771 | return -1 |
|
2772 | 2772 | |
|
2773 | 2773 | wlock = repo.wlock() |
|
2774 | 2774 | try: |
|
2775 | 2775 | for pos, ctx in enumerate(repo.set("%ld", revs)): |
|
2776 | 2776 | current = repo['.'] |
|
2777 | 2777 | |
|
2778 | 2778 | ui.status(_('grafting revision %s\n') % ctx.rev()) |
|
2779 | 2779 | if opts.get('dry_run'): |
|
2780 | 2780 | continue |
|
2781 | 2781 | |
|
2782 | 2782 | # we don't merge the first commit when continuing |
|
2783 | 2783 | if not cont: |
|
2784 | 2784 | # perform the graft merge with p1(rev) as 'ancestor' |
|
2785 | 2785 | try: |
|
2786 | 2786 | # ui.forcemerge is an internal variable, do not document |
|
2787 | 2787 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
2788 | 2788 | stats = mergemod.update(repo, ctx.node(), True, True, False, |
|
2789 | 2789 | ctx.p1().node()) |
|
2790 | 2790 | finally: |
|
2791 | 2791 | repo.ui.setconfig('ui', 'forcemerge', '') |
|
2792 | 2792 | # report any conflicts |
|
2793 | 2793 | if stats and stats[3] > 0: |
|
2794 | 2794 | # write out state for --continue |
|
2795 | 2795 | nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] |
|
2796 | 2796 | repo.opener.write('graftstate', ''.join(nodelines)) |
|
2797 | 2797 | raise util.Abort( |
|
2798 | 2798 | _("unresolved conflicts, can't continue"), |
|
2799 | 2799 | hint=_('use hg resolve and hg graft --continue')) |
|
2800 | 2800 | else: |
|
2801 | 2801 | cont = False |
|
2802 | 2802 | |
|
2803 | 2803 | # drop the second merge parent |
|
2804 | 2804 | repo.setparents(current.node(), nullid) |
|
2805 | 2805 | repo.dirstate.write() |
|
2806 | 2806 | # fix up dirstate for copies and renames |
|
2807 | 2807 | cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev()) |
|
2808 | 2808 | |
|
2809 | 2809 | # commit |
|
2810 | 2810 | source = ctx.extra().get('source') |
|
2811 | 2811 | if not source: |
|
2812 | 2812 | source = ctx.hex() |
|
2813 | 2813 | extra = {'source': source} |
|
2814 | 2814 | user = ctx.user() |
|
2815 | 2815 | if opts.get('user'): |
|
2816 | 2816 | user = opts['user'] |
|
2817 | 2817 | date = ctx.date() |
|
2818 | 2818 | if opts.get('date'): |
|
2819 | 2819 | date = opts['date'] |
|
2820 | 2820 | message = ctx.description() |
|
2821 | 2821 | if opts.get('log'): |
|
2822 | 2822 | message += '\n(grafted from %s)' % ctx.hex() |
|
2823 | 2823 | node = repo.commit(text=message, user=user, |
|
2824 | 2824 | date=date, extra=extra, editor=editor) |
|
2825 | 2825 | if node is None: |
|
2826 | 2826 | ui.status(_('graft for revision %s is empty\n') % ctx.rev()) |
|
2827 | 2827 | finally: |
|
2828 | 2828 | wlock.release() |
|
2829 | 2829 | |
|
2830 | 2830 | # remove state when we complete successfully |
|
2831 | 2831 | if not opts.get('dry_run') and os.path.exists(repo.join('graftstate')): |
|
2832 | 2832 | util.unlinkpath(repo.join('graftstate')) |
|
2833 | 2833 | |
|
2834 | 2834 | return 0 |
|
2835 | 2835 | |
|
2836 | 2836 | @command('grep', |
|
2837 | 2837 | [('0', 'print0', None, _('end fields with NUL')), |
|
2838 | 2838 | ('', 'all', None, _('print all revisions that match')), |
|
2839 | 2839 | ('a', 'text', None, _('treat all files as text')), |
|
2840 | 2840 | ('f', 'follow', None, |
|
2841 | 2841 | _('follow changeset history,' |
|
2842 | 2842 | ' or file history across copies and renames')), |
|
2843 | 2843 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2844 | 2844 | ('l', 'files-with-matches', None, |
|
2845 | 2845 | _('print only filenames and revisions that match')), |
|
2846 | 2846 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2847 | 2847 | ('r', 'rev', [], |
|
2848 | 2848 | _('only search files changed within revision range'), _('REV')), |
|
2849 | 2849 | ('u', 'user', None, _('list the author (long with -v)')), |
|
2850 | 2850 | ('d', 'date', None, _('list the date (short with -q)')), |
|
2851 | 2851 | ] + walkopts, |
|
2852 | 2852 | _('[OPTION]... PATTERN [FILE]...')) |
|
2853 | 2853 | def grep(ui, repo, pattern, *pats, **opts): |
|
2854 | 2854 | """search for a pattern in specified files and revisions |
|
2855 | 2855 | |
|
2856 | 2856 | Search revisions of files for a regular expression. |
|
2857 | 2857 | |
|
2858 | 2858 | This command behaves differently than Unix grep. It only accepts |
|
2859 | 2859 | Python/Perl regexps. It searches repository history, not the |
|
2860 | 2860 | working directory. It always prints the revision number in which a |
|
2861 | 2861 | match appears. |
|
2862 | 2862 | |
|
2863 | 2863 | By default, grep only prints output for the first revision of a |
|
2864 | 2864 | file in which it finds a match. To get it to print every revision |
|
2865 | 2865 | that contains a change in match status ("-" for a match that |
|
2866 | 2866 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
2867 | 2867 | use the --all flag. |
|
2868 | 2868 | |
|
2869 | 2869 | Returns 0 if a match is found, 1 otherwise. |
|
2870 | 2870 | """ |
|
2871 | 2871 | reflags = re.M |
|
2872 | 2872 | if opts.get('ignore_case'): |
|
2873 | 2873 | reflags |= re.I |
|
2874 | 2874 | try: |
|
2875 | 2875 | regexp = re.compile(pattern, reflags) |
|
2876 | 2876 | except re.error, inst: |
|
2877 | 2877 | ui.warn(_("grep: invalid match pattern: %s\n") % inst) |
|
2878 | 2878 | return 1 |
|
2879 | 2879 | sep, eol = ':', '\n' |
|
2880 | 2880 | if opts.get('print0'): |
|
2881 | 2881 | sep = eol = '\0' |
|
2882 | 2882 | |
|
2883 | 2883 | getfile = util.lrucachefunc(repo.file) |
|
2884 | 2884 | |
|
2885 | 2885 | def matchlines(body): |
|
2886 | 2886 | begin = 0 |
|
2887 | 2887 | linenum = 0 |
|
2888 | 2888 | while True: |
|
2889 | 2889 | match = regexp.search(body, begin) |
|
2890 | 2890 | if not match: |
|
2891 | 2891 | break |
|
2892 | 2892 | mstart, mend = match.span() |
|
2893 | 2893 | linenum += body.count('\n', begin, mstart) + 1 |
|
2894 | 2894 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
2895 | 2895 | begin = body.find('\n', mend) + 1 or len(body) + 1 |
|
2896 | 2896 | lend = begin - 1 |
|
2897 | 2897 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
2898 | 2898 | |
|
2899 | 2899 | class linestate(object): |
|
2900 | 2900 | def __init__(self, line, linenum, colstart, colend): |
|
2901 | 2901 | self.line = line |
|
2902 | 2902 | self.linenum = linenum |
|
2903 | 2903 | self.colstart = colstart |
|
2904 | 2904 | self.colend = colend |
|
2905 | 2905 | |
|
2906 | 2906 | def __hash__(self): |
|
2907 | 2907 | return hash((self.linenum, self.line)) |
|
2908 | 2908 | |
|
2909 | 2909 | def __eq__(self, other): |
|
2910 | 2910 | return self.line == other.line |
|
2911 | 2911 | |
|
2912 | 2912 | matches = {} |
|
2913 | 2913 | copies = {} |
|
2914 | 2914 | def grepbody(fn, rev, body): |
|
2915 | 2915 | matches[rev].setdefault(fn, []) |
|
2916 | 2916 | m = matches[rev][fn] |
|
2917 | 2917 | for lnum, cstart, cend, line in matchlines(body): |
|
2918 | 2918 | s = linestate(line, lnum, cstart, cend) |
|
2919 | 2919 | m.append(s) |
|
2920 | 2920 | |
|
2921 | 2921 | def difflinestates(a, b): |
|
2922 | 2922 | sm = difflib.SequenceMatcher(None, a, b) |
|
2923 | 2923 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
2924 | 2924 | if tag == 'insert': |
|
2925 | 2925 | for i in xrange(blo, bhi): |
|
2926 | 2926 | yield ('+', b[i]) |
|
2927 | 2927 | elif tag == 'delete': |
|
2928 | 2928 | for i in xrange(alo, ahi): |
|
2929 | 2929 | yield ('-', a[i]) |
|
2930 | 2930 | elif tag == 'replace': |
|
2931 | 2931 | for i in xrange(alo, ahi): |
|
2932 | 2932 | yield ('-', a[i]) |
|
2933 | 2933 | for i in xrange(blo, bhi): |
|
2934 | 2934 | yield ('+', b[i]) |
|
2935 | 2935 | |
|
2936 | 2936 | def display(fn, ctx, pstates, states): |
|
2937 | 2937 | rev = ctx.rev() |
|
2938 | 2938 | datefunc = ui.quiet and util.shortdate or util.datestr |
|
2939 | 2939 | found = False |
|
2940 | 2940 | filerevmatches = {} |
|
2941 | 2941 | def binary(): |
|
2942 | 2942 | flog = getfile(fn) |
|
2943 | 2943 | return util.binary(flog.read(ctx.filenode(fn))) |
|
2944 | 2944 | |
|
2945 | 2945 | if opts.get('all'): |
|
2946 | 2946 | iter = difflinestates(pstates, states) |
|
2947 | 2947 | else: |
|
2948 | 2948 | iter = [('', l) for l in states] |
|
2949 | 2949 | for change, l in iter: |
|
2950 | 2950 | cols = [fn, str(rev)] |
|
2951 | 2951 | before, match, after = None, None, None |
|
2952 | 2952 | if opts.get('line_number'): |
|
2953 | 2953 | cols.append(str(l.linenum)) |
|
2954 | 2954 | if opts.get('all'): |
|
2955 | 2955 | cols.append(change) |
|
2956 | 2956 | if opts.get('user'): |
|
2957 | 2957 | cols.append(ui.shortuser(ctx.user())) |
|
2958 | 2958 | if opts.get('date'): |
|
2959 | 2959 | cols.append(datefunc(ctx.date())) |
|
2960 | 2960 | if opts.get('files_with_matches'): |
|
2961 | 2961 | c = (fn, rev) |
|
2962 | 2962 | if c in filerevmatches: |
|
2963 | 2963 | continue |
|
2964 | 2964 | filerevmatches[c] = 1 |
|
2965 | 2965 | else: |
|
2966 | 2966 | before = l.line[:l.colstart] |
|
2967 | 2967 | match = l.line[l.colstart:l.colend] |
|
2968 | 2968 | after = l.line[l.colend:] |
|
2969 | 2969 | ui.write(sep.join(cols)) |
|
2970 | 2970 | if before is not None: |
|
2971 | 2971 | if not opts.get('text') and binary(): |
|
2972 | 2972 | ui.write(sep + " Binary file matches") |
|
2973 | 2973 | else: |
|
2974 | 2974 | ui.write(sep + before) |
|
2975 | 2975 | ui.write(match, label='grep.match') |
|
2976 | 2976 | ui.write(after) |
|
2977 | 2977 | ui.write(eol) |
|
2978 | 2978 | found = True |
|
2979 | 2979 | return found |
|
2980 | 2980 | |
|
2981 | 2981 | skip = {} |
|
2982 | 2982 | revfiles = {} |
|
2983 | 2983 | matchfn = scmutil.match(repo[None], pats, opts) |
|
2984 | 2984 | found = False |
|
2985 | 2985 | follow = opts.get('follow') |
|
2986 | 2986 | |
|
2987 | 2987 | def prep(ctx, fns): |
|
2988 | 2988 | rev = ctx.rev() |
|
2989 | 2989 | pctx = ctx.p1() |
|
2990 | 2990 | parent = pctx.rev() |
|
2991 | 2991 | matches.setdefault(rev, {}) |
|
2992 | 2992 | matches.setdefault(parent, {}) |
|
2993 | 2993 | files = revfiles.setdefault(rev, []) |
|
2994 | 2994 | for fn in fns: |
|
2995 | 2995 | flog = getfile(fn) |
|
2996 | 2996 | try: |
|
2997 | 2997 | fnode = ctx.filenode(fn) |
|
2998 | 2998 | except error.LookupError: |
|
2999 | 2999 | continue |
|
3000 | 3000 | |
|
3001 | 3001 | copied = flog.renamed(fnode) |
|
3002 | 3002 | copy = follow and copied and copied[0] |
|
3003 | 3003 | if copy: |
|
3004 | 3004 | copies.setdefault(rev, {})[fn] = copy |
|
3005 | 3005 | if fn in skip: |
|
3006 | 3006 | if copy: |
|
3007 | 3007 | skip[copy] = True |
|
3008 | 3008 | continue |
|
3009 | 3009 | files.append(fn) |
|
3010 | 3010 | |
|
3011 | 3011 | if fn not in matches[rev]: |
|
3012 | 3012 | grepbody(fn, rev, flog.read(fnode)) |
|
3013 | 3013 | |
|
3014 | 3014 | pfn = copy or fn |
|
3015 | 3015 | if pfn not in matches[parent]: |
|
3016 | 3016 | try: |
|
3017 | 3017 | fnode = pctx.filenode(pfn) |
|
3018 | 3018 | grepbody(pfn, parent, flog.read(fnode)) |
|
3019 | 3019 | except error.LookupError: |
|
3020 | 3020 | pass |
|
3021 | 3021 | |
|
3022 | 3022 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
3023 | 3023 | rev = ctx.rev() |
|
3024 | 3024 | parent = ctx.p1().rev() |
|
3025 | 3025 | for fn in sorted(revfiles.get(rev, [])): |
|
3026 | 3026 | states = matches[rev][fn] |
|
3027 | 3027 | copy = copies.get(rev, {}).get(fn) |
|
3028 | 3028 | if fn in skip: |
|
3029 | 3029 | if copy: |
|
3030 | 3030 | skip[copy] = True |
|
3031 | 3031 | continue |
|
3032 | 3032 | pstates = matches.get(parent, {}).get(copy or fn, []) |
|
3033 | 3033 | if pstates or states: |
|
3034 | 3034 | r = display(fn, ctx, pstates, states) |
|
3035 | 3035 | found = found or r |
|
3036 | 3036 | if r and not opts.get('all'): |
|
3037 | 3037 | skip[fn] = True |
|
3038 | 3038 | if copy: |
|
3039 | 3039 | skip[copy] = True |
|
3040 | 3040 | del matches[rev] |
|
3041 | 3041 | del revfiles[rev] |
|
3042 | 3042 | |
|
3043 | 3043 | return not found |
|
3044 | 3044 | |
|
3045 | 3045 | @command('heads', |
|
3046 | 3046 | [('r', 'rev', '', |
|
3047 | 3047 | _('show only heads which are descendants of STARTREV'), _('STARTREV')), |
|
3048 | 3048 | ('t', 'topo', False, _('show topological heads only')), |
|
3049 | 3049 | ('a', 'active', False, _('show active branchheads only (DEPRECATED)')), |
|
3050 | 3050 | ('c', 'closed', False, _('show normal and closed branch heads')), |
|
3051 | 3051 | ] + templateopts, |
|
3052 | 3052 | _('[-ct] [-r STARTREV] [REV]...')) |
|
3053 | 3053 | def heads(ui, repo, *branchrevs, **opts): |
|
3054 | 3054 | """show current repository heads or show branch heads |
|
3055 | 3055 | |
|
3056 | 3056 | With no arguments, show all repository branch heads. |
|
3057 | 3057 | |
|
3058 | 3058 | Repository "heads" are changesets with no child changesets. They are |
|
3059 | 3059 | where development generally takes place and are the usual targets |
|
3060 | 3060 | for update and merge operations. Branch heads are changesets that have |
|
3061 | 3061 | no child changeset on the same branch. |
|
3062 | 3062 | |
|
3063 | 3063 | If one or more REVs are given, only branch heads on the branches |
|
3064 | 3064 | associated with the specified changesets are shown. This means |
|
3065 | 3065 | that you can use :hg:`heads foo` to see the heads on a branch |
|
3066 | 3066 | named ``foo``. |
|
3067 | 3067 | |
|
3068 | 3068 | If -c/--closed is specified, also show branch heads marked closed |
|
3069 | 3069 | (see :hg:`commit --close-branch`). |
|
3070 | 3070 | |
|
3071 | 3071 | If STARTREV is specified, only those heads that are descendants of |
|
3072 | 3072 | STARTREV will be displayed. |
|
3073 | 3073 | |
|
3074 | 3074 | If -t/--topo is specified, named branch mechanics will be ignored and only |
|
3075 | 3075 | changesets without children will be shown. |
|
3076 | 3076 | |
|
3077 | 3077 | Returns 0 if matching heads are found, 1 if not. |
|
3078 | 3078 | """ |
|
3079 | 3079 | |
|
3080 | 3080 | start = None |
|
3081 | 3081 | if 'rev' in opts: |
|
3082 | 3082 | start = scmutil.revsingle(repo, opts['rev'], None).node() |
|
3083 | 3083 | |
|
3084 | 3084 | if opts.get('topo'): |
|
3085 | 3085 | heads = [repo[h] for h in repo.heads(start)] |
|
3086 | 3086 | else: |
|
3087 | 3087 | heads = [] |
|
3088 | 3088 | for branch in repo.branchmap(): |
|
3089 | 3089 | heads += repo.branchheads(branch, start, opts.get('closed')) |
|
3090 | 3090 | heads = [repo[h] for h in heads] |
|
3091 | 3091 | |
|
3092 | 3092 | if branchrevs: |
|
3093 | 3093 | branches = set(repo[br].branch() for br in branchrevs) |
|
3094 | 3094 | heads = [h for h in heads if h.branch() in branches] |
|
3095 | 3095 | |
|
3096 | 3096 | if opts.get('active') and branchrevs: |
|
3097 | 3097 | dagheads = repo.heads(start) |
|
3098 | 3098 | heads = [h for h in heads if h.node() in dagheads] |
|
3099 | 3099 | |
|
3100 | 3100 | if branchrevs: |
|
3101 | 3101 | haveheads = set(h.branch() for h in heads) |
|
3102 | 3102 | if branches - haveheads: |
|
3103 | 3103 | headless = ', '.join(b for b in branches - haveheads) |
|
3104 | 3104 | msg = _('no open branch heads found on branches %s') |
|
3105 | 3105 | if opts.get('rev'): |
|
3106 | 3106 | msg += _(' (started at %s)') % opts['rev'] |
|
3107 | 3107 | ui.warn((msg + '\n') % headless) |
|
3108 | 3108 | |
|
3109 | 3109 | if not heads: |
|
3110 | 3110 | return 1 |
|
3111 | 3111 | |
|
3112 | 3112 | heads = sorted(heads, key=lambda x: -x.rev()) |
|
3113 | 3113 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
3114 | 3114 | for ctx in heads: |
|
3115 | 3115 | displayer.show(ctx) |
|
3116 | 3116 | displayer.close() |
|
3117 | 3117 | |
|
3118 | 3118 | @command('help', |
|
3119 | 3119 | [('e', 'extension', None, _('show only help for extensions')), |
|
3120 | 3120 | ('c', 'command', None, _('show only help for commands')), |
|
3121 | 3121 | ('k', 'keyword', '', _('show topics matching keyword')), |
|
3122 | 3122 | ], |
|
3123 | 3123 | _('[-ec] [TOPIC]')) |
|
3124 | 3124 | def help_(ui, name=None, unknowncmd=False, full=True, **opts): |
|
3125 | 3125 | """show help for a given topic or a help overview |
|
3126 | 3126 | |
|
3127 | 3127 | With no arguments, print a list of commands with short help messages. |
|
3128 | 3128 | |
|
3129 | 3129 | Given a topic, extension, or command name, print help for that |
|
3130 | 3130 | topic. |
|
3131 | 3131 | |
|
3132 | 3132 | Returns 0 if successful. |
|
3133 | 3133 | """ |
|
3134 | 3134 | |
|
3135 | 3135 | textwidth = min(ui.termwidth(), 80) - 2 |
|
3136 | 3136 | |
|
3137 | 3137 | def helpcmd(name): |
|
3138 | 3138 | try: |
|
3139 | 3139 | aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd) |
|
3140 | 3140 | except error.AmbiguousCommand, inst: |
|
3141 | 3141 | # py3k fix: except vars can't be used outside the scope of the |
|
3142 | 3142 | # except block, nor can be used inside a lambda. python issue4617 |
|
3143 | 3143 | prefix = inst.args[0] |
|
3144 | 3144 | select = lambda c: c.lstrip('^').startswith(prefix) |
|
3145 | 3145 | rst = helplist(select) |
|
3146 | 3146 | return rst |
|
3147 | 3147 | |
|
3148 | 3148 | rst = [] |
|
3149 | 3149 | |
|
3150 | 3150 | # check if it's an invalid alias and display its error if it is |
|
3151 | 3151 | if getattr(entry[0], 'badalias', False): |
|
3152 | 3152 | if not unknowncmd: |
|
3153 | 3153 | ui.pushbuffer() |
|
3154 | 3154 | entry[0](ui) |
|
3155 | 3155 | rst.append(ui.popbuffer()) |
|
3156 | 3156 | return rst |
|
3157 | 3157 | |
|
3158 | 3158 | # synopsis |
|
3159 | 3159 | if len(entry) > 2: |
|
3160 | 3160 | if entry[2].startswith('hg'): |
|
3161 | 3161 | rst.append("%s\n" % entry[2]) |
|
3162 | 3162 | else: |
|
3163 | 3163 | rst.append('hg %s %s\n' % (aliases[0], entry[2])) |
|
3164 | 3164 | else: |
|
3165 | 3165 | rst.append('hg %s\n' % aliases[0]) |
|
3166 | 3166 | # aliases |
|
3167 | 3167 | if full and not ui.quiet and len(aliases) > 1: |
|
3168 | 3168 | rst.append(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
3169 | 3169 | rst.append('\n') |
|
3170 | 3170 | |
|
3171 | 3171 | # description |
|
3172 | 3172 | doc = gettext(entry[0].__doc__) |
|
3173 | 3173 | if not doc: |
|
3174 | 3174 | doc = _("(no help text available)") |
|
3175 | 3175 | if util.safehasattr(entry[0], 'definition'): # aliased command |
|
3176 | 3176 | if entry[0].definition.startswith('!'): # shell alias |
|
3177 | 3177 | doc = _('shell alias for::\n\n %s') % entry[0].definition[1:] |
|
3178 | 3178 | else: |
|
3179 | 3179 | doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc) |
|
3180 | 3180 | doc = doc.splitlines(True) |
|
3181 | 3181 | if ui.quiet or not full: |
|
3182 | 3182 | rst.append(doc[0]) |
|
3183 | 3183 | else: |
|
3184 | 3184 | rst.extend(doc) |
|
3185 | 3185 | rst.append('\n') |
|
3186 | 3186 | |
|
3187 | 3187 | # check if this command shadows a non-trivial (multi-line) |
|
3188 | 3188 | # extension help text |
|
3189 | 3189 | try: |
|
3190 | 3190 | mod = extensions.find(name) |
|
3191 | 3191 | doc = gettext(mod.__doc__) or '' |
|
3192 | 3192 | if '\n' in doc.strip(): |
|
3193 | 3193 | msg = _('use "hg help -e %s" to show help for ' |
|
3194 | 3194 | 'the %s extension') % (name, name) |
|
3195 | 3195 | rst.append('\n%s\n' % msg) |
|
3196 | 3196 | except KeyError: |
|
3197 | 3197 | pass |
|
3198 | 3198 | |
|
3199 | 3199 | # options |
|
3200 | 3200 | if not ui.quiet and entry[1]: |
|
3201 | 3201 | rst.append('\n%s\n\n' % _("options:")) |
|
3202 | 3202 | rst.append(help.optrst(entry[1], ui.verbose)) |
|
3203 | 3203 | |
|
3204 | 3204 | if ui.verbose: |
|
3205 | 3205 | rst.append('\n%s\n\n' % _("global options:")) |
|
3206 | 3206 | rst.append(help.optrst(globalopts, ui.verbose)) |
|
3207 | 3207 | |
|
3208 | 3208 | if not ui.verbose: |
|
3209 | 3209 | if not full: |
|
3210 | 3210 | rst.append(_('\nuse "hg help %s" to show the full help text\n') |
|
3211 | 3211 | % name) |
|
3212 | 3212 | elif not ui.quiet: |
|
3213 | 3213 | rst.append(_('\nuse "hg -v help %s" to show more info\n') |
|
3214 | 3214 | % name) |
|
3215 | 3215 | return rst |
|
3216 | 3216 | |
|
3217 | 3217 | |
|
3218 | 3218 | def helplist(select=None): |
|
3219 | 3219 | # list of commands |
|
3220 | 3220 | if name == "shortlist": |
|
3221 | 3221 | header = _('basic commands:\n\n') |
|
3222 | 3222 | else: |
|
3223 | 3223 | header = _('list of commands:\n\n') |
|
3224 | 3224 | |
|
3225 | 3225 | h = {} |
|
3226 | 3226 | cmds = {} |
|
3227 | 3227 | for c, e in table.iteritems(): |
|
3228 | 3228 | f = c.split("|", 1)[0] |
|
3229 | 3229 | if select and not select(f): |
|
3230 | 3230 | continue |
|
3231 | 3231 | if (not select and name != 'shortlist' and |
|
3232 | 3232 | e[0].__module__ != __name__): |
|
3233 | 3233 | continue |
|
3234 | 3234 | if name == "shortlist" and not f.startswith("^"): |
|
3235 | 3235 | continue |
|
3236 | 3236 | f = f.lstrip("^") |
|
3237 | 3237 | if not ui.debugflag and f.startswith("debug"): |
|
3238 | 3238 | continue |
|
3239 | 3239 | doc = e[0].__doc__ |
|
3240 | 3240 | if doc and 'DEPRECATED' in doc and not ui.verbose: |
|
3241 | 3241 | continue |
|
3242 | 3242 | doc = gettext(doc) |
|
3243 | 3243 | if not doc: |
|
3244 | 3244 | doc = _("(no help text available)") |
|
3245 | 3245 | h[f] = doc.splitlines()[0].rstrip() |
|
3246 | 3246 | cmds[f] = c.lstrip("^") |
|
3247 | 3247 | |
|
3248 | 3248 | rst = [] |
|
3249 | 3249 | if not h: |
|
3250 | 3250 | if not ui.quiet: |
|
3251 | 3251 | rst.append(_('no commands defined\n')) |
|
3252 | 3252 | return rst |
|
3253 | 3253 | |
|
3254 | 3254 | if not ui.quiet: |
|
3255 | 3255 | rst.append(header) |
|
3256 | 3256 | fns = sorted(h) |
|
3257 | 3257 | for f in fns: |
|
3258 | 3258 | if ui.verbose: |
|
3259 | 3259 | commands = cmds[f].replace("|",", ") |
|
3260 | 3260 | rst.append(" :%s: %s\n" % (commands, h[f])) |
|
3261 | 3261 | else: |
|
3262 | 3262 | rst.append(' :%s: %s\n' % (f, h[f])) |
|
3263 | 3263 | |
|
3264 | 3264 | if not name: |
|
3265 | 3265 | exts = help.listexts(_('enabled extensions:'), extensions.enabled()) |
|
3266 | 3266 | if exts: |
|
3267 | 3267 | rst.append('\n') |
|
3268 | 3268 | rst.extend(exts) |
|
3269 | 3269 | |
|
3270 | 3270 | rst.append(_("\nadditional help topics:\n\n")) |
|
3271 | 3271 | topics = [] |
|
3272 | 3272 | for names, header, doc in help.helptable: |
|
3273 | 3273 | topics.append((sorted(names, key=len, reverse=True)[0], header)) |
|
3274 | 3274 | for t, desc in topics: |
|
3275 | 3275 | rst.append(" :%s: %s\n" % (t, desc)) |
|
3276 | 3276 | |
|
3277 | 3277 | optlist = [] |
|
3278 | 3278 | if not ui.quiet: |
|
3279 | 3279 | if ui.verbose: |
|
3280 | 3280 | optlist.append((_("global options:"), globalopts)) |
|
3281 | 3281 | if name == 'shortlist': |
|
3282 | 3282 | optlist.append((_('use "hg help" for the full list ' |
|
3283 | 3283 | 'of commands'), ())) |
|
3284 | 3284 | else: |
|
3285 | 3285 | if name == 'shortlist': |
|
3286 | 3286 | msg = _('use "hg help" for the full list of commands ' |
|
3287 | 3287 | 'or "hg -v" for details') |
|
3288 | 3288 | elif name and not full: |
|
3289 | 3289 | msg = _('use "hg help %s" to show the full help ' |
|
3290 | 3290 | 'text') % name |
|
3291 | 3291 | else: |
|
3292 | 3292 | msg = _('use "hg -v help%s" to show builtin aliases and ' |
|
3293 | 3293 | 'global options') % (name and " " + name or "") |
|
3294 | 3294 | optlist.append((msg, ())) |
|
3295 | 3295 | |
|
3296 | 3296 | if optlist: |
|
3297 | 3297 | for title, options in optlist: |
|
3298 | 3298 | rst.append('\n%s\n' % title) |
|
3299 | 3299 | if options: |
|
3300 | 3300 | rst.append('\n%s\n' % help.optrst(options, ui.verbose)) |
|
3301 | 3301 | return rst |
|
3302 | 3302 | |
|
3303 | 3303 | def helptopic(name): |
|
3304 | 3304 | for names, header, doc in help.helptable: |
|
3305 | 3305 | if name in names: |
|
3306 | 3306 | break |
|
3307 | 3307 | else: |
|
3308 | 3308 | raise error.UnknownCommand(name) |
|
3309 | 3309 | |
|
3310 | 3310 | rst = ["%s\n\n" % header] |
|
3311 | 3311 | # description |
|
3312 | 3312 | if not doc: |
|
3313 | 3313 | rst.append(" %s\n" % _("(no help text available)")) |
|
3314 | 3314 | if util.safehasattr(doc, '__call__'): |
|
3315 | 3315 | rst += [" %s\n" % l for l in doc().splitlines()] |
|
3316 | 3316 | |
|
3317 | 3317 | try: |
|
3318 | 3318 | cmdutil.findcmd(name, table) |
|
3319 | 3319 | rst.append(_('\nuse "hg help -c %s" to see help for ' |
|
3320 | 3320 | 'the %s command\n') % (name, name)) |
|
3321 | 3321 | except error.UnknownCommand: |
|
3322 | 3322 | pass |
|
3323 | 3323 | return rst |
|
3324 | 3324 | |
|
3325 | 3325 | def helpext(name): |
|
3326 | 3326 | try: |
|
3327 | 3327 | mod = extensions.find(name) |
|
3328 | 3328 | doc = gettext(mod.__doc__) or _('no help text available') |
|
3329 | 3329 | except KeyError: |
|
3330 | 3330 | mod = None |
|
3331 | 3331 | doc = extensions.disabledext(name) |
|
3332 | 3332 | if not doc: |
|
3333 | 3333 | raise error.UnknownCommand(name) |
|
3334 | 3334 | |
|
3335 | 3335 | if '\n' not in doc: |
|
3336 | 3336 | head, tail = doc, "" |
|
3337 | 3337 | else: |
|
3338 | 3338 | head, tail = doc.split('\n', 1) |
|
3339 | 3339 | rst = [_('%s extension - %s\n\n') % (name.split('.')[-1], head)] |
|
3340 | 3340 | if tail: |
|
3341 | 3341 | rst.extend(tail.splitlines(True)) |
|
3342 | 3342 | rst.append('\n') |
|
3343 | 3343 | |
|
3344 | 3344 | if mod: |
|
3345 | 3345 | try: |
|
3346 | 3346 | ct = mod.cmdtable |
|
3347 | 3347 | except AttributeError: |
|
3348 | 3348 | ct = {} |
|
3349 | 3349 | modcmds = set([c.split('|', 1)[0] for c in ct]) |
|
3350 | 3350 | rst.extend(helplist(modcmds.__contains__)) |
|
3351 | 3351 | else: |
|
3352 | 3352 | rst.append(_('use "hg help extensions" for information on enabling ' |
|
3353 | 3353 | 'extensions\n')) |
|
3354 | 3354 | return rst |
|
3355 | 3355 | |
|
3356 | 3356 | def helpextcmd(name): |
|
3357 | 3357 | cmd, ext, mod = extensions.disabledcmd(ui, name, |
|
3358 | 3358 | ui.configbool('ui', 'strict')) |
|
3359 | 3359 | doc = gettext(mod.__doc__).splitlines()[0] |
|
3360 | 3360 | |
|
3361 | 3361 | rst = help.listexts(_("'%s' is provided by the following " |
|
3362 | 3362 | "extension:") % cmd, {ext: doc}, indent=4) |
|
3363 | 3363 | rst.append('\n') |
|
3364 | 3364 | rst.append(_('use "hg help extensions" for information on enabling ' |
|
3365 | 3365 | 'extensions\n')) |
|
3366 | 3366 | return rst |
|
3367 | 3367 | |
|
3368 | 3368 | |
|
3369 | 3369 | rst = [] |
|
3370 | 3370 | kw = opts.get('keyword') |
|
3371 | 3371 | if kw: |
|
3372 | 3372 | matches = help.topicmatch(kw) |
|
3373 | 3373 | for t, title in (('topics', _('Topics')), |
|
3374 | 3374 | ('commands', _('Commands')), |
|
3375 | 3375 | ('extensions', _('Extensions')), |
|
3376 | 3376 | ('extensioncommands', _('Extension Commands'))): |
|
3377 | 3377 | if matches[t]: |
|
3378 | 3378 | rst.append('%s:\n\n' % title) |
|
3379 | 3379 | rst.extend(minirst.maketable(sorted(matches[t]), 1)) |
|
3380 | 3380 | rst.append('\n') |
|
3381 | 3381 | elif name and name != 'shortlist': |
|
3382 | 3382 | i = None |
|
3383 | 3383 | if unknowncmd: |
|
3384 | 3384 | queries = (helpextcmd,) |
|
3385 | 3385 | elif opts.get('extension'): |
|
3386 | 3386 | queries = (helpext,) |
|
3387 | 3387 | elif opts.get('command'): |
|
3388 | 3388 | queries = (helpcmd,) |
|
3389 | 3389 | else: |
|
3390 | 3390 | queries = (helptopic, helpcmd, helpext, helpextcmd) |
|
3391 | 3391 | for f in queries: |
|
3392 | 3392 | try: |
|
3393 | 3393 | rst = f(name) |
|
3394 | 3394 | i = None |
|
3395 | 3395 | break |
|
3396 | 3396 | except error.UnknownCommand, inst: |
|
3397 | 3397 | i = inst |
|
3398 | 3398 | if i: |
|
3399 | 3399 | raise i |
|
3400 | 3400 | else: |
|
3401 | 3401 | # program name |
|
3402 | 3402 | if not ui.quiet: |
|
3403 | 3403 | rst = [_("Mercurial Distributed SCM\n"), '\n'] |
|
3404 | 3404 | rst.extend(helplist()) |
|
3405 | 3405 | |
|
3406 | 3406 | keep = ui.verbose and ['verbose'] or [] |
|
3407 | 3407 | formatted, pruned = minirst.format(''.join(rst), textwidth, keep=keep) |
|
3408 | 3408 | ui.write(formatted) |
|
3409 | 3409 | |
|
3410 | 3410 | |
|
3411 | 3411 | @command('identify|id', |
|
3412 | 3412 | [('r', 'rev', '', |
|
3413 | 3413 | _('identify the specified revision'), _('REV')), |
|
3414 | 3414 | ('n', 'num', None, _('show local revision number')), |
|
3415 | 3415 | ('i', 'id', None, _('show global revision id')), |
|
3416 | 3416 | ('b', 'branch', None, _('show branch')), |
|
3417 | 3417 | ('t', 'tags', None, _('show tags')), |
|
3418 | 3418 | ('B', 'bookmarks', None, _('show bookmarks')), |
|
3419 | 3419 | ] + remoteopts, |
|
3420 | 3420 | _('[-nibtB] [-r REV] [SOURCE]')) |
|
3421 | 3421 | def identify(ui, repo, source=None, rev=None, |
|
3422 | 3422 | num=None, id=None, branch=None, tags=None, bookmarks=None, **opts): |
|
3423 | 3423 | """identify the working copy or specified revision |
|
3424 | 3424 | |
|
3425 | 3425 | Print a summary identifying the repository state at REV using one or |
|
3426 | 3426 | two parent hash identifiers, followed by a "+" if the working |
|
3427 | 3427 | directory has uncommitted changes, the branch name (if not default), |
|
3428 | 3428 | a list of tags, and a list of bookmarks. |
|
3429 | 3429 | |
|
3430 | 3430 | When REV is not given, print a summary of the current state of the |
|
3431 | 3431 | repository. |
|
3432 | 3432 | |
|
3433 | 3433 | Specifying a path to a repository root or Mercurial bundle will |
|
3434 | 3434 | cause lookup to operate on that repository/bundle. |
|
3435 | 3435 | |
|
3436 | 3436 | .. container:: verbose |
|
3437 | 3437 | |
|
3438 | 3438 | Examples: |
|
3439 | 3439 | |
|
3440 | 3440 | - generate a build identifier for the working directory:: |
|
3441 | 3441 | |
|
3442 | 3442 | hg id --id > build-id.dat |
|
3443 | 3443 | |
|
3444 | 3444 | - find the revision corresponding to a tag:: |
|
3445 | 3445 | |
|
3446 | 3446 | hg id -n -r 1.3 |
|
3447 | 3447 | |
|
3448 | 3448 | - check the most recent revision of a remote repository:: |
|
3449 | 3449 | |
|
3450 | 3450 | hg id -r tip http://selenic.com/hg/ |
|
3451 | 3451 | |
|
3452 | 3452 | Returns 0 if successful. |
|
3453 | 3453 | """ |
|
3454 | 3454 | |
|
3455 | 3455 | if not repo and not source: |
|
3456 | 3456 | raise util.Abort(_("there is no Mercurial repository here " |
|
3457 | 3457 | "(.hg not found)")) |
|
3458 | 3458 | |
|
3459 | 3459 | hexfunc = ui.debugflag and hex or short |
|
3460 | 3460 | default = not (num or id or branch or tags or bookmarks) |
|
3461 | 3461 | output = [] |
|
3462 | 3462 | revs = [] |
|
3463 | 3463 | |
|
3464 | 3464 | if source: |
|
3465 | 3465 | source, branches = hg.parseurl(ui.expandpath(source)) |
|
3466 |
|
|
|
3467 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) | |
|
3468 | ||
|
3469 | if not repo.local(): | |
|
3466 | peer = hg.peer(ui, opts, source) | |
|
3467 | repo = peer.local() | |
|
3468 | revs, checkout = hg.addbranchrevs(repo, peer, branches, None) | |
|
3469 | ||
|
3470 | if not repo: | |
|
3470 | 3471 | if num or branch or tags: |
|
3471 | 3472 | raise util.Abort( |
|
3472 | 3473 | _("can't query remote revision number, branch, or tags")) |
|
3473 | 3474 | if not rev and revs: |
|
3474 | 3475 | rev = revs[0] |
|
3475 | 3476 | if not rev: |
|
3476 | 3477 | rev = "tip" |
|
3477 | 3478 | |
|
3478 |
remoterev = |
|
|
3479 | remoterev = peer.lookup(rev) | |
|
3479 | 3480 | if default or id: |
|
3480 | 3481 | output = [hexfunc(remoterev)] |
|
3481 | 3482 | |
|
3482 | 3483 | def getbms(): |
|
3483 | 3484 | bms = [] |
|
3484 | 3485 | |
|
3485 |
if 'bookmarks' in |
|
|
3486 | if 'bookmarks' in peer.listkeys('namespaces'): | |
|
3486 | 3487 | hexremoterev = hex(remoterev) |
|
3487 |
bms = [bm for bm, bmr in |
|
|
3488 | bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems() | |
|
3488 | 3489 | if bmr == hexremoterev] |
|
3489 | 3490 | |
|
3490 | 3491 | return bms |
|
3491 | 3492 | |
|
3492 | 3493 | if bookmarks: |
|
3493 | 3494 | output.extend(getbms()) |
|
3494 | 3495 | elif default and not ui.quiet: |
|
3495 | 3496 | # multiple bookmarks for a single parent separated by '/' |
|
3496 | 3497 | bm = '/'.join(getbms()) |
|
3497 | 3498 | if bm: |
|
3498 | 3499 | output.append(bm) |
|
3499 | 3500 | else: |
|
3500 | 3501 | if not rev: |
|
3501 | 3502 | ctx = repo[None] |
|
3502 | 3503 | parents = ctx.parents() |
|
3503 | 3504 | changed = "" |
|
3504 | 3505 | if default or id or num: |
|
3505 | 3506 | changed = util.any(repo.status()) and "+" or "" |
|
3506 | 3507 | if default or id: |
|
3507 | 3508 | output = ["%s%s" % |
|
3508 | 3509 | ('+'.join([hexfunc(p.node()) for p in parents]), changed)] |
|
3509 | 3510 | if num: |
|
3510 | 3511 | output.append("%s%s" % |
|
3511 | 3512 | ('+'.join([str(p.rev()) for p in parents]), changed)) |
|
3512 | 3513 | else: |
|
3513 | 3514 | ctx = scmutil.revsingle(repo, rev) |
|
3514 | 3515 | if default or id: |
|
3515 | 3516 | output = [hexfunc(ctx.node())] |
|
3516 | 3517 | if num: |
|
3517 | 3518 | output.append(str(ctx.rev())) |
|
3518 | 3519 | |
|
3519 | 3520 | if default and not ui.quiet: |
|
3520 | 3521 | b = ctx.branch() |
|
3521 | 3522 | if b != 'default': |
|
3522 | 3523 | output.append("(%s)" % b) |
|
3523 | 3524 | |
|
3524 | 3525 | # multiple tags for a single parent separated by '/' |
|
3525 | 3526 | t = '/'.join(ctx.tags()) |
|
3526 | 3527 | if t: |
|
3527 | 3528 | output.append(t) |
|
3528 | 3529 | |
|
3529 | 3530 | # multiple bookmarks for a single parent separated by '/' |
|
3530 | 3531 | bm = '/'.join(ctx.bookmarks()) |
|
3531 | 3532 | if bm: |
|
3532 | 3533 | output.append(bm) |
|
3533 | 3534 | else: |
|
3534 | 3535 | if branch: |
|
3535 | 3536 | output.append(ctx.branch()) |
|
3536 | 3537 | |
|
3537 | 3538 | if tags: |
|
3538 | 3539 | output.extend(ctx.tags()) |
|
3539 | 3540 | |
|
3540 | 3541 | if bookmarks: |
|
3541 | 3542 | output.extend(ctx.bookmarks()) |
|
3542 | 3543 | |
|
3543 | 3544 | ui.write("%s\n" % ' '.join(output)) |
|
3544 | 3545 | |
|
3545 | 3546 | @command('import|patch', |
|
3546 | 3547 | [('p', 'strip', 1, |
|
3547 | 3548 | _('directory strip option for patch. This has the same ' |
|
3548 | 3549 | 'meaning as the corresponding patch option'), _('NUM')), |
|
3549 | 3550 | ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')), |
|
3550 | 3551 | ('e', 'edit', False, _('invoke editor on commit messages')), |
|
3551 | 3552 | ('f', 'force', None, _('skip check for outstanding uncommitted changes')), |
|
3552 | 3553 | ('', 'no-commit', None, |
|
3553 | 3554 | _("don't commit, just update the working directory")), |
|
3554 | 3555 | ('', 'bypass', None, |
|
3555 | 3556 | _("apply patch without touching the working directory")), |
|
3556 | 3557 | ('', 'exact', None, |
|
3557 | 3558 | _('apply patch to the nodes from which it was generated')), |
|
3558 | 3559 | ('', 'import-branch', None, |
|
3559 | 3560 | _('use any branch information in patch (implied by --exact)'))] + |
|
3560 | 3561 | commitopts + commitopts2 + similarityopts, |
|
3561 | 3562 | _('[OPTION]... PATCH...')) |
|
3562 | 3563 | def import_(ui, repo, patch1=None, *patches, **opts): |
|
3563 | 3564 | """import an ordered set of patches |
|
3564 | 3565 | |
|
3565 | 3566 | Import a list of patches and commit them individually (unless |
|
3566 | 3567 | --no-commit is specified). |
|
3567 | 3568 | |
|
3568 | 3569 | If there are outstanding changes in the working directory, import |
|
3569 | 3570 | will abort unless given the -f/--force flag. |
|
3570 | 3571 | |
|
3571 | 3572 | You can import a patch straight from a mail message. Even patches |
|
3572 | 3573 | as attachments work (to use the body part, it must have type |
|
3573 | 3574 | text/plain or text/x-patch). From and Subject headers of email |
|
3574 | 3575 | message are used as default committer and commit message. All |
|
3575 | 3576 | text/plain body parts before first diff are added to commit |
|
3576 | 3577 | message. |
|
3577 | 3578 | |
|
3578 | 3579 | If the imported patch was generated by :hg:`export`, user and |
|
3579 | 3580 | description from patch override values from message headers and |
|
3580 | 3581 | body. Values given on command line with -m/--message and -u/--user |
|
3581 | 3582 | override these. |
|
3582 | 3583 | |
|
3583 | 3584 | If --exact is specified, import will set the working directory to |
|
3584 | 3585 | the parent of each patch before applying it, and will abort if the |
|
3585 | 3586 | resulting changeset has a different ID than the one recorded in |
|
3586 | 3587 | the patch. This may happen due to character set problems or other |
|
3587 | 3588 | deficiencies in the text patch format. |
|
3588 | 3589 | |
|
3589 | 3590 | Use --bypass to apply and commit patches directly to the |
|
3590 | 3591 | repository, not touching the working directory. Without --exact, |
|
3591 | 3592 | patches will be applied on top of the working directory parent |
|
3592 | 3593 | revision. |
|
3593 | 3594 | |
|
3594 | 3595 | With -s/--similarity, hg will attempt to discover renames and |
|
3595 | 3596 | copies in the patch in the same way as :hg:`addremove`. |
|
3596 | 3597 | |
|
3597 | 3598 | To read a patch from standard input, use "-" as the patch name. If |
|
3598 | 3599 | a URL is specified, the patch will be downloaded from it. |
|
3599 | 3600 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
3600 | 3601 | |
|
3601 | 3602 | .. container:: verbose |
|
3602 | 3603 | |
|
3603 | 3604 | Examples: |
|
3604 | 3605 | |
|
3605 | 3606 | - import a traditional patch from a website and detect renames:: |
|
3606 | 3607 | |
|
3607 | 3608 | hg import -s 80 http://example.com/bugfix.patch |
|
3608 | 3609 | |
|
3609 | 3610 | - import a changeset from an hgweb server:: |
|
3610 | 3611 | |
|
3611 | 3612 | hg import http://www.selenic.com/hg/rev/5ca8c111e9aa |
|
3612 | 3613 | |
|
3613 | 3614 | - import all the patches in an Unix-style mbox:: |
|
3614 | 3615 | |
|
3615 | 3616 | hg import incoming-patches.mbox |
|
3616 | 3617 | |
|
3617 | 3618 | - attempt to exactly restore an exported changeset (not always |
|
3618 | 3619 | possible):: |
|
3619 | 3620 | |
|
3620 | 3621 | hg import --exact proposed-fix.patch |
|
3621 | 3622 | |
|
3622 | 3623 | Returns 0 on success. |
|
3623 | 3624 | """ |
|
3624 | 3625 | |
|
3625 | 3626 | if not patch1: |
|
3626 | 3627 | raise util.Abort(_('need at least one patch to import')) |
|
3627 | 3628 | |
|
3628 | 3629 | patches = (patch1,) + patches |
|
3629 | 3630 | |
|
3630 | 3631 | date = opts.get('date') |
|
3631 | 3632 | if date: |
|
3632 | 3633 | opts['date'] = util.parsedate(date) |
|
3633 | 3634 | |
|
3634 | 3635 | editor = cmdutil.commiteditor |
|
3635 | 3636 | if opts.get('edit'): |
|
3636 | 3637 | editor = cmdutil.commitforceeditor |
|
3637 | 3638 | |
|
3638 | 3639 | update = not opts.get('bypass') |
|
3639 | 3640 | if not update and opts.get('no_commit'): |
|
3640 | 3641 | raise util.Abort(_('cannot use --no-commit with --bypass')) |
|
3641 | 3642 | try: |
|
3642 | 3643 | sim = float(opts.get('similarity') or 0) |
|
3643 | 3644 | except ValueError: |
|
3644 | 3645 | raise util.Abort(_('similarity must be a number')) |
|
3645 | 3646 | if sim < 0 or sim > 100: |
|
3646 | 3647 | raise util.Abort(_('similarity must be between 0 and 100')) |
|
3647 | 3648 | if sim and not update: |
|
3648 | 3649 | raise util.Abort(_('cannot use --similarity with --bypass')) |
|
3649 | 3650 | |
|
3650 | 3651 | if (opts.get('exact') or not opts.get('force')) and update: |
|
3651 | 3652 | cmdutil.bailifchanged(repo) |
|
3652 | 3653 | |
|
3653 | 3654 | base = opts["base"] |
|
3654 | 3655 | strip = opts["strip"] |
|
3655 | 3656 | wlock = lock = tr = None |
|
3656 | 3657 | msgs = [] |
|
3657 | 3658 | |
|
3658 | 3659 | def checkexact(repo, n, nodeid): |
|
3659 | 3660 | if opts.get('exact') and hex(n) != nodeid: |
|
3660 | 3661 | repo.rollback() |
|
3661 | 3662 | raise util.Abort(_('patch is damaged or loses information')) |
|
3662 | 3663 | |
|
3663 | 3664 | def tryone(ui, hunk, parents): |
|
3664 | 3665 | tmpname, message, user, date, branch, nodeid, p1, p2 = \ |
|
3665 | 3666 | patch.extract(ui, hunk) |
|
3666 | 3667 | |
|
3667 | 3668 | if not tmpname: |
|
3668 | 3669 | return (None, None) |
|
3669 | 3670 | msg = _('applied to working directory') |
|
3670 | 3671 | |
|
3671 | 3672 | try: |
|
3672 | 3673 | cmdline_message = cmdutil.logmessage(ui, opts) |
|
3673 | 3674 | if cmdline_message: |
|
3674 | 3675 | # pickup the cmdline msg |
|
3675 | 3676 | message = cmdline_message |
|
3676 | 3677 | elif message: |
|
3677 | 3678 | # pickup the patch msg |
|
3678 | 3679 | message = message.strip() |
|
3679 | 3680 | else: |
|
3680 | 3681 | # launch the editor |
|
3681 | 3682 | message = None |
|
3682 | 3683 | ui.debug('message:\n%s\n' % message) |
|
3683 | 3684 | |
|
3684 | 3685 | if len(parents) == 1: |
|
3685 | 3686 | parents.append(repo[nullid]) |
|
3686 | 3687 | if opts.get('exact'): |
|
3687 | 3688 | if not nodeid or not p1: |
|
3688 | 3689 | raise util.Abort(_('not a Mercurial patch')) |
|
3689 | 3690 | p1 = repo[p1] |
|
3690 | 3691 | p2 = repo[p2 or nullid] |
|
3691 | 3692 | elif p2: |
|
3692 | 3693 | try: |
|
3693 | 3694 | p1 = repo[p1] |
|
3694 | 3695 | p2 = repo[p2] |
|
3695 | 3696 | # Without any options, consider p2 only if the |
|
3696 | 3697 | # patch is being applied on top of the recorded |
|
3697 | 3698 | # first parent. |
|
3698 | 3699 | if p1 != parents[0]: |
|
3699 | 3700 | p1 = parents[0] |
|
3700 | 3701 | p2 = repo[nullid] |
|
3701 | 3702 | except error.RepoError: |
|
3702 | 3703 | p1, p2 = parents |
|
3703 | 3704 | else: |
|
3704 | 3705 | p1, p2 = parents |
|
3705 | 3706 | |
|
3706 | 3707 | n = None |
|
3707 | 3708 | if update: |
|
3708 | 3709 | if p1 != parents[0]: |
|
3709 | 3710 | hg.clean(repo, p1.node()) |
|
3710 | 3711 | if p2 != parents[1]: |
|
3711 | 3712 | repo.setparents(p1.node(), p2.node()) |
|
3712 | 3713 | |
|
3713 | 3714 | if opts.get('exact') or opts.get('import_branch'): |
|
3714 | 3715 | repo.dirstate.setbranch(branch or 'default') |
|
3715 | 3716 | |
|
3716 | 3717 | files = set() |
|
3717 | 3718 | patch.patch(ui, repo, tmpname, strip=strip, files=files, |
|
3718 | 3719 | eolmode=None, similarity=sim / 100.0) |
|
3719 | 3720 | files = list(files) |
|
3720 | 3721 | if opts.get('no_commit'): |
|
3721 | 3722 | if message: |
|
3722 | 3723 | msgs.append(message) |
|
3723 | 3724 | else: |
|
3724 | 3725 | if opts.get('exact') or p2: |
|
3725 | 3726 | # If you got here, you either use --force and know what |
|
3726 | 3727 | # you are doing or used --exact or a merge patch while |
|
3727 | 3728 | # being updated to its first parent. |
|
3728 | 3729 | m = None |
|
3729 | 3730 | else: |
|
3730 | 3731 | m = scmutil.matchfiles(repo, files or []) |
|
3731 | 3732 | n = repo.commit(message, opts.get('user') or user, |
|
3732 | 3733 | opts.get('date') or date, match=m, |
|
3733 | 3734 | editor=editor) |
|
3734 | 3735 | checkexact(repo, n, nodeid) |
|
3735 | 3736 | else: |
|
3736 | 3737 | if opts.get('exact') or opts.get('import_branch'): |
|
3737 | 3738 | branch = branch or 'default' |
|
3738 | 3739 | else: |
|
3739 | 3740 | branch = p1.branch() |
|
3740 | 3741 | store = patch.filestore() |
|
3741 | 3742 | try: |
|
3742 | 3743 | files = set() |
|
3743 | 3744 | try: |
|
3744 | 3745 | patch.patchrepo(ui, repo, p1, store, tmpname, strip, |
|
3745 | 3746 | files, eolmode=None) |
|
3746 | 3747 | except patch.PatchError, e: |
|
3747 | 3748 | raise util.Abort(str(e)) |
|
3748 | 3749 | memctx = patch.makememctx(repo, (p1.node(), p2.node()), |
|
3749 | 3750 | message, |
|
3750 | 3751 | opts.get('user') or user, |
|
3751 | 3752 | opts.get('date') or date, |
|
3752 | 3753 | branch, files, store, |
|
3753 | 3754 | editor=cmdutil.commiteditor) |
|
3754 | 3755 | repo.savecommitmessage(memctx.description()) |
|
3755 | 3756 | n = memctx.commit() |
|
3756 | 3757 | checkexact(repo, n, nodeid) |
|
3757 | 3758 | finally: |
|
3758 | 3759 | store.close() |
|
3759 | 3760 | if n: |
|
3760 | 3761 | # i18n: refers to a short changeset id |
|
3761 | 3762 | msg = _('created %s') % short(n) |
|
3762 | 3763 | return (msg, n) |
|
3763 | 3764 | finally: |
|
3764 | 3765 | os.unlink(tmpname) |
|
3765 | 3766 | |
|
3766 | 3767 | try: |
|
3767 | 3768 | try: |
|
3768 | 3769 | wlock = repo.wlock() |
|
3769 | 3770 | if not opts.get('no_commit'): |
|
3770 | 3771 | lock = repo.lock() |
|
3771 | 3772 | tr = repo.transaction('import') |
|
3772 | 3773 | parents = repo.parents() |
|
3773 | 3774 | for patchurl in patches: |
|
3774 | 3775 | if patchurl == '-': |
|
3775 | 3776 | ui.status(_('applying patch from stdin\n')) |
|
3776 | 3777 | patchfile = ui.fin |
|
3777 | 3778 | patchurl = 'stdin' # for error message |
|
3778 | 3779 | else: |
|
3779 | 3780 | patchurl = os.path.join(base, patchurl) |
|
3780 | 3781 | ui.status(_('applying %s\n') % patchurl) |
|
3781 | 3782 | patchfile = url.open(ui, patchurl) |
|
3782 | 3783 | |
|
3783 | 3784 | haspatch = False |
|
3784 | 3785 | for hunk in patch.split(patchfile): |
|
3785 | 3786 | (msg, node) = tryone(ui, hunk, parents) |
|
3786 | 3787 | if msg: |
|
3787 | 3788 | haspatch = True |
|
3788 | 3789 | ui.note(msg + '\n') |
|
3789 | 3790 | if update or opts.get('exact'): |
|
3790 | 3791 | parents = repo.parents() |
|
3791 | 3792 | else: |
|
3792 | 3793 | parents = [repo[node]] |
|
3793 | 3794 | |
|
3794 | 3795 | if not haspatch: |
|
3795 | 3796 | raise util.Abort(_('%s: no diffs found') % patchurl) |
|
3796 | 3797 | |
|
3797 | 3798 | if tr: |
|
3798 | 3799 | tr.close() |
|
3799 | 3800 | if msgs: |
|
3800 | 3801 | repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
3801 | 3802 | except: # re-raises |
|
3802 | 3803 | # wlock.release() indirectly calls dirstate.write(): since |
|
3803 | 3804 | # we're crashing, we do not want to change the working dir |
|
3804 | 3805 | # parent after all, so make sure it writes nothing |
|
3805 | 3806 | repo.dirstate.invalidate() |
|
3806 | 3807 | raise |
|
3807 | 3808 | finally: |
|
3808 | 3809 | if tr: |
|
3809 | 3810 | tr.release() |
|
3810 | 3811 | release(lock, wlock) |
|
3811 | 3812 | |
|
3812 | 3813 | @command('incoming|in', |
|
3813 | 3814 | [('f', 'force', None, |
|
3814 | 3815 | _('run even if remote repository is unrelated')), |
|
3815 | 3816 | ('n', 'newest-first', None, _('show newest record first')), |
|
3816 | 3817 | ('', 'bundle', '', |
|
3817 | 3818 | _('file to store the bundles into'), _('FILE')), |
|
3818 | 3819 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
3819 | 3820 | ('B', 'bookmarks', False, _("compare bookmarks")), |
|
3820 | 3821 | ('b', 'branch', [], |
|
3821 | 3822 | _('a specific branch you would like to pull'), _('BRANCH')), |
|
3822 | 3823 | ] + logopts + remoteopts + subrepoopts, |
|
3823 | 3824 | _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')) |
|
3824 | 3825 | def incoming(ui, repo, source="default", **opts): |
|
3825 | 3826 | """show new changesets found in source |
|
3826 | 3827 | |
|
3827 | 3828 | Show new changesets found in the specified path/URL or the default |
|
3828 | 3829 | pull location. These are the changesets that would have been pulled |
|
3829 | 3830 | if a pull at the time you issued this command. |
|
3830 | 3831 | |
|
3831 | 3832 | For remote repository, using --bundle avoids downloading the |
|
3832 | 3833 | changesets twice if the incoming is followed by a pull. |
|
3833 | 3834 | |
|
3834 | 3835 | See pull for valid source format details. |
|
3835 | 3836 | |
|
3836 | 3837 | Returns 0 if there are incoming changes, 1 otherwise. |
|
3837 | 3838 | """ |
|
3838 | 3839 | if opts.get('graph'): |
|
3839 | 3840 | cmdutil.checkunsupportedgraphflags([], opts) |
|
3840 | 3841 | def display(other, chlist, displayer): |
|
3841 | 3842 | revdag = cmdutil.graphrevs(other, chlist, opts) |
|
3842 | 3843 | showparents = [ctx.node() for ctx in repo[None].parents()] |
|
3843 | 3844 | cmdutil.displaygraph(ui, revdag, displayer, showparents, |
|
3844 | 3845 | graphmod.asciiedges) |
|
3845 | 3846 | |
|
3846 | 3847 | hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True) |
|
3847 | 3848 | return 0 |
|
3848 | 3849 | |
|
3849 | 3850 | if opts.get('bundle') and opts.get('subrepos'): |
|
3850 | 3851 | raise util.Abort(_('cannot combine --bundle and --subrepos')) |
|
3851 | 3852 | |
|
3852 | 3853 | if opts.get('bookmarks'): |
|
3853 | 3854 | source, branches = hg.parseurl(ui.expandpath(source), |
|
3854 | 3855 | opts.get('branch')) |
|
3855 | 3856 | other = hg.peer(repo, opts, source) |
|
3856 | 3857 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
3857 | 3858 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
3858 | 3859 | return 0 |
|
3859 | 3860 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
3860 | 3861 | return bookmarks.diff(ui, repo, other) |
|
3861 | 3862 | |
|
3862 | 3863 | repo._subtoppath = ui.expandpath(source) |
|
3863 | 3864 | try: |
|
3864 | 3865 | return hg.incoming(ui, repo, source, opts) |
|
3865 | 3866 | finally: |
|
3866 | 3867 | del repo._subtoppath |
|
3867 | 3868 | |
|
3868 | 3869 | |
|
3869 | 3870 | @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]')) |
|
3870 | 3871 | def init(ui, dest=".", **opts): |
|
3871 | 3872 | """create a new repository in the given directory |
|
3872 | 3873 | |
|
3873 | 3874 | Initialize a new repository in the given directory. If the given |
|
3874 | 3875 | directory does not exist, it will be created. |
|
3875 | 3876 | |
|
3876 | 3877 | If no directory is given, the current directory is used. |
|
3877 | 3878 | |
|
3878 | 3879 | It is possible to specify an ``ssh://`` URL as the destination. |
|
3879 | 3880 | See :hg:`help urls` for more information. |
|
3880 | 3881 | |
|
3881 | 3882 | Returns 0 on success. |
|
3882 | 3883 | """ |
|
3883 | 3884 | hg.peer(ui, opts, ui.expandpath(dest), create=True) |
|
3884 | 3885 | |
|
3885 | 3886 | @command('locate', |
|
3886 | 3887 | [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')), |
|
3887 | 3888 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
3888 | 3889 | ('f', 'fullpath', None, _('print complete paths from the filesystem root')), |
|
3889 | 3890 | ] + walkopts, |
|
3890 | 3891 | _('[OPTION]... [PATTERN]...')) |
|
3891 | 3892 | def locate(ui, repo, *pats, **opts): |
|
3892 | 3893 | """locate files matching specific patterns |
|
3893 | 3894 | |
|
3894 | 3895 | Print files under Mercurial control in the working directory whose |
|
3895 | 3896 | names match the given patterns. |
|
3896 | 3897 | |
|
3897 | 3898 | By default, this command searches all directories in the working |
|
3898 | 3899 | directory. To search just the current directory and its |
|
3899 | 3900 | subdirectories, use "--include .". |
|
3900 | 3901 | |
|
3901 | 3902 | If no patterns are given to match, this command prints the names |
|
3902 | 3903 | of all files under Mercurial control in the working directory. |
|
3903 | 3904 | |
|
3904 | 3905 | If you want to feed the output of this command into the "xargs" |
|
3905 | 3906 | command, use the -0 option to both this command and "xargs". This |
|
3906 | 3907 | will avoid the problem of "xargs" treating single filenames that |
|
3907 | 3908 | contain whitespace as multiple filenames. |
|
3908 | 3909 | |
|
3909 | 3910 | Returns 0 if a match is found, 1 otherwise. |
|
3910 | 3911 | """ |
|
3911 | 3912 | end = opts.get('print0') and '\0' or '\n' |
|
3912 | 3913 | rev = scmutil.revsingle(repo, opts.get('rev'), None).node() |
|
3913 | 3914 | |
|
3914 | 3915 | ret = 1 |
|
3915 | 3916 | m = scmutil.match(repo[rev], pats, opts, default='relglob') |
|
3916 | 3917 | m.bad = lambda x, y: False |
|
3917 | 3918 | for abs in repo[rev].walk(m): |
|
3918 | 3919 | if not rev and abs not in repo.dirstate: |
|
3919 | 3920 | continue |
|
3920 | 3921 | if opts.get('fullpath'): |
|
3921 | 3922 | ui.write(repo.wjoin(abs), end) |
|
3922 | 3923 | else: |
|
3923 | 3924 | ui.write(((pats and m.rel(abs)) or abs), end) |
|
3924 | 3925 | ret = 0 |
|
3925 | 3926 | |
|
3926 | 3927 | return ret |
|
3927 | 3928 | |
|
3928 | 3929 | @command('^log|history', |
|
3929 | 3930 | [('f', 'follow', None, |
|
3930 | 3931 | _('follow changeset history, or file history across copies and renames')), |
|
3931 | 3932 | ('', 'follow-first', None, |
|
3932 | 3933 | _('only follow the first parent of merge changesets (DEPRECATED)')), |
|
3933 | 3934 | ('d', 'date', '', _('show revisions matching date spec'), _('DATE')), |
|
3934 | 3935 | ('C', 'copies', None, _('show copied files')), |
|
3935 | 3936 | ('k', 'keyword', [], |
|
3936 | 3937 | _('do case-insensitive search for a given text'), _('TEXT')), |
|
3937 | 3938 | ('r', 'rev', [], _('show the specified revision or range'), _('REV')), |
|
3938 | 3939 | ('', 'removed', None, _('include revisions where files were removed')), |
|
3939 | 3940 | ('m', 'only-merges', None, _('show only merges (DEPRECATED)')), |
|
3940 | 3941 | ('u', 'user', [], _('revisions committed by user'), _('USER')), |
|
3941 | 3942 | ('', 'only-branch', [], |
|
3942 | 3943 | _('show only changesets within the given named branch (DEPRECATED)'), |
|
3943 | 3944 | _('BRANCH')), |
|
3944 | 3945 | ('b', 'branch', [], |
|
3945 | 3946 | _('show changesets within the given named branch'), _('BRANCH')), |
|
3946 | 3947 | ('P', 'prune', [], |
|
3947 | 3948 | _('do not display revision or any of its ancestors'), _('REV')), |
|
3948 | 3949 | ('', 'hidden', False, _('show hidden changesets (DEPRECATED)')), |
|
3949 | 3950 | ] + logopts + walkopts, |
|
3950 | 3951 | _('[OPTION]... [FILE]')) |
|
3951 | 3952 | def log(ui, repo, *pats, **opts): |
|
3952 | 3953 | """show revision history of entire repository or files |
|
3953 | 3954 | |
|
3954 | 3955 | Print the revision history of the specified files or the entire |
|
3955 | 3956 | project. |
|
3956 | 3957 | |
|
3957 | 3958 | If no revision range is specified, the default is ``tip:0`` unless |
|
3958 | 3959 | --follow is set, in which case the working directory parent is |
|
3959 | 3960 | used as the starting revision. |
|
3960 | 3961 | |
|
3961 | 3962 | File history is shown without following rename or copy history of |
|
3962 | 3963 | files. Use -f/--follow with a filename to follow history across |
|
3963 | 3964 | renames and copies. --follow without a filename will only show |
|
3964 | 3965 | ancestors or descendants of the starting revision. |
|
3965 | 3966 | |
|
3966 | 3967 | By default this command prints revision number and changeset id, |
|
3967 | 3968 | tags, non-trivial parents, user, date and time, and a summary for |
|
3968 | 3969 | each commit. When the -v/--verbose switch is used, the list of |
|
3969 | 3970 | changed files and full commit message are shown. |
|
3970 | 3971 | |
|
3971 | 3972 | .. note:: |
|
3972 | 3973 | log -p/--patch may generate unexpected diff output for merge |
|
3973 | 3974 | changesets, as it will only compare the merge changeset against |
|
3974 | 3975 | its first parent. Also, only files different from BOTH parents |
|
3975 | 3976 | will appear in files:. |
|
3976 | 3977 | |
|
3977 | 3978 | .. note:: |
|
3978 | 3979 | for performance reasons, log FILE may omit duplicate changes |
|
3979 | 3980 | made on branches and will not show deletions. To see all |
|
3980 | 3981 | changes including duplicates and deletions, use the --removed |
|
3981 | 3982 | switch. |
|
3982 | 3983 | |
|
3983 | 3984 | .. container:: verbose |
|
3984 | 3985 | |
|
3985 | 3986 | Some examples: |
|
3986 | 3987 | |
|
3987 | 3988 | - changesets with full descriptions and file lists:: |
|
3988 | 3989 | |
|
3989 | 3990 | hg log -v |
|
3990 | 3991 | |
|
3991 | 3992 | - changesets ancestral to the working directory:: |
|
3992 | 3993 | |
|
3993 | 3994 | hg log -f |
|
3994 | 3995 | |
|
3995 | 3996 | - last 10 commits on the current branch:: |
|
3996 | 3997 | |
|
3997 | 3998 | hg log -l 10 -b . |
|
3998 | 3999 | |
|
3999 | 4000 | - changesets showing all modifications of a file, including removals:: |
|
4000 | 4001 | |
|
4001 | 4002 | hg log --removed file.c |
|
4002 | 4003 | |
|
4003 | 4004 | - all changesets that touch a directory, with diffs, excluding merges:: |
|
4004 | 4005 | |
|
4005 | 4006 | hg log -Mp lib/ |
|
4006 | 4007 | |
|
4007 | 4008 | - all revision numbers that match a keyword:: |
|
4008 | 4009 | |
|
4009 | 4010 | hg log -k bug --template "{rev}\\n" |
|
4010 | 4011 | |
|
4011 | 4012 | - check if a given changeset is included is a tagged release:: |
|
4012 | 4013 | |
|
4013 | 4014 | hg log -r "a21ccf and ancestor(1.9)" |
|
4014 | 4015 | |
|
4015 | 4016 | - find all changesets by some user in a date range:: |
|
4016 | 4017 | |
|
4017 | 4018 | hg log -k alice -d "may 2008 to jul 2008" |
|
4018 | 4019 | |
|
4019 | 4020 | - summary of all changesets after the last tag:: |
|
4020 | 4021 | |
|
4021 | 4022 | hg log -r "last(tagged())::" --template "{desc|firstline}\\n" |
|
4022 | 4023 | |
|
4023 | 4024 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4024 | 4025 | |
|
4025 | 4026 | See :hg:`help revisions` and :hg:`help revsets` for more about |
|
4026 | 4027 | specifying revisions. |
|
4027 | 4028 | |
|
4028 | 4029 | See :hg:`help templates` for more about pre-packaged styles and |
|
4029 | 4030 | specifying custom templates. |
|
4030 | 4031 | |
|
4031 | 4032 | Returns 0 on success. |
|
4032 | 4033 | """ |
|
4033 | 4034 | if opts.get('graph'): |
|
4034 | 4035 | return cmdutil.graphlog(ui, repo, *pats, **opts) |
|
4035 | 4036 | |
|
4036 | 4037 | matchfn = scmutil.match(repo[None], pats, opts) |
|
4037 | 4038 | limit = cmdutil.loglimit(opts) |
|
4038 | 4039 | count = 0 |
|
4039 | 4040 | |
|
4040 | 4041 | getrenamed, endrev = None, None |
|
4041 | 4042 | if opts.get('copies'): |
|
4042 | 4043 | if opts.get('rev'): |
|
4043 | 4044 | endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1 |
|
4044 | 4045 | getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
|
4045 | 4046 | |
|
4046 | 4047 | df = False |
|
4047 | 4048 | if opts["date"]: |
|
4048 | 4049 | df = util.matchdate(opts["date"]) |
|
4049 | 4050 | |
|
4050 | 4051 | branches = opts.get('branch', []) + opts.get('only_branch', []) |
|
4051 | 4052 | opts['branch'] = [repo.lookupbranch(b) for b in branches] |
|
4052 | 4053 | |
|
4053 | 4054 | displayer = cmdutil.show_changeset(ui, repo, opts, True) |
|
4054 | 4055 | def prep(ctx, fns): |
|
4055 | 4056 | rev = ctx.rev() |
|
4056 | 4057 | parents = [p for p in repo.changelog.parentrevs(rev) |
|
4057 | 4058 | if p != nullrev] |
|
4058 | 4059 | if opts.get('no_merges') and len(parents) == 2: |
|
4059 | 4060 | return |
|
4060 | 4061 | if opts.get('only_merges') and len(parents) != 2: |
|
4061 | 4062 | return |
|
4062 | 4063 | if opts.get('branch') and ctx.branch() not in opts['branch']: |
|
4063 | 4064 | return |
|
4064 | 4065 | if not opts.get('hidden') and ctx.hidden(): |
|
4065 | 4066 | return |
|
4066 | 4067 | if df and not df(ctx.date()[0]): |
|
4067 | 4068 | return |
|
4068 | 4069 | |
|
4069 | 4070 | lower = encoding.lower |
|
4070 | 4071 | if opts.get('user'): |
|
4071 | 4072 | luser = lower(ctx.user()) |
|
4072 | 4073 | for k in [lower(x) for x in opts['user']]: |
|
4073 | 4074 | if (k in luser): |
|
4074 | 4075 | break |
|
4075 | 4076 | else: |
|
4076 | 4077 | return |
|
4077 | 4078 | if opts.get('keyword'): |
|
4078 | 4079 | luser = lower(ctx.user()) |
|
4079 | 4080 | ldesc = lower(ctx.description()) |
|
4080 | 4081 | lfiles = lower(" ".join(ctx.files())) |
|
4081 | 4082 | for k in [lower(x) for x in opts['keyword']]: |
|
4082 | 4083 | if (k in luser or k in ldesc or k in lfiles): |
|
4083 | 4084 | break |
|
4084 | 4085 | else: |
|
4085 | 4086 | return |
|
4086 | 4087 | |
|
4087 | 4088 | copies = None |
|
4088 | 4089 | if getrenamed is not None and rev: |
|
4089 | 4090 | copies = [] |
|
4090 | 4091 | for fn in ctx.files(): |
|
4091 | 4092 | rename = getrenamed(fn, rev) |
|
4092 | 4093 | if rename: |
|
4093 | 4094 | copies.append((fn, rename[0])) |
|
4094 | 4095 | |
|
4095 | 4096 | revmatchfn = None |
|
4096 | 4097 | if opts.get('patch') or opts.get('stat'): |
|
4097 | 4098 | if opts.get('follow') or opts.get('follow_first'): |
|
4098 | 4099 | # note: this might be wrong when following through merges |
|
4099 | 4100 | revmatchfn = scmutil.match(repo[None], fns, default='path') |
|
4100 | 4101 | else: |
|
4101 | 4102 | revmatchfn = matchfn |
|
4102 | 4103 | |
|
4103 | 4104 | displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
|
4104 | 4105 | |
|
4105 | 4106 | for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep): |
|
4106 | 4107 | if count == limit: |
|
4107 | 4108 | break |
|
4108 | 4109 | if displayer.flush(ctx.rev()): |
|
4109 | 4110 | count += 1 |
|
4110 | 4111 | displayer.close() |
|
4111 | 4112 | |
|
4112 | 4113 | @command('manifest', |
|
4113 | 4114 | [('r', 'rev', '', _('revision to display'), _('REV')), |
|
4114 | 4115 | ('', 'all', False, _("list files from all revisions"))], |
|
4115 | 4116 | _('[-r REV]')) |
|
4116 | 4117 | def manifest(ui, repo, node=None, rev=None, **opts): |
|
4117 | 4118 | """output the current or given revision of the project manifest |
|
4118 | 4119 | |
|
4119 | 4120 | Print a list of version controlled files for the given revision. |
|
4120 | 4121 | If no revision is given, the first parent of the working directory |
|
4121 | 4122 | is used, or the null revision if no revision is checked out. |
|
4122 | 4123 | |
|
4123 | 4124 | With -v, print file permissions, symlink and executable bits. |
|
4124 | 4125 | With --debug, print file revision hashes. |
|
4125 | 4126 | |
|
4126 | 4127 | If option --all is specified, the list of all files from all revisions |
|
4127 | 4128 | is printed. This includes deleted and renamed files. |
|
4128 | 4129 | |
|
4129 | 4130 | Returns 0 on success. |
|
4130 | 4131 | """ |
|
4131 | 4132 | if opts.get('all'): |
|
4132 | 4133 | if rev or node: |
|
4133 | 4134 | raise util.Abort(_("can't specify a revision with --all")) |
|
4134 | 4135 | |
|
4135 | 4136 | res = [] |
|
4136 | 4137 | prefix = "data/" |
|
4137 | 4138 | suffix = ".i" |
|
4138 | 4139 | plen = len(prefix) |
|
4139 | 4140 | slen = len(suffix) |
|
4140 | 4141 | lock = repo.lock() |
|
4141 | 4142 | try: |
|
4142 | 4143 | for fn, b, size in repo.store.datafiles(): |
|
4143 | 4144 | if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix: |
|
4144 | 4145 | res.append(fn[plen:-slen]) |
|
4145 | 4146 | finally: |
|
4146 | 4147 | lock.release() |
|
4147 | 4148 | for f in sorted(res): |
|
4148 | 4149 | ui.write("%s\n" % f) |
|
4149 | 4150 | return |
|
4150 | 4151 | |
|
4151 | 4152 | if rev and node: |
|
4152 | 4153 | raise util.Abort(_("please specify just one revision")) |
|
4153 | 4154 | |
|
4154 | 4155 | if not node: |
|
4155 | 4156 | node = rev |
|
4156 | 4157 | |
|
4157 | 4158 | decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} |
|
4158 | 4159 | ctx = scmutil.revsingle(repo, node) |
|
4159 | 4160 | for f in ctx: |
|
4160 | 4161 | if ui.debugflag: |
|
4161 | 4162 | ui.write("%40s " % hex(ctx.manifest()[f])) |
|
4162 | 4163 | if ui.verbose: |
|
4163 | 4164 | ui.write(decor[ctx.flags(f)]) |
|
4164 | 4165 | ui.write("%s\n" % f) |
|
4165 | 4166 | |
|
4166 | 4167 | @command('^merge', |
|
4167 | 4168 | [('f', 'force', None, _('force a merge with outstanding changes')), |
|
4168 | 4169 | ('r', 'rev', '', _('revision to merge'), _('REV')), |
|
4169 | 4170 | ('P', 'preview', None, |
|
4170 | 4171 | _('review revisions to merge (no merge is performed)')) |
|
4171 | 4172 | ] + mergetoolopts, |
|
4172 | 4173 | _('[-P] [-f] [[-r] REV]')) |
|
4173 | 4174 | def merge(ui, repo, node=None, **opts): |
|
4174 | 4175 | """merge working directory with another revision |
|
4175 | 4176 | |
|
4176 | 4177 | The current working directory is updated with all changes made in |
|
4177 | 4178 | the requested revision since the last common predecessor revision. |
|
4178 | 4179 | |
|
4179 | 4180 | Files that changed between either parent are marked as changed for |
|
4180 | 4181 | the next commit and a commit must be performed before any further |
|
4181 | 4182 | updates to the repository are allowed. The next commit will have |
|
4182 | 4183 | two parents. |
|
4183 | 4184 | |
|
4184 | 4185 | ``--tool`` can be used to specify the merge tool used for file |
|
4185 | 4186 | merges. It overrides the HGMERGE environment variable and your |
|
4186 | 4187 | configuration files. See :hg:`help merge-tools` for options. |
|
4187 | 4188 | |
|
4188 | 4189 | If no revision is specified, the working directory's parent is a |
|
4189 | 4190 | head revision, and the current branch contains exactly one other |
|
4190 | 4191 | head, the other head is merged with by default. Otherwise, an |
|
4191 | 4192 | explicit revision with which to merge with must be provided. |
|
4192 | 4193 | |
|
4193 | 4194 | :hg:`resolve` must be used to resolve unresolved files. |
|
4194 | 4195 | |
|
4195 | 4196 | To undo an uncommitted merge, use :hg:`update --clean .` which |
|
4196 | 4197 | will check out a clean copy of the original merge parent, losing |
|
4197 | 4198 | all changes. |
|
4198 | 4199 | |
|
4199 | 4200 | Returns 0 on success, 1 if there are unresolved files. |
|
4200 | 4201 | """ |
|
4201 | 4202 | |
|
4202 | 4203 | if opts.get('rev') and node: |
|
4203 | 4204 | raise util.Abort(_("please specify just one revision")) |
|
4204 | 4205 | if not node: |
|
4205 | 4206 | node = opts.get('rev') |
|
4206 | 4207 | |
|
4207 | 4208 | if node: |
|
4208 | 4209 | node = scmutil.revsingle(repo, node).node() |
|
4209 | 4210 | |
|
4210 | 4211 | if not node and repo._bookmarkcurrent: |
|
4211 | 4212 | bmheads = repo.bookmarkheads(repo._bookmarkcurrent) |
|
4212 | 4213 | curhead = repo[repo._bookmarkcurrent] |
|
4213 | 4214 | if len(bmheads) == 2: |
|
4214 | 4215 | if curhead == bmheads[0]: |
|
4215 | 4216 | node = bmheads[1] |
|
4216 | 4217 | else: |
|
4217 | 4218 | node = bmheads[0] |
|
4218 | 4219 | elif len(bmheads) > 2: |
|
4219 | 4220 | raise util.Abort(_("multiple matching bookmarks to merge - " |
|
4220 | 4221 | "please merge with an explicit rev or bookmark"), |
|
4221 | 4222 | hint=_("run 'hg heads' to see all heads")) |
|
4222 | 4223 | elif len(bmheads) <= 1: |
|
4223 | 4224 | raise util.Abort(_("no matching bookmark to merge - " |
|
4224 | 4225 | "please merge with an explicit rev or bookmark"), |
|
4225 | 4226 | hint=_("run 'hg heads' to see all heads")) |
|
4226 | 4227 | |
|
4227 | 4228 | if not node and not repo._bookmarkcurrent: |
|
4228 | 4229 | branch = repo[None].branch() |
|
4229 | 4230 | bheads = repo.branchheads(branch) |
|
4230 | 4231 | nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] |
|
4231 | 4232 | |
|
4232 | 4233 | if len(nbhs) > 2: |
|
4233 | 4234 | raise util.Abort(_("branch '%s' has %d heads - " |
|
4234 | 4235 | "please merge with an explicit rev") |
|
4235 | 4236 | % (branch, len(bheads)), |
|
4236 | 4237 | hint=_("run 'hg heads .' to see heads")) |
|
4237 | 4238 | |
|
4238 | 4239 | parent = repo.dirstate.p1() |
|
4239 | 4240 | if len(nbhs) == 1: |
|
4240 | 4241 | if len(bheads) > 1: |
|
4241 | 4242 | raise util.Abort(_("heads are bookmarked - " |
|
4242 | 4243 | "please merge with an explicit rev"), |
|
4243 | 4244 | hint=_("run 'hg heads' to see all heads")) |
|
4244 | 4245 | if len(repo.heads()) > 1: |
|
4245 | 4246 | raise util.Abort(_("branch '%s' has one head - " |
|
4246 | 4247 | "please merge with an explicit rev") |
|
4247 | 4248 | % branch, |
|
4248 | 4249 | hint=_("run 'hg heads' to see all heads")) |
|
4249 | 4250 | msg, hint = _('nothing to merge'), None |
|
4250 | 4251 | if parent != repo.lookup(branch): |
|
4251 | 4252 | hint = _("use 'hg update' instead") |
|
4252 | 4253 | raise util.Abort(msg, hint=hint) |
|
4253 | 4254 | |
|
4254 | 4255 | if parent not in bheads: |
|
4255 | 4256 | raise util.Abort(_('working directory not at a head revision'), |
|
4256 | 4257 | hint=_("use 'hg update' or merge with an " |
|
4257 | 4258 | "explicit revision")) |
|
4258 | 4259 | if parent == nbhs[0]: |
|
4259 | 4260 | node = nbhs[-1] |
|
4260 | 4261 | else: |
|
4261 | 4262 | node = nbhs[0] |
|
4262 | 4263 | |
|
4263 | 4264 | if opts.get('preview'): |
|
4264 | 4265 | # find nodes that are ancestors of p2 but not of p1 |
|
4265 | 4266 | p1 = repo.lookup('.') |
|
4266 | 4267 | p2 = repo.lookup(node) |
|
4267 | 4268 | nodes = repo.changelog.findmissing(common=[p1], heads=[p2]) |
|
4268 | 4269 | |
|
4269 | 4270 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
4270 | 4271 | for node in nodes: |
|
4271 | 4272 | displayer.show(repo[node]) |
|
4272 | 4273 | displayer.close() |
|
4273 | 4274 | return 0 |
|
4274 | 4275 | |
|
4275 | 4276 | try: |
|
4276 | 4277 | # ui.forcemerge is an internal variable, do not document |
|
4277 | 4278 | repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
4278 | 4279 | return hg.merge(repo, node, force=opts.get('force')) |
|
4279 | 4280 | finally: |
|
4280 | 4281 | ui.setconfig('ui', 'forcemerge', '') |
|
4281 | 4282 | |
|
4282 | 4283 | @command('outgoing|out', |
|
4283 | 4284 | [('f', 'force', None, _('run even when the destination is unrelated')), |
|
4284 | 4285 | ('r', 'rev', [], |
|
4285 | 4286 | _('a changeset intended to be included in the destination'), _('REV')), |
|
4286 | 4287 | ('n', 'newest-first', None, _('show newest record first')), |
|
4287 | 4288 | ('B', 'bookmarks', False, _('compare bookmarks')), |
|
4288 | 4289 | ('b', 'branch', [], _('a specific branch you would like to push'), |
|
4289 | 4290 | _('BRANCH')), |
|
4290 | 4291 | ] + logopts + remoteopts + subrepoopts, |
|
4291 | 4292 | _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')) |
|
4292 | 4293 | def outgoing(ui, repo, dest=None, **opts): |
|
4293 | 4294 | """show changesets not found in the destination |
|
4294 | 4295 | |
|
4295 | 4296 | Show changesets not found in the specified destination repository |
|
4296 | 4297 | or the default push location. These are the changesets that would |
|
4297 | 4298 | be pushed if a push was requested. |
|
4298 | 4299 | |
|
4299 | 4300 | See pull for details of valid destination formats. |
|
4300 | 4301 | |
|
4301 | 4302 | Returns 0 if there are outgoing changes, 1 otherwise. |
|
4302 | 4303 | """ |
|
4303 | 4304 | if opts.get('graph'): |
|
4304 | 4305 | cmdutil.checkunsupportedgraphflags([], opts) |
|
4305 | 4306 | o = hg._outgoing(ui, repo, dest, opts) |
|
4306 | 4307 | if o is None: |
|
4307 | 4308 | return |
|
4308 | 4309 | |
|
4309 | 4310 | revdag = cmdutil.graphrevs(repo, o, opts) |
|
4310 | 4311 | displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True) |
|
4311 | 4312 | showparents = [ctx.node() for ctx in repo[None].parents()] |
|
4312 | 4313 | cmdutil.displaygraph(ui, revdag, displayer, showparents, |
|
4313 | 4314 | graphmod.asciiedges) |
|
4314 | 4315 | return 0 |
|
4315 | 4316 | |
|
4316 | 4317 | if opts.get('bookmarks'): |
|
4317 | 4318 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
4318 | 4319 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
4319 | 4320 | other = hg.peer(repo, opts, dest) |
|
4320 | 4321 | if 'bookmarks' not in other.listkeys('namespaces'): |
|
4321 | 4322 | ui.warn(_("remote doesn't support bookmarks\n")) |
|
4322 | 4323 | return 0 |
|
4323 | 4324 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
4324 | 4325 | return bookmarks.diff(ui, other, repo) |
|
4325 | 4326 | |
|
4326 | 4327 | repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default') |
|
4327 | 4328 | try: |
|
4328 | 4329 | return hg.outgoing(ui, repo, dest, opts) |
|
4329 | 4330 | finally: |
|
4330 | 4331 | del repo._subtoppath |
|
4331 | 4332 | |
|
4332 | 4333 | @command('parents', |
|
4333 | 4334 | [('r', 'rev', '', _('show parents of the specified revision'), _('REV')), |
|
4334 | 4335 | ] + templateopts, |
|
4335 | 4336 | _('[-r REV] [FILE]')) |
|
4336 | 4337 | def parents(ui, repo, file_=None, **opts): |
|
4337 | 4338 | """show the parents of the working directory or revision |
|
4338 | 4339 | |
|
4339 | 4340 | Print the working directory's parent revisions. If a revision is |
|
4340 | 4341 | given via -r/--rev, the parent of that revision will be printed. |
|
4341 | 4342 | If a file argument is given, the revision in which the file was |
|
4342 | 4343 | last changed (before the working directory revision or the |
|
4343 | 4344 | argument to --rev if given) is printed. |
|
4344 | 4345 | |
|
4345 | 4346 | Returns 0 on success. |
|
4346 | 4347 | """ |
|
4347 | 4348 | |
|
4348 | 4349 | ctx = scmutil.revsingle(repo, opts.get('rev'), None) |
|
4349 | 4350 | |
|
4350 | 4351 | if file_: |
|
4351 | 4352 | m = scmutil.match(ctx, (file_,), opts) |
|
4352 | 4353 | if m.anypats() or len(m.files()) != 1: |
|
4353 | 4354 | raise util.Abort(_('can only specify an explicit filename')) |
|
4354 | 4355 | file_ = m.files()[0] |
|
4355 | 4356 | filenodes = [] |
|
4356 | 4357 | for cp in ctx.parents(): |
|
4357 | 4358 | if not cp: |
|
4358 | 4359 | continue |
|
4359 | 4360 | try: |
|
4360 | 4361 | filenodes.append(cp.filenode(file_)) |
|
4361 | 4362 | except error.LookupError: |
|
4362 | 4363 | pass |
|
4363 | 4364 | if not filenodes: |
|
4364 | 4365 | raise util.Abort(_("'%s' not found in manifest!") % file_) |
|
4365 | 4366 | fl = repo.file(file_) |
|
4366 | 4367 | p = [repo.lookup(fl.linkrev(fl.rev(fn))) for fn in filenodes] |
|
4367 | 4368 | else: |
|
4368 | 4369 | p = [cp.node() for cp in ctx.parents()] |
|
4369 | 4370 | |
|
4370 | 4371 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
4371 | 4372 | for n in p: |
|
4372 | 4373 | if n != nullid: |
|
4373 | 4374 | displayer.show(repo[n]) |
|
4374 | 4375 | displayer.close() |
|
4375 | 4376 | |
|
4376 | 4377 | @command('paths', [], _('[NAME]')) |
|
4377 | 4378 | def paths(ui, repo, search=None): |
|
4378 | 4379 | """show aliases for remote repositories |
|
4379 | 4380 | |
|
4380 | 4381 | Show definition of symbolic path name NAME. If no name is given, |
|
4381 | 4382 | show definition of all available names. |
|
4382 | 4383 | |
|
4383 | 4384 | Option -q/--quiet suppresses all output when searching for NAME |
|
4384 | 4385 | and shows only the path names when listing all definitions. |
|
4385 | 4386 | |
|
4386 | 4387 | Path names are defined in the [paths] section of your |
|
4387 | 4388 | configuration file and in ``/etc/mercurial/hgrc``. If run inside a |
|
4388 | 4389 | repository, ``.hg/hgrc`` is used, too. |
|
4389 | 4390 | |
|
4390 | 4391 | The path names ``default`` and ``default-push`` have a special |
|
4391 | 4392 | meaning. When performing a push or pull operation, they are used |
|
4392 | 4393 | as fallbacks if no location is specified on the command-line. |
|
4393 | 4394 | When ``default-push`` is set, it will be used for push and |
|
4394 | 4395 | ``default`` will be used for pull; otherwise ``default`` is used |
|
4395 | 4396 | as the fallback for both. When cloning a repository, the clone |
|
4396 | 4397 | source is written as ``default`` in ``.hg/hgrc``. Note that |
|
4397 | 4398 | ``default`` and ``default-push`` apply to all inbound (e.g. |
|
4398 | 4399 | :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email` and |
|
4399 | 4400 | :hg:`bundle`) operations. |
|
4400 | 4401 | |
|
4401 | 4402 | See :hg:`help urls` for more information. |
|
4402 | 4403 | |
|
4403 | 4404 | Returns 0 on success. |
|
4404 | 4405 | """ |
|
4405 | 4406 | if search: |
|
4406 | 4407 | for name, path in ui.configitems("paths"): |
|
4407 | 4408 | if name == search: |
|
4408 | 4409 | ui.status("%s\n" % util.hidepassword(path)) |
|
4409 | 4410 | return |
|
4410 | 4411 | if not ui.quiet: |
|
4411 | 4412 | ui.warn(_("not found!\n")) |
|
4412 | 4413 | return 1 |
|
4413 | 4414 | else: |
|
4414 | 4415 | for name, path in ui.configitems("paths"): |
|
4415 | 4416 | if ui.quiet: |
|
4416 | 4417 | ui.write("%s\n" % name) |
|
4417 | 4418 | else: |
|
4418 | 4419 | ui.write("%s = %s\n" % (name, util.hidepassword(path))) |
|
4419 | 4420 | |
|
4420 | 4421 | @command('^phase', |
|
4421 | 4422 | [('p', 'public', False, _('set changeset phase to public')), |
|
4422 | 4423 | ('d', 'draft', False, _('set changeset phase to draft')), |
|
4423 | 4424 | ('s', 'secret', False, _('set changeset phase to secret')), |
|
4424 | 4425 | ('f', 'force', False, _('allow to move boundary backward')), |
|
4425 | 4426 | ('r', 'rev', [], _('target revision'), _('REV')), |
|
4426 | 4427 | ], |
|
4427 | 4428 | _('[-p|-d|-s] [-f] [-r] REV...')) |
|
4428 | 4429 | def phase(ui, repo, *revs, **opts): |
|
4429 | 4430 | """set or show the current phase name |
|
4430 | 4431 | |
|
4431 | 4432 | With no argument, show the phase name of specified revisions. |
|
4432 | 4433 | |
|
4433 | 4434 | With one of -p/--public, -d/--draft or -s/--secret, change the |
|
4434 | 4435 | phase value of the specified revisions. |
|
4435 | 4436 | |
|
4436 | 4437 | Unless -f/--force is specified, :hg:`phase` won't move changeset from a |
|
4437 | 4438 | lower phase to an higher phase. Phases are ordered as follows:: |
|
4438 | 4439 | |
|
4439 | 4440 | public < draft < secret |
|
4440 | 4441 | |
|
4441 | 4442 | Return 0 on success, 1 if no phases were changed or some could not |
|
4442 | 4443 | be changed. |
|
4443 | 4444 | """ |
|
4444 | 4445 | # search for a unique phase argument |
|
4445 | 4446 | targetphase = None |
|
4446 | 4447 | for idx, name in enumerate(phases.phasenames): |
|
4447 | 4448 | if opts[name]: |
|
4448 | 4449 | if targetphase is not None: |
|
4449 | 4450 | raise util.Abort(_('only one phase can be specified')) |
|
4450 | 4451 | targetphase = idx |
|
4451 | 4452 | |
|
4452 | 4453 | # look for specified revision |
|
4453 | 4454 | revs = list(revs) |
|
4454 | 4455 | revs.extend(opts['rev']) |
|
4455 | 4456 | if not revs: |
|
4456 | 4457 | raise util.Abort(_('no revisions specified')) |
|
4457 | 4458 | |
|
4458 | 4459 | revs = scmutil.revrange(repo, revs) |
|
4459 | 4460 | |
|
4460 | 4461 | lock = None |
|
4461 | 4462 | ret = 0 |
|
4462 | 4463 | if targetphase is None: |
|
4463 | 4464 | # display |
|
4464 | 4465 | for r in revs: |
|
4465 | 4466 | ctx = repo[r] |
|
4466 | 4467 | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) |
|
4467 | 4468 | else: |
|
4468 | 4469 | lock = repo.lock() |
|
4469 | 4470 | try: |
|
4470 | 4471 | # set phase |
|
4471 | 4472 | if not revs: |
|
4472 | 4473 | raise util.Abort(_('empty revision set')) |
|
4473 | 4474 | nodes = [repo[r].node() for r in revs] |
|
4474 | 4475 | olddata = repo._phasecache.getphaserevs(repo)[:] |
|
4475 | 4476 | phases.advanceboundary(repo, targetphase, nodes) |
|
4476 | 4477 | if opts['force']: |
|
4477 | 4478 | phases.retractboundary(repo, targetphase, nodes) |
|
4478 | 4479 | finally: |
|
4479 | 4480 | lock.release() |
|
4480 | 4481 | newdata = repo._phasecache.getphaserevs(repo) |
|
4481 | 4482 | changes = sum(o != newdata[i] for i, o in enumerate(olddata)) |
|
4482 | 4483 | rejected = [n for n in nodes |
|
4483 | 4484 | if newdata[repo[n].rev()] < targetphase] |
|
4484 | 4485 | if rejected: |
|
4485 | 4486 | ui.warn(_('cannot move %i changesets to a more permissive ' |
|
4486 | 4487 | 'phase, use --force\n') % len(rejected)) |
|
4487 | 4488 | ret = 1 |
|
4488 | 4489 | if changes: |
|
4489 | 4490 | msg = _('phase changed for %i changesets\n') % changes |
|
4490 | 4491 | if ret: |
|
4491 | 4492 | ui.status(msg) |
|
4492 | 4493 | else: |
|
4493 | 4494 | ui.note(msg) |
|
4494 | 4495 | else: |
|
4495 | 4496 | ui.warn(_('no phases changed\n')) |
|
4496 | 4497 | ret = 1 |
|
4497 | 4498 | return ret |
|
4498 | 4499 | |
|
4499 | 4500 | def postincoming(ui, repo, modheads, optupdate, checkout): |
|
4500 | 4501 | if modheads == 0: |
|
4501 | 4502 | return |
|
4502 | 4503 | if optupdate: |
|
4503 | 4504 | movemarkfrom = repo['.'].node() |
|
4504 | 4505 | try: |
|
4505 | 4506 | ret = hg.update(repo, checkout) |
|
4506 | 4507 | except util.Abort, inst: |
|
4507 | 4508 | ui.warn(_("not updating: %s\n") % str(inst)) |
|
4508 | 4509 | return 0 |
|
4509 | 4510 | if not ret and not checkout: |
|
4510 | 4511 | if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
|
4511 | 4512 | ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent) |
|
4512 | 4513 | return ret |
|
4513 | 4514 | if modheads > 1: |
|
4514 | 4515 | currentbranchheads = len(repo.branchheads()) |
|
4515 | 4516 | if currentbranchheads == modheads: |
|
4516 | 4517 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
4517 | 4518 | elif currentbranchheads > 1: |
|
4518 | 4519 | ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to " |
|
4519 | 4520 | "merge)\n")) |
|
4520 | 4521 | else: |
|
4521 | 4522 | ui.status(_("(run 'hg heads' to see heads)\n")) |
|
4522 | 4523 | else: |
|
4523 | 4524 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
4524 | 4525 | |
|
4525 | 4526 | @command('^pull', |
|
4526 | 4527 | [('u', 'update', None, |
|
4527 | 4528 | _('update to new branch head if changesets were pulled')), |
|
4528 | 4529 | ('f', 'force', None, _('run even when remote repository is unrelated')), |
|
4529 | 4530 | ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')), |
|
4530 | 4531 | ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')), |
|
4531 | 4532 | ('b', 'branch', [], _('a specific branch you would like to pull'), |
|
4532 | 4533 | _('BRANCH')), |
|
4533 | 4534 | ] + remoteopts, |
|
4534 | 4535 | _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')) |
|
4535 | 4536 | def pull(ui, repo, source="default", **opts): |
|
4536 | 4537 | """pull changes from the specified source |
|
4537 | 4538 | |
|
4538 | 4539 | Pull changes from a remote repository to a local one. |
|
4539 | 4540 | |
|
4540 | 4541 | This finds all changes from the repository at the specified path |
|
4541 | 4542 | or URL and adds them to a local repository (the current one unless |
|
4542 | 4543 | -R is specified). By default, this does not update the copy of the |
|
4543 | 4544 | project in the working directory. |
|
4544 | 4545 | |
|
4545 | 4546 | Use :hg:`incoming` if you want to see what would have been added |
|
4546 | 4547 | by a pull at the time you issued this command. If you then decide |
|
4547 | 4548 | to add those changes to the repository, you should use :hg:`pull |
|
4548 | 4549 | -r X` where ``X`` is the last changeset listed by :hg:`incoming`. |
|
4549 | 4550 | |
|
4550 | 4551 | If SOURCE is omitted, the 'default' path will be used. |
|
4551 | 4552 | See :hg:`help urls` for more information. |
|
4552 | 4553 | |
|
4553 | 4554 | Returns 0 on success, 1 if an update had unresolved files. |
|
4554 | 4555 | """ |
|
4555 | 4556 | source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
|
4556 | 4557 | other = hg.peer(repo, opts, source) |
|
4557 | 4558 | ui.status(_('pulling from %s\n') % util.hidepassword(source)) |
|
4558 | 4559 | revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get('rev')) |
|
4559 | 4560 | |
|
4560 | 4561 | if opts.get('bookmark'): |
|
4561 | 4562 | if not revs: |
|
4562 | 4563 | revs = [] |
|
4563 | 4564 | rb = other.listkeys('bookmarks') |
|
4564 | 4565 | for b in opts['bookmark']: |
|
4565 | 4566 | if b not in rb: |
|
4566 | 4567 | raise util.Abort(_('remote bookmark %s not found!') % b) |
|
4567 | 4568 | revs.append(rb[b]) |
|
4568 | 4569 | |
|
4569 | 4570 | if revs: |
|
4570 | 4571 | try: |
|
4571 | 4572 | revs = [other.lookup(rev) for rev in revs] |
|
4572 | 4573 | except error.CapabilityError: |
|
4573 | 4574 | err = _("other repository doesn't support revision lookup, " |
|
4574 | 4575 | "so a rev cannot be specified.") |
|
4575 | 4576 | raise util.Abort(err) |
|
4576 | 4577 | |
|
4577 | 4578 | modheads = repo.pull(other, heads=revs, force=opts.get('force')) |
|
4578 | 4579 | bookmarks.updatefromremote(ui, repo, other, source) |
|
4579 | 4580 | if checkout: |
|
4580 | 4581 | checkout = str(repo.changelog.rev(other.lookup(checkout))) |
|
4581 | 4582 | repo._subtoppath = source |
|
4582 | 4583 | try: |
|
4583 | 4584 | ret = postincoming(ui, repo, modheads, opts.get('update'), checkout) |
|
4584 | 4585 | |
|
4585 | 4586 | finally: |
|
4586 | 4587 | del repo._subtoppath |
|
4587 | 4588 | |
|
4588 | 4589 | # update specified bookmarks |
|
4589 | 4590 | if opts.get('bookmark'): |
|
4590 | 4591 | for b in opts['bookmark']: |
|
4591 | 4592 | # explicit pull overrides local bookmark if any |
|
4592 | 4593 | ui.status(_("importing bookmark %s\n") % b) |
|
4593 | 4594 | repo._bookmarks[b] = repo[rb[b]].node() |
|
4594 | 4595 | bookmarks.write(repo) |
|
4595 | 4596 | |
|
4596 | 4597 | return ret |
|
4597 | 4598 | |
|
4598 | 4599 | @command('^push', |
|
4599 | 4600 | [('f', 'force', None, _('force push')), |
|
4600 | 4601 | ('r', 'rev', [], |
|
4601 | 4602 | _('a changeset intended to be included in the destination'), |
|
4602 | 4603 | _('REV')), |
|
4603 | 4604 | ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')), |
|
4604 | 4605 | ('b', 'branch', [], |
|
4605 | 4606 | _('a specific branch you would like to push'), _('BRANCH')), |
|
4606 | 4607 | ('', 'new-branch', False, _('allow pushing a new branch')), |
|
4607 | 4608 | ] + remoteopts, |
|
4608 | 4609 | _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')) |
|
4609 | 4610 | def push(ui, repo, dest=None, **opts): |
|
4610 | 4611 | """push changes to the specified destination |
|
4611 | 4612 | |
|
4612 | 4613 | Push changesets from the local repository to the specified |
|
4613 | 4614 | destination. |
|
4614 | 4615 | |
|
4615 | 4616 | This operation is symmetrical to pull: it is identical to a pull |
|
4616 | 4617 | in the destination repository from the current one. |
|
4617 | 4618 | |
|
4618 | 4619 | By default, push will not allow creation of new heads at the |
|
4619 | 4620 | destination, since multiple heads would make it unclear which head |
|
4620 | 4621 | to use. In this situation, it is recommended to pull and merge |
|
4621 | 4622 | before pushing. |
|
4622 | 4623 | |
|
4623 | 4624 | Use --new-branch if you want to allow push to create a new named |
|
4624 | 4625 | branch that is not present at the destination. This allows you to |
|
4625 | 4626 | only create a new branch without forcing other changes. |
|
4626 | 4627 | |
|
4627 | 4628 | Use -f/--force to override the default behavior and push all |
|
4628 | 4629 | changesets on all branches. |
|
4629 | 4630 | |
|
4630 | 4631 | If -r/--rev is used, the specified revision and all its ancestors |
|
4631 | 4632 | will be pushed to the remote repository. |
|
4632 | 4633 | |
|
4633 | 4634 | If -B/--bookmark is used, the specified bookmarked revision, its |
|
4634 | 4635 | ancestors, and the bookmark will be pushed to the remote |
|
4635 | 4636 | repository. |
|
4636 | 4637 | |
|
4637 | 4638 | Please see :hg:`help urls` for important details about ``ssh://`` |
|
4638 | 4639 | URLs. If DESTINATION is omitted, a default path will be used. |
|
4639 | 4640 | |
|
4640 | 4641 | Returns 0 if push was successful, 1 if nothing to push. |
|
4641 | 4642 | """ |
|
4642 | 4643 | |
|
4643 | 4644 | if opts.get('bookmark'): |
|
4644 | 4645 | for b in opts['bookmark']: |
|
4645 | 4646 | # translate -B options to -r so changesets get pushed |
|
4646 | 4647 | if b in repo._bookmarks: |
|
4647 | 4648 | opts.setdefault('rev', []).append(b) |
|
4648 | 4649 | else: |
|
4649 | 4650 | # if we try to push a deleted bookmark, translate it to null |
|
4650 | 4651 | # this lets simultaneous -r, -b options continue working |
|
4651 | 4652 | opts.setdefault('rev', []).append("null") |
|
4652 | 4653 | |
|
4653 | 4654 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
4654 | 4655 | dest, branches = hg.parseurl(dest, opts.get('branch')) |
|
4655 | 4656 | ui.status(_('pushing to %s\n') % util.hidepassword(dest)) |
|
4656 | 4657 | revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
4657 | 4658 | other = hg.peer(repo, opts, dest) |
|
4658 | 4659 | if revs: |
|
4659 | 4660 | revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)] |
|
4660 | 4661 | |
|
4661 | 4662 | repo._subtoppath = dest |
|
4662 | 4663 | try: |
|
4663 | 4664 | # push subrepos depth-first for coherent ordering |
|
4664 | 4665 | c = repo[''] |
|
4665 | 4666 | subs = c.substate # only repos that are committed |
|
4666 | 4667 | for s in sorted(subs): |
|
4667 | 4668 | if c.sub(s).push(opts) == 0: |
|
4668 | 4669 | return False |
|
4669 | 4670 | finally: |
|
4670 | 4671 | del repo._subtoppath |
|
4671 | 4672 | result = repo.push(other, opts.get('force'), revs=revs, |
|
4672 | 4673 | newbranch=opts.get('new_branch')) |
|
4673 | 4674 | |
|
4674 | 4675 | result = not result |
|
4675 | 4676 | |
|
4676 | 4677 | if opts.get('bookmark'): |
|
4677 | 4678 | rb = other.listkeys('bookmarks') |
|
4678 | 4679 | for b in opts['bookmark']: |
|
4679 | 4680 | # explicit push overrides remote bookmark if any |
|
4680 | 4681 | if b in repo._bookmarks: |
|
4681 | 4682 | ui.status(_("exporting bookmark %s\n") % b) |
|
4682 | 4683 | new = repo[b].hex() |
|
4683 | 4684 | elif b in rb: |
|
4684 | 4685 | ui.status(_("deleting remote bookmark %s\n") % b) |
|
4685 | 4686 | new = '' # delete |
|
4686 | 4687 | else: |
|
4687 | 4688 | ui.warn(_('bookmark %s does not exist on the local ' |
|
4688 | 4689 | 'or remote repository!\n') % b) |
|
4689 | 4690 | return 2 |
|
4690 | 4691 | old = rb.get(b, '') |
|
4691 | 4692 | r = other.pushkey('bookmarks', b, old, new) |
|
4692 | 4693 | if not r: |
|
4693 | 4694 | ui.warn(_('updating bookmark %s failed!\n') % b) |
|
4694 | 4695 | if not result: |
|
4695 | 4696 | result = 2 |
|
4696 | 4697 | |
|
4697 | 4698 | return result |
|
4698 | 4699 | |
|
4699 | 4700 | @command('recover', []) |
|
4700 | 4701 | def recover(ui, repo): |
|
4701 | 4702 | """roll back an interrupted transaction |
|
4702 | 4703 | |
|
4703 | 4704 | Recover from an interrupted commit or pull. |
|
4704 | 4705 | |
|
4705 | 4706 | This command tries to fix the repository status after an |
|
4706 | 4707 | interrupted operation. It should only be necessary when Mercurial |
|
4707 | 4708 | suggests it. |
|
4708 | 4709 | |
|
4709 | 4710 | Returns 0 if successful, 1 if nothing to recover or verify fails. |
|
4710 | 4711 | """ |
|
4711 | 4712 | if repo.recover(): |
|
4712 | 4713 | return hg.verify(repo) |
|
4713 | 4714 | return 1 |
|
4714 | 4715 | |
|
4715 | 4716 | @command('^remove|rm', |
|
4716 | 4717 | [('A', 'after', None, _('record delete for missing files')), |
|
4717 | 4718 | ('f', 'force', None, |
|
4718 | 4719 | _('remove (and delete) file even if added or modified')), |
|
4719 | 4720 | ] + walkopts, |
|
4720 | 4721 | _('[OPTION]... FILE...')) |
|
4721 | 4722 | def remove(ui, repo, *pats, **opts): |
|
4722 | 4723 | """remove the specified files on the next commit |
|
4723 | 4724 | |
|
4724 | 4725 | Schedule the indicated files for removal from the current branch. |
|
4725 | 4726 | |
|
4726 | 4727 | This command schedules the files to be removed at the next commit. |
|
4727 | 4728 | To undo a remove before that, see :hg:`revert`. To undo added |
|
4728 | 4729 | files, see :hg:`forget`. |
|
4729 | 4730 | |
|
4730 | 4731 | .. container:: verbose |
|
4731 | 4732 | |
|
4732 | 4733 | -A/--after can be used to remove only files that have already |
|
4733 | 4734 | been deleted, -f/--force can be used to force deletion, and -Af |
|
4734 | 4735 | can be used to remove files from the next revision without |
|
4735 | 4736 | deleting them from the working directory. |
|
4736 | 4737 | |
|
4737 | 4738 | The following table details the behavior of remove for different |
|
4738 | 4739 | file states (columns) and option combinations (rows). The file |
|
4739 | 4740 | states are Added [A], Clean [C], Modified [M] and Missing [!] |
|
4740 | 4741 | (as reported by :hg:`status`). The actions are Warn, Remove |
|
4741 | 4742 | (from branch) and Delete (from disk): |
|
4742 | 4743 | |
|
4743 | 4744 | ======= == == == == |
|
4744 | 4745 | A C M ! |
|
4745 | 4746 | ======= == == == == |
|
4746 | 4747 | none W RD W R |
|
4747 | 4748 | -f R RD RD R |
|
4748 | 4749 | -A W W W R |
|
4749 | 4750 | -Af R R R R |
|
4750 | 4751 | ======= == == == == |
|
4751 | 4752 | |
|
4752 | 4753 | Note that remove never deletes files in Added [A] state from the |
|
4753 | 4754 | working directory, not even if option --force is specified. |
|
4754 | 4755 | |
|
4755 | 4756 | Returns 0 on success, 1 if any warnings encountered. |
|
4756 | 4757 | """ |
|
4757 | 4758 | |
|
4758 | 4759 | ret = 0 |
|
4759 | 4760 | after, force = opts.get('after'), opts.get('force') |
|
4760 | 4761 | if not pats and not after: |
|
4761 | 4762 | raise util.Abort(_('no files specified')) |
|
4762 | 4763 | |
|
4763 | 4764 | m = scmutil.match(repo[None], pats, opts) |
|
4764 | 4765 | s = repo.status(match=m, clean=True) |
|
4765 | 4766 | modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
|
4766 | 4767 | |
|
4767 | 4768 | for f in m.files(): |
|
4768 | 4769 | if f not in repo.dirstate and not os.path.isdir(m.rel(f)): |
|
4769 | 4770 | if os.path.exists(m.rel(f)): |
|
4770 | 4771 | ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) |
|
4771 | 4772 | ret = 1 |
|
4772 | 4773 | |
|
4773 | 4774 | if force: |
|
4774 | 4775 | list = modified + deleted + clean + added |
|
4775 | 4776 | elif after: |
|
4776 | 4777 | list = deleted |
|
4777 | 4778 | for f in modified + added + clean: |
|
4778 | 4779 | ui.warn(_('not removing %s: file still exists (use -f' |
|
4779 | 4780 | ' to force removal)\n') % m.rel(f)) |
|
4780 | 4781 | ret = 1 |
|
4781 | 4782 | else: |
|
4782 | 4783 | list = deleted + clean |
|
4783 | 4784 | for f in modified: |
|
4784 | 4785 | ui.warn(_('not removing %s: file is modified (use -f' |
|
4785 | 4786 | ' to force removal)\n') % m.rel(f)) |
|
4786 | 4787 | ret = 1 |
|
4787 | 4788 | for f in added: |
|
4788 | 4789 | ui.warn(_('not removing %s: file has been marked for add' |
|
4789 | 4790 | ' (use forget to undo)\n') % m.rel(f)) |
|
4790 | 4791 | ret = 1 |
|
4791 | 4792 | |
|
4792 | 4793 | for f in sorted(list): |
|
4793 | 4794 | if ui.verbose or not m.exact(f): |
|
4794 | 4795 | ui.status(_('removing %s\n') % m.rel(f)) |
|
4795 | 4796 | |
|
4796 | 4797 | wlock = repo.wlock() |
|
4797 | 4798 | try: |
|
4798 | 4799 | if not after: |
|
4799 | 4800 | for f in list: |
|
4800 | 4801 | if f in added: |
|
4801 | 4802 | continue # we never unlink added files on remove |
|
4802 | 4803 | try: |
|
4803 | 4804 | util.unlinkpath(repo.wjoin(f)) |
|
4804 | 4805 | except OSError, inst: |
|
4805 | 4806 | if inst.errno != errno.ENOENT: |
|
4806 | 4807 | raise |
|
4807 | 4808 | repo[None].forget(list) |
|
4808 | 4809 | finally: |
|
4809 | 4810 | wlock.release() |
|
4810 | 4811 | |
|
4811 | 4812 | return ret |
|
4812 | 4813 | |
|
4813 | 4814 | @command('rename|move|mv', |
|
4814 | 4815 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
4815 | 4816 | ('f', 'force', None, _('forcibly copy over an existing managed file')), |
|
4816 | 4817 | ] + walkopts + dryrunopts, |
|
4817 | 4818 | _('[OPTION]... SOURCE... DEST')) |
|
4818 | 4819 | def rename(ui, repo, *pats, **opts): |
|
4819 | 4820 | """rename files; equivalent of copy + remove |
|
4820 | 4821 | |
|
4821 | 4822 | Mark dest as copies of sources; mark sources for deletion. If dest |
|
4822 | 4823 | is a directory, copies are put in that directory. If dest is a |
|
4823 | 4824 | file, there can only be one source. |
|
4824 | 4825 | |
|
4825 | 4826 | By default, this command copies the contents of files as they |
|
4826 | 4827 | exist in the working directory. If invoked with -A/--after, the |
|
4827 | 4828 | operation is recorded, but no copying is performed. |
|
4828 | 4829 | |
|
4829 | 4830 | This command takes effect at the next commit. To undo a rename |
|
4830 | 4831 | before that, see :hg:`revert`. |
|
4831 | 4832 | |
|
4832 | 4833 | Returns 0 on success, 1 if errors are encountered. |
|
4833 | 4834 | """ |
|
4834 | 4835 | wlock = repo.wlock(False) |
|
4835 | 4836 | try: |
|
4836 | 4837 | return cmdutil.copy(ui, repo, pats, opts, rename=True) |
|
4837 | 4838 | finally: |
|
4838 | 4839 | wlock.release() |
|
4839 | 4840 | |
|
4840 | 4841 | @command('resolve', |
|
4841 | 4842 | [('a', 'all', None, _('select all unresolved files')), |
|
4842 | 4843 | ('l', 'list', None, _('list state of files needing merge')), |
|
4843 | 4844 | ('m', 'mark', None, _('mark files as resolved')), |
|
4844 | 4845 | ('u', 'unmark', None, _('mark files as unresolved')), |
|
4845 | 4846 | ('n', 'no-status', None, _('hide status prefix'))] |
|
4846 | 4847 | + mergetoolopts + walkopts, |
|
4847 | 4848 | _('[OPTION]... [FILE]...')) |
|
4848 | 4849 | def resolve(ui, repo, *pats, **opts): |
|
4849 | 4850 | """redo merges or set/view the merge status of files |
|
4850 | 4851 | |
|
4851 | 4852 | Merges with unresolved conflicts are often the result of |
|
4852 | 4853 | non-interactive merging using the ``internal:merge`` configuration |
|
4853 | 4854 | setting, or a command-line merge tool like ``diff3``. The resolve |
|
4854 | 4855 | command is used to manage the files involved in a merge, after |
|
4855 | 4856 | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the |
|
4856 | 4857 | working directory must have two parents). See :hg:`help |
|
4857 | 4858 | merge-tools` for information on configuring merge tools. |
|
4858 | 4859 | |
|
4859 | 4860 | The resolve command can be used in the following ways: |
|
4860 | 4861 | |
|
4861 | 4862 | - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified |
|
4862 | 4863 | files, discarding any previous merge attempts. Re-merging is not |
|
4863 | 4864 | performed for files already marked as resolved. Use ``--all/-a`` |
|
4864 | 4865 | to select all unresolved files. ``--tool`` can be used to specify |
|
4865 | 4866 | the merge tool used for the given files. It overrides the HGMERGE |
|
4866 | 4867 | environment variable and your configuration files. Previous file |
|
4867 | 4868 | contents are saved with a ``.orig`` suffix. |
|
4868 | 4869 | |
|
4869 | 4870 | - :hg:`resolve -m [FILE]`: mark a file as having been resolved |
|
4870 | 4871 | (e.g. after having manually fixed-up the files). The default is |
|
4871 | 4872 | to mark all unresolved files. |
|
4872 | 4873 | |
|
4873 | 4874 | - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The |
|
4874 | 4875 | default is to mark all resolved files. |
|
4875 | 4876 | |
|
4876 | 4877 | - :hg:`resolve -l`: list files which had or still have conflicts. |
|
4877 | 4878 | In the printed list, ``U`` = unresolved and ``R`` = resolved. |
|
4878 | 4879 | |
|
4879 | 4880 | Note that Mercurial will not let you commit files with unresolved |
|
4880 | 4881 | merge conflicts. You must use :hg:`resolve -m ...` before you can |
|
4881 | 4882 | commit after a conflicting merge. |
|
4882 | 4883 | |
|
4883 | 4884 | Returns 0 on success, 1 if any files fail a resolve attempt. |
|
4884 | 4885 | """ |
|
4885 | 4886 | |
|
4886 | 4887 | all, mark, unmark, show, nostatus = \ |
|
4887 | 4888 | [opts.get(o) for o in 'all mark unmark list no_status'.split()] |
|
4888 | 4889 | |
|
4889 | 4890 | if (show and (mark or unmark)) or (mark and unmark): |
|
4890 | 4891 | raise util.Abort(_("too many options specified")) |
|
4891 | 4892 | if pats and all: |
|
4892 | 4893 | raise util.Abort(_("can't specify --all and patterns")) |
|
4893 | 4894 | if not (all or pats or show or mark or unmark): |
|
4894 | 4895 | raise util.Abort(_('no files or directories specified; ' |
|
4895 | 4896 | 'use --all to remerge all files')) |
|
4896 | 4897 | |
|
4897 | 4898 | ms = mergemod.mergestate(repo) |
|
4898 | 4899 | m = scmutil.match(repo[None], pats, opts) |
|
4899 | 4900 | ret = 0 |
|
4900 | 4901 | |
|
4901 | 4902 | for f in ms: |
|
4902 | 4903 | if m(f): |
|
4903 | 4904 | if show: |
|
4904 | 4905 | if nostatus: |
|
4905 | 4906 | ui.write("%s\n" % f) |
|
4906 | 4907 | else: |
|
4907 | 4908 | ui.write("%s %s\n" % (ms[f].upper(), f), |
|
4908 | 4909 | label='resolve.' + |
|
4909 | 4910 | {'u': 'unresolved', 'r': 'resolved'}[ms[f]]) |
|
4910 | 4911 | elif mark: |
|
4911 | 4912 | ms.mark(f, "r") |
|
4912 | 4913 | elif unmark: |
|
4913 | 4914 | ms.mark(f, "u") |
|
4914 | 4915 | else: |
|
4915 | 4916 | wctx = repo[None] |
|
4916 | 4917 | mctx = wctx.parents()[-1] |
|
4917 | 4918 | |
|
4918 | 4919 | # backup pre-resolve (merge uses .orig for its own purposes) |
|
4919 | 4920 | a = repo.wjoin(f) |
|
4920 | 4921 | util.copyfile(a, a + ".resolve") |
|
4921 | 4922 | |
|
4922 | 4923 | try: |
|
4923 | 4924 | # resolve file |
|
4924 | 4925 | ui.setconfig('ui', 'forcemerge', opts.get('tool', '')) |
|
4925 | 4926 | if ms.resolve(f, wctx, mctx): |
|
4926 | 4927 | ret = 1 |
|
4927 | 4928 | finally: |
|
4928 | 4929 | ui.setconfig('ui', 'forcemerge', '') |
|
4929 | 4930 | |
|
4930 | 4931 | # replace filemerge's .orig file with our resolve file |
|
4931 | 4932 | util.rename(a + ".resolve", a + ".orig") |
|
4932 | 4933 | |
|
4933 | 4934 | ms.commit() |
|
4934 | 4935 | return ret |
|
4935 | 4936 | |
|
4936 | 4937 | @command('revert', |
|
4937 | 4938 | [('a', 'all', None, _('revert all changes when no arguments given')), |
|
4938 | 4939 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
4939 | 4940 | ('r', 'rev', '', _('revert to the specified revision'), _('REV')), |
|
4940 | 4941 | ('C', 'no-backup', None, _('do not save backup copies of files')), |
|
4941 | 4942 | ] + walkopts + dryrunopts, |
|
4942 | 4943 | _('[OPTION]... [-r REV] [NAME]...')) |
|
4943 | 4944 | def revert(ui, repo, *pats, **opts): |
|
4944 | 4945 | """restore files to their checkout state |
|
4945 | 4946 | |
|
4946 | 4947 | .. note:: |
|
4947 | 4948 | |
|
4948 | 4949 | To check out earlier revisions, you should use :hg:`update REV`. |
|
4949 | 4950 | To cancel an uncommitted merge (and lose your changes), use |
|
4950 | 4951 | :hg:`update --clean .`. |
|
4951 | 4952 | |
|
4952 | 4953 | With no revision specified, revert the specified files or directories |
|
4953 | 4954 | to the contents they had in the parent of the working directory. |
|
4954 | 4955 | This restores the contents of files to an unmodified |
|
4955 | 4956 | state and unschedules adds, removes, copies, and renames. If the |
|
4956 | 4957 | working directory has two parents, you must explicitly specify a |
|
4957 | 4958 | revision. |
|
4958 | 4959 | |
|
4959 | 4960 | Using the -r/--rev or -d/--date options, revert the given files or |
|
4960 | 4961 | directories to their states as of a specific revision. Because |
|
4961 | 4962 | revert does not change the working directory parents, this will |
|
4962 | 4963 | cause these files to appear modified. This can be helpful to "back |
|
4963 | 4964 | out" some or all of an earlier change. See :hg:`backout` for a |
|
4964 | 4965 | related method. |
|
4965 | 4966 | |
|
4966 | 4967 | Modified files are saved with a .orig suffix before reverting. |
|
4967 | 4968 | To disable these backups, use --no-backup. |
|
4968 | 4969 | |
|
4969 | 4970 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
4970 | 4971 | |
|
4971 | 4972 | Returns 0 on success. |
|
4972 | 4973 | """ |
|
4973 | 4974 | |
|
4974 | 4975 | if opts.get("date"): |
|
4975 | 4976 | if opts.get("rev"): |
|
4976 | 4977 | raise util.Abort(_("you can't specify a revision and a date")) |
|
4977 | 4978 | opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) |
|
4978 | 4979 | |
|
4979 | 4980 | parent, p2 = repo.dirstate.parents() |
|
4980 | 4981 | if not opts.get('rev') and p2 != nullid: |
|
4981 | 4982 | # revert after merge is a trap for new users (issue2915) |
|
4982 | 4983 | raise util.Abort(_('uncommitted merge with no revision specified'), |
|
4983 | 4984 | hint=_('use "hg update" or see "hg help revert"')) |
|
4984 | 4985 | |
|
4985 | 4986 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
4986 | 4987 | |
|
4987 | 4988 | if not pats and not opts.get('all'): |
|
4988 | 4989 | msg = _("no files or directories specified") |
|
4989 | 4990 | if p2 != nullid: |
|
4990 | 4991 | hint = _("uncommitted merge, use --all to discard all changes," |
|
4991 | 4992 | " or 'hg update -C .' to abort the merge") |
|
4992 | 4993 | raise util.Abort(msg, hint=hint) |
|
4993 | 4994 | dirty = util.any(repo.status()) |
|
4994 | 4995 | node = ctx.node() |
|
4995 | 4996 | if node != parent: |
|
4996 | 4997 | if dirty: |
|
4997 | 4998 | hint = _("uncommitted changes, use --all to discard all" |
|
4998 | 4999 | " changes, or 'hg update %s' to update") % ctx.rev() |
|
4999 | 5000 | else: |
|
5000 | 5001 | hint = _("use --all to revert all files," |
|
5001 | 5002 | " or 'hg update %s' to update") % ctx.rev() |
|
5002 | 5003 | elif dirty: |
|
5003 | 5004 | hint = _("uncommitted changes, use --all to discard all changes") |
|
5004 | 5005 | else: |
|
5005 | 5006 | hint = _("use --all to revert all files") |
|
5006 | 5007 | raise util.Abort(msg, hint=hint) |
|
5007 | 5008 | |
|
5008 | 5009 | return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats, **opts) |
|
5009 | 5010 | |
|
5010 | 5011 | @command('rollback', dryrunopts + |
|
5011 | 5012 | [('f', 'force', False, _('ignore safety measures'))]) |
|
5012 | 5013 | def rollback(ui, repo, **opts): |
|
5013 | 5014 | """roll back the last transaction (dangerous) |
|
5014 | 5015 | |
|
5015 | 5016 | This command should be used with care. There is only one level of |
|
5016 | 5017 | rollback, and there is no way to undo a rollback. It will also |
|
5017 | 5018 | restore the dirstate at the time of the last transaction, losing |
|
5018 | 5019 | any dirstate changes since that time. This command does not alter |
|
5019 | 5020 | the working directory. |
|
5020 | 5021 | |
|
5021 | 5022 | Transactions are used to encapsulate the effects of all commands |
|
5022 | 5023 | that create new changesets or propagate existing changesets into a |
|
5023 | 5024 | repository. |
|
5024 | 5025 | |
|
5025 | 5026 | .. container:: verbose |
|
5026 | 5027 | |
|
5027 | 5028 | For example, the following commands are transactional, and their |
|
5028 | 5029 | effects can be rolled back: |
|
5029 | 5030 | |
|
5030 | 5031 | - commit |
|
5031 | 5032 | - import |
|
5032 | 5033 | - pull |
|
5033 | 5034 | - push (with this repository as the destination) |
|
5034 | 5035 | - unbundle |
|
5035 | 5036 | |
|
5036 | 5037 | To avoid permanent data loss, rollback will refuse to rollback a |
|
5037 | 5038 | commit transaction if it isn't checked out. Use --force to |
|
5038 | 5039 | override this protection. |
|
5039 | 5040 | |
|
5040 | 5041 | This command is not intended for use on public repositories. Once |
|
5041 | 5042 | changes are visible for pull by other users, rolling a transaction |
|
5042 | 5043 | back locally is ineffective (someone else may already have pulled |
|
5043 | 5044 | the changes). Furthermore, a race is possible with readers of the |
|
5044 | 5045 | repository; for example an in-progress pull from the repository |
|
5045 | 5046 | may fail if a rollback is performed. |
|
5046 | 5047 | |
|
5047 | 5048 | Returns 0 on success, 1 if no rollback data is available. |
|
5048 | 5049 | """ |
|
5049 | 5050 | return repo.rollback(dryrun=opts.get('dry_run'), |
|
5050 | 5051 | force=opts.get('force')) |
|
5051 | 5052 | |
|
5052 | 5053 | @command('root', []) |
|
5053 | 5054 | def root(ui, repo): |
|
5054 | 5055 | """print the root (top) of the current working directory |
|
5055 | 5056 | |
|
5056 | 5057 | Print the root directory of the current repository. |
|
5057 | 5058 | |
|
5058 | 5059 | Returns 0 on success. |
|
5059 | 5060 | """ |
|
5060 | 5061 | ui.write(repo.root + "\n") |
|
5061 | 5062 | |
|
5062 | 5063 | @command('^serve', |
|
5063 | 5064 | [('A', 'accesslog', '', _('name of access log file to write to'), |
|
5064 | 5065 | _('FILE')), |
|
5065 | 5066 | ('d', 'daemon', None, _('run server in background')), |
|
5066 | 5067 | ('', 'daemon-pipefds', '', _('used internally by daemon mode'), _('NUM')), |
|
5067 | 5068 | ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')), |
|
5068 | 5069 | # use string type, then we can check if something was passed |
|
5069 | 5070 | ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')), |
|
5070 | 5071 | ('a', 'address', '', _('address to listen on (default: all interfaces)'), |
|
5071 | 5072 | _('ADDR')), |
|
5072 | 5073 | ('', 'prefix', '', _('prefix path to serve from (default: server root)'), |
|
5073 | 5074 | _('PREFIX')), |
|
5074 | 5075 | ('n', 'name', '', |
|
5075 | 5076 | _('name to show in web pages (default: working directory)'), _('NAME')), |
|
5076 | 5077 | ('', 'web-conf', '', |
|
5077 | 5078 | _('name of the hgweb config file (see "hg help hgweb")'), _('FILE')), |
|
5078 | 5079 | ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'), |
|
5079 | 5080 | _('FILE')), |
|
5080 | 5081 | ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')), |
|
5081 | 5082 | ('', 'stdio', None, _('for remote clients')), |
|
5082 | 5083 | ('', 'cmdserver', '', _('for remote clients'), _('MODE')), |
|
5083 | 5084 | ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')), |
|
5084 | 5085 | ('', 'style', '', _('template style to use'), _('STYLE')), |
|
5085 | 5086 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')), |
|
5086 | 5087 | ('', 'certificate', '', _('SSL certificate file'), _('FILE'))], |
|
5087 | 5088 | _('[OPTION]...')) |
|
5088 | 5089 | def serve(ui, repo, **opts): |
|
5089 | 5090 | """start stand-alone webserver |
|
5090 | 5091 | |
|
5091 | 5092 | Start a local HTTP repository browser and pull server. You can use |
|
5092 | 5093 | this for ad-hoc sharing and browsing of repositories. It is |
|
5093 | 5094 | recommended to use a real web server to serve a repository for |
|
5094 | 5095 | longer periods of time. |
|
5095 | 5096 | |
|
5096 | 5097 | Please note that the server does not implement access control. |
|
5097 | 5098 | This means that, by default, anybody can read from the server and |
|
5098 | 5099 | nobody can write to it by default. Set the ``web.allow_push`` |
|
5099 | 5100 | option to ``*`` to allow everybody to push to the server. You |
|
5100 | 5101 | should use a real web server if you need to authenticate users. |
|
5101 | 5102 | |
|
5102 | 5103 | By default, the server logs accesses to stdout and errors to |
|
5103 | 5104 | stderr. Use the -A/--accesslog and -E/--errorlog options to log to |
|
5104 | 5105 | files. |
|
5105 | 5106 | |
|
5106 | 5107 | To have the server choose a free port number to listen on, specify |
|
5107 | 5108 | a port number of 0; in this case, the server will print the port |
|
5108 | 5109 | number it uses. |
|
5109 | 5110 | |
|
5110 | 5111 | Returns 0 on success. |
|
5111 | 5112 | """ |
|
5112 | 5113 | |
|
5113 | 5114 | if opts["stdio"] and opts["cmdserver"]: |
|
5114 | 5115 | raise util.Abort(_("cannot use --stdio with --cmdserver")) |
|
5115 | 5116 | |
|
5116 | 5117 | def checkrepo(): |
|
5117 | 5118 | if repo is None: |
|
5118 | 5119 | raise error.RepoError(_("there is no Mercurial repository here" |
|
5119 | 5120 | " (.hg not found)")) |
|
5120 | 5121 | |
|
5121 | 5122 | if opts["stdio"]: |
|
5122 | 5123 | checkrepo() |
|
5123 | 5124 | s = sshserver.sshserver(ui, repo) |
|
5124 | 5125 | s.serve_forever() |
|
5125 | 5126 | |
|
5126 | 5127 | if opts["cmdserver"]: |
|
5127 | 5128 | checkrepo() |
|
5128 | 5129 | s = commandserver.server(ui, repo, opts["cmdserver"]) |
|
5129 | 5130 | return s.serve() |
|
5130 | 5131 | |
|
5131 | 5132 | # this way we can check if something was given in the command-line |
|
5132 | 5133 | if opts.get('port'): |
|
5133 | 5134 | opts['port'] = util.getport(opts.get('port')) |
|
5134 | 5135 | |
|
5135 | 5136 | baseui = repo and repo.baseui or ui |
|
5136 | 5137 | optlist = ("name templates style address port prefix ipv6" |
|
5137 | 5138 | " accesslog errorlog certificate encoding") |
|
5138 | 5139 | for o in optlist.split(): |
|
5139 | 5140 | val = opts.get(o, '') |
|
5140 | 5141 | if val in (None, ''): # should check against default options instead |
|
5141 | 5142 | continue |
|
5142 | 5143 | baseui.setconfig("web", o, val) |
|
5143 | 5144 | if repo and repo.ui != baseui: |
|
5144 | 5145 | repo.ui.setconfig("web", o, val) |
|
5145 | 5146 | |
|
5146 | 5147 | o = opts.get('web_conf') or opts.get('webdir_conf') |
|
5147 | 5148 | if not o: |
|
5148 | 5149 | if not repo: |
|
5149 | 5150 | raise error.RepoError(_("there is no Mercurial repository" |
|
5150 | 5151 | " here (.hg not found)")) |
|
5151 | 5152 | o = repo.root |
|
5152 | 5153 | |
|
5153 | 5154 | app = hgweb.hgweb(o, baseui=ui) |
|
5154 | 5155 | |
|
5155 | 5156 | class service(object): |
|
5156 | 5157 | def init(self): |
|
5157 | 5158 | util.setsignalhandler() |
|
5158 | 5159 | self.httpd = hgweb.server.create_server(ui, app) |
|
5159 | 5160 | |
|
5160 | 5161 | if opts['port'] and not ui.verbose: |
|
5161 | 5162 | return |
|
5162 | 5163 | |
|
5163 | 5164 | if self.httpd.prefix: |
|
5164 | 5165 | prefix = self.httpd.prefix.strip('/') + '/' |
|
5165 | 5166 | else: |
|
5166 | 5167 | prefix = '' |
|
5167 | 5168 | |
|
5168 | 5169 | port = ':%d' % self.httpd.port |
|
5169 | 5170 | if port == ':80': |
|
5170 | 5171 | port = '' |
|
5171 | 5172 | |
|
5172 | 5173 | bindaddr = self.httpd.addr |
|
5173 | 5174 | if bindaddr == '0.0.0.0': |
|
5174 | 5175 | bindaddr = '*' |
|
5175 | 5176 | elif ':' in bindaddr: # IPv6 |
|
5176 | 5177 | bindaddr = '[%s]' % bindaddr |
|
5177 | 5178 | |
|
5178 | 5179 | fqaddr = self.httpd.fqaddr |
|
5179 | 5180 | if ':' in fqaddr: |
|
5180 | 5181 | fqaddr = '[%s]' % fqaddr |
|
5181 | 5182 | if opts['port']: |
|
5182 | 5183 | write = ui.status |
|
5183 | 5184 | else: |
|
5184 | 5185 | write = ui.write |
|
5185 | 5186 | write(_('listening at http://%s%s/%s (bound to %s:%d)\n') % |
|
5186 | 5187 | (fqaddr, port, prefix, bindaddr, self.httpd.port)) |
|
5187 | 5188 | |
|
5188 | 5189 | def run(self): |
|
5189 | 5190 | self.httpd.serve_forever() |
|
5190 | 5191 | |
|
5191 | 5192 | service = service() |
|
5192 | 5193 | |
|
5193 | 5194 | cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
5194 | 5195 | |
|
5195 | 5196 | @command('showconfig|debugconfig', |
|
5196 | 5197 | [('u', 'untrusted', None, _('show untrusted configuration options'))], |
|
5197 | 5198 | _('[-u] [NAME]...')) |
|
5198 | 5199 | def showconfig(ui, repo, *values, **opts): |
|
5199 | 5200 | """show combined config settings from all hgrc files |
|
5200 | 5201 | |
|
5201 | 5202 | With no arguments, print names and values of all config items. |
|
5202 | 5203 | |
|
5203 | 5204 | With one argument of the form section.name, print just the value |
|
5204 | 5205 | of that config item. |
|
5205 | 5206 | |
|
5206 | 5207 | With multiple arguments, print names and values of all config |
|
5207 | 5208 | items with matching section names. |
|
5208 | 5209 | |
|
5209 | 5210 | With --debug, the source (filename and line number) is printed |
|
5210 | 5211 | for each config item. |
|
5211 | 5212 | |
|
5212 | 5213 | Returns 0 on success. |
|
5213 | 5214 | """ |
|
5214 | 5215 | |
|
5215 | 5216 | for f in scmutil.rcpath(): |
|
5216 | 5217 | ui.debug('read config from: %s\n' % f) |
|
5217 | 5218 | untrusted = bool(opts.get('untrusted')) |
|
5218 | 5219 | if values: |
|
5219 | 5220 | sections = [v for v in values if '.' not in v] |
|
5220 | 5221 | items = [v for v in values if '.' in v] |
|
5221 | 5222 | if len(items) > 1 or items and sections: |
|
5222 | 5223 | raise util.Abort(_('only one config item permitted')) |
|
5223 | 5224 | for section, name, value in ui.walkconfig(untrusted=untrusted): |
|
5224 | 5225 | value = str(value).replace('\n', '\\n') |
|
5225 | 5226 | sectname = section + '.' + name |
|
5226 | 5227 | if values: |
|
5227 | 5228 | for v in values: |
|
5228 | 5229 | if v == section: |
|
5229 | 5230 | ui.debug('%s: ' % |
|
5230 | 5231 | ui.configsource(section, name, untrusted)) |
|
5231 | 5232 | ui.write('%s=%s\n' % (sectname, value)) |
|
5232 | 5233 | elif v == sectname: |
|
5233 | 5234 | ui.debug('%s: ' % |
|
5234 | 5235 | ui.configsource(section, name, untrusted)) |
|
5235 | 5236 | ui.write(value, '\n') |
|
5236 | 5237 | else: |
|
5237 | 5238 | ui.debug('%s: ' % |
|
5238 | 5239 | ui.configsource(section, name, untrusted)) |
|
5239 | 5240 | ui.write('%s=%s\n' % (sectname, value)) |
|
5240 | 5241 | |
|
5241 | 5242 | @command('^status|st', |
|
5242 | 5243 | [('A', 'all', None, _('show status of all files')), |
|
5243 | 5244 | ('m', 'modified', None, _('show only modified files')), |
|
5244 | 5245 | ('a', 'added', None, _('show only added files')), |
|
5245 | 5246 | ('r', 'removed', None, _('show only removed files')), |
|
5246 | 5247 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
5247 | 5248 | ('c', 'clean', None, _('show only files without changes')), |
|
5248 | 5249 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
5249 | 5250 | ('i', 'ignored', None, _('show only ignored files')), |
|
5250 | 5251 | ('n', 'no-status', None, _('hide status prefix')), |
|
5251 | 5252 | ('C', 'copies', None, _('show source of copied files')), |
|
5252 | 5253 | ('0', 'print0', None, _('end filenames with NUL, for use with xargs')), |
|
5253 | 5254 | ('', 'rev', [], _('show difference from revision'), _('REV')), |
|
5254 | 5255 | ('', 'change', '', _('list the changed files of a revision'), _('REV')), |
|
5255 | 5256 | ] + walkopts + subrepoopts, |
|
5256 | 5257 | _('[OPTION]... [FILE]...')) |
|
5257 | 5258 | def status(ui, repo, *pats, **opts): |
|
5258 | 5259 | """show changed files in the working directory |
|
5259 | 5260 | |
|
5260 | 5261 | Show status of files in the repository. If names are given, only |
|
5261 | 5262 | files that match are shown. Files that are clean or ignored or |
|
5262 | 5263 | the source of a copy/move operation, are not listed unless |
|
5263 | 5264 | -c/--clean, -i/--ignored, -C/--copies or -A/--all are given. |
|
5264 | 5265 | Unless options described with "show only ..." are given, the |
|
5265 | 5266 | options -mardu are used. |
|
5266 | 5267 | |
|
5267 | 5268 | Option -q/--quiet hides untracked (unknown and ignored) files |
|
5268 | 5269 | unless explicitly requested with -u/--unknown or -i/--ignored. |
|
5269 | 5270 | |
|
5270 | 5271 | .. note:: |
|
5271 | 5272 | status may appear to disagree with diff if permissions have |
|
5272 | 5273 | changed or a merge has occurred. The standard diff format does |
|
5273 | 5274 | not report permission changes and diff only reports changes |
|
5274 | 5275 | relative to one merge parent. |
|
5275 | 5276 | |
|
5276 | 5277 | If one revision is given, it is used as the base revision. |
|
5277 | 5278 | If two revisions are given, the differences between them are |
|
5278 | 5279 | shown. The --change option can also be used as a shortcut to list |
|
5279 | 5280 | the changed files of a revision from its first parent. |
|
5280 | 5281 | |
|
5281 | 5282 | The codes used to show the status of files are:: |
|
5282 | 5283 | |
|
5283 | 5284 | M = modified |
|
5284 | 5285 | A = added |
|
5285 | 5286 | R = removed |
|
5286 | 5287 | C = clean |
|
5287 | 5288 | ! = missing (deleted by non-hg command, but still tracked) |
|
5288 | 5289 | ? = not tracked |
|
5289 | 5290 | I = ignored |
|
5290 | 5291 | = origin of the previous file listed as A (added) |
|
5291 | 5292 | |
|
5292 | 5293 | .. container:: verbose |
|
5293 | 5294 | |
|
5294 | 5295 | Examples: |
|
5295 | 5296 | |
|
5296 | 5297 | - show changes in the working directory relative to a |
|
5297 | 5298 | changeset:: |
|
5298 | 5299 | |
|
5299 | 5300 | hg status --rev 9353 |
|
5300 | 5301 | |
|
5301 | 5302 | - show all changes including copies in an existing changeset:: |
|
5302 | 5303 | |
|
5303 | 5304 | hg status --copies --change 9353 |
|
5304 | 5305 | |
|
5305 | 5306 | - get a NUL separated list of added files, suitable for xargs:: |
|
5306 | 5307 | |
|
5307 | 5308 | hg status -an0 |
|
5308 | 5309 | |
|
5309 | 5310 | Returns 0 on success. |
|
5310 | 5311 | """ |
|
5311 | 5312 | |
|
5312 | 5313 | revs = opts.get('rev') |
|
5313 | 5314 | change = opts.get('change') |
|
5314 | 5315 | |
|
5315 | 5316 | if revs and change: |
|
5316 | 5317 | msg = _('cannot specify --rev and --change at the same time') |
|
5317 | 5318 | raise util.Abort(msg) |
|
5318 | 5319 | elif change: |
|
5319 | 5320 | node2 = scmutil.revsingle(repo, change, None).node() |
|
5320 | 5321 | node1 = repo[node2].p1().node() |
|
5321 | 5322 | else: |
|
5322 | 5323 | node1, node2 = scmutil.revpair(repo, revs) |
|
5323 | 5324 | |
|
5324 | 5325 | cwd = (pats and repo.getcwd()) or '' |
|
5325 | 5326 | end = opts.get('print0') and '\0' or '\n' |
|
5326 | 5327 | copy = {} |
|
5327 | 5328 | states = 'modified added removed deleted unknown ignored clean'.split() |
|
5328 | 5329 | show = [k for k in states if opts.get(k)] |
|
5329 | 5330 | if opts.get('all'): |
|
5330 | 5331 | show += ui.quiet and (states[:4] + ['clean']) or states |
|
5331 | 5332 | if not show: |
|
5332 | 5333 | show = ui.quiet and states[:4] or states[:5] |
|
5333 | 5334 | |
|
5334 | 5335 | stat = repo.status(node1, node2, scmutil.match(repo[node2], pats, opts), |
|
5335 | 5336 | 'ignored' in show, 'clean' in show, 'unknown' in show, |
|
5336 | 5337 | opts.get('subrepos')) |
|
5337 | 5338 | changestates = zip(states, 'MAR!?IC', stat) |
|
5338 | 5339 | |
|
5339 | 5340 | if (opts.get('all') or opts.get('copies')) and not opts.get('no_status'): |
|
5340 | 5341 | copy = copies.pathcopies(repo[node1], repo[node2]) |
|
5341 | 5342 | |
|
5342 | 5343 | fm = ui.formatter('status', opts) |
|
5343 | 5344 | format = '%s %s' + end |
|
5344 | 5345 | if opts.get('no_status'): |
|
5345 | 5346 | format = '%.0s%s' + end |
|
5346 | 5347 | |
|
5347 | 5348 | for state, char, files in changestates: |
|
5348 | 5349 | if state in show: |
|
5349 | 5350 | label = 'status.' + state |
|
5350 | 5351 | for f in files: |
|
5351 | 5352 | fm.startitem() |
|
5352 | 5353 | fm.write("status path", format, char, |
|
5353 | 5354 | repo.pathto(f, cwd), label=label) |
|
5354 | 5355 | if f in copy: |
|
5355 | 5356 | fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd), |
|
5356 | 5357 | label='status.copied') |
|
5357 | 5358 | fm.end() |
|
5358 | 5359 | |
|
5359 | 5360 | @command('^summary|sum', |
|
5360 | 5361 | [('', 'remote', None, _('check for push and pull'))], '[--remote]') |
|
5361 | 5362 | def summary(ui, repo, **opts): |
|
5362 | 5363 | """summarize working directory state |
|
5363 | 5364 | |
|
5364 | 5365 | This generates a brief summary of the working directory state, |
|
5365 | 5366 | including parents, branch, commit status, and available updates. |
|
5366 | 5367 | |
|
5367 | 5368 | With the --remote option, this will check the default paths for |
|
5368 | 5369 | incoming and outgoing changes. This can be time-consuming. |
|
5369 | 5370 | |
|
5370 | 5371 | Returns 0 on success. |
|
5371 | 5372 | """ |
|
5372 | 5373 | |
|
5373 | 5374 | ctx = repo[None] |
|
5374 | 5375 | parents = ctx.parents() |
|
5375 | 5376 | pnode = parents[0].node() |
|
5376 | 5377 | marks = [] |
|
5377 | 5378 | |
|
5378 | 5379 | for p in parents: |
|
5379 | 5380 | # label with log.changeset (instead of log.parent) since this |
|
5380 | 5381 | # shows a working directory parent *changeset*: |
|
5381 | 5382 | ui.write(_('parent: %d:%s ') % (p.rev(), str(p)), |
|
5382 | 5383 | label='log.changeset') |
|
5383 | 5384 | ui.write(' '.join(p.tags()), label='log.tag') |
|
5384 | 5385 | if p.bookmarks(): |
|
5385 | 5386 | marks.extend(p.bookmarks()) |
|
5386 | 5387 | if p.rev() == -1: |
|
5387 | 5388 | if not len(repo): |
|
5388 | 5389 | ui.write(_(' (empty repository)')) |
|
5389 | 5390 | else: |
|
5390 | 5391 | ui.write(_(' (no revision checked out)')) |
|
5391 | 5392 | ui.write('\n') |
|
5392 | 5393 | if p.description(): |
|
5393 | 5394 | ui.status(' ' + p.description().splitlines()[0].strip() + '\n', |
|
5394 | 5395 | label='log.summary') |
|
5395 | 5396 | |
|
5396 | 5397 | branch = ctx.branch() |
|
5397 | 5398 | bheads = repo.branchheads(branch) |
|
5398 | 5399 | m = _('branch: %s\n') % branch |
|
5399 | 5400 | if branch != 'default': |
|
5400 | 5401 | ui.write(m, label='log.branch') |
|
5401 | 5402 | else: |
|
5402 | 5403 | ui.status(m, label='log.branch') |
|
5403 | 5404 | |
|
5404 | 5405 | if marks: |
|
5405 | 5406 | current = repo._bookmarkcurrent |
|
5406 | 5407 | ui.write(_('bookmarks:'), label='log.bookmark') |
|
5407 | 5408 | if current is not None: |
|
5408 | 5409 | try: |
|
5409 | 5410 | marks.remove(current) |
|
5410 | 5411 | ui.write(' *' + current, label='bookmarks.current') |
|
5411 | 5412 | except ValueError: |
|
5412 | 5413 | # current bookmark not in parent ctx marks |
|
5413 | 5414 | pass |
|
5414 | 5415 | for m in marks: |
|
5415 | 5416 | ui.write(' ' + m, label='log.bookmark') |
|
5416 | 5417 | ui.write('\n', label='log.bookmark') |
|
5417 | 5418 | |
|
5418 | 5419 | st = list(repo.status(unknown=True))[:6] |
|
5419 | 5420 | |
|
5420 | 5421 | c = repo.dirstate.copies() |
|
5421 | 5422 | copied, renamed = [], [] |
|
5422 | 5423 | for d, s in c.iteritems(): |
|
5423 | 5424 | if s in st[2]: |
|
5424 | 5425 | st[2].remove(s) |
|
5425 | 5426 | renamed.append(d) |
|
5426 | 5427 | else: |
|
5427 | 5428 | copied.append(d) |
|
5428 | 5429 | if d in st[1]: |
|
5429 | 5430 | st[1].remove(d) |
|
5430 | 5431 | st.insert(3, renamed) |
|
5431 | 5432 | st.insert(4, copied) |
|
5432 | 5433 | |
|
5433 | 5434 | ms = mergemod.mergestate(repo) |
|
5434 | 5435 | st.append([f for f in ms if ms[f] == 'u']) |
|
5435 | 5436 | |
|
5436 | 5437 | subs = [s for s in ctx.substate if ctx.sub(s).dirty()] |
|
5437 | 5438 | st.append(subs) |
|
5438 | 5439 | |
|
5439 | 5440 | labels = [ui.label(_('%d modified'), 'status.modified'), |
|
5440 | 5441 | ui.label(_('%d added'), 'status.added'), |
|
5441 | 5442 | ui.label(_('%d removed'), 'status.removed'), |
|
5442 | 5443 | ui.label(_('%d renamed'), 'status.copied'), |
|
5443 | 5444 | ui.label(_('%d copied'), 'status.copied'), |
|
5444 | 5445 | ui.label(_('%d deleted'), 'status.deleted'), |
|
5445 | 5446 | ui.label(_('%d unknown'), 'status.unknown'), |
|
5446 | 5447 | ui.label(_('%d ignored'), 'status.ignored'), |
|
5447 | 5448 | ui.label(_('%d unresolved'), 'resolve.unresolved'), |
|
5448 | 5449 | ui.label(_('%d subrepos'), 'status.modified')] |
|
5449 | 5450 | t = [] |
|
5450 | 5451 | for s, l in zip(st, labels): |
|
5451 | 5452 | if s: |
|
5452 | 5453 | t.append(l % len(s)) |
|
5453 | 5454 | |
|
5454 | 5455 | t = ', '.join(t) |
|
5455 | 5456 | cleanworkdir = False |
|
5456 | 5457 | |
|
5457 | 5458 | if len(parents) > 1: |
|
5458 | 5459 | t += _(' (merge)') |
|
5459 | 5460 | elif branch != parents[0].branch(): |
|
5460 | 5461 | t += _(' (new branch)') |
|
5461 | 5462 | elif (parents[0].closesbranch() and |
|
5462 | 5463 | pnode in repo.branchheads(branch, closed=True)): |
|
5463 | 5464 | t += _(' (head closed)') |
|
5464 | 5465 | elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]): |
|
5465 | 5466 | t += _(' (clean)') |
|
5466 | 5467 | cleanworkdir = True |
|
5467 | 5468 | elif pnode not in bheads: |
|
5468 | 5469 | t += _(' (new branch head)') |
|
5469 | 5470 | |
|
5470 | 5471 | if cleanworkdir: |
|
5471 | 5472 | ui.status(_('commit: %s\n') % t.strip()) |
|
5472 | 5473 | else: |
|
5473 | 5474 | ui.write(_('commit: %s\n') % t.strip()) |
|
5474 | 5475 | |
|
5475 | 5476 | # all ancestors of branch heads - all ancestors of parent = new csets |
|
5476 | 5477 | new = [0] * len(repo) |
|
5477 | 5478 | cl = repo.changelog |
|
5478 | 5479 | for a in [cl.rev(n) for n in bheads]: |
|
5479 | 5480 | new[a] = 1 |
|
5480 | 5481 | for a in cl.ancestors([cl.rev(n) for n in bheads]): |
|
5481 | 5482 | new[a] = 1 |
|
5482 | 5483 | for a in [p.rev() for p in parents]: |
|
5483 | 5484 | if a >= 0: |
|
5484 | 5485 | new[a] = 0 |
|
5485 | 5486 | for a in cl.ancestors([p.rev() for p in parents]): |
|
5486 | 5487 | new[a] = 0 |
|
5487 | 5488 | new = sum(new) |
|
5488 | 5489 | |
|
5489 | 5490 | if new == 0: |
|
5490 | 5491 | ui.status(_('update: (current)\n')) |
|
5491 | 5492 | elif pnode not in bheads: |
|
5492 | 5493 | ui.write(_('update: %d new changesets (update)\n') % new) |
|
5493 | 5494 | else: |
|
5494 | 5495 | ui.write(_('update: %d new changesets, %d branch heads (merge)\n') % |
|
5495 | 5496 | (new, len(bheads))) |
|
5496 | 5497 | |
|
5497 | 5498 | if opts.get('remote'): |
|
5498 | 5499 | t = [] |
|
5499 | 5500 | source, branches = hg.parseurl(ui.expandpath('default')) |
|
5500 | 5501 | other = hg.peer(repo, {}, source) |
|
5501 | 5502 | revs, checkout = hg.addbranchrevs(repo, other, branches, |
|
5502 | 5503 | opts.get('rev')) |
|
5503 | 5504 | ui.debug('comparing with %s\n' % util.hidepassword(source)) |
|
5504 | 5505 | repo.ui.pushbuffer() |
|
5505 | 5506 | commoninc = discovery.findcommonincoming(repo, other) |
|
5506 | 5507 | _common, incoming, _rheads = commoninc |
|
5507 | 5508 | repo.ui.popbuffer() |
|
5508 | 5509 | if incoming: |
|
5509 | 5510 | t.append(_('1 or more incoming')) |
|
5510 | 5511 | |
|
5511 | 5512 | dest, branches = hg.parseurl(ui.expandpath('default-push', 'default')) |
|
5512 | 5513 | revs, checkout = hg.addbranchrevs(repo, repo, branches, None) |
|
5513 | 5514 | if source != dest: |
|
5514 | 5515 | other = hg.peer(repo, {}, dest) |
|
5515 | 5516 | commoninc = None |
|
5516 | 5517 | ui.debug('comparing with %s\n' % util.hidepassword(dest)) |
|
5517 | 5518 | repo.ui.pushbuffer() |
|
5518 | 5519 | outgoing = discovery.findcommonoutgoing(repo, other, |
|
5519 | 5520 | commoninc=commoninc) |
|
5520 | 5521 | repo.ui.popbuffer() |
|
5521 | 5522 | o = outgoing.missing |
|
5522 | 5523 | if o: |
|
5523 | 5524 | t.append(_('%d outgoing') % len(o)) |
|
5524 | 5525 | if 'bookmarks' in other.listkeys('namespaces'): |
|
5525 | 5526 | lmarks = repo.listkeys('bookmarks') |
|
5526 | 5527 | rmarks = other.listkeys('bookmarks') |
|
5527 | 5528 | diff = set(rmarks) - set(lmarks) |
|
5528 | 5529 | if len(diff) > 0: |
|
5529 | 5530 | t.append(_('%d incoming bookmarks') % len(diff)) |
|
5530 | 5531 | diff = set(lmarks) - set(rmarks) |
|
5531 | 5532 | if len(diff) > 0: |
|
5532 | 5533 | t.append(_('%d outgoing bookmarks') % len(diff)) |
|
5533 | 5534 | |
|
5534 | 5535 | if t: |
|
5535 | 5536 | ui.write(_('remote: %s\n') % (', '.join(t))) |
|
5536 | 5537 | else: |
|
5537 | 5538 | ui.status(_('remote: (synced)\n')) |
|
5538 | 5539 | |
|
5539 | 5540 | @command('tag', |
|
5540 | 5541 | [('f', 'force', None, _('force tag')), |
|
5541 | 5542 | ('l', 'local', None, _('make the tag local')), |
|
5542 | 5543 | ('r', 'rev', '', _('revision to tag'), _('REV')), |
|
5543 | 5544 | ('', 'remove', None, _('remove a tag')), |
|
5544 | 5545 | # -l/--local is already there, commitopts cannot be used |
|
5545 | 5546 | ('e', 'edit', None, _('edit commit message')), |
|
5546 | 5547 | ('m', 'message', '', _('use <text> as commit message'), _('TEXT')), |
|
5547 | 5548 | ] + commitopts2, |
|
5548 | 5549 | _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...')) |
|
5549 | 5550 | def tag(ui, repo, name1, *names, **opts): |
|
5550 | 5551 | """add one or more tags for the current or given revision |
|
5551 | 5552 | |
|
5552 | 5553 | Name a particular revision using <name>. |
|
5553 | 5554 | |
|
5554 | 5555 | Tags are used to name particular revisions of the repository and are |
|
5555 | 5556 | very useful to compare different revisions, to go back to significant |
|
5556 | 5557 | earlier versions or to mark branch points as releases, etc. Changing |
|
5557 | 5558 | an existing tag is normally disallowed; use -f/--force to override. |
|
5558 | 5559 | |
|
5559 | 5560 | If no revision is given, the parent of the working directory is |
|
5560 | 5561 | used, or tip if no revision is checked out. |
|
5561 | 5562 | |
|
5562 | 5563 | To facilitate version control, distribution, and merging of tags, |
|
5563 | 5564 | they are stored as a file named ".hgtags" which is managed similarly |
|
5564 | 5565 | to other project files and can be hand-edited if necessary. This |
|
5565 | 5566 | also means that tagging creates a new commit. The file |
|
5566 | 5567 | ".hg/localtags" is used for local tags (not shared among |
|
5567 | 5568 | repositories). |
|
5568 | 5569 | |
|
5569 | 5570 | Tag commits are usually made at the head of a branch. If the parent |
|
5570 | 5571 | of the working directory is not a branch head, :hg:`tag` aborts; use |
|
5571 | 5572 | -f/--force to force the tag commit to be based on a non-head |
|
5572 | 5573 | changeset. |
|
5573 | 5574 | |
|
5574 | 5575 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5575 | 5576 | |
|
5576 | 5577 | Since tag names have priority over branch names during revision |
|
5577 | 5578 | lookup, using an existing branch name as a tag name is discouraged. |
|
5578 | 5579 | |
|
5579 | 5580 | Returns 0 on success. |
|
5580 | 5581 | """ |
|
5581 | 5582 | wlock = lock = None |
|
5582 | 5583 | try: |
|
5583 | 5584 | wlock = repo.wlock() |
|
5584 | 5585 | lock = repo.lock() |
|
5585 | 5586 | rev_ = "." |
|
5586 | 5587 | names = [t.strip() for t in (name1,) + names] |
|
5587 | 5588 | if len(names) != len(set(names)): |
|
5588 | 5589 | raise util.Abort(_('tag names must be unique')) |
|
5589 | 5590 | for n in names: |
|
5590 | 5591 | if n in ['tip', '.', 'null']: |
|
5591 | 5592 | raise util.Abort(_("the name '%s' is reserved") % n) |
|
5592 | 5593 | if not n: |
|
5593 | 5594 | raise util.Abort(_('tag names cannot consist entirely of ' |
|
5594 | 5595 | 'whitespace')) |
|
5595 | 5596 | if opts.get('rev') and opts.get('remove'): |
|
5596 | 5597 | raise util.Abort(_("--rev and --remove are incompatible")) |
|
5597 | 5598 | if opts.get('rev'): |
|
5598 | 5599 | rev_ = opts['rev'] |
|
5599 | 5600 | message = opts.get('message') |
|
5600 | 5601 | if opts.get('remove'): |
|
5601 | 5602 | expectedtype = opts.get('local') and 'local' or 'global' |
|
5602 | 5603 | for n in names: |
|
5603 | 5604 | if not repo.tagtype(n): |
|
5604 | 5605 | raise util.Abort(_("tag '%s' does not exist") % n) |
|
5605 | 5606 | if repo.tagtype(n) != expectedtype: |
|
5606 | 5607 | if expectedtype == 'global': |
|
5607 | 5608 | raise util.Abort(_("tag '%s' is not a global tag") % n) |
|
5608 | 5609 | else: |
|
5609 | 5610 | raise util.Abort(_("tag '%s' is not a local tag") % n) |
|
5610 | 5611 | rev_ = nullid |
|
5611 | 5612 | if not message: |
|
5612 | 5613 | # we don't translate commit messages |
|
5613 | 5614 | message = 'Removed tag %s' % ', '.join(names) |
|
5614 | 5615 | elif not opts.get('force'): |
|
5615 | 5616 | for n in names: |
|
5616 | 5617 | if n in repo.tags(): |
|
5617 | 5618 | raise util.Abort(_("tag '%s' already exists " |
|
5618 | 5619 | "(use -f to force)") % n) |
|
5619 | 5620 | if not opts.get('local'): |
|
5620 | 5621 | p1, p2 = repo.dirstate.parents() |
|
5621 | 5622 | if p2 != nullid: |
|
5622 | 5623 | raise util.Abort(_('uncommitted merge')) |
|
5623 | 5624 | bheads = repo.branchheads() |
|
5624 | 5625 | if not opts.get('force') and bheads and p1 not in bheads: |
|
5625 | 5626 | raise util.Abort(_('not at a branch head (use -f to force)')) |
|
5626 | 5627 | r = scmutil.revsingle(repo, rev_).node() |
|
5627 | 5628 | |
|
5628 | 5629 | if not message: |
|
5629 | 5630 | # we don't translate commit messages |
|
5630 | 5631 | message = ('Added tag %s for changeset %s' % |
|
5631 | 5632 | (', '.join(names), short(r))) |
|
5632 | 5633 | |
|
5633 | 5634 | date = opts.get('date') |
|
5634 | 5635 | if date: |
|
5635 | 5636 | date = util.parsedate(date) |
|
5636 | 5637 | |
|
5637 | 5638 | if opts.get('edit'): |
|
5638 | 5639 | message = ui.edit(message, ui.username()) |
|
5639 | 5640 | |
|
5640 | 5641 | repo.tag(names, r, message, opts.get('local'), opts.get('user'), date) |
|
5641 | 5642 | finally: |
|
5642 | 5643 | release(lock, wlock) |
|
5643 | 5644 | |
|
5644 | 5645 | @command('tags', [], '') |
|
5645 | 5646 | def tags(ui, repo): |
|
5646 | 5647 | """list repository tags |
|
5647 | 5648 | |
|
5648 | 5649 | This lists both regular and local tags. When the -v/--verbose |
|
5649 | 5650 | switch is used, a third column "local" is printed for local tags. |
|
5650 | 5651 | |
|
5651 | 5652 | Returns 0 on success. |
|
5652 | 5653 | """ |
|
5653 | 5654 | |
|
5654 | 5655 | hexfunc = ui.debugflag and hex or short |
|
5655 | 5656 | tagtype = "" |
|
5656 | 5657 | |
|
5657 | 5658 | for t, n in reversed(repo.tagslist()): |
|
5658 | 5659 | if ui.quiet: |
|
5659 | 5660 | ui.write("%s\n" % t, label='tags.normal') |
|
5660 | 5661 | continue |
|
5661 | 5662 | |
|
5662 | 5663 | hn = hexfunc(n) |
|
5663 | 5664 | r = "%5d:%s" % (repo.changelog.rev(n), hn) |
|
5664 | 5665 | rev = ui.label(r, 'log.changeset') |
|
5665 | 5666 | spaces = " " * (30 - encoding.colwidth(t)) |
|
5666 | 5667 | |
|
5667 | 5668 | tag = ui.label(t, 'tags.normal') |
|
5668 | 5669 | if ui.verbose: |
|
5669 | 5670 | if repo.tagtype(t) == 'local': |
|
5670 | 5671 | tagtype = " local" |
|
5671 | 5672 | tag = ui.label(t, 'tags.local') |
|
5672 | 5673 | else: |
|
5673 | 5674 | tagtype = "" |
|
5674 | 5675 | ui.write("%s%s %s%s\n" % (tag, spaces, rev, tagtype)) |
|
5675 | 5676 | |
|
5676 | 5677 | @command('tip', |
|
5677 | 5678 | [('p', 'patch', None, _('show patch')), |
|
5678 | 5679 | ('g', 'git', None, _('use git extended diff format')), |
|
5679 | 5680 | ] + templateopts, |
|
5680 | 5681 | _('[-p] [-g]')) |
|
5681 | 5682 | def tip(ui, repo, **opts): |
|
5682 | 5683 | """show the tip revision |
|
5683 | 5684 | |
|
5684 | 5685 | The tip revision (usually just called the tip) is the changeset |
|
5685 | 5686 | most recently added to the repository (and therefore the most |
|
5686 | 5687 | recently changed head). |
|
5687 | 5688 | |
|
5688 | 5689 | If you have just made a commit, that commit will be the tip. If |
|
5689 | 5690 | you have just pulled changes from another repository, the tip of |
|
5690 | 5691 | that repository becomes the current tip. The "tip" tag is special |
|
5691 | 5692 | and cannot be renamed or assigned to a different changeset. |
|
5692 | 5693 | |
|
5693 | 5694 | Returns 0 on success. |
|
5694 | 5695 | """ |
|
5695 | 5696 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
5696 | 5697 | displayer.show(repo[len(repo) - 1]) |
|
5697 | 5698 | displayer.close() |
|
5698 | 5699 | |
|
5699 | 5700 | @command('unbundle', |
|
5700 | 5701 | [('u', 'update', None, |
|
5701 | 5702 | _('update to new branch head if changesets were unbundled'))], |
|
5702 | 5703 | _('[-u] FILE...')) |
|
5703 | 5704 | def unbundle(ui, repo, fname1, *fnames, **opts): |
|
5704 | 5705 | """apply one or more changegroup files |
|
5705 | 5706 | |
|
5706 | 5707 | Apply one or more compressed changegroup files generated by the |
|
5707 | 5708 | bundle command. |
|
5708 | 5709 | |
|
5709 | 5710 | Returns 0 on success, 1 if an update has unresolved files. |
|
5710 | 5711 | """ |
|
5711 | 5712 | fnames = (fname1,) + fnames |
|
5712 | 5713 | |
|
5713 | 5714 | lock = repo.lock() |
|
5714 | 5715 | wc = repo['.'] |
|
5715 | 5716 | try: |
|
5716 | 5717 | for fname in fnames: |
|
5717 | 5718 | f = url.open(ui, fname) |
|
5718 | 5719 | gen = changegroup.readbundle(f, fname) |
|
5719 | 5720 | modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) |
|
5720 | 5721 | finally: |
|
5721 | 5722 | lock.release() |
|
5722 | 5723 | bookmarks.updatecurrentbookmark(repo, wc.node(), wc.branch()) |
|
5723 | 5724 | return postincoming(ui, repo, modheads, opts.get('update'), None) |
|
5724 | 5725 | |
|
5725 | 5726 | @command('^update|up|checkout|co', |
|
5726 | 5727 | [('C', 'clean', None, _('discard uncommitted changes (no backup)')), |
|
5727 | 5728 | ('c', 'check', None, |
|
5728 | 5729 | _('update across branches if no uncommitted changes')), |
|
5729 | 5730 | ('d', 'date', '', _('tipmost revision matching date'), _('DATE')), |
|
5730 | 5731 | ('r', 'rev', '', _('revision'), _('REV'))], |
|
5731 | 5732 | _('[-c] [-C] [-d DATE] [[-r] REV]')) |
|
5732 | 5733 | def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False): |
|
5733 | 5734 | """update working directory (or switch revisions) |
|
5734 | 5735 | |
|
5735 | 5736 | Update the repository's working directory to the specified |
|
5736 | 5737 | changeset. If no changeset is specified, update to the tip of the |
|
5737 | 5738 | current named branch and move the current bookmark (see :hg:`help |
|
5738 | 5739 | bookmarks`). |
|
5739 | 5740 | |
|
5740 | 5741 | Update sets the working directory's parent revison to the specified |
|
5741 | 5742 | changeset (see :hg:`help parents`). |
|
5742 | 5743 | |
|
5743 | 5744 | If the changeset is not a descendant or ancestor of the working |
|
5744 | 5745 | directory's parent, the update is aborted. With the -c/--check |
|
5745 | 5746 | option, the working directory is checked for uncommitted changes; if |
|
5746 | 5747 | none are found, the working directory is updated to the specified |
|
5747 | 5748 | changeset. |
|
5748 | 5749 | |
|
5749 | 5750 | The following rules apply when the working directory contains |
|
5750 | 5751 | uncommitted changes: |
|
5751 | 5752 | |
|
5752 | 5753 | 1. If neither -c/--check nor -C/--clean is specified, and if |
|
5753 | 5754 | the requested changeset is an ancestor or descendant of |
|
5754 | 5755 | the working directory's parent, the uncommitted changes |
|
5755 | 5756 | are merged into the requested changeset and the merged |
|
5756 | 5757 | result is left uncommitted. If the requested changeset is |
|
5757 | 5758 | not an ancestor or descendant (that is, it is on another |
|
5758 | 5759 | branch), the update is aborted and the uncommitted changes |
|
5759 | 5760 | are preserved. |
|
5760 | 5761 | |
|
5761 | 5762 | 2. With the -c/--check option, the update is aborted and the |
|
5762 | 5763 | uncommitted changes are preserved. |
|
5763 | 5764 | |
|
5764 | 5765 | 3. With the -C/--clean option, uncommitted changes are discarded and |
|
5765 | 5766 | the working directory is updated to the requested changeset. |
|
5766 | 5767 | |
|
5767 | 5768 | To cancel an uncommitted merge (and lose your changes), use |
|
5768 | 5769 | :hg:`update --clean .`. |
|
5769 | 5770 | |
|
5770 | 5771 | Use null as the changeset to remove the working directory (like |
|
5771 | 5772 | :hg:`clone -U`). |
|
5772 | 5773 | |
|
5773 | 5774 | If you want to revert just one file to an older revision, use |
|
5774 | 5775 | :hg:`revert [-r REV] NAME`. |
|
5775 | 5776 | |
|
5776 | 5777 | See :hg:`help dates` for a list of formats valid for -d/--date. |
|
5777 | 5778 | |
|
5778 | 5779 | Returns 0 on success, 1 if there are unresolved files. |
|
5779 | 5780 | """ |
|
5780 | 5781 | if rev and node: |
|
5781 | 5782 | raise util.Abort(_("please specify just one revision")) |
|
5782 | 5783 | |
|
5783 | 5784 | if rev is None or rev == '': |
|
5784 | 5785 | rev = node |
|
5785 | 5786 | |
|
5786 | 5787 | # with no argument, we also move the current bookmark, if any |
|
5787 | 5788 | movemarkfrom = None |
|
5788 | 5789 | if rev is None or node == '': |
|
5789 | 5790 | movemarkfrom = repo['.'].node() |
|
5790 | 5791 | |
|
5791 | 5792 | # if we defined a bookmark, we have to remember the original bookmark name |
|
5792 | 5793 | brev = rev |
|
5793 | 5794 | rev = scmutil.revsingle(repo, rev, rev).rev() |
|
5794 | 5795 | |
|
5795 | 5796 | if check and clean: |
|
5796 | 5797 | raise util.Abort(_("cannot specify both -c/--check and -C/--clean")) |
|
5797 | 5798 | |
|
5798 | 5799 | if date: |
|
5799 | 5800 | if rev is not None: |
|
5800 | 5801 | raise util.Abort(_("you can't specify a revision and a date")) |
|
5801 | 5802 | rev = cmdutil.finddate(ui, repo, date) |
|
5802 | 5803 | |
|
5803 | 5804 | if check: |
|
5804 | 5805 | c = repo[None] |
|
5805 | 5806 | if c.dirty(merge=False, branch=False): |
|
5806 | 5807 | raise util.Abort(_("uncommitted local changes")) |
|
5807 | 5808 | if rev is None: |
|
5808 | 5809 | rev = repo[repo[None].branch()].rev() |
|
5809 | 5810 | mergemod._checkunknown(repo, repo[None], repo[rev]) |
|
5810 | 5811 | |
|
5811 | 5812 | if clean: |
|
5812 | 5813 | ret = hg.clean(repo, rev) |
|
5813 | 5814 | else: |
|
5814 | 5815 | ret = hg.update(repo, rev) |
|
5815 | 5816 | |
|
5816 | 5817 | if not ret and movemarkfrom: |
|
5817 | 5818 | if bookmarks.update(repo, [movemarkfrom], repo['.'].node()): |
|
5818 | 5819 | ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent) |
|
5819 | 5820 | elif brev in repo._bookmarks: |
|
5820 | 5821 | bookmarks.setcurrent(repo, brev) |
|
5821 | 5822 | elif brev: |
|
5822 | 5823 | bookmarks.unsetcurrent(repo) |
|
5823 | 5824 | |
|
5824 | 5825 | return ret |
|
5825 | 5826 | |
|
5826 | 5827 | @command('verify', []) |
|
5827 | 5828 | def verify(ui, repo): |
|
5828 | 5829 | """verify the integrity of the repository |
|
5829 | 5830 | |
|
5830 | 5831 | Verify the integrity of the current repository. |
|
5831 | 5832 | |
|
5832 | 5833 | This will perform an extensive check of the repository's |
|
5833 | 5834 | integrity, validating the hashes and checksums of each entry in |
|
5834 | 5835 | the changelog, manifest, and tracked files, as well as the |
|
5835 | 5836 | integrity of their crosslinks and indices. |
|
5836 | 5837 | |
|
5837 | 5838 | Returns 0 on success, 1 if errors are encountered. |
|
5838 | 5839 | """ |
|
5839 | 5840 | return hg.verify(repo) |
|
5840 | 5841 | |
|
5841 | 5842 | @command('version', []) |
|
5842 | 5843 | def version_(ui): |
|
5843 | 5844 | """output version and copyright information""" |
|
5844 | 5845 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
5845 | 5846 | % util.version()) |
|
5846 | 5847 | ui.status(_( |
|
5847 | 5848 | "(see http://mercurial.selenic.com for more information)\n" |
|
5848 | 5849 | "\nCopyright (C) 2005-2012 Matt Mackall and others\n" |
|
5849 | 5850 | "This is free software; see the source for copying conditions. " |
|
5850 | 5851 | "There is NO\nwarranty; " |
|
5851 | 5852 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
5852 | 5853 | )) |
|
5853 | 5854 | |
|
5854 | 5855 | norepo = ("clone init version help debugcommands debugcomplete" |
|
5855 | 5856 | " debugdate debuginstall debugfsinfo debugpushkey debugwireargs" |
|
5856 | 5857 | " debugknown debuggetbundle debugbundle") |
|
5857 | 5858 | optionalrepo = ("identify paths serve showconfig debugancestor debugdag" |
|
5858 | 5859 | " debugdata debugindex debugindexdot debugrevlog") |
@@ -1,266 +1,266 | |||
|
1 | 1 | # discovery.py - protocol changeset discovery functions |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from node import nullid, short |
|
9 | 9 | from i18n import _ |
|
10 | 10 | import util, setdiscovery, treediscovery, phases |
|
11 | 11 | |
|
12 | 12 | def findcommonincoming(repo, remote, heads=None, force=False): |
|
13 | 13 | """Return a tuple (common, anyincoming, heads) used to identify the common |
|
14 | 14 | subset of nodes between repo and remote. |
|
15 | 15 | |
|
16 | 16 | "common" is a list of (at least) the heads of the common subset. |
|
17 | 17 | "anyincoming" is testable as a boolean indicating if any nodes are missing |
|
18 | 18 | locally. If remote does not support getbundle, this actually is a list of |
|
19 | 19 | roots of the nodes that would be incoming, to be supplied to |
|
20 | 20 | changegroupsubset. No code except for pull should be relying on this fact |
|
21 | 21 | any longer. |
|
22 | 22 | "heads" is either the supplied heads, or else the remote's heads. |
|
23 | 23 | |
|
24 | 24 | If you pass heads and they are all known locally, the reponse lists justs |
|
25 | 25 | these heads in "common" and in "heads". |
|
26 | 26 | |
|
27 | 27 | Please use findcommonoutgoing to compute the set of outgoing nodes to give |
|
28 | 28 | extensions a good hook into outgoing. |
|
29 | 29 | """ |
|
30 | 30 | |
|
31 | 31 | if not remote.capable('getbundle'): |
|
32 | 32 | return treediscovery.findcommonincoming(repo, remote, heads, force) |
|
33 | 33 | |
|
34 | 34 | if heads: |
|
35 | 35 | allknown = True |
|
36 | 36 | nm = repo.changelog.nodemap |
|
37 | 37 | for h in heads: |
|
38 | 38 | if nm.get(h) is None: |
|
39 | 39 | allknown = False |
|
40 | 40 | break |
|
41 | 41 | if allknown: |
|
42 | 42 | return (heads, False, heads) |
|
43 | 43 | |
|
44 | 44 | res = setdiscovery.findcommonheads(repo.ui, repo, remote, |
|
45 | 45 | abortwhenunrelated=not force) |
|
46 | 46 | common, anyinc, srvheads = res |
|
47 | 47 | return (list(common), anyinc, heads or list(srvheads)) |
|
48 | 48 | |
|
49 | 49 | class outgoing(object): |
|
50 | 50 | '''Represents the set of nodes present in a local repo but not in a |
|
51 | 51 | (possibly) remote one. |
|
52 | 52 | |
|
53 | 53 | Members: |
|
54 | 54 | |
|
55 | 55 | missing is a list of all nodes present in local but not in remote. |
|
56 | 56 | common is a list of all nodes shared between the two repos. |
|
57 | 57 | excluded is the list of missing changeset that shouldn't be sent remotely. |
|
58 | 58 | missingheads is the list of heads of missing. |
|
59 | 59 | commonheads is the list of heads of common. |
|
60 | 60 | |
|
61 | 61 | The sets are computed on demand from the heads, unless provided upfront |
|
62 | 62 | by discovery.''' |
|
63 | 63 | |
|
64 | 64 | def __init__(self, revlog, commonheads, missingheads): |
|
65 | 65 | self.commonheads = commonheads |
|
66 | 66 | self.missingheads = missingheads |
|
67 | 67 | self._revlog = revlog |
|
68 | 68 | self._common = None |
|
69 | 69 | self._missing = None |
|
70 | 70 | self.excluded = [] |
|
71 | 71 | |
|
72 | 72 | def _computecommonmissing(self): |
|
73 | 73 | sets = self._revlog.findcommonmissing(self.commonheads, |
|
74 | 74 | self.missingheads) |
|
75 | 75 | self._common, self._missing = sets |
|
76 | 76 | |
|
77 | 77 | @util.propertycache |
|
78 | 78 | def common(self): |
|
79 | 79 | if self._common is None: |
|
80 | 80 | self._computecommonmissing() |
|
81 | 81 | return self._common |
|
82 | 82 | |
|
83 | 83 | @util.propertycache |
|
84 | 84 | def missing(self): |
|
85 | 85 | if self._missing is None: |
|
86 | 86 | self._computecommonmissing() |
|
87 | 87 | return self._missing |
|
88 | 88 | |
|
89 | 89 | def findcommonoutgoing(repo, other, onlyheads=None, force=False, |
|
90 | 90 | commoninc=None, portable=False): |
|
91 | 91 | '''Return an outgoing instance to identify the nodes present in repo but |
|
92 | 92 | not in other. |
|
93 | 93 | |
|
94 | 94 | If onlyheads is given, only nodes ancestral to nodes in onlyheads |
|
95 | 95 | (inclusive) are included. If you already know the local repo's heads, |
|
96 | 96 | passing them in onlyheads is faster than letting them be recomputed here. |
|
97 | 97 | |
|
98 | 98 | If commoninc is given, it must the the result of a prior call to |
|
99 | 99 | findcommonincoming(repo, other, force) to avoid recomputing it here. |
|
100 | 100 | |
|
101 | 101 | If portable is given, compute more conservative common and missingheads, |
|
102 | 102 | to make bundles created from the instance more portable.''' |
|
103 | 103 | # declare an empty outgoing object to be filled later |
|
104 | 104 | og = outgoing(repo.changelog, None, None) |
|
105 | 105 | |
|
106 | 106 | # get common set if not provided |
|
107 | 107 | if commoninc is None: |
|
108 | 108 | commoninc = findcommonincoming(repo, other, force=force) |
|
109 | 109 | og.commonheads, _any, _hds = commoninc |
|
110 | 110 | |
|
111 | 111 | # compute outgoing |
|
112 | 112 | if not repo._phasecache.phaseroots[phases.secret]: |
|
113 | 113 | og.missingheads = onlyheads or repo.heads() |
|
114 | 114 | elif onlyheads is None: |
|
115 | 115 | # use visible heads as it should be cached |
|
116 | 116 | og.missingheads = phases.visibleheads(repo) |
|
117 | 117 | og.excluded = [ctx.node() for ctx in repo.set('secret()')] |
|
118 | 118 | else: |
|
119 | 119 | # compute common, missing and exclude secret stuff |
|
120 | 120 | sets = repo.changelog.findcommonmissing(og.commonheads, onlyheads) |
|
121 | 121 | og._common, allmissing = sets |
|
122 | 122 | og._missing = missing = [] |
|
123 | 123 | og.excluded = excluded = [] |
|
124 | 124 | for node in allmissing: |
|
125 | 125 | if repo[node].phase() >= phases.secret: |
|
126 | 126 | excluded.append(node) |
|
127 | 127 | else: |
|
128 | 128 | missing.append(node) |
|
129 | 129 | if excluded: |
|
130 | 130 | # update missing heads |
|
131 | 131 | missingheads = phases.newheads(repo, onlyheads, excluded) |
|
132 | 132 | else: |
|
133 | 133 | missingheads = onlyheads |
|
134 | 134 | og.missingheads = missingheads |
|
135 | 135 | |
|
136 | 136 | if portable: |
|
137 | 137 | # recompute common and missingheads as if -r<rev> had been given for |
|
138 | 138 | # each head of missing, and --base <rev> for each head of the proper |
|
139 | 139 | # ancestors of missing |
|
140 | 140 | og._computecommonmissing() |
|
141 | 141 | cl = repo.changelog |
|
142 | 142 | missingrevs = set(cl.rev(n) for n in og._missing) |
|
143 | 143 | og._common = set(cl.ancestors(missingrevs)) - missingrevs |
|
144 | 144 | commonheads = set(og.commonheads) |
|
145 | 145 | og.missingheads = [h for h in og.missingheads if h not in commonheads] |
|
146 | 146 | |
|
147 | 147 | return og |
|
148 | 148 | |
|
149 | 149 | def checkheads(repo, remote, outgoing, remoteheads, newbranch=False, inc=False): |
|
150 | 150 | """Check that a push won't add any outgoing head |
|
151 | 151 | |
|
152 | 152 | raise Abort error and display ui message as needed. |
|
153 | 153 | """ |
|
154 | 154 | if remoteheads == [nullid]: |
|
155 | 155 | # remote is empty, nothing to check. |
|
156 | 156 | return |
|
157 | 157 | |
|
158 | 158 | cl = repo.changelog |
|
159 | 159 | if remote.capable('branchmap'): |
|
160 | 160 | # Check for each named branch if we're creating new remote heads. |
|
161 | 161 | # To be a remote head after push, node must be either: |
|
162 | 162 | # - unknown locally |
|
163 | 163 | # - a local outgoing head descended from update |
|
164 | 164 | # - a remote head that's known locally and not |
|
165 | 165 | # ancestral to an outgoing head |
|
166 | 166 | |
|
167 | 167 | # 1. Create set of branches involved in the push. |
|
168 | 168 | branches = set(repo[n].branch() for n in outgoing.missing) |
|
169 | 169 | |
|
170 | 170 | # 2. Check for new branches on the remote. |
|
171 | 171 | if remote.local(): |
|
172 | remotemap = phases.visiblebranchmap(remote) | |
|
172 | remotemap = phases.visiblebranchmap(remote.local()) | |
|
173 | 173 | else: |
|
174 | 174 | remotemap = remote.branchmap() |
|
175 | 175 | newbranches = branches - set(remotemap) |
|
176 | 176 | if newbranches and not newbranch: # new branch requires --new-branch |
|
177 | 177 | branchnames = ', '.join(sorted(newbranches)) |
|
178 | 178 | raise util.Abort(_("push creates new remote branches: %s!") |
|
179 | 179 | % branchnames, |
|
180 | 180 | hint=_("use 'hg push --new-branch' to create" |
|
181 | 181 | " new remote branches")) |
|
182 | 182 | branches.difference_update(newbranches) |
|
183 | 183 | |
|
184 | 184 | # 3. Construct the initial oldmap and newmap dicts. |
|
185 | 185 | # They contain information about the remote heads before and |
|
186 | 186 | # after the push, respectively. |
|
187 | 187 | # Heads not found locally are not included in either dict, |
|
188 | 188 | # since they won't be affected by the push. |
|
189 | 189 | # unsynced contains all branches with incoming changesets. |
|
190 | 190 | oldmap = {} |
|
191 | 191 | newmap = {} |
|
192 | 192 | unsynced = set() |
|
193 | 193 | for branch in branches: |
|
194 | 194 | remotebrheads = remotemap[branch] |
|
195 | 195 | prunedbrheads = [h for h in remotebrheads if h in cl.nodemap] |
|
196 | 196 | oldmap[branch] = prunedbrheads |
|
197 | 197 | newmap[branch] = list(prunedbrheads) |
|
198 | 198 | if len(remotebrheads) > len(prunedbrheads): |
|
199 | 199 | unsynced.add(branch) |
|
200 | 200 | |
|
201 | 201 | # 4. Update newmap with outgoing changes. |
|
202 | 202 | # This will possibly add new heads and remove existing ones. |
|
203 | 203 | ctxgen = (repo[n] for n in outgoing.missing) |
|
204 | 204 | repo._updatebranchcache(newmap, ctxgen) |
|
205 | 205 | |
|
206 | 206 | else: |
|
207 | 207 | # 1-4b. old servers: Check for new topological heads. |
|
208 | 208 | # Construct {old,new}map with branch = None (topological branch). |
|
209 | 209 | # (code based on _updatebranchcache) |
|
210 | 210 | oldheads = set(h for h in remoteheads if h in cl.nodemap) |
|
211 | 211 | # all nodes in outgoing.missing are children of either: |
|
212 | 212 | # - an element of oldheads |
|
213 | 213 | # - another element of outgoing.missing |
|
214 | 214 | # - nullrev |
|
215 | 215 | # This explains why the new head are very simple to compute. |
|
216 | 216 | r = repo.set('heads(%ln + %ln)', oldheads, outgoing.missing) |
|
217 | 217 | branches = set([None]) |
|
218 | 218 | newmap = {None: list(c.node() for c in r)} |
|
219 | 219 | oldmap = {None: oldheads} |
|
220 | 220 | unsynced = inc and branches or set() |
|
221 | 221 | |
|
222 | 222 | # 5. Check for new heads. |
|
223 | 223 | # If there are more heads after the push than before, a suitable |
|
224 | 224 | # error message, depending on unsynced status, is displayed. |
|
225 | 225 | error = None |
|
226 | 226 | localbookmarks = repo._bookmarks |
|
227 | 227 | |
|
228 | 228 | for branch in branches: |
|
229 | 229 | newhs = set(newmap[branch]) |
|
230 | 230 | oldhs = set(oldmap[branch]) |
|
231 | 231 | dhs = None |
|
232 | 232 | if len(newhs) > len(oldhs): |
|
233 | 233 | # strip updates to existing remote heads from the new heads list |
|
234 | 234 | remotebookmarks = remote.listkeys('bookmarks') |
|
235 | 235 | bookmarkedheads = set() |
|
236 | 236 | for bm in localbookmarks: |
|
237 | 237 | rnode = remotebookmarks.get(bm) |
|
238 | 238 | if rnode and rnode in repo: |
|
239 | 239 | lctx, rctx = repo[bm], repo[rnode] |
|
240 | 240 | if rctx == lctx.ancestor(rctx): |
|
241 | 241 | bookmarkedheads.add(lctx.node()) |
|
242 | 242 | dhs = list(newhs - bookmarkedheads - oldhs) |
|
243 | 243 | if dhs: |
|
244 | 244 | if error is None: |
|
245 | 245 | if branch not in ('default', None): |
|
246 | 246 | error = _("push creates new remote head %s " |
|
247 | 247 | "on branch '%s'!") % (short(dhs[0]), branch) |
|
248 | 248 | else: |
|
249 | 249 | error = _("push creates new remote head %s!" |
|
250 | 250 | ) % short(dhs[0]) |
|
251 | 251 | if branch in unsynced: |
|
252 | 252 | hint = _("you should pull and merge or " |
|
253 | 253 | "use push -f to force") |
|
254 | 254 | else: |
|
255 | 255 | hint = _("did you forget to merge? " |
|
256 | 256 | "use push -f to force") |
|
257 | 257 | if branch is not None: |
|
258 | 258 | repo.ui.note(_("new remote heads on branch '%s'\n") % branch) |
|
259 | 259 | for h in dhs: |
|
260 | 260 | repo.ui.note(_("new remote head %s\n") % short(h)) |
|
261 | 261 | if error: |
|
262 | 262 | raise util.Abort(error, hint=hint) |
|
263 | 263 | |
|
264 | 264 | # 6. Check for unsynced changes on involved branches. |
|
265 | 265 | if unsynced: |
|
266 | 266 | repo.ui.warn(_("note: unsynced remote changes!\n")) |
@@ -1,588 +1,597 | |||
|
1 | 1 | # hg.py - repository classes for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2 or any later version. |
|
8 | 8 | |
|
9 | 9 | from i18n import _ |
|
10 | 10 | from lock import release |
|
11 | 11 | from node import hex, nullid |
|
12 | 12 | import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo, bookmarks |
|
13 | 13 | import lock, util, extensions, error, node, scmutil |
|
14 | 14 | import cmdutil, discovery |
|
15 | 15 | import merge as mergemod |
|
16 | 16 | import verify as verifymod |
|
17 | 17 | import errno, os, shutil |
|
18 | 18 | |
|
19 | 19 | def _local(path): |
|
20 | 20 | path = util.expandpath(util.urllocalpath(path)) |
|
21 | 21 | return (os.path.isfile(path) and bundlerepo or localrepo) |
|
22 | 22 | |
|
23 |
def addbranchrevs(lrepo, r |
|
|
23 | def addbranchrevs(lrepo, other, branches, revs): | |
|
24 | peer = other.peer() # a courtesy to callers using a localrepo for other | |
|
24 | 25 | hashbranch, branches = branches |
|
25 | 26 | if not hashbranch and not branches: |
|
26 | 27 | return revs or None, revs and revs[0] or None |
|
27 | 28 | revs = revs and list(revs) or [] |
|
28 |
if not |
|
|
29 | if not peer.capable('branchmap'): | |
|
29 | 30 | if branches: |
|
30 | 31 | raise util.Abort(_("remote branch lookup not supported")) |
|
31 | 32 | revs.append(hashbranch) |
|
32 | 33 | return revs, revs[0] |
|
33 |
branchmap = |
|
|
34 | branchmap = peer.branchmap() | |
|
34 | 35 | |
|
35 | 36 | def primary(branch): |
|
36 | 37 | if branch == '.': |
|
37 |
if not lrepo |
|
|
38 | if not lrepo: | |
|
38 | 39 | raise util.Abort(_("dirstate branch not accessible")) |
|
39 | 40 | branch = lrepo.dirstate.branch() |
|
40 | 41 | if branch in branchmap: |
|
41 | 42 | revs.extend(node.hex(r) for r in reversed(branchmap[branch])) |
|
42 | 43 | return True |
|
43 | 44 | else: |
|
44 | 45 | return False |
|
45 | 46 | |
|
46 | 47 | for branch in branches: |
|
47 | 48 | if not primary(branch): |
|
48 | 49 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
|
49 | 50 | if hashbranch: |
|
50 | 51 | if not primary(hashbranch): |
|
51 | 52 | revs.append(hashbranch) |
|
52 | 53 | return revs, revs[0] |
|
53 | 54 | |
|
54 | 55 | def parseurl(path, branches=None): |
|
55 | 56 | '''parse url#branch, returning (url, (branch, branches))''' |
|
56 | 57 | |
|
57 | 58 | u = util.url(path) |
|
58 | 59 | branch = None |
|
59 | 60 | if u.fragment: |
|
60 | 61 | branch = u.fragment |
|
61 | 62 | u.fragment = None |
|
62 | 63 | return str(u), (branch, branches or []) |
|
63 | 64 | |
|
64 | 65 | schemes = { |
|
65 | 66 | 'bundle': bundlerepo, |
|
66 | 67 | 'file': _local, |
|
67 | 68 | 'http': httprepo, |
|
68 | 69 | 'https': httprepo, |
|
69 | 70 | 'ssh': sshrepo, |
|
70 | 71 | 'static-http': statichttprepo, |
|
71 | 72 | } |
|
72 | 73 | |
|
73 | 74 | def _peerlookup(path): |
|
74 | 75 | u = util.url(path) |
|
75 | 76 | scheme = u.scheme or 'file' |
|
76 | 77 | thing = schemes.get(scheme) or schemes['file'] |
|
77 | 78 | try: |
|
78 | 79 | return thing(path) |
|
79 | 80 | except TypeError: |
|
80 | 81 | return thing |
|
81 | 82 | |
|
82 | 83 | def islocal(repo): |
|
83 | 84 | '''return true if repo or path is local''' |
|
84 | 85 | if isinstance(repo, str): |
|
85 | 86 | try: |
|
86 | 87 | return _peerlookup(repo).islocal(repo) |
|
87 | 88 | except AttributeError: |
|
88 | 89 | return False |
|
89 | 90 | return repo.local() |
|
90 | 91 | |
|
91 |
def repo |
|
|
92 | def _peerorrepo(ui, path, create=False): | |
|
92 | 93 | """return a repository object for the specified path""" |
|
93 |
|
|
|
94 |
ui = getattr( |
|
|
94 | obj = _peerlookup(path).instance(ui, path, create) | |
|
95 | ui = getattr(obj, "ui", ui) | |
|
95 | 96 | for name, module in extensions.extensions(): |
|
96 | 97 | hook = getattr(module, 'reposetup', None) |
|
97 | 98 | if hook: |
|
98 |
hook(ui, |
|
|
99 | hook(ui, obj) | |
|
100 | return obj | |
|
101 | ||
|
102 | def repository(ui, path='', create=False): | |
|
103 | """return a repository object for the specified path""" | |
|
104 | peer = _peerorrepo(ui, path, create) | |
|
105 | repo = peer.local() | |
|
106 | if not repo: | |
|
107 | raise util.Abort(_("repository '%s' is not local") % | |
|
108 | (path or peer.url())) | |
|
99 | 109 | return repo |
|
100 | 110 | |
|
101 | 111 | def peer(uiorrepo, opts, path, create=False): |
|
102 | 112 | '''return a repository peer for the specified path''' |
|
103 | 113 | rui = remoteui(uiorrepo, opts) |
|
104 |
return repo |
|
|
114 | return _peerorrepo(rui, path, create).peer() | |
|
105 | 115 | |
|
106 | 116 | def defaultdest(source): |
|
107 | 117 | '''return default destination of clone if none is given''' |
|
108 | 118 | return os.path.basename(os.path.normpath(source)) |
|
109 | 119 | |
|
110 | 120 | def share(ui, source, dest=None, update=True): |
|
111 | 121 | '''create a shared repository''' |
|
112 | 122 | |
|
113 | 123 | if not islocal(source): |
|
114 | 124 | raise util.Abort(_('can only share local repositories')) |
|
115 | 125 | |
|
116 | 126 | if not dest: |
|
117 | 127 | dest = defaultdest(source) |
|
118 | 128 | else: |
|
119 | 129 | dest = ui.expandpath(dest) |
|
120 | 130 | |
|
121 | 131 | if isinstance(source, str): |
|
122 | 132 | origsource = ui.expandpath(source) |
|
123 | 133 | source, branches = parseurl(origsource) |
|
124 | 134 | srcrepo = repository(ui, source) |
|
125 | 135 | rev, checkout = addbranchrevs(srcrepo, srcrepo, branches, None) |
|
126 | 136 | else: |
|
127 | srcrepo = source | |
|
137 | srcrepo = source.local() | |
|
128 | 138 | origsource = source = srcrepo.url() |
|
129 | 139 | checkout = None |
|
130 | 140 | |
|
131 | 141 | sharedpath = srcrepo.sharedpath # if our source is already sharing |
|
132 | 142 | |
|
133 | 143 | root = os.path.realpath(dest) |
|
134 | 144 | roothg = os.path.join(root, '.hg') |
|
135 | 145 | |
|
136 | 146 | if os.path.exists(roothg): |
|
137 | 147 | raise util.Abort(_('destination already exists')) |
|
138 | 148 | |
|
139 | 149 | if not os.path.isdir(root): |
|
140 | 150 | os.mkdir(root) |
|
141 | 151 | util.makedir(roothg, notindexed=True) |
|
142 | 152 | |
|
143 | 153 | requirements = '' |
|
144 | 154 | try: |
|
145 | 155 | requirements = srcrepo.opener.read('requires') |
|
146 | 156 | except IOError, inst: |
|
147 | 157 | if inst.errno != errno.ENOENT: |
|
148 | 158 | raise |
|
149 | 159 | |
|
150 | 160 | requirements += 'shared\n' |
|
151 | 161 | util.writefile(os.path.join(roothg, 'requires'), requirements) |
|
152 | 162 | util.writefile(os.path.join(roothg, 'sharedpath'), sharedpath) |
|
153 | 163 | |
|
154 | 164 | r = repository(ui, root) |
|
155 | 165 | |
|
156 | 166 | default = srcrepo.ui.config('paths', 'default') |
|
157 | 167 | if default: |
|
158 | 168 | fp = r.opener("hgrc", "w", text=True) |
|
159 | 169 | fp.write("[paths]\n") |
|
160 | 170 | fp.write("default = %s\n" % default) |
|
161 | 171 | fp.close() |
|
162 | 172 | |
|
163 | 173 | if update: |
|
164 | 174 | r.ui.status(_("updating working directory\n")) |
|
165 | 175 | if update is not True: |
|
166 | 176 | checkout = update |
|
167 | 177 | for test in (checkout, 'default', 'tip'): |
|
168 | 178 | if test is None: |
|
169 | 179 | continue |
|
170 | 180 | try: |
|
171 | 181 | uprev = r.lookup(test) |
|
172 | 182 | break |
|
173 | 183 | except error.RepoLookupError: |
|
174 | 184 | continue |
|
175 | 185 | _update(r, uprev) |
|
176 | 186 | |
|
177 | 187 | def copystore(ui, srcrepo, destpath): |
|
178 | 188 | '''copy files from store of srcrepo in destpath |
|
179 | 189 | |
|
180 | 190 | returns destlock |
|
181 | 191 | ''' |
|
182 | 192 | destlock = None |
|
183 | 193 | try: |
|
184 | 194 | hardlink = None |
|
185 | 195 | num = 0 |
|
186 | 196 | srcpublishing = srcrepo.ui.configbool('phases', 'publish', True) |
|
187 | 197 | for f in srcrepo.store.copylist(): |
|
188 | 198 | if srcpublishing and f.endswith('phaseroots'): |
|
189 | 199 | continue |
|
190 | 200 | src = os.path.join(srcrepo.sharedpath, f) |
|
191 | 201 | dst = os.path.join(destpath, f) |
|
192 | 202 | dstbase = os.path.dirname(dst) |
|
193 | 203 | if dstbase and not os.path.exists(dstbase): |
|
194 | 204 | os.mkdir(dstbase) |
|
195 | 205 | if os.path.exists(src): |
|
196 | 206 | if dst.endswith('data'): |
|
197 | 207 | # lock to avoid premature writing to the target |
|
198 | 208 | destlock = lock.lock(os.path.join(dstbase, "lock")) |
|
199 | 209 | hardlink, n = util.copyfiles(src, dst, hardlink) |
|
200 | 210 | num += n |
|
201 | 211 | if hardlink: |
|
202 | 212 | ui.debug("linked %d files\n" % num) |
|
203 | 213 | else: |
|
204 | 214 | ui.debug("copied %d files\n" % num) |
|
205 | 215 | return destlock |
|
206 | 216 | except: # re-raises |
|
207 | 217 | release(destlock) |
|
208 | 218 | raise |
|
209 | 219 | |
|
210 | 220 | def clone(ui, peeropts, source, dest=None, pull=False, rev=None, |
|
211 | 221 | update=True, stream=False, branch=None): |
|
212 | 222 | """Make a copy of an existing repository. |
|
213 | 223 | |
|
214 | 224 | Create a copy of an existing repository in a new directory. The |
|
215 | 225 | source and destination are URLs, as passed to the repository |
|
216 |
function. Returns a pair of repository |
|
|
226 | function. Returns a pair of repository peers, the source and | |
|
217 | 227 | newly created destination. |
|
218 | 228 | |
|
219 | 229 | The location of the source is added to the new repository's |
|
220 | 230 | .hg/hgrc file, as the default to be used for future pulls and |
|
221 | 231 | pushes. |
|
222 | 232 | |
|
223 | 233 | If an exception is raised, the partly cloned/updated destination |
|
224 | 234 | repository will be deleted. |
|
225 | 235 | |
|
226 | 236 | Arguments: |
|
227 | 237 | |
|
228 | 238 | source: repository object or URL |
|
229 | 239 | |
|
230 | 240 | dest: URL of destination repository to create (defaults to base |
|
231 | 241 | name of source repository) |
|
232 | 242 | |
|
233 | 243 | pull: always pull from source repository, even in local case |
|
234 | 244 | |
|
235 | 245 | stream: stream raw data uncompressed from repository (fast over |
|
236 | 246 | LAN, slow over WAN) |
|
237 | 247 | |
|
238 | 248 | rev: revision to clone up to (implies pull=True) |
|
239 | 249 | |
|
240 | 250 | update: update working directory after clone completes, if |
|
241 | 251 | destination is local repository (True means update to default rev, |
|
242 | 252 | anything else is treated as a revision) |
|
243 | 253 | |
|
244 | 254 | branch: branches to clone |
|
245 | 255 | """ |
|
246 | 256 | |
|
247 | 257 | if isinstance(source, str): |
|
248 | 258 | origsource = ui.expandpath(source) |
|
249 | 259 | source, branch = parseurl(origsource, branch) |
|
250 |
src |
|
|
260 | srcpeer = peer(ui, peeropts, source) | |
|
251 | 261 | else: |
|
252 | srcrepo = source | |
|
262 | srcpeer = source.peer() # in case we were called with a localrepo | |
|
253 | 263 | branch = (None, branch or []) |
|
254 |
origsource = source = src |
|
|
255 |
rev, checkout = addbranchrevs(src |
|
|
264 | origsource = source = srcpeer.url() | |
|
265 | rev, checkout = addbranchrevs(srcpeer, srcpeer, branch, rev) | |
|
256 | 266 | |
|
257 | 267 | if dest is None: |
|
258 | 268 | dest = defaultdest(source) |
|
259 | 269 | ui.status(_("destination directory: %s\n") % dest) |
|
260 | 270 | else: |
|
261 | 271 | dest = ui.expandpath(dest) |
|
262 | 272 | |
|
263 | 273 | dest = util.urllocalpath(dest) |
|
264 | 274 | source = util.urllocalpath(source) |
|
265 | 275 | |
|
266 | 276 | if not dest: |
|
267 | 277 | raise util.Abort(_("empty destination path is not valid")) |
|
268 | 278 | if os.path.exists(dest): |
|
269 | 279 | if not os.path.isdir(dest): |
|
270 | 280 | raise util.Abort(_("destination '%s' already exists") % dest) |
|
271 | 281 | elif os.listdir(dest): |
|
272 | 282 | raise util.Abort(_("destination '%s' is not empty") % dest) |
|
273 | 283 | |
|
274 | 284 | class DirCleanup(object): |
|
275 | 285 | def __init__(self, dir_): |
|
276 | 286 | self.rmtree = shutil.rmtree |
|
277 | 287 | self.dir_ = dir_ |
|
278 | 288 | def close(self): |
|
279 | 289 | self.dir_ = None |
|
280 | 290 | def cleanup(self): |
|
281 | 291 | if self.dir_: |
|
282 | 292 | self.rmtree(self.dir_, True) |
|
283 | 293 | |
|
284 | 294 | srclock = destlock = dircleanup = None |
|
295 | srcrepo = srcpeer.local() | |
|
285 | 296 | try: |
|
286 | 297 | abspath = origsource |
|
287 | 298 | if islocal(origsource): |
|
288 | 299 | abspath = os.path.abspath(util.urllocalpath(origsource)) |
|
289 | 300 | |
|
290 | 301 | if islocal(dest): |
|
291 | 302 | dircleanup = DirCleanup(dest) |
|
292 | 303 | |
|
293 | 304 | copy = False |
|
294 |
if src |
|
|
305 | if srcpeer.cancopy() and islocal(dest) and not srcrepo.revs("secret()"): | |
|
295 | 306 | copy = not pull and not rev |
|
296 | 307 | |
|
297 | 308 | if copy: |
|
298 | 309 | try: |
|
299 | 310 | # we use a lock here because if we race with commit, we |
|
300 | 311 | # can end up with extra data in the cloned revlogs that's |
|
301 | 312 | # not pointed to by changesets, thus causing verify to |
|
302 | 313 | # fail |
|
303 | 314 | srclock = srcrepo.lock(wait=False) |
|
304 | 315 | except error.LockError: |
|
305 | 316 | copy = False |
|
306 | 317 | |
|
307 | 318 | if copy: |
|
308 | 319 | srcrepo.hook('preoutgoing', throw=True, source='clone') |
|
309 | 320 | hgdir = os.path.realpath(os.path.join(dest, ".hg")) |
|
310 | 321 | if not os.path.exists(dest): |
|
311 | 322 | os.mkdir(dest) |
|
312 | 323 | else: |
|
313 | 324 | # only clean up directories we create ourselves |
|
314 | 325 | dircleanup.dir_ = hgdir |
|
315 | 326 | try: |
|
316 | 327 | destpath = hgdir |
|
317 | 328 | util.makedir(destpath, notindexed=True) |
|
318 | 329 | except OSError, inst: |
|
319 | 330 | if inst.errno == errno.EEXIST: |
|
320 | 331 | dircleanup.close() |
|
321 | 332 | raise util.Abort(_("destination '%s' already exists") |
|
322 | 333 | % dest) |
|
323 | 334 | raise |
|
324 | 335 | |
|
325 | 336 | destlock = copystore(ui, srcrepo, destpath) |
|
326 | 337 | |
|
327 | 338 | # we need to re-init the repo after manually copying the data |
|
328 | 339 | # into it |
|
329 |
dest |
|
|
340 | destpeer = peer(ui, peeropts, dest) | |
|
330 | 341 | srcrepo.hook('outgoing', source='clone', |
|
331 | 342 | node=node.hex(node.nullid)) |
|
332 | 343 | else: |
|
333 | 344 | try: |
|
334 |
dest |
|
|
335 | create=True) | |
|
345 | destpeer = peer(ui, peeropts, dest, create=True) | |
|
336 | 346 | except OSError, inst: |
|
337 | 347 | if inst.errno == errno.EEXIST: |
|
338 | 348 | dircleanup.close() |
|
339 | 349 | raise util.Abort(_("destination '%s' already exists") |
|
340 | 350 | % dest) |
|
341 | 351 | raise |
|
342 | 352 | |
|
343 | 353 | revs = None |
|
344 | 354 | if rev: |
|
345 |
if not src |
|
|
355 | if not srcpeer.capable('lookup'): | |
|
346 | 356 | raise util.Abort(_("src repository does not support " |
|
347 | 357 | "revision lookup and so doesn't " |
|
348 | 358 | "support clone by revision")) |
|
349 |
revs = [src |
|
|
359 | revs = [srcpeer.lookup(r) for r in rev] | |
|
350 | 360 | checkout = revs[0] |
|
351 |
if dest |
|
|
352 |
dest |
|
|
353 |
elif srcrepo |
|
|
354 |
srcrepo.push(dest |
|
|
361 | if destpeer.local(): | |
|
362 | destpeer.local().clone(srcpeer, heads=revs, stream=stream) | |
|
363 | elif srcrepo: | |
|
364 | srcrepo.push(destpeer, revs=revs) | |
|
355 | 365 | else: |
|
356 | 366 | raise util.Abort(_("clone from remote to remote not supported")) |
|
357 | 367 | |
|
358 | 368 | if dircleanup: |
|
359 | 369 | dircleanup.close() |
|
360 | 370 | |
|
361 | 371 | # clone all bookmarks except divergent ones |
|
362 | if destrepo.local() and srcrepo.capable("pushkey"): | |
|
363 | rb = srcrepo.listkeys('bookmarks') | |
|
372 | destrepo = destpeer.local() | |
|
373 | if destrepo and srcpeer.capable("pushkey"): | |
|
374 | rb = srcpeer.listkeys('bookmarks') | |
|
364 | 375 | for k, n in rb.iteritems(): |
|
365 | 376 | try: |
|
366 | 377 | m = destrepo.lookup(n) |
|
367 | 378 | destrepo._bookmarks[k] = m |
|
368 | 379 | except error.RepoLookupError: |
|
369 | 380 | pass |
|
370 | 381 | if rb: |
|
371 | 382 | bookmarks.write(destrepo) |
|
372 |
elif srcrepo |
|
|
383 | elif srcrepo and destpeer.capable("pushkey"): | |
|
373 | 384 | for k, n in srcrepo._bookmarks.iteritems(): |
|
374 |
dest |
|
|
385 | destpeer.pushkey('bookmarks', k, '', hex(n)) | |
|
375 | 386 | |
|
376 |
if destrepo |
|
|
387 | if destrepo: | |
|
377 | 388 | fp = destrepo.opener("hgrc", "w", text=True) |
|
378 | 389 | fp.write("[paths]\n") |
|
379 | 390 | u = util.url(abspath) |
|
380 | 391 | u.passwd = None |
|
381 | 392 | defaulturl = str(u) |
|
382 | 393 | fp.write("default = %s\n" % defaulturl) |
|
383 | 394 | fp.close() |
|
384 | 395 | |
|
385 | 396 | destrepo.ui.setconfig('paths', 'default', defaulturl) |
|
386 | 397 | |
|
387 | 398 | if update: |
|
388 | 399 | if update is not True: |
|
389 | checkout = update | |
|
390 | if srcrepo.local(): | |
|
391 | 400 |
|
|
392 | 401 | for test in (checkout, 'default', 'tip'): |
|
393 | 402 | if test is None: |
|
394 | 403 | continue |
|
395 | 404 | try: |
|
396 | 405 | uprev = destrepo.lookup(test) |
|
397 | 406 | break |
|
398 | 407 | except error.RepoLookupError: |
|
399 | 408 | continue |
|
400 | 409 | bn = destrepo[uprev].branch() |
|
401 | 410 | destrepo.ui.status(_("updating to branch %s\n") % bn) |
|
402 | 411 | _update(destrepo, uprev) |
|
403 | 412 | |
|
404 |
return src |
|
|
413 | return srcpeer, destpeer | |
|
405 | 414 | finally: |
|
406 | 415 | release(srclock, destlock) |
|
407 | 416 | if dircleanup is not None: |
|
408 | 417 | dircleanup.cleanup() |
|
409 |
if src |
|
|
410 |
src |
|
|
418 | if srcpeer is not None: | |
|
419 | srcpeer.close() | |
|
411 | 420 | |
|
412 | 421 | def _showstats(repo, stats): |
|
413 | 422 | repo.ui.status(_("%d files updated, %d files merged, " |
|
414 | 423 | "%d files removed, %d files unresolved\n") % stats) |
|
415 | 424 | |
|
416 | 425 | def update(repo, node): |
|
417 | 426 | """update the working directory to node, merging linear changes""" |
|
418 | 427 | stats = mergemod.update(repo, node, False, False, None) |
|
419 | 428 | _showstats(repo, stats) |
|
420 | 429 | if stats[3]: |
|
421 | 430 | repo.ui.status(_("use 'hg resolve' to retry unresolved file merges\n")) |
|
422 | 431 | return stats[3] > 0 |
|
423 | 432 | |
|
424 | 433 | # naming conflict in clone() |
|
425 | 434 | _update = update |
|
426 | 435 | |
|
427 | 436 | def clean(repo, node, show_stats=True): |
|
428 | 437 | """forcibly switch the working directory to node, clobbering changes""" |
|
429 | 438 | stats = mergemod.update(repo, node, False, True, None) |
|
430 | 439 | if show_stats: |
|
431 | 440 | _showstats(repo, stats) |
|
432 | 441 | return stats[3] > 0 |
|
433 | 442 | |
|
434 | 443 | def merge(repo, node, force=None, remind=True): |
|
435 | 444 | """Branch merge with node, resolving changes. Return true if any |
|
436 | 445 | unresolved conflicts.""" |
|
437 | 446 | stats = mergemod.update(repo, node, True, force, False) |
|
438 | 447 | _showstats(repo, stats) |
|
439 | 448 | if stats[3]: |
|
440 | 449 | repo.ui.status(_("use 'hg resolve' to retry unresolved file merges " |
|
441 | 450 | "or 'hg update -C .' to abandon\n")) |
|
442 | 451 | elif remind: |
|
443 | 452 | repo.ui.status(_("(branch merge, don't forget to commit)\n")) |
|
444 | 453 | return stats[3] > 0 |
|
445 | 454 | |
|
446 | 455 | def _incoming(displaychlist, subreporecurse, ui, repo, source, |
|
447 | 456 | opts, buffered=False): |
|
448 | 457 | """ |
|
449 | 458 | Helper for incoming / gincoming. |
|
450 | 459 | displaychlist gets called with |
|
451 | 460 | (remoterepo, incomingchangesetlist, displayer) parameters, |
|
452 | 461 | and is supposed to contain only code that can't be unified. |
|
453 | 462 | """ |
|
454 | 463 | source, branches = parseurl(ui.expandpath(source), opts.get('branch')) |
|
455 | 464 | other = peer(repo, opts, source) |
|
456 | 465 | ui.status(_('comparing with %s\n') % util.hidepassword(source)) |
|
457 | 466 | revs, checkout = addbranchrevs(repo, other, branches, opts.get('rev')) |
|
458 | 467 | |
|
459 | 468 | if revs: |
|
460 | 469 | revs = [other.lookup(rev) for rev in revs] |
|
461 | 470 | other, chlist, cleanupfn = bundlerepo.getremotechanges(ui, repo, other, |
|
462 | 471 | revs, opts["bundle"], opts["force"]) |
|
463 | 472 | try: |
|
464 | 473 | if not chlist: |
|
465 | 474 | ui.status(_("no changes found\n")) |
|
466 | 475 | return subreporecurse() |
|
467 | 476 | |
|
468 | 477 | displayer = cmdutil.show_changeset(ui, other, opts, buffered) |
|
469 | 478 | |
|
470 | 479 | # XXX once graphlog extension makes it into core, |
|
471 | 480 | # should be replaced by a if graph/else |
|
472 | 481 | displaychlist(other, chlist, displayer) |
|
473 | 482 | |
|
474 | 483 | displayer.close() |
|
475 | 484 | finally: |
|
476 | 485 | cleanupfn() |
|
477 | 486 | subreporecurse() |
|
478 | 487 | return 0 # exit code is zero since we found incoming changes |
|
479 | 488 | |
|
480 | 489 | def incoming(ui, repo, source, opts): |
|
481 | 490 | def subreporecurse(): |
|
482 | 491 | ret = 1 |
|
483 | 492 | if opts.get('subrepos'): |
|
484 | 493 | ctx = repo[None] |
|
485 | 494 | for subpath in sorted(ctx.substate): |
|
486 | 495 | sub = ctx.sub(subpath) |
|
487 | 496 | ret = min(ret, sub.incoming(ui, source, opts)) |
|
488 | 497 | return ret |
|
489 | 498 | |
|
490 | 499 | def display(other, chlist, displayer): |
|
491 | 500 | limit = cmdutil.loglimit(opts) |
|
492 | 501 | if opts.get('newest_first'): |
|
493 | 502 | chlist.reverse() |
|
494 | 503 | count = 0 |
|
495 | 504 | for n in chlist: |
|
496 | 505 | if limit is not None and count >= limit: |
|
497 | 506 | break |
|
498 | 507 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
499 | 508 | if opts.get('no_merges') and len(parents) == 2: |
|
500 | 509 | continue |
|
501 | 510 | count += 1 |
|
502 | 511 | displayer.show(other[n]) |
|
503 | 512 | return _incoming(display, subreporecurse, ui, repo, source, opts) |
|
504 | 513 | |
|
505 | 514 | def _outgoing(ui, repo, dest, opts): |
|
506 | 515 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
507 | 516 | dest, branches = parseurl(dest, opts.get('branch')) |
|
508 | 517 | ui.status(_('comparing with %s\n') % util.hidepassword(dest)) |
|
509 | 518 | revs, checkout = addbranchrevs(repo, repo, branches, opts.get('rev')) |
|
510 | 519 | if revs: |
|
511 | 520 | revs = [repo.lookup(rev) for rev in revs] |
|
512 | 521 | |
|
513 | 522 | other = peer(repo, opts, dest) |
|
514 | 523 | outgoing = discovery.findcommonoutgoing(repo, other, revs, |
|
515 | 524 | force=opts.get('force')) |
|
516 | 525 | o = outgoing.missing |
|
517 | 526 | if not o: |
|
518 | 527 | scmutil.nochangesfound(repo.ui, outgoing.excluded) |
|
519 | 528 | return None |
|
520 | 529 | return o |
|
521 | 530 | |
|
522 | 531 | def outgoing(ui, repo, dest, opts): |
|
523 | 532 | def recurse(): |
|
524 | 533 | ret = 1 |
|
525 | 534 | if opts.get('subrepos'): |
|
526 | 535 | ctx = repo[None] |
|
527 | 536 | for subpath in sorted(ctx.substate): |
|
528 | 537 | sub = ctx.sub(subpath) |
|
529 | 538 | ret = min(ret, sub.outgoing(ui, dest, opts)) |
|
530 | 539 | return ret |
|
531 | 540 | |
|
532 | 541 | limit = cmdutil.loglimit(opts) |
|
533 | 542 | o = _outgoing(ui, repo, dest, opts) |
|
534 | 543 | if o is None: |
|
535 | 544 | return recurse() |
|
536 | 545 | |
|
537 | 546 | if opts.get('newest_first'): |
|
538 | 547 | o.reverse() |
|
539 | 548 | displayer = cmdutil.show_changeset(ui, repo, opts) |
|
540 | 549 | count = 0 |
|
541 | 550 | for n in o: |
|
542 | 551 | if limit is not None and count >= limit: |
|
543 | 552 | break |
|
544 | 553 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
545 | 554 | if opts.get('no_merges') and len(parents) == 2: |
|
546 | 555 | continue |
|
547 | 556 | count += 1 |
|
548 | 557 | displayer.show(repo[n]) |
|
549 | 558 | displayer.close() |
|
550 | 559 | recurse() |
|
551 | 560 | return 0 # exit code is zero since we found outgoing changes |
|
552 | 561 | |
|
553 | 562 | def revert(repo, node, choose): |
|
554 | 563 | """revert changes to revision in node without updating dirstate""" |
|
555 | 564 | return mergemod.update(repo, node, False, True, choose)[3] > 0 |
|
556 | 565 | |
|
557 | 566 | def verify(repo): |
|
558 | 567 | """verify the consistency of a repository""" |
|
559 | 568 | return verifymod.verify(repo) |
|
560 | 569 | |
|
561 | 570 | def remoteui(src, opts): |
|
562 | 571 | 'build a remote ui from ui or repo and opts' |
|
563 | 572 | if util.safehasattr(src, 'baseui'): # looks like a repository |
|
564 | 573 | dst = src.baseui.copy() # drop repo-specific config |
|
565 | 574 | src = src.ui # copy target options from repo |
|
566 | 575 | else: # assume it's a global ui object |
|
567 | 576 | dst = src.copy() # keep all global options |
|
568 | 577 | |
|
569 | 578 | # copy ssh-specific options |
|
570 | 579 | for o in 'ssh', 'remotecmd': |
|
571 | 580 | v = opts.get(o) or src.config('ui', o) |
|
572 | 581 | if v: |
|
573 | 582 | dst.setconfig("ui", o, v) |
|
574 | 583 | |
|
575 | 584 | # copy bundle-specific options |
|
576 | 585 | r = src.config('bundle', 'mainreporoot') |
|
577 | 586 | if r: |
|
578 | 587 | dst.setconfig('bundle', 'mainreporoot', r) |
|
579 | 588 | |
|
580 | 589 | # copy selected local settings to the remote ui |
|
581 | 590 | for sect in ('auth', 'hostfingerprints', 'http_proxy'): |
|
582 | 591 | for key, val in src.configitems(sect): |
|
583 | 592 | dst.setconfig(sect, key, val) |
|
584 | 593 | v = src.config('web', 'cacerts') |
|
585 | 594 | if v: |
|
586 | 595 | dst.setconfig('web', 'cacerts', util.expandpath(v)) |
|
587 | 596 | |
|
588 | 597 | return dst |
@@ -1,40 +1,43 | |||
|
1 | 1 | # repo.py - repository base classes for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2 or any later version. |
|
8 | 8 | |
|
9 | 9 | from i18n import _ |
|
10 | 10 | import error |
|
11 | 11 | |
|
12 | 12 | class repository(object): |
|
13 | 13 | def capable(self, name): |
|
14 | 14 | '''tell whether repo supports named capability. |
|
15 | 15 | return False if not supported. |
|
16 | 16 | if boolean capability, return True. |
|
17 | 17 | if string capability, return string.''' |
|
18 | 18 | if name in self.capabilities: |
|
19 | 19 | return True |
|
20 | 20 | name_eq = name + '=' |
|
21 | 21 | for cap in self.capabilities: |
|
22 | 22 | if cap.startswith(name_eq): |
|
23 | 23 | return cap[len(name_eq):] |
|
24 | 24 | return False |
|
25 | 25 | |
|
26 | 26 | def requirecap(self, name, purpose): |
|
27 | 27 | '''raise an exception if the given capability is not present''' |
|
28 | 28 | if not self.capable(name): |
|
29 | 29 | raise error.CapabilityError( |
|
30 | 30 | _('cannot %s; remote repository does not ' |
|
31 | 31 | 'support the %r capability') % (purpose, name)) |
|
32 | 32 | |
|
33 | 33 | def local(self): |
|
34 | 34 | return False |
|
35 | 35 | |
|
36 | def peer(self): | |
|
37 | return self | |
|
38 | ||
|
36 | 39 | def cancopy(self): |
|
37 | 40 | return self.local() |
|
38 | 41 | |
|
39 | 42 | def close(self): |
|
40 | 43 | pass |
@@ -1,200 +1,200 | |||
|
1 | 1 | # setdiscovery.py - improved discovery of common nodeset for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2010 Benoit Boissinot <bboissin@gmail.com> |
|
4 | 4 | # and Peter Arrenbrecht <peter@arrenbrecht.ch> |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2 or any later version. |
|
8 | 8 | |
|
9 | 9 | from node import nullid |
|
10 | 10 | from i18n import _ |
|
11 | 11 | import random, util, dagutil |
|
12 | 12 | import phases |
|
13 | 13 | |
|
14 | 14 | def _updatesample(dag, nodes, sample, always, quicksamplesize=0): |
|
15 | 15 | # if nodes is empty we scan the entire graph |
|
16 | 16 | if nodes: |
|
17 | 17 | heads = dag.headsetofconnecteds(nodes) |
|
18 | 18 | else: |
|
19 | 19 | heads = dag.heads() |
|
20 | 20 | dist = {} |
|
21 | 21 | visit = util.deque(heads) |
|
22 | 22 | seen = set() |
|
23 | 23 | factor = 1 |
|
24 | 24 | while visit: |
|
25 | 25 | curr = visit.popleft() |
|
26 | 26 | if curr in seen: |
|
27 | 27 | continue |
|
28 | 28 | d = dist.setdefault(curr, 1) |
|
29 | 29 | if d > factor: |
|
30 | 30 | factor *= 2 |
|
31 | 31 | if d == factor: |
|
32 | 32 | if curr not in always: # need this check for the early exit below |
|
33 | 33 | sample.add(curr) |
|
34 | 34 | if quicksamplesize and (len(sample) >= quicksamplesize): |
|
35 | 35 | return |
|
36 | 36 | seen.add(curr) |
|
37 | 37 | for p in dag.parents(curr): |
|
38 | 38 | if not nodes or p in nodes: |
|
39 | 39 | dist.setdefault(p, d + 1) |
|
40 | 40 | visit.append(p) |
|
41 | 41 | |
|
42 | 42 | def _setupsample(dag, nodes, size): |
|
43 | 43 | if len(nodes) <= size: |
|
44 | 44 | return set(nodes), None, 0 |
|
45 | 45 | always = dag.headsetofconnecteds(nodes) |
|
46 | 46 | desiredlen = size - len(always) |
|
47 | 47 | if desiredlen <= 0: |
|
48 | 48 | # This could be bad if there are very many heads, all unknown to the |
|
49 | 49 | # server. We're counting on long request support here. |
|
50 | 50 | return always, None, desiredlen |
|
51 | 51 | return always, set(), desiredlen |
|
52 | 52 | |
|
53 | 53 | def _takequicksample(dag, nodes, size, initial): |
|
54 | 54 | always, sample, desiredlen = _setupsample(dag, nodes, size) |
|
55 | 55 | if sample is None: |
|
56 | 56 | return always |
|
57 | 57 | if initial: |
|
58 | 58 | fromset = None |
|
59 | 59 | else: |
|
60 | 60 | fromset = nodes |
|
61 | 61 | _updatesample(dag, fromset, sample, always, quicksamplesize=desiredlen) |
|
62 | 62 | sample.update(always) |
|
63 | 63 | return sample |
|
64 | 64 | |
|
65 | 65 | def _takefullsample(dag, nodes, size): |
|
66 | 66 | always, sample, desiredlen = _setupsample(dag, nodes, size) |
|
67 | 67 | if sample is None: |
|
68 | 68 | return always |
|
69 | 69 | # update from heads |
|
70 | 70 | _updatesample(dag, nodes, sample, always) |
|
71 | 71 | # update from roots |
|
72 | 72 | _updatesample(dag.inverse(), nodes, sample, always) |
|
73 | 73 | assert sample |
|
74 | 74 | if len(sample) > desiredlen: |
|
75 | 75 | sample = set(random.sample(sample, desiredlen)) |
|
76 | 76 | elif len(sample) < desiredlen: |
|
77 | 77 | more = desiredlen - len(sample) |
|
78 | 78 | sample.update(random.sample(list(nodes - sample - always), more)) |
|
79 | 79 | sample.update(always) |
|
80 | 80 | return sample |
|
81 | 81 | |
|
82 | 82 | def findcommonheads(ui, local, remote, |
|
83 | 83 | initialsamplesize=100, |
|
84 | 84 | fullsamplesize=200, |
|
85 | 85 | abortwhenunrelated=True): |
|
86 | 86 | '''Return a tuple (common, anyincoming, remoteheads) used to identify |
|
87 | 87 | missing nodes from or in remote. |
|
88 | 88 | |
|
89 | 89 | shortcutlocal determines whether we try use direct access to localrepo if |
|
90 | 90 | remote is actually local. |
|
91 | 91 | ''' |
|
92 | 92 | roundtrips = 0 |
|
93 | 93 | cl = local.changelog |
|
94 | 94 | dag = dagutil.revlogdag(cl) |
|
95 | 95 | |
|
96 | 96 | # early exit if we know all the specified remote heads already |
|
97 | 97 | ui.debug("query 1; heads\n") |
|
98 | 98 | roundtrips += 1 |
|
99 | 99 | ownheads = dag.heads() |
|
100 | 100 | sample = ownheads |
|
101 | 101 | if remote.local(): |
|
102 | 102 | # stopgap until we have a proper localpeer that supports batch() |
|
103 | srvheadhashes = phases.visibleheads(remote) | |
|
103 | srvheadhashes = phases.visibleheads(remote.local()) | |
|
104 | 104 | yesno = remote.known(dag.externalizeall(sample)) |
|
105 | 105 | elif remote.capable('batch'): |
|
106 | 106 | batch = remote.batch() |
|
107 | 107 | srvheadhashesref = batch.heads() |
|
108 | 108 | yesnoref = batch.known(dag.externalizeall(sample)) |
|
109 | 109 | batch.submit() |
|
110 | 110 | srvheadhashes = srvheadhashesref.value |
|
111 | 111 | yesno = yesnoref.value |
|
112 | 112 | else: |
|
113 | 113 | # compatibitity with pre-batch, but post-known remotes during 1.9 devel |
|
114 | 114 | srvheadhashes = remote.heads() |
|
115 | 115 | sample = [] |
|
116 | 116 | |
|
117 | 117 | if cl.tip() == nullid: |
|
118 | 118 | if srvheadhashes != [nullid]: |
|
119 | 119 | return [nullid], True, srvheadhashes |
|
120 | 120 | return [nullid], False, [] |
|
121 | 121 | |
|
122 | 122 | # start actual discovery (we note this before the next "if" for |
|
123 | 123 | # compatibility reasons) |
|
124 | 124 | ui.status(_("searching for changes\n")) |
|
125 | 125 | |
|
126 | 126 | srvheads = dag.internalizeall(srvheadhashes, filterunknown=True) |
|
127 | 127 | if len(srvheads) == len(srvheadhashes): |
|
128 | 128 | ui.debug("all remote heads known locally\n") |
|
129 | 129 | return (srvheadhashes, False, srvheadhashes,) |
|
130 | 130 | |
|
131 | 131 | if sample and util.all(yesno): |
|
132 | 132 | ui.note(_("all local heads known remotely\n")) |
|
133 | 133 | ownheadhashes = dag.externalizeall(ownheads) |
|
134 | 134 | return (ownheadhashes, True, srvheadhashes,) |
|
135 | 135 | |
|
136 | 136 | # full blown discovery |
|
137 | 137 | |
|
138 | 138 | # own nodes where I don't know if remote knows them |
|
139 | 139 | undecided = dag.nodeset() |
|
140 | 140 | # own nodes I know we both know |
|
141 | 141 | common = set() |
|
142 | 142 | # own nodes I know remote lacks |
|
143 | 143 | missing = set() |
|
144 | 144 | |
|
145 | 145 | # treat remote heads (and maybe own heads) as a first implicit sample |
|
146 | 146 | # response |
|
147 | 147 | common.update(dag.ancestorset(srvheads)) |
|
148 | 148 | undecided.difference_update(common) |
|
149 | 149 | |
|
150 | 150 | full = False |
|
151 | 151 | while undecided: |
|
152 | 152 | |
|
153 | 153 | if sample: |
|
154 | 154 | commoninsample = set(n for i, n in enumerate(sample) if yesno[i]) |
|
155 | 155 | common.update(dag.ancestorset(commoninsample, common)) |
|
156 | 156 | |
|
157 | 157 | missinginsample = [n for i, n in enumerate(sample) if not yesno[i]] |
|
158 | 158 | missing.update(dag.descendantset(missinginsample, missing)) |
|
159 | 159 | |
|
160 | 160 | undecided.difference_update(missing) |
|
161 | 161 | undecided.difference_update(common) |
|
162 | 162 | |
|
163 | 163 | if not undecided: |
|
164 | 164 | break |
|
165 | 165 | |
|
166 | 166 | if full: |
|
167 | 167 | ui.note(_("sampling from both directions\n")) |
|
168 | 168 | sample = _takefullsample(dag, undecided, size=fullsamplesize) |
|
169 | 169 | elif common: |
|
170 | 170 | # use cheapish initial sample |
|
171 | 171 | ui.debug("taking initial sample\n") |
|
172 | 172 | sample = _takefullsample(dag, undecided, size=fullsamplesize) |
|
173 | 173 | else: |
|
174 | 174 | # use even cheaper initial sample |
|
175 | 175 | ui.debug("taking quick initial sample\n") |
|
176 | 176 | sample = _takequicksample(dag, undecided, size=initialsamplesize, |
|
177 | 177 | initial=True) |
|
178 | 178 | |
|
179 | 179 | roundtrips += 1 |
|
180 | 180 | ui.progress(_('searching'), roundtrips, unit=_('queries')) |
|
181 | 181 | ui.debug("query %i; still undecided: %i, sample size is: %i\n" |
|
182 | 182 | % (roundtrips, len(undecided), len(sample))) |
|
183 | 183 | # indices between sample and externalized version must match |
|
184 | 184 | sample = list(sample) |
|
185 | 185 | yesno = remote.known(dag.externalizeall(sample)) |
|
186 | 186 | full = True |
|
187 | 187 | |
|
188 | 188 | result = dag.headsetofconnecteds(common) |
|
189 | 189 | ui.progress(_('searching'), None) |
|
190 | 190 | ui.debug("%d total queries\n" % roundtrips) |
|
191 | 191 | |
|
192 | 192 | if not result and srvheadhashes != [nullid]: |
|
193 | 193 | if abortwhenunrelated: |
|
194 | 194 | raise util.Abort(_("repository is unrelated")) |
|
195 | 195 | else: |
|
196 | 196 | ui.warn(_("warning: repository is unrelated\n")) |
|
197 | 197 | return (set([nullid]), True, srvheadhashes,) |
|
198 | 198 | |
|
199 | 199 | anyincoming = (srvheadhashes != [nullid]) |
|
200 | 200 | return dag.externalizeall(result), anyincoming, srvheadhashes |
@@ -1,1272 +1,1273 | |||
|
1 | 1 | # subrepo.py - sub-repository handling for Mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2009-2010 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | import errno, os, re, xml.dom.minidom, shutil, posixpath |
|
9 | 9 | import stat, subprocess, tarfile |
|
10 | 10 | from i18n import _ |
|
11 | 11 | import config, scmutil, util, node, error, cmdutil, bookmarks, match as matchmod |
|
12 | 12 | hg = None |
|
13 | 13 | propertycache = util.propertycache |
|
14 | 14 | |
|
15 | 15 | nullstate = ('', '', 'empty') |
|
16 | 16 | |
|
17 | 17 | def state(ctx, ui): |
|
18 | 18 | """return a state dict, mapping subrepo paths configured in .hgsub |
|
19 | 19 | to tuple: (source from .hgsub, revision from .hgsubstate, kind |
|
20 | 20 | (key in types dict)) |
|
21 | 21 | """ |
|
22 | 22 | p = config.config() |
|
23 | 23 | def read(f, sections=None, remap=None): |
|
24 | 24 | if f in ctx: |
|
25 | 25 | try: |
|
26 | 26 | data = ctx[f].data() |
|
27 | 27 | except IOError, err: |
|
28 | 28 | if err.errno != errno.ENOENT: |
|
29 | 29 | raise |
|
30 | 30 | # handle missing subrepo spec files as removed |
|
31 | 31 | ui.warn(_("warning: subrepo spec file %s not found\n") % f) |
|
32 | 32 | return |
|
33 | 33 | p.parse(f, data, sections, remap, read) |
|
34 | 34 | else: |
|
35 | 35 | raise util.Abort(_("subrepo spec file %s not found") % f) |
|
36 | 36 | |
|
37 | 37 | if '.hgsub' in ctx: |
|
38 | 38 | read('.hgsub') |
|
39 | 39 | |
|
40 | 40 | for path, src in ui.configitems('subpaths'): |
|
41 | 41 | p.set('subpaths', path, src, ui.configsource('subpaths', path)) |
|
42 | 42 | |
|
43 | 43 | rev = {} |
|
44 | 44 | if '.hgsubstate' in ctx: |
|
45 | 45 | try: |
|
46 | 46 | for i, l in enumerate(ctx['.hgsubstate'].data().splitlines()): |
|
47 | 47 | l = l.lstrip() |
|
48 | 48 | if not l: |
|
49 | 49 | continue |
|
50 | 50 | try: |
|
51 | 51 | revision, path = l.split(" ", 1) |
|
52 | 52 | except ValueError: |
|
53 | 53 | raise util.Abort(_("invalid subrepository revision " |
|
54 | 54 | "specifier in .hgsubstate line %d") |
|
55 | 55 | % (i + 1)) |
|
56 | 56 | rev[path] = revision |
|
57 | 57 | except IOError, err: |
|
58 | 58 | if err.errno != errno.ENOENT: |
|
59 | 59 | raise |
|
60 | 60 | |
|
61 | 61 | def remap(src): |
|
62 | 62 | for pattern, repl in p.items('subpaths'): |
|
63 | 63 | # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub |
|
64 | 64 | # does a string decode. |
|
65 | 65 | repl = repl.encode('string-escape') |
|
66 | 66 | # However, we still want to allow back references to go |
|
67 | 67 | # through unharmed, so we turn r'\\1' into r'\1'. Again, |
|
68 | 68 | # extra escapes are needed because re.sub string decodes. |
|
69 | 69 | repl = re.sub(r'\\\\([0-9]+)', r'\\\1', repl) |
|
70 | 70 | try: |
|
71 | 71 | src = re.sub(pattern, repl, src, 1) |
|
72 | 72 | except re.error, e: |
|
73 | 73 | raise util.Abort(_("bad subrepository pattern in %s: %s") |
|
74 | 74 | % (p.source('subpaths', pattern), e)) |
|
75 | 75 | return src |
|
76 | 76 | |
|
77 | 77 | state = {} |
|
78 | 78 | for path, src in p[''].items(): |
|
79 | 79 | kind = 'hg' |
|
80 | 80 | if src.startswith('['): |
|
81 | 81 | if ']' not in src: |
|
82 | 82 | raise util.Abort(_('missing ] in subrepo source')) |
|
83 | 83 | kind, src = src.split(']', 1) |
|
84 | 84 | kind = kind[1:] |
|
85 | 85 | src = src.lstrip() # strip any extra whitespace after ']' |
|
86 | 86 | |
|
87 | 87 | if not util.url(src).isabs(): |
|
88 | 88 | parent = _abssource(ctx._repo, abort=False) |
|
89 | 89 | if parent: |
|
90 | 90 | parent = util.url(parent) |
|
91 | 91 | parent.path = posixpath.join(parent.path or '', src) |
|
92 | 92 | parent.path = posixpath.normpath(parent.path) |
|
93 | 93 | joined = str(parent) |
|
94 | 94 | # Remap the full joined path and use it if it changes, |
|
95 | 95 | # else remap the original source. |
|
96 | 96 | remapped = remap(joined) |
|
97 | 97 | if remapped == joined: |
|
98 | 98 | src = remap(src) |
|
99 | 99 | else: |
|
100 | 100 | src = remapped |
|
101 | 101 | |
|
102 | 102 | src = remap(src) |
|
103 | 103 | state[util.pconvert(path)] = (src.strip(), rev.get(path, ''), kind) |
|
104 | 104 | |
|
105 | 105 | return state |
|
106 | 106 | |
|
107 | 107 | def writestate(repo, state): |
|
108 | 108 | """rewrite .hgsubstate in (outer) repo with these subrepo states""" |
|
109 | 109 | lines = ['%s %s\n' % (state[s][1], s) for s in sorted(state)] |
|
110 | 110 | repo.wwrite('.hgsubstate', ''.join(lines), '') |
|
111 | 111 | |
|
112 | 112 | def submerge(repo, wctx, mctx, actx, overwrite): |
|
113 | 113 | """delegated from merge.applyupdates: merging of .hgsubstate file |
|
114 | 114 | in working context, merging context and ancestor context""" |
|
115 | 115 | if mctx == actx: # backwards? |
|
116 | 116 | actx = wctx.p1() |
|
117 | 117 | s1 = wctx.substate |
|
118 | 118 | s2 = mctx.substate |
|
119 | 119 | sa = actx.substate |
|
120 | 120 | sm = {} |
|
121 | 121 | |
|
122 | 122 | repo.ui.debug("subrepo merge %s %s %s\n" % (wctx, mctx, actx)) |
|
123 | 123 | |
|
124 | 124 | def debug(s, msg, r=""): |
|
125 | 125 | if r: |
|
126 | 126 | r = "%s:%s:%s" % r |
|
127 | 127 | repo.ui.debug(" subrepo %s: %s %s\n" % (s, msg, r)) |
|
128 | 128 | |
|
129 | 129 | for s, l in s1.items(): |
|
130 | 130 | a = sa.get(s, nullstate) |
|
131 | 131 | ld = l # local state with possible dirty flag for compares |
|
132 | 132 | if wctx.sub(s).dirty(): |
|
133 | 133 | ld = (l[0], l[1] + "+") |
|
134 | 134 | if wctx == actx: # overwrite |
|
135 | 135 | a = ld |
|
136 | 136 | |
|
137 | 137 | if s in s2: |
|
138 | 138 | r = s2[s] |
|
139 | 139 | if ld == r or r == a: # no change or local is newer |
|
140 | 140 | sm[s] = l |
|
141 | 141 | continue |
|
142 | 142 | elif ld == a: # other side changed |
|
143 | 143 | debug(s, "other changed, get", r) |
|
144 | 144 | wctx.sub(s).get(r, overwrite) |
|
145 | 145 | sm[s] = r |
|
146 | 146 | elif ld[0] != r[0]: # sources differ |
|
147 | 147 | if repo.ui.promptchoice( |
|
148 | 148 | _(' subrepository sources for %s differ\n' |
|
149 | 149 | 'use (l)ocal source (%s) or (r)emote source (%s)?') |
|
150 | 150 | % (s, l[0], r[0]), |
|
151 | 151 | (_('&Local'), _('&Remote')), 0): |
|
152 | 152 | debug(s, "prompt changed, get", r) |
|
153 | 153 | wctx.sub(s).get(r, overwrite) |
|
154 | 154 | sm[s] = r |
|
155 | 155 | elif ld[1] == a[1]: # local side is unchanged |
|
156 | 156 | debug(s, "other side changed, get", r) |
|
157 | 157 | wctx.sub(s).get(r, overwrite) |
|
158 | 158 | sm[s] = r |
|
159 | 159 | else: |
|
160 | 160 | debug(s, "both sides changed, merge with", r) |
|
161 | 161 | wctx.sub(s).merge(r) |
|
162 | 162 | sm[s] = l |
|
163 | 163 | elif ld == a: # remote removed, local unchanged |
|
164 | 164 | debug(s, "remote removed, remove") |
|
165 | 165 | wctx.sub(s).remove() |
|
166 | 166 | elif a == nullstate: # not present in remote or ancestor |
|
167 | 167 | debug(s, "local added, keep") |
|
168 | 168 | sm[s] = l |
|
169 | 169 | continue |
|
170 | 170 | else: |
|
171 | 171 | if repo.ui.promptchoice( |
|
172 | 172 | _(' local changed subrepository %s which remote removed\n' |
|
173 | 173 | 'use (c)hanged version or (d)elete?') % s, |
|
174 | 174 | (_('&Changed'), _('&Delete')), 0): |
|
175 | 175 | debug(s, "prompt remove") |
|
176 | 176 | wctx.sub(s).remove() |
|
177 | 177 | |
|
178 | 178 | for s, r in sorted(s2.items()): |
|
179 | 179 | if s in s1: |
|
180 | 180 | continue |
|
181 | 181 | elif s not in sa: |
|
182 | 182 | debug(s, "remote added, get", r) |
|
183 | 183 | mctx.sub(s).get(r) |
|
184 | 184 | sm[s] = r |
|
185 | 185 | elif r != sa[s]: |
|
186 | 186 | if repo.ui.promptchoice( |
|
187 | 187 | _(' remote changed subrepository %s which local removed\n' |
|
188 | 188 | 'use (c)hanged version or (d)elete?') % s, |
|
189 | 189 | (_('&Changed'), _('&Delete')), 0) == 0: |
|
190 | 190 | debug(s, "prompt recreate", r) |
|
191 | 191 | wctx.sub(s).get(r) |
|
192 | 192 | sm[s] = r |
|
193 | 193 | |
|
194 | 194 | # record merged .hgsubstate |
|
195 | 195 | writestate(repo, sm) |
|
196 | 196 | |
|
197 | 197 | def _updateprompt(ui, sub, dirty, local, remote): |
|
198 | 198 | if dirty: |
|
199 | 199 | msg = (_(' subrepository sources for %s differ\n' |
|
200 | 200 | 'use (l)ocal source (%s) or (r)emote source (%s)?\n') |
|
201 | 201 | % (subrelpath(sub), local, remote)) |
|
202 | 202 | else: |
|
203 | 203 | msg = (_(' subrepository sources for %s differ (in checked out ' |
|
204 | 204 | 'version)\n' |
|
205 | 205 | 'use (l)ocal source (%s) or (r)emote source (%s)?\n') |
|
206 | 206 | % (subrelpath(sub), local, remote)) |
|
207 | 207 | return ui.promptchoice(msg, (_('&Local'), _('&Remote')), 0) |
|
208 | 208 | |
|
209 | 209 | def reporelpath(repo): |
|
210 | 210 | """return path to this (sub)repo as seen from outermost repo""" |
|
211 | 211 | parent = repo |
|
212 | 212 | while util.safehasattr(parent, '_subparent'): |
|
213 | 213 | parent = parent._subparent |
|
214 | 214 | p = parent.root.rstrip(os.sep) |
|
215 | 215 | return repo.root[len(p) + 1:] |
|
216 | 216 | |
|
217 | 217 | def subrelpath(sub): |
|
218 | 218 | """return path to this subrepo as seen from outermost repo""" |
|
219 | 219 | if util.safehasattr(sub, '_relpath'): |
|
220 | 220 | return sub._relpath |
|
221 | 221 | if not util.safehasattr(sub, '_repo'): |
|
222 | 222 | return sub._path |
|
223 | 223 | return reporelpath(sub._repo) |
|
224 | 224 | |
|
225 | 225 | def _abssource(repo, push=False, abort=True): |
|
226 | 226 | """return pull/push path of repo - either based on parent repo .hgsub info |
|
227 | 227 | or on the top repo config. Abort or return None if no source found.""" |
|
228 | 228 | if util.safehasattr(repo, '_subparent'): |
|
229 | 229 | source = util.url(repo._subsource) |
|
230 | 230 | if source.isabs(): |
|
231 | 231 | return str(source) |
|
232 | 232 | source.path = posixpath.normpath(source.path) |
|
233 | 233 | parent = _abssource(repo._subparent, push, abort=False) |
|
234 | 234 | if parent: |
|
235 | 235 | parent = util.url(util.pconvert(parent)) |
|
236 | 236 | parent.path = posixpath.join(parent.path or '', source.path) |
|
237 | 237 | parent.path = posixpath.normpath(parent.path) |
|
238 | 238 | return str(parent) |
|
239 | 239 | else: # recursion reached top repo |
|
240 | 240 | if util.safehasattr(repo, '_subtoppath'): |
|
241 | 241 | return repo._subtoppath |
|
242 | 242 | if push and repo.ui.config('paths', 'default-push'): |
|
243 | 243 | return repo.ui.config('paths', 'default-push') |
|
244 | 244 | if repo.ui.config('paths', 'default'): |
|
245 | 245 | return repo.ui.config('paths', 'default') |
|
246 | 246 | if abort: |
|
247 | 247 | raise util.Abort(_("default path for subrepository %s not found") % |
|
248 | 248 | reporelpath(repo)) |
|
249 | 249 | |
|
250 | 250 | def itersubrepos(ctx1, ctx2): |
|
251 | 251 | """find subrepos in ctx1 or ctx2""" |
|
252 | 252 | # Create a (subpath, ctx) mapping where we prefer subpaths from |
|
253 | 253 | # ctx1. The subpaths from ctx2 are important when the .hgsub file |
|
254 | 254 | # has been modified (in ctx2) but not yet committed (in ctx1). |
|
255 | 255 | subpaths = dict.fromkeys(ctx2.substate, ctx2) |
|
256 | 256 | subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) |
|
257 | 257 | for subpath, ctx in sorted(subpaths.iteritems()): |
|
258 | 258 | yield subpath, ctx.sub(subpath) |
|
259 | 259 | |
|
260 | 260 | def subrepo(ctx, path): |
|
261 | 261 | """return instance of the right subrepo class for subrepo in path""" |
|
262 | 262 | # subrepo inherently violates our import layering rules |
|
263 | 263 | # because it wants to make repo objects from deep inside the stack |
|
264 | 264 | # so we manually delay the circular imports to not break |
|
265 | 265 | # scripts that don't use our demand-loading |
|
266 | 266 | global hg |
|
267 | 267 | import hg as h |
|
268 | 268 | hg = h |
|
269 | 269 | |
|
270 | 270 | scmutil.pathauditor(ctx._repo.root)(path) |
|
271 | 271 | state = ctx.substate[path] |
|
272 | 272 | if state[2] not in types: |
|
273 | 273 | raise util.Abort(_('unknown subrepo type %s') % state[2]) |
|
274 | 274 | return types[state[2]](ctx, path, state[:2]) |
|
275 | 275 | |
|
276 | 276 | # subrepo classes need to implement the following abstract class: |
|
277 | 277 | |
|
278 | 278 | class abstractsubrepo(object): |
|
279 | 279 | |
|
280 | 280 | def dirty(self, ignoreupdate=False): |
|
281 | 281 | """returns true if the dirstate of the subrepo is dirty or does not |
|
282 | 282 | match current stored state. If ignoreupdate is true, only check |
|
283 | 283 | whether the subrepo has uncommitted changes in its dirstate. |
|
284 | 284 | """ |
|
285 | 285 | raise NotImplementedError |
|
286 | 286 | |
|
287 | 287 | def basestate(self): |
|
288 | 288 | """current working directory base state, disregarding .hgsubstate |
|
289 | 289 | state and working directory modifications""" |
|
290 | 290 | raise NotImplementedError |
|
291 | 291 | |
|
292 | 292 | def checknested(self, path): |
|
293 | 293 | """check if path is a subrepository within this repository""" |
|
294 | 294 | return False |
|
295 | 295 | |
|
296 | 296 | def commit(self, text, user, date): |
|
297 | 297 | """commit the current changes to the subrepo with the given |
|
298 | 298 | log message. Use given user and date if possible. Return the |
|
299 | 299 | new state of the subrepo. |
|
300 | 300 | """ |
|
301 | 301 | raise NotImplementedError |
|
302 | 302 | |
|
303 | 303 | def remove(self): |
|
304 | 304 | """remove the subrepo |
|
305 | 305 | |
|
306 | 306 | (should verify the dirstate is not dirty first) |
|
307 | 307 | """ |
|
308 | 308 | raise NotImplementedError |
|
309 | 309 | |
|
310 | 310 | def get(self, state, overwrite=False): |
|
311 | 311 | """run whatever commands are needed to put the subrepo into |
|
312 | 312 | this state |
|
313 | 313 | """ |
|
314 | 314 | raise NotImplementedError |
|
315 | 315 | |
|
316 | 316 | def merge(self, state): |
|
317 | 317 | """merge currently-saved state with the new state.""" |
|
318 | 318 | raise NotImplementedError |
|
319 | 319 | |
|
320 | 320 | def push(self, opts): |
|
321 | 321 | """perform whatever action is analogous to 'hg push' |
|
322 | 322 | |
|
323 | 323 | This may be a no-op on some systems. |
|
324 | 324 | """ |
|
325 | 325 | raise NotImplementedError |
|
326 | 326 | |
|
327 | 327 | def add(self, ui, match, dryrun, listsubrepos, prefix, explicitonly): |
|
328 | 328 | return [] |
|
329 | 329 | |
|
330 | 330 | def status(self, rev2, **opts): |
|
331 | 331 | return [], [], [], [], [], [], [] |
|
332 | 332 | |
|
333 | 333 | def diff(self, diffopts, node2, match, prefix, **opts): |
|
334 | 334 | pass |
|
335 | 335 | |
|
336 | 336 | def outgoing(self, ui, dest, opts): |
|
337 | 337 | return 1 |
|
338 | 338 | |
|
339 | 339 | def incoming(self, ui, source, opts): |
|
340 | 340 | return 1 |
|
341 | 341 | |
|
342 | 342 | def files(self): |
|
343 | 343 | """return filename iterator""" |
|
344 | 344 | raise NotImplementedError |
|
345 | 345 | |
|
346 | 346 | def filedata(self, name): |
|
347 | 347 | """return file data""" |
|
348 | 348 | raise NotImplementedError |
|
349 | 349 | |
|
350 | 350 | def fileflags(self, name): |
|
351 | 351 | """return file flags""" |
|
352 | 352 | return '' |
|
353 | 353 | |
|
354 | 354 | def archive(self, ui, archiver, prefix, match=None): |
|
355 | 355 | if match is not None: |
|
356 | 356 | files = [f for f in self.files() if match(f)] |
|
357 | 357 | else: |
|
358 | 358 | files = self.files() |
|
359 | 359 | total = len(files) |
|
360 | 360 | relpath = subrelpath(self) |
|
361 | 361 | ui.progress(_('archiving (%s)') % relpath, 0, |
|
362 | 362 | unit=_('files'), total=total) |
|
363 | 363 | for i, name in enumerate(files): |
|
364 | 364 | flags = self.fileflags(name) |
|
365 | 365 | mode = 'x' in flags and 0755 or 0644 |
|
366 | 366 | symlink = 'l' in flags |
|
367 | 367 | archiver.addfile(os.path.join(prefix, self._path, name), |
|
368 | 368 | mode, symlink, self.filedata(name)) |
|
369 | 369 | ui.progress(_('archiving (%s)') % relpath, i + 1, |
|
370 | 370 | unit=_('files'), total=total) |
|
371 | 371 | ui.progress(_('archiving (%s)') % relpath, None) |
|
372 | 372 | |
|
373 | 373 | def walk(self, match): |
|
374 | 374 | ''' |
|
375 | 375 | walk recursively through the directory tree, finding all files |
|
376 | 376 | matched by the match function |
|
377 | 377 | ''' |
|
378 | 378 | pass |
|
379 | 379 | |
|
380 | 380 | def forget(self, ui, match, prefix): |
|
381 | 381 | return ([], []) |
|
382 | 382 | |
|
383 | 383 | def revert(self, ui, substate, *pats, **opts): |
|
384 | 384 | ui.warn('%s: reverting %s subrepos is unsupported\n' \ |
|
385 | 385 | % (substate[0], substate[2])) |
|
386 | 386 | return [] |
|
387 | 387 | |
|
388 | 388 | class hgsubrepo(abstractsubrepo): |
|
389 | 389 | def __init__(self, ctx, path, state): |
|
390 | 390 | self._path = path |
|
391 | 391 | self._state = state |
|
392 | 392 | r = ctx._repo |
|
393 | 393 | root = r.wjoin(path) |
|
394 | 394 | create = False |
|
395 | 395 | if not os.path.exists(os.path.join(root, '.hg')): |
|
396 | 396 | create = True |
|
397 | 397 | util.makedirs(root) |
|
398 | 398 | self._repo = hg.repository(r.ui, root, create=create) |
|
399 | 399 | self._initrepo(r, state[0], create) |
|
400 | 400 | |
|
401 | 401 | def _initrepo(self, parentrepo, source, create): |
|
402 | 402 | self._repo._subparent = parentrepo |
|
403 | 403 | self._repo._subsource = source |
|
404 | 404 | |
|
405 | 405 | if create: |
|
406 | 406 | fp = self._repo.opener("hgrc", "w", text=True) |
|
407 | 407 | fp.write('[paths]\n') |
|
408 | 408 | |
|
409 | 409 | def addpathconfig(key, value): |
|
410 | 410 | if value: |
|
411 | 411 | fp.write('%s = %s\n' % (key, value)) |
|
412 | 412 | self._repo.ui.setconfig('paths', key, value) |
|
413 | 413 | |
|
414 | 414 | defpath = _abssource(self._repo, abort=False) |
|
415 | 415 | defpushpath = _abssource(self._repo, True, abort=False) |
|
416 | 416 | addpathconfig('default', defpath) |
|
417 | 417 | if defpath != defpushpath: |
|
418 | 418 | addpathconfig('default-push', defpushpath) |
|
419 | 419 | fp.close() |
|
420 | 420 | |
|
421 | 421 | def add(self, ui, match, dryrun, listsubrepos, prefix, explicitonly): |
|
422 | 422 | return cmdutil.add(ui, self._repo, match, dryrun, listsubrepos, |
|
423 | 423 | os.path.join(prefix, self._path), explicitonly) |
|
424 | 424 | |
|
425 | 425 | def status(self, rev2, **opts): |
|
426 | 426 | try: |
|
427 | 427 | rev1 = self._state[1] |
|
428 | 428 | ctx1 = self._repo[rev1] |
|
429 | 429 | ctx2 = self._repo[rev2] |
|
430 | 430 | return self._repo.status(ctx1, ctx2, **opts) |
|
431 | 431 | except error.RepoLookupError, inst: |
|
432 | 432 | self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
|
433 | 433 | % (inst, subrelpath(self))) |
|
434 | 434 | return [], [], [], [], [], [], [] |
|
435 | 435 | |
|
436 | 436 | def diff(self, diffopts, node2, match, prefix, **opts): |
|
437 | 437 | try: |
|
438 | 438 | node1 = node.bin(self._state[1]) |
|
439 | 439 | # We currently expect node2 to come from substate and be |
|
440 | 440 | # in hex format |
|
441 | 441 | if node2 is not None: |
|
442 | 442 | node2 = node.bin(node2) |
|
443 | 443 | cmdutil.diffordiffstat(self._repo.ui, self._repo, diffopts, |
|
444 | 444 | node1, node2, match, |
|
445 | 445 | prefix=os.path.join(prefix, self._path), |
|
446 | 446 | listsubrepos=True, **opts) |
|
447 | 447 | except error.RepoLookupError, inst: |
|
448 | 448 | self._repo.ui.warn(_('warning: error "%s" in subrepository "%s"\n') |
|
449 | 449 | % (inst, subrelpath(self))) |
|
450 | 450 | |
|
451 | 451 | def archive(self, ui, archiver, prefix, match=None): |
|
452 | 452 | self._get(self._state + ('hg',)) |
|
453 | 453 | abstractsubrepo.archive(self, ui, archiver, prefix, match) |
|
454 | 454 | |
|
455 | 455 | rev = self._state[1] |
|
456 | 456 | ctx = self._repo[rev] |
|
457 | 457 | for subpath in ctx.substate: |
|
458 | 458 | s = subrepo(ctx, subpath) |
|
459 | 459 | submatch = matchmod.narrowmatcher(subpath, match) |
|
460 | 460 | s.archive(ui, archiver, os.path.join(prefix, self._path), submatch) |
|
461 | 461 | |
|
462 | 462 | def dirty(self, ignoreupdate=False): |
|
463 | 463 | r = self._state[1] |
|
464 | 464 | if r == '' and not ignoreupdate: # no state recorded |
|
465 | 465 | return True |
|
466 | 466 | w = self._repo[None] |
|
467 | 467 | if r != w.p1().hex() and not ignoreupdate: |
|
468 | 468 | # different version checked out |
|
469 | 469 | return True |
|
470 | 470 | return w.dirty() # working directory changed |
|
471 | 471 | |
|
472 | 472 | def basestate(self): |
|
473 | 473 | return self._repo['.'].hex() |
|
474 | 474 | |
|
475 | 475 | def checknested(self, path): |
|
476 | 476 | return self._repo._checknested(self._repo.wjoin(path)) |
|
477 | 477 | |
|
478 | 478 | def commit(self, text, user, date): |
|
479 | 479 | # don't bother committing in the subrepo if it's only been |
|
480 | 480 | # updated |
|
481 | 481 | if not self.dirty(True): |
|
482 | 482 | return self._repo['.'].hex() |
|
483 | 483 | self._repo.ui.debug("committing subrepo %s\n" % subrelpath(self)) |
|
484 | 484 | n = self._repo.commit(text, user, date) |
|
485 | 485 | if not n: |
|
486 | 486 | return self._repo['.'].hex() # different version checked out |
|
487 | 487 | return node.hex(n) |
|
488 | 488 | |
|
489 | 489 | def remove(self): |
|
490 | 490 | # we can't fully delete the repository as it may contain |
|
491 | 491 | # local-only history |
|
492 | 492 | self._repo.ui.note(_('removing subrepo %s\n') % subrelpath(self)) |
|
493 | 493 | hg.clean(self._repo, node.nullid, False) |
|
494 | 494 | |
|
495 | 495 | def _get(self, state): |
|
496 | 496 | source, revision, kind = state |
|
497 | 497 | if revision not in self._repo: |
|
498 | 498 | self._repo._subsource = source |
|
499 | 499 | srcurl = _abssource(self._repo) |
|
500 | 500 | other = hg.peer(self._repo.ui, {}, srcurl) |
|
501 | 501 | if len(self._repo) == 0: |
|
502 | 502 | self._repo.ui.status(_('cloning subrepo %s from %s\n') |
|
503 | 503 | % (subrelpath(self), srcurl)) |
|
504 | 504 | parentrepo = self._repo._subparent |
|
505 | 505 | shutil.rmtree(self._repo.path) |
|
506 |
other, |
|
|
506 | other, cloned = hg.clone(self._repo._subparent.ui, {}, | |
|
507 | 507 |
|
|
508 | 508 |
|
|
509 | self._repo = cloned.local() | |
|
509 | 510 | self._initrepo(parentrepo, source, create=True) |
|
510 | 511 | else: |
|
511 | 512 | self._repo.ui.status(_('pulling subrepo %s from %s\n') |
|
512 | 513 | % (subrelpath(self), srcurl)) |
|
513 | 514 | self._repo.pull(other) |
|
514 | 515 | bookmarks.updatefromremote(self._repo.ui, self._repo, other, |
|
515 | 516 | srcurl) |
|
516 | 517 | |
|
517 | 518 | def get(self, state, overwrite=False): |
|
518 | 519 | self._get(state) |
|
519 | 520 | source, revision, kind = state |
|
520 | 521 | self._repo.ui.debug("getting subrepo %s\n" % self._path) |
|
521 | 522 | hg.clean(self._repo, revision, False) |
|
522 | 523 | |
|
523 | 524 | def merge(self, state): |
|
524 | 525 | self._get(state) |
|
525 | 526 | cur = self._repo['.'] |
|
526 | 527 | dst = self._repo[state[1]] |
|
527 | 528 | anc = dst.ancestor(cur) |
|
528 | 529 | |
|
529 | 530 | def mergefunc(): |
|
530 | 531 | if anc == cur and dst.branch() == cur.branch(): |
|
531 | 532 | self._repo.ui.debug("updating subrepo %s\n" % subrelpath(self)) |
|
532 | 533 | hg.update(self._repo, state[1]) |
|
533 | 534 | elif anc == dst: |
|
534 | 535 | self._repo.ui.debug("skipping subrepo %s\n" % subrelpath(self)) |
|
535 | 536 | else: |
|
536 | 537 | self._repo.ui.debug("merging subrepo %s\n" % subrelpath(self)) |
|
537 | 538 | hg.merge(self._repo, state[1], remind=False) |
|
538 | 539 | |
|
539 | 540 | wctx = self._repo[None] |
|
540 | 541 | if self.dirty(): |
|
541 | 542 | if anc != dst: |
|
542 | 543 | if _updateprompt(self._repo.ui, self, wctx.dirty(), cur, dst): |
|
543 | 544 | mergefunc() |
|
544 | 545 | else: |
|
545 | 546 | mergefunc() |
|
546 | 547 | else: |
|
547 | 548 | mergefunc() |
|
548 | 549 | |
|
549 | 550 | def push(self, opts): |
|
550 | 551 | force = opts.get('force') |
|
551 | 552 | newbranch = opts.get('new_branch') |
|
552 | 553 | ssh = opts.get('ssh') |
|
553 | 554 | |
|
554 | 555 | # push subrepos depth-first for coherent ordering |
|
555 | 556 | c = self._repo[''] |
|
556 | 557 | subs = c.substate # only repos that are committed |
|
557 | 558 | for s in sorted(subs): |
|
558 | 559 | if c.sub(s).push(opts) == 0: |
|
559 | 560 | return False |
|
560 | 561 | |
|
561 | 562 | dsturl = _abssource(self._repo, True) |
|
562 | 563 | self._repo.ui.status(_('pushing subrepo %s to %s\n') % |
|
563 | 564 | (subrelpath(self), dsturl)) |
|
564 | 565 | other = hg.peer(self._repo.ui, {'ssh': ssh}, dsturl) |
|
565 | 566 | return self._repo.push(other, force, newbranch=newbranch) |
|
566 | 567 | |
|
567 | 568 | def outgoing(self, ui, dest, opts): |
|
568 | 569 | return hg.outgoing(ui, self._repo, _abssource(self._repo, True), opts) |
|
569 | 570 | |
|
570 | 571 | def incoming(self, ui, source, opts): |
|
571 | 572 | return hg.incoming(ui, self._repo, _abssource(self._repo, False), opts) |
|
572 | 573 | |
|
573 | 574 | def files(self): |
|
574 | 575 | rev = self._state[1] |
|
575 | 576 | ctx = self._repo[rev] |
|
576 | 577 | return ctx.manifest() |
|
577 | 578 | |
|
578 | 579 | def filedata(self, name): |
|
579 | 580 | rev = self._state[1] |
|
580 | 581 | return self._repo[rev][name].data() |
|
581 | 582 | |
|
582 | 583 | def fileflags(self, name): |
|
583 | 584 | rev = self._state[1] |
|
584 | 585 | ctx = self._repo[rev] |
|
585 | 586 | return ctx.flags(name) |
|
586 | 587 | |
|
587 | 588 | def walk(self, match): |
|
588 | 589 | ctx = self._repo[None] |
|
589 | 590 | return ctx.walk(match) |
|
590 | 591 | |
|
591 | 592 | def forget(self, ui, match, prefix): |
|
592 | 593 | return cmdutil.forget(ui, self._repo, match, |
|
593 | 594 | os.path.join(prefix, self._path), True) |
|
594 | 595 | |
|
595 | 596 | def revert(self, ui, substate, *pats, **opts): |
|
596 | 597 | # reverting a subrepo is a 2 step process: |
|
597 | 598 | # 1. if the no_backup is not set, revert all modified |
|
598 | 599 | # files inside the subrepo |
|
599 | 600 | # 2. update the subrepo to the revision specified in |
|
600 | 601 | # the corresponding substate dictionary |
|
601 | 602 | ui.status(_('reverting subrepo %s\n') % substate[0]) |
|
602 | 603 | if not opts.get('no_backup'): |
|
603 | 604 | # Revert all files on the subrepo, creating backups |
|
604 | 605 | # Note that this will not recursively revert subrepos |
|
605 | 606 | # We could do it if there was a set:subrepos() predicate |
|
606 | 607 | opts = opts.copy() |
|
607 | 608 | opts['date'] = None |
|
608 | 609 | opts['rev'] = substate[1] |
|
609 | 610 | |
|
610 | 611 | pats = [] |
|
611 | 612 | if not opts['all']: |
|
612 | 613 | pats = ['set:modified()'] |
|
613 | 614 | self.filerevert(ui, *pats, **opts) |
|
614 | 615 | |
|
615 | 616 | # Update the repo to the revision specified in the given substate |
|
616 | 617 | self.get(substate, overwrite=True) |
|
617 | 618 | |
|
618 | 619 | def filerevert(self, ui, *pats, **opts): |
|
619 | 620 | ctx = self._repo[opts['rev']] |
|
620 | 621 | parents = self._repo.dirstate.parents() |
|
621 | 622 | if opts['all']: |
|
622 | 623 | pats = ['set:modified()'] |
|
623 | 624 | else: |
|
624 | 625 | pats = [] |
|
625 | 626 | cmdutil.revert(ui, self._repo, ctx, parents, *pats, **opts) |
|
626 | 627 | |
|
627 | 628 | class svnsubrepo(abstractsubrepo): |
|
628 | 629 | def __init__(self, ctx, path, state): |
|
629 | 630 | self._path = path |
|
630 | 631 | self._state = state |
|
631 | 632 | self._ctx = ctx |
|
632 | 633 | self._ui = ctx._repo.ui |
|
633 | 634 | self._exe = util.findexe('svn') |
|
634 | 635 | if not self._exe: |
|
635 | 636 | raise util.Abort(_("'svn' executable not found for subrepo '%s'") |
|
636 | 637 | % self._path) |
|
637 | 638 | |
|
638 | 639 | def _svncommand(self, commands, filename='', failok=False): |
|
639 | 640 | cmd = [self._exe] |
|
640 | 641 | extrakw = {} |
|
641 | 642 | if not self._ui.interactive(): |
|
642 | 643 | # Making stdin be a pipe should prevent svn from behaving |
|
643 | 644 | # interactively even if we can't pass --non-interactive. |
|
644 | 645 | extrakw['stdin'] = subprocess.PIPE |
|
645 | 646 | # Starting in svn 1.5 --non-interactive is a global flag |
|
646 | 647 | # instead of being per-command, but we need to support 1.4 so |
|
647 | 648 | # we have to be intelligent about what commands take |
|
648 | 649 | # --non-interactive. |
|
649 | 650 | if commands[0] in ('update', 'checkout', 'commit'): |
|
650 | 651 | cmd.append('--non-interactive') |
|
651 | 652 | cmd.extend(commands) |
|
652 | 653 | if filename is not None: |
|
653 | 654 | path = os.path.join(self._ctx._repo.origroot, self._path, filename) |
|
654 | 655 | cmd.append(path) |
|
655 | 656 | env = dict(os.environ) |
|
656 | 657 | # Avoid localized output, preserve current locale for everything else. |
|
657 | 658 | env['LC_MESSAGES'] = 'C' |
|
658 | 659 | p = subprocess.Popen(cmd, bufsize=-1, close_fds=util.closefds, |
|
659 | 660 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
|
660 | 661 | universal_newlines=True, env=env, **extrakw) |
|
661 | 662 | stdout, stderr = p.communicate() |
|
662 | 663 | stderr = stderr.strip() |
|
663 | 664 | if not failok: |
|
664 | 665 | if p.returncode: |
|
665 | 666 | raise util.Abort(stderr or 'exited with code %d' % p.returncode) |
|
666 | 667 | if stderr: |
|
667 | 668 | self._ui.warn(stderr + '\n') |
|
668 | 669 | return stdout, stderr |
|
669 | 670 | |
|
670 | 671 | @propertycache |
|
671 | 672 | def _svnversion(self): |
|
672 | 673 | output, err = self._svncommand(['--version'], filename=None) |
|
673 | 674 | m = re.search(r'^svn,\s+version\s+(\d+)\.(\d+)', output) |
|
674 | 675 | if not m: |
|
675 | 676 | raise util.Abort(_('cannot retrieve svn tool version')) |
|
676 | 677 | return (int(m.group(1)), int(m.group(2))) |
|
677 | 678 | |
|
678 | 679 | def _wcrevs(self): |
|
679 | 680 | # Get the working directory revision as well as the last |
|
680 | 681 | # commit revision so we can compare the subrepo state with |
|
681 | 682 | # both. We used to store the working directory one. |
|
682 | 683 | output, err = self._svncommand(['info', '--xml']) |
|
683 | 684 | doc = xml.dom.minidom.parseString(output) |
|
684 | 685 | entries = doc.getElementsByTagName('entry') |
|
685 | 686 | lastrev, rev = '0', '0' |
|
686 | 687 | if entries: |
|
687 | 688 | rev = str(entries[0].getAttribute('revision')) or '0' |
|
688 | 689 | commits = entries[0].getElementsByTagName('commit') |
|
689 | 690 | if commits: |
|
690 | 691 | lastrev = str(commits[0].getAttribute('revision')) or '0' |
|
691 | 692 | return (lastrev, rev) |
|
692 | 693 | |
|
693 | 694 | def _wcrev(self): |
|
694 | 695 | return self._wcrevs()[0] |
|
695 | 696 | |
|
696 | 697 | def _wcchanged(self): |
|
697 | 698 | """Return (changes, extchanges, missing) where changes is True |
|
698 | 699 | if the working directory was changed, extchanges is |
|
699 | 700 | True if any of these changes concern an external entry and missing |
|
700 | 701 | is True if any change is a missing entry. |
|
701 | 702 | """ |
|
702 | 703 | output, err = self._svncommand(['status', '--xml']) |
|
703 | 704 | externals, changes, missing = [], [], [] |
|
704 | 705 | doc = xml.dom.minidom.parseString(output) |
|
705 | 706 | for e in doc.getElementsByTagName('entry'): |
|
706 | 707 | s = e.getElementsByTagName('wc-status') |
|
707 | 708 | if not s: |
|
708 | 709 | continue |
|
709 | 710 | item = s[0].getAttribute('item') |
|
710 | 711 | props = s[0].getAttribute('props') |
|
711 | 712 | path = e.getAttribute('path') |
|
712 | 713 | if item == 'external': |
|
713 | 714 | externals.append(path) |
|
714 | 715 | elif item == 'missing': |
|
715 | 716 | missing.append(path) |
|
716 | 717 | if (item not in ('', 'normal', 'unversioned', 'external') |
|
717 | 718 | or props not in ('', 'none', 'normal')): |
|
718 | 719 | changes.append(path) |
|
719 | 720 | for path in changes: |
|
720 | 721 | for ext in externals: |
|
721 | 722 | if path == ext or path.startswith(ext + os.sep): |
|
722 | 723 | return True, True, bool(missing) |
|
723 | 724 | return bool(changes), False, bool(missing) |
|
724 | 725 | |
|
725 | 726 | def dirty(self, ignoreupdate=False): |
|
726 | 727 | if not self._wcchanged()[0]: |
|
727 | 728 | if self._state[1] in self._wcrevs() or ignoreupdate: |
|
728 | 729 | return False |
|
729 | 730 | return True |
|
730 | 731 | |
|
731 | 732 | def basestate(self): |
|
732 | 733 | lastrev, rev = self._wcrevs() |
|
733 | 734 | if lastrev != rev: |
|
734 | 735 | # Last committed rev is not the same than rev. We would |
|
735 | 736 | # like to take lastrev but we do not know if the subrepo |
|
736 | 737 | # URL exists at lastrev. Test it and fallback to rev it |
|
737 | 738 | # is not there. |
|
738 | 739 | try: |
|
739 | 740 | self._svncommand(['list', '%s@%s' % (self._state[0], lastrev)]) |
|
740 | 741 | return lastrev |
|
741 | 742 | except error.Abort: |
|
742 | 743 | pass |
|
743 | 744 | return rev |
|
744 | 745 | |
|
745 | 746 | def commit(self, text, user, date): |
|
746 | 747 | # user and date are out of our hands since svn is centralized |
|
747 | 748 | changed, extchanged, missing = self._wcchanged() |
|
748 | 749 | if not changed: |
|
749 | 750 | return self.basestate() |
|
750 | 751 | if extchanged: |
|
751 | 752 | # Do not try to commit externals |
|
752 | 753 | raise util.Abort(_('cannot commit svn externals')) |
|
753 | 754 | if missing: |
|
754 | 755 | # svn can commit with missing entries but aborting like hg |
|
755 | 756 | # seems a better approach. |
|
756 | 757 | raise util.Abort(_('cannot commit missing svn entries')) |
|
757 | 758 | commitinfo, err = self._svncommand(['commit', '-m', text]) |
|
758 | 759 | self._ui.status(commitinfo) |
|
759 | 760 | newrev = re.search('Committed revision ([0-9]+).', commitinfo) |
|
760 | 761 | if not newrev: |
|
761 | 762 | if not commitinfo.strip(): |
|
762 | 763 | # Sometimes, our definition of "changed" differs from |
|
763 | 764 | # svn one. For instance, svn ignores missing files |
|
764 | 765 | # when committing. If there are only missing files, no |
|
765 | 766 | # commit is made, no output and no error code. |
|
766 | 767 | raise util.Abort(_('failed to commit svn changes')) |
|
767 | 768 | raise util.Abort(commitinfo.splitlines()[-1]) |
|
768 | 769 | newrev = newrev.groups()[0] |
|
769 | 770 | self._ui.status(self._svncommand(['update', '-r', newrev])[0]) |
|
770 | 771 | return newrev |
|
771 | 772 | |
|
772 | 773 | def remove(self): |
|
773 | 774 | if self.dirty(): |
|
774 | 775 | self._ui.warn(_('not removing repo %s because ' |
|
775 | 776 | 'it has changes.\n' % self._path)) |
|
776 | 777 | return |
|
777 | 778 | self._ui.note(_('removing subrepo %s\n') % self._path) |
|
778 | 779 | |
|
779 | 780 | def onerror(function, path, excinfo): |
|
780 | 781 | if function is not os.remove: |
|
781 | 782 | raise |
|
782 | 783 | # read-only files cannot be unlinked under Windows |
|
783 | 784 | s = os.stat(path) |
|
784 | 785 | if (s.st_mode & stat.S_IWRITE) != 0: |
|
785 | 786 | raise |
|
786 | 787 | os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE) |
|
787 | 788 | os.remove(path) |
|
788 | 789 | |
|
789 | 790 | path = self._ctx._repo.wjoin(self._path) |
|
790 | 791 | shutil.rmtree(path, onerror=onerror) |
|
791 | 792 | try: |
|
792 | 793 | os.removedirs(os.path.dirname(path)) |
|
793 | 794 | except OSError: |
|
794 | 795 | pass |
|
795 | 796 | |
|
796 | 797 | def get(self, state, overwrite=False): |
|
797 | 798 | if overwrite: |
|
798 | 799 | self._svncommand(['revert', '--recursive']) |
|
799 | 800 | args = ['checkout'] |
|
800 | 801 | if self._svnversion >= (1, 5): |
|
801 | 802 | args.append('--force') |
|
802 | 803 | # The revision must be specified at the end of the URL to properly |
|
803 | 804 | # update to a directory which has since been deleted and recreated. |
|
804 | 805 | args.append('%s@%s' % (state[0], state[1])) |
|
805 | 806 | status, err = self._svncommand(args, failok=True) |
|
806 | 807 | if not re.search('Checked out revision [0-9]+.', status): |
|
807 | 808 | if ('is already a working copy for a different URL' in err |
|
808 | 809 | and (self._wcchanged()[:2] == (False, False))): |
|
809 | 810 | # obstructed but clean working copy, so just blow it away. |
|
810 | 811 | self.remove() |
|
811 | 812 | self.get(state, overwrite=False) |
|
812 | 813 | return |
|
813 | 814 | raise util.Abort((status or err).splitlines()[-1]) |
|
814 | 815 | self._ui.status(status) |
|
815 | 816 | |
|
816 | 817 | def merge(self, state): |
|
817 | 818 | old = self._state[1] |
|
818 | 819 | new = state[1] |
|
819 | 820 | wcrev = self._wcrev() |
|
820 | 821 | if new != wcrev: |
|
821 | 822 | dirty = old == wcrev or self._wcchanged()[0] |
|
822 | 823 | if _updateprompt(self._ui, self, dirty, wcrev, new): |
|
823 | 824 | self.get(state, False) |
|
824 | 825 | |
|
825 | 826 | def push(self, opts): |
|
826 | 827 | # push is a no-op for SVN |
|
827 | 828 | return True |
|
828 | 829 | |
|
829 | 830 | def files(self): |
|
830 | 831 | output = self._svncommand(['list', '--recursive', '--xml'])[0] |
|
831 | 832 | doc = xml.dom.minidom.parseString(output) |
|
832 | 833 | paths = [] |
|
833 | 834 | for e in doc.getElementsByTagName('entry'): |
|
834 | 835 | kind = str(e.getAttribute('kind')) |
|
835 | 836 | if kind != 'file': |
|
836 | 837 | continue |
|
837 | 838 | name = ''.join(c.data for c |
|
838 | 839 | in e.getElementsByTagName('name')[0].childNodes |
|
839 | 840 | if c.nodeType == c.TEXT_NODE) |
|
840 | 841 | paths.append(name) |
|
841 | 842 | return paths |
|
842 | 843 | |
|
843 | 844 | def filedata(self, name): |
|
844 | 845 | return self._svncommand(['cat'], name)[0] |
|
845 | 846 | |
|
846 | 847 | |
|
847 | 848 | class gitsubrepo(abstractsubrepo): |
|
848 | 849 | def __init__(self, ctx, path, state): |
|
849 | 850 | self._state = state |
|
850 | 851 | self._ctx = ctx |
|
851 | 852 | self._path = path |
|
852 | 853 | self._relpath = os.path.join(reporelpath(ctx._repo), path) |
|
853 | 854 | self._abspath = ctx._repo.wjoin(path) |
|
854 | 855 | self._subparent = ctx._repo |
|
855 | 856 | self._ui = ctx._repo.ui |
|
856 | 857 | self._ensuregit() |
|
857 | 858 | |
|
858 | 859 | def _ensuregit(self): |
|
859 | 860 | try: |
|
860 | 861 | self._gitexecutable = 'git' |
|
861 | 862 | out, err = self._gitnodir(['--version']) |
|
862 | 863 | except OSError, e: |
|
863 | 864 | if e.errno != 2 or os.name != 'nt': |
|
864 | 865 | raise |
|
865 | 866 | self._gitexecutable = 'git.cmd' |
|
866 | 867 | out, err = self._gitnodir(['--version']) |
|
867 | 868 | m = re.search(r'^git version (\d+)\.(\d+)\.(\d+)', out) |
|
868 | 869 | if not m: |
|
869 | 870 | self._ui.warn(_('cannot retrieve git version')) |
|
870 | 871 | return |
|
871 | 872 | version = (int(m.group(1)), m.group(2), m.group(3)) |
|
872 | 873 | # git 1.4.0 can't work at all, but 1.5.X can in at least some cases, |
|
873 | 874 | # despite the docstring comment. For now, error on 1.4.0, warn on |
|
874 | 875 | # 1.5.0 but attempt to continue. |
|
875 | 876 | if version < (1, 5, 0): |
|
876 | 877 | raise util.Abort(_('git subrepo requires at least 1.6.0 or later')) |
|
877 | 878 | elif version < (1, 6, 0): |
|
878 | 879 | self._ui.warn(_('git subrepo requires at least 1.6.0 or later')) |
|
879 | 880 | |
|
880 | 881 | def _gitcommand(self, commands, env=None, stream=False): |
|
881 | 882 | return self._gitdir(commands, env=env, stream=stream)[0] |
|
882 | 883 | |
|
883 | 884 | def _gitdir(self, commands, env=None, stream=False): |
|
884 | 885 | return self._gitnodir(commands, env=env, stream=stream, |
|
885 | 886 | cwd=self._abspath) |
|
886 | 887 | |
|
887 | 888 | def _gitnodir(self, commands, env=None, stream=False, cwd=None): |
|
888 | 889 | """Calls the git command |
|
889 | 890 | |
|
890 | 891 | The methods tries to call the git command. versions previor to 1.6.0 |
|
891 | 892 | are not supported and very probably fail. |
|
892 | 893 | """ |
|
893 | 894 | self._ui.debug('%s: git %s\n' % (self._relpath, ' '.join(commands))) |
|
894 | 895 | # unless ui.quiet is set, print git's stderr, |
|
895 | 896 | # which is mostly progress and useful info |
|
896 | 897 | errpipe = None |
|
897 | 898 | if self._ui.quiet: |
|
898 | 899 | errpipe = open(os.devnull, 'w') |
|
899 | 900 | p = subprocess.Popen([self._gitexecutable] + commands, bufsize=-1, |
|
900 | 901 | cwd=cwd, env=env, close_fds=util.closefds, |
|
901 | 902 | stdout=subprocess.PIPE, stderr=errpipe) |
|
902 | 903 | if stream: |
|
903 | 904 | return p.stdout, None |
|
904 | 905 | |
|
905 | 906 | retdata = p.stdout.read().strip() |
|
906 | 907 | # wait for the child to exit to avoid race condition. |
|
907 | 908 | p.wait() |
|
908 | 909 | |
|
909 | 910 | if p.returncode != 0 and p.returncode != 1: |
|
910 | 911 | # there are certain error codes that are ok |
|
911 | 912 | command = commands[0] |
|
912 | 913 | if command in ('cat-file', 'symbolic-ref'): |
|
913 | 914 | return retdata, p.returncode |
|
914 | 915 | # for all others, abort |
|
915 | 916 | raise util.Abort('git %s error %d in %s' % |
|
916 | 917 | (command, p.returncode, self._relpath)) |
|
917 | 918 | |
|
918 | 919 | return retdata, p.returncode |
|
919 | 920 | |
|
920 | 921 | def _gitmissing(self): |
|
921 | 922 | return not os.path.exists(os.path.join(self._abspath, '.git')) |
|
922 | 923 | |
|
923 | 924 | def _gitstate(self): |
|
924 | 925 | return self._gitcommand(['rev-parse', 'HEAD']) |
|
925 | 926 | |
|
926 | 927 | def _gitcurrentbranch(self): |
|
927 | 928 | current, err = self._gitdir(['symbolic-ref', 'HEAD', '--quiet']) |
|
928 | 929 | if err: |
|
929 | 930 | current = None |
|
930 | 931 | return current |
|
931 | 932 | |
|
932 | 933 | def _gitremote(self, remote): |
|
933 | 934 | out = self._gitcommand(['remote', 'show', '-n', remote]) |
|
934 | 935 | line = out.split('\n')[1] |
|
935 | 936 | i = line.index('URL: ') + len('URL: ') |
|
936 | 937 | return line[i:] |
|
937 | 938 | |
|
938 | 939 | def _githavelocally(self, revision): |
|
939 | 940 | out, code = self._gitdir(['cat-file', '-e', revision]) |
|
940 | 941 | return code == 0 |
|
941 | 942 | |
|
942 | 943 | def _gitisancestor(self, r1, r2): |
|
943 | 944 | base = self._gitcommand(['merge-base', r1, r2]) |
|
944 | 945 | return base == r1 |
|
945 | 946 | |
|
946 | 947 | def _gitisbare(self): |
|
947 | 948 | return self._gitcommand(['config', '--bool', 'core.bare']) == 'true' |
|
948 | 949 | |
|
949 | 950 | def _gitupdatestat(self): |
|
950 | 951 | """This must be run before git diff-index. |
|
951 | 952 | diff-index only looks at changes to file stat; |
|
952 | 953 | this command looks at file contents and updates the stat.""" |
|
953 | 954 | self._gitcommand(['update-index', '-q', '--refresh']) |
|
954 | 955 | |
|
955 | 956 | def _gitbranchmap(self): |
|
956 | 957 | '''returns 2 things: |
|
957 | 958 | a map from git branch to revision |
|
958 | 959 | a map from revision to branches''' |
|
959 | 960 | branch2rev = {} |
|
960 | 961 | rev2branch = {} |
|
961 | 962 | |
|
962 | 963 | out = self._gitcommand(['for-each-ref', '--format', |
|
963 | 964 | '%(objectname) %(refname)']) |
|
964 | 965 | for line in out.split('\n'): |
|
965 | 966 | revision, ref = line.split(' ') |
|
966 | 967 | if (not ref.startswith('refs/heads/') and |
|
967 | 968 | not ref.startswith('refs/remotes/')): |
|
968 | 969 | continue |
|
969 | 970 | if ref.startswith('refs/remotes/') and ref.endswith('/HEAD'): |
|
970 | 971 | continue # ignore remote/HEAD redirects |
|
971 | 972 | branch2rev[ref] = revision |
|
972 | 973 | rev2branch.setdefault(revision, []).append(ref) |
|
973 | 974 | return branch2rev, rev2branch |
|
974 | 975 | |
|
975 | 976 | def _gittracking(self, branches): |
|
976 | 977 | 'return map of remote branch to local tracking branch' |
|
977 | 978 | # assumes no more than one local tracking branch for each remote |
|
978 | 979 | tracking = {} |
|
979 | 980 | for b in branches: |
|
980 | 981 | if b.startswith('refs/remotes/'): |
|
981 | 982 | continue |
|
982 | 983 | bname = b.split('/', 2)[2] |
|
983 | 984 | remote = self._gitcommand(['config', 'branch.%s.remote' % bname]) |
|
984 | 985 | if remote: |
|
985 | 986 | ref = self._gitcommand(['config', 'branch.%s.merge' % bname]) |
|
986 | 987 | tracking['refs/remotes/%s/%s' % |
|
987 | 988 | (remote, ref.split('/', 2)[2])] = b |
|
988 | 989 | return tracking |
|
989 | 990 | |
|
990 | 991 | def _abssource(self, source): |
|
991 | 992 | if '://' not in source: |
|
992 | 993 | # recognize the scp syntax as an absolute source |
|
993 | 994 | colon = source.find(':') |
|
994 | 995 | if colon != -1 and '/' not in source[:colon]: |
|
995 | 996 | return source |
|
996 | 997 | self._subsource = source |
|
997 | 998 | return _abssource(self) |
|
998 | 999 | |
|
999 | 1000 | def _fetch(self, source, revision): |
|
1000 | 1001 | if self._gitmissing(): |
|
1001 | 1002 | source = self._abssource(source) |
|
1002 | 1003 | self._ui.status(_('cloning subrepo %s from %s\n') % |
|
1003 | 1004 | (self._relpath, source)) |
|
1004 | 1005 | self._gitnodir(['clone', source, self._abspath]) |
|
1005 | 1006 | if self._githavelocally(revision): |
|
1006 | 1007 | return |
|
1007 | 1008 | self._ui.status(_('pulling subrepo %s from %s\n') % |
|
1008 | 1009 | (self._relpath, self._gitremote('origin'))) |
|
1009 | 1010 | # try only origin: the originally cloned repo |
|
1010 | 1011 | self._gitcommand(['fetch']) |
|
1011 | 1012 | if not self._githavelocally(revision): |
|
1012 | 1013 | raise util.Abort(_("revision %s does not exist in subrepo %s\n") % |
|
1013 | 1014 | (revision, self._relpath)) |
|
1014 | 1015 | |
|
1015 | 1016 | def dirty(self, ignoreupdate=False): |
|
1016 | 1017 | if self._gitmissing(): |
|
1017 | 1018 | return self._state[1] != '' |
|
1018 | 1019 | if self._gitisbare(): |
|
1019 | 1020 | return True |
|
1020 | 1021 | if not ignoreupdate and self._state[1] != self._gitstate(): |
|
1021 | 1022 | # different version checked out |
|
1022 | 1023 | return True |
|
1023 | 1024 | # check for staged changes or modified files; ignore untracked files |
|
1024 | 1025 | self._gitupdatestat() |
|
1025 | 1026 | out, code = self._gitdir(['diff-index', '--quiet', 'HEAD']) |
|
1026 | 1027 | return code == 1 |
|
1027 | 1028 | |
|
1028 | 1029 | def basestate(self): |
|
1029 | 1030 | return self._gitstate() |
|
1030 | 1031 | |
|
1031 | 1032 | def get(self, state, overwrite=False): |
|
1032 | 1033 | source, revision, kind = state |
|
1033 | 1034 | if not revision: |
|
1034 | 1035 | self.remove() |
|
1035 | 1036 | return |
|
1036 | 1037 | self._fetch(source, revision) |
|
1037 | 1038 | # if the repo was set to be bare, unbare it |
|
1038 | 1039 | if self._gitisbare(): |
|
1039 | 1040 | self._gitcommand(['config', 'core.bare', 'false']) |
|
1040 | 1041 | if self._gitstate() == revision: |
|
1041 | 1042 | self._gitcommand(['reset', '--hard', 'HEAD']) |
|
1042 | 1043 | return |
|
1043 | 1044 | elif self._gitstate() == revision: |
|
1044 | 1045 | if overwrite: |
|
1045 | 1046 | # first reset the index to unmark new files for commit, because |
|
1046 | 1047 | # reset --hard will otherwise throw away files added for commit, |
|
1047 | 1048 | # not just unmark them. |
|
1048 | 1049 | self._gitcommand(['reset', 'HEAD']) |
|
1049 | 1050 | self._gitcommand(['reset', '--hard', 'HEAD']) |
|
1050 | 1051 | return |
|
1051 | 1052 | branch2rev, rev2branch = self._gitbranchmap() |
|
1052 | 1053 | |
|
1053 | 1054 | def checkout(args): |
|
1054 | 1055 | cmd = ['checkout'] |
|
1055 | 1056 | if overwrite: |
|
1056 | 1057 | # first reset the index to unmark new files for commit, because |
|
1057 | 1058 | # the -f option will otherwise throw away files added for |
|
1058 | 1059 | # commit, not just unmark them. |
|
1059 | 1060 | self._gitcommand(['reset', 'HEAD']) |
|
1060 | 1061 | cmd.append('-f') |
|
1061 | 1062 | self._gitcommand(cmd + args) |
|
1062 | 1063 | |
|
1063 | 1064 | def rawcheckout(): |
|
1064 | 1065 | # no branch to checkout, check it out with no branch |
|
1065 | 1066 | self._ui.warn(_('checking out detached HEAD in subrepo %s\n') % |
|
1066 | 1067 | self._relpath) |
|
1067 | 1068 | self._ui.warn(_('check out a git branch if you intend ' |
|
1068 | 1069 | 'to make changes\n')) |
|
1069 | 1070 | checkout(['-q', revision]) |
|
1070 | 1071 | |
|
1071 | 1072 | if revision not in rev2branch: |
|
1072 | 1073 | rawcheckout() |
|
1073 | 1074 | return |
|
1074 | 1075 | branches = rev2branch[revision] |
|
1075 | 1076 | firstlocalbranch = None |
|
1076 | 1077 | for b in branches: |
|
1077 | 1078 | if b == 'refs/heads/master': |
|
1078 | 1079 | # master trumps all other branches |
|
1079 | 1080 | checkout(['refs/heads/master']) |
|
1080 | 1081 | return |
|
1081 | 1082 | if not firstlocalbranch and not b.startswith('refs/remotes/'): |
|
1082 | 1083 | firstlocalbranch = b |
|
1083 | 1084 | if firstlocalbranch: |
|
1084 | 1085 | checkout([firstlocalbranch]) |
|
1085 | 1086 | return |
|
1086 | 1087 | |
|
1087 | 1088 | tracking = self._gittracking(branch2rev.keys()) |
|
1088 | 1089 | # choose a remote branch already tracked if possible |
|
1089 | 1090 | remote = branches[0] |
|
1090 | 1091 | if remote not in tracking: |
|
1091 | 1092 | for b in branches: |
|
1092 | 1093 | if b in tracking: |
|
1093 | 1094 | remote = b |
|
1094 | 1095 | break |
|
1095 | 1096 | |
|
1096 | 1097 | if remote not in tracking: |
|
1097 | 1098 | # create a new local tracking branch |
|
1098 | 1099 | local = remote.split('/', 2)[2] |
|
1099 | 1100 | checkout(['-b', local, remote]) |
|
1100 | 1101 | elif self._gitisancestor(branch2rev[tracking[remote]], remote): |
|
1101 | 1102 | # When updating to a tracked remote branch, |
|
1102 | 1103 | # if the local tracking branch is downstream of it, |
|
1103 | 1104 | # a normal `git pull` would have performed a "fast-forward merge" |
|
1104 | 1105 | # which is equivalent to updating the local branch to the remote. |
|
1105 | 1106 | # Since we are only looking at branching at update, we need to |
|
1106 | 1107 | # detect this situation and perform this action lazily. |
|
1107 | 1108 | if tracking[remote] != self._gitcurrentbranch(): |
|
1108 | 1109 | checkout([tracking[remote]]) |
|
1109 | 1110 | self._gitcommand(['merge', '--ff', remote]) |
|
1110 | 1111 | else: |
|
1111 | 1112 | # a real merge would be required, just checkout the revision |
|
1112 | 1113 | rawcheckout() |
|
1113 | 1114 | |
|
1114 | 1115 | def commit(self, text, user, date): |
|
1115 | 1116 | if self._gitmissing(): |
|
1116 | 1117 | raise util.Abort(_("subrepo %s is missing") % self._relpath) |
|
1117 | 1118 | cmd = ['commit', '-a', '-m', text] |
|
1118 | 1119 | env = os.environ.copy() |
|
1119 | 1120 | if user: |
|
1120 | 1121 | cmd += ['--author', user] |
|
1121 | 1122 | if date: |
|
1122 | 1123 | # git's date parser silently ignores when seconds < 1e9 |
|
1123 | 1124 | # convert to ISO8601 |
|
1124 | 1125 | env['GIT_AUTHOR_DATE'] = util.datestr(date, |
|
1125 | 1126 | '%Y-%m-%dT%H:%M:%S %1%2') |
|
1126 | 1127 | self._gitcommand(cmd, env=env) |
|
1127 | 1128 | # make sure commit works otherwise HEAD might not exist under certain |
|
1128 | 1129 | # circumstances |
|
1129 | 1130 | return self._gitstate() |
|
1130 | 1131 | |
|
1131 | 1132 | def merge(self, state): |
|
1132 | 1133 | source, revision, kind = state |
|
1133 | 1134 | self._fetch(source, revision) |
|
1134 | 1135 | base = self._gitcommand(['merge-base', revision, self._state[1]]) |
|
1135 | 1136 | self._gitupdatestat() |
|
1136 | 1137 | out, code = self._gitdir(['diff-index', '--quiet', 'HEAD']) |
|
1137 | 1138 | |
|
1138 | 1139 | def mergefunc(): |
|
1139 | 1140 | if base == revision: |
|
1140 | 1141 | self.get(state) # fast forward merge |
|
1141 | 1142 | elif base != self._state[1]: |
|
1142 | 1143 | self._gitcommand(['merge', '--no-commit', revision]) |
|
1143 | 1144 | |
|
1144 | 1145 | if self.dirty(): |
|
1145 | 1146 | if self._gitstate() != revision: |
|
1146 | 1147 | dirty = self._gitstate() == self._state[1] or code != 0 |
|
1147 | 1148 | if _updateprompt(self._ui, self, dirty, |
|
1148 | 1149 | self._state[1][:7], revision[:7]): |
|
1149 | 1150 | mergefunc() |
|
1150 | 1151 | else: |
|
1151 | 1152 | mergefunc() |
|
1152 | 1153 | |
|
1153 | 1154 | def push(self, opts): |
|
1154 | 1155 | force = opts.get('force') |
|
1155 | 1156 | |
|
1156 | 1157 | if not self._state[1]: |
|
1157 | 1158 | return True |
|
1158 | 1159 | if self._gitmissing(): |
|
1159 | 1160 | raise util.Abort(_("subrepo %s is missing") % self._relpath) |
|
1160 | 1161 | # if a branch in origin contains the revision, nothing to do |
|
1161 | 1162 | branch2rev, rev2branch = self._gitbranchmap() |
|
1162 | 1163 | if self._state[1] in rev2branch: |
|
1163 | 1164 | for b in rev2branch[self._state[1]]: |
|
1164 | 1165 | if b.startswith('refs/remotes/origin/'): |
|
1165 | 1166 | return True |
|
1166 | 1167 | for b, revision in branch2rev.iteritems(): |
|
1167 | 1168 | if b.startswith('refs/remotes/origin/'): |
|
1168 | 1169 | if self._gitisancestor(self._state[1], revision): |
|
1169 | 1170 | return True |
|
1170 | 1171 | # otherwise, try to push the currently checked out branch |
|
1171 | 1172 | cmd = ['push'] |
|
1172 | 1173 | if force: |
|
1173 | 1174 | cmd.append('--force') |
|
1174 | 1175 | |
|
1175 | 1176 | current = self._gitcurrentbranch() |
|
1176 | 1177 | if current: |
|
1177 | 1178 | # determine if the current branch is even useful |
|
1178 | 1179 | if not self._gitisancestor(self._state[1], current): |
|
1179 | 1180 | self._ui.warn(_('unrelated git branch checked out ' |
|
1180 | 1181 | 'in subrepo %s\n') % self._relpath) |
|
1181 | 1182 | return False |
|
1182 | 1183 | self._ui.status(_('pushing branch %s of subrepo %s\n') % |
|
1183 | 1184 | (current.split('/', 2)[2], self._relpath)) |
|
1184 | 1185 | self._gitcommand(cmd + ['origin', current]) |
|
1185 | 1186 | return True |
|
1186 | 1187 | else: |
|
1187 | 1188 | self._ui.warn(_('no branch checked out in subrepo %s\n' |
|
1188 | 1189 | 'cannot push revision %s\n') % |
|
1189 | 1190 | (self._relpath, self._state[1])) |
|
1190 | 1191 | return False |
|
1191 | 1192 | |
|
1192 | 1193 | def remove(self): |
|
1193 | 1194 | if self._gitmissing(): |
|
1194 | 1195 | return |
|
1195 | 1196 | if self.dirty(): |
|
1196 | 1197 | self._ui.warn(_('not removing repo %s because ' |
|
1197 | 1198 | 'it has changes.\n') % self._relpath) |
|
1198 | 1199 | return |
|
1199 | 1200 | # we can't fully delete the repository as it may contain |
|
1200 | 1201 | # local-only history |
|
1201 | 1202 | self._ui.note(_('removing subrepo %s\n') % self._relpath) |
|
1202 | 1203 | self._gitcommand(['config', 'core.bare', 'true']) |
|
1203 | 1204 | for f in os.listdir(self._abspath): |
|
1204 | 1205 | if f == '.git': |
|
1205 | 1206 | continue |
|
1206 | 1207 | path = os.path.join(self._abspath, f) |
|
1207 | 1208 | if os.path.isdir(path) and not os.path.islink(path): |
|
1208 | 1209 | shutil.rmtree(path) |
|
1209 | 1210 | else: |
|
1210 | 1211 | os.remove(path) |
|
1211 | 1212 | |
|
1212 | 1213 | def archive(self, ui, archiver, prefix, match=None): |
|
1213 | 1214 | source, revision = self._state |
|
1214 | 1215 | if not revision: |
|
1215 | 1216 | return |
|
1216 | 1217 | self._fetch(source, revision) |
|
1217 | 1218 | |
|
1218 | 1219 | # Parse git's native archive command. |
|
1219 | 1220 | # This should be much faster than manually traversing the trees |
|
1220 | 1221 | # and objects with many subprocess calls. |
|
1221 | 1222 | tarstream = self._gitcommand(['archive', revision], stream=True) |
|
1222 | 1223 | tar = tarfile.open(fileobj=tarstream, mode='r|') |
|
1223 | 1224 | relpath = subrelpath(self) |
|
1224 | 1225 | ui.progress(_('archiving (%s)') % relpath, 0, unit=_('files')) |
|
1225 | 1226 | for i, info in enumerate(tar): |
|
1226 | 1227 | if info.isdir(): |
|
1227 | 1228 | continue |
|
1228 | 1229 | if match and not match(info.name): |
|
1229 | 1230 | continue |
|
1230 | 1231 | if info.issym(): |
|
1231 | 1232 | data = info.linkname |
|
1232 | 1233 | else: |
|
1233 | 1234 | data = tar.extractfile(info).read() |
|
1234 | 1235 | archiver.addfile(os.path.join(prefix, self._path, info.name), |
|
1235 | 1236 | info.mode, info.issym(), data) |
|
1236 | 1237 | ui.progress(_('archiving (%s)') % relpath, i + 1, |
|
1237 | 1238 | unit=_('files')) |
|
1238 | 1239 | ui.progress(_('archiving (%s)') % relpath, None) |
|
1239 | 1240 | |
|
1240 | 1241 | |
|
1241 | 1242 | def status(self, rev2, **opts): |
|
1242 | 1243 | rev1 = self._state[1] |
|
1243 | 1244 | if self._gitmissing() or not rev1: |
|
1244 | 1245 | # if the repo is missing, return no results |
|
1245 | 1246 | return [], [], [], [], [], [], [] |
|
1246 | 1247 | modified, added, removed = [], [], [] |
|
1247 | 1248 | self._gitupdatestat() |
|
1248 | 1249 | if rev2: |
|
1249 | 1250 | command = ['diff-tree', rev1, rev2] |
|
1250 | 1251 | else: |
|
1251 | 1252 | command = ['diff-index', rev1] |
|
1252 | 1253 | out = self._gitcommand(command) |
|
1253 | 1254 | for line in out.split('\n'): |
|
1254 | 1255 | tab = line.find('\t') |
|
1255 | 1256 | if tab == -1: |
|
1256 | 1257 | continue |
|
1257 | 1258 | status, f = line[tab - 1], line[tab + 1:] |
|
1258 | 1259 | if status == 'M': |
|
1259 | 1260 | modified.append(f) |
|
1260 | 1261 | elif status == 'A': |
|
1261 | 1262 | added.append(f) |
|
1262 | 1263 | elif status == 'D': |
|
1263 | 1264 | removed.append(f) |
|
1264 | 1265 | |
|
1265 | 1266 | deleted = unknown = ignored = clean = [] |
|
1266 | 1267 | return modified, added, removed, deleted, unknown, ignored, clean |
|
1267 | 1268 | |
|
1268 | 1269 | types = { |
|
1269 | 1270 | 'hg': hgsubrepo, |
|
1270 | 1271 | 'svn': svnsubrepo, |
|
1271 | 1272 | 'git': gitsubrepo, |
|
1272 | 1273 | } |
General Comments 0
You need to be logged in to leave comments.
Login now