Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
alias.c | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
branch.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
imap-send.c | 68 ++++++++++++++++++++++++++-----------------------------------
1 file changed, 29 insertions(+), 39 deletions(-)
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
pager.c | 44 +++++++++++++++-----------------------------
1 file changed, 15 insertions(+), 29 deletions(-)
@@ -155,30 +149,22 @@ int decimal_width(int number)returnwidth;}-staticintpager_command_config(constchar*var,constchar*value,void*data)-{-structpager_config*c=data;-if(starts_with(var,"pager.")&&!strcmp(var+6,c->cmd)){-intb=git_config_maybe_bool(var,value);-if(b>=0)-c->want=b;-else{-c->want=1;-c->value=xstrdup(value);-}-}-return0;-}-/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */intcheck_pager_config(constchar*cmd){-structpager_configc;-c.cmd=cmd;-c.want=-1;-c.value=NULL;-git_config(pager_command_config,&c);-if(c.value)-pager_program=c.value;-returnc.want;+structstrbufkey=STRBUF_INIT;+intwant=-1;+constchar*value=NULL;+strbuf_addf(&key,"pager.%s",cmd);+if(!git_config_get_string(key.buf,&value)){+intb=git_config_maybe_bool(key.buf,value);+if(b>=0)+want=b;+else+want=1;+}+if(value)+pager_program=value;+strbuf_release(&key);+returnwant;}
From: Eric Sunshine <hidden> Date: 2016-06-15 23:01:44
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted hunk
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
alias.c | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
+ value = xstrdup(v);
+ strbuf_release(&key);
+ return value;
You could release the strbuf earlier, which would allow you to 'return
xstrdup(v)' and drop the 'value' variable. Perhaps you want something
like this:
const char *v;
struct strbuf key = STRBUF_INIT;
strbuf_addf(&key, "alias.%s", alias);
git_config_get_string(key.buf, &v);
if (v)
config_error_nonbool(key.buf);
strbuf_release(&key);
return v ? xstrdup(v) : NULL;
From: Eric Sunshine <hidden> Date: 2016-06-15 23:01:44
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted hunk
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
pager.c | 44 +++++++++++++++-----------------------------
1 file changed, 15 insertions(+), 29 deletions(-)
@@ -155,30 +149,22 @@ int decimal_width(int number)returnwidth;}-staticintpager_command_config(constchar*var,constchar*value,void*data)-{-structpager_config*c=data;-if(starts_with(var,"pager.")&&!strcmp(var+6,c->cmd)){-intb=git_config_maybe_bool(var,value);-if(b>=0)-c->want=b;-else{-c->want=1;-c->value=xstrdup(value);-}-}-return0;-}-/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */intcheck_pager_config(constchar*cmd){-structpager_configc;-c.cmd=cmd;-c.want=-1;-c.value=NULL;-git_config(pager_command_config,&c);-if(c.value)-pager_program=c.value;-returnc.want;+structstrbufkey=STRBUF_INIT;+intwant=-1;+constchar*value=NULL;+strbuf_addf(&key,"pager.%s",cmd);+if(!git_config_get_string(key.buf,&value)){+intb=git_config_maybe_bool(key.buf,value);+if(b>=0)+want=b;+else+want=1;+}+if(value)+pager_program=value;
Two issues:
First, why is 'if(value)' standing by itself? Although this works, it
seems to imply that 'value' might be able to become non-NULL by some
mechanism other than the get_config_maybe_bool() call, which means
that people reading this code have to spend extra time trying to
understand the overall logic. If you follow the example of the
original code, where 'value' is only ever set when 'b < 0', then it is
obvious even to the most casual reader that 'pager_program' is
assigned only for that one condition.
Second, don't you want to xstrdup(value) when assigning to
'pager_program'? If you don't, then 'pager_program' will become a
dangling pointer when config_cache_free() is invoked.
From: Eric Sunshine <hidden> Date: 2016-06-15 23:01:44
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted hunk
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
branch.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
What is the purpose of retaining this structure? Following your
changes, it is never used outside of read_branch_desc(), and
'config_name' and 'value' would be more naturally declared as
variables local to that function.
Although it works in this case, it's somewhat ugly that you ignore the
return value of git_config_get_string(), and a person reading the code
has to spend extra time digging into git_config_string() to figure out
why this is safe. If might be clearer for future readers by rephrasing
like this:
if (git_config_get_string(desc.config_name, &value) < 0 ||
git_config_string(&desc.value, desc.config_name, value) < 0) {
From: Eric Sunshine <hidden> Date: 2016-06-15 23:01:44
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
You may want to mention as a side-note the slight behavior change
introduced by this patch. The original code complained about any
unknown boolean "imap.*" key, whereas the new code does not.
More below.
@@ -1326,47 +1326,37 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)staticchar*imap_folder;-staticintgit_imap_config(constchar*key,constchar*val,void*cb)+staticvoidgit_imap_config(void){-charimap_key[]="imap.";--if(strncmp(key,imap_key,sizeofimap_key-1))-return0;--key+=sizeofimap_key-1;--/* check booleans first, and barf on others */-if(!strcmp("sslverify",key))-server.ssl_verify=git_config_bool(key,val);-elseif(!strcmp("preformattedhtml",key))-server.use_html=git_config_bool(key,val);-elseif(!val)-returnconfig_error_nonbool(key);--if(!strcmp("folder",key)){-imap_folder=xstrdup(val);-}elseif(!strcmp("host",key)){-if(starts_with(val,"imap:"))-val+=5;-elseif(starts_with(val,"imaps:")){-val+=6;+constchar*value;
Observation: If you name this variable 'val', which is the name of the
argument to the function in the original code, you will get a slightly
smaller and more readable diff. In this case, the improvement in the
diff is so slight that it might not be worth re-using the old variable
name, but in general, it's helpful to keep in mind that the smaller
and simpler the diff, the easier the patch is to review.
+ if (!git_config_get_string("imap.sslverify", &value))
+ server.ssl_verify = git_config_bool("sslverify", value);
I realize that you are just replicating the behavior of the original
code, but the error message emitted here for a non-bool value is less
than desirable since it throws away context (namely, the "imap."
prefix). You can improve the message, and help the user resolve the
error more quickly, by presenting the full configuration key (namely,
"imap.sslverify"). Such a change would deserve mention in the commit
message. Alternately, it could be fixed in a follow-up patch.
+ if (!git_config_get_string("imap.preformattedhtml", &value))
+ server.use_html = git_config_bool("preformattedhtml", value);
From: Eric Sunshine <hidden> Date: 2016-06-15 23:01:44
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted hunk
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
c->combine = parse_combine_notes_fn(v);
Worse: Though you correctly emit an error when 'v' is NULL, you then
(incorrectly) invoke parse_combine_notes_fn() with that NULL value,
which will result in a crash.
quoted hunk
- if (!c->combine) {
+ if (!c->combine)
error(_("Bad notes.rewriteMode value: '%s'"), v);
- return 1;
- }
- return 0;
- } else if (!c->refs_from_env && !strcmp(k, "notes.rewriteref")) {
+ }
+ if (!c->refs_from_env && !git_config_get_string("notes.rewriteref", &v)) {
/* note that a refs/ prefix is implied in the
* underlying for_each_glob_ref */
if (starts_with(v, "refs/notes/"))
@@ -91,10 +92,8 @@ static int notes_rewrite_config(const char *k, const char *v, void *cb) else warning(_("Refusing to rewrite notes in %s" " (outside of refs/notes/)"), v);- return 0; }-- return 0;+ strbuf_release(&key);
It would be better to release the strbuf immediately after its final
use rather than waiting until the end of function. Not only does that
reduce cognitive load on people reading the code, but it also reduces
likelihood of 'key' being leaked if some future programmer inserts an
early 'return' into the function for some reason.
From: Eric Sunshine <hidden> Date: 2016-06-15 23:01:44
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted hunk
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
Although you correctly diagnose a NULL 'value', you then invoke
string_list_add_refs_by_glob() with that NULL, which will result in a
crash.
This is not a new error. It dates back to 894a9d33 (Support showing
notes from more than one notes tree; 2010-03-12), but your rewrite
should not retain the brokenness. Whether you fix it in this patch or
a lead-in fix-up patch, the fix deserves mention in the commit
message.
+ }
if (opt) {
struct string_list_item *item;
--
1.9.0.GIT
What is the purpose of retaining this structure? Following your
changes, it is never used outside of read_branch_desc(), and
'config_name' and 'value' would be more naturally declared as
variables local to that function.
Although it works in this case, it's somewhat ugly that you ignore the
return value of git_config_get_string(), and a person reading the code
has to spend extra time digging into git_config_string() to figure out
why this is safe. If might be clearer for future readers by rephrasing
like this:
if (git_config_get_string(desc.config_name, &value) < 0 ||
git_config_string(&desc.value, desc.config_name, value) < 0) {
Noted, also didn't the old code leak desc.value as it was xstrduped
by git_config_string()? Thanks for the review.
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
You may want to mention as a side-note the slight behavior change
introduced by this patch. The original code complained about any
unknown boolean "imap.*" key, whereas the new code does not.
Also, my code is error prone. Previous one had all NULL values returned
as config_non_boolean. But, now I have to add a NULL check to every strdup
in the code.
More below,
@@ -1326,47 +1326,37 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)staticchar*imap_folder;-staticintgit_imap_config(constchar*key,constchar*val,void*cb)+staticvoidgit_imap_config(void){-charimap_key[]="imap.";--if(strncmp(key,imap_key,sizeofimap_key-1))-return0;--key+=sizeofimap_key-1;--/* check booleans first, and barf on others */-if(!strcmp("sslverify",key))-server.ssl_verify=git_config_bool(key,val);-elseif(!strcmp("preformattedhtml",key))-server.use_html=git_config_bool(key,val);-elseif(!val)-returnconfig_error_nonbool(key);--if(!strcmp("folder",key)){-imap_folder=xstrdup(val);-}elseif(!strcmp("host",key)){-if(starts_with(val,"imap:"))-val+=5;-elseif(starts_with(val,"imaps:")){-val+=6;+constchar*value;
Observation: If you name this variable 'val', which is the name of the
argument to the function in the original code, you will get a slightly
smaller and more readable diff.
Noted.
quoted
+ if (!git_config_get_string("imap.sslverify", &value))
+ server.ssl_verify = git_config_bool("sslverify", value);
I realize that you are just replicating the behavior of the original
code, but the error message emitted here for a non-bool value is less
than desirable since it throws away context (namely, the "imap."
prefix). You can improve the message, and help the user resolve the
error more quickly, by presenting the full configuration key (namely,
"imap.sslverify"). Such a change would deserve mention in the commit
message. Alternately, it could be fixed in a follow-up patch.
Yes, I thought so also when writing the patch. Will change it in the next
iteration.
Thanks.
Tanay Abhra.
quoted
+ if (!git_config_get_string("imap.preformattedhtml", &value))
+ server.use_html = git_config_bool("preformattedhtml", value);
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
Is this change serious enough? Can I ignore it?
quoted
c->combine = parse_combine_notes_fn(v);
Worse: Though you correctly emit an error when 'v' is NULL, you then
(incorrectly) invoke parse_combine_notes_fn() with that NULL value,
which will result in a crash.
Noted.
quoted
- if (!c->combine) {
+ if (!c->combine)
error(_("Bad notes.rewriteMode value: '%s'"), v);
- return 1;
- }
- return 0;
- } else if (!c->refs_from_env && !strcmp(k, "notes.rewriteref")) {
+ }
+ if (!c->refs_from_env && !git_config_get_string("notes.rewriteref", &v)) {
/* note that a refs/ prefix is implied in the
* underlying for_each_glob_ref */
if (starts_with(v, "refs/notes/"))
@@ -91,10 +92,8 @@ static int notes_rewrite_config(const char *k, const char *v, void *cb) else warning(_("Refusing to rewrite notes in %s" " (outside of refs/notes/)"), v);- return 0; }-- return 0;+ strbuf_release(&key);
It would be better to release the strbuf immediately after its final
use rather than waiting until the end of function. Not only does that
reduce cognitive load on people reading the code, but it also reduces
likelihood of 'key' being leaked if some future programmer inserts an
early 'return' into the function for some reason.
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
Although you correctly diagnose a NULL 'value', you then invoke
string_list_add_refs_by_glob() with that NULL, which will result in a
crash.
This is not a new error. It dates back to 894a9d33 (Support showing
notes from more than one notes tree; 2010-03-12), but your rewrite
should not retain the brokenness. Whether you fix it in this patch or
a lead-in fix-up patch, the fix deserves mention in the commit
message.
Done. Thanks.
quoted
+ }
if (opt) {
struct string_list_item *item;
--
1.9.0.GIT
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
pager.c | 44 +++++++++++++++-----------------------------
1 file changed, 15 insertions(+), 29 deletions(-)
@@ -155,30 +149,22 @@ int decimal_width(int number)returnwidth;}-staticintpager_command_config(constchar*var,constchar*value,void*data)-{-structpager_config*c=data;-if(starts_with(var,"pager.")&&!strcmp(var+6,c->cmd)){-intb=git_config_maybe_bool(var,value);-if(b>=0)-c->want=b;-else{-c->want=1;-c->value=xstrdup(value);-}-}-return0;-}-/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */intcheck_pager_config(constchar*cmd){-structpager_configc;-c.cmd=cmd;-c.want=-1;-c.value=NULL;-git_config(pager_command_config,&c);-if(c.value)-pager_program=c.value;-returnc.want;+structstrbufkey=STRBUF_INIT;+intwant=-1;+constchar*value=NULL;+strbuf_addf(&key,"pager.%s",cmd);+if(!git_config_get_string(key.buf,&value)){+intb=git_config_maybe_bool(key.buf,value);+if(b>=0)+want=b;+else+want=1;+}+if(value)+pager_program=value;
Two issues:
First, why is 'if(value)' standing by itself? Although this works, it
seems to imply that 'value' might be able to become non-NULL by some
mechanism other than the get_config_maybe_bool() call, which means
that people reading this code have to spend extra time trying to
understand the overall logic. If you follow the example of the
original code, where 'value' is only ever set when 'b < 0', then it is
obvious even to the most casual reader that 'pager_program' is
assigned only for that one condition.
Noted.
Second, don't you want to xstrdup(value) when assigning to
'pager_program'? If you don't, then 'pager_program' will become a
dangling pointer when config_cache_free() is invoked.
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
alias.c | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
+ value = xstrdup(v);
+ strbuf_release(&key);
+ return value;
You could release the strbuf earlier, which would allow you to 'return
xstrdup(v)' and drop the 'value' variable. Perhaps you want something
like this:
const char *v;
struct strbuf key = STRBUF_INIT;
strbuf_addf(&key, "alias.%s", alias);
git_config_get_string(key.buf, &v);
if (v)
config_error_nonbool(key.buf);
strbuf_release(&key);
return v ? xstrdup(v) : NULL;
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
[...]
quoted
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
int check_pager_config(const char *cmd)
{
- struct pager_config c;
- c.cmd = cmd;
- c.want = -1;
- c.value = NULL;
- git_config(pager_command_config, &c);
- if (c.value)
- pager_program = c.value;
- return c.want;
+ struct strbuf key = STRBUF_INIT;
+ int want = -1;
+ const char *value = NULL;
+ strbuf_addf(&key, "pager.%s", cmd);
+ if (!git_config_get_string(key.buf, &value)) {
+ int b = git_config_maybe_bool(key.buf, value);
+ if (b >= 0)
+ want = b;
+ else
+ want = 1;
+ }
+ if (value)
+ pager_program = value;
[...]
Second, don't you want to xstrdup(value) when assigning to
'pager_program'? If you don't, then 'pager_program' will become a
dangling pointer when config_cache_free() is invoked.
I don't think that values from the global config cache should be xstrdup()ed.
After all, caching the values during the lifetime of the git process is the
entire point of the config cache, isn't it?
The only reason to call config_cache_free() is to load a _different_
configuration. In this case, however, you would also need to call the relevant
config functions again, leaking all xstrdup()ed strings.
If for some reason a config string is accessed after config_cache_free()
(which would be a bug), you won't notice if strings are xstrdup()ed (i.e. git
will continue to run with some invalid configuration). This is IMO much worse
than failing with segfault.
From: Eric Sunshine <hidden> Date: 2016-06-15 23:01:46
On Thu, Jun 26, 2014 at 4:19 AM, Tanay Abhra [off-list ref] wrote:
On 6/25/2014 1:24 PM, Eric Sunshine wrote:
quoted
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
Is this change serious enough? Can I ignore it?
I don't know. Even within this single function there is no consistency
about whether such problems should die() or just emit a message and
continue. For instance:
- if "notes.rewritemode" is bool, it die()s.
- if "notes.rewritemode" doesn't specify a recognized mode, it
error()s but continues
- if "notes.rewriteref" doesn't start with "refs/notes/, it warning()s
and continues
It would be nice to hear an opinion from someone more invested in the
config system.
quoted
quoted
c->combine = parse_combine_notes_fn(v);
Worse: Though you correctly emit an error when 'v' is NULL, you then
(incorrectly) invoke parse_combine_notes_fn() with that NULL value,
which will result in a crash.
Noted.
quoted
quoted
- if (!c->combine) {
+ if (!c->combine)
error(_("Bad notes.rewriteMode value: '%s'"), v);
- return 1;
- }
- return 0;
- } else if (!c->refs_from_env && !strcmp(k, "notes.rewriteref")) {
+ }
+ if (!c->refs_from_env && !git_config_get_string("notes.rewriteref", &v)) {
/* note that a refs/ prefix is implied in the
* underlying for_each_glob_ref */
if (starts_with(v, "refs/notes/"))
@@ -91,10 +92,8 @@ static int notes_rewrite_config(const char *k, const char *v, void *cb) else warning(_("Refusing to rewrite notes in %s" " (outside of refs/notes/)"), v);- return 0; }-- return 0;+ strbuf_release(&key);
It would be better to release the strbuf immediately after its final
use rather than waiting until the end of function. Not only does that
reduce cognitive load on people reading the code, but it also reduces
likelihood of 'key' being leaked if some future programmer inserts an
early 'return' into the function for some reason.
Although it works in this case, it's somewhat ugly that you ignore the
return value of git_config_get_string(), and a person reading the code
has to spend extra time digging into git_config_string() to figure out
why this is safe. If might be clearer for future readers by rephrasing
like this:
if (git_config_get_string(desc.config_name, &value) < 0 ||
git_config_string(&desc.value, desc.config_name, value) < 0) {
Noted, also didn't the old code leak desc.value as it was xstrduped
by git_config_string()? Thanks for the review.
On Thu, Jun 26, 2014 at 4:19 AM, Tanay Abhra [off-list ref] wrote:
quoted
On 6/25/2014 1:24 PM, Eric Sunshine wrote:
quoted
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
Is this change serious enough? Can I ignore it?
IMO its better to Fail Fast than continue with some invalid config (which
may lead to more severe errors such as data corruption / data loss).
I don't know. Even within this single function there is no consistency
about whether such problems should die() or just emit a message and
continue. For instance:
- if "notes.rewritemode" is bool, it die()s.
- if "notes.rewritemode" doesn't specify a recognized mode, it
error()s but continues
I think this would also die in git_parse_source():
...
if (get_value(fn, data, var) < 0)
break;
}
if (cf->die_on_error)
die("bad config file line %d in %s", cf->linenr, cf->name);
...
(AFAICT, die_on_error is always true, except if invoked via 'git-config
--blob', which isn't used anywhere...)
This, however, raises another issue: switching to the config cache looses
file/line-precise error reporting for semantic errors. I don't know if
this feature is important enough to do something about it, though. A
message of the form "Key 'xyz' is bad" should usually enable a user to
locate the problematic file and line.
From: Eric Sunshine <hidden> Date: 2016-06-15 23:01:46
On Mon, Jun 30, 2014 at 9:34 AM, Karsten Blees [off-list ref] wrote:
Am 29.06.2014 13:01, schrieb Eric Sunshine:
quoted
On Thu, Jun 26, 2014 at 4:19 AM, Tanay Abhra [off-list ref] wrote:
quoted
On 6/25/2014 1:24 PM, Eric Sunshine wrote:
quoted
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
Is this change serious enough? Can I ignore it?
IMO its better to Fail Fast than continue with some invalid config (which
may lead to more severe errors such as data corruption / data loss).
quoted
I don't know. Even within this single function there is no consistency
about whether such problems should die() or just emit a message and
continue. For instance:
- if "notes.rewritemode" is bool, it die()s.
- if "notes.rewritemode" doesn't specify a recognized mode, it
error()s but continues
I think this would also die in git_parse_source():
...
if (get_value(fn, data, var) < 0)
break;
}
if (cf->die_on_error)
die("bad config file line %d in %s", cf->linenr, cf->name);
...
One would expect so, but notes-utils.c:notes_rewrite_config() is
actually doing this:
if (!c->combine) {
error(_("Bad notes.rewriteMode value: '%s'"), v);
return 1;
}
Rather than returning the -1 result of error(), which would make
git_parse_source() die(), it's explicitly returning 1, which
get_parse_source() ignores.
(AFAICT, die_on_error is always true, except if invoked via 'git-config
--blob', which isn't used anywhere...)
This, however, raises another issue: switching to the config cache looses
file/line-precise error reporting for semantic errors. I don't know if
this feature is important enough to do something about it, though. A
message of the form "Key 'xyz' is bad" should usually enable a user to
locate the problematic file and line.
On Thu, Jun 26, 2014 at 4:19 AM, Tanay Abhra [off-list ref] wrote:
quoted
On 6/25/2014 1:24 PM, Eric Sunshine wrote:
quoted
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
Is this change serious enough? Can I ignore it?
IMO its better to Fail Fast than continue with some invalid config (which
may lead to more severe errors such as data corruption / data loss).
Noted but, what I am trying to do with the rewrite is emit an error and
not set the value if the value found is a NULL. The only change is that
program will not crash in this case and warn the user not set a NULL value for
a non boolean key.
This won't lead to severe errors as the value will not be set if found value
is a NULL.
quoted
I don't know. Even within this single function there is no consistency
about whether such problems should die() or just emit a message and
continue. For instance:
- if "notes.rewritemode" is bool, it die()s.
- if "notes.rewritemode" doesn't specify a recognized mode, it
error()s but continues
I think this would also die in git_parse_source():
...
if (get_value(fn, data, var) < 0)
break;
}
if (cf->die_on_error)
die("bad config file line %d in %s", cf->linenr, cf->name);
...
(AFAICT, die_on_error is always true, except if invoked via 'git-config
--blob', which isn't used anywhere...)
Noted.
This, however, raises another issue: switching to the config cache looses
file/line-precise error reporting for semantic errors. I don't know if
this feature is important enough to do something about it, though. A
message of the form "Key 'xyz' is bad" should usually enable a user to
locate the problematic file and line.
Hmn, but during the config cache construction we parse key-value pairs through
git_config() which still warns users about semantic errors. This happened
yesterday only when I was writing tests for the new API.
Thanks for the review.
Cheers,
Tanay Abhra.
On Mon, Jun 30, 2014 at 9:34 AM, Karsten Blees [off-list ref] wrote:
quoted
Am 29.06.2014 13:01, schrieb Eric Sunshine:
quoted
On Thu, Jun 26, 2014 at 4:19 AM, Tanay Abhra [off-list ref] wrote:
quoted
On 6/25/2014 1:24 PM, Eric Sunshine wrote:
quoted
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
Is this change serious enough? Can I ignore it?
IMO its better to Fail Fast than continue with some invalid config (which
may lead to more severe errors such as data corruption / data loss).
quoted
I don't know. Even within this single function there is no consistency
about whether such problems should die() or just emit a message and
continue. For instance:
- if "notes.rewritemode" is bool, it die()s.
- if "notes.rewritemode" doesn't specify a recognized mode, it
error()s but continues
I think this would also die in git_parse_source():
...
if (get_value(fn, data, var) < 0)
break;
}
if (cf->die_on_error)
die("bad config file line %d in %s", cf->linenr, cf->name);
...
One would expect so, but notes-utils.c:notes_rewrite_config() is
actually doing this:
if (!c->combine) {
error(_("Bad notes.rewriteMode value: '%s'"), v);
return 1;
}
Rather than returning the -1 result of error(), which would make
git_parse_source() die(), it's explicitly returning 1, which
get_parse_source() ignores.
On Thu, Jun 26, 2014 at 4:19 AM, Tanay Abhra [off-list ref] wrote:
quoted
On 6/25/2014 1:24 PM, Eric Sunshine wrote:
quoted
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
Is this change serious enough? Can I ignore it?
IMO its better to Fail Fast than continue with some invalid config (which
may lead to more severe errors such as data corruption / data loss).
Noted but, what I am trying to do with the rewrite is emit an error and
not set the value if the value found is a NULL.
If you don't set the value and continue, git will proceed with the variable's
default setting.
Which may not be too harmful in some cases, but if a user changes:
gc.pruneexpire=4.weeks.ago
to
gc.pruneexpire=4.monhts.ago
(note the typo), the next git-gc will warn the user and then happily throw
away data that the user intended to keep (default is 2.weeks.ago).
Thus I think git should die() if it encounters an invalid config setting.
quoted
This, however, raises another issue: switching to the config cache looses
file/line-precise error reporting for semantic errors. I don't know if
this feature is important enough to do something about it, though. A
message of the form "Key 'xyz' is bad" should usually enable a user to
locate the problematic file and line.
Hmn, but during the config cache construction we parse key-value pairs through
git_config() which still warns users about semantic errors.
If I'm not mistaken you only detect _syntax_ errors when loading the file (i.e.
whether the config file is structurally correct).
The semantic value and correctness of a key (e.g. whether its a boolean or an
int or a string that denotes a known merge algorithm) is only checked when it is
accessed via git_config_get_<type>. And at this point, <file>:<line> information
is already lost.
With the callback approach, both syntactic (structure) and semantic (meaning)
errors were checked at load time, resulting in
die("bad config file line %d in %s", cf->linenr, cf->name);
if the callback returned -1.
On Thu, Jun 26, 2014 at 4:19 AM, Tanay Abhra [off-list ref] wrote:
quoted
On 6/25/2014 1:24 PM, Eric Sunshine wrote:
quoted
On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra [off-list ref] wrote:
quoted
Use git_config_get_string instead of git_config to take advantage of
the config hash-table api which provides a cleaner control flow.
Signed-off-by: Tanay Abhra <redacted>
---
notes-utils.c | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
There's a behavior change here. In the original code, the callback
function would return -1, which would cause the program to die() if
the config.c:die_on_error flag was set. The new code merely emits an
error.
Is this change serious enough? Can I ignore it?
IMO its better to Fail Fast than continue with some invalid config (which
may lead to more severe errors such as data corruption / data loss).
Noted but, what I am trying to do with the rewrite is emit an error and
not set the value if the value found is a NULL.
If you don't set the value and continue, git will proceed with the variable's
default setting.
Which may not be too harmful in some cases, but if a user changes:
gc.pruneexpire=4.weeks.ago
to
gc.pruneexpire=4.monhts.ago
(note the typo), the next git-gc will warn the user and then happily throw
away data that the user intended to keep (default is 2.weeks.ago).
Thus I think git should die() if it encounters an invalid config setting.
Okay, point noted.
quoted
quoted
This, however, raises another issue: switching to the config cache looses
file/line-precise error reporting for semantic errors. I don't know if
this feature is important enough to do something about it, though. A
message of the form "Key 'xyz' is bad" should usually enable a user to
locate the problematic file and line.
Hmn, but during the config cache construction we parse key-value pairs through
git_config() which still warns users about semantic errors.
If I'm not mistaken you only detect _syntax_ errors when loading the file (i.e.
whether the config file is structurally correct).
The semantic value and correctness of a key (e.g. whether its a boolean or an
int or a string that denotes a known merge algorithm) is only checked when it is
accessed via git_config_get_<type>. And at this point, <file>:<line> information
is already lost.
With the callback approach, both syntactic (structure) and semantic (meaning)
errors were checked at load time, resulting in
die("bad config file line %d in %s", cf->linenr, cf->name);
if the callback returned -1.
Yup, you are right, we check only syntax error when loading the file for the cache.
I could save the <filename>:<linenr> when the loading the file for future error
reporting. Thanks.