blob: 99f9c709c536ac19c677e97348e9924c2764d217 [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;
Nguyễn Thái Ngọc Duy56842002018-11-10 06:48:53 +01009struct repository;
Jacob Keller4d03dd12015-08-17 14:33:30 -070010
Johan Herland809f38c2010-11-09 22:49:51 +010011#define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE"
12
Johan Herland75ef3f42010-11-09 22:49:46 +010013enum notes_merge_verbosity {
14 NOTES_MERGE_VERBOSITY_DEFAULT = 2,
15 NOTES_MERGE_VERBOSITY_MAX = 5
16};
17
18struct notes_merge_options {
Nguyễn Thái Ngọc Duy56842002018-11-10 06:48:53 +010019 struct repository *repo;
Johan Herland75ef3f42010-11-09 22:49:46 +010020 const char *local_ref;
21 const char *remote_ref;
Johan Herland443259c2010-11-09 22:49:53 +010022 struct strbuf commit_msg;
Johan Herland75ef3f42010-11-09 22:49:46 +010023 int verbosity;
Jacob Keller4d03dd12015-08-17 14:33:30 -070024 enum notes_merge_strategy strategy;
Johan Herland809f38c2010-11-09 22:49:51 +010025 unsigned has_worktree:1;
Johan Herland75ef3f42010-11-09 22:49:46 +010026};
27
Nguyễn Thái Ngọc Duy56842002018-11-10 06:48:53 +010028void init_notes_merge_options(struct repository *r,
29 struct notes_merge_options *o);
Johan Herland75ef3f42010-11-09 22:49:46 +010030
31/*
Johan Herland75ef3f42010-11-09 22:49:46 +010032 * Merge notes from o->remote_ref into o->local_ref
33 *
Johan Herland2085b162010-11-15 00:54:11 +010034 * The given notes_tree 'local_tree' must be the notes_tree referenced by the
35 * o->local_ref. This is the notes_tree in which the object-level merge is
36 * performed.
37 *
Johan Herland75ef3f42010-11-09 22:49:46 +010038 * The commits given by the two refs are merged, producing one of the following
39 * outcomes:
40 *
41 * 1. The merge trivially results in an existing commit (e.g. fast-forward or
Brandon Williams5237e0e2017-05-30 10:30:58 -070042 * already-up-to-date). 'local_tree' is untouched, the OID of the result
43 * is written into 'result_oid' and 0 is returned.
Johan Herland2085b162010-11-15 00:54:11 +010044 * 2. The merge successfully completes, producing a merge commit. local_tree
Brandon Williams5237e0e2017-05-30 10:30:58 -070045 * contains the updated notes tree, the OID of the resulting commit is
46 * written into 'result_oid', and 1 is returned.
Johan Herland809f38c2010-11-09 22:49:51 +010047 * 3. The merge results in conflicts. This is similar to #2 in that the
48 * partial merge result (i.e. merge result minus the unmerged entries)
Brandon Williams5237e0e2017-05-30 10:30:58 -070049 * are stored in 'local_tree', and the OID or the resulting commit
Johan Herland809f38c2010-11-09 22:49:51 +010050 * (to be amended when the conflicts have been resolved) is written into
Brandon Williams5237e0e2017-05-30 10:30:58 -070051 * 'result_oid'. The unmerged entries are written into the
Johan Herland809f38c2010-11-09 22:49:51 +010052 * .git/NOTES_MERGE_WORKTREE directory with conflict markers.
53 * -1 is returned.
Johan Herland75ef3f42010-11-09 22:49:46 +010054 *
55 * Both o->local_ref and o->remote_ref must be given (non-NULL), but either ref
56 * (although not both) may refer to a non-existing notes ref, in which case
57 * that notes ref is interpreted as an empty notes tree, and the merge
58 * trivially results in what the other ref points to.
59 */
60int notes_merge(struct notes_merge_options *o,
Johan Herland2085b162010-11-15 00:54:11 +010061 struct notes_tree *local_tree,
Brandon Williams5237e0e2017-05-30 10:30:58 -070062 struct object_id *result_oid);
Johan Herland75ef3f42010-11-09 22:49:46 +010063
Johan Herland6abb3652010-11-09 22:49:52 +010064/*
65 * Finalize conflict resolution from an earlier notes_merge()
66 *
67 * The given notes tree 'partial_tree' must be the notes_tree corresponding to
68 * the given 'partial_commit', the partial result commit created by a previous
69 * call to notes_merge().
70 *
71 * This function will add the (now resolved) notes in .git/NOTES_MERGE_WORKTREE
Brandon Williams5237e0e2017-05-30 10:30:58 -070072 * to 'partial_tree', and create a final notes merge commit, the OID of which
73 * will be stored in 'result_oid'.
Johan Herland6abb3652010-11-09 22:49:52 +010074 */
75int notes_merge_commit(struct notes_merge_options *o,
76 struct notes_tree *partial_tree,
77 struct commit *partial_commit,
Brandon Williams5237e0e2017-05-30 10:30:58 -070078 struct object_id *result_oid);
Johan Herland6abb3652010-11-09 22:49:52 +010079
80/*
81 * Abort conflict resolution from an earlier notes_merge()
82 *
83 * Removes the notes merge worktree in .git/NOTES_MERGE_WORKTREE.
84 */
85int notes_merge_abort(struct notes_merge_options *o);
86
Johan Herland75ef3f42010-11-09 22:49:46 +010087#endif