hgext/fetch.py
changeset 4917 126f527b3ba3
parent 4915 97b734fb9c6f
child 5147 c80af96943aa
equal deleted inserted replaced
4916:5c5d23d93447 4917:126f527b3ba3
    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, lock, wlock):
    22     def postincoming(other, modheads):
    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())
    27         newheads = repo.heads(parent)
    27         newheads = repo.heads(parent)
    28         newchildren = [n for n in repo.heads(parent) if n != parent]
    28         newchildren = [n for n in repo.heads(parent) if n != parent]
    29         newparent = parent
    29         newparent = parent
    30         if newchildren:
    30         if newchildren:
    31             newparent = newchildren[0]
    31             newparent = newchildren[0]
    32             hg.clean(repo, newparent, wlock=wlock)
    32             hg.clean(repo, newparent)
    33         newheads = [n for n in repo.heads() if n != newparent]
    33         newheads = [n for n in repo.heads() if n != newparent]
    34         err = False
    34         err = False
    35         if newheads:
    35         if newheads:
    36             ui.status(_('merging with new head %d:%s\n') %
    36             ui.status(_('merging with new head %d:%s\n') %
    37                       (repo.changelog.rev(newheads[0]), short(newheads[0])))
    37                       (repo.changelog.rev(newheads[0]), short(newheads[0])))
    38             err = hg.merge(repo, newheads[0], remind=False, wlock=wlock)
    38             err = hg.merge(repo, newheads[0], remind=False)
    39         if not err and len(newheads) > 1:
    39         if not err and len(newheads) > 1:
    40             ui.status(_('not merging with %d other new heads '
    40             ui.status(_('not merging with %d other new heads '
    41                         '(use "hg heads" and "hg merge" to merge them)') %
    41                         '(use "hg heads" and "hg merge" to merge them)') %
    42                       (len(newheads) - 1))
    42                       (len(newheads) - 1))
    43         if not err:
    43         if not err:
    44             mod, add, rem = repo.status(wlock=wlock)[:3]
    44             mod, add, rem = repo.status()[:3]
    45             message = (cmdutil.logmessage(opts) or
    45             message = (cmdutil.logmessage(opts) or
    46                        (_('Automated merge with %s') % other.url()))
    46                        (_('Automated merge with %s') % other.url()))
    47             n = repo.commit(mod + add + rem, message,
    47             n = repo.commit(mod + add + rem, message,
    48                             opts['user'], opts['date'], lock=lock, wlock=wlock,
    48                             opts['user'], opts['date'],
    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(lock, wlock):
    53     def pull():
    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)
    64         return postincoming(other, modheads, lock, wlock)
    64         return postincoming(other, modheads)
    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)'))
    71         raise util.Abort(_('outstanding uncommitted merge'))
    71         raise util.Abort(_('outstanding uncommitted merge'))
    72     wlock = lock = None
    72     wlock = lock = None
    73     try:
    73     try:
    74         wlock = repo.wlock()
    74         wlock = repo.wlock()
    75         lock = repo.lock()
    75         lock = repo.lock()
    76         mod, add, rem = repo.status(wlock=wlock)[:3]
    76         mod, add, rem = repo.status()[:3]
    77         if mod or add or rem:
    77         if mod or add or rem:
    78             raise util.Abort(_('outstanding uncommitted changes'))
    78             raise util.Abort(_('outstanding uncommitted changes'))
    79         if len(repo.heads()) > 1:
    79         if len(repo.heads()) > 1:
    80             raise util.Abort(_('multiple heads in this repository '
    80             raise util.Abort(_('multiple heads in this repository '
    81                                '(use "hg heads" and "hg merge" to merge)'))
    81                                '(use "hg heads" and "hg merge" to merge)'))
    82         return pull(lock, wlock)
    82         return pull()
    83     finally:
    83     finally:
    84         del lock, wlock
    84         del lock, wlock
    85 
    85 
    86 cmdtable = {
    86 cmdtable = {
    87     'fetch':
    87     'fetch':