contrib/hgit
author mpm@selenic.com
Wed, 08 Jun 2005 10:52:01 -0800
changeset 280 a69c3b2957d1
parent 267 497aa6d276d2
child 334 290574209284
child 349 b2293093b89e
permissions -rwxr-xr-x
Mark the usual things executable -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Mark the usual things executable manifest hash: e55dde46fd1a97ce338c1ac71278b67ca9d96bf7 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCpz5RywK+sNU5EO8RAnypAJwLpjrQ09nMSJUELtCondHI0fvuVACfQu2J mFi9D3L9ULGO457NWB4h3kY= =3bcD -----END PGP SIGNATURE-----
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     1
#!/usr/bin/env python
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     2
#
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     3
# Minimal support for git commands on an hg repository
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     4
#
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     5
# Copyright 2005 Chris Mason <mason@suse.com>
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     6
#
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     7
# This software may be used and distributed according to the terms
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     8
# of the GNU General Public License, incorporated herein by reference.
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     9
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    10
import time, sys, signal
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    11
from mercurial import hg, mdiff, fancyopts, commands, ui
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    12
    
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    13
def difftree(args, repo):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    14
    def __difftree(repo, files = None, node1 = None, node2 = None):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    15
	def date(c):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    16
	    return time.asctime(time.gmtime(float(c[2].split(' ')[0])))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    17
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    18
	if node2:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    19
	    change = repo.changelog.read(node2)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    20
	    mmap2 = repo.manifest.read(change[0])
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    21
	    (c, a, d) = repo.diffrevs(node1, node2)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    22
	    def read(f): return repo.file(f).read(mmap2[f])
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    23
	    date2 = date(change)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    24
	else:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    25
	    date2 = time.asctime()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    26
	    (c, a, d, u) = repo.diffdir(repo.root, node1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    27
	    if not node1:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    28
		node1 = repo.dirstate.parents()[0]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    29
	    def read(f): return file(os.path.join(repo.root, f)).read()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    30
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    31
	change = repo.changelog.read(node1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    32
	mmap = repo.manifest.read(change[0])
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    33
	date1 = date(change)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    34
	empty = "0" * 40;
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    35
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    36
	if files:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    37
	    c, a, d = map(lambda x: filterfiles(files, x), (c, a, d))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    38
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    39
	for f in c:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    40
	    # TODO get file permissions
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    41
	    print ":100664 100664 %s %s %s %s" % (hg.hex(mmap[f]), 
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    42
	                                              hg.hex(mmap2[f]), f, f)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    43
	for f in a:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    44
	    print ":000000 100664 %s %s %s %s" % (empty, hg.hex(mmap2[f]), f, f)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    45
	for f in d:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    46
	    print ":100664 000000 %s %s %s %s" % (hg.hex(mmap[f]), empty, f, f)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    47
    ##
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    48
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    49
    revs = []
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    50
    if args:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    51
	doptions = {}
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    52
	opts = [('p', 'patch', None, 'patch'),
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    53
		('r', 'recursive', None, 'recursive')]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    54
	args = fancyopts.fancyopts(args, opts, doptions,
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    55
                                   'hg diff-tree [options] sha1 sha1')
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    56
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    57
    if len(args) < 2:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    58
	help()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    59
        sys.exit(1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    60
    revs.append(repo.lookup(args[0]))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    61
    revs.append(repo.lookup(args[1]))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    62
    args = args[2:]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    63
    if doptions['patch']:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    64
	commands.dodiff(repo, args, *revs)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    65
    else:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    66
	__difftree(repo, args, *revs)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    67
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    68
def catcommit(repo, n, prefix):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    69
    nlprefix = '\n' + prefix;
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    70
    changes = repo.changelog.read(n)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    71
    (p1, p2) = repo.changelog.parents(n)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    72
    (h, h1, h2) = map(hg.hex, (n, p1, p2))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    73
    (i1, i2) = map(repo.changelog.rev, (p1, p2))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    74
    print "tree %s" % (h)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    75
    if i1 != -1: print "%sparent %s" % (prefix, h1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    76
    if i2 != -1: print "%sparent %s" % (prefix, h2)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    77
    date_ar = changes[2].split(' ')
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    78
    date = int(float(date_ar[0]))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    79
    print "%sauthor <%s> %s %s" % (prefix, changes[1], date, date_ar[1])
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    80
    print "%scommitter <%s> %s %s" % (prefix, changes[1], date, date_ar[1])
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    81
    print prefix
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    82
    if prefix != "":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    83
	print "%s%s" % (prefix, changes[4].replace('\n', nlprefix).strip())
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    84
    else:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    85
	print changes[4]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    86
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    87
def catfile(args, ui, repo):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    88
    doptions = {}
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    89
    opts = [('s', 'stdin', None, 'stdin')]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    90
    args = fancyopts.fancyopts(args, opts, doptions,
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    91
			       'hg cat-file type sha1')
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    92
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    93
    # in stdin mode, every line except the commit is prefixed with two
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    94
    # spaces.  This way the our caller can find the commit without magic
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    95
    # strings
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    96
    #
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    97
    prefix = ""
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    98
    if doptions['stdin']:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    99
	try:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   100
	    (type, r) = raw_input().split(' ');
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   101
	    prefix = "  "
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   102
	except EOFError:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   103
	    return
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   104
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   105
    else:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   106
	if len(args) < 2:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   107
	    help()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   108
	    sys.exit(1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   109
        type = args[0]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   110
	r = args[1]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   111
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   112
    while r:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   113
	if type != "commit":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   114
	    sys.stderr.write("aborting hg cat-file only understands commits\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   115
	    sys.exit(1);
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   116
	n = repo.changelog.lookup(r)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   117
	catcommit(repo, n, prefix)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   118
	if doptions['stdin']:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   119
	    try:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   120
		(type, r) = raw_input().split(' ');
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   121
	    except EOFError:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   122
		break
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   123
	else:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   124
	    break
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   125
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   126
# git rev-tree is a confusing thing.  You can supply a number of
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   127
# commit sha1s on the command line, and it walks the commit history
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   128
# telling you which commits are reachable from the supplied ones via
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   129
# a bitmask based on arg position.
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   130
# you can specify a commit to stop at by starting the sha1 with ^
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   131
def revtree(args, repo):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   132
    # calculate and return the reachability bitmask for sha
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   133
    def is_reachable(ar, reachable, sha):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   134
	if len(ar) == 0:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   135
	    return 1
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   136
	mask = 0
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   137
	for i in range(len(ar)):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   138
	    if sha in reachable[i]:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   139
	        mask |= 1 << i
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   140
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   141
	return mask
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   142
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   143
    reachable = []
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   144
    stop_sha1 = []
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   145
    want_sha1 = []
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   146
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   147
    # figure out which commits they are asking for and which ones they
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   148
    # want us to stop on
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   149
    for i in range(len(args)):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   150
        if args[i].count('^'):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   151
	    s = args[i].split('^')[1]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   152
	    stop_sha1.append(repo.changelog.lookup(s))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   153
	    want_sha1.append(s)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   154
	elif args[i] != 'HEAD':
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   155
	    want_sha1.append(args[i])
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   156
    # calculate the graph for the supplied commits
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   157
    for i in range(len(want_sha1)):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   158
	reachable.append({});
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   159
	n = repo.changelog.lookup(want_sha1[i]);
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   160
	visit = [n];
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   161
	reachable[i][n] = 1
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   162
	while visit:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   163
	    n = visit.pop(0)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   164
	    if n in stop_sha1:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   165
		break
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   166
	    for p in repo.changelog.parents(n):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   167
		if p not in reachable[i]:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   168
		    reachable[i][p] = 1
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   169
		    visit.append(p)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   170
		if p in stop_sha1:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   171
		    break
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   172
    # walk the repository looking for commits that are in our
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   173
    # reachability graph
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   174
    for i in range(repo.changelog.count()):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   175
	n = repo.changelog.node(i)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   176
	mask = is_reachable(want_sha1, reachable, n)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   177
	if mask:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   178
	    changes = repo.changelog.read(n)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   179
	    (p1, p2) = repo.changelog.parents(n)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   180
	    (h, h1, h2) = map(hg.hex, (n, p1, p2))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   181
	    (i1, i2) = map(repo.changelog.rev, (p1, p2))
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   182
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   183
	    date = changes[2].split(' ')[0]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   184
	    print "%s %s:%s" % (date, h, mask),
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   185
	    mask = is_reachable(want_sha1, reachable, p1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   186
	    if i1 != -1 and mask > 0:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   187
		print "%s:%s " % (h1, mask),
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   188
	    mask = is_reachable(want_sha1, reachable, p2)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   189
	    if i2 != -1 and mask > 0:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   190
		print "%s:%s " % (h2, mask),
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   191
	    print ""
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   192
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   193
# git rev-list tries to order things by date, and has the ability to stop
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   194
# at a given commit without walking the whole repo.  TODO add the stop
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   195
# parameter
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   196
def revlist(args, repo):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   197
    doptions = {}
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   198
    opts = [('c', 'commit', None, 'commit')]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   199
    args = fancyopts.fancyopts(args, opts, doptions,
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   200
			       'hg rev-list')
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   201
    for i in range(repo.changelog.count()):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   202
	n = repo.changelog.node(i)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   203
	print hg.hex(n)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   204
	if doptions['commit']:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   205
	    catcommit(repo, n, '  ')
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   206
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   207
def catchterm(*args):
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   208
    raise SignalInterrupt
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   209
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   210
def help():
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   211
    sys.stderr.write("commands:\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   212
    sys.stderr.write("  hgit cat-file [type] sha1\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   213
    sys.stderr.write("  hgit diff-tree [-p] [-r] sha1 sha1\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   214
    sys.stderr.write("  hgit rev-tree [sha1 ... [^stop sha1]]\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   215
    sys.stderr.write("  hgit rev-list [-c]\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   216
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   217
cmd = sys.argv[1]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   218
args = sys.argv[2:]
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   219
u = ui.ui()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   220
signal.signal(signal.SIGTERM, catchterm)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   221
repo = hg.repository(ui = u)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   222
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   223
if cmd == "diff-tree":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   224
    difftree(args, repo)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   225
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   226
elif cmd == "cat-file":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   227
    catfile(args, ui, repo)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   228
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   229
elif cmd == "rev-tree":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   230
    revtree(args, repo)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   231
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   232
elif cmd == "rev-list":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   233
    revlist(args, repo)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   234
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   235
elif cmd == "help":
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   236
    help()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   237
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   238
else:
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   239
    if cmd: sys.stderr.write("unknown command\n\n")
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   240
    help()
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   241
    sys.exit(1)
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   242
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
   243
sys.exit(0)