sapling/mercurial
Patrick Mezard b5270209ca patch: fix patch hunk/metdata synchronization (issue3384)
Git patches are parsed in two phases: 1) extract metadata, 2) parse actual
deltas and merge them with the previous metadata. We do this to avoid
dependency issues like "modify a; copy a to b", where "b" must be copied from
the unmodified "a".

Issue3384 is caused by flaky code I wrote to synchronize the patch metadata
with the emitted hunk:

 if (gitpatches and
     (gitpatches[-1][0] == afile or gitpatches[-1][1] == bfile)):
     gp = gitpatches.pop()[2]

With a patch like:

 diff --git a/a b/c
 copy from a
 copy to c
 --- a/a
 +++ b/c
 @@ -1,1 +1,2 @@
  a
 +a
 @@ -2,1 +2,2 @@
  a
 +a
 diff --git a/a b/a
 --- a/a
 +++ b/a
 @@ -1,1 +1,2 @@
  a
 +b

the first hunk of the first block is matched with the metadata for the block
"diff --git a/a b/c", then the second hunk of the first block is matched with
the metadata of the second block "diff --git a/a b/a", because of the "or" in
the code paste above. Turning the "or" into an "and" is not enough as we have
to deal with /dev/null cases for each file.

We I remove this broken piece of code:

 # copy/rename + modify should modify target, not source
 if gp.op in ('COPY', 'DELETE', 'RENAME', 'ADD') or gp.mode:
     afile = bfile

because "afile = bfile" set "afile" to stuff like "b/file" instead of "a/file",
and because this only happens for git patches, which afile/bfile are ignored
anyway by applydiff().

v2:
- Avoid a traceback on git metadata desynchronization
2012-04-21 21:40:25 +02:00
..
help doc: add note about pattern rooted/unrooted cases to "hgignore" and "patterns" 2012-04-23 00:38:22 +09:00
hgweb i18n: show localized messages for commands/extensions in hgweb help top (issue3383) 2012-04-19 20:54:56 +09:00
httpclient httpclient: update to 07d8c356f4d1 of py-nonblocking-http 2011-10-10 17:57:40 -05:00
pure pure/osutil: use Python's msvcrt module (issue3380) 2012-04-19 17:08:12 +02:00
templates templates: move Graph.edge() implementation in mercurial.js 2012-02-17 16:49:43 +01:00
__init__.py Add back links from file revisions to changeset revisions 2005-05-03 13:16:10 -08:00
ancestor.py check-code: flag 0/1 used as constant Boolean expression 2011-06-01 12:38:46 +02:00
archival.py atomictempfile: make close() consistent with other file-like objects. 2011-08-25 20:21:04 -04:00
base85.c backout of e4cb9628354c 2011-01-27 11:15:08 +01:00
bdiff.c bdiff.bdiff: release the GIL before doing expensive diff operations 2012-04-20 11:08:14 -05:00
bookmarks.py bookmarks: clone non-divergent bookmarks with @ in them 2012-03-21 16:39:38 -05:00
bundlerepo.py revlog: fix partial revision() docstring (from f4a6c9197dbd) 2012-04-13 10:14:59 +02:00
byterange.py Remove FSF mailing address from GPL headers 2012-01-06 16:27:13 +01:00
changegroup.py check-code: flag 0/1 used as constant Boolean expression 2011-06-01 12:38:46 +02:00
changelog.py changelog: micro-optimizations to changelog.read() 2012-03-18 18:19:16 -05:00
cmdutil.py commit: add option to amend the working dir parent 2012-04-18 01:20:16 +03:00
commands.py update: make --check abort with dirty subrepos 2012-04-23 12:12:04 +02:00
commandserver.py cmdserver: invalidate the dirstate when running commands (issue3271) 2012-02-15 23:44:10 +02:00
config.py config: discard UTF-8 BOM if found 2012-04-03 11:35:04 -05:00
context.py update: make --check abort with dirty subrepos 2012-04-23 12:12:04 +02:00
copies.py copies: use ctx.dirs() for directory rename detection 2012-02-26 16:45:59 -06:00
dagparser.py cleanup: use x in (a, b) instead of x == a or x == b 2010-09-23 00:02:31 -05:00
dagutil.py dagutil: fix off-by-one in inverserevlogdag buildup 2011-08-25 17:20:00 +02:00
demandimport.py demandimport: determine at load time if __import__ has level argument 2011-08-22 22:50:52 +02:00
diffhelpers.c backout of e4cb9628354c 2011-01-27 11:15:08 +01:00
dirstate.py dirstate: write branch file atomically 2012-04-19 18:11:42 +03:00
discovery.py discovery: fix regression when checking heads for pre 1.4 client (issue3218) 2012-01-24 19:49:30 +01:00
dispatch.py dispatch: add support for statprof as a profiler 2012-04-09 13:48:45 -07:00
encoding.py encoding: protect against non-ascii default encoding 2012-04-22 21:27:52 -04:00
error.py wireproto: add out-of-band error class to allow remote repo to report errors 2011-08-02 15:21:10 -04:00
extensions.py extensions: print some debug info on import failure 2011-10-01 16:42:39 -04:00
fancyopts.py globally: use safehasattr(x, '__call__') instead of hasattr(x, '__call__') 2011-07-25 16:24:37 -05:00
filelog.py filelog: add file function to open other filelogs 2011-05-10 17:38:58 +02:00
filemerge.py merge with stable 2012-03-13 16:29:13 -05:00
fileset.py fileset: add "subrepo" fileset symbol 2012-03-22 21:12:15 +01:00
formatter.py formatter: add basic formatters 2012-02-20 16:42:47 -06:00
graphmod.py graphmod: add config cache 2012-02-17 13:53:41 -06:00
hbisect.py bisect: add i18n contexts 2011-10-18 09:38:14 -02:00
help.py help: strip doctest from dochelp 2012-03-09 22:54:17 +01:00
hg.py clone: always close source repository (issue2491) 2012-04-03 22:01:28 +02:00
hook.py hooks: prioritize run order of hooks 2012-01-15 13:50:12 -07:00
httpconnection.py Use explicit integer division 2012-01-08 18:15:54 +01:00
httprepo.py httprepo: make __del__ more stable in error situations 2011-10-13 04:27:49 +02:00
i18n.py i18n: use getattr instead of hasattr 2011-07-25 20:46:30 -05:00
ignore.py misc: adding missing file close() calls 2011-11-03 11:24:55 -05:00
keepalive.py Remove FSF mailing address from GPL headers 2012-01-06 16:27:13 +01:00
localrepo.py journal: use tryread helper to backup files (issue3375) 2012-04-17 11:13:38 -05:00
lock.py lock: change name of release chain 2011-11-30 16:53:44 -06:00
lsprof.py profile: add undocumented config options for profiler output 2012-03-15 15:59:26 -05:00
lsprofcalltree.py drop unused imports 2009-05-14 15:35:46 +02:00
mail.py mail: use quoted-printable for mime encoding to avoid too long lines (issue3075) 2011-11-23 02:44:11 +01:00
manifest.py util: don't mess with builtins to emulate buffer() 2011-12-15 15:27:11 -06:00
match.py match: consider filesets as "anypats" 2012-02-26 17:10:55 +01:00
mdiff.py mdiff: fix diff header generation for files with spaces (issue3357) 2012-04-05 15:39:07 +02:00
merge.py update: fix case-collision with a clean wd and no --clean 2012-04-23 14:32:59 +02:00
minirst.py minirst: simplify and standardize field list formatting 2012-01-11 18:08:25 +01:00
mpatch.c util.h: replace ntohl/htonl with get/putbe32 2012-04-16 11:26:00 -05:00
node.py Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
osutil.c merge with stable 2011-09-14 14:37:10 -05:00
parser.py parsers: fix localization markup of parser errors 2011-06-21 00:17:52 +02:00
parsers.c util.h: replace ntohl/htonl with get/putbe32 2012-04-16 11:26:00 -05:00
patch.py patch: fix patch hunk/metdata synchronization (issue3384) 2012-04-21 21:40:25 +02:00
phases.py phases: fix a non-standard debug message 2012-02-15 17:30:21 -05:00
posix.py plan9: initial support for plan 9 from bell labs 2012-04-08 12:43:41 -07:00
pushkey.py phases: add basic pushkey support 2011-12-15 11:24:26 +01:00
pvec.py pvec: introduce pvecs 2012-03-12 13:37:39 -05:00
py3kcompat.py py3kcompat: added fake ord implementation for py3k 2010-08-07 16:38:38 -03:00
repair.py repair: fix missing import 2012-04-16 10:33:18 +02:00
repo.py Make sure bundlerepo doesn't leak temp files (issue2491) 2011-02-12 10:58:11 +01:00
revlog.py revlog: fix partial revision() docstring (from f4a6c9197dbd) 2012-04-13 10:14:59 +02:00
revset.py revset: fix O(n**2) behaviour of bisect() (issue3381) 2012-04-18 21:27:35 -07:00
scmutil.py opener: coding style, use triple quotes for doc string 2012-04-18 15:16:15 +02:00
setdiscovery.py phases: do not exchange secret changesets 2011-12-22 00:42:25 +01:00
similar.py fix coding style 2010-05-02 00:48:33 +02:00
simplemerge.py Remove FSF mailing address from GPL headers 2012-01-06 16:27:13 +01:00
sshrepo.py sshrepo: add more safe characters (issue2983) 2011-12-09 15:50:33 +01:00
sshserver.py addchangegroup: remove the lock argument on the addchangegroup methods 2011-11-28 01:32:13 +01:00
sslutil.py ui: optionally quiesce ssl verification warnings on python 2.5 2012-04-09 14:36:16 -07:00
statichttprepo.py scmutil: update cached copy when filecached attribute is assigned (issue3263) 2012-02-15 20:02:35 +02:00
store.py store: speed up read and write of large fncache files 2012-04-12 15:21:54 -07:00
strutil.py Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
subrepo.py revert: show warning when reverting subrepos that do not support revert 2012-04-19 23:36:42 +02:00
tags.py atomictempfile: make close() consistent with other file-like objects. 2011-08-25 20:21:04 -04:00
templatefilters.py templates/filters: extracting the user portion of an email address 2012-03-28 16:06:20 +02:00
templatekw.py templatekw: fix phase keywords 2012-01-20 13:10:01 -02:00
templater.py globally: use safehasattr(x, '__iter__') instead of hasattr(x, '__iter__') 2011-07-25 15:30:19 -05:00
transaction.py transaction: use posixfile and unlink from util 2011-02-15 14:41:49 +01:00
treediscovery.py treediscovery: always return all remote heads 2011-06-20 14:11:01 +02:00
ui.py plan9: initial support for plan 9 from bell labs 2012-04-08 12:43:41 -07:00
url.py merge with stable 2011-09-10 17:56:42 -05:00
util.h util.h: replace ntohl/htonl with get/putbe32 2012-04-16 11:26:00 -05:00
util.py util: create bytecount array just once 2012-04-12 20:22:18 -05:00
verify.py verify: fix mq misfire 2011-07-14 12:39:39 -05:00
win32.py win32: quietly ignore missing CreateHardLinkA for Wine 2011-09-13 17:01:07 -05:00
windows.py windows: use 'str.replace()' instead of combination of split() and join() 2012-02-05 22:58:31 +09:00
wireproto.py protocol: Add the stream-preferred capability 2012-04-04 00:00:47 +02:00