1313#include "utf8.h"
1414#include "git-compat-util.h"
1515#include "version.h"
16+ #include "trailer.h"
1617
1718typedef enum { FIELD_STR , FIELD_ULONG , FIELD_TIME } cmp_type ;
1819
@@ -40,7 +41,7 @@ static struct used_atom {
4041 enum { RR_NORMAL , RR_SHORTEN , RR_TRACK , RR_TRACKSHORT }
4142 remote_ref ;
4243 struct {
43- enum { C_BARE , C_BODY , C_BODY_DEP , C_LINES , C_SIG , C_SUB } option ;
44+ enum { C_BARE , C_BODY , C_BODY_DEP , C_LINES , C_SIG , C_SUB , C_TRAILERS } option ;
4445 unsigned int nlines ;
4546 } contents ;
4647 enum { O_FULL , O_SHORT } objectname ;
@@ -85,6 +86,13 @@ static void subject_atom_parser(struct used_atom *atom, const char *arg)
8586 atom -> u .contents .option = C_SUB ;
8687}
8788
89+ static void trailers_atom_parser (struct used_atom * atom , const char * arg )
90+ {
91+ if (arg )
92+ die (_ ("%%(trailers) does not take arguments" ));
93+ atom -> u .contents .option = C_TRAILERS ;
94+ }
95+
8896static void contents_atom_parser (struct used_atom * atom , const char * arg )
8997{
9098 if (!arg )
@@ -95,6 +103,8 @@ static void contents_atom_parser(struct used_atom *atom, const char *arg)
95103 atom -> u .contents .option = C_SIG ;
96104 else if (!strcmp (arg , "subject" ))
97105 atom -> u .contents .option = C_SUB ;
106+ else if (!strcmp (arg , "trailers" ))
107+ atom -> u .contents .option = C_TRAILERS ;
98108 else if (skip_prefix (arg , "lines=" , & arg )) {
99109 atom -> u .contents .option = C_LINES ;
100110 if (strtoul_ui (arg , 10 , & atom -> u .contents .nlines ))
@@ -194,6 +204,7 @@ static struct {
194204 { "creatordate" , FIELD_TIME },
195205 { "subject" , FIELD_STR , subject_atom_parser },
196206 { "body" , FIELD_STR , body_atom_parser },
207+ { "trailers" , FIELD_STR , trailers_atom_parser },
197208 { "contents" , FIELD_STR , contents_atom_parser },
198209 { "upstream" , FIELD_STR , remote_ref_atom_parser },
199210 { "push" , FIELD_STR , remote_ref_atom_parser },
@@ -785,6 +796,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj
785796 name ++ ;
786797 if (strcmp (name , "subject" ) &&
787798 strcmp (name , "body" ) &&
799+ strcmp (name , "trailers" ) &&
788800 !starts_with (name , "contents" ))
789801 continue ;
790802 if (!subpos )
@@ -808,6 +820,14 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj
808820 /* Size is the length of the message after removing the signature */
809821 append_lines (& s , subpos , contents_end - subpos , atom -> u .contents .nlines );
810822 v -> s = strbuf_detach (& s , NULL );
823+ } else if (atom -> u .contents .option == C_TRAILERS ) {
824+ struct trailer_info info ;
825+
826+ /* Search for trailer info */
827+ trailer_info_get (& info , subpos );
828+ v -> s = xmemdupz (info .trailer_start ,
829+ info .trailer_end - info .trailer_start );
830+ trailer_info_release (& info );
811831 } else if (atom -> u .contents .option == C_BARE )
812832 v -> s = xstrdup (subpos );
813833 }
0 commit comments