grep: honor --textconv for the case rev:path
Make "grep" honor the "--textconv" option also for the object case, i.e. when used with an argument "rev:path". Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
335ec3bf41
commit
afa15f3cd8
@ -458,10 +458,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
|
static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
|
||||||
struct object *obj, const char *name)
|
struct object *obj, const char *name, struct object_context *oc)
|
||||||
{
|
{
|
||||||
if (obj->type == OBJ_BLOB)
|
if (obj->type == OBJ_BLOB)
|
||||||
return grep_sha1(opt, obj->sha1, name, 0, NULL);
|
return grep_sha1(opt, obj->sha1, name, 0, oc ? oc->path : NULL);
|
||||||
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;
|
||||||
@ -503,7 +503,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
|
|||||||
for (i = 0; i < nr; i++) {
|
for (i = 0; i < nr; i++) {
|
||||||
struct object *real_obj;
|
struct object *real_obj;
|
||||||
real_obj = deref_tag(list->objects[i].item, NULL, 0);
|
real_obj = deref_tag(list->objects[i].item, NULL, 0);
|
||||||
if (grep_object(opt, pathspec, real_obj, list->objects[i].name)) {
|
if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].context)) {
|
||||||
hit = 1;
|
hit = 1;
|
||||||
if (opt->status_only)
|
if (opt->status_only)
|
||||||
break;
|
break;
|
||||||
@ -820,12 +820,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
|||||||
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];
|
unsigned char sha1[20];
|
||||||
|
struct object_context oc;
|
||||||
/* Is it a rev? */
|
/* Is it a rev? */
|
||||||
if (!get_sha1(arg, sha1)) {
|
if (!get_sha1_with_context(arg, 0, sha1, &oc)) {
|
||||||
struct object *object = parse_object_or_die(sha1, arg);
|
struct object *object = parse_object_or_die(sha1, arg);
|
||||||
if (!seen_dashdash)
|
if (!seen_dashdash)
|
||||||
verify_non_filename(prefix, arg);
|
verify_non_filename(prefix, arg);
|
||||||
add_object_array(object, arg, &list);
|
add_object_array_with_context(object, arg, &list, xmemdupz(&oc, sizeof(struct object_context)));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "--")) {
|
if (!strcmp(arg, "--")) {
|
||||||
|
26
object.c
26
object.c
@ -255,12 +255,7 @@ int object_list_contains(struct object_list *list, struct object *obj)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_object_array(struct object *obj, const char *name, struct object_array *array)
|
static void add_object_array_with_mode_context(struct object *obj, const char *name, struct object_array *array, unsigned mode, struct object_context *context)
|
||||||
{
|
|
||||||
add_object_array_with_mode(obj, name, array, S_IFINVALID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode)
|
|
||||||
{
|
{
|
||||||
unsigned nr = array->nr;
|
unsigned nr = array->nr;
|
||||||
unsigned alloc = array->alloc;
|
unsigned alloc = array->alloc;
|
||||||
@ -275,9 +270,28 @@ void add_object_array_with_mode(struct object *obj, const char *name, struct obj
|
|||||||
objects[nr].item = obj;
|
objects[nr].item = obj;
|
||||||
objects[nr].name = name;
|
objects[nr].name = name;
|
||||||
objects[nr].mode = mode;
|
objects[nr].mode = mode;
|
||||||
|
objects[nr].context = context;
|
||||||
array->nr = ++nr;
|
array->nr = ++nr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_object_array(struct object *obj, const char *name, struct object_array *array)
|
||||||
|
{
|
||||||
|
add_object_array_with_mode(obj, name, array, S_IFINVALID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode)
|
||||||
|
{
|
||||||
|
add_object_array_with_mode_context(obj, name, array, mode, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_object_array_with_context(struct object *obj, const char *name, struct object_array *array, struct object_context *context)
|
||||||
|
{
|
||||||
|
if (context)
|
||||||
|
add_object_array_with_mode_context(obj, name, array, context->mode, context);
|
||||||
|
else
|
||||||
|
add_object_array_with_mode_context(obj, name, array, S_IFINVALID, context);
|
||||||
|
}
|
||||||
|
|
||||||
void object_array_remove_duplicates(struct object_array *array)
|
void object_array_remove_duplicates(struct object_array *array)
|
||||||
{
|
{
|
||||||
unsigned int ref, src, dst;
|
unsigned int ref, src, dst;
|
||||||
|
2
object.h
2
object.h
@ -13,6 +13,7 @@ struct object_array {
|
|||||||
struct object *item;
|
struct object *item;
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned mode;
|
unsigned mode;
|
||||||
|
struct object_context *context;
|
||||||
} *objects;
|
} *objects;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ int object_list_contains(struct object_list *list, struct object *obj);
|
|||||||
/* Object array handling .. */
|
/* Object array handling .. */
|
||||||
void add_object_array(struct object *obj, const char *name, struct object_array *array);
|
void add_object_array(struct object *obj, const char *name, struct object_array *array);
|
||||||
void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode);
|
void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode);
|
||||||
|
void add_object_array_with_context(struct object *obj, const char *name, struct object_array *array, struct object_context *context);
|
||||||
void object_array_remove_duplicates(struct object_array *);
|
void object_array_remove_duplicates(struct object_array *);
|
||||||
|
|
||||||
void clear_object_flags(unsigned flags);
|
void clear_object_flags(unsigned flags);
|
||||||
|
@ -170,14 +170,10 @@ test_expect_success 'grep --no-textconv does not honor textconv' '
|
|||||||
test_must_fail git grep --no-textconv Qfile
|
test_must_fail git grep --no-textconv Qfile
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'grep --textconv blob honors textconv' '
|
test_expect_success 'grep --textconv blob honors textconv' '
|
||||||
echo "HEAD:a:binaryQfile" >expect &&
|
echo "HEAD:a:binaryQfile" >expect &&
|
||||||
git grep --textconv Qfile HEAD:a >actual &&
|
git grep --textconv Qfile HEAD:a >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'grep --no-textconv blob does not honor textconv' '
|
|
||||||
test_must_fail git grep --no-textconv Qfile HEAD:a
|
|
||||||
'
|
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user