Commit Graph

147 Commits

Author SHA1 Message Date
liscju
d19dfc8664 bookmarks: abort 'push -B .' when no active bookmark 2016-06-13 23:50:26 +02:00
FUJIWARA Katsunori
bb78b3c1b0 bookmarks: make writing files out avoid ambiguity of file stat
Cached attribute repo._bookmarks uses stat of '.hg/bookmarks' and
'.hg/bookmarks.current' files to examine validity of cached
contents. If writing these files out keeps ctime, mtime and size of
them, change is overlooked, and old contents cached before change
isn't invalidated as expected.

To avoid ambiguity of file stat, this patch writes '.hg/bookmarks' and
'.hg/bookmarks.current' files out with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-03 00:44:20 +09:00
Augie Fackler
419a5a94fb bookmarks: jettison bmstore's write() method per deprecation policy 2016-05-04 21:01:49 -04:00
Augie Fackler
5a2af0bc22 bookmarks: properly invalidate volatile sets when writing bookmarks
This corrects a regression introduced during the 3.7 cycle, but which
went undetected due to the surviving-but-deprecated write() method on
bmstore.
2016-05-04 22:44:30 -04:00
liscju
533e0cc9bc bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917) 2016-02-19 22:28:09 +01:00
Bryan O'Sullivan
6e36744ca3 with: use context manager for wlock in _writeactive 2016-01-15 13:14:45 -08:00
Bryan O'Sullivan
e93bfbcbd9 with: use context manager for wlock in _writerepo 2016-01-15 13:14:45 -08:00
Augie Fackler
a7381bb9d3 bmstore: add handling of the active bookmark
This further centralizes the handling of bookmark storage, and will
help get some lingering bookmarks business out of localrepo. Right
now, this change implies reading of the active bookmark to also imply
reading all bookmarks from disk - for users with many many bookmarks
this may be a measurable performance hit. In that case, we should
migrate bmstore to be able to lazy-read its properties from disk
rather than having to eagerly read them, but I decided to avoid doing
that to try and avoid some potentially complicated filecache decorator
issues.

This doesn't move the logic for writing the active bookmark into a
transaction, though that is probably the correct next step. Since the
API probably needs to morph a little more, I didn't bother marking
bookmarks.{activate,deactivate} as deprecated yet.
2015-11-11 21:18:02 -05:00
Augie Fackler
c341de89c9 bookmarks: make _readactive safe when readlines raises ENOENT
When reading over static http, the file isn't actually opened until
the readlines() call, so we have to check for ENOENT IOErrors here
too. This is necessary so that we can use the bmstore everywhere for
managing the active bookmark, which will be true in the next change.
2015-12-01 13:08:05 -05:00
Pierre-Yves David
2e682e667f bookmark: deprecate 'bmstore.write' method
This function does not collaborate with the transaction and must disappear. As
we have likely a lot of third party users, we make it deprecated to let them some
time to upgrade their code.

Thanks goes to Laurent Charignon for cleanup the last remains of the 'write'
method.
2015-12-05 23:34:07 -08:00
Augie Fackler
b35ce782e0 bmstore: close file in a finally block in _writerepo
Also rename the variable to file_ to avoid shadowing a builtin.
2015-11-11 21:03:48 -05:00
Augie Fackler
e8456bcfd8 bmstore: add basic clean-state tracking
I'm about to move active-bookmark management into the bmstore. I'd
like to avoid re-writing the bookmarks data (as distinct from the
active bookmark file) if possible, so let's introduce some
dirty-tracking early.
2015-11-11 21:01:23 -05:00
Augie Fackler
c6a7c82c31 bookmarks: hoist getbkfile out of bmstore class
It's totally fine that this hook exists, but I don't see a need for it
to live inside the bmstore class.
2015-11-11 20:45:38 -05:00
Augie Fackler
1495625440 bookmarks: document getbkfile method
I'm working on bmstore again, and this function gave me a moment's
pause. Document it to save future readers from any undue confusion.
2015-11-11 20:43:25 -05:00
Laurent Charignon
7ef3c26089 bookmarks: use repo._bookmarks.recordchange instead of repo._bookmarks.write
We move from the old api repo._bookmarks.write to the new api
repo._bookmarks.recordchange.
2015-11-17 12:49:57 -08:00
Mads Kiilerich
09567db49a spelling: trivial spell checking 2015-10-17 00:58:46 +02:00
FUJIWARA Katsunori
5b79d1f206 bookmarks: use recordchange instead of writing if transaction is active
Before this patch, 'bmstore.write()' always write in-memory bookmark
changes into '.hg/bookmarks' regardless of transaction activity.

If 'bmstore.write()' is invoked inside a transaction and it writes
changes into '.hg/bookmarks', then:

  - original bookmarks aren't restored at failure of that transaction

    This breaks "all or nothing" policy of the transaction.

    BTW, "hg rollback" can restore bookmarks successfully even before
    this patch, because original bookmarks are saved into
    '.hg/journal.bookmarks' at the beginning of the transaction, and
    it (actually renamed as '.hg/undo.bookmarks') is used by "hg
    rollback".

  - uncommitted bookmark changes are visible to other processes

    This is a kind of "dirty read"

For example, 'rebase.rebase()' implies 'bmstore.write()', and it may
be executed inside the transaction of "hg unshelve". Then, intentional
aborting at the end of "hg unshelve" transaction doesn't restore
original bookmarks (this is obviously a bug).

This patch uses 'bmstore.recordchange()' instead of actual writing by
'bmstore._writerepo()', if any transaction is active

This patch also removes meaningless restoring bmstore explicitly at
the end of "hg shelve".

This patch doesn't choose fixing each 'bmstore.write()' callers as
like below, because writing similar code here and there is very
redundant.

  before:
    bmstore.write()

  after:
    tr = repo.currenttransaction()
    if tr:
        bmstore.recordchange(tr)
    else:
        bmstore.write()

Even though 'bmstore.write()' itself may have to be discarded by
putting bookmark operations into transaction scope, this patch chose
fixing it to implement "transactional dirstate" at first.
2015-10-08 01:41:30 +09:00
Laurent Charignon
6644ede114 devel-warn: issue a warning when writing bookmarks without holding the wlock
I saw an issue in an extension that we develop where we were writing bookmarks
without holding the wlock. Another extension was taking a lock at the same time
and wiped out the bookmarks we were about to write. This patch adds a
devel-warning to urge people to fix their invalid code.
2015-08-01 05:43:39 -07:00
Gregory Szorc
565027bd3e bookmarks: use absolute_import 2015-08-07 19:49:21 -07:00
Pierre-Yves David
6d7fad1767 bookmark: remove the "touch changelog" hack
Any changes to bookmarks used to touch the changelog to ensure hgweb was
reloaded. This was fairly hacky and stops working when bookmarks are moved as
part of the transaction. As hgweb is now explicitly tracking bookmark changes,
we can remove this hack (and no tests break).
2015-07-01 01:09:57 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Laurent Charignon
887ad23366 repoview: invalidate 'visible' filtered revisions when bookmarks change
Context: the result of computehidden, used to compute the 'visible' revisions
is cached. Its output can change when:
1) new obsolete commits are created
2) new bookmarks are created or deleted
3) new tags are created or deleted
4) the parents of the working copy change

We currently correctly invalidate the cache only in the case 1).
This patch fixes the second case (bookmarks) by invalidating the cache once
a bookmark is added or removed.
2015-06-13 00:51:43 -07:00
Pierre-Yves David
e4e6aeb80c bookmark: informs of failure to upgrade a bookmark
When we explicitly requested to update a bookmark but the bookmark location was
missing locally, we used to silently ignore the case. We now issue a message
about it to point that something wrong is going on.

By chance, we fixed all the cases where is case happened (for explicit pulling
only, issue4700 is still open). But I think it is still valuable to have a
warning in place in case such issue is reintroduced.

This patch have been tested against issue4689 test (but without issue4689 fix).
It give the better but expected failure seen below:

> --- /home/pyd/src/mercurial-dev/tests/test-bookmarks-pushpull.t
> +++ /home/pyd/src/mercurial-dev/tests/test-bookmarks-pushpull.t.err
> @@ -337,12 +337,12 @@
>    adding manifests
>    adding file changes
>    added 1 changesets with 1 changes to 1 files
> -  updating bookmark Y
> +  remote bookmark Y point to locally missing 0d60821d2197
>    (run 'hg update' to get a working copy)
>    $ hg book
>     * @                         1:0d2164f0ce0d
>       X                         1:0d2164f0ce0d
> -     Y                         5:35d1ef0a8d1b
> +     Y                         4:b0a5eff05604
>       Z                         1:0d2164f0ce0d
>
>  Update a bookmark right after the initial lookup -r (issue4700)
> @@ -387,12 +387,11 @@
>    adding manifests
>    adding file changes
>    added 1 changesets with 1 changes to 1 files
> -  updating bookmark Y
>    (run 'hg update' to get a working copy)
>    $ hg book
>     * @                         1:0d2164f0ce0d
>       X                         1:0d2164f0ce0d
> -     Y                         6:0d60821d2197
> +     Y                         4:b0a5eff05604
>       Z                         1:0d2164f0ce0d
>    $ hg -R $TESTTMP/pull-race book
>       @                         1:0d2164f0ce0d
2015-06-11 17:19:48 -07:00
Ryan McElroy
cf22167e56 bookmarks: rename current to active in variables and comments
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-14 12:53:48 -07:00
Matt Mackall
e0e6c9b392 bookmarks: use try/except/finally 2015-05-15 09:55:47 -05:00
Ryan McElroy
be754988cc bookmarks: simplify iscurrent to isactivewdirparent (API)
Previously this function accepted two optional parameters that were unused by
any callers and complicated the function.

Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-14 12:45:15 -07:00
Ryan McElroy
dd86cb80b4 bookmarks: remove unused updatecurrentbookmark function (API)
This function was not used anywhere in core and there is no indication that
it is used elsewhere either.
2015-04-14 13:31:50 -07:00
Ryan McElroy
7a091e748f bookmarks: rename bookmarkcurrent to activebookmark (API)
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-14 13:17:33 -07:00
Ryan McElroy
7f74c0caf3 bookmarks: rename readcurrent to readactive (API)
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-13 23:03:13 -07:00
Ryan McElroy
fb38156bdc bookmarks: rename setcurrent to activate (API)
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-13 22:27:01 -07:00
Ryan McElroy
2f82753cb2 bookmarks: rename unsetcurrent to deactivate (API)
Today, the terms 'active' and 'current' are interchangeably used throughout the
codebase in reference to the active bookmark (the bookmark that will be updated
with the next commit). This leads to confusion among developers and users.
This patch is part of a series to standardize the usage to 'active' throughout
the mercurial codebase and user interface.
2015-04-13 21:53:37 -07:00
Wagner Bruna
7e2d119543 bookmarks: add i18n hints to bookmark sync states 2015-04-21 21:02:08 -03:00
FUJIWARA Katsunori
15fa88d61c bookmarks: show detailed status about outgoing bookmarks
Before this patch, "hg outgoing -B" shows only difference of bookmarks
between two repositories, and it isn't user friendly.

This patch shows detailed status about outgoing bookmarks at "hg
outgoing -B".

To avoid breaking backward compatibility with other tool chains, this
patch shows status, only if --verbose is specified,
2015-04-08 02:56:19 +09:00
FUJIWARA Katsunori
f7b7fe9dcb bookmarks: show detailed status about incoming bookmarks
Before this patch, "hg incoming -B" shows only difference of bookmarks
between two repositories, and it isn't user friendly.

This patch shows detailed status about incoming bookmarks at "hg
incoming -B".

To avoid breaking backward compatibility with other tool chains, this
patch shows status, only if --verbose is specified,
2015-04-08 02:56:19 +09:00
FUJIWARA Katsunori
71b8a887f2 bookmarks: show outgoing bookmarks more exactly
Before this patch, "hg outgoing -B" shows only bookmarks added
locally. Then, users can't know about bookmarks below before "hg push"
execution.

  - deleted locally (even though it may be added remotely from "hg pull" view)
  - advanced locally
  - diverged
  - changed (= remote revision is unknown for local)

This patch shows such bookmarks, too.
2015-04-08 02:56:19 +09:00
FUJIWARA Katsunori
c1a49db724 bookmarks: show incoming bookmarks more exactly
Before this patch, "hg incoming -B" shows only bookmarks added
remotely. Then, users can't know about bookmarks below before "hg
pull" execution.

  - advanced remotely
  - diverged
  - changed (remote revision is unknown for local)

This patch shows such bookmarks, too.
2015-04-08 02:56:19 +09:00
FUJIWARA Katsunori
928dad06e6 bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
This patch adds utility function "summary()", to replace comparing
bookmarks in "commands.summary()". This replacement finishes
centralizing the logic to compare bookmarks into "bookmarks.compare()".

This patch also adds test to check summary output with
incoming/outgoing bookmarks, because "hg summary --remote" is not
tested yet on the repository with incoming/outgoing bookmarks.

This test uses "(glob)" to ignore summary about incoming/outgoing
changesets.
2015-03-19 23:36:06 +09:00
FUJIWARA Katsunori
1c3d3702ce bookmarks: remove useless diff()
Previous patches removed code paths referring it.
2015-03-19 23:36:05 +09:00
FUJIWARA Katsunori
eefef22b72 bookmarks: add outgoing() to replace diff() for outgoing bookmarks
This replacement makes enhancement of "show outgoing bookmarks" easy,
because "compare()" can detect more detailed difference of bookmarks
between two repositories.
2015-03-19 23:36:05 +09:00
FUJIWARA Katsunori
db0c9bd871 bookmarks: add incoming() to replace diff() for incoming bookmarks
This replacement makes enhancement of "show incoming bookmarks" easy,
because "compare()" can detect more detailed difference of bookmarks
between two repositories.
2015-03-19 23:36:05 +09:00
FUJIWARA Katsunori
d8359fb8e3 bookmarks: reuse @number bookmark, if it refers changeset referred remotely
Before this patch, "@number" suffixed bookmark may be newly created at
each "hg pull" from the remote repository, if the bookmark in remote
repository diverges from one in local one.

This causes unexpected increase of "@number" suffixed bookmarks.

This patch reuses "@number" suffixed bookmark, if it refers the
changeset which is referred by the same bookmark in the remote
repository.
2015-03-17 18:20:24 +09:00
FUJIWARA Katsunori
995101b792 bookmarks: check @pathalias suffix before available @number for efficiency
Before this patch, available "@number" suffix is searched before
"@pathalias" suffix, even though the latter has higher priority than
the former if the latter exits.

This patch checks "@pathalias" suffix before available "@number" for
efficiency.

When an URL has multiple path definitions, the first one is used for
"pathalias" after this patch, even though the last one is used before
this patch, because:

  - this choice can terminate loop immediately for efficiency
  - such case seems to be rare
2015-03-17 18:20:24 +09:00
FUJIWARA Katsunori
2ae4c00003 bookmarks: prevent divergent bookmark from being updated unexpectedly
Before this patch, "@99" suffixed bookmark may be updated unexpectedly
by the bookmark value on the remote side at "hg pull", if all of "@1"
to "@99" suffixed bookmarks exist in the local repository, because
variable "n" still refers "@99" suffixed bookmark after the loop to
examine "@num" suffixes, even though it already exists in the local
repository.

This patch prevents divergent bookmark from being updated
unexpectedly, and shows warning message in such situation.

This patch uses original python script "seq.py" instead of "seq"
command to create sequence numbers in the test, because "seq" command
may not be available: it isn't defined in recent POSIX specification
(POSIX.1-2001 2013 Edition or XPG7)
2015-03-17 18:20:24 +09:00
Jordi Gutiérrez Hermoso
8eb132f5ea style: kill ersatz if-else ternary operators
Although Python supports `X = Y if COND else Z`, this was only
introduced in Python 2.5. Since we have to support Python 2.4, it was
a very common thing to write instead `X = COND and Y or Z`, which is a
bit obscure at a glance. It requires some intricate knowledge of
Python to understand how to parse these one-liners.

We change instead all of these one-liners to 4-liners. This was
executed with the following perlism:

    find -name "*.py" -exec perl -pi -e 's,(\s*)([\.\w]+) = \(?(\S+)\s+and\s+(\S*)\)?\s+or\s+(\S*)$,$1if $3:\n$1    $2 = $4\n$1else:\n$1    $2 = $5,' {} \;

I tweaked the following cases from the automatic Perl output:

    prev = (parents and parents[0]) or nullid
    port = (use_ssl and 443 or 80)
    cwd = (pats and repo.getcwd()) or ''
    rename = fctx and webutil.renamelink(fctx) or []
    ctx = fctx and fctx or ctx
    self.base = (mapfile and os.path.dirname(mapfile)) or ''

I also added some newlines wherever they seemd appropriate for readability

There are probably a few ersatz ternary operators still in the code
somewhere, lurking away from the power of a simple regex.
2015-03-13 17:00:06 -04:00
Mads Kiilerich
b2b60414f6 spelling: fixes from proofreading of spell checker issues 2015-01-18 02:38:57 +01:00
Angel Ezquerra
88cbab7845 localrepo: remove all external users of localrepo.opener
This change touches every module in which repository.opener was being used, and
changes it for the equivalent repository.vfs. This is meant to make it easier
to split the repository.vfs into several separate vfs.

It should now be possible to remove localrepo.opener.
2015-01-15 23:17:12 +01:00
Ryan McElroy
cf43c21202 bookmarks: factor out repository lookup from writing bookmarks file
This will allow the share extension to extend bookmarks functionality to share
bookmarks between repositories.
2014-12-02 20:31:19 -08:00
Ryan McElroy
468da3b11a bookmarks: factor out bookmark file opening for easier extensibility 2014-11-27 00:24:25 -08:00
Pierre-Yves David
4012eb31b0 bookmark: read pending data when appropriate
If we are called by a hook and pending data exists, read it.
2014-09-28 21:27:48 -07:00
Pierre-Yves David
b9594d1c53 transaction: use 'location' instead of 'vfs' objects for file generation
The argument is now a location name. The location must be present in the
'vfsmap' provided to the transaction at creation time.
2014-10-17 20:53:42 -07:00