comparison mercurial/patch.py @ 11377:9916263d9a60

patch: inline small, single-use 'write' function
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 17 Jun 2010 15:51:27 +0200
parents ad764a6a2eed
children 4f5a6df2af92
comparison
equal deleted inserted replaced
11376:ad764a6a2eed 11377:9916263d9a60
524 yield l 524 yield l
525 if l[-1] != '\n': 525 if l[-1] != '\n':
526 yield "\n\ No newline at end of file\n" 526 yield "\n\ No newline at end of file\n"
527 527
528 self.writelines(fname, rejlines()) 528 self.writelines(fname, rejlines())
529
530 def write(self, dest=None):
531 if not self.dirty:
532 return
533 if not dest:
534 dest = self.fname
535 self.writelines(dest, self.lines)
536 529
537 def apply(self, h): 530 def apply(self, h):
538 if not h.complete(): 531 if not h.complete():
539 raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") % 532 raise PatchError(_("bad hunk #%d %s (%d %d %d %d)") %
540 (h.number, h.desc, len(h.a), h.lena, len(h.b), 533 (h.number, h.desc, len(h.a), h.lena, len(h.b),
1153 opener = util.opener(cwd) 1146 opener = util.opener(cwd)
1154 1147
1155 def closefile(): 1148 def closefile():
1156 if not current_file: 1149 if not current_file:
1157 return 0 1150 return 0
1158 current_file.write() 1151 if current_file.dirty:
1152 current_file.writelines(current_file.fname, current_file.lines)
1159 current_file.write_rej() 1153 current_file.write_rej()
1160 return len(current_file.rej) 1154 return len(current_file.rej)
1161 1155
1162 for state, values in iterhunks(ui, fp, sourcefile): 1156 for state, values in iterhunks(ui, fp, sourcefile):
1163 if state == 'hunk': 1157 if state == 'hunk':