From patchwork Wed Feb 16 08:14:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12748162 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 BA85FC433F5 for ; Wed, 16 Feb 2022 08:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231502AbiBPIO2 (ORCPT ); Wed, 16 Feb 2022 03:14:28 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:49326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231477AbiBPIO1 (ORCPT ); Wed, 16 Feb 2022 03:14:27 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 854D62503AB for ; Wed, 16 Feb 2022 00:14:15 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id d14-20020a05600c34ce00b0037bf4d14dc7so971282wmq.3 for ; Wed, 16 Feb 2022 00:14:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FhEc+YlMw+SDx6rzPsXWqcBAIYaqydANiL45K/IQxg0=; b=WFUu681qpps330HChUt/W0JhZi8M5fzssLBdRadSYRqPHfaQVy+DzT5AEHBB7JhiXY ZmNAXNYE6RtOv5GvxE2BMr6ndPHa/Ry9NHK1xPRcFWMP3w9C/t0UHUF5ml3m2G+BGeHT YO6Wpos2gtNTNAgeZCqBNicN2cMC39XEYXhuJU7tc/xrlU3c/EqW5zraflFcQhYRdrxk 4Ieccg8/U3WTdRQGUFs/plk72VWBqenvhGjbdJbvjPQ5M+VB302CeDGgg6Spfqtt+zwB JM0/o2Mu3db+15jouRfJ4PJu0easxc+D9enYIaRd95xTGWR2I7xju8UX8BrPxsHYaJxU P9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FhEc+YlMw+SDx6rzPsXWqcBAIYaqydANiL45K/IQxg0=; b=tQm3CGRND7K5LYKpIyad5kS38FIM8cZI6J0wv+zB20nprnZyaVoXqgxWq+CZaTe+Lw 7hYQAs5dFqXW2LES9zT0pZNBQVAUGcVzmQIFnL4oONSW2e3ha9GRQt0YAG/6hbSGS37Z EX2l0JUiQDlYmH4F2OVy9xHyRBuHLcvd61xkV3P5i+BiXGwcNkEW1cV8wbv9hxOUpWGQ uBBkhuIm6DVlzuXurDks17tTNyE1X6S4o+4zgvUNm5ccch8NoKUnTfVL37OzTEKaYaE+ 9cHJL7myvHFWOvCdKenrCLsL4tyI4X3wwOSCpsajbesgYNfXUK5Mhg5cSkWnvQGDyJJ7 InHw== X-Gm-Message-State: AOAM530X2kgTGwnNmMw08BrhvPBjH/StNbYlySUdl4HoONnfboSmOyNN 1tQBr145MemFDhT5odR6/2/xuLzRij5fEg== X-Google-Smtp-Source: ABdhPJwtnB+DQKqVl8Y+iJPRvHZFNWSUjHsKAsMldVrJMy4wi5ju1kK63mVYZl3rQe8r6DKQCOqygg== X-Received: by 2002:a1c:7c07:0:b0:37b:b973:bd3f with SMTP id x7-20020a1c7c07000000b0037bb973bd3fmr423517wmc.87.1644999253749; Wed, 16 Feb 2022 00:14:13 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b16sm26173443wrj.26.2022.02.16.00.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 00:14:12 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 1/5] cache.h: remove always unused show_date_human() declaration Date: Wed, 16 Feb 2022 09:14:01 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1028.g2d2d4be19de In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There has never been a show_date_human() function on the "master" branch in git.git. This declaration was added in b841d4ff438 (Add `human` format to test-tool, 2019-01-28). A look at the ML history reveals that it was leftover cruft from an earlier version of that commit[1]. 1. https://lore.kernel.org/git/20190118061805.19086-5-ischis2@cox.net/ Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/cache.h b/cache.h index 4148b6322d5..703a474e5a7 100644 --- a/cache.h +++ b/cache.h @@ -1588,8 +1588,6 @@ struct date_mode *date_mode_from_type(enum date_mode_type type); const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode); void show_date_relative(timestamp_t time, struct strbuf *timebuf); -void show_date_human(timestamp_t time, int tz, const struct timeval *now, - struct strbuf *timebuf); int parse_date(const char *date, struct strbuf *out); int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset); int parse_expiry_date(const char *date, timestamp_t *timestamp); From patchwork Wed Feb 16 08:14:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12748164 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 C8345C433EF for ; Wed, 16 Feb 2022 08:14:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231517AbiBPIOb (ORCPT ); Wed, 16 Feb 2022 03:14:31 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:49434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbiBPIO2 (ORCPT ); Wed, 16 Feb 2022 03:14:28 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A8F82503B3 for ; Wed, 16 Feb 2022 00:14:16 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id d14-20020a05600c34ce00b0037bf4d14dc7so971308wmq.3 for ; Wed, 16 Feb 2022 00:14:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0lmRz54IBwh6lqRlhHobkqzV8zdEE+2tPmrMXxJOjeE=; b=CvvyejT1+JJRAceoNRqzcLrcivaeIaPBXgrdXPrCueL2BS9NY2Wm/nH4okjIfWMlHx BBHaG+CHHugcfqj9vnuaMHa6mURUG4dwIt313oSbGAZ2FoiXYPygj51toCm02rqekdMx lVeT3SARJqrg75eLrUoMzsA6QZ4ihtQOx4vkx+gfDU74bqnpTFB5jB5tBeJbQtcr2wy6 HWYj1uDcfFZG5A9PJLMwISdBTcl+fZee85MjWEgI/TVzA2GrIJkoPl8246ri7MieMIBr lCYMkwdT7b7X6IMiKSwalk9nvCrX/wyYOGO4vscSbVvTtSotXF0ER+SdKsx4SZEYZ1ll qB7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0lmRz54IBwh6lqRlhHobkqzV8zdEE+2tPmrMXxJOjeE=; b=Y4jbN/pGUNQdpmSTYYjzXKEdbEQaVWEaNFVieiGRtm/gxe4EDqDrPXkiS7ljGpgpH4 teisYuyIqRFcPb8PclvWaCk6KFUfRZHKHwgvU0Sq9Xjno+MRzWhJP+Ie8KyJ76NDTlOO ELV65OfMQdZd+6gb2rut2DTIzJ01p6QsjlXg9edBbgggpfYm/Y502dIa3bPlmvSM83SC FszYU7uJf8N9awJ1HsZLay37cighuYqav04ZOUtLhqooRMbI7AmEskFKOPa67cMw5Ak/ vcbLHQh+YGWw+HbSK+8UcmV2lG+2may1Xik7Oi+1M5slRmrymCSyV53qWrEeM3dhlmzG USZw== X-Gm-Message-State: AOAM5301X349TxH3UwMwloSKuENl127OjxSfaUlU9uTmhmfS/z9RjZJ6 l4K6MEi3C+47Ctmfogl77RvfrEbJDWlaxQ== X-Google-Smtp-Source: ABdhPJwhixdULYUzu/ISQCv4CBL2DyB5sqbfunplTcYe2O7qUIdkpHLfXFJWwRFjKyGar3CNQXJgXQ== X-Received: by 2002:a7b:cb44:0:b0:37b:c569:5924 with SMTP id v4-20020a7bcb44000000b0037bc5695924mr418687wmj.83.1644999254778; Wed, 16 Feb 2022 00:14:14 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b16sm26173443wrj.26.2022.02.16.00.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 00:14:14 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 2/5] date API: create a date.h, split from cache.h Date: Wed, 16 Feb 2022 09:14:02 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1028.g2d2d4be19de In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the declaration of the date.c functions from cache.h, and adjust the relevant users to include the new date.h header. The show_ident_date() function belonged in pretty.h (it's defined in pretty.c), its two users outside of pretty.c didn't strictly need to include pretty.h, as they get it indirectly, but let's add it to them anyway. Similarly, the change to "builtin/{fast-import,show-branch,tag}.c" isn't needed as far as the compiler is concerned, but since they all use the "DATE_MODE()" macro we now define in date.h, let's have them include it. We could simply include this new header in "cache.h", but as this change shows these functions weren't common enough to warrant including in it in the first place. By moving them out of cache.h changes to this API will no longer cause a (mostly) full re-build of the project when "make" is run. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive-zip.c | 1 + builtin/am.c | 1 + builtin/commit.c | 1 + builtin/fast-import.c | 1 + builtin/show-branch.c | 1 + builtin/tag.c | 1 + cache.h | 48 ------------------------------------------- config.c | 1 + date.c | 1 + date.h | 43 ++++++++++++++++++++++++++++++++++++++ http-backend.c | 1 + ident.c | 1 + object-name.c | 1 + pretty.h | 10 +++++++++ reflog-walk.h | 1 + refs.c | 1 + strbuf.c | 1 + t/helper/test-date.c | 1 + 18 files changed, 68 insertions(+), 48 deletions(-) create mode 100644 date.h diff --git a/archive-zip.c b/archive-zip.c index 2961e01c754..8ea9d1a5dae 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -9,6 +9,7 @@ #include "object-store.h" #include "userdiff.h" #include "xdiff-interface.h" +#include "date.h" static int zip_date; static int zip_time; diff --git a/builtin/am.c b/builtin/am.c index 7de2c89ef22..eb24bc89bb5 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -34,6 +34,7 @@ #include "string-list.h" #include "packfile.h" #include "repository.h" +#include "pretty.h" /** * Returns the length of the first line of msg. diff --git a/builtin/commit.c b/builtin/commit.c index b9ed0374e30..6b99ac276d8 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -37,6 +37,7 @@ #include "help.h" #include "commit-reach.h" #include "commit-graph.h" +#include "pretty.h" static const char * const builtin_commit_usage[] = { N_("git commit [] [--] ..."), diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 2b2e28bad79..28f2b9cc91f 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -19,6 +19,7 @@ #include "mem-pool.h" #include "commit-reach.h" #include "khash.h" +#include "date.h" #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<] [-f] [-m | -F ]\n" diff --git a/cache.h b/cache.h index 703a474e5a7..48e77aa0697 100644 --- a/cache.h +++ b/cache.h @@ -1559,46 +1559,6 @@ struct object *repo_peel_to_type(struct repository *r, #define peel_to_type(name, namelen, obj, type) \ repo_peel_to_type(the_repository, name, namelen, obj, type) -enum date_mode_type { - DATE_NORMAL = 0, - DATE_HUMAN, - DATE_RELATIVE, - DATE_SHORT, - DATE_ISO8601, - DATE_ISO8601_STRICT, - DATE_RFC2822, - DATE_STRFTIME, - DATE_RAW, - DATE_UNIX -}; - -struct date_mode { - enum date_mode_type type; - const char *strftime_fmt; - int local; -}; - -/* - * Convenience helper for passing a constant type, like: - * - * show_date(t, tz, DATE_MODE(NORMAL)); - */ -#define DATE_MODE(t) date_mode_from_type(DATE_##t) -struct date_mode *date_mode_from_type(enum date_mode_type type); - -const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode); -void show_date_relative(timestamp_t time, struct strbuf *timebuf); -int parse_date(const char *date, struct strbuf *out); -int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset); -int parse_expiry_date(const char *date, timestamp_t *timestamp); -void datestamp(struct strbuf *out); -#define approxidate(s) approxidate_careful((s), NULL) -timestamp_t approxidate_careful(const char *, int *); -timestamp_t approxidate_relative(const char *date); -void parse_date_format(const char *format, struct date_mode *mode); -int date_overflows(timestamp_t date); -time_t tm_to_time_t(const struct tm *tm); - #define IDENT_STRICT 1 #define IDENT_NO_DATE 2 #define IDENT_NO_NAME 4 @@ -1644,14 +1604,6 @@ struct ident_split { */ int split_ident_line(struct ident_split *, const char *, int); -/* - * Like show_date, but pull the timestamp and tz parameters from - * the ident_split. It will also sanity-check the values and produce - * a well-known sentinel date if they appear bogus. - */ -const char *show_ident_date(const struct ident_split *id, - const struct date_mode *mode); - /* * Compare split idents for equality or strict ordering. Note that we * compare only the ident part of the line, ignoring any timestamp. diff --git a/config.c b/config.c index e0c03d154c9..430868f1ec0 100644 --- a/config.c +++ b/config.c @@ -6,6 +6,7 @@ * */ #include "cache.h" +#include "date.h" #include "branch.h" #include "config.h" #include "environment.h" diff --git a/date.c b/date.c index 84bb4451c1a..863b07e9e63 100644 --- a/date.c +++ b/date.c @@ -5,6 +5,7 @@ */ #include "cache.h" +#include "date.h" /* * This is like mktime, but without normalization of tm_wday and tm_yday. diff --git a/date.h b/date.h new file mode 100644 index 00000000000..5db9ec8dd29 --- /dev/null +++ b/date.h @@ -0,0 +1,43 @@ +#ifndef DATE_H +#define DATE_H + +enum date_mode_type { + DATE_NORMAL = 0, + DATE_HUMAN, + DATE_RELATIVE, + DATE_SHORT, + DATE_ISO8601, + DATE_ISO8601_STRICT, + DATE_RFC2822, + DATE_STRFTIME, + DATE_RAW, + DATE_UNIX +}; + +struct date_mode { + enum date_mode_type type; + const char *strftime_fmt; + int local; +}; + +/* + * Convenience helper for passing a constant type, like: + * + * show_date(t, tz, DATE_MODE(NORMAL)); + */ +#define DATE_MODE(t) date_mode_from_type(DATE_##t) +struct date_mode *date_mode_from_type(enum date_mode_type type); + +const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode); +void show_date_relative(timestamp_t time, struct strbuf *timebuf); +int parse_date(const char *date, struct strbuf *out); +int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset); +int parse_expiry_date(const char *date, timestamp_t *timestamp); +void datestamp(struct strbuf *out); +#define approxidate(s) approxidate_careful((s), NULL) +timestamp_t approxidate_careful(const char *, int *); +timestamp_t approxidate_relative(const char *date); +void parse_date_format(const char *format, struct date_mode *mode); +int date_overflows(timestamp_t date); +time_t tm_to_time_t(const struct tm *tm); +#endif diff --git a/http-backend.c b/http-backend.c index 807fb8839e7..81a7229ece0 100644 --- a/http-backend.c +++ b/http-backend.c @@ -13,6 +13,7 @@ #include "packfile.h" #include "object-store.h" #include "protocol.h" +#include "date.h" static const char content_type[] = "Content-Type"; static const char content_length[] = "Content-Length"; diff --git a/ident.c b/ident.c index 6aba4b5cb6f..89ca5b47008 100644 --- a/ident.c +++ b/ident.c @@ -7,6 +7,7 @@ */ #include "cache.h" #include "config.h" +#include "date.h" static struct strbuf git_default_name = STRBUF_INIT; static struct strbuf git_default_email = STRBUF_INIT; diff --git a/object-name.c b/object-name.c index 92862eeb1ac..060d892a97f 100644 --- a/object-name.c +++ b/object-name.c @@ -15,6 +15,7 @@ #include "submodule.h" #include "midx.h" #include "commit-reach.h" +#include "date.h" static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *); diff --git a/pretty.h b/pretty.h index 2f16acd213d..f34e24c53a4 100644 --- a/pretty.h +++ b/pretty.h @@ -2,6 +2,7 @@ #define PRETTY_H #include "cache.h" +#include "date.h" #include "string-list.h" struct commit; @@ -163,4 +164,13 @@ int format_set_trailers_options(struct process_trailer_options *opts, const char **arg, char **invalid_arg); +/* + * Like show_date, but pull the timestamp and tz parameters from + * the ident_split. It will also sanity-check the values and produce + * a well-known sentinel date if they appear bogus. + */ +const char *show_ident_date(const struct ident_split *id, + const struct date_mode *mode); + + #endif /* PRETTY_H */ diff --git a/reflog-walk.h b/reflog-walk.h index f26408f6cc1..e9e00ffd479 100644 --- a/reflog-walk.h +++ b/reflog-walk.h @@ -5,6 +5,7 @@ struct commit; struct reflog_walk_info; +struct date_mode; void init_reflog_walk(struct reflog_walk_info **info); int add_reflog_for_walk(struct reflog_walk_info *info, diff --git a/refs.c b/refs.c index 7017ae59804..b74f3815a52 100644 --- a/refs.c +++ b/refs.c @@ -19,6 +19,7 @@ #include "strvec.h" #include "repository.h" #include "sigchain.h" +#include "date.h" /* * List of all available backends diff --git a/strbuf.c b/strbuf.c index 613fee8c82e..00abeb55afd 100644 --- a/strbuf.c +++ b/strbuf.c @@ -2,6 +2,7 @@ #include "refs.h" #include "string-list.h" #include "utf8.h" +#include "date.h" int starts_with(const char *str, const char *prefix) { diff --git a/t/helper/test-date.c b/t/helper/test-date.c index 099eff4f0fc..ded3d059f56 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "date.h" static const char *usage_msg = "\n" " test-tool date relative [time_t]...\n" From patchwork Wed Feb 16 08:14:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12748165 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 7A650C433EF for ; Wed, 16 Feb 2022 08:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231526AbiBPIOg (ORCPT ); Wed, 16 Feb 2022 03:14:36 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:49904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231514AbiBPIOa (ORCPT ); Wed, 16 Feb 2022 03:14:30 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99AE324CDFC for ; Wed, 16 Feb 2022 00:14:17 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id u2so951001wrw.1 for ; Wed, 16 Feb 2022 00:14:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T4/ysCaEmPMDyG5UxSTyeW4/KIwH4WVlNh0PLg0FfK4=; b=on3aHySw+cadFR+5RgVHe/PgOdmzd7FkKx58yT7TpujXUo0e3Ny/sK2lp6mDVrncvn jL+4K9XFHLWRzF7dExyWw/ieqaPoSVKEAdz5t7BeeNJCSg7PwT8skZWrnoprDNP5ggoD u1z3F9Fg32Auu1xXtU3Uws5PFzPwuBQHKIbc4EAxuW1KFULUtHAFbqutNL4bM2mdYn6H DAnMiHeu6nD+R/uQlNtUp7QgqqxZZqXLFuC+jab4MU5CcosQWq2w+KEQNm4A/fzDkuH5 WBqbjZuBSl7hPDHEbgaDiUNkmKZEJrEKx2fqwLPUcHGtjrSdPafAkvT54Kf4QOLv9VlI WZvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T4/ysCaEmPMDyG5UxSTyeW4/KIwH4WVlNh0PLg0FfK4=; b=if8aGJzeWBCTDafEyrP4+yqaxOPW5FHCG9CpVEzTHpOgrVxn4er43oDyavuZoX6VGg wATLs6k2ghYdlVHTNlIww+5ivE7SYyPRBCqyDWfaUw/76ZLQYIZM1eAbmcfuQMbgzwr3 X1k2le9xrlLRWtP3nrck04xIrQLAVI011ZDnVkYTOh/PhWz0AY376wK/SfSGjiVOVB1W V5la7jCzCCHjLIrGYRwgsnUwd3O6Xil9iq7duNeL3loxUDzaovFOPZYI9dgtNf7E9Kx7 yhrVeoGl+HQCx04iHQJEgcRxqCi8Wj1/p6oOYto/MSpGLYcKKhbnZUx8CPf5Xs5ji0AP DOiw== X-Gm-Message-State: AOAM530HaIv5+P6jcpYNwDYr277p59K33yYslda3WJ8LTPX/rpoQ+fPo lL8FhAKimBb6yEJq3WtTq6ycNKREsKBgyA== X-Google-Smtp-Source: ABdhPJwzvmJ2kKmKKl6XfO+j21Q2Bz/dKRVHirtmvbj22UhvF65VINMRzl0i4z/xCPXj0MVBJkhm3Q== X-Received: by 2002:a5d:5701:0:b0:1e4:ab98:74c5 with SMTP id a1-20020a5d5701000000b001e4ab9874c5mr1301194wrv.704.1644999255939; Wed, 16 Feb 2022 00:14:15 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b16sm26173443wrj.26.2022.02.16.00.14.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 00:14:14 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 3/5] date API: provide and use a DATE_MODE_INIT Date: Wed, 16 Feb 2022 09:14:03 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1028.g2d2d4be19de In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Provide and use a DATE_MODE_INIT macro. Most of the users of struct date_mode" use it via pretty.h's "struct pretty_print_context" which doesn't have an initialization macro, so we're still bound to being initialized to "{ 0 }" by default. But we can change the couple of callers that directly declared a variable on the stack to instead use the initializer, and thus do away with the "mode.local = 0" added in add00ba2de9 (date: make "local" orthogonal to date format, 2015-09-03). Signed-off-by: Ævar Arnfjörð Bjarmason --- date.c | 3 +-- date.h | 4 ++++ ref-filter.c | 2 +- t/helper/test-date.c | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/date.c b/date.c index 863b07e9e63..54c709e4a08 100644 --- a/date.c +++ b/date.c @@ -206,11 +206,10 @@ void show_date_relative(timestamp_t time, struct strbuf *timebuf) struct date_mode *date_mode_from_type(enum date_mode_type type) { - static struct date_mode mode; + static struct date_mode mode = DATE_MODE_INIT; if (type == DATE_STRFTIME) BUG("cannot create anonymous strftime date_mode struct"); mode.type = type; - mode.local = 0; return &mode; } diff --git a/date.h b/date.h index 5db9ec8dd29..c3a00d08ed6 100644 --- a/date.h +++ b/date.h @@ -20,6 +20,10 @@ struct date_mode { int local; }; +#define DATE_MODE_INIT { \ + .type = DATE_NORMAL, \ +} + /* * Convenience helper for passing a constant type, like: * diff --git a/ref-filter.c b/ref-filter.c index f7a2f17bfd9..3399bde932f 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1251,7 +1251,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam char *zone; timestamp_t timestamp; long tz; - struct date_mode date_mode = { DATE_NORMAL }; + struct date_mode date_mode = DATE_MODE_INIT; const char *formatp; /* diff --git a/t/helper/test-date.c b/t/helper/test-date.c index ded3d059f56..111071e1dd1 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -35,7 +35,7 @@ static void show_human_dates(const char **argv) static void show_dates(const char **argv, const char *format) { - struct date_mode mode; + struct date_mode mode = DATE_MODE_INIT; parse_date_format(format, &mode); for (; *argv; argv++) { From patchwork Wed Feb 16 08:14:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12748166 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 9EADEC433EF for ; Wed, 16 Feb 2022 08:14:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231532AbiBPIOi (ORCPT ); Wed, 16 Feb 2022 03:14:38 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:50270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbiBPIOc (ORCPT ); Wed, 16 Feb 2022 03:14:32 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A40250393 for ; Wed, 16 Feb 2022 00:14:18 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id k3-20020a1ca103000000b0037bdea84f9cso986164wme.1 for ; Wed, 16 Feb 2022 00:14:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=awfNansQ+Tc/fElV0Ux9pm23dtDubw9vDfPAUdaRzgg=; b=Phh7wkMxvHelxkQZS0xF9PaL8E7Gr2iyf5Vf77TbJl9o4ktgfCorZ8ohTqc8lgKTbP m4AZnjYAcoNSxOtT/s4JSVAxWAD1ZqzCL6D6/q5mqhLgZWkqbJZcqoePTDsSVlVuxpyR am+5qGOuOWs+6dwRZEnf7WWlQpFtjgLtgjE1Jc4cAkh9DNZ6Mot9i7dfQx2gbOb7xR8Q Y4nZg4P+L0noNpwMN6PB115h+NO4wOBmer5k/FCu9nj7qcAoukGEUnOff0TN1z/dfcbH chCIpThQqSZgVlwAySIRuyIBZ7ONzo+DHt4E9LkwuoMuRE2r4sNoKvA5a/QoLK4iL1P2 BPjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=awfNansQ+Tc/fElV0Ux9pm23dtDubw9vDfPAUdaRzgg=; b=EXXMROp2Uhf+ODWQ7mUZMViBYD2v1dj8MIXSpYYCKdFZbSJY35iXPCMDkUov8nWuvh QVSkSNo0ttkQLLw+ykRY/uJztvbHuQusCCbnTSdyYvJpMcsX9foae6xqTh5uawQAWpC5 dTZWkQHDg7KyCu/gvixgBM2YYiACt5c9U9XDWrt2vrbZPwrfbNSslGsl04R57PcSgWIZ BF7h+H32f11JhLQOSZwsTldy5Cags4dPsfiiK7re44YX1swVa8Siaz7Kl0weiPubbNk6 WrFfHu5X9xbV5Ek8YwMOy19P4TRZTEOT283bB3yflTOHgiUDG8ffjzz/ILDM6U3uw6Mv SMjQ== X-Gm-Message-State: AOAM53163o87HU8NS9fyp6BMf5t7PmPLRGGw8QCtxHhJjzkTKoRdLP0o gNnT/dooVw6O/75vKgy0Q2rEahmBzPrQag== X-Google-Smtp-Source: ABdhPJybfLRXJrFqkFuzTYzFIcIYEiFxot/Eg0b90eCQ32rV1xwi3JLO/ktF7MlUzjutvchsaC+AvQ== X-Received: by 2002:a05:600c:3505:b0:37b:bf81:97d8 with SMTP id h5-20020a05600c350500b0037bbf8197d8mr456695wmq.30.1644999256983; Wed, 16 Feb 2022 00:14:16 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b16sm26173443wrj.26.2022.02.16.00.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 00:14:16 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 4/5] date API: add basic API docs Date: Wed, 16 Feb 2022 09:14:04 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1028.g2d2d4be19de In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add basic API doc comments to date.h, and while doing so move the the parse_date_format() function adjacent to show_date(). This way all the "struct date_mode" functions are grouped together. Documenting the rest is one of our #leftoverbits. Signed-off-by: Ævar Arnfjörð Bjarmason --- date.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/date.h b/date.h index c3a00d08ed6..bbd6a6477b5 100644 --- a/date.h +++ b/date.h @@ -1,6 +1,12 @@ #ifndef DATE_H #define DATE_H +/** + * The date mode type. This has DATE_NORMAL at an explicit "= 0" to + * accommodate a memset([...], 0, [...]) initialization when "struct + * date_mode" is used as an embedded struct member, as in the case of + * e.g. "struct pretty_print_context" and "struct rev_info". + */ enum date_mode_type { DATE_NORMAL = 0, DATE_HUMAN, @@ -24,7 +30,7 @@ struct date_mode { .type = DATE_NORMAL, \ } -/* +/** * Convenience helper for passing a constant type, like: * * show_date(t, tz, DATE_MODE(NORMAL)); @@ -32,7 +38,22 @@ struct date_mode { #define DATE_MODE(t) date_mode_from_type(DATE_##t) struct date_mode *date_mode_from_type(enum date_mode_type type); +/** + * Format <'time', 'timezone'> into static memory according to 'mode' + * and return it. The mode is an initialized "struct date_mode" + * (usually from the DATE_MODE() macro). + */ const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode); + +/** + * Parse a date format for later use with show_date(). + * + * When the "date_mode_type" is DATE_STRFTIME the "strftime_fmt" + * member of "struct date_mode" will be a malloc()'d format string to + * be used with strbuf_addftime(). + */ +void parse_date_format(const char *format, struct date_mode *mode); + void show_date_relative(timestamp_t time, struct strbuf *timebuf); int parse_date(const char *date, struct strbuf *out); int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset); @@ -41,7 +62,6 @@ void datestamp(struct strbuf *out); #define approxidate(s) approxidate_careful((s), NULL) timestamp_t approxidate_careful(const char *, int *); timestamp_t approxidate_relative(const char *date); -void parse_date_format(const char *format, struct date_mode *mode); int date_overflows(timestamp_t date); time_t tm_to_time_t(const struct tm *tm); #endif From patchwork Wed Feb 16 08:14:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12748167 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 BC401C433FE for ; Wed, 16 Feb 2022 08:14:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231539AbiBPIOj (ORCPT ); Wed, 16 Feb 2022 03:14:39 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:50848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231520AbiBPIOg (ORCPT ); Wed, 16 Feb 2022 03:14:36 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6E05254A7D for ; Wed, 16 Feb 2022 00:14:19 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id n8so701641wms.3 for ; Wed, 16 Feb 2022 00:14:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8urM7VG877IDaNA72S3sLKTXReyCiarLAOHtJwnfa5Y=; b=Vz868hi/4yuso8mmQ+Jr9uH+EFh+83zkb3402lrnneR0sSyJBqacHbpUFTrMJteU7w La6gN5O2VsK3Ai9yZ8dG65YyBIi+8ZrM4Y11/+p1EhCKmjK7Rz1I8mcrcBgQ+CinVq8I MgfUGtZs6iHzmhiufx1hRI+lUB8gMoim4HauzRS/HW2WGaFgDCeN7ksu4LrLdUOctCJ0 Azf59oG4j/eaDHGoJgdyNSBnmuE5TEltTXWuT0qJX1/4JJQGQbH0Q/s7d7JfOswmNO3T fpqsA+iKadd2Jv/5ECfbhGAdlFz5ib/PK9VbNqDa0wWH228aDm4ua5gtEgi8o/O3PzHc 4p4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8urM7VG877IDaNA72S3sLKTXReyCiarLAOHtJwnfa5Y=; b=i52bqb6y7ZXgXSeRet5U+J1iGOj+1b7CgdwxfkRVtC2Hrd3+XcTANzZuuSkClQBEl/ KcPr7VKW4yn3LD2le719jEo4URWjLrfNaI63MOpT8UYnI8tKtlYc4u3Zk/n8Axo1PR2/ djp5OsT6f6GYpO3HS3tvPiWK1Nw8is4y/OlsQpX9yZPmZUUWO+kx/YXNnLXHHjIk6m+N TdjjScnfXEYB3+vR8pV1aRTpWz2WdmySeVYyCH0/EBOsB3Uv0ZCLfadj9aM/4iRveo1G HKKBEl8ZTmNZpU0PC3fx49ryA3xb8wpuSUpdQinmzIfuafv5JI0BAEBqTJR9oTFQaUmw K8FQ== X-Gm-Message-State: AOAM530CIibsf069DI5uHsrGobkLUoiRCMtY0Q6kmjuFvk+ta+PKboJE HT/yYbthbfHysx2djd8q5Oq/YLoibgpSvw== X-Google-Smtp-Source: ABdhPJzij6eMizjEeDXmpbJ8pKGYid9zZKHWaEOf1sJ2Q0RbY6fp7yVT+YdiDemMl3DopAytBIUBpg== X-Received: by 2002:a1c:3b06:0:b0:37b:bb14:1f87 with SMTP id i6-20020a1c3b06000000b0037bbb141f87mr448462wma.0.1644999258041; Wed, 16 Feb 2022 00:14:18 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b16sm26173443wrj.26.2022.02.16.00.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 00:14:17 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 5/5] date API: add and use a date_mode_release() Date: Wed, 16 Feb 2022 09:14:05 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.1028.g2d2d4be19de In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in the parse_date_format() function by providing a new date_mode_release() companion function. By using this in "t/helper/test-date.c" we can mark the "t0006-date.sh" test as passing when git is compiled with SANITIZE=leak, and whitelist it to run under "GIT_TEST_PASSING_SANITIZE_LEAK=true" by adding "TEST_PASSES_SANITIZE_LEAK=true" to the test itself. The other tests that expose this memory leak (i.e. take the "mode->type == DATE_STRFTIME" branch in parse_date_format()) are "t6300-for-each-ref.sh" and "t7004-tag.sh". The former is due to an easily fixed leak in "ref-filter.c", and brings the failures in "t6300-for-each-ref.sh" down from 51 to 48. Fixing the remaining leaks will have to wait until there's a release_revisions() in "revision.c", as they have to do with leaks via "struct rev_info". There is also a leak in "builtin/blame.c" due to its call to parse_date_format() to parse the "blame.date" configuration. However as it declares a file-level "static struct date_mode blame_date_mode" to track the data, LSAN will not report it as a leak. It's possible to get valgrind(1) to complain about it with e.g.: valgrind --leak-check=full --show-leak-kinds=all ./git -P -c blame.date=format:%Y blame README.md But let's focus on things LSAN complains about, and are thus observable with "TEST_PASSES_SANITIZE_LEAK=true". We should get to fixing memory leaks in "builtin/blame.c", but as doing so would require some re-arrangement of cmd_blame() let's leave it for some other time. Signed-off-by: Ævar Arnfjörð Bjarmason --- date.c | 5 +++++ date.h | 9 ++++++++- ref-filter.c | 1 + t/helper/test-date.c | 2 ++ t/t0006-date.sh | 2 ++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/date.c b/date.c index 54c709e4a08..68a260c214d 100644 --- a/date.c +++ b/date.c @@ -993,6 +993,11 @@ void parse_date_format(const char *format, struct date_mode *mode) die("unknown date format %s", format); } +void date_mode_release(struct date_mode *mode) +{ + free((char *)mode->strftime_fmt); +} + void datestamp(struct strbuf *out) { time_t now; diff --git a/date.h b/date.h index bbd6a6477b5..5d4eaba0a90 100644 --- a/date.h +++ b/date.h @@ -50,10 +50,17 @@ const char *show_date(timestamp_t time, int timezone, const struct date_mode *mo * * When the "date_mode_type" is DATE_STRFTIME the "strftime_fmt" * member of "struct date_mode" will be a malloc()'d format string to - * be used with strbuf_addftime(). + * be used with strbuf_addftime(), in which case you'll need to call + * date_mode_release() later. */ void parse_date_format(const char *format, struct date_mode *mode); +/** + * Release a "struct date_mode", currently only required if + * parse_date_format() has parsed a "DATE_STRFTIME" format. + */ +void date_mode_release(struct date_mode *mode); + void show_date_relative(timestamp_t time, struct strbuf *timebuf); int parse_date(const char *date, struct strbuf *out); int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset); diff --git a/ref-filter.c b/ref-filter.c index 3399bde932f..7838bd22b8d 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1276,6 +1276,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam goto bad; v->s = xstrdup(show_date(timestamp, tz, &date_mode)); v->value = timestamp; + date_mode_release(&date_mode); return; bad: v->s = xstrdup(""); diff --git a/t/helper/test-date.c b/t/helper/test-date.c index 111071e1dd1..45951b1df87 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -54,6 +54,8 @@ static void show_dates(const char **argv, const char *format) printf("%s -> %s\n", *argv, show_date(t, tz, &mode)); } + + date_mode_release(&mode); } static void parse_dates(const char **argv) diff --git a/t/t0006-date.sh b/t/t0006-date.sh index 794186961ee..2490162071e 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test date parsing and printing' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # arbitrary reference time: 2009-08-30 19:20:00