Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9.2, 1.9.3, and 2.0

chunks: create helper function for applying chunks to a fileListFrame

Capture output that normally would go to stderr and look for .rej notifications
Handle typical patch errors

Changeset b329d0932b39

Parent e39142cd6cd6

by Steve Borho

Changes to one file · Browse files at b329d0932b39 Showing diff from parent e39142cd6cd6 Diff from another changeset...

 
9
10
11
12
 
13
14
15
 
94
95
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
98
99
 
166
167
168
169
170
171
 
172
173
174
 
236
237
238
239
240
241
242
243
244
245
246
247
 
248
249
250
 
9
10
11
 
12
13
14
15
 
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
 
191
192
193
 
 
 
194
195
196
197
 
259
260
261
 
 
 
 
 
 
 
 
 
262
263
264
265
@@ -9,7 +9,7 @@
 import os    from mercurial import hg, util, patch -from mercurial import match as matchmod +from mercurial import match as matchmod, ui as uimod  from hgext import record    from tortoisehg.util import hglib @@ -94,6 +94,31 @@
  self.mtime = newmtime   self.refresh()   + def runPatcher(self, fp, wfile, updatestate): + class warncapt(uimod.ui): + def warn(self, msg, *args, **opts): + self.write(msg) + repo = self.repo + ui = warncapt() + ui.pushbuffer() + strip, pfiles = 1, {} + ok = True + try: + patch.internalpatch(fp, ui, strip, repo.root, files=pfiles, + eolmode=None) + except patch.PatchError, err: + ok = False + self.showMessage.emit(hglib.tounicode(str(err))) + for line in ui.popbuffer().splitlines(): + if line.endswith(wfile + '.rej'): + print 'reject file created for', wfile + # TODO: ask user if they want to edit file + .rej + # TODO: ask user if it is ok to remove chunks from source + if updatestate and ok: + # Apply operations specified in git diff headers + hglib.updatedir(repo.ui, repo, pfiles) + return ok +   def editCurrentFile(self):   ctx = self.filelistmodel._ctx   if isinstance(ctx, patchctx): @@ -166,9 +191,7 @@
  for c in kchunks:   c.write(fp)   fp.seek(0) - pfiles = {} - patch.internalpatch(fp, repo.ui, 1, repo.root, files=pfiles, - eolmode=None) + self.runPatcher(fp, self.currentFile, False)   finally:   wlock.release()   self.fileModified.emit() @@ -236,15 +259,7 @@
  fp.seek(0)   wlock = repo.wlock()   try: - try: - pfiles = {} - patch.internalpatch(fp, repo.ui, 1, repo.root, files=pfiles, - eolmode=None) - hglib.updatedir(repo.ui, repo, pfiles) - # TODO: detect patch rejects, offer to open editor - return True - except patch.PatchError, err: - self.showMessage.emit(hglib.tounicode(str(err))) + return self.runPatcher(fp, wfile, True)   finally:   wlock.release()   return False