author | Martin Geisler <mg@lazybytes.net> |
Wed, 17 Feb 2010 23:07:50 +0100 | |
branch | stable |
changeset 10496 | 45734b51c99b |
parent 10463 | 5ddde896a19d |
child 10510 | f77f3383c666 |
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 |
|
9251
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
15 |
It is possible to use bookmark names in every revision lookup (e.g. hg |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
16 |
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 |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
21 |
your .hgrc:: |
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 _ |
7638
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
32 |
from mercurial.node import nullid, nullrev, hex, short |
10463 | 33 |
from mercurial import util, commands, repair, extensions |
7638
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
34 |
import os |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
35 |
|
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
36 |
def write(repo): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
37 |
'''Write bookmarks |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
38 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
39 |
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
|
40 |
in a format equal to those of localtags. |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
41 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
42 |
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
|
43 |
can be copied back on rollback. |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
44 |
''' |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
45 |
refs = repo._bookmarks |
7253
8b81d1e2dc04
bookmarks: Only save undo.bookmarks if bookmarks exist
Joel Rosdahl <joel@rosdahl.net>
parents:
7252
diff
changeset
|
46 |
if os.path.exists(repo.join('bookmarks')): |
8b81d1e2dc04
bookmarks: Only save undo.bookmarks if bookmarks exist
Joel Rosdahl <joel@rosdahl.net>
parents:
7252
diff
changeset
|
47 |
util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks')) |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
48 |
if repo._bookmarkcurrent not in refs: |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
49 |
setcurrent(repo, None) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
50 |
wlock = repo.wlock() |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
51 |
try: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
52 |
file = repo.opener('bookmarks', 'w', atomictemp=True) |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
53 |
for refspec, node in refs.iteritems(): |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
54 |
file.write("%s %s\n" % (hex(node), refspec)) |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
55 |
file.rename() |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
56 |
finally: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
57 |
wlock.release() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
58 |
|
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
59 |
def setcurrent(repo, mark): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
60 |
'''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
|
61 |
|
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
62 |
Set the name of the bookmark that we are on (hg update <bookmark>). |
8087 | 63 |
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
|
64 |
''' |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
65 |
current = repo._bookmarkcurrent |
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
66 |
if current == mark: |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
67 |
return |
7484
167853c7e54a
bookmarks: do not overwrite bookmarks.current if not necessary
David Soria Parra <dsp@php.net>
parents:
7483
diff
changeset
|
68 |
|
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
69 |
refs = repo._bookmarks |
7484
167853c7e54a
bookmarks: do not overwrite bookmarks.current if not necessary
David Soria Parra <dsp@php.net>
parents:
7483
diff
changeset
|
70 |
|
7491
b95ff487870e
bookmarks: this is a comment, not a string
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7489
diff
changeset
|
71 |
# 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
|
72 |
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
|
73 |
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
|
74 |
return |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
75 |
if mark not in refs: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
76 |
mark = '' |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
77 |
wlock = repo.wlock() |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
78 |
try: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
79 |
file = repo.opener('bookmarks.current', 'w', atomictemp=True) |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
80 |
file.write(mark) |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
81 |
file.rename() |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
82 |
finally: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
83 |
wlock.release() |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
84 |
repo._bookmarkcurrent = mark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
85 |
|
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
86 |
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
|
87 |
'''track a line of development with movable markers |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
88 |
|
9251
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
89 |
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
|
90 |
committing. Bookmarks are local. They can be renamed, copied and |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
91 |
deleted. It is possible to use bookmark names in 'hg merge' and |
6bddba3973bc
bookmarks: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9202
diff
changeset
|
92 |
'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
|
93 |
|
8725
353b1c160c2d
bookmarks: update docstring
Abderrahim Kitouni <a.kitouni@gmail.com>
parents:
8527
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
the bookmark is assigned to that revision. |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
98 |
''' |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
99 |
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
|
100 |
marks = repo._bookmarks |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
101 |
cur = repo.changectx('.').node() |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
102 |
|
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
103 |
if rename: |
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
104 |
if rename not in marks: |
7251
444d88175e33
bookmarks: Fix spelling and grammar
Joel Rosdahl <joel@rosdahl.net>
parents:
7250
diff
changeset
|
105 |
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
|
106 |
if mark in marks and not force: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
107 |
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
|
108 |
if mark is None: |
d892211d670e
bookmarks: Require new bookmark name when renaming
Joel Rosdahl <joel@rosdahl.net>
parents:
7253
diff
changeset
|
109 |
raise util.Abort(_("new bookmark name required")) |
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
110 |
marks[mark] = marks[rename] |
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
111 |
del marks[rename] |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
112 |
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
|
113 |
setcurrent(repo, mark) |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
114 |
write(repo) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
115 |
return |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
116 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
117 |
if delete: |
8527
f9a80054dd3c
use 'x is None' instead of 'x == None'
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
118 |
if mark is None: |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
119 |
raise util.Abort(_("bookmark name required")) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
120 |
if mark not in marks: |
7251
444d88175e33
bookmarks: Fix spelling and grammar
Joel Rosdahl <joel@rosdahl.net>
parents:
7250
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
setcurrent(repo, None) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
124 |
del marks[mark] |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
125 |
write(repo) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
126 |
return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
127 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
128 |
if mark != None: |
7259
18c23375861f
bookmarks: Correctly reject newlines in bookmark names
Joel Rosdahl <joel@rosdahl.net>
parents:
7258
diff
changeset
|
129 |
if "\n" in mark: |
18c23375861f
bookmarks: Correctly reject newlines in bookmark names
Joel Rosdahl <joel@rosdahl.net>
parents:
7258
diff
changeset
|
130 |
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
|
131 |
mark = mark.strip() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
132 |
if mark in marks and not force: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
and not force): |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
136 |
raise util.Abort( |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
137 |
_("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
|
138 |
if rev: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
139 |
marks[mark] = repo.lookup(rev) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
140 |
else: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
141 |
marks[mark] = repo.changectx('.').node() |
7816
f420eafe59cd
bookmarks: Set current bookmark if we create a new one on the tip
David Soria Parra <dsp@php.net>
parents:
7795
diff
changeset
|
142 |
setcurrent(repo, 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 |
|
8527
f9a80054dd3c
use 'x is None' instead of 'x == None'
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
146 |
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
|
147 |
if rev: |
9bd051efbdd6
bookmarks: Require a bookmark name when a revision is specified
Joel Rosdahl <joel@rosdahl.net>
parents:
7257
diff
changeset
|
148 |
raise util.Abort(_("bookmark name required")) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
149 |
if len(marks) == 0: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
150 |
ui.status("no bookmarks set\n") |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
151 |
else: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
152 |
for bmark, n in marks.iteritems(): |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
153 |
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
|
154 |
current = repo._bookmarkcurrent |
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
155 |
prefix = (bmark == current and n == cur) and '*' or ' ' |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
156 |
else: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
157 |
prefix = (n == cur) and '*' or ' ' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
158 |
|
9459
3b283adcc720
bookmarks: support --quiet
Steve Losh <steve@stevelosh.com>
parents:
9282
diff
changeset
|
159 |
if ui.quiet: |
3b283adcc720
bookmarks: support --quiet
Steve Losh <steve@stevelosh.com>
parents:
9282
diff
changeset
|
160 |
ui.write("%s\n" % bmark) |
3b283adcc720
bookmarks: support --quiet
Steve Losh <steve@stevelosh.com>
parents:
9282
diff
changeset
|
161 |
else: |
3b283adcc720
bookmarks: support --quiet
Steve Losh <steve@stevelosh.com>
parents:
9282
diff
changeset
|
162 |
ui.write(" %s %-25s %d:%s\n" % ( |
3b283adcc720
bookmarks: support --quiet
Steve Losh <steve@stevelosh.com>
parents:
9282
diff
changeset
|
163 |
prefix, bmark, repo.changelog.rev(n), hexfn(n))) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
164 |
return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
165 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
166 |
def _revstostrip(changelog, node): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
167 |
srev = changelog.rev(node) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
168 |
tostrip = [srev] |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
169 |
saveheads = [] |
7283
b19c0200c90b
bookmarks: fix strip handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
170 |
for r in xrange(srev, len(changelog)): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
171 |
parents = changelog.parentrevs(r) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
172 |
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
|
173 |
tostrip.append(r) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
174 |
if parents[1] != nullrev: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
175 |
for p in parents: |
7283
b19c0200c90b
bookmarks: fix strip handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
176 |
if p not in tostrip and p > srev: |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
177 |
saveheads.append(p) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
178 |
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
|
179 |
|
7638
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
180 |
def strip(oldstrip, ui, repo, node, backup="all"): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
181 |
"""Strip bookmarks if revisions are stripped using |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
182 |
the mercurial.strip method. This usually happens during |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
183 |
qpush and qpop""" |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
184 |
revisions = _revstostrip(repo.changelog, node) |
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
185 |
marks = repo._bookmarks |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
186 |
update = [] |
7622
4dd7b28003d2
use dict.iteritems() rather than dict.items()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7552
diff
changeset
|
187 |
for mark, n in marks.iteritems(): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
188 |
if repo.changelog.rev(n) in revisions: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
189 |
update.append(mark) |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7262
diff
changeset
|
190 |
oldstrip(ui, repo, node, backup) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
191 |
if len(update) > 0: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
192 |
for m in update: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
193 |
marks[m] = repo.changectx('.').node() |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
194 |
write(repo) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
195 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
196 |
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
|
197 |
if not repo.local(): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
198 |
return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
199 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
200 |
class bookmark_repo(repo.__class__): |
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
201 |
|
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
202 |
@util.propertycache |
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
203 |
def _bookmarks(self): |
10109
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
204 |
'''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
|
205 |
|
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
206 |
Bookmarks are stored as {HASH}\\s{NAME}\\n (localtags format) values |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
207 |
in the .hg/bookmarks file. They are read returned as a dictionary |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
208 |
with name => hash values. |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
209 |
''' |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
210 |
try: |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
211 |
bookmarks = {} |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
212 |
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
|
213 |
sha, refspec = line.strip().split(' ', 1) |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
214 |
bookmarks[refspec] = super(bookmark_repo, self).lookup(sha) |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
215 |
except: |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
216 |
pass |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
217 |
return bookmarks |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
218 |
|
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
219 |
@util.propertycache |
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
220 |
def _bookmarkcurrent(self): |
10109
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
221 |
'''Get the current bookmark |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
222 |
|
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
''' |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
227 |
mark = None |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
228 |
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
|
229 |
file = self.opener('bookmarks.current') |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
230 |
# 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
|
231 |
mark = (file.readlines() or [''])[0] |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
232 |
if mark == '': |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
233 |
mark = None |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
234 |
file.close() |
be041d6714ed
bookmarks: move parse() and current() into property definitions
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10108
diff
changeset
|
235 |
return mark |
10107
c03f467423f3
bookmarks: repo._bookmarkcurrent should be a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10106
diff
changeset
|
236 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
237 |
def rollback(self): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
238 |
if os.path.exists(self.join('undo.bookmarks')): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
239 |
util.rename(self.join('undo.bookmarks'), self.join('bookmarks')) |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
240 |
return super(bookmark_repo, self).rollback() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
241 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
242 |
def lookup(self, key): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
243 |
if key in self._bookmarks: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
244 |
key = self._bookmarks[key] |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
245 |
return super(bookmark_repo, self).lookup(key) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
246 |
|
10108
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
247 |
def _bookmarksupdate(self, parents, node): |
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
248 |
marks = self._bookmarks |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
249 |
update = False |
9236
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
250 |
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
|
251 |
mark = self._bookmarkcurrent |
9236
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
252 |
if mark and marks[mark] in parents: |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
253 |
marks[mark] = node |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
254 |
update = True |
9236
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
255 |
else: |
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
256 |
for mark, n in marks.items(): |
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
257 |
if n in parents: |
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
258 |
marks[mark] = node |
a15b0412de06
bookmarks: Teach addchangset to respect track.current
David Soria Parra <dsp@php.net>
parents:
9235
diff
changeset
|
259 |
update = True |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
260 |
if update: |
10106
cb3f6da91646
bookmarks: write() can simply access repo._bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10105
diff
changeset
|
261 |
write(self) |
10108
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
262 |
|
9235
dde454349864
bookmarks: Wrap commictx instead of commit (issue 1515)
David Soria Parra <dsp@php.net>
parents:
9202
diff
changeset
|
263 |
def commitctx(self, ctx, error=False): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
264 |
"""Add a revision to the repository and |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
265 |
move the bookmark""" |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
266 |
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
|
267 |
try: |
9235
dde454349864
bookmarks: Wrap commictx instead of commit (issue 1515)
David Soria Parra <dsp@php.net>
parents:
9202
diff
changeset
|
268 |
node = super(bookmark_repo, self).commitctx(ctx, error) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
269 |
if node is None: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
270 |
return None |
8944
dda4ad7c9ea9
bookmarks: Change references to "repo" by references to "self" (issue1611)
Isaac Jurado <diptongo@gmail.com>
parents:
8894
diff
changeset
|
271 |
parents = self.changelog.parents(node) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
272 |
if parents[1] == nullid: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
273 |
parents = (parents[0],) |
10108
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
274 |
|
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
275 |
self._bookmarksupdate(parents, node) |
8862
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
276 |
return node |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
277 |
finally: |
cd96f159a2d3
bookmarks: add appropriate locking (issue1691)
Matt Mackall <mpm@selenic.com>
parents:
8762
diff
changeset
|
278 |
wlock.release() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
279 |
|
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
280 |
def addchangegroup(self, source, srctype, url, emptyok=False): |
8944
dda4ad7c9ea9
bookmarks: Change references to "repo" by references to "self" (issue1611)
Isaac Jurado <diptongo@gmail.com>
parents:
8894
diff
changeset
|
281 |
parents = self.dirstate.parents() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
282 |
|
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
283 |
result = super(bookmark_repo, self).addchangegroup( |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
284 |
source, srctype, url, emptyok) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
285 |
if result > 1: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
286 |
# We have more heads than before |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
287 |
return result |
8944
dda4ad7c9ea9
bookmarks: Change references to "repo" by references to "self" (issue1611)
Isaac Jurado <diptongo@gmail.com>
parents:
8894
diff
changeset
|
288 |
node = self.changelog.tip() |
10108
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
289 |
|
b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10107
diff
changeset
|
290 |
self._bookmarksupdate(parents, node) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
291 |
return result |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
292 |
|
9145
6b03f93b8ff3
localrepo: factor _findtags() out of tags() (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9053
diff
changeset
|
293 |
def _findtags(self): |
7480
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
294 |
"""Merge bookmarks with normal tags""" |
9145
6b03f93b8ff3
localrepo: factor _findtags() out of tags() (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9053
diff
changeset
|
295 |
(tags, tagtypes) = super(bookmark_repo, self)._findtags() |
10105
dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9643
diff
changeset
|
296 |
tags.update(self._bookmarks) |
9145
6b03f93b8ff3
localrepo: factor _findtags() out of tags() (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9053
diff
changeset
|
297 |
return (tags, tagtypes) |
7480
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
298 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
299 |
repo.__class__ = bookmark_repo |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
300 |
|
7638
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
301 |
def uisetup(ui): |
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
302 |
extensions.wrapfunction(repair, "strip", strip) |
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
303 |
if ui.configbool('bookmarks', 'track.current'): |
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
304 |
extensions.wrapcommand(commands.table, 'update', updatecurbookmark) |
f83a2b1d1a71
bookmarks; clean up imports and function wrapping
Matt Mackall <mpm@selenic.com>
parents:
7637
diff
changeset
|
305 |
|
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
306 |
def updatecurbookmark(orig, ui, repo, *args, **opts): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
307 |
'''Set the current bookmark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
308 |
|
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
309 |
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
|
310 |
file. |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
311 |
''' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
312 |
res = orig(ui, repo, *args, **opts) |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
313 |
rev = opts['rev'] |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
314 |
if not rev and len(args) > 0: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
315 |
rev = args[0] |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
316 |
setcurrent(repo, rev) |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
317 |
return res |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
318 |
|
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
319 |
cmdtable = { |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
320 |
"bookmarks": |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
321 |
(bookmark, |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
322 |
[('f', 'force', False, _('force')), |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
323 |
('r', 'rev', '', _('revision')), |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
324 |
('d', 'delete', False, _('delete a given bookmark')), |
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
325 |
('m', 'rename', '', _('rename a given bookmark'))], |
7818
b6b9065c20b3
bookmarks: change NAME to REV
Benoit Allard <benoit@aeteurope.nl>
parents:
7817
diff
changeset
|
326 |
_('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
|
327 |
} |