revisions: refactor init_revisions and setup_revisions.
PATCH 1/1 revisions: refactor init_revisions and setup_revisions.
struct rev_info gains two new field:
* .def to store --default argument;
* .show_merge 1-bit field.
The refactor consists into the following steps:
* init_revisions now takes the --default argument to initialize .def properly, instead of getting it through setup_revisions.
* setup_revisions has been split in two: parse_revisions that does (almost) only argument parsing, to be more like what parse-options can do, and setup_revisions that does the rest.
Many places had no arguments to pass to setup_revisions, and those don't use parse_revisions at all.
---
This is a required patch for revisions parse-optification that splits the logic of revision arguments parsing in parsing, and post-processing.
The aim is to replace parsing with parse-opt at some point.
The final version (using parse-options) will probably need more rework in revisions.[hc], but I'd like to avoid rebasing this patch over and over, and I'd be glad if it's merged now, as it's not _that_ intrusive.
I've been using a git with this patch for a week without issues.
builtin-add.c | 4 ++-- builtin-blame.c | 5 +++-- builtin-checkout.c | 7 ++++--- builtin-commit.c | 8 ++++---- builtin-diff-files.c | 8 +++++--- builtin-diff-index.c | 5 +++-- builtin-diff-tree.c | 5 +++-- builtin-diff.c | 8 +++++--- builtin-fast-export.c | 5 +++-- builtin-fmt-merge-msg.c | 4 ++-- builtin-log.c | 20 +++++++++++--------- builtin-pack-objects.c | 5 +++-- builtin-prune.c | 2 +- builtin-reflog.c | 2 +- builtin-rev-list.c | 5 +++-- builtin-revert.c | 4 ++-- builtin-shortlog.c | 5 +++-- bundle.c | 10 ++++++---- diff-lib.c | 2 +- http-push.c | 5 +++-- revision.c | 36 +++++++++++++++++++----------------- revision.h | 7 +++++-- upload-pack.c | 6 +++--- wt-status.c | 12 ++++++------ 24 files changed, 101 insertions(+), 79 deletions(-)
builtin-add.c +2 -2
@@ -108,8 +108,8 @@ static void update_callback(struct diff_queue_struct *q,void add_files_to_cache (int verbose,const char *prefix,const char **pathspec) {struct rev_info rev; -init_revisions (&rev, prefix); -setup_revisions (0 ,NULL , &rev,NULL ); +init_revisions (&rev, prefix,NULL ); +setup_revisions (&rev); rev.prune_data = pathspec; rev.diffopt.output_format =DIFF_FORMAT_CALLBACK ; rev.diffopt.format_callback = update_callback;
builtin-blame.c +3 -2
@@ -2323,8 +2323,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix) argv[unk++] ="--" ;/* terminate the rev name */ argv[unk] =NULL ; -init_revisions (&revs,NULL ); -setup_revisions (unk, argv, &revs,NULL ); +init_revisions (&revs,NULL ,NULL ); +parse_revisions (unk, argv, &revs); +setup_revisions (&revs);memset (&sb,0 ,sizeof (sb));/*
builtin-checkout.c +4 -3
@@ -130,7 +130,7 @@ static void show_local_changes(struct object *head) {struct rev_info rev;/* I think we want full paths, even if we're in a subdirectory. */ -init_revisions (&rev,NULL ); +init_revisions (&rev,NULL ,NULL ); rev.abbrev =0 ; rev.diffopt.output_format |=DIFF_FORMAT_NAME_STATUS ;add_pending_object (&rev, head,NULL );
@@ -345,8 +345,9 @@ static void report_tracking(struct branch_info *new, struct checkout_opts *opts)strcpy (symmetric +40 ,"..." );strcpy (symmetric +43 ,sha1_to_hex (theirs->object.sha1)); -init_revisions (&revs,NULL ); -setup_revisions (rev_argc, rev_argv, &revs,NULL ); +init_revisions (&revs,NULL ,NULL ); +parse_revisions (rev_argc, rev_argv, &revs); +setup_revisions (&revs);prepare_revision_walk (&revs);/* ... and count the commits on each side. */
builtin-commit.c +4 -4
@@ -522,9 +522,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix)if (get_sha1 (parent, sha1)) commitable = !!active_nr;else { -init_revisions (&rev,"" ); +init_revisions (&rev,"" , parent); rev.abbrev =0 ; -setup_revisions (0 ,NULL , &rev, parent); +setup_revisions (&rev);DIFF_OPT_SET (&rev.diffopt,QUIET );DIFF_OPT_SET (&rev.diffopt,EXIT_WITH_STATUS );run_diff_index (&rev,1 /* cached */ );
@@ -798,8 +798,8 @@ static void print_summary(const char *prefix, const unsigned char *sha1)if (!commit ||parse_commit (commit))die ("could not parse newly created commit" ); -init_revisions (&rev, prefix); -setup_revisions (0 ,NULL , &rev,NULL ); +init_revisions (&rev, prefix,NULL ); +setup_revisions (&rev); rev.abbrev =0 ; rev.diff =1 ;
builtin-diff-files.c +5 -3
@@ -20,14 +20,16 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)int result; prefix =setup_git_directory_gently (&nongit); -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,NULL );git_config (git_diff_basic_config);/* no "diff" UI options */ rev.abbrev =0 ;if (!setup_diff_no_index (&rev, argc, argv, nongit, prefix)) argc =0 ; -else - argc =setup_revisions (argc, argv, &rev,NULL ); +else { + argc =parse_revisions (argc, argv, &rev); +setup_revisions (&rev); + }if (!rev.diffopt.output_format) rev.diffopt.output_format =DIFF_FORMAT_RAW ; result =run_diff_files_cmd (&rev, argc, argv);
builtin-diff-index.c +3 -2
@@ -16,11 +16,12 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)int i;int result; -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,NULL );git_config (git_diff_basic_config);/* no "diff" UI options */ rev.abbrev =0 ; - argc =setup_revisions (argc, argv, &rev,NULL ); + argc =parse_revisions (argc, argv, &rev); +setup_revisions (&rev);for (i =1 ; i < argc; i++) {const char *arg = argv[i];
builtin-diff-tree.c +3 -2
@@ -67,12 +67,13 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)static struct rev_info *opt = &log_tree_opt;int read_stdin =0 ; -init_revisions (opt, prefix); +init_revisions (opt, prefix,NULL );git_config (git_diff_basic_config);/* no "diff" UI options */ nr_sha1 =0 ; opt->abbrev =0 ; opt->diff =1 ; - argc =setup_revisions (argc, argv, opt,NULL ); + argc =parse_revisions (argc, argv, opt); +setup_revisions (opt);while (--argc >0 ) {const char *arg = *++argv;
builtin-diff.c +5 -3
@@ -239,13 +239,15 @@ int cmd_diff(int argc, const char **argv, const char *prefix)if (diff_use_color_default ==-1 ) diff_use_color_default = git_use_color_default; -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,NULL ); rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;if (!setup_diff_no_index (&rev, argc, argv, nongit, prefix)) argc =0 ; -else - argc =setup_revisions (argc, argv, &rev,NULL ); +else { + argc =parse_revisions (argc, argv, &rev); +setup_revisions (&rev); + }if (!rev.diffopt.output_format) { rev.diffopt.output_format =DIFF_FORMAT_PATCH ;if (diff_setup_done (&rev.diffopt) <0 )
builtin-fast-export.c +3 -2
@@ -374,8 +374,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)/* we handle encodings */ git_config (git_default_config); -init_revisions (&revs, prefix); - argc =setup_revisions (argc, argv, &revs,NULL ); +init_revisions (&revs, prefix,NULL ); + argc =parse_revisions (argc, argv, &revs); +setup_revisions (&revs); argc =parse_options (argc, argv, options, fast_export_usage,0 );if (argc >1 )usage_with_options (fast_export_usage, options);
builtin-fmt-merge-msg.c +2 -2
@@ -182,7 +182,7 @@ static void shortlog(const char *name, unsigned char *sha1,if (!branch || branch->type !=OBJ_COMMIT )return ; -setup_revisions (0 ,NULL , rev,NULL ); +setup_revisions (rev); rev->ignore_merges =1 ;add_pending_object (rev, branch, name);add_pending_object (rev, &head->object,"^HEAD" );
@@ -339,7 +339,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)struct rev_info rev; head =lookup_commit (head_sha1); -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,NULL ); rev.commit_format =CMIT_FMT_ONELINE ; rev.ignore_merges =1 ; rev.limited =1 ;
builtin-log.c +11 -9
@@ -58,7 +58,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,DIFF_OPT_SET (&rev->diffopt,RECURSIVE ); rev->show_root_diff = default_show_root; rev->subject_prefix = fmt_patch_subject_prefix; - argc =setup_revisions (argc, argv, rev,"HEAD" ); + argc =parse_revisions (argc, argv, rev); +setup_revisions (rev);if (rev->diffopt.pickaxe || rev->diffopt.filter) rev->always_show_header =0 ;if (DIFF_OPT_TST (&rev->diffopt,FOLLOW_RENAMES )) {
@@ -243,7 +244,7 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)if (diff_use_color_default ==-1 ) diff_use_color_default = git_use_color_default; -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,"HEAD" ); rev.diff =1 ; rev.simplify_history =0 ;cmd_log_init (argc, argv, prefix, &rev);
@@ -319,7 +320,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)if (diff_use_color_default ==-1 ) diff_use_color_default = git_use_color_default; -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,"HEAD" ); rev.diff =1 ; rev.combine_merges =1 ; rev.dense_combined_merges =1 ;
@@ -383,7 +384,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)if (diff_use_color_default ==-1 ) diff_use_color_default = git_use_color_default; -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,"HEAD" );init_reflog_walk (&rev.reflog_info); rev.abbrev_commit =1 ; rev.verbose_header =1 ;
@@ -415,7 +416,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)if (diff_use_color_default ==-1 ) diff_use_color_default = git_use_color_default; -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,"HEAD" ); rev.always_show_header =1 ;cmd_log_init (argc, argv, prefix, &rev);return cmd_log_walk (&rev);
@@ -601,7 +602,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const chainit_patch_ids (ids);/* given a range a..b get all patch ids for b..a */ -init_revisions (&check_rev, prefix); +init_revisions (&check_rev, prefix,NULL ); o1->flags ^=UNINTERESTING ; o2->flags ^=UNINTERESTING ;add_pending_object (&check_rev, o1,"o1" );
@@ -756,7 +757,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)struct strbuf buf;git_config (git_format_config); -init_revisions (&rev, prefix); +init_revisions (&rev, prefix,"HEAD" ); rev.commit_format =CMIT_FMT_EMAIL ; rev.verbose_header =1 ; rev.diff =1 ;
@@ -900,7 +901,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)if (numbered_files && use_stdout)die ("--numbered-files and --stdout are mutually exclusive." ); - argc =setup_revisions (argc, argv, &rev,"HEAD" ); + argc =parse_revisions (argc, argv, &rev); +setup_revisions (&rev);if (argc >1 )die ("unrecognized argument: %s" , argv[1 ]);
@@ -1095,7 +1097,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)usage (cherry_usage); } -init_revisions (&revs, prefix); +init_revisions (&revs, prefix,NULL ); revs.diff =1 ; revs.combine_merges =0 ; revs.ignore_merges =1 ;
builtin-pack-objects.c +3 -2
@@ -1871,9 +1871,10 @@ static void get_object_list(int ac, const char **av)char line[1000 ];int flags =0 ; -init_revisions (&revs,NULL ); +init_revisions (&revs,NULL ,NULL ); save_commit_buffer =0 ; -setup_revisions (ac, av, &revs,NULL ); +parse_revisions (ac, av, &revs); +setup_revisions (&revs);while (fgets (line,sizeof (line), stdin) !=NULL ) {int len =strlen (line);
builtin-prune.c +1 -1
@@ -146,7 +146,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix) } save_commit_buffer =0 ; -init_revisions (&revs, prefix); +init_revisions (&revs, prefix,NULL );mark_reachable_objects (&revs,1 );prune_object_dir (get_object_directory ());
builtin-reflog.c +1 -1
@@ -399,7 +399,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)break ; }if (cb.stalefix) { -init_revisions (&cb.revs, prefix); +init_revisions (&cb.revs, prefix,NULL );if (cb.verbose)printf ("Marking reachable objects..." );mark_reachable_objects (&cb.revs,0 );
builtin-rev-list.c +3 -2
@@ -546,10 +546,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)int quiet =0 ;git_config (git_default_config); -init_revisions (&revs, prefix); +init_revisions (&revs, prefix,NULL ); revs.abbrev =0 ; revs.commit_format =CMIT_FMT_UNSPECIFIED ; - argc =setup_revisions (argc, argv, &revs,NULL ); + argc =parse_revisions (argc, argv, &revs); +setup_revisions (&revs);for (i =1 ; i < argc; i++) {const char *arg = argv[i];
builtin-revert.c +2 -2
@@ -251,8 +251,8 @@ static char *help_msg(const unsigned char *sha1)static int index_is_dirty (void ) {struct rev_info rev; -init_revisions (&rev,NULL ); -setup_revisions (0 ,NULL , &rev,"HEAD" ); +init_revisions (&rev,NULL ,"HEAD" ); +setup_revisions (&rev);DIFF_OPT_SET (&rev.diffopt,QUIET );DIFF_OPT_SET (&rev.diffopt,EXIT_WITH_STATUS );run_diff_index (&rev,1 );
builtin-shortlog.c +3 -2
@@ -252,8 +252,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) argv++; argc--; } -init_revisions (&rev, prefix); - argc =setup_revisions (argc, argv, &rev,NULL ); +init_revisions (&rev, prefix,NULL ); + argc =parse_revisions (argc, argv, &rev); +setup_revisions (&rev);if (argc >1 )die ("unrecognized argument: %s" , argv[1 ]);
bundle.c +6 -4
@@ -104,7 +104,7 @@ int verify_bundle(struct bundle_header *header, int verbose)int i, ret =0 , req_nr;const char *message ="Repository lacks these prerequisite commits:" ; -init_revisions (&revs,NULL ); +init_revisions (&revs,NULL ,NULL );for (i =0 ; i < p->nr; i++) {struct ref_list_entry *e = p->list + i;struct object *o =parse_object (e->sha1);
@@ -120,7 +120,8 @@ int verify_bundle(struct bundle_header *header, int verbose)if (revs.pending.nr != p->nr)return ret; req_nr = revs.pending.nr; -setup_revisions (2 , argv, &revs,NULL ); +parse_revisions (2 , argv, &revs); +setup_revisions (&revs);memset (&refs,0 ,sizeof (struct object_array ));for (i =0 ; i < revs.pending.nr; i++) {
@@ -192,7 +193,7 @@ int create_bundle(struct bundle_header *header, const char *path,/* init revs to list objects for pack-objects later */ save_commit_buffer =0 ; -init_revisions (&revs,NULL ); +init_revisions (&revs,NULL ,NULL );/* write prerequisites */ memcpy (argv_boundary +3 , argv +1 , argc *sizeof (const char *));
@@ -226,7 +227,8 @@ int create_bundle(struct bundle_header *header, const char *path,return error ("rev-list died" );/* write references */ - argc =setup_revisions (argc, argv, &revs,NULL ); + argc =parse_revisions (argc, argv, &revs); +setup_revisions (&revs);if (argc >1 )return error ("unrecognized argument: %s'" , argv[1 ]);
diff-lib.c +1 -1
@@ -775,7 +775,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt) } active_nr = dst - active_cache; -init_revisions (&revs,NULL ); +init_revisions (&revs,NULL ,NULL ); revs.prune_data = opt->paths; tree =parse_tree_indirect (tree_sha1);if (!tree)
http-push.c +3 -2
@@ -2382,8 +2382,9 @@ int main(int argc, char **argv) commit_argv[3 ] = old_sha1_hex; commit_argc++; } -init_revisions (&revs,setup_git_directory ()); -setup_revisions (commit_argc, commit_argv, &revs,NULL ); +init_revisions (&revs,setup_git_directory (),NULL ); +parse_revisions (commit_argc, commit_argv, &revs); +setup_revisions (&revs);free (new_sha1_hex);if (old_sha1_hex) {free (old_sha1_hex);
revision.c +19 -17
@@ -717,7 +717,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)return 1 ; } -void init_revisions (struct rev_info *revs,const char *prefix) +void init_revisions (struct rev_info *revs,const char *prefix,const char *def) {memset (revs,0 ,sizeof (*revs));
@@ -731,6 +731,7 @@ void init_revisions(struct rev_info *revs, const char *prefix) revs->lifo =1 ; revs->dense =1 ; revs->prefix = prefix; + revs->def = def; revs->max_age =-1 ; revs->min_age =-1 ; revs->skip_count =-1 ;
@@ -892,8 +893,7 @@ static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token opt->regflags =REG_NEWLINE ; revs->grep_filter = opt; } -append_grep_pattern (revs->grep_filter, ptn, -"command line" ,0 , what); +append_grep_pattern (revs->grep_filter, ptn,"command line" ,0 , what); }static void add_header_grep (struct rev_info *revs,const char *field,const char *pattern)
@@ -936,9 +936,9 @@ static void add_ignore_packed(struct rev_info *revs, const char *name)* Returns the number of arguments left that weren't recognized * (which are also moved to the head of the argument list) */ -int setup_revisions (int argc,const char **argv,struct rev_info *revs,const char *def) +int parse_revisions (int argc,const char **argv,struct rev_info *revs) { -int i, flags, seen_dashdash, show_merge; +int i, flags, seen_dashdash;const char **unrecognized = argv +1 ;int left =1 ;int all_match =0 ;
@@ -959,7 +959,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const chbreak ; } - flags = show_merge =0 ; + flags =0 ;for (i =1 ; i < argc; i++) {const char *arg = argv[i];if (*arg =='-' ) {
@@ -1047,11 +1047,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const chif (!strcmp (arg,"--default" )) {if (++i >= argc)die ("bad --default argument" ); - def = argv[i]; + revs->def = argv[i];continue ; }if (!strcmp (arg,"--merge" )) { - show_merge =1 ; + revs->show_merge =1 ;continue ; }if (!strcmp (arg,"--topo-order" )) {
@@ -1315,18 +1315,23 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const chif (revs->grep_filter) { revs->grep_filter->regflags |= regflags; revs->grep_filter->fixed = fixed; + revs->grep_filter->all_match = all_match; } +return left; +} -if (show_merge) +void setup_revisions (struct rev_info *revs) +{ +if (revs->show_merge)prepare_show_merge (revs); -if (def && !revs->pending.nr) { +if (revs->def && !revs->pending.nr) {unsigned char sha1[20 ];struct object *object;unsigned mode; -if (get_sha1_with_mode (def, sha1, &mode)) -die ("bad default revision '%s'" , def); - object =get_reference (revs, def, sha1,0 ); -add_pending_object_with_mode (revs, object, def, mode); +if (get_sha1_with_mode (revs->def, sha1, &mode)) +die ("bad default revision '%s'" , revs->def); + object =get_reference (revs, revs->def, sha1,0 ); +add_pending_object_with_mode (revs, object, revs->def, mode); }/* Did the user ask for any diff output? Run the diff! */
@@ -1360,14 +1365,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const chdie ("diff_setup_done failed" );if (revs->grep_filter) { - revs->grep_filter->all_match = all_match;compile_grep_patterns (revs->grep_filter); }if (revs->reverse && revs->reflog_info)die ("cannot combine --reverse with --walk-reflogs" ); - -return left; }int prepare_revision_walk (struct rev_info *revs)
revision.h +5 -2
@@ -25,6 +25,7 @@ struct rev_info {/* Basic information */ const char *prefix; +const char *def;void *prune_data;unsigned int early_output;
@@ -64,6 +65,7 @@ struct rev_info {/* Format info */ unsigned int shown_one:1, + show_merge:1, abbrev_commit:1;enum date_mode date_mode;
@@ -108,8 +110,9 @@ struct rev_info {typedef void (*show_early_output_fn_t )(struct rev_info *,struct commit_list *);volatile show_early_output_fn_t show_early_output; -extern void init_revisions (struct rev_info *revs,const char *prefix); -extern int setup_revisions (int argc,const char **argv,struct rev_info *revs,const char *def); +extern void init_revisions (struct rev_info *revs,const char *prefix,const char *def); +extern int parse_revisions (int argc,const char **argv,struct rev_info *revs); +extern void setup_revisions (struct rev_info *revs);extern int handle_revision_arg (const char *arg,struct rev_info *revs,int flags,int cant_be_filename);extern int prepare_revision_walk (struct rev_info *revs);
upload-pack.c +3 -3
@@ -106,7 +106,7 @@ static int do_rev_list(int fd, void *create_full_pack) pack_pipe =fdopen (fd,"w" );if (create_full_pack) use_thin_pack =0 ;/* no point doing it */ -init_revisions (&revs,NULL ); +init_revisions (&revs,NULL ,NULL ); revs.tag_objects =1 ; revs.tree_objects =1 ; revs.blob_objects =1 ;
@@ -115,7 +115,7 @@ static int do_rev_list(int fd, void *create_full_pack)if (create_full_pack) {const char *args[] = {"rev-list" ,"--all" ,NULL }; -setup_revisions (2 , args, &revs,NULL ); +parse_revisions (2 , args, &revs); }else {for (i =0 ; i < want_obj.nr; i++) {struct object *o = want_obj.objects[i].item;
@@ -128,8 +128,8 @@ static int do_rev_list(int fd, void *create_full_pack) o->flags |=UNINTERESTING ;add_pending_object (&revs, o,NULL ); } -setup_revisions (0 ,NULL , &revs,NULL ); } +setup_revisions (&revs);if (prepare_revision_walk (&revs))die ("revision walk setup failed" );mark_edges_uninteresting (revs.commits, &revs, show_edge);
wt-status.c +6 -6
@@ -241,8 +241,8 @@ static void wt_status_print_initial(struct wt_status *s)static void wt_status_print_updated (struct wt_status *s) {struct rev_info rev; -init_revisions (&rev,NULL ); -setup_revisions (0 ,NULL , &rev, s->reference); +init_revisions (&rev,NULL , s->reference); +setup_revisions (&rev); rev.diffopt.output_format |=DIFF_FORMAT_CALLBACK ; rev.diffopt.format_callback = wt_status_print_updated_cb; rev.diffopt.format_callback_data = s;
@@ -255,8 +255,8 @@ static void wt_status_print_updated(struct wt_status *s)static void wt_status_print_changed (struct wt_status *s) {struct rev_info rev; -init_revisions (&rev,"" ); -setup_revisions (0 ,NULL , &rev,NULL ); +init_revisions (&rev,"" ,NULL ); +setup_revisions (&rev); rev.diffopt.output_format |=DIFF_FORMAT_CALLBACK ; rev.diffopt.format_callback = wt_status_print_changed_cb; rev.diffopt.format_callback_data = s;
@@ -322,8 +322,8 @@ static void wt_status_print_verbose(struct wt_status *s)if (saved_stdout <0 ||dup2 (fileno (s->fp),STDOUT_FILENO ) <0 )die ("couldn't redirect stdout\n" ); -init_revisions (&rev,NULL ); -setup_revisions (0 ,NULL , &rev, s->reference); +init_revisions (&rev,NULL , s->reference); +setup_revisions (&rev); rev.diffopt.output_format |=DIFF_FORMAT_PATCH ; rev.diffopt.detect_rename =1 ;run_diff_index (&rev,1 );
Signature · 1 line
1.5.4.3.534.g7c43.dirty
Pierre Habouzit <[email protected]> writes:
struct rev_info gains two new fields:
* .def to store --default argument;
* .show_merge 1-bit field.
The refactor consists of the following steps:
* init_revisions now takes the --default argument to initialize .def properly, instead of getting it through setup_revisions.
* setup_revisions has been split in two:
- parse_revisions that does (almost) only argument parsing, to be more like what parse-options can do, and
- setup_revisions that does the rest.
Many places had no arguments to pass to setup_revisions, and those don't use parse_revisions at all.
Conceptually, I like the split up into three, which are:
- initializes the structure (init_revisions);
- parses the user arguments (parse_revisions -- the naming could probably be improved, though);
- prepares the derived/derivable fields for the real work (setup_revisions).
Was there a particular reason you moved default to init_revisions() and not kept it with setup_revisions()? All the callers of cmd_log_init() needs to say "I want to default to HEAD" because of it, instead of letting cmd_log_init() say it at only one place. Also the caller needs to decide upfront before calling init_revisions() what the default should be.
Quoted 6 lines
Signed-off-by Pierre Habouzit <[email protected]>---
This is a required patch for revisions parse-optification that splits the logic of revision arguments parsing in parsing, and post-processing.
Quoted 8 lines
The aim is to replace parsing with parse-opt at some point.
The final version (using parse-options) will probably need more rework in revisions.[hc], but I'd like to avoid rebasing this patch over and over, and I'd be glad if it's merged now, as it's not _that_ intrusive.
I've been using a git with this patch for a week without issues.
... which is a nice assuring comment ;-)
revision.c static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token · line 897
Quoted 8 lines
revision.c +1
-2@@ -892,8 +893,7 @@ static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token opt->regflags =REG_NEWLINE ; revs->grep_filter = opt; } -append_grep_pattern (revs->grep_filter, ptn, -"command line" ,0 , what); +append_grep_pattern (revs->grep_filter, ptn,"command line" ,0 , what); }
Made me go "huh?".
But everything else looked pretty mechanical conversion, and in that sense it is not that intrusive.
Applying this to 'master' and then merging 'pu' shows that there are a few topics that are cooking that would conflict with this change. Merging 'next' seems to go cleanly (I haven't checked the result), so it is not too bad for me to carrry this at this moment, if we were not this close to the rc freeze. I dunno.
Quoted 22 lines · Junio C Hamano
Pierre Habouzit <[email protected]> writes:
struct
rev_infogains two new fields:* .def to store --default argument;
* .show_merge 1-bit field.The refactor consists of the following steps:
*
init_revisionsnow takes the --default argument to initialize .def properly, instead of getting it throughsetup_revisions.*
setup_revisionshas been split in two:-
parse_revisionsthat does (almost) only argument parsing, to be more like what parse-options can do, and-
setup_revisionsthat does the rest.Many places had no arguments to pass to
setup_revisions, and those don't useparse_revisionsat all.
Quoted 6 lines
Conceptually, I like the split up into three, which are:
- initializes the structure (
init_revisions);- parses the user arguments (
parse_revisions-- the naming could probably be improved, though);
Well, the goal is to replace that bit with a parse_options
structure/macro at some point, so the naming isn't really important.
Quoted 8 lines
- prepares the derived/derivable fields for the real work (
setup_revisions).Was there a particular reason you moved default to
init_revisions()and not kept it withsetup_revisions()? All the callers ofcmd_log_init()needs to say "I want to default to HEAD" because of it, instead of lettingcmd_log_init()say it at only one place. Also the caller needs to decide upfront before callinginit_revisions()what the default should be.
Yes, because the revision parsing has side effects on that default
parameter (the --default command line switch).
We could of course have a .def member in the struct rev_info, and use
the one passed to setup_revisions then if it's still NULL, but it doesn't really makes sense to me, and I don't really see a problem with saying at init time that you'll default to "HEAD". Though if you really dislike it that much, I squash a patch that does that on top of it.
Quoted 8 lines
Quoted 8 lines
Signed-off-by Pierre Habouzit <[email protected]>---
This is a required patch for revisions parse-optification that splits the logic of revision arguments parsing in parsing, and post-processing.
The aim is to replace parsing with parse-opt at some point.
Quoted 8 lines
Quoted 6 lines
The final version (using parse-options) will probably need more rework in revisions.[hc], but I'd like to avoid rebasing this patch over and over, and I'd be glad if it's merged now, as it's not _that_ intrusive.
I've been using a git with this patch for a week without issues.
.... which is a nice assuring comment ;-)
Well it has been even more since :)
Quoted 10 lines
revision.c static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token · line 897
Quoted 8 lines
revision.c +1
-2@@ -892,8 +893,7 @@ static void add_grep(struct rev_info *revs, const char *ptn, enum grep_pat_token opt->regflags =REG_NEWLINE ; revs->grep_filter = opt; } -append_grep_pattern (revs->grep_filter, ptn, -"command line" ,0 , what); +append_grep_pattern (revs->grep_filter, ptn,"command line" ,0 , what); }Made me go "huh?".
Huh yeah, sorry, that's totally spurious indeed.
Quoted 8 lines
But everything else looked pretty mechanical conversion, and in that sense it is not that intrusive.
Applying this to 'master' and then merging 'pu' shows that there are a few topics that are cooking that would conflict with this change. Merging 'next' seems to go cleanly (I haven't checked the result), so it is not too bad for me to carrry this at this moment, if we were not this close to the rc freeze. I dunno.
Well I can wait longer, I'd just like to see it merged in a not too
far future, because I have to check for new places that would need conversions at each reabase :) (though the init/setup_revisions functions changed their number of arguments so I _think_ I should miss none each time but …).
Signature · 3 lines
·O· Pierre Habouzit ··O [email protected] OOO http://www.madism.org
Quoted 5 lines · Pierre Habouzit
We could of course have a .def member in the struct
rev_info, and use
the one passed tosetup_revisionsthen if it's still NULL, but it doesn't really makes sense to me, and I don't really see a problem with saying at init time that you'll default to "HEAD". Though if you really dislike it that much, I squash a patch that does that on top of it.
Well, it was not liking or disliking. Although I thought "default" that sets a value to the default after the parser finds that the user did not give anything (the approach you described in the above quoted paragraph) is a natural implementation, probably more so than what you did, I do not have strong preference either way.
When I see a change where I do not see a reason to, I get suspicious, wondering if I am missing some bigger reason (e.g. "by moving it there this and that would become much easier and cleaner, even though it now forces callers of cmd_log_init() to duplicate the default values"). There must be an obvious justification you had when you changed it, which I am not seeing. Hence that question.
Quoted 9 lines
Quoted 5 lines
Applying this to 'master' and then merging 'pu' shows that there are a few topics that are cooking that would conflict with this change. Merging 'next' seems to go cleanly (I haven't checked the result), so it is not too bad for me to carrry this at this moment, if we were not this close to the rc freeze. I dunno.
Well I can wait longer, I'd just like to see it merged in a not too
far future, because I have to check for new places that would need conversions at each reabase :)
Yeah, that burden can be shifted to me, in other words ;-)
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Pierre Habouzit
We could of course have a .def member in the struct
rev_info, and use
the one passed tosetup_revisionsthen if it's still NULL, but it doesn't really makes sense to me, and I don't really see a problem with saying at init time that you'll default to "HEAD". Though if you really dislike it that much, I squash a patch that does that on top of it.
Quoted 5 lines
Well, it was not liking or disliking. Although I thought "default" that sets a value to the default after the parser finds that the user did not give anything (the approach you described in the above quoted paragraph) is a natural implementation, probably more so than what you did, I do not have strong preference either way.
Well Okay, I'll let others comment, and will implement this way if
more are in favor of it than against then :)
Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Applying this to 'master' and then merging 'pu' shows that there are a few topics that are cooking that would conflict with this change. Merging 'next' seems to go cleanly (I haven't checked the result), so it is not too bad for me to carrry this at this moment, if we were not this close to the rc freeze. I dunno.
Well I can wait longer, I'd just like to see it merged in a not too
far future, because I have to check for new places that would need conversions at each reabase :)Yeah, that burden can be shifted to me, in other words ;-)
Heh, fair enough. Well, I can wait a bit longer :)
Signature · 3 lines
·O· Pierre Habouzit ··O [email protected] OOO http://www.madism.org