From: Linus Torvalds Date: Fri, 29 Apr 2005 21:09:11 +0000 (-0700) Subject: Rename git core commands to be "git-xxxx" to avoid name clashes. X-Git-Tag: v0.99~702 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;ds=sidebyside;h=a3df180138b85a603656582bde6df757095618cf;p=git.git Rename git core commands to be "git-xxxx" to avoid name clashes. This also regularizes the make. The source files themselves don't get the "git-" prefix, because that's just inconvenient. So instead we just make the rule that "git-xxxx" depends on "xxxx.c", and do that for all the core programs (ie the old "git-mktag.c" got renamed to just "mktag.c" to match everything else). And "show-diff" got renamed to "git-diff-files" while at it, since that's what it really should be to match the other git-diff-xxx cases. --- diff --git a/Makefile b/Makefile index 0b330dc3..ad31e8a2 100644 --- a/Makefile +++ b/Makefile @@ -12,13 +12,16 @@ CFLAGS=-g -O2 -Wall CC=gcc AR=ar -SCRIPTS=git-merge-one-file-script git-prune-script git-pull-script git-tag-script +SCRIPTS=git-merge-one-file-script git-prune-script git-pull-script \ + git-tag-script -PROG= update-cache show-diff init-db write-tree read-tree commit-tree \ - cat-file fsck-cache checkout-cache diff-tree rev-tree show-files \ - check-files ls-tree merge-base merge-cache unpack-file git-export \ - diff-cache convert-cache http-pull rpush rpull rev-list git-mktag \ - diff-tree-helper tar-tree +PROG= git-update-cache git-diff-files git-init-db git-write-tree \ + git-read-tree git-commit-tree git-cat-file git-fsck-cache \ + git-checkout-cache git-diff-tree git-rev-tree git-show-files \ + git-check-files git-ls-tree git-merge-base git-merge-cache \ + git-unpack-file git-export git-diff-cache git-convert-cache \ + git-http-pull git-rpush git-rpull git-rev-list git-mktag \ + git-diff-tree-helper git-tar-tree all: $(PROG) @@ -58,46 +61,49 @@ $(LIB_FILE): $(LIB_OBJS) init-db: init-db.o -%: %.c $(LIB_FILE) +git-%: %.c $(LIB_FILE) $(CC) $(CFLAGS) -o $@ $(filter %.c,$^) $(LIBS) -rpush: rsh.c - -rpull: rsh.c - -http-pull: LIBS += -lcurl - +git-update-cache: update-cache.c +git-diff-files: diff-files.c +git-init-db: init-db.c +git-write-tree: write-tree.c +git-read-tree: read-tree.c +git-commit-tree: commit-tree.c +git-cat-file: cat-file.c +git-fsck-cache: fsck-cache.c +git-checkout-cache: checkout-cache.c +git-diff-tree: diff-tree.c +git-rev-tree: rev-tree.c +git-show-files: show-files.c +git-check-files: check-files.c +git-ls-tree: ls-tree.c +git-merge-base: merge-base.c +git-merge-cache: merge-cache.c +git-unpack-file: unpack-file.c +git-export: export.c +git-diff-cache: diff-cache.c +git-convert-cache: convert-cache.c +git-http-pull: http-pull.c +git-rpush: rsh.c +git-rpull: rsh.c +git-rev-list: rev-list.c +git-mktag: mktag.c +git-diff-tree-helper: diff-tree-helper.c +git-tar-tree: tar-tree.c + +git-http-pull: LIBS += -lcurl + +# Library objects.. blob.o: $(LIB_H) -cat-file.o: $(LIB_H) -check-files.o: $(LIB_H) -checkout-cache.o: $(LIB_H) +tree.o: $(LIB_H) commit.o: $(LIB_H) -commit-tree.o: $(LIB_H) -convert-cache.o: $(LIB_H) -diff.o: $(LIB_H) -diff-cache.o: $(LIB_H) -diff-tree.o: $(LIB_H) -fsck-cache.o: $(LIB_H) -git-export.o: $(LIB_H) -init-db.o: $(LIB_H) -ls-tree.o: $(LIB_H) -merge-base.o: $(LIB_H) -merge-cache.o: $(LIB_H) +tag.o: $(LIB_H) object.o: $(LIB_H) read-cache.o: $(LIB_H) -read-tree.o: $(LIB_H) -rev-tree.o: $(LIB_H) sha1_file.o: $(LIB_H) -show-diff.o: $(LIB_H) -show-files.o: $(LIB_H) -tree.o: $(LIB_H) -update-cache.o: $(LIB_H) usage.o: $(LIB_H) -unpack-file.o: $(LIB_H) -write-tree.o: $(LIB_H) -http-pull.o: $(LIB_H) -rpull.o: $(LIB_H) -rpush.o: $(LIB_H) +diff.o: $(LIB_H) clean: rm -f *.o mozilla-sha1/*.o ppc/*.o $(PROG) $(LIB_FILE) diff --git a/diff-files.c b/diff-files.c new file mode 100644 index 00000000..fdd7dd4b --- /dev/null +++ b/diff-files.c @@ -0,0 +1,135 @@ +/* + * GIT - The information manager from hell + * + * Copyright (C) Linus Torvalds, 2005 + */ +#include "cache.h" +#include "diff.h" + +static const char *show_diff_usage = +"show-diff [-p] [-q] [-r] [-z] [paths...]"; + +static int generate_patch = 0; +static int line_termination = '\n'; +static int silent = 0; + +static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt) +{ + int i; + int namelen = ce_namelen(ce); + for (i = 0; i < cnt; i++) { + int speclen = strlen(spec[i]); + if (! strncmp(spec[i], ce->name, speclen) && + speclen <= namelen && + (ce->name[speclen] == 0 || + ce->name[speclen] == '/')) + return 1; + } + return 0; +} + +static void show_unmerge(const char *path) +{ + if (generate_patch) + diff_unmerge(path); + else + printf("U %s%c", path, line_termination); +} + +static void show_file(int pfx, struct cache_entry *ce) +{ + if (generate_patch) + diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1, + ce->name, NULL); + else + printf("%c%06o\t%s\t%s\t%s%c", + pfx, ntohl(ce->ce_mode), "blob", + sha1_to_hex(ce->sha1), ce->name, line_termination); +} + +static void show_modified(int oldmode, int mode, + const char *old_sha1, const char *sha1, + char *path) +{ + char old_sha1_hex[41]; + strcpy(old_sha1_hex, sha1_to_hex(old_sha1)); + + if (generate_patch) + diff_change(oldmode, mode, old_sha1, sha1, path, NULL); + else + printf("*%06o->%06o\tblob\t%s->%s\t%s%c", + oldmode, mode, old_sha1_hex, sha1_to_hex(sha1), path, + line_termination); +} + +int main(int argc, char **argv) +{ + static const char null_sha1[20] = { 0, }; + int entries = read_cache(); + int i; + + while (1 < argc && argv[1][0] == '-') { + if (!strcmp(argv[1], "-p")) + generate_patch = 1; + else if (!strcmp(argv[1], "-q")) + silent = 1; + else if (!strcmp(argv[1], "-r")) + ; /* no-op */ + else if (!strcmp(argv[1], "-s")) + ; /* no-op */ + else if (!strcmp(argv[1], "-z")) + line_termination = 0; + else + usage(show_diff_usage); + argv++; argc--; + } + + /* At this point, if argc == 1, then we are doing everything. + * Otherwise argv[1] .. argv[argc-1] have the explicit paths. + */ + if (entries < 0) { + perror("read_cache"); + exit(1); + } + + for (i = 0; i < entries; i++) { + struct stat st; + unsigned int oldmode, mode; + struct cache_entry *ce = active_cache[i]; + int changed; + + if (1 < argc && + ! matches_pathspec(ce, argv+1, argc-1)) + continue; + + if (ce_stage(ce)) { + show_unmerge(ce->name); + while (i < entries && + !strcmp(ce->name, active_cache[i]->name)) + i++; + i--; /* compensate for loop control increments */ + continue; + } + + if (stat(ce->name, &st) < 0) { + if (errno != ENOENT) { + perror(ce->name); + continue; + } + if (silent) + continue; + show_file('-', ce); + continue; + } + changed = cache_match_stat(ce, &st); + if (!changed) + continue; + + oldmode = ntohl(ce->ce_mode); + mode = S_IFREG | ce_permissions(st.st_mode); + + show_modified(oldmode, mode, ce->sha1, null_sha1, + ce->name); + } + return 0; +} diff --git a/export.c b/export.c new file mode 100644 index 00000000..77f5198b --- /dev/null +++ b/export.c @@ -0,0 +1,81 @@ +#include "cache.h" +#include "commit.h" + +/* + * Show one commit + */ +void show_commit(struct commit *commit) +{ + char cmdline[400]; + char hex[100]; + + strcpy(hex, sha1_to_hex(commit->object.sha1)); + printf("Id: %s\n", hex); + fflush(NULL); + sprintf(cmdline, "cat-file commit %s", hex); + system(cmdline); + if (commit->parents) { + char *against = sha1_to_hex(commit->parents->item->object.sha1); + printf("\n\n======== diff against %s ========\n", against); + fflush(NULL); + sprintf(cmdline, "diff-tree -p %s %s", against, hex); + system(cmdline); + } + printf("======== end ========\n\n"); +} + +/* + * Show all unseen commits, depth-first + */ +void show_unseen(struct commit *top) +{ + struct commit_list *parents; + + if (top->object.flags & 2) + return; + top->object.flags |= 2; + parents = top->parents; + while (parents) { + show_unseen(parents->item); + parents = parents->next; + } + show_commit(top); +} + +void export(struct commit *top, struct commit *base) +{ + mark_reachable(&top->object, 1); + if (base) + mark_reachable(&base->object, 2); + show_unseen(top); +} + +struct commit *get_commit(unsigned char *sha1) +{ + struct commit *commit = lookup_commit(sha1); + if (!commit->object.parsed) { + struct commit_list *parents; + + if (parse_commit(commit) < 0) + die("unable to parse commit %s", sha1_to_hex(sha1)); + parents = commit->parents; + while (parents) { + get_commit(parents->item->object.sha1); + parents = parents->next; + } + } + return commit; +} + +int main(int argc, char **argv) +{ + unsigned char base_sha1[20]; + 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))) + usage("git-export top [base]"); + export(get_commit(top_sha1), argc==3 ? get_commit(base_sha1) : NULL); + return 0; +} diff --git a/git-export.c b/git-export.c deleted file mode 100644 index 77f5198b..00000000 --- a/git-export.c +++ /dev/null @@ -1,81 +0,0 @@ -#include "cache.h" -#include "commit.h" - -/* - * Show one commit - */ -void show_commit(struct commit *commit) -{ - char cmdline[400]; - char hex[100]; - - strcpy(hex, sha1_to_hex(commit->object.sha1)); - printf("Id: %s\n", hex); - fflush(NULL); - sprintf(cmdline, "cat-file commit %s", hex); - system(cmdline); - if (commit->parents) { - char *against = sha1_to_hex(commit->parents->item->object.sha1); - printf("\n\n======== diff against %s ========\n", against); - fflush(NULL); - sprintf(cmdline, "diff-tree -p %s %s", against, hex); - system(cmdline); - } - printf("======== end ========\n\n"); -} - -/* - * Show all unseen commits, depth-first - */ -void show_unseen(struct commit *top) -{ - struct commit_list *parents; - - if (top->object.flags & 2) - return; - top->object.flags |= 2; - parents = top->parents; - while (parents) { - show_unseen(parents->item); - parents = parents->next; - } - show_commit(top); -} - -void export(struct commit *top, struct commit *base) -{ - mark_reachable(&top->object, 1); - if (base) - mark_reachable(&base->object, 2); - show_unseen(top); -} - -struct commit *get_commit(unsigned char *sha1) -{ - struct commit *commit = lookup_commit(sha1); - if (!commit->object.parsed) { - struct commit_list *parents; - - if (parse_commit(commit) < 0) - die("unable to parse commit %s", sha1_to_hex(sha1)); - parents = commit->parents; - while (parents) { - get_commit(parents->item->object.sha1); - parents = parents->next; - } - } - return commit; -} - -int main(int argc, char **argv) -{ - unsigned char base_sha1[20]; - 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))) - usage("git-export top [base]"); - export(get_commit(top_sha1), argc==3 ? get_commit(base_sha1) : NULL); - return 0; -} diff --git a/git-mktag.c b/git-mktag.c deleted file mode 100644 index 8605802d..00000000 --- a/git-mktag.c +++ /dev/null @@ -1,125 +0,0 @@ -#include "cache.h" - -/* - * A signature file has a very simple fixed format: three lines - * of "object " + "type " + "tag ", - * followed by some free-form signature that git itself doesn't - * care about, but that can be verified with gpg or similar. - * - * The first three lines are guaranteed to be at least 63 bytes: - * "object \n" is 48 bytes, "type tag\n" at 9 bytes is the - * shortest possible type-line, and "tag .\n" at 6 bytes is the - * shortest single-character-tag line. - * - * We also artificially limit the size of the full object to 8kB. - * Just because I'm a lazy bastard, and if you can't fit a signature - * in that size, you're doing something wrong. - */ - -// Some random size -#define MAXSIZE (8192) - -/* - * We refuse to tag something we can't verify. Just because. - */ -static int verify_object(unsigned char *sha1, const char *expected_type) -{ - int ret = -1; - unsigned long mapsize; - void *map = map_sha1_file(sha1, &mapsize); - - if (map) { - char type[100]; - unsigned long size; - void *buffer = unpack_sha1_file(map, mapsize, type, &size); - - if (buffer) { - if (!strcmp(type, expected_type)) - ret = check_sha1_signature(sha1, buffer, size, type); - free(buffer); - } - munmap(map, mapsize); - } - return ret; -} - -static int verify_tag(char *buffer, unsigned long size) -{ - int typelen; - char type[20]; - unsigned char sha1[20]; - const char *object, *type_line, *tag_line; - - if (size < 64 || size > MAXSIZE-1) - return -1; - buffer[size] = 0; - - /* Verify object line */ - object = buffer; - if (memcmp(object, "object ", 7)) - return -1; - if (get_sha1_hex(object + 7, sha1)) - return -1; - - /* Verify type line */ - type_line = object + 48; - if (memcmp(type_line - 1, "\ntype ", 6)) - return -1; - - /* Verify tag-line */ - tag_line = strchr(type_line, '\n'); - if (!tag_line) - return -1; - tag_line++; - if (memcmp(tag_line, "tag ", 4) || tag_line[4] == '\n') - return -1; - - /* Get the actual type */ - typelen = tag_line - type_line - strlen("type \n"); - if (typelen >= sizeof(type)) - return -1; - memcpy(type, type_line+5, typelen); - type[typelen] = 0; - - /* Verify that the object matches */ - if (get_sha1_hex(object + 7, sha1)) - return -1; - if (verify_object(sha1, type)) - return -1; - - /* Verify the tag-name: we don't allow control characters or spaces in it */ - tag_line += 4; - for (;;) { - unsigned char c = *tag_line++; - if (c == '\n') - break; - if (c > ' ') - continue; - return -1; - } - - /* The actual stuff afterwards we don't care about.. */ - return 0; -} - -int main(int argc, char **argv) -{ - unsigned long size; - char buffer[MAXSIZE]; - unsigned char result_sha1[20]; - - if (argc != 1) - usage("cat | git-mktag"); - - // Read the signature - size = read(0, buffer, MAXSIZE); - - // Verify it for some basic sanity: it needs to start with "object \ntype " - if (verify_tag(buffer, size) < 0) - die("invalid tag signature file"); - - if (write_sha1_file(buffer, size, "tag", result_sha1) < 0) - die("unable to write tag file"); - printf("%s\n", sha1_to_hex(result_sha1)); - return 0; -} diff --git a/mktag.c b/mktag.c new file mode 100644 index 00000000..8605802d --- /dev/null +++ b/mktag.c @@ -0,0 +1,125 @@ +#include "cache.h" + +/* + * A signature file has a very simple fixed format: three lines + * of "object " + "type " + "tag ", + * followed by some free-form signature that git itself doesn't + * care about, but that can be verified with gpg or similar. + * + * The first three lines are guaranteed to be at least 63 bytes: + * "object \n" is 48 bytes, "type tag\n" at 9 bytes is the + * shortest possible type-line, and "tag .\n" at 6 bytes is the + * shortest single-character-tag line. + * + * We also artificially limit the size of the full object to 8kB. + * Just because I'm a lazy bastard, and if you can't fit a signature + * in that size, you're doing something wrong. + */ + +// Some random size +#define MAXSIZE (8192) + +/* + * We refuse to tag something we can't verify. Just because. + */ +static int verify_object(unsigned char *sha1, const char *expected_type) +{ + int ret = -1; + unsigned long mapsize; + void *map = map_sha1_file(sha1, &mapsize); + + if (map) { + char type[100]; + unsigned long size; + void *buffer = unpack_sha1_file(map, mapsize, type, &size); + + if (buffer) { + if (!strcmp(type, expected_type)) + ret = check_sha1_signature(sha1, buffer, size, type); + free(buffer); + } + munmap(map, mapsize); + } + return ret; +} + +static int verify_tag(char *buffer, unsigned long size) +{ + int typelen; + char type[20]; + unsigned char sha1[20]; + const char *object, *type_line, *tag_line; + + if (size < 64 || size > MAXSIZE-1) + return -1; + buffer[size] = 0; + + /* Verify object line */ + object = buffer; + if (memcmp(object, "object ", 7)) + return -1; + if (get_sha1_hex(object + 7, sha1)) + return -1; + + /* Verify type line */ + type_line = object + 48; + if (memcmp(type_line - 1, "\ntype ", 6)) + return -1; + + /* Verify tag-line */ + tag_line = strchr(type_line, '\n'); + if (!tag_line) + return -1; + tag_line++; + if (memcmp(tag_line, "tag ", 4) || tag_line[4] == '\n') + return -1; + + /* Get the actual type */ + typelen = tag_line - type_line - strlen("type \n"); + if (typelen >= sizeof(type)) + return -1; + memcpy(type, type_line+5, typelen); + type[typelen] = 0; + + /* Verify that the object matches */ + if (get_sha1_hex(object + 7, sha1)) + return -1; + if (verify_object(sha1, type)) + return -1; + + /* Verify the tag-name: we don't allow control characters or spaces in it */ + tag_line += 4; + for (;;) { + unsigned char c = *tag_line++; + if (c == '\n') + break; + if (c > ' ') + continue; + return -1; + } + + /* The actual stuff afterwards we don't care about.. */ + return 0; +} + +int main(int argc, char **argv) +{ + unsigned long size; + char buffer[MAXSIZE]; + unsigned char result_sha1[20]; + + if (argc != 1) + usage("cat | git-mktag"); + + // Read the signature + size = read(0, buffer, MAXSIZE); + + // Verify it for some basic sanity: it needs to start with "object \ntype " + if (verify_tag(buffer, size) < 0) + die("invalid tag signature file"); + + if (write_sha1_file(buffer, size, "tag", result_sha1) < 0) + die("unable to write tag file"); + printf("%s\n", sha1_to_hex(result_sha1)); + return 0; +} diff --git a/show-diff.c b/show-diff.c deleted file mode 100644 index fdd7dd4b..00000000 --- a/show-diff.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * GIT - The information manager from hell - * - * Copyright (C) Linus Torvalds, 2005 - */ -#include "cache.h" -#include "diff.h" - -static const char *show_diff_usage = -"show-diff [-p] [-q] [-r] [-z] [paths...]"; - -static int generate_patch = 0; -static int line_termination = '\n'; -static int silent = 0; - -static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt) -{ - int i; - int namelen = ce_namelen(ce); - for (i = 0; i < cnt; i++) { - int speclen = strlen(spec[i]); - if (! strncmp(spec[i], ce->name, speclen) && - speclen <= namelen && - (ce->name[speclen] == 0 || - ce->name[speclen] == '/')) - return 1; - } - return 0; -} - -static void show_unmerge(const char *path) -{ - if (generate_patch) - diff_unmerge(path); - else - printf("U %s%c", path, line_termination); -} - -static void show_file(int pfx, struct cache_entry *ce) -{ - if (generate_patch) - diff_addremove(pfx, ntohl(ce->ce_mode), ce->sha1, - ce->name, NULL); - else - printf("%c%06o\t%s\t%s\t%s%c", - pfx, ntohl(ce->ce_mode), "blob", - sha1_to_hex(ce->sha1), ce->name, line_termination); -} - -static void show_modified(int oldmode, int mode, - const char *old_sha1, const char *sha1, - char *path) -{ - char old_sha1_hex[41]; - strcpy(old_sha1_hex, sha1_to_hex(old_sha1)); - - if (generate_patch) - diff_change(oldmode, mode, old_sha1, sha1, path, NULL); - else - printf("*%06o->%06o\tblob\t%s->%s\t%s%c", - oldmode, mode, old_sha1_hex, sha1_to_hex(sha1), path, - line_termination); -} - -int main(int argc, char **argv) -{ - static const char null_sha1[20] = { 0, }; - int entries = read_cache(); - int i; - - while (1 < argc && argv[1][0] == '-') { - if (!strcmp(argv[1], "-p")) - generate_patch = 1; - else if (!strcmp(argv[1], "-q")) - silent = 1; - else if (!strcmp(argv[1], "-r")) - ; /* no-op */ - else if (!strcmp(argv[1], "-s")) - ; /* no-op */ - else if (!strcmp(argv[1], "-z")) - line_termination = 0; - else - usage(show_diff_usage); - argv++; argc--; - } - - /* At this point, if argc == 1, then we are doing everything. - * Otherwise argv[1] .. argv[argc-1] have the explicit paths. - */ - if (entries < 0) { - perror("read_cache"); - exit(1); - } - - for (i = 0; i < entries; i++) { - struct stat st; - unsigned int oldmode, mode; - struct cache_entry *ce = active_cache[i]; - int changed; - - if (1 < argc && - ! matches_pathspec(ce, argv+1, argc-1)) - continue; - - if (ce_stage(ce)) { - show_unmerge(ce->name); - while (i < entries && - !strcmp(ce->name, active_cache[i]->name)) - i++; - i--; /* compensate for loop control increments */ - continue; - } - - if (stat(ce->name, &st) < 0) { - if (errno != ENOENT) { - perror(ce->name); - continue; - } - if (silent) - continue; - show_file('-', ce); - continue; - } - changed = cache_match_stat(ce, &st); - if (!changed) - continue; - - oldmode = ntohl(ce->ce_mode); - mode = S_IFREG | ce_permissions(st.st_mode); - - show_modified(oldmode, mode, ce->sha1, null_sha1, - ce->name); - } - return 0; -}