Separate the commands in stgit/commands/* files
[stgit] / stgit / commands / diff.py
1
2 __copyright__ = """
3 Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation.
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
19 import sys, os
20 from optparse import OptionParser, make_option
21
22 from stgit.commands.common import *
23 from stgit.utils import *
24 from stgit import stack, git
25
26
27 help = 'show the tree diff'
28 usage = """%prog [options] [<files...>]
29
30 The revision format is '([patch]/[bottom | top]) | <tree-ish>'"""
31
32 options = [make_option('-r', metavar = 'rev1[:[rev2]]', dest = 'revs',
33 help = 'show the diff between revisions'),
34 make_option('-s', '--stat',
35 help = 'show the stat instead of the diff',
36 action = 'store_true')]
37
38
39 def func(parser, options, args):
40 """Show the tree diff
41 """
42 if options.revs:
43 rev_list = options.revs.split(':')
44 rev_list_len = len(rev_list)
45 if rev_list_len == 1:
46 if rev_list[0][-1] == '/':
47 # the whole patch
48 rev1 = rev_list[0] + 'bottom'
49 rev2 = rev_list[0] + 'top'
50 else:
51 rev1 = rev_list[0]
52 rev2 = None
53 elif rev_list_len == 2:
54 rev1 = rev_list[0]
55 rev2 = rev_list[1]
56 if rev2 == '':
57 rev2 = 'HEAD'
58 else:
59 parser.error('incorrect parameters to -r')
60 else:
61 rev1 = 'HEAD'
62 rev2 = None
63
64 if options.stat:
65 print git.diffstat(args, git_id(rev1), git_id(rev2))
66 else:
67 git.diff(args, git_id(rev1), git_id(rev2))