Mercurial > hg
annotate hgext/bookmarks.py @ 7481:5f681a143ede
bookmarks: more git-like branches
Bookmarks are not really git branches, but with the track.current option we try
to focus more on a git like behavior as this was requested.
author | David Soria Parra <dsp@php.net> |
---|---|
date | Sat, 06 Dec 2008 01:10:11 +0100 |
parents | 31f70804f1b1 |
children | 187a13bd14c6 |
rev | line source |
---|---|
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 # |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
7 |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
8 '''mercurial bookmarks |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
9 |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
10 Mercurial bookmarks are local moveable pointers to changesets. Every |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
11 bookmark points to a changeset identified by its hash. If you commit a |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
12 changeset that is based on a changeset that has a bookmark on it, the |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
13 bookmark is forwarded to the new changeset. |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
14 |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
15 It is possible to use bookmark names in every revision lookup (e.g. hg |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
16 merge, hg update). |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
17 |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
18 The bookmark extension offers the possiblity to have a more git-like experience |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
19 by adding the following configuration option to your .hgrc: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
20 |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
21 [bookmarks] |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
22 track.current = True |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
23 |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
24 This will cause bookmarks to track the bookmark that you are currently on, and |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
25 just updates it. This is similar to git's approach of branching. |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
26 ''' |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
27 |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
28 from mercurial.commands import templateopts, hex, short |
7478
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
29 from mercurial import extensions |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
30 from mercurial.i18n import _ |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
31 from mercurial import cmdutil, util, commands, changelog |
7256
df800e004077
bookmarks: Avoid unconditional forwarding of bookmarks for the null revision
Joel Rosdahl <joel@rosdahl.net>
parents:
7255
diff
changeset
|
32 from mercurial.node import nullid, nullrev |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
33 from mercurial.repo import RepoError |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
34 import mercurial, mercurial.localrepo, mercurial.repair, os |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
35 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
36 def parse(repo): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
37 '''Parse .hg/bookmarks file and return a dictionary |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
38 |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
39 Bookmarks are stored as {HASH}\s{NAME}\n (localtags format) values |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
40 in the .hg/bookmarks file. They are read by the parse() method and |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
41 returned as a dictionary with name => hash values. |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
42 |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
43 The parsed dictionary is cached until a write() operation is done. |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
44 ''' |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
45 try: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
46 if repo._bookmarks: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
47 return repo._bookmarks |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
48 repo._bookmarks = {} |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
49 for line in repo.opener('bookmarks'): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
50 sha, refspec = line.strip().split(' ', 1) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
51 repo._bookmarks[refspec] = repo.lookup(sha) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
52 except: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
53 pass |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
54 return repo._bookmarks |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
55 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
56 def write(repo, refs): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
57 '''Write bookmarks |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
58 |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
59 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
|
60 in a format equal to those of localtags. |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
61 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
62 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
|
63 can be copied back on rollback. |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
64 ''' |
7253
8b81d1e2dc04
bookmarks: Only save undo.bookmarks if bookmarks exist
Joel Rosdahl <joel@rosdahl.net>
parents:
7252
diff
changeset
|
65 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
|
66 util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks')) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
67 file = repo.opener('bookmarks', 'w+') |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
68 if current(repo) not in refs: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
69 setcurrent(repo, None) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
70 for refspec, node in refs.items(): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
71 file.write("%s %s\n" % (hex(node), refspec)) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
72 file.close() |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
73 |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
74 def current(repo): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
75 '''Get the current bookmark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
76 |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
77 If we use gittishsh branches we have a current bookmark that |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
78 we are on. This function returns the name of the bookmark. It |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
79 is stored in .hg/bookmarks.current |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
80 ''' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
81 if repo._bookmarkcurrent: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
82 return repo._bookmarkcurrent |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
83 mark = None |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
84 if os.path.exists(repo.join('bookmarks.current')): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
85 file = repo.opener('bookmarks.current') |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
86 mark = file.readline() |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
87 if mark == '': |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
88 mark = None |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
89 file.close() |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
90 repo._bookmarkcurrent = mark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
91 return mark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
92 |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
93 def setcurrent(repo, mark): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
94 '''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
|
95 |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
96 Set the name of the bookmark that we are on (hg update <bookmark>). |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
97 The name is recoreded in .hg/bookmarks.current |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
98 ''' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
99 if repo._bookmarkcurrent == mark: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
100 return |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
101 refs = parse(repo) |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
102 if mark not in refs: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
103 mark = '' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
104 file = repo.opener('bookmarks.current', 'w+') |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
105 file.write(mark) |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
106 file.close() |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
107 repo._bookmarkcurrent = mark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
108 |
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
109 def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, rename=None): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
110 '''mercurial bookmarks |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
111 |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
112 Bookmarks are pointers to certain commits that move when |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
113 commiting. Bookmarks are local. They can be renamed, copied and |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
114 deleted. It is possible to use bookmark names in 'hg merge' and 'hg |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
115 update' to update to a given bookmark. |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
116 |
7257
7fb0e130cf14
bookmarks: Improve documentation
Joel Rosdahl <joel@rosdahl.net>
parents:
7256
diff
changeset
|
117 You can use 'hg bookmark NAME' to set a bookmark on the current |
7fb0e130cf14
bookmarks: Improve documentation
Joel Rosdahl <joel@rosdahl.net>
parents:
7256
diff
changeset
|
118 tip with the given name. If you specify a revision using -r REV |
7fb0e130cf14
bookmarks: Improve documentation
Joel Rosdahl <joel@rosdahl.net>
parents:
7256
diff
changeset
|
119 (where REV may be an existing bookmark), the bookmark is set to |
7fb0e130cf14
bookmarks: Improve documentation
Joel Rosdahl <joel@rosdahl.net>
parents:
7256
diff
changeset
|
120 that revision. |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
121 ''' |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
122 hexfn = ui.debugflag and hex or short |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
123 marks = parse(repo) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
124 cur = repo.changectx('.').node() |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
125 |
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
126 if rename: |
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
127 if rename not in marks: |
7251
444d88175e33
bookmarks: Fix spelling and grammar
Joel Rosdahl <joel@rosdahl.net>
parents:
7250
diff
changeset
|
128 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
|
129 if mark in marks and not force: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
130 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
|
131 if mark is None: |
d892211d670e
bookmarks: Require new bookmark name when renaming
Joel Rosdahl <joel@rosdahl.net>
parents:
7253
diff
changeset
|
132 raise util.Abort(_("new bookmark name required")) |
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
133 marks[mark] = marks[rename] |
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
134 del marks[rename] |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
135 write(repo, marks) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
136 return |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
137 |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
138 if delete: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
139 if mark == None: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
140 raise util.Abort(_("bookmark name required")) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
141 if mark not in marks: |
7251
444d88175e33
bookmarks: Fix spelling and grammar
Joel Rosdahl <joel@rosdahl.net>
parents:
7250
diff
changeset
|
142 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
|
143 del marks[mark] |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
144 write(repo, marks) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
145 return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
146 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
147 if mark != None: |
7259
18c23375861f
bookmarks: Correctly reject newlines in bookmark names
Joel Rosdahl <joel@rosdahl.net>
parents:
7258
diff
changeset
|
148 if "\n" in mark: |
18c23375861f
bookmarks: Correctly reject newlines in bookmark names
Joel Rosdahl <joel@rosdahl.net>
parents:
7258
diff
changeset
|
149 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
|
150 mark = mark.strip() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
151 if mark in marks and not force: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
152 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
|
153 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
|
154 and not force): |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
155 raise util.Abort( |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
156 _("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
|
157 if rev: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
158 marks[mark] = repo.lookup(rev) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
159 else: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
160 marks[mark] = repo.changectx('.').node() |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
161 write(repo, marks) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
162 return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
163 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
164 if mark == None: |
7258
9bd051efbdd6
bookmarks: Require a bookmark name when a revision is specified
Joel Rosdahl <joel@rosdahl.net>
parents:
7257
diff
changeset
|
165 if rev: |
9bd051efbdd6
bookmarks: Require a bookmark name when a revision is specified
Joel Rosdahl <joel@rosdahl.net>
parents:
7257
diff
changeset
|
166 raise util.Abort(_("bookmark name required")) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
167 if len(marks) == 0: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
168 ui.status("no bookmarks set\n") |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
169 else: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
170 for bmark, n in marks.iteritems(): |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
171 if ui.configbool('bookmarks', 'track.current'): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
172 prefix = (bmark == current(repo) and n == cur) and '*' or ' ' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
173 else: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
174 prefix = (n == cur) and '*' or ' ' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
175 |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
176 ui.write(" %s %-25s %d:%s\n" % ( |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
177 prefix, bmark, repo.changelog.rev(n), hexfn(n))) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
178 return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
179 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
180 def _revstostrip(changelog, node): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
181 srev = changelog.rev(node) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
182 tostrip = [srev] |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
183 saveheads = [] |
7283
b19c0200c90b
bookmarks: fix strip handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
184 for r in xrange(srev, len(changelog)): |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
185 parents = changelog.parentrevs(r) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
186 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
|
187 tostrip.append(r) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
188 if parents[1] != nullrev: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
189 for p in parents: |
7283
b19c0200c90b
bookmarks: fix strip handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7280
diff
changeset
|
190 if p not in tostrip and p > srev: |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
191 saveheads.append(p) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
192 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
|
193 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
194 def strip(ui, repo, node, backup="all"): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
195 """Strip bookmarks if revisions are stripped using |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
196 the mercurial.strip method. This usually happens during |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
197 qpush and qpop""" |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
198 revisions = _revstostrip(repo.changelog, node) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
199 marks = parse(repo) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
200 update = [] |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
201 for mark, n in marks.items(): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
202 if repo.changelog.rev(n) in revisions: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
203 update.append(mark) |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7262
diff
changeset
|
204 oldstrip(ui, repo, node, backup) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
205 if len(update) > 0: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
206 for m in update: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
207 marks[m] = repo.changectx('.').node() |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
208 write(repo, marks) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
209 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
210 oldstrip = mercurial.repair.strip |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
211 mercurial.repair.strip = strip |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
212 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
213 def reposetup(ui, repo): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
214 if not isinstance(repo, mercurial.localrepo.localrepository): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
215 return |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
216 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
217 # init a bookmark cache as otherwise we would get a infinite reading |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
218 # in lookup() |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
219 repo._bookmarks = None |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
220 repo._bookmarkcurrent = None |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
221 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
222 class bookmark_repo(repo.__class__): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
223 def rollback(self): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
224 if os.path.exists(self.join('undo.bookmarks')): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
225 util.rename(self.join('undo.bookmarks'), self.join('bookmarks')) |
7250
352627bcafc3
bookmarks: Remove trailing space
Joel Rosdahl <joel@rosdahl.net>
parents:
7239
diff
changeset
|
226 return super(bookmark_repo, self).rollback() |
7239
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 def lookup(self, key): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
229 if self._bookmarks is None: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
230 self._bookmarks = parse(self) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
231 if key in self._bookmarks: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
232 key = self._bookmarks[key] |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
233 return super(bookmark_repo, self).lookup(key) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
234 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
235 def commit(self, *k, **kw): |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
236 """Add a revision to the repository and |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
237 move the bookmark""" |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
238 node = super(bookmark_repo, self).commit(*k, **kw) |
7262
3cbadcf28a4c
bookmarks: do nothing if commit was not successful.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
7260
diff
changeset
|
239 if node == None: |
3cbadcf28a4c
bookmarks: do nothing if commit was not successful.
Dmitriy Taychenachev <dimichxp@gmail.com>
parents:
7260
diff
changeset
|
240 return None |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
241 parents = repo.changelog.parents(node) |
7256
df800e004077
bookmarks: Avoid unconditional forwarding of bookmarks for the null revision
Joel Rosdahl <joel@rosdahl.net>
parents:
7255
diff
changeset
|
242 if parents[1] == nullid: |
df800e004077
bookmarks: Avoid unconditional forwarding of bookmarks for the null revision
Joel Rosdahl <joel@rosdahl.net>
parents:
7255
diff
changeset
|
243 parents = (parents[0],) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
244 marks = parse(repo) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
245 update = False |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
246 for mark, n in marks.items(): |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
247 if ui.configbool('bookmarks', 'track.current'): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
248 if mark == current(repo) and n in parents: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
249 marks[mark] = node |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
250 update = True |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
251 else: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
252 if n in parents: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
253 marks[mark] = node |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
254 update = True |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
255 if update: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
256 write(repo, marks) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
257 return node |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
258 |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
259 def addchangegroup(self, source, srctype, url, emptyok=False): |
7316
9737041646bc
bookmarks: Use dirstate to determine the current node in addchangegroup
David Soria Parra <dsp@php.net>
parents:
7283
diff
changeset
|
260 parents = repo.dirstate.parents() |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
261 |
7252
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
262 result = super(bookmark_repo, self).addchangegroup( |
104a8324798e
bookmarks: Avoid long lines
Joel Rosdahl <joel@rosdahl.net>
parents:
7251
diff
changeset
|
263 source, srctype, url, emptyok) |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
264 if result > 1: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
265 # We have more heads than before |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
266 return result |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
267 node = repo.changelog.tip() |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
268 marks = parse(repo) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
269 update = False |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
270 for mark, n in marks.items(): |
7316
9737041646bc
bookmarks: Use dirstate to determine the current node in addchangegroup
David Soria Parra <dsp@php.net>
parents:
7283
diff
changeset
|
271 if n in parents: |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
272 marks[mark] = node |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
273 update = True |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
274 if update: |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
275 write(repo, marks) |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
276 return result |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
277 |
7480
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
278 def tags(self): |
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
279 """Merge bookmarks with normal tags""" |
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
280 if self.tagscache: |
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
281 return self.tagscache |
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
282 |
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
283 tagscache = super(bookmark_repo, self).tags() |
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
284 tagscache.update(parse(repo)) |
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
285 return tagscache |
31f70804f1b1
bookmarks: Include bookmarks in tags.
Martin Geisler <mg...@daimi.au.dk>
parents:
7479
diff
changeset
|
286 |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
287 repo.__class__ = bookmark_repo |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
288 |
7478
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
289 def pushnonbookmarked(orig, ui, repo, *args, **opts): |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
290 'Call push with only the heads that are not bookmarked' |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
291 if opts.get('non_bookmarked'): |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
292 if opts.get('rev'): |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
293 heads = [repo.lookup(r) for r in opts.get('rev')] |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
294 else: |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
295 heads = repo.heads() |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
296 |
7479 | 297 markheads = parse(repo).values() |
7478
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
298 opts['rev'] = [head for head in heads if not(head in markheads)] |
7479 | 299 |
7478
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
300 orig(ui, repo, *args, **opts) |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
301 |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
302 def updatecurbookmark(orig, ui, repo, *args, **opts): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
303 '''Set the current bookmark |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
304 |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
305 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
|
306 file. |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
307 ''' |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
308 res = orig(ui, repo, *args, **opts) |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
309 rev = opts['rev'] |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
310 if not rev and len(args) > 0: |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
311 rev = args[0] |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
312 setcurrent(repo, rev) |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
313 return res |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
314 |
7478
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
315 def uisetup(ui): |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
316 'Replace push with a decorator to provide --non-bookmarked option' |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
317 entry = extensions.wrapcommand(commands.table, 'push', pushnonbookmarked) |
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
318 entry[1].append(('', 'non-bookmarked', None, _("push all heads that are not bookmarked"))) |
7481
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
319 if ui.configbool('bookmarks', 'track.current'): |
5f681a143ede
bookmarks: more git-like branches
David Soria Parra <dsp@php.net>
parents:
7480
diff
changeset
|
320 extensions.wrapcommand(commands.table, 'update', updatecurbookmark) |
7478
4c3e0ad58c5b
bookmarks: Adds support for a --non-bookmarked option to push
Stefan Rusek <stefan@rusek.org>
parents:
7316
diff
changeset
|
321 |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
322 cmdtable = { |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
323 "bookmarks": |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
324 (bookmark, |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
325 [('f', 'force', False, _('force')), |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
326 ('r', 'rev', '', _('revision')), |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
327 ('d', 'delete', False, _('delete a given bookmark')), |
7255
69e431ea124d
bookmarks: Rename --move to --rename
Joel Rosdahl <joel@rosdahl.net>
parents:
7254
diff
changeset
|
328 ('m', 'rename', '', _('rename a given bookmark'))], |
7239
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
329 _('hg bookmarks [-d] [-m NAME] [-r NAME] [NAME]')), |
135003a470f3
Bookmarks: Add the bookmarks extension
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
330 } |