# HG changeset patch # User Franz Glasner # Date 1758298788 -7200 # Node ID 21c6080bc183820a06d1740b86a57f7c5c7de9a9 # Parent 3b13504f9d8945af398b1e86e6b90cb51a30fdac When building "_build.py": also handle Mercurial repositories. BUGS: Attribute names are left as-is. diff -r 3b13504f9d89 -r 21c6080bc183 setup.py --- a/setup.py Fri Sep 19 12:40:07 2025 +0200 +++ b/setup.py Fri Sep 19 18:19:48 2025 +0200 @@ -366,27 +366,63 @@ Returns `(sha, comment, diff, branch)`, all items are str or None if not available. + Also handles Mercurial repository information. + directory: Root of git checkout. ''' sha, comment, diff, branch = '', '', '', '' - cp = subprocess.run( - f'cd {directory} && (PAGER= git show --pretty=oneline|head -n 1 && git diff)', - capture_output=1, - shell=1, - text=1, - ) - if cp.returncode == 0: - sha, _ = cp.stdout.split(' ', 1) - comment, diff = _.split('\n', 1) - cp = subprocess.run( - f'cd {directory} && git rev-parse --abbrev-ref HEAD', - capture_output=1, - shell=1, - text=1, - ) - if cp.returncode == 0: - branch = cp.stdout.strip() + if os.path.isdir(os.path.join(directory, '.hg')): + cp = subprocess.run( + f'hg -R {directory} id -i', + capture_output=1, + shell=1, + text=1, + ) + if cp.returncode == 0: + sha = cp.stdout.strip() + cp = subprocess.run( + f'hg -R {directory} diff --git', + capture_output=1, + shell=1, + text=1, + ) + if cp.returncode == 0: + diff = cp.stdout + cp = subprocess.run( + f'hg -R {directory} log -r. --template "{{branch}}"', + capture_output=1, + shell=1, + text=1, + ) + if cp.returncode == 0: + branch = cp.stdout.strip() + fp = subprocess.run( + f'hg -R {directory} log -r. --template "{{desc|firstline}}"', + capture_output=1, + shell=1, + text=1, + ) + if cp.returncode == 0: + comment = cp.stdout.strip() + else: + cp = subprocess.run( + f'cd {directory} && (PAGER= git show --pretty=oneline|head -n 1 && git diff)', + capture_output=1, + shell=1, + text=1, + ) + if cp.returncode == 0: + sha, _ = cp.stdout.split(' ', 1) + comment, diff = _.split('\n', 1) + cp = subprocess.run( + f'cd {directory} && git rev-parse --abbrev-ref HEAD', + capture_output=1, + shell=1, + text=1, + ) + if cp.returncode == 0: + branch = cp.stdout.strip() log(f'git_info(): directory={directory!r} returning branch={branch!r} sha={sha!r} comment={comment!r}') return sha, comment, diff, branch