add --no-filters option to git hash-object
The new option allows the contents to be hashed as is, ignoring any input filter that would have been chosen by the attributes mechanism. This option is incompatible with --path and --stdin-paths options. Signed-off-by: Dmitry Potapov <dpotapov@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dmitry Potapov committed
Aug 3, 2008 at 18:36 UTC
4a3d85dcf6722b7e5d16b5b1f69b51e39ad5f1dc
3 files changed
+44
-5
Documentation/git-hash-object.txt
+7
-1
@@ -9,7 +9,7 @@ git-hash-object - Compute object ID and optionally creates a blob from a file
9
SYNOPSIS
10
--------
11
[verse]
12
-'git hash-object' [-t <type>] [-w] [--path=<file>] [--stdin] [--] <file>...
12
+'git hash-object' [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>...
13
'git hash-object' [-t <type>] [-w] --stdin-paths < <list-of-paths>
14
15
DESCRIPTION
@@ -47,6 +47,12 @@ OPTIONS
47
temporary files located outside of the working directory or files
48
read from stdin.
49
50
+--no-filters::
51
+ Hash the contents as is, ignoring any input filter that would
52
+ have been chosen by the attributes mechanism, including crlf
53
+ conversion. If the file is read from standard input then this
54
+ is always implied, unless the --path option is given.
55
+
56
Author
57
------
58
Written by Junio C Hamano <gitster@pobox.com>
hash-object.c
+13
-4
@@ -52,7 +52,7 @@ static void hash_stdin_paths(const char *type, int write_objects)
52
}
53
54
static const char * const hash_object_usage[] = {
55
- "git hash-object [-t <type>] [-w] [--path=<file>] [--stdin] [--] <file>...",
55
+ "git hash-object [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>...",
56
"git hash-object --stdin-paths < <list-of-paths>",
57
NULL
58
};
@@ -61,6 +61,7 @@ static const char *type;
61
static int write_object;
62
static int hashstdin;
63
static int stdin_paths;
64
+static int no_filters;
65
static const char *vpath;
66
67
static const struct option hash_object_options[] = {
@@ -68,6 +69,7 @@ static const struct option hash_object_options[] = {
69
OPT_BOOLEAN('w', NULL, &write_object, "write the object into the object database"),
70
OPT_BOOLEAN( 0 , "stdin", &hashstdin, "read the object from stdin"),
71
OPT_BOOLEAN( 0 , "stdin-paths", &stdin_paths, "read file names from stdin"),
72
+ OPT_BOOLEAN( 0 , "no-filters", &no_filters, "store file as is without filters"),
73
OPT_STRING( 0 , "path", &vpath, "file", "process file as it were from this path"),
74
OPT_END()
75
};
@@ -99,9 +101,15 @@ int main(int argc, const char **argv)
101
errstr = "Can't specify files with --stdin-paths";
102
else if (vpath)
103
errstr = "Can't use --stdin-paths with --path";
104
+ else if (no_filters)
105
+ errstr = "Can't use --stdin-paths with --no-filters";
106
+ }
107
+ else {
108
+ if (hashstdin > 1)
109
+ errstr = "Multiple --stdin arguments are not supported";
110
+ if (vpath && no_filters)
111
+ errstr = "Can't use --path with --no-filters";
112
}
103
- else if (hashstdin > 1)
104
- errstr = "Multiple --stdin arguments are not supported";
113
114
if (errstr) {
115
error (errstr);
@@ -116,7 +124,8 @@ int main(int argc, const char **argv)
124
125
if (0 <= prefix_length)
126
arg = prefix_filename(prefix, prefix_length, arg);
119
- hash_object(arg, type, write_object, vpath ? vpath : arg);
127
+ hash_object(arg, type, write_object,
128
+ no_filters ? NULL : vpath ? vpath : arg);
129
}
130
131
if (stdin_paths)
t/t1007-hash-object.sh
+24
@@ -65,6 +65,14 @@ test_expect_success "Can't use --path with --stdin-paths" '
65
echo example | test_must_fail git hash-object --stdin-paths --path=foo
66
'
67
68
+test_expect_success "Can't use --stdin-paths with --no-filters" '
69
+ echo example | test_must_fail git hash-object --stdin-paths --no-filters
70
+'
71
+
72
+test_expect_success "Can't use --path with --no-filters" '
73
+ test_must_fail git hash-object --no-filters --path=foo
74
+'
75
+
76
# Behavior
77
78
push_repo
@@ -117,6 +125,22 @@ test_expect_success 'check that appropriate filter is invoke when --path is used
125
git config --unset core.autocrlf
126
'
127
128
+test_expect_success 'check that --no-filters option works' '
129
+ echo fooQ | tr Q "\\015" >file0 &&
130
+ cp file0 file1 &&
131
+ echo "file0 -crlf" >.gitattributes &&
132
+ echo "file1 crlf" >>.gitattributes &&
133
+ git config core.autocrlf true &&
134
+ file0_sha=$(git hash-object file0) &&
135
+ file1_sha=$(git hash-object file1) &&
136
+ test "$file0_sha" != "$file1_sha" &&
137
+ nofilters_file1=$(git hash-object --no-filters file1) &&
138
+ test "$file0_sha" = "$nofilters_file1" &&
139
+ nofilters_file1=$(cat file1 | git hash-object --stdin) &&
140
+ test "$file0_sha" = "$nofilters_file1" &&
141
+ git config --unset core.autocrlf
142
+'
143
+
144
pop_repo
145
146
for args in "-w --stdin" "--stdin -w"; do