git-query

git data extraction tool using c and libgit2

git clone https://9o.is/git/git-query.git

commit 5d964e5c133c4ddb2ff27ab65506dff7886a875d
parent 6433f991566c8b36cad5906cedf9734f48166d50
Author: Jul <jul@9o.is>
Date:   Mon,  2 Mar 2026 16:48:56 +0800

git-query blob only returns raw content

Diffstat:
Mgit-query.1 | 5++++-
Mgit-query.c | 11++---------
2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/git-query.1 b/git-query.1 @@ -50,11 +50,14 @@ Each entry contains path, mode, type (blob/tree/commit), oid and size (for blobs .Ar path .Op Ar oid .Xc -Output blob (file content) in XML format. +Output raw file content to stdout. .Ar path is the path to the file relative to the repository root. .Ar oid can be specified to get the file at a specific commit. +Use the +.Cm tree +command to get the file oid and size. .It Xo .Cm refs .Ar repo diff --git a/git-query.c b/git-query.c @@ -533,7 +533,6 @@ print_blob(FILE *fp, const char *path, const char *oidstr) git_object *obj = NULL; git_blob *blob = NULL; git_oid id; - char oid[GIT_OID_HEXSZ + 1]; if (oidstr) { if (git_oid_fromstrn(&id, oidstr, strlen(oidstr))) @@ -550,16 +549,10 @@ print_blob(FILE *fp, const char *path, const char *oidstr) if (git_blob_lookup(&blob, repo, &id)) errx(1, "blob not found: %s", oidstr ? oidstr : path); - git_oid_tostr(oid, sizeof(oid), &id); - - fprintf(fp, "<blob oid=\"%s\" size=\"%zu\">\n", oid, git_blob_rawsize(blob)); - if (git_blob_is_binary(blob)) { - fputs("<binary/></blob>\n", fp); + fprintf(stderr, "warning: binary file, not outputting content\n"); } else { - fputs("<content>\n", fp); - xmlencodeline(fp, git_blob_rawcontent(blob), git_blob_rawsize(blob)); - fputs("</content></blob>\n", fp); + fwrite(git_blob_rawcontent(blob), 1, git_blob_rawsize(blob), fp); } git_blob_free(blob);