git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/3] git-commit.sh: convert run_status to a C builtin
Date: Thu, 07 Sep 2006 17:20:20 -0700	[thread overview]
Message-ID: <7vzmdbqke3.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <20060907063621.GC17083@coredump.intra.peff.net> (Jeff King's message of "Thu, 7 Sep 2006 02:36:21 -0400")

Jeff King <peff@peff.net> writes:

> diff --git a/Makefile b/Makefile
> index 78748cb..d0ba3b5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -252,7 +252,7 @@ LIB_OBJS = \
>  	fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
>  	write_or_die.o trace.o \
>  	alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) \
> -	color.o
> +	color.o status.o
>  
>  BUILTIN_OBJS = \
>  	builtin-add.o \

At some point (this does not have to be part of this series), we
should demote DIFF_OBJS to just ordinary LIB_OBJS.  They used to
be special in that they are used only by handful special
commands, but these days more and more things are integrated and
it outlived its usefulness.

> +static const char runstatus_usage[] =
> +"git-runstatus [--color|--nocolor] [--amend] [--verbose]";
> +
> +int cmd_runstatus(int argc, const char **argv, const char *prefix)
> +{
> +	struct status s;
> +	int i;
> +
> +	git_config(git_status_config);
> +	status_prepare(&s);
> +
> +	for (i = 1; i < argc; i++) {
> +		if (!strcmp(argv[i], "--color"))
> +			status_use_color = 1;
> +		else if (!strcmp(argv[i], "--nocolor"))
> +			status_use_color = 0;
> +    else if (!strcmp(argv[i], "--amend")) {
> +      s.amend = 1;
> +      s.reference = "HEAD^1";
> +    }
> +    else if (!strcmp(argv[i], "--verbose"))
> +      s.verbose = 1;
> +		else
> +			usage(runstatus_usage);
> +	}
> +
> +	status_print(&s);
> +  return s.commitable ? 0 : 1;
> +}

Quite funny indentation style your MUA likes ;-).

> diff --git a/status.c b/status.c
> new file mode 100644
> index 0000000..82aa881
> --- /dev/null
> +++ b/status.c
> @@ -0,0 +1,283 @@
> +#include "status.h"

"status.h" and "struct status" somehow sounds too broad.
Granted, "object.h" is also broad, but in git context "object"
has a specific meaning.

Having said that I cannot come up with a good alternative name.
It is not "project status" nor "repository status".  It is
"working tree status", but that sounds very loooooooooooooooong.

> +	color_printf(color(STATUS_HEADER), "#\t");
> +	switch (p->status) {
> +	case DIFF_STATUS_ADDED:
> +		color_printf(c, "new file: %s\n", p->one->path); break;

Very nicely done.  Especially I liked that you are careful not
to paint leading '#\t' (which is noticeable when you use reverse
as an attribute).

> +static void
> +status_print_untracked(const struct status *s)
> +{
> +	struct dir_struct dir;
> +	const char *x;
> +	int i;
> +	int shown_header = 0;
> +
> +	memset(&dir, 0, sizeof(dir));
> +
> +	dir.exclude_per_dir = ".gitignore";
> +	x = git_path("info/exclude");
> +	if (file_exists(x))
> +		add_excludes_from_file(&dir, x);
> +
> +	read_directory(&dir, ".", "", 0);
> +	for(i = 0; i < dir.nr; i++) {
> +		/* check for matching entry, which is unmerged; lifted from
> +		 * builtin-ls-files:show_other_files */
> +		struct dir_entry *ent = dir.entries[i];
> +		int pos = cache_name_pos(ent->name, ent->len);
> +		struct cache_entry *ce;
> +		if (0 <= pos)
> +			die("bug in status_print_untracked");
> +		pos = -pos - 1;
> +		if (pos < active_nr) {
> +			ce = active_cache[pos];
> +			if (ce_namelen(ce) == ent->len &&
> +			    !memcmp(ce->name, ent->name, ent->len))
> +				continue;
> +		}
> +		if (!shown_header) {
> +			status_print_header("Untracked files",
> +				"use \"git add\" to add to commit");
> +			shown_header = 1;
> +		}
> +		color_printf(color(STATUS_HEADER), "#\t");
> +		color_printf(color(STATUS_UNTRACKED), "%.*s\n",
> +				ent->len, ent->name);
> +	}
> +}

Very nice code reuse.  I do not mean sarcasm -- the part copied
and pasted from ls-files is almost trivial to bother factoring
out.  What's nice is read_directory() does all what is needed to
deal with .gitignore files, which I forgot almost all about.

> +int status_foreach_cached(status_cb cb);
> +int status_foreach_updated(status_cb cb);
> +int status_foreach_changed(status_cb cb);
> +int status_foreach_untracked(status_cb cb);

I do not see them defined nor used...

I'll take only [1/3] for now but I am interested in 2 and 3.

  parent reply	other threads:[~2006-09-08  0:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <64c62cc942e872b29d7225999e74a07be586674a.1157610743.git.peff@peff.net>
2006-09-07  6:36 ` [PATCH 3/3] git-commit.sh: convert run_status to a C builtin Jeff King
2006-09-07  9:10   ` Jeff King
2006-09-08  0:20   ` Junio C Hamano [this message]
2006-09-08  5:42     ` Jeff King
2006-09-08  5:56       ` Junio C Hamano
2006-09-08  7:34         ` Jeff King
2006-09-08  8:03           ` [PATCH] Move color option parsing out of diff.c and into color.[ch] Jeff King
2006-09-08  8:49             ` Junio C Hamano
2006-09-08  9:12               ` Jeff King
2006-09-08 21:19                 ` Junio C Hamano

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=7vzmdbqke3.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    --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).