From patchwork Fri Feb 4 23:53: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: 12735849 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 A186EC433EF for ; Fri, 4 Feb 2022 23:53:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378342AbiBDXxP (ORCPT ); Fri, 4 Feb 2022 18:53:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378292AbiBDXxM (ORCPT ); Fri, 4 Feb 2022 18:53:12 -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 CE5A7C103DFB for ; Fri, 4 Feb 2022 15:53:11 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id u15so14091148wrt.3 for ; Fri, 04 Feb 2022 15:53:11 -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=5iR5X2y5OvtUAZcKm2+js850VNVqvo8pdy2WJ7qA6Ew=; b=gKEw51/R/c9S/Ug+f04GClVD6LDy75Rk603U/oXgXgJDCBMPvheo2qwqQqbmO3rybo DnlirHBvVbexRES22uVWvsljBxU3bNJemtFusA+BxBtbqpIwAWvvLo/eLsHBipj+5WxH OW62a1Bulhdr4bmbSSO9pwbHHgDptBg/MFZS2/DkPhGfovXoY078K1pWzfGKDaDZClpK I0MgFdMXIOGAgFXsM9n74PyDQXehCLzQtvDa5NyPz5GLmF8QqYhhJsvd4WqRELASjb/+ kFmQpybGuNOiFSnBE1CJqM0ZVT9iQV+GvWNBXjYp+cZ5ZiFyDYPij1dMQ7XvrcMMrQru 1eLA== 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=5iR5X2y5OvtUAZcKm2+js850VNVqvo8pdy2WJ7qA6Ew=; b=Bs/66WfgeJIh2/Ybd6dFF2dWtgM+3av9cBrkhL6SXE1xWUECitYlEHErc3ZfnKSDnG KvKh6j3zJMiNre0GAUf7OUVjxhp8VPTj9UvXyE+omOAgrIY6RDf1mYExMJK1tFbz/slT E2wFJmS+qrfGMfc3eOMyUdaLVUjqDYxyUzrv/Tmy4b4FkikS/09Fws/uB0M9ufJVT775 CF5Apo67RAear1UN5eW7rPau/YCrBIm6hIwZT1Acb/29z14houVG8D9El4LuqQR++u+j g/KyOLyFyt6G5cQ6O+x9eIy24LPwyz8rVA5vZktlW8l2xN+eZdw5Fj6TUaBWN655iMNJ nVIg== X-Gm-Message-State: AOAM533kc79r7FZSIYHZRl96C0lsx2lzIxle608U/p0EznC81NrdZOIb YMNUay2hV7/CH0EfvwJXpZOnAah2+A6ZYA== X-Google-Smtp-Source: ABdhPJziFCuYUEHcJzqrEJqvQBn3f2c0fW6t8CSkeOotopkDuLilTrnmeqqYYiQGPvF5V2I4wmxoAA== X-Received: by 2002:a5d:64c2:: with SMTP id f2mr961352wri.429.1644018790149; Fri, 04 Feb 2022 15:53:10 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a18sm3304507wrw.5.2022.02.04.15.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 15:53:09 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 1/5] cache.h: remove always unused show_date_human() declaration Date: Sat, 5 Feb 2022 00:53:02 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.940.ge7a5b4b05f2 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 281f00ab1b1..49b46244c74 100644 --- a/cache.h +++ b/cache.h @@ -1586,8 +1586,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 Fri Feb 4 23:53: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: 12735850 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 ED4E0C433FE for ; Fri, 4 Feb 2022 23:53:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378360AbiBDXxR (ORCPT ); Fri, 4 Feb 2022 18:53:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378323AbiBDXxO (ORCPT ); Fri, 4 Feb 2022 18:53:14 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCBC1C103DF8 for ; Fri, 4 Feb 2022 15:53:12 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id k6-20020a05600c1c8600b003524656034cso4671862wms.2 for ; Fri, 04 Feb 2022 15:53:12 -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=vro00B6htmvV+lakAiFYWTaNVvZs6eIw92Nzwk0s7rQ=; b=jtGCcoYqR3UQpH/7l3HcwligeNkd+n4ar+Y5nwtXh3o6JUrzvJCyzFyXI8IQ+33iQe Y5j4/pBB35fouTfwrU56M/wgZyU2egTtezjL1gTEzY/fURu27JtWc1oAsCYpWTcEAkHU ul0LQPwwzDxGyAoaXiwhIAnWdK9Q1dNl7aeSHKa0WeNNzV5I+KpW4X/HG+9tvxiqsDh2 TXlj2G0vUttFEEI/andRCownHhwkqTGmDEcb1D12GRck0D18expV7Gid8+0Vb9xBlgng 1Z2Dcr16Ge6abGowQTuFXUNM0Q7OtjS3mem/gUlzHMBniOq+wF0EKHiOjc52PY9RK+df c/OA== 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=vro00B6htmvV+lakAiFYWTaNVvZs6eIw92Nzwk0s7rQ=; b=eEMQO7A8iStxCnaeGYw1UQZehiIN6W7U/CIGnmdhgAihOrkz77E1kWIt5sk8mA1LWV c7PFnjlXtgsN14HHO5QT92IqYgoOF8uaaWPxrTd5RJkJQfv8omyc0bj8CaZwdC/vvfnr N46weiYYDprT/LfntGCnR3fGtnFLI++ybgrAgZPVJZHypRtbUkxFV76YzRE7yE6HSlIW pXRmYkMGufCWtuz/40Gjeoc6bBi9FYxKfShvHvhj4hVLBfoA1npptelUaCo0fEz1FmP6 aqibnWZTNFdYKr4efpjCqLhiOJWUpeoRbqKOxDHNbqCDaJpGncvzRpDrIlFle9JViVLW g37Q== X-Gm-Message-State: AOAM5305dXBegiUgaOUuWGcIZuvVf7AeZWNMHLteBXB8xb8YlpdgzFZc 5Gb8ZVVHca8QUkEiIwf+qSPu/sKZiUKBbw== X-Google-Smtp-Source: ABdhPJx1ZqB+bK5JWcrJ0ip4hGWz6qfk7YmQe1xJBYCxrlRrNNO77Txr9Ui6xRiEZHKeBrohKIxquQ== X-Received: by 2002:a05:600c:2b89:: with SMTP id j9mr877804wmc.190.1644018791023; Fri, 04 Feb 2022 15:53:11 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a18sm3304507wrw.5.2022.02.04.15.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 15:53:10 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 2/5] date API: create a date.h, split from cache.h Date: Sat, 5 Feb 2022 00:53:03 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.940.ge7a5b4b05f2 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. 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 b6be1f1cb11..cc8cd6d6e4b 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 49b46244c74..6add78fd701 100644 --- a/cache.h +++ b/cache.h @@ -1557,46 +1557,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 @@ -1642,14 +1602,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 2bffa8d4a01..9c9dc8a6f62 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 fdff4601b2c..f9527817b64 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 addb26293b4..33ed3732d1b 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 Fri Feb 4 23:53: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: 12735851 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 2D05FC433EF for ; Fri, 4 Feb 2022 23:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378367AbiBDXxS (ORCPT ); Fri, 4 Feb 2022 18:53:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378336AbiBDXxO (ORCPT ); Fri, 4 Feb 2022 18:53:14 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 995C8C103DFB for ; Fri, 4 Feb 2022 15:53:13 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id j16so13986965wrd.8 for ; Fri, 04 Feb 2022 15:53:13 -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=YJmrKbf5WfVLWO420q6rwPxscLSQ0M9xIx8W2MU2E3o=; b=aIqiNn8n/ubUNods4rf3ooqst+IgvN5DoIvZg+W5CRe1BHx3i1LBZrlsIWS4Qx9G/R O+vPelbNJkynoDHUEZ7Pdkr/EigUnAfUZAeuH7k4vfek6obihO0neW9uxo1PNO5zZ4Lf QOyxhIBnyQfVjBE0EFgDNYiZShzYETvTRAxGBBhqgHXyJsFqTABLgRic1ZpQXfIksFLL rllG6vmijZzfAMW5W30vJJc/H0vPI7duAgYIpx8nKcXptTmHt498rrXDHicyGqTZkNjG 8mdZrVISgLeeTZ0sRRVFPU0UWNeA/Y47NnFiOsPdWCwz4pdUbiwrADOwWGY+6XE0ELkJ 0o4g== 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=YJmrKbf5WfVLWO420q6rwPxscLSQ0M9xIx8W2MU2E3o=; b=uagGJo4kkf3PCyRLELnjZ0eGp+azn0WDn4ad8UWwXm4bPls9lYVOjiqLM6Ji02zml/ CR6G/aE0H+PiaHgqlg26iBTj9+7gqDYbDY4dr5z1sznO2Z59W5uV1Wlq+03XY91OvcKS 6/NTdjTMao1YlBgc/3a5cxwLgLz/4Y7N5PRU/1mppwsKYW+II6rMnAKjVnG7CVM5bhBi 3KxyibsrgOdtajjJ5YFuNsAPYPllslhphuVJtjWWbMOTa4L8pOlLy8YHsZhH8uomhvDT 8hTcY/65zQI6E18LOQzoRGBJAf2tFoLGkx9q/G/pR29HYxN/MzmrkivUnQo7LNzn5oHp jDRw== X-Gm-Message-State: AOAM531RR2F/uxBcUUzH3y9B2AfOVfqN4zP5ppukSBqg62d7jX+uRJFD FHpgynjpUngiw40USxY/CUuMp9SBeyiufQ== X-Google-Smtp-Source: ABdhPJyL4Nm28/JuHv8OBpu45tNRtwGSlvNEwtBarEYU2Hbt/QmRilwwrhgp+FGsI/lx0sfPBEtViA== X-Received: by 2002:a05:6000:1d88:: with SMTP id bk8mr993491wrb.508.1644018791966; Fri, 04 Feb 2022 15:53:11 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a18sm3304507wrw.5.2022.02.04.15.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 15:53:11 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 3/5] date API: provide and use a DATE_MODE_INIT Date: Sat, 5 Feb 2022 00:53:04 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.940.ge7a5b4b05f2 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 Fri Feb 4 23:53: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: 12735852 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 0A456C433EF for ; Fri, 4 Feb 2022 23:53:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378384AbiBDXxT (ORCPT ); Fri, 4 Feb 2022 18:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378268AbiBDXxP (ORCPT ); Fri, 4 Feb 2022 18:53:15 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61FE3C104372 for ; Fri, 4 Feb 2022 15:53:14 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id m14so13987805wrg.12 for ; Fri, 04 Feb 2022 15:53:14 -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=CxIExHfpQA96SI5C5xne6UDjJJzbSBpJheF8LtY9FDs=; b=GjKx4nLSVOctG6ugczEMvwoHf8cTlNNxIXc3p6Lavfv6mNehrxyEM00mBoDNeHoAGK IaBQC3Rh+Rz9UXj2fKSoReMoPKZZu2CtoQxq9+jIEAH/KP7qdQgkTiOGhP64mziwwY6p HfMLySIrdbI5jpaQ+aTM86wt3/BrHVuvcWpKXi4g6dSD/Kd8ZpuXwZcIcGgxMTzvku3H Ybrg8BFZ0Z19Syc51zs9lMbyQgrDnOxFFOeJUEcVcuv7FPiuZrUoGnTBGbtNnuerWHxe 2FYW7cOefPJfX7Y3zi4Cm3bFGZocd2G+RrMgNN1gXE61huIlMuGOMgrHu1GAp0QWyGk8 5wXQ== 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=CxIExHfpQA96SI5C5xne6UDjJJzbSBpJheF8LtY9FDs=; b=sRLktTcfYCL3nyVm9Jwyh9WtgvM5tSiNCK0U+Z8jRXVIKVHhnT78lBuvSkgglxqNwV 7n5kJiVO7OP8cN/zEJtOsd2X5+SIpgntx9R85dtHLP/fdQs8wrUxjaJEeRlChgy/tyb9 SMiwBwgrBZcyC93XDZnRBDg4qhHiNR5VP5UavrWmHm/SF2TAHotshQ+SuJEqHEx/XcY6 9oeqy475CZlACgnxkElTxHRGOqspJGn2Nsxg0oKa6mI988FAlKNSMkAFli8EELGTm57x P3mjWJAeKZTh9zegcNcTux8EL2piFbhbcFX8aCZvlXxPcDHnZ37LeY2I2RASdq4YIe9f cuzg== X-Gm-Message-State: AOAM531TUYS5/mcmwWh4KG4/h82XyWJ3T/HJkVWh/bUgDvu964D7bLAd giaEpl+/mblyEbuWaDuUMnPGCKvZZxBIdw== X-Google-Smtp-Source: ABdhPJxteiC39g2vv1FxezgjoCO3x4+iEKe0jcT1W1z6WJzZFc7sUHpr38rQEpvg7Kf5I9lpkTvooA== X-Received: by 2002:a5d:6686:: with SMTP id l6mr994024wru.314.1644018792733; Fri, 04 Feb 2022 15:53:12 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a18sm3304507wrw.5.2022.02.04.15.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 15:53: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 v2 4/5] date API: add basic API docs Date: Sat, 5 Feb 2022 00:53:05 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.940.ge7a5b4b05f2 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 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/date.h b/date.h index c3a00d08ed6..4ed83506de9 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,21 @@ 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); +/** + * Show the date given 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 +61,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 Fri Feb 4 23:53:06 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: 12735853 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 24E94C433F5 for ; Fri, 4 Feb 2022 23:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378428AbiBDXx2 (ORCPT ); Fri, 4 Feb 2022 18:53:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378340AbiBDXxQ (ORCPT ); Fri, 4 Feb 2022 18:53:16 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DBCCC103DF8 for ; Fri, 4 Feb 2022 15:53:15 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id r17so4990180wrr.6 for ; Fri, 04 Feb 2022 15:53: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=cka9gv2FJRo33/y5IIOgigdh/JUPtSbkAPp0ahuz2e8=; b=gbHUgM033GeS/89/rdxRch38J6V2dI6B1UJOsBJ1oFKVFsOw/Lcwd8TfvsZ22vnhhN W+HBRZLDv9KW2BNbm2uHkQpLkfPQvvp+5PzPZBxKXoKZ6Z46SQihFdzxvzmlbCXaxxH+ CPA+E2cT76lwSnocaNKcVf9osWmK8b+f7oZzeZ5rfwsFygh7g5zLiYCeX9qxr7EoYrXC iEmcN6Y0PMMq8KPADS5YzCmMeqE+kym653dRtIMwjryqZAl62Wa1yFwjY0pvIsGgMWeo AXKqLbokOUMhhgmWwgIR9e32WL2hozF6x+eqDnET5ygmhc804McKZm7u5BdV7Xkf+bVj 5xFQ== 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=cka9gv2FJRo33/y5IIOgigdh/JUPtSbkAPp0ahuz2e8=; b=gy1wiAtchuFmtPfCiF9ILdZIVitcGzyYxvu/OXh+iud3n+QUfJx8OYNk/9/XaO8N7x d82o6TC3owkUn/QvJ8tBfFgeTPqhwoFTYTO5aH7GvpCHcphGctbI3TP9+uQjtdEtbhW8 ZaSpEhWYvvT+uy5gfHtH5VFOhMzVWbaZ4Ix94Uc7uR6TFmYWsCM/H15uUd89gH5Y67zP f45NU1WWyC4FD8Qnm8hbyqceF+aeHbwi1CZ9cChV8wPi1f/a27VprxV/NKSa/yq3/zsJ Rdh606ws9pQebm+rsi9s6Biy6Bfo4pXoy86I/h1O1q1JaQhT9/CESHwsPwBQHEaoU3uh Wcjw== X-Gm-Message-State: AOAM532kIsHC/HtpSS7gyze5xRinsOUBBx7Z36tDv6/yyp+AgRALVvgw XhED1UqBk59DnxEEDVADCFoRe4DWXk+9sQ== X-Google-Smtp-Source: ABdhPJz6MpHCP/G/aBiwBAfzINgAnzcNWNdVqSfOlyEnNZm37jpBb3L1QK1EJIcmllgPRfNIXiK0qg== X-Received: by 2002:a05:6000:1b88:: with SMTP id r8mr1004856wru.447.1644018793509; Fri, 04 Feb 2022 15:53:13 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a18sm3304507wrw.5.2022.02.04.15.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 15:53: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 v2 5/5] date API: add and use a date_mode_release() Date: Sat, 5 Feb 2022 00:53:06 +0100 Message-Id: X-Mailer: git-send-email 2.35.1.940.ge7a5b4b05f2 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". 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 4ed83506de9..bfcd4eb458c 100644 --- a/date.h +++ b/date.h @@ -49,10 +49,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