MCPcopy Index your code
hub / github.com/git/git / parse_treeish_arg

Function parse_treeish_arg

archive.c:485–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

483}
484
485static void parse_treeish_arg(const char **argv,
486 struct archiver_args *ar_args, int remote)
487{
488 const char *name = argv[0];
489 const struct object_id *commit_oid;
490 time_t archive_time;
491 struct tree *tree;
492 const struct commit *commit;
493 struct object_id oid;
494 char *ref = NULL;
495
496 /* Remotes are only allowed to fetch actual refs */
497 if (remote && !remote_allow_unreachable) {
498 const char *colon = strchrnul(name, ':');
499 int refnamelen = colon - name;
500
501 if (!repo_dwim_ref(the_repository, name, refnamelen, &oid, &ref, 0))
502 die(_("no such ref: %.*s"), refnamelen, name);
503 } else {
504 repo_dwim_ref(the_repository, name, strlen(name), &oid, &ref,
505 0);
506 }
507
508 if (repo_get_oid(the_repository, name, &oid))
509 die(_("not a valid object name: %s"), name);
510
511 commit = lookup_commit_reference_gently(ar_args->repo, &oid, 1);
512 if (commit) {
513 commit_oid = &commit->object.oid;
514 archive_time = commit->date;
515 } else {
516 commit_oid = NULL;
517 archive_time = time(NULL);
518 }
519 if (ar_args->mtime_option)
520 archive_time = approxidate(ar_args->mtime_option);
521
522 tree = repo_parse_tree_indirect(the_repository, &oid);
523 if (!tree)
524 die(_("not a tree object: %s"), oid_to_hex(&oid));
525
526 /*
527 * Setup index and instruct attr to read index only
528 */
529 if (!ar_args->worktree_attributes) {
530 struct unpack_trees_options opts;
531 struct tree_desc t;
532
533 memset(&opts, 0, sizeof(opts));
534 opts.index_only = 1;
535 opts.head_idx = -1;
536 opts.src_index = ar_args->repo->index;
537 opts.dst_index = ar_args->repo->index;
538 opts.fn = oneway_merge;
539 init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
540 if (unpack_trees(1, &t, &opts))
541 die(_("failed to unpack tree object %s"),
542 oid_to_hex(&tree->object.oid));

Callers 1

write_archiveFunction · 0.85

Calls 9

repo_dwim_refFunction · 0.85
repo_get_oidFunction · 0.85
repo_parse_tree_indirectFunction · 0.85
oid_to_hexFunction · 0.85
init_tree_descFunction · 0.85
unpack_treesFunction · 0.85
git_attr_set_directionFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected