Merge branch 'mg/reflog-with-options'
* mg/reflog-with-options: reflog: fix overriding of command line options t/t1411: test reflog with formats builtin/log.c: separate default and setup of cmd_log_init()
This commit is contained in:
		@ -49,13 +49,8 @@ static int parse_decoration_style(const char *var, const char *value)
 | 
				
			|||||||
	return -1;
 | 
						return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void cmd_log_init(int argc, const char **argv, const char *prefix,
 | 
					static void cmd_log_init_defaults(struct rev_info *rev)
 | 
				
			||||||
			 struct rev_info *rev, struct setup_revision_opt *opt)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i;
 | 
					 | 
				
			||||||
	int decoration_given = 0;
 | 
					 | 
				
			||||||
	struct userformat_want w;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	rev->abbrev = DEFAULT_ABBREV;
 | 
						rev->abbrev = DEFAULT_ABBREV;
 | 
				
			||||||
	rev->commit_format = CMIT_FMT_DEFAULT;
 | 
						rev->commit_format = CMIT_FMT_DEFAULT;
 | 
				
			||||||
	if (fmt_pretty)
 | 
						if (fmt_pretty)
 | 
				
			||||||
@ -68,7 +63,14 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (default_date_mode)
 | 
						if (default_date_mode)
 | 
				
			||||||
		rev->date_mode = parse_date_format(default_date_mode);
 | 
							rev->date_mode = parse_date_format(default_date_mode);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 | 
				
			||||||
 | 
								 struct rev_info *rev, struct setup_revision_opt *opt)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						int decoration_given = 0;
 | 
				
			||||||
 | 
						struct userformat_want w;
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Check for -h before setup_revisions(), or "git log -h" will
 | 
						 * Check for -h before setup_revisions(), or "git log -h" will
 | 
				
			||||||
	 * fail when run without a git directory.
 | 
						 * fail when run without a git directory.
 | 
				
			||||||
@ -128,6 +130,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 | 
				
			|||||||
	setup_pager();
 | 
						setup_pager();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void cmd_log_init(int argc, const char **argv, const char *prefix,
 | 
				
			||||||
 | 
								 struct rev_info *rev, struct setup_revision_opt *opt)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						cmd_log_init_defaults(rev);
 | 
				
			||||||
 | 
						cmd_log_init_finish(argc, argv, prefix, rev, opt);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * This gives a rough estimate for how many commits we
 | 
					 * This gives a rough estimate for how many commits we
 | 
				
			||||||
 * will print out in the list.
 | 
					 * will print out in the list.
 | 
				
			||||||
@ -486,16 +495,11 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
 | 
				
			|||||||
	rev.verbose_header = 1;
 | 
						rev.verbose_header = 1;
 | 
				
			||||||
	memset(&opt, 0, sizeof(opt));
 | 
						memset(&opt, 0, sizeof(opt));
 | 
				
			||||||
	opt.def = "HEAD";
 | 
						opt.def = "HEAD";
 | 
				
			||||||
	cmd_log_init(argc, argv, prefix, &rev, &opt);
 | 
						cmd_log_init_defaults(&rev);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	 * This means that we override whatever commit format the user gave
 | 
					 | 
				
			||||||
	 * on the cmd line.  Sad, but cmd_log_init() currently doesn't
 | 
					 | 
				
			||||||
	 * allow us to set a different default.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	rev.commit_format = CMIT_FMT_ONELINE;
 | 
						rev.commit_format = CMIT_FMT_ONELINE;
 | 
				
			||||||
	rev.use_terminator = 1;
 | 
						rev.use_terminator = 1;
 | 
				
			||||||
	rev.always_show_header = 1;
 | 
						rev.always_show_header = 1;
 | 
				
			||||||
 | 
						cmd_log_init_finish(argc, argv, prefix, &rev, &opt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return cmd_log_walk(&rev);
 | 
						return cmd_log_walk(&rev);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -28,6 +28,24 @@ test_expect_success 'oneline reflog format' '
 | 
				
			|||||||
	test_cmp expect actual
 | 
						test_cmp expect actual
 | 
				
			||||||
'
 | 
					'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test_expect_success 'reflog default format' '
 | 
				
			||||||
 | 
						git reflog -1 >actual &&
 | 
				
			||||||
 | 
						test_cmp expect actual
 | 
				
			||||||
 | 
					'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cat >expect <<'EOF'
 | 
				
			||||||
 | 
					commit e46513e
 | 
				
			||||||
 | 
					Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
 | 
				
			||||||
 | 
					Reflog message: commit (initial): one
 | 
				
			||||||
 | 
					Author: A U Thor <author@example.com>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    one
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					test_expect_success 'override reflog default format' '
 | 
				
			||||||
 | 
						git reflog --format=short -1 >actual &&
 | 
				
			||||||
 | 
						test_cmp expect actual
 | 
				
			||||||
 | 
					'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cat >expect <<'EOF'
 | 
					cat >expect <<'EOF'
 | 
				
			||||||
Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
 | 
					Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
 | 
				
			||||||
Reflog message: commit (initial): one
 | 
					Reflog message: commit (initial): one
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user