# HG changeset patch # User Kyle Lippincott # Date 2019-08-27 18:56:15 # Node ID 1fd530b1e1cfbed016eacd4d1daa0bb109b693ca # Parent db51a4ac85ac27c37bf1b602c2183b82e447071f split: handle partial commit of copies when doing split or record When using split or record, using either interface (text or curses), selecting portions of the file to be committed/recorded did not work; the entire file was treated as having been selected. This appears to be because the logic for handling partial application of the patches relies on knowing what files are "new with modifications", and it doesn't treat "copy destination" as "new". Handling renames correctly is more difficult and will be done in a later patch. Differential Revision: https://phab.mercurial-scm.org/D6767 diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -864,7 +864,7 @@ class header(object): allhunks_re = re.compile('(?:index|deleted file) ') pretty_re = re.compile('(?:new file|deleted file) ') special_re = re.compile('(?:index|deleted|copy|rename|new mode) ') - newfile_re = re.compile('(?:new file)') + newfile_re = re.compile('(?:new file|copy to)') def __init__(self, header): self.header = header diff --git a/tests/test-split.t b/tests/test-split.t --- a/tests/test-split.t +++ b/tests/test-split.t @@ -789,3 +789,100 @@ TODO: Fix this on Windows. See issue 202 abort: cannot split an empty revision [255] #endif + +Test that splitting copies works properly (issue5723) +---------------------------------------------------- + + $ hg init $TESTTMP/issue5723-cp + $ cd $TESTTMP/issue5723-cp + $ printf '1\n2\n' > file + $ hg ci -qAm initial + $ hg cp file file2 + $ printf 'a\nb\n1\n2\n3\n4\n' > file2 +Also modify 'file' to prove that the changes aren't being pulled in +accidentally. + $ printf 'this is the new contents of "file"' > file + $ cat > $TESTTMP/messages < split1, keeping "file" and only the numbered lines in file2 + > -- + > split2, keeping the lettered lines in file2 + > EOF + $ hg ci -m 'copy file->file2, modify both' + $ printf 'f\ny\nn\na\na\n' | hg split + diff --git a/file b/file + 1 hunks, 2 lines changed + examine changes to 'file'? + (enter ? for help) [Ynesfdaq?] f + + diff --git a/file b/file2 + copy from file + copy to file2 + 2 hunks, 4 lines changed + examine changes to 'file' and 'file2'? + (enter ? for help) [Ynesfdaq?] y + + @@ -0,0 +1,2 @@ + +a + +b + record change 2/3 to 'file2'? + (enter ? for help) [Ynesfdaq?] n + + @@ -2,0 +5,2 @@ 2 + +3 + +4 + record change 3/3 to 'file2'? + (enter ? for help) [Ynesfdaq?] a + + EDITOR: HG: Splitting 41c861dfa61e. Write commit message for the first split changeset. + EDITOR: copy file->file2, modify both + EDITOR: + EDITOR: + EDITOR: HG: Enter commit message. Lines beginning with 'HG:' are removed. + EDITOR: HG: Leave message empty to abort commit. + EDITOR: HG: -- + EDITOR: HG: user: test + EDITOR: HG: branch 'default' + EDITOR: HG: added file2 + EDITOR: HG: changed file + created new head + diff --git a/file2 b/file2 + 1 hunks, 2 lines changed + examine changes to 'file2'? + (enter ? for help) [Ynesfdaq?] a + + EDITOR: HG: Splitting 41c861dfa61e. So far it has been split into: + EDITOR: HG: - 4b19e06610eb: split1, keeping "file" and only the numbered lines in file2 + EDITOR: HG: Write commit message for the next split changeset. + EDITOR: copy file->file2, modify both + EDITOR: + EDITOR: + EDITOR: HG: Enter commit message. Lines beginning with 'HG:' are removed. + EDITOR: HG: Leave message empty to abort commit. + EDITOR: HG: -- + EDITOR: HG: user: test + EDITOR: HG: branch 'default' + EDITOR: HG: changed file2 + saved backup bundle to $TESTTMP/issue5723-cp/.hg/strip-backup/41c861dfa61e-467e8d3c-split.hg (obsstore-off !) + $ hg log -T '{desc}: {files%"{file} "}\n' + split2, keeping the lettered lines in file2: file2 + split1, keeping "file" and only the numbered lines in file2: file file2 + initial: file + $ cat file2 + a + b + 1 + 2 + 3 + 4 + $ hg cat -r ".^" file2 + 1 + 2 + 3 + 4 + $ hg cat -r . file2 + a + b + 1 + 2 + 3 + 4