summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 68849b5)
raw | patch | inline | side by side (parent: 68849b5)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sun, 1 May 2005 23:36:56 +0000 (16:36 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sun, 1 May 2005 23:36:56 +0000 (16:36 -0700) |
This allows the programs to use various simplified versions of
the SHA1 names, eg just say "HEAD" for the SHA1 pointed to by
the .git/HEAD file etc.
For example, this commit has been done with
git-commit-tree $(git-write-tree) -p HEAD
instead of the traditional "$(cat .git/HEAD)" syntax.
the SHA1 names, eg just say "HEAD" for the SHA1 pointed to by
the .git/HEAD file etc.
For example, this commit has been done with
git-commit-tree $(git-write-tree) -p HEAD
instead of the traditional "$(cat .git/HEAD)" syntax.
16 files changed:
cache.h | patch | blob | history | |
cat-file.c | patch | blob | history | |
commit-tree.c | patch | blob | history | |
convert-cache.c | patch | blob | history | |
diff-cache.c | patch | blob | history | |
diff-tree.c | patch | blob | history | |
export.c | patch | blob | history | |
fsck-cache.c | patch | blob | history | |
ls-tree.c | patch | blob | history | |
merge-base.c | patch | blob | history | |
read-tree.c | patch | blob | history | |
rev-list.c | patch | blob | history | |
rev-tree.c | patch | blob | history | |
sha1_file.c | patch | blob | history | |
tar-tree.c | patch | blob | history | |
unpack-file.c | patch | blob | history |
index af6345820f3f8c533868394059b2d3b189e6b422..940ced03148782c549a309249729c942b6cc9b85 100644 (file)
--- a/cache.h
+++ b/cache.h
extern int has_sha1_file(const unsigned char *sha1);
/* Convert to/from hex/sha1 representation */
+extern int get_sha1(const char *str, unsigned char *sha1);
extern int get_sha1_hex(const char *hex, unsigned char *sha1);
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
diff --git a/cat-file.c b/cat-file.c
index 3c47d79a16305d326a65768fe9f37ee25928510b..d253ff93807fa9bbd66e7cd278f213e06644c31e 100644 (file)
--- a/cat-file.c
+++ b/cat-file.c
void *buf;
unsigned long size;
- if (argc != 3 || get_sha1_hex(argv[2], sha1))
+ if (argc != 3 || get_sha1(argv[2], sha1))
usage("cat-file [-t | tagname] <sha1>");
buf = read_sha1_file(sha1, type, &size);
if (!buf)
diff --git a/commit-tree.c b/commit-tree.c
index 0c568d0179e93bc202ac62c31fca7fe107b3ab1c..cfd6730fe8da68a9b4e10ccf6481a2a1264fc81d 100644 (file)
--- a/commit-tree.c
+++ b/commit-tree.c
for (i = 2; i < argc; i += 2) {
char *a, *b;
a = argv[i]; b = argv[i+1];
- if (!b || strcmp(a, "-p") || get_sha1_hex(b, parent_sha1[parents]))
+ if (!b || strcmp(a, "-p") || get_sha1(b, parent_sha1[parents]))
usage(commit_tree_usage);
check_valid(parent_sha1[parents], "commit");
parents++;
diff --git a/convert-cache.c b/convert-cache.c
index 631d1aa910e7328c99642495f93908c749074f91..4d34d2d57ecda02aea70fab008fab32f5a4391b0 100644 (file)
--- a/convert-cache.c
+++ b/convert-cache.c
unsigned char sha1[20];
struct entry *entry;
- if (argc != 2 || get_sha1_hex(argv[1], sha1))
+ if (argc != 2 || get_sha1(argv[1], sha1))
usage("convert-cache <sha1>");
entry = convert_entry(sha1);
diff --git a/diff-cache.c b/diff-cache.c
index 899e37361e5d34a38e4746b3cd290d9b96a6c8f8..03dd69df3eb3bc9a516f3bec06a3580a78abf632 100644 (file)
--- a/diff-cache.c
+++ b/diff-cache.c
usage(diff_cache_usage);
}
- if (argc != 2 || get_sha1_hex(argv[1], tree_sha1))
+ if (argc != 2 || get_sha1(argv[1], tree_sha1))
usage(diff_cache_usage);
mark_merge_entries();
diff --git a/diff-tree.c b/diff-tree.c
index e7a5b7cc76f5d80e602184f1ef12f502d53a552b..1186c5ce6d690766f586f320889da9d78d2404b9 100644 (file)
--- a/diff-tree.c
+++ b/diff-tree.c
usage(diff_tree_usage);
}
- if (argc < 3 || get_sha1_hex(argv[1], old) || get_sha1_hex(argv[2], new))
+ if (argc < 3 || get_sha1(argv[1], old) || get_sha1(argv[2], new))
usage(diff_tree_usage);
if (argc > 3) {
diff --git a/export.c b/export.c
index 885f4e88fc93368862c44f359b7149c576e0c841..78bfe9f2224408056ad7992827dff498302e67b7 100644 (file)
--- a/export.c
+++ b/export.c
unsigned char top_sha1[20];
if (argc < 2 || argc > 4 ||
- get_sha1_hex(argv[1], top_sha1) ||
- (argc == 3 && get_sha1_hex(argv[2], base_sha1)))
+ get_sha1(argv[1], top_sha1) ||
+ (argc == 3 && get_sha1(argv[2], base_sha1)))
usage("git-export top [base]");
export(get_commit(top_sha1), argc==3 ? get_commit(base_sha1) : NULL);
return 0;
diff --git a/fsck-cache.c b/fsck-cache.c
index d8d2e594fc787e9d0f8d0485568ff6635efca4c1..fbcd2b64f493a41f576781e3e42ad459d1a2a486 100644 (file)
--- a/fsck-cache.c
+++ b/fsck-cache.c
if (*arg == '-')
continue;
- if (!get_sha1_hex(arg, head_sha1)) {
+ if (!get_sha1(arg, head_sha1)) {
struct commit *commit = lookup_commit(head_sha1);
struct object *obj;
diff --git a/ls-tree.c b/ls-tree.c
index d2ab02e3484efaf851c50574e603c785d713bc87..339ac36a4cad45acd5d6769bed6c8b01c5da453a 100644 (file)
--- a/ls-tree.c
+++ b/ls-tree.c
if (argc != 2)
usage(ls_tree_usage);
- if (get_sha1_hex(argv[1], sha1) < 0)
+ if (get_sha1(argv[1], sha1) < 0)
usage(ls_tree_usage);
sha1_file_directory = getenv(DB_ENVIRONMENT);
if (!sha1_file_directory)
diff --git a/merge-base.c b/merge-base.c
index 2c40881302e586366f03ae6ac6e7c0035847e2f0..2ea44970d20500740db78b1cf0b9854c29e27553 100644 (file)
--- a/merge-base.c
+++ b/merge-base.c
unsigned char rev1key[20], rev2key[20];
if (argc != 3 ||
- get_sha1_hex(argv[1], rev1key) ||
- get_sha1_hex(argv[2], rev2key)) {
+ get_sha1(argv[1], rev1key) ||
+ get_sha1(argv[2], rev2key)) {
usage("merge-base <commit-id> <commit-id>");
}
rev1 = lookup_commit(rev1key);
diff --git a/read-tree.c b/read-tree.c
index 604884a983e087e25afccc1c52beff3883036e58..f8dc509a1f999fcbcccc6936477ddc80c9d063cc 100644 (file)
--- a/read-tree.c
+++ b/read-tree.c
merge = 1;
continue;
}
- if (get_sha1_hex(arg, sha1) < 0)
+ if (get_sha1(arg, sha1) < 0)
usage(read_tree_usage);
if (stage > 3)
usage(read_tree_usage);
diff --git a/rev-list.c b/rev-list.c
index 77bfc29db1aad08ba9d7d87ce08d33d4a88e74e3..42fd154fc1a3b9a066a5d7d3ec997355e53f784e 100644 (file)
--- a/rev-list.c
+++ b/rev-list.c
struct commit_list *list = NULL;
struct commit *commit;
- if (argc != 2 || get_sha1_hex(argv[1], sha1))
+ if (argc != 2 || get_sha1(argv[1], sha1))
usage("rev-list <commit-id>");
commit = lookup_commit(sha1);
diff --git a/rev-tree.c b/rev-tree.c
index 95ec274fc7fa68d2e70446104c51732ac7815fe2..bfc8b125794d5c7104ed955eb3021c5958fc11b5 100644 (file)
--- a/rev-tree.c
+++ b/rev-tree.c
arg++;
basemask |= 1<<nr;
}
- if (nr >= MAX_COMMITS || get_sha1_hex(arg, sha1[nr]))
+ if (nr >= MAX_COMMITS || get_sha1(arg, sha1[nr]))
usage("rev-tree [--edges] [--cache <cache-file>] <commit-id> [<commit-id>]");
process_commit(sha1[nr]);
nr++;
diff --git a/sha1_file.c b/sha1_file.c
index 29f48d56b18fae6e323d37eebbd440574aed2cfa..d91e072f3e5480de3605fb3f1e581a938301bdfb 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
return 0;
}
+int get_sha1_file(const char *path, unsigned char *result)
+{
+ char buffer[60];
+ int fd = open(path, O_RDONLY);
+ int len;
+
+ if (fd < 0)
+ return -1;
+ len = read(fd, buffer, sizeof(buffer));
+ close(fd);
+ if (len < 40)
+ return -1;
+ return get_sha1_hex(buffer, result);
+}
+
+int get_sha1(const char *str, unsigned char *sha1)
+{
+ static char pathname[PATH_MAX];
+
+ if (!get_sha1_hex(str, sha1))
+ return 0;
+ if (!get_sha1_file(str, sha1))
+ return 0;
+ snprintf(pathname, sizeof(pathname), ".git/%s", str);
+ if (!get_sha1_file(pathname, sha1))
+ return 0;
+ return -1;
+}
+
char * sha1_to_hex(const unsigned char *sha1)
{
static char buffer[50];
diff --git a/tar-tree.c b/tar-tree.c
index ea7ea91add54532c38dde9e343efe34d56805341..2c64f690e52093af13585521de4df478ac6e85e5 100644 (file)
--- a/tar-tree.c
+++ b/tar-tree.c
basedir = argv[2];
/* FALLTHROUGH */
case 2:
- if (get_sha1_hex(argv[1], sha1) < 0)
+ if (get_sha1(argv[1], sha1) < 0)
usage(tar_tree_usage);
break;
default:
diff --git a/unpack-file.c b/unpack-file.c
index 6ff3d51c182627f42b104932ecea9b95d6225a5d..b7988c5575fabd57100d25742a1d0578bcc181d7 100644 (file)
--- a/unpack-file.c
+++ b/unpack-file.c
{
unsigned char sha1[20];
- if (argc != 2 || get_sha1_hex(argv[1], sha1))
+ if (argc != 2 || get_sha1(argv[1], sha1))
usage("unpack-file.c <sha1>");
puts(create_temp_file(sha1));