Implement 'git symbolic-ref HEAD' in Python

This is invoked once per project in `repo sync`.  Taking it out
saves about 1/114 of a second, so on a large set of projects like
Android it can save up to a full second of sync time.

Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/project.py b/project.py
index b19ab5f..311379c 100644
--- a/project.py
+++ b/project.py
@@ -237,10 +237,7 @@
        The branch name omits the 'refs/heads/' prefix.
        None is returned if the project is on a detached HEAD.
     """
-    try:
-      b = self.work_git.GetHead()
-    except GitError:
-      return None
+    b = self.work_git.GetHead()
     if b.startswith(R_HEADS):
       return b[len(R_HEADS):]
     return None
@@ -817,9 +814,8 @@
       kill.append(cb)
 
     if kill:
-      try:
-        old = self.bare_git.GetHead()
-      except GitError:
+      old = self.bare_git.GetHead()
+      if old is None:
         old = 'refs/heads/please_never_use_this_as_a_branch_name'
 
       try:
@@ -1125,7 +1121,14 @@
         p.Wait()
 
     def GetHead(self):
-      return self.symbolic_ref(HEAD)
+      if self._bare:
+        path = os.path.join(self._project.gitdir, HEAD)
+      else:
+        path = os.path.join(self._project.worktree, '.git', HEAD)
+      line = open(path, 'r').read()
+      if line.startswith('ref: '):
+        return line[5:-1]
+      return line[:-1]
 
     def SetHead(self, ref, message=None):
       cmdv = []