* [PATCH v2 0/3] commit --dry-run @ 2009-08-08 7:14 Junio C Hamano 2009-08-08 7:14 ` [PATCH v2 1/3] commit: --dry-run Junio C Hamano 2009-08-08 7:18 ` [PATCH v2 0/3] commit --dry-run Sverre Rabbelier 0 siblings, 2 replies; 5+ messages in thread From: Junio C Hamano @ 2009-08-08 7:14 UTC (permalink / raw) To: git This is a re-roll of the commit in the jc/shortstatus series that has been kept out of 'pu'. First, we introduce "git commit --dry-run", which does exactly the same thing as the current "git status". A longer term goal of this change is so that we could make "git status" behave completely differently after an ample warning period. The second commit introduces a new "git status" under a tentative name "git stat". In this step, it does not do anything interesting, other than that it ignores the path parameters. The third commit adds "-s" option to the new command, to give the "short" output format. Probably the next round should insert a commit between the second one and the third one to take pathspec parameters that are used as path limiters, but I am too tired for doing that myself tonight. Junio C Hamano (3): commit: --dry-run git stat: the beginning git stat -s: short status output Documentation/git-commit.txt | 7 ++- Makefile | 1 + builtin-commit.c | 163 ++++++++++++++++++++++++++++++++++++------ builtin.h | 1 + git.c | 1 + wt-status.c | 24 ++++--- wt-status.h | 1 + 7 files changed, 165 insertions(+), 33 deletions(-) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] commit: --dry-run 2009-08-08 7:14 [PATCH v2 0/3] commit --dry-run Junio C Hamano @ 2009-08-08 7:14 ` Junio C Hamano 2009-08-08 7:14 ` [PATCH v2 2/3] git stat: the beginning Junio C Hamano 2009-08-08 7:18 ` [PATCH v2 0/3] commit --dry-run Sverre Rabbelier 1 sibling, 1 reply; 5+ messages in thread From: Junio C Hamano @ 2009-08-08 7:14 UTC (permalink / raw) To: git 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. Signed-off-by: Junio C Hamano <gitster@pobox.com> --- Documentation/git-commit.txt | 7 ++++++- builtin-commit.c | 29 ++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index b5d81be..d01ff5a 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -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. diff --git a/builtin-commit.c b/builtin-commit.c index 6d12c2e..3a7e35d 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -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); -- 1.6.4.159.gd0d612 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] git stat: the beginning 2009-08-08 7:14 ` [PATCH v2 1/3] commit: --dry-run Junio C Hamano @ 2009-08-08 7:14 ` Junio C Hamano 2009-08-08 7:14 ` [PATCH v2 3/3] git stat -s: short status output Junio C Hamano 0 siblings, 1 reply; 5+ messages in thread From: Junio C Hamano @ 2009-08-08 7:14 UTC (permalink / raw) To: git 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. Signed-off-by: Junio C Hamano <gitster@pobox.com> --- Makefile | 1 + builtin-commit.c | 56 ++++++++++++++++++++++++++++++++++++++++++++--------- builtin.h | 1 + git.c | 1 + wt-status.c | 24 ++++++++++++++-------- wt-status.h | 1 + 6 files changed, 65 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index daf4296..39dd334 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/builtin-commit.c b/builtin-commit.c index 3a7e35d..10f9d4f 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -35,6 +35,11 @@ static const char * const builtin_status_usage[] = { NULL }; +static const char * const builtin_stat_usage[] = { + "git stat [options]", + NULL +}; + static unsigned char head_sha1[20], merge_head_sha1[20]; static char *use_message_buffer; static const char commit_editmsg[] = "COMMIT_EDITMSG"; @@ -693,6 +698,21 @@ static const char *find_author_by_nickname(const char *name) die("No existing author found with '%s'", name); } + +static void handle_untracked_files_arg(void) +{ + if (!untracked_files_arg) + ; /* default already initialized */ + else if (!strcmp(untracked_files_arg, "no")) + show_untracked_files = SHOW_NO_UNTRACKED_FILES; + else if (!strcmp(untracked_files_arg, "normal")) + show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; + else if (!strcmp(untracked_files_arg, "all")) + show_untracked_files = SHOW_ALL_UNTRACKED_FILES; + else + die("Invalid untracked files mode '%s'", untracked_files_arg); +} + static int parse_and_validate_options(int argc, const char *argv[], const char * const usage[], const char *prefix) @@ -795,16 +815,7 @@ static int parse_and_validate_options(int argc, const char *argv[], else die("Invalid cleanup mode %s", cleanup_arg); - if (!untracked_files_arg) - ; /* default already initialized */ - else if (!strcmp(untracked_files_arg, "no")) - show_untracked_files = SHOW_NO_UNTRACKED_FILES; - else if (!strcmp(untracked_files_arg, "normal")) - show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; - else if (!strcmp(untracked_files_arg, "all")) - show_untracked_files = SHOW_ALL_UNTRACKED_FILES; - else - die("Invalid untracked files mode '%s'", untracked_files_arg); + handle_untracked_files_arg(); if (all && argc > 0) die("Paths with -a does not make sense."); @@ -814,6 +825,31 @@ static int parse_and_validate_options(int argc, const char *argv[], return argc; } +int cmd_stat(int argc, const char **argv, const char *prefix) +{ + struct wt_status s; + static struct option builtin_stat_options[] = { + { 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_END(), + }; + + argc = parse_options(argc, argv, prefix, + builtin_stat_options, + builtin_stat_usage, 0); + handle_untracked_files_arg(); + + read_cache(); + refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED); + wt_status_prepare(&s); + wt_status_collect_changes(&s); + + wt_status_print_body(&s); + return 0; +} + static int dry_run_commit(int argc, const char **argv, const char *prefix) { int commitable; diff --git a/builtin.h b/builtin.h index 20427d2..eeaf0b6 100644 --- a/builtin.h +++ b/builtin.h @@ -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); diff --git a/git.c b/git.c index 807d875..de7fcf6 100644 --- a/git.c +++ b/git.c @@ -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 }, diff --git a/wt-status.c b/wt-status.c index 97fedfa..6eb32df 100644 --- a/wt-status.c +++ b/wt-status.c @@ -537,6 +537,20 @@ static void wt_status_print_tracking(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); } +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 (wt_status_submodule_summary) + wt_status_print_submodule_summary(s); + if (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]; @@ -567,15 +581,7 @@ void wt_status_print(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); } - wt_status_print_unmerged(s); - wt_status_print_updated(s); - wt_status_print_changed(s); - if (wt_status_submodule_summary) - wt_status_print_submodule_summary(s); - if (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); diff --git a/wt-status.h b/wt-status.h index f80142f..ebbf06a 100644 --- a/wt-status.h +++ b/wt-status.h @@ -50,6 +50,7 @@ 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_print_body(struct wt_status *s); void wt_status_collect_changes(struct wt_status *s); #endif /* STATUS_H */ -- 1.6.4.159.gd0d612 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] git stat -s: short status output 2009-08-08 7:14 ` [PATCH v2 2/3] git stat: the beginning Junio C Hamano @ 2009-08-08 7:14 ` Junio C Hamano 0 siblings, 0 replies; 5+ messages in thread From: Junio C Hamano @ 2009-08-08 7:14 UTC (permalink / raw) To: git 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. 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 When given -z option, the records are terminated by NUL characters for better machine readability. Signed-off-by: Junio C Hamano <gitster@pobox.com> --- builtin-commit.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 79 insertions(+), 1 deletions(-) diff --git a/builtin-commit.c b/builtin-commit.c index 10f9d4f..abb4377 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -24,6 +24,7 @@ #include "string-list.h" #include "rerere.h" #include "unpack-trees.h" +#include "quote.h" static const char * const builtin_commit_usage[] = { "git commit [options] [--] <filepattern>...", @@ -825,10 +826,72 @@ static int parse_and_validate_options(int argc, const char *argv[], return argc; } +#define quote_path quote_path_relative + +static void show_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 show_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); + } +} + 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)", @@ -844,9 +907,24 @@ int cmd_stat(int argc, const char **argv, const char *prefix) read_cache(); refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED); wt_status_prepare(&s); + s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0; wt_status_collect_changes(&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) + show_unmerged(null_termination, it, &s); + else + show_status(null_termination, it, &s); + } + } else { + wt_status_print_body(&s); + } return 0; } -- 1.6.4.159.gd0d612 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] commit --dry-run 2009-08-08 7:14 [PATCH v2 0/3] commit --dry-run Junio C Hamano 2009-08-08 7:14 ` [PATCH v2 1/3] commit: --dry-run Junio C Hamano @ 2009-08-08 7:18 ` Sverre Rabbelier 1 sibling, 0 replies; 5+ messages in thread From: Sverre Rabbelier @ 2009-08-08 7:18 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Heya, On Sat, Aug 8, 2009 at 00:14, Junio C Hamano<gitster@pobox.com> wrote: > The second commit introduces a new "git status" under a tentative name > "git stat". That would put 'git status' at 'git statu<tab>', instead of 'git stat<tab>', I don't know if that's a concern though. -- Cheers, Sverre Rabbelier ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-08 7:18 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-08-08 7:14 [PATCH v2 0/3] commit --dry-run Junio C Hamano 2009-08-08 7:14 ` [PATCH v2 1/3] commit: --dry-run Junio C Hamano 2009-08-08 7:14 ` [PATCH v2 2/3] git stat: the beginning Junio C Hamano 2009-08-08 7:14 ` [PATCH v2 3/3] git stat -s: short status output Junio C Hamano 2009-08-08 7:18 ` [PATCH v2 0/3] commit --dry-run Sverre Rabbelier
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).