# [PATCH] [Outreachy] patch-ids: fix NEEDSWORK timezone parsing in fast-import.c

5 messages from 2025-10-09 to 2025-10-10. Participants: Okhuomon Ajayi, Kristoffer Haugsbakk, Patrick Steinhardt, Junio C Hamano.
Thread: https://gitlist.dev/t/64289

## Okhuomon Ajayi, 2025-10-09 23:49

Subject: [PATCH] [Outreachy] patch-ids: fix NEEDSWORK timezone parsing in fast-import.c
Message-ID: <20251009234957.1789543-1-okhuomonajayi54@gmail.com>
URL: https://gitlist.dev/e/20251009234957.1789543-1-okhuomonajayi54%40gmail.com

```
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 builtin/fast-import.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 606c6aea82..695e1a0ae1 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -1959,14 +1959,15 @@ static int validate_raw_date(const char *src, struct strbuf *result, int strict)
 		return -1;
 
 	num = strtoul(src + 1, &endp, 10);
-	/*
-	 * NEEDSWORK: check for brokenness other than num > 1400, such as
-	 *            (num % 100) >= 60, or ((num % 100) % 15) != 0 ?
-	 */
-	if (errno || endp == src + 1 || *endp || /* did not parse */
-	    (strict && (1400 < num))             /* parsed a broken timezone */
-	   )
+	
+
+        unsigned int hours = num / 100;
+        unsigned int minutes = num % 100;
+
+	if (errno || endp == src + 1 || *endp || 
+	    (strict && (num > 1400 || minutes >=60 || minutes % 15 != 0))){
 		return -1;
+	}
 
 	strbuf_addstr(result, orig_src);
 	return 0;
-- 
2.43.0


```

## Kristoffer Haugsbakk, 2025-10-09 23:57

Subject: Re: [PATCH] [Outreachy] patch-ids: fix NEEDSWORK timezone parsing in fast-import.c
Message-ID: <3fa266f2-2376-4497-9d36-966fbdb4ca0e@app.fastmail.com>
URL: https://gitlist.dev/e/3fa266f2-2376-4497-9d36-966fbdb4ca0e%40app.fastmail.com
In-Reply-To: <20251009234957.1789543-1-okhuomonajayi54@gmail.com>

```
On Fri, Oct 10, 2025, at 01:49, Okhuomon Ajayi wrote:
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> ---
>  builtin/fast-import.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> index 606c6aea82..695e1a0ae1 100644
> --- a/builtin/fast-import.c
> +++ b/builtin/fast-import.c
> @@ -1959,14 +1959,15 @@ static int validate_raw_date(const char *src,
> struct strbuf *result, int strict)
>  		return -1;
>
>  	num = strtoul(src + 1, &endp, 10);
> -	/*
> -	 * NEEDSWORK: check for brokenness other than num > 1400, such as
> -	 *            (num % 100) >= 60, or ((num % 100) % 15) != 0 ?
> -	 */
> -	if (errno || endp == src + 1 || *endp || /* did not parse */
> -	    (strict && (1400 < num))             /* parsed a broken timezone */
> -	   )
> +
> +

These two new blank lines should probably not be here.

> +        unsigned int hours = num / 100;
> +        unsigned int minutes = num % 100;
> +

You’re mixing spaces-for-indentation right here with tabs (next).  The
project uses tabs for indentation.

Try to run `./ci/check-whitespace.sh @^`

> +	if (errno || endp == src + 1 || *endp ||
> +	    (strict && (num > 1400 || minutes >=60 || minutes % 15 != 0))){
>  		return -1;
> +	}
>
>  	strbuf_addstr(result, orig_src);
>  	return 0;
> --
> 2.43.0

```

## Patrick Steinhardt, 2025-10-10 05:30

Subject: Re: [PATCH] [Outreachy] patch-ids: fix NEEDSWORK timezone parsing in fast-import.c
Message-ID: <aOiZ_v3bO35oVWf-@pks.im>
URL: https://gitlist.dev/e/aOiZ_v3bO35oVWf-%40pks.im
In-Reply-To: <20251009234957.1789543-1-okhuomonajayi54@gmail.com>

```
On Fri, Oct 10, 2025 at 12:49:57AM +0100, Okhuomon Ajayi wrote:
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> ---

For a change like this it is important to explain what the problem is,
why it is a problem and how your change improves the code for the
better. All of this needs to be patr of the commit message so that the
reader can understand what you're actually doing.

Also, if this fixes a real issue, is it possible to demonstrate the
issue and the fix with a test?

> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> index 606c6aea82..695e1a0ae1 100644
> --- a/builtin/fast-import.c
> +++ b/builtin/fast-import.c
> @@ -1959,14 +1959,15 @@ static int validate_raw_date(const char *src, struct strbuf *result, int strict)
>  		return -1;
>  
>  	num = strtoul(src + 1, &endp, 10);
> -	/*
> -	 * NEEDSWORK: check for brokenness other than num > 1400, such as
> -	 *            (num % 100) >= 60, or ((num % 100) % 15) != 0 ?
> -	 */
> -	if (errno || endp == src + 1 || *endp || /* did not parse */
> -	    (strict && (1400 < num))             /* parsed a broken timezone */
> -	   )
> +	
> +
> +        unsigned int hours = num / 100;
> +        unsigned int minutes = num % 100;
> +
> +	if (errno || endp == src + 1 || *endp || 
> +	    (strict && (num > 1400 || minutes >=60 || minutes % 15 != 0))){
>  		return -1;
> +	}

Despite the formatting issues I also think that this here is becoming
hard to read. It may make sense to split this up into multiple
conditions.

Thanks!

Patrick

```

## Junio C Hamano, 2025-10-10 15:45

Subject: Re: [PATCH] [Outreachy] patch-ids: fix NEEDSWORK timezone parsing in fast-import.c
Message-ID: <xmqq1pnabw1p.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq1pnabw1p.fsf%40gitster.g
In-Reply-To: <aOiZ_v3bO35oVWf-@pks.im>

```
Patrick Steinhardt <ps@pks.im> writes:

> On Fri, Oct 10, 2025 at 12:49:57AM +0100, Okhuomon Ajayi wrote:
>> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
>> ---
>
> For a change like this it is important to explain what the problem is,
> why it is a problem and how your change improves the code for the
> better. All of this needs to be patr of the commit message so that the
> reader can understand what you're actually doing.
>
> Also, if this fixes a real issue, is it possible to demonstrate the
> issue and the fix with a test?
>
>> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
>> index 606c6aea82..695e1a0ae1 100644
>> --- a/builtin/fast-import.c
>> +++ b/builtin/fast-import.c
>> @@ -1959,14 +1959,15 @@ static int validate_raw_date(const char *src, struct strbuf *result, int strict)
>>  		return -1;
>>  
>>  	num = strtoul(src + 1, &endp, 10);
>> -	/*
>> -	 * NEEDSWORK: check for brokenness other than num > 1400, such as
>> -	 *            (num % 100) >= 60, or ((num % 100) % 15) != 0 ?
>> -	 */
>> -	if (errno || endp == src + 1 || *endp || /* did not parse */
>> -	    (strict && (1400 < num))             /* parsed a broken timezone */
>> -	   )
>> +	
>> +
>> +        unsigned int hours = num / 100;
>> +        unsigned int minutes = num % 100;
>> +
>> +	if (errno || endp == src + 1 || *endp || 
>> +	    (strict && (num > 1400 || minutes >=60 || minutes % 15 != 0))){
>>  		return -1;
>> +	}
>
> Despite the formatting issues I also think that this here is becoming
> hard to read. It may make sense to split this up into multiple
> conditions.
>
> Thanks!
>
> Patrick

Thanks for a good suggestion.

There is another thing we should be aware of about these NEEDSWORK
comments.  Often, the task a NEEDSWORK comment suggests includes and
starts from assessing if the task indeed is worth doing.  We should
read a NEEDSWORK comment like above one as its author mumbling to
themselves: this feels lacking, and we may want to do more here,
like X and Y and Z.  Maybe not.

Do we need to check even more precisely here?  What's the point of
doing so, and doing so here at this point in the control flow?  Are
there better approaches than incrementally adding more of similar
kinds of checks?

Without being able to answer these questions oneself, one shouldn't
be blindly following what a NEEDSWORK comment like this floats as
"ideas to do more".

The current code may turn out to be good enough.  Removing the
NEEDSWORK comment with a solid answer to the question it poses in
the proposed log message would be a commit worth making in such a
case.

Thanks.

```

## Okhuomon Ajayi, 2025-10-10 17:16

Subject: Re: [PATCH] [Outreachy] patch-ids: fix NEEDSWORK timezone parsing in fast-import.c
Message-ID: <CAFpMFfCfLZgUDnZBWg7kmGN84Y7gTxOm6SYe7F2__t=hHhBZow@mail.gmail.com>
URL: https://gitlist.dev/e/CAFpMFfCfLZgUDnZBWg7kmGN84Y7gTxOm6SYe7F2__t%3DhHhBZow%40mail.gmail.com
In-Reply-To: <xmqq1pnabw1p.fsf@gitster.g>

```
Thanks for the detailed explanation, Junio, and also thanks Patrick
and Kristoffer for the earlier feedback.
That makes sense
 I’ll review whether the additional timezone checks are actually
necessary and if they improve correctness in real cases. I’ll also
update the commit message to better describe the motivation, and fix
the formatting issues mentioned.
Once I’ve clarified the behavior and possibly added a test case, I’ll
send a v2 patch.
Thanks again for the guidance!

On Fri, Oct 10, 2025 at 4:45 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Patrick Steinhardt <ps@pks.im> writes:
>
> > On Fri, Oct 10, 2025 at 12:49:57AM +0100, Okhuomon Ajayi wrote:
> >> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> >> ---
> >
> > For a change like this it is important to explain what the problem is,
> > why it is a problem and how your change improves the code for the
> > better. All of this needs to be patr of the commit message so that the
> > reader can understand what you're actually doing.
> >
> > Also, if this fixes a real issue, is it possible to demonstrate the
> > issue and the fix with a test?
> >
> >> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> >> index 606c6aea82..695e1a0ae1 100644
> >> --- a/builtin/fast-import.c
> >> +++ b/builtin/fast-import.c
> >> @@ -1959,14 +1959,15 @@ static int validate_raw_date(const char *src, struct strbuf *result, int strict)
> >>              return -1;
> >>
> >>      num = strtoul(src + 1, &endp, 10);
> >> -    /*
> >> -     * NEEDSWORK: check for brokenness other than num > 1400, such as
> >> -     *            (num % 100) >= 60, or ((num % 100) % 15) != 0 ?
> >> -     */
> >> -    if (errno || endp == src + 1 || *endp || /* did not parse */
> >> -        (strict && (1400 < num))             /* parsed a broken timezone */
> >> -       )
> >> +
> >> +
> >> +        unsigned int hours = num / 100;
> >> +        unsigned int minutes = num % 100;
> >> +
> >> +    if (errno || endp == src + 1 || *endp ||
> >> +        (strict && (num > 1400 || minutes >=60 || minutes % 15 != 0))){
> >>              return -1;
> >> +    }
> >
> > Despite the formatting issues I also think that this here is becoming
> > hard to read. It may make sense to split this up into multiple
> > conditions.
> >
> > Thanks!
> >
> > Patrick
>
> Thanks for a good suggestion.
>
> There is another thing we should be aware of about these NEEDSWORK
> comments.  Often, the task a NEEDSWORK comment suggests includes and
> starts from assessing if the task indeed is worth doing.  We should
> read a NEEDSWORK comment like above one as its author mumbling to
> themselves: this feels lacking, and we may want to do more here,
> like X and Y and Z.  Maybe not.
>
> Do we need to check even more precisely here?  What's the point of
> doing so, and doing so here at this point in the control flow?  Are
> there better approaches than incrementally adding more of similar
> kinds of checks?
>
> Without being able to answer these questions oneself, one shouldn't
> be blindly following what a NEEDSWORK comment like this floats as
> "ideas to do more".
>
> The current code may turn out to be good enough.  Removing the
> NEEDSWORK comment with a solid answer to the question it poses in
> the proposed log message would be a commit worth making in such a
> case.
>
> Thanks.

```
