Move try_merge_command and checkout_fast_forward to libgit.a
PATCH 1/1 Move try_merge_command and checkout_fast_forward to libgit.a
These functions are called in sequencer.c, which is part of libgit.a. This makes libgit.a potentially require builtin/merge.c for external git commands.
---
I made some unrelated changes in sequencer.c and this problem shown up. merge-recursive.c is probably not the best place for these functions. I just don't want to create merge.c for them.
builtin/merge.c | 106 +---------------------------------------------------- cache.h | 3 -- merge-recursive.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ merge-recursive.h | 4 ++ sequencer.c | 2 +- 5 files changed, 115 insertions(+), 108 deletions(-)
builtin/merge.c +2 -104
@@ -628,59 +628,6 @@ static void write_tree_trivial(unsigned char *sha1)die (_ ("git write-tree failed to write a tree" )); } -static const char *merge_argument (struct commit *commit) -{ -if (commit) -return sha1_to_hex (commit->object.sha1); -else -return EMPTY_TREE_SHA1_HEX ; -} - -int try_merge_command (const char *strategy,size_t xopts_nr, -const char **xopts,struct commit_list *common, -const char *head_arg,struct commit_list *remotes) -{ -const char **args; -int i =0 , x =0 , ret; -struct commit_list *j; -struct strbuf buf =STRBUF_INIT ; - - args =xmalloc ((4 + xopts_nr +commit_list_count (common) + -commit_list_count (remotes)) *sizeof (char *)); -strbuf_addf (&buf,"merge-%s" , strategy); - args[i++] = buf.buf; -for (x =0 ; x < xopts_nr; x++) { -char *s =xmalloc (strlen (xopts[x])+2 +1 ); -strcpy (s,"--" ); -strcpy (s+2 , xopts[x]); - args[i++] = s; - } -for (j = common; j; j = j->next) - args[i++] =xstrdup (merge_argument (j->item)); - args[i++] ="--" ; - args[i++] = head_arg; -for (j = remotes; j; j = j->next) - args[i++] =xstrdup (merge_argument (j->item)); - args[i] =NULL ; - ret =run_command_v_opt (args,RUN_GIT_CMD ); -strbuf_release (&buf); - i =1 ; -for (x =0 ; x < xopts_nr; x++) -free ((void *)args[i++]); -for (j = common; j; j = j->next) -free ((void *)args[i++]); - i +=2 ; -for (j = remotes; j; j = j->next) -free ((void *)args[i++]); -free (args); -discard_cache (); -if (read_cache () <0 ) -die (_ ("failed to read the cache" )); -resolve_undo_clear (); - -return ret; -} -static int try_merge_strategy (const char *strategy,struct commit_list *common,struct commit_list *remoteheads,struct commit *head,const char *head_arg)
@@ -762,56 +709,6 @@ static int count_unmerged_entries(void)return ret; } -int checkout_fast_forward (const unsigned char *head,const unsigned char *remote) -{ -struct tree *trees[MAX_UNPACK_TREES ]; -struct unpack_trees_options opts; -struct tree_desc t[MAX_UNPACK_TREES ]; -int i, fd, nr_trees =0 ; -struct dir_struct dir; -struct lock_file *lock_file =xcalloc (1 ,sizeof (struct lock_file )); - -refresh_cache (REFRESH_QUIET ); - - fd =hold_locked_index (lock_file,1 ); - -memset (&trees,0 ,sizeof (trees)); -memset (&opts,0 ,sizeof (opts)); -memset (&t,0 ,sizeof (t)); -if (overwrite_ignore) { -memset (&dir,0 ,sizeof (dir)); - dir.flags |=DIR_SHOW_IGNORED ; -setup_standard_excludes (&dir); - opts.dir = &dir; - } - - opts.head_idx =1 ; - opts.src_index = &the_index; - opts.dst_index = &the_index; - opts.update =1 ; - opts.verbose_update =1 ; - opts.merge =1 ; - opts.fn = twoway_merge; -setup_unpack_trees_porcelain (&opts,"merge" ); - - trees[nr_trees] =parse_tree_indirect (head); -if (!trees[nr_trees++]) -return -1 ; - trees[nr_trees] =parse_tree_indirect (remote); -if (!trees[nr_trees++]) -return -1 ; -for (i =0 ; i < nr_trees; i++) { -parse_tree (trees[i]); -init_tree_desc (t+i, trees[i]->buffer, trees[i]->size); - } -if (unpack_trees (nr_trees, t, &opts)) -return -1 ; -if (write_cache (fd, active_cache, active_nr) || -commit_locked_index (lock_file)) -die (_ ("unable to write new index file" )); -return 0 ; -} -static void split_merge_strategies (const char *string,struct strategy **list,int *nr,int *alloc) {
@@ -1424,7 +1321,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) }if (checkout_fast_forward (head_commit->object.sha1, - commit->object.sha1)) { + commit->object.sha1, + overwrite_ignore)) { ret =1 ; goto done; }
cache.h +0 -3
@@ -1265,9 +1265,6 @@ struct startup_info { };extern struct startup_info *startup_info; -/* builtin/merge.c */ -int checkout_fast_forward (const unsigned char *from,const unsigned char *to); -int sane_execvp (const char *file,char *const argv[]);#endif /* CACHE_H */
merge-recursive.c +108 -0
117 lines not on this page · raw message
merge-recursive.h +4 -0
@@ -64,4 +64,8 @@ int try_merge_command(const char *strategy, size_t xopts_nr, const char **xopts, struct commit_list *common, const char *head_arg, struct commit_list *remotes); +int checkout_fast_forward (const unsigned char *from, +const unsigned char *to, +int overwrite_ignore); +#endif
sequencer.c +1 -1
@@ -191,7 +191,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from)struct ref_lock *ref_lock;read_cache (); -if (checkout_fast_forward (from, to)) +if (checkout_fast_forward (from, to,1 ))exit (1 );/* the callee should have complained already */ ref_lock =lock_any_ref_for_update ("HEAD" , from,0 );return write_ref_sha1 (ref_lock, to,"cherry-pick" );
Signature · 1 line
1.8.0.rc3.18.g0d9b108
Quoted 9 lines · Nguyen Thai Ngoc Duy
These functions are called in
sequencer.c, which is part of libgit.a. This makes libgit.a potentially requirebuiltin/merge.cfor external git commands.Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
I made some unrelated changes insequencer.cand this problem shown up.merge-recursive.cis probably not the best place for these functions. I just don't want to createmerge.cfor them.
I'm fine with this conceptually, but merge-recursive really is the wrong place. I'd much rather see a new merge.c to collect merge-related helper functions that are not strategy-specific.
-Peff
Quoted 12 lines · Jeff King
Quoted 9 lines · Nguyen Thai Ngoc Duy
These functions are called in
sequencer.c, which is part of libgit.a. This makes libgit.a potentially requirebuiltin/merge.cfor external git commands.Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
I made some unrelated changes insequencer.cand this problem shown up.merge-recursive.cis probably not the best place for these functions. I just don't want to createmerge.cfor them.
Quoted 3 lines
I'm fine with this conceptually, but merge-recursive really is the wrong place. I'd much rather see a new
merge.cto collect merge-related helper functions that are not strategy-specific.
OK. I checked around for similar issues and found these used by libgit.a but stay in builtin/ instead:
estimate_bisect_steps: bisect.c and builtin/rev-list.cprint_commit_list: bisect.c and builtin/rev-list.c
-> move them to bisect.c? another candidate is revision.c.
fetch_pack: transport.c and builtin/fetch-pack.csend_pack: transport.c and builtin/send-pack.c
-> move them to transport.c? or new files fetch-pack.c andsend-pack.c? I haven't check how many functions they may pull together.
setup_diff_pager: diff-no-index.c and builtin/diff.c
-> to diff-lib.c?
Signature · 1 line
Duy
Quoted 13 lines · Nguyen Thai Ngoc Duy
Quoted 12 lines · Jeff King
Quoted 9 lines · Nguyen Thai Ngoc Duy
These functions are called in
sequencer.c, which is part of libgit.a. This makes libgit.a potentially requirebuiltin/merge.cfor external git commands.Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>---
I made some unrelated changes insequencer.cand this problem shown up.merge-recursive.cis probably not the best place for these functions. I just don't want to createmerge.cfor them.
Quoted 6 lines
Quoted 3 lines
I'm fine with this conceptually, but merge-recursive really is the wrong place. I'd much rather see a new
merge.cto collect merge-related helper functions that are not strategy-specific.OK. I checked around for similar issues and found these used by libgit.a but stay in builtin/ instead:
Yeah, we have traditionally been kind of lazy about the distinction, because it doesn't really matter for our build system (i.e., libgit.a is not _really_ a library, but just a convenience in the build process). So one option is just not caring about these. I'm also fine with fixing.
Quoted 4 lines
estimate_bisect_steps:bisect.candbuiltin/rev-list.cprint_commit_list:bisect.candbuiltin/rev-list.c-> move them to
bisect.c? another candidate isrevision.c.
I'd probably say bisect.c for the first, and commit.c for the latter (that is where commit_list functions are defined, and it is really about that).
Quoted 6 lines
fetch_pack:transport.candbuiltin/fetch-pack.csend_pack:transport.candbuiltin/send-pack.c-> move them to
transport.c? or new filesfetch-pack.candsend-pack.c? I haven't check how many functions they may pull together.
I think I'd rather have fetch-pack.c and send-pack.c than putting them into transport.c (which is getting kind of bloated already).
Quoted 3 lines
setup_diff_pager:diff-no-index.candbuiltin/diff.c-> to
diff-lib.c?
I'm not sure (to be honest, I am not even sure of the intended difference between diff.c and diff-lib.c). That function is really not for general diffing, but for diff-like commands. Probably it would be OK in diff.c.
-Peff
cover Move code from builtin to libgit.a
Quoted 7 lines · Jeff King
Quoted 2 lines
OK. I checked around for similar issues and found these used by libgit.a but stay in builtin/ instead:
Yeah, we have traditionally been kind of lazy about the distinction, because it doesn't really matter for our build system (i.e., libgit.a is not _really_ a library, but just a convenience in the build process). So one option is just not caring about these.
Yeah. We can fix it up when we encounter new undefined reference errors (e.g. a new test program that links to libgit.a). Anyway it does not look too difficult to do. Take it or drop it. Your call.
Quoted 10 lines
I'm also fine with fixing.
Quoted 4 lines
estimate_bisect_steps:bisect.candbuiltin/rev-list.cprint_commit_list:bisect.candbuiltin/rev-list.c-> move them to
bisect.c? another candidate isrevision.c.I'd probably say
bisect.cfor the first, andcommit.cfor the latter (that is wherecommit_listfunctions are defined, and it is really about that).
Makes sense.
Quoted 8 lines
Quoted 3 lines
setup_diff_pager:diff-no-index.candbuiltin/diff.c-> to
diff-lib.c?I'm not sure (to be honest, I am not even sure of the intended difference between
diff.canddiff-lib.c). That function is really not for general diffing, but for diff-like commands. Probably it would be OK indiff.c.
Ditto. check_pager_config() is also moved from git.c to pager.c.
Quoted 9 lines
Quoted 6 lines
fetch_pack:transport.candbuiltin/fetch-pack.csend_pack:transport.candbuiltin/send-pack.c-> move them to
transport.c? or new filesfetch-pack.candsend-pack.c? I haven't check how many functions they may pull together.I think I'd rather have
fetch-pack.candsend-pack.cthan putting them intotransport.c(which is getting kind of bloated already).
These two are big code moves, basically all {fetch,send}-pack code. While I think this is good cleanup (I get surprise every time I look at transport.c and it leads to buitin/fetch-pack.c), this is probably not a good idea if we have on flight topics, which may cause lots of conflicts for you and Junio. Fortunately we don't at the moment.
Nguyễn Thái Ngọc Duy (7):
Move try_merge_command and checkout_fast_forward to libgit.a Move estimate_bisect_steps to libgit.a
Move print_commit_list to libgit.a
Move setup_diff_pager to libgit.a
send-pack: move core code to libgit.a
fetch-pack: remove global (static) configuration variable "args"
fetch-pack: move core code to libgit.a
Makefile | 3 + bisect.c | 38 ++ bisect.h | 4 - builtin.h | 4 - builtin/diff.c | 16 - builtin/fetch-pack.c | 951 +-------------------------------------------------- builtin/merge.c | 106 +----- builtin/rev-list.c | 49 --- builtin/send-pack.c | 333 ------------------ cache.h | 12 +- commit.c | 10 + commit.h | 4 + diff.c | 16 + diff.h | 1 + fetch-pack.c | 951 +++++++++++++++++++++++++++++++++++++++++++++++++++ git.c | 33 -- merge-recursive.h | 5 - merge.c | 112 ++++++ pager.c | 34 ++ send-pack.c | 344 +++++++++++++++++++ sequencer.c | 2 +- transport.h | 5 + 22 files changed, 1535 insertions(+), 1498 deletions(-) create mode 100644 fetch-pack.c create mode 100644 merge.c create mode 100644 send-pack.c
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH 1/7 Move try_merge_command and checkout_fast_forward to libgit.a
These functions are called in sequencer.c, which is part of libgit.a. This makes libgit.a potentially require builtin/merge.c for external git commands.
--- Makefile | 1 + builtin/merge.c | 106 +-------------------------------------------------- cache.h | 11 +++++- merge-recursive.h | 5 --- merge.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ sequencer.c | 2 +- 6 files changed, 125 insertions(+), 112 deletions(-) create mode 100644 merge.c
Makefile +1 -0
@@ -762,6 +762,7 @@ LIB_OBJS += lockfile.o LIB_OBJS += log-tree.o LIB_OBJS += mailmap.o LIB_OBJS += match-trees.o +LIB_OBJS += merge.o LIB_OBJS += merge-file.o LIB_OBJS += merge-recursive.o LIB_OBJS += mergesort.o
builtin/merge.c +2 -104
124 lines not on this page · raw message
cache.h +9 -2
@@ -1265,8 +1265,15 @@ struct startup_info { };extern struct startup_info *startup_info; -/* builtin/merge.c */ -int checkout_fast_forward (const unsigned char *from,const unsigned char *to); +/* merge.c */ +struct commit_list ; +int try_merge_command (const char *strategy,size_t xopts_nr, +const char **xopts,struct commit_list *common, +const char *head_arg,struct commit_list *remotes); +int checkout_fast_forward (const unsigned char *from, +const unsigned char *to, +int overwrite_ignore); +int sane_execvp (const char *file,char *const argv[]);
merge-recursive.h +0 -5
@@ -59,9 +59,4 @@ struct tree *write_tree_from_memory(struct merge_options *o);int parse_merge_opt (struct merge_options *out,const char *s); -/* builtin/merge.c */ -int try_merge_command (const char *strategy,size_t xopts_nr, -const char **xopts,struct commit_list *common, -const char *head_arg,struct commit_list *remotes); -#endif
merge.c new file +112 -0
112 lines not on this page · raw message
sequencer.c +1 -1
@@ -191,7 +191,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from)struct ref_lock *ref_lock;read_cache (); -if (checkout_fast_forward (from, to)) +if (checkout_fast_forward (from, to,1 ))exit (1 );/* the callee should have complained already */ ref_lock =lock_any_ref_for_update ("HEAD" , from,0 );return write_ref_sha1 (ref_lock, to,"cherry-pick" );
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH 2/7 Move estimate_bisect_steps to libgit.a
In reply to Nguyễn Thái Ngọc DuyThis function is used by bisect.c, part of libgit.a while estimate_bisect_steps stays in builtin/rev-list.c. Move it to bisect.a so we won't have undefine reference if a standalone program that uses libgit.a happens to pull it in.
--- bisect.c | 38 ++++++++++++++++++++++++++++++++++++++ builtin/rev-list.c | 39 --------------------------------------- 2 files changed, 38 insertions(+), 39 deletions(-)
bisect.c +38 -0
@@ -956,3 +956,41 @@ int bisect_next_all(const char *prefix, int no_checkout)return bisect_checkout (bisect_rev_hex, no_checkout); } +static inline int log2i (int n) +{ +int log2 =0 ; + +for (; n >1 ; n >>=1 ) + log2++; + +return log2; +} + +static inline int exp2i (int n) +{ +return 1 << n; +} + +/* +* Estimate the number of bisect steps left (after the current step) +* +* For any x between 0 included and 2^n excluded, the probability for +* n - 1 steps left looks like: +* +* P(2^n + x) == (2^n - x) / (2^n + x) +* +* and P(2^n + x) < 0.5 means 2^n < 3x +*/ +int estimate_bisect_steps (int all) +{ +int n, x, e; + +if (all <3 ) +return 0 ; + + n =log2i (all); + e =exp2i (n); + x = all - e; + +return (e <3 * x) ? n : n -1 ; +}
builtin/rev-list.c +0 -39
@@ -201,45 +201,6 @@ static void show_edge(struct commit *commit)printf ("-%s\n" ,sha1_to_hex (commit->object.sha1)); } -static inline int log2i (int n) -{ -int log2 =0 ; - -for (; n >1 ; n >>=1 ) - log2++; - -return log2; -} - -static inline int exp2i (int n) -{ -return 1 << n; -} - -/* -* Estimate the number of bisect steps left (after the current step) -* -* For any x between 0 included and 2^n excluded, the probability for -* n - 1 steps left looks like: -* -* P(2^n + x) == (2^n - x) / (2^n + x) -* -* and P(2^n + x) < 0.5 means 2^n < 3x -*/ -int estimate_bisect_steps (int all) -{ -int n, x, e; - -if (all <3 ) -return 0 ; - - n =log2i (all); - e =exp2i (n); - x = all - e; - -return (e <3 * x) ? n : n -1 ; -} -void print_commit_list (struct commit_list *list,const char *format_cur,const char *format_last)
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH 3/7 Move print_commit_list to libgit.a
In reply to Nguyễn Thái Ngọc DuyThis is used by bisect.c, part of libgit.a while it stays in builtin/rev-list.c. Move it to commit.c so that we won't get undefined reference if a program that uses libgit.a happens to pull it in.
--- bisect.h | 4 ---- builtin/rev-list.c | 10 ---------- commit.c | 10 ++++++++++ commit.h | 4 ++++ 4 files changed, 14 insertions(+), 14 deletions(-)
bisect.h +0 -4
@@ -11,10 +11,6 @@ extern struct commit_list *filter_skipped(struct commit_list *list,int *count, int *skipped_first); -extern void print_commit_list (struct commit_list *list, -const char *format_cur, -const char *format_last); -#define BISECT_SHOW_ALL (1<<0)#define REV_LIST_QUIET (1<<1)
builtin/rev-list.c +0 -10
@@ -201,16 +201,6 @@ static void show_edge(struct commit *commit)printf ("-%s\n" ,sha1_to_hex (commit->object.sha1)); } -void print_commit_list (struct commit_list *list, -const char *format_cur, -const char *format_last) -{ -for ( ; list; list = list->next) { -const char *format = list->next ? format_cur : format_last; -printf (format,sha1_to_hex (list->item->object.sha1)); - } -} -static void print_var_str (const char *var,const char *val) {printf ("%s='%s'\n" , var, val);
commit.c +10 -0
@@ -1347,3 +1347,13 @@ struct commit_list **commit_list_append(struct commit *commit, new->next =NULL ;return &new->next; } + +void print_commit_list (struct commit_list *list, +const char *format_cur, +const char *format_last) +{ +for ( ; list; list = list->next) { +const char *format = list->next ? format_cur : format_last; +printf (format,sha1_to_hex (list->item->object.sha1)); + } +}
commit.h +4 -0
@@ -222,4 +222,8 @@ struct commit *get_merge_parent(const char *name);extern int parse_signed_commit (const unsigned char *sha1,struct strbuf *message,struct strbuf *signature); +extern void print_commit_list (struct commit_list *list, +const char *format_cur, +const char *format_last); +#endif /* COMMIT_H */
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH 4/7 Move setup_diff_pager to libgit.a
In reply to Nguyễn Thái Ngọc DuyThis is used by diff-no-index.c, part of libgit.a while it stays in builtin/diff.c. Move it to diff.c so that we won't get undefined reference if a program that uses libgit.a happens to pull it in.
While at it, move check_pager from git.c to pager.c. It makes more sense there and pager.c is also part of libgit.a
--- builtin.h | 4 ---- builtin/diff.c | 16 ---------------- cache.h | 1 + diff.c | 16 ++++++++++++++++ diff.h | 1 + git.c | 33 --------------------------------- pager.c | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 52 insertions(+), 53 deletions(-)
builtin.h +0 -4
@@ -37,10 +37,6 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c, const unsigned char *from_obj, const unsigned char *to_obj);void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c); -extern int check_pager_config (const char *cmd); -struct diff_options ; -extern void setup_diff_pager (struct diff_options *); -extern int textconv_object (const char *path,unsigned mode,const unsigned char *sha1,int sha1_valid,char **buf,unsigned long *buf_size);extern int cmd_add (int argc,const char **argv,const char *prefix);
builtin/diff.c +0 -16
@@ -418,19 +418,3 @@ int cmd_diff(int argc, const char **argv, const char *prefix)refresh_index_quietly ();return result; } - -void setup_diff_pager (struct diff_options *opt) -{ -/* -* If the user asked for our exit code, then either they want --quiet -* or --exit-code. We should definitely not bother with a pager in the -* former case, as we will generate no output. Since we still properly -* report our exit code even when a pager is run, we _could_ run a -* pager with --exit-code. But since we have not done so historically, -* and because it is easy to find people oneline advising "git diff -* --exit-code" in hooks and other scripts, we do not do so. -*/ -if (!DIFF_OPT_TST (opt,EXIT_WITH_STATUS ) && -check_pager_config ("diff" ) !=0 ) -setup_pager (); -}
cache.h +1 -0
@@ -1183,6 +1183,7 @@ extern int pager_in_use(void);extern int pager_use_color;extern int term_columns (void );extern int decimal_width (int ); +extern int check_pager_config (const char *cmd);extern const char *editor_program;extern const char *askpass_program;
diff.c +16 -0
@@ -4871,3 +4871,19 @@ size_t fill_textconv(struct userdiff_driver *driver,return size; } + +void setup_diff_pager (struct diff_options *opt) +{ +/* +* If the user asked for our exit code, then either they want --quiet +* or --exit-code. We should definitely not bother with a pager in the +* former case, as we will generate no output. Since we still properly +* report our exit code even when a pager is run, we _could_ run a +* pager with --exit-code. But since we have not done so historically, +* and because it is easy to find people oneline advising "git diff +* --exit-code" in hooks and other scripts, we do not do so. +*/ +if (!DIFF_OPT_TST (opt,EXIT_WITH_STATUS ) && +check_pager_config ("diff" ) !=0 ) +setup_pager (); +}
diff.h +1 -0
@@ -335,5 +335,6 @@ extern int parse_rename_score(const char **cp_p);extern int print_stat_summary (FILE *fp,int files,int insertions,int deletions); +extern void setup_diff_pager (struct diff_options *);#endif /* DIFF_H */
git.c +0 -33
@@ -17,39 +17,6 @@ const char git_more_info_string[] =static struct startup_info git_startup_info;static int use_pager =-1 ; -struct pager_config { -const char *cmd; -int want; -char *value; -}; - -static int pager_command_config (const char *var,const char *value,void *data) -{ -struct pager_config *c = data; -if (!prefixcmp (var,"pager." ) && !strcmp (var +6 , c->cmd)) { -int b =git_config_maybe_bool (var, value); -if (b >=0 ) - c->want = b; -else { - c->want =1 ; - c->value =xstrdup (value); - } - } -return 0 ; -} - -/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */ -int check_pager_config (const char *cmd) -{ -struct pager_config c; - c.cmd = cmd; - c.want =-1 ; - c.value =NULL ; -git_config (pager_command_config, &c); -if (c.value) - pager_program = c.value; -return c.want; -}static void commit_pager_choice (void ) {switch (use_pager) {
pager.c +34 -0
@@ -6,6 +6,12 @@#define DEFAULT_PAGER "less"#endif +struct pager_config { +const char *cmd; +int want; +char *value; +}; +/* * This is split up from the rest of git so that we can do * something different on Windows.
@@ -159,3 +165,31 @@ int decimal_width(int number) i *=10 ;return width; } + +static int pager_command_config (const char *var,const char *value,void *data) +{ +struct pager_config *c = data; +if (!prefixcmp (var,"pager." ) && !strcmp (var +6 , c->cmd)) { +int b =git_config_maybe_bool (var, value); +if (b >=0 ) + c->want = b; +else { + c->want =1 ; + c->value =xstrdup (value); + } + } +return 0 ; +} + +/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */ +int check_pager_config (const char *cmd) +{ +struct pager_config c; + c.cmd = cmd; + c.want =-1 ; + c.value =NULL ; +git_config (pager_command_config, &c); +if (c.value) + pager_program = c.value; +return c.want; +}
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH 5/7 send-pack: move core code to libgit.a
In reply to Nguyễn Thái Ngọc Duysend_pack() is used by transport.c, part of libgit.a while it stays in builtin/send-pack.c. Move it to send-pack.c so that we won't get undefined reference if a program that uses libgit.a happens to pull it in.
--- Makefile | 1 + builtin/send-pack.c | 333 -------------------------------------------------- send-pack.c | 344 ++++++++++++++++++++++++++++++++++++++++++++++++++++ transport.h | 5 + 4 files changed, 350 insertions(+), 333 deletions(-) create mode 100644 send-pack.c
Makefile +1 -0
@@ -797,6 +797,7 @@ LIB_OBJS += rerere.o LIB_OBJS += resolve-undo.o LIB_OBJS += revision.o LIB_OBJS += run-command.o +LIB_OBJS += send-pack.o LIB_OBJS += sequencer.o LIB_OBJS += server-info.o LIB_OBJS += setup.o
builtin/send-pack.c +0 -333
345 lines not on this page · raw message
send-pack.c new file +344 -0
344 lines not on this page · raw message
transport.h +5 -0
@@ -175,4 +175,9 @@ void transport_print_push_status(const char *dest, struct ref *refs,typedef void alternate_ref_fn (const struct ref *,void *);extern void for_each_alternate_ref (alternate_ref_fn ,void *); +struct send_pack_args ; +extern int send_pack (struct send_pack_args *args, +int fd[],struct child_process *conn, +struct ref *remote_refs, +struct extra_have_objects *extra_have);#endif
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH 6/7 fetch-pack: remove global (static) configuration variable "args"
In reply to Nguyễn Thái Ngọc DuyThis helps removes the hack in fetch_pack() that copies my_args to args.
--- builtin/fetch-pack.c | 160 ++++++++++++++++++++++++++------------------------- 1 file changed, 83 insertions(+), 77 deletions(-)
builtin/fetch-pack.c +83 -77
@@ -20,9 +20,6 @@ static int no_done;static int fetch_fsck_objects =-1 ;static int transfer_fsck_objects =-1 ;static int agent_supported; -static struct fetch_pack_args args = { -/* .uploadpack = */ "git-upload-pack" , -};static const char fetch_pack_usage[] ="git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] "
@@ -173,9 +170,9 @@ enum ack_type { ACK_ready }; -static void consume_shallow_list (int fd) +static void consume_shallow_list (struct fetch_pack_args *args,int fd) { -if (args.stateless_rpc && args.depth >0 ) { +if (args->stateless_rpc && args->depth >0 ) {/* If we sent a depth we will get back "duplicate" * shallow and unshallow commands every time there * is a block of have lines exchanged.
@@ -246,9 +243,10 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)die ("git fetch_pack: expected ACK/NAK, got '%s'" , line); } -static void send_request (int fd,struct strbuf *buf) +static void send_request (struct fetch_pack_args *args, +int fd,struct strbuf *buf) { -if (args.stateless_rpc) { +if (args->stateless_rpc) {send_sideband (fd,-1 , buf->buf, buf->len,LARGE_PACKET_MAX );packet_flush (fd); }else
@@ -264,9 +262,9 @@ static void insert_one_alternate_ref(const struct ref *ref, void *unused)#define PIPESAFE_FLUSH 32#define LARGE_FLUSH 1024 -static int next_flush (int count) +static int next_flush (struct fetch_pack_args *args,int count) { -int flush_limit = args.stateless_rpc ?LARGE_FLUSH :PIPESAFE_FLUSH ; +int flush_limit = args->stateless_rpc ?LARGE_FLUSH :PIPESAFE_FLUSH ;if (count < flush_limit) count <<=1 ;
@@ -275,7 +273,8 @@ static int next_flush(int count)return count; } -static int find_common (int fd[2 ],unsigned char *result_sha1, +static int find_common (struct fetch_pack_args *args, +int fd[2 ],unsigned char *result_sha1,struct ref *refs) {int fetching;
@@ -287,7 +286,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,struct strbuf req_buf =STRBUF_INIT ;size_t state_len =0 ; -if (args.stateless_rpc && multi_ack ==1 ) +if (args->stateless_rpc && multi_ack ==1 )die ("--stateless-rpc requires multi_ack_detailed" );if (marked)for_each_ref (clear_marks,NULL );
@@ -325,9 +324,9 @@ static int find_common(int fd[2], unsigned char *result_sha1,if (no_done)strbuf_addstr (&c," no-done" );if (use_sideband ==2 )strbuf_addstr (&c," side-band-64k" );if (use_sideband ==1 )strbuf_addstr (&c," side-band" ); -if (args.use_thin_pack)strbuf_addstr (&c," thin-pack" ); -if (args.no_progress)strbuf_addstr (&c," no-progress" ); -if (args.include_tag)strbuf_addstr (&c," include-tag" ); +if (args->use_thin_pack)strbuf_addstr (&c," thin-pack" ); +if (args->no_progress)strbuf_addstr (&c," no-progress" ); +if (args->include_tag)strbuf_addstr (&c," include-tag" );if (prefer_ofs_delta)strbuf_addstr (&c," ofs-delta" );if (agent_supported)strbuf_addf (&c," agent=%s" ,git_user_agent_sanitized ());
@@ -346,16 +345,16 @@ static int find_common(int fd[2], unsigned char *result_sha1,if (is_repository_shallow ())write_shallow_commits (&req_buf,1 ); -if (args.depth >0 ) -packet_buf_write (&req_buf,"deepen %d" , args.depth); +if (args->depth >0 ) +packet_buf_write (&req_buf,"deepen %d" , args->depth);packet_buf_flush (&req_buf); state_len = req_buf.len; -if (args.depth >0 ) { +if (args->depth >0 ) {char line[1024 ];unsigned char sha1[20 ]; -send_request (fd[1 ], &req_buf); +send_request (args, fd[1 ], &req_buf);while (packet_read_line (fd[0 ], line,sizeof (line))) {if (!prefixcmp (line,"shallow " )) {if (get_sha1_hex (line +8 , sha1))
@@ -377,10 +376,10 @@ static int find_common(int fd[2], unsigned char *result_sha1, }die ("expected shallow/unshallow, got %s" , line); } - }else if (!args.stateless_rpc) -send_request (fd[1 ], &req_buf); + }else if (!args->stateless_rpc) +send_request (args, fd[1 ], &req_buf); -if (!args.stateless_rpc) { +if (!args->stateless_rpc) {/* If we aren't using the stateless-rpc interface * we don't need to retain the headers. */
@@ -392,29 +391,29 @@ static int find_common(int fd[2], unsigned char *result_sha1, retval =-1 ;while ((sha1 =get_rev ())) {packet_buf_write (&req_buf,"have %s\n" ,sha1_to_hex (sha1)); -if (args.verbose) +if (args->verbose)fprintf (stderr,"have %s\n" ,sha1_to_hex (sha1)); in_vain++;if (flush_at <= ++count) {int ack;packet_buf_flush (&req_buf); -send_request (fd[1 ], &req_buf); +send_request (args, fd[1 ], &req_buf);strbuf_setlen (&req_buf, state_len); flushes++; - flush_at =next_flush (count); + flush_at =next_flush (args, count);/* * We keep one window "ahead" of the other side, and * will wait for an ACK only on the next one */ -if (!args.stateless_rpc && count ==INITIAL_FLUSH ) +if (!args->stateless_rpc && count ==INITIAL_FLUSH )continue ; -consume_shallow_list (fd[0 ]); +consume_shallow_list (args, fd[0 ]); do { ack = get_ack(fd[0], result_sha1); - if (args.verbose && ack) + if (args->verbose && ack) fprintf(stderr, "got ack %d %s\n", ack, sha1_to_hex(result_sha1)); switch (ack) {
@@ -430,7 +429,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,lookup_commit (result_sha1);if (!commit)die ("invalid commit %s" ,sha1_to_hex (result_sha1)); -if (args.stateless_rpc +if (args->stateless_rpc && ack == ACK_common && !(commit->object.flags &COMMON )) {/* We need to replay the have for this object
@@ -455,7 +454,7 @@ static int find_common(int fd[2], unsigned char *result_sha1, }while (ack); flushes--;if (got_continue &&MAX_IN_VAIN < in_vain) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"giving up\n" );break ;/* give up */ }
@@ -464,9 +463,9 @@ static int find_common(int fd[2], unsigned char *result_sha1, done:if (!got_ready || !no_done) {packet_buf_write (&req_buf,"done\n" ); -send_request (fd[1 ], &req_buf); +send_request (args, fd[1 ], &req_buf); } -if (args.verbose) +if (args->verbose)fprintf (stderr,"done\n" );if (retval !=0 ) { multi_ack =0 ;
@@ -474,11 +473,11 @@ done: }strbuf_release (&req_buf); -consume_shallow_list (fd[0 ]); +consume_shallow_list (args, fd[0 ]);while (flushes || multi_ack) {int ack =get_ack (fd[0 ], result_sha1);if (ack) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"got ack (%d) %s\n" , ack,sha1_to_hex (result_sha1));if (ack ==ACK )
@@ -515,10 +514,11 @@ static int mark_complete(const char *refname, const unsigned char *sha1, int flareturn 0 ; } -static void mark_recent_complete_commits (unsigned long cutoff) +static void mark_recent_complete_commits (struct fetch_pack_args *args, +unsigned long cutoff) {while (complete && cutoff <= complete->item->date) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"Marking %s as complete\n" ,sha1_to_hex (complete->item->object.sha1));pop_most_recent_commit (&complete,COMPLETE );
@@ -535,7 +535,8 @@ static int non_matching_ref(struct string_list_item *item, void *unused)return 1 ; } -static void filter_refs (struct ref **refs,struct string_list *sought) +static void filter_refs (struct fetch_pack_args *args, +struct ref **refs,struct string_list *sought) {struct ref *newlist =NULL ;struct ref **newtail = &newlist;
@@ -564,8 +565,8 @@ static void filter_refs(struct ref **refs, struct string_list *sought) } } -if (! keep && args.fetch_all && - (!args.depth ||prefixcmp (ref->name,"refs/tags/" ))) +if (! keep && args->fetch_all && + (!args->depth ||prefixcmp (ref->name,"refs/tags/" ))) keep =1 ;if (keep) {
@@ -586,7 +587,8 @@ static void mark_alternate_complete(const struct ref *ref, void *unused)mark_complete (NULL , ref->old_sha1,0 ,NULL ); } -static int everything_local (struct ref **refs,struct string_list *sought) +static int everything_local (struct fetch_pack_args *args, +struct ref **refs,struct string_list *sought) {struct ref *ref;int retval;
@@ -612,11 +614,11 @@ static int everything_local(struct ref **refs, struct string_list *sought) } } -if (!args.depth) { +if (!args->depth) {for_each_ref (mark_complete,NULL );for_each_alternate_ref (mark_alternate_complete,NULL );if (cutoff) -mark_recent_complete_commits (cutoff); +mark_recent_complete_commits (args, cutoff); }/*
@@ -637,7 +639,7 @@ static int everything_local(struct ref **refs, struct string_list *sought) } } -filter_refs (refs, sought); +filter_refs (args, refs, sought);for (retval =1 , ref = *refs; ref ; ref = ref->next) {const unsigned char *remote = ref->old_sha1;
@@ -647,7 +649,7 @@ static int everything_local(struct ref **refs, struct string_list *sought) o =lookup_object (remote);if (!o || !(o->flags &COMPLETE )) { retval =0 ; -if (!args.verbose) +if (!args->verbose)continue ; fprintf(stderr, "want %s (%s)\n", sha1_to_hex(remote),
@@ -656,7 +658,7 @@ static int everything_local(struct ref **refs, struct string_list *sought) }hashcpy (ref->new_sha1, local); -if (!args.verbose) +if (!args->verbose)continue ; fprintf(stderr, "already have %s (%s)\n", sha1_to_hex(remote),
@@ -674,14 +676,15 @@ static int sideband_demux(int in, int out, void *data)return ret; } -static int get_pack (int xd[2 ],char **pack_lockfile) +static int get_pack (struct fetch_pack_args *args, +int xd[2 ],char **pack_lockfile) {struct async demux;const char *argv[20 ];char keep_arg[256 ];char hdr_arg[256 ];const char **av; -int do_keep = args.keep_pack; +int do_keep = args->keep_pack;struct child_process cmd;memset (&demux,0 ,sizeof (demux));
@@ -704,7 +707,7 @@ static int get_pack(int xd[2], char **pack_lockfile) cmd.argv = argv; av = argv; *hdr_arg =0 ; -if (!args.keep_pack && unpack_limit) { +if (!args->keep_pack && unpack_limit) {struct pack_header header;if (read_pack_header (demux.out, &header))
@@ -723,11 +726,11 @@ static int get_pack(int xd[2], char **pack_lockfile) cmd.out =-1 ; *av++ ="index-pack" ; *av++ ="--stdin" ; -if (!args.quiet && !args.no_progress) +if (!args->quiet && !args->no_progress) *av++ ="-v" ; -if (args.use_thin_pack) +if (args->use_thin_pack) *av++ ="--fix-thin" ; -if (args.lock_pack || unpack_limit) { +if (args->lock_pack || unpack_limit) {int s =sprintf (keep_arg,"--keep=fetch-pack %" PRIuMAX" on " , (uintmax_t )getpid ());if (gethostname (keep_arg + s,sizeof (keep_arg) - s))
@@ -737,7 +740,7 @@ static int get_pack(int xd[2], char **pack_lockfile) }else { *av++ ="unpack-objects" ; -if (args.quiet || args.no_progress) +if (args->quiet || args->no_progress) *av++ ="-q" ; }if (*hdr_arg)
@@ -766,10 +769,11 @@ static int get_pack(int xd[2], char **pack_lockfile)return 0 ; } -static struct ref *do_fetch_pack (int fd[2 ], -const struct ref *orig_ref, -struct string_list *sought, -char **pack_lockfile) +static struct ref *do_fetch_pack (struct fetch_pack_args *args, +int fd[2 ], +const struct ref *orig_ref, +struct string_list *sought, +char **pack_lockfile) {struct ref *ref =copy_ref_list (orig_ref);unsigned char sha1[20 ];
@@ -781,64 +785,64 @@ static struct ref *do_fetch_pack(int fd[2],if (is_repository_shallow () && !server_supports ("shallow" ))die ("Server does not support shallow clients" );if (server_supports ("multi_ack_detailed" )) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"Server supports multi_ack_detailed\n" ); multi_ack =2 ;if (server_supports ("no-done" )) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"Server supports no-done\n" ); -if (args.stateless_rpc) +if (args->stateless_rpc) no_done =1 ; } }else if (server_supports ("multi_ack" )) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"Server supports multi_ack\n" ); multi_ack =1 ; }if (server_supports ("side-band-64k" )) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"Server supports side-band-64k\n" ); use_sideband =2 ; }else if (server_supports ("side-band" )) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"Server supports side-band\n" ); use_sideband =1 ; }if (!server_supports ("thin-pack" )) - args.use_thin_pack =0 ; + args->use_thin_pack =0 ;if (!server_supports ("no-progress" )) - args.no_progress =0 ; + args->no_progress =0 ;if (!server_supports ("include-tag" )) - args.include_tag =0 ; + args->include_tag =0 ;if (server_supports ("ofs-delta" )) { -if (args.verbose) +if (args->verbose)fprintf (stderr,"Server supports ofs-delta\n" ); }else prefer_ofs_delta =0 ;if ((agent_feature =server_feature_value ("agent" , &agent_len))) { agent_supported =1 ; -if (args.verbose && agent_len) +if (args->verbose && agent_len)fprintf (stderr,"Server version is %.*s\n" , agent_len, agent_feature); } -if (everything_local (&ref, sought)) { +if (everything_local (args, &ref, sought)) {packet_flush (fd[1 ]); goto all_done; } -if (find_common (fd, sha1, ref) <0 ) -if (!args.keep_pack) +if (find_common (args, fd, sha1, ref) <0 ) +if (!args->keep_pack)/* When cloning, it is not unusual to have * no common commit. */ warning ("no common commits" ); -if (args.stateless_rpc) +if (args->stateless_rpc)packet_flush (fd[1 ]); -if (get_pack (fd, pack_lockfile)) +if (get_pack (args, fd, pack_lockfile))die ("git fetch-pack: fetch failed." ); all_done:
@@ -900,9 +904,13 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)char *pack_lockfile =NULL ;char **pack_lockfile_ptr =NULL ;struct child_process *conn; +struct fetch_pack_args args;packet_trace_identity ("fetch-pack" ); +memset (&args,0 ,sizeof (args)); + args.uploadpack ="git-upload-pack" ; +for (i =1 ; i < argc && *argv[i] =='-' ; i++) {const char *arg = argv[i];
@@ -1039,7 +1047,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)return ret; } -struct ref *fetch_pack(struct fetch_pack_args *my_args, +struct ref *fetch_pack(struct fetch_pack_args *args, int fd[], struct child_process *conn, const struct ref *ref, const char *dest,
@@ -1050,9 +1058,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,struct ref *ref_cpy;fetch_pack_setup (); -if (&args != my_args) -memcpy (&args, my_args,sizeof (args)); -if (args.depth >0 ) { +if (args->depth >0 ) {if (stat (git_path ("shallow" ), &st)) st.st_mtime =0 ; }
@@ -1066,9 +1072,9 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,packet_flush (fd[1 ]);die ("no matching remote head" ); } - ref_cpy =do_fetch_pack (fd, ref, sought, pack_lockfile); + ref_cpy =do_fetch_pack (args, fd, ref, sought, pack_lockfile); -if (args.depth >0 ) { +if (args->depth >0 ) {struct cache_time mtime;struct strbuf sb =STRBUF_INIT ;char *shallow =git_path ("shallow" );
Signature · 1 line
1.8.0.rc2.23.g1fb49df
PATCH 7/7 fetch-pack: move core code to libgit.a
In reply to Nguyễn Thái Ngọc Duyfetch_pack() is used by transport.c, part of libgit.a while it stays in builtin/fetch-pack.c. Move it to fetch-pack.c so that we won't get undefined reference if a program that uses libgit.a happens to pull it in.
--- Makefile | 1 + builtin/fetch-pack.c | 949 -------------------------------------------------- fetch-pack.c | 951 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 952 insertions(+), 949 deletions(-) create mode 100644 fetch-pack.c
Makefile +1 -0
@@ -745,6 +745,7 @@ LIB_OBJS += editor.o LIB_OBJS += entry.o LIB_OBJS += environment.o LIB_OBJS += exec_cmd.o +LIB_OBJS += fetch-pack.o LIB_OBJS += fsck.o LIB_OBJS += gettext.o LIB_OBJS += gpg-interface.o
builtin/fetch-pack.c +0 -949
963 lines not on this page · raw message
fetch-pack.c new file +951 -0
951 lines not on this page · raw message
Signature · 1 line
1.8.0.rc2.23.g1fb49df
Re: [PATCH 0/7] Move code from builtin to libgit.a
In reply to Nguyễn Thái Ngọc DuyQuoted 6 lines · Nguyen Thai Ngoc Duy
These two are big code moves, basically all {fetch,send}-pack code. While I think this is good cleanup (I get surprise every time I look at
transport.cand it leads tobuitin/fetch-pack.c), this is probably not a good idea if we have on flight topics, which may cause lots of conflicts for you and Junio. Fortunately we don't at the moment.
Quoted 8 lines
Nguyễn Thái Ngọc Duy (7):
Movetry_merge_commandandcheckout_fast_forwardto libgit.a Moveestimate_bisect_stepsto libgit.a
Moveprint_commit_listto libgit.a
Movesetup_diff_pagerto libgit.a
send-pack: move core code to libgit.a
fetch-pack: remove global (static) configuration variable "args"
fetch-pack: move core code to libgit.a
This does not seem to disturb anything in pu, so I am very tempted.
I tweaked the last one, which removed the inclusion of pkt-line.h from builtin/fetch-pack.c; it is still needed by the use of packet_read_line when reading stateless rpc refs from stdin (caught by "-Wall -Werror").
-Peff