contrib/compress.py
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
Sun, 22 Aug 2010 19:27:09 +0200
changeset 12021 42253a4d2be5
parent 12020 69498b1b552b
child 12022 6b04f1e1aa8a
permissions -rw-r--r--
contrib/compress: correct ordering of copying Changelog should always be copied last, otherwise readers can see an inconsistent repo.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     1
# Copyright 2010 Pradeepkumar Gayam <in3xes@gmail.com>
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     2
#
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     3
# Author(s):
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     4
# Pradeepkumar Gayam <in3xes@gmail.com>
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     5
#
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     8
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
     9
12019
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
    10
from mercurial import hg, localrepo
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    11
from mercurial.lock import release
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    12
import weakref
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
    13
12020
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    14
def _copyrevlog(ui, src, dst, tr, progress=None):
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    15
    if progress:
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    16
        desc = 'adding %s' % progress
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    17
        total = len(src)
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    18
        def progress(count):
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    19
            ui.progress(desc, count, unit=('revisions'), total=total)
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    20
    else:
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    21
        progress = lambda x: None
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    22
    for r in src:
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    23
        p = [src.node(i) for i in src.parentrevs(r)]
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    24
        dst.addrevision(src.revision(src.node(r)), tr, src.linkrev(r),
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    25
                        p[0], p[1])
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    26
        progress(r)
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    27
12015
73940fe84cbf contrib/compress: remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11933
diff changeset
    28
def compress(ui, repo, dest):
12017
9182f434ec58 contrib/compress: use hg API to compute the destination path
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12016
diff changeset
    29
    dest = hg.localpath(ui.expandpath(dest))
9182f434ec58 contrib/compress: use hg API to compute the destination path
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12016
diff changeset
    30
    target = localrepo.instance(ui, dest, create=True)
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    31
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    32
    tr = lock = tlock = None
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    33
    try:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    34
        lock = repo.lock()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    35
        tlock = target.lock()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    36
        tr = target.transaction("compress")
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    37
        trp = weakref.proxy(tr)
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
    38
12020
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    39
        _copyrevlog(ui, repo.manifest, target.manifest, trp, 'manifest')
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
    40
12019
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
    41
        # only keep indexes and filter "data/" prefix and ".i" suffix
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
    42
        datafiles = [fn[5:-2] for fn, f2, size in repo.store.datafiles()
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
    43
                                      if size and fn.endswith('.i')]
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
    44
        total = len(datafiles)
456f0fed8f17 contrib/compress: use store API instead of a collector
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12018
diff changeset
    45
        for cnt, f in enumerate(datafiles):
12020
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    46
            _copyrevlog(ui, repo.file(f), target.file(f), trp)
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    47
            ui.progress(('adding files'), cnt, item=f, unit=('file'),
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    48
                        total=total)
12020
69498b1b552b contrib/compress: refactor revlog copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12019
diff changeset
    49
12021
42253a4d2be5 contrib/compress: correct ordering of copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12020
diff changeset
    50
        _copyrevlog(ui, repo.changelog, target.changelog, trp, 'changesets')
42253a4d2be5 contrib/compress: correct ordering of copying
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12020
diff changeset
    51
12018
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    52
        tr.close()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    53
    finally:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    54
        if tr:
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    55
            tr.release()
fd206fabc14f contrib/compress: proper lock handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12017
diff changeset
    56
        release(tlock, lock)
11933
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
    57
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
    58
cmdtable = {
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
    59
    "compress" : (compress, [], "DEST")
293afcfb66a8 contrib: simple extension to practically convert a repo from tip delta to parentdelta
Pradeepkumar Gayam <in3xes@gmail.com>
parents:
diff changeset
    60
    }