git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Shengfa Lin <shengfa@google.com>
Cc: git@vger.kernel.org, nathaniel@google.com,
	rsbecker@nexbridge.com, santiago@nyu.edu
Subject: Re: [RFC PATCH 1/1] hideTimezone: add a user.hideTimezone config
Date: Wed, 30 Sep 2020 16:55:02 -0700	[thread overview]
Message-ID: <xmqqh7rees6h.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20200930232138.3656304-2-shengfa@google.com> (Shengfa Lin's message of "Wed, 30 Sep 2020 23:21:38 +0000")

Shengfa Lin <shengfa@google.com> writes:

> Users requested hiding location in the world from source control
> trail. This is an implementation to read user.hideTimezone in
> cmd_commit and set timezone to UTC if it's true.

Not a very good proposed log message, that sounds as if "it is
what 'Users' requested, so it must be a worthwhile thing to do",
which is not the line of thinking to go by.




>
> Added a brief explanation of the new field in Documentation
> and added tests for true/false and reset-author
>
> Signed-off-by: Shengfa Lin <shengfa@google.com>
> ---
>  Documentation/config/user.txt   |  4 ++++
>  builtin/commit.c                |  5 +++++
>  t/t7527-commit-hide-timezone.sh | 37 +++++++++++++++++++++++++++++++++
>  3 files changed, 46 insertions(+)
>  create mode 100755 t/t7527-commit-hide-timezone.sh
>
> diff --git a/Documentation/config/user.txt b/Documentation/config/user.txt
> index 59aec7c3ae..bd6813f527 100644
> --- a/Documentation/config/user.txt
> +++ b/Documentation/config/user.txt
> @@ -36,3 +36,7 @@ user.signingKey::
>  	commit, you can override the default selection with this variable.
>  	This option is passed unchanged to gpg's --local-user parameter,
>  	so you may specify a key using any method that gpg supports.
> +
> +user.hideTimezone::
> +  Override TZ to UTC for Git commits to hide user's timezone in commit
> +  date
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 42b964e0ca..fb1cbb8a39 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1569,6 +1569,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>  	status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
>  	s.colopts = 0;
>  
> +  git_config(git_default_config, NULL);
> +  int hide_timezone = 0;
> +  if (!git_config_get_bool("user.hideTimezone", &hide_timezone)  && hide_timezone)
> +    setenv("TZ", "UTC", 1);
> +
>  	if (get_oid("HEAD", &oid))
>  		current_head = NULL;
>  	else {
> diff --git a/t/t7527-commit-hide-timezone.sh b/t/t7527-commit-hide-timezone.sh
> new file mode 100755
> index 0000000000..41ed9c27da
> --- /dev/null
> +++ b/t/t7527-commit-hide-timezone.sh
> @@ -0,0 +1,37 @@
> +#!/bin/sh
> +
> +test_description='git-commit can override local timezone setting by reading user.hideTimezone from config'
> +
> +. ./test-lib.sh
> +
> +test_expect_success 'commit date shows timezone offset +0300 when user.hideTimezone is false' '
> +        git config user.hideTimezone false &&
> +        echo test1 >> file &&
> +        git add file &&
> +        # unset GIT_AUTHOR_DATE from test_tick
> +        unset GIT_AUTHOR_DATE &&
> +        TZ=Europe/Istanbul git commit -m initial &&
> +        git log -1 > output &&
> +        grep "Date: .* +0300" output
> +'
> +
> +test_expect_success 'commit date shows timezone offset +0000 when user.hideTimezone is true and reset' '
> +        git config user.hideTimezone true &&
> +        git commit --amend --reset-author &&
> +        git log -1 > output &&
> +        grep "Date: .* +0000" output
> +'
> +
> +test_expect_success 'commit date shows timezone offset +0000 even TZ setting says otherwise' '
> +        git config user.hideTimezone true &&
> +        echo test2 >> file &&
> +        git add file &&
> +        # TZ setting corresponding to -0600 or -0500 depending on DST
> +        # unset GIT_AUTHOR_DATE from test_tick
> +        unset GIT_AUTHOR_DATE &&
> +        TZ=America/Chicago git commit -m test2 &&
> +        git log -1 > output &&
> +        grep "Date: .* +0000" output
> +'
> +
> +test_done

  parent reply	other threads:[~2020-09-30 23:55 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05 17:14 [ISSUE] Stop accessing, storing, and sharing the user's time zone Nathaniel Manista
2019-12-05 17:31 ` Junio C Hamano
2019-12-05 17:33 ` Randall S. Becker
2019-12-05 17:43   ` Junio C Hamano
2019-12-05 17:53     ` Santiago Torres Arias
2019-12-05 18:00     ` Randall S. Becker
2020-09-30 23:21 ` [RFC PATCH 0/1] adding user.hideTimezone for setting UTC timezone Shengfa Lin
2020-09-30 23:21   ` [RFC PATCH 1/1] hideTimezone: add a user.hideTimezone config Shengfa Lin
2020-09-30 23:41     ` Junio C Hamano
2020-10-01  0:17       ` Junio C Hamano
2020-10-02  6:07         ` Shengfa Lin
2020-10-01  0:31       ` Junio C Hamano
2020-10-01  0:35         ` Junio C Hamano
2020-10-02  6:41           ` Shengfa Lin
2020-10-02  6:46             ` Shengfa Lin
2020-10-02  6:37         ` Shengfa Lin
2020-10-02  6:02       ` Shengfa Lin
2020-10-02  6:15         ` Jonathan Nieder
2020-10-02 22:32           ` Shengfa Lin
2020-10-03  4:57             ` Junio C Hamano
2020-09-30 23:55     ` Junio C Hamano [this message]
2020-10-02  6:51       ` Shengfa Lin
2020-10-01  0:05     ` Junio C Hamano
2020-10-01  2:44     ` Jonathan Nieder
2020-10-02 21:17       ` Shengfa Lin
2020-09-30 23:53   ` [RFC PATCH 0/1] adding user.hideTimezone for setting UTC timezone Junio C Hamano
2020-10-01  2:17     ` Junio C Hamano
2020-10-01  3:43       ` Jonathan Nieder
2020-10-01 15:48         ` Junio C Hamano
2020-10-08 19:49           ` Junio C Hamano
     [not found]             ` <CAEOYnASgxCE5NjhoSgDwyQyAmdLhw5UyFq_Fu==8q7y6uXGz6w@mail.gmail.com>
2020-10-09 16:48               ` Junio C Hamano
2020-10-02 21:56         ` Shengfa Lin
2020-10-02 22:06           ` Junio C Hamano
2020-10-03  3:50             ` Shengfa Lin
2020-10-03  4:42               ` Junio C Hamano
2020-10-03 19:53         ` brian m. carlson
2020-10-03 22:14           ` Junio C Hamano
2020-10-02 21:42       ` Shengfa Lin
2020-10-02 21:23     ` Shengfa Lin
2020-10-13  5:28 ` [WIP v2 0/2] experiment with commit option record-time-zone Shengfa Lin
2020-10-13  5:28   ` [WIP v2 1/2] Adding a record-time-zone command option for commit Shengfa Lin
2020-10-13 20:03     ` Junio C Hamano
2020-10-21  5:01       ` Shengfa Lin
2020-10-21 18:55         ` Junio C Hamano
2020-10-22 16:27           ` Junio C Hamano
2020-10-26  4:14             ` Shengfa Lin
2020-10-13  5:28   ` [WIP v2 2/2] Demonstrate failing and passing tests Shengfa Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqh7rees6h.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=nathaniel@google.com \
    --cc=rsbecker@nexbridge.com \
    --cc=santiago@nyu.edu \
    --cc=shengfa@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).