diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-10-02 11:21:53 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-10-03 14:40:37 +0100 |
commit | 28f8e387b8e5bf6ffcc0ca340bfc8717d5ffc9d5 (patch) | |
tree | f65a926c6ee38e3581793061fd2929668c61f1dc | |
parent | 021b065273c0fd01bd688fc121cbc778973ab7c4 (diff) | |
download | morph-28f8e387b8e5bf6ffcc0ca340bfc8717d5ffc9d5.tar.gz |
Extract is_valid_sha1() to morphlib.git
-rw-r--r-- | morphlib/cachedrepo.py | 12 | ||||
-rw-r--r-- | morphlib/git.py | 6 |
2 files changed, 9 insertions, 9 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index 61526cd7..827acf47 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -103,12 +103,6 @@ class CachedRepo(object): self.url = url self.path = path - def is_valid_sha1(self, 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 resolve_ref(self, ref): '''Attempts to resolve a ref into its SHA1 and tree SHA1. @@ -117,7 +111,7 @@ class CachedRepo(object): ''' - if not self.is_valid_sha1(ref): + if not morphlib.git.is_valid_sha1(ref): try: refs = self._show_ref(ref).split('\n') refs = [x.split() for x in refs] @@ -143,7 +137,7 @@ class CachedRepo(object): ''' - if not self.is_valid_sha1(ref): + if not morphlib.git.is_valid_sha1(ref): raise UnresolvedNamedReferenceError(self, ref) try: sha1 = self._rev_list(ref).strip() @@ -203,7 +197,7 @@ class CachedRepo(object): ''' - if not self.is_valid_sha1(ref): + if not morphlib.git.is_valid_sha1(ref): raise UnresolvedNamedReferenceError(self, ref) try: sha1 = self._rev_list(ref).strip() 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]) |