##// END OF EJS Templates
move most of tag code to localrepository class.
Vadim Gelfer -
r2601:00fc88b0 default
parent child Browse files
Show More
@@ -2653,35 +2653,8 b' def tag(ui, repo, name, rev_=None, **opt'
2653 else:
2653 else:
2654 r = hex(repo.changelog.tip())
2654 r = hex(repo.changelog.tip())
2655
2655
2656 disallowed = (revrangesep, '\r', '\n')
2656 repo.tag(name, r, opts['local'], opts['message'], opts['user'],
2657 for c in disallowed:
2657 opts['date'])
2658 if c in name:
2659 raise util.Abort(_("%s cannot be used in a tag name") % repr(c))
2660
2661 repo.hook('pretag', throw=True, node=r, tag=name,
2662 local=int(not not opts['local']))
2663
2664 if opts['local']:
2665 repo.opener("localtags", "a").write("%s %s\n" % (r, name))
2666 repo.hook('tag', node=r, tag=name, local=1)
2667 return
2668
2669 for x in repo.changes():
2670 if ".hgtags" in x:
2671 raise util.Abort(_("working copy of .hgtags is changed "
2672 "(please commit .hgtags manually)"))
2673
2674 repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name))
2675 if repo.dirstate.state(".hgtags") == '?':
2676 repo.add([".hgtags"])
2677
2678 message = (opts['message'] or
2679 _("Added tag %s for changeset %s") % (name, r))
2680 try:
2681 repo.commit([".hgtags"], message, opts['user'], opts['date'])
2682 repo.hook('tag', node=r, tag=name, local=0)
2683 except ValueError, inst:
2684 raise util.Abort(str(inst))
2685
2658
2686 def tags(ui, repo):
2659 def tags(ui, repo):
2687 """list repository tags
2660 """list repository tags
@@ -162,6 +162,52 b' class localrepository(object):'
162 r = runhook(hname, cmd) or r
162 r = runhook(hname, cmd) or r
163 return r
163 return r
164
164
165 tag_disallowed = ':\r\n'
166
167 def tag(self, name, node, local=False, message=None, user=None, date=None):
168 '''tag a revision with a symbolic name.
169
170 if local is True, the tag is stored in a per-repository file.
171 otherwise, it is stored in the .hgtags file, and a new
172 changeset is committed with the change.
173
174 keyword arguments:
175
176 local: whether to store tag in non-version-controlled file
177 (default False)
178
179 message: commit message to use if committing
180
181 user: name of user to use if committing
182
183 date: date tuple to use if committing'''
184
185 for c in self.tag_disallowed:
186 if c in name:
187 raise util.Abort(_('%r cannot be used in a tag name') % c)
188
189 self.hook('pretag', throw=True, node=node, tag=name, local=local)
190
191 if local:
192 self.opener('localtags', 'a').write('%s %s\n' % (node, name))
193 self.hook('tag', node=node, tag=name, local=local)
194 return
195
196 for x in self.changes():
197 if '.hgtags' in x:
198 raise util.Abort(_('working copy of .hgtags is changed '
199 '(please commit .hgtags manually)'))
200
201 self.wfile('.hgtags', 'ab').write('%s %s\n' % (node, name))
202 if self.dirstate.state('.hgtags') == '?':
203 self.add(['.hgtags'])
204
205 if not message:
206 message = _('Added tag %s for changeset %s') % (name, node)
207
208 self.commit(['.hgtags'], message, user, date)
209 self.hook('tag', node=node, tag=name, local=local)
210
165 def tags(self):
211 def tags(self):
166 '''return a mapping of tag to node'''
212 '''return a mapping of tag to node'''
167 if not self.tagscache:
213 if not self.tagscache:
@@ -378,6 +378,13 b' def system(cmd, environ={}, cwd=None, on'
378 if command fails and onerr is None, return status. if ui object,
378 if command fails and onerr is None, return status. if ui object,
379 print error message and return status, else raise onerr object as
379 print error message and return status, else raise onerr object as
380 exception.'''
380 exception.'''
381 def py2shell(val):
382 'convert python object into string that is useful to shell'
383 if val in (None, False):
384 return '0'
385 if val == True:
386 return '1'
387 return str(val)
381 oldenv = {}
388 oldenv = {}
382 for k in environ:
389 for k in environ:
383 oldenv[k] = os.environ.get(k)
390 oldenv[k] = os.environ.get(k)
@@ -385,7 +392,7 b' def system(cmd, environ={}, cwd=None, on'
385 oldcwd = os.getcwd()
392 oldcwd = os.getcwd()
386 try:
393 try:
387 for k, v in environ.iteritems():
394 for k, v in environ.iteritems():
388 os.environ[k] = str(v)
395 os.environ[k] = py2shell(v)
389 if cwd is not None and oldcwd != cwd:
396 if cwd is not None and oldcwd != cwd:
390 os.chdir(cwd)
397 os.chdir(cwd)
391 rc = os.system(cmd)
398 rc = os.system(cmd)
General Comments 0
You need to be logged in to leave comments. Login now