diff options
-rw-r--r-- | docs/manifest-format.txt | 27 | ||||
-rw-r--r-- | gitc_utils.py | 81 | ||||
-rw-r--r-- | manifest_xml.py | 5 | ||||
-rw-r--r-- | project.py | 4 | ||||
-rw-r--r-- | subcmds/gitc_init.py | 14 | ||||
-rw-r--r-- | subcmds/start.py | 10 | ||||
-rw-r--r-- | subcmds/sync.py | 32 |
7 files changed, 135 insertions, 38 deletions
diff --git a/docs/manifest-format.txt b/docs/manifest-format.txt index 1aa93965..7f138209 100644 --- a/docs/manifest-format.txt +++ b/docs/manifest-format.txt | |||
@@ -50,7 +50,9 @@ following DTD: | |||
50 | <!ATTLIST url CDATA #REQUIRED> | 50 | <!ATTLIST url CDATA #REQUIRED> |
51 | 51 | ||
52 | <!ELEMENT project (annotation*, | 52 | <!ELEMENT project (annotation*, |
53 | project*)> | 53 | project*, |
54 | copyfile?, | ||
55 | linkfile?)> | ||
54 | <!ATTLIST project name CDATA #REQUIRED> | 56 | <!ATTLIST project name CDATA #REQUIRED> |
55 | <!ATTLIST project path CDATA #IMPLIED> | 57 | <!ATTLIST project path CDATA #IMPLIED> |
56 | <!ATTLIST project remote IDREF #IMPLIED> | 58 | <!ATTLIST project remote IDREF #IMPLIED> |
@@ -68,6 +70,14 @@ following DTD: | |||
68 | <!ATTLIST annotation value CDATA #REQUIRED> | 70 | <!ATTLIST annotation value CDATA #REQUIRED> |
69 | <!ATTLIST annotation keep CDATA "true"> | 71 | <!ATTLIST annotation keep CDATA "true"> |
70 | 72 | ||
73 | <!ELEMENT copyfile (EMPTY)> | ||
74 | <!ATTLIST src value CDATA #REQUIRED> | ||
75 | <!ATTLIST dest value CDATA #REQUIRED> | ||
76 | |||
77 | <!ELEMENT linkfile (EMPTY)> | ||
78 | <!ATTLIST src value CDATA #REQUIRED> | ||
79 | <!ATTLIST dest value CDATA #REQUIRED> | ||
80 | |||
71 | <!ELEMENT extend-project> | 81 | <!ELEMENT extend-project> |
72 | <!ATTLIST extend-project name CDATA #REQUIRED> | 82 | <!ATTLIST extend-project name CDATA #REQUIRED> |
73 | <!ATTLIST extend-project path CDATA #IMPLIED> | 83 | <!ATTLIST extend-project path CDATA #IMPLIED> |
@@ -285,6 +295,21 @@ prefixed with REPO__. In addition, there is an optional attribute | |||
285 | "false". This attribute determines whether or not the annotation will | 295 | "false". This attribute determines whether or not the annotation will |
286 | be kept when exported with the manifest subcommand. | 296 | be kept when exported with the manifest subcommand. |
287 | 297 | ||
298 | Element copyfile | ||
299 | ---------------- | ||
300 | |||
301 | Zero or more copyfile elements may be specified as children of a | ||
302 | project element. Each element describes a src-dest pair of files; | ||
303 | the "src" file will be copied to the "dest" place during 'repo sync' | ||
304 | command. | ||
305 | "src" is project relative, "dest" is relative to the top of the tree. | ||
306 | |||
307 | Element linkfile | ||
308 | ---------------- | ||
309 | |||
310 | It's just like copyfile and runs at the same time as copyfile but | ||
311 | instead of copying it creates a symlink. | ||
312 | |||
288 | Element remove-project | 313 | Element remove-project |
289 | ---------------------- | 314 | ---------------------- |
290 | 315 | ||
diff --git a/gitc_utils.py b/gitc_utils.py index d082c8d7..dd38f890 100644 --- a/gitc_utils.py +++ b/gitc_utils.py | |||
@@ -15,6 +15,8 @@ | |||
15 | 15 | ||
16 | from __future__ import print_function | 16 | from __future__ import print_function |
17 | import os | 17 | import os |
18 | import platform | ||
19 | import re | ||
18 | import sys | 20 | import sys |
19 | import time | 21 | import time |
20 | 22 | ||
@@ -22,7 +24,6 @@ import git_command | |||
22 | import git_config | 24 | import git_config |
23 | import wrapper | 25 | import wrapper |
24 | 26 | ||
25 | |||
26 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' | 27 | GITC_FS_ROOT_DIR = '/gitc/manifest-rw/' |
27 | NUM_BATCH_RETRIEVE_REVISIONID = 300 | 28 | NUM_BATCH_RETRIEVE_REVISIONID = 300 |
28 | 29 | ||
@@ -65,26 +66,82 @@ def _set_project_revisions(projects): | |||
65 | sys.exit(1) | 66 | sys.exit(1) |
66 | proj.revisionExpr = gitcmd.stdout.split('\t')[0] | 67 | proj.revisionExpr = gitcmd.stdout.split('\t')[0] |
67 | 68 | ||
68 | def generate_gitc_manifest(client_dir, manifest, projects=None): | 69 | def _manifest_groups(manifest): |
70 | """Returns the manifest group string that should be synced | ||
71 | |||
72 | This is the same logic used by Command.GetProjects(), which is used during | ||
73 | repo sync | ||
74 | |||
75 | @param manifest: The XmlManifest object | ||
76 | """ | ||
77 | mp = manifest.manifestProject | ||
78 | groups = mp.config.GetString('manifest.groups') | ||
79 | if not groups: | ||
80 | groups = 'default,platform-' + platform.system().lower() | ||
81 | return groups | ||
82 | |||
83 | def generate_gitc_manifest(gitc_manifest, manifest, paths=None): | ||
69 | """Generate a manifest for shafsd to use for this GITC client. | 84 | """Generate a manifest for shafsd to use for this GITC client. |
70 | 85 | ||
71 | @param client_dir: GITC client directory to install the .manifest file in. | 86 | @param gitc_manifest: Current gitc manifest, or None if there isn't one yet. |
72 | @param manifest: XmlManifest object representing the repo manifest. | 87 | @param manifest: A GitcManifest object loaded with the current repo manifest. |
73 | @param projects: List of projects we want to update, this must be a sublist | 88 | @param paths: List of project paths we want to update. |
74 | of manifest.projects to work properly. If not provided, | ||
75 | manifest.projects is used. | ||
76 | """ | 89 | """ |
90 | |||
77 | print('Generating GITC Manifest by fetching revision SHAs for each ' | 91 | print('Generating GITC Manifest by fetching revision SHAs for each ' |
78 | 'project.') | 92 | 'project.') |
79 | if projects is None: | 93 | if paths is None: |
80 | projects = manifest.projects | 94 | paths = manifest.paths.keys() |
95 | |||
96 | groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x] | ||
97 | |||
98 | # Convert the paths to projects, and filter them to the matched groups. | ||
99 | projects = [manifest.paths[p] for p in paths] | ||
100 | projects = [p for p in projects if p.MatchesGroups(groups)] | ||
101 | |||
102 | if gitc_manifest is not None: | ||
103 | for path, proj in manifest.paths.iteritems(): | ||
104 | if not proj.MatchesGroups(groups): | ||
105 | continue | ||
106 | |||
107 | if not proj.upstream and not git_config.IsId(proj.revisionExpr): | ||
108 | proj.upstream = proj.revisionExpr | ||
109 | |||
110 | if not path in gitc_manifest.paths: | ||
111 | # Any new projects need their first revision, even if we weren't asked | ||
112 | # for them. | ||
113 | projects.append(proj) | ||
114 | elif not path in paths: | ||
115 | # And copy revisions from the previous manifest if we're not updating | ||
116 | # them now. | ||
117 | gitc_proj = gitc_manifest.paths[path] | ||
118 | if gitc_proj.old_revision: | ||
119 | proj.revisionExpr = None | ||
120 | proj.old_revision = gitc_proj.old_revision | ||
121 | else: | ||
122 | proj.revisionExpr = gitc_proj.revisionExpr | ||
123 | |||
81 | index = 0 | 124 | index = 0 |
82 | while index < len(projects): | 125 | while index < len(projects): |
83 | _set_project_revisions( | 126 | _set_project_revisions( |
84 | projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) | 127 | projects[index:(index+NUM_BATCH_RETRIEVE_REVISIONID)]) |
85 | index += NUM_BATCH_RETRIEVE_REVISIONID | 128 | index += NUM_BATCH_RETRIEVE_REVISIONID |
129 | |||
130 | if gitc_manifest is not None: | ||
131 | for path, proj in gitc_manifest.paths.iteritems(): | ||
132 | if proj.old_revision and path in paths: | ||
133 | # If we updated a project that has been started, keep the old-revision | ||
134 | # updated. | ||
135 | repo_proj = manifest.paths[path] | ||
136 | repo_proj.old_revision = repo_proj.revisionExpr | ||
137 | repo_proj.revisionExpr = None | ||
138 | |||
139 | # Convert URLs from relative to absolute. | ||
140 | for name, remote in manifest.remotes.iteritems(): | ||
141 | remote.fetchUrl = remote.resolvedFetchUrl | ||
142 | |||
86 | # Save the manifest. | 143 | # Save the manifest. |
87 | save_manifest(manifest, client_dir=client_dir) | 144 | save_manifest(manifest) |
88 | 145 | ||
89 | def save_manifest(manifest, client_dir=None): | 146 | def save_manifest(manifest, client_dir=None): |
90 | """Save the manifest file in the client_dir. | 147 | """Save the manifest file in the client_dir. |
@@ -95,7 +152,7 @@ def save_manifest(manifest, client_dir=None): | |||
95 | if not client_dir: | 152 | if not client_dir: |
96 | client_dir = manifest.gitc_client_dir | 153 | client_dir = manifest.gitc_client_dir |
97 | with open(os.path.join(client_dir, '.manifest'), 'w') as f: | 154 | with open(os.path.join(client_dir, '.manifest'), 'w') as f: |
98 | manifest.Save(f) | 155 | manifest.Save(f, groups=_manifest_groups(manifest)) |
99 | # TODO(sbasi/jorg): Come up with a solution to remove the sleep below. | 156 | # TODO(sbasi/jorg): Come up with a solution to remove the sleep below. |
100 | # Give the GITC filesystem time to register the manifest changes. | 157 | # Give the GITC filesystem time to register the manifest changes. |
101 | time.sleep(3) \ No newline at end of file | 158 | time.sleep(3) |
diff --git a/manifest_xml.py b/manifest_xml.py index a7fe8ddf..3ac607ec 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -167,12 +167,13 @@ 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): | 170 | def Save(self, fd, peg_rev=False, peg_rev_upstream=True, groups=None): |
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 | groups = mp.config.GetString('manifest.groups') | 175 | if groups is None: |
176 | groups = mp.config.GetString('manifest.groups') | ||
176 | if groups: | 177 | if groups: |
177 | groups = self._ParseGroups(groups) | 178 | groups = self._ParseGroups(groups) |
178 | 179 | ||
@@ -1275,6 +1275,8 @@ class Project(object): | |||
1275 | # Except if the head needs to be detached | 1275 | # Except if the head needs to be detached |
1276 | # | 1276 | # |
1277 | if not syncbuf.detach_head: | 1277 | if not syncbuf.detach_head: |
1278 | # The copy/linkfile config may have changed. | ||
1279 | self._CopyAndLinkFiles() | ||
1278 | return | 1280 | return |
1279 | else: | 1281 | else: |
1280 | lost = self._revlist(not_rev(revid), HEAD) | 1282 | lost = self._revlist(not_rev(revid), HEAD) |
@@ -1292,6 +1294,8 @@ class Project(object): | |||
1292 | if head == revid: | 1294 | if head == revid: |
1293 | # No changes; don't do anything further. | 1295 | # No changes; don't do anything further. |
1294 | # | 1296 | # |
1297 | # The copy/linkfile config may have changed. | ||
1298 | self._CopyAndLinkFiles() | ||
1295 | return | 1299 | return |
1296 | 1300 | ||
1297 | branch = self.GetBranch(branch) | 1301 | branch = self.GetBranch(branch) |
diff --git a/subcmds/gitc_init.py b/subcmds/gitc_init.py index e99affa5..c243bb3b 100644 --- a/subcmds/gitc_init.py +++ b/subcmds/gitc_init.py | |||
@@ -19,6 +19,7 @@ import sys | |||
19 | 19 | ||
20 | import gitc_utils | 20 | import gitc_utils |
21 | from command import RequiresGitcCommand | 21 | from command import RequiresGitcCommand |
22 | from manifest_xml import GitcManifest | ||
22 | from subcmds import init | 23 | from subcmds import init |
23 | 24 | ||
24 | 25 | ||
@@ -34,7 +35,7 @@ with the GITC file system. | |||
34 | 35 | ||
35 | This command will setup the client directory, initialize repo, just | 36 | This command will setup the client directory, initialize repo, just |
36 | like repo init does, and then downloads the manifest collection | 37 | like repo init does, and then downloads the manifest collection |
37 | and installs in in the .repo/directory of the GITC client. | 38 | and installs it in the .repo/directory of the GITC client. |
38 | 39 | ||
39 | Once this is done, a GITC manifest is generated by pulling the HEAD | 40 | Once this is done, a GITC manifest is generated by pulling the HEAD |
40 | SHA for each project and generates the properly formatted XML file | 41 | SHA for each project and generates the properly formatted XML file |
@@ -68,15 +69,16 @@ use for this GITC client. | |||
68 | os.mkdir(self.client_dir) | 69 | os.mkdir(self.client_dir) |
69 | super(GitcInit, self).Execute(opt, args) | 70 | super(GitcInit, self).Execute(opt, args) |
70 | 71 | ||
71 | for name, remote in self.manifest.remotes.iteritems(): | 72 | manifest_file = self.manifest.manifestFile |
72 | remote.fetchUrl = remote.resolvedFetchUrl | ||
73 | |||
74 | if opt.manifest_file: | 73 | if opt.manifest_file: |
75 | if not os.path.exists(opt.manifest_file): | 74 | if not os.path.exists(opt.manifest_file): |
76 | print('fatal: Specified manifest file %s does not exist.' % | 75 | print('fatal: Specified manifest file %s does not exist.' % |
77 | opt.manifest_file) | 76 | opt.manifest_file) |
78 | sys.exit(1) | 77 | sys.exit(1) |
79 | self.manifest.Override(opt.manifest_file) | 78 | manifest_file = opt.manifest_file |
80 | gitc_utils.generate_gitc_manifest(self.client_dir, self.manifest) | 79 | |
80 | manifest = GitcManifest(self.repodir, opt.gitc_client) | ||
81 | manifest.Override(manifest_file) | ||
82 | gitc_utils.generate_gitc_manifest(None, manifest) | ||
81 | print('Please run `cd %s` to view your GITC client.' % | 83 | print('Please run `cd %s` to view your GITC client.' % |
82 | os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client)) | 84 | os.path.join(gitc_utils.GITC_FS_ROOT_DIR, opt.gitc_client)) |
diff --git a/subcmds/start.py b/subcmds/start.py index 188fd7c6..940c3413 100644 --- a/subcmds/start.py +++ b/subcmds/start.py | |||
@@ -57,7 +57,6 @@ 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 = {} | ||
61 | if self.gitc_manifest: | 60 | if self.gitc_manifest: |
62 | all_projects = self.GetProjects(projects, manifest=self.gitc_manifest, | 61 | all_projects = self.GetProjects(projects, manifest=self.gitc_manifest, |
63 | missing_ok=True) | 62 | missing_ok=True) |
@@ -67,7 +66,6 @@ revision specified in the manifest. | |||
67 | else: | 66 | else: |
68 | project.already_synced = False | 67 | project.already_synced = False |
69 | project.old_revision = project.revisionExpr | 68 | project.old_revision = project.revisionExpr |
70 | proj_name_to_gitc_proj_dict[project.name] = project | ||
71 | project.revisionExpr = None | 69 | project.revisionExpr = None |
72 | # Save the GITC manifest. | 70 | # Save the GITC manifest. |
73 | gitc_utils.save_manifest(self.gitc_manifest) | 71 | gitc_utils.save_manifest(self.gitc_manifest) |
@@ -77,9 +75,10 @@ revision specified in the manifest. | |||
77 | pm = Progress('Starting %s' % nb, len(all_projects)) | 75 | pm = Progress('Starting %s' % nb, len(all_projects)) |
78 | for project in all_projects: | 76 | for project in all_projects: |
79 | pm.update() | 77 | pm.update() |
78 | |||
80 | if self.gitc_manifest: | 79 | if self.gitc_manifest: |
81 | gitc_project = proj_name_to_gitc_proj_dict[project.name] | 80 | gitc_project = self.gitc_manifest.paths[project.relpath] |
82 | # Sync projects that have already been opened. | 81 | # Sync projects that have not been opened. |
83 | if not gitc_project.already_synced: | 82 | if not gitc_project.already_synced: |
84 | proj_localdir = os.path.join(self.gitc_manifest.gitc_client_dir, | 83 | proj_localdir = os.path.join(self.gitc_manifest.gitc_client_dir, |
85 | project.relpath) | 84 | project.relpath) |
@@ -89,7 +88,7 @@ revision specified in the manifest. | |||
89 | project.Sync_NetworkHalf() | 88 | project.Sync_NetworkHalf() |
90 | sync_buf = SyncBuffer(self.manifest.manifestProject.config) | 89 | sync_buf = SyncBuffer(self.manifest.manifestProject.config) |
91 | project.Sync_LocalHalf(sync_buf) | 90 | project.Sync_LocalHalf(sync_buf) |
92 | project.revisionExpr = gitc_project.old_revision | 91 | project.revisionId = gitc_project.old_revision |
93 | 92 | ||
94 | # If the current revision is a specific SHA1 then we can't push back | 93 | # If the current revision is a specific SHA1 then we can't push back |
95 | # to it; so substitute with dest_branch if defined, or with manifest | 94 | # to it; so substitute with dest_branch if defined, or with manifest |
@@ -100,6 +99,7 @@ revision specified in the manifest. | |||
100 | branch_merge = project.dest_branch | 99 | branch_merge = project.dest_branch |
101 | else: | 100 | else: |
102 | branch_merge = self.manifest.default.revisionExpr | 101 | 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 2e9bbe70..a99d7e74 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -75,6 +75,7 @@ from error import RepoChangedException, GitError, ManifestParseError | |||
75 | from project import SyncBuffer | 75 | from project import SyncBuffer |
76 | from progress import Progress | 76 | from progress import Progress |
77 | from wrapper import Wrapper | 77 | from wrapper import Wrapper |
78 | from manifest_xml import GitcManifest | ||
78 | 79 | ||
79 | _ONE_DAY_S = 24 * 60 * 60 | 80 | _ONE_DAY_S = 24 * 60 * 60 |
80 | 81 | ||
@@ -670,32 +671,39 @@ later is required to fix a server side protocol bug. | |||
670 | if opt.jobs is None: | 671 | if opt.jobs is None: |
671 | self.jobs = self.manifest.default.sync_j | 672 | self.jobs = self.manifest.default.sync_j |
672 | 673 | ||
673 | # TODO (sbasi) - Add support for manifest changes, aka projects | ||
674 | # have been added or deleted from the manifest. | ||
675 | if self.gitc_manifest: | 674 | if self.gitc_manifest: |
676 | gitc_manifest_projects = self.GetProjects(args, | 675 | gitc_manifest_projects = self.GetProjects(args, |
677 | manifest=self.gitc_manifest, | ||
678 | missing_ok=True) | 676 | missing_ok=True) |
679 | gitc_projects = [] | 677 | gitc_projects = [] |
680 | opened_projects = [] | 678 | opened_projects = [] |
681 | for project in gitc_manifest_projects: | 679 | for project in gitc_manifest_projects: |
682 | if not project.old_revision: | 680 | if project.relpath in self.gitc_manifest.paths and \ |
683 | gitc_projects.append(project) | 681 | self.gitc_manifest.paths[project.relpath].old_revision: |
682 | opened_projects.append(project.relpath) | ||
684 | else: | 683 | else: |
685 | opened_projects.append(project) | 684 | gitc_projects.append(project.relpath) |
686 | 685 | ||
687 | if gitc_projects and not opt.local_only: | 686 | if not args: |
687 | gitc_projects = None | ||
688 | |||
689 | if gitc_projects != [] and not opt.local_only: | ||
688 | print('Updating GITC client: %s' % self.gitc_manifest.gitc_client_name) | 690 | print('Updating GITC client: %s' % self.gitc_manifest.gitc_client_name) |
689 | gitc_utils.generate_gitc_manifest(self.gitc_manifest.gitc_client_dir, | 691 | manifest = GitcManifest(self.repodir, self.gitc_manifest.gitc_client_name) |
690 | self.gitc_manifest, | 692 | if manifest_name: |
693 | manifest.Override(manifest_name) | ||
694 | else: | ||
695 | manifest.Override(self.manifest.manifestFile) | ||
696 | gitc_utils.generate_gitc_manifest(self.gitc_manifest, | ||
697 | manifest, | ||
691 | gitc_projects) | 698 | gitc_projects) |
692 | print('GITC client successfully synced.') | 699 | print('GITC client successfully synced.') |
693 | 700 | ||
694 | # The opened projects need to be synced as normal, therefore we | 701 | # The opened projects need to be synced as normal, therefore we |
695 | # generate a new args list to represent the opened projects. | 702 | # generate a new args list to represent the opened projects. |
696 | args = [] | 703 | # TODO: make this more reliable -- if there's a project name/path overlap, |
697 | for proj in opened_projects: | 704 | # this may choose the wrong project. |
698 | args.append(os.path.relpath(proj.worktree, cwd)) | 705 | args = [os.path.relpath(self.manifest.paths[p].worktree, os.getcwd()) |
706 | for p in opened_projects] | ||
699 | if not args: | 707 | if not args: |
700 | return | 708 | return |
701 | all_projects = self.GetProjects(args, | 709 | all_projects = self.GetProjects(args, |