From patchwork Mon Mar 11 18:56:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 13589226 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBD2354BCA for ; Mon, 11 Mar 2024 18:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710183368; cv=none; b=s6H9SGxprRGj1Vznfca89ojJzEfT51R8lJ21qvCLI99rP41nphkPCKNtVulS4pDiWcSEzP4OfOYevsNu5+21kk/xLa9vMV4CHkmFrOKm9ho3rEyl54WzJ7tLkZSgJ/Oe7P72q7pe5kN3X+HkZKGgTlbVWoQ27xS+r1zgwPP8ES8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710183368; c=relaxed/simple; bh=Q9mC0HVSU2O6KkbwKf/kvCMmLLxFf3tY5p4J3a87LA8=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=HVwXgfGW3o6pZr1TPQ1frEuI2GzhjM9pswjcqx3EptRhJKZUDN2gix8dpHvLk95v9JlxuOg0fTW8/gYUbpRTHUxcyBL6pLy/cF41+I5mBHtweD9rI170CRLwJgioimdyokmGte1uL6aceqrMhl5J7SJ+utTMO1Q6UyvCcM6gzUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QL+eyiff; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QL+eyiff" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-33e94c12cfaso1267458f8f.3 for ; Mon, 11 Mar 2024 11:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710183364; x=1710788164; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=DRdSL+V7jMot64FfpKDpV7DizO46WJ4pPaJ4th8i6HQ=; b=QL+eyiffXoQC/Mnz9LxutCoepfHn8Np/dkt89KN9kLKpzjr3i0J8L80EaeNe1TYaDK h9B38jo5XzMZgO5mfRoz0Qx8iAA/n7QXNDtZt/nyJoD1p6NGlsFGRhzgoc3VZJn4BBDz PcyMDvQTlfhucTpNwYdt8Q79KPsuN3ujPFuyexsyXgnHLbXBNeD+VDvo7UkCs7mgawHV 3p4+VzAqcTtz2wpr6LEXZvFwAICuhN7aifoYjtF63lN8VKIduW7GMAQ8U/6G2GcJqumG HxAJpr845+34Zf6akhXDTQEj9wX0m26pK5rygA/sTW6ILNdN1ZseMa8/2c61a2wMmljA ZEqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710183364; x=1710788164; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DRdSL+V7jMot64FfpKDpV7DizO46WJ4pPaJ4th8i6HQ=; b=vn/cVL3ocxFI+VKHSZqvMy1rdR0Z7ODj8vbcSlSPL6qMJEYHTHd94xwZJQic/vGo97 bzd/ASaKJDECiXXT2ad0AxILBIT4kP7zGtHDz4WW3+9Zi4/o/zQvPIF2Jb9tzpmpzYVk ItETbiAGrneDpELSetwq/d0f1FkdVgFwp+QtB+E5Gfa4n/TJZ3cijmwN7LO/0C1WmrJL xdv1pU6eTVFCqpitk5oJmAWG8hShD/P61XIddxQXlHrL69CuN+2VWBa7aegjAswoKNsI Ll7Xxij2UCqHc5e2Z7A4x4IZ1ERlRUfBc0G8nO+2gKOgkZeeLQpUCOisT5rmQbiGFasa 9HeQ== X-Gm-Message-State: AOJu0YyV775G4YquGs7r5y/4yuZUNjcfesz0bYxBSaeDl53G+sGumKJt NTVzJJaoPTg7J8tOahEUT8WUniAhwvgHCubN3h4LbPm8etoRbueKCVS4cWqo X-Google-Smtp-Source: AGHT+IF0tZH+XZEGK3wZZNVCNq/3KwiW4/uMy9A1DwWB9LidTrmfRW2Ez1Td9iDADywJNjObq9XT3w== X-Received: by 2002:adf:fc0c:0:b0:33e:a1ec:bb69 with SMTP id i12-20020adffc0c000000b0033ea1ecbb69mr185008wrr.40.1710183364212; Mon, 11 Mar 2024 11:56:04 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bo3-20020a056000068300b0033e9d0b3faasm1852807wrb.82.2024.03.11.11.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 11:56:03 -0700 (PDT) Message-ID: <765d7240311e145b43bbe40f00436f3854a4a177.1710183362.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 11 Mar 2024 18:56:00 +0000 Subject: [PATCH 1/3] t1006: update 'run_tests' to test generic object specifiers Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Victoria Dye From: Victoria Dye From: Victoria Dye Update the 'run_tests' test wrapper so that the first argument may refer to any specifier that uniquely identifies an object (e.g. a ref name, ':', '^{}', etc.), rather than only a full object ID. Also, add a test that uses a non-OID identifier, ensuring appropriate parsing in 'cat-file'. Signed-off-by: Victoria Dye Signed-off-by: Johannes Schindelin --- t/t1006-cat-file.sh | 46 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index e0c6482797e..ac1f754ee32 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -112,65 +112,66 @@ strlen () { run_tests () { type=$1 - sha1=$2 + object_name=$2 + oid=$(git rev-parse --verify $object_name) size=$3 content=$4 pretty_content=$5 - batch_output="$sha1 $type $size + batch_output="$oid $type $size $content" test_expect_success "$type exists" ' - git cat-file -e $sha1 + git cat-file -e $object_name ' test_expect_success "Type of $type is correct" ' echo $type >expect && - git cat-file -t $sha1 >actual && + git cat-file -t $object_name >actual && test_cmp expect actual ' test_expect_success "Size of $type is correct" ' echo $size >expect && - git cat-file -s $sha1 >actual && + git cat-file -s $object_name >actual && test_cmp expect actual ' test_expect_success "Type of $type is correct using --allow-unknown-type" ' echo $type >expect && - git cat-file -t --allow-unknown-type $sha1 >actual && + git cat-file -t --allow-unknown-type $object_name >actual && test_cmp expect actual ' test_expect_success "Size of $type is correct using --allow-unknown-type" ' echo $size >expect && - git cat-file -s --allow-unknown-type $sha1 >actual && + git cat-file -s --allow-unknown-type $object_name >actual && test_cmp expect actual ' test -z "$content" || test_expect_success "Content of $type is correct" ' echo_without_newline "$content" >expect && - git cat-file $type $sha1 >actual && + git cat-file $type $object_name >actual && test_cmp expect actual ' test_expect_success "Pretty content of $type is correct" ' echo_without_newline "$pretty_content" >expect && - git cat-file -p $sha1 >actual && + git cat-file -p $object_name >actual && test_cmp expect actual ' test -z "$content" || test_expect_success "--batch output of $type is correct" ' echo "$batch_output" >expect && - echo $sha1 | git cat-file --batch >actual && + echo $object_name | git cat-file --batch >actual && test_cmp expect actual ' test_expect_success "--batch-check output of $type is correct" ' - echo "$sha1 $type $size" >expect && - echo_without_newline $sha1 | git cat-file --batch-check >actual && + echo "$oid $type $size" >expect && + echo_without_newline $object_name | git cat-file --batch-check >actual && test_cmp expect actual ' @@ -179,33 +180,33 @@ $content" test -z "$content" || test_expect_success "--batch-command $opt output of $type content is correct" ' echo "$batch_output" >expect && - test_write_lines "contents $sha1" | git cat-file --batch-command $opt >actual && + test_write_lines "contents $object_name" | git cat-file --batch-command $opt >actual && test_cmp expect actual ' test_expect_success "--batch-command $opt output of $type info is correct" ' - echo "$sha1 $type $size" >expect && - test_write_lines "info $sha1" | + echo "$oid $type $size" >expect && + test_write_lines "info $object_name" | git cat-file --batch-command $opt >actual && test_cmp expect actual ' done test_expect_success "custom --batch-check format" ' - echo "$type $sha1" >expect && - echo $sha1 | git cat-file --batch-check="%(objecttype) %(objectname)" >actual && + echo "$type $oid" >expect && + echo $object_name | git cat-file --batch-check="%(objecttype) %(objectname)" >actual && test_cmp expect actual ' test_expect_success "custom --batch-command format" ' - echo "$type $sha1" >expect && - echo "info $sha1" | git cat-file --batch-command="%(objecttype) %(objectname)" >actual && + echo "$type $oid" >expect && + echo "info $object_name" | git cat-file --batch-command="%(objecttype) %(objectname)" >actual && test_cmp expect actual ' test_expect_success '--batch-check with %(rest)' ' echo "$type this is some extra content" >expect && - echo "$sha1 this is some extra content" | + echo "$object_name this is some extra content" | git cat-file --batch-check="%(objecttype) %(rest)" >actual && test_cmp expect actual ' @@ -216,7 +217,7 @@ $content" echo "$size" && echo "$content" } >expect && - echo $sha1 | git cat-file --batch="%(objectsize)" >actual && + echo $object_name | git cat-file --batch="%(objectsize)" >actual && test_cmp expect actual ' @@ -226,7 +227,7 @@ $content" echo "$type" && echo "$content" } >expect && - echo $sha1 | git cat-file --batch="%(objecttype)" >actual && + echo $object_name | git cat-file --batch="%(objecttype)" >actual && test_cmp expect actual ' } @@ -271,6 +272,7 @@ tree_size=$(($(test_oid rawsz) + 13)) tree_pretty_content="100644 blob $hello_sha1 hello${LF}" run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content" +run_tests 'blob' "$tree_sha1:hello" $hello_size "" "$hello_content" commit_message="Initial commit" commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1) From patchwork Mon Mar 11 18:56:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 13589227 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 122C55467F for ; Mon, 11 Mar 2024 18:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710183369; cv=none; b=YowSBrUHIFg1kQhFfxX3Y5dKQJ4u5Q7CKlEu36HsqCb69BqcZeHc6FfASw6q61yyl+ywgXv6mr3RejKg/Uvr+eigRa0OICv+xO8Q8783OI+Se/OuOsITBdz1W6Y8DxFGG5UoakPaEnC+Kbjwra1nmssBuAC91rBVZ3yKDePfebc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710183369; c=relaxed/simple; bh=EHNLXjZ6w5iAQ44bkpBjN7PUZM4qCN//PuNIpDa8DQQ=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=oWEMacwtCfR3gUzQ1KLRpQ77haFTEEfog54llMNJND/Y9L3P4BfKWIMyRNY4Bp8eZ6YO5LFppQ6LtZqYVPow6G0cnW2xluiXPE+RdCEl0arJMZ7kBdWAtxaMnkvTOu8t6TDriN93tyWUu0lD+Ufs6LwvK43z3NXR1EdEd1+RPUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f7N5zKms; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f7N5zKms" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-413328344acso313065e9.3 for ; Mon, 11 Mar 2024 11:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710183366; x=1710788166; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=EJYITVq5DxLpd/LY3SAUdz00h5C/RPNtpMlH5+xQBys=; b=f7N5zKmsM7suTI7nMf8Iah8W8zv4UHlwe+DsZAy/qfOddNCXQnnebpYcV1rbMuLJjM 9Hme4L/enAbciDaNYo8hkwClk/X8lKr9cYROZDyV5cMLJfpzqic7E4jQEHnpT+lZu750 DBuuoGftOgjrBiiXVX9jywVKdWicHmjPiKmJDP3BFeCwMzSt2uvnKhcsdUT1FkUFWDc/ hfqonoahPd9xsYXQbV93g6E96AbzEXXnWe+SG8ItFdHuwb//n8zvaLdLPvNElUudImqJ 2A6FUkKN4/ryRzG3xYCGlWsmbWpGnddqA5YamfTqsXX18ZSP/V8wguGhsJcwWPIGOTkj 5wMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710183366; x=1710788166; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EJYITVq5DxLpd/LY3SAUdz00h5C/RPNtpMlH5+xQBys=; b=m64zQ+w2LxqRFhMOSWsBEU4YftjuEkHe9vr/ZIoqPAyxryRR0qnxIFFJShuU2Mcd93 zMhLYu6NnAXu3/ZS0FnBQeh8TU14CKR2nXqqkZNnFKpwioHtfdEgefVKwjE9EPMKzLCY F/gz2zy1UNgXTMa210/tIIucRUt2QBr+J85wDvWbzeP32N1oeHmVEsIV7qj9MRNawHk7 1oo+GgV9dGpnKE7up/SvZLZ9xoM39COlXf/R2IanrbB+NOXt1oyruUGK4TCizOHec0VH YRBUWn/cNyJ49vCqBNpcHKWQZGEvMtEBQi7fVhe8w0wZppLlKQ8fBCWFKe1gPc1BIbMU uvaA== X-Gm-Message-State: AOJu0YzajQe0euG1k7MgLHizePABYK4E1vMkCW8/4lWz+AOh84rlOx/q WcN5QS16wV6ep/JtL5BxoWb+ViOuqfkfi/5PSt1sU2BPX4I45dE4CPHmuju7 X-Google-Smtp-Source: AGHT+IHqHT9Ll/RzwyDQXAfo1gzqE2n1Kn4xOnhr1u4Rg/WBsbbDSVXT+QDNR74H74NJnML8fUPE8g== X-Received: by 2002:a05:600c:35d4:b0:413:7f3:8d5 with SMTP id r20-20020a05600c35d400b0041307f308d5mr5096677wmq.0.1710183365614; Mon, 11 Mar 2024 11:56:05 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bo5-20020a056000068500b0033e7e9c8657sm7065667wrb.45.2024.03.11.11.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 11:56:04 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Mon, 11 Mar 2024 18:56:01 +0000 Subject: [PATCH 2/3] cat-file: add %(objectmode) atom Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Victoria Dye From: Victoria Dye From: Victoria Dye Add a formatting atom, used with the --batch-check/--batch-command options, that prints the octal representation of the object mode if a given revision includes that information, e.g. one that follows the format :. If the mode information does not exist, an empty string is printed instead. Signed-off-by: Victoria Dye Signed-off-by: Johannes Schindelin --- Documentation/git-cat-file.txt | 5 +++++ builtin/cat-file.c | 9 +++++++-- t/t1006-cat-file.sh | 23 +++++++++++++++-------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt index bd95a6c10a7..de29e6d79d9 100644 --- a/Documentation/git-cat-file.txt +++ b/Documentation/git-cat-file.txt @@ -292,6 +292,11 @@ newline. The available atoms are: `objecttype`:: The type of the object (the same as `cat-file -t` reports). +`objectmode`:: + If the specified object has mode information (such as a tree or + index entry), the mode expressed as an octal integer. Otherwise, + empty string. + `objectsize`:: The size, in bytes, of the object (the same as `cat-file -s` reports). diff --git a/builtin/cat-file.c b/builtin/cat-file.c index bbf851138ec..73bd78c0b63 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -272,6 +272,7 @@ struct expand_data { struct object_id oid; enum object_type type; unsigned long size; + unsigned short mode; off_t disk_size; const char *rest; struct object_id delta_base_oid; @@ -303,6 +304,7 @@ struct expand_data { */ unsigned skip_object_info : 1; }; +#define EXPAND_DATA_INIT { .mode = S_IFINVALID } static int is_atom(const char *atom, const char *s, int slen) { @@ -342,6 +344,9 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len, else strbuf_addstr(sb, oid_to_hex(&data->delta_base_oid)); + } else if (is_atom("objectmode", atom, len)) { + if (!data->mark_query && !(S_IFINVALID == data->mode)) + strbuf_addf(sb, "%06o", data->mode); } else die("unknown format element: %.*s", len, atom); } @@ -562,6 +567,7 @@ static void batch_one_object(const char *obj_name, return; } + data->mode = ctx.mode; batch_object_write(obj_name, scratch, opt, data, NULL, 0); } @@ -766,7 +772,7 @@ static int batch_objects(struct batch_options *opt) { struct strbuf input = STRBUF_INIT; struct strbuf output = STRBUF_INIT; - struct expand_data data; + struct expand_data data = EXPAND_DATA_INIT; int save_warning; int retval = 0; @@ -775,7 +781,6 @@ static int batch_objects(struct batch_options *opt) * object_info to be handed to oid_object_info_extended for each * object. */ - memset(&data, 0, sizeof(data)); data.mark_query = 1; expand_format(&output, opt->format ? opt->format : DEFAULT_FORMAT, diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index ac1f754ee32..6f25cc20ec6 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -114,9 +114,10 @@ run_tests () { type=$1 object_name=$2 oid=$(git rev-parse --verify $object_name) - size=$3 - content=$4 - pretty_content=$5 + mode=$3 + size=$4 + content=$5 + pretty_content=$6 batch_output="$oid $type $size $content" @@ -211,6 +212,12 @@ $content" test_cmp expect actual ' + test_expect_success '--batch-check with %(objectmode)' ' + echo "$mode $oid" >expect && + echo $object_name | git cat-file --batch-check="%(objectmode) %(objectname)" >actual && + test_cmp expect actual + ' + test -z "$content" || test_expect_success "--batch without type ($type)" ' { @@ -241,7 +248,7 @@ test_expect_success "setup" ' git update-index --add hello ' -run_tests 'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content" +run_tests 'blob' $hello_sha1 "" $hello_size "$hello_content" "$hello_content" test_expect_success '--batch-command --buffer with flush for blob info' ' echo "$hello_sha1 blob $hello_size" >expect && @@ -271,8 +278,8 @@ tree_sha1=$(git write-tree) tree_size=$(($(test_oid rawsz) + 13)) tree_pretty_content="100644 blob $hello_sha1 hello${LF}" -run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content" -run_tests 'blob' "$tree_sha1:hello" $hello_size "" "$hello_content" +run_tests 'tree' $tree_sha1 "" $tree_size "" "$tree_pretty_content" +run_tests 'blob' "$tree_sha1:hello" "100644" $hello_size "" "$hello_content" commit_message="Initial commit" commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1) @@ -283,7 +290,7 @@ committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE $commit_message" -run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" +run_tests 'commit' $commit_sha1 "" $commit_size "$commit_content" "$commit_content" tag_header_without_timestamp="object $hello_sha1 type blob @@ -297,7 +304,7 @@ $tag_description" tag_sha1=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w) tag_size=$(strlen "$tag_content") -run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" +run_tests 'tag' $tag_sha1 "" $tag_size "$tag_content" "$tag_content" test_expect_success "Reach a blob from a tag pointing to it" ' echo_without_newline "$hello_content" >expect && From patchwork Mon Mar 11 18:56:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13589228 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46D3356B70 for ; Mon, 11 Mar 2024 18:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710183371; cv=none; b=YRaXqqd0ynF6xLyfON+eFpWe8Eq1yH5Y5ncMp2ccGsa7HhpWCjZ/YtVWDUgMD/CLEW6q+5edOr3FJ+zFMNMpgxyGO9G0isyQ1NTvnLoFhPjdgMkI7wBkVSu1tJaHP6T+fR+u4BYI8RgdZajV6djtBHxH8QSuczXCS9rIPRwhLOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710183371; c=relaxed/simple; bh=B0UK4xFeT/+jAnON+ggJ0ncjHxbPSK/Dq2087FliE9g=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=a+wymOb1nEkcihn5uQQwi1+mxyL4pkAxnxZPgYIkJhv6gZHjWt4cmQRJ83awYTpWtSrytmws1U/ZpCPnXqx6jILP7I+Vg+gaqf6h8GS8ZjoqoxR3iYRuusw7kygeNON01+sBPOljIj+NSsF2PNIaWojHJyZp64oKIpV05CV2gDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HT8ceJCK; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HT8ceJCK" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4132f780ee2so4869245e9.0 for ; Mon, 11 Mar 2024 11:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710183367; x=1710788167; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=KiNmcppLSuZ3kX5OqT4X52QIqiQ8P8ajK3HwdVXTiMM=; b=HT8ceJCKVlTiefaYgpCpgicjLlCC+r76nkstmFeQGSID8kX2PdD6ODdu+GCfvk81aR zKx8tgyrDRAix/rxTpiQu5lQmCyK9Zldh7sjwpYZ/zTLMX3fUnENpWd2Zsn2OopgHe/t YhD3jBS5AalSLc539ujgMgKtE56AhysoGlhcIFl8g6zpyDPcCsAcqKlOX+a/HDsNVDNv ME/LQxPXD4r/cBQ8w+g5x7k+2GdgWYobHtfhaCi09F2JYJ8UWILIcARcyvLQEXDDV1jk JnfNdZ6CZH1Uf24UeMj5ormoUWkK0/7vwdLCRQxywYA0P1Dda0vmwr/EK2vVrVj9Un1e w/MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710183367; x=1710788167; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KiNmcppLSuZ3kX5OqT4X52QIqiQ8P8ajK3HwdVXTiMM=; b=D+F01aTJCbh5PCt8+6dLkqNa9h3/2PvS1AQGlU0w/mbdkD32lneFn7WRuVW++m7dIP shmQTOpP88dxbNuesnL0ImfulXyHcjXaa0/lHVweppHB/7PfLYvX9/oU8gdrsnbvORtt UtimKjnHYTr/Er1hgLIGiccQqJVTjWyglp4z8QIfJIHay/21zisJrBlZ7naLtiaXB95q 7i7l84W15vNs6yz7xFw0KlJVNmEI6T722iC8SBKR4z/5JLfq8MxkE7ehpRj7wfqtPtuB THjcPE2Lq5FfZPofRLEQcz9yWG0/9mTbnPf+WH9NEcgqPLnpnSHizwO67jol07mib/sc 5NQw== X-Gm-Message-State: AOJu0Yw4NC9JyPuwSFBK7Cm1q1/ZQY8P0DX4Toonqc0wMyK1Of7Z5TtX qFQiuG5l6yLHJgHp0JVLOwYy/g8m+I8BfW0UL4keLd3MOdo7Q+yd30YhimQ5 X-Google-Smtp-Source: AGHT+IEQdIyiD9t4oGoKpcrvH+XGXQ37IfzR94vy/+QFZK4fSbPGM8XkTG1zUr9InPBfWn1+4xY1wQ== X-Received: by 2002:a05:600c:4fce:b0:412:e444:133a with SMTP id o14-20020a05600c4fce00b00412e444133amr6795611wmq.20.1710183366164; Mon, 11 Mar 2024 11:56:06 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o27-20020a5d58db000000b0033d640c8942sm7093378wrf.10.2024.03.11.11.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 11:56:05 -0700 (PDT) Message-ID: <951f73397c15f76da75bbd74a02f36da0116623f.1710183362.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 11 Mar 2024 18:56:02 +0000 Subject: [PATCH 3/3] cat-file: avoid verifying submodules' OIDs Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin Submodules are strange creatures. They have OIDs, but the corresponding objects are not expected to be present in the current directory. Let's teach `cat-file` about this: This command should not even attempt to look up those objects, let alone declare them "missing". Signed-off-by: Johannes Schindelin --- Documentation/git-cat-file.txt | 5 +++++ builtin/cat-file.c | 32 ++++++++++++++++++++++++++------ t/t1006-cat-file.sh | 10 ++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt index de29e6d79d9..69b50d2042f 100644 --- a/Documentation/git-cat-file.txt +++ b/Documentation/git-cat-file.txt @@ -412,6 +412,11 @@ Note also that multiple copies of an object may be present in the object database; in this case, it is undefined which copy's size or delta base will be reported. +Submodules are handled specially in `git cat-file`, as the objects +corresponding to the recorded OIDs are not expected to be present in the +current repository. For that reason, submodules are reported as having +type `submodule` and mode 1600000 and all other fields are zeroed out. + GIT --- Part of the linkgit:git[1] suite diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 73bd78c0b63..c59ad682d1f 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -128,7 +128,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, switch (opt) { case 't': oi.type_name = &sb; - if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0) + if (obj_context.mode == S_IFGITLINK) + strbuf_addstr(&sb, "submodule"); + else if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0) die("git cat-file: could not get object info"); if (sb.len) { printf("%s\n", sb.buf); @@ -319,17 +321,26 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len, if (!data->mark_query) strbuf_addstr(sb, oid_to_hex(&data->oid)); } else if (is_atom("objecttype", atom, len)) { - if (data->mark_query) + if (data->mode == S_IFGITLINK) { + if (!data->mark_query) + strbuf_addstr(sb, "submodule"); + } else if (data->mark_query) data->info.typep = &data->type; else strbuf_addstr(sb, type_name(data->type)); } else if (is_atom("objectsize", atom, len)) { - if (data->mark_query) + if (data->mode == S_IFGITLINK) { + if (!data->mark_query) + strbuf_addstr(sb, "0"); + } else if (data->mark_query) data->info.sizep = &data->size; else strbuf_addf(sb, "%"PRIuMAX , (uintmax_t)data->size); } else if (is_atom("objectsize:disk", atom, len)) { - if (data->mark_query) + if (data->mode == S_IFGITLINK) { + if (!data->mark_query) + strbuf_addstr(sb, "0"); + } else if (data->mark_query) data->info.disk_sizep = &data->disk_size; else strbuf_addf(sb, "%"PRIuMAX, (uintmax_t)data->disk_size); @@ -448,7 +459,8 @@ static void print_default_format(struct strbuf *scratch, struct expand_data *dat struct batch_options *opt) { strbuf_addf(scratch, "%s %s %"PRIuMAX"%c", oid_to_hex(&data->oid), - type_name(data->type), + data->mode == S_IFGITLINK ? + "submodule" : type_name(data->type), (uintmax_t)data->size, opt->output_delim); } @@ -470,7 +482,15 @@ static void batch_object_write(const char *obj_name, if (use_mailmap) data->info.typep = &data->type; - if (pack) + if (data->mode == S_IFGITLINK) { + data->type = OBJ_BAD; /* `type_name()` does not know submodules */ + data->size = 0; + data->disk_size = 0; + data->rest = NULL; + oidcpy(&data->delta_base_oid, null_oid()); + memset(&data->info, 0, sizeof(data->info)); + ret = 0; /* no info to look up */ + } else if (pack) ret = packed_object_info(the_repository, pack, offset, &data->info); else diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 6f25cc20ec6..3368b663ef3 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -1178,6 +1178,16 @@ test_expect_success 'cat-file --batch-check respects replace objects' ' test_cmp expect actual ' +test_expect_success 'batch-command with a submodule' ' + printf "160000 commit %0.*d\tsub\n" $(test_oid hexsz) 17 >tree-with-sub && + tree=$(git mktree actual <<-EOF && + $tree:sub + EOF + printf "%0.*d submodule 0\n" $(test_oid hexsz) 17 >expect && + test_cmp expect actual +' + # Pull the entry for object with oid "$1" out of the output of # "cat-file --batch", including its object content (which requires # parsing and reading a set amount of bytes, hence perl).