blob: 6c74e9385b83ce317d6ca91f328c7790d0753e2c [file] [log] [blame]
Johan Herland75ef3f42010-11-09 22:49:46 +01001#ifndef NOTES_MERGE_H
2#define NOTES_MERGE_H
3
Jacob Keller4d03dd12015-08-17 14:33:30 -07004#include "notes-utils.h"
Elijah Newrenef3ca952018-08-15 10:54:05 -07005#include "strbuf.h"
6
7struct commit;
8struct object_id;
Jacob Keller4d03dd12015-08-17 14:33:30 -07009
Johan Herland809f38c2010-11-09 22:49:51 +010010#define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE"
11
Johan Herland75ef3f42010-11-09 22:49:46 +010012enum notes_merge_verbosity {
13 NOTES_MERGE_VERBOSITY_DEFAULT = 2,
14 NOTES_MERGE_VERBOSITY_MAX = 5
15};
16
17struct notes_merge_options {
18 const char *local_ref;
19 const char *remote_ref;
Johan Herland443259c2010-11-09 22:49:53 +010020 struct strbuf commit_msg;
Johan Herland75ef3f42010-11-09 22:49:46 +010021 int verbosity;
Jacob Keller4d03dd12015-08-17 14:33:30 -070022 enum notes_merge_strategy strategy;
Johan Herland809f38c2010-11-09 22:49:51 +010023 unsigned has_worktree:1;
Johan Herland75ef3f42010-11-09 22:49:46 +010024};
25
26void init_notes_merge_options(struct notes_merge_options *o);
27
28/*
Johan Herland75ef3f42010-11-09 22:49:46 +010029 * Merge notes from o->remote_ref into o->local_ref
30 *
Johan Herland2085b162010-11-15 00:54:11 +010031 * The given notes_tree 'local_tree' must be the notes_tree referenced by the
32 * o->local_ref. This is the notes_tree in which the object-level merge is
33 * performed.
34 *
Johan Herland75ef3f42010-11-09 22:49:46 +010035 * The commits given by the two refs are merged, producing one of the following
36 * outcomes:
37 *
38 * 1. The merge trivially results in an existing commit (e.g. fast-forward or
Brandon Williams5237e0e2017-05-30 10:30:58 -070039 * already-up-to-date). 'local_tree' is untouched, the OID of the result
40 * is written into 'result_oid' and 0 is returned.
Johan Herland2085b162010-11-15 00:54:11 +010041 * 2. The merge successfully completes, producing a merge commit. local_tree
Brandon Williams5237e0e2017-05-30 10:30:58 -070042 * contains the updated notes tree, the OID of the resulting commit is
43 * written into 'result_oid', and 1 is returned.
Johan Herland809f38c2010-11-09 22:49:51 +010044 * 3. The merge results in conflicts. This is similar to #2 in that the
45 * partial merge result (i.e. merge result minus the unmerged entries)
Brandon Williams5237e0e2017-05-30 10:30:58 -070046 * are stored in 'local_tree', and the OID or the resulting commit
Johan Herland809f38c2010-11-09 22:49:51 +010047 * (to be amended when the conflicts have been resolved) is written into
Brandon Williams5237e0e2017-05-30 10:30:58 -070048 * 'result_oid'. The unmerged entries are written into the
Johan Herland809f38c2010-11-09 22:49:51 +010049 * .git/NOTES_MERGE_WORKTREE directory with conflict markers.
50 * -1 is returned.
Johan Herland75ef3f42010-11-09 22:49:46 +010051 *
52 * Both o->local_ref and o->remote_ref must be given (non-NULL), but either ref
53 * (although not both) may refer to a non-existing notes ref, in which case
54 * that notes ref is interpreted as an empty notes tree, and the merge
55 * trivially results in what the other ref points to.
56 */
57int notes_merge(struct notes_merge_options *o,
Johan Herland2085b162010-11-15 00:54:11 +010058 struct notes_tree *local_tree,
Brandon Williams5237e0e2017-05-30 10:30:58 -070059 struct object_id *result_oid);
Johan Herland75ef3f42010-11-09 22:49:46 +010060
Johan Herland6abb3652010-11-09 22:49:52 +010061/*
62 * Finalize conflict resolution from an earlier notes_merge()
63 *
64 * The given notes tree 'partial_tree' must be the notes_tree corresponding to
65 * the given 'partial_commit', the partial result commit created by a previous
66 * call to notes_merge().
67 *
68 * This function will add the (now resolved) notes in .git/NOTES_MERGE_WORKTREE
Brandon Williams5237e0e2017-05-30 10:30:58 -070069 * to 'partial_tree', and create a final notes merge commit, the OID of which
70 * will be stored in 'result_oid'.
Johan Herland6abb3652010-11-09 22:49:52 +010071 */
72int notes_merge_commit(struct notes_merge_options *o,
73 struct notes_tree *partial_tree,
74 struct commit *partial_commit,
Brandon Williams5237e0e2017-05-30 10:30:58 -070075 struct object_id *result_oid);
Johan Herland6abb3652010-11-09 22:49:52 +010076
77/*
78 * Abort conflict resolution from an earlier notes_merge()
79 *
80 * Removes the notes merge worktree in .git/NOTES_MERGE_WORKTREE.
81 */
82int notes_merge_abort(struct notes_merge_options *o);
83
Johan Herland75ef3f42010-11-09 22:49:46 +010084#endif