Archive release benchmark data in separate folder

Change-Id: I0ff75487590917c6dc80d11ca9c528203ee41773
diff --git a/tools/historic_run.py b/tools/historic_run.py
index 9836b1d..cef478a 100755
--- a/tools/historic_run.py
+++ b/tools/historic_run.py
@@ -56,6 +56,11 @@
     def __repr__(self):
         return self.__str__()
 
+    def branch(self):
+        result = subprocess.check_output(
+            ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode('utf-8')
+        return result.strip()
+
     def hash(self):
         return self.git_hash
 
diff --git a/tools/perf.py b/tools/perf.py
index d63fe1d..4131bce 100755
--- a/tools/perf.py
+++ b/tools/perf.py
@@ -215,8 +215,14 @@
 
 
 def GetArtifactLocation(benchmark, target, version, filename):
-    version_or_head = version or utils.get_HEAD_sha1()
-    return f'{benchmark}/{target}/{version_or_head}/{filename}'
+    if version:
+        return f'{benchmark}/{target}/{version}/{filename}'
+    else:
+        commit = utils.get_HEAD_commit()
+        branch = commit.branch()
+        if branch == 'main':
+            return f'{benchmark}/{target}/{commit.hash()}/{filename}'
+        return f'branches/{branch}/{benchmark}/{target}/{commit.hash()}/{filename}'
 
 
 def GetGSLocation(filename, bucket=BUCKET):
diff --git a/tools/utils.py b/tools/utils.py
index 66f8e36..1e26ee9 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -17,6 +17,7 @@
 import zipfile
 
 import defines
+import historic_run
 from thread_utils import print_thread
 
 ANDROID_JAR_DIR = 'third_party/android_jar/lib-v{api}'
@@ -385,6 +386,10 @@
     return result.strip()
 
 
+def get_HEAD_commit():
+    return historic_run.git_commit_from_hash(get_HEAD_sha1())
+
+
 def get_HEAD_sha1():
     return get_sha1_from_revision('HEAD')