Mercurial > public > mercurial-scm > hg-stable
diff mercurial/patch.py @ 17946:1e13b1184292
diff: move index header generation to patch
In an upcoming patch, we will add index information to all git diffs, not
only binary diffs, so this code needs to be moved to a more appropriate
place.
Also, since this information is used for patch headers, it makes more
sense to be in the patch module, along with other patch-related metadata.
author | Guillermo P?rez <bisho@fb.com> |
---|---|
date | Thu, 15 Nov 2012 15:16:41 -0800 |
parents | 45766e2a7384 |
children | a9f4a6076740 |
line wrap: on
line diff
--- a/mercurial/patch.py Thu Nov 15 15:06:32 2012 -0800 +++ b/mercurial/patch.py Thu Nov 15 15:16:41 2012 -0800 @@ -10,7 +10,7 @@ import tempfile, zlib, shutil from i18n import _ -from node import hex, short +from node import hex, nullid, short import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error import context @@ -1662,6 +1662,22 @@ header.append('old mode %s\n' % omode) header.append('new mode %s\n' % nmode) + def addindexmeta(meta, revs): + if opts.git: + i = len(revs) + if i==2: + meta.append('index %s..%s\n' % tuple(revs)) + elif i==3: + meta.append('index %s,%s..%s\n' % tuple(revs)) + + def gitindex(text): + if not text: + return hex(nullid) + l = len(text) + s = util.sha1('blob %d\0' % l) + s.update(text) + return s.hexdigest() + def diffline(a, b, revs): if opts.git: line = 'diff --git a/%s b/%s\n' % (a, b) @@ -1763,6 +1779,8 @@ header.insert(0, diffline(join(a), join(b), revs)) if dodiff == 'binary': text = mdiff.b85diff(to, tn) + if text: + addindexmeta(header, [gitindex(to), gitindex(tn)]) else: text = mdiff.unidiff(to, date1, # ctx2 date may be dynamic