Skip to contentSkip to conversation

repo: support category-based prefix querying for info keys

PATCH In review K Jayatheerth 2 participants 3 messages Jul 3 – Jul 12 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 repo: support category-based prefix querying for info keys

Currently, git repo info relies on an all-or-nothing query model where users must either know the exact, fully-qualified key name or use the --all flag to dump the entire repository state.
As the number of supported keys expands, dumping all metadata and relying on external filters like grep becomes an inefficient bottleneck for a plumbing command.

Enable category-based prefix querying so users can request entire groups of related keys natively

---
Hi!

This patch adds category-based prefix querying to
git repo info as part of my GSoC project.
A quick note on the implementation: I replaced the bsearch with a linear search to find the initial prefix match.
I discussed this with my mentors, and we decided to fall back to a linear search because the overhead of a custom binary search (to find the *first* match in a block) wasn't justified given the currently small size of the repo_info_field array.

Since the array is strictly sorted alphabetically, the loop safely short-circuits via strncmp once it steps outside the matching prefix block.

Looking forward to feedback!

 Documentation/git-repo.adoc | 12 ++++++++
 builtin/repo.c              | 58 +++++++++++++++++++++++--------------
 t/t1900-repo-info.sh        | 16 ++++++++++
 3 files changed, 64 insertions(+), 22 deletions(-)
Documentation/git-repo.adoc +12 -0
index 42262c1983..3e840d6323 100644
@@ -25,6 +25,12 @@ COMMANDS
 	the requested data will be returned based on their keys (see "INFO KEYS"
 	section below).
 +
+If a `<key>` argument matches a category prefix (i.e. a namespace that ends at
+a `.` boundary), all keys within that namespace are returned. For example,
+`layout` returns both `layout.bare` and `layout.shallow`. The prefix must
+align with a namespace boundary; partial prefixes that do not end at a `.`
+separator (e.g. `lay`) are treated as unknown keys and will produce an error.
++
 The values are returned in the same order in which their respective keys were
 requested. The `--all` flag requests the values for all the available keys.
 +
@@ -126,6 +132,12 @@ using the `nul` format:
 git repo info --format=nul layout.bare layout.shallow
 ------------
 
+* Retrieves all keys under the `layout` category prefix:
++
+------------
+git repo info layout
+------------
+
 SEE ALSO
 --------
 linkgit:git-rev-parse[1]
builtin/repo.c +36 -22

77 lines not on this page · raw message

t/t1900-repo-info.sh +16 -0
index 39bb77dda0..80ae8f8396 100755
@@ -149,6 +149,22 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
 	test_cmp expect actual
 '
 
+test_expect_success 'git repo info with category prefix returns all keys in namespace' '
+	cat >expect <<-\EOF &&
+	layout.bare=false
+	layout.shallow=false
+	EOF
+	git init prefix-repo &&
+	git -C prefix-repo repo info layout >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'git repo info with invalid partial boundary fails' '
+	echo "error: key ${SQ}lay${SQ} not found" >expect &&
+	test_must_fail git -C prefix-repo repo info lay 2>actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'git repo info -h shows only repo info usage' '
 	test_must_fail git repo info -h >actual &&
 	test_grep "git repo info" actual &&
Signature · 1 line
2.55.0-rc1
#1 lore raw
Quoted 9 lines · K Jayatheerth

Currently, git repo info relies on an all-or-nothing query model where users must either know the exact, fully-qualified key name or use the --all flag to dump the entire repository state.
As the number of supported keys expands, dumping all metadata and relying on external filters like grep becomes an inefficient bottleneck for a plumbing command.

Enable category-based prefix querying so users can request entire groups of related keys natively

You mean "repo info" takes layout.bare and layout.shallow (right now, later we may gain a lot more), so you want to say "everything under 'layout' to grab these two values?

Why should we limit ourselves to "prefix match"? Would a glob like "layout.*", or "path.*.absolute", work better? Especially the latter, i.e., "I want the path variables, but am not interested in their .relative values, only the .absolute ones." It is especially puzzling as you are going to do a dumb linear search in this mode anyway.

Perhaps during each iteration of the loop over argv[], you can first look for exact match using the existing bsearch() codepath. If that succeeds, you have a single key to return the value for. If it does not match exactly any key, use the new "prefix" (or "glob" which I think would make far more sense) match codepath to find which key(s) to return values for, so iterate over them (or say "Hey, that pattern does not match any key!" and fail).

#2 lore raw

Hey Junio,

Quoted 12 lines · Junio C Hamano

You mean "repo info" takes layout.bare and layout.shallow (right now, later we may gain a lot more), so you want to say "everything under 'layout' to grab these two values?

Why should we limit ourselves to "prefix match"? Would a glob like "layout.*", or "path.*.absolute", work better? Especially the latter, i.e., "I want the path variables, but am not interested in their .relative values, only the .absolute ones." It is especially puzzling as you are going to do a dumb linear search in this mode anyway.

Quoted 7 lines

Perhaps during each iteration of the loop over argv[], you can first look for exact match using the existing bsearch() codepath. If that succeeds, you have a single key to return the value for. If it does not match exactly any key, use the new "prefix" (or "glob" which I think would make far more sense) match codepath to find which key(s) to return values for, so iterate over them (or say "Hey, that pattern does not match any key!" and fail).

Sorry this response took a long time but I have given a good thought about this You are right that adding globs makes much more sense in this case. I was initially skeptical about globs, but looking at the direction we took in path.* keys it makes much more sense.

But I think adding a query system is not a good idea anymore.
I have discussed this with my mentors at length.
Since we are building a plumbing command, we couldn't think of a use-case where people would need globs over hard-coded value in scripts.
Also globing might introduce uncertainties if the script doesn't have an appropriate fall back.
I am also wondering if there will be any significant performance difference with --all vs globs.

A query system in itself is meant to simplify commands for user usage, but I don't think adding it makes sense "yet".

I also wanted your opinion on this

For my GSoC I can pick the histograms patch in the git repo structure instead of this.

Regards,
- K Jayatheerth