Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
read_packed_refs: pass strbuf to parse_ref_line
author
Jeff King
<peff@peff.net>
Wed, 10 Dec 2014 10:40:19 +0000
(
05:40
-0500)
committer
Junio C Hamano
<gitster@pobox.com>
Wed, 10 Dec 2014 17:28:54 +0000
(09:28 -0800)
Now that we have a strbuf in read_packed_refs, we can pass
it straight to the line parser, which saves us an extra
strlen.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
10c497a
)
diff --git
a/refs.c
b/refs.c
index 60a7e33d5b1bad9000d2a230eac09190fa858c85..047353ea1ff63daaeb04475d05515fb9bbbe7c39 100644
(file)
--- a/
refs.c
+++ b/
refs.c
@@
-973,8
+973,10
@@
static const char PACKED_REFS_HEADER[] =
* Return a pointer to the refname within the line (null-terminated),
* or NULL if there was a problem.
*/
* Return a pointer to the refname within the line (null-terminated),
* or NULL if there was a problem.
*/
-static const char *parse_ref_line(
char
*line, unsigned char *sha1)
+static const char *parse_ref_line(
struct strbuf
*line, unsigned char *sha1)
{
{
+ const char *ref;
+
/*
* 42: the answer to everything.
*
/*
* 42: the answer to everything.
*
@@
-983,22
+985,23
@@
static const char *parse_ref_line(char *line, unsigned char *sha1)
* +1 (space in between hex and name)
* +1 (newline at the end of the line)
*/
* +1 (space in between hex and name)
* +1 (newline at the end of the line)
*/
- int len = strlen(line) - 42;
-
- if (len <= 0)
+ if (line->len <= 42)
return NULL;
return NULL;
- if (get_sha1_hex(line, sha1) < 0)
+
+ if (get_sha1_hex(line->buf, sha1) < 0)
return NULL;
return NULL;
- if (!isspace(line[40]))
+ if (!isspace(line
->buf
[40]))
return NULL;
return NULL;
- line += 41;
- if (isspace(*line))
+
+ ref = line->buf + 41;
+ if (isspace(*ref))
return NULL;
return NULL;
- if (line[len] != '\n')
+
+ if (line->buf[line->len - 1] != '\n')
return NULL;
return NULL;
- line
[
len] = 0;
+ line
->buf[--line->
len] = 0;
- return
line
;
+ return
ref
;
}
/*
}
/*
@@
-1049,7
+1052,7
@@
static void read_packed_refs(FILE *f, struct ref_dir *dir)
continue;
}
continue;
}
- refname = parse_ref_line(
line.buf
, sha1);
+ refname = parse_ref_line(
&line
, sha1);
if (refname) {
last = create_ref_entry(refname, sha1, REF_ISPACKED, 1);
if (peeled == PEELED_FULLY ||
if (refname) {
last = create_ref_entry(refname, sha1, REF_ISPACKED, 1);
if (peeled == PEELED_FULLY ||