X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=trailer.h;h=cd93e7ddea789cb6c320af2a7b984bd6f8a8215f;hb=a78305ffbca58e49a7cdad901df0ae779bbed8fb;hp=9c10026c358326ce0c0098ca52341ce8160c5bbe;hpb=63b33047c1428dbf4f480b384962c6c8c0e841dd;p=platform%2Fupstream%2Fgit.git diff --git a/trailer.h b/trailer.h index 9c10026..cd93e7d 100644 --- a/trailer.h +++ b/trailer.h @@ -2,8 +2,7 @@ #define TRAILER_H #include "list.h" - -struct strbuf; +#include "strbuf.h" enum trailer_where { WHERE_DEFAULT, @@ -71,6 +70,11 @@ struct process_trailer_options { int only_trailers; int only_input; int unfold; + int no_divider; + int value_only; + const struct strbuf *separator; + int (*filter)(const struct strbuf *, void *); + void *filter_data; }; #define PROCESS_TRAILER_OPTIONS_INIT {0} @@ -79,7 +83,8 @@ void process_trailers(const char *file, const struct process_trailer_options *opts, struct list_head *new_trailer_head); -void trailer_info_get(struct trailer_info *info, const char *str); +void trailer_info_get(struct trailer_info *info, const char *str, + const struct process_trailer_options *opts); void trailer_info_release(struct trailer_info *info); @@ -97,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 */