Skip to content

Commit 37ec2b4

Browse files
committed
Merge branch 'rs/pretty'
* rs/pretty: Fix preprocessor logic that determines the availablity of strchrnul(). Simplify strchrnul() compat code --format=pretty: avoid calculating expensive expansions twice add strbuf_adddup() --pretty=format: parse commit message only once --pretty=format: on-demand format expansion Add strchrnul()
2 parents 4356736 + 726c8ef commit 37ec2b4

File tree

5 files changed

+284
-135
lines changed

5 files changed

+284
-135
lines changed

builtin-fetch--tool.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu
435435
cp++;
436436
if (!*cp)
437437
break;
438-
np = strchr(cp, '\n');
439-
if (!np)
440-
np = cp + strlen(cp);
438+
np = strchrnul(cp, '\n');
441439
if (pass) {
442440
lrr_list[i].line = cp;
443441
lrr_list[i].name = cp + 41;
@@ -461,9 +459,7 @@ static int pick_rref(int sha1_only, const char *rref, const char *ls_remote_resu
461459
rref++;
462460
if (!*rref)
463461
break;
464-
next = strchr(rref, '\n');
465-
if (!next)
466-
next = rref + strlen(rref);
462+
next = strchrnul(rref, '\n');
467463
rreflen = next - rref;
468464

469465
for (i = 0; i < lrr_count; i++) {

git-compat-util.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ void *gitmemmem(const void *haystack, size_t haystacklen,
183183
const void *needle, size_t needlelen);
184184
#endif
185185

186+
#ifdef __GLIBC_PREREQ
187+
#if __GLIBC_PREREQ(2, 1)
188+
#define HAVE_STRCHRNUL
189+
#endif
190+
#endif
191+
192+
#ifndef HAVE_STRCHRNUL
193+
#define strchrnul gitstrchrnul
194+
static inline char *gitstrchrnul(const char *s, int c)
195+
{
196+
while (*s && *s != c)
197+
s++;
198+
return (char *)s;
199+
}
200+
#endif
201+
186202
extern void release_pack_memory(size_t, int);
187203

188204
static inline char* xstrdup(const char *str)

0 commit comments

Comments
 (0)