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

extract filerevmodel.py from repomodel.py

Changeset bc305895d2aa

Parent ece79e7cf485

by Adrian Buehlmann

Changes to 3 files · Browse files at bc305895d2aa Showing diff from parent ece79e7cf485 Diff from another changeset...

 
32
33
34
35
 
36
37
38
 
32
33
34
 
35
36
37
38
@@ -32,7 +32,7 @@
   from tortoisehg.hgqt import icon as geticon  from tortoisehg.hgqt.dialogmixin import HgDialogMixin -from tortoisehg.hgqt.repomodel import FileRevModel +from tortoisehg.hgqt.filerevmodel import FileRevModel  from tortoisehg.hgqt.blockmatcher import BlockList, BlockMatch  from tortoisehg.hgqt.lexers import get_lexer  from tortoisehg.hgqt.quickbar import FindInGraphlogQuickBar
Change 1 of 1 Show Entire File tortoisehg/​hgqt/​filerevmodel.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@@ -0,0 +1,70 @@
+# Copyright (c) 2009-2010 LOGILAB S.A. (Paris, FRANCE). +# http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +from tortoisehg.util.util import Curry + +from tortoisehg.hgqt.repomodel import HgRepoListModel +from tortoisehg.hgqt.graph import Graph, filelog_grapher + +from PyQt4 import QtCore +connect = QtCore.QObject.connect +SIGNAL = QtCore.SIGNAL + +class FileRevModel(HgRepoListModel): + """ + Model used to manage the list of revisions of a file, in file + viewer of in diff-file viewer dialogs. + """ + _allcolumns = ('ID', 'Branch', 'Log', 'Author', 'Date', 'Tags', 'Filename') + _columns = ('ID', 'Branch', 'Log', 'Author', 'Date', 'Filename') + _stretchs = {'Log': 1, } + _getcolumns = "getFilelogColumns" + + def __init__(self, repo, filename=None, parent=None): + """ + data is a HgHLRepo instance + """ + HgRepoListModel.__init__(self, repo, parent=parent) + self.setFilename(filename) + + def setRepo(self, repo, branch='', fromhead=None, follow=False): + self.repo = repo + self._datacache = {} + self.load_config() + + def setFilename(self, filename): + self.filename = filename + + self._user_colors = {} + self._branch_colors = {} + + self.rowcount = 0 + self._datacache = {} + + if self.filename: + grapher = filelog_grapher(self.repo, self.filename) + self.graph = Graph(self.repo, grapher, self.max_file_size) + fl = self.repo.file(self.filename) + # we use fl.index here (instead of linkrev) cause + # linkrev API changed between 1.0 and 1.?. So this + # works with both versions. + self.heads = [fl.index[fl.rev(x)][4] for x in fl.heads()] + self.ensureBuilt(row=self.fill_step/2) + QtCore.QTimer.singleShot(0, Curry(self.emit, SIGNAL('filled'))) + self._fill_timer = self.startTimer(500) + else: + self.graph = None + self.heads = []
 
13
14
15
16
17
18
 
19
20
21
22
23
24
25
26
27
 
28
29
30
31
32
 
33
34
35
36
37
38
 
94
95
96
97
 
 
98
99
100
101
102
103
104
105
106
107
108
 
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
489
 
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
 
13
14
15
 
 
 
16
17
 
18
 
19
 
 
20
 
21
22
23
24
25
 
26
27
28
 
29
30
31
 
87
88
89
 
90
91
92
93
 
 
 
 
 
 
94
95
96
 
425
426
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
429
430
 
699
700
701
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -13,26 +13,19 @@
 # You should have received a copy of the GNU General Public License along with  # this program; if not, write to the Free Software Foundation, Inc.,  # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -""" -Qt4 model for hg repo changelogs and filelogs -""" +  import sys -import mx.DateTime as dt  import re -import os, os.path as osp   -from mercurial.node import nullrev -from mercurial.node import hex, short as short_hex  from mercurial.revlog import LookupError -from mercurial import util, error +from mercurial import error    from tortoisehg.util.util import tounicode, isbfile, Curry    from tortoisehg.hgqt.graph import Graph, ismerge, diff as revdiff -from tortoisehg.hgqt.graph import revision_grapher, filelog_grapher +from tortoisehg.hgqt.graph import revision_grapher  from tortoisehg.hgqt.config import HgConfig  from tortoisehg.hgqt import icon as geticon -from tortoisehg.hgqt.decorators import timeit    from PyQt4 import QtCore, QtGui  connect = QtCore.QObject.connect @@ -94,15 +87,10 @@
  'Filename': lambda model, ctx, gnode: gnode.extra[0],   }   -_tooltips = {'ID': lambda model, ctx, gnode: ctx.rev() is not None and ctx.hex() or "Working Directory", +_tooltips = {'ID': lambda model, ctx, + gnode: ctx.rev() is not None and ctx.hex() or "Working Directory",   }   -def auth_width(model, repo): - auths = model._aliases.values() - if not auths: - return None - return sorted(auths, cmp=lambda x,y: cmp(len(x), len(y)))[-1] -  # in following lambdas, r is a hg repo  _maxwidth = {'ID': lambda self, r: str(len(r.changelog)),   'Date': lambda self, r: cvrt_date(r.changectx(0).date()), @@ -437,53 +425,6 @@
  def notify_data_changed(self):   self.emit(SIGNAL("layoutChanged()"))   -class FileRevModel(HgRepoListModel): - """ - Model used to manage the list of revisions of a file, in file - viewer of in diff-file viewer dialogs. - """ - _allcolumns = ('ID', 'Branch', 'Log', 'Author', 'Date', 'Tags', 'Filename') - _columns = ('ID', 'Branch', 'Log', 'Author', 'Date', 'Filename') - _stretchs = {'Log': 1, } - _getcolumns = "getFilelogColumns" - - def __init__(self, repo, filename=None, parent=None): - """ - data is a HgHLRepo instance - """ - HgRepoListModel.__init__(self, repo, parent=parent) - self.setFilename(filename) - - def setRepo(self, repo, branch='', fromhead=None, follow=False): - self.repo = repo - self._datacache = {} - self.load_config() - - def setFilename(self, filename): - self.filename = filename - - self._user_colors = {} - self._branch_colors = {} - - self.rowcount = 0 - self._datacache = {} - - if self.filename: - grapher = filelog_grapher(self.repo, self.filename) - self.graph = Graph(self.repo, grapher, self.max_file_size) - fl = self.repo.file(self.filename) - # we use fl.index here (instead of linkrev) cause - # linkrev API changed between 1.0 and 1.?. So this - # works with both versions. - self.heads = [fl.index[fl.rev(x)][4] for x in fl.heads()] - self.ensureBuilt(row=self.fill_step/2) - QtCore.QTimer.singleShot(0, Curry(self.emit, SIGNAL('filled'))) - self._fill_timer = self.startTimer(500) - else: - self.graph = None - self.heads = [] - -  replus = re.compile(r'^[+][^+].*', re.M)  reminus = re.compile(r'^[-][^-].*', re.M)   @@ -758,40 +699,3 @@
  return QtCore.QVariant(header[section])     return nullvariant - - -if __name__ == "__main__": - from mercurial import ui, hg - from optparse import OptionParser - p = OptionParser() - p.add_option('-R', '--root', default='.', - dest='root', - help="Repository main directory") - p.add_option('-f', '--file', default=None, - dest='filename', - help="display the revision graph of this file (if not given, display the whole rev graph)") - - opt, args = p.parse_args() - - u = ui.ui() - repo = hg.repository(u, opt.root) - app = QtGui.QApplication(sys.argv) - if opt.filename is not None: - model = FileRevModel(repo, opt.filename) - else: - model = HgRepoListModel(repo) - - view = QtGui.QTableView() - #delegate = GraphDelegate() - #view.setItemDelegateForColumn(1, delegate) - view.setShowGrid(False) - view.verticalHeader().hide() - view.verticalHeader().setDefaultSectionSize(20) - view.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) - view.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) - view.setModel(model) - view.setWindowTitle("Simple Hg List Model") - view.show() - view.setAlternatingRowColors(True) - #view.resizeColumnsToContents() - sys.exit(app.exec_())