git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob 969d957a11db3c0d13c03c8254161f11f980ecb0 1276 bytes (raw)
name: test-submodule-config.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
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cache.h"
#include "submodule-config.h"

static void die_usage(int argc, char **argv, const char *msg)
{
	fprintf(stderr, "%s\n", msg);
	fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
	exit(1);
}

int main(int argc, char **argv)
{
	char **arg = argv;
	int my_argc = argc;
	int output_url = 0;

	arg++;
	my_argc--;
	while (starts_with(arg[0], "--")) {
		if (!strcmp(arg[0], "--url"))
			output_url = 1;
		arg++;
		my_argc--;
	}

	if (my_argc % 2 != 0)
		die_usage(argc, argv, "Wrong number of arguments.");

	while (*arg) {
		unsigned char commit_sha1[20];
		const struct submodule *submodule;
		const char *commit;
		const char *path;

		commit = arg[0];
		path = arg[1];

		if (commit[0] == '\0')
			hashcpy(commit_sha1, null_sha1);
		else if (get_sha1(commit, commit_sha1) < 0)
			die_usage(argc, argv, "Commit not found.");

		submodule = submodule_from_path(commit_sha1, path);
		if (!submodule)
			die_usage(argc, argv, "Submodule not found.");

		if (output_url)
			printf("Submodule url: '%s' for path '%s'\n",
					submodule->url, path);
		else
			printf("Submodule name: '%s' for path '%s'\n",
					submodule->name, path);

		arg += 2;
	}

	submodule_free();

	return 0;
}

debug log:

solving 969d957 ...
found 969d957 in https://public-inbox.org/git/20140605060750.GC23874@sandbox-ub/

applying [1/1] https://public-inbox.org/git/20140605060750.GC23874@sandbox-ub/
diff --git a/test-submodule-config.c b/test-submodule-config.c
new file mode 100644
index 0000000..969d957

Checking patch test-submodule-config.c...
Applied patch test-submodule-config.c cleanly.

index at:
100644 969d957a11db3c0d13c03c8254161f11f980ecb0	test-submodule-config.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).