Browse Source
This patch makes the first half of write_sha1_file() and index_fd() externally visible, to allow callers to compute the object ID without actually storing it in the object database. [JC demangled the whitespaces himself because he liked the patch so much, and reworked the interface to index_fd() slightly, taking suggestion from Linus and of his own.] Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>maint
Bryan Larsen
20 years ago
committed by
Linus Torvalds
11 changed files with 113 additions and 75 deletions
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
git-hash-object(1) |
||||
================== |
||||
v0.1, May 2005 |
||||
|
||||
NAME |
||||
---- |
||||
git-hash-object - Computes object ID and optionally creates a blob from a file. |
||||
|
||||
|
||||
SYNOPSIS |
||||
-------- |
||||
'git-hash-object' [-t <type>] [-w] <any-file-on-the-filesystem> |
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
Computes the object ID value for an object with specified type |
||||
with the contents of the named file (which can be outside of the |
||||
work tree), and optionally writes the resulting object into the |
||||
object database. Reports its object ID to its standard output. |
||||
This is used by "git-cvsimport-script" to update the cache |
||||
without modifying files in the work tree. When <type> is not |
||||
specified, it defaults to "blob". |
||||
|
||||
|
||||
Author |
||||
------ |
||||
Written by Junio C Hamano <junkio@cox.net> |
||||
|
||||
Documentation |
||||
-------------- |
||||
Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>. |
||||
|
||||
GIT |
||||
--- |
||||
Part of the link:git.html[git] suite |
||||
|
@ -1,33 +0,0 @@
@@ -1,33 +0,0 @@
|
||||
git-write-blob(1) |
||||
================= |
||||
v0.1, May 2005 |
||||
|
||||
NAME |
||||
---- |
||||
git-write-blob - Creates a blob from a file |
||||
|
||||
|
||||
SYNOPSIS |
||||
-------- |
||||
'git-write-blob' <any-file-on-the-filesystem> |
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
Writes the contents of the named file (which can be outside of the work |
||||
tree) as a blob into the object database, and reports its object ID to its |
||||
standard output. This is used by "git-merge-one-file-script" to update the |
||||
cache without modifying files in the work tree. |
||||
|
||||
|
||||
Author |
||||
------ |
||||
Written by Linus Torvalds <torvalds@osdl.org> |
||||
|
||||
Documentation |
||||
-------------- |
||||
Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>. |
||||
|
||||
GIT |
||||
--- |
||||
Part of the link:git.html[git] suite |
||||
|
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* GIT - The information manager from hell |
||||
* |
||||
* Copyright (C) Linus Torvalds, 2005 |
||||
* Copyright (C) Junio C Hamano, 2005 |
||||
*/ |
||||
#include "cache.h" |
||||
|
||||
static void hash_object(const char *path, const char *type, int write_object) |
||||
{ |
||||
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)) |
||||
die(write_object |
||||
? "Unable to add %s to database" |
||||
: "Unable to hash %s", path); |
||||
printf("%s\n", sha1_to_hex(sha1)); |
||||
} |
||||
|
||||
static const char *hash_object_usage = |
||||
"git-hash-object [-t <type>] [-w] <file>..."; |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
int i; |
||||
const char *type = "blob"; |
||||
int write_object = 0; |
||||
|
||||
for (i = 1 ; i < argc; i++) { |
||||
if (!strcmp(argv[i], "-t")) { |
||||
if (argc <= ++i) |
||||
die(hash_object_usage); |
||||
type = argv[i]; |
||||
} |
||||
else if (!strcmp(argv[i], "-w")) |
||||
write_object = 1; |
||||
else |
||||
hash_object(argv[i], type, write_object); |
||||
} |
||||
return 0; |
||||
} |
@ -1,25 +0,0 @@
@@ -1,25 +0,0 @@
|
||||
/* |
||||
* 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; |
||||
} |
Loading…
Reference in new issue