Add flags to get_commit_notes() to control the format of the note string
This patch adds the following flags to get_commit_notes() for adjusting the format of the produced note string: - NOTES_SHOW_HEADER: Print "Notes:" line before the notes contents - NOTES_INDENT: Indent notes contents by 4 spaces Suggested-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									3ed24b6aaf
								
							
						
					
					
						commit
						c56fcc89b9
					
				
							
								
								
									
										8
									
								
								notes.c
								
								
								
								
							
							
						
						
									
										8
									
								
								notes.c
								
								
								
								
							|  | @ -106,7 +106,7 @@ static unsigned char *lookup_notes(const unsigned char *commit_sha1) | ||||||
| } | } | ||||||
|  |  | ||||||
| void get_commit_notes(const struct commit *commit, struct strbuf *sb, | void get_commit_notes(const struct commit *commit, struct strbuf *sb, | ||||||
| 		const char *output_encoding) | 		const char *output_encoding, int flags) | ||||||
| { | { | ||||||
| 	static const char utf8[] = "utf-8"; | 	static const char utf8[] = "utf-8"; | ||||||
| 	unsigned char *sha1; | 	unsigned char *sha1; | ||||||
|  | @ -148,12 +148,14 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb, | ||||||
| 	if (msglen && msg[msglen - 1] == '\n') | 	if (msglen && msg[msglen - 1] == '\n') | ||||||
| 		msglen--; | 		msglen--; | ||||||
|  |  | ||||||
| 	strbuf_addstr(sb, "\nNotes:\n"); | 	if (flags & NOTES_SHOW_HEADER) | ||||||
|  | 		strbuf_addstr(sb, "\nNotes:\n"); | ||||||
|  |  | ||||||
| 	for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) { | 	for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) { | ||||||
| 		linelen = strchrnul(msg_p, '\n') - msg_p; | 		linelen = strchrnul(msg_p, '\n') - msg_p; | ||||||
|  |  | ||||||
| 		strbuf_addstr(sb, "    "); | 		if (flags & NOTES_INDENT) | ||||||
|  | 			strbuf_addstr(sb, "    "); | ||||||
| 		strbuf_add(sb, msg_p, linelen); | 		strbuf_add(sb, msg_p, linelen); | ||||||
| 		strbuf_addch(sb, '\n'); | 		strbuf_addch(sb, '\n'); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
							
								
								
									
										5
									
								
								notes.h
								
								
								
								
							
							
						
						
									
										5
									
								
								notes.h
								
								
								
								
							|  | @ -1,7 +1,10 @@ | ||||||
| #ifndef NOTES_H | #ifndef NOTES_H | ||||||
| #define NOTES_H | #define NOTES_H | ||||||
|  |  | ||||||
|  | #define NOTES_SHOW_HEADER 1 | ||||||
|  | #define NOTES_INDENT 2 | ||||||
|  |  | ||||||
| void get_commit_notes(const struct commit *commit, struct strbuf *sb, | void get_commit_notes(const struct commit *commit, struct strbuf *sb, | ||||||
| 		const char *output_encoding); | 		const char *output_encoding, int flags); | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								pretty.c
								
								
								
								
							
							
						
						
									
										3
									
								
								pretty.c
								
								
								
								
							|  | @ -978,7 +978,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, | ||||||
| 		strbuf_addch(sb, '\n'); | 		strbuf_addch(sb, '\n'); | ||||||
|  |  | ||||||
| 	if (fmt != CMIT_FMT_ONELINE) | 	if (fmt != CMIT_FMT_ONELINE) | ||||||
| 		get_commit_notes(commit, sb, encoding); | 		get_commit_notes(commit, sb, encoding, | ||||||
|  | 				 NOTES_SHOW_HEADER | NOTES_INDENT); | ||||||
|  |  | ||||||
| 	free(reencoded); | 	free(reencoded); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Johan Herland
						Johan Herland