~abentley/bzrtools/bzrtools.dev

147.1.3 by Robert Collins
test and deliver basic pending-merges into bzr so that merging is recorded
1
# Copyright (C) 2004 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
3
#
4
#    This program is free software; you can redistribute it and/or modify
5
#    it under the terms of the GNU General Public License as published by
6
#    the Free Software Foundation; either version 2 of the License, or
7
#    (at your option) any later version.
8
#
9
#    This program is distributed in the hope that it will be useful,
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#    GNU General Public License for more details.
13
#
14
#    You should have received a copy of the GNU General Public License
15
#    along with this program; if not, write to the Free Software
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
import sys
19
import os
20
import shutil
21
22
sys.path=[os.path.realpath(os.path.dirname(__file__)+"/..")]+sys.path
23
import arch
24
25
import pylon
26
from pylon.util import tmpdir
27
from pylon import errors
28
29
import cmdutil
30
import commands
31
32
__docformat__ = "restructuredtext"
33
__doc__ = "Native show-changeset command"
34
35
class ShowChangeset(commands.BaseCommand):
36
    """Show the changes made by a changeset"""
37
    def __init__(self):
38
        self.description = self.__doc__
39
40
    def get_completer(self, arg, index):
41
        iter_r = cmdutil.iter_revision_completions(arg, arch.tree_root("."))
42
        iter_d = cmdutil.iter_dir_completions(arg)
43
        return cmdutil.iter_combine([iter_r, iter_d])
44
45
46
    def do_command(self, cmdargs):
47
        parser=self.get_parser()
48
        (options, args) = parser.parse_args(cmdargs)
49
        if len(args) != 1:
50
            raise errors.GetHelp
51
        try:
52
            tree = arch.tree_root(".")
53
        except:
54
            tree = None
55
        try:
56
            revision = cmdutil.determine_revision_arch(tree, args[0])
57
            tempdir = tmpdir(os.getcwd())
58
            dir = tempdir
59
        except errors.CantDetermineRevision:
60
            revision = None
61
            if os.access(args[0], os.X_OK) and os.path.isdir(args[0]):
62
                dirspec=args[0]
63
                tempdir = None
64
            elif os.access(args[0], os.R_OK) and os.path.isfile(args[0]):
65
                tempdir = tmpdir(os.getcwd())
66
                dirspec = pylon.util.untar_parent(args[0], tempdir)
67
                
68
            else:
69
                raise
70
        
71
        try:
72
            if revision:
73
                cmdutil.ensure_archive_registered(revision.archive)
74
                changeset = revision.get_patch(dir)
75
            elif dirspec:
76
                changeset = arch.Changeset(dirspec)
77
            try:
78
                munger = pylon.ChangesetMunger(changeset)
79
                munger.read_indices()
80
81
                for line in pylon.iter_changes(munger):
82
                    cmdutil.colorize(line)
83
            except errors.InvalidChangeset, e:
84
                raise errors.CommandFailedWrapper(e)
85
86
            if options.diff:
87
                for line in pylon.diff_iter2(munger.changeset):
88
                    cmdutil.colorize(line)
89
90
        finally:
91
            if tempdir:
92
                shutil.rmtree(tempdir)
93
            
94
        return 0
95
96
    def get_parser(self):
97
        parser = cmdutil.CmdOptionParser("fai show-changeset REVISION/DIR")
98
        parser.add_option("-d", "--diff", action="store_true", 
99
                          dest="diff", help="Show diffs")
100
        return parser
101
102
    def help(self, parser=None):
103
        """
104
        Prints a help message.
105
106
        :param parser: If supplied, the parser to use for generating help.  If \
107
        not supplied, it is retrieved.
108
        :type parser: cmdutil.CmdOptionParser
109
        """
110
        if parser==None:
111
            parser=self.get_parser()
112
        parser.print_help()
113
114
115
def add_command(commands):
116
    commands["show-changeset"] = ShowChangeset
117
118
119
# arch-tag: 04abf5e0-b961-4367-9c47-d2d25f8f0ddb