393
exit(status);
394
}
395
396
-static int grep_cache(struct grep_opt *opt, struct repository *repo,
396
+static int grep_cache(struct grep_opt *opt,
397
const struct pathspec *pathspec, int cached);
398
static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
399
struct tree_desc *tree, struct strbuf *base, int tn_len,
400
- int check_attr, struct repository *repo);
400
+ int check_attr);
401
402
-static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
402
+static int grep_submodule(struct grep_opt *opt,
403
const struct pathspec *pathspec,
404
const struct object_id *oid,
405
const char *filename, const char *path)
406
{
407
+ struct repository *superproject = opt->repo;
408
struct repository submodule;
409
+ struct grep_opt subopt;
410
int hit;
411
412
/*
442
add_to_alternates_memory(submodule.objects->odb->path);
443
grep_read_unlock();
444
445
+ memcpy(&subopt, opt, sizeof(subopt));
446
+ subopt.repo = &submodule;
447
+
448
if (oid) {
449
struct object *object;
450
struct tree_desc tree;
466
strbuf_addch(&base, '/');
467
468
init_tree_desc(&tree, data, size);
464
- hit = grep_tree(opt, pathspec, &tree, &base, base.len,
465
- object->type == OBJ_COMMIT, &submodule);
469
+ hit = grep_tree(&subopt, pathspec, &tree, &base, base.len,
470
+ object->type == OBJ_COMMIT);
471
strbuf_release(&base);
472
free(data);
473
} else {
469
- hit = grep_cache(opt, &submodule, pathspec, 1);
474
+ hit = grep_cache(&subopt, pathspec, 1);
475
}
476
477
repo_clear(&submodule);
478
return hit;
479
}
480
476
-static int grep_cache(struct grep_opt *opt, struct repository *repo,
481
+static int grep_cache(struct grep_opt *opt,
482
const struct pathspec *pathspec, int cached)
483
{
484
+ struct repository *repo = opt->repo;
485
int hit = 0;
486
int nr;
487
struct strbuf name = STRBUF_INIT;
519
}
520
} else if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
521
submodule_path_match(repo->index, pathspec, name.buf, NULL)) {
516
- hit |= grep_submodule(opt, repo, pathspec, NULL, ce->name, ce->name);
522
+ hit |= grep_submodule(opt, pathspec, NULL, ce->name, ce->name);
523
} else {
524
continue;
525
}
541
542
static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
543
struct tree_desc *tree, struct strbuf *base, int tn_len,
538
- int check_attr, struct repository *repo)
544
+ int check_attr)
545
{
546
+ struct repository *repo = opt->repo;
547
int hit = 0;
548
enum interesting match = entry_not_interesting;
549
struct name_entry entry;
589
strbuf_addch(base, '/');
590
init_tree_desc(&sub, data, size);
591
hit |= grep_tree(opt, pathspec, &sub, base, tn_len,
585
- check_attr, repo);
592
+ check_attr);
593
free(data);
594
} else if (recurse_submodules && S_ISGITLINK(entry.mode)) {
588
- hit |= grep_submodule(opt, repo, pathspec, entry.oid,
595
+ hit |= grep_submodule(opt, pathspec, entry.oid,
596
base->buf, base->buf + tn_len);
597
}
598
634
}
635
init_tree_desc(&tree, data, size);
636
hit = grep_tree(opt, pathspec, &tree, &base, base.len,
630
- obj->type == OBJ_COMMIT, the_repository);
637
+ obj->type == OBJ_COMMIT);
638
strbuf_release(&base);
639
free(data);
640
return hit;
651
652
for (i = 0; i < nr; i++) {
653
struct object *real_obj;
647
- real_obj = deref_tag(the_repository, list->objects[i].item,
654
+ real_obj = deref_tag(opt->repo, list->objects[i].item,
655
NULL, 0);
656
657
/* load the gitmodules file for this rev */
658
if (recurse_submodules) {
652
- submodule_free(the_repository);
659
+ submodule_free(opt->repo);
660
gitmodules_config_oid(&real_obj->oid);
661
}
662
if (grep_object(opt, pathspec, real_obj, list->objects[i].name,
681
if (exc_std)
682
setup_standard_excludes(&dir);
683
677
- fill_directory(&dir, &the_index, pathspec);
684
+ fill_directory(&dir, opt->repo->index, pathspec);
685
for (i = 0; i < dir.nr; i++) {
679
- if (!dir_path_match(&the_index, dir.entries[i], pathspec, 0, NULL))
686
+ if (!dir_path_match(opt->repo->index, dir.entries[i], pathspec, 0, NULL))
687
continue;
688
hit |= grep_file(opt, dir.entries[i]->name);
689
if (hit && opt->status_only)
1124
if (!cached)
1125
setup_work_tree();
1126
1120
- hit = grep_cache(&opt, the_repository, &pathspec, cached);
1127
+ hit = grep_cache(&opt, &pathspec, cached);
1128
} else {
1129
if (cached)
1130
die(_("both --cached and trees are given"));