repopick: handle variant hal branching

Change-Id: Ib0dee19abc13a7fb8d8e42c09b73c1b4f35ca938
diff --git a/tools/repopick.py b/tools/repopick.py
index 2600bde..13be690 100755
--- a/tools/repopick.py
+++ b/tools/repopick.py
@@ -264,6 +264,7 @@
     # Extract information from the JSON response
     date_fluff       = '.000000000'
     project_name     = data['project']
+    project_branch   = data['branch']
     change_number    = data['_number']
     status           = data['status']
     current_revision = data['revisions'][data['current_revision']]
@@ -290,6 +291,27 @@
     #   - check that the project path exists
     if project_name in project_name_to_path:
         project_path = project_name_to_path[project_name];
+
+        if project_path.startswith('hardware/qcom/'):
+            split_path = project_path.split('/')
+            # split_path[2] might be display or it might be display-caf, trim the -caf
+            split_path[2] = split_path[2].split('-')[0]
+
+            # Need to treat hardware/qcom/{audio,display,media} specially
+            if split_path[2] == 'audio' or split_path[2] == 'display' or split_path[2] == 'media':
+                split_branch = project_branch.split('-')
+
+                # display is extra special
+                if split_path[2] == 'display' and len(split_path) == 3:
+                    project_path = '/'.join(split_path)
+                else:
+                    project_path = '/'.join(split_path[:-1])
+
+                if len(split_branch) == 4 and split_branch[0] == 'cm' and split_branch[2] == 'caf':
+                    project_path += '-caf/msm' + split_branch[3]
+                # audio and media are different from display
+                elif split_path[2] == 'audio' or split_path[2] == 'media':
+                    project_path += '/default'
     elif args.ignore_missing:
         print('WARNING: Skipping %d since there is no project directory for: %s\n' % (change_number, project_name))
         continue;