##// END OF EJS Templates
tag: handle .hgtags and .hg/localtags with missing final newline (issue 601)...
Bryan O'Sullivan -
r4932:f0c25ed4 default
parent child Browse files
Show More
@@ -118,22 +118,43 b' class localrepository(repo.repository):'
118
118
119 self.hook('pretag', throw=True, node=hex(node), tag=name, local=local)
119 self.hook('pretag', throw=True, node=hex(node), tag=name, local=local)
120
120
121 def writetag(fp, name, munge, prevtags):
122 if prevtags and prevtags[-1] != '\n':
123 fp.write('\n')
124 fp.write('%s %s\n' % (hex(node), munge and munge(name) or name))
125 fp.close()
126 self.hook('tag', node=hex(node), tag=name, local=local)
127
128 prevtags = ''
121 if local:
129 if local:
130 try:
131 fp = self.opener('localtags', 'r+')
132 except IOError, err:
133 fp = self.opener('localtags', 'a')
134 else:
135 prevtags = fp.read()
136
122 # local tags are stored in the current charset
137 # local tags are stored in the current charset
123 self.opener('localtags', 'a').write('%s %s\n' % (hex(node), name))
138 writetag(fp, name, None, prevtags)
124 self.hook('tag', node=hex(node), tag=name, local=local)
125 return
139 return
126
140
141 if use_dirstate:
142 try:
143 fp = self.wfile('.hgtags', 'rb+')
144 except IOError, err:
145 fp = self.wfile('.hgtags', 'ab')
146 else:
147 prevtags = fp.read()
148 else:
149 try:
150 prevtags = self.filectx('.hgtags', parent).data()
151 except revlog.LookupError:
152 pass
153 fp = self.wfile('.hgtags', 'wb')
154
127 # committed tags are stored in UTF-8
155 # committed tags are stored in UTF-8
128 line = '%s %s\n' % (hex(node), util.fromlocal(name))
156 writetag(fp, name, util.fromlocal, prevtags)
129 if use_dirstate:
157
130 self.wfile('.hgtags', 'ab').write(line)
131 else:
132 try:
133 ntags = self.filectx('.hgtags', parent).data()
134 except revlog.LookupError:
135 ntags = ''
136 self.wfile('.hgtags', 'wb').write(ntags + line)
137 if use_dirstate and self.dirstate.state('.hgtags') == '?':
158 if use_dirstate and self.dirstate.state('.hgtags') == '?':
138 self.add(['.hgtags'])
159 self.add(['.hgtags'])
139
160
@@ -40,6 +40,7 b' adding file changes'
40 added 3 changesets with 2 changes to 2 files
40 added 3 changesets with 2 changes to 2 files
41 (run 'hg update' to get a working copy)
41 (run 'hg update' to get a working copy)
42 pretag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a
42 pretag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a
43 tag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a
43 precommit hook: HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
44 precommit hook: HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
44 pretxncommit hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
45 pretxncommit hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
45 4:8ea2ef7ad3e8
46 4:8ea2ef7ad3e8
@@ -27,4 +27,17 b' cat .hg/localtags'
27 hg tag -l 'xx
27 hg tag -l 'xx
28 newline'
28 newline'
29 hg tag -l 'xx:xx'
29 hg tag -l 'xx:xx'
30 true
30
31 echo % issue 601
32 mv .hg/localtags .hg/ltags
33 head -1 .hg/ltags | tr -d '\n' > .hg/localtags
34 cat .hg/localtags
35 hg tag -l localnewline
36 cat .hg/localtags
37
38 mv .hgtags hgtags
39 head -1 hgtags | tr -d '\n' > .hgtags
40 hg ci -d '1000000 0' -m'broken manual edit of .hgtags'
41 cat .hgtags
42 hg tag -d '1000000 0' newline
43 cat .hgtags
@@ -30,3 +30,8 b' 0acdaf8983679e0aac16e811534eb49d7ee1f2b4'
30 3ecf002a1c572a2f3bb4e665417e60fca65bbd42 bleah1
30 3ecf002a1c572a2f3bb4e665417e60fca65bbd42 bleah1
31 abort: '\n' cannot be used in a tag name
31 abort: '\n' cannot be used in a tag name
32 abort: ':' cannot be used in a tag name
32 abort: ':' cannot be used in a tag name
33 % issue 601
34 3ecf002a1c572a2f3bb4e665417e60fca65bbd42 bleah13ecf002a1c572a2f3bb4e665417e60fca65bbd42 bleah1
35 f68b039e72eacbb2e68b0543e1f6e50990aa2bb5 localnewline
36 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar0acdaf8983679e0aac16e811534eb49d7ee1f2b4 foobar
37 6ae703d793c8b1f097116869275ecd97b2977a2b newline
General Comments 0
You need to be logged in to leave comments. Login now