diff -r 4a740f9eee49 -r 522abf1d70b7 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Mon Dec 24 17:47:28 2018 +0100 +++ b/hgext3rd/topic/__init__.py Tue Jan 22 12:54:44 2019 -0500 @@ -177,10 +177,10 @@ 'topic.active': 'green', } -__version__ = '0.12.3.dev' +__version__ = '0.13.0.dev' -testedwith = '4.3.3 4.4.2 4.5.2 4.6.2 4.7' -minimumhgversion = '4.3' +testedwith = '4.4.2 4.5.2 4.6.2 4.7 4.8' +minimumhgversion = '4.4' buglink = 'https://bz.mercurial-scm.org/' if util.safehasattr(registrar, 'configitem'): @@ -680,7 +680,11 @@ txn = repo.transaction('rewrite-topics') rewrote = _changetopics(ui, repo, touchedrevs, topic) txn.close() - ui.status('changed topic on %d changes\n' % rewrote) + if topic is None: + ui.status('cleared topic on %d changesets\n' % rewrote) + else: + ui.status('changed topic on %d changesets to "%s"\n' % (rewrote, + topic)) finally: lockmod.release(txn, lock, wl) repo.invalidate() @@ -717,6 +721,8 @@ return ret @command('stack', [ + ('c', 'children', None, + _('display data about children outside of the stack')) ] + commands.formatteropts, _('hg stack [TOPIC]')) def cmdstack(ui, repo, topic='', **opts): @@ -950,17 +956,21 @@ def _listtopics(ui, repo, opts): fm = ui.formatter('topics', opts) - showlast = opts.get('age') - if showlast: - # we have a new function as plugging logic into existing function is - # pretty much difficult - return _showlasttouched(repo, fm, opts) activetopic = repo.currenttopic namemask = '%s' if repo.topics: maxwidth = max(len(t) for t in repo.topics) namemask = '%%-%is' % maxwidth - for topic in sorted(repo.topics): + if opts.get('age'): + # here we sort by age and topic name + topicsdata = sorted(_getlasttouched(repo, repo.topics)) + else: + # here we sort by topic name only + topicsdata = ( + (None, topic, None, None) + for topic in sorted(repo.topics) + ) + for age, topic, date, user in topicsdata: fm.startitem() marker = ' ' label = 'topic' @@ -977,8 +987,18 @@ if ui.quiet: fm.plain('\n') continue + fm.plain(' (') + if date: + if age == -1: + timestr = 'empty and active' + else: + timestr = templatefilters.age(date) + fm.write('lasttouched', '%s', timestr, label='topic.list.time') + if user: + fm.write('usertouched', ' by %s', user, label='topic.list.user') + if date: + fm.plain(', ') data = stack.stack(repo, topic=topic) - fm.plain(' (') if ui.verbose: fm.write('branches+', 'on branch: %s', '+'.join(data.branches), # XXX use list directly after 4.0 is released @@ -1018,52 +1038,17 @@ fm.plain(')\n') fm.end() -def _showlasttouched(repo, fm, opts): - topics = repo.topics - timedict = _getlasttouched(repo, topics) - times = timedict.keys() - times.sort() - if topics: - maxwidth = max(len(t) for t in topics) - namemask = '%%-%is' % maxwidth - activetopic = repo.currenttopic - for timevalue in times: - curtopics = sorted(timedict[timevalue][1]) - for topic, user in curtopics: - fm.startitem() - marker = ' ' - label = 'topic' - active = (topic == activetopic) - if active: - marker = '*' - label = 'topic.active' - fm.plain(' %s ' % marker, label=label) - fm.write('topic', namemask, topic, label=label) - fm.data(active=active) - fm.plain(' (') - if timevalue == -1: - timestr = 'empty and active' - else: - timestr = templatefilters.age(timedict[timevalue][0]) - fm.write('lasttouched', '%s', timestr, label='topic.list.time') - if user: - fm.write('usertouched', ' by %s', user, label='topic.list.user') - fm.plain(')') - fm.plain('\n') - fm.end() - def _getlasttouched(repo, topics): """ - Calculates the last time a topic was used. Returns a dictionary of seconds - passed from current time for a topic as keys and topic name as values. + Calculates the last time a topic was used. Returns a generator of 4-tuples: + (age in seconds, topic name, date, and user who last touched the topic). """ - topicstime = {} curtime = time.time() - for t in topics: - secspassed = -1 + for topic in topics: + age = -1 user = None maxtime = (0, 0) - trevs = repo.revs("topic(%s)", t) + trevs = repo.revs("topic(%s)", topic) # Need to check for the time of all changesets in the topic, whether # they are obsolete of non-heads # XXX: can we just rely on the max rev number for this @@ -1084,16 +1069,10 @@ maxtime = rt username = stack.parseusername(user) - topicuser = (t, username) + if trevs: + age = curtime - maxtime[0] - if trevs: - secspassed = (curtime - maxtime[0]) - try: - topicstime[secspassed][1].append(topicuser) - except KeyError: - topicstime[secspassed] = (maxtime, [topicuser]) - - return topicstime + yield (age, topic, maxtime, username) def summaryhook(ui, repo): t = getattr(repo, 'currenttopic', '')