summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimran Basi <sbasi@google.com>2015-08-28 14:25:44 -0700
committerDan Willemsen <dwillemsen@google.com>2015-08-31 21:39:17 +0000
commit8ce5041596ef486510245946b7c6c68ec59add29 (patch)
tree77ba4fc3346af1f6a54d4018eae12d719671b532
parentf7a51898d3c989321c29f4ebaf7c3e9d106bc509 (diff)
downloadgit-repo-8ce5041596ef486510245946b7c6c68ec59add29.tar.gz
GITC: Pull GITC Manifest Dir from the config.
Updates the repo launcher and gitc_utils to pull the manifest directory location out of the gitc config file. Change-Id: Id08381b8a7d61962093d5cddcb3ff6afbb13004b
-rw-r--r--gitc_utils.py6
-rw-r--r--manifest_xml.py2
-rwxr-xr-xrepo29
-rw-r--r--subcmds/gitc_init.py6
-rw-r--r--subcmds/sync.py13
5 files changed, 35 insertions, 21 deletions
diff --git a/gitc_utils.py b/gitc_utils.py
index 4d8d5366..d082c8d7 100644
--- a/gitc_utils.py
+++ b/gitc_utils.py
@@ -20,13 +20,15 @@ import time
20 20
21import git_command 21import git_command
22import git_config 22import git_config
23import wrapper
23 24
24 25
25# TODO (sbasi) - Remove this constant and fetch manifest dir from /gitc/.config
26GITC_MANIFEST_DIR = '/usr/local/google/gitc/'
27GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' 26GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
28NUM_BATCH_RETRIEVE_REVISIONID = 300 27NUM_BATCH_RETRIEVE_REVISIONID = 300
29 28
29def get_gitc_manifest_dir():
30 return wrapper.Wrapper().get_gitc_manifest_dir()
31
30def parse_clientdir(gitc_fs_path): 32def parse_clientdir(gitc_fs_path):
31 """Parse a path in the GITC FS and return its client name. 33 """Parse a path in the GITC FS and return its client name.
32 34
diff --git a/manifest_xml.py b/manifest_xml.py
index b33ec627..a7fe8ddf 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -956,7 +956,7 @@ class GitcManifest(XmlManifest):
956 super(GitcManifest, self).__init__(repodir) 956 super(GitcManifest, self).__init__(repodir)
957 self.isGitcClient = True 957 self.isGitcClient = True
958 self.gitc_client_name = gitc_client_name 958 self.gitc_client_name = gitc_client_name
959 self.gitc_client_dir = os.path.join(gitc_utils.GITC_MANIFEST_DIR, 959 self.gitc_client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
960 gitc_client_name) 960 gitc_client_name)
961 self.manifestFile = os.path.join(self.gitc_client_dir, '.manifest') 961 self.manifestFile = os.path.join(self.gitc_client_dir, '.manifest')
962 962
diff --git a/repo b/repo
index bf8fa3dc..ff82159d 100755
--- a/repo
+++ b/repo
@@ -108,7 +108,7 @@ S_repo = 'repo' # special repo repository
108S_manifests = 'manifests' # special manifest repository 108S_manifests = 'manifests' # special manifest repository
109REPO_MAIN = S_repo + '/main.py' # main script 109REPO_MAIN = S_repo + '/main.py' # main script
110MIN_PYTHON_VERSION = (2, 6) # minimum supported python version 110MIN_PYTHON_VERSION = (2, 6) # minimum supported python version
111GITC_MANIFEST_DIR = '/usr/local/google/gitc' 111GITC_CONFIG_FILE = '/gitc/.config'
112 112
113 113
114import errno 114import errno
@@ -222,6 +222,20 @@ def _GitcInitOptions(init_optparse):
222 dest='gitc_client', 222 dest='gitc_client',
223 help='The name for the new gitc_client instance.') 223 help='The name for the new gitc_client instance.')
224 224
225_gitc_manifest_dir = None
226def get_gitc_manifest_dir():
227 global _gitc_manifest_dir
228 if _gitc_manifest_dir is None:
229 try:
230 with open(GITC_CONFIG_FILE, 'r') as gitc_config:
231 for line in gitc_config:
232 match = re.match('gitc_dir=(?P<gitc_manifest_dir>.*)', line)
233 if match:
234 _gitc_manifest_dir = match.group('gitc_manifest_dir')
235 except IOError:
236 _gitc_manifest_dir = ''
237 return _gitc_manifest_dir
238
225class CloneFailure(Exception): 239class CloneFailure(Exception):
226 """Indicate the remote clone of repo itself failed. 240 """Indicate the remote clone of repo itself failed.
227 """ 241 """
@@ -255,7 +269,12 @@ def _Init(args, gitc_init=False):
255 269
256 try: 270 try:
257 if gitc_init: 271 if gitc_init:
258 client_dir = os.path.join(GITC_MANIFEST_DIR, opt.gitc_client) 272 gitc_manifest_dir = get_gitc_manifest_dir()
273 if not gitc_manifest_dir:
274 _print('error: GITC filesystem is not running. Exiting...',
275 file=sys.stderr)
276 sys.exit(1)
277 client_dir = os.path.join(gitc_manifest_dir, opt.gitc_client)
259 if not os.path.exists(client_dir): 278 if not os.path.exists(client_dir):
260 os.makedirs(client_dir) 279 os.makedirs(client_dir)
261 os.chdir(client_dir) 280 os.chdir(client_dir)
@@ -746,6 +765,12 @@ def main(orig_args):
746 wrapper_path = os.path.abspath(__file__) 765 wrapper_path = os.path.abspath(__file__)
747 my_main, my_git = _RunSelf(wrapper_path) 766 my_main, my_git = _RunSelf(wrapper_path)
748 767
768 cwd = os.getcwd()
769 if cwd.startswith(get_gitc_manifest_dir()):
770 _print('error: repo cannot be used in the GITC local manifest directory.'
771 '\nIf you want to work on this GITC client please rerun this '
772 'command from the corresponding client under /gitc/', file=sys.stderr)
773 sys.exit(1)
749 if not repo_main: 774 if not repo_main:
750 if opt.help: 775 if opt.help:
751 _Usage() 776 _Usage()
diff --git a/subcmds/gitc_init.py b/subcmds/gitc_init.py
index 92b34f72..c0568caa 100644
--- a/subcmds/gitc_init.py
+++ b/subcmds/gitc_init.py
@@ -59,10 +59,10 @@ use for this GITC client.
59 if not opt.gitc_client: 59 if not opt.gitc_client:
60 print('fatal: gitc client (-c) is required', file=sys.stderr) 60 print('fatal: gitc client (-c) is required', file=sys.stderr)
61 sys.exit(1) 61 sys.exit(1)
62 self.client_dir = os.path.join(gitc_utils.GITC_MANIFEST_DIR, 62 self.client_dir = os.path.join(gitc_utils.get_gitc_manifest_dir(),
63 opt.gitc_client) 63 opt.gitc_client)
64 if not os.path.exists(gitc_utils.GITC_MANIFEST_DIR): 64 if not os.path.exists(gitc_utils.get_gitc_manifest_dir()):
65 os.makedirs(gitc_utils.GITC_MANIFEST_DIR) 65 os.makedirs(gitc_utils.get_gitc_manifest_dir())
66 if not os.path.exists(self.client_dir): 66 if not os.path.exists(self.client_dir):
67 os.mkdir(self.client_dir) 67 os.mkdir(self.client_dir)
68 super(GitcInit, self).Execute(opt, args) 68 super(GitcInit, self).Execute(opt, args)
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 934aaa80..2e9bbe70 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -194,9 +194,6 @@ later is required to fix a server side protocol bug.
194 help="overwrite an existing git directory if it needs to " 194 help="overwrite an existing git directory if it needs to "
195 "point to a different object directory. WARNING: this " 195 "point to a different object directory. WARNING: this "
196 "may cause loss of data") 196 "may cause loss of data")
197 p.add_option('--force-gitc',
198 dest='force_gitc', action='store_true',
199 help="actually sync sources in the gitc client directory.")
200 p.add_option('-l', '--local-only', 197 p.add_option('-l', '--local-only',
201 dest='local_only', action='store_true', 198 dest='local_only', action='store_true',
202 help="only update working tree, don't fetch") 199 help="only update working tree, don't fetch")
@@ -539,16 +536,6 @@ later is required to fix a server side protocol bug.
539 print('error: both -u and -p must be given', file=sys.stderr) 536 print('error: both -u and -p must be given', file=sys.stderr)
540 sys.exit(1) 537 sys.exit(1)
541 538
542 cwd = os.getcwd()
543 if cwd.startswith(gitc_utils.GITC_MANIFEST_DIR) and not opt.force_gitc:
544 print('WARNING this will pull all the sources like a normal repo sync.\n'
545 '\nIf you want to update your GITC Client View please rerun this '
546 'command in \n%s%s.\nOr if you actually want to pull the sources, '
547 'rerun with --force-gitc.' %
548 (gitc_utils.GITC_FS_ROOT_DIR,
549 cwd.split(gitc_utils.GITC_MANIFEST_DIR)[1]))
550 sys.exit(1)
551
552 if opt.manifest_name: 539 if opt.manifest_name:
553 self.manifest.Override(opt.manifest_name) 540 self.manifest.Override(opt.manifest_name)
554 541