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

Re: [PATCH] git-svn now work with crlf convertion enabled.

From
Dmitry Potapov <dpotapov@gmail.com>
Date
Aug 1, 2008, 22:09 UTC
Message-ID
<20080801220932.GK7008@dpotapov.dyndns.org>
In-Reply-To
<7vmyjwserv.fsf@gitster.siamese.dyndns.org>
On Fri, Aug 01, 2008 at 12:42:44PM -0700, Junio C Hamano wrote:
> 
> Ok, earlier I was confused who was proposing what for what purpose, but
> that one was not just "a bit hackish" but an unacceptable hack ;-)
Thanks for correct my wording ;-)
> 
> Perhaps you would want to do the s/write_object/flags/ conversion, like
> this?
Yes, it was my prefered choice to change these index_xx functions.

I have applied your patch and then corrected mine to use flags. See below.

I wonder if something should be done about other places where index_xx functions are called. I have looked at them and all they use either 0 or 1 (boolean expression which will be evaluated to 0 or 1), so they should work as is, but I can correct them to use HASH_OBJECT_DO_CREATE instead of 1 if it helps with readability.

-- 8< --
From: Dmitry Potapov <dpotapov@gmail.com>
Date: Thu, 31 Jul 2008 21:10:26 +0400
Subject: [PATCH] hash-object --no-filters

The --no-filters option makes git hash-object to work as there were no input filters. This option is useful for importers such as git-svn to put new version of files as is even if autocrlf is set.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
 Documentation/git-hash-object.txt |    6 ++++++
 hash-object.c                     |   28 +++++++++++++++-------------
 2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt
index ac928e1..69a17c7 100644
--- a/Documentation/git-hash-object.txt
+++ b/Documentation/git-hash-object.txt
@@ -35,6 +35,12 @@ OPTIONS
 --stdin-paths::
 	Read file names from stdin instead of from the command-line.
 
+--no-filters::
+	If this option is given then the file is hashed as is ignoring
+	all filters specified in the configuration, including crlf
+	conversion. If the file is read from standard input then no
+	filters is always implied.
+
 Author
 ------
 Written by Junio C Hamano <gitster@pobox.com>
diff --git a/hash-object.c b/hash-object.c
index 46c06a9..2dd7283 100644
--- a/hash-object.c
+++ b/hash-object.c
@@ -8,7 +8,7 @@
 #include "blob.h"
 #include "quote.h"
 
-static void hash_object(const char *path, enum object_type type, int write_object)
+static void hash_object(const char *path, enum object_type type, int flags)
 {
 	int fd;
 	struct stat st;
@@ -16,23 +16,23 @@ static void hash_object(const char *path, enum object_type type, int write_objec
 	fd = open(path, O_RDONLY);
 	if (fd < 0 ||
 	    fstat(fd, &st) < 0 ||
-	    index_fd(sha1, fd, &st, write_object, type, path))
-		die(write_object
+	    index_fd(sha1, fd, &st, flags, type, path))
+		die((flags & HASH_OBJECT_DO_CREATE)
 		    ? "Unable to add %s to database"
 		    : "Unable to hash %s", path);
 	printf("%s\n", sha1_to_hex(sha1));
 	maybe_flush_or_die(stdout, "hash to stdout");
 }
 
-static void hash_stdin(const char *type, int write_object)
+static void hash_stdin(const char *type, int flags)
 {
 	unsigned char sha1[20];
-	if (index_pipe(sha1, 0, type, write_object))
+	if (index_pipe(sha1, 0, type, flags))
 		die("Unable to add stdin to database");
 	printf("%s\n", sha1_to_hex(sha1));
 }
 
-static void hash_stdin_paths(const char *type, int write_objects)
+static void hash_stdin_paths(const char *type, int flags)
 {
 	struct strbuf buf, nbuf;
 
@@ -45,7 +45,7 @@ static void hash_stdin_paths(const char *type, int write_objects)
 				die("line is badly quoted");
 			strbuf_swap(&buf, &nbuf);
 		}
-		hash_object(buf.buf, type_from_string(type), write_objects);
+		hash_object(buf.buf, type_from_string(type), flags);
 	}
 	strbuf_release(&buf);
 	strbuf_release(&nbuf);
@@ -58,7 +58,7 @@ int main(int argc, char **argv)
 {
 	int i;
 	const char *type = blob_type;
-	int write_object = 0;
+	int flags = 0;
 	const char *prefix = NULL;
 	int prefix_length = -1;
 	int no_more_flags = 0;
@@ -80,7 +80,7 @@ int main(int argc, char **argv)
 					prefix_length =
 						prefix ? strlen(prefix) : 0;
 				}
-				write_object = 1;
+				flags |= HASH_OBJECT_DO_CREATE;
 			}
 			else if (!strcmp(argv[i], "--")) {
 				no_more_flags = 1;
@@ -104,6 +104,8 @@ int main(int argc, char **argv)
 					die("Multiple --stdin arguments are not supported");
 				hashstdin = 1;
 			}
+			else if (!strcmp(argv[i], "--no-filters"))
+				flags |= HASH_OBJECT_LITERALLY;
 			else
 				usage(hash_object_usage);
 		}
@@ -116,21 +118,21 @@ int main(int argc, char **argv)
 			}
 
 			if (hashstdin) {
-				hash_stdin(type, write_object);
+				hash_stdin(type, flags);
 				hashstdin = 0;
 			}
 			if (0 <= prefix_length)
 				arg = prefix_filename(prefix, prefix_length,
 						      arg);
-			hash_object(arg, type_from_string(type), write_object);
+			hash_object(arg, type_from_string(type), flags);
 			no_more_flags = 1;
 		}
 	}
 
 	if (stdin_paths)
-		hash_stdin_paths(type, write_object);
+		hash_stdin_paths(type, flags);
 
 	if (hashstdin)
-		hash_stdin(type, write_object);
+		hash_stdin(type, flags);
 	return 0;
 }
-- 
1.6.0.rc1.33.gb756f
Previous: Junio C HamanoNext: Junio C Hamano
Message 30 of 45 in “git-svn does not seems to work with crlf convertion enabled.”
  1. Alexander LitvinovJul 23, 2008
  2. Johannes SchindelinJul 23, 2008
  3. Alexander LitvinovJul 23, 2008
  4. Johannes SchindelinJul 23, 2008
  5. Avery PennarunJul 23, 2008
  6. Johannes SchindelinJul 23, 2008
  7. Alexander LitvinovJul 24, 2008
  8. Petr BaudisAug 6, 2008
  9. Peter HarrisAug 6, 2008
  10. Johannes SchindelinAug 6, 2008
  11. git-svn on MSysGit and why is it (going to be?) unsupportedPetr Baudis, Aug 6, 2008
  12. Avery PennarunAug 6, 2008
  13. Dmitry PotapovAug 6, 2008
  14. Dmitry PotapovJul 24, 2008
  15. Johannes SchindelinJul 24, 2008
  16. Avery PennarunJul 24, 2008
  17. Alexander LitvinovJul 30, 2008
  18. git-svn now work with crlf convertion enabled.Alexander Litvinov, Jul 31, 2008
  19. Alexander LitvinovJul 31, 2008
  20. Dmitry PotapovJul 31, 2008
  21. [RFC] hash-object --no-filtersDmitry Potapov, Jul 31, 2008
  22. Alexander LitvinovAug 1, 2008
  23. Junio C HamanoAug 1, 2008
  24. Dmitry PotapovAug 1, 2008
  25. Alexander LitvinovAug 1, 2008
  26. Dmitry PotapovAug 1, 2008
  27. Junio C HamanoAug 1, 2008
  28. Dmitry PotapovAug 1, 2008
  29. Junio C HamanoAug 1, 2008
  30. Dmitry PotapovAug 1, 2008
  31. Junio C HamanoAug 1, 2008
  32. Dmitry PotapovAug 1, 2008
  33. Junio C HamanoAug 2, 2008
  34. Dmitry PotapovAug 3, 2008
  35. Dmitry PotapovAug 3, 2008
  36. 1/5 correct argument checking test for git hash-objectDmitry Potapov, Aug 3, 2008
  37. 2/5 correct usage help string for git-hash-objectDmitry Potapov, Aug 3, 2008
  38. 3/5 use parse_options() in git hash-objectDmitry Potapov, Aug 3, 2008
  39. 4/5 add --path option to git hash-objectDmitry Potapov, Aug 3, 2008
  40. 5/5 add --no-filters option to git hash-objectDmitry Potapov, Aug 3, 2008
  41. Junio C HamanoAug 3, 2008
  42. Alexander LitvinovAug 1, 2008
  43. Dmitry PotapovAug 1, 2008
  44. Alexander LitvinovAug 4, 2008
  45. Eric WongAug 4, 2008

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.