# HG changeset patch # User Laurent Charignon # Date 1425686263 28800 # Node ID 79fceed676763ca219031ea67161b55c5747bf50 # Parent 7977d35df13b40ebdf4e306b2c3c6f226c692cb4 record: allow editing new files (issue4304) While using the record extension to select changes, the user couldn't see the content of newly added files and had to select/reject them based on filename. The test is changed accordingly in two places. diff -r 7977d35df13b -r 79fceed67676 hgext/record.py --- a/hgext/record.py Thu Mar 05 14:42:25 2015 -0800 +++ b/hgext/record.py Fri Mar 06 15:57:43 2015 -0800 @@ -76,7 +76,7 @@ """ diffgit_re = re.compile('diff --git a/(.*) b/(.*)$') diff_re = re.compile('diff -r .* (.*)$') - allhunks_re = re.compile('(?:index|new file|deleted file) ') + allhunks_re = re.compile('(?:index|deleted file) ') pretty_re = re.compile('(?:new file|deleted file) ') special_re = re.compile('(?:index|new|deleted|copy|rename) ') @@ -522,9 +522,9 @@ diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True) diffopts.nodates = True diffopts.git = True - chunks = patch.diff(repo, changes=status, opts=diffopts) + originalchunks = patch.diff(repo, changes=status, opts=diffopts) fp = cStringIO.StringIO() - fp.write(''.join(chunks)) + fp.write(''.join(originalchunks)) fp.seek(0) # 1. filter patch, so we have intending-to apply subset of it @@ -548,13 +548,22 @@ ui.status(_('no changes to record\n')) return 0 + newandmodifiedfiles = set() + for h in chunks: + ishunk = isinstance(h, hunk) + isnew = h.filename() in status.added + if ishunk and isnew and not h in originalchunks: + newandmodifiedfiles.add(h.filename()) + modified = set(status.modified) # 2. backup changed files, so we can restore them in the end + if backupall: tobackup = changed else: - tobackup = [f for f in newfiles if f in modified] + tobackup = [f for f in newfiles + if f in modified or f in newandmodifiedfiles] backups = {} if tobackup: @@ -577,11 +586,14 @@ fp = cStringIO.StringIO() for c in chunks: - if c.filename() in backups: + fname = c.filename() + if fname in backups or fname in newandmodifiedfiles: c.write(fp) dopatch = fp.tell() fp.seek(0) + [os.unlink(c) for c in newandmodifiedfiles] + # 3a. apply filtered patch to clean repo (clean) if backups: hg.revert(repo, repo.dirstate.p1(), diff -r 7977d35df13b -r 79fceed67676 tests/test-keyword.t --- a/tests/test-keyword.t Thu Mar 05 14:42:25 2015 -0800 +++ b/tests/test-keyword.t Fri Mar 06 15:57:43 2015 -0800 @@ -473,18 +473,24 @@ $ hg -v record -l msg -d '12 2' r< y + > y > EOF diff --git a/r b/r new file mode 100644 examine changes to 'r'? [Ynesfdaq?] y + @@ -0,0 +1,1 @@ + +$Id$ + record this change to 'r'? [Ynesfdaq?] y + + resolving manifests + patching file r committing files: r committing manifest committing changelog committed changeset 3:82a2f715724d overwriting r expanding keywords - - status call required for dirstate.normallookup() check $ hg status r $ hg --verbose rollback repository tip rolled back to revision 2 (undo commit) @@ -501,11 +507,18 @@ $ hg add i $ hg --verbose record -d '13 1' -m recignored< y + > y > EOF diff --git a/i b/i new file mode 100644 examine changes to 'i'? [Ynesfdaq?] y + @@ -0,0 +1,1 @@ + +$Id$ + record this change to 'i'? [Ynesfdaq?] y + + resolving manifests + patching file i committing files: i committing manifest diff -r 7977d35df13b -r 79fceed67676 tests/test-mq-subrepo.t --- a/tests/test-mq-subrepo.t Thu Mar 05 14:42:25 2015 -0800 +++ b/tests/test-mq-subrepo.t Fri Mar 06 15:57:43 2015 -0800 @@ -295,6 +295,11 @@ new file mode 100644 examine changes to '.hgsub'? [Ynesfdaq?] y + @@ -0,0 +1,1 @@ + +sub = sub + record this change to '.hgsub'? [Ynesfdaq?] y + + warning: subrepo spec file .hgsub not found abort: uncommitted changes in subrepository sub [255] % update substate when adding .hgsub w/clean updated subrepo @@ -304,10 +309,14 @@ new file mode 100644 examine changes to '.hgsub'? [Ynesfdaq?] y + @@ -0,0 +1,1 @@ + +sub = sub + record this change to '.hgsub'? [Ynesfdaq?] y + + warning: subrepo spec file .hgsub not found path sub source sub revision b2fdb12cd82b021c3b7053d67802e77b6eeaee31 - $ testmod qrecord --config ui.interactive=1 -m1 1.diff < y > y diff -r 7977d35df13b -r 79fceed67676 tests/test-record.t --- a/tests/test-record.t Thu Mar 05 14:42:25 2015 -0800 +++ b/tests/test-record.t Fri Mar 06 15:57:43 2015 -0800 @@ -235,7 +235,19 @@ new file mode 100644 examine changes to 'plain'? [Ynesfdaq?] y - + @@ -0,0 +1,10 @@ + +1 + +2 + +3 + +4 + +5 + +6 + +7 + +8 + +9 + +10 + record this change to 'plain'? [Ynesfdaq?] y + $ hg tip -p changeset: 7:11fb457c1be4 tag: tip @@ -317,6 +329,7 @@ > y > y > y + > y > EOF diff --git a/plain b/plain 1 hunks, 1 lines changed @@ -335,7 +348,10 @@ new file mode 100644 examine changes to 'plain2'? [Ynesfdaq?] y - + @@ -0,0 +1,1 @@ + +1 + record change 2/2 to 'plain2'? [Ynesfdaq?] y + Modify beginning, trim end, record both, add another file to test changes numbering @@ -1353,6 +1369,8 @@ c +d + + Test --user when ui.username not set $ unset HGUSER $ echo e >> subdir/f1 @@ -1376,4 +1394,41 @@ $ HGUSER="test" $ export HGUSER + +Editing patch of newly added file + + $ cat > editor.sh << '__EOF__' + > cat "$1" | sed "s/first/very/g" > tt + > mv tt "$1" + > __EOF__ + $ cat > newfile << '__EOF__' + > This is the first line + > This is the second line + > This is the third line + > __EOF__ + $ hg add newfile + $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record -d '23 0' -medit-patch-new < y + > e + > EOF + diff --git a/newfile b/newfile + new file mode 100644 + examine changes to 'newfile'? [Ynesfdaq?] y + + @@ -0,0 +1,3 @@ + +This is the first line + +This is the second line + +This is the third line + record this change to 'newfile'? [Ynesfdaq?] e + + $ hg cat -r tip newfile + This is the very line + This is the second line + This is the third line + + $ cat newfile + This is the first line + This is the second line + This is the third line + $ cd ..