Commit Graph

60 Commits

Author SHA1 Message Date
Augie Fackler
9766845689 bookmarks: introduce a bmstore to manage bookmark persistence
Bookmarks persistence still showed a fair amount of its legacy as a
monkeypatching extension. This encapsulates all bookmarks
serialization and parsing in a single class, and offers a single
location where other bookmarks storage engines can be substituted
in. As a result, many files no longer import the bookmarks module,
which strikes me as an encapsulation win.

This doesn't do anything to the current bookmark state yet, but I'm
hoping put that in the bmstore class as well.
2012-11-07 16:21:39 -06:00
Pierre-Yves David
9a87309c77 bookmark: remove useless line in validdest
This case is already covered by the `if old == new:` conditional at the start of
the function.
2012-10-24 18:11:17 +02:00
Pierre-Yves David
e4be0103aa bookmark: issue a single call to allsuccessors per loop
Update to this code was minimalist when `allsuccessors` argument were changed
from a list to a set. As this code is getting my attention again I realised we
can drastically simplify this part of the code by issue a single call to
`allsuccessors`.
2012-10-24 17:55:21 +02:00
Pierre-Yves David
d33a990ff6 bookmark: simplify mutability check in validdest
There is no need to check phase by hand. We already have a ctx method for that.
2012-10-24 17:26:40 +02:00
Thomas Arendsen Hein
6a57af18d2 bookmark: simplify nodemap check introduced in the previous changeset 2012-10-26 09:29:50 +02:00
Pierre-Yves David
b13f928861 bookmark: prevent crashing when a successor is unknown locally (issue3680)
The `%ln` revset substitution does not accept unknown node. We prune unknown
node from potential successors before computing descendants.

This have no impact on the result of this function.

- Descendants of unknown changeset as unknown,
- all successors of unknown changesets are already return by the call who
  returned those same unknown changesets,
- unknown changesets are never a valid destination for a bookmark.
2012-10-25 23:43:52 +02:00
Pierre-Yves David
19b261d640 obsolete: have allsuccessors takes a list of nodes
Additional logic, used to detect mutable history troubles, will need to quickly
compute successors of a whole set of changeset.
2012-10-16 15:49:58 +02:00
Pierre-Yves David
1d9b00f6af obsolete: rename anysuccessors into allsuccessors
The "any" prefix looks like it returned a boolean. `allsuccessors` is more
accurate.
2012-10-19 00:30:11 +02:00
Kevin Bullock
f8141466d2 bookmarks: use scmutil.checknewlabel
Validation is pulled up into the commands module to avoid an import
cycle.
2012-10-17 17:23:39 -05:00
Kevin Bullock
4f9b1ecf92 bookmarks: disallow bookmarks named 'tip', '.', or 'null'
This makes bookmarks reject the same reserved names as tags and branches.
2012-10-17 16:32:43 -05:00
Kevin Bullock
a73acf6db3 bookmarks: abort directly on invalid name
This consolidates the abort message for a bookmark name containing
invalid characters into one place, and renames the valid() method to
checkvalid() to reflect the fact that it's no longer a predicate.
2012-10-17 17:03:01 -05:00
David M. Carr
c447f272ec bookmarks: when @ bookmark diverges, don't double the @ sign (BC)
This changeset treats the bookmark "@" as a special case for the naming of
divergent bookmarks, as per the tables below.  For the <no alias> case, the
actual suffix will vary, depending on what suffixes are already in use.

Before:
Bookmark | Remote     | Divergent Bookmark
--------------------------------------
foo      | bar        | foo@bar
foo      | <no alias> | foo@1
@        | bar        | @@bar
@        | <no alias> | @@1

After:
Bookmark | Remote     | Divergent Bookmark
--------------------------------------
foo      | bar        | foo@bar
foo      | <no alias> | foo@1
@        | bar        | @bar
@        | <no alias> | @1

This case is likely to be more common now that c1644655c164 has made the "@"
bookmark have special meaning to clone.

The change in behavior was discussed on the mailing list in the thread below:
http://markmail.org/thread/rwedgxp7le5j2h2f
2012-10-15 23:54:54 -04:00
Mads Kiilerich
588e53b65c spelling: fix minor spell checker issues 2012-10-10 01:29:56 +02:00
FUJIWARA Katsunori
3bef78e26e bookmarks: rename arguments/variables for source code readability
Before this patch, the argument bound to the source repository of
incoming bookmarks for "bookmarks.diff()" is named as "remote".

But in "hg outgoing" case, this argument is bound to local repository
object.

In addition to it, "local"/"remote" seem to mean not the direction of
propagation of bookmarks, but just the location of cooperative
repositories.

To indicate the direction of propagation of bookmarks clearly on the
source code, this patch uses "d(st)" and "s(rc)" combination instead
of "l(ocal)" and "r(emote)" one.

  - "repo" and "remote" arguments are renamed to "dst" and "src"
  - "lmarks" and "rmarks" variables are renamed to "dmarsk" and "smarks"
2012-09-22 14:53:50 +09:00
FUJIWARA Katsunori
414d11165a bookmarks: use "changectx.descendant()" for efficient descendant examination
This patch uses "old.descendant(new)" expression instead of
"new in old.descendants()" for efficiency.
2012-09-18 21:39:12 +09:00
FUJIWARA Katsunori
9701df1178 bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()" 2012-09-18 21:39:12 +09:00
Pierre-Yves David
6431172ad3 bookmark: take successors into account when updating (issue3561)
When we rewrite a bookmarked changeset, we want to update the
bookmark on its successors. But the successors are not descendants
of its precursor (by definition). This changeset alters the bookmarks
logic to update bookmark location if the newer location is a successor
of the old one[1].

note: valid destinations are in fact any kind of successors of any kind
      of descendants (recursively.)

This changeset requires the enabling of the obsolete feature in
some bookmark tests.
2012-08-26 01:28:22 +02:00
Pierre-Yves David
342b88a402 bookmarks: extract valid destination logic in a dedicated function
We usually update bookmarks only if the new location is descendant of the old
bookmarks location.  We extract this logic into a function. This is the first
step to allow more complex logic using obsolescence in this validation of the
bookmark movement.
2012-08-26 00:28:56 +02:00
Mads Kiilerich
2372d51b68 fix wording and not-completely-trivial spelling errors and bad docstrings 2012-08-15 22:39:18 +02:00
Brodie Rao
d36ae7f264 localrepo: add branchtip() method for faster single-branch lookups
For the PyPy repo with 744 branches and 843 branch heads, this brings
hg log -r default over NFS from:

   CallCount    Recursive    Total(ms)   Inline(ms) module:lineno(function)
        3249            0      1.3222      1.3222   <open>
        3244            0      0.6211      0.6211   <method 'close' of 'file' objects>
        3243            0      0.0800      0.0800   <method 'read' of 'file' objects>
        3241            0      0.0660      0.0660   <method 'seek' of 'file' objects>
        3905            0      0.0476      0.0476   <zlib.decompress>
        3281            0      2.6756      0.0472   mercurial.changelog:182(read)
       +3281            0      2.5256      0.0453   +mercurial.revlog:881(revision)
       +3276            0      0.0389      0.0196   +mercurial.changelog:28(decodeextra)
       +6562            0      0.0123      0.0123   +<method 'split' of 'str' objects>
       +6562            0      0.0408      0.0073   +mercurial.encoding:61(tolocal)
       +3281            0      0.0054      0.0054   +<method 'index' of 'str' objects>
        3241            0      2.2464      0.0456   mercurial.revlog:818(_loadchunk)
       +3241            0      0.6205      0.6205   +<method 'close' of 'file' objects>
       +3241            0      0.0765      0.0765   +<method 'read' of 'file' objects>
       +3241            0      0.0660      0.0660   +<method 'seek' of 'file' objects>
       +3241            0      1.4209      0.0135   +mercurial.store:374(__call__)
       +3241            0      0.0122      0.0107   +mercurial.revlog:810(_addchunk)
        3281            0      2.5256      0.0453   mercurial.revlog:881(revision)
       +3280            0      0.0175      0.0175   +mercurial.revlog:305(rev)
       +3281            0      2.2819      0.0119   +mercurial.revlog:847(_chunkraw)
       +3281            0      0.0603      0.0083   +mercurial.revlog:945(_checkhash)
       +3281            0      0.0051      0.0051   +mercurial.revlog:349(flags)
       +3281            0      0.0040      0.0040   +<mercurial.mpatch.patches>
       13682            0      0.0479      0.0248   <method 'decode' of 'str' objects>
       +7418            0      0.0228      0.0076   +encodings.utf_8:15(decode)
          +1            0      0.0003      0.0000   +encodings:71(search_function)
        3248            0      1.3995      0.0246   mercurial.scmutil:218(__call__)
       +3248            0      1.3222      1.3222   +<open>
       +3248            0      0.0235      0.0184   +os.path:80(split)
       +3248            0      0.0084      0.0068   +mercurial.scmutil:92(__call__)
Time: real 2.750 secs (user 0.680+0.000 sys 0.360+0.000)

down to:

   CallCount    Recursive    Total(ms)   Inline(ms) module:lineno(function)
          55           31      0.0197      0.0163   <__import__>
          +1            0      0.0006      0.0002   +mercurial.context:8(<module>)
          +1            0      0.0042      0.0001   +mercurial.revlog:12(<module>)
          +1            0      0.0002      0.0001   +mercurial.match:8(<module>)
          +1            0      0.0003      0.0001   +mercurial.dirstate:7(<module>)
          +1            0      0.0057      0.0001   +mercurial.changelog:8(<module>)
           1            0      0.0117      0.0032   mercurial.localrepo:525(_readbranchcache)
        +844            0      0.0015      0.0015   +<binascii.unhexlify>
        +845            0      0.0010      0.0010   +<method 'split' of 'str' objects>
        +843            0      0.0045      0.0009   +mercurial.encoding:61(tolocal)
        +843            0      0.0004      0.0004   +<method 'setdefault' of 'dict' objects>
          +1            0      0.0003      0.0003   +<method 'close' of 'file' objects>
           3            0      0.0029      0.0029   <method 'read' of 'file' objects>
           9            0      0.0018      0.0018   <open>
         990            0      0.0017      0.0017   <binascii.unhexlify>
          53            0      0.0016      0.0016   mercurial.demandimport:43(__init__)
         862            0      0.0015      0.0015   <_codecs.utf_8_decode>
         862            0      0.0037      0.0014   <method 'decode' of 'str' objects>
        +862            0      0.0023      0.0008   +encodings.utf_8:15(decode)
         981            0      0.0011      0.0011   <method 'split' of 'str' objects>
         861            0      0.0046      0.0009   mercurial.encoding:61(tolocal)
        +861            0      0.0037      0.0014   +<method 'decode' of 'str' objects>
         862            0      0.0023      0.0008   encodings.utf_8:15(decode)
        +862            0      0.0015      0.0015   +<_codecs.utf_8_decode>
           4            0      0.0008      0.0008   <method 'close' of 'file' objects>
         179          154      0.0202      0.0004   mercurial.demandimport:83(__getattribute__)
         +36           11      0.0199      0.0003   +mercurial.demandimport:55(_load)
         +72            0      0.0001      0.0001   +mercurial.demandimport:83(__getattribute__)
         +36            0      0.0000      0.0000   +<getattr>
           1            0      0.0015      0.0004   mercurial.tags:148(_readtagcache)
Time: real 0.060 secs (user 0.030+0.000 sys 0.010+0.000)
2012-05-13 14:04:04 +02:00
David Soria Parra
7ffe2b2eb4 bookmarks: delete divergent bookmarks on merge 2012-05-12 21:28:10 +02:00
Levi Bard
ff2ee52b29 bookmarks: pull new bookmarks from remote by default (BC) 2012-05-12 17:00:01 +02:00
Matt Mackall
ed0ae26f56 bookmarks: catch the proper exception for missing revisions
This fixes a regression from 1.7
2012-05-03 16:03:08 -05:00
Kevin Bullock
2e6b4bf150 bookmarks: clone non-divergent bookmarks with @ in them 2012-03-21 16:39:38 -05:00
Gilles Moris
6e3d39e6ce bookmarks: restore python 2.4 compatibility
Remove py25 'try except finally' clause.
2012-02-29 09:34:19 +01:00
Idan Kamara
263be8e6a2 update: delete bookmarks.current when explicitly updating to a rev (issue3276) 2012-02-28 23:47:46 +02:00
David Soria Parra
adfa1608de bookmarks: respect --debug during incoming/outgoing 2012-01-25 20:03:46 +01:00
Matt Mackall
eb2ed976cb bookmarks: backout locking change in 31cb6aaf3b7a
Repo lock only applies to data in .hg/store/
2012-01-18 14:56:52 -06:00
Mads Kiilerich
50c2110b65 bookmarks: primarily use repo lock, not wlock
Bookmarks are repository data, not working directory data. Only the current
bookmark is working directory data.

Some lock shuffling is required to avoid lockout between the initial mock lock
and locking of the localrepo instance that is created after copying.
2012-01-13 02:30:43 +01:00
Kevin Bullock
487ddecbc0 bookmarks: update and updatecurrentbookmark return status
This makes bookmarks.update() and bookmarks.updatecurrentbookmark() return
True or False to indicate whether the bookmark was updated or not. This allows
callers to e.g. abort if the update failed.
2011-11-16 15:29:57 -06:00
Matt Mackall
239b73ab8c bookmarks: mark divergent bookmarks with book@pathalias when source in [paths] 2011-12-07 16:19:39 -06:00
Matt Mackall
395e8d3f93 bookmarks: shadow divergent bookmarks of foo with foo@n 2011-12-06 14:17:33 -06:00
Augie Fackler
6d4a8aa3a9 bookmarks: delegate writing to the repo just like reading
This makes it easier for alternate storage backends to not use flat
files for bookmarks storage.
2011-10-12 11:09:57 -05:00
Greg Ward
bc1dfb1ac9 atomictempfile: make close() consistent with other file-like objects.
The usual contract is that close() makes your writes permanent, so
atomictempfile's use of close() to *discard* writes (and rename() to
keep them) is rather unexpected. Thus, change it so close() makes
things permanent and add a new discard() method to throw them away.
discard() is only used internally, in __del__(), to ensure that writes
are discarded when an atomictempfile object goes out of scope.

I audited mercurial.*, hgext.*, and ~80 third-party extensions, and
found no one using the existing semantics of close() to discard
writes, so this should be safe.
2011-08-25 20:21:04 -04:00
Augie Fackler
139280a0ab bookmarks: use getattr instead of hasattr 2011-07-25 15:07:09 -05:00
Matt Mackall
a4528a6eaf bookmarks: simplify warning code 2011-07-06 19:25:56 -05:00
Matt Mackall
1278299c3f bookmarks: drop superfluous strip 2011-07-06 19:25:56 -05:00
Pierre-Yves David
31fc6f84be bookmarks: add a warning for non empty malformed line 2011-07-05 10:20:27 +02:00
Pierre-Yves David
5984ee96d7 bookmarks: more robust parsing of bookmarks file 2011-07-05 10:13:54 +02:00
LUO Zheng
04c821e46b bookmarks: recognize the current bookmark when the local encoding isn't UTF-8
The current bookmark is stored in bookmark.current, supposingly in UTF-8.
But the call to encoding.fromlocal() is missing, therefore Hg is not able
to recognize the current bookmark in the case that bookmark uses
characters of which the bit stream is different between local encoding
and UTF-8.
For example, the Chinese version of Windows cmd uses gbk(cp936), not UTF-8.
Therefore I won't be able to make a Chinese bookmark current.

By wrapping mark in a encoding.fromlocal() call, the problem is solved.
2011-06-08 21:25:18 +08:00
Matt Mackall
511ac574fb merge with stable 2011-05-08 16:16:41 -05:00
Alexander Solovyov
6240007914 fix bookmarks rollback behavior
Before this patch undo.bookmarks was created on bookmarks write and
not with other transaction-related files. There were two issues: first
is that if you have changed bookmarks few times after a transaction
happened, rollback will give you a state which can point to
non-existing revision. Second is that if you have not changed
bookmarks after a transaction, rollback will touch your state anyway.

This change also adds `localrepo._writejournal` method, which can be
used by other extensions to save their transaction-related backup in
right time.
2011-05-01 13:07:00 +02:00
Benoit Boissinot
4e06bc9a34 bookmarks: discard current bookmark if absent from the bookmarks (issue2692)
After a rollback, the current bookmark might be absent from the bookmarks
file. In that case we discard it instead of displaying a traceback during
commit.
2011-03-13 14:36:47 +01:00
David Soria Parra
36125c089f bookmarks: restrict moving a bookmark to its descendants (issue1502)
A bookmark can only move to a descendant on commit, pull or
unbundle. Bookmarks cannot jump between heads anymore. This fixese
issue 1502.

We explicitly use new.node(), to emphasise that we are updating the
current bookmark to the new node.
2011-02-24 14:38:50 +01:00
David Soria Parra
90a5744f74 bookmarks: forbid \0 \r \n : in bookmark names (BC)
We restrict : to 1. make it easer to convert bookmarks to git branches,
2. use : later for a syntax to push a local bookmark to a remote bookmark
of a different name. \0, \n, \r are fobbidden they are used to separate
bookmarks in the bookmark file.

This change breaks backward compatbility as ':' was an allowed character in
previous versions.
2011-02-16 18:36:45 +01:00
David Soria Parra
12aa64e430 bookmarks: make track.current=True default behaviour and remove option (BC) 2011-02-16 01:29:26 +01:00
David Soria Parra
c2b26a0902 bookmarks: read current bookmark as utf-8 and convert it to local 2011-02-11 19:32:49 +01:00
Matt Mackall
1b243d934f bookmarks: move diff to core 2011-02-10 13:46:27 -06:00
Matt Mackall
3d6c8e8713 bookmarks: move pushkey functions into core 2011-02-10 13:46:27 -06:00
Matt Mackall
2580f39614 bookmarks: move update into core 2011-02-10 13:46:27 -06:00