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" |
| 5 | |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 6 | #define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE" |
| 7 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 8 | enum notes_merge_verbosity { |
| 9 | NOTES_MERGE_VERBOSITY_DEFAULT = 2, |
| 10 | NOTES_MERGE_VERBOSITY_MAX = 5 |
| 11 | }; |
| 12 | |
| 13 | struct notes_merge_options { |
| 14 | const char *local_ref; |
| 15 | const char *remote_ref; |
Johan Herland | 443259c | 2010-11-09 22:49:53 +0100 | [diff] [blame] | 16 | struct strbuf commit_msg; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 17 | int verbosity; |
Jacob Keller | 4d03dd1 | 2015-08-17 14:33:30 -0700 | [diff] [blame] | 18 | enum notes_merge_strategy strategy; |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 19 | unsigned has_worktree:1; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | void init_notes_merge_options(struct notes_merge_options *o); |
| 23 | |
| 24 | /* |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 25 | * Merge notes from o->remote_ref into o->local_ref |
| 26 | * |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 27 | * The given notes_tree 'local_tree' must be the notes_tree referenced by the |
| 28 | * o->local_ref. This is the notes_tree in which the object-level merge is |
| 29 | * performed. |
| 30 | * |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 31 | * The commits given by the two refs are merged, producing one of the following |
| 32 | * outcomes: |
| 33 | * |
| 34 | * 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] | 35 | * already-up-to-date). 'local_tree' is untouched, the OID of the result |
| 36 | * is written into 'result_oid' and 0 is returned. |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 37 | * 2. The merge successfully completes, producing a merge commit. local_tree |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 38 | * contains the updated notes tree, the OID of the resulting commit is |
| 39 | * written into 'result_oid', and 1 is returned. |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 40 | * 3. The merge results in conflicts. This is similar to #2 in that the |
| 41 | * partial merge result (i.e. merge result minus the unmerged entries) |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 42 | * are stored in 'local_tree', and the OID or the resulting commit |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 43 | * (to be amended when the conflicts have been resolved) is written into |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 44 | * 'result_oid'. The unmerged entries are written into the |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 45 | * .git/NOTES_MERGE_WORKTREE directory with conflict markers. |
| 46 | * -1 is returned. |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 47 | * |
| 48 | * Both o->local_ref and o->remote_ref must be given (non-NULL), but either ref |
| 49 | * (although not both) may refer to a non-existing notes ref, in which case |
| 50 | * that notes ref is interpreted as an empty notes tree, and the merge |
| 51 | * trivially results in what the other ref points to. |
| 52 | */ |
| 53 | int notes_merge(struct notes_merge_options *o, |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 54 | struct notes_tree *local_tree, |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 55 | struct object_id *result_oid); |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 56 | |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 57 | /* |
| 58 | * Finalize conflict resolution from an earlier notes_merge() |
| 59 | * |
| 60 | * The given notes tree 'partial_tree' must be the notes_tree corresponding to |
| 61 | * the given 'partial_commit', the partial result commit created by a previous |
| 62 | * call to notes_merge(). |
| 63 | * |
| 64 | * 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] | 65 | * to 'partial_tree', and create a final notes merge commit, the OID of which |
| 66 | * will be stored in 'result_oid'. |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 67 | */ |
| 68 | int notes_merge_commit(struct notes_merge_options *o, |
| 69 | struct notes_tree *partial_tree, |
| 70 | struct commit *partial_commit, |
Brandon Williams | 5237e0e | 2017-05-30 10:30:58 -0700 | [diff] [blame] | 71 | struct object_id *result_oid); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * Abort conflict resolution from an earlier notes_merge() |
| 75 | * |
| 76 | * Removes the notes merge worktree in .git/NOTES_MERGE_WORKTREE. |
| 77 | */ |
| 78 | int notes_merge_abort(struct notes_merge_options *o); |
| 79 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 80 | #endif |