Mercurial > hg
annotate mercurial/bookmarks.py @ 24765:bdf84cc2115b
histedit: add a new histeditaction class
This adds a new class called histeditaction. It represents a single action in a
histedit plan. Future patches will integrate it into the histedit flow, then
convert each existing action in to the class form one by one.
This is part of a larger refactor aimed at increasing histedit robustness,
maintainability, and extensibility.
author | Durham Goode <durham@fb.com> |
---|---|
date | Sat, 04 Apr 2015 11:34:53 -0700 |
parents | 8cf70c97a6e1 |
children | 5947a68fa271 |
rev | line source |
---|---|
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # Mercurial bookmark support code |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 # Copyright 2008 David Soria Parra <dsp@php.net> |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
23360
e06daad65f85
bookmark: read pending data when appropriate
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23317
diff
changeset
|
8 import os |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
9 from mercurial.i18n import _ |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
10 from mercurial.node import hex, bin |
22667
3acc3f95548c
push: update bookmarks (on server) within a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22666
diff
changeset
|
11 from mercurial import encoding, error, util, obsolete, lock as lockmod |
19896
af03279c766a
bookmarks: use "vfs.utime()" instead of "os.utime()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19895
diff
changeset
|
12 import errno |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
13 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
14 class bmstore(dict): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
15 """Storage for bookmarks. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
16 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
17 This object should do all bookmark reads and writes, so that it's |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
18 fairly simple to replace the storage underlying bookmarks without |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
19 having to clone the logic surrounding bookmarks. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
20 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
21 This particular bmstore implementation stores bookmarks as |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
22 {hash}\s{name}\n (the same format as localtags) in |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
23 .hg/bookmarks. The mapping is stored as {name: nodeid}. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
24 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
25 This class does NOT handle the "current" bookmark state at this |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
26 time. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
27 """ |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
28 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
29 def __init__(self, repo): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
30 dict.__init__(self) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
31 self._repo = repo |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
32 try: |
23458
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
33 bkfile = self.getbkfile(repo) |
23360
e06daad65f85
bookmark: read pending data when appropriate
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23317
diff
changeset
|
34 for line in bkfile: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
35 line = line.strip() |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
36 if not line: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
37 continue |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
38 if ' ' not in line: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
39 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n') |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
40 % line) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
41 continue |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
42 sha, refspec = line.split(' ', 1) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
43 refspec = encoding.tolocal(refspec) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
44 try: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
45 self[refspec] = repo.changelog.lookup(sha) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
46 except LookupError: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
47 pass |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
48 except IOError, inst: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
49 if inst.errno != errno.ENOENT: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
50 raise |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
51 |
23458
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
52 def getbkfile(self, repo): |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
53 bkfile = None |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
54 if 'HG_PENDING' in os.environ: |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
55 try: |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
56 bkfile = repo.vfs('bookmarks.pending') |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
57 except IOError, inst: |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
58 if inst.errno != errno.ENOENT: |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
59 raise |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
60 if bkfile is None: |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
61 bkfile = repo.vfs('bookmarks') |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
62 return bkfile |
756376ec6c12
bookmarks: factor out bookmark file opening for easier extensibility
Ryan McElroy <rmcelroy@fb.com>
parents:
23360
diff
changeset
|
63 |
22665
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
64 def recordchange(self, tr): |
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
65 """record that bookmarks have been changed in a transaction |
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
66 |
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
67 The transaction is then responsible for updating the file content.""" |
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
68 tr.addfilegenerator('bookmarks', ('bookmarks',), self._write, |
23317
197e17be5407
transaction: use 'location' instead of 'vfs' objects for file generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23199
diff
changeset
|
69 location='plain') |
22941
da2758c0aca0
bookmarks: inform transaction-related hooks that some bookmarks were moved
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22667
diff
changeset
|
70 tr.hookargs['bookmark_moved'] = '1' |
22665
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
71 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
72 def write(self): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
73 '''Write bookmarks |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
74 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
75 Write the given bookmark => hash dictionary to the .hg/bookmarks file |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
76 in a format equal to those of localtags. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
77 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
78 We also store a backup of the previous state in undo.bookmarks that |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
79 can be copied back on rollback. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
80 ''' |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
81 repo = self._repo |
23469
65e48b8d20f5
bookmarks: factor out repository lookup from writing bookmarks file
Ryan McElroy <rmcelroy@fb.com>
parents:
23458
diff
changeset
|
82 self._writerepo(repo) |
65e48b8d20f5
bookmarks: factor out repository lookup from writing bookmarks file
Ryan McElroy <rmcelroy@fb.com>
parents:
23458
diff
changeset
|
83 |
65e48b8d20f5
bookmarks: factor out repository lookup from writing bookmarks file
Ryan McElroy <rmcelroy@fb.com>
parents:
23458
diff
changeset
|
84 def _writerepo(self, repo): |
65e48b8d20f5
bookmarks: factor out repository lookup from writing bookmarks file
Ryan McElroy <rmcelroy@fb.com>
parents:
23458
diff
changeset
|
85 """Factored out for extensibility""" |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
86 if repo._bookmarkcurrent not in self: |
20098
2880b45636ca
bmstore.write: use unsetcurrent instead of setcurrent with None
Siddharth Agarwal <sid0@fb.com>
parents:
20027
diff
changeset
|
87 unsetcurrent(repo) |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
88 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
89 wlock = repo.wlock() |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
90 try: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
91 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
92 file = repo.vfs('bookmarks', 'w', atomictemp=True) |
22664
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
93 self._write(file) |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
94 file.close() |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
95 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
96 # touch 00changelog.i so hgweb reloads bookmarks (no lock needed) |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
97 try: |
19896
af03279c766a
bookmarks: use "vfs.utime()" instead of "os.utime()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19895
diff
changeset
|
98 repo.svfs.utime('00changelog.i', None) |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
99 except OSError: |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
100 pass |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
101 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
102 finally: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
103 wlock.release() |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
104 |
22664
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
105 def _write(self, fp): |
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
106 for name, node in self.iteritems(): |
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
107 fp.write("%s %s\n" % (hex(node), encoding.fromlocal(name))) |
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
108 |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
109 def readcurrent(repo): |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
110 '''Get the current bookmark |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
111 |
18043
20459152c7ac
bookmarks: spelling correction in docstring
Kevin Bullock <kbullock@ringworld.org>
parents:
18008
diff
changeset
|
112 If we use gittish branches we have a current bookmark that |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
113 we are on. This function returns the name of the bookmark. It |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
114 is stored in .hg/bookmarks.current |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
115 ''' |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
116 mark = None |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
117 try: |
23877
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
23469
diff
changeset
|
118 file = repo.vfs('bookmarks.current') |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
119 except IOError, inst: |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
120 if inst.errno != errno.ENOENT: |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
121 raise |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
122 return None |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
123 try: |
17425
e95ec38f86b0
fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents:
16719
diff
changeset
|
124 # No readline() in osutil.posixfile, reading everything is cheap |
13381
d073468e3c5f
bookmarks: read current bookmark as utf-8 and convert it to local
David Soria Parra <dsp@php.net>
parents:
13354
diff
changeset
|
125 mark = encoding.tolocal((file.readlines() or [''])[0]) |
13627
71a96f6c205d
bookmarks: discard current bookmark if absent from the bookmarks (issue2692)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13478
diff
changeset
|
126 if mark == '' or mark not in repo._bookmarks: |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
127 mark = None |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
128 finally: |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
129 file.close() |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
130 return mark |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
131 |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
132 def setcurrent(repo, mark): |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
133 '''Set the name of the bookmark that we are currently on |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
134 |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
135 Set the name of the bookmark that we are on (hg update <bookmark>). |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
136 The name is recorded in .hg/bookmarks.current |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
137 ''' |
20100
0f01d0692bc5
bookmarks: make setcurrent with None an error
Siddharth Agarwal <sid0@fb.com>
parents:
20098
diff
changeset
|
138 if mark not in repo._bookmarks: |
0f01d0692bc5
bookmarks: make setcurrent with None an error
Siddharth Agarwal <sid0@fb.com>
parents:
20098
diff
changeset
|
139 raise AssertionError('bookmark %s does not exist!' % mark) |
0f01d0692bc5
bookmarks: make setcurrent with None an error
Siddharth Agarwal <sid0@fb.com>
parents:
20098
diff
changeset
|
140 |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
141 current = repo._bookmarkcurrent |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
142 if current == mark: |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
143 return |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
144 |
15908
60cb4f381a78
bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents:
15887
diff
changeset
|
145 wlock = repo.wlock() |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
146 try: |
23877
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
23469
diff
changeset
|
147 file = repo.vfs('bookmarks.current', 'w', atomictemp=True) |
14559
e29821ca94cf
bookmarks: recognize the current bookmark when the local encoding isn't UTF-8
LUO Zheng <xmuluo@gmail.com>
parents:
14268
diff
changeset
|
148 file.write(encoding.fromlocal(mark)) |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14946
diff
changeset
|
149 file.close() |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
150 finally: |
15908
60cb4f381a78
bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents:
15887
diff
changeset
|
151 wlock.release() |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
152 repo._bookmarkcurrent = mark |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
153 |
16191
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
154 def unsetcurrent(repo): |
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
155 wlock = repo.wlock() |
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
156 try: |
16194
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
157 try: |
19895
37c0d93fb166
bookmarks: use "vfs.unlink()" instead of "util.unlink()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19523
diff
changeset
|
158 repo.vfs.unlink('bookmarks.current') |
16194
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
159 repo._bookmarkcurrent = None |
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
160 except OSError, inst: |
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
161 if inst.errno != errno.ENOENT: |
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
162 raise |
16191
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
163 finally: |
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
164 wlock.release() |
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
165 |
18471
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
166 def iscurrent(repo, mark=None, parents=None): |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
167 '''Tell whether the current bookmark is also active |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
168 |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
169 I.e., the bookmark listed in .hg/bookmarks.current also points to a |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
170 parent of the working directory. |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
171 ''' |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
172 if not mark: |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
173 mark = repo._bookmarkcurrent |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
174 if not parents: |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
175 parents = [p.node() for p in repo[None].parents()] |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
176 marks = repo._bookmarks |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
177 return (mark in marks and marks[mark] in parents) |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
178 |
13663
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
179 def updatecurrentbookmark(repo, oldnode, curbranch): |
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
180 try: |
16719
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16706
diff
changeset
|
181 return update(repo, oldnode, repo.branchtip(curbranch)) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16706
diff
changeset
|
182 except error.RepoLookupError: |
13663
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
183 if curbranch == "default": # no default branch! |
15621
013688350c7d
bookmarks: update and updatecurrentbookmark return status
Kevin Bullock <kbullock@ringworld.org>
parents:
15614
diff
changeset
|
184 return update(repo, oldnode, repo.lookup("tip")) |
13663
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
185 else: |
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
186 raise util.Abort(_("branch %s not found") % curbranch) |
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
187 |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
188 def deletedivergent(repo, deletefrom, bm): |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
189 '''Delete divergent versions of bm on nodes in deletefrom. |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
190 |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
191 Return True if at least one bookmark was deleted, False otherwise.''' |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
192 deleted = False |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
193 marks = repo._bookmarks |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
194 divergent = [b for b in marks if b.split('@', 1)[0] == bm.split('@', 1)[0]] |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
195 for mark in divergent: |
21843
92666a869ea4
bookmarks: avoid deleting primary bookmarks on rebase
Matt Mackall <mpm@selenic.com>
parents:
20352
diff
changeset
|
196 if mark == '@' or '@' not in mark: |
92666a869ea4
bookmarks: avoid deleting primary bookmarks on rebase
Matt Mackall <mpm@selenic.com>
parents:
20352
diff
changeset
|
197 # can't be divergent by definition |
92666a869ea4
bookmarks: avoid deleting primary bookmarks on rebase
Matt Mackall <mpm@selenic.com>
parents:
20352
diff
changeset
|
198 continue |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
199 if mark and marks[mark] in deletefrom: |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
200 if mark != bm: |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
201 del marks[mark] |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
202 deleted = True |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
203 return deleted |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
204 |
19523
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
205 def calculateupdate(ui, repo, checkout): |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
206 '''Return a tuple (targetrev, movemarkfrom) indicating the rev to |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
207 check out and where to move the active bookmark from, if needed.''' |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
208 movemarkfrom = None |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
209 if checkout is None: |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
210 curmark = repo._bookmarkcurrent |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
211 if iscurrent(repo): |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
212 movemarkfrom = repo['.'].node() |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
213 elif curmark: |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
214 ui.status(_("updating to active bookmark %s\n") % curmark) |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
215 checkout = curmark |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
216 return (checkout, movemarkfrom) |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
217 |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
218 def update(repo, parents, node): |
19110
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
219 deletefrom = parents |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
220 marks = repo._bookmarks |
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
221 update = False |
16706
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
222 cur = repo._bookmarkcurrent |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
223 if not cur: |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
224 return False |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
225 |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
226 if marks[cur] in parents: |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
227 new = repo[node] |
19110
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
228 divs = [repo[b] for b in marks |
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
229 if b.split('@', 1)[0] == cur.split('@', 1)[0]] |
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
230 anc = repo.changelog.ancestors([new.rev()]) |
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
231 deletefrom = [b.node() for b in divs if b.rev() in anc or b == new] |
20281
67ee87a371b2
update: consider successor changesets when moving active bookmark
Sean Farley <sean.michael.farley@gmail.com>
parents:
20100
diff
changeset
|
232 if validdest(repo, repo[marks[cur]], new): |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
233 marks[cur] = new.node() |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
234 update = True |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
235 |
19110
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
236 if deletedivergent(repo, deletefrom, cur): |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
237 update = True |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
238 |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
239 if update: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
240 marks.write() |
15621
013688350c7d
bookmarks: update and updatecurrentbookmark return status
Kevin Bullock <kbullock@ringworld.org>
parents:
15614
diff
changeset
|
241 return update |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
242 |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
243 def listbookmarks(repo): |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
244 # We may try to list bookmarks on a repo type that does not |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
245 # support it (e.g., statichttprepository). |
14946
28762bf809d8
bookmarks: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14848
diff
changeset
|
246 marks = getattr(repo, '_bookmarks', {}) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
247 |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
248 d = {} |
18496
d1c13a4dc638
bookmarks: hide bookmarks on filtered revs from listkeys
Kevin Bullock <kbullock@ringworld.org>
parents:
18471
diff
changeset
|
249 hasnode = repo.changelog.hasnode |
14946
28762bf809d8
bookmarks: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14848
diff
changeset
|
250 for k, v in marks.iteritems(): |
15613
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
251 # don't expose local divergent bookmarks |
18496
d1c13a4dc638
bookmarks: hide bookmarks on filtered revs from listkeys
Kevin Bullock <kbullock@ringworld.org>
parents:
18471
diff
changeset
|
252 if hasnode(v) and ('@' not in k or k.endswith('@')): |
15613
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
253 d[k] = hex(v) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
254 return d |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
255 |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
256 def pushbookmark(repo, key, old, new): |
22667
3acc3f95548c
push: update bookmarks (on server) within a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22666
diff
changeset
|
257 w = l = tr = None |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
258 try: |
22667
3acc3f95548c
push: update bookmarks (on server) within a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22666
diff
changeset
|
259 w = repo.wlock() |
3acc3f95548c
push: update bookmarks (on server) within a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22666
diff
changeset
|
260 l = repo.lock() |
3acc3f95548c
push: update bookmarks (on server) within a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22666
diff
changeset
|
261 tr = repo.transaction('bookmarks') |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
262 marks = repo._bookmarks |
22364
5c153c69fdb2
bookmarks: allow pushkey if new equals current
Durham Goode <durham@fb.com>
parents:
21843
diff
changeset
|
263 existing = hex(marks.get(key, '')) |
5c153c69fdb2
bookmarks: allow pushkey if new equals current
Durham Goode <durham@fb.com>
parents:
21843
diff
changeset
|
264 if existing != old and existing != new: |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
265 return False |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
266 if new == '': |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
267 del marks[key] |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
268 else: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
269 if new not in repo: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
270 return False |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
271 marks[key] = repo[new].node() |
22667
3acc3f95548c
push: update bookmarks (on server) within a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22666
diff
changeset
|
272 marks.recordchange(tr) |
3acc3f95548c
push: update bookmarks (on server) within a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22666
diff
changeset
|
273 tr.close() |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
274 return True |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
275 finally: |
22667
3acc3f95548c
push: update bookmarks (on server) within a transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22666
diff
changeset
|
276 lockmod.release(tr, l, w) |
13354
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
277 |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
278 def compare(repo, srcmarks, dstmarks, |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
279 srchex=None, dsthex=None, targets=None): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
280 '''Compare bookmarks between srcmarks and dstmarks |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
281 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
282 This returns tuple "(addsrc, adddst, advsrc, advdst, diverge, |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
283 differ, invalid)", each are list of bookmarks below: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
284 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
285 :addsrc: added on src side (removed on dst side, perhaps) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
286 :adddst: added on dst side (removed on src side, perhaps) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
287 :advsrc: advanced on src side |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
288 :advdst: advanced on dst side |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
289 :diverge: diverge |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
290 :differ: changed, but changeset referred on src is unknown on dst |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
291 :invalid: unknown on both side |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
292 :same: same on both side |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
293 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
294 Each elements of lists in result tuple is tuple "(bookmark name, |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
295 changeset ID on source side, changeset ID on destination |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
296 side)". Each changeset IDs are 40 hexadecimal digit string or |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
297 None. |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
298 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
299 Changeset IDs of tuples in "addsrc", "adddst", "differ" or |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
300 "invalid" list may be unknown for repo. |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
301 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
302 This function expects that "srcmarks" and "dstmarks" return |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
303 changeset ID in 40 hexadecimal digit string for specified |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
304 bookmark. If not so (e.g. bmstore "repo._bookmarks" returning |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
305 binary value), "srchex" or "dsthex" should be specified to convert |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
306 into such form. |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
307 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
308 If "targets" is specified, only bookmarks listed in it are |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
309 examined. |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
310 ''' |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
311 if not srchex: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
312 srchex = lambda x: x |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
313 if not dsthex: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
314 dsthex = lambda x: x |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
315 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
316 if targets: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
317 bset = set(targets) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
318 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
319 srcmarkset = set(srcmarks) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
320 dstmarkset = set(dstmarks) |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
321 bset = srcmarkset | dstmarkset |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
322 |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
323 results = ([], [], [], [], [], [], [], []) |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
324 addsrc = results[0].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
325 adddst = results[1].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
326 advsrc = results[2].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
327 advdst = results[3].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
328 diverge = results[4].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
329 differ = results[5].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
330 invalid = results[6].append |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
331 same = results[7].append |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
332 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
333 for b in sorted(bset): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
334 if b not in srcmarks: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
335 if b in dstmarks: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
336 adddst((b, None, dsthex(dstmarks[b]))) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
337 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
338 invalid((b, None, None)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
339 elif b not in dstmarks: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
340 addsrc((b, srchex(srcmarks[b]), None)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
341 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
342 scid = srchex(srcmarks[b]) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
343 dcid = dsthex(dstmarks[b]) |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
344 if scid == dcid: |
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
345 same((b, scid, dcid)) |
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
346 elif scid in repo and dcid in repo: |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
347 sctx = repo[scid] |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
348 dctx = repo[dcid] |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
349 if sctx.rev() < dctx.rev(): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
350 if validdest(repo, sctx, dctx): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
351 advdst((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
352 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
353 diverge((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
354 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
355 if validdest(repo, dctx, sctx): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
356 advsrc((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
357 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
358 diverge((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
359 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
360 # it is too expensive to examine in detail, in this case |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
361 differ((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
362 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
363 return results |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
364 |
24355
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
365 def _diverge(ui, b, path, localmarks, remotenode): |
24353
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
366 '''Return appropriate diverged bookmark for specified ``path`` |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
367 |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
368 This returns None, if it is failed to assign any divergent |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
369 bookmark name. |
24355
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
370 |
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
371 This reuses already existing one with "@number" suffix, if it |
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
372 refers ``remotenode``. |
24353
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
373 ''' |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
374 if b == '@': |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
375 b = '' |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
376 # try to use an @pathalias suffix |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
377 # if an @pathalias already exists, we overwrite (update) it |
22629
b3f74b405c20
bookmarks: fix divergent bookmark path normalization
Matt Mackall <mpm@selenic.com>
parents:
22627
diff
changeset
|
378 if path.startswith("file:"): |
b3f74b405c20
bookmarks: fix divergent bookmark path normalization
Matt Mackall <mpm@selenic.com>
parents:
22627
diff
changeset
|
379 path = util.url(path).path |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
380 for p, u in ui.configitems("paths"): |
22629
b3f74b405c20
bookmarks: fix divergent bookmark path normalization
Matt Mackall <mpm@selenic.com>
parents:
22627
diff
changeset
|
381 if u.startswith("file:"): |
b3f74b405c20
bookmarks: fix divergent bookmark path normalization
Matt Mackall <mpm@selenic.com>
parents:
22627
diff
changeset
|
382 u = util.url(u).path |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
383 if path == u: |
24354
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
384 return '%s@%s' % (b, p) |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
385 |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
386 # assign a unique "@number" suffix newly |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
387 for x in range(1, 100): |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
388 n = '%s@%d' % (b, x) |
24355
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
389 if n not in localmarks or localmarks[n] == remotenode: |
24354
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
390 return n |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
391 |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
392 return None |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
393 |
22666
0f8120c1ecf5
pull: perform bookmark updates in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22665
diff
changeset
|
394 def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()): |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
395 ui.debug("checking for updated bookmarks\n") |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
396 localmarks = repo._bookmarks |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
397 (addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
398 ) = compare(repo, remotemarks, localmarks, dsthex=hex) |
15614
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
399 |
22644
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
400 status = ui.status |
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
401 warn = ui.warn |
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
402 if ui.configbool('ui', 'quietbookmarkmove', False): |
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
403 status = warn = ui.debug |
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
404 |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
405 explicit = set(explicit) |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
406 changed = [] |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
407 for b, scid, dcid in addsrc: |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
408 if scid in repo: # add remote bookmarks for changes we already have |
22644
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
409 changed.append((b, bin(scid), status, |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
410 _("adding remote bookmark %s\n") % (b))) |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
411 for b, scid, dcid in advsrc: |
22644
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
412 changed.append((b, bin(scid), status, |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
413 _("updating bookmark %s\n") % (b))) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
414 # remove normal movement from explicit set |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
415 explicit.difference_update(d[0] for d in changed) |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
416 |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
417 for b, scid, dcid in diverge: |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
418 if b in explicit: |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
419 explicit.discard(b) |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
420 changed.append((b, bin(scid), status, |
23199
c35ffa4249ca
bookmarks: fix formatting of exchange message (issue4439)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23081
diff
changeset
|
421 _("importing bookmark %s\n") % (b))) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
422 else: |
24355
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
423 snode = bin(scid) |
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
424 db = _diverge(ui, b, path, localmarks, snode) |
24353
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
425 if db: |
24355
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
426 changed.append((db, snode, warn, |
24353
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
427 _("divergent bookmark %s stored as %s\n") % |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
428 (b, db))) |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
429 else: |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
430 warn(_("warning: failed to assign numbered name " |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
431 "to divergent bookmark %s\n") % (b)) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
432 for b, scid, dcid in adddst + advdst: |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
433 if b in explicit: |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
434 explicit.discard(b) |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
435 changed.append((b, bin(scid), status, |
23199
c35ffa4249ca
bookmarks: fix formatting of exchange message (issue4439)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23081
diff
changeset
|
436 _("importing bookmark %s\n") % (b))) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
437 |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
438 if changed: |
22666
0f8120c1ecf5
pull: perform bookmark updates in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22665
diff
changeset
|
439 tr = trfunc() |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
440 for b, node, writer, msg in sorted(changed): |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
441 localmarks[b] = node |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
442 writer(msg) |
22666
0f8120c1ecf5
pull: perform bookmark updates in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22665
diff
changeset
|
443 localmarks.recordchange(tr) |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
444 |
24397
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
445 def incoming(ui, repo, other): |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
446 '''Show bookmarks incoming from other to repo |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
447 ''' |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
448 ui.status(_("searching for changed bookmarks\n")) |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
449 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
450 r = compare(repo, other.listkeys('bookmarks'), repo._bookmarks, |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
451 dsthex=hex) |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
452 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
453 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
454 incomings = [] |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
455 if ui.debugflag: |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
456 getid = lambda id: id |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
457 else: |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
458 getid = lambda id: id[:12] |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
459 if ui.verbose: |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
460 def add(b, id, st): |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
461 incomings.append(" %-25s %s %s\n" % (b, getid(id), st)) |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
462 else: |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
463 def add(b, id, st): |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
464 incomings.append(" %-25s %s\n" % (b, getid(id))) |
24397
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
465 for b, scid, dcid in addsrc: |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
466 add(b, scid, _('added')) |
24657
3d7c512b258d
bookmarks: show incoming bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24400
diff
changeset
|
467 for b, scid, dcid in advsrc: |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
468 add(b, scid, _('advanced')) |
24657
3d7c512b258d
bookmarks: show incoming bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24400
diff
changeset
|
469 for b, scid, dcid in diverge: |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
470 add(b, scid, _('diverged')) |
24657
3d7c512b258d
bookmarks: show incoming bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24400
diff
changeset
|
471 for b, scid, dcid in differ: |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
472 add(b, scid, _('changed')) |
24397
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
473 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
474 if not incomings: |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
475 ui.status(_("no changed bookmarks found\n")) |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
476 return 1 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
477 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
478 for s in sorted(incomings): |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
479 ui.write(s) |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
480 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
481 return 0 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
482 |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
483 def outgoing(ui, repo, other): |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
484 '''Show bookmarks outgoing from repo to other |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
485 ''' |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
486 ui.status(_("searching for changed bookmarks\n")) |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
487 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
488 r = compare(repo, repo._bookmarks, other.listkeys('bookmarks'), |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
489 srchex=hex) |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
490 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
491 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
492 outgoings = [] |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
493 if ui.debugflag: |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
494 getid = lambda id: id |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
495 else: |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
496 getid = lambda id: id[:12] |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
497 if ui.verbose: |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
498 def add(b, id, st): |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
499 outgoings.append(" %-25s %s %s\n" % (b, getid(id), st)) |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
500 else: |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
501 def add(b, id, st): |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
502 outgoings.append(" %-25s %s\n" % (b, getid(id))) |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
503 for b, scid, dcid in addsrc: |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
504 add(b, scid, _('added')) |
24658
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24657
diff
changeset
|
505 for b, scid, dcid in adddst: |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
506 add(b, ' ' * 40, _('deleted')) |
24658
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24657
diff
changeset
|
507 for b, scid, dcid in advsrc: |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
508 add(b, scid, _('advanced')) |
24658
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24657
diff
changeset
|
509 for b, scid, dcid in diverge: |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
510 add(b, scid, _('diverged')) |
24658
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24657
diff
changeset
|
511 for b, scid, dcid in differ: |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
512 add(b, scid, _('changed')) |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
513 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
514 if not outgoings: |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
515 ui.status(_("no changed bookmarks found\n")) |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
516 return 1 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
517 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
518 for s in sorted(outgoings): |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
519 ui.write(s) |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
520 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
521 return 0 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
522 |
24400
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
523 def summary(repo, other): |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
524 '''Compare bookmarks between repo and other for "hg summary" output |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
525 |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
526 This returns "(# of incoming, # of outgoing)" tuple. |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
527 ''' |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
528 r = compare(repo, other.listkeys('bookmarks'), repo._bookmarks, |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
529 dsthex=hex) |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
530 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
531 return (len(addsrc), len(adddst)) |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
532 |
17550
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17425
diff
changeset
|
533 def validdest(repo, old, new): |
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17425
diff
changeset
|
534 """Is the new bookmark destination a valid update from the old one""" |
18008
cf91b36f368c
clfilter: `bookmark.validdest` should run on unfiltered repo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17922
diff
changeset
|
535 repo = repo.unfiltered() |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
536 if old == new: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
537 # Old == new -> nothing to update. |
17625
b83c18204c36
bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17551
diff
changeset
|
538 return False |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
539 elif not old: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
540 # old is nullrev, anything is valid. |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
541 # (new != nullrev has been excluded by the previous check) |
17625
b83c18204c36
bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17551
diff
changeset
|
542 return True |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
543 elif repo.obsstore: |
18984
efef056b1ae9
obsolete: extract foreground computation from bookmark.validdest
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18851
diff
changeset
|
544 return new.node() in obsolete.foreground(repo, [old.node()]) |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
545 else: |
24180
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23877
diff
changeset
|
546 # still an independent clause as it is lazier (and therefore faster) |
17627
84f12b832ee8
bookmarks: use "changectx.descendant()" for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17625
diff
changeset
|
547 return old.descendant(new) |