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

Re: [RFC/PATCH] shortstatus v1

From
Jeff King <peff@peff.net>
Date
Feb 10, 2009, 19:11 UTC
Message-ID
<20090210191118.GA26651@coredump.intra.peff.net>
In-Reply-To
<20090210181052.GA19634@coredump.intra.peff.net>
On Tue, Feb 10, 2009 at 01:10:52PM -0500, Jeff King wrote:
Show 10 quoted lines
>   - I don't think the "mini" status is really related to this. The novel
>     thing here is collating the outputs into a single sorted list. But
>     the "mini" output is not about that at all:
> 
>       1. It doesn't care about full output, so it should be able to exit
>          early from the diff, avoid rename detection, etc, so that it is
>          as quick as possible.
> 
>       2. It doesn't collate the output at all. It is about three
>          separate symbols for the three separate lists.

OK, I realize this is not exactly what the proposed --mini does. But here is more along the lines of what I was thinking.

Warm cache, it runs in .042s on my git repo, about half of which is the untracked files check. It takes about .49s on the kernel repo. The read_directory() bit is not optimized at all, and could probably benefit from an early return (OTOH, the worst case is still going to need to look at every path).

I am not particularly interested in a fancy prompt myself, but maybe this will help somebody else.

The patch relies on the index_differs_from() patch that Stephan posted earlier today.

---
 .gitignore           |    1 +
 Makefile             |    1 +
 builtin-ministatus.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 builtin.h            |    1 +
 git.c                |    1 +
 5 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
index 055eb54..de2249b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -81,6 +81,7 @@ git-mergetool
 git-mktag
 git-mktree
 git-name-rev
+git-ministatus
 git-mv
 git-notes
 git-pack-redundant
diff --git a/Makefile b/Makefile
index a0ca137..9145c7b 100644
--- a/Makefile
+++ b/Makefile
@@ -559,6 +559,7 @@ BUILTIN_OBJS += builtin-merge-base.o
 BUILTIN_OBJS += builtin-merge-file.o
 BUILTIN_OBJS += builtin-merge-ours.o
 BUILTIN_OBJS += builtin-merge-recursive.o
+BUILTIN_OBJS += builtin-ministatus.o
 BUILTIN_OBJS += builtin-mv.o
 BUILTIN_OBJS += builtin-name-rev.o
 BUILTIN_OBJS += builtin-pack-objects.o
diff --git a/builtin-ministatus.c b/builtin-ministatus.c
new file mode 100644
index 0000000..c9f8e7f
--- /dev/null
+++ b/builtin-ministatus.c
@@ -0,0 +1,52 @@
+#include "cache.h"
+#include "diff.h"
+#include "commit.h"
+#include "revision.h"
+#include "dir.h"
+
+static int worktree_is_dirty(void)
+{
+	struct rev_info rev;
+	init_revisions(&rev, "");
+	setup_revisions(0, NULL, &rev, NULL);
+	DIFF_OPT_SET(&rev.diffopt, QUIET);
+	DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
+	run_diff_files(&rev, 0);
+	return DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES);
+}
+
+static int have_untracked(void)
+{
+	struct dir_struct dir;
+	int i;
+
+	memset(&dir, 0, sizeof dir);
+	setup_standard_excludes(&dir);
+
+	read_directory(&dir, ".", "", 0, NULL);
+	/* XXX we are probably leaking memory from dir */
+	for (i = 0; i < dir.nr; i++)
+		struct dir_entry *ent = dir.entries[i];
+		if (cache_name_is_other(ent->name, ent->len))
+			return 1;
+	}
+	return 0;
+}
+
+int cmd_ministatus(int argc, const char **argv, const char *prefix)
+{
+	if (argc != 1)
+		die("Sorry, I don't understand any command line options.");
+
+	read_cache();
+	refresh_cache(REFRESH_QUIET);
+
+	if (index_differs_from("HEAD", 0))
+		putchar('+');
+	if (worktree_is_dirty())
+		putchar('*');
+	if (have_untracked())
+		putchar('?');
+
+	return 0;
+}
diff --git a/builtin.h b/builtin.h
index f054fc7..03e6a88 100644
--- a/builtin.h
+++ b/builtin.h
@@ -71,6 +71,7 @@ extern int cmd_merge_base(int argc, const char **argv, const char *prefix);
 extern int cmd_merge_ours(int argc, const char **argv, const char *prefix);
 extern int cmd_merge_file(int argc, const char **argv, const char *prefix);
 extern int cmd_merge_recursive(int argc, const char **argv, const char *prefix);
+extern int cmd_ministatus(int argc, const char **argv, const char *prefix);
 extern int cmd_mv(int argc, const char **argv, const char *prefix);
 extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
 extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
diff --git a/git.c b/git.c
index 4c0fa44..8bf7e78 100644
--- a/git.c
+++ b/git.c
@@ -323,6 +323,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "merge-ours", cmd_merge_ours, RUN_SETUP },
 		{ "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },
 		{ "merge-subtree", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },
+		{ "ministatus", cmd_ministatus, RUN_SETUP | NEED_WORK_TREE },
 		{ "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE },
 		{ "name-rev", cmd_name_rev, RUN_SETUP },
 		{ "pack-objects", cmd_pack_objects, RUN_SETUP },
Previous: Jeff KingNext: Tuncer Ayaz
Message 16 of 25 in “shortstatus v1”
  1. shortstatus v1Tuncer Ayaz, Feb 10, 2009
  2. Junio C HamanoFeb 10, 2009
  3. Sitaram ChamartyFeb 10, 2009
  4. Spending time in PS1, was Re: [RFC/PATCH] shortstatus v1Johannes Schindelin, Feb 10, 2009
  5. Sitaram ChamartyFeb 10, 2009
  6. Tuncer AyazFeb 10, 2009
  7. Jeff KingFeb 10, 2009
  8. Michael J GruberFeb 10, 2009
  9. Tuncer AyazFeb 10, 2009
  10. Jeff KingFeb 10, 2009
  11. Michael J GruberFeb 10, 2009
  12. Jeff KingFeb 10, 2009
  13. Junio C HamanoFeb 10, 2009
  14. Jeff KingFeb 10, 2009
  15. Jeff KingFeb 10, 2009
  16. Jeff KingFeb 10, 2009
  17. Tuncer AyazFeb 10, 2009
  18. Jeff KingFeb 10, 2009
  19. Junio C HamanoFeb 10, 2009
  20. Tuncer AyazFeb 10, 2009
  21. Jeff KingFeb 10, 2009
  22. Junio C HamanoFeb 10, 2009
  23. Jeff KingFeb 12, 2009
  24. Nanako ShiraishiFeb 10, 2009
  25. Junio C HamanoFeb 11, 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.