refs: print errno for read_raw_ref if GIT_TRACE_REFS is set
PATCH 1/1 refs: print errno for read_raw_ref if GIT_TRACE_REFS is set
From: Han-Wen Nienhuys <[email protected]>
The ref backend API uses errno as a sideband error channel.
---
refs: print errno for read_raw_ref if GIT_TRACE_REFS is set
The ref backend API uses errno as a sideband error channel.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1002%2Fhanwen%2Ferrno-debug-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1002/hanwen/errno-debug-v1
Pull-Request: https://github.com/git/git/pull/1002
refs/debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
refs/debug.c +4 -1
@@ -244,6 +244,7 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,int res =0 ;oidcpy (oid, &null_oid); + errno =0 ; res = drefs->refs->be->read_raw_ref (drefs->refs, refname, oid, referent, type);
@@ -251,7 +252,9 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,trace_printf_key (&trace_refs,"read_raw_ref: %s: %s (=> %s) type %x: %d\n" , refname,oid_to_hex (oid), referent->buf, *type, res); }else { -trace_printf_key (&trace_refs,"read_raw_ref: %s: %d\n" , refname, res); +trace_printf_key (&trace_refs, +"read_raw_ref: %s: %d (errno %d)\n" , refname, + res, errno); }return res; }
base-commit: 89b43f80a514aee58b662ad606e6352e03eaeee4
Signature · 1 line
gitgitgadget
Quoted 13 lines · Han-Wen Nienhuys via GitGitGadget
refs/debug.c +1
-0@@ -244,6 +244,7 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,int res =0 ;oidcpy (oid, &null_oid); + errno =0 ; res = drefs->refs->be->read_raw_ref (drefs->refs, refname, oid, referent, type);
refs/debug.c static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname, · line 258
Quoted 8 lines
refs/debug.c +3
-1@@ -251,7 +252,9 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,trace_printf_key (&trace_refs,"read_raw_ref: %s: %s (=> %s) type %x: %d\n" , refname,oid_to_hex (oid), referent->buf, *type, res); }else { -trace_printf_key (&trace_refs,"read_raw_ref: %s: %d\n" , refname, res); +trace_printf_key (&trace_refs, +"read_raw_ref: %s: %d (errno %d)\n" , refname, + res, errno); }
OK. Between trace_printf_key() and the return of the call to read_raw_ref() method of the ref backend is only an "if (res == 0)" condition and I do not see anything that might clobber errno.
I do wonder if we want strerror(errno) instead of the number, but I can go either way (it's just a trace output).
Thanks, will queue.
Quoted 5 lines · Junio C Hamano
Quoted 5 lines
refs/debug.c +0
-1@@ -251,7 +252,9 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,trace_printf_key (&trace_refs,"read_raw_ref: %s: %s (=> %s) type %x: %d\n" , refname,oid_to_hex (oid), referent->buf, *type, res); }else { -trace_printf_key (&trace_refs,"read_raw_ref: %s: %d\n" , refname, res);
Quoted 8 lines
refs/debug.c static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname, · line 258
Quoted 4 lines
refs/debug.c +3
-0+trace_printf_key (&trace_refs, +"read_raw_ref: %s: %d (errno %d)\n" , refname, + res, errno); }OK. Between
trace_printf_key()and the return of the call toread_raw_ref()method of the ref backend is only an "if (res == 0)" condition and I do not see anything that might clobber errno.
I don't want to bet on that. Let me send a second round.
Quoted 2 lines
I do wonder if we want strerror(errno) instead of the number, but I can go either way (it's just a trace output).
For tracing, it would be most useful if we got the actual symbol (eg. ENOENT). Is there a way to get at that?
Signature · 11 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Quoted 16 lines · Han-Wen Nienhuys
Quoted 5 lines · Junio C Hamano
Quoted 5 lines
refs/debug.c +0
-1@@ -251,7 +252,9 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,trace_printf_key (&trace_refs,"read_raw_ref: %s: %s (=> %s) type %x: %d\n" , refname,oid_to_hex (oid), referent->buf, *type, res); }else { -trace_printf_key (&trace_refs,"read_raw_ref: %s: %d\n" , refname, res);Quoted 8 lines
refs/debug.c static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname, · line 258
Quoted 4 lines
refs/debug.c +3
-0+trace_printf_key (&trace_refs, +"read_raw_ref: %s: %d (errno %d)\n" , refname, + res, errno); }OK. Between
trace_printf_key()and the return of the call toread_raw_ref()method of the ref backend is only an "if (res == 0)" condition and I do not see anything that might clobber errno.
Quoted 1 line
I don't want to bet on that. Let me send a second round.
oh, ugh. In email, there are two calls, but one is prefixed with '-'.
Nevertheless, a bit of paranoia doesn't hurt here.
Signature · 11 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
PATCH v2 1/1 refs: print errno for read_raw_ref if GIT_TRACE_REFS is set
In reply to Han-Wen Nienhuys via GitGitGadgetFrom: Han-Wen Nienhuys <[email protected]>
The ref backend API uses errno as a sideband error channel.
---
refs: print errno for read_raw_ref if GIT_TRACE_REFS is set
The ref backend API uses errno as a sideband error channel.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1002%2Fhanwen%2Ferrno-debug-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1002/hanwen/errno-debug-v2
Pull-Request: https://github.com/git/git/pull/1002
Range-diff vs v1:
1: 9b150c5563f9 ! 1: 1e9a8990e7f2 refs: print errno for read_raw_ref if GIT_TRACE_REFS is set
@@ Commit message
## refs/debug.c ##
@@ refs/debug.c: static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
+ {
+ struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
int res = 0;
++ int saved_errno = 0;
oidcpy(oid, &null_oid);
+ errno = 0;
res = drefs->refs->be->read_raw_ref(drefs->refs, refname, oid, referent,
type);
++ saved_errno = errno;
-@@ refs/debug.c: static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
+ if (res == 0) {
trace_printf_key(&trace_refs, "read_raw_ref: %s: %s (=> %s) type %x: %d\n",
refname, oid_to_hex(oid), referent->buf, *type, res);
} else {
- trace_printf_key(&trace_refs, "read_raw_ref: %s: %d\n", refname, res);
+ trace_printf_key(&trace_refs,
+ "read_raw_ref: %s: %d (errno %d)\n", refname,
-+ res, errno);
++ res, saved_errno);
}
return res;
}refs/debug.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
refs/debug.c +6 -1
@@ -242,16 +242,21 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname, {struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;int res =0 ; +int saved_errno =0 ;oidcpy (oid, &null_oid); + errno =0 ; res = drefs->refs->be->read_raw_ref (drefs->refs, refname, oid, referent, type); + saved_errno = errno;if (res ==0 ) {trace_printf_key (&trace_refs,"read_raw_ref: %s: %s (=> %s) type %x: %d\n" , refname,oid_to_hex (oid), referent->buf, *type, res); }else { -trace_printf_key (&trace_refs,"read_raw_ref: %s: %d\n" , refname, res); +trace_printf_key (&trace_refs, +"read_raw_ref: %s: %d (errno %d)\n" , refname, + res, saved_errno); }return res; }
base-commit: 89b43f80a514aee58b662ad606e6352e03eaeee4
Signature · 1 line
gitgitgadget
Quoted 5 lines · Han-Wen Nienhuys
Quoted 2 lines
I do wonder if we want strerror(errno) instead of the number, but I can go either way (it's just a trace output).
For tracing, it would be most useful if we got the actual symbol (eg. ENOENT). Is there a way to get at that?
I do not think there is.
And that is the reason why we see everywhere calls to die_errno(), error(..., strerror(errno)), etc.
As this is interpolated into trace with untranslated string, I suspect that strerror() is not a good match, so let's live with %d for now.
Thanks.
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Han-Wen Nienhuys
Quoted 2 lines
I do wonder if we want strerror(errno) instead of the number, but I can go either way (it's just a trace output).
For tracing, it would be most useful if we got the actual symbol (eg. ENOENT). Is there a way to get at that?
Quoted 8 lines
I do not think there is.
And that is the reason why we see everywhere calls to
die_errno(),error(..., strerror(errno)), etc.As this is interpolated into trace with untranslated string, I suspect that
strerror()is not a good match, so let's live with %d for now.
Great!
This topic is marked as
Waiting for reviews to conclude.
cf. <[email protected]>
but I don't know what is left to do. Oversight?
Signature · 7 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado