shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
# shelve.py - save/restore working directory state
|
|
|
|
#
|
|
|
|
# Copyright 2013 Facebook, Inc.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
|
|
|
"""save and restore changes to the working directory
|
|
|
|
|
|
|
|
The "hg shelve" command saves changes made to the working directory
|
|
|
|
and reverts those changes, resetting the working directory to a clean
|
|
|
|
state.
|
|
|
|
|
|
|
|
Later on, the "hg unshelve" command restores the changes saved by "hg
|
|
|
|
shelve". Changes can be restored even after updating to a different
|
|
|
|
parent, in which case Mercurial's merge machinery will resolve any
|
|
|
|
conflicts if necessary.
|
|
|
|
|
|
|
|
You can have more than one shelved change outstanding at a time; each
|
|
|
|
shelved change has a distinct name. For details, see the help for "hg
|
|
|
|
shelve".
|
|
|
|
"""
|
2016-03-03 00:30:51 +03:00
|
|
|
from __future__ import absolute_import
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2015-05-16 21:28:04 +03:00
|
|
|
import collections
|
2016-03-03 00:30:51 +03:00
|
|
|
import errno
|
2015-07-01 23:13:02 +03:00
|
|
|
import itertools
|
2016-05-14 08:03:12 +03:00
|
|
|
|
|
|
|
from mercurial.i18n import _
|
2016-03-03 00:30:51 +03:00
|
|
|
from mercurial import (
|
|
|
|
bundle2,
|
|
|
|
bundlerepo,
|
|
|
|
changegroup,
|
|
|
|
cmdutil,
|
|
|
|
commands,
|
|
|
|
error,
|
|
|
|
exchange,
|
|
|
|
hg,
|
|
|
|
lock as lockmod,
|
|
|
|
mdiff,
|
|
|
|
merge,
|
|
|
|
node as nodemod,
|
|
|
|
patch,
|
|
|
|
phases,
|
|
|
|
repair,
|
|
|
|
scmutil,
|
|
|
|
templatefilters,
|
|
|
|
util,
|
2017-03-02 15:31:32 +03:00
|
|
|
vfs as vfsmod,
|
2016-03-03 00:30:51 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
from . import (
|
|
|
|
rebase,
|
|
|
|
)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
cmdtable = {}
|
|
|
|
command = cmdutil.command(cmdtable)
|
2016-08-23 18:26:08 +03:00
|
|
|
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
|
2015-04-28 23:44:37 +03:00
|
|
|
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
|
|
|
|
# be specifying the version(s) of Mercurial they are tested with, or
|
|
|
|
# leave the attribute unspecified.
|
2016-08-23 18:26:08 +03:00
|
|
|
testedwith = 'ships-with-hg-core'
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2015-07-01 23:14:03 +03:00
|
|
|
backupdir = 'shelve-backup'
|
2016-04-09 09:33:28 +03:00
|
|
|
shelvedir = 'shelved'
|
2016-11-10 14:07:20 +03:00
|
|
|
shelvefileextensions = ['hg', 'patch']
|
2016-11-29 18:20:03 +03:00
|
|
|
# universal extension is present in all types of shelves
|
|
|
|
patchextension = 'patch'
|
2015-07-01 23:14:03 +03:00
|
|
|
|
2016-11-10 14:26:31 +03:00
|
|
|
# we never need the user, so we use a
|
|
|
|
# generic user for all shelve operations
|
|
|
|
shelveuser = 'shelve@localhost'
|
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
class shelvedfile(object):
|
2013-10-14 20:29:56 +04:00
|
|
|
"""Helper for the file storing a single shelve
|
|
|
|
|
2014-09-30 10:23:44 +04:00
|
|
|
Handles common functions on shelve files (.hg/.patch) using
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
the vfs layer"""
|
|
|
|
def __init__(self, repo, name, filetype=None):
|
|
|
|
self.repo = repo
|
|
|
|
self.name = name
|
2017-03-09 03:52:42 +03:00
|
|
|
self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
|
|
|
|
self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
|
2015-01-16 01:39:41 +03:00
|
|
|
self.ui = self.repo.ui
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if filetype:
|
|
|
|
self.fname = name + '.' + filetype
|
|
|
|
else:
|
|
|
|
self.fname = name
|
|
|
|
|
|
|
|
def exists(self):
|
|
|
|
return self.vfs.exists(self.fname)
|
|
|
|
|
|
|
|
def filename(self):
|
|
|
|
return self.vfs.join(self.fname)
|
|
|
|
|
2015-07-01 23:13:02 +03:00
|
|
|
def backupfilename(self):
|
|
|
|
def gennames(base):
|
|
|
|
yield base
|
|
|
|
base, ext = base.rsplit('.', 1)
|
|
|
|
for i in itertools.count(1):
|
|
|
|
yield '%s-%d.%s' % (base, i, ext)
|
|
|
|
|
|
|
|
name = self.backupvfs.join(self.fname)
|
|
|
|
for n in gennames(name):
|
|
|
|
if not self.backupvfs.exists(n):
|
|
|
|
return n
|
|
|
|
|
|
|
|
def movetobackup(self):
|
|
|
|
if not self.backupvfs.isdir():
|
|
|
|
self.backupvfs.makedir()
|
|
|
|
util.rename(self.filename(), self.backupfilename())
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
def stat(self):
|
|
|
|
return self.vfs.stat(self.fname)
|
|
|
|
|
|
|
|
def opener(self, mode='rb'):
|
|
|
|
try:
|
|
|
|
return self.vfs(self.fname, mode)
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as err:
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("shelved change '%s' not found") % self.name)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2014-03-08 20:03:28 +04:00
|
|
|
def applybundle(self):
|
|
|
|
fp = self.opener()
|
|
|
|
try:
|
2014-04-14 23:45:30 +04:00
|
|
|
gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
|
2015-10-19 16:42:50 +03:00
|
|
|
if not isinstance(gen, bundle2.unbundle20):
|
|
|
|
gen.apply(self.repo, 'unshelve',
|
|
|
|
'bundle:' + self.vfs.join(self.fname),
|
|
|
|
targetphase=phases.secret)
|
|
|
|
if isinstance(gen, bundle2.unbundle20):
|
|
|
|
bundle2.applybundle(self.repo, gen,
|
|
|
|
self.repo.currenttransaction(),
|
|
|
|
source='unshelve',
|
|
|
|
url='bundle:' + self.vfs.join(self.fname))
|
2014-03-08 20:03:28 +04:00
|
|
|
finally:
|
|
|
|
fp.close()
|
|
|
|
|
2014-10-10 22:44:40 +04:00
|
|
|
def bundlerepo(self):
|
|
|
|
return bundlerepo.bundlerepository(self.repo.baseui, self.repo.root,
|
|
|
|
self.vfs.join(self.fname))
|
2015-10-02 01:09:32 +03:00
|
|
|
def writebundle(self, bases, node):
|
2016-01-20 02:37:07 +03:00
|
|
|
cgversion = changegroup.safeversion(self.repo)
|
|
|
|
if cgversion == '01':
|
|
|
|
btype = 'HG10BZ'
|
|
|
|
compression = None
|
|
|
|
else:
|
2015-10-02 01:08:00 +03:00
|
|
|
btype = 'HG20'
|
|
|
|
compression = 'BZ'
|
|
|
|
|
|
|
|
cg = changegroup.changegroupsubset(self.repo, bases, [node], 'shelve',
|
|
|
|
version=cgversion)
|
2016-03-29 00:41:29 +03:00
|
|
|
bundle2.writebundle(self.ui, cg, self.fname, btype, self.vfs,
|
2015-10-02 01:08:00 +03:00
|
|
|
compression=compression)
|
2014-03-08 20:03:28 +04:00
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
class shelvedstate(object):
|
2013-10-16 18:36:58 +04:00
|
|
|
"""Handle persistence during unshelving operations.
|
2013-10-14 20:29:56 +04:00
|
|
|
|
|
|
|
Handles saving and restoring a shelved state. Ensures that different
|
2013-10-16 18:36:58 +04:00
|
|
|
versions of a shelved state are possible and handles them appropriately.
|
|
|
|
"""
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
_version = 1
|
|
|
|
_filename = 'shelvedstate'
|
2016-11-24 01:58:52 +03:00
|
|
|
_keep = 'keep'
|
|
|
|
_nokeep = 'nokeep'
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def load(cls, repo):
|
2015-01-16 01:17:12 +03:00
|
|
|
fp = repo.vfs(cls._filename)
|
2013-10-14 20:59:12 +04:00
|
|
|
try:
|
|
|
|
version = int(fp.readline().strip())
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2013-10-14 20:59:12 +04:00
|
|
|
if version != cls._version:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('this version of shelve is incompatible '
|
2013-10-14 20:59:12 +04:00
|
|
|
'with the version used in this repo'))
|
|
|
|
name = fp.readline().strip()
|
2016-07-13 18:16:18 +03:00
|
|
|
wctx = nodemod.bin(fp.readline().strip())
|
|
|
|
pendingctx = nodemod.bin(fp.readline().strip())
|
2016-03-03 00:30:51 +03:00
|
|
|
parents = [nodemod.bin(h) for h in fp.readline().split()]
|
|
|
|
stripnodes = [nodemod.bin(h) for h in fp.readline().split()]
|
2016-02-10 04:23:27 +03:00
|
|
|
branchtorestore = fp.readline().strip()
|
2016-11-24 01:58:52 +03:00
|
|
|
keep = fp.readline().strip() == cls._keep
|
2016-07-13 18:16:18 +03:00
|
|
|
except (ValueError, TypeError) as err:
|
|
|
|
raise error.CorruptedState(str(err))
|
2013-10-14 20:59:12 +04:00
|
|
|
finally:
|
|
|
|
fp.close()
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2016-07-13 18:16:18 +03:00
|
|
|
try:
|
|
|
|
obj = cls()
|
|
|
|
obj.name = name
|
|
|
|
obj.wctx = repo[wctx]
|
|
|
|
obj.pendingctx = repo[pendingctx]
|
|
|
|
obj.parents = parents
|
|
|
|
obj.stripnodes = stripnodes
|
|
|
|
obj.branchtorestore = branchtorestore
|
2016-11-24 01:58:52 +03:00
|
|
|
obj.keep = keep
|
2016-07-13 18:16:18 +03:00
|
|
|
except error.RepoLookupError as err:
|
|
|
|
raise error.CorruptedState(str(err))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
return obj
|
|
|
|
|
|
|
|
@classmethod
|
2016-02-10 04:23:27 +03:00
|
|
|
def save(cls, repo, name, originalwctx, pendingctx, stripnodes,
|
2016-11-24 01:58:52 +03:00
|
|
|
branchtorestore, keep=False):
|
2015-01-16 01:17:12 +03:00
|
|
|
fp = repo.vfs(cls._filename, 'wb')
|
2013-10-14 20:59:12 +04:00
|
|
|
fp.write('%i\n' % cls._version)
|
|
|
|
fp.write('%s\n' % name)
|
2016-03-03 00:30:51 +03:00
|
|
|
fp.write('%s\n' % nodemod.hex(originalwctx.node()))
|
|
|
|
fp.write('%s\n' % nodemod.hex(pendingctx.node()))
|
|
|
|
fp.write('%s\n' %
|
|
|
|
' '.join([nodemod.hex(p) for p in repo.dirstate.parents()]))
|
|
|
|
fp.write('%s\n' %
|
|
|
|
' '.join([nodemod.hex(n) for n in stripnodes]))
|
2016-02-10 04:23:27 +03:00
|
|
|
fp.write('%s\n' % branchtorestore)
|
2016-11-24 01:58:52 +03:00
|
|
|
fp.write('%s\n' % (cls._keep if keep else cls._nokeep))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
fp.close()
|
|
|
|
|
2013-10-14 19:46:47 +04:00
|
|
|
@classmethod
|
|
|
|
def clear(cls, repo):
|
2017-03-11 22:02:25 +03:00
|
|
|
repo.vfs.unlinkpath(cls._filename, ignoremissing=True)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2015-07-01 23:14:03 +03:00
|
|
|
def cleanupoldbackups(repo):
|
2017-03-09 03:52:42 +03:00
|
|
|
vfs = vfsmod.vfs(repo.vfs.join(backupdir))
|
2015-07-01 23:14:03 +03:00
|
|
|
maxbackups = repo.ui.configint('shelve', 'maxbackups', 10)
|
2016-11-29 18:20:03 +03:00
|
|
|
hgfiles = [f for f in vfs.listdir()
|
|
|
|
if f.endswith('.' + patchextension)]
|
2015-07-01 23:14:03 +03:00
|
|
|
hgfiles = sorted([(vfs.stat(f).st_mtime, f) for f in hgfiles])
|
2015-07-13 17:34:12 +03:00
|
|
|
if 0 < maxbackups and maxbackups < len(hgfiles):
|
|
|
|
bordermtime = hgfiles[-maxbackups][0]
|
|
|
|
else:
|
|
|
|
bordermtime = None
|
2015-07-01 23:14:03 +03:00
|
|
|
for mtime, f in hgfiles[:len(hgfiles) - maxbackups]:
|
2015-07-13 17:34:12 +03:00
|
|
|
if mtime == bordermtime:
|
|
|
|
# keep it, because timestamp can't decide exact order of backups
|
|
|
|
continue
|
2016-11-29 18:20:03 +03:00
|
|
|
base = f[:-(1 + len(patchextension))]
|
2016-11-10 14:07:20 +03:00
|
|
|
for ext in shelvefileextensions:
|
2015-07-01 23:14:03 +03:00
|
|
|
try:
|
|
|
|
vfs.unlink(base + '.' + ext)
|
|
|
|
except OSError as err:
|
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
|
shelve: add utility to abort current transaction but keep dirstate
"hg shelve" and "hg unshelve" use aborting a current transaction to
discard temporary changes while (un)shelving.
This assumes that dirstate changes in a transaction scope are kept
even after aborting it. But this assumption will be broken by
"transactional dirstate". See the wiki page below for detail about it.
https://mercurial.selenic.com/wiki/DirstateTransactionPlan
This patch adds utility function "_aborttransaction()" to abort
current transaction but keep dirstate changes for (un)shelving.
'dirstate.invalidate()' just after aborting a transaction should be
removed soon by subsequent patch, which writes or discards in-memory
dirstate changes at releasing transaction according to the result of
it.
BTW, there are some other ways below, which (seem to, at first glance)
resolve this issue. But this patch chose straightforward way for ease
of review and future refactorring.
- commit transaction at first, and then rollback it
It causes unintentional "dirty read" of running transaction to
other processes at committing it.
- use dirstateguard to save and restore shelved dirstate
After DirstateTransactionPlan, making 'dirstate.write()' write
in-memory changes into actual file requires
'transaction.writepending()' while transaction running.
It causes meaningless writing other in-memory changes out, even
though they are never referred.
In addition to it, it isn't desirable that scope of dirstateguard
and transaction intersects each other.
- get list of files changed from the parent, keep it in memory, and
emulate that changes after aborting transaction
This additional memory consumption may block aborting transaction
in large repository (on small resource environment).
2015-10-07 19:41:30 +03:00
|
|
|
def _aborttransaction(repo):
|
|
|
|
'''Abort current transaction for shelve/unshelve, but keep dirstate
|
|
|
|
'''
|
2016-05-24 23:29:53 +03:00
|
|
|
tr = repo.currenttransaction()
|
|
|
|
repo.dirstate.savebackup(tr, suffix='.shelve')
|
|
|
|
tr.abort()
|
|
|
|
repo.dirstate.restorebackup(None, suffix='.shelve')
|
shelve: add utility to abort current transaction but keep dirstate
"hg shelve" and "hg unshelve" use aborting a current transaction to
discard temporary changes while (un)shelving.
This assumes that dirstate changes in a transaction scope are kept
even after aborting it. But this assumption will be broken by
"transactional dirstate". See the wiki page below for detail about it.
https://mercurial.selenic.com/wiki/DirstateTransactionPlan
This patch adds utility function "_aborttransaction()" to abort
current transaction but keep dirstate changes for (un)shelving.
'dirstate.invalidate()' just after aborting a transaction should be
removed soon by subsequent patch, which writes or discards in-memory
dirstate changes at releasing transaction according to the result of
it.
BTW, there are some other ways below, which (seem to, at first glance)
resolve this issue. But this patch chose straightforward way for ease
of review and future refactorring.
- commit transaction at first, and then rollback it
It causes unintentional "dirty read" of running transaction to
other processes at committing it.
- use dirstateguard to save and restore shelved dirstate
After DirstateTransactionPlan, making 'dirstate.write()' write
in-memory changes into actual file requires
'transaction.writepending()' while transaction running.
It causes meaningless writing other in-memory changes out, even
though they are never referred.
In addition to it, it isn't desirable that scope of dirstateguard
and transaction intersects each other.
- get list of files changed from the parent, keep it in memory, and
emulate that changes after aborting transaction
This additional memory consumption may block aborting transaction
in large repository (on small resource environment).
2015-10-07 19:41:30 +03:00
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
def createcmd(ui, repo, pats, opts):
|
2013-10-16 18:36:58 +04:00
|
|
|
"""subcommand that creates a new shelve"""
|
2016-01-16 00:14:47 +03:00
|
|
|
with repo.wlock():
|
2015-12-01 21:12:08 +03:00
|
|
|
cmdutil.checkunfinished(repo)
|
2015-12-01 21:12:08 +03:00
|
|
|
return _docreatecmd(ui, repo, pats, opts)
|
2013-10-14 20:29:56 +04:00
|
|
|
|
2016-11-10 14:22:55 +03:00
|
|
|
def getshelvename(repo, parent, opts):
|
|
|
|
"""Decide on the name this shelve is going to have"""
|
|
|
|
def gennames():
|
|
|
|
yield label
|
|
|
|
for i in xrange(1, 100):
|
|
|
|
yield '%s-%02d' % (label, i)
|
|
|
|
name = opts.get('name')
|
|
|
|
label = repo._activebookmark or parent.branch() or 'default'
|
|
|
|
# slashes aren't allowed in filenames, therefore we rename it
|
|
|
|
label = label.replace('/', '_')
|
2016-12-22 17:05:30 +03:00
|
|
|
label = label.replace('\\', '_')
|
|
|
|
# filenames must not start with '.' as it should not be hidden
|
|
|
|
if label.startswith('.'):
|
|
|
|
label = label.replace('.', '_', 1)
|
2016-11-10 14:22:55 +03:00
|
|
|
|
|
|
|
if name:
|
2016-11-29 18:20:03 +03:00
|
|
|
if shelvedfile(repo, name, patchextension).exists():
|
2016-11-10 14:22:55 +03:00
|
|
|
e = _("a shelved change named '%s' already exists") % name
|
|
|
|
raise error.Abort(e)
|
2016-12-22 17:05:30 +03:00
|
|
|
|
|
|
|
# ensure we are not creating a subdirectory or a hidden file
|
|
|
|
if '/' in name or '\\' in name:
|
|
|
|
raise error.Abort(_('shelved change names can not contain slashes'))
|
|
|
|
if name.startswith('.'):
|
|
|
|
raise error.Abort(_("shelved change names can not start with '.'"))
|
|
|
|
|
2016-11-10 14:22:55 +03:00
|
|
|
else:
|
|
|
|
for n in gennames():
|
2016-11-29 18:20:03 +03:00
|
|
|
if not shelvedfile(repo, n, patchextension).exists():
|
2016-11-10 14:22:55 +03:00
|
|
|
name = n
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise error.Abort(_("too many shelved changes named '%s'") % label)
|
|
|
|
|
|
|
|
return name
|
|
|
|
|
2016-11-10 14:24:07 +03:00
|
|
|
def mutableancestors(ctx):
|
|
|
|
"""return all mutable ancestors for ctx (included)
|
|
|
|
|
|
|
|
Much faster than the revset ancestors(ctx) & draft()"""
|
|
|
|
seen = set([nodemod.nullrev])
|
|
|
|
visit = collections.deque()
|
|
|
|
visit.append(ctx)
|
|
|
|
while visit:
|
|
|
|
ctx = visit.popleft()
|
|
|
|
yield ctx.node()
|
|
|
|
for parent in ctx.parents():
|
|
|
|
rev = parent.rev()
|
|
|
|
if rev not in seen:
|
|
|
|
seen.add(rev)
|
|
|
|
if parent.mutable():
|
|
|
|
visit.append(parent)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2016-11-10 14:26:31 +03:00
|
|
|
def getcommitfunc(extra, interactive, editor=False):
|
|
|
|
def commitfunc(ui, repo, message, match, opts):
|
|
|
|
hasmq = util.safehasattr(repo, 'mq')
|
|
|
|
if hasmq:
|
|
|
|
saved, repo.mq.checkapplied = repo.mq.checkapplied, False
|
|
|
|
backup = repo.ui.backupconfig('phases', 'new-commit')
|
|
|
|
try:
|
|
|
|
repo.ui.setconfig('phases', 'new-commit', phases.secret)
|
|
|
|
editor_ = False
|
|
|
|
if editor:
|
|
|
|
editor_ = cmdutil.getcommiteditor(editform='shelve.shelve',
|
|
|
|
**opts)
|
|
|
|
return repo.commit(message, shelveuser, opts.get('date'), match,
|
|
|
|
editor=editor_, extra=extra)
|
|
|
|
finally:
|
|
|
|
repo.ui.restoreconfig(backup)
|
|
|
|
if hasmq:
|
|
|
|
repo.mq.checkapplied = saved
|
|
|
|
|
|
|
|
def interactivecommitfunc(ui, repo, *pats, **opts):
|
|
|
|
match = scmutil.match(repo['.'], pats, {})
|
|
|
|
message = opts['message']
|
|
|
|
return commitfunc(ui, repo, message, match, opts)
|
|
|
|
|
|
|
|
return interactivecommitfunc if interactive else commitfunc
|
|
|
|
|
2016-11-10 14:33:01 +03:00
|
|
|
def _nothingtoshelvemessaging(ui, repo, pats, opts):
|
|
|
|
stat = repo.status(match=scmutil.match(repo[None], pats, opts))
|
|
|
|
if stat.deleted:
|
|
|
|
ui.status(_("nothing changed (%d missing files, see "
|
|
|
|
"'hg status')\n") % len(stat.deleted))
|
|
|
|
else:
|
|
|
|
ui.status(_("nothing changed\n"))
|
|
|
|
|
2016-11-10 14:07:20 +03:00
|
|
|
def _shelvecreatedcommit(repo, node, name):
|
|
|
|
bases = list(mutableancestors(repo[node]))
|
|
|
|
shelvedfile(repo, name, 'hg').writebundle(bases, node)
|
|
|
|
cmdutil.export(repo, [node],
|
2016-11-29 18:20:03 +03:00
|
|
|
fp=shelvedfile(repo, name, patchextension).opener('wb'),
|
2016-11-10 14:07:20 +03:00
|
|
|
opts=mdiff.diffopts(git=True))
|
|
|
|
|
2016-11-10 14:20:28 +03:00
|
|
|
def _includeunknownfiles(repo, pats, opts, extra):
|
|
|
|
s = repo.status(match=scmutil.match(repo[None], pats, opts),
|
|
|
|
unknown=True)
|
|
|
|
if s.unknown:
|
|
|
|
extra['shelve_unknown'] = '\0'.join(s.unknown)
|
|
|
|
repo[None].add(s.unknown)
|
|
|
|
|
2016-11-10 14:15:41 +03:00
|
|
|
def _finishshelve(repo):
|
|
|
|
_aborttransaction(repo)
|
|
|
|
|
2016-11-10 14:24:07 +03:00
|
|
|
def _docreatecmd(ui, repo, pats, opts):
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
wctx = repo[None]
|
|
|
|
parents = wctx.parents()
|
|
|
|
if len(parents) > 1:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot shelve while merging'))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
parent = parents[0]
|
2016-03-12 20:36:31 +03:00
|
|
|
origbranch = wctx.branch()
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2016-03-03 00:30:51 +03:00
|
|
|
if parent.node() != nodemod.nullid:
|
2015-11-23 08:40:23 +03:00
|
|
|
desc = "changes to: %s" % parent.description().split('\n', 1)[0]
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
else:
|
2014-02-10 03:53:27 +04:00
|
|
|
desc = '(changes in empty repository)'
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2016-03-09 10:21:57 +03:00
|
|
|
if not opts.get('message'):
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
opts['message'] = desc
|
|
|
|
|
2015-12-01 21:12:08 +03:00
|
|
|
lock = tr = None
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
try:
|
|
|
|
lock = repo.lock()
|
|
|
|
|
2013-10-23 21:49:56 +04:00
|
|
|
# use an uncommitted transaction to generate the bundle to avoid
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
# pull races. ensure we don't print the abort message to stderr.
|
|
|
|
tr = repo.transaction('commit', report=lambda x: None)
|
|
|
|
|
2015-03-26 01:52:28 +03:00
|
|
|
interactive = opts.get('interactive', False)
|
2016-01-14 21:03:31 +03:00
|
|
|
includeunknown = (opts.get('unknown', False) and
|
|
|
|
not opts.get('addremove', False))
|
|
|
|
|
2016-11-10 14:22:55 +03:00
|
|
|
name = getshelvename(repo, parent, opts)
|
2016-11-10 14:20:28 +03:00
|
|
|
extra = {}
|
2016-01-14 21:03:31 +03:00
|
|
|
if includeunknown:
|
2016-11-10 14:20:28 +03:00
|
|
|
_includeunknownfiles(repo, pats, opts, extra)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2016-03-08 00:58:11 +03:00
|
|
|
if _iswctxonnewbranch(repo) and not _isbareshelve(pats, opts):
|
|
|
|
# In non-bare shelve we don't store newly created branch
|
|
|
|
# at bundled commit
|
|
|
|
repo.dirstate.setbranch(repo['.'].branch())
|
|
|
|
|
2016-11-10 14:26:31 +03:00
|
|
|
commitfunc = getcommitfunc(extra, interactive, editor=True)
|
2015-03-26 01:53:30 +03:00
|
|
|
if not interactive:
|
|
|
|
node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
|
|
|
|
else:
|
2016-11-10 14:26:31 +03:00
|
|
|
node = cmdutil.dorecord(ui, repo, commitfunc, None,
|
2015-03-26 01:53:30 +03:00
|
|
|
False, cmdutil.recordfilter, *pats, **opts)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if not node:
|
2016-11-10 14:33:01 +03:00
|
|
|
_nothingtoshelvemessaging(ui, repo, pats, opts)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
return 1
|
|
|
|
|
2016-11-10 14:07:20 +03:00
|
|
|
_shelvecreatedcommit(repo, node, name)
|
2013-10-03 21:41:25 +04:00
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if ui.formatted():
|
|
|
|
desc = util.ellipsis(desc, ui.termwidth())
|
|
|
|
ui.status(_('shelved as %s\n') % name)
|
|
|
|
hg.update(repo, parent.node())
|
2016-03-12 20:36:31 +03:00
|
|
|
if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
|
|
|
|
repo.dirstate.setbranch(origbranch)
|
2015-10-07 19:41:30 +03:00
|
|
|
|
2016-11-10 14:15:41 +03:00
|
|
|
_finishshelve(repo)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
finally:
|
2015-12-01 21:12:08 +03:00
|
|
|
lockmod.release(tr, lock)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2016-03-12 20:36:31 +03:00
|
|
|
def _isbareshelve(pats, opts):
|
|
|
|
return (not pats
|
|
|
|
and not opts.get('interactive', False)
|
|
|
|
and not opts.get('include', False)
|
|
|
|
and not opts.get('exclude', False))
|
|
|
|
|
2016-03-08 00:58:11 +03:00
|
|
|
def _iswctxonnewbranch(repo):
|
|
|
|
return repo[None].branch() != repo['.'].branch()
|
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
def cleanupcmd(ui, repo):
|
2013-10-16 18:36:58 +04:00
|
|
|
"""subcommand that deletes all shelves"""
|
2013-10-14 20:29:56 +04:00
|
|
|
|
2016-01-16 00:14:47 +03:00
|
|
|
with repo.wlock():
|
2016-04-09 09:33:28 +03:00
|
|
|
for (name, _type) in repo.vfs.readdir(shelvedir):
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
suffix = name.rsplit('.', 1)[-1]
|
2016-11-10 14:07:20 +03:00
|
|
|
if suffix in shelvefileextensions:
|
2015-07-01 23:13:02 +03:00
|
|
|
shelvedfile(repo, name).movetobackup()
|
2015-07-01 23:14:03 +03:00
|
|
|
cleanupoldbackups(repo)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
def deletecmd(ui, repo, pats):
|
2013-10-16 18:36:58 +04:00
|
|
|
"""subcommand that deletes a specific shelve"""
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if not pats:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('no shelved changes specified!'))
|
2016-01-16 00:14:47 +03:00
|
|
|
with repo.wlock():
|
|
|
|
try:
|
|
|
|
for name in pats:
|
2016-11-10 14:07:20 +03:00
|
|
|
for suffix in shelvefileextensions:
|
|
|
|
shfile = shelvedfile(repo, name, suffix)
|
|
|
|
# patch file is necessary, as it should
|
|
|
|
# be present for any kind of shelve,
|
|
|
|
# but the .hg file is optional as in future we
|
|
|
|
# will add obsolete shelve with does not create a
|
|
|
|
# bundle
|
2016-11-29 18:20:03 +03:00
|
|
|
if shfile.exists() or suffix == patchextension:
|
2016-11-10 14:07:20 +03:00
|
|
|
shfile.movetobackup()
|
2016-01-16 00:14:47 +03:00
|
|
|
cleanupoldbackups(repo)
|
|
|
|
except OSError as err:
|
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
raise error.Abort(_("shelved change '%s' not found") % name)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
def listshelves(repo):
|
2013-10-16 18:36:58 +04:00
|
|
|
"""return all shelves in repo as list of (time, filename)"""
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
try:
|
2016-04-09 09:33:28 +03:00
|
|
|
names = repo.vfs.readdir(shelvedir)
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as err:
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
return []
|
|
|
|
info = []
|
2014-08-15 18:20:47 +04:00
|
|
|
for (name, _type) in names:
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
pfx, sfx = name.rsplit('.', 1)
|
2016-11-29 18:20:03 +03:00
|
|
|
if not pfx or sfx != patchextension:
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
continue
|
|
|
|
st = shelvedfile(repo, name).stat()
|
|
|
|
info.append((st.st_mtime, shelvedfile(repo, pfx).filename()))
|
|
|
|
return sorted(info, reverse=True)
|
|
|
|
|
|
|
|
def listcmd(ui, repo, pats, opts):
|
2013-10-16 18:36:58 +04:00
|
|
|
"""subcommand that displays the list of shelves"""
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
pats = set(pats)
|
|
|
|
width = 80
|
|
|
|
if not ui.plain():
|
|
|
|
width = ui.termwidth()
|
|
|
|
namelabel = 'shelve.newest'
|
2017-02-25 01:12:43 +03:00
|
|
|
ui.pager('shelve')
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
for mtime, name in listshelves(repo):
|
|
|
|
sname = util.split(name)[1]
|
|
|
|
if pats and sname not in pats:
|
|
|
|
continue
|
|
|
|
ui.write(sname, label=namelabel)
|
|
|
|
namelabel = 'shelve.name'
|
|
|
|
if ui.quiet:
|
|
|
|
ui.write('\n')
|
|
|
|
continue
|
|
|
|
ui.write(' ' * (16 - len(sname)))
|
|
|
|
used = 16
|
2013-10-01 14:20:31 +04:00
|
|
|
age = '(%s)' % templatefilters.age(util.makedate(mtime), abbrev=True)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
ui.write(age, label='shelve.age')
|
2013-10-01 14:20:31 +04:00
|
|
|
ui.write(' ' * (12 - len(age)))
|
|
|
|
used += 12
|
2016-11-29 18:20:03 +03:00
|
|
|
with open(name + '.' + patchextension, 'rb') as fp:
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
while True:
|
|
|
|
line = fp.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
if not line.startswith('#'):
|
|
|
|
desc = line.rstrip()
|
|
|
|
if ui.formatted():
|
|
|
|
desc = util.ellipsis(desc, width - used)
|
|
|
|
ui.write(desc)
|
|
|
|
break
|
|
|
|
ui.write('\n')
|
|
|
|
if not (opts['patch'] or opts['stat']):
|
|
|
|
continue
|
|
|
|
difflines = fp.readlines()
|
|
|
|
if opts['patch']:
|
|
|
|
for chunk, label in patch.difflabel(iter, difflines):
|
|
|
|
ui.write(chunk, label=label)
|
|
|
|
if opts['stat']:
|
2016-11-12 15:36:17 +03:00
|
|
|
for chunk, label in patch.diffstatui(difflines, width=width):
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
ui.write(chunk, label=label)
|
|
|
|
|
2017-01-13 22:53:07 +03:00
|
|
|
def patchcmds(ui, repo, pats, opts, subcommand):
|
|
|
|
"""subcommand that displays shelves"""
|
|
|
|
if len(pats) == 0:
|
|
|
|
raise error.Abort(_("--%s expects at least one shelf") % subcommand)
|
2015-04-14 23:23:54 +03:00
|
|
|
|
2017-01-13 22:53:07 +03:00
|
|
|
for shelfname in pats:
|
|
|
|
if not shelvedfile(repo, shelfname, patchextension).exists():
|
|
|
|
raise error.Abort(_("cannot find shelf %s") % shelfname)
|
2015-04-14 23:23:54 +03:00
|
|
|
|
|
|
|
listcmd(ui, repo, pats, opts)
|
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
def checkparents(repo, state):
|
2013-10-14 20:29:56 +04:00
|
|
|
"""check parent while resuming an unshelve"""
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if state.parents != repo.dirstate.parents():
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('working directory parents do not match unshelve '
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
'state'))
|
|
|
|
|
2013-10-22 07:41:05 +04:00
|
|
|
def pathtofiles(repo, files):
|
|
|
|
cwd = repo.getcwd()
|
|
|
|
return [repo.pathto(f, cwd) for f in files]
|
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
def unshelveabort(ui, repo, state, opts):
|
2013-10-14 20:29:56 +04:00
|
|
|
"""subcommand that abort an in-progress unshelve"""
|
2016-01-16 00:14:50 +03:00
|
|
|
with repo.lock():
|
2013-10-24 00:12:48 +04:00
|
|
|
try:
|
2016-01-16 00:14:50 +03:00
|
|
|
checkparents(repo, state)
|
2013-10-24 00:12:48 +04:00
|
|
|
|
2017-03-11 22:04:14 +03:00
|
|
|
repo.vfs.rename('unshelverebasestate', 'rebasestate')
|
2016-01-16 00:14:50 +03:00
|
|
|
try:
|
|
|
|
rebase.rebase(ui, repo, **{
|
|
|
|
'abort' : True
|
|
|
|
})
|
|
|
|
except Exception:
|
2017-03-11 22:04:14 +03:00
|
|
|
repo.vfs.rename('rebasestate', 'unshelverebasestate')
|
2016-01-16 00:14:50 +03:00
|
|
|
raise
|
2013-10-24 00:12:48 +04:00
|
|
|
|
2016-01-16 00:14:50 +03:00
|
|
|
mergefiles(ui, repo, state.wctx, state.pendingctx)
|
|
|
|
repair.strip(ui, repo, state.stripnodes, backup=False,
|
|
|
|
topic='shelve')
|
|
|
|
finally:
|
|
|
|
shelvedstate.clear(repo)
|
|
|
|
ui.warn(_("unshelve of '%s' aborted\n") % state.name)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2013-11-27 04:23:05 +04:00
|
|
|
def mergefiles(ui, repo, wctx, shelvectx):
|
2013-10-24 00:12:48 +04:00
|
|
|
"""updates to wctx and merges the changes from shelvectx into the
|
2013-11-27 04:23:05 +04:00
|
|
|
dirstate."""
|
2013-10-24 00:12:48 +04:00
|
|
|
oldquiet = ui.quiet
|
|
|
|
try:
|
|
|
|
ui.quiet = True
|
|
|
|
hg.update(repo, wctx.node())
|
|
|
|
files = []
|
|
|
|
files.extend(shelvectx.files())
|
|
|
|
files.extend(shelvectx.parents()[0].files())
|
2013-11-27 04:23:05 +04:00
|
|
|
|
|
|
|
# revert will overwrite unknown files, so move them out of the way
|
2014-10-04 09:12:43 +04:00
|
|
|
for file in repo.status(unknown=True).unknown:
|
2013-11-27 04:23:05 +04:00
|
|
|
if file in files:
|
2016-01-02 14:02:57 +03:00
|
|
|
util.rename(file, scmutil.origpath(ui, repo, file))
|
2014-08-15 19:54:15 +04:00
|
|
|
ui.pushbuffer(True)
|
2013-10-24 00:12:48 +04:00
|
|
|
cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(),
|
|
|
|
*pathtofiles(repo, files),
|
|
|
|
**{'no_backup': True})
|
2014-08-15 19:54:15 +04:00
|
|
|
ui.popbuffer()
|
2013-10-24 00:12:48 +04:00
|
|
|
finally:
|
|
|
|
ui.quiet = oldquiet
|
|
|
|
|
2016-02-10 04:23:27 +03:00
|
|
|
def restorebranch(ui, repo, branchtorestore):
|
|
|
|
if branchtorestore and branchtorestore != repo.dirstate.branch():
|
|
|
|
repo.dirstate.setbranch(branchtorestore)
|
|
|
|
ui.status(_('marked working directory as branch %s\n')
|
|
|
|
% branchtorestore)
|
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
def unshelvecleanup(ui, repo, name, opts):
|
2013-10-16 18:36:58 +04:00
|
|
|
"""remove related files after an unshelve"""
|
2016-03-09 10:21:57 +03:00
|
|
|
if not opts.get('keep'):
|
2016-11-10 14:07:20 +03:00
|
|
|
for filetype in shelvefileextensions:
|
|
|
|
shfile = shelvedfile(repo, name, filetype)
|
|
|
|
if shfile.exists():
|
|
|
|
shfile.movetobackup()
|
2015-07-01 23:14:03 +03:00
|
|
|
cleanupoldbackups(repo)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
def unshelvecontinue(ui, repo, state, opts):
|
2013-10-14 20:29:56 +04:00
|
|
|
"""subcommand to continue an in-progress unshelve"""
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
# We're finishing off a merge. First parent is our original
|
|
|
|
# parent, second is the temporary "fake" commit we're unshelving.
|
2016-01-16 00:14:47 +03:00
|
|
|
with repo.lock():
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
checkparents(repo, state)
|
2015-11-18 00:56:10 +03:00
|
|
|
ms = merge.mergestate.read(repo)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if [f for f in ms if ms[f] == 'u']:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
_("unresolved conflicts, can't continue"),
|
|
|
|
hint=_("see 'hg resolve', then 'hg unshelve --continue'"))
|
2013-10-24 00:12:48 +04:00
|
|
|
|
2017-03-11 22:04:14 +03:00
|
|
|
repo.vfs.rename('unshelverebasestate', 'rebasestate')
|
2013-10-24 00:12:48 +04:00
|
|
|
try:
|
|
|
|
rebase.rebase(ui, repo, **{
|
|
|
|
'continue' : True
|
|
|
|
})
|
|
|
|
except Exception:
|
2017-03-11 22:04:14 +03:00
|
|
|
repo.vfs.rename('rebasestate', 'unshelverebasestate')
|
2013-10-24 00:12:48 +04:00
|
|
|
raise
|
|
|
|
|
|
|
|
shelvectx = repo['tip']
|
|
|
|
if not shelvectx in state.pendingctx.children():
|
|
|
|
# rebase was a no-op, so it produced no child commit
|
|
|
|
shelvectx = state.pendingctx
|
2014-10-08 15:47:11 +04:00
|
|
|
else:
|
|
|
|
# only strip the shelvectx if the rebase produced it
|
|
|
|
state.stripnodes.append(shelvectx.node())
|
2013-10-24 00:12:48 +04:00
|
|
|
|
2013-11-27 04:23:05 +04:00
|
|
|
mergefiles(ui, repo, state.wctx, shelvectx)
|
2016-02-10 04:23:27 +03:00
|
|
|
restorebranch(ui, repo, state.branchtorestore)
|
2013-10-24 00:12:48 +04:00
|
|
|
|
2014-07-24 23:06:08 +04:00
|
|
|
repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve')
|
2013-10-24 00:12:48 +04:00
|
|
|
shelvedstate.clear(repo)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
unshelvecleanup(ui, repo, state.name, opts)
|
|
|
|
ui.status(_("unshelve of '%s' complete\n") % state.name)
|
|
|
|
|
2016-11-13 14:35:52 +03:00
|
|
|
def _commitworkingcopychanges(ui, repo, opts, tmpwctx):
|
|
|
|
"""Temporarily commit working copy changes before moving unshelve commit"""
|
|
|
|
# Store pending changes in a commit and remember added in case a shelve
|
|
|
|
# contains unknown files that are part of the pending change
|
|
|
|
s = repo.status()
|
|
|
|
addedbefore = frozenset(s.added)
|
2017-01-19 20:48:40 +03:00
|
|
|
if not (s.modified or s.added or s.removed):
|
2016-11-13 14:35:52 +03:00
|
|
|
return tmpwctx, addedbefore
|
|
|
|
ui.status(_("temporarily committing pending changes "
|
|
|
|
"(restore with 'hg unshelve --abort')\n"))
|
|
|
|
commitfunc = getcommitfunc(extra=None, interactive=False,
|
|
|
|
editor=False)
|
|
|
|
tempopts = {}
|
|
|
|
tempopts['message'] = "pending changes temporary commit"
|
|
|
|
tempopts['date'] = opts.get('date')
|
|
|
|
ui.quiet = True
|
|
|
|
node = cmdutil.commit(ui, repo, commitfunc, [], tempopts)
|
|
|
|
tmpwctx = repo[node]
|
|
|
|
return tmpwctx, addedbefore
|
|
|
|
|
2016-11-10 21:51:06 +03:00
|
|
|
def _unshelverestorecommit(ui, repo, basename, oldquiet):
|
|
|
|
"""Recreate commit in the repository during the unshelve"""
|
|
|
|
ui.quiet = True
|
|
|
|
shelvedfile(repo, basename, 'hg').applybundle()
|
|
|
|
shelvectx = repo['tip']
|
|
|
|
ui.quiet = oldquiet
|
|
|
|
return repo, shelvectx
|
|
|
|
|
2016-11-10 21:57:10 +03:00
|
|
|
def _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, basename, pctx,
|
|
|
|
tmpwctx, shelvectx, branchtorestore):
|
|
|
|
"""Rebase restored commit from its original location to a destination"""
|
|
|
|
# If the shelve is not immediately on top of the commit
|
|
|
|
# we'll be merging with, rebase it to be on top.
|
|
|
|
if tmpwctx.node() == shelvectx.parents()[0].node():
|
|
|
|
return shelvectx
|
|
|
|
|
|
|
|
ui.status(_('rebasing shelved changes\n'))
|
|
|
|
try:
|
|
|
|
rebase.rebase(ui, repo, **{
|
|
|
|
'rev': [shelvectx.rev()],
|
|
|
|
'dest': str(tmpwctx.rev()),
|
|
|
|
'keep': True,
|
|
|
|
'tool': opts.get('tool', ''),
|
|
|
|
})
|
|
|
|
except error.InterventionRequired:
|
|
|
|
tr.close()
|
|
|
|
|
|
|
|
stripnodes = [repo.changelog.node(rev)
|
|
|
|
for rev in xrange(oldtiprev, len(repo))]
|
|
|
|
shelvedstate.save(repo, basename, pctx, tmpwctx, stripnodes,
|
2016-11-24 01:58:52 +03:00
|
|
|
branchtorestore, opts.get('keep'))
|
2016-11-10 21:57:10 +03:00
|
|
|
|
2017-03-11 22:04:14 +03:00
|
|
|
repo.vfs.rename('rebasestate', 'unshelverebasestate')
|
2016-11-10 21:57:10 +03:00
|
|
|
raise error.InterventionRequired(
|
|
|
|
_("unresolved conflicts (see 'hg resolve', then "
|
|
|
|
"'hg unshelve --continue')"))
|
|
|
|
|
|
|
|
# refresh ctx after rebase completes
|
|
|
|
shelvectx = repo['tip']
|
|
|
|
|
|
|
|
if not shelvectx in tmpwctx.children():
|
|
|
|
# rebase was a no-op, so it produced no child commit
|
|
|
|
shelvectx = tmpwctx
|
|
|
|
return shelvectx
|
|
|
|
|
2016-11-10 22:02:39 +03:00
|
|
|
def _forgetunknownfiles(repo, shelvectx, addedbefore):
|
|
|
|
# Forget any files that were unknown before the shelve, unknown before
|
|
|
|
# unshelve started, but are now added.
|
|
|
|
shelveunknown = shelvectx.extra().get('shelve_unknown')
|
|
|
|
if not shelveunknown:
|
|
|
|
return
|
|
|
|
shelveunknown = frozenset(shelveunknown.split('\0'))
|
|
|
|
addedafter = frozenset(repo.status().added)
|
|
|
|
toforget = (addedafter & shelveunknown) - addedbefore
|
|
|
|
repo[None].forget(toforget)
|
|
|
|
|
2016-11-11 18:01:27 +03:00
|
|
|
def _finishunshelve(repo, oldtiprev, tr):
|
|
|
|
# The transaction aborting will strip all the commits for us,
|
|
|
|
# but it doesn't update the inmemory structures, so addchangegroup
|
|
|
|
# hooks still fire and try to operate on the missing commits.
|
|
|
|
# Clean up manually to prevent this.
|
|
|
|
repo.unfiltered().changelog.strip(oldtiprev, tr)
|
|
|
|
_aborttransaction(repo)
|
|
|
|
|
2017-01-19 20:48:40 +03:00
|
|
|
def _checkunshelveuntrackedproblems(ui, repo, shelvectx):
|
|
|
|
"""Check potential problems which may result from working
|
|
|
|
copy having untracked changes."""
|
|
|
|
wcdeleted = set(repo.status().deleted)
|
|
|
|
shelvetouched = set(shelvectx.files())
|
|
|
|
intersection = wcdeleted.intersection(shelvetouched)
|
|
|
|
if intersection:
|
|
|
|
m = _("shelved change touches missing files")
|
|
|
|
hint = _("run hg status to see which files are missing")
|
|
|
|
raise error.Abort(m, hint=hint)
|
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
@command('unshelve',
|
|
|
|
[('a', 'abort', None,
|
|
|
|
_('abort an incomplete unshelve operation')),
|
|
|
|
('c', 'continue', None,
|
|
|
|
_('continue an incomplete unshelve operation')),
|
2015-11-19 02:04:03 +03:00
|
|
|
('k', 'keep', None,
|
2014-04-08 01:10:20 +04:00
|
|
|
_('keep shelve after unshelving')),
|
2017-02-19 12:56:08 +03:00
|
|
|
('n', 'name', '',
|
|
|
|
_('restore shelved change with given name'), _('NAME')),
|
2015-11-19 02:11:23 +03:00
|
|
|
('t', 'tool', '', _('specify merge tool')),
|
2014-04-08 01:10:20 +04:00
|
|
|
('', 'date', '',
|
|
|
|
_('set date for temporary commits (DEPRECATED)'), _('DATE'))],
|
2017-02-19 12:56:08 +03:00
|
|
|
_('hg unshelve [[-n] SHELVED]'))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
def unshelve(ui, repo, *shelved, **opts):
|
|
|
|
"""restore a shelved change to the working directory
|
|
|
|
|
|
|
|
This command accepts an optional name of a shelved change to
|
|
|
|
restore. If none is given, the most recent shelved change is used.
|
|
|
|
|
|
|
|
If a shelved change is applied successfully, the bundle that
|
2015-07-01 23:13:02 +03:00
|
|
|
contains the shelved changes is moved to a backup location
|
|
|
|
(.hg/shelve-backup).
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
Since you can restore a shelved change on top of an arbitrary
|
|
|
|
commit, it is possible that unshelving will result in a conflict
|
|
|
|
between your changes and the commits you are unshelving onto. If
|
|
|
|
this occurs, you must resolve the conflict, then use
|
|
|
|
``--continue`` to complete the unshelve operation. (The bundle
|
2015-07-01 23:13:02 +03:00
|
|
|
will not be moved until you successfully complete the unshelve.)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
(Alternatively, you can use ``--abort`` to abandon an unshelve
|
|
|
|
that causes a conflict. This reverts the unshelved changes, and
|
2015-07-01 23:13:02 +03:00
|
|
|
leaves the bundle in place.)
|
2015-07-01 23:14:03 +03:00
|
|
|
|
2016-02-10 04:23:27 +03:00
|
|
|
If bare shelved change(when no files are specified, without interactive,
|
|
|
|
include and exclude option) was done on newly created branch it would
|
|
|
|
restore branch information to the working directory.
|
|
|
|
|
2015-07-01 23:14:03 +03:00
|
|
|
After a successful unshelve, the shelved changes are stored in a
|
|
|
|
backup directory. Only the N most recent backups are kept. N
|
2015-07-18 22:17:46 +03:00
|
|
|
defaults to 10 but can be overridden using the ``shelve.maxbackups``
|
2015-07-01 23:14:03 +03:00
|
|
|
configuration option.
|
2015-07-13 17:34:12 +03:00
|
|
|
|
|
|
|
.. container:: verbose
|
|
|
|
|
|
|
|
Timestamp in seconds is used to decide order of backups. More
|
|
|
|
than ``maxbackups`` backups are kept, if same timestamp
|
|
|
|
prevents from deciding exact order of them, for safety.
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
"""
|
2016-01-16 00:14:47 +03:00
|
|
|
with repo.wlock():
|
2015-12-09 02:28:53 +03:00
|
|
|
return _dounshelve(ui, repo, *shelved, **opts)
|
|
|
|
|
|
|
|
def _dounshelve(ui, repo, *shelved, **opts):
|
2016-03-09 10:21:57 +03:00
|
|
|
abortf = opts.get('abort')
|
|
|
|
continuef = opts.get('continue')
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if not abortf and not continuef:
|
|
|
|
cmdutil.checkunfinished(repo)
|
2017-02-19 12:56:08 +03:00
|
|
|
shelved = list(shelved)
|
|
|
|
if opts.get("name"):
|
|
|
|
shelved.append(opts["name"])
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
if abortf or continuef:
|
|
|
|
if abortf and continuef:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot use both abort and continue'))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if shelved:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot combine abort/continue with '
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
'naming a shelved change'))
|
2015-11-19 02:11:23 +03:00
|
|
|
if abortf and opts.get('tool', False):
|
|
|
|
ui.warn(_('tool option will be ignored\n'))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
state = shelvedstate.load(repo)
|
2016-11-24 01:58:52 +03:00
|
|
|
if opts.get('keep') is None:
|
|
|
|
opts['keep'] = state.keep
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as err:
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
2016-02-04 06:47:38 +03:00
|
|
|
cmdutil.wrongtooltocontinue(repo, _('unshelve'))
|
2016-07-13 18:16:18 +03:00
|
|
|
except error.CorruptedState as err:
|
|
|
|
ui.debug(str(err) + '\n')
|
|
|
|
if continuef:
|
|
|
|
msg = _('corrupted shelved state file')
|
|
|
|
hint = _('please run hg unshelve --abort to abort unshelve '
|
|
|
|
'operation')
|
|
|
|
raise error.Abort(msg, hint=hint)
|
|
|
|
elif abortf:
|
|
|
|
msg = _('could not read shelved state file, your working copy '
|
|
|
|
'may be in an unexpected state\nplease update to some '
|
|
|
|
'commit\n')
|
|
|
|
ui.warn(msg)
|
|
|
|
shelvedstate.clear(repo)
|
|
|
|
return
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
if abortf:
|
|
|
|
return unshelveabort(ui, repo, state, opts)
|
|
|
|
elif continuef:
|
|
|
|
return unshelvecontinue(ui, repo, state, opts)
|
|
|
|
elif len(shelved) > 1:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('can only unshelve one change at a time'))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
elif not shelved:
|
|
|
|
shelved = listshelves(repo)
|
|
|
|
if not shelved:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('no shelved changes to apply!'))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
basename = util.split(shelved[0][1])[1]
|
|
|
|
ui.status(_("unshelving change '%s'\n") % basename)
|
|
|
|
else:
|
|
|
|
basename = shelved[0]
|
|
|
|
|
2016-11-29 18:20:03 +03:00
|
|
|
if not shelvedfile(repo, basename, patchextension).exists():
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("shelved change '%s' not found") % basename)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
2014-02-10 03:54:12 +04:00
|
|
|
oldquiet = ui.quiet
|
2015-12-09 02:28:53 +03:00
|
|
|
lock = tr = None
|
2015-11-19 02:11:23 +03:00
|
|
|
forcemerge = ui.backupconfig('ui', 'forcemerge')
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
try:
|
2015-11-19 02:11:23 +03:00
|
|
|
ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'unshelve')
|
2015-04-12 21:59:31 +03:00
|
|
|
lock = repo.lock()
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
tr = repo.transaction('unshelve', report=lambda x: None)
|
|
|
|
oldtiprev = len(repo)
|
2013-10-24 00:12:48 +04:00
|
|
|
|
2014-04-08 01:10:20 +04:00
|
|
|
pctx = repo['.']
|
|
|
|
tmpwctx = pctx
|
2013-10-24 00:12:48 +04:00
|
|
|
# The goal is to have a commit structure like so:
|
2014-04-08 01:10:20 +04:00
|
|
|
# ...-> pctx -> tmpwctx -> shelvectx
|
2013-10-24 00:12:48 +04:00
|
|
|
# where tmpwctx is an optional commit with the user's pending changes
|
|
|
|
# and shelvectx is the unshelved changes. Then we merge it all down
|
2014-04-08 01:10:20 +04:00
|
|
|
# to the original pctx.
|
2013-10-24 00:12:48 +04:00
|
|
|
|
2016-11-13 14:35:52 +03:00
|
|
|
tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts,
|
|
|
|
tmpwctx)
|
2013-10-24 00:12:48 +04:00
|
|
|
|
2016-11-10 21:51:06 +03:00
|
|
|
repo, shelvectx = _unshelverestorecommit(ui, repo, basename, oldquiet)
|
2017-01-19 20:48:40 +03:00
|
|
|
_checkunshelveuntrackedproblems(ui, repo, shelvectx)
|
2016-02-10 04:23:27 +03:00
|
|
|
branchtorestore = ''
|
|
|
|
if shelvectx.branch() != shelvectx.p1().branch():
|
|
|
|
branchtorestore = shelvectx.branch()
|
|
|
|
|
2016-11-10 21:57:10 +03:00
|
|
|
shelvectx = _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev,
|
|
|
|
basename, pctx, tmpwctx, shelvectx,
|
|
|
|
branchtorestore)
|
2014-04-08 01:10:20 +04:00
|
|
|
mergefiles(ui, repo, pctx, shelvectx)
|
2016-02-10 04:23:27 +03:00
|
|
|
restorebranch(ui, repo, branchtorestore)
|
2016-11-10 22:02:39 +03:00
|
|
|
_forgetunknownfiles(repo, shelvectx, addedbefore)
|
2016-01-14 21:03:31 +03:00
|
|
|
|
2013-10-24 00:12:48 +04:00
|
|
|
shelvedstate.clear(repo)
|
2016-11-11 18:01:27 +03:00
|
|
|
_finishunshelve(repo, oldtiprev, tr)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
unshelvecleanup(ui, repo, basename, opts)
|
|
|
|
finally:
|
2014-02-10 03:54:12 +04:00
|
|
|
ui.quiet = oldquiet
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if tr:
|
|
|
|
tr.release()
|
2015-12-09 02:28:53 +03:00
|
|
|
lockmod.release(lock)
|
2015-11-19 02:11:23 +03:00
|
|
|
ui.restoreconfig(forcemerge)
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
|
|
|
|
@command('shelve',
|
|
|
|
[('A', 'addremove', None,
|
|
|
|
_('mark new/missing files as added/removed before shelving')),
|
2016-01-14 21:03:31 +03:00
|
|
|
('u', 'unknown', None,
|
2016-01-21 03:20:19 +03:00
|
|
|
_('store unknown files in the shelve')),
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
('', 'cleanup', None,
|
|
|
|
_('delete all shelved changes')),
|
|
|
|
('', 'date', '',
|
|
|
|
_('shelve with the specified commit date'), _('DATE')),
|
|
|
|
('d', 'delete', None,
|
|
|
|
_('delete the named shelved change(s)')),
|
2014-06-20 11:15:38 +04:00
|
|
|
('e', 'edit', False,
|
|
|
|
_('invoke editor on commit messages')),
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
('l', 'list', None,
|
|
|
|
_('list current shelves')),
|
|
|
|
('m', 'message', '',
|
|
|
|
_('use text as shelve message'), _('TEXT')),
|
|
|
|
('n', 'name', '',
|
|
|
|
_('use the given name for the shelved commit'), _('NAME')),
|
|
|
|
('p', 'patch', None,
|
|
|
|
_('show patch')),
|
2015-03-26 01:52:28 +03:00
|
|
|
('i', 'interactive', None,
|
2015-05-22 00:57:30 +03:00
|
|
|
_('interactive mode, only works while creating a shelve')),
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
('', 'stat', None,
|
2014-02-10 03:53:25 +04:00
|
|
|
_('output diffstat-style summary of changes'))] + commands.walkopts,
|
2014-02-10 03:53:27 +04:00
|
|
|
_('hg shelve [OPTION]... [FILE]...'))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
def shelvecmd(ui, repo, *pats, **opts):
|
|
|
|
'''save and set aside changes from the working directory
|
|
|
|
|
|
|
|
Shelving takes files that "hg status" reports as not clean, saves
|
|
|
|
the modifications to a bundle (a shelved change), and reverts the
|
|
|
|
files so that their state in the working directory becomes clean.
|
|
|
|
|
|
|
|
To restore these changes to the working directory, using "hg
|
|
|
|
unshelve"; this will work even if you switch to a different
|
|
|
|
commit.
|
|
|
|
|
|
|
|
When no files are specified, "hg shelve" saves all not-clean
|
|
|
|
files. If specific files or directories are named, only changes to
|
|
|
|
those files are shelved.
|
|
|
|
|
2016-11-15 00:43:25 +03:00
|
|
|
In bare shelve (when no files are specified, without interactive,
|
2016-02-10 04:23:27 +03:00
|
|
|
include and exclude option), shelving remembers information if the
|
|
|
|
working directory was on newly created branch, in other words working
|
|
|
|
directory was on different branch than its first parent. In this
|
|
|
|
situation unshelving restores branch information to the working directory.
|
|
|
|
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
Each shelved change has a name that makes it easier to find later.
|
|
|
|
The name of a shelved change defaults to being based on the active
|
|
|
|
bookmark, or if there is no active bookmark, the current named
|
|
|
|
branch. To specify a different name, use ``--name``.
|
|
|
|
|
|
|
|
To see a list of existing shelved changes, use the ``--list``
|
|
|
|
option. For each shelved change, this will print its name, age,
|
|
|
|
and description; use ``--patch`` or ``--stat`` for more details.
|
|
|
|
|
|
|
|
To delete specific shelved changes, use ``--delete``. To delete
|
|
|
|
all shelved changes, use ``--cleanup``.
|
|
|
|
'''
|
shelve: refactor option combination check to easily add new ones
Before this patch, the name of a newly added option had to be added
into each string that was passed to the "checkopt()" internal
function: these are white-space-separated list of un-acceptable option
names (= "black list" for the specified "opt").
This new option had to be added into multiple strings because each
option could belong to only one action of "create", "cleanup",
"delete" or "list".
In addition to this redundancy, each string passed to "checkopt()" was
already too long to include a new one.
This patch refactors option combination check to make it easier to add
a new option in a subsequent patch.
New "checkopt()" only takes one action ("cleanup", "delete" or
"list"), and checks whether all explicitly activated options are
allowed for it or not (if specified action is activated in "opts").
The "date" entry is listed in "allowables", but commented out,
because:
- "date" shouldn't be checked for test
checking "date" causes unexpected failure of "test-shelve.t",
because "run-test.py" puts "[default] shelve = --date '0 0'" into
hgrc.
- explicitly listing it can advertise that ignoring it is intentional
This patch doesn't choose "white list" for the specified "opt", to
avoid treating global options.
2014-06-20 11:15:38 +04:00
|
|
|
allowables = [
|
2015-04-14 23:23:07 +03:00
|
|
|
('addremove', set(['create'])), # 'create' is pseudo action
|
2016-01-14 21:03:31 +03:00
|
|
|
('unknown', set(['create'])),
|
2015-04-14 23:23:07 +03:00
|
|
|
('cleanup', set(['cleanup'])),
|
|
|
|
# ('date', set(['create'])), # ignored for passing '--date "0 0"' in tests
|
|
|
|
('delete', set(['delete'])),
|
|
|
|
('edit', set(['create'])),
|
|
|
|
('list', set(['list'])),
|
|
|
|
('message', set(['create'])),
|
|
|
|
('name', set(['create'])),
|
2015-04-14 23:23:54 +03:00
|
|
|
('patch', set(['patch', 'list'])),
|
|
|
|
('stat', set(['stat', 'list'])),
|
shelve: refactor option combination check to easily add new ones
Before this patch, the name of a newly added option had to be added
into each string that was passed to the "checkopt()" internal
function: these are white-space-separated list of un-acceptable option
names (= "black list" for the specified "opt").
This new option had to be added into multiple strings because each
option could belong to only one action of "create", "cleanup",
"delete" or "list".
In addition to this redundancy, each string passed to "checkopt()" was
already too long to include a new one.
This patch refactors option combination check to make it easier to add
a new option in a subsequent patch.
New "checkopt()" only takes one action ("cleanup", "delete" or
"list"), and checks whether all explicitly activated options are
allowed for it or not (if specified action is activated in "opts").
The "date" entry is listed in "allowables", but commented out,
because:
- "date" shouldn't be checked for test
checking "date" causes unexpected failure of "test-shelve.t",
because "run-test.py" puts "[default] shelve = --date '0 0'" into
hgrc.
- explicitly listing it can advertise that ignoring it is intentional
This patch doesn't choose "white list" for the specified "opt", to
avoid treating global options.
2014-06-20 11:15:38 +04:00
|
|
|
]
|
|
|
|
def checkopt(opt):
|
2016-03-09 10:21:57 +03:00
|
|
|
if opts.get(opt):
|
shelve: refactor option combination check to easily add new ones
Before this patch, the name of a newly added option had to be added
into each string that was passed to the "checkopt()" internal
function: these are white-space-separated list of un-acceptable option
names (= "black list" for the specified "opt").
This new option had to be added into multiple strings because each
option could belong to only one action of "create", "cleanup",
"delete" or "list".
In addition to this redundancy, each string passed to "checkopt()" was
already too long to include a new one.
This patch refactors option combination check to make it easier to add
a new option in a subsequent patch.
New "checkopt()" only takes one action ("cleanup", "delete" or
"list"), and checks whether all explicitly activated options are
allowed for it or not (if specified action is activated in "opts").
The "date" entry is listed in "allowables", but commented out,
because:
- "date" shouldn't be checked for test
checking "date" causes unexpected failure of "test-shelve.t",
because "run-test.py" puts "[default] shelve = --date '0 0'" into
hgrc.
- explicitly listing it can advertise that ignoring it is intentional
This patch doesn't choose "white list" for the specified "opt", to
avoid treating global options.
2014-06-20 11:15:38 +04:00
|
|
|
for i, allowable in allowables:
|
2015-04-14 23:23:07 +03:00
|
|
|
if opts[i] and opt not in allowable:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("options '--%s' and '--%s' may not be "
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
"used together") % (opt, i))
|
|
|
|
return True
|
shelve: refactor option combination check to easily add new ones
Before this patch, the name of a newly added option had to be added
into each string that was passed to the "checkopt()" internal
function: these are white-space-separated list of un-acceptable option
names (= "black list" for the specified "opt").
This new option had to be added into multiple strings because each
option could belong to only one action of "create", "cleanup",
"delete" or "list".
In addition to this redundancy, each string passed to "checkopt()" was
already too long to include a new one.
This patch refactors option combination check to make it easier to add
a new option in a subsequent patch.
New "checkopt()" only takes one action ("cleanup", "delete" or
"list"), and checks whether all explicitly activated options are
allowed for it or not (if specified action is activated in "opts").
The "date" entry is listed in "allowables", but commented out,
because:
- "date" shouldn't be checked for test
checking "date" causes unexpected failure of "test-shelve.t",
because "run-test.py" puts "[default] shelve = --date '0 0'" into
hgrc.
- explicitly listing it can advertise that ignoring it is intentional
This patch doesn't choose "white list" for the specified "opt", to
avoid treating global options.
2014-06-20 11:15:38 +04:00
|
|
|
if checkopt('cleanup'):
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
if pats:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_("cannot specify names when using '--cleanup'"))
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
return cleanupcmd(ui, repo)
|
shelve: refactor option combination check to easily add new ones
Before this patch, the name of a newly added option had to be added
into each string that was passed to the "checkopt()" internal
function: these are white-space-separated list of un-acceptable option
names (= "black list" for the specified "opt").
This new option had to be added into multiple strings because each
option could belong to only one action of "create", "cleanup",
"delete" or "list".
In addition to this redundancy, each string passed to "checkopt()" was
already too long to include a new one.
This patch refactors option combination check to make it easier to add
a new option in a subsequent patch.
New "checkopt()" only takes one action ("cleanup", "delete" or
"list"), and checks whether all explicitly activated options are
allowed for it or not (if specified action is activated in "opts").
The "date" entry is listed in "allowables", but commented out,
because:
- "date" shouldn't be checked for test
checking "date" causes unexpected failure of "test-shelve.t",
because "run-test.py" puts "[default] shelve = --date '0 0'" into
hgrc.
- explicitly listing it can advertise that ignoring it is intentional
This patch doesn't choose "white list" for the specified "opt", to
avoid treating global options.
2014-06-20 11:15:38 +04:00
|
|
|
elif checkopt('delete'):
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
return deletecmd(ui, repo, pats)
|
shelve: refactor option combination check to easily add new ones
Before this patch, the name of a newly added option had to be added
into each string that was passed to the "checkopt()" internal
function: these are white-space-separated list of un-acceptable option
names (= "black list" for the specified "opt").
This new option had to be added into multiple strings because each
option could belong to only one action of "create", "cleanup",
"delete" or "list".
In addition to this redundancy, each string passed to "checkopt()" was
already too long to include a new one.
This patch refactors option combination check to make it easier to add
a new option in a subsequent patch.
New "checkopt()" only takes one action ("cleanup", "delete" or
"list"), and checks whether all explicitly activated options are
allowed for it or not (if specified action is activated in "opts").
The "date" entry is listed in "allowables", but commented out,
because:
- "date" shouldn't be checked for test
checking "date" causes unexpected failure of "test-shelve.t",
because "run-test.py" puts "[default] shelve = --date '0 0'" into
hgrc.
- explicitly listing it can advertise that ignoring it is intentional
This patch doesn't choose "white list" for the specified "opt", to
avoid treating global options.
2014-06-20 11:15:38 +04:00
|
|
|
elif checkopt('list'):
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
return listcmd(ui, repo, pats, opts)
|
2015-04-14 23:23:54 +03:00
|
|
|
elif checkopt('patch'):
|
2017-01-13 22:53:07 +03:00
|
|
|
return patchcmds(ui, repo, pats, opts, subcommand='patch')
|
2015-04-14 23:23:54 +03:00
|
|
|
elif checkopt('stat'):
|
2017-01-13 22:53:07 +03:00
|
|
|
return patchcmds(ui, repo, pats, opts, subcommand='stat')
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
else:
|
|
|
|
return createcmd(ui, repo, pats, opts)
|
|
|
|
|
|
|
|
def extsetup(ui):
|
|
|
|
cmdutil.unfinishedstates.append(
|
2013-10-28 20:03:43 +04:00
|
|
|
[shelvedstate._filename, False, False,
|
|
|
|
_('unshelve already in progress'),
|
shelve: add a shelve extension to save/restore working changes
This extension saves shelved changes using a temporary draft commit,
and bundles the temporary commit and its draft ancestors, then
strips them.
This strategy makes it possible to use Mercurial's bundle and merge
machinery to resolve conflicts if necessary when unshelving, even
when the destination commit or its ancestors have been amended,
squashed, or evolved. (Once a change has been unshelved, its
associated unbundled commits are either rolled back or stripped.)
Storing the shelved change as a bundle also avoids the difficulty
that hidden commits would cause, of making it impossible to amend
the parent if it is a draft commits (a common scenario).
Although this extension shares its name and some functionality with
the third party hgshelve extension, it has little else in common.
Notably, the hgshelve extension shelves changes as unified diffs,
which makes conflict resolution a matter of finding .rej files and
conflict markers, and cleaning up the mess by hand.
We do not yet allow hunk-level choosing of changes to record.
Compared to the hgshelve extension, this is a small regression in
usability, but we hope to integrate that at a later point, once the
record machinery becomes more reusable and robust.
2013-08-29 20:22:13 +04:00
|
|
|
_("use 'hg unshelve --continue' or 'hg unshelve --abort'")])
|
2016-01-06 01:23:27 +03:00
|
|
|
cmdutil.afterresolvedstates.append(
|
|
|
|
[shelvedstate._filename, _('hg unshelve --continue')])
|