shortstatus updates
Subsystems (2)
v3 cover shortstatus updates
Another round of "git status won't be a preview of git commit someday". This builds on the part that are already in 'pu', and is queued in 'pu'.
Junio C Hamano (8):
commit: --dry-run
wt-status: move many global settings to wt_status structure
wt-status: move wt_status_colors[] into wt_status structure Make git_status_config() file scope static to builtin-commit.c
wt-status: collect untracked files in a separate "collect" phase git stat: the beginning
git stat: pathspec limits, unlike traditional "git status" git stat -s: short status output
Documentation/git-commit.txt | 7 +- Makefile | 1 + builtin-commit.c | 312 +++++++++++++++++++++++++++++++++++------- builtin.h | 1 + git.c | 1 + wt-status.c | 206 ++++++++++++---------------- wt-status.h | 17 ++- 7 files changed, 367 insertions(+), 178 deletions(-)
PATCH v3 1/8 commit: --dry-run
This teaches --dry-run option to "git commit".
It is the same as "git status", but in the longer term we would want to change the semantics of "git status" not to be the preview of commit, and this is the first step for doing so.
--- Documentation/git-commit.txt | 7 ++++++- builtin-commit.c | 29 ++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-)
Documentation/git-commit.txt +6 -1
@@ -8,7 +8,7 @@ git-commit - Record changes to the repository SYNOPSIS -------- [verse] -'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] +'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run] [(-c | -C) <commit>] [-F <file> | -m <msg>] [--allow-empty] [--no-verify] [-e] [--author=<author>] [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
@@ -198,6 +198,11 @@ specified. --quiet:: Suppress commit summary message. +--dry-run:: + Do not create a commit, but show a list of paths that are + to be committed, paths with local changes that will be left + uncommitted and paths that are untracked. + \--:: Do not interpret any more arguments as options.
builtin-commit.c +16 -13
@@ -51,7 +51,7 @@ static const char *template_file;static char *edit_message, *use_message;static char *author_name, *author_email, *author_date;static int all, edit_flag, also, interactive, only, amend, signoff; -static int quiet, verbose, no_verify, allow_empty; +static int quiet, verbose, no_verify, allow_empty, dry_run;static char *untracked_files_arg;/* * The default commit message cleanup mode will remove the lines
@@ -103,6 +103,7 @@ static struct option builtin_commit_options[] = {OPT_BOOLEAN (0 ,"interactive" , &interactive,"interactively add files" ),OPT_BOOLEAN ('o' ,"only" , &only,"commit only specified files" ),OPT_BOOLEAN ('n' ,"no-verify" , &no_verify,"bypass pre-commit hook" ), +OPT_BOOLEAN (0 ,"dry-run" , &dry_run,"show what would be committed" ),OPT_BOOLEAN (0 ,"amend" , &amend,"amend previous commit" ), { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" }, OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
@@ -813,28 +814,28 @@ static int parse_and_validate_options(int argc, const char *argv[],return argc; } -int cmd_status (int argc,const char **argv,const char *prefix) +static int dry_run_commit (int argc,const char **argv,const char *prefix) { -const char *index_file;int commitable; +const char *index_file; -git_config (git_status_config,NULL ); + index_file =prepare_index (argc, argv, prefix,1 ); + commitable =run_status (stdout, index_file, prefix,0 ); +rollback_index_files (); +return commitable ?0 :1 ; +} + +int cmd_status (int argc,const char **argv,const char *prefix) +{ +git_config (git_status_config,NULL );if (wt_status_use_color ==-1 ) wt_status_use_color = git_use_color_default; -if (diff_use_color_default ==-1 ) diff_use_color_default = git_use_color_default; argc =parse_and_validate_options (argc, argv, builtin_status_usage, prefix); - - index_file =prepare_index (argc, argv, prefix,1 ); - - commitable =run_status (stdout, index_file, prefix,0 ); - -rollback_index_files (); - -return commitable ?0 :1 ; +return dry_run_commit (argc, argv, prefix); }static void print_summary (const char *prefix,const unsigned char *sha1)
@@ -909,6 +910,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) wt_status_use_color = git_use_color_default; argc =parse_and_validate_options (argc, argv, builtin_commit_usage, prefix); +if (dry_run) +return dry_run_commit (argc, argv, prefix); index_file =prepare_index (argc, argv, prefix,0 );
Signature · 1 line
1.6.4.173.g72959
PATCH v3 2/8 wt-status: move many global settings to wt_status structure
Turn four global variables (wt_status_use_color, show_tracked_files, wt_status_relative_paths, and wt_status_submodule_summary) into fields of wt_status structure. Get rid of "untracked" field that was used only to keep track of otherwise available information redundantly.
--- builtin-commit.c | 87 +++++++++++++++++++++++++++++------------------------ wt-status.c | 81 +++++++++++++++++++++++++------------------------- wt-status.h | 9 +++-- 3 files changed, 93 insertions(+), 84 deletions(-)
builtin-commit.c +48 -39
@@ -343,27 +343,24 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, intreturn false_lock.filename; } -static int run_status (FILE *fp,const char *index_file,const char *prefix,int nowarn) +static int run_status (FILE *fp,const char *index_file,const char *prefix,int nowarn, +struct wt_status *s) { -struct wt_status s; - -wt_status_prepare (&s); -if (wt_status_relative_paths) - s.prefix = prefix; +if (s->wt_status_relative_paths) + s->prefix = prefix;if (amend) { - s.amend =1 ; - s.reference ="HEAD^1" ; + s->amend =1 ; + s->reference ="HEAD^1" ; } - s.verbose = verbose; - s.untracked = (show_untracked_files ==SHOW_ALL_UNTRACKED_FILES ); - s.index_file = index_file; - s.fp = fp; - s.nowarn = nowarn; + s->verbose = verbose; + s->index_file = index_file; + s->fp = fp; + s->nowarn = nowarn; -wt_status_print (&s); +wt_status_print (s); -return s.commitable; +return s->commitable; }static int is_a_merge (const unsigned char *sha1)
@@ -417,7 +414,8 @@ static void determine_author_info(void) author_date = date; } -static int prepare_to_commit (const char *index_file,const char *prefix) +static int prepare_to_commit (const char *index_file,const char *prefix, +struct wt_status *s) {struct stat statbuf;int commitable, saved_color_setting;
@@ -559,10 +557,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix)if (ident_shown)fprintf (fp,"#\n" ); - saved_color_setting = wt_status_use_color; - wt_status_use_color =0 ; - commitable =run_status (fp, index_file, prefix,1 ); - wt_status_use_color = saved_color_setting; + saved_color_setting = s->wt_status_use_color; + s->wt_status_use_color =0 ; + commitable =run_status (fp, index_file, prefix,1 , s); + s->wt_status_use_color = saved_color_setting; }else {unsigned char sha1[20 ];const char *parent ="HEAD" ;
@@ -583,7 +581,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)if (!commitable && !in_merge && !allow_empty && !(amend &&is_a_merge (head_sha1))) { -run_status (stdout, index_file, prefix,0 ); +run_status (stdout, index_file, prefix,0 , s);return 0 ; }
@@ -695,7 +693,8 @@ static const char *find_author_by_nickname(const char *name)static int parse_and_validate_options (int argc,const char *argv[],const char *const usage[], -const char *prefix) +const char *prefix, +struct wt_status *s) {int f =0 ;
@@ -798,11 +797,11 @@ static int parse_and_validate_options(int argc, const char *argv[],if (!untracked_files_arg) ;/* default already initialized */ else if (!strcmp (untracked_files_arg,"no" )) - show_untracked_files =SHOW_NO_UNTRACKED_FILES ; + s->show_untracked_files =SHOW_NO_UNTRACKED_FILES ;else if (!strcmp (untracked_files_arg,"normal" )) - show_untracked_files =SHOW_NORMAL_UNTRACKED_FILES ; + s->show_untracked_files =SHOW_NORMAL_UNTRACKED_FILES ;else if (!strcmp (untracked_files_arg,"all" )) - show_untracked_files =SHOW_ALL_UNTRACKED_FILES ; + s->show_untracked_files =SHOW_ALL_UNTRACKED_FILES ;else die ("Invalid untracked files mode '%s'" , untracked_files_arg);
@@ -814,13 +813,14 @@ static int parse_and_validate_options(int argc, const char *argv[],return argc; } -static int dry_run_commit (int argc,const char **argv,const char *prefix) +static int dry_run_commit (int argc,const char **argv,const char *prefix, +struct wt_status *s) {int commitable;const char *index_file; index_file =prepare_index (argc, argv, prefix,1 ); - commitable =run_status (stdout, index_file, prefix,0 ); + commitable =run_status (stdout, index_file, prefix,0 , s);rollback_index_files ();return commitable ?0 :1 ;
@@ -828,14 +828,18 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix)int cmd_status (int argc,const char **argv,const char *prefix) { -git_config (git_status_config,NULL ); -if (wt_status_use_color ==-1 ) - wt_status_use_color = git_use_color_default; +struct wt_status s; + +wt_status_prepare (&s); +git_config (git_status_config, &s); +if (s.wt_status_use_color ==-1 ) + s.wt_status_use_color = git_use_color_default;if (diff_use_color_default ==-1 ) diff_use_color_default = git_use_color_default; - argc =parse_and_validate_options (argc, argv, builtin_status_usage, prefix); -return dry_run_commit (argc, argv, prefix); + argc =parse_and_validate_options (argc, argv, builtin_status_usage, + prefix, &s); +return dry_run_commit (argc, argv, prefix, &s); }static void print_summary (const char *prefix,const unsigned char *sha1)
@@ -887,10 +891,12 @@ static void print_summary(const char *prefix, const unsigned char *sha1)static int git_commit_config (const char *k,const char *v,void *cb) { +struct wt_status *s = cb; +if (!strcmp (k,"commit.template" ))return git_config_string (&template_file, k, v); -return git_status_config (k, v, cb); +return git_status_config (k, v, s); }int cmd_commit (int argc,const char **argv,const char *prefix)
@@ -903,21 +909,24 @@ int cmd_commit(int argc, const char **argv, const char *prefix)struct commit_list *parents =NULL , **pptr = &parents;struct stat statbuf;int allow_fast_forward =1 ; +struct wt_status s; -git_config (git_commit_config,NULL ); +wt_status_prepare (&s); +git_config (git_commit_config, &s); -if (wt_status_use_color ==-1 ) - wt_status_use_color = git_use_color_default; +if (s.wt_status_use_color ==-1 ) + s.wt_status_use_color = git_use_color_default; - argc =parse_and_validate_options (argc, argv, builtin_commit_usage, prefix); + argc =parse_and_validate_options (argc, argv, builtin_commit_usage, + prefix, &s);if (dry_run) -return dry_run_commit (argc, argv, prefix); +return dry_run_commit (argc, argv, prefix, &s); index_file =prepare_index (argc, argv, prefix,0 );/* Set up everything for writing the commit object. This includes running hooks, writing the trees, and interacting with the user. */ -if (!prepare_to_commit (index_file, prefix)) { +if (!prepare_to_commit (index_file, prefix, &s)) {rollback_index_files ();return 1 ; }
wt-status.c +40 -41
242 lines not on this page · raw message
wt-status.h +5 -4
@@ -18,7 +18,6 @@ enum untracked_status_type { SHOW_NORMAL_UNTRACKED_FILES,SHOW_ALL_UNTRACKED_FILES }; -extern enum untracked_status_type show_untracked_files;struct wt_status_change_data {int worktree_status;
@@ -33,8 +32,12 @@ struct wt_status {const char *reference;int verbose;int amend; -int untracked;int nowarn; +int wt_status_use_color; +int wt_status_relative_paths; +int wt_status_submodule_summary; +enum untracked_status_type show_untracked_files; +/* These are computed during processing of the individual sections */ int commitable;int workdir_dirty;
@@ -46,8 +49,6 @@ struct wt_status { };int git_status_config (const char *var,const char *value,void *cb); -extern int wt_status_use_color; -extern int wt_status_relative_paths;void wt_status_prepare (struct wt_status *s);void wt_status_print (struct wt_status *s);void wt_status_collect_changes (struct wt_status *s);
Signature · 1 line
1.6.4.173.g72959
PATCH v3 3/8 wt-status: move wt_status_colors[] into wt_status structure
The benefit of this one alone is somewhat iffy, but for completeness this moves the wt_status_colors[] color palette to the wt_status structure to complete what the previous commit started.
--- wt-status.c | 9 +++++---- wt-status.h | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-)
wt-status.c +5 -4
@@ -1,6 +1,5 @@#include "cache.h" #include "wt-status.h" -#include "color.h" #include "object.h" #include "dir.h" #include "commit.h"
@@ -11,7 +10,7 @@#include "run-command.h" #include "remote.h" -static char wt_status_colors[][COLOR_MAXLEN ] = { +static char default_wt_status_colors[][COLOR_MAXLEN ] = {GIT_COLOR_NORMAL ,/* WT_STATUS_HEADER */ GIT_COLOR_GREEN ,/* WT_STATUS_UPDATED */ GIT_COLOR_RED ,/* WT_STATUS_CHANGED */
@@ -40,7 +39,7 @@ static int parse_status_slot(const char *var, int offset)static const char *color (int slot,struct wt_status *s) { -return s->wt_status_use_color >0 ? wt_status_colors[slot] :"" ; +return s->wt_status_use_color >0 ? s->wt_status_colors[slot] :"" ; }void wt_status_prepare (struct wt_status *s)
@@ -49,6 +48,8 @@ void wt_status_prepare(struct wt_status *s)const char *head;memset (s,0 ,sizeof (*s)); +memcpy (s->wt_status_colors, default_wt_status_colors, +sizeof (default_wt_status_colors)); s->show_untracked_files =SHOW_NORMAL_UNTRACKED_FILES ; s->wt_status_use_color =-1 ; s->wt_status_relative_paths =1 ;
@@ -613,7 +614,7 @@ int git_status_config(const char *k, const char *v, void *cb)int slot =parse_status_slot (k,13 );if (!v)return config_error_nonbool (k); -color_parse (v, k, wt_status_colors[slot]); +color_parse (v, k, s->wt_status_colors[slot]);return 0 ; }if (!strcmp (k,"status.relativepaths" )) {
wt-status.h +2 -0
@@ -3,6 +3,7 @@#include <stdio.h> #include "string-list.h" +#include "color.h" enum color_wt_status {WT_STATUS_HEADER ,
@@ -37,6 +38,7 @@ struct wt_status {int wt_status_relative_paths;int wt_status_submodule_summary;enum untracked_status_type show_untracked_files; +char wt_status_colors[6 ][COLOR_MAXLEN ];/* These are computed during processing of the individual sections */ int commitable;
Signature · 1 line
1.6.4.173.g72959
PATCH v3 4/8 Make git_status_config() file scope static to builtin-commit.c
--- builtin-commit.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ wt-status.c | 60 ------------------------------------------------------ wt-status.h | 1 - 3 files changed, 60 insertions(+), 61 deletions(-)
builtin-commit.c +60 -0
@@ -826,6 +826,66 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix,return commitable ?0 :1 ; } +static int parse_status_slot (const char *var,int offset) +{ +if (!strcasecmp (var+offset,"header" )) +return WT_STATUS_HEADER ; +if (!strcasecmp (var+offset,"updated" ) + || !strcasecmp (var+offset,"added" )) +return WT_STATUS_UPDATED ; +if (!strcasecmp (var+offset,"changed" )) +return WT_STATUS_CHANGED ; +if (!strcasecmp (var+offset,"untracked" )) +return WT_STATUS_UNTRACKED ; +if (!strcasecmp (var+offset,"nobranch" )) +return WT_STATUS_NOBRANCH ; +if (!strcasecmp (var+offset,"unmerged" )) +return WT_STATUS_UNMERGED ; +die ("bad config variable '%s'" , var); +} + +static int git_status_config (const char *k,const char *v,void *cb) +{ +struct wt_status *s = cb; + +if (!strcmp (k,"status.submodulesummary" )) { +int is_bool; + s->wt_status_submodule_summary =git_config_bool_or_int (k, v, &is_bool); +if (is_bool && s->wt_status_submodule_summary) + s->wt_status_submodule_summary =-1 ; +return 0 ; + } +if (!strcmp (k,"status.color" ) || !strcmp (k,"color.status" )) { + s->wt_status_use_color =git_config_colorbool (k, v,-1 ); +return 0 ; + } +if (!prefixcmp (k,"status.color." ) || !prefixcmp (k,"color.status." )) { +int slot =parse_status_slot (k,13 ); +if (!v) +return config_error_nonbool (k); +color_parse (v, k, s->wt_status_colors[slot]); +return 0 ; + } +if (!strcmp (k,"status.relativepaths" )) { + s->wt_status_relative_paths =git_config_bool (k, v); +return 0 ; + } +if (!strcmp (k,"status.showuntrackedfiles" )) { +if (!v) +return config_error_nonbool (k); +else if (!strcmp (v,"no" )) + s->show_untracked_files =SHOW_NO_UNTRACKED_FILES ; +else if (!strcmp (v,"normal" )) + s->show_untracked_files =SHOW_NORMAL_UNTRACKED_FILES ; +else if (!strcmp (v,"all" )) + s->show_untracked_files =SHOW_ALL_UNTRACKED_FILES ; +else +return error ("Invalid untracked files mode '%s'" , v); +return 0 ; + } +return git_diff_ui_config (k, v,NULL ); +} +int cmd_status (int argc,const char **argv,const char *prefix) {struct wt_status s;
wt-status.c +0 -60
69 lines not on this page · raw message
wt-status.h +0 -1
@@ -50,7 +50,6 @@ struct wt_status {struct string_list change; }; -int git_status_config (const char *var,const char *value,void *cb);void wt_status_prepare (struct wt_status *s);void wt_status_print (struct wt_status *s);void wt_status_collect_changes (struct wt_status *s);
Signature · 1 line
1.6.4.173.g72959
PATCH v3 5/8 wt-status: collect untracked files in a separate "collect" phase
In a way similar to updated and locally modified files are collected.
--- wt-status.c | 58 ++++++++++++++++++++++++++++++++++++---------------------- wt-status.h | 3 ++- 2 files changed, 38 insertions(+), 23 deletions(-)
wt-status.c +36 -22
@@ -41,6 +41,7 @@ void wt_status_prepare(struct wt_status *s) s->fp = stdout; s->index_file =get_index_file (); s->change.strdup_strings =1 ; + s->untracked.strdup_strings =1 ; }static void wt_status_print_unmerged_header (struct wt_status *s)
@@ -311,7 +312,30 @@ static void wt_status_collect_changes_initial(struct wt_status *s) } } -void wt_status_collect_changes (struct wt_status *s) +static void wt_status_collect_untracked (struct wt_status *s) +{ +int i; +struct dir_struct dir; + +if (!s->show_untracked_files) +return ; +memset (&dir,0 ,sizeof (dir)); +if (s->show_untracked_files !=SHOW_ALL_UNTRACKED_FILES ) + dir.flags |= +DIR_SHOW_OTHER_DIRECTORIES |DIR_HIDE_EMPTY_DIRECTORIES ; +setup_standard_excludes (&dir); + +fill_directory (&dir,NULL ); +for (i =0 ; i < dir.nr; i++) { +struct dir_entry *ent = dir.entries[i]; +if (!cache_name_is_other (ent->name, ent->len)) +continue ; + s->workdir_untracked =1 ; +string_list_insert (ent->name, &s->untracked); + } +} + +void wt_status_collect (struct wt_status *s) {wt_status_collect_changes_worktree (s);
@@ -319,6 +343,7 @@ void wt_status_collect_changes(struct wt_status *s)wt_status_collect_changes_initial (s); elsewt_status_collect_changes_index (s ); +wt_status_collect_untracked (s); }static void wt_status_print_unmerged (struct wt_status *s)
@@ -446,31 +471,20 @@ static void wt_status_print_submodule_summary(struct wt_status *s)static void wt_status_print_untracked (struct wt_status *s) { -struct dir_struct dir;int i; -int shown_header =0 ;struct strbuf buf =STRBUF_INIT ; -memset (&dir,0 ,sizeof (dir)); -if (s->show_untracked_files !=SHOW_ALL_UNTRACKED_FILES ) - dir.flags |= -DIR_SHOW_OTHER_DIRECTORIES |DIR_HIDE_EMPTY_DIRECTORIES ; -setup_standard_excludes (&dir); +if (!s->untracked.nr) +return ; -fill_directory (&dir,NULL ); -for (i =0 ; i < dir.nr; i++) { -struct dir_entry *ent = dir.entries[i]; -if (!cache_name_is_other (ent->name, ent->len)) -continue ; -if (!shown_header) { - s->workdir_untracked =1 ; -wt_status_print_untracked_header (s); - shown_header =1 ; - } +wt_status_print_untracked_header (s); +for (i =0 ; i < s->untracked.nr; i++) { +struct string_list_item *it; + it = &(s->untracked.items[i]);color_fprintf (s->fp,color (WT_STATUS_HEADER , s),"#\t" );color_fprintf_ln (s->fp,color (WT_STATUS_UNTRACKED , s),"%s" , -quote_path (ent->name, ent->len, - &buf, s->prefix)); +quote_path (it->string,strlen (it->string), + &buf, s->prefix)); }strbuf_release (&buf); }
@@ -539,7 +553,7 @@ void wt_status_print(struct wt_status *s)wt_status_print_tracking (s); } -wt_status_collect_changes (s); +wt_status_collect (s);if (s->is_initial) {color_fprintf_ln (s->fp,color (WT_STATUS_HEADER , s),"#" );
@@ -566,7 +580,7 @@ void wt_status_print(struct wt_status *s) ;/* nothing */ else if (s->workdir_dirty) printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"); - else if (s->workdir_untracked) + else if (s->untracked.nr) printf("nothing added to commit but untracked files present (use \"git add\" to track)\n"); else if (s->is_initial) printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
wt-status.h +2 -1
@@ -48,10 +48,11 @@ struct wt_status {FILE *fp;const char *prefix;struct string_list change; + struct string_list untracked; };void wt_status_prepare (struct wt_status *s);void wt_status_print (struct wt_status *s); -void wt_status_collect_changes (struct wt_status *s); +void wt_status_collect (struct wt_status *s);#endif /* STATUS_H */
Signature · 1 line
1.6.4.173.g72959
PATCH v3 6/8 git stat: the beginning
Tentatively add "git stat" as a new command. This does not munge the index with paths parameters before showing the status like "git status" does. In later rounds, we will take path parameters as pathspec to limit the output.
--- Makefile | 1 + builtin-commit.c | 60 +++++++++++++++++++++++++++++++++++++++++++++--------- builtin.h | 1 + git.c | 1 + wt-status.c | 24 +++++++++++++-------- wt-status.h | 1 + 6 files changed, 69 insertions(+), 19 deletions(-)
Makefile +1 -0
@@ -378,6 +378,7 @@ BUILT_INS += git-init$X BUILT_INS += git-merge-subtree$X BUILT_INS += git-peek-remote$X BUILT_INS += git-repo-config$X +BUILT_INS += git-stat$X BUILT_INS += git-show$X BUILT_INS += git-stage$X BUILT_INS += git-status$X
builtin-commit.c +50 -10
90 lines not on this page · raw message
builtin.h +1 -0
@@ -95,6 +95,7 @@ extern int cmd_send_pack(int argc, const char **argv, const char *prefix);extern int cmd_shortlog (int argc,const char **argv,const char *prefix);extern int cmd_show (int argc,const char **argv,const char *prefix);extern int cmd_show_branch (int argc,const char **argv,const char *prefix); +extern int cmd_stat (int argc,const char **argv,const char *prefix);extern int cmd_status (int argc,const char **argv,const char *prefix);extern int cmd_stripspace (int argc,const char **argv,const char *prefix);extern int cmd_symbolic_ref (int argc,const char **argv,const char *prefix);
git.c +1 -0
@@ -350,6 +350,7 @@ static void handle_internal_command(int argc, const char **argv) { "shortlog", cmd_shortlog, USE_PAGER }, { "show-branch", cmd_show_branch, RUN_SETUP }, { "show", cmd_show, RUN_SETUP | USE_PAGER }, + { "stat", cmd_stat, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
wt-status.c +15 -9
@@ -531,6 +531,20 @@ static void wt_status_print_tracking(struct wt_status *s)color_fprintf_ln (s->fp,color (WT_STATUS_HEADER , s),"#" ); } +void wt_status_print_body (struct wt_status *s) +{ +wt_status_print_unmerged (s); +wt_status_print_updated (s); +wt_status_print_changed (s); +if (s->wt_status_submodule_summary) +wt_status_print_submodule_summary (s); +if (s->show_untracked_files) +wt_status_print_untracked (s); +else if (s->commitable) +fprintf (s->fp, +"# Untracked files not listed (use -u option to show untracked files)\n" ); +} +void wt_status_print (struct wt_status *s) {unsigned char sha1[20 ];
@@ -561,15 +575,7 @@ void wt_status_print(struct wt_status *s)color_fprintf_ln (s->fp,color (WT_STATUS_HEADER , s),"#" ); } -wt_status_print_unmerged (s); -wt_status_print_updated (s); -wt_status_print_changed (s); -if (s->wt_status_submodule_summary) -wt_status_print_submodule_summary (s); -if (s->show_untracked_files) -wt_status_print_untracked (s); -else if (s->commitable) -fprintf (s->fp,"# Untracked files not listed (use -u option to show untracked files)\n" ); +wt_status_print_body (s);if (s->verbose)wt_status_print_verbose (s);
wt-status.h +1 -0
@@ -54,5 +54,6 @@ struct wt_status {void wt_status_prepare (struct wt_status *s);void wt_status_print (struct wt_status *s);void wt_status_collect (struct wt_status *s); +void wt_status_print_body (struct wt_status *s);#endif /* STATUS_H */
Signature · 1 line
1.6.4.173.g72959
PATCH v3 7/8 git stat: pathspec limits, unlike traditional "git status"
The "git stat" command is not "preview of commit with the same arguments"; the path parameters are not paths to be added to the pristine index (aka "--only" option), but are taken as pathspecs to limit the output.
--- builtin-commit.c | 3 +++ wt-status.c | 6 ++++++ wt-status.h | 1 + 3 files changed, 10 insertions(+), 0 deletions(-)
builtin-commit.c +3 -0
@@ -917,6 +917,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix) builtin_stat_usage, 0);handle_untracked_files_arg (&s); +if (*argv) + s.pathspec =get_pathspec (prefix, argv); +read_cache ();refresh_cache (REFRESH_QUIET |REFRESH_UNMERGED ); s.is_initial =get_sha1 (s.reference, sha1) ?1 :0 ;
wt-status.c +6 -0
@@ -269,6 +269,7 @@ static void wt_status_collect_changes_worktree(struct wt_status *s) rev.diffopt.output_format |=DIFF_FORMAT_CALLBACK ; rev.diffopt.format_callback = wt_status_collect_changed_cb; rev.diffopt.format_callback_data = s; + rev.prune_data = s->pathspec;run_diff_files (&rev,0 ); }
@@ -285,6 +286,7 @@ static void wt_status_collect_changes_index(struct wt_status *s) rev.diffopt.detect_rename =1 ; rev.diffopt.rename_limit =200 ; rev.diffopt.break_opt =0 ; + rev.prune_data = s->pathspec;run_diff_index (&rev,1 ); }
@@ -297,6 +299,8 @@ static void wt_status_collect_changes_initial(struct wt_status *s)struct wt_status_change_data *d;struct cache_entry *ce = active_cache[i]; +if (!ce_path_match (ce, s->pathspec)) +continue ; it =string_list_insert (ce->name, &s->change); d = it->util;if (!d) {
@@ -330,6 +334,8 @@ static void wt_status_collect_untracked(struct wt_status *s)struct dir_entry *ent = dir.entries[i];if (!cache_name_is_other (ent->name, ent->len))continue ; +if (!match_pathspec (s->pathspec, ent->name, ent->len,0 ,NULL )) +continue ; s->workdir_untracked =1 ;string_list_insert (ent->name, &s->untracked); }
wt-status.h +1 -0
@@ -31,6 +31,7 @@ struct wt_status {int is_initial;char *branch;const char *reference; +const char **pathspec;int verbose;int amend;int nowarn;
Signature · 1 line
1.6.4.173.g72959
PATCH v3 8/8 git stat -s: short status output
Give -s(hort) option to "git stat" that shows the status of paths in a more concise way.
XY PATH1 -> PATH2
format to be more machine readable than output from "git status", which is about previewing of "git commit" with the same arguments.
PATH1 is the path in the HEAD, and " -> PATH2" part is shown only when PATH1 corresponds to a different path in the index/worktree.
For unmerged entries, X shows the status of stage #2 (i.e. ours) and Y shows the status of stage #3 (i.e. theirs). For entries that do not have conflicts, X shows the status of the index, and Y shows the status of the work tree. For untracked paths, XY are "??".
X Y Meaning
-------------------------------------------------
[MD] not updated
M [ MD] updated in index
A [ MD] added to index
D [ MD] deleted from index
R [ MD] renamed in index
C [ MD] copied in index
[MARC] index and work tree matches
[ MARC] M work tree changed since index
[ MARC] D deleted in work tree
D D unmerged, both deleted
A U unmerged, added by us
U D unmerged, deleted by them
U A unmerged, added by them
D U unmerged, deleted by us
A A unmerged, both added
U U unmerged, both modified
? ? untracked
When given -z option, the records are terminated by NUL characters for better machine readability.
--- builtin-commit.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 96 insertions(+), 1 deletions(-)
builtin-commit.c +96 -1
@@ -898,11 +898,86 @@ static int git_status_config(const char *k, const char *v, void *cb)return git_diff_ui_config (k, v,NULL ); } +#define quote_path quote_path_relative + +static void short_unmerged (int null_termination,struct string_list_item *it, +struct wt_status *s) +{ +struct wt_status_change_data *d = it->util; +const char *how ="??" ; + +switch (d->stagemask) { +case 1 : how ="DD" ;break ;/* both deleted */ +case 2 : how ="AU" ;break ;/* added by us */ +case 3 : how ="UD" ;break ;/* deleted by them */ +case 4 : how ="UA" ;break ;/* added by them */ +case 5 : how ="DU" ;break ;/* deleted by us */ +case 6 : how ="AA" ;break ;/* both added */ +case 7 : how ="UU" ;break ;/* both modified */ + } +printf ("%s " , how); +if (null_termination) { +fprintf (stdout,"%s%c" , it->string,0 ); + }else { +struct strbuf onebuf =STRBUF_INIT ; +const char *one; + one =quote_path (it->string,-1 , &onebuf, s->prefix); +printf ("%s\n" , one); +strbuf_release (&onebuf); + } +} + +static void short_status (int null_termination,struct string_list_item *it, +struct wt_status *s) +{ +struct wt_status_change_data *d = it->util; + +printf ("%c%c " , + !d->index_status ?' ' : d->index_status, + !d->worktree_status ?' ' : d->worktree_status); +if (null_termination) { +fprintf (stdout,"%s%c" , it->string,0 ); +if (d->head_path) +fprintf (stdout,"%s%c" , d->head_path,0 ); + }else { +struct strbuf onebuf =STRBUF_INIT ; +const char *one; +if (d->head_path) { + one =quote_path (d->head_path,-1 , &onebuf, s->prefix); +printf ("%s -> " , one); +strbuf_release (&onebuf); + } + one =quote_path (it->string,-1 , &onebuf, s->prefix); +printf ("%s\n" , one); +strbuf_release (&onebuf); + } +} + +static void short_untracked (int null_termination,struct string_list_item *it, +struct wt_status *s) +{ +if (null_termination) { +fprintf (stdout,"?? %s%c" , it->string,0 ); + }else { +struct strbuf onebuf =STRBUF_INIT ; +const char *one; + one =quote_path (it->string,-1 , &onebuf, s->prefix); +printf ("?? %s\n" , one); +strbuf_release (&onebuf); + } +} +int cmd_stat (int argc,const char **argv,const char *prefix) {struct wt_status s; +static int null_termination, shortstatus; +int i;unsigned char sha1[20 ];static struct option builtin_stat_options[] = { +OPT_BOOLEAN ('s' ,"short" , &shortstatus, +"show status concicely" ), +OPT_BOOLEAN ('z' ,"null" , &null_termination, +"terminate entries with NUL" ), {OPTION_STRING ,'u' ,"untracked-files" , &untracked_files_arg,"mode" ,"show untracked files, optional modes: all, normal, no. (Default: all)" ,
@@ -925,7 +1000,27 @@ int cmd_stat(int argc, const char **argv, const char *prefix) s.is_initial =get_sha1 (s.reference, sha1) ?1 :0 ;wt_status_collect (&s); -wt_status_print_body (&s); +if (shortstatus) { +for (i =0 ; i < s.change.nr; i++) { +struct wt_status_change_data *d; +struct string_list_item *it; + + it = &(s.change.items[i]); + d = it->util; +if (d->stagemask) +short_unmerged (null_termination, it, &s); +else +short_status (null_termination, it, &s); + } +for (i =0 ; i < s.untracked.nr; i++) { +struct string_list_item *it; + + it = &(s.untracked.items[i]); +short_untracked (null_termination, it, &s); + } + }else { +wt_status_print_body (&s); + }return 0 ; }
Signature · 1 line
1.6.4.173.g72959
Re: [PATCH v3 3/8] wt-status: move wt_status_colors[] into wt_status structure
In reply to Junio C Hamanowt-status.h struct wt_status { · line 41
Quoted 5 lines · Junio C Hamano
wt-status.h +1
-0@@ -37,6 +38,7 @@ struct wt_status {int wt_status_relative_paths;int wt_status_submodule_summary;enum untracked_status_type show_untracked_files; +char wt_status_colors[6 ][COLOR_MAXLEN ];
Yuck on the magic "6". It should be safe to use
ARRAY_SIZE(wt_status_colors_default)
since that is computed purely from sizeof's. Though I am not discounting the possibility that there are compilers which will screw it up.
-Peff
Re: [PATCH v3 2/8] wt-status: move many global settings to wt_status structure
In reply to Junio C HamanoQuoted 4 lines · Junio C Hamano
wt-status.h +0
-0
wt-status.h struct wt_status { · line 40
Quoted 10 lines
wt-status.h +5
-1@@ -33,8 +32,12 @@ struct wt_status {const char *reference;int verbose;int amend; -int untracked;int nowarn; +int wt_status_use_color; +int wt_status_relative_paths; +int wt_status_submodule_summary; +enum untracked_status_type show_untracked_files; +
Is there a particular reason to use such enormous struct member names? IOW, inside wt_status, why not just "use_color"?
Other than that, I think this is a very positive change (and in fact, I like the way this whole series is shaping up).
-Peff