Skip to content

Commit 17d9dbd

Browse files
committed
Merge branch 'jk/no-funny-object-types'
Support to create a loose object file with unknown object type has been dropped. * jk/no-funny-object-types: object-file: drop support for writing objects with unknown types hash-object: handle --literally with OPT_NEGBIT hash-object: merge HASH_* and INDEX_* flags hash-object: stop allowing unknown types t: add lib-loose.sh t/helper: add zlib test-tool oid_object_info(): drop type_name strbuf fsck: stop using object_info->type_name strbuf oid_object_info_convert(): stop using string for object type cat-file: use type enum instead of buffer for -t option object-file: drop OBJECT_INFO_ALLOW_UNKNOWN_TYPE flag cat-file: make --allow-unknown-type a noop object-file.h: fix typo in variable declaration
2 parents b6fa7fb + 141f8c8 commit 17d9dbd

20 files changed

+220
-447
lines changed

Documentation/git-cat-file.adoc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
'git cat-file' <type> <object>
12-
'git cat-file' (-e | -p) <object>
13-
'git cat-file' (-t | -s) [--allow-unknown-type] <object>
12+
'git cat-file' (-e | -p | -t | -s) <object>
1413
'git cat-file' (--textconv | --filters)
1514
[<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]
1615
'git cat-file' (--batch | --batch-check | --batch-command) [--batch-all-objects]
@@ -202,9 +201,6 @@ flush::
202201
only once, even if it is stored multiple times in the
203202
repository.
204203

205-
--allow-unknown-type::
206-
Allow `-s` or `-t` to query broken/corrupt objects of unknown type.
207-
208204
--follow-symlinks::
209205
With `--batch` or `--batch-check`, follow symlinks inside the
210206
repository when requesting objects with extended SHA-1

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ TEST_BUILTINS_OBJS += test-wildmatch.o
859859
TEST_BUILTINS_OBJS += test-windows-named-pipe.o
860860
TEST_BUILTINS_OBJS += test-write-cache.o
861861
TEST_BUILTINS_OBJS += test-xml-encode.o
862+
TEST_BUILTINS_OBJS += test-zlib.o
862863

863864
# Do not add more tests here unless they have extra dependencies. Add
864865
# them in TEST_BUILTINS_OBJS above.

builtin/cat-file.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ static int stream_blob(const struct object_id *oid)
100100
return 0;
101101
}
102102

103-
static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
104-
int unknown_type)
103+
static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
105104
{
106105
int ret;
107106
struct object_id oid;
@@ -110,7 +109,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
110109
unsigned long size;
111110
struct object_context obj_context = {0};
112111
struct object_info oi = OBJECT_INFO_INIT;
113-
struct strbuf sb = STRBUF_INIT;
114112
unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
115113
unsigned get_oid_flags =
116114
GET_OID_RECORD_PATH |
@@ -121,9 +119,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
121119
if (!path && opt_cw)
122120
get_oid_flags |= GET_OID_REQUIRE_PATH;
123121

124-
if (unknown_type)
125-
flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
126-
127122
if (get_oid_with_context(the_repository, obj_name, get_oid_flags, &oid,
128123
&obj_context))
129124
die("Not a valid object name %s", obj_name);
@@ -136,16 +131,12 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
136131
buf = NULL;
137132
switch (opt) {
138133
case 't':
139-
oi.type_name = &sb;
134+
oi.typep = &type;
140135
if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
141136
die("git cat-file: could not get object info");
142-
if (sb.len) {
143-
printf("%s\n", sb.buf);
144-
strbuf_release(&sb);
145-
ret = 0;
146-
goto cleanup;
147-
}
148-
break;
137+
printf("%s\n", type_name(type));
138+
ret = 0;
139+
goto cleanup;
149140

150141
case 's':
151142
oi.sizep = &size;
@@ -1038,8 +1029,7 @@ int cmd_cat_file(int argc,
10381029

10391030
const char * const builtin_catfile_usage[] = {
10401031
N_("git cat-file <type> <object>"),
1041-
N_("git cat-file (-e | -p) <object>"),
1042-
N_("git cat-file (-t | -s) [--allow-unknown-type] <object>"),
1032+
N_("git cat-file (-e | -p | -t | -s) <object>"),
10431033
N_("git cat-file (--textconv | --filters)\n"
10441034
" [<rev>:<path|tree-ish> | --path=<path|tree-ish> <rev>]"),
10451035
N_("git cat-file (--batch | --batch-check | --batch-command) [--batch-all-objects]\n"
@@ -1057,8 +1047,8 @@ int cmd_cat_file(int argc,
10571047
OPT_GROUP(N_("Emit [broken] object attributes")),
10581048
OPT_CMDMODE('t', NULL, &opt, N_("show object type (one of 'blob', 'tree', 'commit', 'tag', ...)"), 't'),
10591049
OPT_CMDMODE('s', NULL, &opt, N_("show object size"), 's'),
1060-
OPT_BOOL(0, "allow-unknown-type", &unknown_type,
1061-
N_("allow -s and -t to work with broken/corrupt objects")),
1050+
OPT_HIDDEN_BOOL(0, "allow-unknown-type", &unknown_type,
1051+
N_("historical option -- no-op")),
10621052
OPT_BOOL(0, "use-mailmap", &use_mailmap, N_("use mail map file")),
10631053
OPT_ALIAS(0, "mailmap", "use-mailmap"),
10641054
/* Batch mode */
@@ -1209,10 +1199,7 @@ int cmd_cat_file(int argc,
12091199
obj_name = argv[1];
12101200
}
12111201

1212-
if (unknown_type && opt != 't' && opt != 's')
1213-
die("git cat-file --allow-unknown-type: use with -s or -t");
1214-
1215-
ret = cat_one_file(opt, exp_type, obj_name, unknown_type);
1202+
ret = cat_one_file(opt, exp_type, obj_name);
12161203

12171204
out:
12181205
list_objects_filter_release(&batch.objects_filter);

builtin/fsck.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,11 @@ static void get_default_heads(void)
614614
struct for_each_loose_cb
615615
{
616616
struct progress *progress;
617-
struct strbuf obj_type;
618617
};
619618

620-
static int fsck_loose(const struct object_id *oid, const char *path, void *data)
619+
static int fsck_loose(const struct object_id *oid, const char *path,
620+
void *data UNUSED)
621621
{
622-
struct for_each_loose_cb *cb_data = data;
623622
struct object *obj;
624623
enum object_type type = OBJ_NONE;
625624
unsigned long size;
@@ -629,8 +628,6 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
629628
struct object_id real_oid = *null_oid(the_hash_algo);
630629
int err = 0;
631630

632-
strbuf_reset(&cb_data->obj_type);
633-
oi.type_name = &cb_data->obj_type;
634631
oi.sizep = &size;
635632
oi.typep = &type;
636633

@@ -642,10 +639,6 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
642639
err = error(_("%s: object corrupt or missing: %s"),
643640
oid_to_hex(oid), path);
644641
}
645-
if (type != OBJ_NONE && type < 0)
646-
err = error(_("%s: object is of unknown type '%s': %s"),
647-
oid_to_hex(&real_oid), cb_data->obj_type.buf,
648-
path);
649642
if (err < 0) {
650643
errors_found |= ERROR_OBJECT;
651644
free(contents);
@@ -697,7 +690,6 @@ static void fsck_object_dir(const char *path)
697690
{
698691
struct progress *progress = NULL;
699692
struct for_each_loose_cb cb_data = {
700-
.obj_type = STRBUF_INIT,
701693
.progress = progress,
702694
};
703695

@@ -712,7 +704,6 @@ static void fsck_object_dir(const char *path)
712704
&cb_data);
713705
display_progress(progress, 256);
714706
stop_progress(&progress);
715-
strbuf_release(&cb_data.obj_type);
716707
}
717708

718709
static int fsck_head_link(const char *head_ref_name,

builtin/hash-object.c

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,65 +19,30 @@
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-
27-
/*
28-
* This is to create corrupt objects for debugging and as such it
29-
* needs to bypass the data conversion performed by, and the type
30-
* limitation imposed by, index_fd() and its callees.
31-
*/
32-
static int hash_literally(struct object_id *oid, int fd, const char *type, unsigned flags)
22+
static void hash_fd(int fd, const char *type, const char *path, unsigned flags)
3323
{
34-
struct strbuf buf = STRBUF_INIT;
35-
int ret;
36-
37-
if (strbuf_read(&buf, fd, 4096) < 0)
38-
ret = -1;
39-
else
40-
ret = write_object_file_literally(buf.buf, buf.len, type, oid,
41-
(flags & HASH_OBJECT_WRITE) ? WRITE_OBJECT_FILE_PERSIST : 0);
42-
close(fd);
43-
strbuf_release(&buf);
44-
return ret;
45-
}
46-
47-
static void hash_fd(int fd, const char *type, const char *path, unsigned flags,
48-
int literally)
49-
{
50-
unsigned int index_flags = 0;
5124
struct stat st;
5225
struct object_id oid;
5326

54-
if (flags & HASH_OBJECT_WRITE)
55-
index_flags |= INDEX_WRITE_OBJECT;
56-
if (flags & HASH_OBJECT_CHECK)
57-
index_flags |= INDEX_FORMAT_CHECK;
58-
5927
if (fstat(fd, &st) < 0 ||
60-
(literally
61-
? hash_literally(&oid, fd, type, flags)
62-
: index_fd(the_repository->index, &oid, fd, &st,
63-
type_from_string(type), path, index_flags)))
64-
die((flags & HASH_OBJECT_WRITE)
28+
index_fd(the_repository->index, &oid, fd, &st,
29+
type_from_string(type), path, flags))
30+
die((flags & INDEX_WRITE_OBJECT)
6531
? "Unable to add %s to database"
6632
: "Unable to hash %s", path);
6733
printf("%s\n", oid_to_hex(&oid));
6834
maybe_flush_or_die(stdout, "hash to stdout");
6935
}
7036

7137
static void hash_object(const char *path, const char *type, const char *vpath,
72-
unsigned flags, int literally)
38+
unsigned flags)
7339
{
7440
int fd;
7541
fd = xopen(path, O_RDONLY);
76-
hash_fd(fd, type, vpath, flags, literally);
42+
hash_fd(fd, type, vpath, flags);
7743
}
7844

79-
static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
80-
int literally)
45+
static void hash_stdin_paths(const char *type, int no_filters, unsigned flags)
8146
{
8247
struct strbuf buf = STRBUF_INIT;
8348
struct strbuf unquoted = STRBUF_INIT;
@@ -89,8 +54,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
8954
die("line is badly quoted");
9055
strbuf_swap(&buf, &unquoted);
9156
}
92-
hash_object(buf.buf, type, no_filters ? NULL : buf.buf, flags,
93-
literally);
57+
hash_object(buf.buf, type, no_filters ? NULL : buf.buf, flags);
9458
}
9559
strbuf_release(&buf);
9660
strbuf_release(&unquoted);
@@ -111,19 +75,20 @@ int cmd_hash_object(int argc,
11175
int hashstdin = 0;
11276
int stdin_paths = 0;
11377
int no_filters = 0;
114-
int literally = 0;
11578
int nongit = 0;
116-
unsigned flags = HASH_OBJECT_CHECK;
79+
unsigned flags = INDEX_FORMAT_CHECK;
11780
const char *vpath = NULL;
11881
char *vpath_free = NULL;
11982
const struct option hash_object_options[] = {
12083
OPT_STRING('t', NULL, &type, N_("type"), N_("object type")),
12184
OPT_BIT('w', NULL, &flags, N_("write the object into the object database"),
122-
HASH_OBJECT_WRITE),
85+
INDEX_WRITE_OBJECT),
12386
OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")),
12487
OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")),
12588
OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")),
126-
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),
12792
OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")),
12893
OPT_END()
12994
};
@@ -133,7 +98,7 @@ int cmd_hash_object(int argc,
13398
argc = parse_options(argc, argv, prefix, hash_object_options,
13499
hash_object_usage, 0);
135100

136-
if (flags & HASH_OBJECT_WRITE)
101+
if (flags & INDEX_WRITE_OBJECT)
137102
prefix = setup_git_directory();
138103
else
139104
prefix = setup_git_directory_gently(&nongit);
@@ -169,7 +134,7 @@ int cmd_hash_object(int argc,
169134
}
170135

171136
if (hashstdin)
172-
hash_fd(0, type, vpath, flags, literally);
137+
hash_fd(0, type, vpath, flags);
173138

174139
for (i = 0 ; i < argc; i++) {
175140
const char *arg = argv[i];
@@ -178,12 +143,12 @@ int cmd_hash_object(int argc,
178143
if (prefix)
179144
arg = to_free = prefix_filename(prefix, arg);
180145
hash_object(arg, type, no_filters ? NULL : vpath ? vpath : arg,
181-
flags, literally);
146+
flags);
182147
free(to_free);
183148
}
184149

185150
if (stdin_paths)
186-
hash_stdin_paths(type, no_filters, flags, literally);
151+
hash_stdin_paths(type, no_filters, flags);
187152

188153
free(vpath_free);
189154

0 commit comments

Comments
 (0)