@@ -50,6 +50,7 @@ static int add_revision(struct log_state *s, const char *revstr);
50
50
/** log_options holds other command line options that affect log output */
51
51
struct log_options {
52
52
int show_diff ;
53
+ int show_oneline ;
53
54
int show_log_size ;
54
55
int skip , limit ;
55
56
int min_parents , max_parents ;
@@ -81,9 +82,11 @@ int lg2_log(git_repository *repo, int argc, char *argv[])
81
82
git_commit * commit = NULL ;
82
83
git_pathspec * ps = NULL ;
83
84
85
+ memset (& s , 0 , sizeof (s ));
86
+
84
87
/** Parse arguments and set up revwalker. */
85
- last_arg = parse_options (& s , & opt , argc , argv );
86
88
s .repo = repo ;
89
+ last_arg = parse_options (& s , & opt , argc , argv );
87
90
88
91
diffopts .pathspec .strings = & argv [last_arg ];
89
92
diffopts .pathspec .count = argc - last_arg ;
@@ -335,34 +338,45 @@ static void print_commit(git_commit *commit, struct log_options *opts)
335
338
const char * scan , * eol ;
336
339
337
340
git_oid_tostr (buf , sizeof (buf ), git_commit_id (commit ));
338
- printf ("commit %s\n" , buf );
339
341
340
- if (opts -> show_log_size ) {
341
- printf ("log size %d\n" , (int )strlen (git_commit_message (commit )));
342
- }
342
+ if (opts -> show_oneline ) {
343
+ printf ("%s " , buf );
344
+ } else {
345
+ printf ("commit %s\n" , buf );
343
346
344
- if ((count = (int )git_commit_parentcount (commit )) > 1 ) {
345
- printf ("Merge:" );
346
- for (i = 0 ; i < count ; ++ i ) {
347
- git_oid_tostr (buf , 8 , git_commit_parent_id (commit , i ));
348
- printf (" %s" , buf );
347
+ if (opts -> show_log_size ) {
348
+ printf ("log size %d\n" , (int )strlen (git_commit_message (commit )));
349
+ }
350
+
351
+ if ((count = (int )git_commit_parentcount (commit )) > 1 ) {
352
+ printf ("Merge:" );
353
+ for (i = 0 ; i < count ; ++ i ) {
354
+ git_oid_tostr (buf , 8 , git_commit_parent_id (commit , i ));
355
+ printf (" %s" , buf );
356
+ }
357
+ printf ("\n" );
349
358
}
350
- printf ("\n" );
351
- }
352
359
353
- if ((sig = git_commit_author (commit )) != NULL ) {
354
- printf ("Author: %s <%s>\n" , sig -> name , sig -> email );
355
- print_time (& sig -> when , "Date: " );
360
+ if ((sig = git_commit_author (commit )) != NULL ) {
361
+ printf ("Author: %s <%s>\n" , sig -> name , sig -> email );
362
+ print_time (& sig -> when , "Date: " );
363
+ }
364
+ printf ("\n" );
356
365
}
357
- printf ("\n" );
358
366
359
367
for (scan = git_commit_message (commit ); scan && * scan ; ) {
360
368
for (eol = scan ; * eol && * eol != '\n' ; ++ eol ) /* find eol */ ;
361
369
362
- printf (" %.*s\n" , (int )(eol - scan ), scan );
370
+ if (opts -> show_oneline )
371
+ printf ("%.*s\n" , (int )(eol - scan ), scan );
372
+ else
373
+ printf (" %.*s\n" , (int )(eol - scan ), scan );
363
374
scan = * eol ? eol + 1 : NULL ;
375
+ if (opts -> show_oneline )
376
+ break ;
364
377
}
365
- printf ("\n" );
378
+ if (!opts -> show_oneline )
379
+ printf ("\n" );
366
380
}
367
381
368
382
/** Helper to find how many files in a commit changed from its nth parent. */
@@ -407,8 +421,6 @@ static int parse_options(
407
421
struct log_state * s , struct log_options * opt , int argc , char * * argv )
408
422
{
409
423
struct args_info args = ARGS_INFO_INIT ;
410
-
411
- memset (s , 0 , sizeof (* s ));
412
424
s -> sorting = GIT_SORT_TIME ;
413
425
414
426
memset (opt , 0 , sizeof (* opt ));
@@ -424,7 +436,7 @@ static int parse_options(
424
436
else
425
437
/** Try failed revision parse as filename. */
426
438
break ;
427
- } else if (! match_arg_separator (& args )) {
439
+ } else if (match_arg_separator (& args )) {
428
440
break ;
429
441
}
430
442
else if (!strcmp (a , "--date-order" ))
@@ -474,6 +486,8 @@ static int parse_options(
474
486
opt -> show_diff = 1 ;
475
487
else if (!strcmp (a , "--log-size" ))
476
488
opt -> show_log_size = 1 ;
489
+ else if (!strcmp (a , "--oneline" ))
490
+ opt -> show_oneline = 1 ;
477
491
else
478
492
usage ("Unsupported argument" , a );
479
493
}
0 commit comments