Skip to content

Commit f710fd7

Browse files
peffgitster
authored andcommitted
hash-object: handle --literally with OPT_NEGBIT
Since we recently removed the hash_literally() function, the hash-object --literally option has been simplified to just removing the INDEX_FORMAT_CHECK flag. Rather than pass it around as a separate bool, we can just have the option parser remove the bit from the set of flags directly. This simplifies the helper functions. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 931e5ca commit f710fd7

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

builtin/hash-object.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919
#include "strbuf.h"
2020
#include "write-or-die.h"
2121

22-
static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
23-
int literally)
22+
static void hash_fd(int fd, const char *type, const char *path, unsigned flags)
2423
{
2524
struct stat st;
2625
struct object_id oid;
2726

28-
if (literally)
29-
flags &= ~INDEX_FORMAT_CHECK;
30-
3127
if (fstat(fd, &st) < 0 ||
3228
index_fd(the_repository->index, &oid, fd, &st,
3329
type_from_string(type), path, flags))
@@ -39,15 +35,14 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
3935
}
4036

4137
static void hash_object(const char *path, const char *type, const char *vpath,
42-
unsigned flags, int literally)
38+
unsigned flags)
4339
{
4440
int fd;
4541
fd = xopen(path, O_RDONLY);
46-
hash_fd(fd, type, vpath, flags, literally);
42+
hash_fd(fd, type, vpath, flags);
4743
}
4844

49-
static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
50-
int literally)
45+
static void hash_stdin_paths(const char *type, int no_filters, unsigned flags)
5146
{
5247
struct strbuf buf = STRBUF_INIT;
5348
struct strbuf unquoted = STRBUF_INIT;
@@ -59,8 +54,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
5954
die("line is badly quoted");
6055
strbuf_swap(&buf, &unquoted);
6156
}
62-
hash_object(buf.buf, type, no_filters ? NULL : buf.buf, flags,
63-
literally);
57+
hash_object(buf.buf, type, no_filters ? NULL : buf.buf, flags);
6458
}
6559
strbuf_release(&buf);
6660
strbuf_release(&unquoted);
@@ -81,7 +75,6 @@ int cmd_hash_object(int argc,
8175
int hashstdin = 0;
8276
int stdin_paths = 0;
8377
int no_filters = 0;
84-
int literally = 0;
8578
int nongit = 0;
8679
unsigned flags = INDEX_FORMAT_CHECK;
8780
const char *vpath = NULL;
@@ -93,7 +86,9 @@ int cmd_hash_object(int argc,
9386
OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")),
9487
OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")),
9588
OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")),
96-
OPT_BOOL( 0, "literally", &literally, N_("just hash any random garbage to create corrupt objects for debugging Git")),
89+
OPT_NEGBIT( 0, "literally", &flags,
90+
N_("just hash any random garbage to create corrupt objects for debugging Git"),
91+
INDEX_FORMAT_CHECK),
9792
OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")),
9893
OPT_END()
9994
};
@@ -139,7 +134,7 @@ int cmd_hash_object(int argc,
139134
}
140135

141136
if (hashstdin)
142-
hash_fd(0, type, vpath, flags, literally);
137+
hash_fd(0, type, vpath, flags);
143138

144139
for (i = 0 ; i < argc; i++) {
145140
const char *arg = argv[i];
@@ -148,12 +143,12 @@ int cmd_hash_object(int argc,
148143
if (prefix)
149144
arg = to_free = prefix_filename(prefix, arg);
150145
hash_object(arg, type, no_filters ? NULL : vpath ? vpath : arg,
151-
flags, literally);
146+
flags);
152147
free(to_free);
153148
}
154149

155150
if (stdin_paths)
156-
hash_stdin_paths(type, no_filters, flags, literally);
151+
hash_stdin_paths(type, no_filters, flags);
157152

158153
free(vpath_free);
159154

0 commit comments

Comments
 (0)