git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob c9f5c5aae42b0eeb2c3c58517ede1315993fd434 4492 bytes (raw)
name: t/helper/test-proc-receive.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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
 
#include "cache.h"
#include "connect.h"
#include "parse-options.h"
#include "pkt-line.h"
#include "sigchain.h"
#include "string-list.h"
#include "test-tool.h"

static const char *proc_receive_usage[] = {
	"test-tool proc-receive [<options>...]",
	NULL
};

static int version = 1;
static int verbose = 0;
static int no_push_options = 0;
static int use_atomic = 0;
static int use_push_options = 0;
static struct string_list returns = STRING_LIST_INIT_NODUP;

struct command {
	struct command *next;
	const char *error_string;
	unsigned int skip_update:1,
		     did_not_exist:1;
	int index;
	struct object_id old_oid;
	struct object_id new_oid;
	char ref_name[FLEX_ARRAY]; /* more */
};

static void proc_receive_verison(struct packet_reader *reader) {
	int server_version = 0;

	for (;;) {
		int linelen;

		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
			break;

		if (reader->pktlen > 8 && starts_with(reader->line, "version=")) {
			server_version = atoi(reader->line+8);
			linelen = strlen(reader->line);
			if (linelen < reader->pktlen) {
				const char *feature_list = reader->line + linelen + 1;
				if (parse_feature_request(feature_list, "atomic"))
					use_atomic= 1;
				if (parse_feature_request(feature_list, "push-options"))
					use_push_options = 1;
			}
		}
	}

	if (server_version != 1)
		die("bad protocol version: %d", server_version);

	packet_write_fmt(1, "version=%d%c%s\n",
			 version, '\0',
			 use_push_options && !no_push_options ? "push-options": "");
	packet_flush(1);
}

static void proc_receive_read_commands(struct packet_reader *reader,
				       struct command **commands)
{
	struct command **tail = commands;

	for (;;) {
		struct object_id old_oid, new_oid;
		struct command *cmd;
		const char *refname;
		const char *p;

		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
			break;

		if (parse_oid_hex(reader->line, &old_oid, &p) ||
		    *p++ != ' ' ||
		    parse_oid_hex(p, &new_oid, &p) ||
		    *p++ != ' ')
			die("protocol error: expected 'old new ref', got '%s'",
			    reader->line);
		refname = p;
		FLEX_ALLOC_STR(cmd, ref_name, refname);
		oidcpy(&cmd->old_oid, &old_oid);
		oidcpy(&cmd->new_oid, &new_oid);

		*tail = cmd;
		tail = &cmd->next;
	}
}

static void proc_receive_read_push_options(struct packet_reader *reader,
					   struct string_list *options)
{

	if (no_push_options || !use_push_options)
	       return;

	while (1) {
		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
			break;

		string_list_append(options, reader->line);
	}
}

int cmd__proc_receive(int argc, const char **argv)
{
	struct packet_reader reader;
	struct command *commands = NULL;
	struct string_list push_options = STRING_LIST_INIT_DUP;
	struct string_list_item *item;
	struct option options[] = {
		OPT_BOOL(0, "no-push-options", &no_push_options,
			 "disable push options"),
		OPT_STRING_LIST('r', "return", &returns, "old/new/ref/status/msg",
				"return of results"),
		OPT__VERBOSE(&verbose, "be verbose"),
		OPT_INTEGER('V', "version", &version,
			    "use this protocol version number"),
		OPT_END()
	};

	argc = parse_options(argc, argv, "test-tools", options, proc_receive_usage, 0);
	if (argc > 0)
		usage_msg_opt("Too many arguments.", proc_receive_usage, options);

	packet_reader_init(&reader, 0, NULL, 0,
			   PACKET_READ_CHOMP_NEWLINE |
			   PACKET_READ_DIE_ON_ERR_PACKET);

	sigchain_push(SIGPIPE, SIG_IGN);
	proc_receive_verison(&reader);
	proc_receive_read_commands(&reader, &commands);
	proc_receive_read_push_options(&reader, &push_options);

	if (verbose) {
		struct command *cmd;

		if (use_push_options || use_atomic)
			fprintf(stderr, "proc-receive:%s%s\n",
				use_atomic? " atomic": "",
				use_push_options ? " push_options": "");

		for (cmd = commands; cmd; cmd = cmd->next)
			fprintf(stderr, "proc-receive< %s %s %s\n",
				oid_to_hex(&cmd->old_oid),
				oid_to_hex(&cmd->new_oid),
				cmd->ref_name);

		if (push_options.nr > 0)
			for_each_string_list_item(item, &push_options)
				fprintf(stderr, "proc-receive< %s\n", item->string);

		if (returns.nr)
			for_each_string_list_item(item, &returns)
				fprintf(stderr, "proc-receive> %s\n", item->string);
	}

	if (returns.nr)
		for_each_string_list_item(item, &returns) {
			char *p;

			p = strstr(item->string, "\\0");
			if (p) {
				*p = '\0';
				p += 2;
				packet_write_fmt(1, "%s%c%s\n", item->string, '\0', p);
			} else {
				packet_write_fmt(1, "%s\n", item->string);
			}
		}
	packet_flush(1);
	sigchain_pop(SIGPIPE);

	return 0;
}

debug log:

solving c9f5c5aae4 ...
found c9f5c5aae4 in https://public-inbox.org/git/20200412133022.17590-7-worldhello.net@gmail.com/ ||
	https://public-inbox.org/git/20200414123257.27449-4-worldhello.net@gmail.com/ ||
	https://public-inbox.org/git/20200413164828.23260-4-worldhello.net@gmail.com/
found 8fb143d692 in https://public-inbox.org/git/20200412133022.17590-3-worldhello.net@gmail.com/

applying [1/2] https://public-inbox.org/git/20200412133022.17590-3-worldhello.net@gmail.com/
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
new file mode 100644
index 0000000000..8fb143d692


applying [2/2] https://public-inbox.org/git/20200412133022.17590-7-worldhello.net@gmail.com/
diff --git a/t/helper/test-proc-receive.c b/t/helper/test-proc-receive.c
index 8fb143d692..c9f5c5aae4 100644

Checking patch t/helper/test-proc-receive.c...
Applied patch t/helper/test-proc-receive.c cleanly.
Checking patch t/helper/test-proc-receive.c...
Applied patch t/helper/test-proc-receive.c cleanly.

skipping https://public-inbox.org/git/20200414123257.27449-4-worldhello.net@gmail.com/ for c9f5c5aae4
skipping https://public-inbox.org/git/20200413164828.23260-4-worldhello.net@gmail.com/ for c9f5c5aae4
index at:
100644 c9f5c5aae42b0eeb2c3c58517ede1315993fd434	t/helper/test-proc-receive.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).