Skip to content

Commit 931e5ca

Browse files
peffgitster
authored andcommitted
hash-object: merge HASH_* and INDEX_* flags
The hash-object command has its own custom flag bits that it sets based on command-line options. But since we dropped hash_literally() in the previous commit, the only thing we do with those flag bits is convert them directly into "index_flags" to pass to index_fd(). This extra layer of indirection makes the code harder to read and reason about. Let's just use the INDEX_* flags directly. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 65a6a79 commit 931e5ca

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

builtin/hash-object.c

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

22-
enum {
23-
HASH_OBJECT_CHECK = (1 << 0),
24-
HASH_OBJECT_WRITE = (1 << 1),
25-
};
26-
2722
static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
2823
int literally)
2924
{
30-
unsigned int index_flags = 0;
3125
struct stat st;
3226
struct object_id oid;
3327

34-
if (flags & HASH_OBJECT_WRITE)
35-
index_flags |= INDEX_WRITE_OBJECT;
36-
if (flags & HASH_OBJECT_CHECK)
37-
index_flags |= INDEX_FORMAT_CHECK;
38-
3928
if (literally)
40-
index_flags &= ~INDEX_FORMAT_CHECK;
29+
flags &= ~INDEX_FORMAT_CHECK;
4130

4231
if (fstat(fd, &st) < 0 ||
4332
index_fd(the_repository->index, &oid, fd, &st,
44-
type_from_string(type), path, index_flags))
45-
die((flags & HASH_OBJECT_WRITE)
33+
type_from_string(type), path, flags))
34+
die((flags & INDEX_WRITE_OBJECT)
4635
? "Unable to add %s to database"
4736
: "Unable to hash %s", path);
4837
printf("%s\n", oid_to_hex(&oid));
@@ -94,13 +83,13 @@ int cmd_hash_object(int argc,
9483
int no_filters = 0;
9584
int literally = 0;
9685
int nongit = 0;
97-
unsigned flags = HASH_OBJECT_CHECK;
86+
unsigned flags = INDEX_FORMAT_CHECK;
9887
const char *vpath = NULL;
9988
char *vpath_free = NULL;
10089
const struct option hash_object_options[] = {
10190
OPT_STRING('t', NULL, &type, N_("type"), N_("object type")),
10291
OPT_BIT('w', NULL, &flags, N_("write the object into the object database"),
103-
HASH_OBJECT_WRITE),
92+
INDEX_WRITE_OBJECT),
10493
OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")),
10594
OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")),
10695
OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")),
@@ -114,7 +103,7 @@ int cmd_hash_object(int argc,
114103
argc = parse_options(argc, argv, prefix, hash_object_options,
115104
hash_object_usage, 0);
116105

117-
if (flags & HASH_OBJECT_WRITE)
106+
if (flags & INDEX_WRITE_OBJECT)
118107
prefix = setup_git_directory();
119108
else
120109
prefix = setup_git_directory_gently(&nongit);

0 commit comments

Comments
 (0)