Details
Details
- Reviewers
durin42 - Group Reviewers
hg-reviewers - Commits
- rHGdda3cae3c9c5: phase: use context managers for lock and transaction
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
durin42 |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/commands.py (11 lines) |
Status | Author | Revision | |
---|---|---|---|
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz |
revs.extend(opts['rev']) | revs.extend(opts['rev']) | ||||
if not revs: | if not revs: | ||||
# display both parents as the second parent phase can influence | # display both parents as the second parent phase can influence | ||||
# the phase of a merge commit | # the phase of a merge commit | ||||
revs = [c.rev() for c in repo[None].parents()] | revs = [c.rev() for c in repo[None].parents()] | ||||
revs = scmutil.revrange(repo, revs) | revs = scmutil.revrange(repo, revs) | ||||
lock = None | |||||
ret = 0 | ret = 0 | ||||
if targetphase is None: | if targetphase is None: | ||||
# display | # display | ||||
for r in revs: | for r in revs: | ||||
ctx = repo[r] | ctx = repo[r] | ||||
ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) | ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr())) | ||||
else: | else: | ||||
tr = None | with repo.lock(), repo.transaction("phase") as tr: | ||||
lock = repo.lock() | |||||
try: | |||||
tr = repo.transaction("phase") | |||||
# set phase | # set phase | ||||
if not revs: | if not revs: | ||||
raise error.Abort(_('empty revision set')) | raise error.Abort(_('empty revision set')) | ||||
nodes = [repo[r].node() for r in revs] | nodes = [repo[r].node() for r in revs] | ||||
# moving revision from public to draft may hide them | # moving revision from public to draft may hide them | ||||
# We have to check result on an unfiltered repository | # We have to check result on an unfiltered repository | ||||
unfi = repo.unfiltered() | unfi = repo.unfiltered() | ||||
getphase = unfi._phasecache.phase | getphase = unfi._phasecache.phase | ||||
olddata = [getphase(unfi, r) for r in unfi] | olddata = [getphase(unfi, r) for r in unfi] | ||||
phases.advanceboundary(repo, tr, targetphase, nodes) | phases.advanceboundary(repo, tr, targetphase, nodes) | ||||
if opts['force']: | if opts['force']: | ||||
phases.retractboundary(repo, tr, targetphase, nodes) | phases.retractboundary(repo, tr, targetphase, nodes) | ||||
tr.close() | |||||
finally: | |||||
if tr is not None: | |||||
tr.release() | |||||
lock.release() | |||||
getphase = unfi._phasecache.phase | getphase = unfi._phasecache.phase | ||||
newdata = [getphase(unfi, r) for r in unfi] | newdata = [getphase(unfi, r) for r in unfi] | ||||
changes = sum(newdata[r] != olddata[r] for r in unfi) | changes = sum(newdata[r] != olddata[r] for r in unfi) | ||||
cl = unfi.changelog | cl = unfi.changelog | ||||
rejected = [n for n in nodes | rejected = [n for n in nodes | ||||
if newdata[cl.rev(n)] < targetphase] | if newdata[cl.rev(n)] < targetphase] | ||||
if rejected: | if rejected: | ||||
ui.warn(_('cannot move %i changesets to a higher ' | ui.warn(_('cannot move %i changesets to a higher ' |