summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2015-09-09 21:44:11 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-09-09 21:44:11 +0000
commit5cc384034d144c339d2e5822c36c5ca4529ac487 (patch)
treee2a5cb35a8ea85984c7e4f92bac9fffd4d1e617c
parentc32ba1961e3451101ce94a26f83cf56681ff6414 (diff)
parent037552333182497e9e38bff984de44df0f93e54b (diff)
downloadgit-repo-5cc384034d144c339d2e5822c36c5ca4529ac487.tar.gz
Merge "Revert "GITC: Always update the gitc manifest from the repo manifest""v1.12.30.1
-rw-r--r--gitc_utils.py85
-rw-r--r--manifest_xml.py5
-rw-r--r--subcmds/gitc_init.py8
-rw-r--r--subcmds/start.py10
-rw-r--r--subcmds/sync.py26
5 files changed, 34 insertions, 100 deletions
diff --git a/gitc_utils.py b/gitc_utils.py
index 04307a3c..d082c8d7 100644
--- a/gitc_utils.py
+++ b/gitc_utils.py
@@ -15,8 +15,6 @@
15 15
16from __future__ import print_function 16from __future__ import print_function
17import os 17import os
18import platform
19import re
20import sys 18import sys
21import time 19import time
22 20
@@ -24,7 +22,6 @@ import git_command
24import git_config 22import git_config
25import wrapper 23import wrapper
26 24
27from manifest_xml import GitcManifest
28 25
29GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' 26GITC_FS_ROOT_DIR = '/gitc/manifest-rw/'
30NUM_BATCH_RETRIEVE_REVISIONID = 300 27NUM_BATCH_RETRIEVE_REVISIONID = 300
@@ -68,86 +65,26 @@ def _set_project_revisions(projects):
68 sys.exit(1) 65 sys.exit(1)
69 proj.revisionExpr = gitcmd.stdout.split('\t')[0] 66 proj.revisionExpr = gitcmd.stdout.split('\t')[0]
70 67
71def _manifest_groups(manifest): 68def generate_gitc_manifest(client_dir, manifest, projects=None):
72 """Returns the manifest group string that should be synced
73
74 This is the same logic used by Command.GetProjects(), which is used during
75 repo sync
76
77 @param manifest: The XmlManifest object
78 """
79 mp = manifest.manifestProject
80 groups = mp.config.GetString('manifest.groups')
81 if not groups:
82 groups = 'default,platform-' + platform.system().lower()
83 return groups
84
85def generate_gitc_manifest(repodir, client_name, gitc_manifest, repo_manifest_file, paths=None):
86 """Generate a manifest for shafsd to use for this GITC client. 69 """Generate a manifest for shafsd to use for this GITC client.
87 70
88 @param repodir: The repo directory 71 @param client_dir: GITC client directory to install the .manifest file in.
89 @param client_name: The gitc client name 72 @param manifest: XmlManifest object representing the repo manifest.
90 @param gitc_manifest: Current gitc manifest, or None if there isn't one yet 73 @param projects: List of projects we want to update, this must be a sublist
91 @param repo_manifest_file: The file used by the main repo manifest 74 of manifest.projects to work properly. If not provided,
92 @param paths: List of project paths we want to update. 75 manifest.projects is used.
93 """ 76 """
94 manifest = GitcManifest(repodir, client_name)
95 manifest.Override(repo_manifest_file)
96
97 print('Generating GITC Manifest by fetching revision SHAs for each ' 77 print('Generating GITC Manifest by fetching revision SHAs for each '
98 'project.') 78 'project.')
99 if paths is None: 79 if projects is None:
100 paths = manifest.paths.keys() 80 projects = manifest.projects
101
102 groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x]
103
104 # Convert the paths to projects, and filter them to the matched groups.
105 projects = [manifest.paths[p] for p in paths]
106 projects = [p for p in projects if p.MatchesGroups(groups)]
107
108 if gitc_manifest is not None:
109 for path, proj in manifest.paths.iteritems():
110 if not proj.MatchesGroups(groups):
111 continue
112
113 if not proj.upstream and not git_config.IsId(proj.revisionExpr):
114 proj.upstream = proj.revisionExpr
115
116 if not path in gitc_manifest.paths:
117 # Any new projects need their first revision, even if we weren't asked
118 # for them.
119 projects.append(proj)
120 elif not path in paths:
121 # And copy revisions from the previous manifest if we're not updating
122 # them now.
123 gitc_proj = gitc_manifest.paths[path]
124 if gitc_proj.old_revision:
125 proj.revisionExpr = None
126 proj.old_revision = gitc_proj.old_revision
127 else:
128 proj.revisionExpr = gitc_proj.revisionExpr
129
130 index = 0 81 index = 0
131 while index < len(projects): 82 while index < len(projects):
132 _set_project_revisions( 83 _set_project_revisions(
133 projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) 84 projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)])
134 index += NUM_BATCH_RETRIEVE_REVISIONID 85 index += NUM_BATCH_RETRIEVE_REVISIONID
135
136 if gitc_manifest is not None:
137 for path, proj in gitc_manifest.paths.iteritems():
138 if proj.old_revision and path in paths:
139 # If we updated a project that has been started, keep the old-revision
140 # updated.
141 repo_proj = manifest.paths[path]
142 repo_proj.old_revision = repo_proj.revisionExpr
143 repo_proj.revisionExpr = None
144
145 # Convert URLs from relative to absolute.
146 for name, remote in manifest.remotes.iteritems():
147 remote.fetchUrl = remote.resolvedFetchUrl
148
149 # Save the manifest. 86 # Save the manifest.
150 save_manifest(manifest) 87 save_manifest(manifest, client_dir=client_dir)
151 88
152def save_manifest(manifest, client_dir=None): 89def save_manifest(manifest, client_dir=None):
153 """Save the manifest file in the client_dir. 90 """Save the manifest file in the client_dir.
@@ -158,7 +95,7 @@ def save_manifest(manifest, client_dir=None):
158 if not client_dir: 95 if not client_dir:
159 client_dir = manifest.gitc_client_dir 96 client_dir = manifest.gitc_client_dir
160 with open(os.path.join(client_dir, '.manifest'), 'w') as f: 97 with open(os.path.join(client_dir, '.manifest'), 'w') as f:
161 manifest.Save(f, groups=_manifest_groups(manifest)) 98 manifest.Save(f)
162 # TODO(sbasi/jorg): Come up with a solution to remove the sleep below. 99 # TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
163 # Give the GITC filesystem time to register the manifest changes. 100 # Give the GITC filesystem time to register the manifest changes.
164 time.sleep(3) 101 time.sleep(3) \ No newline at end of file
diff --git a/manifest_xml.py b/manifest_xml.py
index 3ac607ec..a7fe8ddf 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -167,13 +167,12 @@ class XmlManifest(object):
167 def _ParseGroups(self, groups): 167 def _ParseGroups(self, groups):
168 return [x for x in re.split(r'[,\s]+', groups) if x] 168 return [x for x in re.split(r'[,\s]+', groups) if x]
169 169
170 def Save(self, fd, peg_rev=False, peg_rev_upstream=True, groups=None): 170 def Save(self, fd, peg_rev=False, peg_rev_upstream=True):
171 """Write the current manifest out to the given file descriptor. 171 """Write the current manifest out to the given file descriptor.
172 """ 172 """
173 mp = self.manifestProject 173 mp = self.manifestProject
174 174
175 if groups is None: 175 groups = mp.config.GetString('manifest.groups')
176 groups = mp.config.GetString('manifest.groups')
177 if groups: 176 if groups:
178 groups = self._ParseGroups(groups) 177 groups = self._ParseGroups(groups)
179 178
diff --git a/subcmds/gitc_init.py b/subcmds/gitc_init.py
index c957a9dc..e99affa5 100644
--- a/subcmds/gitc_init.py
+++ b/subcmds/gitc_init.py
@@ -68,13 +68,15 @@ use for this GITC client.
68 os.mkdir(self.client_dir) 68 os.mkdir(self.client_dir)
69 super(GitcInit, self).Execute(opt, args) 69 super(GitcInit, self).Execute(opt, args)
70 70
71 manifest_file = self.manifest.manifestFile 71 for name, remote in self.manifest.remotes.iteritems():
72 remote.fetchUrl = remote.resolvedFetchUrl
73
72 if opt.manifest_file: 74 if opt.manifest_file:
73 if not os.path.exists(opt.manifest_file): 75 if not os.path.exists(opt.manifest_file):
74 print('fatal: Specified manifest file %s does not exist.' % 76 print('fatal: Specified manifest file %s does not exist.' %
75 opt.manifest_file) 77 opt.manifest_file)
76 sys.exit(1) 78 sys.exit(1)
77 manifest_file = opt.manifest_file 79 self.manifest.Override(opt.manifest_file)
78 gitc_utils.generate_gitc_manifest(self.repodir, opt.gitc_client, None, manifest_file) 80 gitc_utils.generate_gitc_manifest(self.client_dir, self.manifest)
79 print('Please run `cd %s` to view your GITC client.' % 81 print('Please run `cd %s` to view your GITC client.' %
80 os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client)) 82 os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client))
diff --git a/subcmds/start.py b/subcmds/start.py
index 940c3413..188fd7c6 100644
--- a/subcmds/start.py
+++ b/subcmds/start.py
@@ -57,6 +57,7 @@ revision specified in the manifest.
57 print("error: at least one project must be specified", file=sys.stderr) 57 print("error: at least one project must be specified", file=sys.stderr)
58 sys.exit(1) 58 sys.exit(1)
59 59
60 proj_name_to_gitc_proj_dict = {}
60 if self.gitc_manifest: 61 if self.gitc_manifest:
61 all_projects = self.GetProjects(projects, manifest=self.gitc_manifest, 62 all_projects = self.GetProjects(projects, manifest=self.gitc_manifest,
62 missing_ok=True) 63 missing_ok=True)
@@ -66,6 +67,7 @@ revision specified in the manifest.
66 else: 67 else:
67 project.already_synced = False 68 project.already_synced = False
68 project.old_revision = project.revisionExpr 69 project.old_revision = project.revisionExpr
70 proj_name_to_gitc_proj_dict[project.name] = project
69 project.revisionExpr = None 71 project.revisionExpr = None
70 # Save the GITC manifest. 72 # Save the GITC manifest.
71 gitc_utils.save_manifest(self.gitc_manifest) 73 gitc_utils.save_manifest(self.gitc_manifest)
@@ -75,10 +77,9 @@ revision specified in the manifest.
75 pm = Progress('Starting %s' % nb, len(all_projects)) 77 pm = Progress('Starting %s' % nb, len(all_projects))
76 for project in all_projects: 78 for project in all_projects:
77 pm.update() 79 pm.update()
78
79 if self.gitc_manifest: 80 if self.gitc_manifest:
80 gitc_project = self.gitc_manifest.paths[project.relpath] 81 gitc_project = proj_name_to_gitc_proj_dict[project.name]
81 # Sync projects that have not been opened. 82 # Sync projects that have already been opened.
82 if not gitc_project.already_synced: 83 if not gitc_project.already_synced:
83 proj_localdir = os.path.join(self.gitc_manifest.gitc_client_dir, 84 proj_localdir = os.path.join(self.gitc_manifest.gitc_client_dir,
84 project.relpath) 85 project.relpath)
@@ -88,7 +89,7 @@ revision specified in the manifest.
88 project.Sync_NetworkHalf() 89 project.Sync_NetworkHalf()
89 sync_buf = SyncBuffer(self.manifest.manifestProject.config) 90 sync_buf = SyncBuffer(self.manifest.manifestProject.config)
90 project.Sync_LocalHalf(sync_buf) 91 project.Sync_LocalHalf(sync_buf)
91 project.revisionId = gitc_project.old_revision 92 project.revisionExpr = gitc_project.old_revision
92 93
93 # If the current revision is a specific SHA1 then we can't push back 94 # If the current revision is a specific SHA1 then we can't push back
94 # to it; so substitute with dest_branch if defined, or with manifest 95 # to it; so substitute with dest_branch if defined, or with manifest
@@ -99,7 +100,6 @@ revision specified in the manifest.
99 branch_merge = project.dest_branch 100 branch_merge = project.dest_branch
100 else: 101 else:
101 branch_merge = self.manifest.default.revisionExpr 102 branch_merge = self.manifest.default.revisionExpr
102
103 if not project.StartBranch(nb, branch_merge=branch_merge): 103 if not project.StartBranch(nb, branch_merge=branch_merge):
104 err.append(project) 104 err.append(project)
105 pm.end() 105 pm.end()
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 79cfaaa5..7b44dbd8 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -670,36 +670,32 @@ later is required to fix a server side protocol bug.
670 if opt.jobs is None: 670 if opt.jobs is None:
671 self.jobs = self.manifest.default.sync_j 671 self.jobs = self.manifest.default.sync_j
672 672
673 # TODO (sbasi) - Add support for manifest changes, aka projects
674 # have been added or deleted from the manifest.
673 if self.gitc_manifest: 675 if self.gitc_manifest:
674 gitc_manifest_projects = self.GetProjects(args, 676 gitc_manifest_projects = self.GetProjects(args,
677 manifest=self.gitc_manifest,
675 missing_ok=True) 678 missing_ok=True)
676 gitc_projects = [] 679 gitc_projects = []
677 opened_projects = [] 680 opened_projects = []
678 for project in gitc_manifest_projects: 681 for project in gitc_manifest_projects:
679 if project.relpath in self.gitc_manifest.paths and \ 682 if not project.old_revision:
680 self.gitc_manifest.paths[project.relpath].old_revision: 683 gitc_projects.append(project)
681 opened_projects.append(project.relpath)
682 else: 684 else:
683 gitc_projects.append(project.relpath) 685 opened_projects.append(project)
684 686
685 if not args: 687 if gitc_projects and not opt.local_only:
686 gitc_projects = None
687
688 if gitc_projects != [] and not opt.local_only:
689 print('Updating GITC client: %s' % self.gitc_manifest.gitc_client_name) 688 print('Updating GITC client: %s' % self.gitc_manifest.gitc_client_name)
690 gitc_utils.generate_gitc_manifest(self.repodir, 689 gitc_utils.generate_gitc_manifest(self.gitc_manifest.gitc_client_dir,
691 self.gitc_manifest.gitc_client_name,
692 self.gitc_manifest, 690 self.gitc_manifest,
693 self.manifest.manifestFile,
694 gitc_projects) 691 gitc_projects)
695 print('GITC client successfully synced.') 692 print('GITC client successfully synced.')
696 693
697 # The opened projects need to be synced as normal, therefore we 694 # The opened projects need to be synced as normal, therefore we
698 # generate a new args list to represent the opened projects. 695 # generate a new args list to represent the opened projects.
699 # TODO: make this more reliable -- if there's a project name/path overlap, 696 args = []
700 # this may choose the wrong project. 697 for proj in opened_projects:
701 args = [os.path.relpath(self.manifest.paths[p].worktree, os.getcwd()) 698 args.append(os.path.relpath(proj.worktree, os.getcwd()))
702 for p in opened_projects]
703 if not args: 699 if not args:
704 return 700 return
705 all_projects = self.GetProjects(args, 701 all_projects = self.GetProjects(args,