[PATCH] --pretty=gnucl: avoid line wrapping before the comma

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Earlier, this code played dumb by outputting the file name and the comma
separately (to make it easier to determine when to output a colon
instead of the comma). This misguided code is fixed by this patch.

Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx>
---

	I know that this is a dead topic branch, but I did not want
	to leave buggy code behind for future reference.

 diff.c |   60 ++++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/diff.c b/diff.c
index 9f9cb34..d33242a 100644
--- a/diff.c
+++ b/diff.c
@@ -1851,52 +1851,64 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o)
 
 struct changelog_t {
 	int offset, seen_first;
+	char buffer[1024];
 };
 
+static void flush_changelog_file_entry(struct changelog_t *log, char delim) {
+	if (!log->seen_first) {
+		log->offset = print_wrapped_text("* ", -CHANGELOG_TAB_SIZE,
+				CHANGELOG_TAB_SIZE + 2, CHANGELOG_WIDTH);
+		log->seen_first = 1;
+	}
+
+	if (log->buffer[0]) {
+		int len = strlen(log->buffer);
+		if (len + 3 < sizeof(log->buffer)) {
+			log->buffer[len++] = delim;
+			log->buffer[len++] = ' ';
+			log->buffer[len++] = '\0';
+		} else
+			warn("Line too long: skipping delimiter");
+
+		log->offset = print_wrapped_text(log->buffer, -log->offset,
+				CHANGELOG_TAB_SIZE + 2, CHANGELOG_WIDTH);
+		log->buffer[0] = '\0';
+	}
+}
+
 static void run_changelog(struct diff_filepair *p, struct diff_options *o,
-	struct changelog_t *changelog)
+	struct changelog_t *log)
 {
 	const char *name;
 	const char *other;
-	static char buffer[1024];
 
 	if (DIFF_PAIR_UNMERGED(p)) {
 		/* unmerged */
 		return;
 	}
 
-	if (changelog->seen_first)
-		buffer[0] = ',';
-	else {
-		buffer[0] = '*';
-		changelog->offset = -CHANGELOG_TAB_SIZE;
-		changelog->seen_first = 1;
-	}
-
 	name = p->one->path;
 	other = p->two->path;
 
-	if (!name) {
-		if (!other)
-			return;
-		snprintf(buffer + 1, sizeof(buffer) - 1, " %s", other);
-	} else if (!other || !strcmp(name, other))
-		snprintf(buffer + 1, sizeof(buffer) - 1, " %s", name);
+	if (!name && !other)
+		return;
+
+	flush_changelog_file_entry(log, ',');
+	if (!name)
+		snprintf(log->buffer, sizeof(log->buffer), "%s", other);
+	else if (!other || !strcmp(name, other))
+		snprintf(log->buffer, sizeof(log->buffer), "%s", name);
 	else
-		snprintf(buffer + 1, sizeof(buffer) - 1, " %s => %s",
+		snprintf(log->buffer, sizeof(log->buffer), "%s => %s",
 				name, other);
-	changelog->offset = print_wrapped_text(buffer, -changelog->offset,
-		CHANGELOG_TAB_SIZE + 2, CHANGELOG_WIDTH);
 }
 
 static void finalize_changelog(struct diff_options *options,
 		struct changelog_t *changelog)
 {
-	if (!options->stat_sep)
-		return;
-	changelog->offset = print_wrapped_text(": ", -changelog->offset,
-		CHANGELOG_TAB_SIZE + 2, CHANGELOG_WIDTH);
-	changelog->offset = print_wrapped_text(options->stat_sep,
+	flush_changelog_file_entry(changelog, ':');
+	changelog->offset = print_wrapped_text(options->stat_sep ?
+			options->stat_sep : "*** empty message ***",
 			-changelog->offset,
 			CHANGELOG_TAB_SIZE + 2, CHANGELOG_WIDTH);
 }
-- 
1.5.0.2.780.g57e5-dirty


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]