git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
b63fe9866589c0eb0921f43f475172e6130160b0 blob 6201 bytes (raw)

  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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
 
#include "builtin.h"
#include "ref-filter.h"
#include "parse-options.h"
#include "metacommit.h"
#include "config.h"

static const char * const builtin_change_usage[] = {
	N_("git change list [<pattern>...]"),
	N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"),
	NULL
};

static const char * const builtin_list_usage[] = {
	N_("git change list [<pattern>...]"),
	NULL
};

static const char * const builtin_update_usage[] = {
	N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"),
	NULL
};

static int change_list(int argc, const char **argv, const char* prefix)
{
	struct option options[] = {
		OPT_END()
	};
	struct ref_filter filter;
	// TODO: Sorting temporarily disabled. See comments, below.
	//struct ref_sorting *sorting = ref_default_sorting();
	struct ref_format format = REF_FORMAT_INIT;
	struct ref_array array;
	int i;

	argc = parse_options(argc, argv, prefix, options, builtin_list_usage, 0);

	setup_ref_filter_porcelain_msg();

	memset(&filter, 0, sizeof(filter));
	memset(&array, 0, sizeof(array));

	filter.kind = FILTER_REFS_CHANGES;
	filter.name_patterns = argv;

	filter_refs(&array, &filter, FILTER_REFS_CHANGES);

	// TODO: This causes a crash. It sets one of the atom_value handlers to
	// something invalid, which causes a crash later when we call
	// show_ref_array_item. Figure out why this happens and put back the sorting.
	//ref_array_sort(sorting, &array);

	if (!format.format) {
		format.format = "%(refname:lstrip=1)";
	}

	if (verify_ref_format(&format))
		die(_("unable to parse format string"));

	for (i = 0; i < array.nr; i++) {
		show_ref_array_item(array.items[i], &format);
	}

	ref_array_clear(&array);

	return 0;
}

struct update_state {
	int options;
	const char* change;
	const char* content;
	struct string_list replace;
	struct string_list origin;
};

static void init_update_state(struct update_state *state)
{
	memset(state, 0, sizeof(*state));
	state->content = "HEAD";
	string_list_init(&state->replace, 0);
	string_list_init(&state->origin, 0);
}

static void clear_update_state(struct update_state *state)
{
	string_list_clear(&state->replace, 0);
	string_list_clear(&state->origin, 0);
}

static int update_option_parse_replace(const struct option *opt,
							const char *arg, int unset)
{
	struct update_state *state = opt->value;
	string_list_append(&state->replace, arg);
	return 0;
}

static int update_option_parse_origin(const struct option *opt,
							const char *arg, int unset)
{
	struct update_state *state = opt->value;
	string_list_append(&state->origin, arg);
	return 0;
}

static int resolve_commit(const char *committish, struct object_id *result)
{
	struct commit *commit;
	if (get_oid_committish(committish, result))
		die(_("Failed to resolve '%s' as a valid revision."), committish);
	commit = lookup_commit_reference(the_repository, result);
	if (!commit)
		die(_("Could not parse object '%s'."), committish);
	oidcpy(result, &commit->object.oid);
	return 0;
}

static void resolve_commit_list(const struct string_list *commitsish_list,
	struct oid_array* result)
{
	int i;
	for (i = 0; i < commitsish_list->nr; i++) {
		struct string_list_item *item = &commitsish_list->items[i];
		struct object_id next;
		resolve_commit(item->string, &next);
		oid_array_append(result, &next);
	}
}

/*
 * Given the command-line options for the update command, fills in a
 * metacommit_data with the corresponding changes.
 */
static void get_metacommit_from_command_line(
	const struct update_state* commands, struct metacommit_data *result)
{
	resolve_commit(commands->content, &(result->content));
	resolve_commit_list(&(commands->replace), &(result->replace));
	resolve_commit_list(&(commands->origin), &(result->origin));
}

static int perform_update(
	struct repository *repo,
	const struct update_state *state,
	struct strbuf *err)
{
	struct metacommit_data metacommit;
	int ret;

	init_metacommit_data(&metacommit);

	get_metacommit_from_command_line(state, &metacommit);

	ret = record_metacommit(repo, &metacommit, state->change, state->options, err);

	clear_metacommit_data(&metacommit);

	return ret;
}

static int change_update(int argc, const char **argv, const char* prefix)
{
	int result;
	int force = 0;
	int newchange = 0;
	struct strbuf err = STRBUF_INIT;
	struct update_state state;
	struct option options[] = {
		{ OPTION_CALLBACK, 'r', "replace", &state, N_("commit"),
			N_("marks the given commit as being obsolete"),
			0, update_option_parse_replace },
		{ OPTION_CALLBACK, 'o', "origin", &state, N_("commit"),
			N_("marks the given commit as being the origin of this commit"),
			0, update_option_parse_origin },
		OPT_BOOL('F', "force", &force,
			N_("overwrite an existing change of the same name")),
		OPT_STRING('c', "content", &state.content, N_("commit"),
				 N_("identifies the new content commit for the change")),
		OPT_STRING('g', "change", &state.change, N_("commit"),
				 N_("name of the change to update")),
		OPT_BOOL('n', "new", &newchange,
			N_("create a new change - do not append to any existing change")),
		OPT_END()
	};

	init_update_state(&state);

	argc = parse_options(argc, argv, prefix, options, builtin_update_usage, 0);

	if (force) state.options |= UPDATE_OPTION_FORCE;
	if (newchange) state.options |= UPDATE_OPTION_NOAPPEND;

	result = perform_update(the_repository, &state, &err);

	if (result < 0) {
		error("%s", err.buf);
		strbuf_release(&err);
	}

	clear_update_state(&state);

	return result;
}

int cmd_change(int argc, const char **argv, const char *prefix)
{
	// No options permitted before subcommand currently
	struct option options[] = {
		OPT_END()
	};
	int result = 1;

	argc = parse_options(argc, argv, prefix, options, builtin_change_usage,
		PARSE_OPT_STOP_AT_NON_OPTION);

	if (argc < 1)
		usage_with_options(builtin_change_usage, options);
	else if (!strcmp(argv[0], "list"))
		result = change_list(argc, argv, prefix);
	else if (!strcmp(argv[0], "update"))
		result = change_update(argc, argv, prefix);
	else {
		error(_("Unknown subcommand: %s"), argv[0]);
		usage_with_options(builtin_change_usage, options);
	}

	return result ? 1 : 0;
}
debug log:

solving b63fe98665 ...
found b63fe98665 in https://public-inbox.org/git/20190121223216.66659-8-sxenos@google.com/ ||
	https://public-inbox.org/git/20190127194415.171035-8-sxenos@google.com/ ||
	https://public-inbox.org/git/20190127194128.161250-8-sxenos@google.com/
found ff7eb3b113 in https://public-inbox.org/git/20190121223216.66659-7-sxenos@google.com/ ||
	https://public-inbox.org/git/20190127194415.171035-7-sxenos@google.com/ ||
	https://public-inbox.org/git/20190127194128.161250-7-sxenos@google.com/

applying [1/6] https://public-inbox.org/git/20190121223216.66659-7-sxenos@google.com/
diff --git a/builtin/change.c b/builtin/change.c
new file mode 100644
index 0000000000..ff7eb3b113

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

skipping https://public-inbox.org/git/20190127194415.171035-7-sxenos@google.com/ for ff7eb3b113
skipping https://public-inbox.org/git/20190127194128.161250-7-sxenos@google.com/ for ff7eb3b113
index at:
100644 ff7eb3b113572ab3b4a3b586701b42aa25053560	builtin/change.c

applying [2/6] https://public-inbox.org/git/20190121223216.66659-8-sxenos@google.com/
diff --git a/builtin/change.c b/builtin/change.c
index ff7eb3b113..b63fe98665 100644

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

skipping https://public-inbox.org/git/20190127194415.171035-8-sxenos@google.com/ for b63fe98665
skipping https://public-inbox.org/git/20190127194128.161250-8-sxenos@google.com/ for b63fe98665
index at:
100644 b63fe9866589c0eb0921f43f475172e6130160b0	builtin/change.c

Code repositories for project(s) associated with this 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).