Mercurial > public > mercurial-scm > hg
diff mercurial/patch.py @ 46529:33350debb480 stable
patch: make diff --git to differentiate b/w file is empty or doesn't exists
Before this patch, as we didn't differentiate the two cases of a file in a context:
1. File doesn't exists
2. File is empty
which causes the blob id to be same for both the cases.
Now we use `nullhex` for a file which doesn't exists in a context (aligning it with
the git diff format)
Changes in test file reflect the fixed behavior.
Differential Revision: https://phab.mercurial-scm.org/D10001
author | Sushil khanchi <sushilkhanchi97@gmail.com> |
---|---|
date | Tue, 16 Feb 2021 15:44:51 +0530 |
parents | 416ecdaa12df |
children | a9887f9e87aa |
line wrap: on
line diff
--- a/mercurial/patch.py Tue Feb 16 15:37:19 2021 +0530 +++ b/mercurial/patch.py Tue Feb 16 15:44:51 2021 +0530 @@ -20,6 +20,7 @@ from .i18n import _ from .node import ( hex, + nullhex, short, ) from .pycompat import open @@ -3099,11 +3100,13 @@ ctx1, fctx1, path1, flag1, content1, date1 = data1 ctx2, fctx2, path2, flag2, content2, date2 = data2 + index1 = _gitindex(content1) if path1 in ctx1 else nullhex + index2 = _gitindex(content2) if path2 in ctx2 else nullhex if binary and opts.git and not opts.nobinary: text = mdiff.b85diff(content1, content2) if text: header.append( - b'index %s..%s' % (_gitindex(content1), _gitindex(content2)) + b'index %s..%s' % (index1, index2) ) hunks = ((None, [text]),) else: @@ -3114,8 +3117,8 @@ header.append( b'index %s..%s %s' % ( - _gitindex(content1)[0 : opts.index], - _gitindex(content2)[0 : opts.index], + index1[0 : opts.index], + index2[0 : opts.index], _gitmode[flag], ) )