[PATCH 2 of 5] diff: generalize addmodehdr to support delete/new file flags
Guillermo Pérez
bisho at fb.com
Wed Nov 21 11:28:14 CST 2012
# HG changeset patch
# User Guillermo Pérez <bisho at fb.com>
# Date 1353509645 28800
# Node ID 7f925309efeb8f58edba8f6bbf943c1791e0e685
# Parent afc2d3d7a9aaac736efe291d5aff087743092467
diff: generalize addmodehdr to support delete/new file flags
All the handling of flags for modified, deleted and new files
could be managed in the handler, and move the logic on what
to print there.
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1659,10 +1659,15 @@
gitmode = {'l': '120000', 'x': '100755', '': '100644'}
- def addflagchangemeta(meta, fa, fb):
+ def addflagsmeta(meta, fa, fb):
if opts.git:
- meta.append('old mode %s\n' % gitmode[fa])
- meta.append('new mode %s\n' % gitmode[fb])
+ if fa is not None and fb is not None and fa != fb:
+ meta.append('old mode %s\n' % gitmode[fa])
+ meta.append('new mode %s\n' % gitmode[fb])
+ elif fb is not None and fa is None:
+ meta.append('new file mode %s\n' % gitmode[fb])
+ elif fa is not None and fb is None:
+ meta.append('deleted file mode %s\n' % gitmode[fa])
def addindexmeta(meta, revs):
if opts.git:
@@ -1735,11 +1740,8 @@
to = getfilectx(a, ctx1).data()
else:
losedatafn(f)
- else:
- if opts.git:
- header.append('new file mode %s\n' % gitmode[nflag])
- elif ctx2.flags(f):
- losedatafn(f)
+ elif not opts.git and ctx2.flags(f):
+ losedatafn(f)
# In theory, if tn was copied or renamed we should check
# if the source is binary too but the copy record already
# forces git mode.
@@ -1752,6 +1754,7 @@
# regular diffs cannot represent new empty file
losedatafn(f)
elif f in removed:
+ oflag = man1.flags(f)
if opts.git:
# have we already reported a copy above?
if ((f in copy and copy[f] in added
@@ -1759,9 +1762,6 @@
(f in copyto and copyto[f] in added
and copy[copyto[f]] == f)):
dodiff = False
- else:
- header.append('deleted file mode %s\n' %
- gitmode[man1.flags(f)])
elif not to or util.binary(to):
# regular diffs cannot represent empty file deletion
losedatafn(f)
@@ -1775,8 +1775,7 @@
elif binary or nflag != oflag:
losedatafn(f)
- if nflag is not None and oflag is not None and nflag != oflag:
- addflagchangemeta(header, oflag, nflag)
+ addflagsmeta(header, oflag, nflag)
if dodiff:
if opts.git or revs:
header.insert(0, diffline(join(a), join(b), revs))
More information about the Mercurial-devel
mailing list