@@ -25,12 +25,15 @@ static const char *default_date_mode = NULL;
25
25
26
26
static int default_show_root = 1 ;
27
27
static int decoration_style ;
28
+ static int decoration_given ;
28
29
static const char * fmt_patch_subject_prefix = "PATCH" ;
29
30
static const char * fmt_pretty ;
30
31
31
- static const char * const builtin_log_usage =
32
+ static const char * const builtin_log_usage [] = {
32
33
"git log [<options>] [<since>..<until>] [[--] <path>...]\n"
33
- " or: git show [options] <object>..." ;
34
+ " or: git show [options] <object>..." ,
35
+ NULL
36
+ };
34
37
35
38
static int parse_decoration_style (const char * var , const char * value )
36
39
{
@@ -49,12 +52,41 @@ static int parse_decoration_style(const char *var, const char *value)
49
52
return -1 ;
50
53
}
51
54
55
+ static int decorate_callback (const struct option * opt , const char * arg , int unset )
56
+ {
57
+ if (unset )
58
+ decoration_style = 0 ;
59
+ else if (arg )
60
+ decoration_style = parse_decoration_style ("command line" , arg );
61
+ else
62
+ decoration_style = DECORATE_SHORT_REFS ;
63
+
64
+ if (decoration_style < 0 )
65
+ die ("invalid --decorate option: %s" , arg );
66
+
67
+ decoration_given = 1 ;
68
+
69
+ return 0 ;
70
+ }
71
+
52
72
static void cmd_log_init (int argc , const char * * argv , const char * prefix ,
53
73
struct rev_info * rev , struct setup_revision_opt * opt )
54
74
{
55
- int i ;
56
- int decoration_given = 0 ;
57
75
struct userformat_want w ;
76
+ int quiet = 0 , source = 0 ;
77
+
78
+ const struct option builtin_log_options [] = {
79
+ OPT_BOOLEAN (0 , "quiet" , & quiet , "supress diff output" ),
80
+ OPT_BOOLEAN (0 , "source" , & source , "show source" ),
81
+ { OPTION_CALLBACK , 0 , "decorate" , NULL , NULL , "decorate options" ,
82
+ PARSE_OPT_OPTARG , decorate_callback },
83
+ OPT_END ()
84
+ };
85
+
86
+ argc = parse_options (argc , argv , prefix ,
87
+ builtin_log_options , builtin_log_usage ,
88
+ PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
89
+ PARSE_OPT_KEEP_DASHDASH );
58
90
59
91
rev -> abbrev = DEFAULT_ABBREV ;
60
92
rev -> commit_format = CMIT_FMT_DEFAULT ;
@@ -69,14 +101,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
69
101
if (default_date_mode )
70
102
rev -> date_mode = parse_date_format (default_date_mode );
71
103
72
- /*
73
- * Check for -h before setup_revisions(), or "git log -h" will
74
- * fail when run without a git directory.
75
- */
76
- if (argc == 2 && !strcmp (argv [1 ], "-h" ))
77
- usage (builtin_log_usage );
78
104
argc = setup_revisions (argc , argv , rev , opt );
79
105
106
+ /* Any arguments at this point are not recognized */
107
+ if (argc > 1 )
108
+ die ("unrecognized argument: %s" , argv [1 ]);
109
+
80
110
memset (& w , 0 , sizeof (w ));
81
111
userformat_find_requirements (NULL , & w );
82
112
@@ -92,26 +122,9 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
92
122
if (rev -> diffopt .nr_paths != 1 )
93
123
usage ("git logs can only follow renames on one pathname at a time" );
94
124
}
95
- for (i = 1 ; i < argc ; i ++ ) {
96
- const char * arg = argv [i ];
97
- if (!strcmp (arg , "--decorate" )) {
98
- decoration_style = DECORATE_SHORT_REFS ;
99
- decoration_given = 1 ;
100
- } else if (!prefixcmp (arg , "--decorate=" )) {
101
- const char * v = skip_prefix (arg , "--decorate=" );
102
- decoration_style = parse_decoration_style (arg , v );
103
- if (decoration_style < 0 )
104
- die ("invalid --decorate option: %s" , arg );
105
- decoration_given = 1 ;
106
- } else if (!strcmp (arg , "--no-decorate" )) {
107
- decoration_style = 0 ;
108
- } else if (!strcmp (arg , "--source" )) {
109
- rev -> show_source = 1 ;
110
- } else if (!strcmp (arg , "-h" )) {
111
- usage (builtin_log_usage );
112
- } else
113
- die ("unrecognized argument: %s" , arg );
114
- }
125
+
126
+ if (source )
127
+ rev -> show_source = 1 ;
115
128
116
129
/*
117
130
* defeat log.decorate configuration interacting with --pretty=raw
0 commit comments