hgext/relink.py
changeset 11355 9011036ba79d
parent 11354 412a6e749f8d
child 11357 7914628b4751
equal deleted inserted replaced
11354:412a6e749f8d 11355:9011036ba79d
    46     ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path))
    46     ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path))
    47     locallock = repo.lock()
    47     locallock = repo.lock()
    48     try:
    48     try:
    49         remotelock = src.lock()
    49         remotelock = src.lock()
    50         try:
    50         try:
    51             candidates = sorted(collect(src.store.path, ui))
    51             candidates = sorted(collect(src, ui))
    52             targets = prune(candidates, src.store.path, repo.store.path, ui)
    52             targets = prune(candidates, src.store.path, repo.store.path, ui)
    53             do_relink(src.store.path, repo.store.path, targets, ui)
    53             do_relink(src.store.path, repo.store.path, targets, ui)
    54         finally:
    54         finally:
    55             remotelock.release()
    55             remotelock.release()
    56     finally:
    56     finally:
    57         locallock.release()
    57         locallock.release()
    58 
    58 
    59 def collect(src, ui):
    59 def collect(src, ui):
    60     seplen = len(os.path.sep)
    60     seplen = len(os.path.sep)
    61     candidates = []
    61     candidates = []
       
    62     live = len(src['tip'].manifest())
       
    63     # Your average repository has some files which were deleted before
       
    64     # the tip revision. We account for that by assuming that there are
       
    65     # 3 tracked files for every 2 live files as of the tip version of
       
    66     # the repository.
       
    67     #
       
    68     # mozilla-central as of 2010-06-10 had a ratio of just over 7:5.
       
    69     total = live * 3 // 2
       
    70     src = src.store.path
       
    71     pos = 0
       
    72     ui.status(_("tip has %d files, estimated total number of files: %s\n")
       
    73               % (live, total))
    62     for dirpath, dirnames, filenames in os.walk(src):
    74     for dirpath, dirnames, filenames in os.walk(src):
    63         relpath = dirpath[len(src) + seplen:]
    75         relpath = dirpath[len(src) + seplen:]
    64         for filename in filenames:
    76         for filename in filenames:
    65             if not filename[-2:] in ('.d', '.i'):
    77             if not filename[-2:] in ('.d', '.i'):
    66                 continue
    78                 continue
    67             st = os.stat(os.path.join(dirpath, filename))
    79             st = os.stat(os.path.join(dirpath, filename))
    68             if not stat.S_ISREG(st.st_mode):
    80             if not stat.S_ISREG(st.st_mode):
    69                 continue
    81                 continue
       
    82             pos += 1
    70             candidates.append((os.path.join(relpath, filename), st))
    83             candidates.append((os.path.join(relpath, filename), st))
       
    84             ui.progress(_('collecting'), pos, filename, _('files'), total)
    71 
    85 
       
    86     ui.progress(_('collecting'), None)
    72     ui.status(_('collected %d candidate storage files\n') % len(candidates))
    87     ui.status(_('collected %d candidate storage files\n') % len(candidates))
    73     return candidates
    88     return candidates
    74 
    89 
    75 def prune(candidates, src, dst, ui):
    90 def prune(candidates, src, dst, ui):
    76     def linkfilter(src, dst, st):
    91     def linkfilter(src, dst, st):