git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
2f7a3e1db282be7ceb799e378d83029d824459b0 blob 2054 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
 
/*
 * Builtin "git merge-one-file"
 *
 * Copyright (c) 2020 Alban Gruin
 *
 * Based on git-merge-one-file.sh, written by Linus Torvalds.
 *
 * This is the git per-file merge script, called with
 *
 *   $1 - original file SHA1 (or empty)
 *   $2 - file in branch1 SHA1 (or empty)
 *   $3 - file in branch2 SHA1 (or empty)
 *   $4 - pathname in repository
 *   $5 - original file mode (or empty)
 *   $6 - file in branch1 mode (or empty)
 *   $7 - file in branch2 mode (or empty)
 *
 * Handle some trivial cases.. The _really_ trivial cases have
 * been handled already by git read-tree, but that one doesn't
 * do any merges that might change the tree layout.
 */

#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "builtin.h"
#include "lockfile.h"
#include "merge-strategies.h"

static const char builtin_merge_one_file_usage[] =
	"git merge-one-file <orig blob> <our blob> <their blob> <path> "
	"<orig mode> <our mode> <their mode>\n\n"
	"Blob ids and modes should be empty for missing files.";

int cmd_merge_one_file(int argc, const char **argv, const char *prefix)
{
	struct object_id orig_blob, our_blob, their_blob,
		*p_orig_blob = NULL, *p_our_blob = NULL, *p_their_blob = NULL;
	unsigned int orig_mode = 0, our_mode = 0, their_mode = 0, ret;
	struct lock_file lock = LOCK_INIT;

	if (argc != 8)
		usage(builtin_merge_one_file_usage);

	if (read_cache() < 0)
		die("invalid index");

	hold_locked_index(&lock, LOCK_DIE_ON_ERROR);

	if (!get_oid(argv[1], &orig_blob)) {
		p_orig_blob = &orig_blob;
		orig_mode = strtol(argv[5], NULL, 8);
	}

	if (!get_oid(argv[2], &our_blob)) {
		p_our_blob = &our_blob;
		our_mode = strtol(argv[6], NULL, 8);
	}

	if (!get_oid(argv[3], &their_blob)) {
		p_their_blob = &their_blob;
		their_mode = strtol(argv[7], NULL, 8);
	}

	ret = merge_strategies_one_file(the_repository,
					p_orig_blob, p_our_blob, p_their_blob, argv[4],
					orig_mode, our_mode, their_mode);

	if (ret) {
		rollback_lock_file(&lock);
		return ret;
	}

	return write_locked_index(&the_index, &lock, COMMIT_LOCK);
}
debug log:

solving 2f7a3e1db2 ...
found 2f7a3e1db2 in https://public-inbox.org/git/20200625121953.16991-6-alban.gruin@gmail.com/
found d612885723 in https://public-inbox.org/git/20200625121953.16991-5-alban.gruin@gmail.com/
found d9ebd820cb in https://public-inbox.org/git/20200625121953.16991-4-alban.gruin@gmail.com/
found 4992a6cd30 in https://public-inbox.org/git/20200625121953.16991-3-alban.gruin@gmail.com/

applying [1/4] https://public-inbox.org/git/20200625121953.16991-3-alban.gruin@gmail.com/
diff --git a/builtin/merge-one-file.c b/builtin/merge-one-file.c
new file mode 100644
index 0000000000..4992a6cd30


applying [2/4] https://public-inbox.org/git/20200625121953.16991-4-alban.gruin@gmail.com/
diff --git a/builtin/merge-one-file.c b/builtin/merge-one-file.c
index 4992a6cd30..d9ebd820cb 100644


applying [3/4] https://public-inbox.org/git/20200625121953.16991-5-alban.gruin@gmail.com/
diff --git a/builtin/merge-one-file.c b/builtin/merge-one-file.c
index d9ebd820cb..d612885723 100644


applying [4/4] https://public-inbox.org/git/20200625121953.16991-6-alban.gruin@gmail.com/
diff --git a/builtin/merge-one-file.c b/builtin/merge-one-file.c
index d612885723..2f7a3e1db2 100644

Checking patch builtin/merge-one-file.c...
Applied patch builtin/merge-one-file.c cleanly.
Checking patch builtin/merge-one-file.c...
Applied patch builtin/merge-one-file.c cleanly.
Checking patch builtin/merge-one-file.c...
Applied patch builtin/merge-one-file.c cleanly.
Checking patch builtin/merge-one-file.c...
Applied patch builtin/merge-one-file.c cleanly.

index at:
100644 2f7a3e1db282be7ceb799e378d83029d824459b0	builtin/merge-one-file.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).