mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
builtin/grep: convert to struct object_id
Convert several functions to use struct object_id, and rename them so that they no longer refer to SHA-1. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
175ccdcf2a
commit
1db1108654
|
@ -294,17 +294,17 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
|
static void *lock_and_read_oid_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
grep_read_lock();
|
grep_read_lock();
|
||||||
data = read_sha1_file(sha1, type, size);
|
data = read_sha1_file(oid->hash, type, size);
|
||||||
grep_read_unlock();
|
grep_read_unlock();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
|
static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
|
||||||
const char *filename, int tree_name_len,
|
const char *filename, int tree_name_len,
|
||||||
const char *path)
|
const char *path)
|
||||||
{
|
{
|
||||||
|
@ -323,7 +323,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
|
||||||
|
|
||||||
#ifndef NO_PTHREADS
|
#ifndef NO_PTHREADS
|
||||||
if (num_threads) {
|
if (num_threads) {
|
||||||
add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1);
|
add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, oid);
|
||||||
strbuf_release(&pathbuf);
|
strbuf_release(&pathbuf);
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
|
@ -332,7 +332,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,
|
||||||
struct grep_source gs;
|
struct grep_source gs;
|
||||||
int hit;
|
int hit;
|
||||||
|
|
||||||
grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1);
|
grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, oid);
|
||||||
strbuf_release(&pathbuf);
|
strbuf_release(&pathbuf);
|
||||||
hit = grep_source(opt, &gs);
|
hit = grep_source(opt, &gs);
|
||||||
|
|
||||||
|
@ -690,7 +690,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec,
|
||||||
ce_skip_worktree(ce)) {
|
ce_skip_worktree(ce)) {
|
||||||
if (ce_stage(ce) || ce_intent_to_add(ce))
|
if (ce_stage(ce) || ce_intent_to_add(ce))
|
||||||
continue;
|
continue;
|
||||||
hit |= grep_sha1(opt, ce->oid.hash, ce->name,
|
hit |= grep_oid(opt, &ce->oid, ce->name,
|
||||||
0, ce->name);
|
0, ce->name);
|
||||||
} else {
|
} else {
|
||||||
hit |= grep_file(opt, ce->name);
|
hit |= grep_file(opt, ce->name);
|
||||||
|
@ -750,7 +750,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
|
||||||
strbuf_add(base, entry.path, te_len);
|
strbuf_add(base, entry.path, te_len);
|
||||||
|
|
||||||
if (S_ISREG(entry.mode)) {
|
if (S_ISREG(entry.mode)) {
|
||||||
hit |= grep_sha1(opt, entry.oid->hash, base->buf, tn_len,
|
hit |= grep_oid(opt, entry.oid, base->buf, tn_len,
|
||||||
check_attr ? base->buf + tn_len : NULL);
|
check_attr ? base->buf + tn_len : NULL);
|
||||||
} else if (S_ISDIR(entry.mode)) {
|
} else if (S_ISDIR(entry.mode)) {
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
|
@ -758,7 +758,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
|
||||||
void *data;
|
void *data;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
|
|
||||||
data = lock_and_read_sha1_file(entry.oid->hash, &type, &size);
|
data = lock_and_read_oid_file(entry.oid, &type, &size);
|
||||||
if (!data)
|
if (!data)
|
||||||
die(_("unable to read tree (%s)"),
|
die(_("unable to read tree (%s)"),
|
||||||
oid_to_hex(entry.oid));
|
oid_to_hex(entry.oid));
|
||||||
|
@ -787,7 +787,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
|
||||||
struct object *obj, const char *name, const char *path)
|
struct object *obj, const char *name, const char *path)
|
||||||
{
|
{
|
||||||
if (obj->type == OBJ_BLOB)
|
if (obj->type == OBJ_BLOB)
|
||||||
return grep_sha1(opt, obj->oid.hash, name, 0, path);
|
return grep_oid(opt, &obj->oid, name, 0, path);
|
||||||
if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
|
if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
|
||||||
struct tree_desc tree;
|
struct tree_desc tree;
|
||||||
void *data;
|
void *data;
|
||||||
|
@ -1152,11 +1152,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
||||||
/* Check revs and then paths */
|
/* Check revs and then paths */
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
const char *arg = argv[i];
|
const char *arg = argv[i];
|
||||||
unsigned char sha1[20];
|
struct object_id oid;
|
||||||
struct object_context oc;
|
struct object_context oc;
|
||||||
/* Is it a rev? */
|
/* Is it a rev? */
|
||||||
if (!get_sha1_with_context(arg, 0, sha1, &oc)) {
|
if (!get_sha1_with_context(arg, 0, oid.hash, &oc)) {
|
||||||
struct object *object = parse_object_or_die(sha1, arg);
|
struct object *object = parse_object_or_die(oid.hash, arg);
|
||||||
if (!seen_dashdash)
|
if (!seen_dashdash)
|
||||||
verify_non_filename(prefix, arg);
|
verify_non_filename(prefix, arg);
|
||||||
add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
|
add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
|
||||||
|
|
Loading…
Reference in a new issue