Mercurial > hgrepos > Python2 > PyMuPDF
changeset 24:21c6080bc183
When building "_build.py": also handle Mercurial repositories.
BUGS: Attribute names are left as-is.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 19 Sep 2025 18:19:48 +0200 |
| parents | 3b13504f9d89 |
| children | 575f70dbc259 |
| files | setup.py |
| diffstat | 1 files changed, 53 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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
