2011-02-10 22:46:27 +03:00
|
|
|
# Mercurial bookmark support code
|
|
|
|
#
|
|
|
|
# Copyright 2008 David Soria Parra <dsp@php.net>
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
2015-08-08 05:49:21 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2013-10-14 19:51:04 +04:00
|
|
|
import errno
|
2015-08-08 05:49:21 +03:00
|
|
|
|
|
|
|
from .i18n import _
|
|
|
|
from .node import (
|
|
|
|
bin,
|
|
|
|
hex,
|
2017-06-11 09:42:38 +03:00
|
|
|
short,
|
2015-08-08 05:49:21 +03:00
|
|
|
)
|
|
|
|
from . import (
|
|
|
|
encoding,
|
2016-06-14 00:50:26 +03:00
|
|
|
error,
|
2015-08-08 05:49:21 +03:00
|
|
|
lock as lockmod,
|
2017-06-27 02:40:34 +03:00
|
|
|
obsutil,
|
2017-06-24 17:25:01 +03:00
|
|
|
pycompat,
|
2017-06-11 09:32:58 +03:00
|
|
|
scmutil,
|
bookmarks: check HG_PENDING strictly
Before this patch, checking HG_PENDING in bookmarks.py might cause
unintentional reading unrelated '.hg/bookmarks.pending' in, because it
just examines existence of HG_PENDING environment variable.
This patch uses txnutil.trypending() to check HG_PENDING strictly.
This patch also changes share extension.
Enabling share extension (+ bookmark sharing) makes
bookmarks._getbkfile() receive repo to be shared (= "srcrepo"). On the
other hand, HG_PENDING always refers current working repo (=
"currepo"), and bookmarks.pending is written only into currepo.
Therefore, we should try to read .hg/bookmarks.pending of currepo in
at first. If it doesn't exist, we try to read .hg/bookmarks of srcrepo
in.
Even after this patch, an external hook spawned in currepo can't see
pending changes in currepo via srcrepo, even though such changes
become visible after closing transaction, because there is no easy and
cheap way to know existence of pending changes in currepo via srcrepo.
Please see https://www.mercurial-scm.org/wiki/SharedRepository, too.
BTW, this patch may cause failure of bisect in the repository of
Mercurial itself, if examination at bisecting assumes that an external
hook can see all pending changes while nested transactions across
repositories.
This invisibility issue will be fixed by subsequent patch, which
allows HG_PENDING to refer multiple repositories.
2017-02-20 19:21:00 +03:00
|
|
|
txnutil,
|
2015-08-08 05:49:21 +03:00
|
|
|
util,
|
|
|
|
)
|
2011-02-10 22:46:27 +03:00
|
|
|
|
2017-06-21 01:56:29 +03:00
|
|
|
# label constants
|
|
|
|
# until 3.5, bookmarks.current was the advertised name, not
|
|
|
|
# bookmarks.active, so we must use both to avoid breaking old
|
|
|
|
# custom styles
|
|
|
|
activebookmarklabel = 'bookmarks.active bookmarks.current'
|
|
|
|
|
2015-11-12 04:45:38 +03:00
|
|
|
def _getbkfile(repo):
|
|
|
|
"""Hook so that extensions that mess with the store can hook bm storage.
|
|
|
|
|
|
|
|
For core, this just handles wether we should see pending
|
|
|
|
bookmarks or the committed ones. Other extensions (like share)
|
|
|
|
may need to tweak this behavior further.
|
|
|
|
"""
|
bookmarks: check HG_PENDING strictly
Before this patch, checking HG_PENDING in bookmarks.py might cause
unintentional reading unrelated '.hg/bookmarks.pending' in, because it
just examines existence of HG_PENDING environment variable.
This patch uses txnutil.trypending() to check HG_PENDING strictly.
This patch also changes share extension.
Enabling share extension (+ bookmark sharing) makes
bookmarks._getbkfile() receive repo to be shared (= "srcrepo"). On the
other hand, HG_PENDING always refers current working repo (=
"currepo"), and bookmarks.pending is written only into currepo.
Therefore, we should try to read .hg/bookmarks.pending of currepo in
at first. If it doesn't exist, we try to read .hg/bookmarks of srcrepo
in.
Even after this patch, an external hook spawned in currepo can't see
pending changes in currepo via srcrepo, even though such changes
become visible after closing transaction, because there is no easy and
cheap way to know existence of pending changes in currepo via srcrepo.
Please see https://www.mercurial-scm.org/wiki/SharedRepository, too.
BTW, this patch may cause failure of bisect in the repository of
Mercurial itself, if examination at bisecting assumes that an external
hook can see all pending changes while nested transactions across
repositories.
This invisibility issue will be fixed by subsequent patch, which
allows HG_PENDING to refer multiple repositories.
2017-02-20 19:21:00 +03:00
|
|
|
fp, pending = txnutil.trypending(repo.root, repo.vfs, 'bookmarks')
|
|
|
|
return fp
|
2015-11-12 04:45:38 +03:00
|
|
|
|
2012-11-08 02:21:39 +04:00
|
|
|
class bmstore(dict):
|
|
|
|
"""Storage for bookmarks.
|
2011-02-10 22:46:27 +03:00
|
|
|
|
2015-11-12 05:18:02 +03:00
|
|
|
This object should do all bookmark-related reads and writes, so
|
|
|
|
that it's fairly simple to replace the storage underlying
|
|
|
|
bookmarks without having to clone the logic surrounding
|
|
|
|
bookmarks. This type also should manage the active bookmark, if
|
|
|
|
any.
|
2012-11-08 02:21:39 +04:00
|
|
|
|
|
|
|
This particular bmstore implementation stores bookmarks as
|
|
|
|
{hash}\s{name}\n (the same format as localtags) in
|
|
|
|
.hg/bookmarks. The mapping is stored as {name: nodeid}.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, repo):
|
|
|
|
dict.__init__(self)
|
|
|
|
self._repo = repo
|
2017-06-07 21:32:16 +03:00
|
|
|
self._clean = True
|
|
|
|
self._aclean = True
|
2017-06-08 00:26:43 +03:00
|
|
|
nm = repo.changelog.nodemap
|
|
|
|
tonode = bin # force local lookup
|
2017-06-07 21:13:09 +03:00
|
|
|
setitem = dict.__setitem__
|
2012-11-08 02:21:39 +04:00
|
|
|
try:
|
2017-06-10 03:59:22 +03:00
|
|
|
with _getbkfile(repo) as bkfile:
|
|
|
|
for line in bkfile:
|
|
|
|
line = line.strip()
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
sha, refspec = line.split(' ', 1)
|
|
|
|
node = tonode(sha)
|
|
|
|
if node in nm:
|
|
|
|
refspec = encoding.tolocal(refspec)
|
|
|
|
setitem(self, refspec, node)
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
# TypeError:
|
|
|
|
# - bin(...)
|
|
|
|
# ValueError:
|
|
|
|
# - node in nm, for non-20-bytes entry
|
|
|
|
# - split(...), for string without ' '
|
|
|
|
repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n')
|
|
|
|
% line)
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2012-11-08 02:21:39 +04:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
2015-11-12 05:18:02 +03:00
|
|
|
self._active = _readactive(repo, self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def active(self):
|
|
|
|
return self._active
|
|
|
|
|
|
|
|
@active.setter
|
|
|
|
def active(self, mark):
|
|
|
|
if mark is not None and mark not in self:
|
|
|
|
raise AssertionError('bookmark %s does not exist!' % mark)
|
|
|
|
|
|
|
|
self._active = mark
|
|
|
|
self._aclean = False
|
2015-11-12 05:01:23 +03:00
|
|
|
|
|
|
|
def __setitem__(self, *args, **kwargs):
|
2017-07-10 22:47:34 +03:00
|
|
|
msg = ("'bookmarks[name] = node' is deprecated, "
|
|
|
|
"use 'bookmarks.applychanges'")
|
|
|
|
self._repo.ui.deprecwarn(msg, '4.3')
|
|
|
|
self._set(*args, **kwargs)
|
|
|
|
|
|
|
|
def _set(self, key, value):
|
2015-11-12 05:01:23 +03:00
|
|
|
self._clean = False
|
2017-07-10 22:47:34 +03:00
|
|
|
return dict.__setitem__(self, key, value)
|
2015-11-12 05:01:23 +03:00
|
|
|
|
|
|
|
def __delitem__(self, key):
|
2017-07-10 22:49:37 +03:00
|
|
|
msg = ("'del bookmarks[name]' is deprecated, "
|
|
|
|
"use 'bookmarks.applychanges'")
|
|
|
|
self._repo.ui.deprecwarn(msg, '4.3')
|
|
|
|
self._del(key)
|
|
|
|
|
|
|
|
def _del(self, key):
|
2015-11-12 05:01:23 +03:00
|
|
|
self._clean = False
|
|
|
|
return dict.__delitem__(self, key)
|
2012-11-08 02:21:39 +04:00
|
|
|
|
2017-07-10 18:01:34 +03:00
|
|
|
def applychanges(self, repo, tr, changes):
|
|
|
|
"""Apply a list of changes to bookmarks
|
|
|
|
"""
|
2017-07-10 21:26:53 +03:00
|
|
|
bmchanges = tr.changes.get('bookmarks')
|
2017-07-10 18:01:34 +03:00
|
|
|
for name, node in changes:
|
2017-07-10 21:26:53 +03:00
|
|
|
old = self.get(name)
|
2017-07-10 18:01:34 +03:00
|
|
|
if node is None:
|
2017-07-10 22:49:37 +03:00
|
|
|
self._del(name)
|
2017-07-10 18:01:34 +03:00
|
|
|
else:
|
2017-07-10 22:47:34 +03:00
|
|
|
self._set(name, node)
|
2017-07-10 21:26:53 +03:00
|
|
|
if bmchanges is not None:
|
|
|
|
# if a previous value exist preserve the "initial" value
|
|
|
|
previous = bmchanges.get(name)
|
|
|
|
if previous is not None:
|
|
|
|
old = previous[0]
|
|
|
|
bmchanges[name] = (old, node)
|
2017-07-10 21:10:03 +03:00
|
|
|
self._recordchange(tr)
|
2017-07-10 18:01:34 +03:00
|
|
|
|
2014-09-28 11:41:55 +04:00
|
|
|
def recordchange(self, tr):
|
2017-07-10 21:10:03 +03:00
|
|
|
msg = ("'bookmarks.recorchange' is deprecated, "
|
|
|
|
"use 'bookmarks.applychanges'")
|
|
|
|
self._repo.ui.deprecwarn(msg, '4.3')
|
|
|
|
return self._recordchange(tr)
|
|
|
|
|
|
|
|
def _recordchange(self, tr):
|
2014-09-28 11:41:55 +04:00
|
|
|
"""record that bookmarks have been changed in a transaction
|
|
|
|
|
|
|
|
The transaction is then responsible for updating the file content."""
|
|
|
|
tr.addfilegenerator('bookmarks', ('bookmarks',), self._write,
|
2014-10-18 07:53:42 +04:00
|
|
|
location='plain')
|
2014-10-12 19:29:31 +04:00
|
|
|
tr.hookargs['bookmark_moved'] = '1'
|
2014-09-28 11:41:55 +04:00
|
|
|
|
2014-12-03 07:31:19 +03:00
|
|
|
def _writerepo(self, repo):
|
|
|
|
"""Factored out for extensibility"""
|
2015-11-12 05:18:02 +03:00
|
|
|
rbm = repo._bookmarks
|
|
|
|
if rbm.active not in self:
|
|
|
|
rbm.active = None
|
|
|
|
rbm._writeactive()
|
2012-11-08 02:21:39 +04:00
|
|
|
|
2016-01-16 00:14:45 +03:00
|
|
|
with repo.wlock():
|
2016-06-02 18:44:20 +03:00
|
|
|
file_ = repo.vfs('bookmarks', 'w', atomictemp=True,
|
|
|
|
checkambig=True)
|
2015-11-12 05:03:48 +03:00
|
|
|
try:
|
|
|
|
self._write(file_)
|
|
|
|
except: # re-raises
|
|
|
|
file_.discard()
|
|
|
|
raise
|
|
|
|
finally:
|
|
|
|
file_.close()
|
2012-11-08 02:21:39 +04:00
|
|
|
|
2015-11-12 05:18:02 +03:00
|
|
|
def _writeactive(self):
|
|
|
|
if self._aclean:
|
|
|
|
return
|
2016-01-16 00:14:45 +03:00
|
|
|
with self._repo.wlock():
|
2015-11-12 05:18:02 +03:00
|
|
|
if self._active is not None:
|
2016-06-02 18:44:20 +03:00
|
|
|
f = self._repo.vfs('bookmarks.current', 'w', atomictemp=True,
|
|
|
|
checkambig=True)
|
2015-11-12 05:18:02 +03:00
|
|
|
try:
|
|
|
|
f.write(encoding.fromlocal(self._active))
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
else:
|
2017-03-21 16:50:28 +03:00
|
|
|
self._repo.vfs.tryunlink('bookmarks.current')
|
2015-11-12 05:18:02 +03:00
|
|
|
self._aclean = True
|
|
|
|
|
2014-09-27 14:10:33 +04:00
|
|
|
def _write(self, fp):
|
|
|
|
for name, node in self.iteritems():
|
|
|
|
fp.write("%s %s\n" % (hex(node), encoding.fromlocal(name)))
|
2015-11-12 05:01:23 +03:00
|
|
|
self._clean = True
|
2016-05-05 05:44:30 +03:00
|
|
|
self._repo.invalidatevolatilesets()
|
2014-09-27 14:10:33 +04:00
|
|
|
|
2016-02-20 00:28:09 +03:00
|
|
|
def expandname(self, bname):
|
|
|
|
if bname == '.':
|
2016-06-14 00:50:26 +03:00
|
|
|
if self.active:
|
|
|
|
return self.active
|
|
|
|
else:
|
|
|
|
raise error.Abort(_("no active bookmark"))
|
2016-02-20 00:28:09 +03:00
|
|
|
return bname
|
|
|
|
|
2017-06-11 09:42:38 +03:00
|
|
|
def checkconflict(self, mark, force=False, target=None):
|
|
|
|
"""check repo for a potential clash of mark with an existing bookmark,
|
|
|
|
branch, or hash
|
|
|
|
|
|
|
|
If target is supplied, then check that we are moving the bookmark
|
|
|
|
forward.
|
|
|
|
|
|
|
|
If force is supplied, then forcibly move the bookmark to a new commit
|
|
|
|
regardless if it is a move forward.
|
2017-07-10 21:02:32 +03:00
|
|
|
|
|
|
|
If divergent bookmark are to be deleted, they will be returned as list.
|
2017-06-11 09:42:38 +03:00
|
|
|
"""
|
|
|
|
cur = self._repo.changectx('.').node()
|
|
|
|
if mark in self and not force:
|
|
|
|
if target:
|
|
|
|
if self[mark] == target and target == cur:
|
|
|
|
# re-activating a bookmark
|
2017-07-10 21:02:32 +03:00
|
|
|
return []
|
2017-06-11 09:42:38 +03:00
|
|
|
rev = self._repo[target].rev()
|
|
|
|
anc = self._repo.changelog.ancestors([rev])
|
|
|
|
bmctx = self._repo[self[mark]]
|
|
|
|
divs = [self._repo[b].node() for b in self
|
|
|
|
if b.split('@', 1)[0] == mark.split('@', 1)[0]]
|
|
|
|
|
|
|
|
# allow resolving a single divergent bookmark even if moving
|
|
|
|
# the bookmark across branches when a revision is specified
|
|
|
|
# that contains a divergent bookmark
|
|
|
|
if bmctx.rev() not in anc and target in divs:
|
2017-07-10 21:02:32 +03:00
|
|
|
return divergent2delete(self._repo, [target], mark)
|
2017-06-11 09:42:38 +03:00
|
|
|
|
|
|
|
deletefrom = [b for b in divs
|
|
|
|
if self._repo[b].rev() in anc or b == target]
|
2017-07-10 21:02:32 +03:00
|
|
|
delbms = divergent2delete(self._repo, deletefrom, mark)
|
2017-06-11 09:42:38 +03:00
|
|
|
if validdest(self._repo, bmctx, self._repo[target]):
|
|
|
|
self._repo.ui.status(
|
|
|
|
_("moving bookmark '%s' forward from %s\n") %
|
|
|
|
(mark, short(bmctx.node())))
|
2017-07-10 21:02:32 +03:00
|
|
|
return delbms
|
2017-06-11 09:42:38 +03:00
|
|
|
raise error.Abort(_("bookmark '%s' already exists "
|
|
|
|
"(use -f to force)") % mark)
|
|
|
|
if ((mark in self._repo.branchmap() or
|
|
|
|
mark == self._repo.dirstate.branch()) and not force):
|
|
|
|
raise error.Abort(
|
|
|
|
_("a bookmark cannot have the name of an existing branch"))
|
|
|
|
if len(mark) > 3 and not force:
|
|
|
|
try:
|
|
|
|
shadowhash = (mark in self._repo)
|
|
|
|
except error.LookupError: # ambiguous identifier
|
|
|
|
shadowhash = False
|
|
|
|
if shadowhash:
|
|
|
|
self._repo.ui.warn(
|
|
|
|
_("bookmark %s matches a changeset hash\n"
|
|
|
|
"(did you leave a -r out of an 'hg bookmark' "
|
|
|
|
"command?)\n")
|
|
|
|
% mark)
|
2017-07-10 21:02:32 +03:00
|
|
|
return []
|
2017-06-11 09:42:38 +03:00
|
|
|
|
2015-11-12 05:18:02 +03:00
|
|
|
def _readactive(repo, marks):
|
2015-04-14 09:03:13 +03:00
|
|
|
"""
|
|
|
|
Get the active bookmark. We can have an active bookmark that updates
|
|
|
|
itself as we commit. This function returns the name of that bookmark.
|
|
|
|
It is stored in .hg/bookmarks.current
|
|
|
|
"""
|
2011-02-10 22:46:27 +03:00
|
|
|
mark = None
|
2011-03-13 17:02:49 +03:00
|
|
|
try:
|
2015-01-16 01:17:12 +03:00
|
|
|
file = repo.vfs('bookmarks.current')
|
2015-06-24 08:20:08 +03:00
|
|
|
except IOError as inst:
|
2011-03-13 17:02:49 +03:00
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
return None
|
|
|
|
try:
|
2015-12-01 21:08:05 +03:00
|
|
|
# No readline() in osutil.posixfile, reading everything is
|
|
|
|
# cheap.
|
|
|
|
# Note that it's possible for readlines() here to raise
|
|
|
|
# IOError, since we might be reading the active mark over
|
|
|
|
# static-http which only tries to load the file when we try
|
|
|
|
# to read from it.
|
2011-02-11 21:32:49 +03:00
|
|
|
mark = encoding.tolocal((file.readlines() or [''])[0])
|
2015-11-12 05:18:02 +03:00
|
|
|
if mark == '' or mark not in marks:
|
2011-02-10 22:46:27 +03:00
|
|
|
mark = None
|
2015-12-01 21:08:05 +03:00
|
|
|
except IOError as inst:
|
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
return None
|
2011-03-13 17:02:49 +03:00
|
|
|
finally:
|
2011-02-10 22:46:27 +03:00
|
|
|
file.close()
|
|
|
|
return mark
|
|
|
|
|
2015-04-14 08:27:01 +03:00
|
|
|
def activate(repo, mark):
|
|
|
|
"""
|
|
|
|
Set the given bookmark to be 'active', meaning that this bookmark will
|
|
|
|
follow new commits that are made.
|
2011-02-10 22:46:27 +03:00
|
|
|
The name is recorded in .hg/bookmarks.current
|
2015-04-14 08:27:01 +03:00
|
|
|
"""
|
2015-11-12 05:18:02 +03:00
|
|
|
repo._bookmarks.active = mark
|
|
|
|
repo._bookmarks._writeactive()
|
2011-02-10 22:46:27 +03:00
|
|
|
|
2015-04-14 07:53:37 +03:00
|
|
|
def deactivate(repo):
|
|
|
|
"""
|
2015-10-17 01:58:46 +03:00
|
|
|
Unset the active bookmark in this repository.
|
2015-04-14 07:53:37 +03:00
|
|
|
"""
|
2015-11-12 05:18:02 +03:00
|
|
|
repo._bookmarks.active = None
|
|
|
|
repo._bookmarks._writeactive()
|
2012-02-29 01:47:46 +04:00
|
|
|
|
2015-04-14 22:45:15 +03:00
|
|
|
def isactivewdirparent(repo):
|
|
|
|
"""
|
|
|
|
Tell whether the 'active' bookmark (the one that follows new commits)
|
|
|
|
points to one of the parents of the current working directory (wdir).
|
|
|
|
|
|
|
|
While this is normally the case, it can on occasion be false; for example,
|
|
|
|
immediately after a pull, the active bookmark can be moved to point
|
|
|
|
to a place different than the wdir. This is solved by running `hg update`.
|
|
|
|
"""
|
|
|
|
mark = repo._activebookmark
|
2013-01-21 23:47:10 +04:00
|
|
|
marks = repo._bookmarks
|
2015-04-14 22:45:15 +03:00
|
|
|
parents = [p.node() for p in repo[None].parents()]
|
2013-01-21 23:47:10 +04:00
|
|
|
return (mark in marks and marks[mark] in parents)
|
|
|
|
|
2017-07-10 20:08:17 +03:00
|
|
|
def divergent2delete(repo, deletefrom, bm):
|
|
|
|
"""find divergent versions of bm on nodes in deletefrom.
|
|
|
|
|
|
|
|
the list of bookmark to delete."""
|
|
|
|
todelete = []
|
2013-01-31 03:35:00 +04:00
|
|
|
marks = repo._bookmarks
|
|
|
|
divergent = [b for b in marks if b.split('@', 1)[0] == bm.split('@', 1)[0]]
|
|
|
|
for mark in divergent:
|
2014-07-08 23:45:55 +04:00
|
|
|
if mark == '@' or '@' not in mark:
|
|
|
|
# can't be divergent by definition
|
|
|
|
continue
|
2013-01-31 03:35:00 +04:00
|
|
|
if mark and marks[mark] in deletefrom:
|
|
|
|
if mark != bm:
|
2017-07-10 20:08:17 +03:00
|
|
|
todelete.append(mark)
|
|
|
|
return todelete
|
2013-01-31 03:35:00 +04:00
|
|
|
|
2017-05-18 23:43:56 +03:00
|
|
|
def headsforactive(repo):
|
|
|
|
"""Given a repo with an active bookmark, return divergent bookmark nodes.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
repo: A repository with an active bookmark.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of binary node ids that is the full list of other
|
|
|
|
revisions with bookmarks divergent from the active bookmark. If
|
|
|
|
there were no divergent bookmarks, then this list will contain
|
|
|
|
only one entry.
|
|
|
|
"""
|
|
|
|
if not repo._activebookmark:
|
|
|
|
raise ValueError(
|
|
|
|
'headsforactive() only makes sense with an active bookmark')
|
|
|
|
name = repo._activebookmark.split('@', 1)[0]
|
|
|
|
heads = []
|
|
|
|
for mark, n in repo._bookmarks.iteritems():
|
|
|
|
if mark.split('@', 1)[0] == name:
|
|
|
|
heads.append(n)
|
|
|
|
return heads
|
|
|
|
|
2013-08-02 06:43:14 +04:00
|
|
|
def calculateupdate(ui, repo, checkout):
|
|
|
|
'''Return a tuple (targetrev, movemarkfrom) indicating the rev to
|
|
|
|
check out and where to move the active bookmark from, if needed.'''
|
|
|
|
movemarkfrom = None
|
|
|
|
if checkout is None:
|
2015-04-14 22:53:48 +03:00
|
|
|
activemark = repo._activebookmark
|
2015-04-14 22:45:15 +03:00
|
|
|
if isactivewdirparent(repo):
|
2013-08-02 06:43:14 +04:00
|
|
|
movemarkfrom = repo['.'].node()
|
2015-04-14 22:53:48 +03:00
|
|
|
elif activemark:
|
|
|
|
ui.status(_("updating to active bookmark %s\n") % activemark)
|
|
|
|
checkout = activemark
|
2013-08-02 06:43:14 +04:00
|
|
|
return (checkout, movemarkfrom)
|
|
|
|
|
2011-02-10 22:46:27 +03:00
|
|
|
def update(repo, parents, node):
|
2013-05-02 00:34:45 +04:00
|
|
|
deletefrom = parents
|
2011-02-10 22:46:27 +03:00
|
|
|
marks = repo._bookmarks
|
2015-11-12 05:18:02 +03:00
|
|
|
active = marks.active
|
2015-04-14 22:53:48 +03:00
|
|
|
if not active:
|
2012-05-12 23:28:10 +04:00
|
|
|
return False
|
|
|
|
|
2017-07-10 20:40:23 +03:00
|
|
|
bmchanges = []
|
2015-04-14 22:53:48 +03:00
|
|
|
if marks[active] in parents:
|
2013-01-31 03:35:00 +04:00
|
|
|
new = repo[node]
|
2013-05-02 00:34:45 +04:00
|
|
|
divs = [repo[b] for b in marks
|
2015-04-14 22:53:48 +03:00
|
|
|
if b.split('@', 1)[0] == active.split('@', 1)[0]]
|
2013-05-02 00:34:45 +04:00
|
|
|
anc = repo.changelog.ancestors([new.rev()])
|
|
|
|
deletefrom = [b.node() for b in divs if b.rev() in anc or b == new]
|
2015-04-14 22:53:48 +03:00
|
|
|
if validdest(repo, repo[marks[active]], new):
|
2017-07-10 20:40:23 +03:00
|
|
|
bmchanges.append((active, new.node()))
|
2013-01-31 03:35:00 +04:00
|
|
|
|
2017-07-10 20:12:25 +03:00
|
|
|
for bm in divergent2delete(repo, deletefrom, active):
|
|
|
|
bmchanges.append((bm, None))
|
2013-01-31 03:35:00 +04:00
|
|
|
|
2017-07-10 20:12:25 +03:00
|
|
|
if bmchanges:
|
2015-11-17 23:49:57 +03:00
|
|
|
lock = tr = None
|
|
|
|
try:
|
|
|
|
lock = repo.lock()
|
|
|
|
tr = repo.transaction('bookmark')
|
2017-07-10 20:40:23 +03:00
|
|
|
marks.applychanges(repo, tr, bmchanges)
|
2015-11-17 23:49:57 +03:00
|
|
|
tr.close()
|
|
|
|
finally:
|
|
|
|
lockmod.release(tr, lock)
|
2017-07-10 20:12:25 +03:00
|
|
|
return bool(bmchanges)
|
2011-02-10 22:46:27 +03:00
|
|
|
|
2016-11-17 11:59:41 +03:00
|
|
|
def listbinbookmarks(repo):
|
|
|
|
# We may try to list bookmarks on a repo type that does not
|
|
|
|
# support it (e.g., statichttprepository).
|
|
|
|
marks = getattr(repo, '_bookmarks', {})
|
|
|
|
|
|
|
|
hasnode = repo.changelog.hasnode
|
|
|
|
for k, v in marks.iteritems():
|
|
|
|
# don't expose local divergent bookmarks
|
|
|
|
if hasnode(v) and ('@' not in k or k.endswith('@')):
|
|
|
|
yield k, v
|
|
|
|
|
2011-02-10 22:46:27 +03:00
|
|
|
def listbookmarks(repo):
|
|
|
|
d = {}
|
2016-11-17 11:59:41 +03:00
|
|
|
for book, node in listbinbookmarks(repo):
|
|
|
|
d[book] = hex(node)
|
2011-02-10 22:46:27 +03:00
|
|
|
return d
|
|
|
|
|
|
|
|
def pushbookmark(repo, key, old, new):
|
2014-09-29 04:35:33 +04:00
|
|
|
w = l = tr = None
|
2011-02-10 22:46:27 +03:00
|
|
|
try:
|
2014-09-29 04:35:33 +04:00
|
|
|
w = repo.wlock()
|
|
|
|
l = repo.lock()
|
|
|
|
tr = repo.transaction('bookmarks')
|
2011-02-10 22:46:27 +03:00
|
|
|
marks = repo._bookmarks
|
2014-08-26 15:58:41 +04:00
|
|
|
existing = hex(marks.get(key, ''))
|
|
|
|
if existing != old and existing != new:
|
2011-02-10 22:46:27 +03:00
|
|
|
return False
|
|
|
|
if new == '':
|
2017-07-10 18:24:28 +03:00
|
|
|
changes = [(key, None)]
|
2011-02-10 22:46:27 +03:00
|
|
|
else:
|
|
|
|
if new not in repo:
|
|
|
|
return False
|
2017-07-10 18:24:28 +03:00
|
|
|
changes = [(key, repo[new].node())]
|
|
|
|
marks.applychanges(repo, tr, changes)
|
2014-09-29 04:35:33 +04:00
|
|
|
tr.close()
|
2011-02-10 22:46:27 +03:00
|
|
|
return True
|
|
|
|
finally:
|
2014-09-29 04:35:33 +04:00
|
|
|
lockmod.release(tr, l, w)
|
2011-02-10 22:46:27 +03:00
|
|
|
|
2016-12-09 14:22:26 +03:00
|
|
|
def comparebookmarks(repo, srcmarks, dstmarks, targets=None):
|
2013-11-08 07:45:52 +04:00
|
|
|
'''Compare bookmarks between srcmarks and dstmarks
|
|
|
|
|
|
|
|
This returns tuple "(addsrc, adddst, advsrc, advdst, diverge,
|
|
|
|
differ, invalid)", each are list of bookmarks below:
|
|
|
|
|
|
|
|
:addsrc: added on src side (removed on dst side, perhaps)
|
|
|
|
:adddst: added on dst side (removed on src side, perhaps)
|
|
|
|
:advsrc: advanced on src side
|
|
|
|
:advdst: advanced on dst side
|
|
|
|
:diverge: diverge
|
|
|
|
:differ: changed, but changeset referred on src is unknown on dst
|
|
|
|
:invalid: unknown on both side
|
2014-10-24 21:40:37 +04:00
|
|
|
:same: same on both side
|
2013-11-08 07:45:52 +04:00
|
|
|
|
|
|
|
Each elements of lists in result tuple is tuple "(bookmark name,
|
|
|
|
changeset ID on source side, changeset ID on destination
|
|
|
|
side)". Each changeset IDs are 40 hexadecimal digit string or
|
|
|
|
None.
|
|
|
|
|
|
|
|
Changeset IDs of tuples in "addsrc", "adddst", "differ" or
|
|
|
|
"invalid" list may be unknown for repo.
|
|
|
|
|
|
|
|
If "targets" is specified, only bookmarks listed in it are
|
|
|
|
examined.
|
|
|
|
'''
|
|
|
|
|
|
|
|
if targets:
|
|
|
|
bset = set(targets)
|
|
|
|
else:
|
|
|
|
srcmarkset = set(srcmarks)
|
|
|
|
dstmarkset = set(dstmarks)
|
2014-10-24 21:40:37 +04:00
|
|
|
bset = srcmarkset | dstmarkset
|
2013-11-08 07:45:52 +04:00
|
|
|
|
2014-10-24 21:40:37 +04:00
|
|
|
results = ([], [], [], [], [], [], [], [])
|
2013-11-08 07:45:52 +04:00
|
|
|
addsrc = results[0].append
|
|
|
|
adddst = results[1].append
|
|
|
|
advsrc = results[2].append
|
|
|
|
advdst = results[3].append
|
|
|
|
diverge = results[4].append
|
|
|
|
differ = results[5].append
|
|
|
|
invalid = results[6].append
|
2014-10-24 21:40:37 +04:00
|
|
|
same = results[7].append
|
2013-11-08 07:45:52 +04:00
|
|
|
|
|
|
|
for b in sorted(bset):
|
|
|
|
if b not in srcmarks:
|
|
|
|
if b in dstmarks:
|
2016-12-09 14:22:26 +03:00
|
|
|
adddst((b, None, dstmarks[b]))
|
2013-11-08 07:45:52 +04:00
|
|
|
else:
|
|
|
|
invalid((b, None, None))
|
|
|
|
elif b not in dstmarks:
|
2016-12-09 14:22:26 +03:00
|
|
|
addsrc((b, srcmarks[b], None))
|
2013-11-08 07:45:52 +04:00
|
|
|
else:
|
2016-12-09 14:22:26 +03:00
|
|
|
scid = srcmarks[b]
|
|
|
|
dcid = dstmarks[b]
|
2014-10-24 21:40:37 +04:00
|
|
|
if scid == dcid:
|
|
|
|
same((b, scid, dcid))
|
|
|
|
elif scid in repo and dcid in repo:
|
2013-11-08 07:45:52 +04:00
|
|
|
sctx = repo[scid]
|
|
|
|
dctx = repo[dcid]
|
|
|
|
if sctx.rev() < dctx.rev():
|
|
|
|
if validdest(repo, sctx, dctx):
|
|
|
|
advdst((b, scid, dcid))
|
|
|
|
else:
|
|
|
|
diverge((b, scid, dcid))
|
|
|
|
else:
|
|
|
|
if validdest(repo, dctx, sctx):
|
|
|
|
advsrc((b, scid, dcid))
|
|
|
|
else:
|
|
|
|
diverge((b, scid, dcid))
|
|
|
|
else:
|
|
|
|
# it is too expensive to examine in detail, in this case
|
|
|
|
differ((b, scid, dcid))
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
2015-03-17 12:20:24 +03:00
|
|
|
def _diverge(ui, b, path, localmarks, remotenode):
|
2015-03-17 12:20:24 +03:00
|
|
|
'''Return appropriate diverged bookmark for specified ``path``
|
|
|
|
|
|
|
|
This returns None, if it is failed to assign any divergent
|
|
|
|
bookmark name.
|
2015-03-17 12:20:24 +03:00
|
|
|
|
|
|
|
This reuses already existing one with "@number" suffix, if it
|
|
|
|
refers ``remotenode``.
|
2015-03-17 12:20:24 +03:00
|
|
|
'''
|
2013-11-08 07:45:52 +04:00
|
|
|
if b == '@':
|
|
|
|
b = ''
|
|
|
|
# try to use an @pathalias suffix
|
|
|
|
# if an @pathalias already exists, we overwrite (update) it
|
2014-10-03 01:43:50 +04:00
|
|
|
if path.startswith("file:"):
|
|
|
|
path = util.url(path).path
|
2013-11-08 07:45:52 +04:00
|
|
|
for p, u in ui.configitems("paths"):
|
2014-10-03 01:43:50 +04:00
|
|
|
if u.startswith("file:"):
|
|
|
|
u = util.url(u).path
|
2013-11-08 07:45:52 +04:00
|
|
|
if path == u:
|
2015-03-17 12:20:24 +03:00
|
|
|
return '%s@%s' % (b, p)
|
|
|
|
|
|
|
|
# assign a unique "@number" suffix newly
|
|
|
|
for x in range(1, 100):
|
|
|
|
n = '%s@%d' % (b, x)
|
2015-03-17 12:20:24 +03:00
|
|
|
if n not in localmarks or localmarks[n] == remotenode:
|
2015-03-17 12:20:24 +03:00
|
|
|
return n
|
|
|
|
|
|
|
|
return None
|
2013-11-08 07:45:52 +04:00
|
|
|
|
2016-12-09 14:22:26 +03:00
|
|
|
def unhexlifybookmarks(marks):
|
|
|
|
binremotemarks = {}
|
|
|
|
for name, node in marks.items():
|
|
|
|
binremotemarks[name] = bin(node)
|
|
|
|
return binremotemarks
|
|
|
|
|
2014-09-29 02:21:38 +04:00
|
|
|
def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()):
|
2011-03-14 02:10:43 +03:00
|
|
|
ui.debug("checking for updated bookmarks\n")
|
2012-11-08 02:21:39 +04:00
|
|
|
localmarks = repo._bookmarks
|
2014-10-24 21:40:37 +04:00
|
|
|
(addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same
|
2016-12-09 14:22:26 +03:00
|
|
|
) = comparebookmarks(repo, remotemarks, localmarks)
|
2013-11-08 07:45:52 +04:00
|
|
|
|
2014-10-02 21:16:07 +04:00
|
|
|
status = ui.status
|
|
|
|
warn = ui.warn
|
codemod: register core configitems using a script
This is done by a script [2] using RedBaron [1], a tool designed for doing
code refactoring. All "default" values are decided by the script and are
strongly consistent with the existing code.
There are 2 changes done manually to fix tests:
[warn] mercurial/exchange.py: experimental.bundle2-output-capture: default needs manual removal
[warn] mercurial/localrepo.py: experimental.hook-track-tags: default needs manual removal
Since RedBaron is not confident about how to indent things [2].
[1]: https://github.com/PyCQA/redbaron
[2]: https://github.com/PyCQA/redbaron/issues/100
[3]:
#!/usr/bin/env python
# codemod_configitems.py - codemod tool to fill configitems
#
# Copyright 2017 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.
from __future__ import absolute_import, print_function
import os
import sys
import redbaron
def readpath(path):
with open(path) as f:
return f.read()
def writepath(path, content):
with open(path, 'w') as f:
f.write(content)
_configmethods = {'config', 'configbool', 'configint', 'configbytes',
'configlist', 'configdate'}
def extractstring(rnode):
"""get the string from a RedBaron string or call_argument node"""
while rnode.type != 'string':
rnode = rnode.value
return rnode.value[1:-1] # unquote, "'str'" -> "str"
def uiconfigitems(red):
"""match *.ui.config* pattern, yield (node, method, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
obj = node[-3].value
method = node[-2].value
args = node[-1]
section = args[0].value
name = args[1].value
if (obj in ('ui', 'self') and method in _configmethods
and section.type == 'string' and name.type == 'string'):
entry = (node, method, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def coreconfigitems(red):
"""match coreconfigitem(...) pattern, yield (node, args, section, name)"""
for node in red.find_all('atomtrailers'):
entry = None
try:
args = node[1]
section = args[0].value
name = args[1].value
if (node[0].value == 'coreconfigitem' and section.type == 'string'
and name.type == 'string'):
entry = (node, args, extractstring(section),
extractstring(name))
except Exception:
pass
else:
if entry:
yield entry
def registercoreconfig(cfgred, section, name, defaultrepr):
"""insert coreconfigitem to cfgred AST
section and name are plain string, defaultrepr is a string
"""
# find a place to insert the "coreconfigitem" item
entries = list(coreconfigitems(cfgred))
for node, args, nodesection, nodename in reversed(entries):
if (nodesection, nodename) < (section, name):
# insert after this entry
node.insert_after(
'coreconfigitem(%r, %r,\n'
' default=%s,\n'
')' % (section, name, defaultrepr))
return
def main(argv):
if not argv:
print('Usage: codemod_configitems.py FILES\n'
'For example, FILES could be "{hgext,mercurial}/*/**.py"')
dirname = os.path.dirname
reporoot = dirname(dirname(dirname(os.path.abspath(__file__))))
# register configitems to this destination
cfgpath = os.path.join(reporoot, 'mercurial', 'configitems.py')
cfgred = redbaron.RedBaron(readpath(cfgpath))
# state about what to do
registered = set((s, n) for n, a, s, n in coreconfigitems(cfgred))
toregister = {} # {(section, name): defaultrepr}
coreconfigs = set() # {(section, name)}, whether it's used in core
# first loop: scan all files before taking any action
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
iscore = ('mercurial' in path) and ('hgext' not in path)
red = redbaron.RedBaron(readpath(path))
# find all repo.ui.config* and ui.config* calls, and collect their
# section, name and default value information.
for node, method, args, section, name in uiconfigitems(red):
if section == 'web':
# [web] section has some weirdness, ignore them for now
continue
defaultrepr = None
key = (section, name)
if len(args) == 2:
if key in registered:
continue
if method == 'configlist':
defaultrepr = 'list'
elif method == 'configbool':
defaultrepr = 'False'
else:
defaultrepr = 'None'
elif len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
# try to understand the "default" value
dnode = args[2].value
if dnode.type == 'name':
if dnode.value in {'None', 'True', 'False'}:
defaultrepr = dnode.value
elif dnode.type == 'string':
defaultrepr = repr(dnode.value[1:-1])
elif dnode.type in ('int', 'float'):
defaultrepr = dnode.value
# inconsistent default
if key in toregister and toregister[key] != defaultrepr:
defaultrepr = None
# interesting to rewrite
if key not in registered:
if defaultrepr is None:
print('[note] %s: %s.%s: unsupported default'
% (path, section, name))
registered.add(key) # skip checking it again
else:
toregister[key] = defaultrepr
if iscore:
coreconfigs.add(key)
# second loop: rewrite files given "toregister" result
for path in argv:
# reconstruct redbaron - trade CPU for memory
red = redbaron.RedBaron(readpath(path))
changed = False
for node, method, args, section, name in uiconfigitems(red):
key = (section, name)
defaultrepr = toregister.get(key)
if defaultrepr is None or key not in coreconfigs:
continue
if len(args) >= 3 and (args[2].target is None or
args[2].target.value == 'default'):
try:
del args[2]
changed = True
except Exception:
# redbaron fails to do the rewrite due to indentation
# see https://github.com/PyCQA/redbaron/issues/100
print('[warn] %s: %s.%s: default needs manual removal'
% (path, section, name))
if key not in registered:
print('registering %s.%s' % (section, name))
registercoreconfig(cfgred, section, name, defaultrepr)
registered.add(key)
if changed:
print('updating %s' % path)
writepath(path, red.dumps())
if toregister:
print('updating configitems.py')
writepath(cfgpath, cfgred.dumps())
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
2017-07-15 00:22:40 +03:00
|
|
|
if ui.configbool('ui', 'quietbookmarkmove'):
|
2014-10-02 21:16:07 +04:00
|
|
|
status = warn = ui.debug
|
|
|
|
|
2014-09-29 01:07:56 +04:00
|
|
|
explicit = set(explicit)
|
2013-11-08 07:45:52 +04:00
|
|
|
changed = []
|
|
|
|
for b, scid, dcid in addsrc:
|
|
|
|
if scid in repo: # add remote bookmarks for changes we already have
|
2016-12-09 14:22:26 +03:00
|
|
|
changed.append((b, scid, status,
|
2013-11-08 07:45:52 +04:00
|
|
|
_("adding remote bookmark %s\n") % (b)))
|
2015-06-12 03:19:48 +03:00
|
|
|
elif b in explicit:
|
|
|
|
explicit.remove(b)
|
|
|
|
ui.warn(_("remote bookmark %s points to locally missing %s\n")
|
2016-12-09 14:22:26 +03:00
|
|
|
% (b, hex(scid)[:12]))
|
2015-06-12 03:19:48 +03:00
|
|
|
|
2013-11-08 07:45:52 +04:00
|
|
|
for b, scid, dcid in advsrc:
|
2016-12-09 14:22:26 +03:00
|
|
|
changed.append((b, scid, status,
|
2013-11-08 07:45:52 +04:00
|
|
|
_("updating bookmark %s\n") % (b)))
|
2014-09-29 01:07:56 +04:00
|
|
|
# remove normal movement from explicit set
|
|
|
|
explicit.difference_update(d[0] for d in changed)
|
|
|
|
|
2013-11-08 07:45:52 +04:00
|
|
|
for b, scid, dcid in diverge:
|
2014-09-29 01:07:56 +04:00
|
|
|
if b in explicit:
|
|
|
|
explicit.discard(b)
|
2016-12-09 14:22:26 +03:00
|
|
|
changed.append((b, scid, status,
|
2014-11-05 20:25:00 +03:00
|
|
|
_("importing bookmark %s\n") % (b)))
|
2014-09-29 01:07:56 +04:00
|
|
|
else:
|
2016-12-09 14:22:26 +03:00
|
|
|
db = _diverge(ui, b, path, localmarks, scid)
|
2015-03-17 12:20:24 +03:00
|
|
|
if db:
|
2016-12-09 14:22:26 +03:00
|
|
|
changed.append((db, scid, warn,
|
2015-03-17 12:20:24 +03:00
|
|
|
_("divergent bookmark %s stored as %s\n") %
|
|
|
|
(b, db)))
|
|
|
|
else:
|
|
|
|
warn(_("warning: failed to assign numbered name "
|
|
|
|
"to divergent bookmark %s\n") % (b))
|
2014-09-29 01:07:56 +04:00
|
|
|
for b, scid, dcid in adddst + advdst:
|
|
|
|
if b in explicit:
|
|
|
|
explicit.discard(b)
|
2016-12-09 14:22:26 +03:00
|
|
|
changed.append((b, scid, status,
|
2014-11-05 20:25:00 +03:00
|
|
|
_("importing bookmark %s\n") % (b)))
|
2015-06-12 03:19:48 +03:00
|
|
|
for b, scid, dcid in differ:
|
|
|
|
if b in explicit:
|
|
|
|
explicit.remove(b)
|
|
|
|
ui.warn(_("remote bookmark %s points to locally missing %s\n")
|
2016-12-09 14:22:26 +03:00
|
|
|
% (b, hex(scid)[:12]))
|
2014-09-29 01:07:56 +04:00
|
|
|
|
2011-03-14 02:10:43 +03:00
|
|
|
if changed:
|
2014-09-29 02:21:38 +04:00
|
|
|
tr = trfunc()
|
2017-07-10 18:22:17 +03:00
|
|
|
changes = []
|
2013-11-08 07:45:52 +04:00
|
|
|
for b, node, writer, msg in sorted(changed):
|
2017-07-10 18:22:17 +03:00
|
|
|
changes.append((b, node))
|
2013-11-08 07:45:52 +04:00
|
|
|
writer(msg)
|
2017-07-10 18:22:17 +03:00
|
|
|
localmarks.applychanges(repo, tr, changes)
|
2011-03-14 02:10:43 +03:00
|
|
|
|
2015-03-19 17:36:05 +03:00
|
|
|
def incoming(ui, repo, other):
|
|
|
|
'''Show bookmarks incoming from other to repo
|
|
|
|
'''
|
|
|
|
ui.status(_("searching for changed bookmarks\n"))
|
|
|
|
|
2016-12-09 14:22:26 +03:00
|
|
|
remotemarks = unhexlifybookmarks(other.listkeys('bookmarks'))
|
|
|
|
r = comparebookmarks(repo, remotemarks, repo._bookmarks)
|
2015-03-19 17:36:05 +03:00
|
|
|
addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
|
|
|
|
|
|
|
|
incomings = []
|
|
|
|
if ui.debugflag:
|
|
|
|
getid = lambda id: id
|
|
|
|
else:
|
|
|
|
getid = lambda id: id[:12]
|
2015-04-07 20:56:19 +03:00
|
|
|
if ui.verbose:
|
|
|
|
def add(b, id, st):
|
|
|
|
incomings.append(" %-25s %s %s\n" % (b, getid(id), st))
|
|
|
|
else:
|
|
|
|
def add(b, id, st):
|
|
|
|
incomings.append(" %-25s %s\n" % (b, getid(id)))
|
2015-03-19 17:36:05 +03:00
|
|
|
for b, scid, dcid in addsrc:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "added" refers to a bookmark
|
2016-12-09 14:22:26 +03:00
|
|
|
add(b, hex(scid), _('added'))
|
2015-04-07 20:56:19 +03:00
|
|
|
for b, scid, dcid in advsrc:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "advanced" refers to a bookmark
|
2016-12-09 14:22:26 +03:00
|
|
|
add(b, hex(scid), _('advanced'))
|
2015-04-07 20:56:19 +03:00
|
|
|
for b, scid, dcid in diverge:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "diverged" refers to a bookmark
|
2016-12-09 14:22:26 +03:00
|
|
|
add(b, hex(scid), _('diverged'))
|
2015-04-07 20:56:19 +03:00
|
|
|
for b, scid, dcid in differ:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "changed" refers to a bookmark
|
2016-12-09 14:22:26 +03:00
|
|
|
add(b, hex(scid), _('changed'))
|
2015-03-19 17:36:05 +03:00
|
|
|
|
|
|
|
if not incomings:
|
|
|
|
ui.status(_("no changed bookmarks found\n"))
|
|
|
|
return 1
|
|
|
|
|
|
|
|
for s in sorted(incomings):
|
|
|
|
ui.write(s)
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
2015-03-19 17:36:05 +03:00
|
|
|
def outgoing(ui, repo, other):
|
|
|
|
'''Show bookmarks outgoing from repo to other
|
|
|
|
'''
|
|
|
|
ui.status(_("searching for changed bookmarks\n"))
|
|
|
|
|
2016-12-09 14:22:26 +03:00
|
|
|
remotemarks = unhexlifybookmarks(other.listkeys('bookmarks'))
|
|
|
|
r = comparebookmarks(repo, repo._bookmarks, remotemarks)
|
2015-03-19 17:36:05 +03:00
|
|
|
addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
|
|
|
|
|
|
|
|
outgoings = []
|
|
|
|
if ui.debugflag:
|
|
|
|
getid = lambda id: id
|
|
|
|
else:
|
|
|
|
getid = lambda id: id[:12]
|
2015-04-07 20:56:19 +03:00
|
|
|
if ui.verbose:
|
|
|
|
def add(b, id, st):
|
|
|
|
outgoings.append(" %-25s %s %s\n" % (b, getid(id), st))
|
|
|
|
else:
|
|
|
|
def add(b, id, st):
|
|
|
|
outgoings.append(" %-25s %s\n" % (b, getid(id)))
|
2015-03-19 17:36:05 +03:00
|
|
|
for b, scid, dcid in addsrc:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "added refers to a bookmark
|
2016-12-09 14:22:26 +03:00
|
|
|
add(b, hex(scid), _('added'))
|
2015-04-07 20:56:19 +03:00
|
|
|
for b, scid, dcid in adddst:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "deleted" refers to a bookmark
|
2015-04-07 20:56:19 +03:00
|
|
|
add(b, ' ' * 40, _('deleted'))
|
2015-04-07 20:56:19 +03:00
|
|
|
for b, scid, dcid in advsrc:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "advanced" refers to a bookmark
|
2016-12-09 14:22:26 +03:00
|
|
|
add(b, hex(scid), _('advanced'))
|
2015-04-07 20:56:19 +03:00
|
|
|
for b, scid, dcid in diverge:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "diverged" refers to a bookmark
|
2016-12-09 14:22:26 +03:00
|
|
|
add(b, hex(scid), _('diverged'))
|
2015-04-07 20:56:19 +03:00
|
|
|
for b, scid, dcid in differ:
|
2015-04-22 03:02:08 +03:00
|
|
|
# i18n: "changed" refers to a bookmark
|
2016-12-09 14:22:26 +03:00
|
|
|
add(b, hex(scid), _('changed'))
|
2015-03-19 17:36:05 +03:00
|
|
|
|
|
|
|
if not outgoings:
|
|
|
|
ui.status(_("no changed bookmarks found\n"))
|
|
|
|
return 1
|
|
|
|
|
|
|
|
for s in sorted(outgoings):
|
|
|
|
ui.write(s)
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
2015-03-19 17:36:06 +03:00
|
|
|
def summary(repo, other):
|
|
|
|
'''Compare bookmarks between repo and other for "hg summary" output
|
|
|
|
|
|
|
|
This returns "(# of incoming, # of outgoing)" tuple.
|
|
|
|
'''
|
2016-12-09 14:22:26 +03:00
|
|
|
remotemarks = unhexlifybookmarks(other.listkeys('bookmarks'))
|
|
|
|
r = comparebookmarks(repo, remotemarks, repo._bookmarks)
|
2015-03-19 17:36:06 +03:00
|
|
|
addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r
|
|
|
|
return (len(addsrc), len(adddst))
|
|
|
|
|
2012-08-26 02:28:56 +04:00
|
|
|
def validdest(repo, old, new):
|
|
|
|
"""Is the new bookmark destination a valid update from the old one"""
|
2012-10-08 19:26:23 +04:00
|
|
|
repo = repo.unfiltered()
|
2012-08-26 03:28:22 +04:00
|
|
|
if old == new:
|
|
|
|
# Old == new -> nothing to update.
|
2012-09-18 16:39:12 +04:00
|
|
|
return False
|
2012-08-26 03:28:22 +04:00
|
|
|
elif not old:
|
|
|
|
# old is nullrev, anything is valid.
|
|
|
|
# (new != nullrev has been excluded by the previous check)
|
2012-09-18 16:39:12 +04:00
|
|
|
return True
|
2012-08-26 03:28:22 +04:00
|
|
|
elif repo.obsstore:
|
2017-06-27 02:40:34 +03:00
|
|
|
return new.node() in obsutil.foreground(repo, [old.node()])
|
2012-08-26 03:28:22 +04:00
|
|
|
else:
|
2015-01-18 04:38:57 +03:00
|
|
|
# still an independent clause as it is lazier (and therefore faster)
|
2012-09-18 16:39:12 +04:00
|
|
|
return old.descendant(new)
|
2017-06-11 09:32:58 +03:00
|
|
|
|
|
|
|
def checkformat(repo, mark):
|
|
|
|
"""return a valid version of a potential bookmark name
|
|
|
|
|
|
|
|
Raises an abort error if the bookmark name is not valid.
|
|
|
|
"""
|
|
|
|
mark = mark.strip()
|
|
|
|
if not mark:
|
|
|
|
raise error.Abort(_("bookmark names cannot consist entirely of "
|
|
|
|
"whitespace"))
|
|
|
|
scmutil.checknewlabel(repo, mark, 'bookmark')
|
|
|
|
return mark
|
2017-06-13 09:02:48 +03:00
|
|
|
|
|
|
|
def delete(repo, tr, names):
|
|
|
|
"""remove a mark from the bookmark store
|
|
|
|
|
|
|
|
Raises an abort error if mark does not exist.
|
|
|
|
"""
|
|
|
|
marks = repo._bookmarks
|
2017-07-10 18:04:16 +03:00
|
|
|
changes = []
|
2017-06-13 09:02:48 +03:00
|
|
|
for mark in names:
|
|
|
|
if mark not in marks:
|
|
|
|
raise error.Abort(_("bookmark '%s' does not exist") % mark)
|
|
|
|
if mark == repo._activebookmark:
|
|
|
|
deactivate(repo)
|
2017-07-10 18:04:16 +03:00
|
|
|
changes.append((mark, None))
|
|
|
|
marks.applychanges(repo, tr, changes)
|
2017-06-13 21:10:22 +03:00
|
|
|
|
|
|
|
def rename(repo, tr, old, new, force=False, inactive=False):
|
|
|
|
"""rename a bookmark from old to new
|
|
|
|
|
|
|
|
If force is specified, then the new name can overwrite an existing
|
|
|
|
bookmark.
|
|
|
|
|
|
|
|
If inactive is specified, then do not activate the new bookmark.
|
|
|
|
|
|
|
|
Raises an abort error if old is not in the bookmark store.
|
|
|
|
"""
|
|
|
|
marks = repo._bookmarks
|
|
|
|
mark = checkformat(repo, new)
|
|
|
|
if old not in marks:
|
|
|
|
raise error.Abort(_("bookmark '%s' does not exist") % old)
|
2017-07-10 21:02:32 +03:00
|
|
|
changes = []
|
|
|
|
for bm in marks.checkconflict(mark, force):
|
|
|
|
changes.append((bm, None))
|
|
|
|
changes.extend([(mark, marks[old]), (old, None)])
|
2017-07-10 18:08:20 +03:00
|
|
|
marks.applychanges(repo, tr, changes)
|
2017-06-13 21:10:22 +03:00
|
|
|
if repo._activebookmark == old and not inactive:
|
|
|
|
activate(repo, mark)
|
2017-06-21 01:18:40 +03:00
|
|
|
|
|
|
|
def addbookmarks(repo, tr, names, rev=None, force=False, inactive=False):
|
|
|
|
"""add a list of bookmarks
|
|
|
|
|
|
|
|
If force is specified, then the new name can overwrite an existing
|
|
|
|
bookmark.
|
|
|
|
|
|
|
|
If inactive is specified, then do not activate any bookmark. Otherwise, the
|
|
|
|
first bookmark is activated.
|
|
|
|
|
|
|
|
Raises an abort error if old is not in the bookmark store.
|
|
|
|
"""
|
|
|
|
marks = repo._bookmarks
|
|
|
|
cur = repo.changectx('.').node()
|
|
|
|
newact = None
|
2017-07-10 18:10:56 +03:00
|
|
|
changes = []
|
2017-06-21 01:18:40 +03:00
|
|
|
for mark in names:
|
|
|
|
mark = checkformat(repo, mark)
|
|
|
|
if newact is None:
|
|
|
|
newact = mark
|
|
|
|
if inactive and mark == repo._activebookmark:
|
|
|
|
deactivate(repo)
|
|
|
|
return
|
|
|
|
tgt = cur
|
|
|
|
if rev:
|
|
|
|
tgt = scmutil.revsingle(repo, rev).node()
|
2017-07-10 21:02:32 +03:00
|
|
|
for bm in marks.checkconflict(mark, force, tgt):
|
|
|
|
changes.append((bm, None))
|
2017-07-10 18:10:56 +03:00
|
|
|
changes.append((mark, tgt))
|
|
|
|
marks.applychanges(repo, tr, changes)
|
2017-06-21 01:18:40 +03:00
|
|
|
if not inactive and cur == marks[newact] and not rev:
|
|
|
|
activate(repo, newact)
|
|
|
|
elif cur != tgt and newact == repo._activebookmark:
|
|
|
|
deactivate(repo)
|
2017-06-21 02:36:25 +03:00
|
|
|
|
2017-06-21 03:18:20 +03:00
|
|
|
def _printbookmarks(ui, repo, bmarks, **opts):
|
|
|
|
"""private method to print bookmarks
|
2017-06-21 02:36:25 +03:00
|
|
|
|
2017-06-21 03:18:20 +03:00
|
|
|
Provides a way for extensions to control how bookmarks are printed (e.g.
|
|
|
|
prepend or postpend names)
|
2017-06-21 02:36:25 +03:00
|
|
|
"""
|
2017-06-24 17:25:01 +03:00
|
|
|
opts = pycompat.byteskwargs(opts)
|
2017-06-21 02:36:25 +03:00
|
|
|
fm = ui.formatter('bookmarks', opts)
|
|
|
|
hexfn = fm.hexfunc
|
2017-06-21 03:18:20 +03:00
|
|
|
if len(bmarks) == 0 and fm.isplain():
|
2017-06-21 02:36:25 +03:00
|
|
|
ui.status(_("no bookmarks set\n"))
|
2017-06-21 03:18:20 +03:00
|
|
|
for bmark, (n, prefix, label) in sorted(bmarks.iteritems()):
|
2017-06-21 02:36:25 +03:00
|
|
|
fm.startitem()
|
|
|
|
if not ui.quiet:
|
|
|
|
fm.plain(' %s ' % prefix, label=label)
|
|
|
|
fm.write('bookmark', '%s', bmark, label=label)
|
|
|
|
pad = " " * (25 - encoding.colwidth(bmark))
|
|
|
|
fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s',
|
|
|
|
repo.changelog.rev(n), hexfn(n), label=label)
|
2017-06-21 03:18:20 +03:00
|
|
|
fm.data(active=(activebookmarklabel in label))
|
2017-06-21 02:36:25 +03:00
|
|
|
fm.plain('\n')
|
|
|
|
fm.end()
|
2017-06-21 03:18:20 +03:00
|
|
|
|
|
|
|
def printbookmarks(ui, repo, **opts):
|
|
|
|
"""print bookmarks to a formatter
|
|
|
|
|
|
|
|
Provides a way for extensions to control how bookmarks are printed.
|
|
|
|
"""
|
|
|
|
marks = repo._bookmarks
|
|
|
|
bmarks = {}
|
|
|
|
for bmark, n in sorted(marks.iteritems()):
|
|
|
|
active = repo._activebookmark
|
|
|
|
if bmark == active:
|
|
|
|
prefix, label = '*', activebookmarklabel
|
|
|
|
else:
|
|
|
|
prefix, label = ' ', ''
|
|
|
|
|
|
|
|
bmarks[bmark] = (n, prefix, label)
|
|
|
|
_printbookmarks(ui, repo, bmarks, **opts)
|