* [PATCH] pretend_sha1_file(): Change return type from int to void
@ 2015-10-06 12:15 Tobias Klauser
2015-10-06 13:16 ` Johannes Schindelin
0 siblings, 1 reply; 12+ messages in thread
From: Tobias Klauser @ 2015-10-06 12:15 UTC (permalink / raw)
To: Junio C Hamano, git
prented_sha1_file() always returns 0 and its only callsite in
builtin/blame.c doesn't use the return value, so change the return type
to void.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
cache.h | 2 +-
sha1_file.c | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/cache.h b/cache.h
index 752031e..445853b 100644
--- a/cache.h
+++ b/cache.h
@@ -970,7 +970,7 @@ extern int sha1_object_info(const unsigned char *, unsigned long *);
extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
extern int hash_sha1_file_literally(const void *buf, unsigned long len, const char *type, unsigned char *sha1, unsigned flags);
-extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
+extern void pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
extern int force_object_loose(const unsigned char *sha1, time_t mtime);
extern int git_open_noatime(const char *name);
extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
diff --git a/sha1_file.c b/sha1_file.c
index d295a32..d76b723 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2789,14 +2789,14 @@ static void *read_packed_sha1(const unsigned char *sha1,
return data;
}
-int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
+void pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
unsigned char *sha1)
{
struct cached_object *co;
hash_sha1_file(buf, len, typename(type), sha1);
if (has_sha1_file(sha1) || find_cached_object(sha1))
- return 0;
+ return;
ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
co = &cached_objects[cached_object_nr++];
co->size = len;
@@ -2804,7 +2804,6 @@ int pretend_sha1_file(void *buf, unsigned long len, enum object_type type,
co->buf = xmalloc(len);
memcpy(co->buf, buf, len);
hashcpy(co->sha1, sha1);
- return 0;
}
static void *read_object(const unsigned char *sha1, enum object_type *type,
--
2.6.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-06 12:15 [PATCH] pretend_sha1_file(): Change return type from int to void Tobias Klauser
@ 2015-10-06 13:16 ` Johannes Schindelin
2015-10-06 13:51 ` Tobias Klauser
0 siblings, 1 reply; 12+ messages in thread
From: Johannes Schindelin @ 2015-10-06 13:16 UTC (permalink / raw)
To: Tobias Klauser; +Cc: Junio C Hamano, git
Hi Tobias,
On 2015-10-06 14:15, Tobias Klauser wrote:
> prented_sha1_file() always returns 0 and its only callsite in
> builtin/blame.c doesn't use the return value, so change the return type
> to void.
While this commit message is technically correct, it would appear that there are some things left unsaid.
Is there a problem with the current code that is solved by not returning 0? If so, could you add it to the commit message? And in particular, change the oneline appropriately?
Ciao,
Johannes
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-06 13:16 ` Johannes Schindelin
@ 2015-10-06 13:51 ` Tobias Klauser
2015-10-06 14:30 ` Johannes Schindelin
0 siblings, 1 reply; 12+ messages in thread
From: Tobias Klauser @ 2015-10-06 13:51 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Junio C Hamano, git
Hi Johannes
Thanks for your feedback.
On 2015-10-06 at 15:16:12 +0200, Johannes Schindelin <johannes.schindelin@gmx.de> wrote:
> Hi Tobias,
>
> On 2015-10-06 14:15, Tobias Klauser wrote:
> > prented_sha1_file() always returns 0 and its only callsite in
> > builtin/blame.c doesn't use the return value, so change the return type
> > to void.
>
> While this commit message is technically correct, it would appear that there are some things left unsaid.
>
> Is there a problem with the current code that is solved by not returning 0? If so, could you add it to the commit message? And in particular, change the oneline appropriately?
There's no problem with the current code other than that the return
value is unused and thus unnecessary for correct funcionality. So it's
certainly not a functional problem but rather a cosmetic change.
Does such a change even make sense (it's one of my first patch to git,
so I'm not really sure what your criteria in this respect are)?
If yes, would something like the following bring across the intention
more clearly?
pretend_sha1_file() always returns 0 and its only user in
builtin/blame.c doesn't use the returned value. Thus, the return value
is unnecessary and the return type of pretend_sha1_file() can be
changed to void.
Cheers
Tobias
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-06 13:51 ` Tobias Klauser
@ 2015-10-06 14:30 ` Johannes Schindelin
2015-10-07 8:13 ` Tobias Klauser
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Johannes Schindelin @ 2015-10-06 14:30 UTC (permalink / raw)
To: Tobias Klauser; +Cc: Junio C Hamano, git
Hi Tobias,
On 2015-10-06 15:51, Tobias Klauser wrote:
> On 2015-10-06 at 15:16:12 +0200, Johannes Schindelin
> <johannes.schindelin@gmx.de> wrote:
>>
>> On 2015-10-06 14:15, Tobias Klauser wrote:
>> > prented_sha1_file() always returns 0 and its only callsite in
>> > builtin/blame.c doesn't use the return value, so change the return type
>> > to void.
>>
>> While this commit message is technically correct, it would appear that there are some things left unsaid.
>>
>> Is there a problem with the current code that is solved by not returning 0? If so, could you add it to the commit message? And in particular, change the oneline appropriately?
>
> There's no problem with the current code other than that the return
> value is unused and thus unnecessary for correct funcionality. So it's
> certainly not a functional problem but rather a cosmetic change.
Okay.
> Does such a change even make sense (it's one of my first patch to git,
> so I'm not really sure what your criteria in this respect are)?
Welcome!
As to the patch, I cannot speak for Junio, of course, but my preference would be to keep the return type. Traditionally, functions that can fail either die() or return an int; non-zero indicates an error. In this case, it seems that we do not have any condition (yet...) under which an error could occur. It does not seem very unlikely that we may eventually have such conditions, though, hence my preference.
Ciao,
Johannes
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-06 14:30 ` Johannes Schindelin
@ 2015-10-07 8:13 ` Tobias Klauser
2015-10-07 17:36 ` Junio C Hamano
2015-10-07 21:22 ` Junio C Hamano
2 siblings, 0 replies; 12+ messages in thread
From: Tobias Klauser @ 2015-10-07 8:13 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Junio C Hamano, git
Hi Johannes
On 2015-10-06 at 16:30:36 +0200, Johannes Schindelin <johannes.schindelin@gmx.de> wrote:
> On 2015-10-06 15:51, Tobias Klauser wrote:
>
> > On 2015-10-06 at 15:16:12 +0200, Johannes Schindelin
> > <johannes.schindelin@gmx.de> wrote:
> >>
> >> On 2015-10-06 14:15, Tobias Klauser wrote:
> >> > prented_sha1_file() always returns 0 and its only callsite in
> >> > builtin/blame.c doesn't use the return value, so change the return type
> >> > to void.
> >>
> >> While this commit message is technically correct, it would appear that there are some things left unsaid.
> >>
> >> Is there a problem with the current code that is solved by not returning 0? If so, could you add it to the commit message? And in particular, change the oneline appropriately?
> >
> > There's no problem with the current code other than that the return
> > value is unused and thus unnecessary for correct funcionality. So it's
> > certainly not a functional problem but rather a cosmetic change.
>
> Okay.
>
> > Does such a change even make sense (it's one of my first patch to git,
> > so I'm not really sure what your criteria in this respect are)?
>
> Welcome!
>
> As to the patch, I cannot speak for Junio, of course, but my preference would be to keep the return type. Traditionally, functions that can fail either die() or return an int; non-zero indicates an error. In this case, it seems that we do not have any condition (yet...) under which an error could occur. It does not seem very unlikely that we may eventually have such conditions, though, hence my preference.
Ok, I see. Thank you for your explanation. I'll wait for Junio's decision
then :)
Cheers
Tobias
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-06 14:30 ` Johannes Schindelin
2015-10-07 8:13 ` Tobias Klauser
@ 2015-10-07 17:36 ` Junio C Hamano
2015-10-07 20:42 ` Stefan Beller
2015-10-07 21:22 ` Junio C Hamano
2 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2015-10-07 17:36 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Tobias Klauser, git
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> As to the patch, I cannot speak for Junio, of course, but my
> preference would be to keep the return type. Traditionally, functions
> that can fail either die() or return an int; non-zero indicates an
> error. In this case, it seems that we do not have any condition
> (yet...) under which an error could occur. It does not seem very
> unlikely that we may eventually have such conditions, though, hence my
> preference.
Accepting Tobias's patch may have a documentation value to let the
callers know that the function does not give the caller any error
diagnosis, and it may matter a lot if this were a very frequently
used function, but that is not exactly the case here.
I do not care too deeply.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-07 17:36 ` Junio C Hamano
@ 2015-10-07 20:42 ` Stefan Beller
2015-10-07 21:14 ` Junio C Hamano
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Beller @ 2015-10-07 20:42 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, Tobias Klauser, git@vger.kernel.org
Compare to a patch[1] I sent a while back and the discussion on it.
[1] https://www.mail-archive.com/git@vger.kernel.org/msg70474.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-07 20:42 ` Stefan Beller
@ 2015-10-07 21:14 ` Junio C Hamano
2015-10-07 21:24 ` Stefan Beller
0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2015-10-07 21:14 UTC (permalink / raw)
To: Stefan Beller; +Cc: Johannes Schindelin, Tobias Klauser, git@vger.kernel.org
Stefan Beller <sbeller@google.com> writes:
> Compare to a patch[1] I sent a while back and the discussion on it.
>
> [1] https://www.mail-archive.com/git@vger.kernel.org/msg70474.html
It is not clear what conclusion you want others to draw from the
comparison, I am afraid.
I am guessing that you are in favor of dropping this patch, because
'int' that signals success or error is the most natural return type
and meanint for this function if its callers ever start using the
value as the indication of an error, just like in the old thread,
the return value from get_remote_heads() had the most useful type
and the meaning for its callers if they wanted to use it.
And if that is what you wanted to say, I fully agree with the
conclusion.
By the way, it is not a very good comparison, though. The patch in
the old thread deliberately attempted to discard a useful piece of
information. The information the patch in this thread attempts to
discard is not so useful, as there currently is nobody that returns
an error in the codepath. So in that sense, the patch in this
thread to change the return value to void is a bit more justifiable
than the one in the old thread, I think.
Thanks.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-06 14:30 ` Johannes Schindelin
2015-10-07 8:13 ` Tobias Klauser
2015-10-07 17:36 ` Junio C Hamano
@ 2015-10-07 21:22 ` Junio C Hamano
2015-10-08 7:45 ` Tobias Klauser
2 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2015-10-07 21:22 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Tobias Klauser, git
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> As to the patch, I cannot speak for Junio, of course, but my
> preference would be to keep the return type. Traditionally, functions
> that can fail either die() or return an int; non-zero indicates an
> error. In this case, it seems that we do not have any condition
> (yet...) under which an error could occur. It does not seem very
> unlikely that we may eventually have such conditions, though, hence my
> preference.
Perhaps the attached is a better approach.
Even though the current implementation of "pretend" implementation
does not, future generations are allowed to make pretend_sha1_file()
return failure when appropriate.
builtin/blame.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 203a981..fa24f8f 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2362,7 +2362,8 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
convert_to_git(path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf;
origin->file.size = buf.len;
- pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
+ if (pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1))
+ die("failed to create a fake commit for the working tree version.");
/*
* Read the current index, replace the path entry with
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-07 21:14 ` Junio C Hamano
@ 2015-10-07 21:24 ` Stefan Beller
2015-10-07 21:29 ` Junio C Hamano
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Beller @ 2015-10-07 21:24 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, Tobias Klauser, git@vger.kernel.org
On Wed, Oct 7, 2015 at 2:14 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> Compare to a patch[1] I sent a while back and the discussion on it.
>>
>> [1] https://www.mail-archive.com/git@vger.kernel.org/msg70474.html
>
> It is not clear what conclusion you want others to draw from the
> comparison, I am afraid.
I did not draw a conclusion. All I wanted is to point out, we've had similar
patches before. Maybe I wanted to point out, you had a different opinion
about the patch I linked to than you seem to have now about this patch.
>
> I am guessing that you are in favor of dropping this patch, because
> 'int' that signals success or error is the most natural return type
> and meanint for this function if its callers ever start using the
> value as the indication of an error, just like in the old thread,
> the return value from get_remote_heads() had the most useful type
> and the meaning for its callers if they wanted to use it.
>
> And if that is what you wanted to say, I fully agree with the
> conclusion.
I really did not want to say anything except for pointing out how similar
cases were dealt with in the past. So I guess for a good comparision
we'd need to asses how similar the patches are. If they are similar
it's easier to link to the old discussion instead of retyping the same
reasons.
>
> By the way, it is not a very good comparison, though. The patch in
> the old thread deliberately attempted to discard a useful piece of
> information. The information the patch in this thread attempts to
> discard is not so useful, as there currently is nobody that returns
> an error in the codepath.
Isn't that a bit picky? (old thread: the information is useful, but
nobody uses it,
this thread: information is useless, and nobody uses it)
So the similarity is nobody is using the result, the difference is the
usefulness of
the information provided.
> So in that sense, the patch in this
> thread to change the return value to void is a bit more justifiable
> than the one in the old thread, I think.
That makes sense to me.
>
> Thanks.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-07 21:24 ` Stefan Beller
@ 2015-10-07 21:29 ` Junio C Hamano
0 siblings, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2015-10-07 21:29 UTC (permalink / raw)
To: Stefan Beller; +Cc: Johannes Schindelin, Tobias Klauser, git@vger.kernel.org
Stefan Beller <sbeller@google.com> writes:
>> By the way, it is not a very good comparison, though. The patch in
>> the old thread deliberately attempted to discard a useful piece of
>> information. The information the patch in this thread attempts to
>> discard is not so useful, as there currently is nobody that returns
>> an error in the codepath.
>
> Isn't that a bit picky? (old thread: the information is useful, but
> nobody uses it,
> this thread: information is useless, and nobody uses it)
>
> So the similarity is nobody is using the result, the difference is the
> usefulness of
> the information provided.
Exactly. Why is it picky?
The amount of work in the existing code that is discarded is the
amount of work it will take when somebody wants to resurrect the
compuation of that useful information. When you judge pros and cons
for a patch that discards existing code, you would need to take both
into account---the cost of carrying it and the future cost of having
to resurrect it.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] pretend_sha1_file(): Change return type from int to void
2015-10-07 21:22 ` Junio C Hamano
@ 2015-10-08 7:45 ` Tobias Klauser
0 siblings, 0 replies; 12+ messages in thread
From: Tobias Klauser @ 2015-10-08 7:45 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, git
On 2015-10-07 at 23:22:59 +0200, Junio C Hamano <gitster@pobox.com> wrote:
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
> > As to the patch, I cannot speak for Junio, of course, but my
> > preference would be to keep the return type. Traditionally, functions
> > that can fail either die() or return an int; non-zero indicates an
> > error. In this case, it seems that we do not have any condition
> > (yet...) under which an error could occur. It does not seem very
> > unlikely that we may eventually have such conditions, though, hence my
> > preference.
>
> Perhaps the attached is a better approach.
>
> Even though the current implementation of "pretend" implementation
> does not, future generations are allowed to make pretend_sha1_file()
> return failure when appropriate.
For my original patch I didn't consider that pretend_sha1_file() might
return failure in the future. I was just confused by the fact that the
return value was seemingly useless (but now I realize that unused !=
useless ;-), sorry for the noise.
Please disregard my patch and apply yours instead, if you see fit.
>
> builtin/blame.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/blame.c b/builtin/blame.c
> index 203a981..fa24f8f 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -2362,7 +2362,8 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
> convert_to_git(path, buf.buf, buf.len, &buf, 0);
> origin->file.ptr = buf.buf;
> origin->file.size = buf.len;
> - pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
> + if (pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1))
> + die("failed to create a fake commit for the working tree version.");
>
> /*
> * Read the current index, replace the path entry with
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-10-08 7:45 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-06 12:15 [PATCH] pretend_sha1_file(): Change return type from int to void Tobias Klauser
2015-10-06 13:16 ` Johannes Schindelin
2015-10-06 13:51 ` Tobias Klauser
2015-10-06 14:30 ` Johannes Schindelin
2015-10-07 8:13 ` Tobias Klauser
2015-10-07 17:36 ` Junio C Hamano
2015-10-07 20:42 ` Stefan Beller
2015-10-07 21:14 ` Junio C Hamano
2015-10-07 21:24 ` Stefan Beller
2015-10-07 21:29 ` Junio C Hamano
2015-10-07 21:22 ` Junio C Hamano
2015-10-08 7:45 ` Tobias Klauser
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).