hg
author mpm@selenic.com
Thu, 05 May 2005 15:05:50 -0800
changeset 29 4d3a5dcb6972
parent 24 57a1eef79415
child 31 642058291e74
permissions -rw-r--r--
Make diffdir take a revision argument
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     1
#!/usr/bin/env python
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     2
#
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     3
# mercurial - a minimal scalable distributed SCM
16
7eca4cfa8aad Update version numbers
mpm@selenic.com
parents: 11
diff changeset
     4
# v0.4d "oedipa maas"
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     5
#
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     6
# Copyright 2005 Matt Mackall <mpm@selenic.com>
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     7
#
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     8
# This software may be used and distributed according to the terms
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
     9
# of the GNU General Public License, incorporated herein by reference.
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    10
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    11
# the psyco compiler makes commits about twice as fast
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    12
try:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    13
    import psyco
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    14
    psyco.full()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    15
except:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    16
    pass
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    17
23
018fb8d9ea8d Import time for hg history command
mpm@selenic.com
parents: 22
diff changeset
    18
import sys, os, time
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    19
from mercurial import hg, mdiff, fancyopts
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    20
18
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    21
def help():
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    22
        print """\
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    23
 commands:
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    24
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    25
 init                  create a new repository in this directory
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    26
 branch <path>         create a branch of <path> in this directory
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    27
 merge <path>          merge changes from <path> into local repository
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    28
 checkout [changeset]  checkout the latest or given changeset
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    29
 status                show new, missing, and changed files in working dir
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    30
 add [files...]        add the given files in the next commit
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    31
 remove [files...]     remove the given files in the next commit
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    32
 addremove             add all new files, delete all missing files
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    33
 commit                commit all changes to the repository
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    34
 history               show changeset history
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    35
 log <file>            show revision history of a single file
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    36
 dump <file> [rev]     dump the latest or given revision of a file
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    37
 dumpmanifest [rev]    dump the latest or given revision of the manifest
22
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
    38
 diff [files...]       diff working directory (or selected files)
18
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    39
"""
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    40
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    41
options = {}
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    42
opts = [('v', 'verbose', None, 'verbose'),
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    43
        ('d', 'debug', None, 'debug')]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    44
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    45
args = fancyopts.fancyopts(sys.argv[1:], opts, options,
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    46
                           'hg [options] <command> [command options] [files]')
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    47
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    48
try:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    49
    cmd = args[0]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    50
    args = args[1:]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    51
except:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    52
    cmd = ""
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    53
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    54
ui = hg.ui(options["verbose"], options["debug"])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    55
    
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    56
if cmd == "init":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    57
    repo = hg.repository(ui, ".", create=1)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    58
    sys.exit(0)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    59
elif cmd == "branch" or cmd == "clone":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    60
    os.system("cp -al %s/.hg .hg" % args[0])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    61
    sys.exit(0)
18
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    62
elif cmd == "help":
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    63
    help()
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    64
    sys.exit(0)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    65
else:
18
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    66
    try:
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    67
        repo = hg.repository(ui=ui)
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    68
    except:
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    69
        print "Unable to open repository"
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
    70
        sys.exit(0)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    71
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    72
if cmd == "checkout" or cmd == "co":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    73
    node = repo.changelog.tip()
11
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
    74
    if len(args):
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
    75
        if len(args[0]) < 40:
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
    76
            rev = int(args[0])
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
    77
            node = repo.changelog.node(rev)
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
    78
        else:
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
    79
            node = args[0]
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    80
    repo.checkout(node)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    81
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    82
elif cmd == "add":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    83
    repo.add(args)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    84
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    85
elif cmd == "remove" or cmd == "rm" or cmd == "del" or cmd == "delete":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    86
    repo.remove(args)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    87
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    88
elif cmd == "commit" or cmd == "checkin" or cmd == "ci":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    89
    if 1:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    90
        if len(args) > 0:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    91
            repo.commit(args)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    92
        else:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    93
            repo.commit()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    94
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    95
elif cmd == "import" or cmd == "patch":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    96
    ioptions = {}
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    97
    opts = [('p', 'strip', 1, 'path strip'),
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    98
            ('b', 'base', "", 'base path')]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
    99
    
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   100
    args = fancyopts.fancyopts(args, opts, ioptions,
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   101
                              'hg import [options] <patch names>')
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   102
    d = ioptions["base"]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   103
    strip = ioptions["strip"]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   104
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   105
    for patch in args:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   106
        ui.status("applying %s\n" % patch)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   107
        pf = d + patch
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   108
        os.system("patch -p%d < %s > /dev/null" % (strip, pf))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   109
        f = os.popen("lsdiff --strip %d %s" % (strip, pf))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   110
        files = f.read().splitlines()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   111
        f.close()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   112
        repo.commit(files)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   113
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   114
elif cmd == "status":
29
4d3a5dcb6972 Make diffdir take a revision argument
mpm@selenic.com
parents: 24
diff changeset
   115
    (c, a, d) = repo.diffdir(repo.root, repo.current)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   116
    for f in c: print "C", f
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   117
    for f in a: print "?", f
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   118
    for f in d: print "R", f
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   119
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   120
elif cmd == "diff":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   121
    mmap = {}
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   122
    if repo.current:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   123
        change = repo.changelog.read(repo.current)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   124
        mmap = repo.manifest.read(change[0])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   125
29
4d3a5dcb6972 Make diffdir take a revision argument
mpm@selenic.com
parents: 24
diff changeset
   126
    (c, a, d) = repo.diffdir(repo.root, repo.current)
22
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   127
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   128
    if args:
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   129
        nc = [ x for x in c if x in args ]
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   130
        na = [ x for x in a if x in args ]
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   131
        nd = [ x for x in d if x in args ]
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   132
        for arg in args:
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   133
            if not os.path.isdir(arg): continue
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   134
            if arg[-1] != os.sep: arg += os.sep
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   135
            nc += [ x for x in c if x.startswith(arg) ]
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   136
            na += [ x for x in a if x.startswith(arg) ]
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   137
            nd += [ x for x in d if x.startswith(arg) ]
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   138
        (c, a, d) = (nc, na, nd)
40b8c158c540 Document diff in help
mpm@selenic.com
parents: 21
diff changeset
   139
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   140
    for f in c:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   141
        to = repo.file(f).read(mmap[f])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   142
        tn = file(f).read()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   143
        sys.stdout.write(mdiff.unidiff(to, tn, f))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   144
    for f in a:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   145
        to = ""
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   146
        tn = file(f).read()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   147
        sys.stdout.write(mdiff.unidiff(to, tn, f))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   148
    for f in d:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   149
        to = repo.file(f).read(mmap[f])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   150
        tn = ""
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   151
        sys.stdout.write(mdiff.unidiff(to, tn, f))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   152
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   153
elif cmd == "addremove":
29
4d3a5dcb6972 Make diffdir take a revision argument
mpm@selenic.com
parents: 24
diff changeset
   154
    (c, a, d) = repo.diffdir(repo.root, repo.current)
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   155
    repo.add(a)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   156
    repo.remove(d)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   157
    
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   158
elif cmd == "history":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   159
    for i in range(repo.changelog.count()):
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   160
        n = repo.changelog.node(i)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   161
        changes = repo.changelog.read(n)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   162
        (p1, p2) = repo.changelog.parents(n)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   163
        (h, h1, h2) = map(hg.hex, (n, p1, p2))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   164
        (i1, i2) = map(repo.changelog.rev, (p1, p2))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   165
        print "rev:      %4d:%s" % (i, h)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   166
        print "parents:  %4d:%s" % (i1, h1)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   167
        if i2: print "          %4d:%s" % (i2, h2)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   168
        print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]),
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   169
                                    hg.hex(changes[0]))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   170
        print "user:", changes[1]
21
54a57a5ebcb1 Show date in history
mpm@selenic.com
parents: 18
diff changeset
   171
        print "date:", time.asctime(
54a57a5ebcb1 Show date in history
mpm@selenic.com
parents: 18
diff changeset
   172
            time.localtime(float(changes[2].split(' ')[0])))
11
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
   173
        print "files:", " ".join(changes[3])
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   174
        print "description:"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   175
        print changes[4]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   176
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   177
elif cmd == "log":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   178
    if args:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   179
        r = repo.file(args[0])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   180
        for i in range(r.count()):
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   181
            n = r.node(i)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   182
            (p1, p2) = r.parents(n)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   183
            (h, h1, h2) = map(hg.hex, (n, p1, p2))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   184
            (i1, i2) = map(r.rev, (p1, p2))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   185
            cr = r.linkrev(n)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   186
            cn = hg.hex(repo.changelog.node(cr))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   187
            print "rev:       %4d:%s" % (i, h)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   188
            print "changeset: %4d:%s" % (cr, cn)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   189
            print "parents:   %4d:%s" % (i1, h1)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   190
            if i2: print "           %4d:%s" % (i2, h2)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   191
    else:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   192
        print "missing filename"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   193
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   194
elif cmd == "dump":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   195
    if args:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   196
        r = repo.file(args[0])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   197
        n = r.tip()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   198
        if len(args) > 1: n = hg.bin(args[1])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   199
        sys.stdout.write(r.read(n))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   200
    else:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   201
        print "missing filename"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   202
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   203
elif cmd == "dumpmanifest":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   204
    n = repo.manifest.tip()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   205
    if len(args) > 0:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   206
        n = hg.bin(args[0])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   207
    m = repo.manifest.read(n)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   208
    files = m.keys()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   209
    files.sort()
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   210
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   211
    for f in files:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   212
        print hg.hex(m[f]), f
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   213
24
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   214
elif cmd == "debughash":
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   215
    f = repo.file(args[0])
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   216
    print f.encodepath(args[0])
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   217
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   218
elif cmd == "debugindex":
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   219
    r = hg.revlog(open, args[0], "")
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   220
    print "   rev    offset  length  base linkrev"+\
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   221
          " p1           p2           nodeid"
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   222
    for i in range(r.count()):
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   223
        e = r.index[i]
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   224
        print "% 6d % 9d % 7d % 5d % 7d %s.. %s.. %s.." % (
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   225
            i, e[0], e[1], e[2], e[3],
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   226
            hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5]))
57a1eef79415 Add debughash and debugindex commands
mpm@selenic.com
parents: 23
diff changeset
   227
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   228
elif cmd == "merge":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   229
    if args:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   230
        other = hg.repository(ui, args[0])
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   231
        repo.merge(other)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   232
    else:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   233
        print "missing source repository"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   234
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   235
elif cmd == "verify":
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   236
    filelinkrevs = {}
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   237
    filenodes = {}
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   238
    manifestchangeset = {}
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   239
    changesets = revisions = files = 0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   240
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   241
    print "checking changesets"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   242
    for i in range(repo.changelog.count()):
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   243
        changesets += 1
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   244
        n = repo.changelog.node(i)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   245
        changes = repo.changelog.read(n)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   246
        manifestchangeset[changes[0]] = n
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   247
        for f in changes[3]:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   248
            revisions += 1
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   249
            filelinkrevs.setdefault(f, []).append(i)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   250
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   251
    print "checking manifests"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   252
    for i in range(repo.manifest.count()):
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   253
        n = repo.manifest.node(i)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   254
        ca = repo.changelog.node(repo.manifest.linkrev(n))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   255
        cc = manifestchangeset[n]
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   256
        if ca != cc:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   257
            print "manifest %s points to %s, not %s" % \
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   258
                  (hg.hex(n), hg.hex(ca), hg.hex(cc))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   259
        m = repo.manifest.read(n)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   260
        for f, fn in m.items():
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   261
            filenodes.setdefault(f, {})[fn] = 1
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   262
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   263
    print "crosschecking files in changesets and manifests"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   264
    for f in filenodes:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   265
        if f not in filelinkrevs:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   266
            print "file %s in manifest but not in changesets"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   267
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   268
    for f in filelinkrevs:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   269
        if f not in filenodes:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   270
            print "file %s in changeset but not in manifest"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   271
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   272
    print "checking files"
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   273
    for f in filenodes:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   274
        files += 1
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   275
        fl = repo.file(f)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   276
        nodes = {"\0"*20: 1}
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   277
        for i in range(fl.count()):
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   278
            n = fl.node(i)
17
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   279
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   280
            if n not in filenodes[f]:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   281
                print "%s:%s not in manifests" % (f, hg.hex(n))
17
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   282
            else:
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   283
                del filenodes[f][n]
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   284
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   285
            flr = fl.linkrev(n)
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   286
            if flr not in filelinkrevs[f]:
11
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
   287
                print "%s:%s points to unexpected changeset rev %d" \
7f16aaeed62f Allow checkout by number or hash
oxymoron@cinder.waste.org
parents: 5
diff changeset
   288
                      % (f, hg.hex(n), fl.linkrev(n))
17
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   289
            else:
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   290
                filelinkrevs[f].remove(flr)
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   291
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   292
            # verify contents
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   293
            t = fl.read(n)
17
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   294
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   295
            # verify parents
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   296
            (p1, p2) = fl.parents(n)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   297
            if p1 not in nodes:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   298
                print "%s:%s unknown parent 1 %s" % (f, hg.hex(n), hg.hex(p1))
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   299
            if p2 not in nodes:
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   300
                print "file %s:%s unknown parent %s" % (f, hg.hex(n), hg.hex(p1))
17
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   301
            nodes[n] = 1
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   302
17
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   303
        # cross-check
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   304
        for flr in filelinkrevs[f]:
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   305
            print "changeset rev %d not in %s" % (flr, f)
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   306
            
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   307
        for node in filenodes[f]:
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   308
            print "node %s in manifests not in %s" % (hg.hex(n), f)
ffe6a5ca1a89 Make hg verify do more thorough cross-checking.
mpm@selenic.com
parents: 16
diff changeset
   309
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   310
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   311
    print "%d files, %d changesets, %d total revisions" % (files, changesets,
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   312
                                                           revisions)
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   313
    
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   314
else:
18
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
   315
    print "unknown command\n"
2fd3e1e3783f Give a friendlier message when repo isn't found
mpm@selenic.com
parents: 17
diff changeset
   316
    help()
0
9117c6561b0b Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff changeset
   317
    sys.exit(1)