hgext/fetch.py
changeset 4915 97b734fb9c6f
parent 4730 eadfaa9ec487
child 4917 126f527b3ba3
equal deleted inserted replaced
4914:9a2a73ea6135 4915:97b734fb9c6f
    17 
    17 
    18     If the pulled changes add a new head, the head is automatically
    18     If the pulled changes add a new head, the head is automatically
    19     merged, and the result of the merge is committed.  Otherwise, the
    19     merged, and the result of the merge is committed.  Otherwise, the
    20     working directory is updated.'''
    20     working directory is updated.'''
    21 
    21 
    22     def postincoming(other, modheads):
    22     def postincoming(other, modheads, lock, wlock):
    23         if modheads == 0:
    23         if modheads == 0:
    24             return 0
    24             return 0
    25         if modheads == 1:
    25         if modheads == 1:
    26             return hg.clean(repo, repo.changelog.tip(), wlock=wlock)
    26             return hg.clean(repo, repo.changelog.tip(), wlock=wlock)
    27         newheads = repo.heads(parent)
    27         newheads = repo.heads(parent)
    48                             opts['user'], opts['date'], lock=lock, wlock=wlock,
    48                             opts['user'], opts['date'], lock=lock, wlock=wlock,
    49                             force_editor=opts.get('force_editor'))
    49                             force_editor=opts.get('force_editor'))
    50             ui.status(_('new changeset %d:%s merges remote changes '
    50             ui.status(_('new changeset %d:%s merges remote changes '
    51                         'with local\n') % (repo.changelog.rev(n),
    51                         'with local\n') % (repo.changelog.rev(n),
    52                                            short(n)))
    52                                            short(n)))
    53     def pull():
    53     def pull(lock, wlock):
    54         cmdutil.setremoteconfig(ui, opts)
    54         cmdutil.setremoteconfig(ui, opts)
    55 
    55 
    56         other = hg.repository(ui, ui.expandpath(source))
    56         other = hg.repository(ui, ui.expandpath(source))
    57         ui.status(_('pulling from %s\n') % ui.expandpath(source))
    57         ui.status(_('pulling from %s\n') % ui.expandpath(source))
    58         revs = None
    58         revs = None
    59         if opts['rev'] and not other.local():
    59         if opts['rev'] and not other.local():
    60             raise util.Abort(_("fetch -r doesn't work for remote repositories yet"))
    60             raise util.Abort(_("fetch -r doesn't work for remote repositories yet"))
    61         elif opts['rev']:
    61         elif opts['rev']:
    62             revs = [other.lookup(rev) for rev in opts['rev']]
    62             revs = [other.lookup(rev) for rev in opts['rev']]
    63         modheads = repo.pull(other, heads=revs, lock=lock)
    63         modheads = repo.pull(other, heads=revs, lock=lock)
    64         return postincoming(other, modheads)
    64         return postincoming(other, modheads, lock, wlock)
    65 
    65 
    66     parent, p2 = repo.dirstate.parents()
    66     parent, p2 = repo.dirstate.parents()
    67     if parent != repo.changelog.tip():
    67     if parent != repo.changelog.tip():
    68         raise util.Abort(_('working dir not at tip '
    68         raise util.Abort(_('working dir not at tip '
    69                            '(use "hg update" to check out tip)'))
    69                            '(use "hg update" to check out tip)'))
    70     if p2 != nullid:
    70     if p2 != nullid:
    71         raise util.Abort(_('outstanding uncommitted merge'))
    71         raise util.Abort(_('outstanding uncommitted merge'))
    72     wlock = repo.wlock()
    72     wlock = lock = None
    73     lock = repo.lock()
       
    74     try:
    73     try:
       
    74         wlock = repo.wlock()
       
    75         lock = repo.lock()
    75         mod, add, rem = repo.status(wlock=wlock)[:3]
    76         mod, add, rem = repo.status(wlock=wlock)[:3]
    76         if mod or add or rem:
    77         if mod or add or rem:
    77             raise util.Abort(_('outstanding uncommitted changes'))
    78             raise util.Abort(_('outstanding uncommitted changes'))
    78         if len(repo.heads()) > 1:
    79         if len(repo.heads()) > 1:
    79             raise util.Abort(_('multiple heads in this repository '
    80             raise util.Abort(_('multiple heads in this repository '
    80                                '(use "hg heads" and "hg merge" to merge)'))
    81                                '(use "hg heads" and "hg merge" to merge)'))
    81         return pull()
    82         return pull(lock, wlock)
    82     finally:
    83     finally:
    83         lock.release()
    84         del lock, wlock
    84         wlock.release()
       
    85 
    85 
    86 cmdtable = {
    86 cmdtable = {
    87     'fetch':
    87     'fetch':
    88         (fetch,
    88         (fetch,
    89         [('e', 'ssh', '', _('specify ssh command to use')),
    89         [('e', 'ssh', '', _('specify ssh command to use')),