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 preset_func(widget, item, ctx): if item == 'rev': revnum = self.get_data('revnum', *args) revid = self.get_data('revid', *args) if revid: return (revnum, revid) return None elif item == 'revnum': return ctx.rev() elif item == 'revid': return str(ctx) elif item == 'desc': return hglib.tounicode(ctx.description().replace('\0', '')) elif item == 'summary': summary = hglib.longsummary( ctx.description().replace('\0', '')) if len(summary) == 0: return None return summary elif item == 'user': user = hglib.user(ctx) if user: return hglib.tounicode(user) return None elif item == 'shortuser': return hglib.tounicode(hglib.username(hglib.user(ctx))) elif item == 'dateage': date = self.get_data('date', *args) age = self.get_data('age', *args) if date and age: return (date, age) return None elif item == 'date': date = ctx.date() if date: return hglib.displaytime(date) return None elif item == 'age': date = ctx.date() if date: return hglib.age(date).decode('utf-8') return None elif item == 'rawbranch': return ctx.branch() or None elif item == 'branch': value = self.get_data('rawbranch', *args) if value: repo = ctx._repo try: if ctx.node() != repo.branchtip(ctx.branch()): return None except error.RepoLookupError: # ctx.branch() can be invalid for null or workingctx return None if value in repo.deadbranches: return None return value return None elif item == 'close': return ctx.extra().get('close') elif item == 'tags': return ctx.thgtags() or None elif item == 'graft': extra = ctx.extra() try: return extra['source'] except KeyError: pass return None elif item == 'transplant': extra = ctx.extra() try: ts = extra['transplant_source'] if ts: return binascii.hexlify(ts) except KeyError: pass return None elif item == 'obsolete': obsoletestate = [] if ctx.obsolete(): obsoletestate.append('obsolete') if ctx.extinct(): obsoletestate.append('extinct') obsoletestate += ctx.troubles() if obsoletestate: return obsoletestate return None elif item == 'p4': extra = ctx.extra() p4cl = extra.get('p4', None) return p4cl and ('changelist %s' % p4cl) elif item == 'svn': extra = ctx.extra() cvt = extra.get('convert_revision', '') if cvt.startswith('svn:'): result = cvt.split('/', 1)[-1] if cvt != result: return result return cvt.split('@')[-1] else: return None elif item == 'converted': extra = ctx.extra() cvt = extra.get('convert_revision', '') if cvt and not cvt.startswith('svn:'): return cvt else: return None elif item == 'ishead': childbranches = [cctx.branch() for cctx in ctx.children()] return ctx.branch() not in childbranches elif item == 'mqoriginalparent': target = ctx.thgmqoriginalparent() if not target: return None p1 = ctx.p1() if p1 is not None and p1.hex() == target: return None if target not in ctx._repo: return None return target raise UnknownItem(item)
def preset_func(widget, item, ctx): if item == "rev": revnum = self.get_data("revnum", *args) revid = self.get_data("revid", *args) if revid: return (revnum, revid) return None elif item == "revnum": return ctx.rev() elif item == "revid": return str(ctx) elif item == "desc": return hglib.tounicode(ctx.description().replace("\0", "")) elif item == "summary": summary = hglib.longsummary(ctx.description().replace("\0", "")) if len(summary) == 0: return None return summary elif item == "user": user = hglib.user(ctx) if user: return hglib.tounicode(user) return None elif item == "shortuser": return hglib.tounicode(hglib.username(hglib.user(ctx))) elif item == "dateage": date = self.get_data("date", *args) age = self.get_data("age", *args) if date and age: return (date, age) return None elif item == "date": date = ctx.date() if date: return hglib.displaytime(date) return None elif item == "age": date = ctx.date() if date: return hglib.age(date).decode("utf-8") return None elif item == "rawbranch": return ctx.branch() or None elif item == "branch": value = self.get_data("rawbranch", *args) if value: repo = ctx._repo if ctx.node() not in repo.branchtags().values(): return None if value in repo.deadbranches: return None return value return None elif item == "close": return ctx.extra().get("close") elif item == "rawtags": return hglib.getrawctxtags(ctx) elif item == "tags": return hglib.getctxtags(ctx) elif item == "graft": extra = ctx.extra() try: return extra["source"] except KeyError: pass return None elif item == "transplant": extra = ctx.extra() try: ts = extra["transplant_source"] if ts: return binascii.hexlify(ts) except KeyError: pass return None elif item == "obsolete": obsoletestate = [] if ctx.obsolete(): obsoletestate.append("obsolete") if ctx.extinct(): obsoletestate.append("extinct") obsoletestate += ctx.troubles() if obsoletestate: return obsoletestate return None elif item == "p4": extra = ctx.extra() p4cl = extra.get("p4", None) return p4cl and ("changelist %s" % p4cl) elif item == "svn": extra = ctx.extra() cvt = extra.get("convert_revision", "") if cvt.startswith("svn:"): result = cvt.split("/", 1)[-1] if cvt != result: return result return cvt.split("@")[-1] else: return None elif item == "converted": extra = ctx.extra() cvt = extra.get("convert_revision", "") if cvt and not cvt.startswith("svn:"): return cvt else: return None elif item == "ishead": childbranches = [cctx.branch() for cctx in ctx.children()] return ctx.branch() not in childbranches raise UnknownItem(item)
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]
if ctx.rev() is None: return '' 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 preset_func(widget, item, ctx): if item == "rev": revnum = self.get_data("revnum", *args) revid = self.get_data("revid", *args) if revid: return (revnum, revid) return None elif item == "revnum": return ctx.rev() elif item == "revid": return str(ctx) elif item == "desc": return hglib.toutf(ctx.description().replace("\0", "")) elif item == "summary": value = ctx.description().replace("\0", "").split("\n")[0] if len(value) == 0: return None return hglib.toutf(hglib.tounicode(value)[:80]) elif item == "user": return hglib.toutf(ctx.user()) elif item == "shortuser": return hglib.toutf(hglib.username(ctx.user())) elif item == "dateage": date = self.get_data("date", *args) age = self.get_data("age", *args) if date and age: return (date, age) return None elif item == "date": date = ctx.date() if date: return hglib.displaytime(date) return None elif item == "age": date = ctx.date() if date: return hglib.age(date) return None elif item == "rawbranch": value = ctx.branch() if value: return hglib.toutf(value) return None elif item == "branch": value = self.get_data("rawbranch", *args) if value: repo = ctx._repo if ctx.node() not in repo.branchtags().values(): return None dblist = hglib.getdeadbranch(repo.ui) if value in dblist: return None return value return None elif item == "rawtags": value = [hglib.toutf(tag) for tag in ctx.tags()] if len(value) == 0: return None return value elif item == "tags": value = self.get_data("rawtags", *args) if value: htlist = hglib.gethidetags(ctx._repo.ui) tags = [tag for tag in value if tag not in htlist] if len(tags) == 0: return None return tags return None elif item == "transplant": extra = ctx.extra() try: ts = extra["transplant_source"] if ts: return binascii.hexlify(ts) except KeyError: pass return None elif item == "p4": extra = ctx.extra() p4cl = extra.get("p4", None) return p4cl and ("changelist %s" % p4cl) elif item == "svn": extra = ctx.extra() cvt = extra.get("convert_revision", "") if cvt.startswith("svn:"): result = cvt.split("/", 1)[-1] if cvt != result: return result return cvt.split("@")[-1] else: return None elif item == "ishead": childbranches = [cctx.branch() for cctx in ctx.children()] return ctx.branch() not in childbranches raise UnknownItem(item)
def preset_func(widget, item, ctx): if item == 'rev': revnum = self.get_data('revnum', *args) revid = self.get_data('revid', *args) if revid: return (revnum, revid) return None elif item == 'revnum': return ctx.rev() elif item == 'revid': return str(ctx) elif item == 'desc': return hglib.tounicode(ctx.description().replace('\0', '')) elif item == 'summary': value = ctx.description().replace('\0', '').split('\n')[0] if len(value) == 0: return None return hglib.tounicode(value)[:80] elif item == 'user': user = hglib.user(ctx) if user: return hglib.tounicode(user) return None elif item == 'shortuser': return hglib.tounicode(hglib.username(hglib.user(ctx))) elif item == 'dateage': date = self.get_data('date', *args) age = self.get_data('age', *args) if date and age: return (date, age) return None elif item == 'date': date = ctx.date() if date: return hglib.displaytime(date) return None elif item == 'age': date = ctx.date() if date: return hglib.age(date).decode('utf-8') return None elif item == 'rawbranch': return ctx.branch() or None elif item == 'branch': value = self.get_data('rawbranch', *args) if value: repo = ctx._repo if ctx.node() not in repo.branchtags().values(): return None if value in repo.deadbranches: return None return value return None elif item == 'close': return ctx.extra().get('close') elif item == 'rawtags': return hglib.getrawctxtags(ctx) elif item == 'tags': return hglib.getctxtags(ctx) elif item == 'graft': extra = ctx.extra() try: return extra['source'] except KeyError: pass return None elif item == 'transplant': extra = ctx.extra() try: ts = extra['transplant_source'] if ts: return binascii.hexlify(ts) except KeyError: pass return None elif item == 'p4': extra = ctx.extra() p4cl = extra.get('p4', None) return p4cl and ('changelist %s' % p4cl) elif item == 'svn': extra = ctx.extra() cvt = extra.get('convert_revision', '') if cvt.startswith('svn:'): result = cvt.split('/', 1)[-1] if cvt != result: return result return cvt.split('@')[-1] else: return None elif item == 'converted': extra = ctx.extra() cvt = extra.get('convert_revision', '') if cvt and not cvt.startswith('svn:'): return cvt else: return None elif item == 'ishead': childbranches = [cctx.branch() for cctx in ctx.children()] return ctx.branch() not in childbranches raise UnknownItem(item)
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, }