Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
blame: factor out get_next_line()
author
René Scharfe
<l.s.r@web.de>
Fri, 13 Jun 2014 19:53:03 +0000
(21:53 +0200)
committer
Junio C Hamano
<gitster@pobox.com>
Fri, 13 Jun 2014 21:52:16 +0000
(14:52 -0700)
Move the code for finding the start of the next line into a helper
function in order to reduce duplication.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/blame.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
e156455
)
diff --git
a/builtin/blame.c
b/builtin/blame.c
index 88cb7997274de6f9ab6f8a5944748334ce605f60..f685b38a2f173432fc83a9e743ca1112f0091523 100644
(file)
--- a/
builtin/blame.c
+++ b/
builtin/blame.c
@@
-1741,6
+1741,12
@@
static void output(struct scoreboard *sb, int option)
}
}
}
}
+static const char *get_next_line(const char *start, const char *end)
+{
+ const char *nl = memchr(start, '\n', end - start);
+ return nl ? nl + 1 : NULL;
+}
+
/*
* To allow quick access to the contents of nth line in the
* final image, prepare an index in the scoreboard.
/*
* To allow quick access to the contents of nth line in the
* final image, prepare an index in the scoreboard.
@@
-1754,15
+1760,8
@@
static int prepare_lines(struct scoreboard *sb)
int *lineno;
int num = 0, incomplete = 0;
int *lineno;
int num = 0, incomplete = 0;
- for (p = buf;;) {
- p = memchr(p, '\n', end - p);
- if (p) {
- p++;
- num++;
- continue;
- }
- break;
- }
+ for (p = get_next_line(buf, end); p; p = get_next_line(p, end))
+ num++;
if (len && end[-1] != '\n')
incomplete++; /* incomplete line at the end */
if (len && end[-1] != '\n')
incomplete++; /* incomplete line at the end */
@@
-1771,15
+1770,8
@@
static int prepare_lines(struct scoreboard *sb)
lineno = sb->lineno;
*lineno++ = 0;
lineno = sb->lineno;
*lineno++ = 0;
- for (p = buf;;) {
- p = memchr(p, '\n', end - p);
- if (p) {
- p++;
- *lineno++ = p - buf;
- continue;
- }
- break;
- }
+ for (p = get_next_line(buf, end); p; p = get_next_line(p, end))
+ *lineno++ = p - buf;
if (incomplete)
*lineno++ = len;
if (incomplete)
*lineno++ = len;