git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: git@vger.kernel.org
Subject: Add comment lines to patch format
Date: Fri, 18 May 2012 20:22:28 +0700	[thread overview]
Message-ID: <20120518132228.GA27970@do> (raw)

Hi,

This is just an idea to help spot subtle changes in patch form
(e.g. visible over email). A line starting with '=' (or something
else) is treated like a comment line and ignored by "git apply". We
could use this line to mark special things in the previous line.

One thing is trailing space, like demonstrated in the patch below,
because trailing spaces may be intentional sometimes. But I'd like to
incorporate some word-diff goodness in patch format using this comment
line to spot few/single character addition/removal.

For example, instead of showing

-  "this is a  string"
+  N_("this is a string")

we could show

-  "this is a  string"
=  ..... .. . ^.......
+  N_("this is a string")
=  ^^^..... .. . .......^

If anyone knows a tool with similar feature, I'd greatly appreciate it
(as the Internet taught me, everything I think of is already thought
of/implemented by someone)

-- 8< --
diff --git a/diff.c b/diff.c
index 77edd50..09d8c19 100644
--- a/diff.c
+++ b/diff.c
@@ -1110,6 +1110,30 @@ static void find_lno(const char *line, struct emit_callback *ecbdata)
 	ecbdata->lno_in_postimage = strtol(p + 1, NULL, 10);
 }
 
+static void annotate_line(struct emit_callback *ecbdata,
+			  const char *line, unsigned long len)
+{
+	char *buf, *s;
+	int trailing = 1;
+	if (!isspace(line[len-2]))   
=	.. .......................^^^
+		return;
+	buf = malloc(len);
+	memcpy(buf, line, len);
+	buf[0] = '=';
+	for (s = buf + len - 2; s > buf; s--) {
+		if (trailing && isspace(*s))
+			*s = '^';
+		else
+			trailing = 0;
+		if (!trailing && !isspace(*s))
+			*s = '.';
+	}
+	emit_line(ecbdata->opt,
+		  diff_get_color(ecbdata->color_diff, DIFF_PLAIN),
+		  diff_get_color(ecbdata->color_diff, DIFF_RESET), buf, len);
+	free(buf);
+}
+
 static void fn_out_consume(void *priv, char *line, unsigned long len)
 {
 	struct emit_callback *ecbdata = priv;
@@ -1208,17 +1232,26 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 		return;
 	}
 
-	if (line[0] != '+') {
-		const char *color =
-			diff_get_color(ecbdata->color_diff,
-				       line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);
+	switch (line[0]) {
+	case '-':
 		ecbdata->lno_in_preimage++;
-		if (line[0] == ' ')
-			ecbdata->lno_in_postimage++;
-		emit_line(ecbdata->opt, color, reset, line, len);
-	} else {
+		emit_line(ecbdata->opt,
+			  diff_get_color(ecbdata->color_diff, DIFF_FILE_OLD),
+			  reset, line, len);
+		annotate_line(ecbdata, line, len);
+		break;
+	case '+':
 		ecbdata->lno_in_postimage++;
 		emit_add_line(reset, ecbdata, line + 1, len - 1);
+		annotate_line(ecbdata, line, len);
+		break;
+	case ' ':
+		ecbdata->lno_in_preimage++;
+			ecbdata->lno_in_postimage++;
+		emit_line(ecbdata->opt, plain, reset, line, len);
+		break;
+	default:
+		die("huh? a diff line starting with '%c'??", line[0]);
 	}
 }
 
-- 8< --
-- 
Duy

-- 
Duy

             reply	other threads:[~2012-05-18 13:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-18 13:22 Nguyen Thai Ngoc Duy [this message]
2012-05-18 15:30 ` Add comment lines to patch format Junio C Hamano
2012-05-19  4:50   ` Nguyen Thai Ngoc Duy
2012-05-19  0:14 ` Jeff King
2012-05-19  4:54   ` Nguyen Thai Ngoc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120518132228.GA27970@do \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).