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