From: Catalin Marinas Date: Tue, 4 Oct 2005 19:56:18 +0000 (+0100) Subject: Cache the HEAD value X-Git-Tag: v0.14.3~642 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/aa01a285716ffb29a62cd7d2ef5663fa2b73f568?hp=3097799dcde97cc3e1e3d6c87138f300df0ec2b6 Cache the HEAD value There are many calls to git.get_head(). This value should be cached to speed things up. Signed-off-by: Catalin Marinas --- diff --git a/stgit/git.py b/stgit/git.py index dbc44c8..7a5c9e4 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -214,10 +214,17 @@ def local_changes(): """ return len(__tree_status()) != 0 +# HEAD value cached +__head = None + def get_head(): """Verifies the HEAD and returns the SHA1 id that represents it """ - return rev_parse('HEAD') + global __head + + if not __head: + __head = rev_parse('HEAD') + return __head def get_head_file(): """Returns the name of the file pointed to by the HEAD link @@ -227,6 +234,9 @@ def get_head_file(): def __set_head(val): """Sets the HEAD value """ + global __head + + __head = val if __run('git-update-ref HEAD', [val]) != 0: raise GitException, 'Could not update HEAD to "%s".' % val