mercurial/hg.py
changeset 26587 56b2bcea2529
parent 26354 c1fb2cab6260
child 26654 30657909b2ba
equal deleted inserted replaced
26586:d51c658d3f04 26587:56b2bcea2529
    63     else:
    63     else:
    64         revs = []
    64         revs = []
    65 
    65 
    66     if not peer.capable('branchmap'):
    66     if not peer.capable('branchmap'):
    67         if branches:
    67         if branches:
    68             raise util.Abort(_("remote branch lookup not supported"))
    68             raise error.Abort(_("remote branch lookup not supported"))
    69         revs.append(hashbranch)
    69         revs.append(hashbranch)
    70         return revs, revs[0]
    70         return revs, revs[0]
    71     branchmap = peer.branchmap()
    71     branchmap = peer.branchmap()
    72 
    72 
    73     def primary(branch):
    73     def primary(branch):
    74         if branch == '.':
    74         if branch == '.':
    75             if not lrepo:
    75             if not lrepo:
    76                 raise util.Abort(_("dirstate branch not accessible"))
    76                 raise error.Abort(_("dirstate branch not accessible"))
    77             branch = lrepo.dirstate.branch()
    77             branch = lrepo.dirstate.branch()
    78         if branch in branchmap:
    78         if branch in branchmap:
    79             revs.extend(node.hex(r) for r in reversed(branchmap[branch]))
    79             revs.extend(node.hex(r) for r in reversed(branchmap[branch]))
    80             return True
    80             return True
    81         else:
    81         else:
   158 def repository(ui, path='', create=False):
   158 def repository(ui, path='', create=False):
   159     """return a repository object for the specified path"""
   159     """return a repository object for the specified path"""
   160     peer = _peerorrepo(ui, path, create)
   160     peer = _peerorrepo(ui, path, create)
   161     repo = peer.local()
   161     repo = peer.local()
   162     if not repo:
   162     if not repo:
   163         raise util.Abort(_("repository '%s' is not local") %
   163         raise error.Abort(_("repository '%s' is not local") %
   164                          (path or peer.url()))
   164                          (path or peer.url()))
   165     return repo.filtered('visible')
   165     return repo.filtered('visible')
   166 
   166 
   167 def peer(uiorrepo, opts, path, create=False):
   167 def peer(uiorrepo, opts, path, create=False):
   168     '''return a repository peer for the specified path'''
   168     '''return a repository peer for the specified path'''
   192 
   192 
   193 def share(ui, source, dest=None, update=True, bookmarks=True):
   193 def share(ui, source, dest=None, update=True, bookmarks=True):
   194     '''create a shared repository'''
   194     '''create a shared repository'''
   195 
   195 
   196     if not islocal(source):
   196     if not islocal(source):
   197         raise util.Abort(_('can only share local repositories'))
   197         raise error.Abort(_('can only share local repositories'))
   198 
   198 
   199     if not dest:
   199     if not dest:
   200         dest = defaultdest(source)
   200         dest = defaultdest(source)
   201     else:
   201     else:
   202         dest = ui.expandpath(dest)
   202         dest = ui.expandpath(dest)
   215 
   215 
   216     destwvfs = scmutil.vfs(dest, realpath=True)
   216     destwvfs = scmutil.vfs(dest, realpath=True)
   217     destvfs = scmutil.vfs(os.path.join(destwvfs.base, '.hg'), realpath=True)
   217     destvfs = scmutil.vfs(os.path.join(destwvfs.base, '.hg'), realpath=True)
   218 
   218 
   219     if destvfs.lexists():
   219     if destvfs.lexists():
   220         raise util.Abort(_('destination already exists'))
   220         raise error.Abort(_('destination already exists'))
   221 
   221 
   222     if not destwvfs.isdir():
   222     if not destwvfs.isdir():
   223         destwvfs.mkdir()
   223         destwvfs.mkdir()
   224     destvfs.makedir()
   224     destvfs.makedir()
   225 
   225 
   318     True.
   318     True.
   319     """
   319     """
   320     revs = None
   320     revs = None
   321     if rev:
   321     if rev:
   322         if not srcpeer.capable('lookup'):
   322         if not srcpeer.capable('lookup'):
   323             raise util.Abort(_("src repository does not support "
   323             raise error.Abort(_("src repository does not support "
   324                                "revision lookup and so doesn't "
   324                                "revision lookup and so doesn't "
   325                                "support clone by revision"))
   325                                "support clone by revision"))
   326         revs = [srcpeer.lookup(r) for r in rev]
   326         revs = [srcpeer.lookup(r) for r in rev]
   327 
   327 
   328     basename = os.path.basename(sharepath)
   328     basename = os.path.basename(sharepath)
   414 
   414 
   415     dest = util.urllocalpath(dest)
   415     dest = util.urllocalpath(dest)
   416     source = util.urllocalpath(source)
   416     source = util.urllocalpath(source)
   417 
   417 
   418     if not dest:
   418     if not dest:
   419         raise util.Abort(_("empty destination path is not valid"))
   419         raise error.Abort(_("empty destination path is not valid"))
   420 
   420 
   421     destvfs = scmutil.vfs(dest, expandpath=True)
   421     destvfs = scmutil.vfs(dest, expandpath=True)
   422     if destvfs.lexists():
   422     if destvfs.lexists():
   423         if not destvfs.isdir():
   423         if not destvfs.isdir():
   424             raise util.Abort(_("destination '%s' already exists") % dest)
   424             raise error.Abort(_("destination '%s' already exists") % dest)
   425         elif destvfs.listdir():
   425         elif destvfs.listdir():
   426             raise util.Abort(_("destination '%s' is not empty") % dest)
   426             raise error.Abort(_("destination '%s' is not empty") % dest)
   427 
   427 
   428     shareopts = shareopts or {}
   428     shareopts = shareopts or {}
   429     sharepool = shareopts.get('pool')
   429     sharepool = shareopts.get('pool')
   430     sharenamemode = shareopts.get('mode')
   430     sharenamemode = shareopts.get('mode')
   431     if sharepool and islocal(dest):
   431     if sharepool and islocal(dest):
   446                 ui.status(_('(not using pooled storage: '
   446                 ui.status(_('(not using pooled storage: '
   447                             'unable to resolve identity of remote)\n'))
   447                             'unable to resolve identity of remote)\n'))
   448         elif sharenamemode == 'remote':
   448         elif sharenamemode == 'remote':
   449             sharepath = os.path.join(sharepool, util.sha1(source).hexdigest())
   449             sharepath = os.path.join(sharepool, util.sha1(source).hexdigest())
   450         else:
   450         else:
   451             raise util.Abort('unknown share naming mode: %s' % sharenamemode)
   451             raise error.Abort('unknown share naming mode: %s' % sharenamemode)
   452 
   452 
   453         if sharepath:
   453         if sharepath:
   454             return clonewithshare(ui, peeropts, sharepath, source, srcpeer,
   454             return clonewithshare(ui, peeropts, sharepath, source, srcpeer,
   455                                   dest, pull=pull, rev=rev, update=update,
   455                                   dest, pull=pull, rev=rev, update=update,
   456                                   stream=stream)
   456                                   stream=stream)
   492                 destpath = hgdir
   492                 destpath = hgdir
   493                 util.makedir(destpath, notindexed=True)
   493                 util.makedir(destpath, notindexed=True)
   494             except OSError as inst:
   494             except OSError as inst:
   495                 if inst.errno == errno.EEXIST:
   495                 if inst.errno == errno.EEXIST:
   496                     cleandir = None
   496                     cleandir = None
   497                     raise util.Abort(_("destination '%s' already exists")
   497                     raise error.Abort(_("destination '%s' already exists")
   498                                      % dest)
   498                                      % dest)
   499                 raise
   499                 raise
   500 
   500 
   501             destlock = copystore(ui, srcrepo, destpath)
   501             destlock = copystore(ui, srcrepo, destpath)
   502             # copy bookmarks over
   502             # copy bookmarks over
   532                 destpeer = peer(srcrepo or ui, peeropts, dest, create=True)
   532                 destpeer = peer(srcrepo or ui, peeropts, dest, create=True)
   533                                 # only pass ui when no srcrepo
   533                                 # only pass ui when no srcrepo
   534             except OSError as inst:
   534             except OSError as inst:
   535                 if inst.errno == errno.EEXIST:
   535                 if inst.errno == errno.EEXIST:
   536                     cleandir = None
   536                     cleandir = None
   537                     raise util.Abort(_("destination '%s' already exists")
   537                     raise error.Abort(_("destination '%s' already exists")
   538                                      % dest)
   538                                      % dest)
   539                 raise
   539                 raise
   540 
   540 
   541             revs = None
   541             revs = None
   542             if rev:
   542             if rev:
   543                 if not srcpeer.capable('lookup'):
   543                 if not srcpeer.capable('lookup'):
   544                     raise util.Abort(_("src repository does not support "
   544                     raise error.Abort(_("src repository does not support "
   545                                        "revision lookup and so doesn't "
   545                                        "revision lookup and so doesn't "
   546                                        "support clone by revision"))
   546                                        "support clone by revision"))
   547                 revs = [srcpeer.lookup(r) for r in rev]
   547                 revs = [srcpeer.lookup(r) for r in rev]
   548                 checkout = revs[0]
   548                 checkout = revs[0]
   549             if destpeer.local():
   549             if destpeer.local():
   555                 destpeer.local().clone(srcpeer, heads=revs, stream=stream)
   555                 destpeer.local().clone(srcpeer, heads=revs, stream=stream)
   556             elif srcrepo:
   556             elif srcrepo:
   557                 exchange.push(srcrepo, destpeer, revs=revs,
   557                 exchange.push(srcrepo, destpeer, revs=revs,
   558                               bookmarks=srcrepo._bookmarks.keys())
   558                               bookmarks=srcrepo._bookmarks.keys())
   559             else:
   559             else:
   560                 raise util.Abort(_("clone from remote to remote not supported"))
   560                 raise error.Abort(_("clone from remote to remote not supported")
       
   561                                  )
   561 
   562 
   562         cleandir = None
   563         cleandir = None
   563 
   564 
   564         destrepo = destpeer.local()
   565         destrepo = destpeer.local()
   565         if destrepo:
   566         if destrepo: