@@ -157,18 +157,26 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
157
157
return write_entry (args , sha1 , path .buf , path .len , mode );
158
158
}
159
159
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
+
160
168
static void queue_directory (const unsigned char * sha1 ,
161
- const char * base , int baselen , const char * filename ,
169
+ struct strbuf * base , const char * filename ,
162
170
unsigned mode , int stage , struct archiver_context * c )
163
171
{
164
172
struct directory * d ;
165
- d = xmallocz (sizeof (* d ) + baselen + 1 + strlen (filename ));
173
+ d = xmallocz (sizeof (* d ) + base -> len + 1 + strlen (filename ));
166
174
d -> up = c -> bottom ;
167
- d -> baselen = baselen ;
175
+ d -> baselen = base -> len ;
168
176
d -> mode = mode ;
169
177
d -> stage = stage ;
170
178
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 );
172
180
hashcpy (d -> sha1 , sha1 );
173
181
}
174
182
@@ -191,28 +199,28 @@ static int write_directory(struct archiver_context *c)
191
199
}
192
200
193
201
static 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 ,
195
203
unsigned mode , int stage , void * context )
196
204
{
197
205
struct archiver_context * c = context ;
198
206
199
207
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 ))) {
202
210
struct directory * next = c -> bottom -> up ;
203
211
free (c -> bottom );
204
212
c -> bottom = next ;
205
213
}
206
214
207
215
if (S_ISDIR (mode )) {
208
- queue_directory (sha1 , base , baselen , filename ,
216
+ queue_directory (sha1 , base , filename ,
209
217
mode , stage , c );
210
218
return READ_TREE_RECURSIVE ;
211
219
}
212
220
213
221
if (write_directory (c ))
214
222
return -1 ;
215
- return write_archive_entry (sha1 , base , baselen , filename , mode ,
223
+ return write_archive_entry (sha1 , base -> buf , base -> len , filename , mode ,
216
224
stage , context );
217
225
}
218
226
@@ -260,7 +268,7 @@ int write_archive_entries(struct archiver_args *args,
260
268
err = read_tree_recursive (args -> tree , "" , 0 , 0 , & args -> pathspec ,
261
269
args -> pathspec .has_wildcard ?
262
270
queue_or_write_archive_entry :
263
- write_archive_entry ,
271
+ write_archive_entry_buf ,
264
272
& context );
265
273
if (err == READ_TREE_RECURSIVE )
266
274
err = 0 ;
@@ -286,14 +294,14 @@ static const struct archiver *lookup_archiver(const char *name)
286
294
return NULL ;
287
295
}
288
296
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 ,
291
299
int stage , void * context )
292
300
{
293
301
int ret = -1 ;
294
302
if (S_ISDIR (mode )) {
295
303
struct strbuf sb = STRBUF_INIT ;
296
- strbuf_addstr (& sb , base );
304
+ strbuf_addbuf (& sb , base );
297
305
strbuf_addstr (& sb , filename );
298
306
if (!match_pathspec (context , sb .buf , sb .len , 0 , NULL , 1 ))
299
307
ret = READ_TREE_RECURSIVE ;
0 commit comments