git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 7/8] git stat: pathspec limits, unlike traditional "git status"

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 10, 2009, 08:54 UTC
Message-ID
<1249894465-11018-8-git-send-email-gitster@pobox.com>
In-Reply-To
<1249894465-11018-7-git-send-email-gitster@pobox.com>

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.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-commit.c |    3 +++
 wt-status.c      |    6 ++++++
 wt-status.h      |    1 +
 3 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index bc780a8..9c2a70c 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -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;
diff --git a/wt-status.c b/wt-status.c
index a5dbdcc..aea3bbb 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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);
 	}
diff --git a/wt-status.h b/wt-status.h
index 44c40ff..6dcb739 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -31,6 +31,7 @@ struct wt_status {
 	int is_initial;
 	char *branch;
 	const char *reference;
+	const char **pathspec;
 	int verbose;
 	int amend;
 	int nowarn;
-- 
1.6.4.173.g72959
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 11 in “shortstatus updates”
  1. 0/8 shortstatus updatesJunio C Hamano, Aug 10, 2009
  2. 1/8 commit: --dry-runJunio C Hamano, Aug 10, 2009
  3. 2/8 wt-status: move many global settings to wt_status structureJunio C Hamano, Aug 10, 2009
  4. 3/8 wt-status: move wt_status_colors[] into wt_status structureJunio C Hamano, Aug 10, 2009
  5. 4/8 Make git_status_config() file scope static to builtin-commit.cJunio C Hamano, Aug 10, 2009
  6. 5/8 wt-status: collect untracked files in a separate "collect" phaseJunio C Hamano, Aug 10, 2009
  7. 6/8 git stat: the beginningJunio C Hamano, Aug 10, 2009
  8. 7/8 git stat: pathspec limits, unlike traditional "git status"Junio C Hamano, Aug 10, 2009
  9. 8/8 git stat -s: short status outputJunio C Hamano, Aug 10, 2009
  10. Jeff KingAug 10, 2009
  11. Jeff KingAug 10, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.