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

stable fileview: cleanup block margin update timer

Move SequenceMatcher generator initialization into the timer event.
Move all of the code related to diff blocks together at the end of
the class. Give the timer function a more meaningul name.

Changeset 7f3295aa922f

Parent 6da6c9c2f64a

by Steve Borho

Changes to one file · Browse files at 7f3295aa922f Showing diff from parent 6da6c9c2f64a Diff from another changeset...

 
197
198
199
200
 
201
202
203
 
266
267
268
269
270
271
272
 
347
348
349
350
 
351
352
353
354
355
356
 
 
 
357
358
359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
361
362
 
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
 
197
198
199
 
200
201
202
203
 
266
267
268
 
269
270
271
 
346
347
348
 
349
350
351
352
 
 
 
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
 
474
475
476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
478
479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
481
482
@@ -197,7 +197,7 @@
    self.timer = QTimer()   self.timer.setSingleShot(False) - self.timer.timeout.connect(self.idle_fill_files) + self.timer.timeout.connect(self.timerBuildDiffMarkers)     def setFont(self, font):   self.sci.setFont(font) @@ -266,7 +266,6 @@
  # from disappearing during refresh, and tool layouts bouncing   self.filenamelabel.setText(' ')   self.extralabel.hide() - self._diffs = []     def displayFile(self, filename=None, rev=None, status=None):   if filename is None: @@ -347,16 +346,100 @@
  self.fileDisplayed.emit(uf, fd.contents or QString())     if self._mode == 'file' and fd.contents and fd.olddata: - # Update diff margin + # Update blk margin   if self.timer.isActive():   self.timer.stop()   - olddata = fd.olddata.splitlines() - newdata = fd.contents.splitlines() - self._diff = difflib.SequenceMatcher(None, olddata, newdata) + self._fd = fd + self.actionNextDiff.setEnabled(False) + self.actionPrevDiff.setEnabled(False)   self.blk.syncPageStep()   self.timer.start()   + def nextLine(self): + x, y = self.sci.getCursorPosition() + self.sci.setCursorPosition(x+1, y) + + def prevLine(self): + x, y = self.sci.getCursorPosition() + self.sci.setCursorPosition(x-1, y) + + def nextCol(self): + x, y = self.sci.getCursorPosition() + self.sci.setCursorPosition(x, y+1) + + def prevCol(self): + x, y = self.sci.getCursorPosition() + self.sci.setCursorPosition(x, y-1) + + @pyqtSlot(unicode, object) + @pyqtSlot(unicode, object, int) + def sourceChanged(self, path, rev, line=None): + self.revisionSelected.emit(rev) + + @pyqtSlot(unicode, object, int) + def editSelected(self, path, rev, line): + """Open editor to show the specified file""" + repo = self._ctx._repo + path = hglib.fromunicode(path) + base = visdiff.snapshot(repo, [path], repo[rev])[0] + files = [os.path.join(base, path)] + pattern = hglib.fromunicode(self._lastSearch[0]) + wctxactions.edit(self, repo.ui, repo, files, line, pattern) + + @pyqtSlot(unicode, bool, bool, bool) + def find(self, exp, icase=True, wrap=False, forward=True): + self.sci.find(exp, icase, wrap, forward) + + @pyqtSlot(unicode, bool) + def highlightText(self, match, icase=False): + self._lastSearch = match, icase + self.sci.highlightText(match, icase) + + def verticalScrollBar(self): + return self.sci.verticalScrollBar() + + # + # file mode diff markers + # + def timerBuildDiffMarkers(self): + 'show modified and added lines in the self.blk margin' + self.sci.setUpdatesEnabled(False) + self.blk.setUpdatesEnabled(False) + + if self._fd: + olddata = self._fd.olddata.splitlines() + newdata = self._fd.contents.splitlines() + diff = difflib.SequenceMatcher(None, olddata, newdata) + self._opcodes = diff.get_opcodes() + self._fd = None + self._diffs = [] + + for tag, alo, ahi, blo, bhi in self._opcodes[:30]: + if tag == 'replace': + self._diffs.append([blo, bhi]) + self.blk.addBlock('x', blo, bhi) + for i in range(blo, bhi): + self.sci.markerAdd(i, self.markertriangle) + elif tag == 'insert': + self._diffs.append([blo, bhi]) + self.blk.addBlock('+', blo, bhi) + for i in range(blo, bhi): + self.sci.markerAdd(i, self.markerplus) + elif tag in ('equal', 'delete'): + pass + else: + raise ValueError, 'unknown tag %r' % (tag,) + + self._opcodes = self._opcodes[30:] + if not self._opcodes: + self.actionNextDiff.setEnabled(bool(self._diffs)) + self.actionPrevDiff.setEnabled(False) + self.timer.stop() + + self.sci.setUpdatesEnabled(True) + self.blk.setUpdatesEnabled(True) +   def nextDiff(self):   if self._mode == 'diff' or not self._diffs:   self.actionNextDiff.setEnabled(False) @@ -391,98 +474,9 @@
  self.actionNextDiff.setEnabled(True)   self.actionPrevDiff.setEnabled(not first)   - def nextLine(self): - x, y = self.sci.getCursorPosition() - self.sci.setCursorPosition(x+1, y) - - def prevLine(self): - x, y = self.sci.getCursorPosition() - self.sci.setCursorPosition(x-1, y) - - def nextCol(self): - x, y = self.sci.getCursorPosition() - self.sci.setCursorPosition(x, y+1) - - def prevCol(self): - x, y = self.sci.getCursorPosition() - self.sci.setCursorPosition(x, y-1) -   def nDiffs(self):   return len(self._diffs)   - @pyqtSlot(unicode, object) - @pyqtSlot(unicode, object, int) - def sourceChanged(self, path, rev, line=None): - self.revisionSelected.emit(rev) - - @pyqtSlot(unicode, object, int) - def editSelected(self, path, rev, line): - """Open editor to show the specified file""" - repo = self._ctx._repo - path = hglib.fromunicode(path) - base = visdiff.snapshot(repo, [path], repo[rev])[0] - files = [os.path.join(base, path)] - pattern = hglib.fromunicode(self._lastSearch[0]) - wctxactions.edit(self, repo.ui, repo, files, line, pattern) - - @pyqtSlot(unicode, bool, bool, bool) - def find(self, exp, icase=True, wrap=False, forward=True): - self.sci.find(exp, icase, wrap, forward) - - @pyqtSlot(unicode, bool) - def highlightText(self, match, icase=False): - self._lastSearch = match, icase - self.sci.highlightText(match, icase) - - def verticalScrollBar(self): - return self.sci.verticalScrollBar() - - def idle_fill_files(self): - # we make a burst of diff-lines computed at once, but we - # disable GUI updates for efficiency reasons, then only - # refresh GUI at the end of the burst - self.sci.setUpdatesEnabled(False) - self.blk.setUpdatesEnabled(False) - for n in range(30): # burst pool - if self._diff is None or not self._diff.get_opcodes(): - self.actionNextDiff.setEnabled(bool(self._diffs)) - self.actionPrevDiff.setEnabled(False) - self._diff = None - self.timer.stop() - break - - tag, alo, ahi, blo, bhi = self._diff.get_opcodes().pop(0) - if tag == 'replace': - self._diffs.append([blo, bhi]) - self.blk.addBlock('x', blo, bhi) - for i in range(blo, bhi): - self.sci.markerAdd(i, self.markertriangle) - - elif tag == 'delete': - # You cannot effectively show deleted lines in a single - # pane display. They do not exist. - pass - # self._diffs.append([blo, bhi]) - # self.blk.addBlock('-', blo, bhi) - # for i in range(alo, ahi): - # self.sci.markerAdd(i, self.markerminus) - - elif tag == 'insert': - self._diffs.append([blo, bhi]) - self.blk.addBlock('+', blo, bhi) - for i in range(blo, bhi): - self.sci.markerAdd(i, self.markerplus) - - elif tag == 'equal': - pass - - else: - raise ValueError, 'unknown tag %r' % (tag,) - - # ok, enable GUI refresh for code viewers and diff-block displayers - self.sci.setUpdatesEnabled(True) - self.blk.setUpdatesEnabled(True) -    class FileData(object):   def __init__(self, ctx, ctx2, wfile, status=None):