view util.py @ 131:4d42dbbb5127

hg_delta_editor: fix parent revision detection on branch copy Project items copyfrom revisions are irrelevant to parent revision detection, only the project one or those of its ancestors matter. Items copyfrom is useful when retrieving items content. Former code resulted in incorrect converted graph for pyglet repository, especially on the following revision: ------------------------------------------------------------------------ r274 | r1chardj0n3s | 2006-12-21 02:02:14 +0100 (Jeu, 21 Dec 2006) | 2 lines Changed paths: A /branches/richard-glx-version (from /trunk:269) M /branches/richard-glx-version/pyglet/window/xlib/__init__.py R /branches/richard-glx-version/tests/test.py (from /trunk/tests/test.py:270) R /branches/richard-glx-version/tools/info.py (from /trunk/tools/info.py:272) R /branches/richard-glx-version/website/get_involved.php (from /trunk/website/get_involved.php:273) Branching to horribly mangle GLX
author Patrick Mezard <pmezard@gmail.com>
date Wed, 10 Dec 2008 11:03:22 -0600
parents 291925677a9f
children 9ffde8662967
line wrap: on
line source

import os
import pickle
import shutil

from mercurial import node

svn_subcommands = { }

def register_subcommand(name):
    def inner(fn):
        svn_subcommands[name] = fn
        return fn
    return inner


def generate_help():
    ret = ['', 'hg svn subcommand\n', 'Subcommands:\n']

    for name, func in sorted(svn_subcommands.items()):
        short_description = (func.__doc__ or '').split('\n')[0]
        ret.append(" %-10s  %s" % (name, short_description))

    return "\n".join(ret) + '\n'


def wipe_all_files(hg_wc_path):
    files = [f for f in os.listdir(hg_wc_path) if f != '.hg']
    for f in files:
        f = os.path.join(hg_wc_path, f)
        if os.path.isdir(f):
            shutil.rmtree(f)
        else:
            os.remove(f)

REVMAP_FILE_VERSION = 1
def parse_revmap(revmap_filename):
    revmap = {}
    f = open(revmap_filename)
    try:
        # Remove compat code after March of 2009. That should be more than long
        # enough.
        revmap = pickle.load(f)
        f.close()
        f = open(revmap_filename, 'w')
        f.write('1\n')
        for key, value in sorted(revmap.items()):
            f.write('%s %s %s\n' % (str(key[0]), node.hex(value), key[1] or ''))
        f.close()
    except:
        f.close()
        f = open(revmap_filename)
        ver = int(f.readline())
        if ver == 1:
            for l in f:
                revnum, node_hash, branch = l.split(' ', 2)
                if branch == '\n':
                    branch = None
                else:
                    branch = branch[:-1]
                revmap[int(revnum), branch] = node.bin(node_hash)
            f.close()
        else:
            print ('Your revmap was made by a newer version of hgsubversion.'
                   ' Please upgrade.')
            raise NotImplementedError
    return revmap


class PrefixMatch(object):
    def __init__(self, prefix):
        self.p = prefix
    
    def files(self):
        return []
    
    def __call__(self, fn):
        return fn.startswith(self.p)

def outgoing_revisions(ui, repo, hg_editor, reverse_map):
    """Given a repo and an hg_editor, determines outgoing revisions for the
    current working copy state.
    """
    outgoing_rev_hashes = []
    working_rev = repo.parents()
    assert len(working_rev) == 1
    working_rev = working_rev[0]
    if working_rev.node() in reverse_map:
        return
    while (not working_rev.node() in reverse_map
           and working_rev.node() != node.nullid):
        outgoing_rev_hashes.append(working_rev.node())
        working_rev = working_rev.parents()
        assert len(working_rev) == 1
        working_rev = working_rev[0]
    if working_rev.node() != node.nullid:
        return outgoing_rev_hashes


def is_svn_repo(repo):
    return os.path.exists(os.path.join(repo.path, 'svn'))