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>
Michael J Gruber committed
May 10, 2013 at 17:10 UTC
afa15f3cd8f4cbf9572138329be374ff8566b10a
4 files changed
+29
-16
builtin/grep.c
+6
-5
@@ -458,10 +458,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
458
}
459
460
static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
461
- struct object *obj, const char *name)
461
+ struct object *obj, const char *name, struct object_context *oc)
462
{
463
if (obj->type == OBJ_BLOB)
464
- return grep_sha1(opt, obj->sha1, name, 0, NULL);
464
+ return grep_sha1(opt, obj->sha1, name, 0, oc ? oc->path : NULL);
465
if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
466
struct tree_desc tree;
467
void *data;
@@ -503,7 +503,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
503
for (i = 0; i < nr; i++) {
504
struct object *real_obj;
505
real_obj = deref_tag(list->objects[i].item, NULL, 0);
506
- if (grep_object(opt, pathspec, real_obj, list->objects[i].name)) {
506
+ if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].context)) {
507
hit = 1;
508
if (opt->status_only)
509
break;
@@ -820,12 +820,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
820
for (i = 0; i < argc; i++) {
821
const char *arg = argv[i];
822
unsigned char sha1[20];
823
+ struct object_context oc;
824
/* Is it a rev? */
824
- if (!get_sha1(arg, sha1)) {
825
+ if (!get_sha1_with_context(arg, 0, sha1, &oc)) {
826
struct object *object = parse_object_or_die(sha1, arg);
827
if (!seen_dashdash)
828
verify_non_filename(prefix, arg);
828
- add_object_array(object, arg, &list);
829
+ add_object_array_with_context(object, arg, &list, xmemdupz(&oc, sizeof(struct object_context)));
830
continue;
831
}
832
if (!strcmp(arg, "--")) {
object.c
+20
-6
@@ -255,12 +255,7 @@ int object_list_contains(struct object_list *list, struct object *obj)
255
return 0;
256
}
257
258
-void add_object_array(struct object *obj, const char *name, struct object_array *array)
259
-{
260
- add_object_array_with_mode(obj, name, array, S_IFINVALID);
261
-}
262
-
263
-void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode)
258
+static void add_object_array_with_mode_context(struct object *obj, const char *name, struct object_array *array, unsigned mode, struct object_context *context)
259
{
260
unsigned nr = array->nr;
261
unsigned alloc = array->alloc;
@@ -275,9 +270,28 @@ void add_object_array_with_mode(struct object *obj, const char *name, struct obj
270
objects[nr].item = obj;
271
objects[nr].name = name;
272
objects[nr].mode = mode;
273
+ objects[nr].context = context;
274
array->nr = ++nr;
275
}
276
277
+void add_object_array(struct object *obj, const char *name, struct object_array *array)
278
+{
279
+ add_object_array_with_mode(obj, name, array, S_IFINVALID);
280
+}
281
+
282
+void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode)
283
+{
284
+ add_object_array_with_mode_context(obj, name, array, mode, NULL);
285
+}
286
+
287
+void add_object_array_with_context(struct object *obj, const char *name, struct object_array *array, struct object_context *context)
288
+{
289
+ if (context)
290
+ add_object_array_with_mode_context(obj, name, array, context->mode, context);
291
+ else
292
+ add_object_array_with_mode_context(obj, name, array, S_IFINVALID, context);
293
+}
294
+
295
void object_array_remove_duplicates(struct object_array *array)
296
{
297
unsigned int ref, src, dst;
object.h
+2
@@ -13,6 +13,7 @@ struct object_array {
13
struct object *item;
14
const char *name;
15
unsigned mode;
16
+ struct object_context *context;
17
} *objects;
18
};
19
@@ -85,6 +86,7 @@ int object_list_contains(struct object_list *list, struct object *obj);
86
/* Object array handling .. */
87
void add_object_array(struct object *obj, const char *name, struct object_array *array);
88
void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode);
89
+void add_object_array_with_context(struct object *obj, const char *name, struct object_array *array, struct object_context *context);
90
void object_array_remove_duplicates(struct object_array *);
91
92
void clear_object_flags(unsigned flags);
t/t7008-grep-binary.sh
+1
-5
@@ -170,14 +170,10 @@ test_expect_success 'grep --no-textconv does not honor textconv' '
170
test_must_fail git grep --no-textconv Qfile
171
'
172
173
-test_expect_failure 'grep --textconv blob honors textconv' '
173
+test_expect_success 'grep --textconv blob honors textconv' '
174
echo "HEAD:a:binaryQfile" >expect &&
175
git grep --textconv Qfile HEAD:a >actual &&
176
test_cmp expect actual
177
'
178
179
-test_expect_success 'grep --no-textconv blob does not honor textconv' '
180
- test_must_fail git grep --no-textconv Qfile HEAD:a
181
-'
182
-
179
test_done