Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/patch.py @ 41474:d1d3094b54f9
patch: handle 0 context lines (diff.unified=0) when parsing patches
Previously, if there were no context lines, we would just keep updating the
ranges and the hunk, but not actually storing the hunk (just overwriting it each
time). Thus a diff like this:
$ hg diff --config diff.unified=0
diff --git a/bar b/bar
--- a/bar
+++ b/bar
@@ -1,0 +2,1 @@ 1
+change1
@@ -3,0 +5,1 @@ 3
+change2
would come out of the parser like this (change1 is lost):
bar:
@@ -3,0 +5,1 @@ 3
+change2
This had some really weird side effects for things like commit --interactive,
split, etc.
Differential Revision: https://phab.mercurial-scm.org/D5743
author | Kyle Lippincott <spectral@google.com> |
---|---|
date | Mon, 28 Jan 2019 18:00:14 -0800 |
parents | 4a33a6bf2b52 |
children | a02c8b605d31 |
comparison
equal
deleted
inserted
replaced
41473:1a4a41d39dfc | 41474:d1d3094b54f9 |
---|---|
1607 self.before = [] | 1607 self.before = [] |
1608 self.hunk = [] | 1608 self.hunk = [] |
1609 self.headers = [] | 1609 self.headers = [] |
1610 | 1610 |
1611 def addrange(self, limits): | 1611 def addrange(self, limits): |
1612 self.addcontext([]) | |
1612 fromstart, fromend, tostart, toend, proc = limits | 1613 fromstart, fromend, tostart, toend, proc = limits |
1613 self.fromline = int(fromstart) | 1614 self.fromline = int(fromstart) |
1614 self.toline = int(tostart) | 1615 self.toline = int(tostart) |
1615 self.proc = proc | 1616 self.proc = proc |
1616 | 1617 |
1627 | 1628 |
1628 def addhunk(self, hunk): | 1629 def addhunk(self, hunk): |
1629 if self.context: | 1630 if self.context: |
1630 self.before = self.context | 1631 self.before = self.context |
1631 self.context = [] | 1632 self.context = [] |
1633 if self.hunk: | |
1634 self.addcontext([]) | |
1632 self.hunk = hunk | 1635 self.hunk = hunk |
1633 | 1636 |
1634 def newfile(self, hdr): | 1637 def newfile(self, hdr): |
1635 self.addcontext([]) | 1638 self.addcontext([]) |
1636 h = header(hdr) | 1639 h = header(hdr) |