Now that all the callers of get_sha1 directly or indirectly use struct
object_id, rename the functions starting with get_sha1 to start with
get_oid. Convert the internals in sha1_name.c to use struct object_id
as well, and eliminate explicit length checks where possible. Convert a
use of 40 in get_oid_basic to GIT_SHA1_HEXSZ.
Outside of sha1_name.c and cache.h, this transition was made with the
following semantic patch:
@@
expression E1, E2;
@@
- get_sha1(E1, E2.hash)
+ get_oid(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1(E1, E2->hash)
+ get_oid(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_committish(E1, E2.hash)
+ get_oid_committish(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_committish(E1, E2->hash)
+ get_oid_committish(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_treeish(E1, E2.hash)
+ get_oid_treeish(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_treeish(E1, E2->hash)
+ get_oid_treeish(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_commit(E1, E2.hash)
+ get_oid_commit(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_commit(E1, E2->hash)
+ get_oid_commit(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_tree(E1, E2.hash)
+ get_oid_tree(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_tree(E1, E2->hash)
+ get_oid_tree(E1, E2)
@@
expression E1, E2;
@@
- get_sha1_blob(E1, E2.hash)
+ get_oid_blob(E1, &E2)
@@
expression E1, E2;
@@
- get_sha1_blob(E1, E2->hash)
+ get_oid_blob(E1, E2)
@@
expression E1, E2, E3, E4;
@@
- get_sha1_with_context(E1, E2, E3.hash, E4)
+ get_oid_with_context(E1, E2, &E3, E4)
@@
expression E1, E2, E3, E4;
@@
- get_sha1_with_context(E1, E2, E3->hash, E4)
+ get_oid_with_context(E1, E2, E3, E4)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
20 files changed:
raw | patch | inline | side by side (parent: 15be4a5 )
/* Preimage the patch was prepared for */
if (patch->is_new)
write_sha1_file("", 0, blob_type, pre_oid.hash);
/* Preimage the patch was prepared for */
if (patch->is_new)
write_sha1_file("", 0, blob_type, pre_oid.hash);
- else if (get_sha1(patch->old_sha1_prefix, pre_oid.hash ) ||
+ else if (get_oid(patch->old_sha1_prefix, &pre_oid ) ||
read_blob_object(&buf, &pre_oid, patch->old_mode))
return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
read_blob_object(&buf, &pre_oid, patch->old_mode))
return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
else
return error(_("sha1 information is lacking or "
"useless for submodule %s"), name);
else
return error(_("sha1 information is lacking or "
"useless for submodule %s"), name);
- } else if (!get_sha1_blob(patch->old_sha1_prefix, oid.hash )) {
+ } else if (!get_oid_blob(patch->old_sha1_prefix, &oid )) {
; /* ok */
} else if (!patch->lines_added && !patch->lines_deleted) {
/* mode-only change: update the current */
; /* ok */
} else if (!patch->lines_added && !patch->lines_deleted) {
/* mode-only change: update the current */
- if (get_sha1(name, oid.hash ))
+ if (get_oid(name, &oid ))
die("Not a valid object name");
commit = lookup_commit_reference_gently(&oid, 1);
die("Not a valid object name");
commit = lookup_commit_reference_gently(&oid, 1);
struct object_id head;
int i;
struct object_id head;
int i;
- if (!get_sha1_tree("HEAD", head.hash )) {
+ if (!get_oid_tree("HEAD", &head )) {
struct diff_options opt;
diff_setup(&opt);
struct diff_options opt;
diff_setup(&opt);
struct rev_info rev_info;
FILE *fp;
struct rev_info rev_info;
FILE *fp;
- if (!get_sha1_tree("HEAD", head.hash ))
+ if (!get_oid_tree("HEAD", &head ))
tree = lookup_tree(&head);
else
tree = lookup_tree(&empty_tree_oid);
tree = lookup_tree(&head);
else
tree = lookup_tree(&empty_tree_oid);
if (write_cache_as_tree(tree.hash, 0, NULL))
die(_("git write-tree failed to write a tree"));
if (write_cache_as_tree(tree.hash, 0, NULL))
die(_("git write-tree failed to write a tree"));
- if (!get_sha1_commit("HEAD", parent.hash )) {
+ if (!get_oid_commit("HEAD", &parent )) {
old_oid = &parent;
commit_list_insert(lookup_commit(&parent), &parents);
} else {
old_oid = &parent;
commit_list_insert(lookup_commit(&parent), &parents);
} else {
if (unknown_type)
flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
if (unknown_type)
flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
- if (get_sha1 _with_context(obj_name, GET_SHA1_RECORD_PATH,
- oid.hash , &obj_context))
+ if (get_oid _with_context(obj_name, GET_SHA1_RECORD_PATH,
+ &oid , &obj_context))
die("Not a valid object name %s", obj_name);
if (!path)
die("Not a valid object name %s", obj_name);
if (!path)
int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
enum follow_symlinks_result result;
int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
enum follow_symlinks_result result;
- result = get_sha1_with_context(obj_name, flags, data->oid.hash , &ctx);
+ result = get_oid_with_context(obj_name, flags, &data->oid , &ctx);
if (result != FOUND) {
switch (result) {
case MISSING_OBJECT:
if (result != FOUND) {
switch (result) {
case MISSING_OBJECT:
struct object_id oid;
if (argc <= ++i)
usage(commit_tree_usage);
struct object_id oid;
if (argc <= ++i)
usage(commit_tree_usage);
- if (get_sha1_commit(argv[i], oid.hash ))
+ if (get_oid_commit(argv[i], &oid ))
die("Not a valid object name %s", argv[i]);
assert_sha1_type(oid.hash, OBJ_COMMIT);
new_parent(lookup_commit(&oid), &parents);
die("Not a valid object name %s", argv[i]);
assert_sha1_type(oid.hash, OBJ_COMMIT);
new_parent(lookup_commit(&oid), &parents);
- if (get_sha1_tree(arg, tree_oid.hash ))
+ if (get_oid_tree(arg, &tree_oid ))
die("Not a valid object name %s", arg);
if (got_tree)
die("Cannot give more than one trees");
die("Not a valid object name %s", arg);
if (got_tree)
die("Cannot give more than one trees");
s->index_file = index_file;
s->fp = fp;
s->nowarn = nowarn;
s->index_file = index_file;
s->fp = fp;
s->nowarn = nowarn;
- s->is_initial = get_sha1(s->reference, oid.hash ) ? 1 : 0;
+ s->is_initial = get_oid(s->reference, &oid ) ? 1 : 0;
if (!s->is_initial)
hashcpy(s->sha1_commit, oid.hash);
s->status_format = status_format;
if (!s->is_initial)
hashcpy(s->sha1_commit, oid.hash);
s->status_format = status_format;
if (amend)
parent = "HEAD^1";
if (amend)
parent = "HEAD^1";
- if (get_sha1(parent, oid.hash )) {
+ if (get_oid(parent, &oid )) {
int i, ita_nr = 0;
for (i = 0; i < active_nr; i++)
int i, ita_nr = 0;
for (i = 0; i < active_nr; i++)
fd = hold_locked_index(&index_lock, 0);
fd = hold_locked_index(&index_lock, 0);
- s.is_initial = get_sha1(s.reference, oid.hash ) ? 1 : 0;
+ s.is_initial = get_oid(s.reference, &oid ) ? 1 : 0;
if (!s.is_initial)
hashcpy(s.sha1_commit, oid.hash);
if (!s.is_initial)
hashcpy(s.sha1_commit, oid.hash);
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
s.colopts = 0;
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
s.colopts = 0;
- if (get_sha1("HEAD", oid.hash ))
+ if (get_oid("HEAD", &oid ))
current_head = NULL;
else {
current_head = lookup_commit_or_die(&oid, "HEAD");
current_head = NULL;
else {
current_head = lookup_commit_or_die(&oid, "HEAD");
- if (get_sha1 _with_context(arg, GET_SHA1_RECORD_PATH,
- oid.hash , &oc)) {
+ if (get_oid _with_context(arg, GET_SHA1_RECORD_PATH,
+ &oid , &oc)) {
if (seen_dashdash)
die(_("unable to resolve revision: %s"), arg);
break;
if (seen_dashdash)
die(_("unable to resolve revision: %s"), arg);
break;
!DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
return stream_blob_to_fd(1, oid, NULL, 0);
!DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
return stream_blob_to_fd(1, oid, NULL, 0);
- if (get_sha1 _with_context(obj_name, GET_SHA1_RECORD_PATH,
- oidc.hash , &obj_context))
+ if (get_oid _with_context(obj_name, GET_SHA1_RECORD_PATH,
+ &oidc , &obj_context))
die(_("Not a valid object name %s"), obj_name);
if (!obj_context.path ||
!textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
die(_("Not a valid object name %s"), obj_name);
if (!obj_context.path ||
!textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
struct object_id object;
enum object_type obj_type, repl_type;
struct object_id object;
enum object_type obj_type, repl_type;
- if (get_sha1(refname, object.hash ))
+ if (get_oid(refname, &object ))
return error("Failed to resolve '%s' as a valid ref.", refname);
obj_type = sha1_object_info(object.hash, NULL);
return error("Failed to resolve '%s' as a valid ref.", refname);
obj_type = sha1_object_info(object.hash, NULL);
/* iterate over new parents */
for (i = 1; i < mergetag_data->argc; i++) {
struct object_id oid;
/* iterate over new parents */
for (i = 1; i < mergetag_data->argc; i++) {
struct object_id oid;
- if (get_sha1(mergetag_data->argv[i], oid.hash ) < 0)
+ if (get_oid(mergetag_data->argv[i], &oid ) < 0)
die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]);
if (!oidcmp(&tag->tagged->oid, &oid))
return; /* found */
die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]);
if (!oidcmp(&tag->tagged->oid, &oid))
return; /* found */
* has to be unambiguous. If there is a single argument, it
* can not be a tree
*/
* has to be unambiguous. If there is a single argument, it
* can not be a tree
*/
- else if ((!argv[1] && !get_sha1_committish(argv[0], unused.hash )) ||
- (argv[1] && !get_sha1_treeish(argv[0], unused.hash ))) {
+ else if ((!argv[1] && !get_oid_committish(argv[0], &unused )) ||
+ (argv[1] && !get_oid_treeish(argv[0], &unused ))) {
/*
* Ok, argv[0] looks like a commit/tree; it should not
* be a filename.
/*
* Ok, argv[0] looks like a commit/tree; it should not
* be a filename.
- unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash );
+ unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid );
if (unborn) {
/* reset on unborn branch: treat as reset to empty tree */
hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
} else if (!pathspec.nr) {
struct commit *commit;
if (unborn) {
/* reset on unborn branch: treat as reset to empty tree */
hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
} else if (!pathspec.nr) {
struct commit *commit;
- if (get_sha1_committish(rev, oid.hash ))
+ if (get_oid_committish(rev, &oid ))
die(_("Failed to resolve '%s' as a valid revision."), rev);
commit = lookup_commit_reference(&oid);
if (!commit)
die(_("Failed to resolve '%s' as a valid revision."), rev);
commit = lookup_commit_reference(&oid);
if (!commit)
oidcpy(&oid, &commit->object.oid);
} else {
struct tree *tree;
oidcpy(&oid, &commit->object.oid);
} else {
struct tree *tree;
- if (get_sha1_treeish(rev, oid.hash ))
+ if (get_oid_treeish(rev, &oid ))
die(_("Failed to resolve '%s' as a valid tree."), rev);
tree = parse_tree_indirect(&oid);
if (!tree)
die(_("Failed to resolve '%s' as a valid tree."), rev);
tree = parse_tree_indirect(&oid);
if (!tree)
- if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash )) {
+ if (!get_oid_committish(this, &oid) && !get_oid_committish(next, &end )) {
show_rev(NORMAL, &end, next);
show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
if (symmetric) {
show_rev(NORMAL, &end, next);
show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
if (symmetric) {
- if (get_sha1_committish(arg, oid.hash )) {
+ if (get_oid_committish(arg, &oid )) {
*dotdot = '^';
return 0;
}
*dotdot = '^';
return 0;
}
name++;
type = REVERSED;
}
name++;
type = REVERSED;
}
- if (!get_sha1_with_context(name, flags, oid.hash , &unused)) {
+ if (!get_oid_with_context(name, flags, &oid , &unused)) {
if (verify)
revs_count++;
else
if (verify)
revs_count++;
else
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
- if (get_sha1(refname + ofs, tmp.hash ) || oidcmp(&tmp, oid))
+ if (get_oid(refname + ofs, &tmp ) || oidcmp(&tmp, oid))
ofs = 5;
return append_ref(refname + ofs, oid, 0);
}
ofs = 5;
return append_ref(refname + ofs, oid, 0);
}
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
- if (get_sha1(refname + ofs, tmp.hash ) || oidcmp(&tmp, oid))
+ if (get_oid(refname + ofs, &tmp ) || oidcmp(&tmp, oid))
ofs = 5;
return append_ref(refname + ofs, oid, 0);
}
ofs = 5;
return append_ref(refname + ofs, oid, 0);
}
static void append_one_rev(const char *av)
{
struct object_id revkey;
static void append_one_rev(const char *av)
{
struct object_id revkey;
- if (!get_sha1(av, revkey.hash )) {
+ if (!get_oid(av, &revkey )) {
append_ref(av, &revkey, 0);
return;
}
append_ref(av, &revkey, 0);
return;
}
die(Q_("cannot handle more than %d rev.",
"cannot handle more than %d revs.",
MAX_REVS), MAX_REVS);
die(Q_("cannot handle more than %d rev.",
"cannot handle more than %d revs.",
MAX_REVS), MAX_REVS);
- if (get_sha1(ref_name[num_rev], revkey.hash ))
+ if (get_oid(ref_name[num_rev], &revkey ))
die(_("'%s' is not a valid ref."), ref_name[num_rev]);
commit = lookup_commit_reference(&revkey);
if (!commit)
die(_("'%s' is not a valid ref."), ref_name[num_rev]);
commit = lookup_commit_reference(&revkey);
if (!commit)
GET_SHA1_TREE | GET_SHA1_TREEISH | \
GET_SHA1_BLOB)
GET_SHA1_TREE | GET_SHA1_TREEISH | \
GET_SHA1_BLOB)
-extern int get_sha1(const char *str, unsigned char *sha1 );
-extern int get_sha1_commit(const char *str, unsigned char *sha1 );
-extern int get_sha1_committish(const char *str, unsigned char *sha1 );
-extern int get_sha1_tree(const char *str, unsigned char *sha1 );
-extern int get_sha1_treeish(const char *str, unsigned char *sha1 );
-extern int get_sha1_blob(const char *str, unsigned char *sha1 );
+extern int get_oid(const char *str, struct object_id *oid );
+extern int get_oid_commit(const char *str, struct object_id *oid );
+extern int get_oid_committish(const char *str, struct object_id *oid );
+extern int get_oid_tree(const char *str, struct object_id *oid );
+extern int get_oid_treeish(const char *str, struct object_id *oid );
+extern int get_oid_blob(const char *str, struct object_id *oid );
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
-extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1 , struct object_context *oc);
+extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid , struct object_context *oc);
-extern int get_oid(const char *str, struct object_id *oid);
typedef int each_abbrev_fn(const struct object_id *oid, void *);
extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
typedef int each_abbrev_fn(const struct object_id *oid, void *);
extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
struct object_id oid;
struct commit *commit;
struct object_id oid;
struct commit *commit;
- if (get_sha1_committish(name, oid.hash ))
+ if (get_oid_committish(name, &oid ))
return NULL;
commit = lookup_commit_reference(&oid);
if (parse_commit(commit))
return NULL;
commit = lookup_commit_reference(&oid);
if (parse_commit(commit))
struct object *obj;
struct commit *commit;
struct object_id oid;
struct object *obj;
struct commit *commit;
struct object_id oid;
- if (get_sha1(name, oid.hash ))
+ if (get_oid(name, &oid ))
return NULL;
obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
return NULL;
obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
t->dirty = 0;
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
t->dirty = 0;
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
- get_sha1_treeish(notes_ref, object_oid.hash ))
+ get_oid_treeish(notes_ref, &object_oid ))
return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
die("Cannot use notes ref %s", notes_ref);
return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
die("Cannot use notes ref %s", notes_ref);
- if (get_sha1(name, oid.hash ))
+ if (get_oid(name, &oid ))
flags ^= UNINTERESTING | BOTTOM;
arg++;
}
flags ^= UNINTERESTING | BOTTOM;
arg++;
}
- if (get_sha1_committish(arg, oid.hash ))
+ if (get_oid_committish(arg, &oid ))
return 0;
while (1) {
it = get_reference(revs, arg, &oid, 0);
return 0;
while (1) {
it = get_reference(revs, arg, &oid, 0);
if (!*b_name)
b_name = "HEAD";
if (!*b_name)
b_name = "HEAD";
- if (get_sha1_with_context(a_name, oc_flags, a_oid.hash , a_oc) ||
- get_sha1_with_context(b_name, oc_flags, b_oid.hash , b_oc))
+ if (get_oid_with_context(a_name, oc_flags, &a_oid , a_oc) ||
+ get_oid_with_context(b_name, oc_flags, &b_oid , b_oc))
return -1;
if (!cant_be_filename) {
return -1;
if (!cant_be_filename) {
if (revarg_opt & REVARG_COMMITTISH)
get_sha1_flags |= GET_SHA1_COMMITTISH;
if (revarg_opt & REVARG_COMMITTISH)
get_sha1_flags |= GET_SHA1_COMMITTISH;
- if (get_sha1_with_context(arg, get_sha1_flags, oid.hash , &oc))
+ if (get_oid_with_context(arg, get_sha1_flags, &oid , &oc))
return revs->ignore_missing ? 0 : -1;
if (!cant_be_filename)
verify_non_filename(revs->prefix, arg);
return revs->ignore_missing ? 0 : -1;
if (!cant_be_filename)
verify_non_filename(revs->prefix, arg);
struct object_id oid;
struct object *object;
struct object_context oc;
struct object_id oid;
struct object *object;
struct object_context oc;
- if (get_sha1_with_context(revs->def, 0, oid.hash , &oc))
+ if (get_oid_with_context(revs->def, 0, &oid , &oc))
diagnose_missing_default(revs->def);
object = get_reference(revs, revs->def, &oid, 0);
add_pending_object_with_mode(revs, object, revs->def, oc.mode);
diagnose_missing_default(revs->def);
object = get_reference(revs, revs->def, &oid, 0);
add_pending_object_with_mode(revs, object, revs->def, oc.mode);
log_tree_opt.disable_stdin = 1;
if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
log_tree_opt.disable_stdin = 1;
if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
- !get_sha1(buf.buf, orig.hash ) &&
- !get_sha1("HEAD", head.hash )) {
+ !get_oid(buf.buf, &orig ) &&
+ !get_oid("HEAD", &head )) {
diff_tree_oid(&orig, &head, "",
&log_tree_opt.diffopt);
log_tree_diff_flush(&log_tree_opt);
diff_tree_oid(&orig, &head, "",
&log_tree_opt.diffopt);
log_tree_diff_flush(&log_tree_opt);
struct object_id oid;
if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) &&
struct object_id oid;
if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) &&
- !get_sha1_committish(buf.buf, oid.hash ))
+ !get_oid_committish(buf.buf, &oid ))
record_in_rewritten(&oid, peek_command(&todo_list, 0));
strbuf_release(&buf);
}
record_in_rewritten(&oid, peek_command(&todo_list, 0));
strbuf_release(&buf);
}
#include "dir.h"
#include "sha1-array.h"
#include "dir.h"
#include "sha1-array.h"
-static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *);
+static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
#define SHORT_NAME_AMBIGUOUS (-2)
static int finish_object_disambiguation(struct disambiguate_state *ds,
#define SHORT_NAME_AMBIGUOUS (-2)
static int finish_object_disambiguation(struct disambiguate_state *ds,
{
if (ds->ambiguous)
return SHORT_NAME_AMBIGUOUS;
{
if (ds->ambiguous)
return SHORT_NAME_AMBIGUOUS;
if (!ds->candidate_ok)
return SHORT_NAME_AMBIGUOUS;
if (!ds->candidate_ok)
return SHORT_NAME_AMBIGUOUS;
- hashcpy(sha1, ds->candidate.hash );
+ oidcpy(oid, &ds->candidate );
-static int get_short_sha1(const char *name, int len, unsigned char *sha1 ,
+static int get_short_oid(const char *name, int len, struct object_id *oid ,
unsigned flags)
{
int status;
unsigned flags)
{
int status;
return -1;
if (HAS_MULTI_BITS(flags & GET_SHA1_DISAMBIGUATORS))
return -1;
if (HAS_MULTI_BITS(flags & GET_SHA1_DISAMBIGUATORS))
- die("BUG: multiple get_short_sha1 disambiguator flags");
+ die("BUG: multiple get_short_oid disambiguator flags");
if (flags & GET_SHA1_COMMIT)
ds.fn = disambiguate_commit_only;
if (flags & GET_SHA1_COMMIT)
ds.fn = disambiguate_commit_only;
find_short_object_filename(&ds);
find_short_packed_object(&ds);
find_short_object_filename(&ds);
find_short_packed_object(&ds);
- status = finish_object_disambiguation(&ds, sha1 );
+ status = finish_object_disambiguation(&ds, oid );
if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
error(_("short SHA1 %s is ambiguous"), ds.hex_pfx);
if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
error(_("short SHA1 %s is ambiguous"), ds.hex_pfx);
return 40;
exists = has_sha1_file(sha1);
while (len < 40) {
return 40;
exists = has_sha1_file(sha1);
while (len < 40) {
- unsigned char sha1_ret[20] ;
- status = get_short_sha1(hex, len, sha1 _ret, GET_SHA1_QUIETLY);
+ struct object_id oid_ret ;
+ status = get_short_oid(hex, len, &oid _ret, GET_SHA1_QUIETLY);
if (exists
? !status
: status == SHORT_NAME_NOT_FOUND) {
if (exists
? !status
: status == SHORT_NAME_NOT_FOUND) {
return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
}
return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
}
-static int get_sha1_1(const char *name, int len, unsigned char *sha1 , unsigned lookup_flags);
+static int get_oid_1(const char *name, int len, struct object_id *oid , unsigned lookup_flags);
static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
-static int get_sha1_basic(const char *str, int len, unsigned char *sha1 ,
+static int get_oid_basic(const char *str, int len, struct object_id *oid ,
unsigned int flags)
{
static const char *warn_msg = "refname '%.*s' is ambiguous.";
unsigned int flags)
{
static const char *warn_msg = "refname '%.*s' is ambiguous.";
"where \"$br\" is somehow empty and a 40-hex ref is created. Please\n"
"examine these refs and maybe delete them. Turn this message off by\n"
"running \"git config advice.objectNameWarning false\"");
"where \"$br\" is somehow empty and a 40-hex ref is created. Please\n"
"examine these refs and maybe delete them. Turn this message off by\n"
"running \"git config advice.objectNameWarning false\"");
- unsigned char tmp_sha1[20] ;
+ struct object_id tmp_oid ;
char *real_ref = NULL;
int refs_found = 0;
int at, reflog_len, nth_prior = 0;
char *real_ref = NULL;
int refs_found = 0;
int at, reflog_len, nth_prior = 0;
- if (len == 40 && !get_sha1_hex(str, sha1 )) {
+ if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid )) {
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
- refs_found = dwim_ref(str, len, tmp_sha1 , &real_ref);
+ refs_found = dwim_ref(str, len, tmp_oid.hash , &real_ref);
if (refs_found > 0) {
warning(warn_msg, len, str);
if (advice_object_name_warning)
if (refs_found > 0) {
warning(warn_msg, len, str);
if (advice_object_name_warning)
int detached;
if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
int detached;
if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
- detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1 ));
+ detached = (buf.len == GIT_SHA1_HEXSZ && !get_oid_hex(buf.buf, oid ));
strbuf_release(&buf);
if (detached)
return 0;
strbuf_release(&buf);
if (detached)
return 0;
if (!len && reflog_len)
/* allow "@{...}" to mean the current branch reflog */
if (!len && reflog_len)
/* allow "@{...}" to mean the current branch reflog */
- refs_found = dwim_ref("HEAD", 4, sha1 , &real_ref);
+ refs_found = dwim_ref("HEAD", 4, oid->hash , &real_ref);
- refs_found = dwim_log(str, len, sha1 , &real_ref);
+ refs_found = dwim_log(str, len, oid->hash , &real_ref);
- refs_found = dwim_ref(str, len, sha1 , &real_ref);
+ refs_found = dwim_ref(str, len, oid->hash , &real_ref);
if (!refs_found)
return -1;
if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) &&
(refs_found > 1 ||
if (!refs_found)
return -1;
if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) &&
(refs_found > 1 ||
- !get_short_sha1(str, len, tmp_sha1 , GET_SHA1_QUIETLY)))
+ !get_short_oid(str, len, &tmp_oid , GET_SHA1_QUIETLY)))
warning(warn_msg, len, str);
if (reflog_len) {
warning(warn_msg, len, str);
if (reflog_len) {
- if (read_ref_at(real_ref, flags, at_time, nth, sha1 , NULL,
+ if (read_ref_at(real_ref, flags, at_time, nth, oid->hash , NULL,
&co_time, &co_tz, &co_cnt)) {
if (!len) {
if (starts_with(real_ref, "refs/heads/")) {
&co_time, &co_tz, &co_cnt)) {
if (!len) {
if (starts_with(real_ref, "refs/heads/")) {
}
static int get_parent(const char *name, int len,
}
static int get_parent(const char *name, int len,
- unsigned char *result, int idx)
+ struct object_id *result, int idx)
- int ret = get_sha1_1(name, len, oid.hash , GET_SHA1_COMMITTISH);
+ int ret = get_oid_1(name, len, &oid , GET_SHA1_COMMITTISH);
struct commit *commit;
struct commit_list *p;
struct commit *commit;
struct commit_list *p;
if (parse_commit(commit))
return -1;
if (!idx) {
if (parse_commit(commit))
return -1;
if (!idx) {
- hashcpy(result, commit->object.oid.hash );
+ oidcpy(result, &commit->object.oid );
return 0;
}
p = commit->parents;
while (p) {
if (!--idx) {
return 0;
}
p = commit->parents;
while (p) {
if (!--idx) {
- hashcpy(result, p->item->object.oid.hash );
+ oidcpy(result, &p->item->object.oid );
}
static int get_nth_ancestor(const char *name, int len,
}
static int get_nth_ancestor(const char *name, int len,
- unsigned char *result, int generation)
+ struct object_id *result, int generation)
{
struct object_id oid;
struct commit *commit;
int ret;
{
struct object_id oid;
struct commit *commit;
int ret;
- ret = get_sha1_1(name, len, oid.hash , GET_SHA1_COMMITTISH);
+ ret = get_oid_1(name, len, &oid , GET_SHA1_COMMITTISH);
if (ret)
return ret;
commit = lookup_commit_reference(&oid);
if (ret)
return ret;
commit = lookup_commit_reference(&oid);
return -1;
commit = commit->parents->item;
}
return -1;
commit = commit->parents->item;
}
- hashcpy(result, commit->object.oid.hash );
+ oidcpy(result, &commit->object.oid );
-static int peel_onion(const char *name, int len, unsigned char *sha1 ,
+static int peel_onion(const char *name, int len, struct object_id *oid ,
unsigned lookup_flags)
{
struct object_id outer;
unsigned lookup_flags)
{
struct object_id outer;
else if (expected_type == OBJ_TREE)
lookup_flags |= GET_SHA1_TREEISH;
else if (expected_type == OBJ_TREE)
lookup_flags |= GET_SHA1_TREEISH;
- if (get_sha1_1(name, sp - name - 2, outer.hash , lookup_flags))
+ if (get_oid_1(name, sp - name - 2, &outer , lookup_flags))
return -1;
o = parse_object(&outer);
return -1;
o = parse_object(&outer);
o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(&o->oid)))
return -1;
o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(&o->oid)))
return -1;
- hashcpy(sha1, o->oid.hash );
- hashcpy(sha1, o->oid.hash );
if (sp[0] == '/') {
/* "$commit^{/foo}" */
char *prefix;
if (sp[0] == '/') {
/* "$commit^{/foo}" */
char *prefix;
prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
commit_list_insert((struct commit *)o, &list);
prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
commit_list_insert((struct commit *)o, &list);
- ret = get_sha1_oneline(prefix, sha1 , list);
+ ret = get_oid_oneline(prefix, oid , list);
free(prefix);
return ret;
}
return 0;
}
free(prefix);
return ret;
}
return 0;
}
-static int get_describe_name(const char *name, int len, unsigned char *sha1 )
+static int get_describe_name(const char *name, int len, struct object_id *oid )
{
const char *cp;
unsigned flags = GET_SHA1_QUIETLY | GET_SHA1_COMMIT;
{
const char *cp;
unsigned flags = GET_SHA1_QUIETLY | GET_SHA1_COMMIT;
if (ch == 'g' && cp[-1] == '-') {
cp++;
len -= cp - name;
if (ch == 'g' && cp[-1] == '-') {
cp++;
len -= cp - name;
- return get_short_sha1(cp, len, sha1 , flags);
+ return get_short_oid(cp, len, oid , flags);
-static int get_sha1_1(const char *name, int len, unsigned char *sha1 , unsigned lookup_flags)
+static int get_oid_1(const char *name, int len, struct object_id *oid , unsigned lookup_flags)
{
int ret, has_suffix;
const char *cp;
{
int ret, has_suffix;
const char *cp;
if (!num && len1 == len - 1)
num = 1;
if (has_suffix == '^')
if (!num && len1 == len - 1)
num = 1;
if (has_suffix == '^')
- return get_parent(name, len1, sha1 , num);
+ return get_parent(name, len1, oid , num);
/* else if (has_suffix == '~') -- goes without saying */
/* else if (has_suffix == '~') -- goes without saying */
- return get_nth_ancestor(name, len1, sha1 , num);
+ return get_nth_ancestor(name, len1, oid , num);
- ret = peel_onion(name, len, sha1 , lookup_flags);
+ ret = peel_onion(name, len, oid , lookup_flags);
- ret = get_sha1_basic(name, len, sha1 , lookup_flags);
+ ret = get_oid_basic(name, len, oid , lookup_flags);
if (!ret)
return 0;
/* It could be describe output that is "SOMETHING-gXXXX" */
if (!ret)
return 0;
/* It could be describe output that is "SOMETHING-gXXXX" */
- ret = get_describe_name(name, len, sha1 );
+ ret = get_describe_name(name, len, oid );
- return get_short_sha1(name, len, sha1 , lookup_flags);
+ return get_short_oid(name, len, oid , lookup_flags);
-static int get_sha1_oneline(const char *prefix, unsigned char *sha1 ,
+static int get_oid_oneline(const char *prefix, struct object_id *oid ,
struct commit_list *list)
{
struct commit_list *backup = NULL, *l;
struct commit_list *list)
{
struct commit_list *backup = NULL, *l;
unuse_commit_buffer(commit, buf);
if (matches) {
unuse_commit_buffer(commit, buf);
if (matches) {
- hashcpy(sha1, commit->object.oid.hash );
+ oidcpy(oid, &commit->object.oid );
struct strbuf sb;
strbuf_init(&sb, dots - name);
strbuf_add(&sb, name, dots - name);
struct strbuf sb;
strbuf_init(&sb, dots - name);
strbuf_add(&sb, name, dots - name);
- st = get_sha1_committish(sb.buf, oid_tmp.hash );
+ st = get_oid_committish(sb.buf, &oid_tmp );
strbuf_release(&sb);
}
if (st)
strbuf_release(&sb);
}
if (st)
- if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash ))
+ if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp ))
return -1;
two = lookup_commit_reference_gently(&oid_tmp, 0);
if (!two)
return -1;
two = lookup_commit_reference_gently(&oid_tmp, 0);
if (!two)
- * This is like "get_sha1_basic()", except it allows "sha1 expressions",
+ * This is like "get_oid_basic()", except it allows "object ID expressions",
* notably "xyz^" for "parent of xyz"
*/
* notably "xyz^" for "parent of xyz"
*/
-int get_sha1(const char *name, unsigned char *sha1)
-{
- struct object_context unused;
- return get_sha1_with_context(name, 0, sha1, &unused);
-}
-
-/*
- * This is like "get_sha1()", but for struct object_id.
- */
int get_oid(const char *name, struct object_id *oid)
{
int get_oid(const char *name, struct object_id *oid)
{
- return get_sha1(name, oid->hash);
+ struct object_context unused;
+ return get_oid_with_context(name, 0, oid, &unused);
* commit-ish. It is merely to give a hint to the disambiguation
* machinery.
*/
* commit-ish. It is merely to give a hint to the disambiguation
* machinery.
*/
-int get_sha1_committish(const char *name, unsigned char *sha1 )
+int get_oid_committish(const char *name, struct object_id *oid )
{
struct object_context unused;
{
struct object_context unused;
- return get_sha1 _with_context(name, GET_SHA1_COMMITTISH,
- sha1 , &unused);
+ return get_oid _with_context(name, GET_SHA1_COMMITTISH,
+ oid , &unused);
-int get_sha1_treeish(const char *name, unsigned char *sha1 )
+int get_oid_treeish(const char *name, struct object_id *oid )
{
struct object_context unused;
{
struct object_context unused;
- return get_sha1 _with_context(name, GET_SHA1_TREEISH,
- sha1 , &unused);
+ return get_oid _with_context(name, GET_SHA1_TREEISH,
+ oid , &unused);
-int get_sha1_commit(const char *name, unsigned char *sha1 )
+int get_oid_commit(const char *name, struct object_id *oid )
{
struct object_context unused;
{
struct object_context unused;
- return get_sha1 _with_context(name, GET_SHA1_COMMIT,
- sha1 , &unused);
+ return get_oid _with_context(name, GET_SHA1_COMMIT,
+ oid , &unused);
-int get_sha1_tree(const char *name, unsigned char *sha1 )
+int get_oid_tree(const char *name, struct object_id *oid )
{
struct object_context unused;
{
struct object_context unused;
- return get_sha1 _with_context(name, GET_SHA1_TREE,
- sha1 , &unused);
+ return get_oid _with_context(name, GET_SHA1_TREE,
+ oid , &unused);
-int get_sha1_blob(const char *name, unsigned char *sha1 )
+int get_oid_blob(const char *name, struct object_id *oid )
{
struct object_context unused;
{
struct object_context unused;
- return get_sha1 _with_context(name, GET_SHA1_BLOB,
- sha1 , &unused);
+ return get_oid _with_context(name, GET_SHA1_BLOB,
+ oid , &unused);
}
/* Must be called only when object_name:filename doesn't exist. */
}
/* Must be called only when object_name:filename doesn't exist. */
-static void diagnose_invalid_sha1 _path(const char *prefix,
- const char *filename,
- const unsigned char *tree_sha1 ,
- const char *object_name,
- int object_name_len)
+static void diagnose_invalid_oid _path(const char *prefix,
+ const char *filename,
+ const struct object_id *tree_oid ,
+ const char *object_name,
+ int object_name_len)
- unsigned char sha1[20] ;
unsigned mode;
if (!prefix)
unsigned mode;
if (!prefix)
if (is_missing_file_error(errno)) {
char *fullname = xstrfmt("%s%s", prefix, filename);
if (is_missing_file_error(errno)) {
char *fullname = xstrfmt("%s%s", prefix, filename);
- if (!get_tree_entry(tree_sha1 , fullname,
- sha1 , &mode)) {
+ if (!get_tree_entry(tree_oid->hash , fullname,
+ oid.hash , &mode)) {
die("Path '%s' exists, but not '%s'.\n"
"Did you mean '%.*s:%s' aka '%.*s:./%s'?",
fullname,
die("Path '%s' exists, but not '%s'.\n"
"Did you mean '%.*s:%s' aka '%.*s:./%s'?",
fullname,
-static int get_sha1 _with_context_1(const char *name,
- unsigned flags,
- const char *prefix,
- unsigned char *sha1 ,
- struct object_context *oc)
+static int get_oid _with_context_1(const char *name,
+ unsigned flags,
+ const char *prefix,
+ struct object_id *oid ,
+ struct object_context *oc)
{
int ret, bracket_depth;
int namelen = strlen(name);
{
int ret, bracket_depth;
int namelen = strlen(name);
memset(oc, 0, sizeof(*oc));
oc->mode = S_IFINVALID;
strbuf_init(&oc->symlink_path, 0);
memset(oc, 0, sizeof(*oc));
oc->mode = S_IFINVALID;
strbuf_init(&oc->symlink_path, 0);
- ret = get_sha1_1(name, namelen, sha1 , flags);
+ ret = get_oid_1(name, namelen, oid , flags);
for_each_ref(handle_one_ref, &list);
commit_list_sort_by_date(&list);
for_each_ref(handle_one_ref, &list);
commit_list_sort_by_date(&list);
- return get_sha1_oneline(name + 2, sha1 , list);
+ return get_oid_oneline(name + 2, oid , list);
}
if (namelen < 3 ||
name[2] != ':' ||
}
if (namelen < 3 ||
name[2] != ':' ||
memcmp(ce->name, cp, namelen))
break;
if (ce_stage(ce) == stage) {
memcmp(ce->name, cp, namelen))
break;
if (ce_stage(ce) == stage) {
- hashcpy(sha1, ce->oid.hash );
oc->mode = ce->ce_mode;
free(new_path);
return 0;
oc->mode = ce->ce_mode;
free(new_path);
return 0;
break;
}
if (*cp == ':') {
break;
}
if (*cp == ':') {
- unsigned char tree_sha1[20] ;
+ struct object_id tree_oid ;
int len = cp - name;
unsigned sub_flags = flags;
sub_flags &= ~GET_SHA1_DISAMBIGUATORS;
sub_flags |= GET_SHA1_TREEISH;
int len = cp - name;
unsigned sub_flags = flags;
sub_flags &= ~GET_SHA1_DISAMBIGUATORS;
sub_flags |= GET_SHA1_TREEISH;
- if (!get_sha1_1(name, len, tree_sha1 , sub_flags)) {
+ if (!get_oid_1(name, len, &tree_oid , sub_flags)) {
const char *filename = cp+1;
char *new_filename = NULL;
const char *filename = cp+1;
char *new_filename = NULL;
if (new_filename)
filename = new_filename;
if (flags & GET_SHA1_FOLLOW_SYMLINKS) {
if (new_filename)
filename = new_filename;
if (flags & GET_SHA1_FOLLOW_SYMLINKS) {
- ret = get_tree_entry_follow_symlinks(tree_sha1 ,
- filename, sha1 , &oc->symlink_path,
+ ret = get_tree_entry_follow_symlinks(tree_oid.hash ,
+ filename, oid->hash , &oc->symlink_path,
- ret = get_tree_entry(tree_sha1 , filename,
- sha1 , &oc->mode);
+ ret = get_tree_entry(tree_oid.hash , filename,
+ oid->hash , &oc->mode);
if (ret && only_to_die) {
if (ret && only_to_die) {
- diagnose_invalid_sha1 _path(prefix,
+ diagnose_invalid_oid _path(prefix,
- hashcpy(oc->tree, tree_sha1 );
+ hashcpy(oc->tree, tree_oid.hash );
if (flags & GET_SHA1_RECORD_PATH)
oc->path = xstrdup(filename);
if (flags & GET_SHA1_RECORD_PATH)
oc->path = xstrdup(filename);
void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
{
struct object_context oc;
void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
{
struct object_context oc;
- unsigned char sha1[20] ;
- get_sha1_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, sha1 , &oc);
+ struct object_id oid ;
+ get_oid_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, &oid , &oc);
-int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1 , struct object_context *oc)
+int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid , struct object_context *oc)
{
if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE)
die("BUG: incompatible flags for get_sha1_with_context");
{
if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE)
die("BUG: incompatible flags for get_sha1_with_context");
- return get_sha1_with_context_1(str, flags, NULL, sha1 , oc);
+ return get_oid_with_context_1(str, flags, NULL, oid , oc);
struct object_id oid;
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
struct object_id oid;
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
- if (private && !get_sha1(private, oid.hash )) {
+ if (private && !get_oid(private, &oid )) {
strbuf_addf(&buf, "^%s", private);
string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
oidcpy(&ref->old_oid, &oid);
strbuf_addf(&buf, "^%s", private);
string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
oidcpy(&ref->old_oid, &oid);