From 28f8e387b8e5bf6ffcc0ca340bfc8717d5ffc9d5 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Tue, 2 Oct 2012 11:21:53 +0100 Subject: Extract is_valid_sha1() to morphlib.git --- morphlib/git.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'morphlib/git.py') diff --git a/morphlib/git.py b/morphlib/git.py index 5862ef9b..27f22351 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -225,3 +225,9 @@ def find_first_ref(runcmd, gitdir, ref): '''Find the *first* ref match and returns its sha1.''' return runcmd(['git', 'show-ref', ref], cwd=gitdir).split("\n")[0].split(" ")[0] + +def is_valid_sha1(ref): + '''Checks whether a string is a valid SHA1.''' + + valid_chars = 'abcdefABCDEF0123456789' + return len(ref) == 40 and all([x in valid_chars for x in ref]) -- cgit v1.2.1 From 8bcb622e182d49d143af417bd3d0a64d4188356b Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 1 Oct 2012 19:30:23 +0100 Subject: Use origin/ref for all refs other than the system branch ref itself The rationale here is that inside a checkout of a system branch, the user should only be committing to the refs for that system branch, because those are the only ones that 'morph merge' will look at. This removes a problem where we could be confused by a ref with a name that would be sorted before 'master' in the result of 'git show-ref'. --- morphlib/git.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'morphlib/git.py') diff --git a/morphlib/git.py b/morphlib/git.py index 27f22351..b3dd2c45 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -221,13 +221,12 @@ def clone_into(runcmd, srcpath, targetpath, ref=None): else: runcmd(['git', 'clone', '-b', ref, srcpath, targetpath]) -def find_first_ref(runcmd, gitdir, ref): - '''Find the *first* ref match and returns its sha1.''' - return runcmd(['git', 'show-ref', ref], - cwd=gitdir).split("\n")[0].split(" ")[0] - def is_valid_sha1(ref): '''Checks whether a string is a valid SHA1.''' valid_chars = 'abcdefABCDEF0123456789' return len(ref) == 40 and all([x in valid_chars for x in ref]) + +def rev_parse(runcmd, gitdir, ref): + '''Find the sha1 for the given ref''' + return runcmd(['git', 'rev-parse', ref], cwd=gitdir)[0:40] -- cgit v1.2.1