@matheusbsbs / matheus-bagliano / commits / 9c2e7c0ca2
Fork 0

hash-object: -- and --help

It was cumbersome to feed hash-object the file '-t' (you could have said "./-t", though). Teach it '--' that terminates the option list, like everybody else. There is no way to extract usage string from the command either, so teach it "--help" as well. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 5, 2005 at 22:29 UTC 9c2e7c0ca240e1508871cd22f2ee380f52d69a53
1 file changed +22 -10
hash-object.c
+22 -10
@@ -31,19 +31,30 @@ int main(int argc, char **argv)
31 int write_object = 0;
32 const char *prefix = NULL;
33 int prefix_length = -1;
34 + int no_more_flags = 0;
35
36 for (i = 1 ; i < argc; i++) {
36 - if (!strcmp(argv[i], "-t")) {
37 - if (argc <= ++i)
38 - die(hash_object_usage);
39 - type = argv[i];
40 - }
41 - else if (!strcmp(argv[i], "-w")) {
42 - if (prefix_length < 0) {
43 - prefix = setup_git_directory();
44 - prefix_length = prefix ? strlen(prefix) : 0;
37 + if (!no_more_flags && argv[i][0] == '-') {
38 + if (!strcmp(argv[i], "-t")) {
39 + if (argc <= ++i)
40 + die(hash_object_usage);
41 + type = argv[i];
42 + }
43 + else if (!strcmp(argv[i], "-w")) {
44 + if (prefix_length < 0) {
45 + prefix = setup_git_directory();
46 + prefix_length =
47 + prefix ? strlen(prefix) : 0;
48 + }
49 + write_object = 1;
50 }
46 - write_object = 1;
51 + else if (!strcmp(argv[i], "--")) {
52 + no_more_flags = 1;
53 + }
54 + else if (!strcmp(argv[i], "--help"))
55 + usage(hash_object_usage);
56 + else
57 + die(hash_object_usage);
58 }
59 else {
60 const char *arg = argv[i];
@@ -51,6 +62,7 @@ int main(int argc, char **argv)
62 arg = prefix_filename(prefix, prefix_length,
63 arg);
64 hash_object(arg, type, write_object);
65 + no_more_flags = 1;
66 }
67 }
68 return 0;