Show More
@@ -3139,10 +3139,21 b' def _performrevert(repo, parents, ctx, a' | |||||
3139 | diffopts = patch.difffeatureopts(repo.ui, whitespace=True) |
|
3139 | diffopts = patch.difffeatureopts(repo.ui, whitespace=True) | |
3140 | diffopts.nodates = True |
|
3140 | diffopts.nodates = True | |
3141 | diffopts.git = True |
|
3141 | diffopts.git = True | |
|
3142 | reversehunks = repo.ui.configbool('experimental', | |||
|
3143 | 'revertalternateinteractivemode', | |||
|
3144 | False) | |||
|
3145 | if reversehunks: | |||
|
3146 | diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts) | |||
|
3147 | else: | |||
3142 | diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts) |
|
3148 | diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts) | |
3143 | originalchunks = patch.parsepatch(diff) |
|
3149 | originalchunks = patch.parsepatch(diff) | |
|
3150 | ||||
3144 | try: |
|
3151 | try: | |
|
3152 | ||||
3145 | chunks = recordfilter(repo.ui, originalchunks) |
|
3153 | chunks = recordfilter(repo.ui, originalchunks) | |
|
3154 | if reversehunks: | |||
|
3155 | chunks = patch.reversehunks(chunks) | |||
|
3156 | ||||
3146 | except patch.PatchError, err: |
|
3157 | except patch.PatchError, err: | |
3147 | raise util.Abort(_('error parsing patch: %s') % err) |
|
3158 | raise util.Abort(_('error parsing patch: %s') % err) | |
3148 |
|
3159 |
@@ -1385,6 +1385,77 b' def parsefilename(str):' | |||||
1385 | return s |
|
1385 | return s | |
1386 | return s[:i] |
|
1386 | return s[:i] | |
1387 |
|
1387 | |||
|
1388 | def reversehunks(hunks): | |||
|
1389 | '''reverse the signs in the hunks given as argument | |||
|
1390 | ||||
|
1391 | This function operates on hunks coming out of patch.filterpatch, that is | |||
|
1392 | a list of the form: [header1, hunk1, hunk2, header2...]. Example usage: | |||
|
1393 | ||||
|
1394 | >>> rawpatch = """diff --git a/folder1/g b/folder1/g | |||
|
1395 | ... --- a/folder1/g | |||
|
1396 | ... +++ b/folder1/g | |||
|
1397 | ... @@ -1,7 +1,7 @@ | |||
|
1398 | ... +firstline | |||
|
1399 | ... c | |||
|
1400 | ... 1 | |||
|
1401 | ... 2 | |||
|
1402 | ... + 3 | |||
|
1403 | ... -4 | |||
|
1404 | ... 5 | |||
|
1405 | ... d | |||
|
1406 | ... +lastline""" | |||
|
1407 | >>> hunks = parsepatch(rawpatch) | |||
|
1408 | >>> hunkscomingfromfilterpatch = [] | |||
|
1409 | >>> for h in hunks: | |||
|
1410 | ... hunkscomingfromfilterpatch.append(h) | |||
|
1411 | ... hunkscomingfromfilterpatch.extend(h.hunks) | |||
|
1412 | ||||
|
1413 | >>> reversedhunks = reversehunks(hunkscomingfromfilterpatch) | |||
|
1414 | >>> fp = cStringIO.StringIO() | |||
|
1415 | >>> for c in reversedhunks: | |||
|
1416 | ... c.write(fp) | |||
|
1417 | >>> fp.seek(0) | |||
|
1418 | >>> reversedpatch = fp.read() | |||
|
1419 | >>> print reversedpatch | |||
|
1420 | diff --git a/folder1/g b/folder1/g | |||
|
1421 | --- a/folder1/g | |||
|
1422 | +++ b/folder1/g | |||
|
1423 | @@ -1,4 +1,3 @@ | |||
|
1424 | -firstline | |||
|
1425 | c | |||
|
1426 | 1 | |||
|
1427 | 2 | |||
|
1428 | @@ -1,6 +2,6 @@ | |||
|
1429 | c | |||
|
1430 | 1 | |||
|
1431 | 2 | |||
|
1432 | - 3 | |||
|
1433 | +4 | |||
|
1434 | 5 | |||
|
1435 | d | |||
|
1436 | @@ -5,3 +6,2 @@ | |||
|
1437 | 5 | |||
|
1438 | d | |||
|
1439 | -lastline | |||
|
1440 | ||||
|
1441 | ''' | |||
|
1442 | ||||
|
1443 | import crecord as crecordmod | |||
|
1444 | newhunks = [] | |||
|
1445 | for c in hunks: | |||
|
1446 | if isinstance(c, crecordmod.uihunk): | |||
|
1447 | # curses hunks encapsulate the record hunk in _hunk | |||
|
1448 | c = c._hunk | |||
|
1449 | if isinstance(c, recordhunk): | |||
|
1450 | for j, line in enumerate(c.hunk): | |||
|
1451 | if line.startswith("-"): | |||
|
1452 | c.hunk[j] = "+" + c.hunk[j][1:] | |||
|
1453 | elif line.startswith("+"): | |||
|
1454 | c.hunk[j] = "-" + c.hunk[j][1:] | |||
|
1455 | c.added, c.removed = c.removed, c.added | |||
|
1456 | newhunks.append(c) | |||
|
1457 | return newhunks | |||
|
1458 | ||||
1388 | def parsepatch(originalchunks): |
|
1459 | def parsepatch(originalchunks): | |
1389 | """patch -> [] of headers -> [] of hunks """ |
|
1460 | """patch -> [] of headers -> [] of hunks """ | |
1390 | class parser(object): |
|
1461 | class parser(object): |
@@ -320,3 +320,74 b' 4) Use interactive revert to recover f a' | |||||
320 | 4 |
|
320 | 4 | |
321 | 5 |
|
321 | 5 | |
322 | b |
|
322 | b | |
|
323 | ||||
|
324 | Check the experimental config to invert the selection: | |||
|
325 | $ cat <<EOF >> $HGRCPATH | |||
|
326 | > [experimental] | |||
|
327 | > revertalternateinteractivemode=True | |||
|
328 | > EOF | |||
|
329 | ||||
|
330 | ||||
|
331 | $ hg up -C . | |||
|
332 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |||
|
333 | $ printf 'firstline\nc\n1\n2\n3\n 3\n5\nd\nlastline\n' > folder1/g | |||
|
334 | $ hg diff --nodates | |||
|
335 | diff -r 5a858e056dc0 folder1/g | |||
|
336 | --- a/folder1/g | |||
|
337 | +++ b/folder1/g | |||
|
338 | @@ -1,7 +1,9 @@ | |||
|
339 | +firstline | |||
|
340 | c | |||
|
341 | 1 | |||
|
342 | 2 | |||
|
343 | 3 | |||
|
344 | -4 | |||
|
345 | + 3 | |||
|
346 | 5 | |||
|
347 | d | |||
|
348 | +lastline | |||
|
349 | $ hg revert -i <<EOF | |||
|
350 | > y | |||
|
351 | > y | |||
|
352 | > y | |||
|
353 | > n | |||
|
354 | > EOF | |||
|
355 | reverting folder1/g (glob) | |||
|
356 | diff --git a/folder1/g b/folder1/g | |||
|
357 | 3 hunks, 3 lines changed | |||
|
358 | examine changes to 'folder1/g'? [Ynesfdaq?] y | |||
|
359 | ||||
|
360 | @@ -1,4 +1,5 @@ | |||
|
361 | +firstline | |||
|
362 | c | |||
|
363 | 1 | |||
|
364 | 2 | |||
|
365 | 3 | |||
|
366 | record change 1/3 to 'folder1/g'? [Ynesfdaq?] y | |||
|
367 | ||||
|
368 | @@ -1,7 +2,7 @@ | |||
|
369 | c | |||
|
370 | 1 | |||
|
371 | 2 | |||
|
372 | 3 | |||
|
373 | -4 | |||
|
374 | + 3 | |||
|
375 | 5 | |||
|
376 | d | |||
|
377 | record change 2/3 to 'folder1/g'? [Ynesfdaq?] y | |||
|
378 | ||||
|
379 | @@ -6,2 +7,3 @@ | |||
|
380 | 5 | |||
|
381 | d | |||
|
382 | +lastline | |||
|
383 | record change 3/3 to 'folder1/g'? [Ynesfdaq?] n | |||
|
384 | ||||
|
385 | $ hg diff --nodates | |||
|
386 | diff -r 5a858e056dc0 folder1/g | |||
|
387 | --- a/folder1/g | |||
|
388 | +++ b/folder1/g | |||
|
389 | @@ -5,3 +5,4 @@ | |||
|
390 | 4 | |||
|
391 | 5 | |||
|
392 | d | |||
|
393 | +lastline |
General Comments 0
You need to be logged in to leave comments.
Login now