-
Notifications
You must be signed in to change notification settings - Fork 4
Add support for reading additional optional headers #1
Copy link
Copy link
Open
Milestone
Description
Git commit objects (and possibly objects of other types) can have additional headers. Here is an answer by andrewdotn on stackoverflow:
Yes, you can totally put more fields called “git commit extra headers” in there. They’ll show up with git cat-file -p, but the only way I see to get them in there in the first place with the standard git client is by editing the git source and recompiling.
In commit.h, there is a struct for extra headers, along with functions to add them when committing, and to read them out later.
struct commit_extra_header {
struct commit_extra_header *next;
char *key;
char *value;
size_t len;
};
int commit_tree_extended(const char *msg, size_t msg_len,
const struct object_id *tree,
struct commit_list *parents,
struct object_id *ret, const char *author,
const char *sign_commit,
struct commit_extra_header *);
struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);
commit.c contains a list of ‘standard’ header fields:
static inline int standard_header_field(const char *field, size_t len)
{
return ((len == 4 && !memcmp(field, "tree", 4)) ||
(len == 6 && !memcmp(field, "parent", 6)) ||
(len == 6 && !memcmp(field, "author", 6)) ||
(len == 9 && !memcmp(field, "committer", 9)) ||
(len == 8 && !memcmp(field, "encoding", 8)));
}
with everything else showing up as an ‘extra’ header.
Doing a quick grep of the source code, the only current use I found of this is the gpgsig header used to include GPG signatures on commits.
Kiln Harmony, now discontinued, used fields such as kilnhgusername and kilnhgrawdescription here.
We need to properly handle them and possibly wrap to some kind of structure. Such headers in fact can be multiline: see https://github.com/git/git/blob/cd3e606211bb1cf8bc57f7d76bab98cc17a150bc/Documentation/technical/signature-format.txt#L22-L24
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels