summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0ab1faa)
raw | patch | inline | side by side (parent: 0ab1faa)
author | Johan Herland <johan@herland.net> | |
Sat, 13 Feb 2010 21:28:10 +0000 (22:28 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 14 Feb 2010 03:36:11 +0000 (19:36 -0800) |
There is really no reason why only commit objects can be annotated. By
changing the struct commit parameter to get_commit_notes() into a sha1 we
gain the ability to annotate any object type. To reflect this in the function
naming as well, we rename get_commit_notes() to format_note().
This patch also fixes comments and variable names throughout notes.c as a
consequence of the removal of the unnecessary 'commit' restriction.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
changing the struct commit parameter to get_commit_notes() into a sha1 we
gain the ability to annotate any object type. To reflect this in the function
naming as well, we rename get_commit_notes() to format_note().
This patch also fixes comments and variable names throughout notes.c as a
consequence of the removal of the unnecessary 'commit' restriction.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
notes.c | patch | blob | history | |
notes.h | patch | blob | history | |
pretty.c | patch | blob | history |
index 47e38a10a88aba6821255153b5d3a1cad2a86d01..4ee4fec2331b651d66e04eeeca1b626d98d8f93e 100644 (file)
--- a/notes.c
+++ b/notes.c
#include "cache.h"
-#include "commit.h"
#include "notes.h"
#include "utf8.h"
#include "strbuf.h"
/*
* Leaf nodes come in two variants, note entries and subtree entries,
* distinguished by the LSb of the leaf node pointer (see above).
- * As a note entry, the key is the SHA1 of the referenced commit, and the
+ * As a note entry, the key is the SHA1 of the referenced object, and the
* value is the SHA1 of the note object.
* As a subtree entry, the key is the prefix SHA1 (w/trailing NULs) of the
- * referenced commit, using the last byte of the key to store the length of
+ * referenced object, using the last byte of the key to store the length of
* the prefix. The value is the SHA1 of the tree object containing the notes
* subtree.
*/
if (concatenate_notes(l->val_sha1,
entry->val_sha1))
die("failed to concatenate note %s "
- "into note %s for commit %s",
+ "into note %s for object %s",
sha1_to_hex(entry->val_sha1),
sha1_to_hex(l->val_sha1),
sha1_to_hex(l->key_sha1));
static void load_subtree(struct leaf_node *subtree, struct int_node *node,
unsigned int n)
{
- unsigned char commit_sha1[20];
+ unsigned char object_sha1[20];
unsigned int prefix_len;
void *buf;
struct tree_desc desc;
prefix_len = subtree->key_sha1[19];
assert(prefix_len * 2 >= n);
- memcpy(commit_sha1, subtree->key_sha1, prefix_len);
+ memcpy(object_sha1, subtree->key_sha1, prefix_len);
while (tree_entry(&desc, &entry)) {
int len = get_sha1_hex_segment(entry.path, strlen(entry.path),
- commit_sha1 + prefix_len, 20 - prefix_len);
+ object_sha1 + prefix_len, 20 - prefix_len);
if (len < 0)
continue; /* entry.path is not a SHA1 sum. Skip */
len += prefix_len;
/*
- * If commit SHA1 is complete (len == 20), assume note object
- * If commit SHA1 is incomplete (len < 20), assume note subtree
+ * If object SHA1 is complete (len == 20), assume note object
+ * If object SHA1 is incomplete (len < 20), assume note subtree
*/
if (len <= 20) {
unsigned char type = PTR_TYPE_NOTE;
struct leaf_node *l = (struct leaf_node *)
xcalloc(sizeof(struct leaf_node), 1);
- hashcpy(l->key_sha1, commit_sha1);
+ hashcpy(l->key_sha1, object_sha1);
hashcpy(l->val_sha1, entry.sha1);
if (len < 20) {
if (!S_ISDIR(entry.mode))
static void initialize_notes(const char *notes_ref_name)
{
- unsigned char sha1[20], commit_sha1[20];
+ unsigned char sha1[20], object_sha1[20];
unsigned mode;
struct leaf_node root_tree;
- if (!notes_ref_name || read_ref(notes_ref_name, commit_sha1) ||
- get_tree_entry(commit_sha1, "", sha1, &mode))
+ if (!notes_ref_name || read_ref(notes_ref_name, object_sha1) ||
+ get_tree_entry(object_sha1, "", sha1, &mode))
return;
hashclr(root_tree.key_sha1);
load_subtree(&root_tree, &root_node, 0);
}
-static unsigned char *lookup_notes(const unsigned char *commit_sha1)
+static unsigned char *lookup_notes(const unsigned char *object_sha1)
{
- struct leaf_node *found = note_tree_find(&root_node, 0, commit_sha1);
+ struct leaf_node *found = note_tree_find(&root_node, 0, object_sha1);
if (found)
return found->val_sha1;
return NULL;
initialized = 0;
}
-void get_commit_notes(const struct commit *commit, struct strbuf *sb,
+void format_note(const unsigned char *object_sha1, struct strbuf *sb,
const char *output_encoding, int flags)
{
static const char utf8[] = "utf-8";
initialized = 1;
}
- sha1 = lookup_notes(commit->object.sha1);
+ sha1 = lookup_notes(object_sha1);
if (!sha1)
return;
index a1421e351ae0a6f97824b150140e49ddd5d3414d..d745ed12da5a412c78d7e97a65b66210930ae976 100644 (file)
--- a/notes.h
+++ b/notes.h
/* Free (and de-initialize) the internal notes tree structure */
void free_notes(void);
+/* Flags controlling how notes are formatted */
#define NOTES_SHOW_HEADER 1
#define NOTES_INDENT 2
-void get_commit_notes(const struct commit *commit, struct strbuf *sb,
+/*
+ * Fill the given strbuf with the notes associated with the given object.
+ *
+ * If the internal notes structure is not initialized, it will be auto-
+ * initialized to the default value (see documentation for init_notes() above).
+ *
+ * 'flags' is a bitwise combination of the above formatting flags.
+ */
+void format_note(const unsigned char *object_sha1, struct strbuf *sb,
const char *output_encoding, int flags);
#endif
diff --git a/pretty.c b/pretty.c
index d493cade26890d3e16ea072ced8e0f95679f5670..076b918b5234c14f3b6c5ee737a52ba678e714b5 100644 (file)
--- a/pretty.c
+++ b/pretty.c
}
return 0; /* unknown %g placeholder */
case 'N':
- get_commit_notes(commit, sb, git_log_output_encoding ?
- git_log_output_encoding : git_commit_encoding, 0);
+ format_note(commit->object.sha1, sb, git_log_output_encoding ?
+ git_log_output_encoding : git_commit_encoding, 0);
return 1;
}
strbuf_addch(sb, '\n');
if (context->show_notes)
- get_commit_notes(commit, sb, encoding,
- NOTES_SHOW_HEADER | NOTES_INDENT);
+ format_note(commit->object.sha1, sb, encoding,
+ NOTES_SHOW_HEADER | NOTES_INDENT);
free(reencoded);
}