hgext/hgk.py
author Matt Mackall <mpm@selenic.com>
Thu, 26 Jun 2008 14:35:46 -0500
changeset 6747 f6c00b17387c
parent 6666 53465a7464e2
child 6750 fb42030d79d6
permissions -rw-r--r--
use repo[changeid] to get a changectx
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
# Minimal support for git commands on an hg repository
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     2
#
2859
345bac2bc4ec update copyrights.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2744
diff changeset
     3
# Copyright 2005, 2006 Chris Mason <mason@suse.com>
267
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
# This software may be used and distributed according to the terms
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
     6
# of the GNU General Public License, incorporated herein by reference.
6666
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
     7
'''browsing the repository in a graphical way
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
     8
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
     9
The hgk extension allows browsing the history of a repository in a
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    10
graphical way. It requires Tcl/Tk version 8.4 or later. (Tcl/Tk is
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    11
not distributed with Mercurial.)
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    12
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    13
hgk consists of two parts: a Tcl script that does the displaying and
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    14
querying of information, and an extension to mercurial named hgk.py,
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    15
which provides hooks for hgk to get information. hgk can be found in
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    16
the contrib directory, and hgk.py can be found in the hgext directory.
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    17
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    18
To load the hgext.py extension, add it to your .hgrc file (you have
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    19
to use your global $HOME/.hgrc file, not one in a repository). You
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    20
can specify an absolute path:
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    21
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    22
  [extensions]
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    23
  hgk=/usr/local/lib/hgk.py
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    24
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    25
Mercurial can also scan the default python library path for a file
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    26
named 'hgk.py' if you set hgk empty:
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    27
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    28
  [extensions]
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    29
  hgk=
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    30
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    31
The hg view command will launch the hgk Tcl script. For this command
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    32
to work, hgk must be in your search path. Alternately, you can
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    33
specify the path to hgk in your .hgrc file:
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    34
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    35
  [hgk]
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    36
  path=/location/of/hgk
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    37
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    38
hgk can make use of the extdiff extension to visualize revisions.
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    39
Assuming you had already configured extdiff vdiff command, just add:
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    40
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    41
  [hgk]
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    42
  vdiff=vdiff
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    43
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    44
Revisions context menu will now display additional entries to fire
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6616
diff changeset
    45
vdiff on hovered and selected revisions.'''
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    46
5878
d39af2eabb8c transform a bunch of print statements to appropriate ui calls
Matt Mackall <mpm@selenic.com>
parents: 5859
diff changeset
    47
import os
6599
cd4db3999ef9 status: use match helpers for various users
Matt Mackall <mpm@selenic.com>
parents: 6217
diff changeset
    48
from mercurial import commands, util, patch, revlog, cmdutil
6217
fe8dbbe9520d Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents: 6212
diff changeset
    49
from mercurial.node import nullid, nullrev, short
1239
29f17e083e84 Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents: 740
diff changeset
    50
3063
aa1cee5b8afb hgk.py: add an optional file list to debug-diff-tree
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3059
diff changeset
    51
def difftree(ui, repo, node1=None, node2=None, *files, **opts):
1239
29f17e083e84 Turn hgit into an extension, and add commands supporting the latest gitk
mason@suse.com
parents: 740
diff changeset
    52
    """diff trees from two commits"""
3063
aa1cee5b8afb hgk.py: add an optional file list to debug-diff-tree
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3059
diff changeset
    53
    def __difftree(repo, node1, node2, files=[]):
3978
ee5663cb4406 hgk: remove unused code, node2 is always set
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3963
diff changeset
    54
        assert node2 is not None
6747
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6666
diff changeset
    55
        mmap = repo[node1].manifest()
f6c00b17387c use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents: 6666
diff changeset
    56
        mmap2 = repo[node2].manifest()
6616
e9dfe4e3ee6f hgk: difftree must match all files when supplied list is empty
Patrick Mezard <pmezard@gmail.com>
parents: 6603
diff changeset
    57
        m = cmdutil.match(repo, files)
6603
41eb20cc1c02 match: remove files arg from repo.status and friends
Matt Mackall <mpm@selenic.com>
parents: 6602
diff changeset
    58
        status = repo.status(node1, node2, match=m)[:5]
3978
ee5663cb4406 hgk: remove unused code, node2 is always set
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 3963
diff changeset
    59
        modified, added, removed, deleted, unknown = status
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    60
6217
fe8dbbe9520d Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents: 6212
diff changeset
    61
        empty = short(nullid)
267
497aa6d276d2 Initial import of hgit and hgk
mpm@selenic.com
parents:
diff changeset
    62
1618
ff339dd21976 Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1614
diff changeset
    63
        for f in modified:
334
290574209284 hgit: remove tabs
mpm@selenic.com
parents: 280
diff changeset
    64
            # TODO get file permissions
5878
d39af2eabb8c transform a bunch of print statements to appropriate ui calls
Matt Mackall <mpm@selenic.com>
parents: