summaryrefslogtreecommitdiffstats
path: root/gitc_utils.py
diff options
context:
space:
mode:
authorSimran Basi <sbasi@google.com>2015-08-20 12:19:28 -0700
committerDan Willemsen <dwillemsen@google.com>2015-08-28 10:53:05 -0700
commitb9a1b73425773dc97843f92aeee9c57c9a08c0f7 (patch)
tree592a3655e92af8c7265ba07e29ba35aa1a1a36a8 /gitc_utils.py
parentdc2545cad60d7e8bae894f5d60eaeb3cff7485ae (diff)
downloadgit-repo-b9a1b73425773dc97843f92aeee9c57c9a08c0f7.tar.gz
GITC: Add repo start support.
Add repo start support for GITC checkouts. If the user is in the GITC FS view, they can now run repo start to check out the sources and create a new working branch. When "repo start" is called on a GITC project, the revision tag is set to an empty string and saved in a new tag: old-revision. This tells the GITC filesystem to display the local copy of the sources when being viewed. The local copy is created by pulling the project sources and the new branch is created based off the original project revision. Updated main.py to setup each command's gitc_manifest when appropriate. Updated repo sync's logic to sync opened projects and updating the GITC manifest file for the rest. Change-Id: I7e4809d1c4fc43c69b26f2f1bebe45aab0cae628
Diffstat (limited to 'gitc_utils.py')
-rw-r--r--gitc_utils.py37
1 files changed, 34 insertions, 3 deletions
diff --git a/gitc_utils.py b/gitc_utils.py
index ef028b08..4d8d5366 100644
--- a/gitc_utils.py
+++ b/gitc_utils.py
@@ -16,6 +16,7 @@
16from __future__ import print_function 16from __future__ import print_function
17import os 17import os
18import sys 18import sys
19import time
19 20
20import git_command 21import git_command
21import git_config 22import git_config
@@ -26,6 +27,18 @@ GITC_MANIFEST_DIR = '/usr/local/google/gitc/'
26GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' 27GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
27NUM_BATCH_RETRIEVE_REVISIONID = 300 28NUM_BATCH_RETRIEVE_REVISIONID = 300
28 29
30def parse_clientdir(gitc_fs_path):
31 """Parse a path in the GITC FS and return its client name.
32
33 @param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR.
34
35 @returns: The GITC client name
36 """
37 if (gitc_fs_path == GITC_FS_ROOT_DIR or
38 not gitc_fs_path.startswith(GITC_FS_ROOT_DIR)):
39 return None
40 return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0]
41
29def _set_project_revisions(projects): 42def _set_project_revisions(projects):
30 """Sets the revisionExpr for a list of projects. 43 """Sets the revisionExpr for a list of projects.
31 44
@@ -50,19 +63,37 @@ def _set_project_revisions(projects):
50 sys.exit(1) 63 sys.exit(1)
51 proj.revisionExpr = gitcmd.stdout.split('\t')[0] 64 proj.revisionExpr = gitcmd.stdout.split('\t')[0]
52 65
53def generate_gitc_manifest(client_dir, manifest): 66def generate_gitc_manifest(client_dir, manifest, projects=None):
54 """Generate a manifest for shafsd to use for this GITC client. 67 """Generate a manifest for shafsd to use for this GITC client.
55 68
56 @param client_dir: GITC client directory to install the .manifest file in. 69 @param client_dir: GITC client directory to install the .manifest file in.
57 @param manifest: XmlManifest object representing the repo manifest. 70 @param manifest: XmlManifest object representing the repo manifest.
71 @param projects: List of projects we want to update, this must be a sublist
72 of manifest.projects to work properly. If not provided,
73 manifest.projects is used.
58 """ 74 """
59 print('Generating GITC Manifest by fetching revision SHAs for each ' 75 print('Generating GITC Manifest by fetching revision SHAs for each '
60 'project.') 76 'project.')
77 if projects is None:
78 projects = manifest.projects
61 index = 0 79 index = 0
62 while index < len(manifest.projects): 80 while index < len(projects):
63 _set_project_revisions( 81 _set_project_revisions(
64 manifest.projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) 82 projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)])
65 index += NUM_BATCH_RETRIEVE_REVISIONID 83 index += NUM_BATCH_RETRIEVE_REVISIONID
66 # Save the manifest. 84 # Save the manifest.
85 save_manifest(manifest, client_dir=client_dir)
86
87def save_manifest(manifest, client_dir=None):
88 """Save the manifest file in the client_dir.
89
90 @param client_dir: Client directory to save the manifest in.
91 @param manifest: Manifest object to save.
92 """
93 if not client_dir:
94 client_dir = manifest.gitc_client_dir
67 with open(os.path.join(client_dir, '.manifest'), 'w') as f: 95 with open(os.path.join(client_dir, '.manifest'), 'w') as f:
68 manifest.Save(f) 96 manifest.Save(f)
97 # TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
98 # Give the GITC filesystem time to register the manifest changes.
99 time.sleep(3) \ No newline at end of file