From patchwork Mon Nov 15 11:51:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teng Long X-Patchwork-Id: 12619353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DC7BC433FE for ; Mon, 15 Nov 2021 11:52:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A9D461A3D for ; Mon, 15 Nov 2021 11:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231135AbhKOLz2 (ORCPT ); Mon, 15 Nov 2021 06:55:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbhKOLzU (ORCPT ); Mon, 15 Nov 2021 06:55:20 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 025A8C061746 for ; Mon, 15 Nov 2021 03:52:25 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so12819345pju.3 for ; Mon, 15 Nov 2021 03:52:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4FOfgjijEYdrq3Jcj+ZM3LdOuqFpmG74kxtUzYxw9AY=; b=deix1zH8vCuyL9QVMcgopPw/w8pAbK9w/wLNg/KgLKycT7MSOIeF2G+Qt5ABII79mV kdGLtURNjb1SwkeHP1vnlI6oZw07gPDW2dL6wH0yDoNyj9eEK2pKA1JgpvlfEM5DOAv/ HmrO35VwC2o5/RaAyTQj8B/8KYzrChu8tmpfGfeVVxXNhZAVxhNHngSrF4UYqDblRpaC ueAQVHyPPTzUZz7SGib0eZU1j20462pnJ9kPbboME3levNdz9WiJtjv8bqMzi+JIa+M1 ggO9LRMHvnHWXQ4uycO9F0T5bkIASy7CEoca2oHJlWopYbJZpqcC+++PDUqG5TiACCHm PvrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4FOfgjijEYdrq3Jcj+ZM3LdOuqFpmG74kxtUzYxw9AY=; b=fDVQrulnLj/GSl1K/ZBHzTSntY1QDOigukbBaWYc5oL+AEOWwFfUAfNTkjmdyeNq4s BwnJS36ZVA/3tVBYyR2ud/AphFQKgAi5xvZGqLZTviK6AZiqPMOhW1M47cxpuhfVhJP8 f7senavqH5oktJd9Ff6reGD2rVIILOSN7luDYZnNSMU9GOddUIZwwOw3vCykbUk6qt+K ALl4JZMDUhH1BdYg9LEDD6pOVJSXOikZC/VpFMmWbhzz/VDnCz4hyiOyHjECW54VV5j2 rgsV0dScZWuMFSeISBgUt6ayziQIhTKv7B1n+BjHd0ic9Zprmz27wnYhHVRcjmp3GvVD WjFw== X-Gm-Message-State: AOAM533IwjEdXTSGlCRv/PC9Ow+AXAZrSrxnCsqy1k5wW2I9YLubWPm+ zIal1Ujw8SZI3pnS5viyXJ0N6tAB1dOqLA== X-Google-Smtp-Source: ABdhPJwSF7tPB5NOGgMes2csOHJnr/FGjTKYYrCXoc+PGGIZzV+4zbOMaCl7uFSUqRJTaNS7a+efNg== X-Received: by 2002:a17:90b:4f83:: with SMTP id qe3mr64463135pjb.56.1636977144314; Mon, 15 Nov 2021 03:52:24 -0800 (PST) Received: from localhost.localdomain ([205.204.117.98]) by smtp.gmail.com with ESMTPSA id s2sm17543280pfg.124.2021.11.15.03.52.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Nov 2021 03:52:24 -0800 (PST) From: Teng Long To: git@vger.kernel.org Cc: gitster@pobox.com, peff@peff.net, Teng Long Subject: [PATCH 1/3] ls-tree.c: support `--oid-only` option for "git-ls-tree" Date: Mon, 15 Nov 2021 19:51:51 +0800 Message-Id: <20211115115153.48307-2-dyroneteng@gmail.com> X-Mailer: git-send-email 2.33.1.9.g5fbd2fc599.dirty In-Reply-To: <20211115115153.48307-1-dyroneteng@gmail.com> References: <20211115115153.48307-1-dyroneteng@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This commit supply an option names `--oid-only` to let `git ls-tree` only print out the OID of the object. `--oid-only` and `--name-only` are mutually exclusive in use. Signed-off-by: Teng Long --- builtin/ls-tree.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 3a442631c7..1f82229649 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -20,6 +20,7 @@ static int line_termination = '\n'; #define LS_SHOW_TREES 4 #define LS_NAME_ONLY 8 #define LS_SHOW_SIZE 16 +#define LS_OID_ONLY 32 static int abbrev; static int ls_options; static struct pathspec pathspec; @@ -90,6 +91,14 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, else if (ls_options & LS_TREE_ONLY) return 0; + if ((ls_options & LS_NAME_ONLY) && (ls_options & LS_OID_ONLY)) + die(_("cannot specify --oid-only and --name-only at the same time")); + + if (ls_options & LS_OID_ONLY) { + printf("%s\n", find_unique_abbrev(oid, abbrev)); + return 0; + } + if (!(ls_options & LS_NAME_ONLY)) { if (ls_options & LS_SHOW_SIZE) { char size_text[24]; @@ -139,6 +148,8 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) LS_NAME_ONLY), OPT_BIT(0, "name-status", &ls_options, N_("list only filenames"), LS_NAME_ONLY), + OPT_BIT(0, "oid-only", &ls_options, N_("list only oids"), + LS_OID_ONLY), OPT_SET_INT(0, "full-name", &chomp_prefix, N_("use full path names"), 0), OPT_BOOL(0, "full-tree", &full_tree, From patchwork Mon Nov 15 11:51:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teng Long X-Patchwork-Id: 12619355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 624A7C433F5 for ; Mon, 15 Nov 2021 11:52:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42C3161C4F for ; Mon, 15 Nov 2021 11:52:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231230AbhKOLze (ORCPT ); Mon, 15 Nov 2021 06:55:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbhKOLzX (ORCPT ); Mon, 15 Nov 2021 06:55:23 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9C44C061746 for ; Mon, 15 Nov 2021 03:52:26 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id n8so14249709plf.4 for ; Mon, 15 Nov 2021 03:52:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mMie3k5+afbmSF1t7y73ZW2MTXj10SVKn+IT03w3vI4=; b=Pu0dv31h8BoYlBBYd1dIgkpyS2l179RzBg69iktNMoF98PX4+21b3V7AEq0Wf+aZ7d hp77VEAeV1LW/5UD0SoTA405U8RTJsCj5Z8odJe1G93sx3/MJ9wx7hbikXx5uUNiK4Uk qmku6AWXOXeJgqQdK22P/exW/4tgnOjjqMTxmmH5p3ac0Wco/Ww4/az8afJ49uYB7Q6l DcICqn/oZL8W6EBO9sJ20fhvDMEUV5UzgqqYWaZhePkhq45CrtgRxbymug8KNjvBvsdI xvnGM/p77Cltoz3LZTZxhNyqtVJHGWpiyguOWmX/QcsdmzpJiRRywSWNoKhOEcZyzoOj dONw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mMie3k5+afbmSF1t7y73ZW2MTXj10SVKn+IT03w3vI4=; b=x8vxFnvKN1uacj+DEM81FP9DR1AtTGfnm14ga3SEHF0/1P7HTl6nuzUY4Cdwau5wuE XAeI5Fn3uzGKuVjdgarWjCjIBugjkZEkRIGrdQ0jHoEzkefun+jW/jismPsHW0jsF0JH gmfwRlqUFgKUuUaevEUtlX8ql8miTZEIBV9iC7XtQ3CyGxBgTWyrRqvcK9tRd+gIWrsk hXac+mV5+vCD0xebTxkiuBR5NLXe31o7fzg/IS9ZwvT1tW0nR5WxaR57ksIULm3LSZCT LFPW+3FHIGA35tuyUZT5TqKRU2Iw6ZTR5r62FgLPvC9PM/DkSipdCP8ySV22eaxZ8ky/ YhMw== X-Gm-Message-State: AOAM531bvVb/gHabYgzXKxk3yaO5BgtKlb3CVHmo2u2gnyLTRMGLxoTu 0oGhLnSTJioB7lq0dX0ONG4Lp+IH6XQGMQ== X-Google-Smtp-Source: ABdhPJxY8/fL0V7Ai9hwC6Q+v1Ndbo+rERypeeJ0Bg2hRxGHVDGStBzgyY5/u0ARp+0k2xy1w2+AgQ== X-Received: by 2002:a17:90b:1e0e:: with SMTP id pg14mr63000845pjb.143.1636977146088; Mon, 15 Nov 2021 03:52:26 -0800 (PST) Received: from localhost.localdomain ([205.204.117.98]) by smtp.gmail.com with ESMTPSA id s2sm17543280pfg.124.2021.11.15.03.52.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Nov 2021 03:52:25 -0800 (PST) From: Teng Long To: git@vger.kernel.org Cc: gitster@pobox.com, peff@peff.net, Teng Long Subject: [PATCH 2/3] t3104: add related tests for `--oid-only` option Date: Mon, 15 Nov 2021 19:51:52 +0800 Message-Id: <20211115115153.48307-3-dyroneteng@gmail.com> X-Mailer: git-send-email 2.33.1.9.g5fbd2fc599.dirty In-Reply-To: <20211115115153.48307-1-dyroneteng@gmail.com> References: <20211115115153.48307-1-dyroneteng@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Teng Long --- t/t3104-ls-tree-oid.sh | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 t/t3104-ls-tree-oid.sh diff --git a/t/t3104-ls-tree-oid.sh b/t/t3104-ls-tree-oid.sh new file mode 100755 index 0000000000..78ab9127c7 --- /dev/null +++ b/t/t3104-ls-tree-oid.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +test_description='git ls-tree oids handling.' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo 111 >1.txt && + echo 222 >2.txt && + mkdir -p path0/a/b/c && + echo 333 >path0/a/b/c/3.txt && + find *.txt path* \( -type f -o -type l \) -print | + xargs git update-index --add && + tree=$(git write-tree) && + echo $tree +' + + +test_expect_success 'specify with --oid-only' ' + git ls-tree --oid-only $tree >current && + cat >expected <<\EOF && +58c9bdf9d017fcd178dc8c073cbfcbb7ff240d6c +c200906efd24ec5e783bee7f23b5d7c941b0c12c +4e3849a078083863912298a25db30997cb8ca6d6 +EOF + test_cmp current expected +' + +test_expect_success 'specify with --oid-only and -r' ' + git ls-tree --oid-only -r $tree >current && + cat >expected <<\EOF && +58c9bdf9d017fcd178dc8c073cbfcbb7ff240d6c +c200906efd24ec5e783bee7f23b5d7c941b0c12c +55bd0ac4c42e46cd751eb7405e12a35e61425550 +EOF + test_cmp current expected +' + +test_expect_success 'specify with --oid-only and --abbrev' ' + git ls-tree --oid-only --abbrev=6 $tree >current && + cat >expected <<\EOF && +58c9bd +c20090 +4e3849 +EOF + test_cmp current expected +' + +test_expect_success 'cannot specify --name-only and --oid-only as the same time' ' + test_must_fail git ls-tree --oid-only --name-only $tree >current 2>&1 >/dev/null && + echo "fatal: cannot specify --oid-only and --name-only at the same time" > expected && + test_cmp current expected +' + +test_done From patchwork Mon Nov 15 11:51:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teng Long X-Patchwork-Id: 12619357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 894E5C433F5 for ; Mon, 15 Nov 2021 11:52:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7293461AA7 for ; Mon, 15 Nov 2021 11:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbhKOLzj (ORCPT ); Mon, 15 Nov 2021 06:55:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbhKOLzY (ORCPT ); Mon, 15 Nov 2021 06:55:24 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83243C061766 for ; Mon, 15 Nov 2021 03:52:28 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id w33-20020a17090a6ba400b001a722a06212so10888069pjj.0 for ; Mon, 15 Nov 2021 03:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dgved5jrV+zQPRtwXmRrZVJhNzEzbYmG+Szo57Cn5tA=; b=fjy4NyIwoVXf3qPdoilW5i7q6DHqjGTe8T5xD2w2EjDhd90Dhcl7+CSzieTT1WceoM zJc1/CCw0+4t46iljgnY2L40sNt57fzO9aKpkLdWw/Uu5l4buuiqMA0/9tVcSzJUsT2s kQuXGkZfeIkjfPrU6FVQNpbbMVLiG8AMT5S+j7D3VECdcZ6C+MCinOgLLeegvRYumEqp q+1sP5X+ckO5jCj7K4O2QGWoW/GVe2suAyx24TPqEQi1rzMMgxVaoMYqy3zj/ifNFChf TJ0FruWhcdk17AWMjZ6wqWUuVRVHW5S+Dwm7cXvb0MuJVacPZVgjxxYYijPb3aT6E79k 5YPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dgved5jrV+zQPRtwXmRrZVJhNzEzbYmG+Szo57Cn5tA=; b=46CLU/VBcQ+H08T1MM5wR1lr4jTfymnCYuGZCCaNdfy12Lg6fHBFrFgtTMOOIkk90+ 6JKi/3kBeUNLFe63kK9dJ3bhkY2kpVdloT4OnEjChB7H5Yoo1U1kpGzW3trRUGVypJoW VyfmWv0Qmq3xn2oYTmr4aS4116uA26GcG63/tdYzCcOyQiZSMI9XpB/GWLi+8/657HNI GzAu5AHDA1uzRh9HeLCSe7ZTleoN1RFXQE90mzS43eV9mUzfC7EP7OMus8alfvQ2DJJc NllFxup2CfZbP9gZ+dpczGRoFyNDBZ6TgeNOlrXfB6GRQg0NYjF1W6ig4EtEf6u3msfl KnlQ== X-Gm-Message-State: AOAM530HtaNUQkUYIGVFU3vHzAnWWFjn4Pc9UUwJL4LbjBdVh2vomG9L /ozyf6SKpjzPcOUraZtN4+6fFmUn0IJmTw== X-Google-Smtp-Source: ABdhPJyAh8KMDG+P8I1DvtUEkCRl4Ztgnw7Hu4H/nGT8oXnjK9/VfdlzFSaqvrxvrJPxC2mGKcN7xA== X-Received: by 2002:a17:90b:3807:: with SMTP id mq7mr45490769pjb.38.1636977147746; Mon, 15 Nov 2021 03:52:27 -0800 (PST) Received: from localhost.localdomain ([205.204.117.98]) by smtp.gmail.com with ESMTPSA id s2sm17543280pfg.124.2021.11.15.03.52.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Nov 2021 03:52:27 -0800 (PST) From: Teng Long To: git@vger.kernel.org Cc: gitster@pobox.com, peff@peff.net, Teng Long Subject: [PATCH 3/3] git-ls-tree.txt: description of the 'oid-only' option Date: Mon, 15 Nov 2021 19:51:53 +0800 Message-Id: <20211115115153.48307-4-dyroneteng@gmail.com> X-Mailer: git-send-email 2.33.1.9.g5fbd2fc599.dirty In-Reply-To: <20211115115153.48307-1-dyroneteng@gmail.com> References: <20211115115153.48307-1-dyroneteng@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Teng Long --- Documentation/git-ls-tree.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/git-ls-tree.txt b/Documentation/git-ls-tree.txt index db02d6d79a..bc711dc00a 100644 --- a/Documentation/git-ls-tree.txt +++ b/Documentation/git-ls-tree.txt @@ -10,7 +10,8 @@ SYNOPSIS -------- [verse] 'git ls-tree' [-d] [-r] [-t] [-l] [-z] - [--name-only] [--name-status] [--full-name] [--full-tree] [--abbrev[=]] + [--name-only] [--name-status] [--oid-only] + [--full-name] [--full-tree] [--abbrev[=]] [...] DESCRIPTION @@ -59,7 +60,10 @@ OPTIONS --name-only:: --name-status:: List only filenames (instead of the "long" output), one per line. - + Cannot be used with `--oid-only` together. +--oid-only:: + List only OIDs of the objects, one per line. Cannot be used with + `--name-only` or `--name-status` together. --abbrev[=]:: Instead of showing the full 40-byte hexadecimal object lines, show the shortest prefix that is at least ''