Auto merge of #26720 - camelid:real-version-hash, r=SimonSapin

Show the real commit hash for `./servo --version`, not the bundle hash

<!-- Please describe your changes on the following line: -->
Show the real commit hash of the build when run on a bundle commit, rather than showing the bundle's hash.

It gets the real commit hash by extracting it from the bundle commit message, which has the form `Shallow version of commit {sha1}`, where `{sha1}` is the real commit hash.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors (edits Python code, no Rust changes)
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #26386 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because this only changes infrastructure

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-06-06 11:40:22 -04:00 committed by GitHub
commit 51fd0e83e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -734,9 +734,28 @@ install them, let us know by filing a bug!")
git_info = []
if os.path.isdir('.git') and is_build:
git_sha = subprocess.check_output([
'git', 'rev-parse', '--short', 'HEAD'
# Get the subject of the commit
git_commit_subject = subprocess.check_output([
'git', 'show', '-s', '--format=%s', 'HEAD'
]).strip()
git_sha = None
# Check if it's a bundle commit
if git_commit_subject.startswith(b"Shallow version of commit "):
# This is a bundle commit
# Get the SHA-1 from the bundle subject: "Shallow version of commit {sha1}"
git_sha = git_commit_subject.split(b' ')[-1].strip()
# Shorten hash
# NOTE: Partially verifies the hash, but it will still pass if it's, e.g., a tree
git_sha = subprocess.check_output([
'git', 'rev-parse', '--short', git_sha
])
else:
# This is a regular commit
git_sha = subprocess.check_output([
'git', 'rev-parse', '--short', 'HEAD'
]).strip()
git_is_dirty = bool(subprocess.check_output([
'git', 'status', '--porcelain'
]).strip())