annotate mercurial/tags.py @ 52032:09a54892b7ee

mergestate: reduce the number of attribute lookups This code is called a lot during updates, this is a very small but also very easy thing to do.
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 21 Aug 2024 09:48:14 +0200
parents f4733654f144
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
1 # tags.py - read tag info from local repository
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
2 #
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 46656
diff changeset
3 # Copyright 2009 Olivia Mackall <olivia@selenic.com>
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
4 # Copyright 2009 Greg Ward <greg@gerg.ca>
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
5 #
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
6 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9678
diff changeset
7 # GNU General Public License version 2 or any later version.
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
8
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
9 # Currently this module only deals with reading and caching tags.
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
10 # Eventually, it could take care of updating (adding/removing/moving)
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
11 # tags too.
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
12
51863
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51780
diff changeset
13 from __future__ import annotations
25982
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
14
49248
63fd0282ad40 node: stop converting binascii.Error to TypeError in bin()
Manuel Jacob <me@manueljacob.de>
parents: 48992
diff changeset
15 import binascii
42567
4eaf7197a740 cleanup: use named constants for second arg to .seek()
Augie Fackler <augie@google.com>
parents: 42239
diff changeset
16 import io
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
17
25982
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
18 from .node import (
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
19 bin,
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
20 hex,
42237
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
21 nullrev,
25982
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
22 short,
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
23 )
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
24 from .i18n import _
51599
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
25 from .revlogutils.constants import ENTRY_NODE_ID
25982
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
26 from . import (
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
27 encoding,
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
28 error,
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
29 match as matchmod,
31025
6cf2857526c7 scmutil: proxy revrange() through repo to break import cycles
Yuya Nishihara <yuya@tcha.org>
parents: 30975
diff changeset
30 scmutil,
25982
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
31 util,
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
32 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
33 from .utils import stringutil
25982
b2f3f185e458 tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
34
51599
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
35
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
36 # Tags computation can be expensive and caches exist to make it fast in
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
37 # the common case.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
38 #
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
39 # The "hgtagsfnodes1" cache file caches the .hgtags filenode values for
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
40 # each revision in the repository. The file is effectively an array of
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
41 # fixed length records. Read the docs for "hgtagsfnodescache" for technical
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
42 # details.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
43 #
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
44 # The .hgtags filenode cache grows in proportion to the length of the
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
45 # changelog. The file is truncated when the # changelog is stripped.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
46 #
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
47 # The purpose of the filenode cache is to avoid the most expensive part
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
48 # of finding global tags, which is looking up the .hgtags filenode in the
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
49 # manifest for each head. This can take dozens or over 100ms for
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
50 # repositories with very large manifests. Multiplied by dozens or even
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
51 # hundreds of heads and there is a significant performance concern.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
52 #
24762
1062663808ce tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24761
diff changeset
53 # There also exist a separate cache file for each repository filter.
1062663808ce tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24761
diff changeset
54 # These "tags-*" files store information about the history of tags.
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
55 #
24762
1062663808ce tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24761
diff changeset
56 # The tags cache files consists of a cache validation line followed by
1062663808ce tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24761
diff changeset
57 # a history of tags.
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
58 #
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
59 # The cache validation line has the format:
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
60 #
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
61 # <tiprev> <tipnode> [<filteredhash>]
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
62 #
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
63 # <tiprev> is an integer revision and <tipnode> is a 40 character hex
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
64 # node for that changeset. These redundantly identify the repository
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
65 # tip from the time the cache was written. In addition, <filteredhash>,
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
66 # if present, is a 40 character hex hash of the contents of the filtered
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
67 # revisions for this filter. If the set of filtered revs changes, the
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
68 # hash will change and invalidate the cache.
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
69 #
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
70 # The history part of the tags cache consists of lines of the form:
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
71 #
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
72 # <node> <tag>
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
73 #
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
74 # (This format is identical to that of .hgtags files.)
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
75 #
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
76 # <tag> is the tag name and <node> is the 40 character hex changeset
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
77 # the tag is associated with.
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
78 #
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
79 # Tags are written sorted by tag name.
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
80 #
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
81 # Tags associated with multiple changesets have an entry for each changeset.
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
82 # The most recent changeset (in terms of revlog ordering for the head
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
83 # setting it) for each tag is last.
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
84
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
85
51596
6378d57562af tags-cache: add a dedicated warm cache function to hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51526
diff changeset
86 def warm_cache(repo):
6378d57562af tags-cache: add a dedicated warm cache function to hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51526
diff changeset
87 """ensure the cache is properly filled"""
6378d57562af tags-cache: add a dedicated warm cache function to hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51526
diff changeset
88 unfi = repo.unfiltered()
51599
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
89 fnodescache = hgtagsfnodescache(unfi)
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
90 validated_fnodes = set()
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
91 unknown_entries = set()
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
92 flog = None
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
93
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
94 entries = enumerate(repo.changelog.index)
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
95 node_revs = ((e[ENTRY_NODE_ID], rev) for (rev, e) in entries)
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
96
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
97 for node, rev in node_revs:
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
98 fnode = fnodescache.getfnode(node=node, rev=rev)
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
99 if fnode != repo.nullid:
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
100 if fnode not in validated_fnodes:
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
101 if flog is None:
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
102 flog = repo.file(b'.hgtags')
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
103 if flog.hasnode(fnode):
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
104 validated_fnodes.add(fnode)
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
105 else:
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
106 unknown_entries.add(node)
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
107
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
108 if unknown_entries:
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
109 fnodescache.refresh_invalid_nodes(unknown_entries)
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
110
b0aaffcb6fcf tags-cache: directly perform a monimal walk for hgtagsfnodescache warming
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51598
diff changeset
111 fnodescache.write()
51596
6378d57562af tags-cache: add a dedicated warm cache function to hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51526
diff changeset
112
6378d57562af tags-cache: add a dedicated warm cache function to hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51526
diff changeset
113
31993
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
114 def fnoderevs(ui, repo, revs):
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
115 """return the list of '.hgtags' fnodes used in a set revisions
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
116
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
117 This is returned as list of unique fnodes. We use a list instead of a set
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
118 because order matters when it comes to tags."""
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
119 unfi = repo.unfiltered()
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
120 tonode = unfi.changelog.node
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
121 nodes = [tonode(r) for r in revs]
42239
6770df6e4365 tags: avoid double-reversing a list
Martin von Zweigbergk <martinvonz@google.com>
parents: 42237
diff changeset
122 fnodes = _getfnodes(ui, repo, nodes)
31993
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
123 fnodes = _filterfnodes(fnodes, nodes)
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
124 return fnodes
bfb826c350d4 tags: introduce a function to return a valid fnodes list from revs
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31788
diff changeset
125
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
126
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
127 def _nulltonone(repo, value):
31995
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
128 """convert nullid to None
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
129
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
130 For tag value, nullid means "deleted". This small utility function helps
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
131 translating that to None."""
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
132 if value == repo.nullid:
31995
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
133 return None
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
134 return value
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
135
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
136
31995
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
137 def difftags(ui, repo, oldfnodes, newfnodes):
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
138 """list differences between tags expressed in two set of file-nodes
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
139
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
140 The list contains entries in the form: (tagname, oldvalue, new value).
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
141 None is used to expressed missing value:
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
142 ('foo', None, 'abcd') is a new tag,
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
143 ('bar', 'ef01', None) is a deletion,
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
144 ('baz', 'abcd', 'ef01') is a tag movement.
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
145 """
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
146 if oldfnodes == newfnodes:
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
147 return []
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
148 oldtags = _tagsfromfnodes(ui, repo, oldfnodes)
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
149 newtags = _tagsfromfnodes(ui, repo, newfnodes)
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
150
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
151 # list of (tag, old, new): None means missing
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
152 entries = []
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
153 for tag, (new, __) in newtags.items():
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
154 new = _nulltonone(repo, new)
31995
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
155 old, __ = oldtags.pop(tag, (None, None))
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
156 old = _nulltonone(repo, old)
31995
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
157 if old != new:
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
158 entries.append((tag, old, new))
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
159 # handle deleted tags
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
160 for tag, (old, __) in oldtags.items():
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
161 old = _nulltonone(repo, old)
31995
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
162 if old is not None:
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
163 entries.append((tag, old, None))
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
164 entries.sort()
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
165 return entries
fe9c4d614600 track-tags: compute the actual differences between tags pre/post transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31993
diff changeset
166
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
167
31996
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
168 def writediff(fp, difflist):
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
169 """write tags diff information to a file.
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
170
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
171 Data are stored with a line based format:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
172
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
173 <action> <hex-node> <tag-name>\n
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
174
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
175 Action are defined as follow:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
176 -R tag is removed,
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
177 +A tag is added,
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
178 -M tag is moved (old value),
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
179 +M tag is moved (new value),
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
180
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
181 Example:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
182
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
183 +A 875517b4806a848f942811a315a5bce30804ae85 t5
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
184
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
185 See documentation of difftags output for details about the input.
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
186 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
187 add = b'+A %s %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
188 remove = b'-R %s %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
189 updateold = b'-M %s %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
190 updatenew = b'+M %s %s\n'
31996
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
191 for tag, old, new in difflist:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
192 # translate to hex
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
193 if old is not None:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
194 old = hex(old)
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
195 if new is not None:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
196 new = hex(new)
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
197 # write to file
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
198 if old is None:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
199 fp.write(add % (new, tag))
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
200 elif new is None:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
201 fp.write(remove % (old, tag))
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
202 else:
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
203 fp.write(updateold % (old, tag))
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
204 fp.write(updatenew % (new, tag))
e6e1884df298 track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31995
diff changeset
205
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
206
31706
63d4deda1b31 tags: do not feed dictionaries to 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31705
diff changeset
207 def findglobaltags(ui, repo):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
208 """Find global tags in a repo: return a tagsmap
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
209
31709
c34c170b25f3 tags: only return 'alltags' in 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31708
diff changeset
210 tagsmap: tag name to (node, hist) 2-tuples.
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
211
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
212 The tags cache is read and updated as a side-effect of calling.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
213 """
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
214 (heads, tagfnode, valid, cachetags, shouldwrite) = _readtagcache(ui, repo)
9152
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
215 if cachetags is not None:
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
216 assert not shouldwrite
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
217 # XXX is this really 100% correct? are there oddball special
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
218 # cases where a global tag should outrank a local tag but won't,
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
219 # because cachetags does not contain rank info?
31710
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
220 alltags = {}
31709
c34c170b25f3 tags: only return 'alltags' in 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31708
diff changeset
221 _updatetags(cachetags, alltags)
c34c170b25f3 tags: only return 'alltags' in 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31708
diff changeset
222 return alltags
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
223
50942
75d3306fbc9a tags: avoid expensive access to repo.changelog in a loop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50939
diff changeset
224 has_node = repo.changelog.index.has_node
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
225 for head in reversed(heads): # oldest to newest
50942
75d3306fbc9a tags: avoid expensive access to repo.changelog in a loop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50939
diff changeset
226 assert has_node(head), b"tag cache returned bogus head %s" % short(head)
31711
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
227 fnodes = _filterfnodes(tagfnode, reversed(heads))
31710
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
228 alltags = _tagsfromfnodes(ui, repo, fnodes)
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
229
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
230 # and update the cache (if necessary)
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
231 if shouldwrite:
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
232 _writetagcache(ui, repo, valid, alltags)
31709
c34c170b25f3 tags: only return 'alltags' in 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31708
diff changeset
233 return alltags
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
234
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
235
31711
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
236 def _filterfnodes(tagfnode, nodes):
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
237 """return a list of unique fnodes
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
238
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
239 The order of this list matches the order of "nodes". Preserving this order
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
240 is important as reading tags in different order provides different
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
241 results."""
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
242 seen = set() # set of fnode
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
243 fnodes = []
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
244 for no in nodes: # oldest to newest
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
245 fnode = tagfnode.get(no)
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
246 if fnode and fnode not in seen:
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
247 seen.add(fnode)
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
248 fnodes.append(fnode)
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
249 return fnodes
472d726c1afd tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31710
diff changeset
250
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
251
31710
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
252 def _tagsfromfnodes(ui, repo, fnodes):
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
253 """return a tagsmap from a list of file-node
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
254
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
255 tagsmap: tag name to (node, hist) 2-tuples.
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
256
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
257 The order of the list matters."""
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
258 alltags = {}
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
259 fctx = None
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
260 for fnode in fnodes:
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
261 if fctx is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
262 fctx = repo.filectx(b'.hgtags', fileid=fnode)
31710
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
263 else:
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
264 fctx = fctx.filectx(fnode)
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
265 filetags = _readtags(ui, repo, fctx.data().splitlines(), fctx)
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
266 _updatetags(filetags, alltags)
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
267 return alltags
510267cf6c58 tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31709
diff changeset
268
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
269
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
270 def readlocaltags(ui, repo, alltags, tagtypes):
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
271 '''Read local tags in repo. Update alltags and tagtypes.'''
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
272 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
273 data = repo.vfs.read(b"localtags")
49306
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49248
diff changeset
274 except FileNotFoundError:
14038
0e6f622f31ca tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents: 14020
diff changeset
275 return
0e6f622f31ca tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents: 14020
diff changeset
276
0e6f622f31ca tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents: 14020
diff changeset
277 # localtags is in the local encoding; re-encode to UTF-8 on
0e6f622f31ca tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents: 14020
diff changeset
278 # input for consistency with the rest of this module.
0e6f622f31ca tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents: 14020
diff changeset
279 filetags = _readtags(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
280 ui, repo, data.splitlines(), b"localtags", recode=encoding.fromlocal
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
281 )
21823
925d1bb9a971 repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21030
diff changeset
282
925d1bb9a971 repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21030
diff changeset
283 # remove tags pointing to invalid nodes
925d1bb9a971 repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21030
diff changeset
284 cl = repo.changelog
35828
553a98a436cf tags: explicitly grab list of dict keys
Augie Fackler <augie@google.com>
parents: 34015
diff changeset
285 for t in list(filetags):
21823
925d1bb9a971 repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21030
diff changeset
286 try:
925d1bb9a971 repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21030
diff changeset
287 cl.rev(filetags[t][0])
925d1bb9a971 repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21030
diff changeset
288 except (LookupError, ValueError):
925d1bb9a971 repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21030
diff changeset
289 del filetags[t]
925d1bb9a971 repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21030
diff changeset
290
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
291 _updatetags(filetags, alltags, b'local', tagtypes)
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
292
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
293
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
294 def _readtaghist(ui, repo, lines, fn, recode=None, calcnodelines=False):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
295 """Read tag definitions from a file (or any source of lines).
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
296
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
297 This function returns two sortdicts with similar information:
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
298
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 21892
diff changeset
299 - the first dict, bintaghist, contains the tag information as expected by
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
300 the _readtags function, i.e. a mapping from tag name to (node, hist):
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
301 - node is the node id from the last line read for that name,
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
302 - hist is the list of node ids previously associated with it (in file
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
303 order). All node ids are binary, not hex.
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
304
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
305 - the second dict, hextaglines, is a mapping from tag name to a list of
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
306 [hexnode, line number] pairs, ordered from the oldest to the newest node.
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
307
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
308 When calcnodelines is False the hextaglines dict is not calculated (an
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
309 empty dict is returned). This is done to improve this function's
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
310 performance in cases where the line numbers are not needed.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
311 """
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
312
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
313 bintaghist = util.sortdict()
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
314 hextaglines = util.sortdict()
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
315 count = 0
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
316
29038
a9dd92c48a1c tags: silence cache parsing errors
Matt Mackall <mpm@selenic.com>
parents: 26945
diff changeset
317 def dbg(msg):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
318 ui.debug(b"%s, line %d: %s\n" % (fn, count, msg))
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
319
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
320 for nline, line in enumerate(lines):
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
321 count += 1
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
322 if not line:
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
323 continue
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
324 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
325 (nodehex, name) = line.split(b" ", 1)
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
326 except ValueError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
327 dbg(b"cannot parse entry")
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
328 continue
9152
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
329 name = name.strip()
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
330 if recode:
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
331 name = recode(name)
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
332 try:
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
333 nodebin = bin(nodehex)
49248
63fd0282ad40 node: stop converting binascii.Error to TypeError in bin()
Manuel Jacob <me@manueljacob.de>
parents: 48992
diff changeset
334 except binascii.Error:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
335 dbg(b"node '%s' is not well formed" % nodehex)
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
336 continue
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
337
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
338 # update filetags
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
339 if calcnodelines:
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
340 # map tag name to a list of line numbers
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
341 if name not in hextaglines:
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
342 hextaglines[name] = []
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
343 hextaglines[name].append([nodehex, nline])
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
344 continue
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
345 # map tag name to (node, hist)
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
346 if name not in bintaghist:
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
347 bintaghist[name] = []
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
348 bintaghist[name].append(nodebin)
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
349 return bintaghist, hextaglines
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
350
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
351
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
352 def _readtags(ui, repo, lines, fn, recode=None, calcnodelines=False):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
353 """Read tag definitions from a file (or any source of lines).
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
354
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
355 Returns a mapping from tag name to (node, hist).
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
356
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
357 "node" is the node id from the last line read for that name. "hist"
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
358 is the list of node ids previously associated with it (in file order).
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
359 All node ids are binary, not hex.
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
360 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
361 filetags, nodelines = _readtaghist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
362 ui, repo, lines, fn, recode=recode, calcnodelines=calcnodelines
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
363 )
26945
8a256cee72c8 tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25982
diff changeset
364 # util.sortdict().__setitem__ is much slower at replacing then inserting
8a256cee72c8 tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25982
diff changeset
365 # new entries. The difference can matter if there are thousands of tags.
8a256cee72c8 tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25982
diff changeset
366 # Create a new sortdict to avoid the performance penalty.
8a256cee72c8 tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25982
diff changeset
367 newtags = util.sortdict()
21892
89cdebc31cda tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 21832
diff changeset
368 for tag, taghist in filetags.items():
26945
8a256cee72c8 tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25982
diff changeset
369 newtags[tag] = (taghist[-1], taghist[:-1])
8a256cee72c8 tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25982
diff changeset
370 return newtags
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
371
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
372
31708
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
373 def _updatetags(filetags, alltags, tagtype=None, tagtypes=None):
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
374 """Incorporate the tag info read from one file into dictionnaries
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
375
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
376 The first one, 'alltags', is a "tagmaps" (see 'findglobaltags' for details).
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
377
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
378 The second one, 'tagtypes', is optional and will be updated to track the
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
379 "tagtype" of entries in the tagmaps. When set, the 'tagtype' argument also
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
380 needs to be set."""
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
381 if tagtype is None:
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
382 assert tagtypes is None
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
383
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
384 for name, nodehist in filetags.items():
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
385 if name not in alltags:
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
386 alltags[name] = nodehist
31708
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
387 if tagtype is not None:
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
388 tagtypes[name] = tagtype
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
389 continue
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
390
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
391 # we prefer alltags[name] if:
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17256
diff changeset
392 # it supersedes us OR
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17256
diff changeset
393 # mutual supersedes and it has a higher rank
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
394 # otherwise we win because we're tip-most
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
395 anode, ahist = nodehist
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
396 bnode, bhist = alltags[name]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
397 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
398 bnode != anode
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
399 and anode in bhist
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
400 and (bnode not in ahist or len(bhist) > len(ahist))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
401 ):
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
402 anode = bnode
31708
d0e7c70f14b7 tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31707
diff changeset
403 elif tagtype is not None:
19108
cb95716da5fe tags: update tag type only if tag node is updated (issue3911)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 17424
diff changeset
404 tagtypes[name] = tagtype
9149
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
405 ahist.extend([n for n in bhist if n not in ahist])
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
406 alltags[name] = anode, ahist
abb7d4d43a5f Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff changeset
407
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
408
24737
b061a2049662 tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24735
diff changeset
409 def _filename(repo):
b061a2049662 tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24735
diff changeset
410 """name of a tagcache file for a given repo or repoview"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
411 filename = b'tags2'
24737
b061a2049662 tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24735
diff changeset
412 if repo.filtername:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
413 filename = b'%s-%s' % (filename, repo.filtername)
24737
b061a2049662 tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24735
diff changeset
414 return filename
b061a2049662 tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24735
diff changeset
415
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
416
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
417 def _readtagcache(ui, repo):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
418 """Read the tag cache.
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
419
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
420 Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite).
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
421
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
422 If the cache is completely up-to-date, "cachetags" is a dict of the
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
423 form returned by _readtags() and "heads", "fnodes", and "validinfo" are
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
424 None and "shouldwrite" is False.
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
425
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
426 If the cache is not up to date, "cachetags" is None. "heads" is a list
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
427 of all heads currently in the repository, ordered from tip to oldest.
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
428 "validinfo" is a tuple describing cache validation info. This is used
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
429 when writing the tags cache. "fnodes" is a mapping from head to .hgtags
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
430 filenode. "shouldwrite" is True.
24445
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
431
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
432 If the cache is not up to date, the caller is responsible for reading tag
c71edbafe603 tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24143
diff changeset
433 info from each returned head. (See findglobaltags().)
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
434 """
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
435 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
436 cachefile = repo.cachevfs(_filename(repo), b'r')
11066
26abd91d9e84 static-http: mimic more closely localrepo (issue2164: allow clone -r )
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10263
diff changeset
437 # force reading the file for static-http
26abd91d9e84 static-http: mimic more closely localrepo (issue2164: allow clone -r )
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10263
diff changeset
438 cachelines = iter(cachefile)
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
439 except IOError:
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
440 cachefile = None
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
441
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
442 cacherev = None
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
443 cachenode = None
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
444 cachehash = None
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
445 if cachefile:
12758
2d754eae430c tags: do not fail if tags.cache is corrupted (issue2444)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11352
diff changeset
446 try:
29216
ead25aa27a43 py3: convert to next() function
timeless <timeless@mozdev.org>
parents: 29039
diff changeset
447 validline = next(cachelines)
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
448 validline = validline.split()
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
449 cacherev = int(validline[0])
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
450 cachenode = bin(validline[1])
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
451 if len(validline) > 2:
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
452 cachehash = bin(validline[2])
14020
98f79a5c3086 tags: catch more corruption during cache parsing (issue2779)
Matt Mackall <mpm@selenic.com>
parents: 13341
diff changeset
453 except Exception:
24759
d082c6ef9ec3 tags: don't read .hgtags fnodes from tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24737
diff changeset
454 # corruption of the cache, just recompute it.
d082c6ef9ec3 tags: don't read .hgtags fnodes from tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24737
diff changeset
455 pass
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
456
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
457 tipnode = repo.changelog.tip()
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
458 tiprev = len(repo.changelog) - 1
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
459
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
460 # Case 1 (common): tip is the same, so nothing has changed.
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
461 # (Unchanged tip trivially means no changesets have been added.
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
462 # But, thanks to localrepository.destroyed(), it also means none
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
463 # have been destroyed by strip or rollback.)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
464 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
465 cacherev == tiprev
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
466 and cachenode == tipnode
51526
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
467 and cachehash
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
468 == scmutil.combined_filtered_and_obsolete_hash(
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
469 repo,
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
470 tiprev,
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
471 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
472 ):
11066
26abd91d9e84 static-http: mimic more closely localrepo (issue2164: allow clone -r )
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10263
diff changeset
473 tags = _readtags(ui, repo, cachelines, cachefile.name)
9152
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
474 cachefile.close()
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
475 return (None, None, None, tags, False)
9152
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
476 if cachefile:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
477 cachefile.close() # ignore rest of file
9312
c5f0825c1dbb kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9152
diff changeset
478
51526
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
479 valid = (
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
480 tiprev,
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
481 tipnode,
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
482 scmutil.combined_filtered_and_obsolete_hash(
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
483 repo,
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
484 tiprev,
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
485 ),
a03fa40afd01 filteredhash: rename the filteredhash function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51152
diff changeset
486 )
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
487
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
488 repoheads = repo.heads()
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
489 # Case 2 (uncommon): empty repo; get out quickly and don't bother
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
490 # writing an empty cache.
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
491 if repoheads == [repo.nullid]:
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
492 return ([], {}, valid, {}, False)
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
493
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
494 # Case 3 (uncommon): cache file missing or empty.
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
495
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
496 # Case 4 (uncommon): tip rev decreased. This should only happen
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
497 # when we're called from localrepository.destroyed(). Refresh the
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
498 # cache so future invocations will not see disappeared heads in the
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
499 # cache.
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
500
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
501 # Case 5 (common): tip has changed, so we've added/replaced heads.
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
502
11352
b19067ee4507 tags: remove inactive debugging code.
Greg Ward <greg-hg@gerg.ca>
parents: 11351
diff changeset
503 # As it happens, the code to handle cases 3, 4, 5 is the same.
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
504
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
505 # N.B. in case 4 (nodes destroyed), "new head" really means "newly
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
506 # exposed".
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
507 if not len(repo.file(b'.hgtags')):
16730
dd4ce44ff53c tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents: 16589
diff changeset
508 # No tags have ever been committed, so we can avoid a
dd4ce44ff53c tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents: 16589
diff changeset
509 # potentially expensive search.
24761
61a6d83280d3 tags: return empty list of heads for no .hgtags case
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24760
diff changeset
510 return ([], {}, valid, None, True)
16730
dd4ce44ff53c tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents: 16589
diff changeset
511
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
512 # Now we have to lookup the .hgtags filenode for every new head.
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
513 # This is the most expensive part of finding tags, so performance
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
514 # depends primarily on the size of newheads. Worst case: no cache
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
515 # file, so newheads == repoheads.
42239
6770df6e4365 tags: avoid double-reversing a list
Martin von Zweigbergk <martinvonz@google.com>
parents: 42237
diff changeset
516 # Reversed order helps the cache ('repoheads' is in descending order)
6770df6e4365 tags: avoid double-reversing a list
Martin von Zweigbergk <martinvonz@google.com>
parents: 42237
diff changeset
517 cachefnode = _getfnodes(ui, repo, reversed(repoheads))
31705
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
518
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
519 # Caller has to iterate over all heads, but can use the filenodes in
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
520 # cachefnode to get to each .hgtags revision quickly.
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
521 return (repoheads, cachefnode, valid, None, True)
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
522
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
523
51598
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
524 def _getfnodes(ui, repo, nodes=None, revs=None):
31705
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
525 """return .hgtags fnodes for a list of changeset nodes
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
526
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
527 Return value is a {node: fnode} mapping. There will be no entry for nodes
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
528 without a '.hgtags' file.
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
529 """
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
530 starttime = util.timer()
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
531 fnodescache = hgtagsfnodescache(repo.unfiltered())
24759
d082c6ef9ec3 tags: don't read .hgtags fnodes from tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24737
diff changeset
532 cachefnode = {}
46656
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
533 validated_fnodes = set()
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
534 unknown_entries = set()
49579
15a89b722937 tags-fnode-cache: do not repeatedly open the filelog in a loop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
535
51598
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
536 if nodes is None and revs is None:
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
537 raise error.ProgrammingError("need to specify either nodes or revs")
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
538 elif nodes is not None and revs is None:
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
539 to_rev = repo.changelog.index.rev
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
540 nodes_revs = ((n, to_rev(n)) for n in nodes)
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
541 elif nodes is None and revs is not None:
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
542 to_node = repo.changelog.node
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
543 nodes_revs = ((to_node(r), r) for r in revs)
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
544 else:
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
545 msg = "need to specify only one of nodes or revs"
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
546 raise error.ProgrammingError(msg)
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
547
49579
15a89b722937 tags-fnode-cache: do not repeatedly open the filelog in a loop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
548 flog = None
51598
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
549 for node, rev in nodes_revs:
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
550 fnode = fnodescache.getfnode(node=node, rev=rev)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
551 if fnode != repo.nullid:
46656
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
552 if fnode not in validated_fnodes:
49579
15a89b722937 tags-fnode-cache: do not repeatedly open the filelog in a loop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
553 if flog is None:
15a89b722937 tags-fnode-cache: do not repeatedly open the filelog in a loop
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49306
diff changeset
554 flog = repo.file(b'.hgtags')
46656
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
555 if flog.hasnode(fnode):
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
556 validated_fnodes.add(fnode)
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
557 else:
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
558 unknown_entries.add(node)
31788
417363736c11 tags: rename "head" to "node" where we don't care
Martin von Zweigbergk <martinvonz@google.com>
parents: 31711
diff changeset
559 cachefnode[node] = fnode
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
560
46656
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
561 if unknown_entries:
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
562 fixed_nodemap = fnodescache.refresh_invalid_nodes(unknown_entries)
48913
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
563 for node, fnode in fixed_nodemap.items():
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
564 if fnode != repo.nullid:
46656
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
565 cachefnode[node] = fnode
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
566
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
567 fnodescache.write()
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
568
30975
22fbca1d11ed mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents: 29216
diff changeset
569 duration = util.timer() - starttime
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
570 ui.log(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
571 b'tagscache',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
572 b'%d/%d cache hits/lookups in %0.4f seconds\n',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
573 fnodescache.hitcount,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
574 fnodescache.lookupcount,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
575 duration,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
576 )
31705
5eb4d206202b tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31669
diff changeset
577 return cachefnode
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
578
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
579
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
580 def _writetagcache(ui, repo, valid, cachetags):
24763
a698e088ad29 tags: explicitly log which tags cache file is being written
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24762
diff changeset
581 filename = _filename(repo)
9366
9ff178e7b627 tags: don't crash if unable to write tag cache
Greg Ward <greg-hg@gerg.ca>
parents: 9312
diff changeset
582 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
583 cachefile = repo.cachevfs(filename, b'w', atomictemp=True)
9366
9ff178e7b627 tags: don't crash if unable to write tag cache
Greg Ward <greg-hg@gerg.ca>
parents: 9312
diff changeset
584 except (OSError, IOError):
9ff178e7b627 tags: don't crash if unable to write tag cache
Greg Ward <greg-hg@gerg.ca>
parents: 9312
diff changeset
585 return
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
586
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
587 ui.log(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
588 b'tagscache',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
589 b'writing .hg/cache/%s with %d tags\n',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
590 filename,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
591 len(cachetags),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
592 )
21030
9ea132aee96c tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19646
diff changeset
593
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
594 if valid[2]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
595 cachefile.write(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
596 b'%d %s %s\n' % (valid[0], hex(valid[1]), hex(valid[2]))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
597 )
24760
410f3856196f tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24759
diff changeset
598 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
599 cachefile.write(b'%d %s\n' % (valid[0], hex(valid[1])))
9151
f528d1a93491 tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents: 9149
diff changeset
600
9152
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
601 # Tag names in the cache are in UTF-8 -- which is the whole reason
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
602 # we keep them in UTF-8 throughout this module. If we converted
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
603 # them local encoding on input, we would lose info writing them to
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
604 # the cache.
51703
ca7bde5dbafb black: format the codebase with 23.3.0
Raphaël Gomès <rgomes@octobus.net>
parents: 51700
diff changeset
605 for name, (node, hist) in sorted(cachetags.items()):
19646
335a558f81dc tags: write tag overwriting history also into tag cache file (issue3911)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19108
diff changeset
606 for n in hist:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
607 cachefile.write(b"%s %s\n" % (hex(n), name))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
608 cachefile.write(b"%s %s\n" % (hex(node), name))
9152
4017291c4c48 tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents: 9151
diff changeset
609
14662
2b30124c7d8a tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents: 14168
diff changeset
610 try:
15057
774da7121fc9 atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents: 14662
diff changeset
611 cachefile.close()
14662
2b30124c7d8a tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents: 14168
diff changeset
612 except (OSError, IOError):
2b30124c7d8a tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents: 14168
diff changeset
613 pass
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
614
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
615
31669
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
616 def tag(repo, names, node, message, local, user, date, editor=False):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
617 """tag a revision with one or more symbolic names.
31669
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
618
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
619 names is a list of strings or, when adding a single tag, names may be a
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
620 string.
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
621
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
622 if local is True, the tags are stored in a per-repository file.
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
623 otherwise, they are stored in the .hgtags file, and a new
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
624 changeset is committed with the change.
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
625
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
626 keyword arguments:
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
627
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
628 local: whether to store tags in non-version-controlled file
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
629 (default False)
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
630
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
631 message: commit message to use if committing
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
632
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
633 user: name of user to use if committing
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
634
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45787
diff changeset
635 date: date tuple to use if committing"""
31669
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
636
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
637 if not local:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
638 m = matchmod.exact([b'.hgtags'])
43652
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
639 st = repo.status(match=m, unknown=True, ignored=True)
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
640 if any(
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
641 (
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
642 st.modified,
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
643 st.added,
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
644 st.removed,
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
645 st.deleted,
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
646 st.unknown,
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
647 st.ignored,
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
648 )
ba5c39b9324c tags: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents: 43543
diff changeset
649 ):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
650 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
651 _(b'working copy of .hgtags is changed'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
652 hint=_(b'please commit .hgtags manually'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
653 )
31669
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
654
33255
4f3f08262eb4 tag: make sure the repository is locked when tagging
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 31996
diff changeset
655 with repo.wlock():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
656 repo.tags() # instantiate the cache
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
657 _tag(repo, names, node, message, local, user, date, editor=editor)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
658
31669
a719f3315366 tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31668
diff changeset
659
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
660 def _tag(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
661 repo, names, node, message, local, user, date, extra=None, editor=False
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
662 ):
41841
b1d07f4614a6 py3: use bytes instead of str in isinstance()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41759
diff changeset
663 if isinstance(names, bytes):
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
664 names = (names,)
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
665
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
666 branches = repo.branchmap()
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
667 for name in names:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
668 repo.hook(b'pretag', throw=True, node=hex(node), tag=name, local=local)
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
669 if name in branches:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
670 repo.ui.warn(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
671 _(b"warning: tag %s conflicts with existing branch name\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
672 % name
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
673 )
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
674
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
675 def writetags(fp, names, munge, prevtags):
42567
4eaf7197a740 cleanup: use named constants for second arg to .seek()
Augie Fackler <augie@google.com>
parents: 42239
diff changeset
676 fp.seek(0, io.SEEK_END)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
677 if prevtags and not prevtags.endswith(b'\n'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
678 fp.write(b'\n')
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
679 for name in names:
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
680 if munge:
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
681 m = munge(name)
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
682 else:
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
683 m = name
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
684
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
685 if repo._tagscache.tagtypes and name in repo._tagscache.tagtypes:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
686 old = repo.tags().get(name, repo.nullid)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
687 fp.write(b'%s %s\n' % (hex(old), m))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
688 fp.write(b'%s %s\n' % (hex(node), m))
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
689 fp.close()
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
690
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
691 prevtags = b''
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
692 if local:
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
693 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
694 fp = repo.vfs(b'localtags', b'r+')
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
695 except IOError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
696 fp = repo.vfs(b'localtags', b'a')
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
697 else:
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
698 prevtags = fp.read()
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
699
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
700 # local tags are stored in the current charset
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
701 writetags(fp, names, None, prevtags)
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
702 for name in names:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
703 repo.hook(b'tag', node=hex(node), tag=name, local=local)
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
704 return
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
705
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
706 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
707 fp = repo.wvfs(b'.hgtags', b'rb+')
49306
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49248
diff changeset
708 except FileNotFoundError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
709 fp = repo.wvfs(b'.hgtags', b'ab')
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
710 else:
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
711 prevtags = fp.read()
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
712
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
713 # committed tags are stored in UTF-8
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
714 writetags(fp, names, encoding.fromlocal, prevtags)
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
715
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
716 fp.close()
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
717
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
718 repo.invalidatecaches()
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
719
50036
bb6eaa65d12a dirstate: use `dirstate.change_files` to scope the change in `tag`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49580
diff changeset
720 with repo.dirstate.changing_files(repo):
bb6eaa65d12a dirstate: use `dirstate.change_files` to scope the change in `tag`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49580
diff changeset
721 if b'.hgtags' not in repo.dirstate:
bb6eaa65d12a dirstate: use `dirstate.change_files` to scope the change in `tag`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49580
diff changeset
722 repo[None].add([b'.hgtags'])
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
723
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
724 m = matchmod.exact([b'.hgtags'])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
725 tagnode = repo.commit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
726 message, user, date, extra=extra, match=m, editor=editor
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
727 )
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
728
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
729 for name in names:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
730 repo.hook(b'tag', node=hex(node), tag=name, local=local)
31668
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
731
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
732 return tagnode
7d0459706716 tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31360
diff changeset
733
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
734
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
735 _fnodescachefile = b'hgtagsfnodes1'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
736 _fnodesrecsize = 4 + 20 # changeset fragment + filenode
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
737 _fnodesmissingrec = b'\xff' * 24
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
738
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
739
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48913
diff changeset
740 class hgtagsfnodescache:
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
741 """Persistent cache mapping revisions to .hgtags filenodes.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
742
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
743 The cache is an array of records. Each item in the array corresponds to
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
744 a changelog revision. Values in the array contain the first 4 bytes of
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
745 the node hash and the 20 bytes .hgtags filenode for that revision.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
746
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
747 The first 4 bytes are present as a form of verification. Repository
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
748 stripping and rewriting may change the node at a numeric revision in the
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
749 changelog. The changeset fragment serves as a verifier to detect
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
750 rewriting. This logic is shared with the rev branch cache (see
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
751 branchmap.py).
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
752
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
753 The instance holds in memory the full cache content but entries are
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
754 only parsed on read.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
755
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
756 Instances behave like lists. ``c[i]`` works where i is a rev or
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
757 changeset node. Missing indexes are populated automatically on access.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
758 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
759
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
760 def __init__(self, repo):
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
761 assert repo.filtername is None
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
762
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
763 self._repo = repo
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
764
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
765 # Only for reporting purposes.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
766 self.lookupcount = 0
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
767 self.hitcount = 0
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
768
29039
e3055b46ed1b tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents: 29038
diff changeset
769 try:
33537
709dde1c5dd5 cachevfs: migration the tags fnode cache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents: 33536
diff changeset
770 data = repo.cachevfs.read(_fnodescachefile)
29039
e3055b46ed1b tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents: 29038
diff changeset
771 except (OSError, IOError):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
772 data = b""
31346
2a18e9e6ca43 py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents: 31025
diff changeset
773 self._raw = bytearray(data)
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
774
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
775 # The end state of self._raw is an array that is of the exact length
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
776 # required to hold a record for every revision in the repository.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
777 # We truncate or extend the array as necessary. self._dirtyoffset is
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
778 # defined to be the start offset at which we need to write the output
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
779 # file. This offset is also adjusted when new entries are calculated
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
780 # for array members.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
781 cllen = len(repo.changelog)
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
782 wantedlen = cllen * _fnodesrecsize
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
783 rawlen = len(self._raw)
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
784
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
785 self._dirtyoffset = None
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
786
44306
a0ec05d93c8e cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents: 44292
diff changeset
787 rawlentokeep = min(
44351
8ec186c1ccfe tags: use modern // operator for division
Augie Fackler <augie@google.com>
parents: 44306
diff changeset
788 wantedlen, (rawlen // _fnodesrecsize) * _fnodesrecsize
44306
a0ec05d93c8e cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents: 44292
diff changeset
789 )
44292
f5a7cf0adb12 tags: behave better if a tags cache entry is partially written
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43689
diff changeset
790 if rawlen > rawlentokeep:
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
791 # There's no easy way to truncate array instances. This seems
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
792 # slightly less evil than copying a potentially large array slice.
44292
f5a7cf0adb12 tags: behave better if a tags cache entry is partially written
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43689
diff changeset
793 for i in range(rawlen - rawlentokeep):
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
794 self._raw.pop()
44292
f5a7cf0adb12 tags: behave better if a tags cache entry is partially written
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43689
diff changeset
795 rawlen = len(self._raw)
f5a7cf0adb12 tags: behave better if a tags cache entry is partially written
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43689
diff changeset
796 self._dirtyoffset = rawlen
f5a7cf0adb12 tags: behave better if a tags cache entry is partially written
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43689
diff changeset
797 if rawlen < wantedlen:
f5a7cf0adb12 tags: behave better if a tags cache entry is partially written
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43689
diff changeset
798 if self._dirtyoffset is None:
f5a7cf0adb12 tags: behave better if a tags cache entry is partially written
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43689
diff changeset
799 self._dirtyoffset = rawlen
46495
5aac1a1a5beb tagcache: distinguish between invalid and missing entries
Matt Harbison <matt_harbison@yahoo.com>
parents: 45942
diff changeset
800 # TODO: zero fill entire record, because it's invalid not missing?
44292
f5a7cf0adb12 tags: behave better if a tags cache entry is partially written
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents: 43689
diff changeset
801 self._raw.extend(b'\xff' * (wantedlen - rawlen))
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
802
51598
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
803 def getfnode(self, node, computemissing=True, rev=None):
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
804 """Obtain the filenode of the .hgtags file at a specified revision.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
805
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
806 If the value is in the cache, the entry will be validated and returned.
25380
eaa456c5e699 tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25087
diff changeset
807 Otherwise, the filenode will be computed and returned unless
46495
5aac1a1a5beb tagcache: distinguish between invalid and missing entries
Matt Harbison <matt_harbison@yahoo.com>
parents: 45942
diff changeset
808 "computemissing" is False. In that case, None will be returned if
5aac1a1a5beb tagcache: distinguish between invalid and missing entries
Matt Harbison <matt_harbison@yahoo.com>
parents: 45942
diff changeset
809 the entry is missing or False if the entry is invalid without
25380
eaa456c5e699 tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25087
diff changeset
810 any potentially expensive computation being performed.
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
811
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
812 If an .hgtags does not exist at the specified revision, nullid is
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
813 returned.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
814 """
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
815 if node == self._repo.nullid:
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
816 return node
42236
2930b31383af hgtagsfnodescache: handle nullid lookup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41841
diff changeset
817
51598
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
818 if rev is None:
2664cacd2457 tags-cache: directly operate on rev-num warming hgtagsfnodescache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51597
diff changeset
819 rev = self._repo.changelog.rev(node)
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
820
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
821 self.lookupcount += 1
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
822
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
823 offset = rev * _fnodesrecsize
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
824 record = b'%s' % self._raw[offset : offset + _fnodesrecsize]
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
825 properprefix = node[0:4]
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
826
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
827 # Validate and return existing entry.
45787
225e513c444e tags: add safety check for len(record) while reading hgtagsfnodescache
Pulkit Goyal <7895pulkit@gmail.com>
parents: 45435
diff changeset
828 if record != _fnodesmissingrec and len(record) == _fnodesrecsize:
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
829 fileprefix = record[0:4]
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
830
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
831 if fileprefix == properprefix:
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
832 self.hitcount += 1
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
833 return record[4:]
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
834
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
835 # Fall through.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
836
25380
eaa456c5e699 tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25087
diff changeset
837 # If we get here, the entry is either missing or invalid.
eaa456c5e699 tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25087
diff changeset
838
eaa456c5e699 tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25087
diff changeset
839 if not computemissing:
46495
5aac1a1a5beb tagcache: distinguish between invalid and missing entries
Matt Harbison <matt_harbison@yahoo.com>
parents: 45942
diff changeset
840 if record != _fnodesmissingrec:
5aac1a1a5beb tagcache: distinguish between invalid and missing entries
Matt Harbison <matt_harbison@yahoo.com>
parents: 45942
diff changeset
841 return False
25380
eaa456c5e699 tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25087
diff changeset
842 return None
eaa456c5e699 tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25087
diff changeset
843
46652
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
844 fnode = self._computefnode(node)
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
845 self._writeentry(offset, properprefix, fnode)
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
846 return fnode
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
847
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
848 def _computefnode(self, node):
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
849 """Finds the tag filenode for a node which is missing or invalid
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
850 in cache"""
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
851 ctx = self._repo[node]
75832107ec07 hgtagsfnodes: refactor code to compute fnode into separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46495
diff changeset
852 rev = ctx.rev()
42237
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
853 fnode = None
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
854 cl = self._repo.changelog
51780
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
855 ml = self._repo.manifestlog
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
856 mctx = ctx.manifestctx()
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
857 base_values = {}
42237
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
858 p1rev, p2rev = cl._uncheckedparentrevs(rev)
51780
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
859 m_p1_node, m_p2_node = mctx.parents
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
860 if p1rev != nullrev:
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
861 p1_node = cl.node(p1rev)
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
862 fnode = self.getfnode(p1_node, computemissing=False)
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
863 # when unknown, fnode is None or False
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
864 if fnode:
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
865 p1_manifest_rev = ml.rev(m_p1_node)
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
866 base_values[p1_manifest_rev] = fnode
42237
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
867 if p2rev != nullrev:
51780
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
868 p2_node = cl.node(p2rev)
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
869 fnode = self.getfnode(p2_node, computemissing=False)
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
870 # when unknown, fnode is None or False
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
871 if fnode:
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
872 p2_manifest_rev = ml.rev(m_p2_node)
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
873 base_values[p2_manifest_rev] = fnode
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
874 # XXX: Beware that using delta to speed things up here is actually
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
875 # buggy as it will fails to detect a `.hgtags` deletion. That buggy
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
876 # behavior has been cargo culted from the previous version of this code
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
877 # as "in practice this seems fine" and not using delta is just too
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
878 # slow.
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
879 #
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
880 # However note that we only consider delta from p1 or p2 because it is
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
881 # far less likely to have a .hgtags delete in a child than missing from
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
882 # one branch to another. As the delta chain construction keep being
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
883 # optimized, it means we will not use delta as often as we could.
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
884 if base_values:
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
885 base, m = mctx.read_any_fast_delta(base_values)
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
886 fnode = m.get(b'.hgtags')
42237
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
887 if fnode is None:
51780
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
888 if base is not None:
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
889 fnode = base_values[base]
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
890 else:
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
891 # No delta and .hgtags file on this revision.
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
892 fnode = self._repo.nullid
852bd109dd55 manifest: use `read_any_fast_delta` for tag rev cache computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51703
diff changeset
893 else:
42237
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
894 # Populate missing entry.
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
895 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
896 fnode = ctx.filenode(b'.hgtags')
42237
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
897 except error.LookupError:
9f45d3d526f9 hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42236
diff changeset
898 # No .hgtags file on this revision.
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
899 fnode = self._repo.nullid
25381
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
900 return fnode
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
901
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
902 def setfnode(self, node, fnode):
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
903 """Set the .hgtags filenode for a given changeset."""
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
904 assert len(fnode) == 20
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
905 ctx = self._repo[node]
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
906
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
907 # Do a lookup first to avoid writing if nothing has changed.
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
908 if self.getfnode(ctx.node(), computemissing=False) == fnode:
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
909 return
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
910
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
911 self._writeentry(ctx.rev() * _fnodesrecsize, node[0:4], fnode)
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
912
46656
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
913 def refresh_invalid_nodes(self, nodes):
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
914 """recomputes file nodes for a given set of nodes which has unknown
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
915 filenodes for them in the cache
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
916 Also updates the in-memory cache with the correct filenode.
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
917 Caller needs to take care about calling `.write()` so that updates are
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
918 persisted.
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
919 Returns a map {node: recomputed fnode}
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
920 """
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
921 fixed_nodemap = {}
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
922 for node in nodes:
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
923 fnode = self._computefnode(node)
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
924 fixed_nodemap[node] = fnode
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
925 self.setfnode(node, fnode)
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
926 return fixed_nodemap
9a31f65381ae tags: validate nodes in _getfnodes() and update cache in case of unknown nodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46652
diff changeset
927
25381
47edeff19139 tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25380
diff changeset
928 def _writeentry(self, offset, prefix, fnode):
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
929 # Slices on array instances only accept other array.
31346
2a18e9e6ca43 py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents: 31025
diff changeset
930 entry = bytearray(prefix + fnode)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
931 self._raw[offset : offset + _fnodesrecsize] = entry
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
932 # self._dirtyoffset could be None.
36277
18106c3bc94a tags: don't feed both int and None to min()
Augie Fackler <augie@google.com>
parents: 35828
diff changeset
933 self._dirtyoffset = min(self._dirtyoffset or 0, offset or 0)
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
934
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
935 def write(self):
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
936 """Perform all necessary writes to cache file.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
937
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
938 This may no-op if no writes are needed or if a write lock could
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
939 not be obtained.
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
940 """
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
941 if self._dirtyoffset is None:
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
942 return
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
943
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
944 data = self._raw[self._dirtyoffset :]
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
945 if not data:
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
946 return
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
947
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
948 repo = self._repo
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
949
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
950 try:
45435
64de86fd0984 tags: take lock instead of wlock before writing hgtagsfnodes1 cache
Pulkit Goyal <7895pulkit@gmail.com>
parents: 44351
diff changeset
951 lock = repo.lock(wait=False)
24806
61aea11fb83d tags: do not abort if failed to write lock file to save cache
Yuya Nishihara <yuya@tcha.org>
parents: 24763
diff changeset
952 except error.LockError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
953 repo.ui.log(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
954 b'tagscache',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
955 b'not writing .hg/cache/%s because '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
956 b'lock cannot be acquired\n' % _fnodescachefile,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
957 )
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
958 return
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
959
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
960 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
961 f = repo.cachevfs.open(_fnodescachefile, b'ab')
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
962 try:
25087
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
963 # if the file has been truncated
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
964 actualoffset = f.tell()
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
965 if actualoffset < self._dirtyoffset:
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
966 self._dirtyoffset = actualoffset
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
967 data = self._raw[self._dirtyoffset :]
25087
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
968 f.seek(self._dirtyoffset)
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
969 f.truncate()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
970 repo.ui.log(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
971 b'tagscache',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
972 b'writing %d bytes to cache/%s\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
973 % (len(data), _fnodescachefile),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
974 )
25087
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
975 f.write(data)
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
976 self._dirtyoffset = None
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
977 finally:
559f24e3957d tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents: 24806
diff changeset
978 f.close()
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25381
diff changeset
979 except (IOError, OSError) as inst:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
980 repo.ui.log(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
981 b'tagscache',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
982 b"couldn't write cache/%s: %s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
983 % (_fnodescachefile, stringutil.forcebytestr(inst)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42567
diff changeset
984 )
24735
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
985 finally:
07200e3332a1 tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24532
diff changeset
986 lock.release()
50938
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
987
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
988
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
989 def clear_cache_on_disk(repo):
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
990 """function used by the perf extension to "tags" cache"""
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
991 repo.cachevfs.tryunlink(_filename(repo))
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
992
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
993
51152
6a78b5a1d1ab perf-tags: fix clear_cache_fnodes to actually clear that cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50942
diff changeset
994 # a small attribute to help `hg perf::tags` to detect a fixed version.
6a78b5a1d1ab perf-tags: fix clear_cache_fnodes to actually clear that cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50942
diff changeset
995 clear_cache_fnodes_is_working = True
6a78b5a1d1ab perf-tags: fix clear_cache_fnodes to actually clear that cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50942
diff changeset
996
6a78b5a1d1ab perf-tags: fix clear_cache_fnodes to actually clear that cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50942
diff changeset
997
50938
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
998 def clear_cache_fnodes(repo):
f02b62b7b056 perf: introduce more cache invalidation option in perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50036
diff changeset
999 """function used by the perf extension to clear "file node cache"""
51152
6a78b5a1d1ab perf-tags: fix clear_cache_fnodes to actually clear that cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50942
diff changeset
1000 repo.cachevfs.tryunlink(_fnodescachefile)
50939
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1001
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1002
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1003 def forget_fnodes(repo, revs):
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1004 """function used by the perf extension to prune some entries from the fnodes
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1005 cache"""
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1006 missing_1 = b'\xff' * 4
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1007 missing_2 = b'\xff' * 20
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1008 cache = hgtagsfnodescache(repo.unfiltered())
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1009 for r in revs:
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1010 cache._writeentry(r * _fnodesrecsize, missing_1, missing_2)
e4c4adb694f5 perf: add a `--clear-fnode-cache-rev` argument to perf::tags
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50938
diff changeset
1011 cache.write()