##// END OF EJS Templates
tag: lock before tagging
Mads Kiilerich -
r15877:afd45993 default
parent child Browse files
Show More
@@ -5501,62 +5501,68 b' def tag(ui, repo, name1, *names, **opts)'
5501
5501
5502 Returns 0 on success.
5502 Returns 0 on success.
5503 """
5503 """
5504
5504 wlock = lock = None
5505 rev_ = "."
5505 try:
5506 names = [t.strip() for t in (name1,) + names]
5506 wlock = repo.wlock()
5507 if len(names) != len(set(names)):
5507 lock = repo.lock()
5508 raise util.Abort(_('tag names must be unique'))
5508 rev_ = "."
5509 for n in names:
5509 names = [t.strip() for t in (name1,) + names]
5510 if n in ['tip', '.', 'null']:
5510 if len(names) != len(set(names)):
5511 raise util.Abort(_("the name '%s' is reserved") % n)
5511 raise util.Abort(_('tag names must be unique'))
5512 if not n:
5513 raise util.Abort(_('tag names cannot consist entirely of whitespace'))
5514 if opts.get('rev') and opts.get('remove'):
5515 raise util.Abort(_("--rev and --remove are incompatible"))
5516 if opts.get('rev'):
5517 rev_ = opts['rev']
5518 message = opts.get('message')
5519 if opts.get('remove'):
5520 expectedtype = opts.get('local') and 'local' or 'global'
5521 for n in names:
5512 for n in names:
5522 if not repo.tagtype(n):
5513 if n in ['tip', '.', 'null']:
5523 raise util.Abort(_("tag '%s' does not exist") % n)
5514 raise util.Abort(_("the name '%s' is reserved") % n)
5524 if repo.tagtype(n) != expectedtype:
5515 if not n:
5525 if expectedtype == 'global':
5516 raise util.Abort(_('tag names cannot consist entirely of '
5526 raise util.Abort(_("tag '%s' is not a global tag") % n)
5517 'whitespace'))
5527 else:
5518 if opts.get('rev') and opts.get('remove'):
5528 raise util.Abort(_("tag '%s' is not a local tag") % n)
5519 raise util.Abort(_("--rev and --remove are incompatible"))
5529 rev_ = nullid
5520 if opts.get('rev'):
5521 rev_ = opts['rev']
5522 message = opts.get('message')
5523 if opts.get('remove'):
5524 expectedtype = opts.get('local') and 'local' or 'global'
5525 for n in names:
5526 if not repo.tagtype(n):
5527 raise util.Abort(_("tag '%s' does not exist") % n)
5528 if repo.tagtype(n) != expectedtype:
5529 if expectedtype == 'global':
5530 raise util.Abort(_("tag '%s' is not a global tag") % n)
5531 else:
5532 raise util.Abort(_("tag '%s' is not a local tag") % n)
5533 rev_ = nullid
5534 if not message:
5535 # we don't translate commit messages
5536 message = 'Removed tag %s' % ', '.join(names)
5537 elif not opts.get('force'):
5538 for n in names:
5539 if n in repo.tags():
5540 raise util.Abort(_("tag '%s' already exists "
5541 "(use -f to force)") % n)
5542 if not opts.get('local'):
5543 p1, p2 = repo.dirstate.parents()
5544 if p2 != nullid:
5545 raise util.Abort(_('uncommitted merge'))
5546 bheads = repo.branchheads()
5547 if not opts.get('force') and bheads and p1 not in bheads:
5548 raise util.Abort(_('not at a branch head (use -f to force)'))
5549 r = scmutil.revsingle(repo, rev_).node()
5550
5530 if not message:
5551 if not message:
5531 # we don't translate commit messages
5552 # we don't translate commit messages
5532 message = 'Removed tag %s' % ', '.join(names)
5553 message = ('Added tag %s for changeset %s' %
5533 elif not opts.get('force'):
5554 (', '.join(names), short(r)))
5534 for n in names:
5555
5535 if n in repo.tags():
5556 date = opts.get('date')
5536 raise util.Abort(_("tag '%s' already exists "
5557 if date:
5537 "(use -f to force)") % n)
5558 date = util.parsedate(date)
5538 if not opts.get('local'):
5559
5539 p1, p2 = repo.dirstate.parents()
5560 if opts.get('edit'):
5540 if p2 != nullid:
5561 message = ui.edit(message, ui.username())
5541 raise util.Abort(_('uncommitted merge'))
5562
5542 bheads = repo.branchheads()
5563 repo.tag(names, r, message, opts.get('local'), opts.get('user'), date)
5543 if not opts.get('force') and bheads and p1 not in bheads:
5564 finally:
5544 raise util.Abort(_('not at a branch head (use -f to force)'))
5565 release(lock, wlock)
5545 r = scmutil.revsingle(repo, rev_).node()
5546
5547 if not message:
5548 # we don't translate commit messages
5549 message = ('Added tag %s for changeset %s' %
5550 (', '.join(names), short(r)))
5551
5552 date = opts.get('date')
5553 if date:
5554 date = util.parsedate(date)
5555
5556 if opts.get('edit'):
5557 message = ui.edit(message, ui.username())
5558
5559 repo.tag(names, r, message, opts.get('local'), opts.get('user'), date)
5560
5566
5561 @command('tags', [], '')
5567 @command('tags', [], '')
5562 def tags(ui, repo):
5568 def tags(ui, repo):
@@ -320,9 +320,6 b''
320 > except:
320 > except:
321 warning: naked except clause
321 warning: naked except clause
322 mercurial/commands.py:0:
322 mercurial/commands.py:0:
323 > raise util.Abort(_('tag names cannot consist entirely of whitespace'))
324 warning: line over 80 characters
325 mercurial/commands.py:0:
326 > ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to merge)\n"))
323 > ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to merge)\n"))
327 warning: line over 80 characters
324 warning: line over 80 characters
328 mercurial/commands.py:0:
325 mercurial/commands.py:0:
General Comments 0
You need to be logged in to leave comments. Login now