From patchwork Thu Apr 21 14:57:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12821805 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFCFFC433EF for ; Thu, 21 Apr 2022 14:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389773AbiDUPAs (ORCPT ); Thu, 21 Apr 2022 11:00:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389751AbiDUPAo (ORCPT ); Thu, 21 Apr 2022 11:00:44 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10080443C3 for ; Thu, 21 Apr 2022 07:57:54 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id w4so7041042wrg.12 for ; Thu, 21 Apr 2022 07:57:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=+ol0+1Qc4bYwYytjRhghEShUA8gWYWE4SDrmV1uHNy4=; b=JCab6JprPlTsyc0LCsaoc4cLaVuBISQt/Ui10LVDXeu74+2SalnM79tu6VD2UqpbZG yEHOv2MxCh8tVk0k1ARpGYO+LUvp778nFATlnlhDbw/ZUNLQm1/cP0JQJKGKczAgm80u NMFIGQ/aUYNUi9dlyY0gjS9znlLUtGf78Q8y+3UjQOm85vqUZQ0zpcUr5UyEzT8tKjvj C0DliFBowxPE1cbZgFAGQqmbWy/E5qiLU180v+IXaKyUTqc3A6riNLgLNmok6Nx49H1F 5aATilFZi91AHK8LR43yt6sGCodcDLS4W95+fHfHoDG5tBbgb2k1xibRb6Wb3Etwq86T 6C4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=+ol0+1Qc4bYwYytjRhghEShUA8gWYWE4SDrmV1uHNy4=; b=DhnLYVP1MzlpAnzoGu3KEkBAR7UZtATQDapKHIXQ+MgEk6/aC0jT1rauVrnmZuxs/X 2c6cY0xym/4obpaTrQB0UhztPVmw3tmvbPpOp+VuVDLmXy6JxycWg6f0Zo36rKFiF3z4 io5ui3llN0KYWHVqwd6D4/TGIoI+f/UePCQxIqc7cuP9Ne5ReqHDQpKewPRIDFpkTWyy I9PgYZU8IsxHDO6NeyHtaX3dnjCTIG4nUoWj3hl+wjiOgwq8IIxyC/QVO73LL09qlBLs JHQyEhAs0PEerAGBuENxX+511GxMcgpMdKVyZlYGc96PySJVfssjr39XblMDHJiz5NKT z8vw== X-Gm-Message-State: AOAM5314TeqJ9mdGIO7BA6NArbRfbC9dRnF6lYnNQGzJMRukXuLzgxh4 2h3rQidIVIJXR1O+ORodZzlsR6y7WMY= X-Google-Smtp-Source: ABdhPJy001k/ItsA7eg9UURHtF6CoEoAn9yoJ1GviwxpnJPiyBblRmXCSwkHPu0i2urMPBwOyy60gQ== X-Received: by 2002:a05:6000:2c5:b0:20a:9675:d26c with SMTP id o5-20020a05600002c500b0020a9675d26cmr91451wry.185.1650553072251; Thu, 21 Apr 2022 07:57:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o13-20020a05600c4fcd00b00392951086efsm2430504wmq.34.2022.04.21.07.57.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 07:57:51 -0700 (PDT) Message-Id: <34785a0c7cc6c3547951fb29fc2b3c1cf8be6f54.1650553069.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 21 Apr 2022 14:57:48 +0000 Subject: [PATCH 1/2] midx: use real paths in lookup_multi_pack_index() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, vdye@github.com, me@ttaylorr.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee This helper looks for a parsed multi-pack-index whose object directory matches the given object_dir. Before going into the loop over the parsed multi-pack-indexes, it calls find_odb() to ensure that the given object_dir is actually a known object directory. However, find_odb() uses real-path manipulations to compare the input to the alternate directories. This same real-path comparison is not used in the loop, leading to potential issues with the strcmp(). Update the method to use the real-path values instead. Signed-off-by: Derrick Stolee --- midx.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/midx.c b/midx.c index 107365d2114..3db0e47735f 100644 --- a/midx.c +++ b/midx.c @@ -1132,17 +1132,26 @@ cleanup: static struct multi_pack_index *lookup_multi_pack_index(struct repository *r, const char *object_dir) { + struct multi_pack_index *result = NULL; struct multi_pack_index *cur; + char *obj_dir_real = real_pathdup(object_dir, 1); + struct strbuf cur_path_real = STRBUF_INIT; /* Ensure the given object_dir is local, or a known alternate. */ - find_odb(r, object_dir); + find_odb(r, obj_dir_real); for (cur = get_multi_pack_index(r); cur; cur = cur->next) { - if (!strcmp(object_dir, cur->object_dir)) - return cur; + strbuf_realpath(&cur_path_real, cur->object_dir, 1); + if (!strcmp(obj_dir_real, cur_path_real.buf)) { + result = cur; + goto cleanup; + } } - return NULL; +cleanup: + free(obj_dir_real); + strbuf_release(&cur_path_real); + return result; } static int write_midx_internal(const char *object_dir, From patchwork Thu Apr 21 14:57:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12821806 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 598CAC433EF for ; Thu, 21 Apr 2022 14:58:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389789AbiDUPAy (ORCPT ); Thu, 21 Apr 2022 11:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389750AbiDUPAo (ORCPT ); Thu, 21 Apr 2022 11:00:44 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B54543EF0 for ; Thu, 21 Apr 2022 07:57:55 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id h25so1045349wrc.13 for ; Thu, 21 Apr 2022 07:57:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=0+QHon3pu/abWGcCTSu1HZXk7OetzVMGxKkfNlP+AWo=; b=ZpGITeXq4R+i00SNj8Upxqsclp6o8/ufyFlO61r8OgPlHiEQq1eaIPoQ5TeW0JkOtG VnBMKorSm3u1pRQfWeKEijArOEzkAvQdsgYMFqFaJzGKRmY1GoiwIB53eJ2KRuqrednO 9nwHe0o3o01nUTsY5rzQDERV8Ikhb4e3pXggRIWgqWb+iK+s33x2lHIuNnDk/FT+f86G 4u7KUyYdXpUqn7DU6EPEVjKO8y53sxP7286IpPX7ADqnOF7sFveNuwCdWaovIbyFLa2b OiQq307N3OnglVs8fMgJxejlCK2D0+NJkjT3rs6bSTFHf2vVWCoD73IU1uXsFJaNbvkL 2nMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=0+QHon3pu/abWGcCTSu1HZXk7OetzVMGxKkfNlP+AWo=; b=r5nuFehgmc+4lZgc5siwnblewos7kF8z/YT6vkdU+QeXVbUdbGgWcHdQ5w4UzNZrpQ Ql8fpM4Zq1bTCmrtwB/xgmFi/9kYaJB0J5Bg0cAJkvNssrLNPXwvjIYa6WEQJ4j3p045 OI7cOSZRT8YgCfhHIstUbbCSlE4xvmAk07ExSgtWLFnIDIHYe7biFX2eGWni3ElYdKnO fa+BqTy3G70MiRmBAmf0NWP93OlepkBNhyDdHW400cc169V9rDAqp9b/E5EkLyf0nO2K 3HxiJ4++j3tH5rMU/DKwFf1HpBfbG7ySKa4Q5uZy8i7vDulBr+0pm3uCkawNb1xbuhNm 5Q8g== X-Gm-Message-State: AOAM533HGwQOWS1nFSwvxVG0rpsSm1tcROIduVTGvBT0acnTKw66k4f+ 6MP4fwhczebVO7eCldBRZRiMs8P/EQA= X-Google-Smtp-Source: ABdhPJztPmZTIahj39cE+1f745DE3qFEXIQhDeuhQdw/ZBoxpr2i1CPAwTVPt2a+aIRTgjIOMv3M2g== X-Received: by 2002:adf:e9d1:0:b0:207:b80e:dc22 with SMTP id l17-20020adfe9d1000000b00207b80edc22mr85778wrn.405.1650553073318; Thu, 21 Apr 2022 07:57:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o2-20020a5d6482000000b0020a96536fcdsm2657144wri.57.2022.04.21.07.57.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 07:57:52 -0700 (PDT) Message-Id: <0435406e2db6c5977928a2b0b0b79e66c0a078ee.1650553069.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 21 Apr 2022 14:57:49 +0000 Subject: [PATCH 2/2] multi-pack-index: use --object-dir real path Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, vdye@github.com, me@ttaylorr.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The --object-dir argument to 'git multi-pack-index' allows a user to specify an alternate to use instead of the local $GITDIR. This is used by third-party tools like VFS for Git to maintain the pack-files in a "shared object cache" used by multiple clones. On Windows, the user can specify a path using a Windows-style file path with backslashes such as "C:\Path\To\ObjectDir". This same path style is used in the .git/objects/info/alternates file, so it already matches the path of that alternate. However, find_odb() converts these paths to real-paths for the comparison, which use forward slashes. As of the previous change, lookup_multi_pack_index() uses real-paths, so it correctly finds the target multi-pack-index when given these paths. Some commands such as 'git multi-pack-index repack' call child processes using the object_dir value, so it can be helpful to convert the path to the real-path before sending it to those locations. Adding the normalization in builtin/multi-pack-index.c is a little complicated because of how the sub-commands were split in 60ca94769 (builtin/multi-pack-index.c: split sub-commands, 2021-03-30). The --object-dir argument could be parsed before the sub-command name _or_ after it. Thus, create a normalize_object_dir() helper to call after all arguments are parsed, but before any logic is run on that object dir. Signed-off-by: Derrick Stolee --- builtin/multi-pack-index.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 4480ba39827..3853960f9ba 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -90,6 +90,14 @@ static void read_packs_from_stdin(struct string_list *to) strbuf_release(&buf); } +static void normalize_object_dir(void) +{ + if (!opts.object_dir) + opts.object_dir = get_object_directory(); + else + opts.object_dir = real_pathdup(opts.object_dir, 1); +} + static int cmd_multi_pack_index_write(int argc, const char **argv) { struct option *options; @@ -127,6 +135,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv) FREE_AND_NULL(options); + normalize_object_dir(); + if (opts.stdin_packs) { struct string_list packs = STRING_LIST_INIT_DUP; int ret; @@ -169,6 +179,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv) FREE_AND_NULL(options); + normalize_object_dir(); + return verify_midx_file(the_repository, opts.object_dir, opts.flags); } @@ -195,6 +207,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv) FREE_AND_NULL(options); + normalize_object_dir(); + return expire_midx_packs(the_repository, opts.object_dir, opts.flags); } @@ -225,6 +239,8 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv) FREE_AND_NULL(options); + normalize_object_dir(); + return midx_repack(the_repository, opts.object_dir, (size_t)opts.batch_size, opts.flags); } @@ -241,9 +257,6 @@ int cmd_multi_pack_index(int argc, const char **argv, builtin_multi_pack_index_usage, PARSE_OPT_STOP_AT_NON_OPTION); - if (!opts.object_dir) - opts.object_dir = get_object_directory(); - if (!argc) goto usage;