aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <thomas.voss@humanwave.nl> 2024-01-24 12:51:49 +0100
committerThomas Voss <thomas.voss@humanwave.nl> 2024-01-24 12:53:11 +0100
commitaa9f12ff8ea3fe215ef0a819cdd193e3088d9b86 (patch)
tree34650541f41f67b63c1a1f3f327ddd6792b83208
parent1547077f958bec62f64674ac7c83e8f7f89b0cc9 (diff)
Find files via git-grep instead of git-ls-files
It would be preferable to use git-ls-files as it is more suited for our purposes, however git-grep allows us to filter out binary files. It makes no sense to regex match in a binary file, so this is crucial.
-rw-r--r--man/grab.115
-rw-r--r--src/grab.c13
2 files changed, 13 insertions, 15 deletions
diff --git a/man/grab.1 b/man/grab.1
index ec03068..a5e3a32 100644
--- a/man/grab.1
+++ b/man/grab.1
@@ -1,4 +1,4 @@
-.Dd 23 January, 2024
+.Dd 24 January, 2024
.Dt GRAB 1
.Os Grab 2.1.1
.Sh NAME
@@ -46,14 +46,11 @@ utility in all ways except for two exceptions.
The first is that if no files
.Pq globs in this case to be precise
are specified,
-input is not read from the standard-input but instead all files returned
-by an invocation of
-.Xr git\-ls\-files 1
-are processed.
+input is not read from the standard-input but instead all non-binary
+files found in the current git-repository are processed.
If the user provides one or more globs,
-only the files returned by
-.Xr git\-ls\-files 1
-that match one or more of the given globs will be processed.
+only the non-binary files in the current git-repository that match one or
+more of the given globs will be processed.
Secondly, the
.Fl f
option is not available;
@@ -315,7 +312,7 @@ formatted manual pages:
.Pp
.Dl $ grab \-n 'x/^\e.Sh SYNOPSIS\en(^.*\en(?!^\e.Sh))+/' foo.1 bar.1
.Sh SEE ALSO
-.Xr git\-ls\-files 1 ,
+.Xr git 1 ,
.Xr grep 1 ,
.Xr pcre2syntax 3 ,
.Xr regex 7
diff --git a/src/grab.c b/src/grab.c
index 601d81e..300a787 100644
--- a/src/grab.c
+++ b/src/grab.c
@@ -804,7 +804,7 @@ getfstream(int argc, char *argv[argc])
case -1:
die("fork");
case 0:;
- size_t len = argc + 5;
+ size_t len = argc + 6;
char **args;
close(fds[FD_R]);
@@ -815,14 +815,15 @@ getfstream(int argc, char *argv[argc])
if (!(args = malloc(len * sizeof(char *))))
die("malloc");
args[0] = "git";
- args[1] = "ls-files";
- args[2] = "-z";
- args[3] = "--";
- memcpy(args + 4, argv, argc * sizeof(char *));
+ args[1] = "grep";
+ args[2] = "--cached";
+ args[3] = "-Ilz";
+ args[4] = "";
+ memcpy(args + 5, argv, argc * sizeof(char *));
args[len - 1] = nullptr;
execvp("git", args);
- die("execvp: git ls-files -z");
+ die("execvp: git grep --cached -Ilz ''");
}
close(fds[FD_W]);