Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 1 | #ifndef NOTES_MERGE_H |
| 2 | #define NOTES_MERGE_H |
| 3 | |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 4 | #define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE" |
| 5 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 6 | enum notes_merge_verbosity { |
| 7 | NOTES_MERGE_VERBOSITY_DEFAULT = 2, |
| 8 | NOTES_MERGE_VERBOSITY_MAX = 5 |
| 9 | }; |
| 10 | |
| 11 | struct notes_merge_options { |
| 12 | const char *local_ref; |
| 13 | const char *remote_ref; |
Johan Herland | 443259c | 2010-11-09 22:49:53 +0100 | [diff] [blame] | 14 | struct strbuf commit_msg; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 15 | int verbosity; |
Johan Herland | 3228e67 | 2010-11-15 00:55:12 +0100 | [diff] [blame] | 16 | enum { |
| 17 | NOTES_MERGE_RESOLVE_MANUAL = 0, |
| 18 | NOTES_MERGE_RESOLVE_OURS, |
| 19 | NOTES_MERGE_RESOLVE_THEIRS, |
Johan Herland | a6a0909 | 2010-11-15 00:57:17 +0100 | [diff] [blame] | 20 | NOTES_MERGE_RESOLVE_UNION, |
| 21 | NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ |
Johan Herland | 3228e67 | 2010-11-15 00:55:12 +0100 | [diff] [blame] | 22 | } strategy; |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 23 | unsigned has_worktree:1; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | void init_notes_merge_options(struct notes_merge_options *o); |
| 27 | |
| 28 | /* |
Johan Herland | 5688184 | 2010-11-09 22:49:47 +0100 | [diff] [blame] | 29 | * Create new notes commit from the given notes tree |
| 30 | * |
| 31 | * Properties of the created commit: |
| 32 | * - tree: the result of converting t to a tree object with write_notes_tree(). |
| 33 | * - parents: the given parents OR (if NULL) the commit referenced by t->ref. |
| 34 | * - author/committer: the default determined by commmit_tree(). |
| 35 | * - commit message: msg |
| 36 | * |
| 37 | * The resulting commit SHA1 is stored in result_sha1. |
| 38 | */ |
| 39 | void create_notes_commit(struct notes_tree *t, struct commit_list *parents, |
Nguyễn Thái Ngọc Duy | 13f8b72 | 2011-12-15 20:47:22 +0700 | [diff] [blame] | 40 | const struct strbuf *msg, unsigned char *result_sha1); |
Johan Herland | 5688184 | 2010-11-09 22:49:47 +0100 | [diff] [blame] | 41 | |
| 42 | /* |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 43 | * Merge notes from o->remote_ref into o->local_ref |
| 44 | * |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 45 | * The given notes_tree 'local_tree' must be the notes_tree referenced by the |
| 46 | * o->local_ref. This is the notes_tree in which the object-level merge is |
| 47 | * performed. |
| 48 | * |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 49 | * The commits given by the two refs are merged, producing one of the following |
| 50 | * outcomes: |
| 51 | * |
| 52 | * 1. The merge trivially results in an existing commit (e.g. fast-forward or |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 53 | * already-up-to-date). 'local_tree' is untouched, the SHA1 of the result |
| 54 | * is written into 'result_sha1' and 0 is returned. |
| 55 | * 2. The merge successfully completes, producing a merge commit. local_tree |
| 56 | * contains the updated notes tree, the SHA1 of the resulting commit is |
| 57 | * written into 'result_sha1', and 1 is returned. |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 58 | * 3. The merge results in conflicts. This is similar to #2 in that the |
| 59 | * partial merge result (i.e. merge result minus the unmerged entries) |
| 60 | * are stored in 'local_tree', and the SHA1 or the resulting commit |
| 61 | * (to be amended when the conflicts have been resolved) is written into |
| 62 | * 'result_sha1'. The unmerged entries are written into the |
| 63 | * .git/NOTES_MERGE_WORKTREE directory with conflict markers. |
| 64 | * -1 is returned. |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 65 | * |
| 66 | * Both o->local_ref and o->remote_ref must be given (non-NULL), but either ref |
| 67 | * (although not both) may refer to a non-existing notes ref, in which case |
| 68 | * that notes ref is interpreted as an empty notes tree, and the merge |
| 69 | * trivially results in what the other ref points to. |
| 70 | */ |
| 71 | int notes_merge(struct notes_merge_options *o, |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 72 | struct notes_tree *local_tree, |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 73 | unsigned char *result_sha1); |
| 74 | |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 75 | /* |
| 76 | * Finalize conflict resolution from an earlier notes_merge() |
| 77 | * |
| 78 | * The given notes tree 'partial_tree' must be the notes_tree corresponding to |
| 79 | * the given 'partial_commit', the partial result commit created by a previous |
| 80 | * call to notes_merge(). |
| 81 | * |
| 82 | * This function will add the (now resolved) notes in .git/NOTES_MERGE_WORKTREE |
| 83 | * to 'partial_tree', and create a final notes merge commit, the SHA1 of which |
| 84 | * will be stored in 'result_sha1'. |
| 85 | */ |
| 86 | int notes_merge_commit(struct notes_merge_options *o, |
| 87 | struct notes_tree *partial_tree, |
| 88 | struct commit *partial_commit, |
| 89 | unsigned char *result_sha1); |
| 90 | |
| 91 | /* |
| 92 | * Abort conflict resolution from an earlier notes_merge() |
| 93 | * |
| 94 | * Removes the notes merge worktree in .git/NOTES_MERGE_WORKTREE. |
| 95 | */ |
| 96 | int notes_merge_abort(struct notes_merge_options *o); |
| 97 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 98 | #endif |