git/notes-merge.h

88 lines
2.9 KiB
C
Raw Normal View History

#ifndef NOTES_MERGE_H
#define NOTES_MERGE_H
#include "notes-utils.h"
#include "strbuf.h"
struct commit;
struct object_id;
struct repository;
#define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE"
enum notes_merge_verbosity {
NOTES_MERGE_VERBOSITY_DEFAULT = 2,
NOTES_MERGE_VERBOSITY_MAX = 5
};
struct notes_merge_options {
struct repository *repo;
const char *local_ref;
const char *remote_ref;
struct strbuf commit_msg;
int verbosity;
enum notes_merge_strategy strategy;
unsigned has_worktree:1;
};
void init_notes_merge_options(struct repository *r,
struct notes_merge_options *o);
/*
* Merge notes from o->remote_ref into o->local_ref
*
git notes merge: Handle real, non-conflicting notes merges This continuation of the 'git notes merge' implementation teaches notes-merge to properly do real merges between notes trees: Two diffs are performed, one from $base to $remote, and another from $base to $local. The paths in each diff are normalized to SHA1 object names. The two diffs are then consolidated into a single list of change pairs to be evaluated. Each change pair consist of: - The annotated object's SHA1 - The $base SHA1 (i.e. the common ancestor notes for this object) - The $local SHA1 (i.e. the current notes for this object) - The $remote SHA1 (i.e. the to-be-merged notes for this object) From the pair ($base -> $local, $base -> $remote), we can determine the merge result using regular 3-way rules. If conflicts are encountered in this process, we fail loudly and exit (conflict handling to be added in a future patch), If we can complete the merge without conflicts, the resulting notes tree is committed, and the current notes ref updated. The patch includes added testcases verifying that we can successfully do real conflict-less merges. This patch has been improved by the following contributions: - Jonathan Nieder: Future-proof by always checking add_note() return value - Stephen Boyd: Use test_commit - Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...) - Junio C Hamano: fixup minor style issues Thanks-to: Jonathan Nieder <jrnieder@gmail.com> Thanks-to: Stephen Boyd <bebarino@gmail.com> Thanks-to: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15 00:54:11 +01:00
* The given notes_tree 'local_tree' must be the notes_tree referenced by the
* o->local_ref. This is the notes_tree in which the object-level merge is
* performed.
*
* The commits given by the two refs are merged, producing one of the following
* outcomes:
*
* 1. The merge trivially results in an existing commit (e.g. fast-forward or
* already-up-to-date). 'local_tree' is untouched, the OID of the result
* is written into 'result_oid' and 0 is returned.
git notes merge: Handle real, non-conflicting notes merges This continuation of the 'git notes merge' implementation teaches notes-merge to properly do real merges between notes trees: Two diffs are performed, one from $base to $remote, and another from $base to $local. The paths in each diff are normalized to SHA1 object names. The two diffs are then consolidated into a single list of change pairs to be evaluated. Each change pair consist of: - The annotated object's SHA1 - The $base SHA1 (i.e. the common ancestor notes for this object) - The $local SHA1 (i.e. the current notes for this object) - The $remote SHA1 (i.e. the to-be-merged notes for this object) From the pair ($base -> $local, $base -> $remote), we can determine the merge result using regular 3-way rules. If conflicts are encountered in this process, we fail loudly and exit (conflict handling to be added in a future patch), If we can complete the merge without conflicts, the resulting notes tree is committed, and the current notes ref updated. The patch includes added testcases verifying that we can successfully do real conflict-less merges. This patch has been improved by the following contributions: - Jonathan Nieder: Future-proof by always checking add_note() return value - Stephen Boyd: Use test_commit - Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...) - Junio C Hamano: fixup minor style issues Thanks-to: Jonathan Nieder <jrnieder@gmail.com> Thanks-to: Stephen Boyd <bebarino@gmail.com> Thanks-to: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15 00:54:11 +01:00
* 2. The merge successfully completes, producing a merge commit. local_tree
* contains the updated notes tree, the OID of the resulting commit is
* written into 'result_oid', and 1 is returned.
* 3. The merge results in conflicts. This is similar to #2 in that the
* partial merge result (i.e. merge result minus the unmerged entries)
* are stored in 'local_tree', and the OID or the resulting commit
* (to be amended when the conflicts have been resolved) is written into
* 'result_oid'. The unmerged entries are written into the
* .git/NOTES_MERGE_WORKTREE directory with conflict markers.
* -1 is returned.
*
* Both o->local_ref and o->remote_ref must be given (non-NULL), but either ref
* (although not both) may refer to a non-existing notes ref, in which case
* that notes ref is interpreted as an empty notes tree, and the merge
* trivially results in what the other ref points to.
*/
int notes_merge(struct notes_merge_options *o,
git notes merge: Handle real, non-conflicting notes merges This continuation of the 'git notes merge' implementation teaches notes-merge to properly do real merges between notes trees: Two diffs are performed, one from $base to $remote, and another from $base to $local. The paths in each diff are normalized to SHA1 object names. The two diffs are then consolidated into a single list of change pairs to be evaluated. Each change pair consist of: - The annotated object's SHA1 - The $base SHA1 (i.e. the common ancestor notes for this object) - The $local SHA1 (i.e. the current notes for this object) - The $remote SHA1 (i.e. the to-be-merged notes for this object) From the pair ($base -> $local, $base -> $remote), we can determine the merge result using regular 3-way rules. If conflicts are encountered in this process, we fail loudly and exit (conflict handling to be added in a future patch), If we can complete the merge without conflicts, the resulting notes tree is committed, and the current notes ref updated. The patch includes added testcases verifying that we can successfully do real conflict-less merges. This patch has been improved by the following contributions: - Jonathan Nieder: Future-proof by always checking add_note() return value - Stephen Boyd: Use test_commit - Jonathan Nieder: Use trace_printf(...) instead of OUTPUT(o, 5, ...) - Junio C Hamano: fixup minor style issues Thanks-to: Jonathan Nieder <jrnieder@gmail.com> Thanks-to: Stephen Boyd <bebarino@gmail.com> Thanks-to: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15 00:54:11 +01:00
struct notes_tree *local_tree,
struct object_id *result_oid);
git notes merge: Manual conflict resolution, part 2/2 When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been resolved, we need to record a new notes commit on the appropriate notes ref with the resolved notes. This patch implements 'git notes merge --commit' which the user should run after resolving conflicts in the notes merge worktree. This command finalizes the notes merge by recombining the partial notes tree from part 1 with the now-resolved conflicts in the notes merge worktree in a merge commit, and updating the appropriate ref to this merge commit. In order to correctly finalize the merge, we need to keep track of three things: - The partial merge result from part 1, containing the auto-merged notes. This is now stored into a ref called .git/NOTES_MERGE_PARTIAL. - The unmerged notes. These are already stored in .git/NOTES_MERGE_WORKTREE, thanks to part 1. - The notes ref to be updated by the finalized merge result. This is now stored in a symref called .git/NOTES_MERGE_REF. In addition to "git notes merge --commit", which uses the above details to create the finalized notes merge commit, this patch also implements "git notes merge --reset", which aborts the ongoing notes merge by simply removing the files/directory described above. FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove the information described above (.git/NOTES_MERGE_*) after the notes merge have been successfully finalized. The patch also contains documentation and testcases for the two new options. This patch has been improved by the following contributions: - Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description - Sverre Rabbelier: Rename --reset to --abort Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Thanks-to: Sverre Rabbelier <srabbelier@gmail.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-09 22:49:52 +01:00
/*
* Finalize conflict resolution from an earlier notes_merge()
*
* The given notes tree 'partial_tree' must be the notes_tree corresponding to
* the given 'partial_commit', the partial result commit created by a previous
* call to notes_merge().
*
* This function will add the (now resolved) notes in .git/NOTES_MERGE_WORKTREE
* to 'partial_tree', and create a final notes merge commit, the OID of which
* will be stored in 'result_oid'.
git notes merge: Manual conflict resolution, part 2/2 When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been resolved, we need to record a new notes commit on the appropriate notes ref with the resolved notes. This patch implements 'git notes merge --commit' which the user should run after resolving conflicts in the notes merge worktree. This command finalizes the notes merge by recombining the partial notes tree from part 1 with the now-resolved conflicts in the notes merge worktree in a merge commit, and updating the appropriate ref to this merge commit. In order to correctly finalize the merge, we need to keep track of three things: - The partial merge result from part 1, containing the auto-merged notes. This is now stored into a ref called .git/NOTES_MERGE_PARTIAL. - The unmerged notes. These are already stored in .git/NOTES_MERGE_WORKTREE, thanks to part 1. - The notes ref to be updated by the finalized merge result. This is now stored in a symref called .git/NOTES_MERGE_REF. In addition to "git notes merge --commit", which uses the above details to create the finalized notes merge commit, this patch also implements "git notes merge --reset", which aborts the ongoing notes merge by simply removing the files/directory described above. FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove the information described above (.git/NOTES_MERGE_*) after the notes merge have been successfully finalized. The patch also contains documentation and testcases for the two new options. This patch has been improved by the following contributions: - Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description - Sverre Rabbelier: Rename --reset to --abort Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Thanks-to: Sverre Rabbelier <srabbelier@gmail.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-09 22:49:52 +01:00
*/
int notes_merge_commit(struct notes_merge_options *o,
struct notes_tree *partial_tree,
struct commit *partial_commit,
struct object_id *result_oid);
git notes merge: Manual conflict resolution, part 2/2 When the notes merge conflicts in .git/NOTES_MERGE_WORKTREE have been resolved, we need to record a new notes commit on the appropriate notes ref with the resolved notes. This patch implements 'git notes merge --commit' which the user should run after resolving conflicts in the notes merge worktree. This command finalizes the notes merge by recombining the partial notes tree from part 1 with the now-resolved conflicts in the notes merge worktree in a merge commit, and updating the appropriate ref to this merge commit. In order to correctly finalize the merge, we need to keep track of three things: - The partial merge result from part 1, containing the auto-merged notes. This is now stored into a ref called .git/NOTES_MERGE_PARTIAL. - The unmerged notes. These are already stored in .git/NOTES_MERGE_WORKTREE, thanks to part 1. - The notes ref to be updated by the finalized merge result. This is now stored in a symref called .git/NOTES_MERGE_REF. In addition to "git notes merge --commit", which uses the above details to create the finalized notes merge commit, this patch also implements "git notes merge --reset", which aborts the ongoing notes merge by simply removing the files/directory described above. FTR, "git notes merge --commit" reuses "git notes merge --reset" to remove the information described above (.git/NOTES_MERGE_*) after the notes merge have been successfully finalized. The patch also contains documentation and testcases for the two new options. This patch has been improved by the following contributions: - Ævar Arnfjörð Bjarmason: Fix nonsense sentence in --commit description - Sverre Rabbelier: Rename --reset to --abort Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Thanks-to: Sverre Rabbelier <srabbelier@gmail.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-09 22:49:52 +01:00
/*
* Abort conflict resolution from an earlier notes_merge()
*
* Removes the notes merge worktree in .git/NOTES_MERGE_WORKTREE.
*/
int notes_merge_abort(struct notes_merge_options *o);
#endif