@@ -83,18 +83,51 @@ static int contains(struct commit *candidate, const struct commit_list *want)
8383 return contains_recurse (candidate , want );
8484}
8585
86+ static void show_tag_lines (const unsigned char * sha1 , int lines )
87+ {
88+ int i ;
89+ unsigned long size ;
90+ enum object_type type ;
91+ char * buf , * sp , * eol ;
92+ size_t len ;
93+
94+ buf = read_sha1_file (sha1 , & type , & size );
95+ if (!buf )
96+ die_errno ("unable to read object %s" , sha1_to_hex (sha1 ));
97+ if (type != OBJ_COMMIT && type != OBJ_TAG )
98+ goto free_return ;
99+ if (!size )
100+ die ("an empty %s object %s?" ,
101+ typename (type ), sha1_to_hex (sha1 ));
102+
103+ /* skip header */
104+ sp = strstr (buf , "\n\n" );
105+ if (!sp )
106+ goto free_return ;
107+
108+ /* only take up to "lines" lines, and strip the signature from a tag */
109+ if (type == OBJ_TAG )
110+ size = parse_signature (buf , size );
111+ for (i = 0 , sp += 2 ; i < lines && sp < buf + size ; i ++ ) {
112+ if (i )
113+ printf ("\n " );
114+ eol = memchr (sp , '\n' , size - (sp - buf ));
115+ len = eol ? eol - sp : size - (sp - buf );
116+ fwrite (sp , len , 1 , stdout );
117+ if (!eol )
118+ break ;
119+ sp = eol + 1 ;
120+ }
121+ free_return :
122+ free (buf );
123+ }
124+
86125static int show_reference (const char * refname , const unsigned char * sha1 ,
87126 int flag , void * cb_data )
88127{
89128 struct tag_filter * filter = cb_data ;
90129
91130 if (match_pattern (filter -> patterns , refname )) {
92- int i ;
93- unsigned long size ;
94- enum object_type type ;
95- char * buf , * sp , * eol ;
96- size_t len ;
97-
98131 if (filter -> with_commit ) {
99132 struct commit * commit ;
100133
@@ -110,33 +143,8 @@ static int show_reference(const char *refname, const unsigned char *sha1,
110143 return 0 ;
111144 }
112145 printf ("%-15s " , refname );
113-
114- buf = read_sha1_file (sha1 , & type , & size );
115- if (!buf || !size )
116- return 0 ;
117-
118- /* skip header */
119- sp = strstr (buf , "\n\n" );
120- if (!sp ) {
121- free (buf );
122- return 0 ;
123- }
124- /* only take up to "lines" lines, and strip the signature */
125- size = parse_signature (buf , size );
126- for (i = 0 , sp += 2 ;
127- i < filter -> lines && sp < buf + size ;
128- i ++ ) {
129- if (i )
130- printf ("\n " );
131- eol = memchr (sp , '\n' , size - (sp - buf ));
132- len = eol ? eol - sp : size - (sp - buf );
133- fwrite (sp , len , 1 , stdout );
134- if (!eol )
135- break ;
136- sp = eol + 1 ;
137- }
146+ show_tag_lines (sha1 , filter -> lines );
138147 putchar ('\n' );
139- free (buf );
140148 }
141149
142150 return 0 ;
0 commit comments