| 4005 | } |
| 4006 | |
| 4007 | static int do_reset(struct repository *r, |
| 4008 | const char *name, int len, |
| 4009 | struct replay_opts *opts) |
| 4010 | { |
| 4011 | struct strbuf ref_name = STRBUF_INIT; |
| 4012 | struct object_id oid; |
| 4013 | struct lock_file lock = LOCK_INIT; |
| 4014 | struct tree_desc desc = { 0 }; |
| 4015 | struct tree *tree; |
| 4016 | struct unpack_trees_options unpack_tree_opts = { 0 }; |
| 4017 | int ret = 0; |
| 4018 | |
| 4019 | if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) |
| 4020 | return -1; |
| 4021 | |
| 4022 | if (len == 10 && !strncmp("[new root]", name, len)) { |
| 4023 | if (!opts->have_squash_onto) { |
| 4024 | const char *hex; |
| 4025 | if (commit_tree("", 0, the_hash_algo->empty_tree, |
| 4026 | NULL, &opts->squash_onto, |
| 4027 | NULL, NULL)) |
| 4028 | return error(_("writing fake root commit")); |
| 4029 | opts->have_squash_onto = 1; |
| 4030 | hex = oid_to_hex(&opts->squash_onto); |
| 4031 | if (write_message(hex, strlen(hex), |
| 4032 | rebase_path_squash_onto(), 0)) |
| 4033 | return error(_("writing squash-onto")); |
| 4034 | } |
| 4035 | oidcpy(&oid, &opts->squash_onto); |
| 4036 | } else { |
| 4037 | int i; |
| 4038 | struct commit *commit; |
| 4039 | |
| 4040 | /* Determine the length of the label */ |
| 4041 | for (i = 0; i < len; i++) |
| 4042 | if (isspace(name[i])) |
| 4043 | break; |
| 4044 | len = i; |
| 4045 | |
| 4046 | commit = lookup_label(r, name, len, &ref_name); |
| 4047 | if (!commit) { |
| 4048 | ret = -1; |
| 4049 | goto cleanup; |
| 4050 | } |
| 4051 | oid = commit->object.oid; |
| 4052 | } |
| 4053 | |
| 4054 | setup_unpack_trees_porcelain(&unpack_tree_opts, "reset"); |
| 4055 | unpack_tree_opts.head_idx = 1; |
| 4056 | unpack_tree_opts.src_index = r->index; |
| 4057 | unpack_tree_opts.dst_index = r->index; |
| 4058 | unpack_tree_opts.fn = oneway_merge; |
| 4059 | unpack_tree_opts.merge = 1; |
| 4060 | unpack_tree_opts.update = 1; |
| 4061 | unpack_tree_opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ |
| 4062 | unpack_tree_opts.skip_cache_tree_update = 1; |
| 4063 | init_checkout_metadata(&unpack_tree_opts.meta, name, &oid, NULL); |
| 4064 |
no test coverage detected