From fdaa75354a7638e5044f25f65a0563caabd3b88c Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Wed, 17 Apr 2019 11:16:03 -0700 Subject: [PATCH] chore: save HEAD when git-import-patches runs (#17824) --- script/git-export-patches | 37 +++++++++++++++++++++++++++++-------- script/git-import-patches | 6 ++++++ script/lib/git.py | 6 ++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/script/git-export-patches b/script/git-export-patches index 7983e48c2391..de68c485aaa1 100755 --- a/script/git-export-patches +++ b/script/git-export-patches @@ -9,14 +9,35 @@ import sys def guess_base_commit(repo): """Guess which commit the patches might be based on""" - args = [ - 'git', - '-C', - repo, - 'describe', - '--tags', - ] - return subprocess.check_output(args).rsplit('-', 2)[0:2] + try: + args = [ + 'git', + '-C', + repo, + 'rev-parse', + '--verify', + 'refs/patches/upstream-head', + ] + upstream_head = subprocess.check_output(args).strip() + args = [ + 'git', + '-C', + repo, + 'rev-list', + '--count', + upstream_head + '..', + ] + num_commits = subprocess.check_output(args).strip() + return [upstream_head, num_commits] + except subprocess.CalledProcessError: + args = [ + 'git', + '-C', + repo, + 'describe', + '--tags', + ] + return subprocess.check_output(args).rsplit('-', 2)[0:2] def format_patch(repo, since): diff --git a/script/git-import-patches b/script/git-import-patches index 91d7e1e540b0..5401f371a695 100755 --- a/script/git-import-patches +++ b/script/git-import-patches @@ -17,6 +17,12 @@ def main(argv): help="use 3-way merge to resolve conflicts") args = parser.parse_args(argv) + # save the upstream HEAD so we can refer to it when we later export patches + git.update_ref( + repo='.', + ref='refs/patches/upstream-head', + newvalue='HEAD' + ) git.am( repo='.', patch_data=patch_from_dir(args.patch_dir), diff --git a/script/lib/git.py b/script/lib/git.py index 556bab9308e2..ef2b0bab44e0 100644 --- a/script/lib/git.py +++ b/script/lib/git.py @@ -102,6 +102,12 @@ def get_head_commit(repo): return subprocess.check_output(args).strip() +def update_ref(repo, ref, newvalue): + args = ['git', '-C', repo, 'update-ref', ref, newvalue] + + return subprocess.check_call(args) + + def reset(repo): args = ['git', '-C', repo, 'reset']