ref: 9b144a94e2e8cebf8082c8418ca3a7338c0677c1
parent: eacf9fbbee70d9effcc5b049f3c9e437979f50d5
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Oct 14 17:32:02 EDT 2023
git/query: allow arbitrary length queries
--- a/sys/src/cmd/git/query.c
+++ b/sys/src/cmd/git/query.c
@@ -152,8 +152,8 @@
void
main(int argc, char **argv)
{
- char query[2048], repo[512];
- char *p, *e, *s, *objpfx;
+ char *query, repo[512];
+ char *p, *e, *objpfx;
int i, j, n, nrel;
Hash *h;
@@ -176,15 +176,16 @@
sysfatal("chdir: %r");
if((objpfx = smprint("%s/.git/fs/object/", repo)) == nil)
sysfatal("smprint: %r");
- s = "";
+ for(i = 0, n = 0; i < argc; i++)
+ n += strlen(argv[i]) + 1;
+ query = emalloc(n+1);
p = query;
- e = query + nelem(query);
- for(i = 0; i < argc; i++){
- if((p = seprint(p, e, "%s%s", s, argv[i])) == nil)
- sysfatal("query too long");
- s = " ";
- }
- if((n = resolverefs(&h, query)) == -1)
+ e = query + n;
+ for(i = 0; i < argc; i++)
+ p = seprint(p, e, "%s ", argv[i]);
+ n = resolverefs(&h, query);
+ free(query);
+ if(n == -1)
sysfatal("resolve: %r");
if(changes){
for(i = 1; i < n; i++)