diff options
| -rw-r--r-- | builtin/hash-object.c | 29 | ||||
| -rwxr-xr-x | t/t1007-hash-object.sh | 11 |
2 files changed, 7 insertions, 33 deletions
diff --git a/builtin/hash-object.c b/builtin/hash-object.c index cd53fa3bde..3c6949b3fa 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -24,26 +24,6 @@ enum { HASH_OBJECT_WRITE = (1 << 1), }; -/* - * This is to create corrupt objects for debugging and as such it - * needs to bypass the data conversion performed by, and the type - * limitation imposed by, index_fd() and its callees. - */ -static int hash_literally(struct object_id *oid, int fd, const char *type, unsigned flags) -{ - struct strbuf buf = STRBUF_INIT; - int ret; - - if (strbuf_read(&buf, fd, 4096) < 0) - ret = -1; - else - ret = write_object_file_literally(buf.buf, buf.len, type, oid, - (flags & HASH_OBJECT_WRITE) ? WRITE_OBJECT_FILE_PERSIST : 0); - close(fd); - strbuf_release(&buf); - return ret; -} - static void hash_fd(int fd, const char *type, const char *path, unsigned flags, int literally) { @@ -56,11 +36,12 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags, if (flags & HASH_OBJECT_CHECK) index_flags |= INDEX_FORMAT_CHECK; + if (literally) + index_flags &= ~INDEX_FORMAT_CHECK; + if (fstat(fd, &st) < 0 || - (literally - ? hash_literally(&oid, fd, type, flags) - : index_fd(the_repository->index, &oid, fd, &st, - type_from_string(type), path, index_flags))) + index_fd(the_repository->index, &oid, fd, &st, + type_from_string(type), path, index_flags)) die((flags & HASH_OBJECT_WRITE) ? "Unable to add %s to database" : "Unable to hash %s", path); diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh index b3cf53ff8c..dbbe9fb0d4 100755 --- a/t/t1007-hash-object.sh +++ b/t/t1007-hash-object.sh @@ -248,15 +248,8 @@ test_expect_success 'hash-object complains about truncated type name' ' test_must_fail git hash-object -t bl --stdin </dev/null ' -test_expect_success '--literally' ' - t=1234567890 && - echo example | git hash-object -t $t --literally --stdin -' - -test_expect_success '--literally with extra-long type' ' - t=12345678901234567890123456789012345678901234567890 && - t="$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t$t" && - echo example | git hash-object -t $t --literally --stdin +test_expect_success '--literally complains about non-standard types' ' + test_must_fail git hash-object -t bogus --literally --stdin ' test_expect_success '--stdin outside of repository (uses SHA-1)' ' |
