Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.1, 1.1.1, and 1.1.2

thgpbranch: Add viewing of patches

Changeset bc93972daa6d

Parent c7a36a455451

by Peer Sommerlund

Changes to 4 files · Browse files at bc93972daa6d Showing diff from parent c7a36a455451 Diff from another changeset...

 
191
192
193
 
 
 
 
 
 
 
 
 
 
194
195
196
 
198
199
200
201
 
 
 
 
 
202
203
204
 
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
 
208
209
210
 
211
212
213
214
215
216
217
218
@@ -191,6 +191,16 @@
    def load_patch_details(self, patchfile):   'Load specified patch details into buffer and file list' + pf = open(patchfile) + self.load_patch_details_from_file_object(pf, patchfile) + + def load_patch_details_from_file_object(self, pf, patchfile, isTemp=False): + """ Load patch details into buffer and file list + :param pf: open file object + :param patchfile: path and name of patch file + :param isTemp: if True, then pf is a temporary file + and patchfile does not exist + """   self._filelist.clear()   self._filelist.append(('*', _('[All Files]'), ''))   @@ -198,7 +208,11 @@
  self.currev = -1   self.curphunks = {}   self.curpatch = patchfile - pf = open(self.curpatch) + if isTemp: + # pf is a temporary, so update panel cache while we can + patch_ctx = csinfo.patchctx(patchfile, self.repo, patchHandle=pf) + self.summarypanel.update(patch_ctx, self.patchstyle) + pf.seek(0)   def get_path(a, b):   type = (a == '/dev/null') and 'A' or 'M'   type = (b == '/dev/null') and 'R' or type
 
136
137
138
139
 
 
 
 
 
 
 
140
141
142
143
 
 
 
 
 
144
145
146
147
148
149
150
 
 
 
 
151
152
153
 
469
470
471
 
 
 
 
 
 
 
472
473
474
 
480
481
482
483
 
 
484
485
486
 
136
137
138
 
139
140
141
142
143
144
145
146
147
148
 
149
150
151
152
153
154
155
156
157
158
159
 
160
161
162
163
164
165
166
 
482
483
484
485
486
487
488
489
490
491
492
493
494
 
500
501
502
 
503
504
505
506
507
@@ -136,18 +136,31 @@
   class patchctx(object):   - def __init__(self, patchpath, repo): + def __init__(self, patchpath, repo, patchHandle=None): + """ Read patch context from file + :param patchHandle: If set, then the patch is a temporary. + The provided handle is used to read the patch and + the patchpath contains the name of the patch. + The handle is NOT closed. + """   self._path = patchpath   self._patchname = os.path.basename(patchpath)   self._repo = repo - pf = open(patchpath) + if patchHandle: + pf = patchHandle + pf_start_pos = pf.tell() + else: + pf = open(patchpath)   try:   data = patch.extract(self._repo.ui, pf)   tmpfile, msg, user, date, branch, node, p1, p2 = data   if tmpfile:   os.unlink(tmpfile)   finally: - pf.close() + if patchHandle: + pf.seek(pf_start_pos) + else: + pf.close()   if not msg and hasattr(repo, 'mq'):   # attempt to get commit message   from hgext import mq @@ -469,6 +482,13 @@
  return self.info.get_widget(item, self, self.ctx, self.custom, **kargs)     def update(self, target=None, custom=None, repo=None): + self.ctx = None + if type(target) == patchctx: + # If a patchctx is specified as target, use it instead + # of creating a context from revision or patch file + self.ctx = target + target = None + self.target = None   if target is None:   target = self.target   if target is not None: @@ -480,7 +500,8 @@
  repo = self.repo   if repo is not None:   self.repo = repo - self.ctx = create_context(repo, target) + if self.ctx is None: + self.ctx = create_context(repo, target)   if self.ctx is None:   return False # cannot update   return True
 
834
835
836
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
837
838
839
 
1557
1558
1559
 
1560
1561
1562
 
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
 
1573
1574
1575
1576
1577
1578
1579
@@ -834,6 +834,22 @@
  else:   self.goto_rev(revid)   + def pbranch_selected(self, pbranchwidget, revid, patchname): + 'if revid < 0 then the patch is listed in .hg/pgraph but not in repo' + self.stbar.set_status_text('') + pf = tempfile.TemporaryFile() + try: + try: + pf.writelines(pbranchwidget.pdiff(patchname)) + except (util.Abort, hglib.RepoError), e: + self.stbar.set_status_text(str(e)) + return + self.currevid = self.lastrevid = None + pf.seek(0) + self.changeview.load_patch_details_from_file_object(pf, patchname, isTemp=True) + finally: + pf.close() +   def repo_invalidated(self, widget):   'Emitted from MQWidget and PBranchWidget'   self.reload_log() @@ -1557,6 +1573,7 @@
  # create PBranchWidget   self.pbranchwidget = thgpbranch.PBranchWidget(   self, self.repo, self.stbar, accelgroup, self.tooltips) + self.pbranchwidget.connect('patch-selected', self.pbranch_selected)   self.pbranchwidget.connect('repo-invalidated', self.repo_invalidated)     def wrapframe(widget):
 
73
74
75
 
 
 
 
76
77
78
 
148
149
150
 
151
152
153
 
396
397
398
 
 
 
 
 
 
 
 
 
 
 
 
399
400
401
 
73
74
75
76
77
78
79
80
81
82
 
152
153
154
155
156
157
158
 
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
@@ -73,6 +73,10 @@
  'repo-invalidated': (gobject.SIGNAL_RUN_FIRST,   gobject.TYPE_NONE,   ()), + 'patch-selected': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + (int, # revision number for patch head + str)) # patch name   }     def __init__(self, parentwin, repo, statusbar, accelgroup=None, tooltips=None): @@ -148,6 +152,7 @@
  # To support old PyGTK (<2.12)   if hasattr(self.list, 'set_tooltip_column'):   self.list.set_tooltip_column(M_MSGESC) + self.list.connect('cursor-changed', self.list_sel_changed)   self.list.connect('button-press-event', self.list_pressed)   self.list.connect('row-activated', self.list_row_activated)   self.list.connect('size-allocate', self.list_size_allocated) @@ -396,6 +401,18 @@
  cmdline = ['hg', 'peditmessage', patch_name]   self.cmd.execute(cmdline, self.cmd_done)   + def pdiff(self, patch_name): + """ + [pbranch] Execute 'pdiff --tips' command. + + :param patch_name: Name of patch-branch + :retv: list of lines of generated patch + """ + opts = {} + mgr = self.pbranch.patchmanager(self.repo.ui, self.repo, opts) + graph = mgr.graphattips() + return graph.diff(patch_name, None, opts) +   def pnew_ui(self):   """   Create new patch.