Skip to content

hg: Display formatted user name. #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Niloth-p
Copy link
Contributor

@Niloth-p Niloth-p commented Jul 8, 2025

Mercurial: Format the user name to hide the user's email in the summary line of the message.
Motivation: Updating example screenshots in integration docs.


Mercurial's ctx.user() returns the username.

The username can be set from these sources:

  • env var $HGUSER
  • [ui] username in .hgrc.
  • System username as a fallback

The username could be in any of the following formats, and may have extra spaces anywhere:

  • username <email> (the recommended format)
  • username
  • <email>

I've added a parse_user function which supports all the formats, and strips extra spaces.
It could have been written in a couple of lines, but I've kept the function elaborate and used intermediate variables for readability.

How did you test this PR?
I did not.

Self-review checklist
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

def parse_user(user: str) -> str:
"""Extract the name from user string, or fall back to email or raw string."""
# Match: "Name <[email protected]>"
match = re.match(r"^(.*)<([^>]+)>$", user)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Python have an emailaddress module for parsing these correctly? There's no reason to write custom regexes to parse standard formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants