##// END OF EJS Templates
patch: error out if reached to EOF while reading hunk...
Yuya Nishihara -
r37591:49b82cdb default
parent child Browse files
Show More
@@ -7,6 +7,12
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from .i18n import _
11
12 from . import (
13 error,
14 )
15
10 def addlines(fp, hunk, lena, lenb, a, b):
16 def addlines(fp, hunk, lena, lenb, a, b):
11 """Read lines from fp into the hunk
17 """Read lines from fp into the hunk
12
18
@@ -22,6 +28,8 def addlines(fp, hunk, lena, lenb, a, b)
22 break
28 break
23 for i in xrange(num):
29 for i in xrange(num):
24 s = fp.readline()
30 s = fp.readline()
31 if not s:
32 raise error.ParseError(_('incomplete hunk'))
25 if s == "\\ No newline at end of file\n":
33 if s == "\\ No newline at end of file\n":
26 fixnewline(hunk, a, b)
34 fixnewline(hunk, a, b)
27 continue
35 continue
@@ -1254,8 +1254,11 class hunk(object):
1254 self.lenb = int(self.lenb)
1254 self.lenb = int(self.lenb)
1255 self.starta = int(self.starta)
1255 self.starta = int(self.starta)
1256 self.startb = int(self.startb)
1256 self.startb = int(self.startb)
1257 diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb, self.a,
1257 try:
1258 self.b)
1258 diffhelpers.addlines(lr, self.hunk, self.lena, self.lenb,
1259 self.a, self.b)
1260 except error.ParseError as e:
1261 raise PatchError(_("bad hunk #%d: %s") % (self.number, e))
1259 # if we hit eof before finishing out the hunk, the last line will
1262 # if we hit eof before finishing out the hunk, the last line will
1260 # be zero length. Lets try to fix it up.
1263 # be zero length. Lets try to fix it up.
1261 while len(self.hunk[-1]) == 0:
1264 while len(self.hunk[-1]) == 0:
@@ -1917,3 +1917,26 test import crash (issue5375)
1917 a not tracked!
1917 a not tracked!
1918 abort: source file 'a' does not exist
1918 abort: source file 'a' does not exist
1919 [255]
1919 [255]
1920
1921 test immature end of hunk
1922
1923 $ hg import - <<'EOF'
1924 > diff --git a/foo b/foo
1925 > --- a/foo
1926 > --- b/foo
1927 > @@ -0,0 +1,1 @@
1928 > EOF
1929 applying patch from stdin
1930 abort: bad hunk #1: incomplete hunk
1931 [255]
1932
1933 $ hg import - <<'EOF'
1934 > diff --git a/foo b/foo
1935 > --- a/foo
1936 > --- b/foo
1937 > @@ -0,0 +1,1 @@
1938 > \ No newline at end of file
1939 > EOF
1940 applying patch from stdin
1941 abort: bad hunk #1: incomplete hunk
1942 [255]
General Comments 0
You need to be logged in to leave comments. Login now