Skip to content

Commit

Permalink
Merge branch 'tc/cat-file-z-use-cquote' into seen
Browse files Browse the repository at this point in the history
* tc/cat-file-z-use-cquote:
  cat-file: quote-format name in error when using -z
  • Loading branch information
gitster committed May 10, 2023
2 parents 1633d8e + ec664ab commit 3077684
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
19 changes: 19 additions & 0 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "object-store-ll.h"
#include "replace-object.h"
#include "promisor-remote.h"
#include "quote.h"
#include "mailmap.h"
#include "write-or-die.h"

Expand Down Expand Up @@ -469,8 +470,17 @@ static void batch_object_write(const char *obj_name,
&data->oid, &data->info,
OBJECT_INFO_LOOKUP_REPLACE);
if (ret < 0) {
struct strbuf quoted = STRBUF_INIT;

if (opt->nul_terminated &&
obj_name) {
quote_c_style(obj_name, &quoted, NULL, 0);
obj_name = quoted.buf;
}

printf("%s missing\n",
obj_name ? obj_name : oid_to_hex(&data->oid));
strbuf_release(&quoted);
fflush(stdout);
return;
}
Expand Down Expand Up @@ -517,6 +527,13 @@ static void batch_one_object(const char *obj_name,
result = get_oid_with_context(the_repository, obj_name,
flags, &data->oid, &ctx);
if (result != FOUND) {
struct strbuf quoted = STRBUF_INIT;

if (opt->nul_terminated) {
quote_c_style(obj_name, &quoted, NULL, 0);
obj_name = quoted.buf;
}

switch (result) {
case MISSING_OBJECT:
printf("%s missing\n", obj_name);
Expand All @@ -541,6 +558,8 @@ static void batch_one_object(const char *obj_name,
result);
break;
}

strbuf_release(&quoted);
fflush(stdout);
return;
}
Expand Down
27 changes: 27 additions & 0 deletions t/t1006-cat-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,33 @@ test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '
test_cmp expect actual
'

test_expect_success '--batch-check, -z with newline in non-existent named object' '
printf "HEAD:newline${LF}missing" >in &&
git cat-file --batch-check -z <in >actual &&
printf "\"HEAD:newline\\\\nmissing\" missing\n" >expect &&
test_cmp expect actual
'

test_expect_success FUNNYNAMES '--batch-check, -z with missing object having newline in name' '
git init missing-object-newline &&
(
cd missing-object-newline &&
file="newline${LF}embedded" &&
echo_without_newline "hello" > $file &&
git add "$file" &&
git commit -m "file with newline embedded" &&
test_tick &&
sha1=$(git rev-parse HEAD:"$file") &&
rm .git/objects/$(test_oid_to_path $sha1) &&
printf "HEAD:$file" >in &&
git cat-file --batch-check -z <in >actual &&
printf "\"HEAD:newline\\\\nembedded\" missing\n" >expect &&
test_cmp expect actual
)
'

batch_command_multiple_info="info $hello_sha1
info $tree_sha1
info $commit_sha1
Expand Down

0 comments on commit 3077684

Please sign in to comment.