From 727cc3e32424886b90df2094063549189cbbb390 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 7 May 2015 14:16:49 +0900 Subject: [PATCH 1/4] sync: Improve error message when writing smart sync manifest fails The error message only states that writing the manifest failed. Include the exception message, so it's easier to track down the reason that the write failed. Change-Id: I06e942c48a19521ba45292199519dd0a8bdb1de7 --- subcmds/sync.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index b4546c15..c9ca8897 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -592,8 +592,9 @@ later is required to fix a server side protocol bug. f.write(manifest_str) finally: f.close() - except IOError: - print('error: cannot write manifest to %s' % manifest_path, + except IOError as e: + print('error: cannot write manifest to %s:\n%s' + % (manifest_path, e), file=sys.stderr) sys.exit(1) self._ReloadManifest(manifest_name) From 30d13eea862bdc9df1b0bcd32318f24250dd96ea Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 7 May 2015 15:01:15 +0900 Subject: [PATCH 2/4] forall: Don't try to get lrev of projects in mirror workspace git rev-parse fails for projects that don't have an explicit revision specified, and don't have a branch of the same name as the default revision. This can be the case in a workspace synced with the smart sync (-s) or smart tag (-t) option. Change-Id: I19bfe9fe7396170379415d85f10f6440dc6ea08f --- subcmds/forall.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subcmds/forall.py b/subcmds/forall.py index ebc8beca..3ddc3c3d 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py @@ -151,11 +151,15 @@ without iterating through the remaining projects. attributes that we need. """ + if not self.manifest.IsMirror: + lrev = project.GetRevisionId() + else: + lrev = None return { 'name': project.name, 'relpath': project.relpath, 'remote_name': project.remote.name, - 'lrev': project.GetRevisionId(), + 'lrev': lrev, 'rrev': project.revisionExpr, 'annotations': dict((a.name, a.value) for a in project.annotations), 'gitdir': project.gitdir, From 59b417493e0b0a18ba11f9d214308e82872c38e6 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 7 May 2015 14:36:09 +0900 Subject: [PATCH 3/4] sync: Remove smart sync override manifest when not in smart sync mode When syncing with the -s or -t option, a smart_sync_override.xml file is created. This file is left in the file system when syncing again without the -s or -t option. Remove the smart sync override manifest, if it exists, when not using the -s or -t option. Change-Id: I697a0f6405205ba5f84a4d470becf7cd23c07b4b --- subcmds/sync.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/subcmds/sync.py b/subcmds/sync.py index c9ca8897..ec333ae7 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -517,6 +517,9 @@ later is required to fix a server side protocol bug. self.manifest.Override(opt.manifest_name) manifest_name = opt.manifest_name + smart_sync_manifest_name = "smart_sync_override.xml" + smart_sync_manifest_path = os.path.join( + self.manifest.manifestProject.worktree, smart_sync_manifest_name) if opt.smart_sync or opt.smart_tag: if not self.manifest.manifest_server: @@ -583,18 +586,16 @@ later is required to fix a server side protocol bug. [success, manifest_str] = server.GetManifest(opt.smart_tag) if success: - manifest_name = "smart_sync_override.xml" - manifest_path = os.path.join(self.manifest.manifestProject.worktree, - manifest_name) + manifest_name = smart_sync_manifest_name try: - f = open(manifest_path, 'w') + f = open(smart_sync_manifest_path, 'w') try: f.write(manifest_str) finally: f.close() except IOError as e: print('error: cannot write manifest to %s:\n%s' - % (manifest_path, e), + % (smart_sync_manifest_path, e), file=sys.stderr) sys.exit(1) self._ReloadManifest(manifest_name) @@ -611,6 +612,13 @@ later is required to fix a server side protocol bug. % (self.manifest.manifest_server, e.errcode, e.errmsg), file=sys.stderr) sys.exit(1) + else: # Not smart sync or smart tag mode + if os.path.isfile(smart_sync_manifest_path): + try: + os.remove(smart_sync_manifest_path) + except OSError as e: + print('error: failed to remove existing smart sync override manifest: %s' % + e, file=sys.stderr) rp = self.manifest.repoProject rp.PreSync() From 6944cdb8d1b4765b4e9e6b3f3a09b65495da7ff3 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 7 May 2015 14:39:44 +0900 Subject: [PATCH 4/4] forall: use smart sync override manifest if it exists If a workspace is synced with the -s or -t option, the included projects may be different to those in the original manifest. However, when using the forall command, the list of the projects from the original manifest is used. If the smart sync manifest file exists, use it to override the original manifest. Change-Id: Iaefcbe148d2158ac046f158d98bbd8b5a5378ce7 --- subcmds/forall.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subcmds/forall.py b/subcmds/forall.py index 3ddc3c3d..b93cd6d0 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py @@ -205,6 +205,13 @@ without iterating through the remaining projects. mirror = self.manifest.IsMirror rc = 0 + smart_sync_manifest_name = "smart_sync_override.xml" + smart_sync_manifest_path = os.path.join( + self.manifest.manifestProject.worktree, smart_sync_manifest_name) + + if os.path.isfile(smart_sync_manifest_path): + self.manifest.Override(smart_sync_manifest_path) + if not opt.regex: projects = self.GetProjects(args) else: