From patchwork Tue Aug 11 11:49:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11709149 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E3E2159A for ; Tue, 11 Aug 2020 11:50:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45F9C2076B for ; Tue, 11 Aug 2020 11:50:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C2VQv7dQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728843AbgHKLuG (ORCPT ); Tue, 11 Aug 2020 07:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728326AbgHKLuF (ORCPT ); Tue, 11 Aug 2020 07:50:05 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86A14C06174A for ; Tue, 11 Aug 2020 04:50:05 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id o5so6607323pgb.2 for ; Tue, 11 Aug 2020 04:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nin5JkmNoEBKhu4cp1gDKFRLkFkoHS4XH803ldzy2co=; b=C2VQv7dQoTfCxqHcKe52EbksIAzSOTHQcKNEJssEqhZCwuH74UnUyfm+PEp/H84xFL ZOcHEtX19h/KxBCQtxD8k03o847Jmp5Oa5IOpBP65s7SH4FJTyYs8mJ2cQmbl2qK4qoH LVFtXKo/gjq4cAB84H8exP0xK/X9yM5uCxqIRGLcLcOR92yq0TIlCEIYFoo1JTD55bxH Woe6x37fnWu00ilckiLJCh4rsp27qcOCgkDOVrmrPDtwiVqhJ/DQhQHTb43VGx1uKAy3 BiQPnj/F0i24DOqzvIe4Uw9zBvazx9ECV9Ko209vde+RYWACzaT31Jslc0pJjQshSi1r MfaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nin5JkmNoEBKhu4cp1gDKFRLkFkoHS4XH803ldzy2co=; b=ba3bf756vegLoAT5qptQzsA8xnq/iOLfSIhND/pYRFhmYdLZoNnMd08hoyDjpIvGGK GfDv1VYGAFnhiFe8YrAoQ53F7nsoUCya+VSfHqnSsc/TVinFB92MI2GsT4Nl8yAgIHho 388KouVA+tVAaMv8OofdaONjyXkX0KsbW5JJaEZkLae/NAqB3FnWU/au222Uyib3X7JV w5mwlhBkr5cW8EfNR/R8EDcspHbvSI755kpYJdst5omt7/Y4MyeUcOMQUsIZEpvwT3OM pz1/rhVBaYl/E1JyrYtKjwHzc4kSBCyZ6sCG0zHBdklbrtRJZhMkL5PUYkF8YLpPjx0A kHVQ== X-Gm-Message-State: AOAM532IT0uY6CmL+c4F1oRjEMnD+QzMn/p9MVRNdMKeqc9A0ywY0Vgs p8H0CydyBqJk7rV9OL6IkiMJSLMs X-Google-Smtp-Source: ABdhPJyK7uWzcEyw4Tkr0pJ/C/CdJ9r9WhJCO2+ZJ6bnfzzcG0uZyctQ06J69wFhXY8UvkmaeWTz/Q== X-Received: by 2002:a62:14c4:: with SMTP id 187mr5570195pfu.164.1597146604762; Tue, 11 Aug 2020 04:50:04 -0700 (PDT) Received: from localhost.localdomain ([2402:800:6375:ea17:7ad5:df16:a252:473b]) by smtp.gmail.com with ESMTPSA id q73sm3019220pjc.11.2020.08.11.04.50.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2020 04:50:03 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH v2 1/2] revision: differentiate if --no-abbrev asked explicitly Date: Tue, 11 Aug 2020 18:49:56 +0700 Message-Id: <9daef7445c09d355d4801f64e427c27dd6c44afb.1597146478.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.28.0.215.g32ffa52ee0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When we see `--no-abbrev' in command's arguments, we reset `abbrev' of `diff_options` to 0, thus, on a later stage, the object id won't be shortened (by not set object_id[abbrev] to '\0'). While not doing anything is very effective way to show full object id, we couldn't differentiate if --no-abbrev or not. In a later change, we want to extend --abbrev support to diff-patch format. Let's ask for full object id if we see --no-abbrev instead. Signed-off-by: Đoàn Trần Công Danh --- revision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 3dcf689341..24027b1af3 100644 --- a/revision.c +++ b/revision.c @@ -2430,7 +2430,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--always")) { revs->always_show_header = 1; } else if (!strcmp(arg, "--no-abbrev")) { - revs->abbrev = 0; + revs->abbrev = hexsz; } else if (!strcmp(arg, "--abbrev")) { revs->abbrev = DEFAULT_ABBREV; } else if (skip_prefix(arg, "--abbrev=", &optarg)) { From patchwork Tue Aug 11 11:49:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 11709153 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCF98739 for ; Tue, 11 Aug 2020 11:50:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABC2B2076B for ; Tue, 11 Aug 2020 11:50:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OVn38Xe7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728849AbgHKLuL (ORCPT ); Tue, 11 Aug 2020 07:50:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728326AbgHKLuH (ORCPT ); Tue, 11 Aug 2020 07:50:07 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56B85C06174A for ; Tue, 11 Aug 2020 04:50:07 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id o1so6713460plk.1 for ; Tue, 11 Aug 2020 04:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+9XoaAsvPeDnY5GdAcnbsvK5W3qwFpBoNjMfO85QUic=; b=OVn38Xe7+quFHkjxVhAogE8z8g3PlIL72oJxS1FGGxA1WygOP2XYbxOLc/94LfE1SH teTGWmVA6yooBiYkeXdjO2OS7dVsr4YHL6xlgyPN7Xye44MEzAMhKFPjrdTLA8bUe9Ti duV5M0HULLdRHXNeNtNkxrPJEKuYTkZYxDTv4Bor2d8X4DjBg5884mGOWBFT9G8tz9q6 fp45PL6VclZGzEcGA+PRMhzWMiKT5IUXswnGEBjyMPpM9lg//2QRD/X1K03lkP5RG+Vz hl6x+OTB57FzW2jZscam+4eGRjswdmCgBLoQXKS5EgV5pToM3Fn7z4Xc+Teq2xOSj8dj Va4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+9XoaAsvPeDnY5GdAcnbsvK5W3qwFpBoNjMfO85QUic=; b=W8FmVuRYlwhADCQGW0aaY4UTsohuqBTBVFQaS4O1e21LqUzD+1DRGhGAAFS02rMstX nFclFhYzbF5rLQL70XlFbEdMPHhfknHHKvmNGbPXTr2BC9K+dlE6CU+cu2qCY0quRwHK fmTEXaIMntncU0N+NW1VwBSeWJNnDf6DxaCPZW3mpRnSgPEz5wcoZMxvhM6M+jFIXieB q0P70EmcvvlRI5F9mR34x2nc80J8WnZmGntD69O8jWpp19Dh9mD7CD0SzNBTtSU3UCQE ZGe1QoLTGubHx6kZn/NEuK+pOCHrrkzZhS5UiJMY9oiS/jr9Zz8UBdKGLz07ioN7SM/B /eIg== X-Gm-Message-State: AOAM533yu5ODZgQCUujvompv3EOlnjKSQxCdduGTYWz6yllG0EjbxrdY QPiDok77R8dpE5ISsNUE76GbbAnI X-Google-Smtp-Source: ABdhPJzgNfN1eXZZAjdfX1owGU0X1sENB+rYUeC44iqbAdnJbv60jROFh9v6LHEveeWGDxr3AkIVOQ== X-Received: by 2002:a17:90a:c593:: with SMTP id l19mr701426pjt.20.1597146606474; Tue, 11 Aug 2020 04:50:06 -0700 (PDT) Received: from localhost.localdomain ([2402:800:6375:ea17:7ad5:df16:a252:473b]) by smtp.gmail.com with ESMTPSA id q73sm3019220pjc.11.2020.08.11.04.50.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2020 04:50:05 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= Subject: [PATCH v2 2/2] diff: index-line: respect --abbrev in object's name Date: Tue, 11 Aug 2020 18:49:57 +0700 Message-Id: <12acf1fe5db55199102d27eeb93524a96f914a05.1597146478.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.28.0.215.g32ffa52ee0 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A handful of Git's commands respect `--abbrev' for customizing length of abbreviation of object names. For diff-family, Git supports 2 different options for 2 different purposes, `--full-index' for showing diff-patch object's name in full, and `--abbrev' to customize the length of object names in diff-raw and diff-tree header lines, without any options to customise the length of object names in diff-patch format. When working with diff-patch format, we only have two options, either full index, or default abbrev length. Although, that consistent is documented, it doesn't stop users from trying to use `--abbrev' with the hope of customising diff-patch's objects' name's abbreviation. Let's resolve that inconsistency. To preserve backward compatibility with old script that specify both `--full-index' and `--abbrev', always shows full object id if `--full-index' is specified. Signed-off-by: Đoàn Trần Công Danh --- Documentation/diff-options.txt | 9 +++--- diff.c | 5 +++- t/t4013-diff-various.sh | 3 ++ ...ff.diff-tree_--root_-p_--abbrev=10_initial | 29 +++++++++++++++++++ ...--root_-p_--full-index_--abbrev=10_initial | 29 +++++++++++++++++++ ...f.diff-tree_--root_-p_--full-index_initial | 29 +++++++++++++++++++ 6 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial create mode 100644 t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial create mode 100644 t/t4013/diff.diff-tree_--root_-p_--full-index_initial diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 7987d72b02..c11efa7865 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -441,10 +441,11 @@ endif::git-format-patch[] --abbrev[=]:: Instead of showing the full 40-byte hexadecimal object name in diff-raw format output and diff-tree header - lines, show only a partial prefix. This is - independent of the `--full-index` option above, which controls - the diff-patch output format. Non default number of - digits can be specified with `--abbrev=`. + lines, show only a partial prefix. + In diff-patch output format, `--full-index` takes higher + precedent, i.e. if `--full-index` is specified, full blob + names will be shown regardless of `--abbrev`. + Non default number of digits can be specified with `--abbrev=`. -B[][/]:: --break-rewrites[=[][/]]:: diff --git a/diff.c b/diff.c index f9709de7b4..20dedfe2a9 100644 --- a/diff.c +++ b/diff.c @@ -4319,7 +4319,10 @@ static void fill_metainfo(struct strbuf *msg, } if (one && two && !oideq(&one->oid, &two->oid)) { const unsigned hexsz = the_hash_algo->hexsz; - int abbrev = o->flags.full_index ? hexsz : DEFAULT_ABBREV; + int abbrev = o->abbrev ? o->abbrev : DEFAULT_ABBREV; + + if (o->flags.full_index) + abbrev = hexsz; if (o->flags.binary) { mmfile_t mf; diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 3f60f7d96c..e6eb4dd4c7 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -221,6 +221,9 @@ diff-tree --root -r --abbrev=4 initial :noellipses diff-tree --root -r --abbrev=4 initial diff-tree -p initial diff-tree --root -p initial +diff-tree --root -p --abbrev=10 initial +diff-tree --root -p --full-index initial +diff-tree --root -p --full-index --abbrev=10 initial diff-tree --patch-with-stat initial diff-tree --root --patch-with-stat initial diff-tree --patch-with-raw initial diff --git a/t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial b/t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial new file mode 100644 index 0000000000..7518a9044e --- /dev/null +++ b/t/t4013/diff.diff-tree_--root_-p_--abbrev=10_initial @@ -0,0 +1,29 @@ +$ git diff-tree --root -p --abbrev=10 initial +444ac553ac7612cc88969031b02b3767fb8a353a +diff --git a/dir/sub b/dir/sub +new file mode 100644 +index 0000000000..35d242ba79 +--- /dev/null ++++ b/dir/sub +@@ -0,0 +1,2 @@ ++A ++B +diff --git a/file0 b/file0 +new file mode 100644 +index 0000000000..01e79c32a8 +--- /dev/null ++++ b/file0 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +diff --git a/file2 b/file2 +new file mode 100644 +index 0000000000..01e79c32a8 +--- /dev/null ++++ b/file2 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +$ diff --git a/t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial b/t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial new file mode 100644 index 0000000000..69f913fbe5 --- /dev/null +++ b/t/t4013/diff.diff-tree_--root_-p_--full-index_--abbrev=10_initial @@ -0,0 +1,29 @@ +$ git diff-tree --root -p --full-index --abbrev=10 initial +444ac553ac7612cc88969031b02b3767fb8a353a +diff --git a/dir/sub b/dir/sub +new file mode 100644 +index 0000000000000000000000000000000000000000..35d242ba79ae89ac695e26b3d4c27a8e6f028f9e +--- /dev/null ++++ b/dir/sub +@@ -0,0 +1,2 @@ ++A ++B +diff --git a/file0 b/file0 +new file mode 100644 +index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d +--- /dev/null ++++ b/file0 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +diff --git a/file2 b/file2 +new file mode 100644 +index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d +--- /dev/null ++++ b/file2 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +$ diff --git a/t/t4013/diff.diff-tree_--root_-p_--full-index_initial b/t/t4013/diff.diff-tree_--root_-p_--full-index_initial new file mode 100644 index 0000000000..1b0b6717fa --- /dev/null +++ b/t/t4013/diff.diff-tree_--root_-p_--full-index_initial @@ -0,0 +1,29 @@ +$ git diff-tree --root -p --full-index initial +444ac553ac7612cc88969031b02b3767fb8a353a +diff --git a/dir/sub b/dir/sub +new file mode 100644 +index 0000000000000000000000000000000000000000..35d242ba79ae89ac695e26b3d4c27a8e6f028f9e +--- /dev/null ++++ b/dir/sub +@@ -0,0 +1,2 @@ ++A ++B +diff --git a/file0 b/file0 +new file mode 100644 +index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d +--- /dev/null ++++ b/file0 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +diff --git a/file2 b/file2 +new file mode 100644 +index 0000000000000000000000000000000000000000..01e79c32a8c99c557f0757da7cb6d65b3414466d +--- /dev/null ++++ b/file2 +@@ -0,0 +1,3 @@ ++1 ++2 ++3 +$