##// END OF EJS Templates
patch: write rej files for missing targets (issue 853)
Patrick Mezard -
r5652:e90e72c6 default
parent child Browse files
Show More
@@ -302,14 +302,23 b" unidesc = re.compile('@@ -(\\d+)(,(\\d+))?"
302 302 contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)')
303 303
304 304 class patchfile:
305 def __init__(self, ui, fname):
305 def __init__(self, ui, fname, missing=False):
306 306 self.fname = fname
307 307 self.ui = ui
308 try:
309 fp = file(fname, 'rb')
310 self.lines = fp.readlines()
311 self.exists = True
312 except IOError:
308 self.lines = []
309 self.exists = False
310 self.missing = missing
311 if not missing:
312 try:
313 fp = file(fname, 'rb')
314 self.lines = fp.readlines()
315 self.exists = True
316 except IOError:
317 pass
318 else:
319 self.ui.warn(_("unable to find '%s' for patching\n") % self.fname)
320
321 if not self.exists:
313 322 dirname = os.path.dirname(fname)
314 323 if dirname and not os.path.isdir(dirname):
315 324 dirs = dirname.split(os.path.sep)
@@ -318,8 +327,6 b' class patchfile:'
318 327 d = os.path.join(d, x)
319 328 if not os.path.isdir(d):
320 329 os.mkdir(d)
321 self.lines = []
322 self.exists = False
323 330
324 331 self.hash = {}
325 332 self.dirty = 0
@@ -427,6 +434,10 b' class patchfile:'
427 434 if reverse:
428 435 h.reverse()
429 436
437 if self.missing:
438 self.rej.append(h)
439 return -1
440
430 441 if self.exists and h.createfile():
431 442 self.ui.warn(_("file %s already exists\n") % self.fname)
432 443 self.rej.append(h)
@@ -805,22 +816,23 b' def selectfile(afile_orig, bfile_orig, h'
805 816 createfunc = hunk.createfile
806 817 if reverse:
807 818 createfunc = hunk.rmfile
808 if not goodb and not gooda and not createfunc():
809 raise PatchError(_("unable to find %s or %s for patching") %
810 (afile, bfile))
811 if gooda and goodb:
812 fname = bfile
813 if afile in bfile:
819 missing = not goodb and not gooda and not createfunc()
820 fname = None
821 if not missing:
822 if gooda and goodb:
823 fname = (afile in bfile) and afile or bfile
824 elif gooda:
814 825 fname = afile
815 elif gooda:
816 fname = afile
817 elif not nullb:
818 fname = bfile
819 if afile in bfile:
826
827 if not fname:
828 if not nullb:
829 fname = (afile in bfile) and afile or bfile
830 elif not nulla:
820 831 fname = afile
821 elif not nulla:
822 fname = afile
823 return fname
832 else:
833 raise PatchError(_("undefined source and destination files"))
834
835 return fname, missing
824 836
825 837 class linereader:
826 838 # simple class to allow pushing lines back into the input stream
@@ -1009,9 +1021,9 b' def applydiff(ui, fp, changed, strip=1, '
1009 1021 if sourcefile:
1010 1022 current_file = patchfile(ui, sourcefile)
1011 1023 else:
1012 current_file = selectfile(afile, bfile, first_hunk,
1024 current_file, missing = selectfile(afile, bfile, first_hunk,
1013 1025 strip, reverse)
1014 current_file = patchfile(ui, current_file)
1026 current_file = patchfile(ui, current_file, missing)
1015 1027 except PatchError, err:
1016 1028 ui.warn(str(err) + '\n')
1017 1029 current_file, current_hunk = None, None
@@ -41,6 +41,8 b' hg qpush'
41 41 echo % display added files
42 42 cat a
43 43 cat c
44 echo % display rejections
45 cat b.rej
44 46 cd ..
45 47
46 48
@@ -65,5 +67,7 b' hg st'
65 67 echo % display added files
66 68 cat a
67 69 cat c
70 echo % display rejections
71 cat b.rej
68 72 cd ..
69 73
@@ -2,23 +2,48 b' adding b'
2 2 Patch queue now empty
3 3 % push patch with missing target
4 4 applying changeb
5 unable to find b or b for patching
5 unable to find 'b' for patching
6 2 out of 2 hunks FAILED -- saving rejects to file b.rej
6 7 patch failed, unable to continue (try -v)
7 8 patch failed, rejects left in working dir
8 9 Errors during apply, please fix and refresh changeb
9 10 % display added files
10 11 a
11 12 c
13 % display rejections
14 --- b
15 +++ b
16 @@ -1,3 +1,5 @@ a
17 +b
18 +b
19 a
20 a
21 a
22 @@ -8,3 +10,5 @@ a
23 a
24 a
25 a
26 +c
27 +c
12 28 adding b
13 29 Patch queue now empty
14 30 % push git patch with missing target
15 31 applying changeb
16 unable to find b or b for patching
32 unable to find 'b' for patching
33 1 out of 1 hunk FAILED -- saving rejects to file b.rej
17 34 patch failed, unable to continue (try -v)
18 35 b: No such file or directory
19 36 b not tracked!
20 37 patch failed, rejects left in working dir
21 38 Errors during apply, please fix and refresh changeb
39 ? b.rej
22 40 % display added files
23 41 a
24 42 c
43 % display rejections
44 --- b
45 +++ b
46 GIT binary patch
47 literal 2
48 Jc${No0000400IC2
49
General Comments 0
You need to be logged in to leave comments. Login now