From 894a9d333e9e2015cad00d95250b7c5d3acea8b6 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Fri, 12 Mar 2010 18:04:26 +0100 Subject: Support showing notes from more than one notes tree With this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g., [notes] displayRef = refs/notes/* Then git-log and friends will show notes from all trees. Thanks to Junio C Hamano for lots of feedback, which greatly influenced the design of the entire series and this commit in particular. Signed-off-by: Thomas Rast Acked-by: Johan Herland Signed-off-by: Junio C Hamano --- notes.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'notes.h') diff --git a/notes.h b/notes.h index bad03ccab..2cc07409d 100644 --- a/notes.h +++ b/notes.h @@ -198,4 +198,59 @@ void free_notes(struct notes_tree *t); void format_note(struct notes_tree *t, const unsigned char *object_sha1, struct strbuf *sb, const char *output_encoding, int flags); + +struct string_list; + +struct display_notes_opt { + int suppress_default_notes:1; + struct string_list *extra_notes_refs; +}; + +/* + * Load the notes machinery for displaying several notes trees. + * + * If 'opt' is not NULL, then it specifies additional settings for the + * displaying: + * + * - suppress_default_notes indicates that the notes from + * core.notesRef and notes.displayRef should not be loaded. + * + * - extra_notes_refs may contain a list of globs (in the same style + * as notes.displayRef) where notes should be loaded from. + */ +void init_display_notes(struct display_notes_opt *opt); + +/* + * Append notes for the given 'object_sha1' from all trees set up by + * init_display_notes() to 'sb'. The 'flags' are a bitwise + * combination of + * + * - NOTES_SHOW_HEADER: add a 'Notes (refname):' header + * + * - NOTES_INDENT: indent the notes by 4 places + * + * You *must* call init_display_notes() before using this function. + */ +void format_display_notes(const unsigned char *object_sha1, + struct strbuf *sb, const char *output_encoding, int flags); + +/* + * Load the notes tree from each ref listed in 'refs'. The output is + * an array of notes_tree*, terminated by a NULL. + */ +struct notes_tree **load_notes_trees(struct string_list *refs); + +/* + * Add all refs that match 'glob' to the 'list'. + */ +void string_list_add_refs_by_glob(struct string_list *list, const char *glob); + +/* + * Add all refs from a colon-separated glob list 'globs' to the end of + * 'list'. Empty components are ignored. This helper is used to + * parse GIT_NOTES_DISPLAY_REF style environment variables. + */ +void string_list_add_refs_from_colon_sep(struct string_list *list, + const char *globs); + #endif -- cgit v1.2.1 From 160baa0d9cbdfcdb6251aa5ede77c59c0d53edfd Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Fri, 12 Mar 2010 18:04:31 +0100 Subject: notes: implement 'git notes copy --stdin' This implements a mass-copy command that takes a sequence of lines in the format SP [ SP ] LF on stdin, and copies each 's notes to the . The is ignored. The intent, of course, is that this can read the same input that the 'post-rewrite' hook gets. The copy_note() function is exposed for everyone's and in particular the next commit's use. Signed-off-by: Thomas Rast Acked-by: Johan Herland Signed-off-by: Junio C Hamano --- notes.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'notes.h') diff --git a/notes.h b/notes.h index 2cc07409d..b7fafb448 100644 --- a/notes.h +++ b/notes.h @@ -99,6 +99,15 @@ void remove_note(struct notes_tree *t, const unsigned char *object_sha1); const unsigned char *get_note(struct notes_tree *t, const unsigned char *object_sha1); +/* + * 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. + */ +int copy_note(struct notes_tree *t, + const unsigned char *from_obj, const unsigned char *to_obj, + int force, combine_notes_fn combine_fn); + /* * Flags controlling behaviour of for_each_note() * -- cgit v1.2.1 From 7f710ea98262c7d81006c16c727796d9e6aeaa81 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Fri, 12 Mar 2010 18:04:36 +0100 Subject: notes: track whether notes_trees were changed at all Currently, the notes copying is a bit wasteful since it always creates new trees, even if no notes were copied at all. Teach add_note() and remove_note() to flag the affected notes tree as changed ('dirty'). Then teach builtin/notes.c to use this knowledge and avoid committing trees that weren't changed. Signed-off-by: Thomas Rast Acked-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 b7fafb448..ee65bd1a2 100644 --- a/notes.h +++ b/notes.h @@ -40,6 +40,7 @@ extern struct notes_tree { char *ref; combine_notes_fn *combine_notes; int initialized; + int dirty; } default_notes_tree; /* -- cgit v1.2.1