git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob c1212cc8d463a65b516b11c1d0b79dca5b1a0e98 1510 bytes (raw)
name: builtin/ahead-behind.c 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
#include "builtin.h"
#include "parse-options.h"
#include "config.h"
#include "commit.h"

static const char * const ahead_behind_usage[] = {
	N_("git ahead-behind --base=<ref> [ --stdin | <revs> ]"),
	NULL
};

static int handle_arg(struct string_list *tips, const char *arg)
{
	struct string_list_item *item;
	struct commit *c = lookup_commit_reference_by_name(arg);

	if (!c)
		return error(_("could not resolve '%s'"), arg);

	item = string_list_append(tips, arg);
	item->util = c;
	return 0;
}

int cmd_ahead_behind(int argc, const char **argv, const char *prefix)
{
	const char *base_ref = NULL;
	int from_stdin = 0;
	struct string_list tips = STRING_LIST_INIT_DUP;

	struct option ahead_behind_opts[] = {
		OPT_STRING('b', "base", &base_ref, N_("base"), N_("base reference to process")),
		OPT_BOOL(0 , "stdin", &from_stdin, N_("read rev names from stdin")),
		OPT_END()
	};

	argc = parse_options(argc, argv, NULL, ahead_behind_opts,
			     ahead_behind_usage, PARSE_OPT_KEEP_UNKNOWN_OPT);

	if (!base_ref)
		usage_with_options(ahead_behind_usage, ahead_behind_opts);

	git_config(git_default_config, NULL);

	if (from_stdin) {
		struct strbuf line = STRBUF_INIT;

		while (strbuf_getline(&line, stdin) != EOF) {
			if (!line.len)
				break;

			if (handle_arg(&tips, line.buf))
				return 1;
		}

		strbuf_release(&line);
	} else {
		int i;
		for (i = 0; i < argc; ++i) {
			if (handle_arg(&tips, argv[i]))
				return 1;
		}
	}

	/* Early return for no tips. */
	if (!tips.nr)
		return 0;

	return 0;
}

debug log:

solving c1212cc8d46 ...
found c1212cc8d46 in https://public-inbox.org/git/08fc0710017d4b6178a8c5772e0f15fc69c84ad6.1678111599.git.gitgitgadget@gmail.com/
found a56cc565def in https://public-inbox.org/git/0fd18b6d740f1e8a6f62a25947bc3ad49c2674a6.1678111599.git.gitgitgadget@gmail.com/

applying [1/2] https://public-inbox.org/git/0fd18b6d740f1e8a6f62a25947bc3ad49c2674a6.1678111599.git.gitgitgadget@gmail.com/
diff --git a/builtin/ahead-behind.c b/builtin/ahead-behind.c
new file mode 100644
index 00000000000..a56cc565def


applying [2/2] https://public-inbox.org/git/08fc0710017d4b6178a8c5772e0f15fc69c84ad6.1678111599.git.gitgitgadget@gmail.com/
diff --git a/builtin/ahead-behind.c b/builtin/ahead-behind.c
index a56cc565def..c1212cc8d46 100644

Checking patch builtin/ahead-behind.c...
Applied patch builtin/ahead-behind.c cleanly.
Checking patch builtin/ahead-behind.c...
Applied patch builtin/ahead-behind.c cleanly.

index at:
100644 c1212cc8d463a65b516b11c1d0b79dca5b1a0e98	builtin/ahead-behind.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).