@@ -157,18 +157,26 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
157157 return write_entry (args , sha1 , path .buf , path .len , mode );
158158}
159159
160+ static int write_archive_entry_buf (const unsigned char * sha1 , struct strbuf * base ,
161+ const char * filename , unsigned mode , int stage ,
162+ void * context )
163+ {
164+ return write_archive_entry (sha1 , base -> buf , base -> len ,
165+ filename , mode , stage , context );
166+ }
167+
160168static void queue_directory (const unsigned char * sha1 ,
161- const char * base , int baselen , const char * filename ,
169+ struct strbuf * base , const char * filename ,
162170 unsigned mode , int stage , struct archiver_context * c )
163171{
164172 struct directory * d ;
165- d = xmallocz (sizeof (* d ) + baselen + 1 + strlen (filename ));
173+ d = xmallocz (sizeof (* d ) + base -> len + 1 + strlen (filename ));
166174 d -> up = c -> bottom ;
167- d -> baselen = baselen ;
175+ d -> baselen = base -> len ;
168176 d -> mode = mode ;
169177 d -> stage = stage ;
170178 c -> bottom = d ;
171- d -> len = sprintf (d -> path , "%.*s%s/" , baselen , base , filename );
179+ d -> len = sprintf (d -> path , "%.*s%s/" , ( int ) base -> len , base -> buf , filename );
172180 hashcpy (d -> sha1 , sha1 );
173181}
174182
@@ -191,28 +199,28 @@ static int write_directory(struct archiver_context *c)
191199}
192200
193201static int queue_or_write_archive_entry (const unsigned char * sha1 ,
194- const char * base , int baselen , const char * filename ,
202+ struct strbuf * base , const char * filename ,
195203 unsigned mode , int stage , void * context )
196204{
197205 struct archiver_context * c = context ;
198206
199207 while (c -> bottom &&
200- !(baselen >= c -> bottom -> len &&
201- !strncmp (base , c -> bottom -> path , c -> bottom -> len ))) {
208+ !(base -> len >= c -> bottom -> len &&
209+ !strncmp (base -> buf , c -> bottom -> path , c -> bottom -> len ))) {
202210 struct directory * next = c -> bottom -> up ;
203211 free (c -> bottom );
204212 c -> bottom = next ;
205213 }
206214
207215 if (S_ISDIR (mode )) {
208- queue_directory (sha1 , base , baselen , filename ,
216+ queue_directory (sha1 , base , filename ,
209217 mode , stage , c );
210218 return READ_TREE_RECURSIVE ;
211219 }
212220
213221 if (write_directory (c ))
214222 return -1 ;
215- return write_archive_entry (sha1 , base , baselen , filename , mode ,
223+ return write_archive_entry (sha1 , base -> buf , base -> len , filename , mode ,
216224 stage , context );
217225}
218226
@@ -260,7 +268,7 @@ int write_archive_entries(struct archiver_args *args,
260268 err = read_tree_recursive (args -> tree , "" , 0 , 0 , & args -> pathspec ,
261269 args -> pathspec .has_wildcard ?
262270 queue_or_write_archive_entry :
263- write_archive_entry ,
271+ write_archive_entry_buf ,
264272 & context );
265273 if (err == READ_TREE_RECURSIVE )
266274 err = 0 ;
@@ -286,14 +294,14 @@ static const struct archiver *lookup_archiver(const char *name)
286294 return NULL ;
287295}
288296
289- static int reject_entry (const unsigned char * sha1 , const char * base ,
290- int baselen , const char * filename , unsigned mode ,
297+ static int reject_entry (const unsigned char * sha1 , struct strbuf * base ,
298+ const char * filename , unsigned mode ,
291299 int stage , void * context )
292300{
293301 int ret = -1 ;
294302 if (S_ISDIR (mode )) {
295303 struct strbuf sb = STRBUF_INIT ;
296- strbuf_addstr (& sb , base );
304+ strbuf_addbuf (& sb , base );
297305 strbuf_addstr (& sb , filename );
298306 if (!match_pathspec (context , sb .buf , sb .len , 0 , NULL , 1 ))
299307 ret = READ_TREE_RECURSIVE ;
0 commit comments