diff options
author | Junio C Hamano <junkio@cox.net> | 2005-05-01 23:45:49 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-05-01 23:45:49 -0700 |
commit | 74400e7175e3dac994e75452973d78f6a42de65e (patch) | |
tree | 07f84ebdc715d72c409ce85ab0e8a74672b0a101 /write-blob.c | |
parent | 285bf834bea11981ae7c2242e9f087d3effe7de8 (diff) | |
download | git-74400e7175e3dac994e75452973d78f6a42de65e.tar.gz |
Add git-write-blob.
A new command, git-write-blob, is introduced. This registers
the contents of any file on the filesystem as a blob in the
object database and reports its SHA1 to the standard output.
To implement it, the patch promotes index_fd() from a static
function in update-cache.c to extern and moves it to a library
source, sha1_file.c.
This command is used to update git-merge-one-file-script so that
it does not smudge the work tree.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'write-blob.c')
-rw-r--r-- | write-blob.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/write-blob.c b/write-blob.c new file mode 100644 index 0000000000..8bfd57615a --- /dev/null +++ b/write-blob.c @@ -0,0 +1,25 @@ +/* + * GIT - The information manager from hell + * + * Copyright (C) Linus Torvalds, 2005 + */ +#include "cache.h" + +int main(int argc, char **argv) +{ + int i; + + for (i = 1 ; i < argc; i++) { + char *path = argv[i]; + 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) < 0) + die("Unable to add blob %s to database", path); + printf("%s\n", sha1_to_hex(sha1)); + } + return 0; +} |