git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tuncer Ayaz <tuncer.ayaz@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [RFC/PATCH] shortstatus v1
Date: Tue, 10 Feb 2009 22:21:16 +0100	[thread overview]
Message-ID: <4ac8254d0902101321w1b6171cfkf7a6253181324acd@mail.gmail.com> (raw)
In-Reply-To: <20090210191118.GA26651@coredump.intra.peff.net>

On Tue, Feb 10, 2009 at 8:11 PM, Jeff King <peff@peff.net> wrote:
> On Tue, Feb 10, 2009 at 01:10:52PM -0500, Jeff King wrote:
>
>>   - 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.

I tried this and it did not run faster than my experiment.
I had to add a missing opening curly brace in
have_untracked() before it compiled.

As we haven't found a fast way yet I can live without it.

> 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 },
>

  reply	other threads:[~2009-02-10 21:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-10  0:51 [RFC/PATCH] shortstatus v1 Tuncer Ayaz
2009-02-10  1:44 ` Junio C Hamano
2009-02-10  3:46   ` Sitaram Chamarty
2009-02-10 10:22     ` Spending time in PS1, was " Johannes Schindelin
2009-02-10 17:31       ` Sitaram Chamarty
2009-02-10 10:11   ` Tuncer Ayaz
2009-02-10 11:03 ` Jeff King
2009-02-10 11:29   ` Michael J Gruber
2009-02-10 11:31     ` Tuncer Ayaz
2009-02-10 11:45     ` Jeff King
2009-02-10 12:36       ` Michael J Gruber
2009-02-10 13:01         ` Jeff King
2009-02-10 15:58   ` Junio C Hamano
2009-02-10 18:10     ` Jeff King
2009-02-10 18:22       ` Jeff King
2009-02-10 19:11       ` Jeff King
2009-02-10 21:21         ` Tuncer Ayaz [this message]
2009-02-10 21:36           ` Jeff King
2009-02-10 22:25         ` Junio C Hamano
2009-02-10 22:52           ` Tuncer Ayaz
2009-02-10 22:55           ` Jeff King
2009-02-10 23:05             ` Junio C Hamano
2009-02-12  0:49               ` Jeff King
2009-02-10 23:52     ` Nanako Shiraishi
2009-02-11 21:24       ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2009-02-10 23:58 [RFC] New command: 'git snapshot' Ulrik Sverdrup
2009-02-11  0:08 ` [RFC/PATCH] shortstatus v1 Nanako Shiraishi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ac8254d0902101321w1b6171cfkf7a6253181324acd@mail.gmail.com \
    --to=tuncer.ayaz@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).