def __init__(self, repo, cfgname, branch, revset, rfilter, parent): """ repo is a hg repo instance """ QAbstractTableModel.__init__(self, parent) self._cache = [] self.graph = None self.timerHandle = None self.dotradius = 8 self.rowheight = 20 self.rowcount = 0 self.repo = repo self.revset = revset self.filterbyrevset = rfilter self.unicodestar = True self.unicodexinabox = True self.cfgname = cfgname # To be deleted self._user_colors = {} self._branch_colors = {} self._columnmap = { "Rev": self.getrev, "Node": lambda ctx, gnode: str(ctx), "Graph": lambda ctx, gnode: "", "Description": self.getlog, "Author": self.getauthor, "Tags": self.gettags, "Branch": self.getbranch, "Filename": lambda ctx, gnode: gnode.extra[0], "Age": lambda ctx, gnode: hglib.age(ctx.date()).decode("utf-8"), "LocalTime": lambda ctx, gnode: hglib.displaytime(ctx.date()), "UTCTime": lambda ctx, gnode: hglib.utctime(ctx.date()), "Changes": self.getchanges, } if repo: self.reloadConfig() self.updateColumns() self.setBranch(branch)
def on_get_value(self, rowref, column): (revid, graphnode, lines, path) = self.graphdata[rowref] if column == REVID: return revid if column == LINES: return lines if column == LAST_LINES: if rowref>0: return self.graphdata[rowref-1][2] return [] if column == WFILE: return path or '' try: ctx = self.repo[revid] except IndexError: return None # non-cached columns if column in (HEXID, REVHEX, BRANCH, LOCALTIME, UTC): if column == HEXID: return str(ctx) if column == REVHEX: hexid = gtklib.markup(str(ctx), face='monospace') return '%s: %s' % (revid, hexid) if column == BRANCH: return ctx.branch() if column == LOCALTIME: return hglib.displaytime(ctx.date()) if column == UTC: return hglib.utctime(ctx.date()) # cached columns if revid not in self.revisions: self.revisions[revid] = {} cache = self.revisions[revid] if cache.has_key(column): return cache[column] if column in (COMMITER, FGCOLOR): cache[COMMITER] = hglib.toutf(hglib.username(ctx.user())) if column == TAGS: tags = self.repo.nodetags(ctx.node()) cache[TAGS] = hglib.toutf(', '.join(tags)) elif column == SVNREV: extra = ctx.extra() cvt = extra.get('convert_revision', '') if cvt.startswith('svn:'): rev = cvt.split('/', 1)[-1] rev = rev.split('@', 1)[-1] else: rev = None cache[SVNREV] = rev and hglib.toutf('r%s' % rev) or '' elif column == AGE: cache[AGE] = hglib.age(ctx.date()) elif column == FGCOLOR: cache[FGCOLOR] = self.color_func(revid, cache[COMMITER]) elif column == CHANGES: parent = self.parents.get(revid, None) if parent is None: parent = ctx.parents()[0].node() M, A, R = self.repo.status(parent, ctx.node())[:3] common = dict(color=gtklib.BLACK) M = M and gtklib.markup(' %s ' % len(M), background=gtklib.PORANGE, **common) or '' A = A and gtklib.markup(' %s ' % len(A), background=gtklib.PGREEN, **common) or '' R = R and gtklib.markup(' %s ' % len(R), background=gtklib.PRED, **common) or '' cache[CHANGES] = ''.join((M, A, R)) elif column in (MESSAGE, GRAPHNODE): # convert to Unicode for valid string operations summary = hglib.tounicode(ctx.description()).replace(u'\0', '') if self.longsummary: limit = 80 lines = summary.splitlines() if lines: summary = lines.pop(0) while len(summary) < limit and lines: summary += u' ' + lines.pop(0) summary = summary[0:limit] else: summary = '' else: lines = summary.splitlines() summary = lines and lines[0] or '' escape = gtklib.markup_escape_text summary = escape(hglib.toutf(summary)) tstr = '' for tag in ctx.tags(): if tag not in self.hidetags: if tag in self.mqpatches: bg = gtklib.PBLUE else: bg = gtklib.PYELLOW style = {'color': gtklib.BLACK, 'background': bg} tstr += gtklib.markup(' %s ' % tag, **style) + ' ' for mark in ctx.bookmarks(): if mark == self.curbookmark: bg = gtklib.PORANGE else: bg = gtklib.PLIME style = {'color': gtklib.BLACK, 'background': bg} tstr += gtklib.markup(' %s ' % mark, **style) + ' ' node = ctx.node() branch = ctx.branch() bstr = '' status = 0 if self.branchtags.get(branch) == node: bstr += gtklib.markup(' %s ' % branch, color=gtklib.BLACK, background=gtklib.PGREEN) + ' ' status = 8 if revid in self.wcparents: sumstr = bstr + tstr + '<b><u>' + summary + '</u></b>' status += 4 else: sumstr = bstr + tstr + summary status += 0 if node in self.outgoing: # outgoing if not self.showgraph: marker = hglib.toutf(u'\u2191 ') # up arrow sumstr = marker + sumstr status += 1 elif revid >= self.origtip: if revid >= len(self.repo) - self.npreviews: # incoming if not self.showgraph: marker = hglib.toutf(u'\u2193 ') # down arrow sumstr = marker + sumstr status += 3 else: # new status += 2 cache[MESSAGE] = sumstr gcolumn, gcolor = graphnode cache[GRAPHNODE] = (gcolumn, gcolor, status) return cache[column]
try: return ctx.phasestr() except: return 'draft' _columnmap = { RevColumn: _getrev, BranchColumn: _getbranch, DescColumn: _getlog, AuthorColumn: _getauthor, TagsColumn: _gettags, LatestTagColumn: _getlatesttags, NodeColumn: lambda self, ctx: str(ctx), AgeColumn: lambda self, ctx: hglib.age(ctx.date()).decode('utf-8'), LocalDateColumn: lambda self, ctx: hglib.displaytime(ctx.date()), UtcDateColumn: lambda self, ctx: hglib.utctime(ctx.date()), ConvertedColumn: _getconv, PhaseColumn: _getphase, } class FileRevModel(HgRepoListModel): """ Model used to manage the list of revisions of a file, in file viewer of in diff-file viewer dialogs. """ _defaultcolumns = ('Graph', 'Rev', 'Branch', 'Description', 'Author', 'Age', 'Filename') def __init__(self, repoagent, filename, parent=None):
cvt = extra.get('p4', '') if cvt: return cvt return '' def getphase(self, ctx, gnode): if ctx.rev() is None: return '' try: return ctx.phasestr() except: return 'draft' _columnmap = { 'Rev': getrev, 'Node': lambda self, ctx, gnode: str(ctx), 'Graph': lambda self, ctx, gnode: "", 'Description': getlog, 'Author': getauthor, 'Tags': gettags, 'Latest tags': getlatesttags, 'Branch': getbranch, 'Filename': lambda self, ctx, gnode: gnode.extra[0], 'Age': lambda self, ctx, gnode: hglib.age(ctx.date()).decode('utf-8'), 'LocalTime':lambda self, ctx, gnode: hglib.displaytime(ctx.date()), 'UTCTime': lambda self, ctx, gnode: hglib.utctime(ctx.date()), 'Changes': getchanges, 'Converted': getconv, 'Phase': getphase, }
cvt = extra.get('p4', '') if cvt: return cvt return '' def getphase(self, ctx, gnode): if ctx.rev() is None: return '' try: return ctx.phasestr() except: return 'draft' _columnmap = { 'Rev': getrev, 'Node': lambda self, ctx, gnode: str(ctx), 'Graph': lambda self, ctx, gnode: "", 'Description': getlog, 'Author': getauthor, 'Tags': gettags, 'Latest tags': getlatesttags, 'Branch': getbranch, 'Filename': lambda self, ctx, gnode: gnode.extra[0], 'Age': lambda self, ctx, gnode: hglib.age(ctx.date()).decode('utf-8'), 'LocalTime': lambda self, ctx, gnode: hglib.displaytime(ctx.date()), 'UTCTime': lambda self, ctx, gnode: hglib.utctime(ctx.date()), 'Changes': getchanges, 'Converted': getconv, 'Phase': getphase, }