hgext/relink.py
author Siddharth Agarwal <sid.bugzilla@gmail.com>
Fri, 08 Jan 2010 18:48:39 +0530
branchstable
changeset 10218 750b7a4f01f6
parent 9790 819e6c7085fc
child 10221 489b0caf21ed
child 10225 6521605bc200
permissions -rw-r--r--
Add support for relinking on Windows. Test and minor code change by Patrick Mézard <pmezard@gmail.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
     1
# Mercurial extension to provide 'hg relink' command
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     2
#
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     3
# Copyright (C) 2007 Brendan Cully <brendan@kublai.com>
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 4270
diff changeset
     5
# This software may be used and distributed according to the terms of the
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 4270
diff changeset
     6
# GNU General Public License version 2, incorporated herein by reference.
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     7
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
     8
"""recreates hardlinks between repository clones"""
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
     9
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    10
from mercurial import cmdutil, hg, util
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    11
from mercurial.i18n import _
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    12
import os, stat
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    13
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    14
def relink(ui, repo, origin=None, **opts):
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    15
    """recreate hardlinks between two repositories
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    16
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    17
    When repositories are cloned locally, their data files will be hardlinked
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    18
    so that they only use the space of a single repository.
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    19
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    20
    Unfortunately, subsequent pulls into either repository will break hardlinks
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    21
    for any files touched by the new changesets, even if both repositories end
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    22
    up pulling the same changes.
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    23
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    24
    Similarly, passing --rev to "hg clone" will fail to use
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    25
    any hardlinks, falling back to a complete copy of the source repository.
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    26
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    27
    This command lets you recreate those hardlinks and reclaim that wasted
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    28
    space.
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    29
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    30
    This repository will be relinked to share space with ORIGIN, which must be
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    31
    on the same local disk. If ORIGIN is omitted, looks for "default-relink",
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    32
    then "default", in [paths].
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    33
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    34
    Do not attempt any read operations on this repository while the command is
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    35
    running. (Both repositories will be locked against writes.)
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    36
    """
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    37
    if not hasattr(util, 'samefile') or not hasattr(util, 'samedevice'):
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    38
        raise util.Abort(_('hardlinks are not supported on this system'))
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    39
    src = hg.repository(
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    40
        cmdutil.remoteui(repo, opts),
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    41
        ui.expandpath(origin or 'default-relink', origin or 'default'))
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    42
    if not src.local():
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    43
        raise util.Abort('must specify local origin repository')
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    44
    ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path))
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    45
    locallock = repo.lock()
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    46
    try:
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    47
        remotelock = src.lock()
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    48
        try:
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    49
            candidates = collect(src.store.path, ui)
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    50
            targets = prune(candidates, src.store.path, repo.store.path, ui)
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    51
            do_relink(src.store.path, repo.store.path, targets, ui)
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    52
        finally:
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    53
            remotelock.release()
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    54
    finally:
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    55
        locallock.release()
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    56
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    57
def collect(src, ui):
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    58
    seplen = len(os.path.sep)
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    59
    candidates = []
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    60
    for dirpath, dirnames, filenames in os.walk(src):
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    61
        relpath = dirpath[len(src) + seplen:]
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    62
        for filename in filenames:
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    63
            if not filename[-2:] in ('.d', '.i'):
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    64
                continue
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    65
            st = os.stat(os.path.join(dirpath, filename))
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    66
            if not stat.S_ISREG(st.st_mode):
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    67
                continue
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    68
            candidates.append((os.path.join(relpath, filename), st))
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    69
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    70
    ui.status(_('collected %d candidate storage files\n') % len(candidates))
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    71
    return candidates
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    72
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    73
def prune(candidates, src, dst, ui):
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    74
    def linkfilter(src, dst, st):
4270
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    75
        try:
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    76
            ts = os.stat(dst)
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    77
        except OSError:
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    78
            # Destination doesn't have this file?
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    79
            return False
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    80
        if util.samefile(src, dst):
4270
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    81
            return False
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    82
        if not util.samedevice(src, dst):
4270
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    83
            # No point in continuing
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    84
            raise util.Abort(
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    85
                _('source and destination are on different devices'))
4270
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    86
        if st.st_size != ts.st_size:
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    87
            return False
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    88
        return st
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    89
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    90
    targets = []
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    91
    for fn, st in candidates:
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    92
        srcpath = os.path.join(src, fn)
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    93
        tgt = os.path.join(dst, fn)
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
    94
        ts = linkfilter(srcpath, tgt, st)
4270
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
    95
        if not ts:
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
    96
            ui.debug(_('not linkable: %s\n') % fn)
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    97
            continue
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    98
        targets.append((fn, ts.st_size))
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
    99
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   100
    ui.status(_('pruned down to %d probably relinkable files\n') % len(targets))
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   101
    return targets
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   102
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   103
def do_relink(src, dst, files, ui):
4270
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   104
    def relinkfile(src, dst):
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   105
        bak = dst + '.bak'
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   106
        os.rename(dst, bak)
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   107
        try:
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
   108
            util.os_link(src, dst)
4270
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   109
        except OSError:
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   110
            os.rename(bak, dst)
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   111
            raise
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   112
        os.remove(bak)
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   113
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   114
    CHUNKLEN = 65536
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   115
    relinked = 0
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   116
    savedbytes = 0
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   117
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   118
    pos = 0
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   119
    total = len(files)
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   120
    for f, sz in files:
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   121
        pos += 1
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   122
        source = os.path.join(src, f)
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   123
        tgt = os.path.join(dst, f)
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
   124
        # Binary mode, so that read() works correctly, especially on Windows
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
   125
        sfp = file(source, 'rb')
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
   126
        dfp = file(tgt, 'rb')
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   127
        sin = sfp.read(CHUNKLEN)
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   128
        while sin:
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   129
            din = dfp.read(CHUNKLEN)
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   130
            if sin != din:
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   131
                break
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   132
            sin = sfp.read(CHUNKLEN)
10218
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
   133
        sfp.close()
750b7a4f01f6 Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents: 9790
diff changeset
   134
        dfp.close()
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   135
        if sin:
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   136
            ui.debug(_('not linkable: %s\n') % f)
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   137
            continue
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   138
        try:
4270
29eb88bd5c8d hg-relink: do not compare .d files
Brendan Cully <brendan@kublai.com>
parents: 4249
diff changeset
   139
            relinkfile(source, tgt)
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   140
            ui.progress(_('relink'), pos, f, _(' files'), total)
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   141
            relinked += 1
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   142
            savedbytes += sz
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   143
        except OSError, inst:
9790
819e6c7085fc relink: do not translate format string with no text
Martin Geisler <mg@lazybytes.net>
parents: 9729
diff changeset
   144
            ui.warn('%s: %s\n' % (tgt, str(inst)))
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   145
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   146
    ui.status(_('relinked %d files (%d bytes reclaimed)\n') %
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   147
              (relinked, savedbytes))
4249
7663780b55a7 Add hg-relink script to contrib
Brendan Cully <brendan@kublai.com>
parents:
diff changeset
   148
9729
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   149
cmdtable = {
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   150
    'relink': (
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   151
        relink,
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   152
        [],
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   153
        _('[ORIGIN]')
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   154
    )
aa9ccab5af37 Issue919: add a standard extension to recreate hardlinks between repositories.
Jesse Glick <jesse.glick@sun.com>
parents: 8225
diff changeset
   155
}