git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] diff: make treatment of missing EOL at EOF configurable

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Jun 3, 2010, 14:35 UTC
Message-ID
<77f4ffc1e89c4a5e34c74882dcf4761b486f5b48.1275575236.git.git@drmicha.warpmail.net>
In-Reply-To
<cover.1275575236.git.git@drmicha.warpmail.net>

Make this one of the WS_* flags so that we can later turn the warning for missing EOL at EOF on and off as per config or blob type.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 cache.h |    3 ++-
 diff.c  |    5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index c966023..dc72b8f 100644
--- a/cache.h
+++ b/cache.h
@@ -1048,8 +1048,9 @@ void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *
 #define WS_CR_AT_EOL           010
 #define WS_BLANK_AT_EOF        020
 #define WS_TAB_IN_INDENT       040
+#define WS_NO_EOL_AT_EOF      0100
 #define WS_TRAILING_SPACE      (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)
-#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB)
+#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB|WS_NO_EOL_AT_EOF)
 extern unsigned whitespace_rule_cfg;
 extern unsigned whitespace_rule(const char *);
 extern unsigned parse_whitespace_rule(const char *);
diff --git a/diff.c b/diff.c
index ff44bcc..7950df6 100644
--- a/diff.c
+++ b/diff.c
@@ -455,7 +455,7 @@ static void emit_rewrite_lines(struct emit_callback *ecb,
 		size -= len;
 		data += len;
 	}
-	if (!endp) {
+	if (!endp && (ecb->ws_rule & WS_NO_EOL_AT_EOF)) {
 		const char *plain = diff_get_color(ecb->color_diff,
 						   DIFF_PLAIN);
 		emit_line_0(ecb->file, plain, reset, '\\',
@@ -918,7 +918,8 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
 		emit_add_line(reset, ecbdata, line + 1, len - 1);
 	}
 	if (line[len-1] != '\n')
-		fputs("\n\\ No newline at end of file\n", ecbdata->file);
+		fputs((ecbdata->ws_rule & WS_NO_EOL_AT_EOF)
+			? "\n\\ No newline at end of file\n" : "\n", ecbdata->file);
 }
 
 static char *pprint_rename(const char *a, const char *b)
-- 
1.7.1.351.ge2633e
Previous: Michael J GruberNext: Michael J Gruber
Message 12 of 22 in “Don't warn about missing EOL for symlinks”
  1. 0/4 Don't warn about missing EOL for symlinksMichael J Gruber, Jun 3, 2010
  2. 1/4 diff/xdiff: refactor EOF-EOL detectionMichael J Gruber, Jun 3, 2010
  3. Junio C HamanoJun 3, 2010
  4. Michael J GruberJun 4, 2010
  5. Junio C HamanoJun 5, 2010
  6. Michael J GruberJun 5, 2010
  7. Jeff KingJun 6, 2010
  8. Junio C HamanoJun 6, 2010
  9. Johannes SixtJun 6, 2010
  10. Jeff KingJun 6, 2010
  11. Michael J GruberJun 7, 2010
  12. 2/4 diff: make treatment of missing EOL at EOF configurableMichael J Gruber, Jun 3, 2010
  13. 3/4 diff: Do not warn about missing EOL at EOF for symlinksMichael J Gruber, Jun 3, 2010
  14. Jeff KingJun 3, 2010
  15. 4/4 RFC: add whitespace rule for no-eol-at-eofMichael J Gruber, Jun 3, 2010
  16. Matthieu MoyJun 3, 2010
  17. Michael J GruberJun 3, 2010
  18. Jeff KingJun 3, 2010
  19. Michael J GruberJun 3, 2010
  20. Jeff KingJun 3, 2010
  21. Johannes SixtJun 4, 2010
  22. Jeff KingJun 4, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.