patman: Show the base commit and branch
It is helpful to know which commit patches are based on, even if that
commit might not be available to readers. Add a tag for this in the
cover letter.
Also add the local-branch name since that may be useful to the writer.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/u_boot_pylib/gitutil.py b/tools/u_boot_pylib/gitutil.py
index 5e3e98a..0376bec 100644
--- a/tools/u_boot_pylib/gitutil.py
+++ b/tools/u_boot_pylib/gitutil.py
@@ -701,13 +701,38 @@
.return_code == 0)
+def get_hash(spec):
+ """Get the hash of a commit
+
+ Args:
+ spec (str): Git commit to show, e.g. 'my-branch~12'
+
+ Returns:
+ str: Hash of commit
+ """
+ return command.output_one_line('git', 'show', '-s', '--pretty=format:%H',
+ spec)
+
+
def get_head():
"""Get the hash of the current HEAD
Returns:
Hash of HEAD
"""
+ return get_hash('HEAD')
+
+
+def get_branch():
+ """Get the branch we are currently on
+
+ Return:
+ str: branch name, or None if none
+ """
- return command.output_one_line('git', 'show', '-s', '--pretty=format:%H')
+ out = command.output_one_line('git', 'rev-parse', '--abbrev-ref', 'HEAD')
+ if out == 'HEAD':
+ return None
+ return out
if __name__ == "__main__":