hgext/relink.py
changeset 26587 56b2bcea2529
parent 25660 328739ea70c3
child 26778 a95c975f42e3
equal deleted inserted replaced
26586:d51c658d3f04 26587:56b2bcea2529
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 """recreates hardlinks between repository clones"""
     8 """recreates hardlinks between repository clones"""
     9 
     9 
    10 from mercurial import cmdutil, hg, util
    10 from mercurial import cmdutil, hg, util, error
    11 from mercurial.i18n import _
    11 from mercurial.i18n import _
    12 import os, stat
    12 import os, stat
    13 
    13 
    14 cmdtable = {}
    14 cmdtable = {}
    15 command = cmdutil.command(cmdtable)
    15 command = cmdutil.command(cmdtable)
    45     command is running. (Both repositories will be locked against
    45     command is running. (Both repositories will be locked against
    46     writes.)
    46     writes.)
    47     """
    47     """
    48     if (not util.safehasattr(util, 'samefile') or
    48     if (not util.safehasattr(util, 'samefile') or
    49         not util.safehasattr(util, 'samedevice')):
    49         not util.safehasattr(util, 'samedevice')):
    50         raise util.Abort(_('hardlinks are not supported on this system'))
    50         raise error.Abort(_('hardlinks are not supported on this system'))
    51     src = hg.repository(repo.baseui, ui.expandpath(origin or 'default-relink',
    51     src = hg.repository(repo.baseui, ui.expandpath(origin or 'default-relink',
    52                                           origin or 'default'))
    52                                           origin or 'default'))
    53     ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path))
    53     ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path))
    54     if repo.root == src.root:
    54     if repo.root == src.root:
    55         ui.status(_('there is nothing to relink\n'))
    55         ui.status(_('there is nothing to relink\n'))
    56         return
    56         return
    57 
    57 
    58     if not util.samedevice(src.store.path, repo.store.path):
    58     if not util.samedevice(src.store.path, repo.store.path):
    59         # No point in continuing
    59         # No point in continuing
    60         raise util.Abort(_('source and destination are on different devices'))
    60         raise error.Abort(_('source and destination are on different devices'))
    61 
    61 
    62     locallock = repo.lock()
    62     locallock = repo.lock()
    63     try:
    63     try:
    64         remotelock = src.lock()
    64         remotelock = src.lock()
    65         try:
    65         try:
   112             return False
   112             return False
   113         if util.samefile(src, dst):
   113         if util.samefile(src, dst):
   114             return False
   114             return False
   115         if not util.samedevice(src, dst):
   115         if not util.samedevice(src, dst):
   116             # No point in continuing
   116             # No point in continuing
   117             raise util.Abort(
   117             raise error.Abort(
   118                 _('source and destination are on different devices'))
   118                 _('source and destination are on different devices'))
   119         if st.st_size != ts.st_size:
   119         if st.st_size != ts.st_size:
   120             return False
   120             return False
   121         return st
   121         return st
   122 
   122