From 55d060771a15f4ce75e71b966d8117d8a32cc47b Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Tue, 9 Nov 2010 22:49:38 +0100 Subject: (trivial) notes.h: Minor documentation fixes to copy_notes() Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- notes.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'notes.h') diff --git a/notes.h b/notes.h index 65fc3a66b2..c0288b0d32 100644 --- a/notes.h +++ b/notes.h @@ -104,6 +104,10 @@ const unsigned char *get_note(struct notes_tree *t, * Copy a note from one object to another in the given notes_tree. * * Fails if the to_obj already has a note unless 'force' is true. + * + * IMPORTANT: The changes made by copy_note() to the given notes_tree structure + * are not persistent until a subsequent call to write_notes_tree() returns + * zero. */ int copy_note(struct notes_tree *t, const unsigned char *from_obj, const unsigned char *to_obj, @@ -149,6 +153,7 @@ int copy_note(struct notes_tree *t, * notes tree) from within the callback: * - add_note() * - remove_note() + * - copy_note() * - free_notes() */ typedef int each_note_fn(const unsigned char *object_sha1, -- cgit v1.2.1 From 4a9cf1cefc0fd05e0eb46f862e398f1e4ac1c9a7 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Tue, 9 Nov 2010 22:49:39 +0100 Subject: notes.h: Make default_notes_ref() available in notes API Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- notes.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'notes.h') diff --git a/notes.h b/notes.h index c0288b0d32..20db42fe95 100644 --- a/notes.h +++ b/notes.h @@ -43,6 +43,20 @@ extern struct notes_tree { int dirty; } default_notes_tree; +/* + * Return the default notes ref. + * + * The default notes ref is the notes ref that is used when notes_ref == NULL + * is passed to init_notes(). + * + * This the first of the following to be defined: + * 1. The '--ref' option to 'git notes', if given + * 2. The $GIT_NOTES_REF environment variable, if set + * 3. The value of the core.notesRef config variable, if set + * 4. GIT_NOTES_DEFAULT_REF (i.e. "refs/notes/commits") + */ +const char *default_notes_ref(void); + /* * Flags controlling behaviour of notes tree initialization * -- cgit v1.2.1 From e2656c82fd836a3d410230c98f6a725368f15642 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Tue, 9 Nov 2010 22:49:41 +0100 Subject: notes.h/c: Allow combine_notes functions to remove notes Allow combine_notes functions to request that a note be removed, by setting the resulting note SHA1 to null_sha1 (0000000...). For consistency, also teach note_tree_insert() to skip insertion of an empty note (a note with entry->val_sha1 equal to null_sha1) when there is no note to combine it with. In general, an empty note (null_sha1) is treated identically to no note at all, but when adding an empty note where there already exists a non-empty note, we allow the combine_notes function to potentially record a new/changed note. Document this behaviour, and clearly specify how combine_notes functions are expected to handle null_sha1 in input. Before this patch, storing null_sha1s in the notes tree were silently allowed, causing an invalid notes tree (referring to blobs with null_sha1) to be produced by write_notes_tree(). Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- notes.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'notes.h') diff --git a/notes.h b/notes.h index 20db42fe95..79ea7976ab 100644 --- a/notes.h +++ b/notes.h @@ -12,7 +12,10 @@ * resulting SHA1 into the first SHA1 argument (cur_sha1). A non-zero return * value indicates failure. * - * The two given SHA1s must both be non-NULL and different from each other. + * The two given SHA1s shall both be non-NULL and different from each other. + * Either of them (but not both) may be == null_sha1, which indicates an + * empty/non-existent note. If the resulting SHA1 (cur_sha1) is == null_sha1, + * the note will be removed from the notes tree. * * The default combine_notes function (you get this when passing NULL) is * combine_notes_concatenate(), which appends the contents of the new note to @@ -90,6 +93,17 @@ void init_notes(struct notes_tree *t, const char *notes_ref, /* * Add the given note object to the given notes_tree structure * + * If there already exists a note for the given object_sha1, the given + * combine_notes function is invoked to break the tie. If not given (i.e. + * combine_notes == NULL), the default combine_notes function for the given + * notes_tree is used. + * + * Passing note_sha1 == null_sha1 indicates the addition of an + * empty/non-existent note. This is a (potentially expensive) no-op unless + * there already exists a note for the given object_sha1, AND combining that + * note with the empty note (using the given combine_notes function) results + * in a new/changed note. + * * IMPORTANT: The changes made by add_note() to the given notes_tree structure * are not persistent until a subsequent call to write_notes_tree() returns * zero. -- cgit v1.2.1 From 180619a58572b17de0ebeb96989e0aa832765186 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Mon, 15 Nov 2010 00:52:26 +0100 Subject: notes.h/c: Propagate combine_notes_fn return value to add_note() and beyond The combine_notes_fn functions uses a non-zero return value to indicate failure. However, this return value was converted to a call to die() in note_tree_insert(). Instead, propagate this return value out to add_note(), and return it from there to enable the caller to handle errors appropriately. Existing add_note() callers are updated to die() upon failure, thus preserving the current behaviour. The only exceptions are copy_note() and notes_cache_put() where we are able to propagate the add_note() return value instead. This patch has been improved by the following contributions: - Jonathan Nieder: Future-proof by always checking add_note() return value - Jonathan Nieder: Improve clarity of final if-condition in note_tree_insert() Thanks-to: Jonathan Nieder Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- notes.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'notes.h') diff --git a/notes.h b/notes.h index 79ea7976ab..b3725750bb 100644 --- a/notes.h +++ b/notes.h @@ -104,11 +104,13 @@ void init_notes(struct notes_tree *t, const char *notes_ref, * note with the empty note (using the given combine_notes function) results * in a new/changed note. * + * Returns zero on success; non-zero means combine_notes failed. + * * IMPORTANT: The changes made by add_note() to the given notes_tree structure * are not persistent until a subsequent call to write_notes_tree() returns * zero. */ -void add_note(struct notes_tree *t, const unsigned char *object_sha1, +int add_note(struct notes_tree *t, const unsigned char *object_sha1, const unsigned char *note_sha1, combine_notes_fn combine_notes); /* @@ -131,7 +133,10 @@ const unsigned char *get_note(struct notes_tree *t, /* * Copy a note from one object to another in the given notes_tree. * - * Fails if the to_obj already has a note unless 'force' is true. + * Returns 1 if the to_obj already has a note and 'force' is false. Otherwise, + * returns non-zero if 'force' is true, but the given combine_notes function + * failed to combine from_obj's note with to_obj's existing note. + * Returns zero on success. * * IMPORTANT: The changes made by copy_note() to the given notes_tree structure * are not persistent until a subsequent call to write_notes_tree() returns @@ -139,7 +144,7 @@ const unsigned char *get_note(struct notes_tree *t, */ int copy_note(struct notes_tree *t, const unsigned char *from_obj, const unsigned char *to_obj, - int force, combine_notes_fn combine_fn); + int force, combine_notes_fn combine_notes); /* * Flags controlling behaviour of for_each_note() -- cgit v1.2.1 From a6a09095a08339afc8468d053ff978ed4662a1d5 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Mon, 15 Nov 2010 00:57:17 +0100 Subject: git notes merge: Add another auto-resolving strategy: "cat_sort_uniq" This new strategy is similar to "concatenate", but in addition to concatenating the two note candidates, this strategy sorts the resulting lines, and removes duplicate lines from the result. This is equivalent to applying the "cat | sort | uniq" shell pipeline to the two note candidates. This strategy is useful if the notes follow a line-based format where one wants to avoid duplicate lines in the merge result. Note that if either of the note candidates contain duplicate lines _prior_ to the merge, these will also be removed by this merge strategy. The patch also contains tests and documentation for the new strategy. Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- notes.h | 1 + 1 file changed, 1 insertion(+) (limited to 'notes.h') diff --git a/notes.h b/notes.h index b3725750bb..93a73657e2 100644 --- a/notes.h +++ b/notes.h @@ -27,6 +27,7 @@ typedef int (*combine_notes_fn)(unsigned char *cur_sha1, const unsigned char *ne int combine_notes_concatenate(unsigned char *cur_sha1, const unsigned char *new_sha1); int combine_notes_overwrite(unsigned char *cur_sha1, const unsigned char *new_sha1); int combine_notes_ignore(unsigned char *cur_sha1, const unsigned char *new_sha1); +int combine_notes_cat_sort_uniq(unsigned char *cur_sha1, const unsigned char *new_sha1); /* * Notes tree object -- cgit v1.2.1