builtin-diff-files.c 1.29 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5
/*
 * GIT - The information manager from hell
 *
 * Copyright (C) Linus Torvalds, 2005
 */
6
#include "cache.h"
7
#include "diff.h"
8 9
#include "commit.h"
#include "revision.h"
10
#include "builtin.h"
11

12
static const char diff_files_usage[] =
13
"git-diff-files [-q] [-0/-1/2/3 |-c|--cc] [<common diff options>] [<path>...]"
14
COMMON_DIFF_OPTIONS_HELP;
15

16
int cmd_diff_files(int argc, const char **argv, const char *prefix)
17
{
Junio C Hamano's avatar
Junio C Hamano committed
18 19
	struct rev_info rev;
	int silent = 0;
20

21
	init_revisions(&rev, prefix);
22
	git_config(git_default_config); /* no "diff" UI options */
Junio C Hamano's avatar
Junio C Hamano committed
23 24 25
	rev.abbrev = 0;

	argc = setup_revisions(argc, argv, &rev, NULL);
26
	while (1 < argc && argv[1][0] == '-') {
Junio C Hamano's avatar
Junio C Hamano committed
27 28
		if (!strcmp(argv[1], "--base"))
			rev.max_count = 1;
29
		else if (!strcmp(argv[1], "--ours"))
Junio C Hamano's avatar
Junio C Hamano committed
30
			rev.max_count = 2;
31
		else if (!strcmp(argv[1], "--theirs"))
Junio C Hamano's avatar
Junio C Hamano committed
32
			rev.max_count = 3;
33
		else if (!strcmp(argv[1], "-q"))
34
			silent = 1;
Junio C Hamano's avatar
Junio C Hamano committed
35 36
		else
			usage(diff_files_usage);
37
		argv++; argc--;
38
	}
39 40 41
	if (!rev.diffopt.output_format)
		rev.diffopt.output_format = DIFF_FORMAT_RAW;

Junio C Hamano's avatar
Junio C Hamano committed
42 43 44 45 46
	/*
	 * Make sure there are NO revision (i.e. pending object) parameter,
	 * rev.max_count is reasonable (0 <= n <= 3),
	 * there is no other revision filtering parameters.
	 */
47
	if (rev.pending.nr ||
Junio C Hamano's avatar
Junio C Hamano committed
48
	    rev.min_age != -1 || rev.max_age != -1)
Junio C Hamano's avatar
Junio C Hamano committed
49
		usage(diff_files_usage);
Junio C Hamano's avatar
Junio C Hamano committed
50
	return run_diff_files(&rev, silent);
51
}