summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/am.c10
-rw-r--r--builtin/blame.c5
-rw-r--r--builtin/branch.c2
-rw-r--r--builtin/cat-file.c30
-rw-r--r--builtin/checkout.c12
-rw-r--r--builtin/clone.c3
-rw-r--r--builtin/commit-tree.c2
-rw-r--r--builtin/count-objects.c7
-rw-r--r--builtin/describe.c6
-rw-r--r--builtin/difftool.c2
-rw-r--r--builtin/fast-export.c8
-rw-r--r--builtin/fetch.c12
-rw-r--r--builtin/fmt-merge-msg.c4
-rw-r--r--builtin/fsck.c19
-rw-r--r--builtin/gc.c7
-rw-r--r--builtin/grep.c9
-rw-r--r--builtin/index-pack.c44
-rw-r--r--builtin/log.c8
-rw-r--r--builtin/ls-files.c4
-rw-r--r--builtin/ls-tree.c8
-rw-r--r--builtin/merge-tree.c5
-rw-r--r--builtin/merge.c10
-rw-r--r--builtin/mktag.c20
-rw-r--r--builtin/mktree.c24
-rw-r--r--builtin/name-rev.c2
-rw-r--r--builtin/notes.c14
-rw-r--r--builtin/pack-objects.c49
-rw-r--r--builtin/pack-redundant.c8
-rw-r--r--builtin/prune.c2
-rw-r--r--builtin/receive-pack.c13
-rw-r--r--builtin/reflog.c2
-rw-r--r--builtin/replace.c10
-rw-r--r--builtin/reset.c2
-rw-r--r--builtin/rev-list.c2
-rw-r--r--builtin/rev-parse.c2
-rw-r--r--builtin/rm.c2
-rw-r--r--builtin/shortlog.c9
-rw-r--r--builtin/show-branch.c2
-rw-r--r--builtin/show-ref.c4
-rw-r--r--builtin/submodule--helper.c9
-rw-r--r--builtin/tag.c16
-rw-r--r--builtin/unpack-file.c2
-rw-r--r--builtin/unpack-objects.c4
-rw-r--r--builtin/update-index.c3
-rw-r--r--builtin/verify-commit.c2
-rw-r--r--builtin/worktree.c15
-rw-r--r--builtin/write-tree.c6
47 files changed, 231 insertions, 210 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 1151b5c..9c82603 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1550,7 +1550,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
discard_cache();
read_cache_from(index_path);
- if (write_index_as_tree(orig_tree.hash, &the_index, index_path, 0, NULL))
+ if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL))
return error(_("Repository lacks necessary blobs to fall back on 3-way merge."));
say(state, stdout, _("Using index info to reconstruct a base tree..."));
@@ -1575,7 +1575,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
return error(_("Did you hand edit your patch?\n"
"It does not apply to blobs recorded in its index."));
- if (write_index_as_tree(their_tree.hash, &the_index, index_path, 0, NULL))
+ if (write_index_as_tree(&their_tree, &the_index, index_path, 0, NULL))
return error("could not write tree");
say(state, stdout, _("Falling back to patching base and 3-way merge..."));
@@ -1626,7 +1626,7 @@ static void do_commit(const struct am_state *state)
if (run_hook_le(NULL, "pre-applypatch", NULL))
exit(1);
- if (write_cache_as_tree(tree.hash, 0, NULL))
+ if (write_cache_as_tree(&tree, 0, NULL))
die(_("git write-tree failed to write a tree"));
if (!get_oid_commit("HEAD", &parent)) {
@@ -1862,7 +1862,7 @@ next:
*/
if (!state->rebasing) {
am_destroy(state);
- close_all_packs();
+ close_all_packs(the_repository->objects);
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
}
}
@@ -2004,7 +2004,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
if (fast_forward_to(head_tree, head_tree, 1))
return -1;
- if (write_cache_as_tree(index.hash, 0, NULL))
+ if (write_cache_as_tree(&index, 0, NULL))
return -1;
index_tree = parse_tree_indirect(&index);
diff --git a/builtin/blame.c b/builtin/blame.c
index 9dcb367..db38c0b 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -499,7 +499,7 @@ static int read_ancestry(const char *graft_file)
static int update_auto_abbrev(int auto_abbrev, struct blame_origin *suspect)
{
- const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash,
+ const char *uniq = find_unique_abbrev(&suspect->commit->object.oid,
auto_abbrev);
int len = strlen(uniq);
if (auto_abbrev < len)
@@ -655,7 +655,7 @@ static int is_a_rev(const char *name)
if (get_oid(name, &oid))
return 0;
- return OBJ_NONE < sha1_object_info(oid.hash, NULL);
+ return OBJ_NONE < oid_object_info(&oid, NULL);
}
int cmd_blame(int argc, const char **argv, const char *prefix)
@@ -729,6 +729,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
for (;;) {
switch (parse_options_step(&ctx, options, blame_opt_usage)) {
case PARSE_OPT_HELP:
+ case PARSE_OPT_ERROR:
exit(129);
case PARSE_OPT_DONE:
if (ctx.argv[0])
diff --git a/builtin/branch.c b/builtin/branch.c
index 6d0cea9..5bd2a0d 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -273,7 +273,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
bname.buf,
(flags & REF_ISBROKEN) ? "broken"
: (flags & REF_ISSYMREF) ? target
- : find_unique_abbrev(oid.hash, DEFAULT_ABBREV));
+ : find_unique_abbrev(&oid, DEFAULT_ABBREV));
}
delete_branch_config(bname.buf);
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index d90170f..2c46d25 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -32,7 +32,7 @@ static int filter_object(const char *path, unsigned mode,
{
enum object_type type;
- *buf = read_sha1_file(oid->hash, &type, size);
+ *buf = read_object_file(oid, &type, size);
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
@@ -77,7 +77,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
switch (opt) {
case 't':
oi.type_name = &sb;
- if (sha1_object_info_extended(oid.hash, &oi, flags) < 0)
+ if (oid_object_info_extended(&oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
if (sb.len) {
printf("%s\n", sb.buf);
@@ -88,7 +88,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
case 's':
oi.sizep = &size;
- if (sha1_object_info_extended(oid.hash, &oi, flags) < 0)
+ if (oid_object_info_extended(&oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
printf("%lu\n", size);
return 0;
@@ -116,7 +116,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
/* else fallthrough */
case 'p':
- type = sha1_object_info(oid.hash, NULL);
+ type = oid_object_info(&oid, NULL);
if (type < 0)
die("Not a valid object name %s", obj_name);
@@ -130,7 +130,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
if (type == OBJ_BLOB)
return stream_blob_to_fd(1, &oid, NULL, 0);
- buf = read_sha1_file(oid.hash, &type, &size);
+ buf = read_object_file(&oid, &type, &size);
if (!buf)
die("Cannot read object %s", obj_name);
@@ -140,8 +140,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
case 0:
if (type_from_string(exp_type) == OBJ_BLOB) {
struct object_id blob_oid;
- if (sha1_object_info(oid.hash, NULL) == OBJ_TAG) {
- char *buffer = read_sha1_file(oid.hash, &type, &size);
+ if (oid_object_info(&oid, NULL) == OBJ_TAG) {
+ char *buffer = read_object_file(&oid, &type,
+ &size);
const char *target;
if (!skip_prefix(buffer, "object ", &target) ||
get_oid_hex(target, &blob_oid))
@@ -150,7 +151,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
} else
oidcpy(&blob_oid, &oid);
- if (sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)
+ if (oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
return stream_blob_to_fd(1, &blob_oid, NULL, 0);
/*
* we attempted to dereference a tag to a blob
@@ -159,7 +160,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
* fall-back to the usual case.
*/
}
- buf = read_object_with_reference(oid.hash, exp_type, &size, NULL);
+ buf = read_object_with_reference(&oid, exp_type, &size, NULL);
break;
default:
@@ -304,8 +305,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
enum object_type type;
if (!textconv_object(data->rest, 0100644, oid,
1, &contents, &size))
- contents = read_sha1_file(oid->hash, &type,
- &size);
+ contents = read_object_file(oid,
+ &type,
+ &size);
if (!contents)
die("could not convert '%s' %s",
oid_to_hex(oid), data->rest);
@@ -321,7 +323,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size;
void *contents;
- contents = read_sha1_file(oid->hash, &type, &size);
+ contents = read_object_file(oid, &type, &size);
if (!contents)
die("object %s disappeared", oid_to_hex(oid));
if (type != data->type)
@@ -340,8 +342,8 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,
struct strbuf buf = STRBUF_INIT;
if (!data->skip_object_info &&
- sha1_object_info_extended(data->oid.hash, &data->info,
- OBJECT_INFO_LOOKUP_REPLACE) < 0) {
+ oid_object_info_extended(&data->oid, &data->info,
+ OBJECT_INFO_LOOKUP_REPLACE) < 0) {
printf("%s missing\n",
obj_name ? obj_name : oid_to_hex(&data->oid));
fflush(stdout);
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d76e13c..b49b582 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -66,7 +66,7 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
}
-static int update_some(const unsigned char *sha1, struct strbuf *base,
+static int update_some(const struct object_id *oid, struct strbuf *base,
const char *pathname, unsigned mode, int stage, void *context)
{
int len;
@@ -78,7 +78,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,
len = base->len + strlen(pathname);
ce = xcalloc(1, cache_entry_size(len));
- hashcpy(ce->oid.hash, sha1);
+ oidcpy(&ce->oid, oid);
memcpy(ce->name, base->buf, base->len);
memcpy(ce->name + base->len, pathname, len - base->len);
ce->ce_flags = create_ce_flags(0) | CE_UPDATE;
@@ -405,10 +405,10 @@ static void describe_detached_head(const char *msg, struct commit *commit)
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
if (print_sha1_ellipsis()) {
fprintf(stderr, "%s %s... %s\n", msg,
- find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
+ find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf);
} else {
fprintf(stderr, "%s %s %s\n", msg,
- find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
+ find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf);
}
strbuf_release(&sb);
}
@@ -720,7 +720,7 @@ static int add_pending_uninteresting_ref(const char *refname,
static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
{
strbuf_addstr(sb, " ");
- strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);
+ strbuf_add_unique_abbrev(sb, &commit->object.oid, DEFAULT_ABBREV);
strbuf_addch(sb, ' ');
if (!parse_commit(commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
@@ -778,7 +778,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
" git branch <new-branch-name> %s\n\n",
/* Give ngettext() the count */
lost),
- find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
+ find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
}
/*
diff --git a/builtin/clone.c b/builtin/clone.c
index 101c27a..7df5932 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -27,6 +27,7 @@
#include "connected.h"
#include "packfile.h"
#include "list-objects-filter-options.h"
+#include "object-store.h"
/*
* Overall FIXMEs:
@@ -1217,7 +1218,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
transport_disconnect(transport);
if (option_dissociate) {
- close_all_packs();
+ close_all_packs(the_repository->objects);
dissociate_from_references();
}
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index e5bdf57..ecf4219 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -58,7 +58,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
usage(commit_tree_usage);
if (get_oid_commit(argv[i], &oid))
die("Not a valid object name %s", argv[i]);
- assert_sha1_type(oid.hash, OBJ_COMMIT);
+ assert_oid_type(&oid, OBJ_COMMIT);
new_parent(lookup_commit(&oid), &parents);
continue;
}
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index 3334381..b054713 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -7,10 +7,12 @@
#include "cache.h"
#include "config.h"
#include "dir.h"
+#include "repository.h"
#include "builtin.h"
#include "parse-options.h"
#include "quote.h"
#include "packfile.h"
+#include "object-store.h"
static unsigned long garbage;
static off_t size_garbage;
@@ -120,9 +122,8 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
struct strbuf loose_buf = STRBUF_INIT;
struct strbuf pack_buf = STRBUF_INIT;
struct strbuf garbage_buf = STRBUF_INIT;
- if (!packed_git)
- prepare_packed_git();
- for (p = packed_git; p; p = p->next) {
+
+ for (p = get_packed_git(the_repository); p; p = p->next) {
if (!p->pack_local)
continue;
if (open_pack_index(p))
diff --git a/builtin/describe.c b/builtin/describe.c
index e4869df..de840f9 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -285,7 +285,7 @@ static void append_name(struct commit_name *n, struct strbuf *dst)
static void append_suffix(int depth, const struct object_id *oid, struct strbuf *dst)
{
- strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
+ strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid, abbrev));
}
static void describe_commit(struct object_id *oid, struct strbuf *dst)
@@ -383,7 +383,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
if (!match_cnt) {
struct object_id *cmit_oid = &cmit->object.oid;
if (always) {
- strbuf_add_unique_abbrev(dst, cmit_oid->hash, abbrev);
+ strbuf_add_unique_abbrev(dst, cmit_oid, abbrev);
if (suffix)
strbuf_addstr(dst, suffix);
return;
@@ -502,7 +502,7 @@ static void describe(const char *arg, int last_one)
if (cmit)
describe_commit(&oid, &sb);
- else if (sha1_object_info(oid.hash, NULL) == OBJ_BLOB)
+ else if (oid_object_info(&oid, NULL) == OBJ_BLOB)
describe_blob(oid, &sb);
else
die(_("%s is neither a commit nor blob"), arg);
diff --git a/builtin/difftool.c b/builtin/difftool.c
index bcc79d1..ee8dce0 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -306,7 +306,7 @@ static char *get_symlink(const struct object_id *oid, const char *path)
} else {
enum object_type type;
unsigned long size;
- data = read_sha1_file(oid->hash, &type, &size);
+ data = read_object_file(oid, &type, &size);
if (!data)
die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path);
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 27b2cc1..a15898d 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -237,10 +237,10 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(oid);
eaten = 0;
} else {
- buf = read_sha1_file(oid->hash, &type, &size);
+ buf = read_object_file(oid, &type, &size);
if (!buf)
die ("Could not read blob %s", oid_to_hex(oid));
- if (check_sha1_signature(oid->hash, buf, size, type_name(type)) < 0)
+ if (check_object_signature(oid, buf, size, type_name(type)) < 0)
die("sha1 mismatch in blob %s", oid_to_hex(oid));
object = parse_object_buffer(oid, type, size, buf, &eaten);
}
@@ -682,7 +682,7 @@ static void handle_tag(const char *name, struct tag *tag)
return;
}
- buf = read_sha1_file(tag->object.oid.hash, &type, &size);
+ buf = read_object_file(&tag->object.oid, &type, &size);
if (!buf)
die ("Could not read tag %s", oid_to_hex(&tag->object.oid));
message = memmem(buf, size, "\n\n", 2);
@@ -947,7 +947,7 @@ static void import_marks(char *input_file)
if (last_idnum < mark)
last_idnum = mark;
- type = sha1_object_info(oid.hash, NULL);
+ type = oid_object_info(&oid, NULL);
if (type < 0)
die("object not found: %s", oid_to_hex(&oid));
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 6d73656..dcdfc66 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -637,7 +637,7 @@ static int update_local_ref(struct ref *ref,
struct branch *current_branch = branch_get(NULL);
const char *pretty_ref = prettify_refname(ref->name);
- type = sha1_object_info(ref->new_oid.hash, NULL);
+ type = oid_object_info(&ref->new_oid, NULL);
if (type < 0)
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
@@ -708,9 +708,9 @@ static int update_local_ref(struct ref *ref,
if (in_merge_bases(current, updated)) {
struct strbuf quickref = STRBUF_INIT;
int r;
- strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV);
+ strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
strbuf_addstr(&quickref, "..");
- strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
+ strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(&ref->new_oid);
@@ -723,9 +723,9 @@ static int update_local_ref(struct ref *ref,
} else if (force || ref->force) {
struct strbuf quickref = STRBUF_INIT;
int r;
- strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV);
+ strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
strbuf_addstr(&quickref, "...");
- strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
+ strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(&ref->new_oid);
@@ -1516,7 +1516,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
string_list_clear(&list, 0);
- close_all_packs();
+ close_all_packs(the_repository->objects);
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
if (verbosity < 0)
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 8e8a15e..bd680be 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -485,10 +485,10 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
struct strbuf tagbuf = STRBUF_INIT;
for (i = 0; i < origins.nr; i++) {
- unsigned char *sha1 = origins.items[i].util;
+ struct object_id *oid = origins.items[i].util;
enum object_type type;
unsigned long size, len;
- char *buf = read_sha1_file(sha1, &type, &size);
+ char *buf = read_object_file(oid, &type, &size);
struct strbuf sig = STRBUF_INIT;
if (!buf || type != OBJ_TAG)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index ef78c6c..087360a 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "repository.h"
#include "config.h"
#include "commit.h"
#include "tree.h"
@@ -16,6 +17,7 @@
#include "streaming.h"
#include "decorate.h"
#include "packfile.h"
+#include "object-store.h"
#define REACHABLE 0x0001
#define SEEN 0x0002
@@ -65,7 +67,7 @@ static const char *printable_type(struct object *obj)
const char *ret;
if (obj->type == OBJ_NONE) {
- enum object_type type = sha1_object_info(obj->oid.hash, NULL);
+ enum object_type type = oid_object_info(&obj->oid, NULL);
if (type > 0)
object_as_type(obj, type, 0);
}
@@ -513,7 +515,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
unsigned long size;
int eaten;
- if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)
+ if (read_loose_object(path, oid, &type, &size, &contents) < 0)
return NULL;
if (!contents && type != OBJ_BLOB)
@@ -719,9 +721,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
for_each_packed_object(mark_packed_for_connectivity, NULL, 0);
} else {
+ struct alternate_object_database *alt_odb_list;
+
fsck_object_dir(get_object_directory());
- prepare_alt_odb();
+ prepare_alt_odb(the_repository);
+ alt_odb_list = the_repository->objects->alt_odb_list;
for (alt = alt_odb_list; alt; alt = alt->next)
fsck_object_dir(alt->path);
@@ -730,10 +735,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
uint32_t total = 0, count = 0;
struct progress *progress = NULL;
- prepare_packed_git();
-
if (show_progress) {
- for (p = packed_git; p; p = p->next) {
+ for (p = get_packed_git(the_repository); p;
+ p = p->next) {
if (open_pack_index(p))
continue;
total += p->num_objects;
@@ -741,7 +745,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
progress = start_progress(_("Checking objects"), total);
}
- for (p = packed_git; p; p = p->next) {
+ for (p = get_packed_git(the_repository); p;
+ p = p->next) {
/* verify gives error messages itself */
if (verify_pack(p, fsck_obj_buffer,
progress, count))
diff --git a/builtin/gc.c b/builtin/gc.c
index f51e5a6..3e67124 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -11,6 +11,7 @@
*/
#include "builtin.h"
+#include "repository.h"
#include "config.h"
#include "tempfile.h"
#include "lockfile.h"
@@ -20,6 +21,7 @@
#include "argv-array.h"
#include "commit.h"
#include "packfile.h"
+#include "object-store.h"
#define FAILED_RUN "failed to run %s"
@@ -172,8 +174,7 @@ static int too_many_packs(void)
if (gc_auto_pack_limit <= 0)
return 0;
- prepare_packed_git();
- for (cnt = 0, p = packed_git; p; p = p->next) {
+ for (cnt = 0, p = get_packed_git(the_repository); p; p = p->next) {
if (!p->pack_local)
continue;
if (p->pack_keep)
@@ -479,7 +480,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
return error(FAILED_RUN, rerere.argv[0]);
report_garbage = report_pack_garbage;
- reprepare_packed_git();
+ reprepare_packed_git(the_repository);
if (pack_garbage.nr > 0)
clean_pack_garbage();
diff --git a/builtin/grep.c b/builtin/grep.c
index 789a891..5f32d2c 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -22,6 +22,7 @@
#include "pathspec.h"
#include "submodule.h"
#include "submodule-config.h"
+#include "object-store.h"
static char const * const grep_usage[] = {
N_("git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]"),
@@ -306,7 +307,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ
void *data;
grep_read_lock();
- data = read_sha1_file(oid->hash, type, size);
+ data = read_object_file(oid, type, size);
grep_read_unlock();
return data;
}
@@ -439,7 +440,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
* object.
*/
grep_read_lock();
- add_to_alternates_memory(submodule.objectdir);
+ add_to_alternates_memory(submodule.objects->objectdir);
grep_read_unlock();
if (oid) {
@@ -452,7 +453,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
object = parse_object_or_die(oid, oid_to_hex(oid));
grep_read_lock();
- data = read_object_with_reference(object->oid.hash, tree_type,
+ data = read_object_with_reference(&object->oid, tree_type,
&size, NULL);
grep_read_unlock();
@@ -614,7 +615,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
int hit, len;
grep_read_lock();
- data = read_object_with_reference(obj->oid.hash, tree_type,
+ data = read_object_with_reference(&obj->oid, tree_type,
&size, NULL);
grep_read_unlock();
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index bda84a9..d81473e 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -13,6 +13,7 @@
#include "streaming.h"
#include "thread-utils.h"
#include "packfile.h"
+#include "object-store.h"
static const char index_pack_usage[] =
"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])";
@@ -59,7 +60,7 @@ struct ofs_delta_entry {
};
struct ref_delta_entry {
- unsigned char sha1[20];
+ struct object_id oid;
int obj_no;
};
@@ -222,7 +223,7 @@ static unsigned check_object(struct object *obj)
if (!(obj->flags & FLAG_CHECKED)) {
unsigned long size;
- int type = sha1_object_info(obj->oid.hash, &size);
+ int type = oid_object_info(&obj->oid, &size);
if (type <= 0)
die(_("did not receive expected object %s"),
oid_to_hex(&obj->oid));
@@ -672,18 +673,18 @@ static void find_ofs_delta_children(off_t offset,
*last_index = last;
}
-static int compare_ref_delta_bases(const unsigned char *sha1,
- const unsigned char *sha2,
+static int compare_ref_delta_bases(const struct object_id *oid1,
+ const struct object_id *oid2,
enum object_type type1,
enum object_type type2)
{
int cmp = type1 - type2;
if (cmp)
return cmp;
- return hashcmp(sha1, sha2);
+ return oidcmp(oid1, oid2);
}
-static int find_ref_delta(const unsigned char *sha1, enum object_type type)
+static int find_ref_delta(const struct object_id *oid, enum object_type type)
{
int first = 0, last = nr_ref_deltas;
@@ -692,7 +693,7 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
struct ref_delta_entry *delta = &ref_deltas[next];
int cmp;
- cmp = compare_ref_delta_bases(sha1, delta->sha1,
+ cmp = compare_ref_delta_bases(oid, &delta->oid,
type, objects[delta->obj_no].type);
if (!cmp)
return next;
@@ -705,11 +706,11 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type)
return -first-1;
}
-static void find_ref_delta_children(const unsigned char *sha1,
+static void find_ref_delta_children(const struct object_id *oid,
int *first_index, int *last_index,
enum object_type type)
{
- int first = find_ref_delta(sha1, type);
+ int first = find_ref_delta(oid, type);
int last = first;
int end = nr_ref_deltas - 1;
@@ -718,9 +719,9 @@ static void find_ref_delta_children(const unsigned char *sha1,
*last_index = -1;
return;
}
- while (first > 0 && !hashcmp(ref_deltas[first - 1].sha1, sha1))
+ while (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid))
--first;
- while (last < end && !hashcmp(ref_deltas[last + 1].sha1, sha1))
+ while (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid))
++last;
*first_index = first;
*last_index = last;
@@ -772,7 +773,7 @@ static int check_collison(struct object_entry *entry)
memset(&data, 0, sizeof(data));
data.entry = entry;
- data.st = open_istream(entry->idx.oid.hash, &type, &size, NULL);
+ data.st = open_istream(&entry->idx.oid, &type, &size, NULL);
if (!data.st)
return -1;
if (size != entry->size || type != entry->type)
@@ -811,12 +812,12 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
enum object_type has_type;
unsigned long has_size;
read_lock();
- has_type = sha1_object_info(oid->hash, &has_size);
+ has_type = oid_object_info(oid, &has_size);
if (has_type < 0)
die(_("cannot read existing object info %s"), oid_to_hex(oid));
if (has_type != type || has_size != size)
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
- has_data = read_sha1_file(oid->hash, &has_type, &has_size);
+ has_data = read_object_file(oid, &has_type, &has_size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
@@ -992,7 +993,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base,
struct base_data *prev_base)
{
if (base->ref_last == -1 && base->ofs_last == -1) {
- find_ref_delta_children(base->obj->idx.oid.hash,
+ find_ref_delta_children(&base->obj->idx.oid,
&base->ref_first, &base->ref_last,
OBJ_REF_DELTA);
@@ -1076,7 +1077,7 @@ static int compare_ref_delta_entry(const void *a, const void *b)
const struct ref_delta_entry *delta_a = a;
const struct ref_delta_entry *delta_b = b;
- return hashcmp(delta_a->sha1, delta_b->sha1);
+ return oidcmp(&delta_a->oid, &delta_b->oid);
}
static void resolve_base(struct object_entry *obj)
@@ -1142,7 +1143,7 @@ static void parse_pack_objects(unsigned char *hash)
ofs_delta++;
} else if (obj->type == OBJ_REF_DELTA) {
ALLOC_GROW(ref_deltas, nr_ref_deltas + 1, ref_deltas_alloc);
- hashcpy(ref_deltas[nr_ref_deltas].sha1, ref_delta_oid.hash);
+ oidcpy(&ref_deltas[nr_ref_deltas].oid, &ref_delta_oid);
ref_deltas[nr_ref_deltas].obj_no = i;
nr_ref_deltas++;
} else if (!data) {
@@ -1374,14 +1375,15 @@ static void fix_unresolved_deltas(struct hashfile *f)
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
- base_obj->data = read_sha1_file(d->sha1, &type, &base_obj->size);
+ base_obj->data = read_object_file(&d->oid, &type,
+ &base_obj->size);
if (!base_obj->data)
continue;
- if (check_sha1_signature(d->sha1, base_obj->data,
+ if (check_object_signature(&d->oid, base_obj->data,
base_obj->size, type_name(type)))
- die(_("local object %s is corrupt"), sha1_to_hex(d->sha1));
- base_obj->obj = append_obj_to_pack(f, d->sha1,
+ die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
+ base_obj->obj = append_obj_to_pack(f, d->oid.hash,
base_obj->data, base_obj->size, type);
find_unresolved_deltas(base_obj);
display_progress(progress, nr_resolved_deltas);
diff --git a/builtin/log.c b/builtin/log.c
index 94ee177..71f68a3 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -518,7 +518,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
{
unsigned long size;
enum object_type type;
- char *buf = read_sha1_file(oid->hash, &type, &size);
+ char *buf = read_object_file(oid, &type, &size);
int offset = 0;
if (!buf)
@@ -541,7 +541,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
return 0;
}
-static int show_tree_object(const unsigned char *sha1,
+static int show_tree_object(const struct object_id *oid,
struct strbuf *base,
const char *pathname, unsigned mode, int stage, void *context)
{
@@ -1873,12 +1873,12 @@ static void print_commit(char sign, struct commit *commit, int verbose,
{
if (!verbose) {
fprintf(file, "%c %s\n", sign,
- find_unique_abbrev(commit->object.oid.hash, abbrev));
+ find_unique_abbrev(&commit->object.oid, abbrev));
} else {
struct strbuf buf = STRBUF_INIT;
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
fprintf(file, "%c %s %s\n", sign,
- find_unique_abbrev(commit->object.oid.hash, abbrev),
+ find_unique_abbrev(&commit->object.oid, abbrev),
buf.buf);
strbuf_release(&buf);
}
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 2fc836e..a71f6bd 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -240,7 +240,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
printf("%s%06o %s %d\t",
tag,
ce->ce_mode,
- find_unique_abbrev(ce->oid.hash, abbrev),
+ find_unique_abbrev(&ce->oid, abbrev),
ce_stage(ce));
}
write_eolinfo(repo->index, ce, fullname);
@@ -271,7 +271,7 @@ static void show_ru_info(const struct index_state *istate)
if (!ui->mode[i])
continue;
printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
- find_unique_abbrev(ui->sha1[i], abbrev),
+ find_unique_abbrev(&ui->oid[i], abbrev),
i + 1);
write_name(path);
}
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index ef96540..d44b4f9 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -60,7 +60,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
return 0;
}
-static int show_tree(const unsigned char *sha1, struct strbuf *base,
+static int show_tree(const struct object_id *oid, struct strbuf *base,
const char *pathname, unsigned mode, int stage, void *context)
{
int retval = 0;
@@ -94,7 +94,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
char size_text[24];
if (!strcmp(type, blob_type)) {
unsigned long size;
- if (sha1_object_info(sha1, &size) == OBJ_BAD)
+ if (oid_object_info(oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text),
"BAD");
else
@@ -103,11 +103,11 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
} else
xsnprintf(size_text, sizeof(size_text), "-");
printf("%06o %s %s %7s\t", mode, type,
- find_unique_abbrev(sha1, abbrev),
+ find_unique_abbrev(oid, abbrev),
size_text);
} else
printf("%06o %s %s\t", mode, type,
- find_unique_abbrev(sha1, abbrev));
+ find_unique_abbrev(oid, abbrev));
}
baselen = base->len;
strbuf_addstr(base, pathname);
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index d01ddec..32736e0 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -60,7 +60,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path;
if (!entry->stage)
- return read_sha1_file(entry->blob->object.oid.hash, &type, size);
+ return read_object_file(&entry->blob->object.oid, &type, size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
@@ -82,7 +82,8 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type;
while (entry) {
if (entry->stage == 2)
- return read_sha1_file(entry->blob->object.oid.hash, &type, size);
+ return read_object_file(&entry->blob->object.oid,
+ &type, size);
entry = entry->link;
}
return NULL;
diff --git a/builtin/merge.c b/builtin/merge.c
index ee050a4..9db5a2c 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -412,7 +412,7 @@ static void finish(struct commit *head_commit,
* We ignore errors in 'gc --auto', since the
* user should see them.
*/
- close_all_packs();
+ close_all_packs(the_repository->objects);
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
}
}
@@ -639,7 +639,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
static void write_tree_trivial(struct object_id *oid)
{
- if (write_cache_as_tree(oid->hash, 0, NULL))
+ if (write_cache_as_tree(oid, 0, NULL))
die(_("git write-tree failed to write a tree"));
}
@@ -1324,7 +1324,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
check_commit_signature(commit, &signature_check);
- find_unique_abbrev_r(hex, commit->object.oid.hash, DEFAULT_ABBREV);
+ find_unique_abbrev_r(hex, &commit->object.oid, DEFAULT_ABBREV);
switch (signature_check.result) {
case 'G':
break;
@@ -1417,9 +1417,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (verbosity >= 0) {
printf(_("Updating %s..%s\n"),
- find_unique_abbrev(head_commit->object.oid.hash,
+ find_unique_abbrev(&head_commit->object.oid,
DEFAULT_ABBREV),
- find_unique_abbrev(remoteheads->item->object.oid.hash,
+ find_unique_abbrev(&remoteheads->item->object.oid,
DEFAULT_ABBREV));
}
strbuf_addstr(&msg, "Fast-forward");
diff --git a/builtin/mktag.c b/builtin/mktag.c
index beb5528..9f5a50a 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -18,17 +18,17 @@
/*
* We refuse to tag something we can't verify. Just because.
*/
-static int verify_object(const unsigned char *sha1, const char *expected_type)
+static int verify_object(const struct object_id *oid, const char *expected_type)
{
int ret = -1;
enum object_type type;
unsigned long size;
- void *buffer = read_sha1_file(sha1, &type, &size);
- const unsigned char *repl = lookup_replace_object(sha1);
+ void *buffer = read_object_file(oid, &type, &size);
+ const struct object_id *repl = lookup_replace_object(oid);
if (buffer) {
if (type == type_from_string(expected_type))
- ret = check_sha1_signature(repl, buffer, size, expected_type);
+ ret = check_object_signature(repl, buffer, size, expected_type);
free(buffer);
}
return ret;
@@ -38,8 +38,8 @@ static int verify_tag(char *buffer, unsigned long size)
{
int typelen;
char type[20];
- unsigned char sha1[20];
- const char *object, *type_line, *tag_line, *tagger_line, *lb, *rb;
+ struct object_id oid;
+ const char *object, *type_line, *tag_line, *tagger_line, *lb, *rb, *p;
size_t len;
if (size < 84)
@@ -52,11 +52,11 @@ static int verify_tag(char *buffer, unsigned long size)
if (memcmp(object, "object ", 7))
return error("char%d: does not start with \"object \"", 0);
- if (get_sha1_hex(object + 7, sha1))
+ if (parse_oid_hex(object + 7, &oid, &p))
return error("char%d: could not get SHA1 hash", 7);
/* Verify type line */
- type_line = object + 48;
+ type_line = p + 1;
if (memcmp(type_line - 1, "\ntype ", 6))
return error("char%d: could not find \"\\ntype \"", 47);
@@ -80,8 +80,8 @@ static int verify_tag(char *buffer, unsigned long size)
type[typelen] = 0;
/* Verify that the object matches */
- if (verify_object(sha1, type))
- return error("char%d: could not verify object %s", 7, sha1_to_hex(sha1));
+ if (verify_object(&oid, type))
+ return error("char%d: could not verify object %s", 7, oid_to_hex(&oid));
/* Verify the tag-name: we don't allow control characters or spaces in it */
tag_line += 4;
diff --git a/builtin/mktree.c b/builtin/mktree.c
index f5f3c0e..263c530 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -10,13 +10,13 @@
static struct treeent {
unsigned mode;
- unsigned char sha1[20];
+ struct object_id oid;
int len;
char name[FLEX_ARRAY];
} **entries;
static int alloc, used;
-static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
+static void append_to_tree(unsigned mode, struct object_id *oid, char *path)
{
struct treeent *ent;
size_t len = strlen(path);
@@ -26,7 +26,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
FLEX_ALLOC_MEM(ent, name, path, len);
ent->mode = mode;
ent->len = len;
- hashcpy(ent->sha1, sha1);
+ oidcpy(&ent->oid, oid);
ALLOC_GROW(entries, used + 1, alloc);
entries[used++] = ent;
@@ -54,7 +54,7 @@ static void write_tree(struct object_id *oid)
for (i = 0; i < used; i++) {
struct treeent *ent = entries[i];
strbuf_addf(&buf, "%o %s%c", ent->mode, ent->name, '\0');
- strbuf_add(&buf, ent->sha1, 20);
+ strbuf_add(&buf, ent->oid.hash, the_hash_algo->rawsz);
}
write_object_file(buf.buf, buf.len, tree_type, oid);
@@ -69,11 +69,12 @@ static const char *mktree_usage[] = {
static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_missing)
{
char *ptr, *ntr;
+ const char *p;
unsigned mode;
enum object_type mode_type; /* object type derived from mode */
enum object_type obj_type; /* object type derived from sha */
char *path, *to_free = NULL;
- unsigned char sha1[20];
+ struct object_id oid;
ptr = buf;
/*
@@ -85,9 +86,8 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
die("input format error: %s", buf);
ptr = ntr + 1; /* type */
ntr = strchr(ptr, ' ');
- if (!ntr || buf + len <= ntr + 40 ||
- ntr[41] != '\t' ||
- get_sha1_hex(ntr + 1, sha1))
+ if (!ntr || parse_oid_hex(ntr + 1, &oid, &p) ||
+ *p != '\t')
die("input format error: %s", buf);
/* It is perfectly normal if we do not have a commit from a submodule */
@@ -116,12 +116,12 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
}
/* Check the type of object identified by sha1 */
- obj_type = sha1_object_info(sha1, NULL);
+ obj_type = oid_object_info(&oid, NULL);
if (obj_type < 0) {
if (allow_missing) {
; /* no problem - missing objects are presumed to be of the right type */
} else {
- die("entry '%s' object %s is unavailable", path, sha1_to_hex(sha1));
+ die("entry '%s' object %s is unavailable", path, oid_to_hex(&oid));
}
} else {
if (obj_type != mode_type) {
@@ -131,11 +131,11 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
* because the new tree entry will never be correct.
*/
die("entry '%s' object %s is a %s but specified type was (%s)",
- path, sha1_to_hex(sha1), type_name(obj_type), type_name(mode_type));
+ path, oid_to_hex(&oid), type_name(obj_type), type_name(mode_type));
}
}
- append_to_tree(mode, sha1, path);
+ append_to_tree(mode, &oid, path);
free(to_free);
}
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 9e088eb..387ddf8 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -328,7 +328,7 @@ static void show_name(const struct object *obj,
else if (allow_undefined)
printf("undefined\n");
else if (always)
- printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
+ printf("%s\n", find_unique_abbrev(oid, DEFAULT_ABBREV));
else
die("cannot describe '%s'", oid_to_hex(oid));
strbuf_release(&buf);
diff --git a/builtin/notes.c b/builtin/notes.c
index 6d2fda4..921e08d 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -118,11 +118,11 @@ static int list_each_note(const struct object_id *object_oid,
return 0;
}
-static void copy_obj_to_fd(int fd, const unsigned char *sha1)
+static void copy_obj_to_fd(int fd, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
- char *buf = read_sha1_file(sha1, &type, &size);
+ char *buf = read_object_file(oid, &type, &size);
if (buf) {
if (size)
write_or_die(fd, buf, size);
@@ -162,7 +162,7 @@ static void write_commented_object(int fd, const struct object_id *object)
}
static void prepare_note_data(const struct object_id *object, struct note_data *d,
- const unsigned char *old_note)
+ const struct object_id *old_note)
{
if (d->use_editor || !d->given) {
int fd;
@@ -253,7 +253,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
if (get_oid(arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
- if (!(buf = read_sha1_file(object.hash, &type, &len))) {
+ if (!(buf = read_object_file(&object, &type, &len))) {
free(buf);
die(_("failed to read object '%s'."), arg);
}
@@ -457,7 +457,7 @@ static int add(int argc, const char **argv, const char *prefix)
oid_to_hex(&object));
}
- prepare_note_data(&object, &d, note ? note->hash : NULL);
+ prepare_note_data(&object, &d, note);
if (d.buf.len || allow_empty) {
write_note_data(&d, &new_note);
if (add_note(t, &object, &new_note, combine_notes_overwrite))
@@ -602,13 +602,13 @@ static int append_edit(int argc, const char **argv, const char *prefix)
t = init_notes_check(argv[0], NOTES_INIT_WRITABLE);
note = get_note(t, &object);
- prepare_note_data(&object, &d, edit && note ? note->hash : NULL);
+ prepare_note_data(&object, &d, edit && note ? note : NULL);
if (note && !edit) {
/* Append buf to previous note contents */
unsigned long size;
enum object_type type;
- char *prev_buf = read_sha1_file(note->hash, &type, &size);
+ char *prev_buf = read_object_file(note, &type, &size);
strbuf_grow(&d.buf, size + 1);
if (d.buf.len && prev_buf && size)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index e9d3cfb..4bdae5a 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
#include "builtin.h"
#include "cache.h"
+#include "repository.h"
#include "config.h"
#include "attr.h"
#include "object.h"
@@ -28,6 +29,7 @@
#include "argv-array.h"
#include "list.h"
#include "packfile.h"
+#include "object-store.h"
static const char *pack_usage[] = {
N_("git pack-objects --stdout [<options>...] [< <ref-list> | < <object-list>]"),
@@ -122,11 +124,10 @@ static void *get_delta(struct object_entry *entry)
void *buf, *base_buf, *delta_buf;
enum object_type type;
- buf = read_sha1_file(entry->idx.oid.hash, &type, &size);
+ buf = read_object_file(&entry->idx.oid, &type, &size);
if (!buf)
die("unable to read %s", oid_to_hex(&entry->idx.oid));
- base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type,
- &base_size);
+ base_buf = read_object_file(&entry->delta->idx.oid, &type, &base_size);
if (!base_buf)
die("unable to read %s",
oid_to_hex(&entry->delta->idx.oid));
@@ -267,11 +268,10 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
if (!usable_delta) {
if (entry->type == OBJ_BLOB &&
entry->size > big_file_threshold &&
- (st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL)
+ (st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL)
buf = NULL;
else {
- buf = read_sha1_file(entry->idx.oid.hash, &type,
- &size);
+ buf = read_object_file(&entry->idx.oid, &type, &size);
if (!buf)
die(_("unable to read %s"),
oid_to_hex(&entry->idx.oid));
@@ -1025,8 +1025,7 @@ static int want_object_in_pack(const struct object_id *oid,
if (want != -1)
return want;
}
-
- list_for_each(pos, &packed_git_mru) {
+ list_for_each(pos, get_packed_git_mru(the_repository)) {
struct packed_git *p = list_entry(pos, struct packed_git, mru);
off_t offset;
@@ -1044,7 +1043,8 @@ static int want_object_in_pack(const struct object_id *oid,
}
want = want_found_object(exclude, p);
if (!exclude && want > 0)
- list_move(&p->mru, &packed_git_mru);
+ list_move(&p->mru,
+ get_packed_git_mru(the_repository));
if (want != -1)
return want;
}
@@ -1190,7 +1190,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
/* Did not find one. Either we got a bogus request or
* we need to read and perhaps cache.
*/
- data = read_sha1_file(oid->hash, &type, &size);
+ data = read_object_file(oid, &type, &size);
if (!data)
return NULL;
if (type != OBJ_TREE) {
@@ -1351,7 +1351,7 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++)
return;
- data = read_object_with_reference(oid->hash, tree_type, &size, tree_oid.hash);
+ data = read_object_with_reference(oid, tree_type, &size, &tree_oid);
if (!data)
return;
@@ -1516,7 +1516,7 @@ static void check_object(struct object_entry *entry)
unuse_pack(&w_curs);
}
- entry->type = sha1_object_info(entry->idx.oid.hash, &entry->size);
+ entry->type = oid_object_info(&entry->idx.oid, &entry->size);
/*
* The error condition is checked in prepare_pack(). This is
* to permit a missing preferred base object to be ignored
@@ -1578,8 +1578,7 @@ static void drop_reused_delta(struct object_entry *entry)
* And if that fails, the error will be recorded in entry->type
* and dealt with in prepare_pack().
*/
- entry->type = sha1_object_info(entry->idx.oid.hash,
- &entry->size);
+ entry->type = oid_object_info(&entry->idx.oid, &entry->size);
}
}
@@ -1871,8 +1870,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
/* Load data if not already done */
if (!trg->data) {
read_lock();
- trg->data = read_sha1_file(trg_entry->idx.oid.hash, &type,
- &sz);
+ trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz);
read_unlock();
if (!trg->data)
die("object %s cannot be read",
@@ -1885,8 +1883,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
}
if (!src->data) {
read_lock();
- src->data = read_sha1_file(src_entry->idx.oid.hash, &type,
- &sz);
+ src->data = read_object_file(&src_entry->idx.oid, &type, &sz);
read_unlock();
if (!src->data) {
if (src_entry->preferred_base) {
@@ -2674,7 +2671,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
memset(&in_pack, 0, sizeof(in_pack));
- for (p = packed_git; p; p = p->next) {
+ for (p = get_packed_git(the_repository); p; p = p->next) {
struct object_id oid;
struct object *o;
@@ -2709,7 +2706,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
static int add_loose_object(const struct object_id *oid, const char *path,
void *data)
{
- enum object_type type = sha1_object_info(oid->hash, NULL);
+ enum object_type type = oid_object_info(oid, NULL);
if (type < 0) {
warning("loose object at %s could not be examined", path);
@@ -2737,7 +2734,8 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
static struct packed_git *last_found = (void *)1;
struct packed_git *p;
- p = (last_found != (void *)1) ? last_found : packed_git;
+ p = (last_found != (void *)1) ? last_found :
+ get_packed_git(the_repository);
while (p) {
if ((!p->pack_local || p->pack_keep) &&
@@ -2746,7 +2744,7 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
return 1;
}
if (p == last_found)
- p = packed_git;
+ p = get_packed_git(the_repository);
else
p = p->next;
if (p == last_found)
@@ -2782,7 +2780,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
uint32_t i;
struct object_id oid;
- for (p = packed_git; p; p = p->next) {
+ for (p = get_packed_git(the_repository); p; p = p->next) {
if (!p->pack_local || p->pack_keep)
continue;
@@ -3150,10 +3148,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (progress && all_progress_implied)
progress = 2;
- prepare_packed_git();
if (ignore_packed_keep) {
struct packed_git *p;
- for (p = packed_git; p; p = p->next)
+ for (p = get_packed_git(the_repository); p; p = p->next)
if (p->pack_local && p->pack_keep)
break;
if (!p) /* no keep-able packs found */
@@ -3166,7 +3163,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
* also covers non-local objects
*/
struct packed_git *p;
- for (p = packed_git; p; p = p->next) {
+ for (p = get_packed_git(the_repository); p; p = p->next) {
if (!p->pack_local) {
have_non_local_packs = 1;
break;
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 991e1bb..354478a 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -7,7 +7,9 @@
*/
#include "builtin.h"
+#include "repository.h"
#include "packfile.h"
+#include "object-store.h"
#define BLKSIZE 512
@@ -571,7 +573,7 @@ static struct pack_list * add_pack(struct packed_git *p)
static struct pack_list * add_pack_file(const char *filename)
{
- struct packed_git *p = packed_git;
+ struct packed_git *p = get_packed_git(the_repository);
if (strlen(filename) < 40)
die("Bad pack filename: %s", filename);
@@ -586,7 +588,7 @@ static struct pack_list * add_pack_file(const char *filename)
static void load_all(void)
{
- struct packed_git *p = packed_git;
+ struct packed_git *p = get_packed_git(the_repository);
while (p) {
add_pack(p);
@@ -629,8 +631,6 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
break;
}
- prepare_packed_git();
-
if (load_all_packs)
load_all();
else
diff --git a/builtin/prune.c b/builtin/prune.c
index 4394d01..38ced18 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -50,7 +50,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
- enum object_type type = sha1_object_info(oid->hash, NULL);
+ enum object_type type = oid_object_info(oid, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown");
}
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 75e7f18..c4272fb 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1,4 +1,5 @@
#include "builtin.h"
+#include "repository.h"
#include "config.h"
#include "lockfile.h"
#include "pack.h"
@@ -1242,11 +1243,11 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
" its target '%s' (%s..%s)",
cmd->ref_name,
- find_unique_abbrev(cmd->old_oid.hash, DEFAULT_ABBREV),
- find_unique_abbrev(cmd->new_oid.hash, DEFAULT_ABBREV),
+ find_unique_abbrev(&cmd->old_oid, DEFAULT_ABBREV),
+ find_unique_abbrev(&cmd->new_oid, DEFAULT_ABBREV),
dst_cmd->ref_name,
- find_unique_abbrev(dst_cmd->old_oid.hash, DEFAULT_ABBREV),
- find_unique_abbrev(dst_cmd->new_oid.hash, DEFAULT_ABBREV));
+ find_unique_abbrev(&dst_cmd->old_oid, DEFAULT_ABBREV),
+ find_unique_abbrev(&dst_cmd->new_oid, DEFAULT_ABBREV));
cmd->error_string = dst_cmd->error_string =
"inconsistent aliased update";
@@ -1778,7 +1779,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
status = finish_command(&child);
if (status)
return "index-pack abnormal exit";
- reprepare_packed_git();
+ reprepare_packed_git(the_repository);
}
return NULL;
}
@@ -2027,7 +2028,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
proc.git_cmd = 1;
proc.argv = argv_gc_auto;
- close_all_packs();
+ close_all_packs(the_repository->objects);
if (!start_command(&proc)) {
if (use_sideband)
copy_to_sideband(proc.err, -1, NULL);
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 4719a53..a89bd1d 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -75,7 +75,7 @@ static int tree_is_complete(const struct object_id *oid)
if (!tree->buffer) {
enum object_type type;
unsigned long size;
- void *data = read_sha1_file(oid->hash, &type, &size);
+ void *data = read_object_file(oid, &type, &size);
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
diff --git a/builtin/replace.c b/builtin/replace.c
index 482f120..935647b 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -53,8 +53,8 @@ static int show_reference(const char *refname, const struct object_id *oid,
if (get_oid(refname, &object))
return error("Failed to resolve '%s' as a valid ref.", refname);
- obj_type = sha1_object_info(object.hash, NULL);
- repl_type = sha1_object_info(oid->hash, NULL);
+ obj_type = oid_object_info(&object, NULL);
+ repl_type = oid_object_info(oid, NULL);
printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
oid_to_hex(oid), type_name(repl_type));
@@ -162,8 +162,8 @@ static int replace_object_oid(const char *object_ref,
struct ref_transaction *transaction;
struct strbuf err = STRBUF_INIT;
- obj_type = sha1_object_info(object->hash, NULL);
- repl_type = sha1_object_info(repl->hash, NULL);
+ obj_type = oid_object_info(object, NULL);
+ repl_type = oid_object_info(repl, NULL);
if (!force && obj_type != repl_type)
die("Objects must be of the same type.\n"
"'%s' points to a replaced object of type '%s'\n"
@@ -290,7 +290,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
if (get_oid(object_ref, &old_oid) < 0)
die("Not a valid object name: '%s'", object_ref);
- type = sha1_object_info(old_oid.hash, NULL);
+ type = oid_object_info(&old_oid, NULL);
if (type < 0)
die("unable to get object type for %s", oid_to_hex(&old_oid));
diff --git a/builtin/reset.c b/builtin/reset.c
index 5da0f75..7f1c3f0 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -109,7 +109,7 @@ static void print_new_head_line(struct commit *commit)
struct strbuf buf = STRBUF_INIT;
printf(_("HEAD is now at %s"),
- find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
+ find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
if (buf.len > 0)
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 6f5b9b0..fadd3ec 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -108,7 +108,7 @@ static void show_commit(struct commit *commit, void *data)
if (!revs->graph)
fputs(get_revision_mark(revs, commit), stdout);
if (revs->abbrev_commit && revs->abbrev)
- fputs(find_unique_abbrev(commit->object.oid.hash, revs->abbrev),
+ fputs(find_unique_abbrev(&commit->object.oid, revs->abbrev),
stdout);
else
fputs(oid_to_hex(&commit->object.oid), stdout);
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index a1e680b..36b2087 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -159,7 +159,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
}
}
else if (abbrev)
- show_with_type(type, find_unique_abbrev(oid->hash, abbrev));
+ show_with_type(type, find_unique_abbrev(oid, abbrev));
else
show_with_type(type, oid_to_hex(oid));
}
diff --git a/builtin/rm.c b/builtin/rm.c
index 4447bb4..5b6fc7e 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -178,7 +178,7 @@ static int check_local_mod(struct object_id *head, int index_only)
* way as changed from the HEAD.
*/
if (no_head
- || get_tree_entry(head->hash, name, oid.hash, &mode)
+ || get_tree_entry(head, name, &oid, &mode)
|| ce->ce_mode != create_ce_mode(mode)
|| oidcmp(&ce->oid, &oid))
staged_changes = 1;
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index e29875b..608d6ba 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -11,7 +11,8 @@
#include "parse-options.h"
static char const * const shortlog_usage[] = {
- N_("git shortlog [<options>] [<revision-range>] [[--] [<path>...]]"),
+ N_("git shortlog [<options>] [<revision-range>] [[--] <path>...]"),
+ N_("git log --pretty=short | git shortlog [<options>]"),
NULL
};
@@ -283,6 +284,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
for (;;) {
switch (parse_options_step(&ctx, options, shortlog_usage)) {
case PARSE_OPT_HELP:
+ case PARSE_OPT_ERROR:
exit(129);
case PARSE_OPT_DONE:
goto parse_done;
@@ -292,6 +294,11 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
parse_done:
argc = parse_options_end(&ctx);
+ if (nongit && argc > 1) {
+ error(_("too many arguments given outside repository"));
+ usage_with_options(shortlog_usage, options);
+ }
+
if (setup_revisions(argc, argv, &rev, NULL) != 1) {
error(_("unrecognized argument: %s"), argv[1]);
usage_with_options(shortlog_usage, options);
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index e8a4aa4..6c2148b 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -292,7 +292,7 @@ static void show_one_commit(struct commit *commit, int no_name)
}
else
printf("[%s] ",
- find_unique_abbrev(commit->object.oid.hash,
+ find_unique_abbrev(&commit->object.oid,
DEFAULT_ABBREV));
}
puts(pretty_str);
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 41e5e71..f2eb1a7 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -29,7 +29,7 @@ static void show_one(const char *refname, const struct object_id *oid)
if (quiet)
return;
- hex = find_unique_abbrev(oid->hash, abbrev);
+ hex = find_unique_abbrev(oid, abbrev);
if (hash_only)
printf("%s\n", hex);
else
@@ -39,7 +39,7 @@ static void show_one(const char *refname, const struct object_id *oid)
return;
if (!peel_ref(refname, &peeled)) {
- hex = find_unique_abbrev(peeled.hash, abbrev);
+ hex = find_unique_abbrev(&peeled, abbrev);
printf("%s %s^{}\n", hex, refname);
}
}
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6ba8587..a404df3 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -16,6 +16,7 @@
#include "revision.h"
#include "diffcore.h"
#include "diff.h"
+#include "object-store.h"
#define OPT_QUIET (1 << 0)
#define OPT_CACHED (1 << 1)
@@ -654,9 +655,13 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
displaypath);
} else if (!(flags & OPT_CACHED)) {
struct object_id oid;
+ struct ref_store *refs = get_submodule_ref_store(path);
- if (refs_head_ref(get_submodule_ref_store(path),
- handle_submodule_head_ref, &oid))
+ if (!refs) {
+ print_status(flags, '-', path, ce_oid, displaypath);
+ goto cleanup;
+ }
+ if (refs_head_ref(refs, handle_submodule_head_ref, &oid))
die(_("could not resolve HEAD ref inside the "
"submodule '%s'"), path);
diff --git a/builtin/tag.c b/builtin/tag.c
index da18669..8cff6d0 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -99,7 +99,8 @@ static int delete_tag(const char *name, const char *ref,
{
if (delete_ref(NULL, ref, oid, 0))
return 1;
- printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
+ printf(_("Deleted tag '%s' (was %s)\n"), name,
+ find_unique_abbrev(oid, DEFAULT_ABBREV));
return 0;
}
@@ -167,7 +168,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
enum object_type type;
char *buf, *sp;
- buf = read_sha1_file(oid->hash, &type, &size);
+ buf = read_object_file(oid, &type, &size);
if (!buf)
return;
/* skip header */
@@ -211,7 +212,7 @@ static void create_tag(const struct object_id *object, const char *tag,
struct strbuf header = STRBUF_INIT;
char *path = NULL;
- type = sha1_object_info(object->hash, NULL);
+ type = oid_object_info(object, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
@@ -293,17 +294,17 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
strbuf_addstr(sb, rla);
} else {
strbuf_addstr(sb, "tag: tagging ");
- strbuf_add_unique_abbrev(sb, oid->hash, DEFAULT_ABBREV);
+ strbuf_add_unique_abbrev(sb, oid, DEFAULT_ABBREV);
}
strbuf_addstr(sb, " (");
- type = sha1_object_info(oid->hash, NULL);
+ type = oid_object_info(oid, NULL);
switch (type) {
default:
strbuf_addstr(sb, "object of unknown type");
break;
case OBJ_COMMIT:
- if ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) {
+ if ((buf = read_object_file(oid, &type, &size)) != NULL) {
subject_len = find_commit_subject(buf, &subject_start);
strbuf_insert(sb, sb->len, subject_start, subject_len);
} else {
@@ -558,7 +559,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die("%s", err.buf);
ref_transaction_free(transaction);
if (force && !is_null_oid(&prev) && oidcmp(&prev, &object))
- printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev.hash, DEFAULT_ABBREV));
+ printf(_("Updated tag '%s' (was %s)\n"), tag,
+ find_unique_abbrev(&prev, DEFAULT_ABBREV));
UNLEAK(buf);
UNLEAK(ref);
diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 32e0155..300eb59 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -9,7 +9,7 @@ static char *create_temp_file(struct object_id *oid)
unsigned long size;
int fd;
- buf = read_sha1_file(oid->hash, &type, &size);
+ buf = read_object_file(oid, &type, &size);
if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(oid));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 6620fee..b7755c6 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -199,7 +199,7 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op
if (!(obj->flags & FLAG_OPEN)) {
unsigned long size;
- int type = sha1_object_info(obj->oid.hash, &size);
+ int type = oid_object_info(&obj->oid, &size);
if (type != obj->type || type <= 0)
die("object of unexpected type");
obj->flags |= FLAG_WRITTEN;
@@ -423,7 +423,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
return;
- base = read_sha1_file(base_oid.hash, &type, &base_size);
+ base = read_object_file(&base_oid, &type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid));
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 58d1c2d..10d070a 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -592,7 +592,7 @@ static struct cache_entry *read_one_ent(const char *which,
int size;
struct cache_entry *ce;
- if (get_tree_entry(ent->hash, path, oid.hash, &mode)) {
+ if (get_tree_entry(ent, path, &oid, &mode)) {
if (which)
error("%s: not in %s branch.", path, which);
return NULL;
@@ -1059,6 +1059,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
break;
switch (parseopt_state) {
case PARSE_OPT_HELP:
+ case PARSE_OPT_ERROR:
exit(129);
case PARSE_OPT_NON_OPTION:
case PARSE_OPT_DONE:
diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c
index 05315ea..dcdaada 100644
--- a/builtin/verify-commit.c
+++ b/builtin/verify-commit.c
@@ -44,7 +44,7 @@ static int verify_commit(const char *name, unsigned flags)
if (get_oid(name, &oid))
return error("commit '%s' not found.", name);
- buf = read_sha1_file(oid.hash, &type, &size);
+ buf = read_object_file(&oid, &type, &size);
if (!buf)
return error("%s: unable to read file.", name);
if (type != OBJ_COMMIT)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 670555d..40a438e 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -101,16 +101,9 @@ static int prune_worktree(const char *id, struct strbuf *reason)
}
path[len] = '\0';
if (!file_exists(path)) {
- struct stat st_link;
free(path);
- /*
- * the repo is moved manually and has not been
- * accessed since?
- */
- if (!stat(git_path("worktrees/%s/link", id), &st_link) &&
- st_link.st_nlink > 1)
- return 0;
- if (st.st_mtime <= expire) {
+ if (stat(git_path("worktrees/%s/index", id), &st) ||
+ st.st_mtime <= expire) {
strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id);
return 1;
} else {
@@ -502,7 +495,7 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
strbuf_addstr(&sb, "(bare)");
else {
strbuf_addf(&sb, "%-*s ", abbrev_len,
- find_unique_abbrev(wt->head_oid.hash, DEFAULT_ABBREV));
+ find_unique_abbrev(&wt->head_oid, DEFAULT_ABBREV));
if (wt->is_detached)
strbuf_addstr(&sb, "(detached HEAD)");
else if (wt->head_ref) {
@@ -527,7 +520,7 @@ static void measure_widths(struct worktree **wt, int *abbrev, int *maxlen)
if (path_len > *maxlen)
*maxlen = path_len;
- sha1_len = strlen(find_unique_abbrev(wt[i]->head_oid.hash, *abbrev));
+ sha1_len = strlen(find_unique_abbrev(&wt[i]->head_oid, *abbrev));
if (sha1_len > *abbrev)
*abbrev = sha1_len;
}
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index bd0a78a..c9d3c54 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -19,7 +19,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
{
int flags = 0, ret;
const char *prefix = NULL;
- unsigned char sha1[20];
+ struct object_id oid;
const char *me = "git-write-tree";
struct option write_tree_options[] = {
OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
@@ -38,10 +38,10 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
argc = parse_options(argc, argv, unused_prefix, write_tree_options,
write_tree_usage, 0);
- ret = write_cache_as_tree(sha1, flags, prefix);
+ ret = write_cache_as_tree(&oid, flags, prefix);
switch (ret) {
case 0:
- printf("%s\n", sha1_to_hex(sha1));
+ printf("%s\n", oid_to_hex(&oid));
break;
case WRITE_TREE_UNREADABLE_INDEX:
die("%s: error reading the index", me);