@@ -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,6 +52,23 @@ 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_defaults (struct rev_info * rev )
53
73
{
54
74
rev -> abbrev = DEFAULT_ABBREV ;
@@ -68,17 +88,28 @@ static void cmd_log_init_defaults(struct rev_info *rev)
68
88
static void cmd_log_init_finish (int argc , const char * * argv , const char * prefix ,
69
89
struct rev_info * rev , struct setup_revision_opt * opt )
70
90
{
71
- int i ;
72
- int decoration_given = 0 ;
73
91
struct userformat_want w ;
74
- /*
75
- * Check for -h before setup_revisions(), or "git log -h" will
76
- * fail when run without a git directory.
77
- */
78
- if (argc == 2 && !strcmp (argv [1 ], "-h" ))
79
- usage (builtin_log_usage );
92
+ int quiet = 0 , source = 0 ;
93
+
94
+ const struct option builtin_log_options [] = {
95
+ OPT_BOOLEAN (0 , "quiet" , & quiet , "supress diff output" ),
96
+ OPT_BOOLEAN (0 , "source" , & source , "show source" ),
97
+ { OPTION_CALLBACK , 0 , "decorate" , NULL , NULL , "decorate options" ,
98
+ PARSE_OPT_OPTARG , decorate_callback },
99
+ OPT_END ()
100
+ };
101
+
102
+ argc = parse_options (argc , argv , prefix ,
103
+ builtin_log_options , builtin_log_usage ,
104
+ PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
105
+ PARSE_OPT_KEEP_DASHDASH );
106
+
80
107
argc = setup_revisions (argc , argv , rev , opt );
81
108
109
+ /* Any arguments at this point are not recognized */
110
+ if (argc > 1 )
111
+ die ("unrecognized argument: %s" , argv [1 ]);
112
+
82
113
memset (& w , 0 , sizeof (w ));
83
114
userformat_find_requirements (NULL , & w );
84
115
@@ -94,26 +125,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
94
125
if (rev -> diffopt .pathspec .nr != 1 )
95
126
usage ("git logs can only follow renames on one pathname at a time" );
96
127
}
97
- for (i = 1 ; i < argc ; i ++ ) {
98
- const char * arg = argv [i ];
99
- if (!strcmp (arg , "--decorate" )) {
100
- decoration_style = DECORATE_SHORT_REFS ;
101
- decoration_given = 1 ;
102
- } else if (!prefixcmp (arg , "--decorate=" )) {
103
- const char * v = skip_prefix (arg , "--decorate=" );
104
- decoration_style = parse_decoration_style (arg , v );
105
- if (decoration_style < 0 )
106
- die (_ ("invalid --decorate option: %s" ), arg );
107
- decoration_given = 1 ;
108
- } else if (!strcmp (arg , "--no-decorate" )) {
109
- decoration_style = 0 ;
110
- } else if (!strcmp (arg , "--source" )) {
111
- rev -> show_source = 1 ;
112
- } else if (!strcmp (arg , "-h" )) {
113
- usage (builtin_log_usage );
114
- } else
115
- die (_ ("unrecognized argument: %s" ), arg );
116
- }
128
+
129
+ if (source )
130
+ rev -> show_source = 1 ;
117
131
118
132
/*
119
133
* defeat log.decorate configuration interacting with --pretty=raw
0 commit comments