From patchwork Mon Oct 21 16:00:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11202589 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 977E1913 for ; Mon, 21 Oct 2019 16:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 75196214AE for ; Mon, 21 Oct 2019 16:01:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UH6z8rPJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729127AbfJUQBA (ORCPT ); Mon, 21 Oct 2019 12:01:00 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43325 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726332AbfJUQBA (ORCPT ); Mon, 21 Oct 2019 12:01:00 -0400 Received: by mail-wr1-f66.google.com with SMTP id c2so9391536wrr.10 for ; Mon, 21 Oct 2019 09:00:58 -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=7gS/Xuc2yhFrqOwgoQyAzs7fWOm6Cn3jF4fmBXkRM3I=; b=UH6z8rPJU4BCqCP7YLpLHZY4ngdQbkFwXYnC29yTSLlV/dgFB5NGmcK9YzUHjJz6rK 9aiz9wb2D9uxCRdVXHdWs98awalj1QvLNeIHkaAM/z6TYqwu1iqYKOhS+gDJbTlyVmHk uwRISj47EjMBuiTGhKMdHnZTt0NimMtTyags65h9ohDludBRHnPf8zq+9Slm79Bapc6W T8OAlHHf/juID8VDNHGZBOX9165gx7/tYeCk7mXHJEzGhlcjF1bRpD3J2tl3EUrBpZzY t1022SiDEpf6+hzvYQxi1cvl/FCUTJ6h+5UJDZhLVRxNr4I2ieG09l5hnxp41vviRkGz o+Dg== 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=7gS/Xuc2yhFrqOwgoQyAzs7fWOm6Cn3jF4fmBXkRM3I=; b=kYGvine34KcX9O3DbMB9j16YIPv7YRJhhu1+jBG5Ch4KFnh0adjfTH18UGgd8tRzpf SmHbL/q94jmnG7sGT2RE2BCG2fOapGzEv4FwLsPYBQLTDizMaiXgI0Yv12Avdvq3Lvtd mhut38kdovXPKkw3ch3k44j1nlsipMQtI8tWewtpQsVZGchH1GL3G4CXzWUYIWUrYJ37 9BWLhRFzoJe8cP39xcSE15zi0x3ZKJHj7lowOkXJCM5M34+pKnwP+PDFCj10VOqosKez rZaU/e/v2KFSWMlF316yuVaJlC9DyfagnnwyRuHTkJ7rDd6fOZi6o21hgfphf3MmfDJC 9ifg== X-Gm-Message-State: APjAAAW/vyMJ05z7ASYMASrvdLRDM/8DJAiboGJi906yTswXXbyGRJVZ 865LeRF8a9ZC8n6zgqjr6xeS2jkX X-Google-Smtp-Source: APXvYqykGG44EKt2Bqup/7zb9xPcS9bdSNhNIWIdg1eT/ynkBReeH/JWPvyZDjOpNZ+gj78HxXp8YQ== X-Received: by 2002:adf:ed88:: with SMTP id c8mr20122880wro.214.1571673658301; Mon, 21 Oct 2019 09:00:58 -0700 (PDT) Received: from localhost.localdomain (x4db66cac.dyn.telefonica.de. [77.182.108.172]) by smtp.gmail.com with ESMTPSA id u26sm16293196wrd.87.2019.10.21.09.00.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Oct 2019 09:00:57 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: David Turner , Johannes Schindelin , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 1/5] Documentation: mention more worktree-specific exceptions Date: Mon, 21 Oct 2019 18:00:39 +0200 Message-Id: <20191021160043.701-2-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.rc0.472.ga6f06c86b4 In-Reply-To: <20191021160043.701-1-szeder.dev@gmail.com> References: <20191021160043.701-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org If a directory in $GIT_DIR is overridden when $GIT_COMMON_DIR is set, then usually all paths within that directory are overridden as well. There are a couple of exceptions, though, and two of them, namely 'refs/rewritten' and 'logs/HEAD' are not mentioned in 'gitrepository-layout'. Document them as well. Signed-off-by: SZEDER Gábor --- Documentation/gitrepository-layout.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/gitrepository-layout.txt b/Documentation/gitrepository-layout.txt index d6388f10bb..1a2ef4c150 100644 --- a/Documentation/gitrepository-layout.txt +++ b/Documentation/gitrepository-layout.txt @@ -96,9 +96,9 @@ refs:: directory. The 'git prune' command knows to preserve objects reachable from refs found in this directory and its subdirectories. - This directory is ignored (except refs/bisect and - refs/worktree) if $GIT_COMMON_DIR is set and - "$GIT_COMMON_DIR/refs" will be used instead. + This directory is ignored (except refs/bisect, + refs/rewritten and refs/worktree) if $GIT_COMMON_DIR is + set and "$GIT_COMMON_DIR/refs" will be used instead. refs/heads/`name`:: records tip-of-the-tree commit objects of branch `name` @@ -240,8 +240,8 @@ remotes:: logs:: Records of changes made to refs are stored in this directory. See linkgit:git-update-ref[1] for more information. This - directory is ignored if $GIT_COMMON_DIR is set and - "$GIT_COMMON_DIR/logs" will be used instead. + directory is ignored (except logs/HEAD) if $GIT_COMMON_DIR is + set and "$GIT_COMMON_DIR/logs" will be used instead. logs/refs/heads/`name`:: Records all changes made to the branch tip named `name`. From patchwork Mon Oct 21 16:00:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11202595 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 D644A913 for ; Mon, 21 Oct 2019 16:01:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB90D20B7C for ; Mon, 21 Oct 2019 16:01:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cb/eDi8f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729751AbfJUQBG (ORCPT ); Mon, 21 Oct 2019 12:01:06 -0400 Received: from mail-wr1-f54.google.com ([209.85.221.54]:38309 "EHLO mail-wr1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729525AbfJUQBE (ORCPT ); Mon, 21 Oct 2019 12:01:04 -0400 Received: by mail-wr1-f54.google.com with SMTP id v9so3371510wrq.5 for ; Mon, 21 Oct 2019 09:01:03 -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=ZAxFthZOJG72sI+beMK3PooQleyIgaFV2D0hvrbKwbg=; b=Cb/eDi8fH9xdqyQ2SNwtJDb5wPOUzotsQSvcWRkZfZS9mSYBf/mKoPDgDKbb0EM/I4 r69rqh2U+B8gD07/r7BYMl73nru6ZOAtlaSxRcxv65vDYKas8M6AhhGwAHo4OJPahPxB iVwvY0D5k0c/vXXaAVvXv5iBkLalFFgPHKMMGerELyKGrKP9BsyjRp21l+GWKQrHCy9o 9T/8/vBmUzQrvzd7tqgYQxG26hH+BkEDSDu8uBj0N1aRDmblivegBobpCNRbX3pn1Ngv vF7KGOvmne4u+MCdOed6Rea3oilv/tBRNb38q28xm+bEdhXJPO4tr05/EZXLPcj8JjEZ tBlg== 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=ZAxFthZOJG72sI+beMK3PooQleyIgaFV2D0hvrbKwbg=; b=j5vGsqeMSASo5VTDBP7OZEWZO1pucGDc2zZzWTGSymPjGgwlajRM678Cq6sm7sDthE +L/t5+C5JLnjzF4qNJNrj9G7aTbXo8yfGuQM3DipmBlB00RTIvuGKIHZHrq6tNso6M1O 3yIMaYMZABCC9eZ/VIHqzozeo2L7dSBoEbVT7lPdRw8+pjh2DW3SaNf5s6NGVGFpHSpm hDDk6DfYu55Sz1nuqTlCSlccrUQYpL9cmVDL0JVmnxYMRdYiynKYcnI0EgzR4bH+GQ6Z aWSIWmliXQFtWy4amc2dsq2obYkBTlHyAlntxpL+5l8y/OV+uy7WpbNko0G3nmofTuY8 mbCA== X-Gm-Message-State: APjAAAW1DnCiFPkh/Cwtr4s8K1rNmkl9gVM4SHKw4t1JH1WbVoaajSSq Wt9lD4bVf5bEGi90W+fa9Ps= X-Google-Smtp-Source: APXvYqwxHxp+u+KmGPUhdJMBVpRcVFBjifm88vtJ0Imi7ZI5J+KuAgaaxb6yfcYxSF+EoRal8EbvwA== X-Received: by 2002:adf:9f08:: with SMTP id l8mr19597973wrf.325.1571673659953; Mon, 21 Oct 2019 09:00:59 -0700 (PDT) Received: from localhost.localdomain (x4db66cac.dyn.telefonica.de. [77.182.108.172]) by smtp.gmail.com with ESMTPSA id u26sm16293196wrd.87.2019.10.21.09.00.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Oct 2019 09:00:58 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: David Turner , Johannes Schindelin , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 2/5] path.c: clarify trie_find()'s in-code comment Date: Mon, 21 Oct 2019 18:00:40 +0200 Message-Id: <20191021160043.701-3-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.rc0.472.ga6f06c86b4 In-Reply-To: <20191021160043.701-1-szeder.dev@gmail.com> References: <20191021160043.701-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A fairly long comment describes trie_find()'s behavior and shows examples, but it's slightly incomplete/inaccurate. Update this comment to specify how trie_find() handles a negative return value from the given match function. Furthermore, update the list of examples to include not only two but three levels of path components. This makes the examples slightly more complicated, but it can illustrate the behavior in more corner cases. Finally, basically everything refers to the data stored for a key as "value", with two confusing exceptions: - The type definition of the match function calls its corresponding parameter 'data'. Rename that parameter to 'value'. (check_common(), the only function of this type already calls it 'value'). - The table of examples above trie_find() has a "val from node" column, which has nothing to do with the value stored in the trie: it's a "prefix of the key for which the trie contains a value" that led to that node. Rename that column header to "prefix to node". Note that neither the original nor the updated description and examples correspond 100% to the current implementation, because the implementation is a bit buggy, but the comment describes the desired behavior. The bug will be fixed in the last patch of this series. Signed-off-by: SZEDER Gábor --- path.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/path.c b/path.c index e3da1f3c4e..4ac9a101f5 100644 --- a/path.c +++ b/path.c @@ -236,30 +236,41 @@ static void *add_to_trie(struct trie *root, const char *key, void *value) return old; } -typedef int (*match_fn)(const char *unmatched, void *data, void *baton); +typedef int (*match_fn)(const char *unmatched, void *value, void *baton); /* * Search a trie for some key. Find the longest /-or-\0-terminated - * prefix of the key for which the trie contains a value. Call fn - * with the unmatched portion of the key and the found value, and - * return its return value. If there is no such prefix, return -1. + * prefix of the key for which the trie contains a value. If there is + * no such prefix, return -1. Otherwise call fn with the unmatched + * portion of the key and the found value. If fn returns 0 or + * positive, then return its return value. If fn returns negative, + * then call fn with the next-longest /-terminated prefix of the key + * (i.e. a parent directory) for which the trie contains a value, and + * handle its return value the same way. If there is no shorter + * /-terminated prefix with a value left, then return the negative + * return value of the most recent fn invocation. * * The key is partially normalized: consecutive slashes are skipped. * - * For example, consider the trie containing only [refs, - * refs/worktree] (both with values). - * - * | key | unmatched | val from node | return value | - * |-----------------|------------|---------------|--------------| - * | a | not called | n/a | -1 | - * | refs | \0 | refs | as per fn | - * | refs/ | / | refs | as per fn | - * | refs/w | /w | refs | as per fn | - * | refs/worktree | \0 | refs/worktree | as per fn | - * | refs/worktree/ | / | refs/worktree | as per fn | - * | refs/worktree/a | /a | refs/worktree | as per fn | - * |-----------------|------------|---------------|--------------| + * For example, consider the trie containing only [logs, + * logs/refs/bisect], both with values, but not logs/refs. * + * | key | unmatched | prefix to node | return value | + * |--------------------|----------------|------------------|--------------| + * | a | not called | n/a | -1 | + * | logstore | not called | n/a | -1 | + * | logs | \0 | logs | as per fn | + * | logs/ | / | logs | as per fn | + * | logs/refs | /refs | logs | as per fn | + * | logs/refs/ | /refs/ | logs | as per fn | + * | logs/refs/b | /refs/b | logs | as per fn | + * | logs/refs/bisected | /refs/bisected | logs | as per fn | + * | logs/refs/bisect | \0 | logs/refs/bisect | as per fn | + * | logs/refs/bisect/ | / | logs/refs/bisect | as per fn | + * | logs/refs/bisect/a | /a | logs/refs/bisect | as per fn | + * | (If fn in the previous line returns -1, then fn is called once more:) | + * | logs/refs/bisect/a | /refs/bisect/a | logs | as per fn | + * |--------------------|----------------|------------------|--------------| */ static int trie_find(struct trie *root, const char *key, match_fn fn, void *baton) From patchwork Mon Oct 21 16:00:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11202593 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 028AC913 for ; Mon, 21 Oct 2019 16:01:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D518A20B7C for ; Mon, 21 Oct 2019 16:01:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GEGqHzr0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729714AbfJUQBD (ORCPT ); Mon, 21 Oct 2019 12:01:03 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:50351 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729431AbfJUQBD (ORCPT ); Mon, 21 Oct 2019 12:01:03 -0400 Received: by mail-wm1-f65.google.com with SMTP id q13so3898269wmj.0 for ; Mon, 21 Oct 2019 09:01:02 -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=oPLHTVyChDtpVyWmE9ijTqTAEouKXRIYLoPxaCD/LLA=; b=GEGqHzr0UmS8OliSC1JMsnPpbRzlmPced854FRjGeNW5l112dAJjA7F5tYfIrccL8e DQOL0nLzlNiWVY3/l23KVJzR1jk3M+MTBKhoDym7YRSAFyM5VxLfRM6TPrdRBoqvKTWd m5fynf6gmKN4DlUF8HY/gpLCslkS/JtmcD6uxpaEu5tOr/yuReT1zzY593Tb3BnUJLkP N5l8u5wmlAVHXdmR/LOzF/B5E7Vt+rQ8sKcVoJwzEp3n03qODvuWYGB04eZRIzzCfoSy NBJv3VIBFKmzyXG78MSCSZIiIdPYJSRvjNf9lNKkRLLrFsFylrMFGPcX36+9kr9JFOOx KMkA== 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=oPLHTVyChDtpVyWmE9ijTqTAEouKXRIYLoPxaCD/LLA=; b=tZHJfdnFOAVNkgkqUSpGOEcjzWniJjmdkrVjsdwftvJZJLc5/nZTRdkCI8wzT0zBih oLfIo8d75ulmosBBqan0GC/2/kR12OaqIXu6du5rw85G1XIWc7Wx8QgVsXlK75eQF6vr pYVbR8KbnPuELBu6hNg8SALtFTCMsNQed3yDvRZ7SnJqTqRYdvH/3dY8dK1tG2FkIKt3 qylss0AKIhEueLwlCdVpJ24cOPw1wrEVlU4A0ZFQCu8LW1e5YBYCJXaXH9rXYg+0/wjv hprI4Ujqm69NWa1iz+z92G6ecR9hQdLStPQy0hfVd2FjiA/V5E83ClPrrdj6QWoUxwAt +W4Q== X-Gm-Message-State: APjAAAUcQdmiE0ygv3sUtxsTSoXsDl5xRweEuVNX4dZ0vr8BdflcYxVw E0+rnBBf7EtV0QIMd7SDee9R/xjv X-Google-Smtp-Source: APXvYqxariIqRRJol9sBopzFjqRCmcqAA+r+mlSUqDH7hj1xsg6drICkf9a6+oEJzV/WoCqsVG6YnA== X-Received: by 2002:a1c:44:: with SMTP id 65mr16319962wma.93.1571673661330; Mon, 21 Oct 2019 09:01:01 -0700 (PDT) Received: from localhost.localdomain (x4db66cac.dyn.telefonica.de. [77.182.108.172]) by smtp.gmail.com with ESMTPSA id u26sm16293196wrd.87.2019.10.21.09.01.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Oct 2019 09:01:00 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: David Turner , Johannes Schindelin , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 3/5] path.c: mark 'logs/HEAD' in 'common_list' as file Date: Mon, 21 Oct 2019 18:00:41 +0200 Message-Id: <20191021160043.701-4-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.rc0.472.ga6f06c86b4 In-Reply-To: <20191021160043.701-1-szeder.dev@gmail.com> References: <20191021160043.701-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 'logs/HEAD', i.e. HEAD's reflog, is a file, but its entry in 'common_list' has the 'is_dir' bit set. Unset that bit to make it consistent with what 'logs/HEAD' is supposed to be. This doesn't make a difference in behavior: check_common() is the only function that looks at the 'is_dir' bit, and that function either returns 0, or '!exclude', which for 'logs/HEAD' results in 0 as well. Signed-off-by: SZEDER Gábor --- path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.c b/path.c index 4ac9a101f5..3fac5f5726 100644 --- a/path.c +++ b/path.c @@ -113,7 +113,7 @@ static struct common_dir common_list[] = { { 0, 1, 0, "info" }, { 0, 0, 1, "info/sparse-checkout" }, { 1, 1, 0, "logs" }, - { 1, 1, 1, "logs/HEAD" }, + { 1, 0, 1, "logs/HEAD" }, { 0, 1, 1, "logs/refs/bisect" }, { 0, 1, 1, "logs/refs/rewritten" }, { 0, 1, 1, "logs/refs/worktree" }, From patchwork Mon Oct 21 16:00:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11202597 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 56C50913 for ; Mon, 21 Oct 2019 16:01:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3561B20B7C for ; Mon, 21 Oct 2019 16:01:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lQRZsesF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729754AbfJUQBI (ORCPT ); Mon, 21 Oct 2019 12:01:08 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41048 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729725AbfJUQBH (ORCPT ); Mon, 21 Oct 2019 12:01:07 -0400 Received: by mail-wr1-f66.google.com with SMTP id p4so14623603wrm.8 for ; Mon, 21 Oct 2019 09:01:04 -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=Sa3f5BckwxaktFgPnRapmZd6eaJatuycR9TIbrlM4C4=; b=lQRZsesFFKWtVTVmYgL84MFsD0QHhxyLQ3syYDnVhH0E1zS/cA0k43QpdX80hWW6ou yszSXZdGYRLm9NJOI+aIUgJ7f7KCMYwgOoSv5S9ptkJ48INEpsJaOzR7cR/CpoiPS+A0 C7cbCQjqXBR+W1dh0qYQuA0BjhRhWTUQqWjob/78Qe93s8y6epyE/zyho7A2sBH9E7vR p+IJLfWLsxiwyxC1Witl2aHdVjBOhKNxmlRoM55/OjRxPSInG/deV78FoodRHA+2n0m0 VCIRQKyylggUeF9j4q7EmeDGMxpqZVeOR+69PIN4uZ3xKor44pcugcb+3OWZBSSJjaqR DDUw== 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=Sa3f5BckwxaktFgPnRapmZd6eaJatuycR9TIbrlM4C4=; b=XhmTZ9AJZgIr6MagkPOQQEbDmcqwzMDt9/FUdS+mf8tAkHmAgA8oBNA5cGwa7ULK2F iFYUOE2fGi0k5MuSTMR4HcAykOQm1L04dw8f1rX+sa54N9kGl9antfuI9rfu5+7Bdrfi /hCmL5NDWL3Gz/gpBy/tK6WkiY6AUZtpVGhYfMmVyE8ONNPkZUimBHjNmsy0N0NqsDFF DYgrglJpLitFSH/Ckc6OhO7/fnwkouFDDHkXyLwwvB38aoWc+lK8a0jJzoSrbyxY4JU2 6Ua0O9Aih0xAkUCCKizQE5Kljb38gTvsg86+iH9UyprM6TpPn8Uou9aHI0wtJoY3CjLr yt9Q== X-Gm-Message-State: APjAAAUUvBTOeJ/xkmW1i+N/hBFAcEEwwYPZEmeOA7d/f/IG/plhfbN/ SmJSHJCnMNxF999M6+dPB5U9bnBh X-Google-Smtp-Source: APXvYqyu6xrLq8em45nkOer4yLEEv0+nkiMaVrqYmiHqBJQCE/dXh3oby9WVUB8W1KgTjCQNsb5sMQ== X-Received: by 2002:adf:a109:: with SMTP id o9mr19415045wro.96.1571673663380; Mon, 21 Oct 2019 09:01:03 -0700 (PDT) Received: from localhost.localdomain (x4db66cac.dyn.telefonica.de. [77.182.108.172]) by smtp.gmail.com with ESMTPSA id u26sm16293196wrd.87.2019.10.21.09.01.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Oct 2019 09:01:02 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: David Turner , Johannes Schindelin , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 4/5] path.c: clarify two field names in 'struct common_dir' Date: Mon, 21 Oct 2019 18:00:42 +0200 Message-Id: <20191021160043.701-5-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.rc0.472.ga6f06c86b4 In-Reply-To: <20191021160043.701-1-szeder.dev@gmail.com> References: <20191021160043.701-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org An array of 'struct common_dir' instances is used to specify whether various paths in $GIT_DIR are specific to a worktree, or are common, i.e. belong to main worktree. The names of two fields in this struct are somewhat confusing or ambigious: - The path is recorded in the struct's 'dirname' field, even though several entries are regular files e.g. 'gc.pid', 'packed-refs', etc. Rename this field to 'path' to reduce confusion. - The field 'exclude' tells whether the path is excluded... from where? Excluded from the common dir or from the worktree? It means the former, but it's ambigious. Rename this field to 'is_common' to make it unambigious what it means. This, however, means the exact opposite of what 'exclude' meant, so we have to negate the field's value in all entries as well. The diff is best viewed with '--color-words'. Signed-off-by: SZEDER Gábor --- path.c | 66 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/path.c b/path.c index 3fac5f5726..cf57bd52dd 100644 --- a/path.c +++ b/path.c @@ -101,36 +101,36 @@ struct common_dir { /* Not considered garbage for report_linked_checkout_garbage */ unsigned ignore_garbage:1; unsigned is_dir:1; - /* Not common even though its parent is */ - unsigned exclude:1; - const char *dirname; + /* Belongs to the common dir, though it may contain paths that don't */ + unsigned is_common:1; + const char *path; }; static struct common_dir common_list[] = { - { 0, 1, 0, "branches" }, - { 0, 1, 0, "common" }, - { 0, 1, 0, "hooks" }, - { 0, 1, 0, "info" }, - { 0, 0, 1, "info/sparse-checkout" }, - { 1, 1, 0, "logs" }, - { 1, 0, 1, "logs/HEAD" }, - { 0, 1, 1, "logs/refs/bisect" }, - { 0, 1, 1, "logs/refs/rewritten" }, - { 0, 1, 1, "logs/refs/worktree" }, - { 0, 1, 0, "lost-found" }, - { 0, 1, 0, "objects" }, - { 0, 1, 0, "refs" }, - { 0, 1, 1, "refs/bisect" }, - { 0, 1, 1, "refs/rewritten" }, - { 0, 1, 1, "refs/worktree" }, - { 0, 1, 0, "remotes" }, - { 0, 1, 0, "worktrees" }, - { 0, 1, 0, "rr-cache" }, - { 0, 1, 0, "svn" }, - { 0, 0, 0, "config" }, - { 1, 0, 0, "gc.pid" }, - { 0, 0, 0, "packed-refs" }, - { 0, 0, 0, "shallow" }, + { 0, 1, 1, "branches" }, + { 0, 1, 1, "common" }, + { 0, 1, 1, "hooks" }, + { 0, 1, 1, "info" }, + { 0, 0, 0, "info/sparse-checkout" }, + { 1, 1, 1, "logs" }, + { 1, 0, 0, "logs/HEAD" }, + { 0, 1, 0, "logs/refs/bisect" }, + { 0, 1, 0, "logs/refs/rewritten" }, + { 0, 1, 0, "logs/refs/worktree" }, + { 0, 1, 1, "lost-found" }, + { 0, 1, 1, "objects" }, + { 0, 1, 1, "refs" }, + { 0, 1, 0, "refs/bisect" }, + { 0, 1, 0, "refs/rewritten" }, + { 0, 1, 0, "refs/worktree" }, + { 0, 1, 1, "remotes" }, + { 0, 1, 1, "worktrees" }, + { 0, 1, 1, "rr-cache" }, + { 0, 1, 1, "svn" }, + { 0, 0, 1, "config" }, + { 1, 0, 1, "gc.pid" }, + { 0, 0, 1, "packed-refs" }, + { 0, 0, 1, "shallow" }, { 0, 0, 0, NULL } }; @@ -331,8 +331,8 @@ static void init_common_trie(void) if (common_trie_done_setup) return; - for (p = common_list; p->dirname; p++) - add_to_trie(&common_trie, p->dirname, p); + for (p = common_list; p->path; p++) + add_to_trie(&common_trie, p->path, p); common_trie_done_setup = 1; } @@ -349,10 +349,10 @@ static int check_common(const char *unmatched, void *value, void *baton) return 0; if (dir->is_dir && (unmatched[0] == 0 || unmatched[0] == '/')) - return !dir->exclude; + return dir->is_common; if (!dir->is_dir && unmatched[0] == 0) - return !dir->exclude; + return dir->is_common; return 0; } @@ -376,8 +376,8 @@ void report_linked_checkout_garbage(void) return; strbuf_addf(&sb, "%s/", get_git_dir()); len = sb.len; - for (p = common_list; p->dirname; p++) { - const char *path = p->dirname; + for (p = common_list; p->path; p++) { + const char *path = p->path; if (p->ignore_garbage) continue; strbuf_setlen(&sb, len); From patchwork Mon Oct 21 16:00:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?SZEDER_G=C3=A1bor?= X-Patchwork-Id: 11202599 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 1AA471895 for ; Mon, 21 Oct 2019 16:01:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EDE0A214AE for ; Mon, 21 Oct 2019 16:01:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KuR+aQDJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729781AbfJUQBJ (ORCPT ); Mon, 21 Oct 2019 12:01:09 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36394 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726955AbfJUQBH (ORCPT ); Mon, 21 Oct 2019 12:01:07 -0400 Received: by mail-wm1-f66.google.com with SMTP id c22so4252714wmd.1 for ; Mon, 21 Oct 2019 09:01: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=TZInRNAA5CbZgJHsyHtxLosgGU6+gqfvMFdYH4Oeahs=; b=KuR+aQDJMBT+x1QQM/RZp6/vJ5wxswpm9VYOgpUs9/hGNGcKWbj5fChyH3TejvX/tn kYWpUctaAu05WxHdDkX1NM7bYVSYZ4wQx2VLzrv7AB8I9A3SFIauLaXTsPIYzSwL3Yo6 QShKXC1bFMx0cVGuXVSPgPGLkT08uXQgzs1se2GQ9ULL8t/0wL2dwOtkC3tdChk0CLF3 DnCBEVwkWj5FIZhwgIGyChEv4zHiRf+sOygMLRgj+iSESJjCYwYlZEUdyLmVLAmR+09Y vWr1LOin9vY6lNLrGnBqpZP+ynDGs3zNBoqfg9ukWkH4jVflZfEbRaIC8ZonRxJN6YCL ZFtg== 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=TZInRNAA5CbZgJHsyHtxLosgGU6+gqfvMFdYH4Oeahs=; b=arEw0tfkUY8XrNnWirMqTneHdwJmoSMmSZ8ygQA/oN5Hlxdb0SAKLL04o5SfgDEcF/ Zd/LgS4FN8TlPZsF9zFBF1zQkkMg5Dxj5pb4uY7FyvEmNmA32lPwZXZT7oFF3OrjQDlJ 8lo2pPLM5V7hRUFKaGAC3wDzTIA7IAdfzCDFTHzpeXoHxwI0wV88cf2GWmXpEbRrpxvq xwleTB/dCOTegE0QHbEnZa676EPDXk64ZvH59jgnqXciyzWNiF74n6roxKTufUGA2JkQ YnMKYwqOyc/HJIw1p6m4LAtZY104LZIMVynNeyQCJGZrn3Uatsx+8wa91LrRkEOb+GWT QuKA== X-Gm-Message-State: APjAAAU+ls24knt9MJy0C3lq0777I/EYzEIWxaj0QPCiLohTHY3fLm/T Mz83ZOki2l5fppwT6+RvaN8= X-Google-Smtp-Source: APXvYqzECrdJmLQSQyq0DoMPkR3urd/8aweTx3oJCCCZ1kGr1Ji5ehoA0IzKC+N2yKCL+nZ39Fzqeg== X-Received: by 2002:a7b:cd89:: with SMTP id y9mr21267399wmj.51.1571673664575; Mon, 21 Oct 2019 09:01:04 -0700 (PDT) Received: from localhost.localdomain (x4db66cac.dyn.telefonica.de. [77.182.108.172]) by smtp.gmail.com with ESMTPSA id u26sm16293196wrd.87.2019.10.21.09.01.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Oct 2019 09:01:04 -0700 (PDT) From: =?utf-8?q?SZEDER_G=C3=A1bor?= To: Junio C Hamano Cc: David Turner , Johannes Schindelin , git@vger.kernel.org, =?utf-8?q?SZEDER_G=C3=A1bor?= Subject: [PATCH 5/5] path.c: don't call the match function without value in trie_find() Date: Mon, 21 Oct 2019 18:00:43 +0200 Message-Id: <20191021160043.701-6-szeder.dev@gmail.com> X-Mailer: git-send-email 2.24.0.rc0.472.ga6f06c86b4 In-Reply-To: <20191021160043.701-1-szeder.dev@gmail.com> References: <20191021160043.701-1-szeder.dev@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 'logs/refs' is not a working tree-specific path, but since commit b9317d55a3 (Make sure refs/rewritten/ is per-worktree, 2019-03-07) 'git rev-parse --git-path' has been returning a bogus path if a trailing '/' is present: $ git -C WT/ rev-parse --git-path logs/refs --git-path logs/refs/ /home/szeder/src/git/.git/logs/refs /home/szeder/src/git/.git/worktrees/WT/logs/refs/ We use a trie data structure to efficiently decide whether a path belongs to the common dir or is working tree-specific. As it happens b9317d55a3 triggered a bug that is as old as the trie implementation itself, added in 4e09cf2acf (path: optimize common dir checking, 2015-08-31). - According to the comment describing trie_find(), it should only call the given match function 'fn' for a "/-or-\0-terminated prefix of the key for which the trie contains a value". This is not true: there are three places where trie_find() calls the match function, but one of them is missing the check for value's existence. - b9317d55a3 added two new keys to the trie: 'logs/refs/rewritten' and 'logs/refs/worktree', next to the already existing 'logs/refs/bisect'. This resulted in a trie node with the path 'logs/refs', which didn't exist before, and which doesn't have a value attached. A query for 'logs/refs/' finds this node and then hits that one callsite of the match function which doesn't check for the value's existence, and thus invokes the match function with NULL as value. - When the match function check_common() is invoked with a NULL value, it returns 0, which indicates that the queried path doesn't belong to the common directory, ultimately resulting the bogus path shown above. Add the missing condition to trie_find() so it will never invoke the match function with a non-existing value. check_common() will then no longer have to check that it got a non-NULL value, so remove that condition. I believe that there are no other paths that could cause similar bogus output. AFAICT the only other key resulting in the match function being called with a NULL value is 'co' (because of the keys 'common' and 'config'). However, as they are not in a directory that belongs to the common directory the resulting working tree-specific path is expected. Signed-off-by: SZEDER Gábor --- path.c | 11 ++++++----- t/t0060-path-utils.sh | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/path.c b/path.c index cf57bd52dd..e21b00c4d4 100644 --- a/path.c +++ b/path.c @@ -299,9 +299,13 @@ static int trie_find(struct trie *root, const char *key, match_fn fn, /* Matched the entire compressed section */ key += i; - if (!*key) + if (!*key) { /* End of key */ - return fn(key, root->value, baton); + if (root->value) + return fn(key, root->value, baton); + else + return -1; + } /* Partial path normalization: skip consecutive slashes */ while (key[0] == '/' && key[1] == '/') @@ -345,9 +349,6 @@ static int check_common(const char *unmatched, void *value, void *baton) { struct common_dir *dir = value; - if (!dir) - return 0; - if (dir->is_dir && (unmatched[0] == 0 || unmatched[0] == '/')) return dir->is_common; diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index c7b53e494b..501e1a288d 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -288,6 +288,8 @@ test_git_path GIT_COMMON_DIR=bar index .git/index test_git_path GIT_COMMON_DIR=bar HEAD .git/HEAD test_git_path GIT_COMMON_DIR=bar logs/HEAD .git/logs/HEAD test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo .git/logs/refs/bisect/foo +test_git_path GIT_COMMON_DIR=bar logs/refs bar/logs/refs +test_git_path GIT_COMMON_DIR=bar logs/refs/ bar/logs/refs/ test_git_path GIT_COMMON_DIR=bar logs/refs/bisec/foo bar/logs/refs/bisec/foo test_git_path GIT_COMMON_DIR=bar logs/refs/bisec bar/logs/refs/bisec test_git_path GIT_COMMON_DIR=bar logs/refs/bisectfoo bar/logs/refs/bisectfoo