author | StevenGBrown |
Sun, 16 Jan 2011 19:12:54 +0800 | |
changeset 13269 | aa3f726a2bdb |
parent 13104 | 5dac0d04b838 |
child 13313 | 0c493e5ce8e9 |
permissions | -rw-r--r-- |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
1 |
# Mercurial extension to provide the 'hg bookmark' command |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
2 |
# |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
3 |
# Copyright 2008 David Soria Parra <dsp@php.net> |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
4 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8087
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
10263 | 6 |
# GNU General Public License version 2 or any later version. |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
7 |
|
8894
868670dbc237
extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents:
8892
diff
changeset
|
8 |
'''track a line of development with movable markers |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
9 |
|
9251
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
10 |
Bookmarks are local movable markers to changesets. Every bookmark |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
11 |
points to a changeset identified by its hash. If you commit a |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
12 |
changeset that is based on a changeset that has a bookmark on it, the |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
13 |
bookmark shifts to the new changeset. |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
14 |
|
11193
687c7d395f20
Use our custom hg reStructuredText role some more
Martin Geisler <mg@aragost.com>
parents:
10973
diff
changeset
|
15 |
It is possible to use bookmark names in every revision lookup (e.g. |
687c7d395f20
Use our custom hg reStructuredText role some more
Martin Geisler <mg@aragost.com>
parents:
10973
diff
changeset
|
16 |
:hg:`merge`, :hg:`update`). |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
17 |
|
9251
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
18 |
By default, when several bookmarks point to the same changeset, they |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
19 |
will all move forward together. It is possible to obtain a more |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
20 |
git-like experience by adding the following configuration option to |
12083
ebfc46929f3e
help: refer to user configuration file more consistently
Brodie Rao <brodie@bitheap.org>
parents:
12026
diff
changeset
|
21 |
your configuration file:: |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
22 |
|
8892
30b25ebaa63b
bookmarks: help improvements
Cédric Duval <cedricduval@free.fr>
parents:
8862
diff
changeset
|
23 |
[bookmarks] |
30b25ebaa63b
bookmarks: help improvements
Cédric Duval <cedricduval@free.fr>
parents:
8862
diff
changeset
|
24 |
track.current = True |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
25 |
|
9251
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
26 |
This will cause Mercurial to track the bookmark that you are currently |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
27 |
using, and only update it. This is similar to git's approach to |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
28 |
branching. |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
29 |
''' |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
30 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
31 |
from mercurial.i18n import _ |
12714
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
32 |
from mercurial.node import nullid, nullrev, bin, hex, short |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
33 |
from mercurial import util, commands, repair, extensions, pushkey, hg, url |
13048
e298cca2d53a
bookmarks: use UTF-8 storage
Matt Mackall <mpm@selenic.com>
parents:
13032
diff
changeset
|
34 |
from mercurial import revset, encoding |
7638
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
35 |
import os |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
36 |
|
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
37 |
def write(repo): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
38 |
'''Write bookmarks |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
39 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
40 |
Write the given bookmark => hash dictionary to the .hg/bookmarks file |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
41 |
in a format equal to those of localtags. |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
42 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
43 |
We also store a backup of the previous state in undo.bookmarks that |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
44 |
can be copied back on rollback. |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
45 |
''' |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
46 |
refs = repo._bookmarks |
13103
6e79a3bb8c79
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile
Brodie Rao <brodie@bitheap.org>
parents:
12881
diff
changeset
|
47 |
|
6e79a3bb8c79
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile
Brodie Rao <brodie@bitheap.org>
parents:
12881
diff
changeset
|
48 |
try: |
6e79a3bb8c79
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile
Brodie Rao <brodie@bitheap.org>
parents:
12881
diff
changeset
|
49 |
bms = repo.opener('bookmarks').read() |
6e79a3bb8c79
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile
Brodie Rao <brodie@bitheap.org>
parents:
12881
diff
changeset
|
50 |
except IOError: |
6e79a3bb8c79
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile
Brodie Rao <brodie@bitheap.org>
parents:
12881
diff
changeset
|
51 |
bms = None |
6e79a3bb8c79
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile
Brodie Rao <brodie@bitheap.org>
parents:
12881
diff
changeset
|
52 |
if bms is not None: |
6e79a3bb8c79
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile
Brodie Rao <brodie@bitheap.org>
parents:
12881
diff
changeset
|
53 |
repo.opener('undo.bookmarks', 'w').write(bms) |
6e79a3bb8c79
bookmarks: create undo.bookmarks using repo.opener instead of util.copyfile
Brodie Rao <brodie@bitheap.org>
parents:
12881
diff
changeset
|
54 |
|
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
55 |
if repo._bookmarkcurrent not in refs: |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
56 |
setcurrent(repo, None) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
57 |
wlock = repo.wlock() |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
58 |
try: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
59 |
file = repo.opener('bookmarks', 'w', atomictemp=True) |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
60 |
for refspec, node in refs.iteritems(): |
13048
e298cca2d53a
bookmarks: use UTF-8 storage
Matt Mackall <mpm@selenic.com>
parents:
13032
diff
changeset
|
61 |
file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec))) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
62 |
file.rename() |
11440
5fe4302cfd72
bookmarks: touch changelog on write to force hgweb reload
Matt Mackall <mpm@selenic.com>
parents:
11434
diff
changeset
|
63 |
|
5fe4302cfd72
bookmarks: touch changelog on write to force hgweb reload
Matt Mackall <mpm@selenic.com>
parents:
11434
diff
changeset
|
64 |
# touch 00changelog.i so hgweb reloads bookmarks (no lock needed) |
5fe4302cfd72
bookmarks: touch changelog on write to force hgweb reload
Matt Mackall <mpm@selenic.com>
parents:
11434
diff
changeset
|
65 |
try: |
5fe4302cfd72
bookmarks: touch changelog on write to force hgweb reload
Matt Mackall <mpm@selenic.com>
parents:
11434
diff
changeset
|
66 |
os.utime(repo.sjoin('00changelog.i'), None) |
5fe4302cfd72
bookmarks: touch changelog on write to force hgweb reload
Matt Mackall <mpm@selenic.com>
parents:
11434
diff
changeset
|
67 |
except OSError: |
5fe4302cfd72
bookmarks: touch changelog on write to force hgweb reload
Matt Mackall <mpm@selenic.com>
parents:
11434
diff
changeset
|
68 |
pass |
5fe4302cfd72
bookmarks: touch changelog on write to force hgweb reload
Matt Mackall <mpm@selenic.com>
parents:
11434
diff
changeset
|
69 |
|
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
70 |
finally: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
71 |
wlock.release() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
72 |
|
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
73 |
def setcurrent(repo, mark): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
74 |
'''Set the name of the bookmark that we are currently on |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
75 |
|
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
76 |
Set the name of the bookmark that we are on (hg update <bookmark>). |
8087 | 77 |
The name is recorded in .hg/bookmarks.current |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
78 |
''' |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
79 |
current = repo._bookmarkcurrent |
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
80 |
if current == mark: |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
81 |
return |
7484
167853c7e54a
bookmarks: do not overwrite bookmarks.current if not necessary
David Soria Parra <dsp@php.net>
parents:
7483
diff
changeset
|
82 |
|
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
83 |
refs = repo._bookmarks |
7484
167853c7e54a
bookmarks: do not overwrite bookmarks.current if not necessary
David Soria Parra <dsp@php.net>
parents:
7483
diff
changeset
|
84 |
|
7491
b95ff487870e
bookmarks: this is a comment, not a string
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7489
diff
changeset
|
85 |
# do not update if we do update to a rev equal to the current bookmark |
7817
cb516e788238
bookmarks: fixes bug where a deleted bookmark may still be treated as current when track.current option is set
Alex Unden <alu@zpuppet.org>
parents:
7816
diff
changeset
|
86 |
if (mark and mark not in refs and |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
87 |
current and refs[current] == repo.changectx('.').node()): |
7484
167853c7e54a
bookmarks: do not overwrite bookmarks.current if not necessary
David Soria Parra <dsp@php.net>
parents:
7483
diff
changeset
|
88 |
return |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
89 |
if mark not in refs: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
90 |
mark = '' |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
91 |
wlock = repo.wlock() |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
92 |
try: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
93 |
file = repo.opener('bookmarks.current', 'w', atomictemp=True) |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
94 |
file.write(mark) |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
95 |
file.rename() |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
96 |
finally: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
97 |
wlock.release() |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
98 |
repo._bookmarkcurrent = mark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
99 |
|
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
100 |
def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, rename=None): |
8894
868670dbc237
extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents:
8892
diff
changeset
|
101 |
'''track a line of development with movable markers |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
102 |
|
9251
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
103 |
Bookmarks are pointers to certain commits that move when |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
104 |
committing. Bookmarks are local. They can be renamed, copied and |
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10956
diff
changeset
|
105 |
deleted. It is possible to use bookmark names in :hg:`merge` and |
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10956
diff
changeset
|
106 |
:hg:`update` to merge and update respectively to a given bookmark. |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
107 |
|
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10956
diff
changeset
|
108 |
You can use :hg:`bookmark NAME` to set a bookmark on the working |
9251
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
109 |
directory's parent revision with the given name. If you specify |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
110 |
a revision using -r REV (where REV may be an existing bookmark), |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
111 |
the bookmark is assigned to that revision. |
12772
4212fdc4db18
bookmarks: add paragraph on pushing and pulling to help
Kevin Bullock <kbullock@ringworld.org>
parents:
12747
diff
changeset
|
112 |
|
4212fdc4db18
bookmarks: add paragraph on pushing and pulling to help
Kevin Bullock <kbullock@ringworld.org>
parents:
12747
diff
changeset
|
113 |
Bookmarks can be pushed and pulled between repositories (see :hg:`help |
4212fdc4db18
bookmarks: add paragraph on pushing and pulling to help
Kevin Bullock <kbullock@ringworld.org>
parents:
12747
diff
changeset
|
114 |
push` and :hg:`help pull`). This requires the bookmark extension to be |
4212fdc4db18
bookmarks: add paragraph on pushing and pulling to help
Kevin Bullock <kbullock@ringworld.org>
parents:
12747
diff
changeset
|
115 |
enabled for both the local and remote repositories. |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
116 |
''' |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
117 |
hexfn = ui.debugflag and hex or short |
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
118 |
marks = repo._bookmarks |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
119 |
cur = repo.changectx('.').node() |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
120 |
|
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
121 |
if rename: |
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
122 |
if rename not in marks: |
7251
444d88175e33
bookmarks: Fix spelling and grammar
Joel Rosdahl <joel@rosdahl.net>
parents:
7250
diff
changeset
|
123 |
raise util.Abort(_("a bookmark of this name does not exist")) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
124 |
if mark in marks and not force: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
125 |
raise util.Abort(_("a bookmark of the same name already exists")) |
7254
d892211d670e
bookmarks: Require new bookmark name when renaming
Joel Rosdahl <joel@rosdahl.net>
parents:
7253
diff
changeset
|
126 |
if mark is None: |
d892211d670e
bookmarks: Require new bookmark name when renaming
Joel Rosdahl <joel@rosdahl.net>
parents:
7253
diff
changeset
|
127 |
raise util.Abort(_("new bookmark name required")) |
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
128 |
marks[mark] = marks[rename] |
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
129 |
del marks[rename] |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
130 |
if repo._bookmarkcurrent == rename: |
7550
fead6cf99a09
bookmarks: set the current bookmark to the new name if we rename the current bookmark
David Soria Parra <dsp@php.net>
parents:
7489
diff
changeset
|
131 |
setcurrent(repo, mark) |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
132 |
write(repo) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
133 |
return |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
134 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
135 |
if delete: |
8527
f9a80054dd3c
use 'x is None' instead of 'x == None'
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
136 |
if mark is None: |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
137 |
raise util.Abort(_("bookmark name required")) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
138 |
if mark not in marks: |
7251
444d88175e33
bookmarks: Fix spelling and grammar
Joel Rosdahl <joel@rosdahl.net>
parents:
7250
diff
changeset
|
139 |
raise util.Abort(_("a bookmark of this name does not exist")) |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
140 |
if mark == repo._bookmarkcurrent: |
7817
cb516e788238
bookmarks: fixes bug where a deleted bookmark may still be treated as current when track.current option is set
Alex Unden <alu@zpuppet.org>
parents:
7816
diff
changeset
|
141 |
setcurrent(repo, None) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
142 |
del marks[mark] |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
143 |
write(repo) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
144 |
return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
145 |
|
13031
3da456d0c885
code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents:
12881
diff
changeset
|
146 |
if mark is not None: |
7259
18c23375861f
bookmarks: Correctly reject newlines in bookmark names
Joel Rosdahl <joel@rosdahl.net>
parents:
7258
diff
changeset
|
147 |
if "\n" in mark: |
18c23375861f
bookmarks: Correctly reject newlines in bookmark names
Joel Rosdahl <joel@rosdahl.net>
parents:
7258
diff
changeset
|
148 |
raise util.Abort(_("bookmark name cannot contain newlines")) |
7260
eb91b9ce2c19
bookmarks: Strip bookmark names of whitespace, just like tag names
Joel Rosdahl <joel@rosdahl.net>
parents:
7259
diff
changeset
|
149 |
mark = mark.strip() |
11704
18c47562d331
bookmarks: don't allow name to contain whitespaces only
Idan Kamara <idankk86@gmail.com>
parents:
11641
diff
changeset
|
150 |
if not mark: |
18c47562d331
bookmarks: don't allow name to contain whitespaces only
Idan Kamara <idankk86@gmail.com>
parents:
11641
diff
changeset
|
151 |
raise util.Abort(_("bookmark names cannot consist entirely of " |
18c47562d331
bookmarks: don't allow name to contain whitespaces only
Idan Kamara <idankk86@gmail.com>
parents:
11641
diff
changeset
|
152 |
"whitespace")) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
153 |
if mark in marks and not force: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
154 |
raise util.Abort(_("a bookmark of the same name already exists")) |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
155 |
if ((mark in repo.branchtags() or mark == repo.dirstate.branch()) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
156 |
and not force): |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
157 |
raise util.Abort( |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
158 |
_("a bookmark cannot have the name of an existing branch")) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
159 |
if rev: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
160 |
marks[mark] = repo.lookup(rev) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
161 |
else: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
162 |
marks[mark] = repo.changectx('.').node() |
11561
e5aaaef91a27
bookmarks: ensure current bookmark is updated when specified with -r .
Brodie Rao <brodie@bitheap.org>
parents:
11444
diff
changeset
|
163 |
setcurrent(repo, mark) |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
164 |
write(repo) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
165 |
return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
166 |
|
8527
f9a80054dd3c
use 'x is None' instead of 'x == None'
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
167 |
if mark is None: |
7258
9bd051efbdd6
bookmarks: Require a bookmark name when a revision is specified
Joel Rosdahl <joel@rosdahl.net>
parents:
7257
diff
changeset
|
168 |
if rev: |
9bd051efbdd6
bookmarks: Require a bookmark name when a revision is specified
Joel Rosdahl <joel@rosdahl.net>
parents:
7257
diff
changeset
|
169 |
raise util.Abort(_("bookmark name required")) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
170 |
if len(marks) == 0: |
10510
f77f3383c666
i18n: mark more strings for translation
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10463
diff
changeset
|
171 |
ui.status(_("no bookmarks set\n")) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
172 |
else: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
173 |
for bmark, n in marks.iteritems(): |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
174 |
if ui.configbool('bookmarks', 'track.current'): |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
175 |
current = repo._bookmarkcurrent |
10820
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
176 |
if bmark == current and n == cur: |
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
177 |
prefix, label = '*', 'bookmarks.current' |
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
178 |
else: |
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
179 |
prefix, label = ' ', '' |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
180 |
else: |
10820
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
181 |
if n == cur: |
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
182 |
prefix, label = '*', 'bookmarks.current' |
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
183 |
else: |
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
184 |
prefix, label = ' ', '' |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
185 |
|
9459
3b283adcc720
bookmarks: support --quiet
Steve Losh <steve@stevelosh.com>
parents:
9282
diff
changeset
|
186 |
if ui.quiet: |
10820
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
187 |
ui.write("%s\n" % bmark, label=label) |
9459
3b283adcc720
bookmarks: support --quiet
Steve Losh <steve@stevelosh.com>
parents:
9282
diff
changeset
|
188 |
else: |
3b283adcc720
bookmarks: support --quiet
Steve Losh <steve@stevelosh.com>
parents:
9282
diff
changeset
|
189 |
ui.write(" %s %-25s %d:%s\n" % ( |
10820
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
190 |
prefix, bmark, repo.changelog.rev(n), hexfn(n)), |
da809085bc9f
bookmark: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents:
10597
diff
changeset
|
191 |
label=label) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
192 |
return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
193 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
194 |
def _revstostrip(changelog, node): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
195 |
srev = changelog.rev(node) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
196 |
tostrip = [srev] |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
197 |
saveheads = [] |
7283
b19c0200c90b
bookmarks: fix strip handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
198 |
for r in xrange(srev, len(changelog)): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
199 |
parents = changelog.parentrevs(r) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
200 |
if parents[0] in tostrip or parents[1] in tostrip: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
201 |
tostrip.append(r) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
202 |
if parents[1] != nullrev: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
203 |
for p in parents: |
7283
b19c0200c90b
bookmarks: fix strip handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
204 |
if p not in tostrip and p > srev: |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
205 |
saveheads.append(p) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
206 |
return [r for r in tostrip if r not in saveheads] |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
207 |
|
7638
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
208 |
def strip(oldstrip, ui, repo, node, backup="all"): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
209 |
"""Strip bookmarks if revisions are stripped using |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
210 |
the mercurial.strip method. This usually happens during |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
211 |
qpush and qpop""" |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
212 |
revisions = _revstostrip(repo.changelog, node) |
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
213 |
marks = repo._bookmarks |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
214 |
update = [] |
7622
4dd7b28003d2
use dict.iteritems() rather than dict.items()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7552
diff
changeset
|
215 |
for mark, n in marks.iteritems(): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
216 |
if repo.changelog.rev(n) in revisions: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
217 |
update.append(mark) |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7262
diff
changeset
|
218 |
oldstrip(ui, repo, node, backup) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
219 |
if len(update) > 0: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
220 |
for m in update: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
221 |
marks[m] = repo.changectx('.').node() |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
222 |
write(repo) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
223 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
224 |
def reposetup(ui, repo): |
9643
013cc052a926
bookmarks: use API to determine if repo is local
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9459
diff
changeset
|
225 |
if not repo.local(): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
226 |
return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
227 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
228 |
class bookmark_repo(repo.__class__): |
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
229 |
|
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
230 |
@util.propertycache |
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
231 |
def _bookmarks(self): |
10109
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
232 |
'''Parse .hg/bookmarks file and return a dictionary |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
233 |
|
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
234 |
Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values |
11641
ead7550f1aab
bookmarks: rewrite _bookmarks method documentation
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11561
diff
changeset
|
235 |
in the .hg/bookmarks file. |
ead7550f1aab
bookmarks: rewrite _bookmarks method documentation
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11561
diff
changeset
|
236 |
Read the file and return a (name=>nodeid) dictionary |
10109
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
237 |
''' |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
238 |
try: |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
239 |
bookmarks = {} |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
240 |
for line in self.opener('bookmarks'): |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
241 |
sha, refspec = line.strip().split(' ', 1) |
13048
e298cca2d53a
bookmarks: use UTF-8 storage
Matt Mackall <mpm@selenic.com>
parents:
13032
diff
changeset
|
242 |
refspec = encoding.tolocal(refspec) |
12747
175fb1b193f4
bookmarks: better fix for issue2016 (lookup infinite recursion)
Paul Molodowitch <pm@stanfordalumni.org>
parents:
12714
diff
changeset
|
243 |
bookmarks[refspec] = self.changelog.lookup(sha) |
10109
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
244 |
except: |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
245 |
pass |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
246 |
return bookmarks |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
247 |
|
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
248 |
@util.propertycache |
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
249 |
def _bookmarkcurrent(self): |
10109
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
250 |
'''Get the current bookmark |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
251 |
|
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
252 |
If we use gittishsh branches we have a current bookmark that |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
253 |
we are on. This function returns the name of the bookmark. It |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
254 |
is stored in .hg/bookmarks.current |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
255 |
''' |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
256 |
mark = None |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
257 |
if os.path.exists(self.join('bookmarks.current')): |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
258 |
file = self.opener('bookmarks.current') |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
259 |
# No readline() in posixfile_nt, reading everything is cheap |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
260 |
mark = (file.readlines() or [''])[0] |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
261 |
if mark == '': |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
262 |
mark = None |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
263 |
file.close() |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
264 |
return mark |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
265 |
|
10882
f0bfe42c7b1f
rollback: add dry-run argument, emit transaction description
Steve Borho <steve@borho.org>
parents:
10826
diff
changeset
|
266 |
def rollback(self, *args): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
267 |
if os.path.exists(self.join('undo.bookmarks')): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
268 |
util.rename(self.join('undo.bookmarks'), self.join('bookmarks')) |
10882
f0bfe42c7b1f
rollback: add dry-run argument, emit transaction description
Steve Borho <steve@borho.org>
parents:
10826
diff
changeset
|
269 |
return super(bookmark_repo, self).rollback(*args) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
270 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
271 |
def lookup(self, key): |
12747
175fb1b193f4
bookmarks: better fix for issue2016 (lookup infinite recursion)
Paul Molodowitch <pm@stanfordalumni.org>
parents:
12714
diff
changeset
|
272 |
if key in self._bookmarks: |
175fb1b193f4
bookmarks: better fix for issue2016 (lookup infinite recursion)
Paul Molodowitch <pm@stanfordalumni.org>
parents:
12714
diff
changeset
|
273 |
key = self._bookmarks[key] |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
274 |
return super(bookmark_repo, self).lookup(key) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
275 |
|
10108
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
276 |
def _bookmarksupdate(self, parents, node): |
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
277 |
marks = self._bookmarks |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
278 |
update = False |
9236
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
279 |
if ui.configbool('bookmarks', 'track.current'): |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
280 |
mark = self._bookmarkcurrent |
9236
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
281 |
if mark and marks[mark] in parents: |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
282 |
marks[mark] = node |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
283 |
update = True |
9236
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
284 |
else: |
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
285 |
for mark, n in marks.items(): |
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
286 |
if n in parents: |
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
287 |
marks[mark] = node |
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
288 |
update = True |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
289 |
if update: |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
290 |
write(self) |
10108
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
291 |
|
9235
dde454349864
bookmarks: Wrap commictx instead of commit (issue 1515)
David Soria Parra <dsp@php.net>
parents:
9202
diff
changeset
|
292 |
def commitctx(self, ctx, error=False): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
293 |
"""Add a revision to the repository and |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
294 |
move the bookmark""" |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
295 |
wlock = self.wlock() # do both commit and bookmark with lock held |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
296 |
try: |
9235
dde454349864
bookmarks: Wrap commictx instead of commit (issue 1515)
David Soria Parra <dsp@php.net>
parents:
9202
diff
changeset
|
297 |
node = super(bookmark_repo, self).commitctx(ctx, error) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
298 |
if node is None: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
299 |
return None |
8944
dda4ad7c9ea9
bookmarks: Change references to "repo" by references to "self" (issue1611)
Isaac Jurado <diptongo@gmail.com>
parents:
8894
diff
changeset
|
300 |
parents = self.changelog.parents(node) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
301 |
if parents[1] == nullid: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
302 |
parents = (parents[0],) |
10108
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
303 |
|
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
304 |
self._bookmarksupdate(parents, node) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
305 |
return node |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
306 |
finally: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
307 |
wlock.release() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
308 |
|
11373
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
309 |
def pull(self, remote, heads=None, force=False): |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
310 |
result = super(bookmark_repo, self).pull(remote, heads, force) |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
311 |
|
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
312 |
self.ui.debug("checking for updated bookmarks\n") |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
313 |
rb = remote.listkeys('bookmarks') |
11774
91c4e6d2c9e5
bookmarks: replace var used as a Boolean with a Boolean
Martin Geisler <mg@aragost.com>
parents:
11705
diff
changeset
|
314 |
changed = False |
11373
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
315 |
for k in rb.keys(): |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
316 |
if k in self._bookmarks: |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
317 |
nr, nl = rb[k], self._bookmarks[k] |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
318 |
if nr in self: |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
319 |
cr = self[nr] |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
320 |
cl = self[nl] |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
321 |
if cl.rev() >= cr.rev(): |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
322 |
continue |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
323 |
if cr in cl.descendants(): |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
324 |
self._bookmarks[k] = cr.node() |
11774
91c4e6d2c9e5
bookmarks: replace var used as a Boolean with a Boolean
Martin Geisler <mg@aragost.com>
parents:
11705
diff
changeset
|
325 |
changed = True |
11373
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
326 |
self.ui.status(_("updating bookmark %s\n") % k) |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
327 |
else: |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
328 |
self.ui.warn(_("not updating divergent" |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
329 |
" bookmark %s\n") % k) |
11774
91c4e6d2c9e5
bookmarks: replace var used as a Boolean with a Boolean
Martin Geisler <mg@aragost.com>
parents:
11705
diff
changeset
|
330 |
if changed: |
11373
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
331 |
write(repo) |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
332 |
|
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
333 |
return result |
306fef8440af
bookmarks: pull known bookmarks from server that are newer
Matt Mackall <mpm@selenic.com>
parents:
11372
diff
changeset
|
334 |
|
11374
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
335 |
def push(self, remote, force=False, revs=None, newbranch=False): |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
336 |
result = super(bookmark_repo, self).push(remote, force, revs, |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
337 |
newbranch) |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
338 |
|
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
339 |
self.ui.debug("checking for updated bookmarks\n") |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
340 |
rb = remote.listkeys('bookmarks') |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
341 |
for k in rb.keys(): |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
342 |
if k in self._bookmarks: |
13050 | 343 |
nr, nl = rb[k], hex(self._bookmarks[k]) |
11374
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
344 |
if nr in self: |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
345 |
cr = self[nr] |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
346 |
cl = self[nl] |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
347 |
if cl in cr.descendants(): |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
348 |
r = remote.pushkey('bookmarks', k, nr, nl) |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
349 |
if r: |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
350 |
self.ui.status(_("updating bookmark %s\n") % k) |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
351 |
else: |
11434
86eea1f97eac
bookmarks: Use error message consistently
David Soria Parra <dsp@php.net>
parents:
11431
diff
changeset
|
352 |
self.ui.warn(_('updating bookmark %s' |
86eea1f97eac
bookmarks: Use error message consistently
David Soria Parra <dsp@php.net>
parents:
11431
diff
changeset
|
353 |
' failed!\n') % k) |
11374
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
354 |
|
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
355 |
return result |
e291c039d8ec
bookmarks: update known bookmarks on the target on push
Matt Mackall <mpm@selenic.com>
parents:
11373
diff
changeset
|
356 |
|
11442
ee1ed6afac21
addchangegroup: pass in lock to release it before changegroup hook is called
Matt Mackall <mpm@selenic.com>
parents:
11440
diff
changeset
|
357 |
def addchangegroup(self, *args, **kwargs): |
ee1ed6afac21
addchangegroup: pass in lock to release it before changegroup hook is called
Matt Mackall <mpm@selenic.com>
parents:
11440
diff
changeset
|
358 |
result = super(bookmark_repo, self).addchangegroup(*args, **kwargs) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
359 |
if result > 1: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
360 |
# We have more heads than before |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
361 |
return result |
8944
dda4ad7c9ea9
bookmarks: Change references to "repo" by references to "self" (issue1611)
Isaac Jurado <diptongo@gmail.com>
parents:
8894
diff
changeset
|
362 |
node = self.changelog.tip() |
13032
e41e2b79883d
dirstate: warn on invalid parents rather than aborting
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
363 |
parents = self.dirstate.parents() |
10108
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
364 |
self._bookmarksupdate(parents, node) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
365 |
return result |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
366 |
|
9145
6b03f93b8ff3
localrepo: factor _findtags() out of tags() (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9053
diff
changeset
|
367 |
def _findtags(self): |
7480
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
368 |
"""Merge bookmarks with normal tags""" |
9145
6b03f93b8ff3
localrepo: factor _findtags() out of tags() (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9053
diff
changeset
|
369 |
(tags, tagtypes) = super(bookmark_repo, self)._findtags() |
12747
175fb1b193f4
bookmarks: better fix for issue2016 (lookup infinite recursion)
Paul Molodowitch <pm@stanfordalumni.org>
parents:
12714
diff
changeset
|
370 |
tags.update(self._bookmarks) |
9145
6b03f93b8ff3
localrepo: factor _findtags() out of tags() (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9053
diff
changeset
|
371 |
return (tags, tagtypes) |
7480
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
372 |
|
10597
153d688cdd06
bookmarks: add invalidate() to bookmark_repo
Paul Molodowitch <pm@stanfordalumni.org>
parents:
10510
diff
changeset
|
373 |
if hasattr(repo, 'invalidate'): |
153d688cdd06
bookmarks: add invalidate() to bookmark_repo
Paul Molodowitch <pm@stanfordalumni.org>
parents:
10510
diff
changeset
|
374 |
def invalidate(self): |
153d688cdd06
bookmarks: add invalidate() to bookmark_repo
Paul Molodowitch <pm@stanfordalumni.org>
parents:
10510
diff
changeset
|
375 |
super(bookmark_repo, self).invalidate() |
153d688cdd06
bookmarks: add invalidate() to bookmark_repo
Paul Molodowitch <pm@stanfordalumni.org>
parents:
10510
diff
changeset
|
376 |
for attr in ('_bookmarks', '_bookmarkcurrent'): |
153d688cdd06
bookmarks: add invalidate() to bookmark_repo
Paul Molodowitch <pm@stanfordalumni.org>
parents:
10510
diff
changeset
|
377 |
if attr in self.__dict__: |
10956
a156ce543a5b
bookmarks: complete the missing references from dda4ad7c9ea9 (issue2121)
Isaac Jurado <diptongo@gmail.com>
parents:
10882
diff
changeset
|
378 |
delattr(self, attr) |
10597
153d688cdd06
bookmarks: add invalidate() to bookmark_repo
Paul Molodowitch <pm@stanfordalumni.org>
parents:
10510
diff
changeset
|
379 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
380 |
repo.__class__ = bookmark_repo |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
381 |
|
11372
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
382 |
def listbookmarks(repo): |
12026
1938954354ec
bookmarks: guard against listing bookmarks on unsupported repos
Martin Geisler <mg@lazybytes.net>
parents:
11994
diff
changeset
|
383 |
# We may try to list bookmarks on a repo type that does not |
1938954354ec
bookmarks: guard against listing bookmarks on unsupported repos
Martin Geisler <mg@lazybytes.net>
parents:
11994
diff
changeset
|
384 |
# support it (e.g., statichttprepository). |
1938954354ec
bookmarks: guard against listing bookmarks on unsupported repos
Martin Geisler <mg@lazybytes.net>
parents:
11994
diff
changeset
|
385 |
if not hasattr(repo, '_bookmarks'): |
1938954354ec
bookmarks: guard against listing bookmarks on unsupported repos
Martin Geisler <mg@lazybytes.net>
parents:
11994
diff
changeset
|
386 |
return {} |
1938954354ec
bookmarks: guard against listing bookmarks on unsupported repos
Martin Geisler <mg@lazybytes.net>
parents:
11994
diff
changeset
|
387 |
|
11372
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
388 |
d = {} |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
389 |
for k, v in repo._bookmarks.iteritems(): |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
390 |
d[k] = hex(v) |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
391 |
return d |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
392 |
|
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
393 |
def pushbookmark(repo, key, old, new): |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
394 |
w = repo.wlock() |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
395 |
try: |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
396 |
marks = repo._bookmarks |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
397 |
if hex(marks.get(key, '')) != old: |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
398 |
return False |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
399 |
if new == '': |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
400 |
del marks[key] |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
401 |
else: |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
402 |
if new not in repo: |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
403 |
return False |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
404 |
marks[key] = repo[new].node() |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
405 |
write(repo) |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
406 |
return True |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
407 |
finally: |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
408 |
w.release() |
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
409 |
|
11378
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
410 |
def pull(oldpull, ui, repo, source="default", **opts): |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
411 |
# translate bookmark args to rev args for actual pull |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
412 |
if opts.get('bookmark'): |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
413 |
# this is an unpleasant hack as pull will do this internally |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
414 |
source, branches = hg.parseurl(ui.expandpath(source), |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
415 |
opts.get('branch')) |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
416 |
other = hg.repository(hg.remoteui(repo, opts), source) |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
417 |
rb = other.listkeys('bookmarks') |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
418 |
|
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
419 |
for b in opts['bookmark']: |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
420 |
if b not in rb: |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
421 |
raise util.Abort(_('remote bookmark %s not found!') % b) |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
422 |
opts.setdefault('rev', []).append(b) |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
423 |
|
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
424 |
result = oldpull(ui, repo, source, **opts) |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
425 |
|
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
426 |
# update specified bookmarks |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
427 |
if opts.get('bookmark'): |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
428 |
for b in opts['bookmark']: |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
429 |
# explicit pull overrides local bookmark if any |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
430 |
ui.status(_("importing bookmark %s\n") % b) |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
431 |
repo._bookmarks[b] = repo[rb[b]].node() |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
432 |
write(repo) |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
433 |
|
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
434 |
return result |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
435 |
|
11379
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
436 |
def push(oldpush, ui, repo, dest=None, **opts): |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
437 |
dopush = True |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
438 |
if opts.get('bookmark'): |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
439 |
dopush = False |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
440 |
for b in opts['bookmark']: |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
441 |
if b in repo._bookmarks: |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
442 |
dopush = True |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
443 |
opts.setdefault('rev', []).append(b) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
444 |
|
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
445 |
result = 0 |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
446 |
if dopush: |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
447 |
result = oldpush(ui, repo, dest, **opts) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
448 |
|
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
449 |
if opts.get('bookmark'): |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
450 |
# this is an unpleasant hack as push will do this internally |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
451 |
dest = ui.expandpath(dest or 'default-push', dest or 'default') |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
452 |
dest, branches = hg.parseurl(dest, opts.get('branch')) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
453 |
other = hg.repository(hg.remoteui(repo, opts), dest) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
454 |
rb = other.listkeys('bookmarks') |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
455 |
for b in opts['bookmark']: |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
456 |
# explicit push overrides remote bookmark if any |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
457 |
if b in repo._bookmarks: |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
458 |
ui.status(_("exporting bookmark %s\n") % b) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
459 |
new = repo[b].hex() |
11994
31dde4c3bb83
bookmarks: Check if the bookmark to delete exists on the remote
David Soria Parra <dsp@php.net>
parents:
11704
diff
changeset
|
460 |
elif b in rb: |
11379
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
461 |
ui.status(_("deleting remote bookmark %s\n") % b) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
462 |
new = '' # delete |
11994
31dde4c3bb83
bookmarks: Check if the bookmark to delete exists on the remote
David Soria Parra <dsp@php.net>
parents:
11704
diff
changeset
|
463 |
else: |
12146
4d12c42fe932
bookmarks: break long line found by check-code
Martin Geisler <mg@lazybytes.net>
parents:
12083
diff
changeset
|
464 |
ui.warn(_('bookmark %s does not exist on the local ' |
4d12c42fe932
bookmarks: break long line found by check-code
Martin Geisler <mg@lazybytes.net>
parents:
12083
diff
changeset
|
465 |
'or remote repository!\n') % b) |
11994
31dde4c3bb83
bookmarks: Check if the bookmark to delete exists on the remote
David Soria Parra <dsp@php.net>
parents:
11704
diff
changeset
|
466 |
return 2 |
11379
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
467 |
old = rb.get(b, '') |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
468 |
r = other.pushkey('bookmarks', b, old, new) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
469 |
if not r: |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
470 |
ui.warn(_('updating bookmark %s failed!\n') % b) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
471 |
if not result: |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
472 |
result = 2 |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
473 |
|
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
474 |
return result |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
475 |
|
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
476 |
def diffbookmarks(ui, repo, remote): |
12851
765c98f068d3
bookmarks: improve English for diffbookmarks
timeless <timeless@gmail.com>
parents:
12823
diff
changeset
|
477 |
ui.status(_("searching for changed bookmarks\n")) |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
478 |
|
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
479 |
lmarks = repo.listkeys('bookmarks') |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
480 |
rmarks = remote.listkeys('bookmarks') |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
481 |
|
11682
f54ec9c70877
bookmarks: sort diffbookmarks() output
Patrick Mezard <pmezard@gmail.com>
parents:
11641
diff
changeset
|
482 |
diff = sorted(set(rmarks) - set(lmarks)) |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
483 |
for k in diff: |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
484 |
ui.write(" %-25s %s\n" % (k, rmarks[k][:12])) |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
485 |
|
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
486 |
if len(diff) <= 0: |
12851
765c98f068d3
bookmarks: improve English for diffbookmarks
timeless <timeless@gmail.com>
parents:
12823
diff
changeset
|
487 |
ui.status(_("no changed bookmarks found\n")) |
11444
b9a46acdfe1f
bookmarks: fix in/out return values
Matt Mackall <mpm@selenic.com>
parents:
11443
diff
changeset
|
488 |
return 1 |
b9a46acdfe1f
bookmarks: fix in/out return values
Matt Mackall <mpm@selenic.com>
parents:
11443
diff
changeset
|
489 |
return 0 |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
490 |
|
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
491 |
def incoming(oldincoming, ui, repo, source="default", **opts): |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
492 |
if opts.get('bookmarks'): |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
493 |
source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch')) |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
494 |
other = hg.repository(hg.remoteui(repo, opts), source) |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
495 |
ui.status(_('comparing with %s\n') % url.hidepassword(source)) |
11444
b9a46acdfe1f
bookmarks: fix in/out return values
Matt Mackall <mpm@selenic.com>
parents:
11443
diff
changeset
|
496 |
return diffbookmarks(ui, repo, other) |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
497 |
else: |
11444
b9a46acdfe1f
bookmarks: fix in/out return values
Matt Mackall <mpm@selenic.com>
parents:
11443
diff
changeset
|
498 |
return oldincoming(ui, repo, source, **opts) |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
499 |
|
11443
9e1bc1aafdb1
bookmarks: fix bogus cut and paste for outgoing
Matt Mackall <mpm@selenic.com>
parents:
11442
diff
changeset
|
500 |
def outgoing(oldoutgoing, ui, repo, dest=None, **opts): |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
501 |
if opts.get('bookmarks'): |
11443
9e1bc1aafdb1
bookmarks: fix bogus cut and paste for outgoing
Matt Mackall <mpm@selenic.com>
parents:
11442
diff
changeset
|
502 |
dest = ui.expandpath(dest or 'default-push', dest or 'default') |
9e1bc1aafdb1
bookmarks: fix bogus cut and paste for outgoing
Matt Mackall <mpm@selenic.com>
parents:
11442
diff
changeset
|
503 |
dest, branches = hg.parseurl(dest, opts.get('branch')) |
9e1bc1aafdb1
bookmarks: fix bogus cut and paste for outgoing
Matt Mackall <mpm@selenic.com>
parents:
11442
diff
changeset
|
504 |
other = hg.repository(hg.remoteui(repo, opts), dest) |
9e1bc1aafdb1
bookmarks: fix bogus cut and paste for outgoing
Matt Mackall <mpm@selenic.com>
parents:
11442
diff
changeset
|
505 |
ui.status(_('comparing with %s\n') % url.hidepassword(dest)) |
11444
b9a46acdfe1f
bookmarks: fix in/out return values
Matt Mackall <mpm@selenic.com>
parents:
11443
diff
changeset
|
506 |
return diffbookmarks(ui, other, repo) |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
507 |
else: |
11444
b9a46acdfe1f
bookmarks: fix in/out return values
Matt Mackall <mpm@selenic.com>
parents:
11443
diff
changeset
|
508 |
return oldoutgoing(ui, repo, dest, **opts) |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
509 |
|
7638
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
510 |
def uisetup(ui): |
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
511 |
extensions.wrapfunction(repair, "strip", strip) |
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
512 |
if ui.configbool('bookmarks', 'track.current'): |
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
513 |
extensions.wrapcommand(commands.table, 'update', updatecurbookmark) |
11378
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
514 |
|
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
515 |
entry = extensions.wrapcommand(commands.table, 'pull', pull) |
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
516 |
entry[1].append(('B', 'bookmark', [], |
12302
6ad36bca3a8a
bookmarks: set VALUE in push/pull
Will Maier <willmaier@ml1.net>
parents:
12152
diff
changeset
|
517 |
_("bookmark to import"), |
6ad36bca3a8a
bookmarks: set VALUE in push/pull
Will Maier <willmaier@ml1.net>
parents:
12152
diff
changeset
|
518 |
_('BOOKMARK'))) |
11379
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
519 |
entry = extensions.wrapcommand(commands.table, 'push', push) |
e1a145eebb6a
bookmarks: add support for push --bookmark to export bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11378
diff
changeset
|
520 |
entry[1].append(('B', 'bookmark', [], |
12302
6ad36bca3a8a
bookmarks: set VALUE in push/pull
Will Maier <willmaier@ml1.net>
parents:
12152
diff
changeset
|
521 |
_("bookmark to export"), |
6ad36bca3a8a
bookmarks: set VALUE in push/pull
Will Maier <willmaier@ml1.net>
parents:
12152
diff
changeset
|
522 |
_('BOOKMARK'))) |
11431
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
523 |
entry = extensions.wrapcommand(commands.table, 'incoming', incoming) |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
524 |
entry[1].append(('B', 'bookmarks', False, |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
525 |
_("compare bookmark"))) |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
526 |
entry = extensions.wrapcommand(commands.table, 'outgoing', outgoing) |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
527 |
entry[1].append(('B', 'bookmarks', False, |
cac256790aa4
bookmarks: Add -B option to incoming/outgoing to compare bookmarks
David Soria Parra <dsp@php.net>
parents:
11379
diff
changeset
|
528 |
_("compare bookmark"))) |
11378
cb21fb1b55ba
bookmarks: add support for pull --bookmark to import remote bookmarks
Matt Mackall <mpm@selenic.com>
parents:
11374
diff
changeset
|
529 |
|
11372
735f2d561747
bookmarks: add pushkey server-side support
Matt Mackall <mpm@selenic.com>
parents:
11321
diff
changeset
|
530 |
pushkey.register('bookmarks', pushbookmark, listbookmarks) |
7638
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
531 |
|
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
532 |
def updatecurbookmark(orig, ui, repo, *args, **opts): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
533 |
'''Set the current bookmark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
534 |
|
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
535 |
If the user updates to a bookmark we update the .hg/bookmarks.current |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
536 |
file. |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
537 |
''' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
538 |
res = orig(ui, repo, *args, **opts) |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
539 |
rev = opts['rev'] |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
540 |
if not rev and len(args) > 0: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
541 |
rev = args[0] |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
542 |
setcurrent(repo, rev) |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
543 |
return res |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
544 |
|
12714
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
545 |
def bmrevset(repo, subset, x): |
12822
f13acb96b2a7
Fix and unify transplant and bookmarks revsets doc registration
Patrick Mezard <pmezard@gmail.com>
parents:
12772
diff
changeset
|
546 |
"""``bookmark([name])`` |
f13acb96b2a7
Fix and unify transplant and bookmarks revsets doc registration
Patrick Mezard <pmezard@gmail.com>
parents:
12772
diff
changeset
|
547 |
The named bookmark or all bookmarks. |
f13acb96b2a7
Fix and unify transplant and bookmarks revsets doc registration
Patrick Mezard <pmezard@gmail.com>
parents:
12772
diff
changeset
|
548 |
""" |
12881
161fe4879bfc
i18n, bookmarks: add comments for translators
Martin Geisler <mg@lazybytes.net>
parents:
12851
diff
changeset
|
549 |
# i18n: "bookmark" is a keyword |
12714
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
550 |
args = revset.getargs(x, 0, 1, _('bookmark takes one or no arguments')) |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
551 |
if args: |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
552 |
bm = revset.getstring(args[0], |
12881
161fe4879bfc
i18n, bookmarks: add comments for translators
Martin Geisler <mg@lazybytes.net>
parents:
12851
diff
changeset
|
553 |
# i18n: "bookmark" is a keyword |
12714
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
554 |
_('the argument to bookmark must be a string')) |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
555 |
bmrev = listbookmarks(repo).get(bm, None) |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
556 |
if bmrev: |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
557 |
bmrev = repo.changelog.rev(bin(bmrev)) |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
558 |
return [r for r in subset if r == bmrev] |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
559 |
bms = set([repo.changelog.rev(bin(r)) for r in listbookmarks(repo).values()]) |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
560 |
return [r for r in subset if r in bms] |
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
561 |
|
12822
f13acb96b2a7
Fix and unify transplant and bookmarks revsets doc registration
Patrick Mezard <pmezard@gmail.com>
parents:
12772
diff
changeset
|
562 |
def extsetup(ui): |
f13acb96b2a7
Fix and unify transplant and bookmarks revsets doc registration
Patrick Mezard <pmezard@gmail.com>
parents:
12772
diff
changeset
|
563 |
revset.symbols['bookmark'] = bmrevset |
12714
f5178fbcd197
bookmarks: add revset for referencing bookmarks
Augie Fackler <durin42@gmail.com>
parents:
12394
diff
changeset
|
564 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
565 |
cmdtable = { |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
566 |
"bookmarks": |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
567 |
(bookmark, |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
568 |
[('f', 'force', False, _('force')), |
11321
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
11193
diff
changeset
|
569 |
('r', 'rev', '', _('revision'), _('REV')), |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
570 |
('d', 'delete', False, _('delete a given bookmark')), |
11321
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
11193
diff
changeset
|
571 |
('m', 'rename', '', _('rename a given bookmark'), _('NAME'))], |
7818
b6b9065c20b3
bookmarks: change NAME to REV
Benoit Allard <benoit@aeteurope.nl>
parents:
7817
diff
changeset
|
572 |
_('hg bookmarks [-f] [-d] [-m NAME] [-r REV] [NAME]')), |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
573 |
} |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10820
diff
changeset
|
574 |
|
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10820
diff
changeset
|
575 |
colortable = {'bookmarks.current': 'green'} |
12823
80deae3bc5ea
hggettext: handle i18nfunctions declaration for docstrings translations
Patrick Mezard <pmezard@gmail.com>
parents:
12822
diff
changeset
|
576 |
|
80deae3bc5ea
hggettext: handle i18nfunctions declaration for docstrings translations
Patrick Mezard <pmezard@gmail.com>
parents:
12822
diff
changeset
|
577 |
# tell hggettext to extract docstrings from these functions: |
80deae3bc5ea
hggettext: handle i18nfunctions declaration for docstrings translations
Patrick Mezard <pmezard@gmail.com>
parents:
12822
diff
changeset
|
578 |
i18nfunctions = [bmrevset] |