Mercurial > hg
annotate mercurial/tags.py @ 42530:dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
For the purpose of handling states for various multistep operations like
`hg graft`, `hg histedit`, `hg bisect` et al a new class called statecheck
is created .This will help in having a unified approach towards these commands
and handle them with ease.
The class takes in 4 basic arguments which include the name of the command, the
name of the state file associated with it , clearable flag , allowcommit flag.
This also also adds the support of`checkunfinished()` and
`clearunfinished()` to the class.
Tests remain unchanged.
Differential Revision: https://phab.mercurial-scm.org/D6501
author | Taapas Agrawal <taapas2897@gmail.com> |
---|---|
date | Sun, 09 Jun 2019 00:43:36 +0530 |
parents | 6770df6e4365 |
children | 4eaf7197a740 |
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 # |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
3 # Copyright 2009 Matt Mackall <mpm@selenic.com> |
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 | 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 |
25982
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
13 from __future__ import absolute_import |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
14 |
14038
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
15 import errno |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
16 |
25982
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
17 from .node import ( |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
18 bin, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
19 hex, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
20 nullid, |
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 _ |
25982
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
25 from . import ( |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
26 encoding, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
27 error, |
31668
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
28 match as matchmod, |
31025
6cf2857526c7
scmutil: proxy revrange() through repo to break import cycles
Yuya Nishihara <yuya@tcha.org>
parents:
30975
diff
changeset
|
29 scmutil, |
25982
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
30 util, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
31 ) |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36543
diff
changeset
|
32 from .utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36543
diff
changeset
|
33 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36543
diff
changeset
|
34 ) |
25982
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
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 |
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
|
85 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
|
86 """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
|
87 |
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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 |
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
|
97 def _nulltonone(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
|
98 """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
|
99 |
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
|
100 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
|
101 translating that 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
|
102 if value == nullid: |
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
|
103 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
|
104 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
|
105 |
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
|
106 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
|
107 """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
|
108 |
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
|
109 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
|
110 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
|
111 ('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
|
112 ('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
|
113 ('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
|
114 """ |
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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
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
|
120 # 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
|
121 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
|
122 for tag, (new, __) in newtags.items(): |
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
|
123 new = _nulltonone(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
|
124 old, __ = oldtags.pop(tag, (None, 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
|
125 old = _nulltonone(old) |
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
|
126 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
|
127 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
|
128 # 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
|
129 for tag, (old, __) in oldtags.items(): |
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 old = _nulltonone(old) |
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 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
|
132 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
|
133 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
|
134 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
|
135 |
31996
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
136 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
|
137 """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
|
138 |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
139 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
|
140 |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
141 <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
|
142 |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
143 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
|
144 -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
|
145 +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
|
146 -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
|
147 +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
|
148 |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
149 Example: |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
150 |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
151 +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
|
152 |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
153 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
|
154 """ |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
155 add = '+A %s %s\n' |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
156 remove = '-R %s %s\n' |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
157 updateold = '-M %s %s\n' |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
158 updatenew = '+M %s %s\n' |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
159 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
|
160 # 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
|
161 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
|
162 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
|
163 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
|
164 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
|
165 # 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 else: |
e6e1884df298
track-tags: write all tag changes to a file
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31995
diff
changeset
|
171 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
|
172 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
|
173 |
31706
63d4deda1b31
tags: do not feed dictionaries to 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31705
diff
changeset
|
174 def findglobaltags(ui, repo): |
31709
c34c170b25f3
tags: only return 'alltags' in 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31708
diff
changeset
|
175 '''Find global tags in a repo: return a tagsmap |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
176 |
31709
c34c170b25f3
tags: only return 'alltags' in 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31708
diff
changeset
|
177 tagsmap: tag name to (node, hist) 2-tuples. |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
178 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
179 The tags cache is read and updated as a side-effect of calling. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
180 ''' |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
181 (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
|
182 if cachetags is not None: |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
183 assert not shouldwrite |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
184 # 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
|
185 # 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
|
186 # 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
|
187 alltags = {} |
31709
c34c170b25f3
tags: only return 'alltags' in 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31708
diff
changeset
|
188 _updatetags(cachetags, alltags) |
c34c170b25f3
tags: only return 'alltags' in 'findglobaltags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31708
diff
changeset
|
189 return alltags |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
190 |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
191 for head in reversed(heads): # oldest to newest |
41759
aaad36b88298
cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents:
41676
diff
changeset
|
192 assert head in repo.changelog.nodemap, ( |
aaad36b88298
cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents:
41676
diff
changeset
|
193 "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
|
194 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
|
195 alltags = _tagsfromfnodes(ui, repo, fnodes) |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
196 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
197 # and update the cache (if necessary) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
198 if shouldwrite: |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
199 _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
|
200 return alltags |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
201 |
31711
472d726c1afd
tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31710
diff
changeset
|
202 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
|
203 """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
|
204 |
472d726c1afd
tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31710
diff
changeset
|
205 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
|
206 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
|
207 results.""" |
472d726c1afd
tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31710
diff
changeset
|
208 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
|
209 fnodes = [] |
472d726c1afd
tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31710
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 return fnodes |
472d726c1afd
tags: extract filenode filtering into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31710
diff
changeset
|
216 |
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
|
217 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
|
218 """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
|
219 |
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 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
|
221 |
510267cf6c58
tags: extract tags computation from fnodes into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31709
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 if fctx is 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
|
227 fctx = repo.filectx('.hgtags', fileid=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
|
228 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
|
229 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
|
230 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
|
231 _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
|
232 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
|
233 |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
234 def readlocaltags(ui, repo, alltags, tagtypes): |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
235 '''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
|
236 try: |
23877
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
23139
diff
changeset
|
237 data = repo.vfs.read("localtags") |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25381
diff
changeset
|
238 except IOError as inst: |
14038
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
239 if inst.errno != errno.ENOENT: |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
240 raise |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
241 return |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
242 |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
243 # 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
|
244 # 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
|
245 filetags = _readtags( |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
246 ui, repo, data.splitlines(), "localtags", |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
247 recode=encoding.fromlocal) |
21823
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
248 |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
249 # 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
|
250 cl = repo.changelog |
35828
553a98a436cf
tags: explicitly grab list of dict keys
Augie Fackler <augie@google.com>
parents:
34015
diff
changeset
|
251 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
|
252 try: |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
253 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
|
254 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
|
255 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
|
256 |
31707
9cd640e5c1ba
tags: reorder argument of '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31706
diff
changeset
|
257 _updatetags(filetags, alltags, 'local', tagtypes) |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
258 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
259 def _readtaghist(ui, repo, lines, fn, recode=None, calcnodelines=False): |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
260 '''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
|
261 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
262 This function returns two sortdicts with similar information: |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
263 |
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
21892
diff
changeset
|
264 - 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
|
265 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
|
266 - 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
|
267 - 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
|
268 order). All node ids are binary, not hex. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
269 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
270 - 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
|
271 [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
|
272 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
273 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
|
274 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
|
275 performance in cases where the line numbers are not needed. |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
276 ''' |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
277 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
278 bintaghist = util.sortdict() |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
279 hextaglines = util.sortdict() |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
280 count = 0 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
281 |
29038
a9dd92c48a1c
tags: silence cache parsing errors
Matt Mackall <mpm@selenic.com>
parents:
26945
diff
changeset
|
282 def dbg(msg): |
36399
a24c57f1f5c3
py3: use '%d' for integers instead of '%s'
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36396
diff
changeset
|
283 ui.debug("%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
|
284 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
285 for nline, line in enumerate(lines): |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
286 count += 1 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
287 if not line: |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
288 continue |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
289 try: |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
290 (nodehex, name) = line.split(" ", 1) |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
291 except ValueError: |
29038
a9dd92c48a1c
tags: silence cache parsing errors
Matt Mackall <mpm@selenic.com>
parents:
26945
diff
changeset
|
292 dbg("cannot parse entry") |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
293 continue |
9152
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
294 name = name.strip() |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
295 if recode: |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
296 name = recode(name) |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
297 try: |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
298 nodebin = bin(nodehex) |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
299 except TypeError: |
29038
a9dd92c48a1c
tags: silence cache parsing errors
Matt Mackall <mpm@selenic.com>
parents:
26945
diff
changeset
|
300 dbg("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
|
301 continue |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
302 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
303 # update filetags |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
304 if calcnodelines: |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
305 # map tag name to a list of line numbers |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
306 if name not in hextaglines: |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
307 hextaglines[name] = [] |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
308 hextaglines[name].append([nodehex, nline]) |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
309 continue |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
310 # map tag name to (node, hist) |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
311 if name not in bintaghist: |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
312 bintaghist[name] = [] |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
313 bintaghist[name].append(nodebin) |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
314 return bintaghist, hextaglines |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
315 |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
316 def _readtags(ui, repo, lines, fn, recode=None, calcnodelines=False): |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
317 '''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
|
318 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
319 Returns a mapping from tag name to (node, hist). |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
320 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
321 "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
|
322 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
|
323 All node ids are binary, not hex. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
324 ''' |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
325 filetags, nodelines = _readtaghist(ui, repo, lines, fn, recode=recode, |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
326 calcnodelines=calcnodelines) |
26945
8a256cee72c8
tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25982
diff
changeset
|
327 # 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
|
328 # 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
|
329 # 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
|
330 newtags = util.sortdict() |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
331 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
|
332 newtags[tag] = (taghist[-1], taghist[:-1]) |
8a256cee72c8
tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25982
diff
changeset
|
333 return newtags |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
334 |
31708
d0e7c70f14b7
tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31707
diff
changeset
|
335 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
|
336 """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
|
337 |
d0e7c70f14b7
tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31707
diff
changeset
|
338 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
|
339 |
d0e7c70f14b7
tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31707
diff
changeset
|
340 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
|
341 "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
|
342 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
|
343 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
|
344 assert tagtypes is None |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
345 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
346 for name, nodehist in filetags.iteritems(): |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
347 if name not in alltags: |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
348 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
|
349 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
|
350 tagtypes[name] = tagtype |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
351 continue |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
352 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
353 # we prefer alltags[name] if: |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17256
diff
changeset
|
354 # it supersedes us OR |
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17256
diff
changeset
|
355 # 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
|
356 # 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
|
357 anode, ahist = nodehist |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
358 bnode, bhist = alltags[name] |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
359 if (bnode != anode and anode in bhist and |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
360 (bnode not in ahist or len(bhist) > len(ahist))): |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
361 anode = bnode |
31708
d0e7c70f14b7
tags: make argument 'tagtype' optional in '_updatetags'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31707
diff
changeset
|
362 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
|
363 tagtypes[name] = tagtype |
9149
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
364 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
|
365 alltags[name] = anode, ahist |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
366 |
24737
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24735
diff
changeset
|
367 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
|
368 """name of a tagcache file for a given repo or repoview""" |
33536
ddacd0e453ae
cachevfs: migrate tagscache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33255
diff
changeset
|
369 filename = 'tags2' |
24737
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24735
diff
changeset
|
370 if repo.filtername: |
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24735
diff
changeset
|
371 filename = '%s-%s' % (filename, repo.filtername) |
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24735
diff
changeset
|
372 return filename |
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24735
diff
changeset
|
373 |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
374 def _readtagcache(ui, repo): |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
375 '''Read the tag cache. |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
376 |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
377 Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite). |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
378 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
379 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
|
380 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
|
381 None and "shouldwrite" is False. |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
382 |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
383 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
|
384 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
|
385 "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
|
386 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
|
387 filenode. "shouldwrite" is True. |
24445
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
388 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
389 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
|
390 info from each returned head. (See findglobaltags().) |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24143
diff
changeset
|
391 ''' |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
392 try: |
33536
ddacd0e453ae
cachevfs: migrate tagscache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33255
diff
changeset
|
393 cachefile = repo.cachevfs(_filename(repo), 'r') |
11066
26abd91d9e84
static-http: mimic more closely localrepo (issue2164: allow clone -r )
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10263
diff
changeset
|
394 # 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
|
395 cachelines = iter(cachefile) |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
396 except IOError: |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
397 cachefile = None |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
398 |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
399 cacherev = None |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
400 cachenode = None |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
401 cachehash = None |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
402 if cachefile: |
12758
2d754eae430c
tags: do not fail if tags.cache is corrupted (issue2444)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11352
diff
changeset
|
403 try: |
29216
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
29039
diff
changeset
|
404 validline = next(cachelines) |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
405 validline = validline.split() |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
406 cacherev = int(validline[0]) |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
407 cachenode = bin(validline[1]) |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
408 if len(validline) > 2: |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
409 cachehash = bin(validline[2]) |
14020
98f79a5c3086
tags: catch more corruption during cache parsing (issue2779)
Matt Mackall <mpm@selenic.com>
parents:
13341
diff
changeset
|
410 except Exception: |
24759
d082c6ef9ec3
tags: don't read .hgtags fnodes from tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24737
diff
changeset
|
411 # 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
|
412 pass |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
413 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
414 tipnode = repo.changelog.tip() |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
415 tiprev = len(repo.changelog) - 1 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
416 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
417 # 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
|
418 # (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
|
419 # 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
|
420 # have been destroyed by strip or rollback.) |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
421 if (cacherev == tiprev |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
422 and cachenode == tipnode |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
423 and cachehash == scmutil.filteredhash(repo, tiprev)): |
11066
26abd91d9e84
static-http: mimic more closely localrepo (issue2164: allow clone -r )
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10263
diff
changeset
|
424 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
|
425 cachefile.close() |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
426 return (None, None, None, tags, False) |
9152
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
427 if cachefile: |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
428 cachefile.close() # ignore rest of file |
9312
c5f0825c1dbb
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9152
diff
changeset
|
429 |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
430 valid = (tiprev, tipnode, scmutil.filteredhash(repo, tiprev)) |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
431 |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
432 repoheads = repo.heads() |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
433 # 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
|
434 # writing an empty cache. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
435 if repoheads == [nullid]: |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
436 return ([], {}, valid, {}, False) |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
437 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
438 # 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
|
439 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
440 # 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
|
441 # 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
|
442 # 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
|
443 # cache. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
444 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
445 # 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
|
446 |
11352
b19067ee4507
tags: remove inactive debugging code.
Greg Ward <greg-hg@gerg.ca>
parents:
11351
diff
changeset
|
447 # 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
|
448 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
449 # 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
|
450 # exposed". |
16730
dd4ce44ff53c
tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents:
16589
diff
changeset
|
451 if not len(repo.file('.hgtags')): |
dd4ce44ff53c
tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents:
16589
diff
changeset
|
452 # 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
|
453 # 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
|
454 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
|
455 |
21030
9ea132aee96c
tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19646
diff
changeset
|
456 |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
457 # 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
|
458 # 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
|
459 # 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
|
460 # file, so newheads == repoheads. |
42239
6770df6e4365
tags: avoid double-reversing a list
Martin von Zweigbergk <martinvonz@google.com>
parents:
42237
diff
changeset
|
461 # 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
|
462 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
|
463 |
5eb4d206202b
tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31669
diff
changeset
|
464 # 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
|
465 # 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
|
466 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
|
467 |
5eb4d206202b
tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31669
diff
changeset
|
468 def _getfnodes(ui, repo, nodes): |
5eb4d206202b
tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31669
diff
changeset
|
469 """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
|
470 |
5eb4d206202b
tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31669
diff
changeset
|
471 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
|
472 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
|
473 """ |
5eb4d206202b
tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31669
diff
changeset
|
474 starttime = util.timer() |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
475 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
|
476 cachefnode = {} |
42239
6770df6e4365
tags: avoid double-reversing a list
Martin von Zweigbergk <martinvonz@google.com>
parents:
42237
diff
changeset
|
477 for node in nodes: |
31788
417363736c11
tags: rename "head" to "node" where we don't care
Martin von Zweigbergk <martinvonz@google.com>
parents:
31711
diff
changeset
|
478 fnode = fnodescache.getfnode(node) |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
479 if fnode != nullid: |
31788
417363736c11
tags: rename "head" to "node" where we don't care
Martin von Zweigbergk <martinvonz@google.com>
parents:
31711
diff
changeset
|
480 cachefnode[node] = fnode |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
481 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
482 fnodescache.write() |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
483 |
30975
22fbca1d11ed
mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents:
29216
diff
changeset
|
484 duration = util.timer() - starttime |
21030
9ea132aee96c
tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19646
diff
changeset
|
485 ui.log('tagscache', |
41194
4c5864dad8b0
tags: join string that's unnecessarily split across lines
Martin von Zweigbergk <martinvonz@google.com>
parents:
37084
diff
changeset
|
486 '%d/%d cache hits/lookups in %0.4f seconds\n', |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
487 fnodescache.hitcount, fnodescache.lookupcount, duration) |
31705
5eb4d206202b
tags: extract fnode retrieval into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31669
diff
changeset
|
488 return cachefnode |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
489 |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
490 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
|
491 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
|
492 try: |
33536
ddacd0e453ae
cachevfs: migrate tagscache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33255
diff
changeset
|
493 cachefile = repo.cachevfs(filename, '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
|
494 except (OSError, IOError): |
9ff178e7b627
tags: don't crash if unable to write tag cache
Greg Ward <greg-hg@gerg.ca>
parents:
9312
diff
changeset
|
495 return |
9151
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9149
diff
changeset
|
496 |
33536
ddacd0e453ae
cachevfs: migrate tagscache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33255
diff
changeset
|
497 ui.log('tagscache', 'writing .hg/cache/%s with %d tags\n', |
24763
a698e088ad29
tags: explicitly log which tags cache file is being written
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24762
diff
changeset
|
498 filename, len(cachetags)) |
21030
9ea132aee96c
tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19646
diff
changeset
|
499 |
24760
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
500 if valid[2]: |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
501 cachefile.write('%d %s %s\n' % (valid[0], hex(valid[1]), hex(valid[2]))) |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
502 else: |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24759
diff
changeset
|
503 cachefile.write('%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
|
504 |
9152
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
505 # 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
|
506 # 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
|
507 # 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
|
508 # the cache. |
24143
7b09dbbbd502
tags: write tags cache deterministically
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23877
diff
changeset
|
509 for (name, (node, hist)) in sorted(cachetags.iteritems()): |
19646
335a558f81dc
tags: write tag overwriting history also into tag cache file (issue3911)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19108
diff
changeset
|
510 for n in hist: |
335a558f81dc
tags: write tag overwriting history also into tag cache file (issue3911)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19108
diff
changeset
|
511 cachefile.write("%s %s\n" % (hex(n), name)) |
9152
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
512 cachefile.write("%s %s\n" % (hex(node), name)) |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9151
diff
changeset
|
513 |
14662
2b30124c7d8a
tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents:
14168
diff
changeset
|
514 try: |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14662
diff
changeset
|
515 cachefile.close() |
14662
2b30124c7d8a
tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents:
14168
diff
changeset
|
516 except (OSError, IOError): |
2b30124c7d8a
tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents:
14168
diff
changeset
|
517 pass |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
518 |
31669
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
519 def tag(repo, names, node, message, local, user, date, editor=False): |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
520 '''tag a revision with one or more symbolic names. |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
521 |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
522 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
|
523 string. |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
524 |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
525 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
|
526 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
|
527 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
|
528 |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
529 keyword arguments: |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
530 |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
531 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
|
532 (default False) |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
533 |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
534 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
|
535 |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
536 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
|
537 |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
538 date: date tuple 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
|
539 |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
540 if not local: |
41676
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41194
diff
changeset
|
541 m = matchmod.exact(['.hgtags']) |
31669
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
542 if any(repo.status(match=m, unknown=True, ignored=True)): |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
543 raise error.Abort(_('working copy of .hgtags is changed'), |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
544 hint=_('please commit .hgtags manually')) |
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
545 |
33255
4f3f08262eb4
tag: make sure the repository is locked when tagging
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31996
diff
changeset
|
546 with repo.wlock(): |
4f3f08262eb4
tag: make sure the repository is locked when tagging
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31996
diff
changeset
|
547 repo.tags() # instantiate the cache |
34015
2d80e078724a
tag: use filtered repo when creating new tags (issue5539)
Denis Laxalde <denis@laxalde.org>
parents:
33537
diff
changeset
|
548 _tag(repo, names, node, message, local, user, date, |
33255
4f3f08262eb4
tag: make sure the repository is locked when tagging
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
31996
diff
changeset
|
549 editor=editor) |
31669
a719f3315366
tags: move 'repo.tag' in the 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31668
diff
changeset
|
550 |
31668
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
551 def _tag(repo, names, node, message, local, user, date, extra=None, |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
552 editor=False): |
41841
b1d07f4614a6
py3: use bytes instead of str in isinstance()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41759
diff
changeset
|
553 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
|
554 names = (names,) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
555 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
556 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
|
557 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
|
558 repo.hook('pretag', throw=True, node=hex(node), tag=name, |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
559 local=local) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
560 if name in branches: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
561 repo.ui.warn(_("warning: tag %s conflicts with existing" |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
562 " branch name\n") % name) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
563 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
564 def writetags(fp, names, munge, prevtags): |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
565 fp.seek(0, 2) |
36543
3e458c583d2c
py3: use startswith() to check existence of trailing '\n' in .hgtags file
Yuya Nishihara <yuya@tcha.org>
parents:
36399
diff
changeset
|
566 if prevtags and not prevtags.endswith('\n'): |
31668
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
567 fp.write('\n') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
568 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
|
569 if munge: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
570 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
|
571 else: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
572 m = name |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
573 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
574 if (repo._tagscache.tagtypes and |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
575 name in repo._tagscache.tagtypes): |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
576 old = repo.tags().get(name, nullid) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
577 fp.write('%s %s\n' % (hex(old), m)) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
578 fp.write('%s %s\n' % (hex(node), m)) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
579 fp.close() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
580 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
581 prevtags = '' |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
582 if local: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
583 try: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
584 fp = repo.vfs('localtags', 'r+') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
585 except IOError: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
586 fp = repo.vfs('localtags', 'a') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
587 else: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
588 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
|
589 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
590 # 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
|
591 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
|
592 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
|
593 repo.hook('tag', node=hex(node), tag=name, local=local) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
594 return |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
595 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
596 try: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
597 fp = repo.wvfs('.hgtags', 'rb+') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
598 except IOError as e: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
599 if e.errno != errno.ENOENT: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
600 raise |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
601 fp = repo.wvfs('.hgtags', 'ab') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
602 else: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
603 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
|
604 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
605 # 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
|
606 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
|
607 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
608 fp.close() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
609 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
610 repo.invalidatecaches() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
611 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
612 if '.hgtags' not in repo.dirstate: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
613 repo[None].add(['.hgtags']) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
614 |
41676
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41194
diff
changeset
|
615 m = matchmod.exact(['.hgtags']) |
31668
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
616 tagnode = repo.commit(message, user, date, extra=extra, match=m, |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
617 editor=editor) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
618 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
619 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
|
620 repo.hook('tag', node=hex(node), tag=name, local=local) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
621 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
622 return tagnode |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31360
diff
changeset
|
623 |
33537
709dde1c5dd5
cachevfs: migration the tags fnode cache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33536
diff
changeset
|
624 _fnodescachefile = 'hgtagsfnodes1' |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
625 _fnodesrecsize = 4 + 20 # changeset fragment + filenode |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
626 _fnodesmissingrec = '\xff' * 24 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
627 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
628 class hgtagsfnodescache(object): |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
629 """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
|
630 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
631 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
|
632 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
|
633 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
|
634 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
635 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
|
636 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
|
637 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
|
638 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
|
639 branchmap.py). |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
640 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
641 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
|
642 only parsed on read. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
643 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
644 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
|
645 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
|
646 """ |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
647 def __init__(self, repo): |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
648 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
|
649 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
650 self._repo = repo |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
651 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
652 # Only for reporting purposes. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
653 self.lookupcount = 0 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
654 self.hitcount = 0 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
655 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
656 |
29039
e3055b46ed1b
tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents:
29038
diff
changeset
|
657 try: |
33537
709dde1c5dd5
cachevfs: migration the tags fnode cache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33536
diff
changeset
|
658 data = repo.cachevfs.read(_fnodescachefile) |
29039
e3055b46ed1b
tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents:
29038
diff
changeset
|
659 except (OSError, IOError): |
e3055b46ed1b
tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents:
29038
diff
changeset
|
660 data = "" |
31346
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31025
diff
changeset
|
661 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
|
662 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
663 # 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
|
664 # 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
|
665 # 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
|
666 # 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
|
667 # 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
|
668 # for array members. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
669 cllen = len(repo.changelog) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
670 wantedlen = cllen * _fnodesrecsize |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
671 rawlen = len(self._raw) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
672 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
673 self._dirtyoffset = None |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
674 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
675 if rawlen < wantedlen: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
676 self._dirtyoffset = rawlen |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
677 self._raw.extend('\xff' * (wantedlen - rawlen)) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
678 elif rawlen > wantedlen: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
679 # 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
|
680 # slightly less evil than copying a potentially large array slice. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
681 for i in range(rawlen - wantedlen): |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
682 self._raw.pop() |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
683 self._dirtyoffset = len(self._raw) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
684 |
25380
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25087
diff
changeset
|
685 def getfnode(self, node, computemissing=True): |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
686 """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
|
687 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
688 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
|
689 Otherwise, the filenode will be computed and returned unless |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25087
diff
changeset
|
690 "computemissing" is False, in which case None will be returned without |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25087
diff
changeset
|
691 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
|
692 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
693 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
|
694 returned. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
695 """ |
42236
2930b31383af
hgtagsfnodescache: handle nullid lookup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41841
diff
changeset
|
696 if node == nullid: |
2930b31383af
hgtagsfnodescache: handle nullid lookup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41841
diff
changeset
|
697 return nullid |
2930b31383af
hgtagsfnodescache: handle nullid lookup
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41841
diff
changeset
|
698 |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
699 ctx = self._repo[node] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
700 rev = ctx.rev() |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
701 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
702 self.lookupcount += 1 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
703 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
704 offset = rev * _fnodesrecsize |
31346
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31025
diff
changeset
|
705 record = '%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
|
706 properprefix = node[0:4] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
707 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
708 # Validate and return existing entry. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
709 if record != _fnodesmissingrec: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
710 fileprefix = record[0:4] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
711 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
712 if fileprefix == properprefix: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
713 self.hitcount += 1 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
714 return record[4:] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
715 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
716 # Fall through. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
717 |
25380
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25087
diff
changeset
|
718 # 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
|
719 |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25087
diff
changeset
|
720 if not computemissing: |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25087
diff
changeset
|
721 return None |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25087
diff
changeset
|
722 |
42237
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
723 fnode = None |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
724 cl = self._repo.changelog |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
725 p1rev, p2rev = cl._uncheckedparentrevs(rev) |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
726 p1node = cl.node(p1rev) |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
727 p1fnode = self.getfnode(p1node, computemissing=False) |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
728 if p2rev != nullrev: |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
729 # There is some no-merge changeset where p1 is null and p2 is set |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
730 # Processing them as merge is just slower, but still gives a good |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
731 # result. |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
732 p2node = cl.node(p1rev) |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
733 p2fnode = self.getfnode(p2node, computemissing=False) |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
734 if p1fnode != p2fnode: |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
735 # we cannot rely on readfast because we don't know against what |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
736 # parent the readfast delta is computed |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
737 p1fnode = None |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
738 if p1fnode is not None: |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
739 mctx = ctx.manifestctx() |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
740 fnode = mctx.readfast().get('.hgtags') |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
741 if fnode is None: |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
742 fnode = p1fnode |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
743 if fnode is None: |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
744 # Populate missing entry. |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
745 try: |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
746 fnode = ctx.filenode('.hgtags') |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
747 except error.LookupError: |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
748 # No .hgtags file on this revision. |
9f45d3d526f9
hgtagsfnodescache: inherit fnode from parent when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42236
diff
changeset
|
749 fnode = nullid |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
750 |
25381
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
751 self._writeentry(offset, properprefix, fnode) |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
752 return fnode |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
753 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
754 def setfnode(self, node, fnode): |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
755 """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
|
756 assert len(fnode) == 20 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
757 ctx = self._repo[node] |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
758 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
759 # 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
|
760 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
|
761 return |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
762 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
763 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
|
764 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25380
diff
changeset
|
765 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
|
766 # 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
|
767 entry = bytearray(prefix + fnode) |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
768 self._raw[offset:offset + _fnodesrecsize] = entry |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
769 # 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
|
770 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
|
771 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
772 def write(self): |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
773 """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
|
774 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
775 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
|
776 not be obtained. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
777 """ |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
778 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
|
779 return |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
780 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
781 data = self._raw[self._dirtyoffset:] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
782 if not data: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
783 return |
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 repo = self._repo |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
786 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
787 try: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
788 lock = repo.wlock(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
|
789 except error.LockError: |
33537
709dde1c5dd5
cachevfs: migration the tags fnode cache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33536
diff
changeset
|
790 repo.ui.log('tagscache', 'not writing .hg/cache/%s because ' |
709dde1c5dd5
cachevfs: migration the tags fnode cache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33536
diff
changeset
|
791 'lock cannot be acquired\n' % (_fnodescachefile)) |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
792 return |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
793 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
794 try: |
33537
709dde1c5dd5
cachevfs: migration the tags fnode cache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33536
diff
changeset
|
795 f = repo.cachevfs.open(_fnodescachefile, 'ab') |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
796 try: |
25087
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
797 # if the file has been truncated |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
798 actualoffset = f.tell() |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
799 if actualoffset < self._dirtyoffset: |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
800 self._dirtyoffset = actualoffset |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
801 data = self._raw[self._dirtyoffset:] |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
802 f.seek(self._dirtyoffset) |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
803 f.truncate() |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
804 repo.ui.log('tagscache', |
33537
709dde1c5dd5
cachevfs: migration the tags fnode cache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33536
diff
changeset
|
805 'writing %d bytes to cache/%s\n' % ( |
25087
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
806 len(data), _fnodescachefile)) |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
807 f.write(data) |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
808 self._dirtyoffset = None |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
809 finally: |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
810 f.close() |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25381
diff
changeset
|
811 except (IOError, OSError) as inst: |
25087
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24806
diff
changeset
|
812 repo.ui.log('tagscache', |
33537
709dde1c5dd5
cachevfs: migration the tags fnode cache to 'cachevfs'
Boris Feld <boris.feld@octobus.net>
parents:
33536
diff
changeset
|
813 "couldn't write cache/%s: %s\n" % ( |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36543
diff
changeset
|
814 _fnodescachefile, stringutil.forcebytestr(inst))) |
24735
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
815 finally: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24532
diff
changeset
|
816 lock.release() |