summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3fa509d)
raw | patch | inline | side by side (parent: 3fa509d)
author | Junio C Hamano <gitster@pobox.com> | |
Sat, 8 Aug 2009 06:31:57 +0000 (23:31 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 22 Aug 2009 19:15:57 +0000 (12:15 -0700) |
Tentatively add "git stat" as a new command.
This 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. Later in 1.7.0 release, it will
take over "git status".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This 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. Later in 1.7.0 release, it will
take over "git status".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile | patch | blob | history | |
builtin-commit.c | patch | blob | history | |
builtin.h | patch | blob | history | |
git.c | patch | blob | history | |
wt-status.c | patch | blob | history | |
wt-status.h | patch | blob | history |
diff --git a/Makefile b/Makefile
index daf4296706c4c9c524b6ec4434cadcf95881ea25..39dd3343859684a26adbfaf17cf468e9ce81fe5d 100644 (file)
--- a/Makefile
+++ b/Makefile
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 200ffdaad4226ae2021c86ae4b7a2f8ccefb3600..5e23ef1f0a67bed7088a0eaacc9ac9b36555843b 100644 (file)
--- a/builtin-commit.c
+++ b/builtin-commit.c
#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>...",
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";
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
struct wt_status *s)
{
+ unsigned char sha1[20];
+
if (s->relative_paths)
s->prefix = prefix;
s->index_file = index_file;
s->fp = fp;
s->nowarn = nowarn;
+ s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
+ wt_status_collect(s);
wt_status_print(s);
return s->commitable;
die("No existing author found with '%s'", name);
}
+
+static void handle_untracked_files_arg(struct wt_status *s)
+{
+ if (!untracked_files_arg)
+ ; /* default already initialized */
+ else if (!strcmp(untracked_files_arg, "no"))
+ s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
+ else if (!strcmp(untracked_files_arg, "normal"))
+ s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+ else if (!strcmp(untracked_files_arg, "all"))
+ s->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,
else
die("Invalid cleanup mode %s", cleanup_arg);
- if (!untracked_files_arg)
- ; /* default already initialized */
- else if (!strcmp(untracked_files_arg, "no"))
- s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
- else if (!strcmp(untracked_files_arg, "normal"))
- s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
- else if (!strcmp(untracked_files_arg, "all"))
- s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
- else
- die("Invalid untracked files mode '%s'", untracked_files_arg);
+ handle_untracked_files_arg(s);
if (all && argc > 0)
die("Paths with -a does not make sense.");
return git_diff_ui_config(k, v, NULL);
}
+int cmd_stat(int argc, const char **argv, const char *prefix)
+{
+ struct wt_status s;
+ unsigned char sha1[20];
+ static struct option builtin_stat_options[] = {
+ OPT__VERBOSE(&verbose),
+ { 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(),
+ };
+
+ wt_status_prepare(&s);
+ git_config(git_status_config, &s);
+ argc = parse_options(argc, argv, prefix,
+ builtin_stat_options,
+ 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_collect(&s);
+
+ s.verbose = verbose;
+ if (s.relative_paths)
+ s.prefix = prefix;
+ if (s.use_color == -1)
+ s.use_color = git_use_color_default;
+ if (diff_use_color_default == -1)
+ diff_use_color_default = git_use_color_default;
+ wt_status_print(&s);
+ return 0;
+}
+
int cmd_status(int argc, const char **argv, const char *prefix)
{
struct wt_status s;
diff --git a/builtin.h b/builtin.h
index 20427d2963fa25c1177bd05ab9f8be2890b9f7ba..eeaf0b6cf5306faa6f65c1e8eea3afe64df6e862 100644 (file)
--- a/builtin.h
+++ b/builtin.h
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);
index 807d875ae06ce7bbf61bb846c5b4cb5a51855eba..de7fcf6dfb86b32d07c261dcc25824c7970a77c3 100644 (file)
--- a/git.c
+++ b/git.c
{ "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 63598ce40cdad4bc9acc5446d304f0512341f973..249227c382c1f482fa1a8c0e303c65014b5695b7 100644 (file)
--- a/wt-status.c
+++ b/wt-status.c
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);
}
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);
}
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) {
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);
}
void wt_status_print(struct wt_status *s)
{
- unsigned char sha1[20];
const char *branch_color = color(WT_STATUS_HEADER, s);
- s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
if (s->branch) {
const char *on_what = "On branch ";
const char *branch_name = s->branch;
wt_status_print_tracking(s);
}
- wt_status_collect(s);
-
if (s->is_initial) {
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
diff --git a/wt-status.h b/wt-status.h
index a0e75177bec925e95b4257811aae0bdee93c41f1..09fd9f10919d109fdfbab491620be67e251124ea 100644 (file)
--- a/wt-status.h
+++ b/wt-status.h
int is_initial;
char *branch;
const char *reference;
+ const char **pathspec;
int verbose;
int amend;
int nowarn;