Changeset 782 for git/branches/dmik/archive.c
- Timestamp:
- Jun 23, 2014, 9:45:51 PM (11 years ago)
- Location:
- git/branches/dmik
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
git/branches/dmik ¶
- Property svn:mergeinfo changed
/git/vendor/2.0.0 (added) merged: 777 /git/vendor/current merged: 772,774,776
- Property svn:mergeinfo changed
-
TabularUnified git/branches/dmik/archive.c ¶
r626 r782 8 8 9 9 static char const * const archive_usage[] = { 10 "git archive [options] <tree-ish> [<path>...]",11 "git archive --list",12 "git archive --remote <repo> [--exec <cmd>] [options] <tree-ish> [<path>...]",13 "git archive --remote <repo> [--exec <cmd>] --list",10 N_("git archive [options] <tree-ish> [<path>...]"), 11 N_("git archive --list"), 12 N_("git archive --remote <repo> [--exec <cmd>] [options] <tree-ish> [<path>...]"), 13 N_("git archive --remote <repo> [--exec <cmd>] --list"), 14 14 NULL 15 15 }; … … 18 18 static int nr_archivers; 19 19 static int alloc_archivers; 20 static int remote_allow_unreachable; 20 21 21 22 void register_archiver(struct archiver *ar) … … 60 61 } 61 62 62 static void *sha1_file_to_archive(const char *path, const unsigned char *sha1, 63 unsigned int mode, enum object_type *type, 64 unsigned long *sizep, const struct commit *commit) 63 void *sha1_file_to_archive(const struct archiver_args *args, 64 const char *path, const unsigned char *sha1, 65 unsigned int mode, enum object_type *type, 66 unsigned long *sizep) 65 67 { 66 68 void *buffer; 67 69 const struct commit *commit = args->convert ? args->commit : NULL; 70 71 path += args->baselen; 68 72 buffer = read_sha1_file(sha1, type, sizep); 69 73 if (buffer && S_ISREG(mode)) { … … 110 114 struct git_attr_check check[2]; 111 115 const char *path_without_prefix; 112 int convert = 0;113 116 int err; 114 enum object_type type; 115 unsigned long size; 116 void *buffer; 117 117 118 args->convert = 0; 118 119 strbuf_reset(&path); 119 120 strbuf_grow(&path, PATH_MAX); … … 121 122 strbuf_add(&path, base, baselen); 122 123 strbuf_addstr(&path, filename); 124 if (S_ISDIR(mode) || S_ISGITLINK(mode)) 125 strbuf_addch(&path, '/'); 123 126 path_without_prefix = path.buf + args->baselen; 124 127 … … 127 130 if (ATTR_TRUE(check[0].value)) 128 131 return 0; 129 convert = ATTR_TRUE(check[1].value);132 args->convert = ATTR_TRUE(check[1].value); 130 133 } 131 134 132 135 if (S_ISDIR(mode) || S_ISGITLINK(mode)) { 133 strbuf_addch(&path, '/');134 136 if (args->verbose) 135 137 fprintf(stderr, "%.*s\n", (int)path.len, path.buf); 136 err = write_entry(args, sha1, path.buf, path.len, mode , NULL, 0);138 err = write_entry(args, sha1, path.buf, path.len, mode); 137 139 if (err) 138 140 return err; … … 140 142 } 141 143 142 buffer = sha1_file_to_archive(path_without_prefix, sha1, mode,143 &type, &size, convert ? args->commit : NULL);144 if (!buffer)145 return error("cannot read %s", sha1_to_hex(sha1));146 144 if (args->verbose) 147 145 fprintf(stderr, "%.*s\n", (int)path.len, path.buf); 148 err = write_entry(args, sha1, path.buf, path.len, mode, buffer, size); 149 free(buffer); 150 return err; 146 return write_entry(args, sha1, path.buf, path.len, mode); 151 147 } 152 148 … … 157 153 struct unpack_trees_options opts; 158 154 struct tree_desc t; 159 struct pathspec pathspec;160 155 int err; 161 156 … … 168 163 fprintf(stderr, "%.*s\n", (int)len, args->base); 169 164 err = write_entry(args, args->tree->object.sha1, args->base, 170 len, 040777, NULL, 0);165 len, 040777); 171 166 if (err) 172 167 return err; … … 192 187 } 193 188 194 init_pathspec(&pathspec, args->pathspec); 195 err = read_tree_recursive(args->tree, "", 0, 0, &pathspec, 189 err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec, 196 190 write_archive_entry, &context); 197 free_pathspec(&pathspec);198 191 if (err == READ_TREE_RECURSIVE) 199 192 err = 0; … … 228 221 int ret; 229 222 230 init_pathspec(&pathspec, paths);223 parse_pathspec(&pathspec, 0, 0, "", paths); 231 224 ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL); 232 225 free_pathspec(&pathspec); … … 237 230 struct archiver_args *ar_args) 238 231 { 239 ar_args->pathspec = pathspec = get_pathspec("", pathspec); 232 /* 233 * must be consistent with parse_pathspec in path_exists() 234 * Also if pathspec patterns are dependent, we're in big 235 * trouble as we test each one separately 236 */ 237 parse_pathspec(&ar_args->pathspec, 0, 238 PATHSPEC_PREFER_FULL, 239 "", pathspec); 240 240 if (pathspec) { 241 241 while (*pathspec) { 242 if ( !path_exists(ar_args->tree, *pathspec))243 die( "path not found: %s", *pathspec);242 if (**pathspec && !path_exists(ar_args->tree, *pathspec)) 243 die(_("pathspec '%s' did not match any files"), *pathspec); 244 244 pathspec++; 245 245 } … … 259 259 260 260 /* Remotes are only allowed to fetch actual refs */ 261 if (remote ) {261 if (remote && !remote_allow_unreachable) { 262 262 char *ref = NULL; 263 const char *refname, *colon = NULL; 264 265 colon = strchr(name, ':'); 266 if (colon) 267 refname = xstrndup(name, colon - name); 268 else 269 refname = name; 270 271 if (!dwim_ref(refname, strlen(refname), sha1, &ref)) 272 die("no such ref: %s", refname); 273 if (refname != name) 274 free((void *)refname); 263 const char *colon = strchrnul(name, ':'); 264 int refnamelen = colon - name; 265 266 if (!dwim_ref(name, refnamelen, sha1, &ref)) 267 die("no such ref: %.*s", refnamelen, name); 275 268 free(ref); 276 269 } … … 333 326 struct option opts[] = { 334 327 OPT_GROUP(""), 335 OPT_STRING(0, "format", &format, "fmt", "archive format"),336 OPT_STRING(0, "prefix", &base, "prefix",337 "prepend prefix to each pathname in the archive"),338 OPT_STRING('o', "output", &output, "file",339 "write the archive to this file"),328 OPT_STRING(0, "format", &format, N_("fmt"), N_("archive format")), 329 OPT_STRING(0, "prefix", &base, N_("prefix"), 330 N_("prepend prefix to each pathname in the archive")), 331 OPT_STRING('o', "output", &output, N_("file"), 332 N_("write the archive to this file")), 340 333 OPT_BOOL(0, "worktree-attributes", &worktree_attributes, 341 "read .gitattributes in working directory"),342 OPT__VERBOSE(&verbose, "report archived files on stderr"),343 OPT__COMPR('0', &compression_level, "store only", 0),344 OPT__COMPR('1', &compression_level, "compress faster", 1),334 N_("read .gitattributes in working directory")), 335 OPT__VERBOSE(&verbose, N_("report archived files on stderr")), 336 OPT__COMPR('0', &compression_level, N_("store only"), 0), 337 OPT__COMPR('1', &compression_level, N_("compress faster"), 1), 345 338 OPT__COMPR_HIDDEN('2', &compression_level, 2), 346 339 OPT__COMPR_HIDDEN('3', &compression_level, 3), … … 350 343 OPT__COMPR_HIDDEN('7', &compression_level, 7), 351 344 OPT__COMPR_HIDDEN('8', &compression_level, 8), 352 OPT__COMPR('9', &compression_level, "compress better", 9),345 OPT__COMPR('9', &compression_level, N_("compress better"), 9), 353 346 OPT_GROUP(""), 354 347 OPT_BOOL('l', "list", &list, 355 "list supported archive formats"),348 N_("list supported archive formats")), 356 349 OPT_GROUP(""), 357 OPT_STRING(0, "remote", &remote, "repo",358 "retrieve the archive from remote repository <repo>"),359 OPT_STRING(0, "exec", &exec, "cmd",360 "path to the remote git-upload-archive command"),350 OPT_STRING(0, "remote", &remote, N_("repo"), 351 N_("retrieve the archive from remote repository <repo>")), 352 OPT_STRING(0, "exec", &exec, N_("command"), 353 N_("path to the remote git-upload-archive command")), 361 354 OPT_END() 362 355 }; … … 410 403 } 411 404 405 static int git_default_archive_config(const char *var, const char *value, 406 void *cb) 407 { 408 if (!strcmp(var, "uploadarchive.allowunreachable")) 409 remote_allow_unreachable = git_config_bool(var, value); 410 return git_default_config(var, value, cb); 411 } 412 412 413 int write_archive(int argc, const char **argv, const char *prefix, 413 414 int setup_prefix, const char *name_hint, int remote) … … 420 421 prefix = setup_git_directory_gently(&nongit); 421 422 422 git_config(git_default_ config, NULL);423 git_config(git_default_archive_config, NULL); 423 424 init_tar_archiver(); 424 425 init_zip_archiver(); … … 449 450 * filename). 450 451 */ 451 if (prefixlen < 2 || filename[prefixlen -1] != '.')452 if (prefixlen < 2 || filename[prefixlen - 1] != '.') 452 453 return 0; 453 454 return !strcmp(filename + prefixlen, ext);
Note:
See TracChangeset
for help on using the changeset viewer.