notes-merge.h 2.81 KB
Newer Older
1 2 3
#ifndef NOTES_MERGE_H
#define NOTES_MERGE_H

4 5
#include "notes-utils.h"

6 7
#define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE"

8 9 10 11 12 13 14 15
enum notes_merge_verbosity {
	NOTES_MERGE_VERBOSITY_DEFAULT = 2,
	NOTES_MERGE_VERBOSITY_MAX = 5
};

struct notes_merge_options {
	const char *local_ref;
	const char *remote_ref;
16
	struct strbuf commit_msg;
17
	int verbosity;
18
	enum notes_merge_strategy strategy;
19
	unsigned has_worktree:1;
20 21 22 23 24 25 26
};

void init_notes_merge_options(struct notes_merge_options *o);

/*
 * Merge notes from o->remote_ref into o->local_ref
 *
27 28 29 30
 * The given notes_tree 'local_tree' must be the notes_tree referenced by the
 * o->local_ref. This is the notes_tree in which the object-level merge is
 * performed.
 *
31 32 33 34
 * The commits given by the two refs are merged, producing one of the following
 * outcomes:
 *
 * 1. The merge trivially results in an existing commit (e.g. fast-forward or
35 36
 *    already-up-to-date). 'local_tree' is untouched, the OID of the result
 *    is written into 'result_oid' and 0 is returned.
37
 * 2. The merge successfully completes, producing a merge commit. local_tree
38 39
 *    contains the updated notes tree, the OID of the resulting commit is
 *    written into 'result_oid', and 1 is returned.
40 41
 * 3. The merge results in conflicts. This is similar to #2 in that the
 *    partial merge result (i.e. merge result minus the unmerged entries)
42
 *    are stored in 'local_tree', and the OID or the resulting commit
43
 *    (to be amended when the conflicts have been resolved) is written into
44
 *    'result_oid'. The unmerged entries are written into the
45 46
 *    .git/NOTES_MERGE_WORKTREE directory with conflict markers.
 *    -1 is returned.
47 48 49 50 51 52 53
 *
 * Both o->local_ref and o->remote_ref must be given (non-NULL), but either ref
 * (although not both) may refer to a non-existing notes ref, in which case
 * that notes ref is interpreted as an empty notes tree, and the merge
 * trivially results in what the other ref points to.
 */
int notes_merge(struct notes_merge_options *o,
54
		struct notes_tree *local_tree,
55
		struct object_id *result_oid);
56

57 58 59 60 61 62 63 64
/*
 * Finalize conflict resolution from an earlier notes_merge()
 *
 * The given notes tree 'partial_tree' must be the notes_tree corresponding to
 * the given 'partial_commit', the partial result commit created by a previous
 * call to notes_merge().
 *
 * This function will add the (now resolved) notes in .git/NOTES_MERGE_WORKTREE
65 66
 * to 'partial_tree', and create a final notes merge commit, the OID of which
 * will be stored in 'result_oid'.
67 68 69 70
 */
int notes_merge_commit(struct notes_merge_options *o,
		       struct notes_tree *partial_tree,
		       struct commit *partial_commit,
71
		       struct object_id *result_oid);
72 73 74 75 76 77 78 79

/*
 * Abort conflict resolution from an earlier notes_merge()
 *
 * Removes the notes merge worktree in .git/NOTES_MERGE_WORKTREE.
 */
int notes_merge_abort(struct notes_merge_options *o);

80
#endif