Skip to content

Commit

Permalink
Separate object name errors from usage errors
Browse files Browse the repository at this point in the history
Separate object name errors from usage errors.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Dmitry V. Levin authored and Junio C Hamano committed May 8, 2006
1 parent afb4ff2 commit 31fff30
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 25 deletions.
7 changes: 4 additions & 3 deletions cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ int main(int argc, char **argv)

setup_git_directory();
git_config(git_default_config);
if (argc != 3 || get_sha1(argv[2], sha1))
if (argc != 3)
usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
if (get_sha1(argv[2], sha1))
die("Not a valid object name %s", argv[2]);

opt = 0;
if ( argv[1][0] == '-' ) {
Expand Down Expand Up @@ -133,8 +135,7 @@ int main(int argc, char **argv)
return !has_sha1_file(sha1);

case 'p':
if (get_sha1(argv[2], sha1) ||
sha1_object_info(sha1, type, NULL))
if (sha1_object_info(sha1, type, NULL))
die("Not a valid object name %s", argv[2]);

/* custom pretty-print here */
Expand Down
8 changes: 6 additions & 2 deletions commit-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,19 @@ int main(int argc, char **argv)

git_config(git_default_config);

if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0)
if (argc < 2)
usage(commit_tree_usage);
if (get_sha1(argv[1], tree_sha1))
die("Not a valid object name %s", argv[1]);

check_valid(tree_sha1, tree_type);
for (i = 2; i < argc; i += 2) {
char *a, *b;
a = argv[i]; b = argv[i+1];
if (!b || strcmp(a, "-p") || get_sha1(b, parent_sha1[parents]))
if (!b || strcmp(a, "-p"))
usage(commit_tree_usage);
if (get_sha1(b, parent_sha1[parents]))
die("Not a valid object name %s", b);
check_valid(parent_sha1[parents], commit_type);
if (new_parent(parents))
parents++;
Expand Down
4 changes: 3 additions & 1 deletion convert-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,10 @@ int main(int argc, char **argv)

setup_git_directory();

if (argc != 2 || get_sha1(argv[1], sha1))
if (argc != 2)
usage("git-convert-objects <sha1>");
if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);

entry = convert_entry(sha1);
printf("new sha1: %s\n", sha1_to_hex(entry->new_sha1));
Expand Down
6 changes: 3 additions & 3 deletions describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ static void describe(char *arg, int last_one)
static int initialized = 0;
struct commit_name *n;

if (get_sha1(arg, sha1) < 0)
usage(describe_usage);
if (get_sha1(arg, sha1))
die("Not a valid object name %s", arg);
cmit = lookup_commit_reference(sha1);
if (!cmit)
usage(describe_usage);
die("%s is not a valid '%s' object", arg, commit_type);

if (!initialized) {
initialized = 1;
Expand Down
4 changes: 2 additions & 2 deletions ls-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ int main(int argc, const char **argv)

if (argc < 2)
usage(ls_tree_usage);
if (get_sha1(argv[1], sha1) < 0)
usage(ls_tree_usage);
if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);

pathspec = get_pathspec(prefix, argv + 2);
tree = parse_tree_indirect(sha1);
Expand Down
8 changes: 5 additions & 3 deletions merge-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,12 @@ int main(int argc, char **argv)
usage(merge_base_usage);
argc--; argv++;
}
if (argc != 3 ||
get_sha1(argv[1], rev1key) ||
get_sha1(argv[2], rev2key))
if (argc != 3)
usage(merge_base_usage);
if (get_sha1(argv[1], rev1key))
die("Not a valid object name %s", argv[1]);
if (get_sha1(argv[2], rev2key))
die("Not a valid object name %s", argv[2]);
rev1 = lookup_commit_reference(rev1key);
rev2 = lookup_commit_reference(rev2key);
if (!rev1 || !rev2)
Expand Down
2 changes: 1 addition & 1 deletion merge-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
unsigned char sha1[20];
void *buf;

if (get_sha1(rev, sha1) < 0)
if (get_sha1(rev, sha1))
die("unknown rev %s", rev);
buf = fill_tree_descriptor(desc, sha1);
if (!buf)
Expand Down
4 changes: 2 additions & 2 deletions read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ int main(int argc, char **argv)
if (1 < index_only + update)
usage(read_tree_usage);

if (get_sha1(arg, sha1) < 0)
usage(read_tree_usage);
if (get_sha1(arg, sha1))
die("Not a valid object name %s", arg);
if (list_tree(sha1) < 0)
die("failed to unpack tree object %s", arg);
stage++;
Expand Down
4 changes: 2 additions & 2 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
local_flags = UNINTERESTING;
arg++;
}
if (get_sha1(arg, sha1) < 0) {
if (get_sha1(arg, sha1)) {
int j;

if (seen_dashdash || local_flags)
Expand All @@ -693,7 +693,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
if (def && !revs->commits) {
unsigned char sha1[20];
struct commit *commit;
if (get_sha1(def, sha1) < 0)
if (get_sha1(def, sha1))
die("bad default revision '%s'", def);
commit = get_commit_reference(revs, def, sha1, 0);
add_one_commit(commit, revs);
Expand Down
2 changes: 1 addition & 1 deletion ssh-upload.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int main(int argc, char **argv)
commit_id = argv[arg];
url = argv[arg + 1];
if (get_sha1(commit_id, sha1))
usage(ssh_push_usage);
die("Not a valid object name %s", commit_id);
memcpy(hex, sha1_to_hex(sha1), sizeof(hex));
argv[arg] = hex;

Expand Down
4 changes: 2 additions & 2 deletions tar-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ int main(int argc, char **argv)
strbuf_append_string(&current_path, "/");
/* FALLTHROUGH */
case 2:
if (get_sha1(argv[1], sha1) < 0)
usage(tar_tree_usage);
if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);
break;
default:
usage(tar_tree_usage);
Expand Down
4 changes: 3 additions & 1 deletion unpack-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ int main(int argc, char **argv)
{
unsigned char sha1[20];

if (argc != 2 || get_sha1(argv[1], sha1))
if (argc != 2)
usage("git-unpack-file <sha1>");
if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);

setup_git_directory();
git_config(git_default_config);
Expand Down
4 changes: 2 additions & 2 deletions update-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ int main(int argc, char **argv)
refname = argv[1];
value = argv[2];
oldval = argv[3];
if (get_sha1(value, sha1) < 0)
if (get_sha1(value, sha1))
die("%s: not a valid SHA1", value);
memset(oldsha1, 0, 20);
if (oldval && get_sha1(oldval, oldsha1) < 0)
if (oldval && get_sha1(oldval, oldsha1))
die("%s: not a valid old SHA1", oldval);

path = resolve_ref(git_path("%s", refname), currsha1, !!oldval);
Expand Down

0 comments on commit 31fff30

Please sign in to comment.