Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 1 | #ifndef NOTES_MERGE_H |
| 2 | #define NOTES_MERGE_H |
| 3 | |
Jacob Keller | 4d03dd1 | 2015-08-17 14:33:30 -0700 | [diff] [blame] | 4 | #include "notes-utils.h" |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 5 | #include "strbuf.h" |
| 6 | |
| 7 | struct commit; |
| 8 | struct object_id; |
Nguyễn Thái Ngọc Duy | 5684200 | 2018-11-10 06:48:53 +0100 | [diff] [blame] | 9 | struct repository; |
Jacob Keller | 4d03dd1 | 2015-08-17 14:33:30 -0700 | [diff] [blame] | 10 | |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 11 | #define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE" |
| 12 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 13 | enum notes_merge_verbosity { |
| 14 | NOTES_MERGE_VERBOSITY_DEFAULT = 2, |
| 15 | NOTES_MERGE_VERBOSITY_MAX = 5 |
| 16 | }; |
| 17 | |
| 18 | struct notes_merge_options { |
Nguyễn Thái Ngọc Duy | 5684200 | 2018-11-10 06:48:53 +0100 | [diff] [blame] | 19 | struct repository *repo; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 20 | const char *local_ref; |
| 21 | const char *remote_ref; |
Johan Herland | 443259c | 2010-11-09 22:49:53 +0100 | [diff] [blame] | 22 | struct strbuf commit_msg; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 23 | int verbosity; |
Jacob Keller | 4d03dd1 | 2015-08-17 14:33:30 -0700 | [diff] [blame] | 24 | enum notes_merge_strategy strategy; |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 25 | unsigned has_worktree:1; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 26 | }; |
| 27 | |
Nguyễn Thái Ngọc Duy | 5684200 | 2018-11-10 06:48:53 +0100 | [diff] [blame] | 28 | void init_notes_merge_options(struct repository *r, |
| 29 | struct notes_merge_options *o); |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 30 | |
| 31 | /* |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 32 | * Merge notes from o->remote_ref into o->local_ref |
| 33 | * |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 34 | * 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 Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 38 | * 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 Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 42 | * already-up-to-date). 'local_tree' is untouched, the OID of the result |
| 43 | * is written into 'result_oid' and 0 is returned. |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 44 | * 2. The merge successfully completes, producing a merge commit. local_tree |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 45 | * contains the updated notes tree, the OID of the resulting commit is |
| 46 | * written into 'result_oid', and 1 is returned. |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 47 | * 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 Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 49 | * are stored in 'local_tree', and the OID or the resulting commit |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 50 | * (to be amended when the conflicts have been resolved) is written into |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 51 | * 'result_oid'. The unmerged entries are written into the |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 52 | * .git/NOTES_MERGE_WORKTREE directory with conflict markers. |
| 53 | * -1 is returned. |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 54 | * |
| 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 | */ |
| 60 | int notes_merge(struct notes_merge_options *o, |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 61 | struct notes_tree *local_tree, |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 62 | struct object_id *result_oid); |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 63 | |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 64 | /* |
| 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 Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 72 | * to 'partial_tree', and create a final notes merge commit, the OID of which |
| 73 | * will be stored in 'result_oid'. |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 74 | */ |
| 75 | int notes_merge_commit(struct notes_merge_options *o, |
| 76 | struct notes_tree *partial_tree, |
| 77 | struct commit *partial_commit, |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 78 | struct object_id *result_oid); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Abort conflict resolution from an earlier notes_merge() |
| 82 | * |
| 83 | * Removes the notes merge worktree in .git/NOTES_MERGE_WORKTREE. |
| 84 | */ |
| 85 | int notes_merge_abort(struct notes_merge_options *o); |
| 86 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 87 | #endif |