From ad6a69597e96701b0006b0f0a18e6a126d7ce30a Mon Sep 17 00:00:00 2001 From: Carl Johnson Date: Fri, 21 Feb 2020 14:34:53 +0000 Subject: [PATCH] Fix label syncing (#154) --- python/checkout.py | 6 ++++-- python/perforce.py | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/python/checkout.py b/python/checkout.py index 8e40e5a..ca94533 100644 --- a/python/checkout.py +++ b/python/checkout.py @@ -36,8 +36,10 @@ def main(): repo.p4print_unshelve(changelist) - revision = get_build_revision() - description = repo.description(get_users_changelist() or revision.strip('@')) + description = repo.description( + # Prefer users change description over latest submitted change + get_users_changelist() or repo.head_at_revision(revision) + ) set_build_info(revision, description) diff --git a/python/perforce.py b/python/perforce.py index 20ebe51..06d9c65 100644 --- a/python/perforce.py +++ b/python/perforce.py @@ -149,15 +149,25 @@ def info(self): def head(self): """Get current head revision""" self._setup_client() - client_head = self.perforce.run_changes([ - '-m', '1', '-s', 'submitted', '//%s/...' % self._get_clientname()]) + # Get head based on client view (e.g. within the stream) + client_head = self.head_at_revision('//%s/...' % self._get_clientname()) if client_head: - return client_head[0]['change'] - # Fallback for when client view has no submitted changes + return client_head + # Fallback for when client view has no submitted changes, global head revision return self.perforce.run_counter("maxCommitChange")[0]['value'] + def head_at_revision(self, revision): + """Get head submitted changelist at revision specifier""" + # Resolve revision specifier like "@labelname" to a concrete submitted change + result = self.perforce.run_changes([ + '-m', '1', '-s', 'submitted', revision + ]) + if not result: + return None # Revision spec had no submitted changes + return result[0]['change'] + def description(self, changelist): - """Get description of a given changelist""" + """Get description of a given changelist number""" return self.perforce.run_describe(str(changelist))[0]['desc'] def sync(self, revision=None):