Skip to content

Commit 5de106b

Browse files
authored
Remove backup_changelists option (#193)
1 parent dbaf5fb commit 5de106b

File tree

6 files changed

+3
-120
lines changed

6 files changed

+3
-120
lines changed

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,6 @@ view: >-
7474

7575
### Advanced
7676

77-
#### `backup_changelists` (optional, bool)
78-
79-
Default: `no`.
80-
81-
When running a build against a shelved changelist, create a duplicate of that changelist so that other steps in the build are guaranteed to run against the same version of shelved files.
82-
83-
Caveats:
84-
85-
* May lead to accumulation of many shelved changelists on the server, affecting performance.
86-
* Removes convenience of being able to re-shelve changes and iterate by retrying only failied steps.
87-
8877
#### `client_options` (optional, string)
8978

9079
Default: `clobber`.

plugin.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ description: Checks out a perforce repository instead of git.
33
author: https://github.com/ca-johnson
44
configuration:
55
properties:
6-
backup_changelists:
7-
type: bool
86
client_options:
97
type: string
108
client_type:

python/buildkite.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
__REVISION_METADATA__ = 'buildkite-perforce-revision'
1515
__REVISION_METADATA_DEPRECATED__ = 'buildkite:perforce:revision' # old metadata key, incompatible with `bk local run`
16-
__SHELVED_METADATA__ = 'buildkite-perforce-shelved'
17-
__SHELVED_ANNOTATION__ = "Saved shelved change {original} as {copy}"
1816

1917
def get_env():
2018
"""Get env vars passed in via plugin config"""
@@ -65,9 +63,6 @@ def get_config():
6563
conf['view'] = ['%s %s' % (v, next(view_iter)) for v in view_iter]
6664
return conf
6765

68-
def should_backup_changelists():
69-
return os.environ.get('BUILDKITE_PLUGIN_PERFORCE_BACKUP_CHANGELISTS', 'false') == 'true'
70-
7166
def get_metadata(key):
7267
"""If it exists, retrieve metadata from buildkite for a given key"""
7368
if not __ACCESS_TOKEN__:
@@ -101,23 +96,6 @@ def get_users_changelist():
10196
if branch.isdigit():
10297
return branch
10398

104-
def get_build_changelist():
105-
"""Get a saved version of the users originally supplied changelist, if available"""
106-
return get_metadata(__SHELVED_METADATA__)
107-
108-
def set_build_changelist(changelist):
109-
"""Set a shelved change that should be used instead of the user-supplied one"""
110-
if set_metadata(__SHELVED_METADATA__, changelist) and should_backup_changelists():
111-
subprocess.call([
112-
'buildkite-agent', 'annotate',
113-
__SHELVED_ANNOTATION__.format(**{
114-
'original': get_users_changelist(),
115-
'copy': changelist,
116-
}),
117-
'--context', __SHELVED_METADATA__,
118-
'--style', 'info',
119-
])
120-
12199
def get_build_revision():
122100
"""Get a p4 revision for the build from buildkite context"""
123101
revision = get_metadata(__REVISION_METADATA__) or \

python/checkout.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
from perforce import P4Repo
99
from buildkite import (get_env, get_config, get_build_revision, set_build_revision,
10-
get_users_changelist, get_build_changelist, set_build_changelist, set_build_info,
11-
should_backup_changelists)
10+
get_users_changelist, set_build_info)
1211

1312
def main():
1413
"""Main"""
@@ -26,19 +25,11 @@ def main():
2625

2726
user_changelist = get_users_changelist()
2827
if user_changelist:
29-
# Use existing or make a copy of the users changelist for this build
30-
changelist = get_build_changelist()
31-
if not changelist:
32-
changelist = user_changelist
33-
if should_backup_changelists():
34-
changelist = repo.backup(user_changelist)
35-
set_build_changelist(changelist)
36-
37-
repo.p4print_unshelve(changelist)
28+
repo.p4print_unshelve(user_changelist)
3829

3930
description = repo.description(
4031
# Prefer users change description over latest submitted change
41-
get_users_changelist() or repo.head_at_revision(revision)
32+
user_changelist or repo.head_at_revision(revision)
4233
)
4334
set_build_info(revision, description)
4435

python/perforce.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -245,27 +245,6 @@ def revert(self):
245245
self.perforce.run_clean(patched)
246246
os.remove(self.patchfile)
247247

248-
def unshelve(self, changelist):
249-
"""Unshelve a pending change"""
250-
self._setup_client()
251-
252-
changeinfo = self.perforce.run_describe('-S', changelist)
253-
if not changeinfo:
254-
raise Exception('Changelist %s does not contain any shelved files.' % changelist)
255-
changeinfo = changeinfo[0]
256-
257-
# Reject exclusive lock files for now
258-
modifiers = [filetype.split('+')[1]
259-
for filetype in changeinfo['type']
260-
if '+' in filetype]
261-
if any('l' in modifier for modifier in modifiers):
262-
raise Exception(
263-
'You cannot run a presubmit test with exclusive lock files (+l) at this time\n'
264-
'See https://github.com/ca-johnson/perforce-buildkite-plugin/issues/102 for latest status\n')
265-
266-
267-
self.perforce.run_unshelve('-s', changelist)
268-
269248
def run_parallel_cmds(self, cmds, max_parallel=20):
270249
def run(*args):
271250
"""Acquire new connection and run p4 cmd"""
@@ -310,19 +289,6 @@ def p4print_unshelve(self, changelist):
310289

311290
self.run_parallel_cmds(cmds)
312291

313-
def backup(self, changelist):
314-
"""Make a copy of a shelved change"""
315-
self.revert()
316-
self.unshelve(changelist)
317-
# Make pending CL from default CL
318-
unshelved = self.perforce.fetch_change()
319-
unshelved._description = 'Backup of %s for precommit testing in Buildkite' % changelist
320-
self.perforce.save_change(unshelved)
321-
backup_change_info = self.perforce.run_changes('-c', self.perforce.client, '-s', 'pending', '-m', '1')
322-
backup_cl = backup_change_info[0]['change']
323-
self.perforce.run_shelve('-c', backup_cl)
324-
return backup_cl
325-
326292

327293
class SyncOutput(OutputHandler):
328294
"""Log each synced file"""

python/test_perforce.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -316,35 +316,6 @@ def test_workspace_recovery(server, tmpdir):
316316
assert sorted(os.listdir(tmpdir)) == sorted([
317317
"file.txt", "p4config"]), "Failed to restore corrupt workspace due to missing p4config"
318318

319-
def test_unshelve(server, tmpdir):
320-
"""Test unshelving a pending changelist"""
321-
repo = P4Repo(root=tmpdir)
322-
repo.sync()
323-
with open(os.path.join(tmpdir, "file.txt")) as content:
324-
assert content.read() == "Hello World\n", "Unexpected content in workspace file"
325-
326-
repo.unshelve('3') # Modify a file
327-
with open(os.path.join(tmpdir, "file.txt")) as content:
328-
assert content.read() == "Goodbye World\n", "Unexpected content in workspace file"
329-
repo.sync()
330-
331-
repo.unshelve('4') # Delete a file
332-
assert not os.path.exists(os.path.join(tmpdir, "file.txt"))
333-
repo.sync()
334-
335-
repo.unshelve('5') # Add a file
336-
assert os.path.exists(os.path.join(tmpdir, "newfile.txt"))
337-
repo.sync()
338-
339-
with pytest.raises(Exception, match=r'Changelist 999 does not contain any shelved files.'):
340-
repo.unshelve('999')
341-
342-
# Unshelved changes are removed in following syncs
343-
repo.sync()
344-
with open(os.path.join(tmpdir, "file.txt")) as content:
345-
assert content.read() == "Hello World\n", "Unexpected content in workspace file"
346-
assert not os.path.exists(os.path.join(tmpdir, "newfile.txt")), "File unshelved for add was not deleted"
347-
348319
def test_p4print_unshelve(server, tmpdir):
349320
"""Test unshelving a pending changelist by p4printing content into a file"""
350321
repo = P4Repo(root=tmpdir)
@@ -383,16 +354,6 @@ def test_p4print_unshelve(server, tmpdir):
383354
repo = P4Repo(root=tmpdir, stream='//stream-depot/main')
384355
repo.p4print_unshelve('3') # Modify a file
385356

386-
def test_backup_shelve(server, tmpdir):
387-
"""Test making a copy of a shelved changelist"""
388-
repo = P4Repo(root=tmpdir)
389-
390-
backup_changelist = repo.backup('3')
391-
assert backup_changelist != '3', "Backup changelist number must be new"
392-
repo.revert()
393-
repo.unshelve(backup_changelist)
394-
with open(os.path.join(tmpdir, "file.txt")) as content:
395-
assert content.read() == "Goodbye World\n", "Unexpected content in workspace file"
396357

397358
def copytree(src, dst):
398359
"""Shim to get around shutil.copytree requiring root dir to not exist"""

0 commit comments

Comments
 (0)