Skip to content
Snippets Groups Projects

topic: allow specifying current topic using period

Open Sushil Khanchi requested to merge topic/default/cmd-topic-feature into branch/default
3 unresolved threads
Files
2
+ 15
7
@@ -804,14 +804,22 @@ def topics(ui, repo, topic=None, **opts):
topic = topic.strip()
if not topic:
raise error.Abort(_(b"topic name cannot consist entirely of whitespaces"))
# Have some restrictions on the topic name just like bookmark name
scmutil.checknewlabel(repo, topic, b'topic')
rmatch = re.match(br'[-_.\w]+', topic)
if not rmatch or rmatch.group(0) != topic:
helptxt = _(b"topic names can only consist of alphanumeric, '-'"
b" '_' and '.' characters")
raise error.Abort(_(b"invalid topic name: '%s'") % topic, hint=helptxt)
if topic == b'.' and touchedrevs:
    • What if we don't abort here? hg up . works fine, what's the downside of having hg topics . working as a no-op?

      Asking to try and avoid checking touchedrevs inside if topic block, because we are kinda already checking topic inside if touchedrevs block, and having things live in multiple places could lead to messy code.

      • I don't have any strong opinion, but a little inclined to the current one for msg clarity. If we do no-op here and rely on later check, abort msg would be: abort: changing topic requires a topic name or --clear which obviously not wrong, but also doesn't directly say that there is no active topic (for your hg topic . usage)

      • @av6 what do you think? ^

      • Heptapod put one of my previous comments in limbo, so my comment above is confusing. What I meant is to do

        if topic == b'.':
            topic = repo.currenttopic

        and not check touchedrevs here. Don't indent the block that checks topic name, and let it all keep working with or without touchedrevs. Basically make hg topic . not complain about topic name, but instead be a no-op.

        Edited by Anton Shestakov
      • Please register or sign in to reply
Please register or sign in to reply
# amend revisions with current active topic
topic = repo.currenttopic
if not topic:
raise error.Abort(_(b"no active topic to amend"))
    • This sounds like we're amending topic, like changing the active topic or something like that. I don't know how to phrase this better, but maybe simple "no active topic" is enough in this case.

Please register or sign in to reply
else:
# Have some restrictions on the topic name just like bookmark name
scmutil.checknewlabel(repo, topic, b'topic')
rmatch = re.match(br'[-_.\w]+', topic)
if not rmatch or rmatch.group(0) != topic:
helptxt = _(b"topic names can only consist of alphanumeric,"
b" '-' '_' and '.' characters")
raise error.Abort(_(b"invalid topic name: '%s'") % topic,
hint=helptxt)
if list:
ui.pager(b'topics')
Loading