summaryrefslogtreecommitdiff
path: root/hash-object.c
diff options
context:
space:
mode:
authorDmitry Potapov <dpotapov@gmail.com>2008-08-03 08:39:16 +0400
committerJunio C Hamano <gitster@pobox.com>2008-08-03 13:14:35 -0700
commit43df4f86e035056605ceb757029181d7ddee1e7e (patch)
tree8b6e0b8bc97343fc34328fd44bd26bf0d60a165d /hash-object.c
parent2b603260f325b895baa20867bd45c8e251f19b78 (diff)
downloadgit-43df4f86e035056605ceb757029181d7ddee1e7e.tar.gz
teach index_fd to work with pipes
index_fd can now work with file descriptors that are not normal files but any readable file. If the given file descriptor is a regular file then mmap() is used; for other files, strbuf_read is used. The path parameter, which has been used as hint for filters, can be NULL now to indicate that the file should be hashed literally without any filter. The index_pipe function is removed as redundant. Signed-off-by: Dmitry Potapov <dpotapov@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hash-object.c')
-rw-r--r--hash-object.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/hash-object.c b/hash-object.c
index 46c06a9552..7acfae15d9 100644
--- a/hash-object.c
+++ b/hash-object.c
@@ -8,15 +8,12 @@
#include "blob.h"
#include "quote.h"
-static void hash_object(const char *path, enum object_type type, int write_object)
+static void hash_fd(int fd, const char *type, int write_object, const char *path)
{
- int fd;
struct stat st;
unsigned char sha1[20];
- fd = open(path, O_RDONLY);
- if (fd < 0 ||
- fstat(fd, &st) < 0 ||
- index_fd(sha1, fd, &st, write_object, type, path))
+ if (fstat(fd, &st) < 0 ||
+ index_fd(sha1, fd, &st, write_object, type_from_string(type), path))
die(write_object
? "Unable to add %s to database"
: "Unable to hash %s", path);
@@ -24,12 +21,13 @@ static void hash_object(const char *path, enum object_type type, int write_objec
maybe_flush_or_die(stdout, "hash to stdout");
}
-static void hash_stdin(const char *type, int write_object)
+static void hash_object(const char *path, const char *type, int write_object)
{
- unsigned char sha1[20];
- if (index_pipe(sha1, 0, type, write_object))
- die("Unable to add stdin to database");
- printf("%s\n", sha1_to_hex(sha1));
+ int fd;
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ die("Cannot open %s", path);
+ hash_fd(fd, type, write_object, path);
}
static void hash_stdin_paths(const char *type, int write_objects)
@@ -45,7 +43,7 @@ static void hash_stdin_paths(const char *type, int write_objects)
die("line is badly quoted");
strbuf_swap(&buf, &nbuf);
}
- hash_object(buf.buf, type_from_string(type), write_objects);
+ hash_object(buf.buf, type, write_objects);
}
strbuf_release(&buf);
strbuf_release(&nbuf);
@@ -116,13 +114,13 @@ int main(int argc, char **argv)
}
if (hashstdin) {
- hash_stdin(type, write_object);
+ hash_fd(0, type, write_object, NULL);
hashstdin = 0;
}
if (0 <= prefix_length)
arg = prefix_filename(prefix, prefix_length,
arg);
- hash_object(arg, type_from_string(type), write_object);
+ hash_object(arg, type, write_object);
no_more_flags = 1;
}
}
@@ -131,6 +129,6 @@ int main(int argc, char **argv)
hash_stdin_paths(type, write_object);
if (hashstdin)
- hash_stdin(type, write_object);
+ hash_fd(0, type, write_object, NULL);
return 0;
}