Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 24845:8133494accf1 stable
record: edit patch of newly added files (issue4304)
I tried to fix this issue in the past and had to revert the fix. This is a
second attempt without the regression we found with the first one.
record defines special headers (of file) as headers whose hunk are not shown
to the user for editing, they are used to represent deleted, moved and new
files. Since we want to authorize editing the patch of newly added file we
make the newly added file with some content not special anymore. This entails
that we have to save their content before applying the backup to be able to
revert it if the patch does not apply properly.
We reintroduce the test showing that newly added files can be edited and that
their content is shown to the user.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Thu, 23 Apr 2015 14:27:26 -0700 |
parents | 21b33f0460e0 |
children | d8505bfe4825 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Thu Apr 23 16:59:11 2015 -0700 +++ b/mercurial/cmdutil.py Thu Apr 23 14:27:26 2015 -0700 @@ -59,6 +59,8 @@ def dorecord(ui, repo, commitfunc, cmdsuggest, backupall, filterfn, *pats, **opts): import merge as mergemod + hunkclasses = (crecordmod.uihunk, patch.recordhunk) + ishunk = lambda x: isinstance(x, hunkclasses) if not ui.interactive(): raise util.Abort(_('running non-interactively, use %s instead') % @@ -102,6 +104,14 @@ except patch.PatchError, err: raise util.Abort(_('error parsing patch: %s') % err) + # We need to keep a backup of files that have been newly added and + # modified during the recording process because there is a previous + # version without the edit in the workdir + newlyaddedandmodifiedfiles = set() + for chunk in chunks: + if ishunk(chunk) and chunk.header.isnewfile() and chunk not in \ + originalchunks: + newlyaddedandmodifiedfiles.add(chunk.header.filename()) contenders = set() for h in chunks: try: @@ -122,8 +132,8 @@ 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 \ + newlyaddedandmodifiedfiles] backups = {} if tobackup: backupdir = repo.join('record-backups') @@ -151,6 +161,7 @@ dopatch = fp.tell() fp.seek(0) + [os.unlink(c) for c in newlyaddedandmodifiedfiles] # 3a. apply filtered patch to clean repo (clean) if backups: # Equivalent to hg.revert