##// END OF EJS Templates
cmdutil: fix newandmodified file accounting for --interactive commits...
Daniel Ploch -
r48365:00ae1fb6 default
parent child Browse files
Show More
@@ -346,19 +346,18 b' def ishunk(x):'
346 return isinstance(x, hunkclasses)
346 return isinstance(x, hunkclasses)
347
347
348
348
349 def newandmodified(chunks, originalchunks):
349 def isheader(x):
350 headerclasses = (crecordmod.uiheader, patch.header)
351 return isinstance(x, headerclasses)
352
353
354 def newandmodified(chunks):
350 newlyaddedandmodifiedfiles = set()
355 newlyaddedandmodifiedfiles = set()
351 alsorestore = set()
356 alsorestore = set()
352 for chunk in chunks:
357 for chunk in chunks:
353 if (
358 if isheader(chunk) and chunk.isnewfile():
354 ishunk(chunk)
359 newlyaddedandmodifiedfiles.add(chunk.filename())
355 and chunk.header.isnewfile()
360 alsorestore.update(set(chunk.files()) - {chunk.filename()})
356 and chunk not in originalchunks
357 ):
358 newlyaddedandmodifiedfiles.add(chunk.header.filename())
359 alsorestore.update(
360 set(chunk.header.files()) - {chunk.header.filename()}
361 )
362 return newlyaddedandmodifiedfiles, alsorestore
361 return newlyaddedandmodifiedfiles, alsorestore
363
362
364
363
@@ -517,12 +516,12 b' def dorecord('
517 diffopts.git = True
516 diffopts.git = True
518 diffopts.showfunc = True
517 diffopts.showfunc = True
519 originaldiff = patch.diff(repo, changes=status, opts=diffopts)
518 originaldiff = patch.diff(repo, changes=status, opts=diffopts)
520 originalchunks = patch.parsepatch(originaldiff)
519 original_headers = patch.parsepatch(originaldiff)
521 match = scmutil.match(repo[None], pats)
520 match = scmutil.match(repo[None], pats)
522
521
523 # 1. filter patch, since we are intending to apply subset of it
522 # 1. filter patch, since we are intending to apply subset of it
524 try:
523 try:
525 chunks, newopts = filterfn(ui, originalchunks, match)
524 chunks, newopts = filterfn(ui, original_headers, match)
526 except error.PatchError as err:
525 except error.PatchError as err:
527 raise error.InputError(_(b'error parsing patch: %s') % err)
526 raise error.InputError(_(b'error parsing patch: %s') % err)
528 opts.update(newopts)
527 opts.update(newopts)
@@ -532,15 +531,11 b' def dorecord('
532 # version without the edit in the workdir. We also will need to restore
531 # version without the edit in the workdir. We also will need to restore
533 # files that were the sources of renames so that the patch application
532 # files that were the sources of renames so that the patch application
534 # works.
533 # works.
535 newlyaddedandmodifiedfiles, alsorestore = newandmodified(
534 newlyaddedandmodifiedfiles, alsorestore = newandmodified(chunks)
536 chunks, originalchunks
537 )
538 contenders = set()
535 contenders = set()
539 for h in chunks:
536 for h in chunks:
540 try:
537 if isheader(h):
541 contenders.update(set(h.files()))
538 contenders.update(set(h.files()))
542 except AttributeError:
543 pass
544
539
545 changed = status.modified + status.added + status.removed
540 changed = status.modified + status.added + status.removed
546 newfiles = [f for f in changed if f in contenders]
541 newfiles = [f for f in changed if f in contenders]
@@ -3630,12 +3625,12 b' def _performrevert('
3630 diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
3625 diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
3631 else:
3626 else:
3632 diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
3627 diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
3633 originalchunks = patch.parsepatch(diff)
3628 original_headers = patch.parsepatch(diff)
3634
3629
3635 try:
3630 try:
3636
3631
3637 chunks, opts = recordfilter(
3632 chunks, opts = recordfilter(
3638 repo.ui, originalchunks, match, operation=operation
3633 repo.ui, original_headers, match, operation=operation
3639 )
3634 )
3640 if operation == b'discard':
3635 if operation == b'discard':
3641 chunks = patch.reversehunks(chunks)
3636 chunks = patch.reversehunks(chunks)
@@ -3648,9 +3643,7 b' def _performrevert('
3648 # "remove added file <name> (Yn)?", so we don't need to worry about the
3643 # "remove added file <name> (Yn)?", so we don't need to worry about the
3649 # alsorestore value. Ideally we'd be able to partially revert
3644 # alsorestore value. Ideally we'd be able to partially revert
3650 # copied/renamed files.
3645 # copied/renamed files.
3651 newlyaddedandmodifiedfiles, unusedalsorestore = newandmodified(
3646 newlyaddedandmodifiedfiles, unusedalsorestore = newandmodified(chunks)
3652 chunks, originalchunks
3653 )
3654 if tobackup is None:
3647 if tobackup is None:
3655 tobackup = set()
3648 tobackup = set()
3656 # Apply changes
3649 # Apply changes
@@ -1713,20 +1713,58 b' Moving files'
1713 record this change to 'plain3'?
1713 record this change to 'plain3'?
1714 (enter ? for help) [Ynesfdaq?] y
1714 (enter ? for help) [Ynesfdaq?] y
1715
1715
1716
1717 Rename file but discard edits
1718
1719 $ echo content > new-file
1720 $ hg add -q new-file
1721 $ hg commit -qm 'new file'
1722 $ hg mv new-file renamed-file
1723 $ echo new-content >> renamed-file
1724 $ hg commit -i -d '24 0' -m content-rename<<EOF
1725 > y
1726 > n
1727 > EOF
1728 diff --git a/new-file b/renamed-file
1729 rename from new-file
1730 rename to renamed-file
1731 1 hunks, 1 lines changed
1732 examine changes to 'new-file' and 'renamed-file'?
1733 (enter ? for help) [Ynesfdaq?] y
1734
1735 @@ -1,1 +1,2 @@
1736 content
1737 +new-content
1738 record this change to 'renamed-file'?
1739 (enter ? for help) [Ynesfdaq?] n
1740
1741 $ hg status
1742 M renamed-file
1743 ? editedfile.orig
1744 ? editedfile.rej
1745 ? editor.sh
1746 $ hg diff
1747 diff -r * renamed-file (glob)
1748 --- a/renamed-file Thu Jan 01 00:00:24 1970 +0000
1749 +++ b/renamed-file Thu Jan 01 00:00:00 1970 +0000
1750 @@ -1,1 +1,2 @@
1751 content
1752 +new-content
1753
1716 The #if execbit block above changes the hash here on some systems
1754 The #if execbit block above changes the hash here on some systems
1717 $ hg status -A plain3
1755 $ hg status -A plain3
1718 C plain3
1756 C plain3
1719 $ hg tip
1757 $ hg tip
1720 changeset: 32:* (glob)
1758 changeset: 34:* (glob)
1721 tag: tip
1759 tag: tip
1722 user: test
1760 user: test
1723 date: Thu Jan 01 00:00:23 1970 +0000
1761 date: Thu Jan 01 00:00:24 1970 +0000
1724 summary: moving_files
1762 summary: content-rename
1725
1763
1726 Editing patch of newly added file
1764 Editing patch of newly added file
1727
1765
1728 $ hg update -C .
1766 $ hg update -C .
1729 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1767 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1730 $ cat > editor.sh << '__EOF__'
1768 $ cat > editor.sh << '__EOF__'
1731 > cat "$1" | sed "s/first/very/g" > tt
1769 > cat "$1" | sed "s/first/very/g" > tt
1732 > mv tt "$1"
1770 > mv tt "$1"
@@ -1737,7 +1775,7 b' Editing patch of newly added file'
1737 > This is the third line
1775 > This is the third line
1738 > __EOF__
1776 > __EOF__
1739 $ hg add newfile
1777 $ hg add newfile
1740 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -d '23 0' -medit-patch-new <<EOF
1778 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -d '25 0' -medit-patch-new <<EOF
1741 > y
1779 > y
1742 > e
1780 > e
1743 > EOF
1781 > EOF
@@ -1770,7 +1808,7 b' Add new file from within a subdirectory'
1770 $ cd folder
1808 $ cd folder
1771 $ echo "foo" > bar
1809 $ echo "foo" > bar
1772 $ hg add bar
1810 $ hg add bar
1773 $ hg commit -i -d '23 0' -mnewfilesubdir <<EOF
1811 $ hg commit -i -d '26 0' -mnewfilesubdir <<EOF
1774 > y
1812 > y
1775 > y
1813 > y
1776 > EOF
1814 > EOF
@@ -1786,15 +1824,15 b' Add new file from within a subdirectory'
1786
1824
1787 The #if execbit block above changes the hashes here on some systems
1825 The #if execbit block above changes the hashes here on some systems
1788 $ hg tip -p
1826 $ hg tip -p
1789 changeset: 34:* (glob)
1827 changeset: 36:* (glob)
1790 tag: tip
1828 tag: tip
1791 user: test
1829 user: test
1792 date: Thu Jan 01 00:00:23 1970 +0000
1830 date: Thu Jan 01 00:00:26 1970 +0000
1793 summary: newfilesubdir
1831 summary: newfilesubdir
1794
1832
1795 diff -r * -r * folder/bar (glob)
1833 diff -r * -r * folder/bar (glob)
1796 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1834 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1797 +++ b/folder/bar Thu Jan 01 00:00:23 1970 +0000
1835 +++ b/folder/bar Thu Jan 01 00:00:26 1970 +0000
1798 @@ -0,0 +1,1 @@
1836 @@ -0,0 +1,1 @@
1799 +foo
1837 +foo
1800
1838
General Comments 0
You need to be logged in to leave comments. Login now