Convert git-rebase.sh to C
cover Convert git-rebase.sh to C
In the spirit of sharing code proactively [1], despite my embarrassment, this is what I got for converting git-rebase.sh to C. Note that this is only about git-rebase.sh, not git-rebase--*.sh. Some changes in git-rebase.sh are pushed back to git-rebase--*.sh. The idea is we convert git-rebase.sh first, then the rest later.
Anybody who wants to base their work on this code, feel free to --reset-author (and take all the bugs with you, I'm sure there are lots of them). This work is from 2013. git-rebase.sh has received lots of updates since then, so there's still lots of work to do.
[1] http://article.gmane.org/gmane.comp.version-control.git/265699
Nguyễn Thái Ngọc Duy (8):
strbuf: add and use strbuf_read_file_or_die() Move reset_tree from builtin/checkout.c to unpack-trees.c
rebase: turn rebase--am into a separate program
rebase: turn rebase--merge into a separate program
rebase: turn rebase--interactive into a separate program
rebase: remove unused function
rebase: move resolvemsg to rebase--* scripts Build in rebase
Makefile | 8 +- builtin.h | 1 + builtin/blame.c | 4 +- builtin/checkout.c | 40 +- builtin/commit.c | 16 +- builtin/merge.c | 32 +- builtin/notes.c | 4 +- builtin/rebase.c (new) | 752 ++++++++++++++++++++++++++++++++ builtin/tag.c | 7 +- commit.c | 4 +- commit.h | 4 +- contrib/examples/git-rebase.sh (new +x) | 532 ++++++++++++++++++++++ git-rebase--am.sh (mode +x) | 39 ++ git-rebase--interactive.sh (mode +x) | 41 +- git-rebase--merge.sh (mode +x) | 39 ++ git-rebase.sh (gone) | 544 ----------------------- git.c | 1 + strbuf.c | 8 + strbuf.h | 1 + unpack-trees.c | 33 ++ unpack-trees.h | 4 + 21 files changed, 1480 insertions(+), 634 deletions(-) create mode 100644 builtin/rebase.c create mode 100755 contrib/examples/git-rebase.sh mode change 100644 => 100755 git-rebase--am.sh mode change 100644 => 100755 git-rebase--interactive.sh mode change 100644 => 100755 git-rebase--merge.sh delete mode 100755 git-rebase.sh
Signature · 1 line
2.3.0.rc1.137.g477eb31
PATCH 1/8 strbuf: add and use strbuf_read_file_or_die()
--- builtin/blame.c | 4 ++-- builtin/commit.c | 16 +++++----------- builtin/merge.c | 3 +-- builtin/notes.c | 4 ++-- builtin/tag.c | 7 ++----- strbuf.c | 8 ++++++++ strbuf.h | 1 + 7 files changed, 21 insertions(+), 22 deletions(-)
builtin/blame.c +2 -2
@@ -2193,8 +2193,8 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,if (DIFF_OPT_TST (opt,ALLOW_TEXTCONV ) &&textconv_object (read_from, mode, null_sha1,0 , &buf_ptr, &buf_len))strbuf_attach (&buf, buf_ptr, buf_len, buf_len +1 ); -else if (strbuf_read_file (&buf, read_from, st.st_size) != st.st_size) -die_errno ("cannot open or read '%s'" , read_from); +else +strbuf_read_file_or_die (&buf, read_from, st.st_size);break ;case S_IFLNK :if (strbuf_readlink (&buf, read_from, st.st_size) <0 )
builtin/commit.c +5 -11
@@ -612,9 +612,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,die_errno (_ ("could not read log from standard input" )); hook_arg1 ="message" ; }else if (logfile) { -if (strbuf_read_file (&sb, logfile,0 ) <0 ) -die_errno (_ ("could not read log file '%s'" ), - logfile); +strbuf_read_file_or_die (&sb, logfile,0 ); hook_arg1 ="message" ; }else if (use_message) { buffer =strstr (use_message_buffer,"\n\n" );
@@ -634,16 +632,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix, &sb, &ctx); hook_arg1 ="message" ; }else if (!stat (git_path ("MERGE_MSG" ), &statbuf)) { -if (strbuf_read_file (&sb,git_path ("MERGE_MSG" ),0 ) <0 ) -die_errno (_ ("could not read MERGE_MSG" )); +strbuf_read_file_or_die (&sb,git_path ("MERGE_MSG" ),0 ); hook_arg1 ="merge" ; }else if (!stat (git_path ("SQUASH_MSG" ), &statbuf)) { -if (strbuf_read_file (&sb,git_path ("SQUASH_MSG" ),0 ) <0 ) -die_errno (_ ("could not read SQUASH_MSG" )); +strbuf_read_file_or_die (&sb,git_path ("SQUASH_MSG" ),0 ); hook_arg1 ="squash" ; }else if (template_file) { -if (strbuf_read_file (&sb, template_file,0 ) <0 ) -die_errno (_ ("could not read '%s'" ), template_file); +strbuf_read_file_or_die (&sb, template_file,0 ); hook_arg1 ="template" ; clean_message_contents =0 ; }
@@ -1497,8 +1492,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)fclose (fp);strbuf_release (&m);if (!stat (git_path ("MERGE_MODE" ), &statbuf)) { -if (strbuf_read_file (&sb,git_path ("MERGE_MODE" ),0 ) <0 ) -die_errno (_ ("could not read MERGE_MODE" )); +strbuf_read_file_or_die (&sb,git_path ("MERGE_MODE" ),0 );if (!strcmp (sb.buf,"no-ff" )) allow_fast_forward =0 ; }
builtin/merge.c +1 -2
@@ -769,8 +769,7 @@ static void read_merge_msg(struct strbuf *msg) {const char *filename =git_path ("MERGE_MSG" );strbuf_reset (msg); -if (strbuf_read_file (msg, filename,0 ) <0 ) -die_errno (_ ("Could not read from '%s'" ), filename); +strbuf_read_file_or_die (msg, filename,0 ); }static void write_merge_state (struct commit_list *);
builtin/notes.c +2 -2
@@ -252,8 +252,8 @@ static int parse_file_arg(const struct option *opt, const char *arg, int unset)if (!strcmp (arg,"-" )) {if (strbuf_read (&(msg->buf),0 ,1024 ) <0 )die_errno (_ ("cannot read '%s'" ), arg); - }else if (strbuf_read_file (&(msg->buf), arg,1024 ) <0 ) -die_errno (_ ("could not open or read '%s'" ), arg); + }else +strbuf_read_file_or_die (&(msg->buf), arg,0 );stripspace (&(msg->buf),0 ); msg->given =1 ;
builtin/tag.c +2 -5
@@ -540,11 +540,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)if (!strcmp (msgfile,"-" )) {if (strbuf_read (&buf,0 ,1024 ) <0 )die_errno (_ ("cannot read '%s'" ), msgfile); - }else { -if (strbuf_read_file (&buf, msgfile,1024 ) <0 ) -die_errno (_ ("could not open or read '%s'" ), - msgfile); - } + }else +strbuf_read_file_or_die (&buf, msgfile,0 ); } }
strbuf.c +8 -0
@@ -411,6 +411,14 @@ int strbuf_read_file(struct strbuf *sb, const char *path, size_t hint)return len; } +void strbuf_read_file_or_die (struct strbuf *sb,const char *path,size_t size) +{ +int ret; + ret =strbuf_read_file (sb, path, size); +if (ret <0 || (size && ret != size)) +die_errno (_ ("could not open or read '%s'" ), path); +} +void strbuf_add_lines (struct strbuf *out,const char *prefix,const char *buf,size_t size) {
strbuf.h +1 -0
@@ -152,6 +152,7 @@ extern size_t strbuf_fread(struct strbuf *, size_t, FILE *);/* XXX: if read fails, any partial read is undone */ extern ssize_t strbuf_read (struct strbuf *,int fd,size_t hint);extern int strbuf_read_file (struct strbuf *sb,const char *path,size_t hint); +extern void strbuf_read_file_or_die (struct strbuf *sb,const char *path,size_t size);extern int strbuf_readlink (struct strbuf *sb,const char *path,size_t hint);extern int strbuf_getwholeline (struct strbuf *,FILE *,int );
Signature · 1 line
2.3.0.rc1.137.g477eb31
PATCH 2/8 Move reset_tree from builtin/checkout.c to unpack-trees.c
In reply to Nguyễn Thái Ngọc Duy--- builtin/checkout.c | 40 +++------------------------------------- builtin/merge.c | 29 +++++++---------------------- unpack-trees.c | 33 +++++++++++++++++++++++++++++++++ unpack-trees.h | 4 ++++ 4 files changed, 47 insertions(+), 59 deletions(-)
builtin/checkout.c +3 -37
@@ -362,40 +362,6 @@ static void describe_detached_head(const char *msg, struct commit *commit)strbuf_release (&sb); } -static int reset_tree (struct tree *tree,const struct checkout_opts *o, -int worktree,int *writeout_error) -{ -struct unpack_trees_options opts; -struct tree_desc tree_desc; - -memset (&opts,0 ,sizeof (opts)); - opts.head_idx =-1 ; - opts.update = worktree; - opts.skip_unmerged = !worktree; - opts.reset =1 ; - opts.merge =1 ; - opts.fn = oneway_merge; - opts.verbose_update = !o->quiet &&isatty (2 ); - opts.src_index = &the_index; - opts.dst_index = &the_index; -parse_tree (tree); -init_tree_desc (&tree_desc, tree->buffer, tree->size); -switch (unpack_trees (1 , &tree_desc, &opts)) { -case -2 : - *writeout_error =1 ; -/* -* We return 0 nevertheless, as the index is all right -* and more importantly we have made best efforts to -* update paths in the work tree, and we cannot revert -* them. -*/ -case 0 : -return 0 ; -default : -return 128 ; - } -} -struct branch_info {const char *name;/* The short name used */ const char *path;/* The full name of a real branch */
@@ -427,7 +393,7 @@ static int merge_working_tree(const struct checkout_opts *opts,resolve_undo_clear ();if (opts->force) { - ret =reset_tree (new->commit->tree, opts,1 , writeout_error); + ret =reset_tree (new->commit->tree, opts->quiet,1 , writeout_error);if (ret)return ret; }else {
@@ -513,7 +479,7 @@ static int merge_working_tree(const struct checkout_opts *opts, o.verbosity =0 ; work =write_tree_from_memory (&o); - ret =reset_tree (new->commit->tree, opts,1 , + ret =reset_tree (new->commit->tree, opts->quiet,1 , writeout_error);if (ret)return ret;
@@ -522,7 +488,7 @@ static int merge_working_tree(const struct checkout_opts *opts, o.branch2 ="local" ;merge_trees (&o, new->commit->tree, work, old->commit->tree, &result); - ret =reset_tree (new->commit->tree, opts,0 , + ret =reset_tree (new->commit->tree, opts->quiet,0 , writeout_error);if (ret)return ret;
builtin/merge.c +7 -22
@@ -269,33 +269,18 @@ static void read_empty(unsigned const char *sha1, int verbose)die (_ ("read-tree failed" )); } -static void reset_hard (unsigned const char *sha1,int verbose) -{ -int i =0 ; -const char *args[6 ]; - - args[i++] ="read-tree" ; -if (verbose) - args[i++] ="-v" ; - args[i++] ="--reset" ; - args[i++] ="-u" ; - args[i++] =sha1_to_hex (sha1); - args[i] =NULL ; - -if (run_command_v_opt (args,RUN_GIT_CMD )) -die (_ ("read-tree failed" )); -} - -static void restore_state (const unsigned char *head, +static void restore_state (struct commit *head_commit,const unsigned char *stash) {struct strbuf sb =STRBUF_INIT ;const char *args[] = {"stash" ,"apply" ,NULL ,NULL }; +int error =0 ;if (is_null_sha1 (stash))return ; -reset_hard (head,1 ); +if (reset_tree (head_commit->tree,0 ,1 , &error) || error) +die (_ ("read-tree failed" )); args[2 ] =sha1_to_hex (stash);
@@ -1409,7 +1394,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)int ret;if (i) {printf (_ ("Rewinding the tree to pristine...\n" )); -restore_state (head_commit->object.sha1, stash); +restore_state (head_commit, stash); }if (use_strategies_nr !=1 ) printf(_("Trying merge strategy %s...\n"),
@@ -1475,7 +1460,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)* it up. */ if (!best_strategy) { -restore_state (head_commit->object.sha1, stash); +restore_state (head_commit, stash);if (use_strategies_nr >1 )fprintf (stderr,_ ("No merge strategy handled the merge.\n" ));
@@ -1488,7 +1473,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) ;/* We already have its result in the working tree. */ else {printf (_ ("Rewinding the tree to pristine...\n" )); -restore_state (head_commit->object.sha1, stash); +restore_state (head_commit, stash);printf (_ ("Using the %s to prepare resolving by hand.\n" ), best_strategy); try_merge_strategy(best_strategy, common, remoteheads,
unpack-trees.c +33 -0
@@ -1847,3 +1847,36 @@ int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o) }return merged_entry (a, old, o); } + +int reset_tree (struct tree *tree,int quiet,int worktree,int *writeout_error) +{ +struct unpack_trees_options opts; +struct tree_desc tree_desc; + +memset (&opts,0 ,sizeof (opts)); + opts.head_idx =-1 ; + opts.update = worktree; + opts.skip_unmerged = !worktree; + opts.reset =1 ; + opts.merge =1 ; + opts.fn = oneway_merge; + opts.verbose_update = !quiet &&isatty (2 ); + opts.src_index = &the_index; + opts.dst_index = &the_index; +parse_tree (tree); +init_tree_desc (&tree_desc, tree->buffer, tree->size); +switch (unpack_trees (1 , &tree_desc, &opts)) { +case -2 : + *writeout_error =1 ; +/* +* We return 0 nevertheless, as the index is all right +* and more importantly we have made best efforts to +* update paths in the work tree, and we cannot revert +* them. +*/ +case 0 : +return 0 ; +default : +return 128 ; + } +}
unpack-trees.h +4 -0
@@ -83,4 +83,8 @@ int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o);int bind_merge (struct cache_entry **src,struct unpack_trees_options *o);int oneway_merge (struct cache_entry **src,struct unpack_trees_options *o); + +struct tree ; +extern int reset_tree (struct tree *tree,int quiet, +int worktree,int *writeout_error);#endif
Signature · 1 line
2.3.0.rc1.137.g477eb31
PATCH 3/8 rebase: turn rebase--am into a separate program
In reply to Nguyễn Thái Ngọc Duy--- Makefile | 2 +- git-rebase--am.sh (mode +x) | 34 ++++++++++++++++++++++++++++++++++ git-rebase.sh | 11 ++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) mode change 100644 => 100755 git-rebase--am.sh
Makefile +1 -1
@@ -445,6 +445,7 @@ SCRIPT_SH += git-mergetool.sh SCRIPT_SH += git-pull.sh SCRIPT_SH += git-quiltimport.sh SCRIPT_SH += git-rebase.sh +SCRIPT_SH += git-rebase--am.sh SCRIPT_SH += git-repack.sh SCRIPT_SH += git-request-pull.sh SCRIPT_SH += git-stash.sh
@@ -453,7 +454,6 @@ SCRIPT_SH += git-web--browse.sh SCRIPT_LIB += git-mergetool--lib SCRIPT_LIB += git-parse-remote -SCRIPT_LIB += git-rebase--am SCRIPT_LIB += git-rebase--interactive SCRIPT_LIB += git-rebase--merge SCRIPT_LIB += git-sh-setup
git-rebase--am.sh +34 -0
@@ -3,6 +3,40 @@ # Copyright (c) 2010 Junio C Hamano. # +. git-sh-setup +. git-sh-i18n +set_reflog_action rebase +require_work_tree_exists + +GIT_QUIET=$git_quiet + +write_basic_state () { + echo "$head_name" > "$state_dir"/head-name && + echo "$onto" > "$state_dir"/onto && + echo "$orig_head" > "$state_dir"/orig-head && + echo "$GIT_QUIET" > "$state_dir"/quiet && + test t = "$verbose" && : > "$state_dir"/verbose + test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy + test -n "$strategy_opts" && echo "$strategy_opts" > \ + "$state_dir"/strategy_opts + test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \ + "$state_dir"/allow_rerere_autoupdate +} + +move_to_original_branch () { + case "$head_name" in + refs/*) + message="rebase finished: $head_name onto $onto" + git update-ref -m "$message" \ + $head_name $(git rev-parse HEAD) $orig_head && + git symbolic-ref \ + -m "rebase finished: returning to $head_name" \ + HEAD $head_name || + die "$(gettext "Could not move back to $head_name")" + ;; + esac +} + case "$action" in continue) git am --resolved --resolvemsg="$resolvemsg" &&
git-rebase.sh +10 -1
@@ -149,7 +149,16 @@ run_specific_rebase () { export GIT_EDITOR autosquash= fi - . git-rebase--$type + git_quiet=$GIT_QUIET + export GIT_PAGER + export action allow_rerere_autoupdate git_am_opt git_quiet head_name keep_empty + export onto orig_head rebase_root resolvemsg revisions + export state_dir verbose strategy strategy_opts + if [ "$type" = am ]; then + exec git-rebase--am + else + . git-rebase--$type + fi } run_pre_rebase_hook () {
Signature · 1 line
2.3.0.rc1.137.g477eb31
PATCH 4/8 rebase: turn rebase--merge into a separate program
In reply to Nguyễn Thái Ngọc Duy--- Makefile | 2 +- git-rebase--merge.sh (mode +x) | 34 ++++++++++++++++++++++++++++++++++ git-rebase.sh | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) mode change 100644 => 100755 git-rebase--merge.sh
Makefile +1 -1
@@ -446,6 +446,7 @@ SCRIPT_SH += git-pull.sh SCRIPT_SH += git-quiltimport.sh SCRIPT_SH += git-rebase.sh SCRIPT_SH += git-rebase--am.sh +SCRIPT_SH += git-rebase--merge.sh SCRIPT_SH += git-repack.sh SCRIPT_SH += git-request-pull.sh SCRIPT_SH += git-stash.sh
@@ -455,7 +456,6 @@ SCRIPT_SH += git-web--browse.sh SCRIPT_LIB += git-mergetool--lib SCRIPT_LIB += git-parse-remote SCRIPT_LIB += git-rebase--interactive -SCRIPT_LIB += git-rebase--merge SCRIPT_LIB += git-sh-setup SCRIPT_LIB += git-sh-i18n
git-rebase--merge.sh +34 -0
@@ -3,8 +3,42 @@ # Copyright (c) 2010 Junio C Hamano. # +. git-sh-setup +. git-sh-i18n +set_reflog_action rebase +require_work_tree_exists + +GIT_QUIET=$git_quiet + prec=4 +write_basic_state () { + echo "$head_name" > "$state_dir"/head-name && + echo "$onto" > "$state_dir"/onto && + echo "$orig_head" > "$state_dir"/orig-head && + echo "$GIT_QUIET" > "$state_dir"/quiet && + test t = "$verbose" && : > "$state_dir"/verbose + test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy + test -n "$strategy_opts" && echo "$strategy_opts" > \ + "$state_dir"/strategy_opts + test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \ + "$state_dir"/allow_rerere_autoupdate +} + +move_to_original_branch () { + case "$head_name" in + refs/*) + message="rebase finished: $head_name onto $onto" + git update-ref -m "$message" \ + $head_name $(git rev-parse HEAD) $orig_head && + git symbolic-ref \ + -m "rebase finished: returning to $head_name" \ + HEAD $head_name || + die "$(gettext "Could not move back to $head_name")" + ;; + esac +} + read_state () { onto_name=$(cat "$state_dir"/onto_name) && end=$(cat "$state_dir"/end) &&
git-rebase.sh +2 -0
@@ -156,6 +156,8 @@ run_specific_rebase () { export state_dir verbose strategy strategy_opts if [ "$type" = am ]; then exec git-rebase--am + elif [ "$type" = merge ]; then + exec git-rebase--merge else . git-rebase--$type fi
Signature · 1 line
2.3.0.rc1.137.g477eb31
PATCH 5/8 rebase: turn rebase--interactive into a separate program
In reply to Nguyễn Thái Ngọc Duy--- Makefile | 2 +- git-rebase--interactive.sh (mode +x) | 36 +++++++++++++++++++++++++++++++++++- git-rebase.sh | 9 ++------- 3 files changed, 38 insertions(+), 9 deletions(-) mode change 100644 => 100755 git-rebase--interactive.sh
Makefile +1 -1
@@ -446,6 +446,7 @@ SCRIPT_SH += git-pull.sh SCRIPT_SH += git-quiltimport.sh SCRIPT_SH += git-rebase.sh SCRIPT_SH += git-rebase--am.sh +SCRIPT_SH += git-rebase--interactive.sh SCRIPT_SH += git-rebase--merge.sh SCRIPT_SH += git-repack.sh SCRIPT_SH += git-request-pull.sh
@@ -455,7 +456,6 @@ SCRIPT_SH += git-web--browse.sh SCRIPT_LIB += git-mergetool--lib SCRIPT_LIB += git-parse-remote -SCRIPT_LIB += git-rebase--interactive SCRIPT_LIB += git-sh-setup SCRIPT_LIB += git-sh-i18n
git-rebase--interactive.sh +35 -1
@@ -9,7 +9,14 @@ # # The original idea comes from Eric W. Biederman, in # http://article.gmane.org/gmane.comp.version-control.git/22407 -# + +. git-sh-setup +. git-sh-i18n +set_reflog_action "rebase -i ($action)" +require_work_tree_exists + +GIT_QUIET=$git_quiet + # The file containing rebase commands, comments, and empty lines. # This file is created by "git rebase -i" then edited by the user. As # the lines are processed, they are removed from the front of this
@@ -80,6 +87,33 @@ rewritten_pending="$state_dir"/rewritten-pending GIT_CHERRY_PICK_HELP="$resolvemsg" export GIT_CHERRY_PICK_HELP +write_basic_state () { + echo "$head_name" > "$state_dir"/head-name && + echo "$onto" > "$state_dir"/onto && + echo "$orig_head" > "$state_dir"/orig-head && + echo "$GIT_QUIET" > "$state_dir"/quiet && + test t = "$verbose" && : > "$state_dir"/verbose + test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy + test -n "$strategy_opts" && echo "$strategy_opts" > \ + "$state_dir"/strategy_opts + test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \ + "$state_dir"/allow_rerere_autoupdate +} + +output () { + case "$verbose" in + '') + output=$("$@" 2>&1 ) + status=$? + test $status != 0 && printf "%s\n" "$output" + return $status + ;; + *) + "$@" + ;; + esac +} + warn () { printf '%s\n' "$*" >&2 }
git-rebase.sh +2 -7
@@ -154,13 +154,8 @@ run_specific_rebase () { export action allow_rerere_autoupdate git_am_opt git_quiet head_name keep_empty export onto orig_head rebase_root resolvemsg revisions export state_dir verbose strategy strategy_opts - if [ "$type" = am ]; then - exec git-rebase--am - elif [ "$type" = merge ]; then - exec git-rebase--merge - else - . git-rebase--$type - fi + export autosquash cmd force_rebase preserve_merges squash_onto switch_to upstream + exec git-rebase--$type } run_pre_rebase_hook () {
Signature · 1 line
2.3.0.rc1.137.g477eb31
PATCH 6/8 rebase: remove unused function
In reply to Nguyễn Thái Ngọc Duygit-rebase.sh is no longer a dependency for rebase subscripts. This function is only used by subscripts only, which now becomes useless.
--- git-rebase.sh | 13 ------------- 1 file changed, 13 deletions(-)
git-rebase.sh +0 -13
@@ -102,19 +102,6 @@ read_basic_state () { allow_rerere_autoupdate="$(cat "$state_dir"/allow_rerere_autoupdate)" } -write_basic_state () { - echo "$head_name" > "$state_dir"/head-name && - echo "$onto" > "$state_dir"/onto && - echo "$orig_head" > "$state_dir"/orig-head && - echo "$GIT_QUIET" > "$state_dir"/quiet && - test t = "$verbose" && : > "$state_dir"/verbose - test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy - test -n "$strategy_opts" && echo "$strategy_opts" > \ - "$state_dir"/strategy_opts - test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \ - "$state_dir"/allow_rerere_autoupdate -} - output () { case "$verbose" in '')
Signature · 1 line
2.3.0.rc1.137.g477eb31
PATCH 7/8 rebase: move resolvemsg to rebase--* scripts
In reply to Nguyễn Thái Ngọc Duy--- git-rebase--am.sh | 5 +++++ git-rebase--interactive.sh | 5 +++++ git-rebase--merge.sh | 5 +++++ git-rebase.sh | 7 +------ 4 files changed, 16 insertions(+), 6 deletions(-)
git-rebase--am.sh +5 -0
@@ -9,6 +9,11 @@ set_reflog_action rebase require_work_tree_exists GIT_QUIET=$git_quiet +resolvemsg=" +$(gettext 'When you have resolved this problem, run "git rebase --continue". +If you prefer to skip this patch, run "git rebase --skip" instead. +To check out the original branch and stop rebasing, run "git rebase --abort".') +" write_basic_state () { echo "$head_name" > "$state_dir"/head-name &&
git-rebase--interactive.sh +5 -0
@@ -16,6 +16,11 @@ set_reflog_action "rebase -i ($action)" require_work_tree_exists GIT_QUIET=$git_quiet +resolvemsg=" +$(gettext 'When you have resolved this problem, run "git rebase --continue". +If you prefer to skip this patch, run "git rebase --skip" instead. +To check out the original branch and stop rebasing, run "git rebase --abort".') +" # The file containing rebase commands, comments, and empty lines. # This file is created by "git rebase -i" then edited by the user. As
git-rebase--merge.sh +5 -0
@@ -9,6 +9,11 @@ set_reflog_action rebase require_work_tree_exists GIT_QUIET=$git_quiet +resolvemsg=" +$(gettext 'When you have resolved this problem, run "git rebase --continue". +If you prefer to skip this patch, run "git rebase --skip" instead. +To check out the original branch and stop rebasing, run "git rebase --abort".') +" prec=4
git-rebase.sh +1 -6
@@ -49,11 +49,6 @@ cd_to_toplevel LF=' ' ok_to_skip_pre_rebase= -resolvemsg=" -$(gettext 'When you have resolved this problem, run "git rebase --continue". -If you prefer to skip this patch, run "git rebase --skip" instead. -To check out the original branch and stop rebasing, run "git rebase --abort".') -" unset onto cmd= strategy=
@@ -139,7 +134,7 @@ run_specific_rebase () { git_quiet=$GIT_QUIET export GIT_PAGER export action allow_rerere_autoupdate git_am_opt git_quiet head_name keep_empty - export onto orig_head rebase_root resolvemsg revisions + export onto orig_head rebase_root revisions export state_dir verbose strategy strategy_opts export autosquash cmd force_rebase preserve_merges squash_onto switch_to upstream exec git-rebase--$type
Signature · 1 line
2.3.0.rc1.137.g477eb31
PATCH 8/8 Build in rebase
In reply to Nguyễn Thái Ngọc Duy--- Makefile | 2 +- builtin.h | 1 + builtin/rebase.c (new) | 752 ++++++++++++++++++++++++++++++++ commit.c | 4 +- commit.h | 4 +- contrib/examples/git-rebase.sh (new +x) | 532 ++++++++++++++++++++++ git-rebase.sh (gone) | 532 ---------------------- git.c | 1 + 8 files changed, 1291 insertions(+), 537 deletions(-) create mode 100644 builtin/rebase.c create mode 100755 contrib/examples/git-rebase.sh delete mode 100755 git-rebase.sh
Makefile +1 -1
@@ -444,7 +444,6 @@ SCRIPT_SH += git-merge-resolve.sh SCRIPT_SH += git-mergetool.sh SCRIPT_SH += git-pull.sh SCRIPT_SH += git-quiltimport.sh -SCRIPT_SH += git-rebase.sh SCRIPT_SH += git-rebase--am.sh SCRIPT_SH += git-rebase--interactive.sh SCRIPT_SH += git-rebase--merge.sh
@@ -903,6 +902,7 @@ BUILTIN_OBJS += builtin/prune-packed.o BUILTIN_OBJS += builtin/prune.o BUILTIN_OBJS += builtin/push.o BUILTIN_OBJS += builtin/read-tree.o +BUILTIN_OBJS += builtin/rebase.o BUILTIN_OBJS += builtin/receive-pack.o BUILTIN_OBJS += builtin/reflog.o BUILTIN_OBJS += builtin/remote.o
builtin.h +1 -0
@@ -108,6 +108,7 @@ extern int cmd_prune(int argc, const char **argv, const char *prefix);extern int cmd_prune_packed (int argc,const char **argv,const char *prefix);extern int cmd_push (int argc,const char **argv,const char *prefix);extern int cmd_read_tree (int argc,const char **argv,const char *prefix); +extern int cmd_rebase (int argc,const char **argv,const char *prefix);extern int cmd_receive_pack (int argc,const char **argv,const char *prefix);extern int cmd_reflog (int argc,const char **argv,const char *prefix);extern int cmd_remote (int argc,const char **argv,const char *prefix);
builtin/rebase.c new file +752 -0
752 lines not on this page · raw message
commit.c +2 -2
@@ -1135,7 +1135,7 @@ void free_commit_extra_headers(struct commit_extra_header *extra) } } -int commit_tree (const struct strbuf *msg,unsigned char *tree, +int commit_tree (const struct strbuf *msg,const unsigned char *tree,struct commit_list *parents,unsigned char *ret,const char *author,const char *sign_commit) {
@@ -1238,7 +1238,7 @@ static const char commit_utf8_warn[] ="You may want to amend it after fixing the message, or set the config\n" "variable i18n.commitencoding to the encoding your project uses.\n" ; -int commit_tree_extended (const struct strbuf *msg,unsigned char *tree, +int commit_tree_extended (const struct strbuf *msg,const unsigned char *tree,struct commit_list *parents,unsigned char *ret,const char *author,const char *sign_commit,struct commit_extra_header *extra)
commit.h +2 -2
@@ -193,11 +193,11 @@ struct commit_extra_header {extern void append_merge_tag_headers (struct commit_list *parents,struct commit_extra_header ***tail); -extern int commit_tree (const struct strbuf *msg,unsigned char *tree, +extern int commit_tree (const struct strbuf *msg,const unsigned char *tree,struct commit_list *parents,unsigned char *ret,const char *author,const char *sign_commit); -extern int commit_tree_extended (const struct strbuf *msg,unsigned char *tree, +extern int commit_tree_extended (const struct strbuf *msg,const unsigned char *tree,struct commit_list *parents,unsigned char *ret,const char *author,const char *sign_commit,struct commit_extra_header *);
contrib/examples/git-rebase.sh new file +532 -0
532 lines not on this page · raw message
git-rebase.sh deleted +0 -532
532 lines not on this page · raw message
git.c +1 -0
@@ -379,6 +379,7 @@ static void handle_internal_command(int argc, const char **argv) { "prune-packed", cmd_prune_packed, RUN_SETUP }, { "push", cmd_push, RUN_SETUP }, { "read-tree", cmd_read_tree, RUN_SETUP }, + { "rebase", cmd_rebase, RUN_SETUP | NEED_WORK_TREE }, { "receive-pack", cmd_receive_pack }, { "reflog", cmd_reflog, RUN_SETUP }, { "remote", cmd_remote, RUN_SETUP },
Signature · 1 line
2.3.0.rc1.137.g477eb31