From patchwork Thu Apr 18 18:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13635226 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 AD0D617AD6D for ; Thu, 18 Apr 2024 18:41:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465666; cv=none; b=hAa+ZEv2+KakF3Tq3LGXeNqM2xKXWvDI0ji7/2HX4oqo4LUr2vCcb4BcVLQtgTUsDWCiM11m24pCI5SNm7CMEDr1Svr7ugr+WNgGjTvU6nYTOuZjRNKu9f8un7qGuPrOV+k/Pebh2qwvbZjTc1bc6WMpkR3fVBBjUQxSO5mNnv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465666; c=relaxed/simple; bh=eJiIdjd6VUFH7PtnH1HmEzX+CDrSqTqhklS3Yy+QoYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OMTv6UUgcDcx6O6ytxuG09D26zymJGE/E+mRGrWEO4CJQNNpm7FWU/w8Lejr7EdzG6QRMpgDDytIex5jqMNg0U7N7S2m4RDEgvbfCZcFuGuElGK4D4Z3nmEkEmjTjEKRolGof7mY8rAFqQkcvMXpEHHesz6b0AjiKShqgJneeSA= 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=K8hg/x8m; arc=none smtp.client-ip=209.85.128.41 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="K8hg/x8m" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-415515178ceso9261235e9.0 for ; Thu, 18 Apr 2024 11:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713465662; x=1714070462; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=laVV1Obq0tF6Jin7XzdFzBf2EBgBpO+6tCHi5aSP1wA=; b=K8hg/x8mou2B/jQk2y6DkZ3227p7vilJdD0iqTB4LuHpCgcAlY60EbG2it4a+WJwGm 2SRqHLL1rpIBSwK2aLRiYTz+hsex14uebmi5Nanutn3cADdovNJFFbr154TzMZTytHcD Yr+Sr0908pdcOKGh+ANctPSOVKsupUvxE99ZngaQ1YFrSMXHPIZ9q3ut8jgyoTrdnvel IPhxrqyh4bna+SbDIGMaot4X74pxwfZT+aVhLeY50U6iL7NagZoxQ9b+A90ZEW37FV6h WgZLs/e1SqFtsc3aqz1P47mxTmpQxQlc9h5JTWZikgL0VNDfFPrjK6kdso5FdR9jPUpd J7Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713465662; x=1714070462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=laVV1Obq0tF6Jin7XzdFzBf2EBgBpO+6tCHi5aSP1wA=; b=uEVoQigRp5klUf89Uyn0N1aKjef8vXq35CuPqpemF8sWR4mc6FQs2rS/PRGszUTQjL 2WxS0ukDplz5N/yuh50Pf8Cc4frC1+vGqLMPGjpd3vMrtLwLBR+EsjnIFXz1YoS/FEOj 2aNe1LBLQiQmGvoHUBTdIu5vNPD06D/zhTIWNX2kYJizEVbbIPy1h+sRbuatGzgoEZ/q +oFe00xHFS9ukc88kkMK4aUxKVbUO6vlh+p4euu/fXDzZtLaz8xGPkoDYHXg+qATls5+ s+rQGimJYo1Wmr4sZajnUIFt66MDL8DApnBwnTrnUAowwtjYD9IE1i+YKU4nyHAIU9EN 2GAw== X-Gm-Message-State: AOJu0YwiZ6chwQt0SD7lPXQo68Lu/Fxg3WTPD6kA5lUejW3Ls9tJpVUb JoV5QArSOuDaXXBnBdm77wJl28lhDoceyoK0f1K6JmMgehOFksGLYBnAVw== X-Google-Smtp-Source: AGHT+IEln2OpZmzPbS9EY+UUjSR1pwIRWYbqe2SYnEmUZzy4XVFW0AIpjr/V+d/Rp/PlZtacSB9fjw== X-Received: by 2002:a7b:c5c5:0:b0:418:a786:3760 with SMTP id n5-20020a7bc5c5000000b00418a7863760mr2473675wmk.15.1713465661984; Thu, 18 Apr 2024 11:41:01 -0700 (PDT) Received: from christian-Precision-5550.. (176-138-135-207.abo.bbox.fr. [176.138.135.207]) by smtp.gmail.com with ESMTPSA id t13-20020a05600c450d00b00417f700eaeasm3653670wmo.22.2024.04.18.11.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 11:41:01 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , John Cai , Patrick Steinhardt , Christian Couder , Christian Couder Subject: [PATCH 1/4] rev-list: refactor --missing= Date: Thu, 18 Apr 2024 20:40:40 +0200 Message-ID: <20240418184043.2900955-2-christian.couder@gmail.com> X-Mailer: git-send-email 2.44.0.655.g111bceeb19 In-Reply-To: <20240418184043.2900955-1-christian.couder@gmail.com> References: <20240418184043.2900955-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both `git rev-list` and `git pack-objects` support a `--missing=` feature, but they currently don't share any code for that. In a following commit, we are going to add support for a similar 'missing-action' feature to another command. To avoid duplicating similar code, let's start refactoring the rev-list code for this feature into new "missing.{c,h}" files. For now, this refactoring is about moving code from "builtin/rev-list.c" into new "missing.{c,h}" files. But in a following commit, that refactored code will be used in `git pack-objects` too. As `enum missing_action` and parse_missing_action_value() are moved to "missing.{c,h}", we need to modify the later a bit, so that it stops updating a global variable, but instead returns either -1 on error or the parsed value otherwise. Signed-off-by: Christian Couder --- Makefile | 1 + builtin/rev-list.c | 41 ++++++----------------------------------- missing.c | 26 ++++++++++++++++++++++++++ missing.h | 18 ++++++++++++++++++ 4 files changed, 51 insertions(+), 35 deletions(-) create mode 100644 missing.c create mode 100644 missing.h diff --git a/Makefile b/Makefile index 1e31acc72e..75583a71a0 100644 --- a/Makefile +++ b/Makefile @@ -1076,6 +1076,7 @@ LIB_OBJS += merge-recursive.o LIB_OBJS += merge.o LIB_OBJS += midx.o LIB_OBJS += midx-write.o +LIB_OBJS += missing.o LIB_OBJS += name-hash.o LIB_OBJS += negotiator/default.o LIB_OBJS += negotiator/noop.o diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 77803727e0..f71cc5ebe1 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -20,6 +20,7 @@ #include "reflog-walk.h" #include "oidset.h" #include "packfile.h" +#include "missing.h" static const char rev_list_usage[] = "git rev-list [] ... [--] [...]\n" @@ -71,12 +72,6 @@ static struct oidset omitted_objects; static int arg_print_omitted; /* print objects omitted by filter */ static struct oidset missing_objects; -enum missing_action { - MA_ERROR = 0, /* fail if any missing objects are encountered */ - MA_ALLOW_ANY, /* silently allow ALL missing objects */ - MA_PRINT, /* print ALL missing objects in special section */ - MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */ -}; static enum missing_action arg_missing_action; /* display only the oid of each object encountered */ @@ -392,34 +387,6 @@ static void print_disk_usage(off_t size) strbuf_release(&sb); } -static inline int parse_missing_action_value(const char *value) -{ - if (!strcmp(value, "error")) { - arg_missing_action = MA_ERROR; - return 1; - } - - if (!strcmp(value, "allow-any")) { - arg_missing_action = MA_ALLOW_ANY; - fetch_if_missing = 0; - return 1; - } - - if (!strcmp(value, "print")) { - arg_missing_action = MA_PRINT; - fetch_if_missing = 0; - return 1; - } - - if (!strcmp(value, "allow-promisor")) { - arg_missing_action = MA_ALLOW_PROMISOR; - fetch_if_missing = 0; - return 1; - } - - return 0; -} - static int try_bitmap_count(struct rev_info *revs, int filter_provided_objects) { @@ -569,10 +536,14 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (skip_prefix(arg, "--missing=", &arg)) { + int res; if (revs.exclude_promisor_objects) die(_("options '%s' and '%s' cannot be used together"), "--exclude-promisor-objects", "--missing"); - if (parse_missing_action_value(arg)) + res = parse_missing_action_value(arg); + if (res >= 0) { + arg_missing_action = res; break; + } } } diff --git a/missing.c b/missing.c new file mode 100644 index 0000000000..83e0c5e584 --- /dev/null +++ b/missing.c @@ -0,0 +1,26 @@ +#include "git-compat-util.h" +#include "missing.h" +#include "object-file.h" + +int parse_missing_action_value(const char *value) +{ + if (!strcmp(value, "error")) + return MA_ERROR; + + if (!strcmp(value, "allow-any")) { + fetch_if_missing = 0; + return MA_ALLOW_ANY; + } + + if (!strcmp(value, "print")) { + fetch_if_missing = 0; + return MA_PRINT; + } + + if (!strcmp(value, "allow-promisor")) { + fetch_if_missing = 0; + return MA_ALLOW_PROMISOR; + } + + return -1; +} diff --git a/missing.h b/missing.h new file mode 100644 index 0000000000..c8261dfe55 --- /dev/null +++ b/missing.h @@ -0,0 +1,18 @@ +#ifndef MISSING_H +#define MISSING_H + +enum missing_action { + MA_ERROR = 0, /* fail if any missing objects are encountered */ + MA_ALLOW_ANY, /* silently allow ALL missing objects */ + MA_PRINT, /* print ALL missing objects in special section */ + MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */ +}; + +/* + Return an `enum missing_action` in case parsing is successful or -1 + if parsing failed. Also sets the fetch_if_missing global variable + from "object-file.h". + */ +int parse_missing_action_value(const char *value); + +#endif /* MISSING_H */ From patchwork Thu Apr 18 18:40:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13635227 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 B6DD31442F4 for ; Thu, 18 Apr 2024 18:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465668; cv=none; b=WBbSMZqKVcwC5HRBegpE5QlVGts/JG3bSOXbClo+Or5+7ui1qpbW19dB3itftHu74PZL6xOSoxSYakoGpmh0SzV/7zdC5F+dDWNpTtKoO4ckMTtYlLQ9e80xg4sj1H26ZP/ZDiWXR/CtOwv6ODgReUscZOM3mtlEe1kyLTGj8ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465668; c=relaxed/simple; bh=EVvDz1LlLXbUrD2vKTwc5YSXTSRM10IiSgfejBTEpbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BS/xDDef36XVtvLdCApIinKnwuktTZ1yLEUoXU7vgcCcjsQEwffn5pI8l2dYJszEQ5VmRUMcDSewaFuHJNfe8JMQ1anreKGAyAbGaPz/DGMOEKWV3yIHQpyMxPFdet3ojM2C3YGF1Mo7OjQLYBPouf9os48cI5RvE9LNOwU8zsY= 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=XZjBc/MQ; arc=none smtp.client-ip=209.85.128.51 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="XZjBc/MQ" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-41550858cabso9237895e9.2 for ; Thu, 18 Apr 2024 11:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713465664; x=1714070464; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L7Y0PGMG/OeSnikLwTeetw2v3faGtG5ifwuC7RrJJs4=; b=XZjBc/MQ/uWQJAzHDGZZxhDTSjYOZZ/AqPzCc7sboPGTrSw1ElcbJxp/y+TAqpvVQz PH8Z1y3GBOj08xIvX9l+Ys0ToJuAkKZOWY8IYSri+oLCMqOhPmtHLtJML9jqpaGDSx4n pouDD6xBGfQs8f6MCwYI8gSYnjMVw5wvlbTSNVINaKNzFW2zMUN5bNpa+hY1C59ECDNX 4wencrr7ewgbzcJUQvBMNhVCPCiTYxlsyQQpjF6MnaUog18PdcWWLcP2fepn1pdwmXUQ oIfimcpYKAyfFcpD8EfP7C2ZpfN5CNVBn7AImo4x9tpB6OdkkXSL7FceWyX5KfdWVlKe zmJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713465664; x=1714070464; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L7Y0PGMG/OeSnikLwTeetw2v3faGtG5ifwuC7RrJJs4=; b=EPZK6TlJ/OhXzaDBkxdRTQAEZaO6lCuFjDbxF804A87MMR+a3tjJplUdgHVJuJyLMx +c52Rep5bwFzt09UM1YZiXder0s2eIDkyhZcTkVIvmvJ3AilUpGLRHw6SpiKwrpGxQ6v sR3e1wN/VmWZZxNJQChZ1mTggxIfF8oQc6+5wympfcUjDU81bt1IAAo7z4lW3MkJotuQ 9FCrfa4ntpPmOE1TTcrnfWd/kOv8uYURXhW0ua9vYfm24Q5rrQ/wm42snpzi3dqnfGKF ap1Xd533N1y/0hD45tGp1oVGPEBgwW9JyAn1245CQXHKCSzAF1CgT5IZVhVaM6Lp1d0p xJ5w== X-Gm-Message-State: AOJu0YxpO6d2+NwuD4r8CSp5igd48U8gg1oYw2C2mttRediaa/WPr94M wVB+1f7NL4aNsv/WkUMh45AyNCZ8bcF9cmMqA1if0qdSEUobybveKYQdJg== X-Google-Smtp-Source: AGHT+IGlxfG0VbFGRBh7amyf/w8Xm3FiiCLbMyzBn52NIgHM2GGjDPamRGmtA873tP13ta/rdAZk8g== X-Received: by 2002:a05:600c:1d12:b0:418:fd27:692 with SMTP id l18-20020a05600c1d1200b00418fd270692mr543151wms.14.1713465664239; Thu, 18 Apr 2024 11:41:04 -0700 (PDT) Received: from christian-Precision-5550.. (176-138-135-207.abo.bbox.fr. [176.138.135.207]) by smtp.gmail.com with ESMTPSA id t13-20020a05600c450d00b00417f700eaeasm3653670wmo.22.2024.04.18.11.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 11:41:02 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , John Cai , Patrick Steinhardt , Christian Couder , Christian Couder Subject: [PATCH 2/4] missing: support rejecting --missing=print Date: Thu, 18 Apr 2024 20:40:41 +0200 Message-ID: <20240418184043.2900955-3-christian.couder@gmail.com> X-Mailer: git-send-email 2.44.0.655.g111bceeb19 In-Reply-To: <20240418184043.2900955-1-christian.couder@gmail.com> References: <20240418184043.2900955-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 `git pack-objects` supports the `--missing=` option in the same way as `git rev-list` except when '' is "print", which `git pack-objects` doesn't support. As we want to refactor `git pack-objects` to use the same code from "missing.{c,h}" as `git rev-list` for the `--missing=...` feature, let's make it possible for that code to reject `--missing=print`. `git pack-objects` will then use that code in a following commit. Signed-off-by: Christian Couder --- builtin/rev-list.c | 2 +- missing.c | 4 ++-- missing.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/rev-list.c b/builtin/rev-list.c index f71cc5ebe1..a712a6fd62 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -539,7 +539,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) int res; if (revs.exclude_promisor_objects) die(_("options '%s' and '%s' cannot be used together"), "--exclude-promisor-objects", "--missing"); - res = parse_missing_action_value(arg); + res = parse_missing_action_value(arg, 1); if (res >= 0) { arg_missing_action = res; break; diff --git a/missing.c b/missing.c index 83e0c5e584..d306dea2d9 100644 --- a/missing.c +++ b/missing.c @@ -2,7 +2,7 @@ #include "missing.h" #include "object-file.h" -int parse_missing_action_value(const char *value) +int parse_missing_action_value(const char *value, int print_ok) { if (!strcmp(value, "error")) return MA_ERROR; @@ -12,7 +12,7 @@ int parse_missing_action_value(const char *value) return MA_ALLOW_ANY; } - if (!strcmp(value, "print")) { + if (!strcmp(value, "print") && print_ok) { fetch_if_missing = 0; return MA_PRINT; } diff --git a/missing.h b/missing.h index c8261dfe55..77906691e7 100644 --- a/missing.h +++ b/missing.h @@ -13,6 +13,6 @@ enum missing_action { if parsing failed. Also sets the fetch_if_missing global variable from "object-file.h". */ -int parse_missing_action_value(const char *value); +int parse_missing_action_value(const char *value, int print_ok); #endif /* MISSING_H */ From patchwork Thu Apr 18 18:40:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13635228 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 04F8617F368 for ; Thu, 18 Apr 2024 18:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465672; cv=none; b=nL/1b6UetH65pC6suWFlrkQbtnXnEXaR55PMFXAnz4pz3gOboFr4CsqD8kAHtJqneQPS6Z+05jO8vLatZpF41G2Gq8+AyOYyouIPk8hqqYYHyEfZyJQSJpa/nw7Ds/4tHy5aA1keXhseVoLAoCTPRaN7sPyRlpWO/OpXn/Gv8ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465672; c=relaxed/simple; bh=GrxpEZn5oa0WRpRH5PGeXf4gM1LINqYAM0llRAx9gzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ESdVw3ztOy9xPcprVNmNJegpZ3hUBBtm85qSFHV7MNeW6oH0IpPkkzllZ/nq4Xn7dF/tcuqn/MUouZ9uWxJI6r3xKZFHyJrDAp69GKayznS0GAzD+8CM4BEJRLYEc8Kjs1PsDdmXhyRmHCoc6Jp/T0rzzoxRZNIc4IE6lLS/QYU= 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=SmuHifsd; arc=none smtp.client-ip=209.85.128.50 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="SmuHifsd" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-41551639550so8501495e9.2 for ; Thu, 18 Apr 2024 11:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713465666; x=1714070466; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JfT+Xik2XFEjtCC9S6h6GeC1tDKIph1cZGJdH65ojQI=; b=SmuHifsdxxqpT+UEmKdCd5yL57GdF4A65MTO/yZAjpdOGWPPFzHTWDmVbBFBIUYDK6 ueSafG2Vxx8Une62tdXSfbLJ86j8n6vn1f+2+HofXT51FL57sVttjfteAm7CGzKr00YW GicOMoLr4RDOPLdW1jBv65u7T/l1pWr1Mao2LS66pIDH3/l/Uv5jOiGg9uWET/4BKSzT KdXohVknGxWSUIh7nknS+Pl1FZRaX8oBM3JMvd+xX1eTMp4aYTqa9WBJDA53pNFA+Fdf JbCjCllQJOqa9Orpq6ye4aXxVIIYJt82h31ETJKdveSazqpAiBvhKRjkAhkym8j1O0Bj +KEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713465666; x=1714070466; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JfT+Xik2XFEjtCC9S6h6GeC1tDKIph1cZGJdH65ojQI=; b=Lu8/HxGy8/oW6D+7bGT//NVPCNdY7vNtjtQcDZu6LRn/ve6y0MYiZ9A4kmKvD84hHA T8bumspK6F/mK8WodKJrxvs/fa54rhA5RPlFncQbymiSsCbcSWQdB71CBwdiGm6J2Q+Q fBw4SEoxWr0fO3DGYUgL8AVegqieXroUOsFqN5CCYlKcA4fKhWGA1C+FexMhlqhy8H3q zs6brwgaXKi1ipqliMMpr722jOs6d123TSErbutjlxtc3eicqOHZSqstgB+qtGgnoNKD yYEu3WhGv5uzZuot/GdNFgZFeffrAJge9ffJa2pVNUmCALTkqaZc1ea572Y9mmOwuVeC VQKg== X-Gm-Message-State: AOJu0YxcWjUsVJARYU4CDjLjraNL6VjT81cpWb4C2sohr+noanhMt0hd NRCpb6ZiKkaBuW5gy3mt2+6jI29s3hIMo/RYF0ERKEXdo+P48JnloFdQ3w== X-Google-Smtp-Source: AGHT+IGSbhdbGylApE1YHCGTEXIDy3ID8Qlc/gxma/54doa9bai4yDgvAulePpeXlcYqkUjR6uL5Yg== X-Received: by 2002:a05:600c:3b12:b0:418:c021:33ae with SMTP id m18-20020a05600c3b1200b00418c02133aemr3016046wms.19.1713465666154; Thu, 18 Apr 2024 11:41:06 -0700 (PDT) Received: from christian-Precision-5550.. (176-138-135-207.abo.bbox.fr. [176.138.135.207]) by smtp.gmail.com with ESMTPSA id t13-20020a05600c450d00b00417f700eaeasm3653670wmo.22.2024.04.18.11.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 11:41:04 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , John Cai , Patrick Steinhardt , Christian Couder , Christian Couder Subject: [PATCH 3/4] pack-objects: use the missing action API Date: Thu, 18 Apr 2024 20:40:42 +0200 Message-ID: <20240418184043.2900955-4-christian.couder@gmail.com> X-Mailer: git-send-email 2.44.0.655.g111bceeb19 In-Reply-To: <20240418184043.2900955-1-christian.couder@gmail.com> References: <20240418184043.2900955-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Both `git rev-list` and `git pack-objects` support a `--missing=` option. Previous commits created an API in "missing.{c,h}" to help supporting that option, but only `git rev-list` has been using that API so far. Let's make `git pack-objects` use it too. This involves creating a new show_object_fn_from_action() function to set the `fn_show_object` variable independently from parsing the missing action, which is now performed by the parse_missing_action_value() API function. Signed-off-by: Christian Couder --- builtin/pack-objects.c | 46 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index baf0090fc8..bce586b9a6 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -39,6 +39,7 @@ #include "promisor-remote.h" #include "pack-mtimes.h" #include "parse-options.h" +#include "missing.h" /* * Objects we are going to pack are collected in the `to_pack` structure. @@ -250,11 +251,6 @@ static unsigned long window_memory_limit = 0; static struct string_list uri_protocols = STRING_LIST_INIT_NODUP; -enum missing_action { - MA_ERROR = 0, /* fail if any missing objects are encountered */ - MA_ALLOW_ANY, /* silently allow ALL missing objects */ - MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */ -}; static enum missing_action arg_missing_action; static show_object_fn fn_show_object; @@ -3826,33 +3822,35 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name, show_object(obj, name, data); } +static show_object_fn show_object_fn_from_action(enum missing_action action) +{ + switch (action) { + case MA_ERROR: + return show_object; + case MA_ALLOW_ANY: + return show_object__ma_allow_any; + case MA_ALLOW_PROMISOR: + return show_object__ma_allow_promisor; + default: + BUG("invalid missing action %d", action); + } +} + static int option_parse_missing_action(const struct option *opt UNUSED, const char *arg, int unset) { + int res; + assert(arg); assert(!unset); - if (!strcmp(arg, "error")) { - arg_missing_action = MA_ERROR; - fn_show_object = show_object; - return 0; - } - - if (!strcmp(arg, "allow-any")) { - arg_missing_action = MA_ALLOW_ANY; - fetch_if_missing = 0; - fn_show_object = show_object__ma_allow_any; - return 0; - } + res = parse_missing_action_value(arg, 0); + if (res < 0) + die(_("invalid value for '%s': '%s'"), "--missing", arg); - if (!strcmp(arg, "allow-promisor")) { - arg_missing_action = MA_ALLOW_PROMISOR; - fetch_if_missing = 0; - fn_show_object = show_object__ma_allow_promisor; - return 0; - } + arg_missing_action = res; + fn_show_object = show_object_fn_from_action(arg_missing_action); - die(_("invalid value for '%s': '%s'"), "--missing", arg); return 0; } From patchwork Thu Apr 18 18:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Couder X-Patchwork-Id: 13635229 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 EDA18171090 for ; Thu, 18 Apr 2024 18:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465672; cv=none; b=K925IiIxYKPMikbsg0snTgb9lEZF4doBqzovwQuODS7qifJLF17X2WcS6DsvEJ8UA+fOd2y+o58lycpQLk/+gU9wjKVNaiMi3QC4xxNjmkuTSK3KjMkQ6IXo2Q9cRmM49QRISyZ4kxHP3R3jVoigSpqEurZk0Xk5gDYczp/Jv5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713465672; c=relaxed/simple; bh=SM8HLbabN2WhT3cjZrQLZOTKncyaaB9PTtvhASgUKLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HiR5vMoeLnCMvTr6+gBh8syBM394aVRtbGlRiMgu+ZSNXxbVHDJN/dLPfT91aWLZxpF/H2nAVHmrzRSk6tNdy5gevdnGDpPM2o0ZM2/8b4iJOvsoHId7d6f84MwuLSg7P/IoQz/tQ9n7U7YARivfKow1fO+nhBXYKvyj4pZEGZo= 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=hsHesO9p; arc=none smtp.client-ip=209.85.128.49 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="hsHesO9p" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-418effbc5d4so5150085e9.0 for ; Thu, 18 Apr 2024 11:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713465667; x=1714070467; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l6SqfC+XlSNKud2m+IkuTR+13esum+d7299YKyypEsw=; b=hsHesO9pORjBY38B5kwO79fKu41fNRZjdvl01o0ptADEHNw69tbLbIYJSiM8KEGEdT 7250hszOfoX5r3yxbrrnAn1lAuqDC+XwfVvdHw/lc/UNT7/oflMX2TsoSzRPQlYNt8y3 1xopAE2AE7fEW06bjssGyIqMWcU2Yn/tLD1NVKAt3fVCBw23N2IoLoPxhZ4KOi0moN5N XCUyroiR7+b2uAJIA7Yq6wr8dynVFdOO3gqv1YIqDs8ABDbgwlTUZdB5QLKncMQATXsf bN2BkVB4+QM8I7rIRpioOweSxnsdum9xG8i28EEaU1kr1yu18+Zuw7Q05LB7YlsUG8aQ SKbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713465667; x=1714070467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l6SqfC+XlSNKud2m+IkuTR+13esum+d7299YKyypEsw=; b=uuwJgYUZJWlCQ+TMq8TFTx0bPTcbtxIMNobeD3z9HiLh6HrWAgKHCSfs5nWF4BbrjC OcGSap7VsgyD/PzirlFXy1TimZ1Ahik1iknATYOdfEi83kqQjCye7p4B+vmBxc1yq+qD SpZvfxjhC6bQnkmFz2VkEVFrBvXBS9UU4Jyqn+odtRBuCGkpKovy3CDy7/0e6tv3wgPp Tg9RNrjfe2BjDGz7rdtVpsZJRPX0Eesw9en/8jyh6gY6lV8VKy0Kur5YgxGUlNDG4xLD iITfUe+BiPd/oiHFln1hWTUFt3hL6+7laIa16Ro/McOiSa7xNriOeBatX79AhG7K0Hl/ zPvQ== X-Gm-Message-State: AOJu0YzF9IXEqRpSmTMbqxJoWjmCwUUIhebggnRW1atCKwYJ6YOjy9tf 3Nej1QACAqJcvAqsVvVLXTpKHmURejJ3EIPzPMSTEnJ2K4rh7ilQKVEQ2g== X-Google-Smtp-Source: AGHT+IH7/xr8ugoWWYpzy+FSxW+oqQEr9gKFLDmgTI/+bAsi4TeW355Pb9La8MUY4DgLxxQBFZBFrA== X-Received: by 2002:a05:600c:35d5:b0:414:d95:cc47 with SMTP id r21-20020a05600c35d500b004140d95cc47mr3427121wmq.30.1713465666893; Thu, 18 Apr 2024 11:41:06 -0700 (PDT) Received: from christian-Precision-5550.. (176-138-135-207.abo.bbox.fr. [176.138.135.207]) by smtp.gmail.com with ESMTPSA id t13-20020a05600c450d00b00417f700eaeasm3653670wmo.22.2024.04.18.11.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 11:41:06 -0700 (PDT) From: Christian Couder To: git@vger.kernel.org Cc: Junio C Hamano , John Cai , Patrick Steinhardt , Christian Couder Subject: [PATCH 4/4] upload-pack: allow configuring a missing-action Date: Thu, 18 Apr 2024 20:40:43 +0200 Message-ID: <20240418184043.2900955-5-christian.couder@gmail.com> X-Mailer: git-send-email 2.44.0.655.g111bceeb19 In-Reply-To: <20240418184043.2900955-1-christian.couder@gmail.com> References: <20240418184043.2900955-1-christian.couder@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christian Couder In case some objects are missing from a server, it might still be useful to be able to fetch or clone from it if the client already has the missing objects or can get them in some way. For example, in case both the server and the client are using a separate promisor remote that contain some objects, it can be better if the server doesn't try to send such objects back to the client, but instead let the client get those objects separately from the promisor remote. (The client needs to have the separate promisor remote configured, for that to work.) Another example could be a server where some objects have been corrupted or deleted. It could still be useful for clients who could get those objects from another source, like perhaps a different client, to be able to fetch or clone from the server. To configure what a server should do if there are such missing objects, let's teach `git upload-pack` a new `uploadpack.missingAction` configuration variable. This missing-action works in a similar way as what `git rev-list` and `git pack-objects` already support with their `--missing=` command line options. In fact when `uploadpack.missingAction` is set to something different than "error", `git upload-pack` will just pass the corresponding `--missing=` to `git pack-objects`. So the `uploadpack.missingAction` has the same limitations as `git pack-objects --missing=`. Especially when not using promisor remotes, 'allow-any' works only for blobs. Signed-off-by: Christian Couder --- Documentation/config/uploadpack.txt | 9 ++ missing.c | 16 ++++ missing.h | 2 + t/t5706-upload-pack-missing.sh | 125 ++++++++++++++++++++++++++++ upload-pack.c | 19 +++++ 5 files changed, 171 insertions(+) create mode 100755 t/t5706-upload-pack-missing.sh diff --git a/Documentation/config/uploadpack.txt b/Documentation/config/uploadpack.txt index 16264d82a7..cd70e853b3 100644 --- a/Documentation/config/uploadpack.txt +++ b/Documentation/config/uploadpack.txt @@ -82,3 +82,12 @@ uploadpack.allowRefInWant:: is intended for the benefit of load-balanced servers which may not have the same view of what OIDs their refs point to due to replication delay. + +uploadpack.missingAction:: + If this option is set, `upload-pack` will call + linkgit:git-pack-objects[1] passing it the corresponding + `--missing=` command line option. See the + documentation for that option, to see the valid values and + their meaning. This could be useful if some objects are + missing on a server, but a client already has them or could + still get them from somewhere else. diff --git a/missing.c b/missing.c index d306dea2d9..022ebbe4be 100644 --- a/missing.c +++ b/missing.c @@ -24,3 +24,19 @@ int parse_missing_action_value(const char *value, int print_ok) return -1; } + +const char *missing_action_to_string(enum missing_action action) +{ + switch (action) { + case MA_ERROR: + return "error"; + case MA_ALLOW_ANY: + return "allow-any"; + case MA_PRINT: + return "print"; + case MA_ALLOW_PROMISOR: + return "allow-promisor"; + default: + BUG("invalid missing action %d", action); + } +} diff --git a/missing.h b/missing.h index 77906691e7..ca574f83a0 100644 --- a/missing.h +++ b/missing.h @@ -15,4 +15,6 @@ enum missing_action { */ int parse_missing_action_value(const char *value, int print_ok); +const char *missing_action_to_string(enum missing_action action); + #endif /* MISSING_H */ diff --git a/t/t5706-upload-pack-missing.sh b/t/t5706-upload-pack-missing.sh new file mode 100755 index 0000000000..21bb6aed2b --- /dev/null +++ b/t/t5706-upload-pack-missing.sh @@ -0,0 +1,125 @@ +#!/bin/sh + +test_description='handling of missing objects in upload-pack' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +# Setup the repository with three commits, this way HEAD is always +# available and we can hide commit 1 or 2. +test_expect_success 'setup: create "template" repository' ' + git init template && + test_commit -C template 1 && + test_commit -C template 2 && + test_commit -C template 3 && + test-tool genrandom foo 10240 >template/foo && + git -C template add foo && + git -C template commit -m foo +' + +# A bare repo will act as a server repo with unpacked objects. +test_expect_success 'setup: create bare "server" repository' ' + git clone --bare --no-local template server && + mv server/objects/pack/pack-* . && + packfile=$(ls pack-*.pack) && + git -C server unpack-objects --strict <"$packfile" +' + +# Fetching with 'uploadpack.missingAction=allow-any' only works with +# blobs, as `git pack-objects --missing=allow-any` fails if a missing +# object is not a blob. +test_expect_success "fetch with uploadpack.missingAction=allow-any" ' + oid="$(git -C server rev-parse HEAD:1.t)" && + oid_path="$(test_oid_to_path $oid)" && + path="server/objects/$oid_path" && + + mv "$path" "$path.hidden" && + test_when_finished "mv $path.hidden $path" && + + git init client && + test_when_finished "rm -rf client" && + + # Client needs the missing objects to be available somehow + client_path="client/.git/objects/$oid_path" && + mkdir -p $(dirname "$client_path") && + cp "$path.hidden" "$client_path" && + + test_must_fail git -C client fetch ../server && + git -C server config uploadpack.missingAction error && + test_must_fail git -C client fetch ../server && + git -C server config uploadpack.missingAction allow-any && + git -C client fetch ../server && + git -C server config --unset uploadpack.missingAction +' + +check_missing_objects () { + git -C "$1" rev-list --objects --all --missing=print > all.txt && + sed -n "s/^\?\(.*\)/\1/p" missing.txt && + test_line_count = "$2" missing.txt && + test "$3" = "$(cat missing.txt)" +} + +test_expect_success "setup for testing uploadpack.missingAction=allow-promisor" ' + # Create another bare repo called "server2" + git init --bare server2 && + + # Copy the largest object from server to server2 + obj="HEAD:foo" && + oid="$(git -C server rev-parse $obj)" && + oid_path="$(test_oid_to_path $oid)" && + path="server/objects/$oid_path" && + path2="server2/objects/$oid_path" && + mkdir -p $(dirname "$path2") && + cp "$path" "$path2" && + + # Repack everything first + git -C server -c repack.writebitmaps=false repack -a -d && + + # Repack without the largest object and create a promisor pack on server + git -C server -c repack.writebitmaps=false repack -a -d \ + --filter=blob:limit=5k --filter-to="$(pwd)" && + promisor_file=$(ls server/objects/pack/*.pack | sed "s/\.pack/.promisor/") && + > "$promisor_file" && + + # Check that only one object is missing on the server + check_missing_objects server 1 "$oid" && + + # Configure server2 as promisor remote for server + git -C server remote add server2 "file://$(pwd)/server2" && + git -C server config remote.server2.promisor true && + + git -C server2 config uploadpack.allowFilter true && + git -C server2 config uploadpack.allowAnySHA1InWant true && + git -C server config uploadpack.allowFilter true && + git -C server config uploadpack.allowAnySHA1InWant true +' + +test_expect_success "fetch with uploadpack.missingAction=allow-promisor" ' + git -C server config uploadpack.missingAction allow-promisor && + + # Clone from server to create a client + git clone -c remote.server2.promisor=true \ + -c remote.server2.fetch="+refs/heads/*:refs/remotes/server2/*" \ + -c remote.server2.url="file://$(pwd)/server2" \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is still missing on the server + check_missing_objects server 1 "$oid" +' + +test_expect_success "fetch without uploadpack.missingAction=allow-promisor" ' + git -C server config --unset uploadpack.missingAction && + + # Clone from server to create a client + git clone -c remote.server2.promisor=true \ + -c remote.server2.fetch="+refs/heads/*:refs/remotes/server2/*" \ + -c remote.server2.url="file://$(pwd)/server2" \ + --no-local --filter="blob:limit=5k" server client && + test_when_finished "rm -rf client" && + + # Check that the largest object is not missing on the server anymore + check_missing_objects server 0 "" +' + +test_done diff --git a/upload-pack.c b/upload-pack.c index 902144b9d3..c355ebe1e5 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -29,6 +29,8 @@ #include "write-or-die.h" #include "json-writer.h" #include "strmap.h" +#include "missing.h" +#include "object-file.h" /* Remember to update object flag allocation in object.h */ #define THEY_HAVE (1u << 11) @@ -96,6 +98,8 @@ struct upload_pack_data { const char *pack_objects_hook; + enum missing_action missing_action; + unsigned stateless_rpc : 1; /* v0 only */ unsigned no_done : 1; /* v0 only */ unsigned daemon_mode : 1; /* v0 only */ @@ -315,6 +319,9 @@ static void create_pack_file(struct upload_pack_data *pack_data, strvec_push(&pack_objects.args, "--delta-base-offset"); if (pack_data->use_include_tag) strvec_push(&pack_objects.args, "--include-tag"); + if (pack_data->missing_action) + strvec_pushf(&pack_objects.args, "--missing=%s", + missing_action_to_string(pack_data->missing_action)); if (pack_data->filter_options.choice) { const char *spec = expand_list_objects_filter_spec(&pack_data->filter_options); @@ -1371,6 +1378,18 @@ static int upload_pack_config(const char *var, const char *value, precomposed_unicode = git_config_bool(var, value); } else if (!strcmp("transfer.advertisesid", var)) { data->advertise_sid = git_config_bool(var, value); + } else if (!strcmp("uploadpack.missingaction", var)) { + int res = parse_missing_action_value(value, 0); + if (res < 0) + die(_("invalid value for '%s': '%s'"), var, value); + /* + * parse_missing_action_value() unsets fetch_if_missing + * but if we allow promisor we want to still fetch from + * the promisor remote + */ + if (res == MA_ALLOW_PROMISOR) + fetch_if_missing =1; + data->missing_action = res; } if (parse_object_filter_config(var, value, ctx->kvi, data) < 0)