git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob 3342b91883ad72b8c1caf39e90bb78ce0580ada5 2089 bytes (raw)
name: builtin/authors.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
70
71
72
73
74
75
76
77
78
79
80
81
82
 
#include "builtin.h"
#include "authors.h"
#include "parse-options.h"

static const char *const builtin_authors_usage[] = {
	N_("git authors [<options>]"),
	NULL
};

static int actions;

#define ACTION_LIST (1<<0)
#define ACTION_GET (1<<1)
#define ACTION_SET (1<<2)
#define ACTION_CLEAR (1<<3)

static struct option builtin_authors_options[] = {
	OPT_BIT('c', "clear", &actions, N_("clear current authors"), ACTION_CLEAR),
	OPT_BIT('l', "list", &actions, N_("list all available authors"), ACTION_LIST)
};

static struct string_list authors_map = STRING_LIST_INIT_NODUP;

int cmd_authors(int argc, const char **argv, const char *prefix)
{
	struct string_list_item *item;

	argc = parse_options(argc, argv, prefix, builtin_authors_options,
			     builtin_authors_usage,
			     PARSE_OPT_STOP_AT_NON_OPTION);

	if (actions == 0) {
	if (argc == 0)
		actions = ACTION_GET;
	else
	actions = ACTION_SET;
	}

	read_authors_map_file(&authors_map);

	if (actions == ACTION_LIST)
		for_each_string_list_item(item, &authors_map) {
		printf("%s\n", item->string);
	}
	else if (actions == ACTION_GET) {
		const char *authors_config = NULL;
		const char *expanded_authors;

		if (git_config_get_string_const("authors.current", &authors_config))
			die("No current authors set. Use `git authors <initials> <initials> to set authors.");

		printf("Short:    %s\n", authors_config);

		expanded_authors = expand_authors(&authors_map, authors_config);

		printf("Expanded: %s\n", expanded_authors);
	}
	else if (actions == ACTION_SET) {
		int i;
		static struct strbuf authors_info = STRBUF_INIT;
		int lookup_error = 0;

		for (i = 0; i < argc; ++i) {
			if (!lookup_author(&authors_map, argv[i])) {
				lookup_error--;
				error("Couldn't find author '%s'", argv[i]);
			}
			if (i > 0)
				strbuf_addch(&authors_info, ' ');
				strbuf_addstr(&authors_info, argv[i]);
		}
		if (lookup_error < 0)
			die("Add missing authors to ~/.git_authors_map");

		git_config_set("authors.current", authors_info.buf);
	}
	else if (actions == ACTION_CLEAR) {
		git_config_set("authors.current", NULL);
	}

	return 0;
}

debug log:

solving 3342b91 ...
found 3342b91 in https://public-inbox.org/git/1485713194-11782-1-git-send-email-schumacher@kde.org/

applying [1/1] https://public-inbox.org/git/1485713194-11782-1-git-send-email-schumacher@kde.org/
diff --git a/builtin/authors.c b/builtin/authors.c
new file mode 100644
index 0000000..3342b91

Checking patch builtin/authors.c...
Applied patch builtin/authors.c cleanly.

index at:
100644 3342b91883ad72b8c1caf39e90bb78ce0580ada5	builtin/authors.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).