repack: exit 0 if a repack is in progress

Previously we raised a LockHeld exception if a repack was already in progress,
which caused hg repack to exit non-zero. This changes it to exit 0 since a
repack is in progress to accomplish the desired result. This is useful in
automation that wants to run repack to maintain the repository but depends on
exit codes to know if a command succeeded or not.

Differential Revision: https://phab.mercurial-scm.org/D1668
This commit is contained in:
Durham Goode 2017-12-12 16:16:53 -08:00
parent 9cc2ca09bb
commit 1d65b29746
4 changed files with 17 additions and 11 deletions

View File

@ -748,7 +748,7 @@ def gcclient(ui, cachepath):
repackmod.incrementalrepack(repo)
filesrepacked = True
continue
except IOError:
except (IOError, repackmod.RepackAlreadyRunning):
# If repack cannot be performed due to not enough disk space
# continue doing garbage collection of loose files w/o repack
pass
@ -1038,7 +1038,12 @@ def repack(ui, repo, *pats, **opts):
options = {'packsonly': opts.get('packsonly')}
if opts.get('incremental'):
repackmod.incrementalrepack(repo, options=options)
else:
repackmod.fullrepack(repo, options=options)
try:
if opts.get('incremental'):
repackmod.incrementalrepack(repo, options=options)
else:
repackmod.fullrepack(repo, options=options)
except repackmod.RepackAlreadyRunning as ex:
# Don't propogate the exception if the repack is already in
# progress, since we want the command to exit 0.
repo.ui.warn('%s\n' % ex)

View File

@ -28,6 +28,9 @@ import time
osutil = policy.importmod(r'osutil')
class RepackAlreadyRunning(error.Abort):
pass
def backgroundrepack(repo, incremental=True, packsonly=False):
cmd = [util.hgexecutable(), '-R', repo.origroot, 'repack']
msg = _("(running background repack)\n")
@ -360,8 +363,8 @@ def _runrepack(repo, data, history, packpath, category, fullhistory=None,
try:
packer.run(dpack, hpack)
except error.LockHeld:
raise error.Abort(_("skipping repack - another repack is "
"already running"))
raise RepackAlreadyRunning(_("skipping repack - another repack "
"is already running"))
def keepset(repo, keyfn, lastkeepkeys=None):
"""Computes a keepset which is not garbage collected.

View File

@ -124,8 +124,7 @@
$ hg repack --config "hooks.prerepack=sleep 3" &
$ sleep 1
$ hg repack
abort: skipping repack - another repack is already running
[255]
skipping repack - another repack is already running
$ hg debugwaitonrepack >/dev/null 2>&1
# Run repack in the background

View File

@ -132,8 +132,7 @@
$ hg repack --config "hooks.prerepack=sleep 3" &
$ sleep 1
$ hg repack
abort: skipping repack - another repack is already running
[255]
skipping repack - another repack is already running
$ hg debugwaitonrepack >/dev/null 2>&1
# Run repack in the background