[tor-commits] [pytorctl/master] add function to get current branch and head

mikeperry at torproject.org mikeperry at torproject.org
Thu Sep 1 01:15:57 UTC 2011


commit a3ed3d01ff93df9d25dc64ffbacfcb6b4ef0befa
Author: aagbsn <aagbsn at extc.org>
Date:   Wed Aug 31 17:07:27 2011 -0700

    add function to get current branch and head
---
 TorUtil.py |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/TorUtil.py b/TorUtil.py
index b8d6425..50258e5 100644
--- a/TorUtil.py
+++ b/TorUtil.py
@@ -417,3 +417,25 @@ Usage:   lzprob(z)
         prob = ((1.0-x)*0.5)
     return prob
 
+def get_git_version(path_to_repo):
+  """ Returns a tuple of the branch and head from a git repo (.git)
+      if available, or returns ('unknown', 'unknown')
+  """
+  try:
+    f = open(path_to_repo+'HEAD')
+    ref = f.readline().strip().split(' ')
+    f.close()
+  except IOError, e:
+    plog('ERROR', e)
+    return ('unknown','unknown')
+  try:
+    f = open(path_to_repo+ref[1])
+    branch = ref[1].strip().split('/')[-1]
+    head = f.readline().strip()
+    f.close()
+    return (branch, head)
+  except IOError, e:
+    plog('ERROR', e)
+  except IndexError, e:
+    plog('ERROR', e)
+  return ('unknown','unknown') 



More information about the tor-commits mailing list