Skip to content

Commit ba9f517

Browse files
committed
Merge branch 'gs/pretty-hexval'
* gs/pretty-hexval: pretty.c: add %x00 format specifier.
2 parents 1d2375d + 42c8c74 commit ba9f517

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Documentation/pretty-formats.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,4 @@ The placeholders are:
123123
- '%Creset': reset color
124124
- '%m': left, right or boundary mark
125125
- '%n': newline
126+
- '%x00': print a byte from a hex code

log-tree.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ void show_log(struct rev_info *opt, const char *sep)
317317
if (opt->show_log_size)
318318
printf("log size %i\n", (int)msgbuf.len);
319319

320-
if (msgbuf.len)
321-
printf("%s%s%s", msgbuf.buf, extra, sep);
320+
if (msgbuf.len) {
321+
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
322+
printf("%s%s", extra, sep);
323+
}
322324
strbuf_release(&msgbuf);
323325
}
324326

pretty.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
457457
const struct commit *commit = c->commit;
458458
const char *msg = commit->buffer;
459459
struct commit_list *p;
460+
int h1, h2;
460461

461462
/* these are independent of the commit */
462463
switch (placeholder[0]) {
@@ -478,6 +479,16 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
478479
case 'n': /* newline */
479480
strbuf_addch(sb, '\n');
480481
return 1;
482+
case 'x':
483+
/* %x00 == NUL, %x0a == LF, etc. */
484+
if (0 <= (h1 = hexval_table[0xff & placeholder[1]]) &&
485+
h1 <= 16 &&
486+
0 <= (h2 = hexval_table[0xff & placeholder[2]]) &&
487+
h2 <= 16) {
488+
strbuf_addch(sb, (h1<<4)|h2);
489+
return 3;
490+
} else
491+
return 0;
481492
}
482493

483494
/* these depend on the commit */

0 commit comments

Comments
 (0)