From patchwork Fri Jul 14 19:20:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kousik Sanagavarapu X-Patchwork-Id: 13314183 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 3F499C0015E for ; Fri, 14 Jul 2023 19:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236528AbjGNTnU (ORCPT ); Fri, 14 Jul 2023 15:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236223AbjGNTnR (ORCPT ); Fri, 14 Jul 2023 15:43:17 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F1D13A96 for ; Fri, 14 Jul 2023 12:43:11 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2633fe9b6c0so2354665a91.1 for ; Fri, 14 Jul 2023 12:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689363791; x=1691955791; 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=iIq083vpn9XP9510hqKokeYSfJjKT6YtmBy5zh8DXEw=; b=RDFgVJDiRN7XR5mYLPqUwCXs/x0zO8dk64FrIsX4EM8ns/HF4j+H+GKG/6GDpbknyt Lfb1ugZjyU5MJ+RnziZ3a4qo+kVYFd/oQUNFyg2WlKY6VTjUf1GE4GTPBzF8Cbvur8gM BFk/pr877xadKRJ/7c4NqamDraCy2XOlNRxjSuEsUwwMCR2tishp6oK+K5jd46Q0xkZF AXHzNrTAv505SHwojjtfxY1jtMiWemYQxstSxWI9gJCtrEGmEpXGC20BERLrOOwXlN87 cR69/hr122PI/Mmkzx6ltLm0bQs9gj9yZjecsHgYePn5lwPdPjfXmFdRsBJOWFFn1uG8 Xiww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689363791; x=1691955791; 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=iIq083vpn9XP9510hqKokeYSfJjKT6YtmBy5zh8DXEw=; b=WgRXZPVlVzcjZupCiHTeF7Obk0+RWcJcB6ZVbClsC+HpbsbdAJCPCqEWag47EHz29X wtaaSN3x6pzbn6+zTW5Mg5fo7AUAosT1t28sgLlquyC9Xw5boYMeK91wAQZOVK6DuXmN z/dWFH+Z/wne2NZmy9tzduiNCTAjMyH6hLQxqJ73d6D7vcGBsELuQ0g0DP8EwMBjJ/tg o7l5Iet1ELReeGkYAB1BWXh0XHkNBsdhsfnx6CypyOWBipp6pyR1fGdiabl8nDl6ISng Qnim8y5bid2ZjaEhEZHcnhWNDxAB9/pXF1r+gsko9hcrZ+NnYB0DRLnjgKs0ocehPwBr RN/g== X-Gm-Message-State: ABy/qLb4y2DzN2+lOX4NkIfOnL9MHdDQ89tJ4yC+ocksECSBDWpeiZ1V 8sq61TkCsjtTig3UdVWrpU6GSYy43sU= X-Google-Smtp-Source: APBJJlGEQMbRCIbHc3tl3GIxgEAGk/AIOIO+8/bpyjrUZ4k66tMmY+TcOT+ev5Ko/GDSM0pv/qzKmA== X-Received: by 2002:a17:90b:3143:b0:263:e299:dff9 with SMTP id ip3-20020a17090b314300b00263e299dff9mr4701734pjb.23.1689363790724; Fri, 14 Jul 2023 12:43:10 -0700 (PDT) Received: from fivlite-virtual-machine.localdomain ([49.37.159.128]) by smtp.gmail.com with ESMTPSA id u63-20020a17090a51c500b00260a5ecd273sm1514820pjh.1.2023.07.14.12.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 12:43:10 -0700 (PDT) From: Kousik Sanagavarapu To: git@vger.kernel.org Cc: Junio C Hamano , Kousik Sanagavarapu , Christian Couder , Hariom Verma Subject: [RFC PATCH v2 1/3] ref filter: add multiple-option parsing functions Date: Sat, 15 Jul 2023 00:50:26 +0530 Message-ID: <20230714194249.66862-2-five231003@gmail.com> X-Mailer: git-send-email 2.41.0.29.g8148156d44.dirty In-Reply-To: <20230714194249.66862-1-five231003@gmail.com> References: <20230705175942.21090-1-five231003@gmail.com> <20230714194249.66862-1-five231003@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The functions match_placeholder_arg_value() match_placeholder_bool_arg() were added in pretty (4f732e0fd7 (pretty: allow %(trailers) options with explicit value, 2019-01-29)) to parse multiple options in an argument to --pretty. For example, git log --pretty="%(trailers:key=Signed-Off-By,separator=%x2C )" will output all the trailers matching the key and seperates them by commas per commit. Add similar functions, match_atom_arg_value() match_atom_bool_arg() in ref-filter. A particular use of this can be seen in the subsequent commit where we parse the options given to a new atom "describe". Mentored-by: Christian Couder Mentored-by: Hariom Verma Signed-off-by: Kousik Sanagavarapu --- ref-filter.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/ref-filter.c b/ref-filter.c index e0d03a9f8e..b170994d9d 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -251,6 +251,65 @@ static int err_bad_arg(struct strbuf *sb, const char *name, const char *arg) return -1; } +static int match_atom_arg_value(const char *to_parse, const char *candidate, + const char **end, const char **valuestart, + size_t *valuelen) +{ + const char *atom; + + if (!(skip_prefix(to_parse, candidate, &atom))) + return 0; + if (valuestart) { + if (*atom == '=') { + *valuestart = atom + 1; + *valuelen = strcspn(*valuestart, ",\0"); + atom = *valuestart + *valuelen; + } else { + if (*atom != ',' && *atom != '\0') + return 0; + *valuestart = NULL; + *valuelen = 0; + } + } + if (*atom == ',') { + *end = atom + 1; + return 1; + } + if (*atom == '\0') { + *end = atom; + return 1; + } + return 0; +} + +static int match_atom_bool_arg(const char *to_parse, const char *candidate, + const char **end, int *val) +{ + const char *argval; + char *strval; + size_t arglen; + int v; + + if (!match_atom_arg_value(to_parse, candidate, end, &argval, &arglen)) + return 0; + + if (!argval) { + *val = 1; + return 1; + } + + strval = xstrndup(argval, arglen); + v = git_parse_maybe_bool(strval); + free(strval); + + if (v == -1) + return 0; + + *val = v; + + return 1; +} + static int color_atom_parser(struct ref_format *format, struct used_atom *atom, const char *color_value, struct strbuf *err) { From patchwork Fri Jul 14 19:20:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kousik Sanagavarapu X-Patchwork-Id: 13314185 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 9EAC4EB64DC for ; Fri, 14 Jul 2023 19:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236568AbjGNTn2 (ORCPT ); Fri, 14 Jul 2023 15:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236223AbjGNTnU (ORCPT ); Fri, 14 Jul 2023 15:43:20 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 823023A9B for ; Fri, 14 Jul 2023 12:43:15 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3a36b309524so1913085b6e.3 for ; Fri, 14 Jul 2023 12:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689363794; x=1691955794; 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=mZkf/NEKqUKsiMxRSMp0Ms6SotAxy2FH1lU5fJeVuDQ=; b=Ds/uTgKHNL3jCrWpJyJpIjt8qKGP73JXjiJe/JowmcmYnIPQCTk/84qeUBSm7HbYtw Mqk3XxYRhZiR/BkwkeOZLy/mjmmV9Ri+OYoBezgO9E+Vr7469QkOruqzODM9i9KluGEg +rK/KsjAA74ierb7zvy1P8NR17blO+gQFfyGA4GMtkx2AGwdMLIPa7WVXMX/nd1/GcLa FSYVmeLyA+5JriJLmZy0axb9kynAbc9DmVNyaYqqltzIsn8dgrbTDzuoVQIzkyAqBMPv yL5fYCh8uqVwrOINtvrtdpfr6GyF3OhhuNhMADUNapU+PWC7zszUKS96Zba3l75mz47T c+vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689363794; x=1691955794; 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=mZkf/NEKqUKsiMxRSMp0Ms6SotAxy2FH1lU5fJeVuDQ=; b=RSebeE8+25Pky+/x+DfaZxn0oFqfNaW+TGU4DRFNPjI11u2LolJX9/ftrdBJ927M4J UEGyuVChIC1flVAdRCfbwSKqom0IG+cmR6Uud6PDY52iInrszItXAD6kZK1f30yulugY 1f6jn3tVdOsd7m7/cTZ609hrApUg5XT8etVtONX1du0gIlzVM4RtThdyRF1oB1OC3uqM acI2K36MNyd9xVhyPl3f2f+Psg1GhYB8YRIVd6jVTZUpFRx55ELY0k9ZIvwyflOmXMPj oWyELixr9EsPtpiOQDTGgc1RJxAA3sbE7xOz6SeZ4zn93pn5kGhhyRrxyxu8MAkYBo4W lpbA== X-Gm-Message-State: ABy/qLYXBokQjkxy0kH9F0glMC/Bw2XhbXkxhQs/2vNg3tg5lVxDr/NI wzxHsj6oT5d1xAi8QYX4HThgYReMiUY= X-Google-Smtp-Source: APBJJlEEvyGFP2mTuUmJBhG4rK80qiCLL+OFDjXmR65Nu6+14Sut7n9w4HQgpSgiMqiIiFsc1qlS4g== X-Received: by 2002:aca:b946:0:b0:3a1:dc7e:bb39 with SMTP id j67-20020acab946000000b003a1dc7ebb39mr5986765oif.18.1689363794401; Fri, 14 Jul 2023 12:43:14 -0700 (PDT) Received: from fivlite-virtual-machine.localdomain ([49.37.159.128]) by smtp.gmail.com with ESMTPSA id u63-20020a17090a51c500b00260a5ecd273sm1514820pjh.1.2023.07.14.12.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 12:43:14 -0700 (PDT) From: Kousik Sanagavarapu To: git@vger.kernel.org Cc: Junio C Hamano , Kousik Sanagavarapu , Christian Couder , Hariom Verma Subject: [PATCH v2 2/3] ref-filter: add new "describe" atom Date: Sat, 15 Jul 2023 00:50:27 +0530 Message-ID: <20230714194249.66862-3-five231003@gmail.com> X-Mailer: git-send-email 2.41.0.29.g8148156d44.dirty In-Reply-To: <20230714194249.66862-1-five231003@gmail.com> References: <20230705175942.21090-1-five231003@gmail.com> <20230714194249.66862-1-five231003@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Duplicate the logic of %(describe) and friends from pretty to ref-filter. In the future, this change helps in unifying both the formats as ref-filter will be able to do everything that pretty is doing and we can have a single interface. The new atom "describe" and its friends are equivalent to the existing pretty formats with the same name. Mentored-by: Christian Couder Mentored-by: Hariom Verma Signed-off-by: Kousik Sanagavarapu --- Documentation/git-for-each-ref.txt | 23 +++++ ref-filter.c | 147 +++++++++++++++++++++++++++++ t/t6300-for-each-ref.sh | 85 +++++++++++++++++ 3 files changed, 255 insertions(+) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 1e215d4e73..2a44119f38 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -231,6 +231,29 @@ ahead-behind::: commits ahead and behind, respectively, when comparing the output ref to the `` specified in the format. +describe[:options]:: Human-readable name, like + link-git:git-describe[1]; empty string for + undescribable commits. The `describe` string may be + followed by a colon and zero or more comma-separated + options. Descriptions can be inconsistent when tags + are added or removed at the same time. ++ +-- +tags=;; Instead of only considering annotated tags, consider + lightweight tags as well; see the corresponding option + in linkgit:git-describe[1] for details. +abbrev=;; Use at least hexadecimal digits; see + the corresponding option in linkgit:git-describe[1] + for details. +match=;; Only consider tags matching the given `glob(7)` pattern, + excluding the "refs/tags/" prefix; see the corresponding + option in linkgit:git-describe[1] for details. +exclude=;; Do not consider tags matching the given `glob(7)` + pattern, excluding the "refs/tags/" prefix; see the + corresponding option in linkgit:git-describe[1] for + details. +-- + In addition to the above, for commit and tag objects, the header field names (`tree`, `parent`, `object`, `type`, and `tag`) can be used to specify the value in the header field. diff --git a/ref-filter.c b/ref-filter.c index b170994d9d..fe4830dbea 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2,9 +2,11 @@ #include "alloc.h" #include "environment.h" #include "gettext.h" +#include "config.h" #include "gpg-interface.h" #include "hex.h" #include "parse-options.h" +#include "run-command.h" #include "refs.h" #include "wildmatch.h" #include "object-name.h" @@ -146,6 +148,7 @@ enum atom_type { ATOM_TAGGERDATE, ATOM_CREATOR, ATOM_CREATORDATE, + ATOM_DESCRIBE, ATOM_SUBJECT, ATOM_BODY, ATOM_TRAILERS, @@ -215,6 +218,11 @@ static struct used_atom { struct email_option { enum { EO_RAW, EO_TRIM, EO_LOCALPART } option; } email_option; + struct { + enum { D_BARE, D_TAGS, D_ABBREV, + D_EXCLUDE, D_MATCH } option; + const char **args; + } describe; struct refname_atom refname; char *head; } u; @@ -521,6 +529,94 @@ static int contents_atom_parser(struct ref_format *format, struct used_atom *ato return 0; } +static int describe_atom_parser(struct ref_format *format UNUSED, + struct used_atom *atom, + const char *arg, struct strbuf *err) +{ + const char *describe_opts[] = { + "", + "tags", + "abbrev", + "match", + "exclude", + NULL + }; + + struct strvec args = STRVEC_INIT; + for (;;) { + int found = 0; + const char *argval; + size_t arglen = 0; + int optval = 0; + int opt; + + if (!arg) + break; + + for (opt = D_BARE; !found && describe_opts[opt]; opt++) { + switch(opt) { + case D_BARE: + /* + * Do nothing. This is the bare describe + * atom and we already handle this above. + */ + break; + case D_TAGS: + if (match_atom_bool_arg(arg, describe_opts[opt], + &arg, &optval)) { + if (!optval) + strvec_pushf(&args, "--no-%s", + describe_opts[opt]); + else + strvec_pushf(&args, "--%s", + describe_opts[opt]); + found = 1; + } + break; + case D_ABBREV: + if (match_atom_arg_value(arg, describe_opts[opt], + &arg, &argval, &arglen)) { + char *endptr; + int ret = 0; + + if (!arglen) + ret = -1; + if (strtol(argval, &endptr, 10) < 0) + ret = -1; + if (endptr - argval != arglen) + ret = -1; + + if (ret) + return strbuf_addf_ret(err, ret, + _("positive value expected describe:abbrev=%s"), argval); + strvec_pushf(&args, "--%s=%.*s", + describe_opts[opt], + (int)arglen, argval); + found = 1; + } + break; + case D_MATCH: + case D_EXCLUDE: + if (match_atom_arg_value(arg, describe_opts[opt], + &arg, &argval, &arglen)) { + if (!arglen) + return strbuf_addf_ret(err, -1, + _("value expected describe:%s="), describe_opts[opt]); + strvec_pushf(&args, "--%s=%.*s", + describe_opts[opt], + (int)arglen, argval); + found = 1; + } + break; + } + } + if (!found) + break; + } + atom->u.describe.args = strvec_detach(&args); + return 0; +} + static int raw_atom_parser(struct ref_format *format UNUSED, struct used_atom *atom, const char *arg, struct strbuf *err) @@ -723,6 +819,7 @@ static struct { [ATOM_TAGGERDATE] = { "taggerdate", SOURCE_OBJ, FIELD_TIME }, [ATOM_CREATOR] = { "creator", SOURCE_OBJ }, [ATOM_CREATORDATE] = { "creatordate", SOURCE_OBJ, FIELD_TIME }, + [ATOM_DESCRIBE] = { "describe", SOURCE_OBJ, FIELD_STR, describe_atom_parser }, [ATOM_SUBJECT] = { "subject", SOURCE_OBJ, FIELD_STR, subject_atom_parser }, [ATOM_BODY] = { "body", SOURCE_OBJ, FIELD_STR, body_atom_parser }, [ATOM_TRAILERS] = { "trailers", SOURCE_OBJ, FIELD_STR, trailers_atom_parser }, @@ -1542,6 +1639,54 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size } } +static void grab_describe_values(struct atom_value *val, int deref, + struct object *obj) +{ + struct commit *commit = (struct commit *)obj; + int i; + + for (i = 0; i < used_atom_cnt; i++) { + struct used_atom *atom = &used_atom[i]; + enum atom_type type = atom->atom_type; + const char *name = atom->name; + struct atom_value *v = &val[i]; + + struct child_process cmd = CHILD_PROCESS_INIT; + struct strbuf out = STRBUF_INIT; + struct strbuf err = STRBUF_INIT; + + if (type != ATOM_DESCRIBE) + continue; + + if (!!deref != (*name == '*')) + continue; + if (deref) + name++; + + if (!skip_prefix(name, "describe", &name) || + (*name && *name != ':')) + continue; + if (!*name) + name = NULL; + else + name++; + + cmd.git_cmd = 1; + strvec_push(&cmd.args, "describe"); + strvec_pushv(&cmd.args, atom->u.describe.args); + strvec_push(&cmd.args, oid_to_hex(&commit->object.oid)); + if (pipe_command(&cmd, NULL, 0, &out, 0, &err, 0) < 0) { + error(_("failed to run 'describe'")); + v->s = xstrdup(""); + continue; + } + strbuf_rtrim(&out); + v->s = strbuf_detach(&out, NULL); + + strbuf_release(&err); + } +} + /* See grab_values */ static void grab_sub_body_contents(struct atom_value *val, int deref, struct expand_data *data) { @@ -1651,12 +1796,14 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, s grab_tag_values(val, deref, obj); grab_sub_body_contents(val, deref, data); grab_person("tagger", val, deref, buf); + grab_describe_values(val, deref, obj); break; case OBJ_COMMIT: grab_commit_values(val, deref, obj); grab_sub_body_contents(val, deref, data); grab_person("author", val, deref, buf); grab_person("committer", val, deref, buf); + grab_describe_values(val, deref, obj); break; case OBJ_TREE: /* grab_tree_values(val, deref, obj, buf, sz); */ diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 5c00607608..98ea37d336 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -561,6 +561,91 @@ test_expect_success 'color.ui=always does not override tty check' ' test_cmp expected.bare actual ' +test_expect_success 'describe atom vs git describe' ' + test_when_finished "rm -rf describe-repo" && + + git init describe-repo && + ( + cd describe-repo && + + test_commit --no-tag one && + git tag tagone && + + test_commit --no-tag two && + git tag -a -m "tag two" tagtwo && + + git for-each-ref refs/tags/ --format="%(objectname)" >obj && + while read hash + do + if desc=$(git describe $hash) + then + : >expect-contains-good + else + : >expect-contains-bad + fi && + echo "$hash $desc" || return 1 + done expect && + test_path_exists expect-contains-good && + test_path_exists expect-contains-bad && + + git for-each-ref --format="%(objectname) %(describe)" \ + refs/tags/ >actual 2>err && + test_cmp expect actual && + test_must_be_empty err + ) +' + +test_expect_success 'describe:tags vs describe --tags' ' + test_when_finished "git tag -d tagname" && + git tag tagname && + git describe --tags >expect && + git for-each-ref --format="%(describe:tags)" refs/heads/ >actual && + test_cmp expect actual +' + +test_expect_success 'describe:abbrev=... vs describe --abbrev=...' ' + test_when_finished "git tag -d tagname" && + + # Case 1: We have commits between HEAD and the most + # recent tag reachable from it + test_commit --no-tag file && + git describe --abbrev=14 >expect && + git for-each-ref --format="%(describe:abbrev=14)" \ + refs/heads/ >actual && + test_cmp expect actual && + + # Make sure the hash used is atleast 14 digits long + sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" hexpart && + test 15 -le $(wc -c expect && + git for-each-ref --format="%(describe:abbrev=14)" \ + refs/heads/ >actual && + test_cmp expect actual && + test tagname = $(cat actual) +' + +test_expect_success 'describe:match=... vs describe --match ...' ' + test_when_finished "git tag -d tag-match" && + git tag -a -m "tag match" tag-match && + git describe --match "*-match" >expect && + git for-each-ref --format="%(describe:match="*-match")" \ + refs/heads/ >actual && + test_cmp expect actual +' + +test_expect_success 'describe:exclude:... vs describe --exclude ...' ' + test_when_finished "git tag -d tag-exclude" && + git tag -a -m "tag exclude" tag-exclude && + git describe --exclude "*-exclude" >expect && + git for-each-ref --format="%(describe:exclude="*-exclude")" \ + refs/heads/ >actual && + test_cmp expect actual +' + cat >expected <<\EOF heads/main tags/main From patchwork Fri Jul 14 19:20:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kousik Sanagavarapu X-Patchwork-Id: 13314184 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 0170EC001DC for ; Fri, 14 Jul 2023 19:43:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236546AbjGNTn3 (ORCPT ); Fri, 14 Jul 2023 15:43:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236541AbjGNTn1 (ORCPT ); Fri, 14 Jul 2023 15:43:27 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CD322D57 for ; Fri, 14 Jul 2023 12:43:19 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-262cc036fa4so1205099a91.3 for ; Fri, 14 Jul 2023 12:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689363798; x=1691955798; 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=PulRkw7tNkYBiDShmlY+qsgl0+6GG/LqbAZrLM0NDzI=; b=Zz5bgaftjX+1FIeO/eRxKxI1pmrSIcsPWNmm4km+gSSUgjdRQMTV3jFbutLXat8H0t eOCRtMMfqP899E1WvEHqsYFAjG8kUEThYmi4pb/wl24C9XliMpqZG1MpQkpi6+oi8OCA jO4lnVw3OgXY69lyqiLB9gk2WDp9hl0h1aLHAaxWoyjQqbPI18x3IYUFcMpqsNF6AX3N AAPp6eO907AyyDK3zx9bsMLT2neJNfCjR6vVh5A8BSnq8hzduOVZPTnqPuL3VPgjMsXb EFUJOpooGFW3EK0gO2x3uB1E0gS8xLNvOIQsGqXFlQYy/90mtHxN9s1us06DfPhS4dP0 4sxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689363798; x=1691955798; 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=PulRkw7tNkYBiDShmlY+qsgl0+6GG/LqbAZrLM0NDzI=; b=bSuUlRX2mfIVufwFVmZPWFUY3KioJx3iUmFy9XbV6OW0jTGmcdUe2d6OgNfeShMx4j V+H9GoSDqMJqkfM5issDncW5TjcrC61gdFeUKEWGNc7fTkkE4zatCqacRGJKzOdfKrtv DPfwumWc9278frUEtH7cz99r0lKgstcpR3lziWB2ak9zTw0h5b4Km3leKEkowPhPeBgK yHfT7hlbF8MH5xdDDbmGXNgWB30EMvHaa+0Y7fY18pjegvQCnY0nWiPWjeMLnQrFNfzZ L11lge1+stijufrHQrLsw+UstFrYQHz7EfALNkWQ5n5sj5Jwulvzjc6hksx6EdObKB43 Zmzw== X-Gm-Message-State: ABy/qLYGD7zIMwBvS9Rm7tDCIYQDH/16CaU2qLD9LsUTThp95IV+gjBD tek+nTJRYndt4tod6juP7sWgohmBybg= X-Google-Smtp-Source: APBJJlF/3KAoRW/r9u7v2RU2tV3nHl8SGExBkj77iO0DrsY92Dm3LJj9w3PJ+EeqA0uQ0qp+ITrLgA== X-Received: by 2002:a17:90a:db87:b0:263:6ccd:38b5 with SMTP id h7-20020a17090adb8700b002636ccd38b5mr3920810pjv.1.1689363798517; Fri, 14 Jul 2023 12:43:18 -0700 (PDT) Received: from fivlite-virtual-machine.localdomain ([49.37.159.128]) by smtp.gmail.com with ESMTPSA id u63-20020a17090a51c500b00260a5ecd273sm1514820pjh.1.2023.07.14.12.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 12:43:18 -0700 (PDT) From: Kousik Sanagavarapu To: git@vger.kernel.org Cc: Junio C Hamano , Kousik Sanagavarapu , Christian Couder , Hariom Verma Subject: [PATCH v2 3/3] t6300: run describe atom tests on a different repo Date: Sat, 15 Jul 2023 00:50:28 +0530 Message-ID: <20230714194249.66862-4-five231003@gmail.com> X-Mailer: git-send-email 2.41.0.29.g8148156d44.dirty In-Reply-To: <20230714194249.66862-1-five231003@gmail.com> References: <20230705175942.21090-1-five231003@gmail.com> <20230714194249.66862-1-five231003@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The tests for "describe" atom and its friends currently run on the main repo of t6300, expect for the test for "bare describe", which is run on "describe-repo". Things can get messy with the other tests when such changes to a repo are done (for example, a new commit or a tag is introduced), especially in t6300 where the tests depend on commits and tags. An example for this can be seen in [1], where writing the tests the current way fails the test "Verify sorts with raw:size" on linux-sha256. This, at first glance, seems totally unrelated. Digging in a bit deeper, it is apparent that this behavior is because of the changes in the repo introduced when writing the "describe" tests, which changes the raw:size of an object. Such a change in raw-size would have been, however, small if we were dealing with SHA1, but since we are dealing with SHA256, the change in raw:size is so significant that it fails the above mentioned test. So, run all the "describe" atom tests on "describe-repo", which doesn't interfere with the main repo on which the tests in t6300 are run. [1]: https://github.com/five-sh/git/actions/runs/5446892074/jobs/9908256427 Mentored-by: Christian Couder Mentored-by: Hariom Verma Signed-off-by: Kousik Sanagavarapu --- t/t6300-for-each-ref.sh | 101 +++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 98ea37d336..181b04e699 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -561,9 +561,7 @@ test_expect_success 'color.ui=always does not override tty check' ' test_cmp expected.bare actual ' -test_expect_success 'describe atom vs git describe' ' - test_when_finished "rm -rf describe-repo" && - +test_expect_success 'setup for describe atom tests' ' git init describe-repo && ( cd describe-repo && @@ -572,9 +570,16 @@ test_expect_success 'describe atom vs git describe' ' git tag tagone && test_commit --no-tag two && - git tag -a -m "tag two" tagtwo && + git tag -a -m "tag two" tagtwo + ) +' + +test_expect_success 'describe atom vs git describe' ' + ( + cd describe-repo && - git for-each-ref refs/tags/ --format="%(objectname)" >obj && + git for-each-ref --format="%(objectname)" \ + refs/tags/ >obj && while read hash do if desc=$(git describe $hash) @@ -596,54 +601,62 @@ test_expect_success 'describe atom vs git describe' ' ' test_expect_success 'describe:tags vs describe --tags' ' - test_when_finished "git tag -d tagname" && - git tag tagname && - git describe --tags >expect && - git for-each-ref --format="%(describe:tags)" refs/heads/ >actual && - test_cmp expect actual + ( + cd describe-repo && + git describe --tags >expect && + git for-each-ref --format="%(describe:tags)" \ + refs/heads/ >actual && + test_cmp expect actual + ) ' test_expect_success 'describe:abbrev=... vs describe --abbrev=...' ' - test_when_finished "git tag -d tagname" && - - # Case 1: We have commits between HEAD and the most - # recent tag reachable from it - test_commit --no-tag file && - git describe --abbrev=14 >expect && - git for-each-ref --format="%(describe:abbrev=14)" \ - refs/heads/ >actual && - test_cmp expect actual && - - # Make sure the hash used is atleast 14 digits long - sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" hexpart && - test 15 -le $(wc -c expect && - git for-each-ref --format="%(describe:abbrev=14)" \ - refs/heads/ >actual && - test_cmp expect actual && - test tagname = $(cat actual) + ( + cd describe-repo && + + # Case 1: We have commits between HEAD and the most + # recent tag reachable from it + test_commit --no-tag file && + git describe --abbrev=14 >expect && + git for-each-ref --format="%(describe:abbrev=14)" \ + refs/heads/ >actual && + test_cmp expect actual && + + # Make sure the hash used is atleast 14 digits long + sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" hexpart && + test 15 -le $(wc -c expect && + git for-each-ref --format="%(describe:abbrev=14)" \ + refs/heads/ >actual && + test_cmp expect actual && + test tagname = $(cat actual) + ) ' test_expect_success 'describe:match=... vs describe --match ...' ' - test_when_finished "git tag -d tag-match" && - git tag -a -m "tag match" tag-match && - git describe --match "*-match" >expect && - git for-each-ref --format="%(describe:match="*-match")" \ - refs/heads/ >actual && - test_cmp expect actual + ( + cd describe-repo && + git tag -a -m "tag match" tag-match && + git describe --match "*-match" >expect && + git for-each-ref --format="%(describe:match="*-match")" \ + refs/heads/ >actual && + test_cmp expect actual + ) ' test_expect_success 'describe:exclude:... vs describe --exclude ...' ' - test_when_finished "git tag -d tag-exclude" && - git tag -a -m "tag exclude" tag-exclude && - git describe --exclude "*-exclude" >expect && - git for-each-ref --format="%(describe:exclude="*-exclude")" \ - refs/heads/ >actual && - test_cmp expect actual + ( + cd describe-repo && + git tag -a -m "tag exclude" tag-exclude && + git describe --exclude "*-exclude" >expect && + git for-each-ref --format="%(describe:exclude="*-exclude")" \ + refs/heads/ >actual && + test_cmp expect actual + ) ' cat >expected <<\EOF