git-tar-tree: Move code for git-archive --format=tar to archive-tar.c
This patch doesn't change any functionality, it only moves code around. It makes seeing the few remaining lines of git-tar-tree code easier. ;-) Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
Rene Scharfe committed
Sep 24, 2006 at 17:31 UTC
3d74982f0b1f8895d27937aa6ed62c1ddd50a020
3 files changed
+326
-314
Makefile
+1
-1
@@ -256,7 +256,7 @@ LIB_OBJS = \
256
fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
257
write_or_die.o trace.o list-objects.o grep.o \
258
alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \
259
- color.o wt-status.o archive-zip.o
259
+ color.o wt-status.o archive-zip.o archive-tar.o
260
261
BUILTIN_OBJS = \
262
builtin-add.o \
archive-tar.c
new
+325
@@ -0,0 +1,325 @@
1
+/*
2
+ * Copyright (c) 2005, 2006 Rene Scharfe
3
+ */
4
+#include <time.h>
5
+#include "cache.h"
6
+#include "commit.h"
7
+#include "strbuf.h"
8
+#include "tar.h"
9
+#include "builtin.h"
10
+#include "archive.h"
11
+
12
+#define RECORDSIZE (512)
13
+#define BLOCKSIZE (RECORDSIZE * 20)
14
+
15
+static char block[BLOCKSIZE];
16
+static unsigned long offset;
17
+
18
+static time_t archive_time;
19
+static int tar_umask;
20
+static int verbose;
21
+
22
+/* writes out the whole block, but only if it is full */
23
+static void write_if_needed(void)
24
+{
25
+ if (offset == BLOCKSIZE) {
26
+ write_or_die(1, block, BLOCKSIZE);
27
+ offset = 0;
28
+ }
29
+}
30
+
31
+/*
32
+ * queues up writes, so that all our write(2) calls write exactly one
33
+ * full block; pads writes to RECORDSIZE
34
+ */
35
+static void write_blocked(const void *data, unsigned long size)
36
+{
37
+ const char *buf = data;
38
+ unsigned long tail;
39
+
40
+ if (offset) {
41
+ unsigned long chunk = BLOCKSIZE - offset;
42
+ if (size < chunk)
43
+ chunk = size;
44
+ memcpy(block + offset, buf, chunk);
45
+ size -= chunk;
46
+ offset += chunk;
47
+ buf += chunk;
48
+ write_if_needed();
49
+ }
50
+ while (size >= BLOCKSIZE) {
51
+ write_or_die(1, buf, BLOCKSIZE);
52
+ size -= BLOCKSIZE;
53
+ buf += BLOCKSIZE;
54
+ }
55
+ if (size) {
56
+ memcpy(block + offset, buf, size);
57
+ offset += size;
58
+ }
59
+ tail = offset % RECORDSIZE;
60
+ if (tail) {
61
+ memset(block + offset, 0, RECORDSIZE - tail);
62
+ offset += RECORDSIZE - tail;
63
+ }
64
+ write_if_needed();
65
+}
66
+
67
+/*
68
+ * The end of tar archives is marked by 2*512 nul bytes and after that
69
+ * follows the rest of the block (if any).
70
+ */
71
+static void write_trailer(void)
72
+{
73
+ int tail = BLOCKSIZE - offset;
74
+ memset(block + offset, 0, tail);
75
+ write_or_die(1, block, BLOCKSIZE);
76
+ if (tail < 2 * RECORDSIZE) {
77
+ memset(block, 0, offset);
78
+ write_or_die(1, block, BLOCKSIZE);
79
+ }
80
+}
81
+
82
+static void strbuf_append_string(struct strbuf *sb, const char *s)
83
+{
84
+ int slen = strlen(s);
85
+ int total = sb->len + slen;
86
+ if (total > sb->alloc) {
87
+ sb->buf = xrealloc(sb->buf, total);
88
+ sb->alloc = total;
89
+ }
90
+ memcpy(sb->buf + sb->len, s, slen);
91
+ sb->len = total;
92
+}
93
+
94
+/*
95
+ * pax extended header records have the format "%u %s=%s\n". %u contains
96
+ * the size of the whole string (including the %u), the first %s is the
97
+ * keyword, the second one is the value. This function constructs such a
98
+ * string and appends it to a struct strbuf.
99
+ */
100
+static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
101
+ const char *value, unsigned int valuelen)
102
+{
103
+ char *p;
104
+ int len, total, tmp;
105
+
106
+ /* "%u %s=%s\n" */
107
+ len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1;
108
+ for (tmp = len; tmp > 9; tmp /= 10)
109
+ len++;
110
+
111
+ total = sb->len + len;
112
+ if (total > sb->alloc) {
113
+ sb->buf = xrealloc(sb->buf, total);
114
+ sb->alloc = total;
115
+ }
116
+
117
+ p = sb->buf;
118
+ p += sprintf(p, "%u %s=", len, keyword);
119
+ memcpy(p, value, valuelen);
120
+ p += valuelen;
121
+ *p = '\n';
122
+ sb->len = total;
123
+}
124
+
125
+static unsigned int ustar_header_chksum(const struct ustar_header *header)
126
+{
127
+ char *p = (char *)header;
128
+ unsigned int chksum = 0;
129
+ while (p < header->chksum)
130
+ chksum += *p++;
131
+ chksum += sizeof(header->chksum) * ' ';
132
+ p += sizeof(header->chksum);
133
+ while (p < (char *)header + sizeof(struct ustar_header))
134
+ chksum += *p++;
135
+ return chksum;
136
+}
137
+
138
+static int get_path_prefix(const struct strbuf *path, int maxlen)
139
+{
140
+ int i = path->len;
141
+ if (i > maxlen)
142
+ i = maxlen;
143
+ do {
144
+ i--;
145
+ } while (i > 0 && path->buf[i] != '/');
146
+ return i;
147
+}
148
+
149
+static void write_entry(const unsigned char *sha1, struct strbuf *path,
150
+ unsigned int mode, void *buffer, unsigned long size)
151
+{
152
+ struct ustar_header header;
153
+ struct strbuf ext_header;
154
+
155
+ memset(&header, 0, sizeof(header));
156
+ ext_header.buf = NULL;
157
+ ext_header.len = ext_header.alloc = 0;
158
+
159
+ if (!sha1) {
160
+ *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
161
+ mode = 0100666;
162
+ strcpy(header.name, "pax_global_header");
163
+ } else if (!path) {
164
+ *header.typeflag = TYPEFLAG_EXT_HEADER;
165
+ mode = 0100666;
166
+ sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1));
167
+ } else {
168
+ if (verbose)
169
+ fprintf(stderr, "%.*s\n", path->len, path->buf);
170
+ if (S_ISDIR(mode)) {
171
+ *header.typeflag = TYPEFLAG_DIR;
172
+ mode = (mode | 0777) & ~tar_umask;
173
+ } else if (S_ISLNK(mode)) {
174
+ *header.typeflag = TYPEFLAG_LNK;
175
+ mode |= 0777;
176
+ } else if (S_ISREG(mode)) {
177
+ *header.typeflag = TYPEFLAG_REG;
178
+ mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
179
+ } else {
180
+ error("unsupported file mode: 0%o (SHA1: %s)",
181
+ mode, sha1_to_hex(sha1));
182
+ return;
183
+ }
184
+ if (path->len > sizeof(header.name)) {
185
+ int plen = get_path_prefix(path, sizeof(header.prefix));
186
+ int rest = path->len - plen - 1;
187
+ if (plen > 0 && rest <= sizeof(header.name)) {
188
+ memcpy(header.prefix, path->buf, plen);
189
+ memcpy(header.name, path->buf + plen + 1, rest);
190
+ } else {
191
+ sprintf(header.name, "%s.data",
192
+ sha1_to_hex(sha1));
193
+ strbuf_append_ext_header(&ext_header, "path",
194
+ path->buf, path->len);
195
+ }
196
+ } else
197
+ memcpy(header.name, path->buf, path->len);
198
+ }
199
+
200
+ if (S_ISLNK(mode) && buffer) {
201
+ if (size > sizeof(header.linkname)) {
202
+ sprintf(header.linkname, "see %s.paxheader",
203
+ sha1_to_hex(sha1));
204
+ strbuf_append_ext_header(&ext_header, "linkpath",
205
+ buffer, size);
206
+ } else
207
+ memcpy(header.linkname, buffer, size);
208
+ }
209
+
210
+ sprintf(header.mode, "%07o", mode & 07777);
211
+ sprintf(header.size, "%011lo", S_ISREG(mode) ? size : 0);
212
+ sprintf(header.mtime, "%011lo", archive_time);
213
+
214
+ /* XXX: should we provide more meaningful info here? */
215
+ sprintf(header.uid, "%07o", 0);
216
+ sprintf(header.gid, "%07o", 0);
217
+ strlcpy(header.uname, "git", sizeof(header.uname));
218
+ strlcpy(header.gname, "git", sizeof(header.gname));
219
+ sprintf(header.devmajor, "%07o", 0);
220
+ sprintf(header.devminor, "%07o", 0);
221
+
222
+ memcpy(header.magic, "ustar", 6);
223
+ memcpy(header.version, "00", 2);
224
+
225
+ sprintf(header.chksum, "%07o", ustar_header_chksum(&header));
226
+
227
+ if (ext_header.len > 0) {
228
+ write_entry(sha1, NULL, 0, ext_header.buf, ext_header.len);
229
+ free(ext_header.buf);
230
+ }
231
+ write_blocked(&header, sizeof(header));
232
+ if (S_ISREG(mode) && buffer && size > 0)
233
+ write_blocked(buffer, size);
234
+}
235
+
236
+static void write_global_extended_header(const unsigned char *sha1)
237
+{
238
+ struct strbuf ext_header;
239
+ ext_header.buf = NULL;
240
+ ext_header.len = ext_header.alloc = 0;
241
+ strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
242
+ write_entry(NULL, NULL, 0, ext_header.buf, ext_header.len);
243
+ free(ext_header.buf);
244
+}
245
+
246
+static int git_tar_config(const char *var, const char *value)
247
+{
248
+ if (!strcmp(var, "tar.umask")) {
249
+ if (!strcmp(value, "user")) {
250
+ tar_umask = umask(0);
251
+ umask(tar_umask);
252
+ } else {
253
+ tar_umask = git_config_int(var, value);
254
+ }
255
+ return 0;
256
+ }
257
+ return git_default_config(var, value);
258
+}
259
+
260
+static int write_tar_entry(const unsigned char *sha1,
261
+ const char *base, int baselen,
262
+ const char *filename, unsigned mode, int stage)
263
+{
264
+ static struct strbuf path;
265
+ int filenamelen = strlen(filename);
266
+ void *buffer;
267
+ char type[20];
268
+ unsigned long size;
269
+
270
+ if (!path.alloc) {
271
+ path.buf = xmalloc(PATH_MAX);
272
+ path.alloc = PATH_MAX;
273
+ path.len = path.eof = 0;
274
+ }
275
+ if (path.alloc < baselen + filenamelen) {
276
+ free(path.buf);
277
+ path.buf = xmalloc(baselen + filenamelen);
278
+ path.alloc = baselen + filenamelen;
279
+ }
280
+ memcpy(path.buf, base, baselen);
281
+ memcpy(path.buf + baselen, filename, filenamelen);
282
+ path.len = baselen + filenamelen;
283
+ if (S_ISDIR(mode)) {
284
+ strbuf_append_string(&path, "/");
285
+ buffer = NULL;
286
+ size = 0;
287
+ } else {
288
+ buffer = read_sha1_file(sha1, type, &size);
289
+ if (!buffer)
290
+ die("cannot read %s", sha1_to_hex(sha1));
291
+ }
292
+
293
+ write_entry(sha1, &path, mode, buffer, size);
294
+ free(buffer);
295
+
296
+ return READ_TREE_RECURSIVE;
297
+}
298
+
299
+int write_tar_archive(struct archiver_args *args)
300
+{
301
+ int plen = args->base ? strlen(args->base) : 0;
302
+
303
+ git_config(git_tar_config);
304
+
305
+ archive_time = args->time;
306
+ verbose = args->verbose;
307
+
308
+ if (args->commit_sha1)
309
+ write_global_extended_header(args->commit_sha1);
310
+
311
+ if (args->base && plen > 0 && args->base[plen - 1] == '/') {
312
+ char *base = xstrdup(args->base);
313
+ int baselen = strlen(base);
314
+
315
+ while (baselen > 0 && base[baselen - 1] == '/')
316
+ base[--baselen] = '\0';
317
+ write_tar_entry(args->tree->object.sha1, "", 0, base, 040777, 0);
318
+ free(base);
319
+ }
320
+ read_tree_recursive(args->tree, args->base, plen, 0,
321
+ args->pathspec, write_tar_entry);
322
+ write_trailer();
323
+
324
+ return 0;
325
+}
builtin-tar-tree.c
-313
@@ -4,7 +4,6 @@
4
#include <time.h>
5
#include "cache.h"
6
#include "commit.h"
7
-#include "strbuf.h"
7
#include "tar.h"
8
#include "builtin.h"
9
#include "pkt-line.h"
@@ -16,251 +15,6 @@
15
static const char tar_tree_usage[] =
16
"git-tar-tree [--remote=<repo>] <tree-ish> [basedir]";
17
19
-static char block[BLOCKSIZE];
20
-static unsigned long offset;
21
-
22
-static time_t archive_time;
23
-static int tar_umask;
24
-static int verbose;
25
-
26
-/* writes out the whole block, but only if it is full */
27
-static void write_if_needed(void)
28
-{
29
- if (offset == BLOCKSIZE) {
30
- write_or_die(1, block, BLOCKSIZE);
31
- offset = 0;
32
- }
33
-}
34
-
35
-/*
36
- * queues up writes, so that all our write(2) calls write exactly one
37
- * full block; pads writes to RECORDSIZE
38
- */
39
-static void write_blocked(const void *data, unsigned long size)
40
-{
41
- const char *buf = data;
42
- unsigned long tail;
43
-
44
- if (offset) {
45
- unsigned long chunk = BLOCKSIZE - offset;
46
- if (size < chunk)
47
- chunk = size;
48
- memcpy(block + offset, buf, chunk);
49
- size -= chunk;
50
- offset += chunk;
51
- buf += chunk;
52
- write_if_needed();
53
- }
54
- while (size >= BLOCKSIZE) {
55
- write_or_die(1, buf, BLOCKSIZE);
56
- size -= BLOCKSIZE;
57
- buf += BLOCKSIZE;
58
- }
59
- if (size) {
60
- memcpy(block + offset, buf, size);
61
- offset += size;
62
- }
63
- tail = offset % RECORDSIZE;
64
- if (tail) {
65
- memset(block + offset, 0, RECORDSIZE - tail);
66
- offset += RECORDSIZE - tail;
67
- }
68
- write_if_needed();
69
-}
70
-
71
-/*
72
- * The end of tar archives is marked by 2*512 nul bytes and after that
73
- * follows the rest of the block (if any).
74
- */
75
-static void write_trailer(void)
76
-{
77
- int tail = BLOCKSIZE - offset;
78
- memset(block + offset, 0, tail);
79
- write_or_die(1, block, BLOCKSIZE);
80
- if (tail < 2 * RECORDSIZE) {
81
- memset(block, 0, offset);
82
- write_or_die(1, block, BLOCKSIZE);
83
- }
84
-}
85
-
86
-static void strbuf_append_string(struct strbuf *sb, const char *s)
87
-{
88
- int slen = strlen(s);
89
- int total = sb->len + slen;
90
- if (total > sb->alloc) {
91
- sb->buf = xrealloc(sb->buf, total);
92
- sb->alloc = total;
93
- }
94
- memcpy(sb->buf + sb->len, s, slen);
95
- sb->len = total;
96
-}
97
-
98
-/*
99
- * pax extended header records have the format "%u %s=%s\n". %u contains
100
- * the size of the whole string (including the %u), the first %s is the
101
- * keyword, the second one is the value. This function constructs such a
102
- * string and appends it to a struct strbuf.
103
- */
104
-static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
105
- const char *value, unsigned int valuelen)
106
-{
107
- char *p;
108
- int len, total, tmp;
109
-
110
- /* "%u %s=%s\n" */
111
- len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1;
112
- for (tmp = len; tmp > 9; tmp /= 10)
113
- len++;
114
-
115
- total = sb->len + len;
116
- if (total > sb->alloc) {
117
- sb->buf = xrealloc(sb->buf, total);
118
- sb->alloc = total;
119
- }
120
-
121
- p = sb->buf;
122
- p += sprintf(p, "%u %s=", len, keyword);
123
- memcpy(p, value, valuelen);
124
- p += valuelen;
125
- *p = '\n';
126
- sb->len = total;
127
-}
128
-
129
-static unsigned int ustar_header_chksum(const struct ustar_header *header)
130
-{
131
- char *p = (char *)header;
132
- unsigned int chksum = 0;
133
- while (p < header->chksum)
134
- chksum += *p++;
135
- chksum += sizeof(header->chksum) * ' ';
136
- p += sizeof(header->chksum);
137
- while (p < (char *)header + sizeof(struct ustar_header))
138
- chksum += *p++;
139
- return chksum;
140
-}
141
-
142
-static int get_path_prefix(const struct strbuf *path, int maxlen)
143
-{
144
- int i = path->len;
145
- if (i > maxlen)
146
- i = maxlen;
147
- do {
148
- i--;
149
- } while (i > 0 && path->buf[i] != '/');
150
- return i;
151
-}
152
-
153
-static void write_entry(const unsigned char *sha1, struct strbuf *path,
154
- unsigned int mode, void *buffer, unsigned long size)
155
-{
156
- struct ustar_header header;
157
- struct strbuf ext_header;
158
-
159
- memset(&header, 0, sizeof(header));
160
- ext_header.buf = NULL;
161
- ext_header.len = ext_header.alloc = 0;
162
-
163
- if (!sha1) {
164
- *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
165
- mode = 0100666;
166
- strcpy(header.name, "pax_global_header");
167
- } else if (!path) {
168
- *header.typeflag = TYPEFLAG_EXT_HEADER;
169
- mode = 0100666;
170
- sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1));
171
- } else {
172
- if (verbose)
173
- fprintf(stderr, "%.*s\n", path->len, path->buf);
174
- if (S_ISDIR(mode)) {
175
- *header.typeflag = TYPEFLAG_DIR;
176
- mode = (mode | 0777) & ~tar_umask;
177
- } else if (S_ISLNK(mode)) {
178
- *header.typeflag = TYPEFLAG_LNK;
179
- mode |= 0777;
180
- } else if (S_ISREG(mode)) {
181
- *header.typeflag = TYPEFLAG_REG;
182
- mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
183
- } else {
184
- error("unsupported file mode: 0%o (SHA1: %s)",
185
- mode, sha1_to_hex(sha1));
186
- return;
187
- }
188
- if (path->len > sizeof(header.name)) {
189
- int plen = get_path_prefix(path, sizeof(header.prefix));
190
- int rest = path->len - plen - 1;
191
- if (plen > 0 && rest <= sizeof(header.name)) {
192
- memcpy(header.prefix, path->buf, plen);
193
- memcpy(header.name, path->buf + plen + 1, rest);
194
- } else {
195
- sprintf(header.name, "%s.data",
196
- sha1_to_hex(sha1));
197
- strbuf_append_ext_header(&ext_header, "path",
198
- path->buf, path->len);
199
- }
200
- } else
201
- memcpy(header.name, path->buf, path->len);
202
- }
203
-
204
- if (S_ISLNK(mode) && buffer) {
205
- if (size > sizeof(header.linkname)) {
206
- sprintf(header.linkname, "see %s.paxheader",
207
- sha1_to_hex(sha1));
208
- strbuf_append_ext_header(&ext_header, "linkpath",
209
- buffer, size);
210
- } else
211
- memcpy(header.linkname, buffer, size);
212
- }
213
-
214
- sprintf(header.mode, "%07o", mode & 07777);
215
- sprintf(header.size, "%011lo", S_ISREG(mode) ? size : 0);
216
- sprintf(header.mtime, "%011lo", archive_time);
217
-
218
- /* XXX: should we provide more meaningful info here? */
219
- sprintf(header.uid, "%07o", 0);
220
- sprintf(header.gid, "%07o", 0);
221
- strlcpy(header.uname, "git", sizeof(header.uname));
222
- strlcpy(header.gname, "git", sizeof(header.gname));
223
- sprintf(header.devmajor, "%07o", 0);
224
- sprintf(header.devminor, "%07o", 0);
225
-
226
- memcpy(header.magic, "ustar", 6);
227
- memcpy(header.version, "00", 2);
228
-
229
- sprintf(header.chksum, "%07o", ustar_header_chksum(&header));
230
-
231
- if (ext_header.len > 0) {
232
- write_entry(sha1, NULL, 0, ext_header.buf, ext_header.len);
233
- free(ext_header.buf);
234
- }
235
- write_blocked(&header, sizeof(header));
236
- if (S_ISREG(mode) && buffer && size > 0)
237
- write_blocked(buffer, size);
238
-}
239
-
240
-static void write_global_extended_header(const unsigned char *sha1)
241
-{
242
- struct strbuf ext_header;
243
- ext_header.buf = NULL;
244
- ext_header.len = ext_header.alloc = 0;
245
- strbuf_append_ext_header(&ext_header, "comment", sha1_to_hex(sha1), 40);
246
- write_entry(NULL, NULL, 0, ext_header.buf, ext_header.len);
247
- free(ext_header.buf);
248
-}
249
-
250
-static int git_tar_config(const char *var, const char *value)
251
-{
252
- if (!strcmp(var, "tar.umask")) {
253
- if (!strcmp(value, "user")) {
254
- tar_umask = umask(0);
255
- umask(tar_umask);
256
- } else {
257
- tar_umask = git_config_int(var, value);
258
- }
259
- return 0;
260
- }
261
- return git_default_config(var, value);
262
-}
263
-
18
static int generate_tar(int argc, const char **argv, const char *prefix)
19
{
20
struct archiver_args args;
@@ -286,73 +40,6 @@ static int generate_tar(int argc, const char **argv, const char *prefix)
40
return result;
41
}
42
289
-static int write_tar_entry(const unsigned char *sha1,
290
- const char *base, int baselen,
291
- const char *filename, unsigned mode, int stage)
292
-{
293
- static struct strbuf path;
294
- int filenamelen = strlen(filename);
295
- void *buffer;
296
- char type[20];
297
- unsigned long size;
298
-
299
- if (!path.alloc) {
300
- path.buf = xmalloc(PATH_MAX);
301
- path.alloc = PATH_MAX;
302
- path.len = path.eof = 0;
303
- }
304
- if (path.alloc < baselen + filenamelen) {
305
- free(path.buf);
306
- path.buf = xmalloc(baselen + filenamelen);
307
- path.alloc = baselen + filenamelen;
308
- }
309
- memcpy(path.buf, base, baselen);
310
- memcpy(path.buf + baselen, filename, filenamelen);
311
- path.len = baselen + filenamelen;
312
- if (S_ISDIR(mode)) {
313
- strbuf_append_string(&path, "/");
314
- buffer = NULL;
315
- size = 0;
316
- } else {
317
- buffer = read_sha1_file(sha1, type, &size);
318
- if (!buffer)
319
- die("cannot read %s", sha1_to_hex(sha1));
320
- }
321
-
322
- write_entry(sha1, &path, mode, buffer, size);
323
- free(buffer);
324
-
325
- return READ_TREE_RECURSIVE;
326
-}
327
-
328
-int write_tar_archive(struct archiver_args *args)
329
-{
330
- int plen = args->base ? strlen(args->base) : 0;
331
-
332
- git_config(git_tar_config);
333
-
334
- archive_time = args->time;
335
- verbose = args->verbose;
336
-
337
- if (args->commit_sha1)
338
- write_global_extended_header(args->commit_sha1);
339
-
340
- if (args->base && plen > 0 && args->base[plen - 1] == '/') {
341
- char *base = xstrdup(args->base);
342
- int baselen = strlen(base);
343
-
344
- while (baselen > 0 && base[baselen - 1] == '/')
345
- base[--baselen] = '\0';
346
- write_tar_entry(args->tree->object.sha1, "", 0, base, 040777, 0);
347
- free(base);
348
- }
349
- read_tree_recursive(args->tree, args->base, plen, 0,
350
- args->pathspec, write_tar_entry);
351
- write_trailer();
352
-
353
- return 0;
354
-}
355
-
43
static const char *exec = "git-upload-tar";
44
45
static int remote_tar(int argc, const char **argv)