diff options
author | Vincent Ambo <mail@tazj.in> | 2020-11-21T18·20+0100 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2020-11-21T18·45+0100 |
commit | f4609b896fac842433bd495c166d5987852a6a73 (patch) | |
tree | 95511c465c54c4f5d27e5d39ce187e2a1dd82bd3 /third_party/git/trailer.h | |
parent | 082c006c04343a78d87b6c6ab3608c25d6213c3f (diff) |
merge(3p/git): Merge git subtree at v2.29.2 r/1890
This also bumps the stable nixpkgs to 20.09 as of 2020-11-21, because there is some breakage in the git build related to the netrc credentials helper which someone has taken care of in nixpkgs. The stable channel is not used for anything other than git, so this should be fine. Change-Id: I3575a19dab09e1e9556cf8231d717de9890484fb
Diffstat (limited to 'third_party/git/trailer.h')
-rw-r--r-- | third_party/git/trailer.h | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/third_party/git/trailer.h b/third_party/git/trailer.h index 203acf4ee1db..cd93e7ddea78 100644 --- a/third_party/git/trailer.h +++ b/third_party/git/trailer.h @@ -2,8 +2,7 @@ #define TRAILER_H #include "list.h" - -struct strbuf; +#include "strbuf.h" enum trailer_where { WHERE_DEFAULT, @@ -103,4 +102,46 @@ void trailer_info_release(struct trailer_info *info); void format_trailers_from_commit(struct strbuf *out, const char *msg, const struct process_trailer_options *opts); +/* + * An interface for iterating over the trailers found in a particular commit + * message. Use like: + * + * struct trailer_iterator iter; + * trailer_iterator_init(&iter, msg); + * while (trailer_iterator_advance(&iter)) + * ... do something with iter.key and iter.val ... + * trailer_iterator_release(&iter); + */ +struct trailer_iterator { + struct strbuf key; + struct strbuf val; + + /* private */ + struct trailer_info info; + size_t cur; +}; + +/* + * Initialize "iter" in preparation for walking over the trailers in the commit + * message "msg". The "msg" pointer must remain valid until the iterator is + * released. + * + * After initializing, note that key/val will not yet point to any trailer. + * Call advance() to parse the first one (if any). + */ +void trailer_iterator_init(struct trailer_iterator *iter, const char *msg); + +/* + * Advance to the next trailer of the iterator. Returns 0 if there is no such + * trailer, and 1 otherwise. The key and value of the trailer can be + * fetched from the iter->key and iter->value fields (which are valid + * only until the next advance). + */ +int trailer_iterator_advance(struct trailer_iterator *iter); + +/* + * Release all resources associated with the trailer iteration. + */ +void trailer_iterator_release(struct trailer_iterator *iter); + #endif /* TRAILER_H */ |