[PATCHv2 8/8] reflog: use parse_config_key in config callback

2013-01-22 Thread Jeff King
This doesn't save any lines, but does keep us from doing
error-prone pointer arithmetic with constants.

Signed-off-by: Jeff King p...@peff.net
---
 builtin/reflog.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index b3c9e27..1fedf66 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -510,26 +510,27 @@ static int reflog_expire_config(const char *var, const 
char *value, void *cb)
 
 static int reflog_expire_config(const char *var, const char *value, void *cb)
 {
-   const char *lastdot = strrchr(var, '.');
+   const char *pattern, *key;
+   int pattern_len;
unsigned long expire;
int slot;
struct reflog_expire_cfg *ent;
 
-   if (!lastdot || prefixcmp(var, gc.))
+   if (parse_config_key(var, gc, pattern, pattern_len, key)  0)
return git_default_config(var, value, cb);
 
-   if (!strcmp(lastdot, .reflogexpire)) {
+   if (!strcmp(key, reflogexpire)) {
slot = EXPIRE_TOTAL;
if (parse_expire_cfg_value(var, value, expire))
return -1;
-   } else if (!strcmp(lastdot, .reflogexpireunreachable)) {
+   } else if (!strcmp(key, reflogexpireunreachable)) {
slot = EXPIRE_UNREACH;
if (parse_expire_cfg_value(var, value, expire))
return -1;
} else
return git_default_config(var, value, cb);
 
-   if (lastdot == var + 2) {
+   if (!pattern) {
switch (slot) {
case EXPIRE_TOTAL:
default_reflog_expire = expire;
@@ -541,7 +542,7 @@ static int reflog_expire_config(const char *var, const char 
*value, void *cb)
return 0;
}
 
-   ent = find_cfg_ent(var + 3, lastdot - (var+3));
+   ent = find_cfg_ent(pattern, pattern_len);
if (!ent)
return -1;
switch (slot) {
-- 
1.8.0.2.15.g815dc66
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2 8/8] reflog: use parse_config_key in config callback

2013-01-22 Thread Junio C Hamano
Jeff King p...@peff.net writes:

 This doesn't save any lines, but does keep us from doing
 error-prone pointer arithmetic with constants.

Yeah, this and 7/8 shows that the true value of the new parse
function is not line number reduction but clarity of the calling
code.  There is really no point making everybody implement last_dot
is there, so the subsection name must be between the section name
and that last_dot like the original before this patch.

Thanks.  Will read it over again and then apply.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html