diff: parse separate options like -S foo · wolfpython/git@dea007f · GitHub
Skip to content

Commit dea007f

Browse files
moygitster
authored andcommitted
diff: parse separate options like -S foo
Change the option parsing logic in revision.c to accept separate forms like `-S foo' in addition to `-Sfoo'. The rest of git already accepted this form, but revision.c still used its own option parsing. Short options affected are -S<string>, -l<num> and -O<orderfile>, for which an empty string wouldn't make sense, hence -<option> <arg> isn't ambiguous. This patch does not handle --stat-name-width and --stat-width, which are special-cases where diff_long_opt do not apply. They are handled in a separate patch to ease review. Original patch by Matthieu Moy, plus refactoring by Jonathan Nieder. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 64fdc08 commit dea007f

5 files changed

Lines changed: 95 additions & 23 deletions

File tree

diff.c

Lines changed: 71 additions & 16 deletions

diff.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ extern void diff_unmerge(struct diff_options *,
214214
#define DIFF_SETUP_USE_CACHE 2
215215
#define DIFF_SETUP_USE_SIZE_CACHE 4
216216

217+
/*
218+
* Poor man's alternative to parse-option, to allow both sticked form
219+
* (--option=value) and separate form (--option value).
220+
*/
221+
extern int parse_long_opt(const char *opt, const char **argv,
222+
const char **optarg);
223+
217224
extern int git_diff_basic_config(const char *var, const char *value, void *cb);
218225
extern int git_diff_ui_config(const char *var, const char *value, void *cb);
219226
extern int diff_use_color_default;

t/t4013-diff-various.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ log -p --first-parent master
208208
log -m -p --first-parent master
209209
log -m -p master
210210
log -SF master
211+
log -S F master
211212
log -SF -p master
212213
log --decorate --all
213214
log --decorate=full --all
@@ -282,4 +283,8 @@ diff master master^ side
282283
diff --dirstat master~1 master~2
283284
EOF
284285

286+
test_expect_success 'log -S requires an argument' '
287+
test_must_fail git log -S
288+
'
289+
285290
test_done

t/t4013/diff.log_-S_F_master

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$ git log -S F master
2+
commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
3+
Author: A U Thor <author@example.com>
4+
Date: Mon Jun 26 00:02:00 2006 +0000
5+
6+
Third
7+
$

t/t4202-log.sh

Lines changed: 5 additions & 7 deletions

0 commit comments

Comments
 (0)