git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob 30691fccd77c57577ddaff0d9b6e7a02279c3c70 1892 bytes (raw)
name: merge-strategies.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
 
#include "cache.h"
#include "merge-strategies.h"

static int merge_entry(struct index_state *istate, unsigned int pos,
		       const char *path, int *err, merge_index_fn fn,
		       void *data)
{
	int found = 0;
	const struct object_id *oids[3] = { 0 };
	unsigned int modes[3] = { 0 };

	*err = 0;

	if (pos >= istate->cache_nr)
		die(_("'%s' is not in the cache"), path);
	do {
		const struct cache_entry *ce = istate->cache[pos];
		int stage = ce_stage(ce);

		if (strcmp(ce->name, path))
			break;
		found++;
		oids[stage - 1] = &ce->oid;
		modes[stage - 1] = ce->ce_mode;
	} while (++pos < istate->cache_nr);
	if (!found)
		die(_("'%s' is not in the cache"), path);

	if (fn(istate, oids[0], oids[1], oids[2], path, modes[0], modes[1],
	       modes[2], data))
		(*err)++;

	return found;
}

int merge_index_path(struct index_state *istate, int oneshot, int quiet,
		     const char *path, merge_index_fn fn, void *data)
{
	int err, ret;
	int pos = index_name_pos(istate, path, strlen(path));

	/*
	 * If it already exists in the cache as stage0, it's
	 * already merged and there is nothing to do.
	 */
	if (pos >= 0)
		return 0;

	ret = merge_entry(istate, -pos - 1, path, &err, fn, data);
	if (ret < 0)
		return ret;
	if (err) {
		if (!quiet && !oneshot)
			die(_("merge program failed"));
		return 1;
	}
	return 0;
}

int merge_all_index(struct index_state *istate, int oneshot, int quiet,
		    merge_index_fn fn, void *data)
{
	int err, ret;
	unsigned int i;

	for (i = 0; i < istate->cache_nr; i++) {
		const struct cache_entry *ce = istate->cache[i];
		if (!ce_stage(ce))
			continue;

		ret = merge_entry(istate, i, ce->name, &err, fn, data);
		if (ret < 0)
			return ret;
		else if (ret > 0)
			i += ret - 1;

		if (err && !oneshot) {
			if (!quiet)
				die(_("merge program failed"));
			return 1;
		}
	}

	if (err && !quiet)
		die(_("merge program failed"));
	return err;
}

debug log:

solving 30691fccd77 ...
found 30691fccd77 in https://public-inbox.org/git/patch-v9-10.12-c7a131a9a86-20221118T110058Z-avarab@gmail.com/ ||
	https://public-inbox.org/git/patch-v10-10.12-0efc5039e46-20221215T084803Z-avarab@gmail.com/

applying [1/1] https://public-inbox.org/git/patch-v9-10.12-c7a131a9a86-20221118T110058Z-avarab@gmail.com/
diff --git a/merge-strategies.c b/merge-strategies.c
new file mode 100644
index 00000000000..30691fccd77

Checking patch merge-strategies.c...
Applied patch merge-strategies.c cleanly.

skipping https://public-inbox.org/git/patch-v10-10.12-0efc5039e46-20221215T084803Z-avarab@gmail.com/ for 30691fccd77
index at:
100644 30691fccd77c57577ddaff0d9b6e7a02279c3c70	merge-strategies.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).