Git development
 help / color / mirror / Atom feed
* Re: .gitignore vs untracked working file
From: Johannes Sixt @ 2009-08-10 11:41 UTC (permalink / raw)
  To: Rostislav Svoboda; +Cc: git, Uwe Kleine-König
In-Reply-To: <286817520908100317k4e98faf9n4e852b7abd4719fe@mail.gmail.com>

Rostislav Svoboda schrieb:
> 2009/8/10 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
>> Hello,
>>
>>> $ git checkout master
>>> error: Untracked working tree file 'Project/bin/path/file.jjt' would
>>> be overwritten by merge.
>> What is the output of
>>
>>        $ git ls-files master bin/
> 
> Nothing:

It should have been

	$ git ls-tree master bin

> BTW the rule to ignore bin/ is exclusively in the .gitignore on the
> branch mybranch not in the master branch. Might this be the problem?

It might be, depending on how precious Project/bin/path/file.jjt is for
you. Try this:

	$ git checkout -f master

This will overwrite the existing file with the version from master. If you
later

	$ git checkout mybranch

then the file will be *removed*.

-- Hannes

^ permalink raw reply

* Re: [PATCH] gitweb: Optimize git-favicon.png
From: Benjamin Kramer @ 2009-08-10 11:39 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git
In-Reply-To: <20090810110002.4448.88448.stgit@localhost.localdomain>

Reduce size of git-favicon.png using a combination of optipng and
pngout. From 164 bytes to 115 bytes (30% reduction).

Signed-off-by: Benjamin Kramer <benny.kra@googlemail.com>
---

The contest is now open. Who can do better?

 gitweb/git-favicon.png |  Bin 164 -> 115 bytes
 1 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/gitweb/git-favicon.png b/gitweb/git-favicon.png
index de637c0608090162a6ce6b51d5f9bfe512cf8bcf..aae35a70e70351fe6dcb3e905e2e388cf0cb0ac3 100644
GIT binary patch
delta 85
zcmZ3&SUf?+pEJNG#Pt9J149GD|NsBH{?u>)*{Yr{jv*Y^lOtGJcy4sCvGS>LGzvuT
nGSco!%*slUXkjQ0+{(x>@rZKt$^5c~Kn)C@u6{1-oD!M<s|Fj6

delta 135
zcmXS3!Z<;to+rR3#Pt9J149GDe=s<ftM(tr<t*@sEM{Qf76xHPhFNnYfP!|OE{-7;
zjI0MY3OYE5upapO?DR{I1pyyR7cx(jY7y^{FfMCvb5IaiQM`NJfeQjFwttKJyJNq@
hveI=@x=fAo=hV3$-MIWu9%vGSr>mdKI;RB2CICA_GnfDX

-- 
1.6.4.67.gea5b1

^ permalink raw reply

* Re: [PATCH] fix potential infinite loop given large unsigned integer
From: Erik Faye-Lund @ 2009-08-10 11:12 UTC (permalink / raw)
  To: Christian Couder; +Cc: Junio C Hamano, Ryan Flynn, git
In-Reply-To: <200908100724.53345.chriscool@tuxfamily.org>

On Mon, Aug 10, 2009 at 7:24 AM, Christian
Couder<chriscool@tuxfamily.org> wrote:
>> log10() appears to be C99, but can be emulated on earlier C-versions by
>> doing #define log10(x) (log(x) / log(10.0))
>
> That would mean linking with -lm?

I guess so. Are we currently trying to avoid linking to the math-parts of libc?

-- 
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656

^ permalink raw reply

* [PATCH] gitweb: Optimize git-favicon.png
From: Jakub Narebski @ 2009-08-10 11:00 UTC (permalink / raw)
  To: git

Reduce size of git-favicon.png using Smush.it(TM) online PNG optimizer
  http://developer.yahoo.com/yslow/smushit/
from 164 bytes to 118 bytes (28% reduction).

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Smush.it(TM) could not improve git-logo.png

 gitweb/git-favicon.png |  Bin 164 -> 118 bytes
 1 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/gitweb/git-favicon.png b/gitweb/git-favicon.png
index de637c0608090162a6ce6b51d5f9bfe512cf8bcf..1f8bfa70d674b1073a40ea66ba8c745dfdbaa59d 100644
GIT binary patch
delta 64
zcmZ3&ST@1NO4ZZFF@)oKas(?2&y5Z?Rz5Y3MuF&EM%rD8Sy?F(EeyqhTNxQ99#M`y
TnP0Y$0SG)@{an^LB{Ts5d%zSA

delta 110
zcmXS0!Z^VugR{URvY3H^TNs2H8D`CqU|?Xd^K@|xsbFM1xKYr-L4@_d*Jr0+dMpU|
zSh|pTqEw4`hlFuidz*uTz>4DC^A21PSh4+E+}|Dh9hQ}@lhS2sls~7={piN!fAT<+
O7(8A5T-G@yGywqcawy0E

^ permalink raw reply

* Re: backups with git
From: John Tapsell @ 2009-08-10 10:51 UTC (permalink / raw)
  To: Roald de Vries; +Cc: git
In-Reply-To: <41CB836B-6057-448E-805F-F25EAF765D27@roalddevries.nl>

2009/8/10 Roald de Vries <rdv@roalddevries.nl>:
> Dear all,
>
> I'm thinking of using git as a backup solution for my whole system, setting
> my $GIT_DIR to something like "/backupdisc/backup". Does that seem sensible?
> In his Google tech talk, Linus said that git was not good at huge projects;
> I guess that would apply to backups. On the other hand, maybe a backup
> doesn't need to be as fast as he wants git to be for projects. Has anybody
> used git like this? And was it a good experience?

Perhaps you want something more like btrfs.

John

^ permalink raw reply

* Re: .gitignore vs untracked working file
From: Rostislav Svoboda @ 2009-08-10 10:17 UTC (permalink / raw)
  To: git, Uwe Kleine-König
In-Reply-To: <20090810100148.GB22200@pengutronix.de>

2009/8/10 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> Hello,
>
>> $ git checkout master
>> error: Untracked working tree file 'Project/bin/path/file.jjt' would
>> be overwritten by merge.
> What is the output of
>
>        $ git ls-files master bin/

Nothing:

$ git ls-files master bin/
$ git ls-files master Project/bin/
$ git ls-files mybranch bin/
$ git ls-files mybranch Project/bin/

$ ll 'Project/bin/path/file.jjt'
-rw-r--r--    1 bost  Administ     8233 May 10  2006 Project/bin/path/file.jjt
$ git ls-files ''Project/bin/path/file.jjt'

BTW the rule to ignore bin/ is exclusively in the .gitignore on the
branch mybranch not in the master branch. Might this be the problem?

Bost

^ permalink raw reply

* Re: .gitignore vs untracked working file
From: Uwe Kleine-König @ 2009-08-10 10:01 UTC (permalink / raw)
  To: Rostislav Svoboda; +Cc: git
In-Reply-To: <286817520908100257n35b178ebu387161658554b4a@mail.gmail.com>

Hello,

> $ git checkout master
> error: Untracked working tree file 'Project/bin/path/file.jjt' would
> be overwritten by merge.
What is the output of

	$ git ls-files master bin/

?

Best regards
Uwe

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |

^ permalink raw reply

* .gitignore vs untracked working file
From: Rostislav Svoboda @ 2009-08-10  9:57 UTC (permalink / raw)
  To: git

Hi

I have a .gitignore rule to ignore everything in bin/ directories but
I cannot change branch because of a file lying in a bin/ directory
which actually should be ignored. What am I doing wrong?

$ git branch
  master
* mybranch

$ git status
# On branch mybranch
nothing to commit (working directory clean)

$ cat .gitignore
*.class
.cvsignore
CVS/
.metadata/
build/
bin/
.#*

$ git checkout master
error: Untracked working tree file 'Project/bin/path/file.jjt' would
be overwritten by merge.

$ git --version
git version 1.6.4.msysgit.0


thx

Bost

^ permalink raw reply

* Re: [PATCH 1/1] git-svn: ignore leading blank lines in svn:ignore
From: Eric Wong @ 2009-08-10  9:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Michael Haggerty, Adam Brewster
In-Reply-To: <e6857eacc53d862018138bd8d9e1ab778e8f5725.1249672562.git.mhagger@alum.mit.edu>

Michael Haggerty <mhagger@alum.mit.edu> wrote:
> Subversion ignores all blank lines in svn:ignore properties.  The old
> git-svn code ignored blank lines everywhere except for the first line
> of the svn:ignore property.  This patch makes the "git svn
> show-ignore" and "git svn create-ignore" commands ignore leading blank
> lines, too.
> 
> Also include leading blank lines in the test suite.
> 
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>

Thanks Michael,

Acked out and pushed out along with two of Adam's to
git://yhbt.net/git-svn:

Adam Brewster (2):
      svn: Add && to t9107-git-svn-migrate.sh
      svn: Honor --prefix option in init without --stdlayout

Michael Haggerty (1):
      git-svn: ignore leading blank lines in svn:ignore

-- 
Eric Wong

^ permalink raw reply

* Re: [PATCH v4 0/5] Re: {checkout,reset,stash} --patch
From: Thomas Rast @ 2009-08-10  9:36 UTC (permalink / raw)
  To: Nicolas Sebrecht
  Cc: Jeff King, git, Junio C Hamano, Sverre Rabbelier,
	Nanako Shiraishi
In-Reply-To: <20090809222658.GB12932@vidovic>

Nicolas Sebrecht wrote:
> 
> Ok. All of what you say above makes sense and I'm actually fine with
> your whole answer. That said,
> 
>   % git checkout -p HEAD
> 
> and
> 
>   % git checkout -p HEAD -- file
> 
> behave differently here in my test above.

Oh.  Sorry, that's indeed a bug, I'll fix this.  (The -- file form
loses the HEAD when invoking add--interactive.)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

^ permalink raw reply

* Re: [PATCH v3 3/8] wt-status: move wt_status_colors[] into wt_status structure
From: Jeff King @ 2009-08-10  9:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <1249894465-11018-4-git-send-email-gitster@pobox.com>

On Mon, Aug 10, 2009 at 01:54:20AM -0700, Junio C Hamano wrote:

> @@ -37,6 +38,7 @@ struct wt_status {
>  	int wt_status_relative_paths;
>  	int wt_status_submodule_summary;
>  	enum untracked_status_type show_untracked_files;
> +	char wt_status_colors[6][COLOR_MAXLEN];

Yuck on the magic "6". It should be safe to use

  ARRAY_SIZE(wt_status_colors_default)

since that is computed purely from sizeof's. Though I am not discounting
the possibility that there are compilers which will screw it up.

-Peff

^ permalink raw reply

* Re: [PATCH v3 2/8] wt-status: move many global settings to wt_status structure
From: Jeff King @ 2009-08-10  9:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git
In-Reply-To: <1249894465-11018-3-git-send-email-gitster@pobox.com>

On Mon, Aug 10, 2009 at 01:54:19AM -0700, Junio C Hamano wrote:

> --- a/wt-status.h
> +++ b/wt-status.h
> [...]
> @@ -33,8 +32,12 @@ struct wt_status {
>  	const char *reference;
>  	int verbose;
>  	int amend;
> -	int untracked;
>  	int nowarn;
> +	int wt_status_use_color;
> +	int wt_status_relative_paths;
> +	int wt_status_submodule_summary;
> +	enum untracked_status_type show_untracked_files;
> +

Is there a particular reason to use such enormous struct member names?
IOW, inside wt_status, why not just "use_color"?

Other than that, I think this is a very positive change (and in fact, I
like the way this whole series is shaping up).

-Peff

^ permalink raw reply

* Re: [PATCH v2] push: point to 'git pull' and 'git push --force' in case of non-fast forward
From: Matthieu Moy @ 2009-08-10  8:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Teemu Likonen, git
In-Reply-To: <7v1vnk3vgc.fsf@alter.siamese.dyndns.org>

Junio C Hamano <gitster@pobox.com> writes:

> Matthieu Moy <Matthieu.Moy@imag.fr> writes:
>
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>> If you read "Integrate them with your changes" and understand that it is
>>> talking about "git pull" or "git pull --rebase", then you do not have to
>>> read the doc.  It should "click".
>>
>> But what's the point is being so vague, while you could just add "(see
>> git pull)"? See what you've just wrote: one should "understand that it
>> is about ...". So, why write Y thinking that the user should
>> understand that it is about X while you could write X directly?
>
> In order to cover both "pull" and "pull --rebase"?

"git pull" also covers both. "pull" is the command, "--rebase" is an
option of it.

-- 
Matthieu

^ permalink raw reply

* Re: gitweb stops working sometimes
From: Jakub Narebski @ 2009-08-10  8:58 UTC (permalink / raw)
  To: Erez Zilber; +Cc: git
In-Reply-To: <ce513bcc0908100101u70ade553h9d7dc413cb6a276d@mail.gmail.com>

Erez Zilber <erezzi.list@gmail.com> writes:

> I'm running gitweb on a centos 5.3 server and it works well 99% of the
> time. Sometimes, I see the following behavior:
> 1. I'm able to load the page that shows all git trees.
> 2. When I click on one of the links that should show a specific tree,
> it opens a page with the following text: "<div
> class="title">&nbsp;</div>
> "
> 
> If I restart httpd, it doesn't help. The only solution that I found so
> far is to reboot the server and then everything works. However,
> rebooting the server is a bad solution.
> 
> Any idea?

No idea what might be the cause of that.

1. Do you run gitweb as CGI script, or as mod_perl 
   (ModPerl::Registry) script?
2. Which version of git you are using?
3. Which version of gitweb you are using?

All of this info can be found in "generator" meta header on pages
generated by (modern) gitweb.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

^ permalink raw reply

* Re: [PATCH] git-instaweb: fix mod_perl detection for apache2
From: Jakub Narebski @ 2009-08-10  8:55 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Mark A Rada, git
In-Reply-To: <7vprb45ty7.fsf@alter.siamese.dyndns.org>

Junio C Hamano <gitster@pobox.com> writes:

> Mark A Rada <marada@uwaterloo.ca> writes:
> 
> > The script was looking for something that matched the '^our $gitbin'
> > regex, which no longer exists in gitweb.cgi.
> >
> > Now it looks for 'MOD_PERL', which should be on the line that checks
> > to see if the script is running in a mod_perl environment.
> 
> Thanks.  That sounds like an ancient bug that in turn perhaps suggests
> nobody uses instaweb.  Will apply to 'maint'..

Hmmm... taking a peek at current "Git User's Survey 2009" results
http://www.survs.com/shareResults?survey=2PIMZGU0&rndm=678J66QRA2

11. What Git interfaces, implementations, frontends and tools do you
    use?

    git-instaweb  	3%  	77 / 2712

16. How often do you use the following forms of git commands or extra
    git tools?  

    git instaweb 
      never:     1983 - 79%
      rarely:     208 -  8%
      sometimes:   50 -  2% 	
      often:        9 -  0% 	

    Total respondents  	 2506

-- 
Jakub Narebski
Poland
ShadeHawk on #git

^ permalink raw reply

* [PATCH v3 7/8] git stat: pathspec limits, unlike traditional "git status"
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git
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

^ permalink raw reply related

* [PATCH v3 8/8] git stat -s: short status output
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git
In-Reply-To: <1249894465-11018-8-git-send-email-gitster@pobox.com>

Give -s(hort) option to "git stat" that shows the status of paths in a
more concise way.

    XY PATH1 -> PATH2

format to be more machine readable than output from "git status", which is
about previewing of "git commit" with the same arguments.

PATH1 is the path in the HEAD, and " -> PATH2" part is shown only when
PATH1 corresponds to a different path in the index/worktree.

For unmerged entries, X shows the status of stage #2 (i.e. ours) and Y
shows the status of stage #3 (i.e. theirs).  For entries that do not have
conflicts, X shows the status of the index, and Y shows the status of the
work tree.  For untracked paths, XY are "??".

    X          Y     Meaning
    -------------------------------------------------
              [MD]   not updated
    M        [ MD]   updated in index
    A        [ MD]   added to index
    D        [ MD]   deleted from index
    R        [ MD]   renamed in index
    C        [ MD]   copied in index
    [MARC]           index and work tree matches
    [ MARC]     M    work tree changed since index
    [ MARC]     D    deleted in work tree

    D           D    unmerged, both deleted
    A           U    unmerged, added by us
    U           D    unmerged, deleted by them
    U           A    unmerged, added by them
    D           U    unmerged, deleted by us
    A           A    unmerged, both added
    U           U    unmerged, both modified

    ?           ?    untracked

When given -z option, the records are terminated by NUL characters for
better machine readability.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-commit.c |   97 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 96 insertions(+), 1 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index 9c2a70c..0ed0d71 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -898,11 +898,86 @@ static int git_status_config(const char *k, const char *v, void *cb)
 	return git_diff_ui_config(k, v, NULL);
 }
 
+#define quote_path quote_path_relative
+
+static void short_unmerged(int null_termination, struct string_list_item *it,
+			   struct wt_status *s)
+{
+	struct wt_status_change_data *d = it->util;
+	const char *how = "??";
+
+	switch (d->stagemask) {
+	case 1: how = "DD"; break; /* both deleted */
+	case 2: how = "AU"; break; /* added by us */
+	case 3: how = "UD"; break; /* deleted by them */
+	case 4: how = "UA"; break; /* added by them */
+	case 5: how = "DU"; break; /* deleted by us */
+	case 6: how = "AA"; break; /* both added */
+	case 7: how = "UU"; break; /* both modified */
+	}
+	printf("%s ", how);
+	if (null_termination) {
+		fprintf(stdout, "%s%c", it->string, 0);
+	} else {
+		struct strbuf onebuf = STRBUF_INIT;
+		const char *one;
+		one = quote_path(it->string, -1, &onebuf, s->prefix);
+		printf("%s\n", one);
+		strbuf_release(&onebuf);
+	}
+}
+
+static void short_status(int null_termination, struct string_list_item *it,
+			 struct wt_status *s)
+{
+	struct wt_status_change_data *d = it->util;
+
+	printf("%c%c ",
+	       !d->index_status ? ' ' : d->index_status,
+	       !d->worktree_status ? ' ' : d->worktree_status);
+	if (null_termination) {
+		fprintf(stdout, "%s%c", it->string, 0);
+		if (d->head_path)
+			fprintf(stdout, "%s%c", d->head_path, 0);
+	} else {
+		struct strbuf onebuf = STRBUF_INIT;
+		const char *one;
+		if (d->head_path) {
+			one = quote_path(d->head_path, -1, &onebuf, s->prefix);
+			printf("%s -> ", one);
+			strbuf_release(&onebuf);
+		}
+		one = quote_path(it->string, -1, &onebuf, s->prefix);
+		printf("%s\n", one);
+		strbuf_release(&onebuf);
+	}
+}
+
+static void short_untracked(int null_termination, struct string_list_item *it,
+			    struct wt_status *s)
+{
+	if (null_termination) {
+		fprintf(stdout, "?? %s%c", it->string, 0);
+	} else {
+		struct strbuf onebuf = STRBUF_INIT;
+		const char *one;
+		one = quote_path(it->string, -1, &onebuf, s->prefix);
+		printf("?? %s\n", one);
+		strbuf_release(&onebuf);
+	}
+}
+
 int cmd_stat(int argc, const char **argv, const char *prefix)
 {
 	struct wt_status s;
+	static int null_termination, shortstatus;
+	int i;
 	unsigned char sha1[20];
 	static struct option builtin_stat_options[] = {
+		OPT_BOOLEAN('s', "short", &shortstatus,
+			    "show status concicely"),
+		OPT_BOOLEAN('z', "null", &null_termination,
+			    "terminate entries with NUL"),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
 		  "mode",
 		  "show untracked files, optional modes: all, normal, no. (Default: all)",
@@ -925,7 +1000,27 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
 	s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
 	wt_status_collect(&s);
 
-	wt_status_print_body(&s);
+	if (shortstatus) {
+		for (i = 0; i < s.change.nr; i++) {
+			struct wt_status_change_data *d;
+			struct string_list_item *it;
+
+			it = &(s.change.items[i]);
+			d = it->util;
+			if (d->stagemask)
+				short_unmerged(null_termination, it, &s);
+			else
+				short_status(null_termination, it, &s);
+		}
+		for (i = 0; i < s.untracked.nr; i++) {
+			struct string_list_item *it;
+
+			it = &(s.untracked.items[i]);
+			short_untracked(null_termination, it, &s);
+		}
+	} else {
+		wt_status_print_body(&s);
+	}
 	return 0;
 }
 
-- 
1.6.4.173.g72959

^ permalink raw reply related

* [PATCH v3 6/8] git stat: the beginning
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git
In-Reply-To: <1249894465-11018-6-git-send-email-gitster@pobox.com>

Tentatively add "git stat" as a new command.  This does not munge the
index with paths parameters before showing the status like "git status"
does.  In later rounds, we will take path parameters as pathspec to limit
the output.
---
 Makefile         |    1 +
 builtin-commit.c |   60 +++++++++++++++++++++++++++++++++++++++++++++---------
 builtin.h        |    1 +
 git.c            |    1 +
 wt-status.c      |   24 +++++++++++++--------
 wt-status.h      |    1 +
 6 files changed, 69 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile
index daf4296..39dd334 100644
--- a/Makefile
+++ b/Makefile
@@ -378,6 +378,7 @@ BUILT_INS += git-init$X
 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 601118f..bc780a8 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -24,6 +24,7 @@
 #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>...",
@@ -35,6 +36,11 @@ static const char * const builtin_status_usage[] = {
 	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";
@@ -691,6 +697,21 @@ static const char *find_author_by_nickname(const char *name)
 	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,
@@ -794,16 +815,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	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.");
@@ -886,6 +898,34 @@ static int git_status_config(const char *k, const char *v, void *cb)
 	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[] = {
+		{ 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);
+
+	read_cache();
+	refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
+	s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
+	wt_status_collect(&s);
+
+	wt_status_print_body(&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 20427d2..eeaf0b6 100644
--- a/builtin.h
+++ b/builtin.h
@@ -95,6 +95,7 @@ extern int cmd_send_pack(int argc, const char **argv, const char *prefix);
 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);
diff --git a/git.c b/git.c
index 807d875..de7fcf6 100644
--- a/git.c
+++ b/git.c
@@ -350,6 +350,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "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 b6ae12c..a5dbdcc 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -531,6 +531,20 @@ static void wt_status_print_tracking(struct wt_status *s)
 	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 }
 
+void wt_status_print_body(struct wt_status *s)
+{
+	wt_status_print_unmerged(s);
+	wt_status_print_updated(s);
+	wt_status_print_changed(s);
+	if (s->wt_status_submodule_summary)
+		wt_status_print_submodule_summary(s);
+	if (s->show_untracked_files)
+		wt_status_print_untracked(s);
+	else if (s->commitable)
+		fprintf(s->fp,
+			"# Untracked files not listed (use -u option to show untracked files)\n");
+}
+
 void wt_status_print(struct wt_status *s)
 {
 	unsigned char sha1[20];
@@ -561,15 +575,7 @@ void wt_status_print(struct wt_status *s)
 		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 	}
 
-	wt_status_print_unmerged(s);
-	wt_status_print_updated(s);
-	wt_status_print_changed(s);
-	if (s->wt_status_submodule_summary)
-		wt_status_print_submodule_summary(s);
-	if (s->show_untracked_files)
-		wt_status_print_untracked(s);
-	else if (s->commitable)
-		 fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");
+	wt_status_print_body(s);
 
 	if (s->verbose)
 		wt_status_print_verbose(s);
diff --git a/wt-status.h b/wt-status.h
index 33240b3..44c40ff 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -54,5 +54,6 @@ struct wt_status {
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
+void wt_status_print_body(struct wt_status *s);
 
 #endif /* STATUS_H */
-- 
1.6.4.173.g72959

^ permalink raw reply related

* [PATCH v3 5/8] wt-status: collect untracked files in a separate "collect" phase
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git
In-Reply-To: <1249894465-11018-5-git-send-email-gitster@pobox.com>

In a way similar to updated and locally modified files are collected.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 wt-status.c |   58 ++++++++++++++++++++++++++++++++++++----------------------
 wt-status.h |    3 ++-
 2 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 68e4d9b..b6ae12c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -41,6 +41,7 @@ void wt_status_prepare(struct wt_status *s)
 	s->fp = stdout;
 	s->index_file = get_index_file();
 	s->change.strdup_strings = 1;
+	s->untracked.strdup_strings = 1;
 }
 
 static void wt_status_print_unmerged_header(struct wt_status *s)
@@ -311,7 +312,30 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
 	}
 }
 
-void wt_status_collect_changes(struct wt_status *s)
+static void wt_status_collect_untracked(struct wt_status *s)
+{
+	int i;
+	struct dir_struct dir;
+
+	if (!s->show_untracked_files)
+		return;
+	memset(&dir, 0, sizeof(dir));
+	if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
+		dir.flags |=
+			DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
+	setup_standard_excludes(&dir);
+
+	fill_directory(&dir, NULL);
+	for(i = 0; i < dir.nr; i++) {
+		struct dir_entry *ent = dir.entries[i];
+		if (!cache_name_is_other(ent->name, ent->len))
+			continue;
+		s->workdir_untracked = 1;
+		string_list_insert(ent->name, &s->untracked);
+	}
+}
+
+void wt_status_collect(struct wt_status *s)
 {
 	wt_status_collect_changes_worktree(s);
 
@@ -319,6 +343,7 @@ void wt_status_collect_changes(struct wt_status *s)
 		wt_status_collect_changes_initial(s);
 	else
 		wt_status_collect_changes_index(s);
+	wt_status_collect_untracked(s);
 }
 
 static void wt_status_print_unmerged(struct wt_status *s)
@@ -446,31 +471,20 @@ static void wt_status_print_submodule_summary(struct wt_status *s)
 
 static void wt_status_print_untracked(struct wt_status *s)
 {
-	struct dir_struct dir;
 	int i;
-	int shown_header = 0;
 	struct strbuf buf = STRBUF_INIT;
 
-	memset(&dir, 0, sizeof(dir));
-	if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
-		dir.flags |=
-			DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
-	setup_standard_excludes(&dir);
+	if (!s->untracked.nr)
+		return;
 
-	fill_directory(&dir, NULL);
-	for(i = 0; i < dir.nr; i++) {
-		struct dir_entry *ent = dir.entries[i];
-		if (!cache_name_is_other(ent->name, ent->len))
-			continue;
-		if (!shown_header) {
-			s->workdir_untracked = 1;
-			wt_status_print_untracked_header(s);
-			shown_header = 1;
-		}
+	wt_status_print_untracked_header(s);
+	for (i = 0; i < s->untracked.nr; i++) {
+		struct string_list_item *it;
+		it = &(s->untracked.items[i]);
 		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
 		color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
-				quote_path(ent->name, ent->len,
-					&buf, s->prefix));
+				 quote_path(it->string, strlen(it->string),
+					    &buf, s->prefix));
 	}
 	strbuf_release(&buf);
 }
@@ -539,7 +553,7 @@ void wt_status_print(struct wt_status *s)
 			wt_status_print_tracking(s);
 	}
 
-	wt_status_collect_changes(s);
+	wt_status_collect(s);
 
 	if (s->is_initial) {
 		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
@@ -566,7 +580,7 @@ void wt_status_print(struct wt_status *s)
 			; /* nothing */
 		else if (s->workdir_dirty)
 			printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
-		else if (s->workdir_untracked)
+		else if (s->untracked.nr)
 			printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
 		else if (s->is_initial)
 			printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
diff --git a/wt-status.h b/wt-status.h
index 12dc95e..33240b3 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -48,10 +48,11 @@ struct wt_status {
 	FILE *fp;
 	const char *prefix;
 	struct string_list change;
+	struct string_list untracked;
 };
 
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
-void wt_status_collect_changes(struct wt_status *s);
+void wt_status_collect(struct wt_status *s);
 
 #endif /* STATUS_H */
-- 
1.6.4.173.g72959

^ permalink raw reply related

* [PATCH v3 4/8] Make git_status_config() file scope static to builtin-commit.c
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git
In-Reply-To: <1249894465-11018-4-git-send-email-gitster@pobox.com>

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-commit.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.c      |   60 ------------------------------------------------------
 wt-status.h      |    1 -
 3 files changed, 60 insertions(+), 61 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index ca36ba2..601118f 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -826,6 +826,66 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix,
 	return commitable ? 0 : 1;
 }
 
+static int parse_status_slot(const char *var, int offset)
+{
+	if (!strcasecmp(var+offset, "header"))
+		return WT_STATUS_HEADER;
+	if (!strcasecmp(var+offset, "updated")
+		|| !strcasecmp(var+offset, "added"))
+		return WT_STATUS_UPDATED;
+	if (!strcasecmp(var+offset, "changed"))
+		return WT_STATUS_CHANGED;
+	if (!strcasecmp(var+offset, "untracked"))
+		return WT_STATUS_UNTRACKED;
+	if (!strcasecmp(var+offset, "nobranch"))
+		return WT_STATUS_NOBRANCH;
+	if (!strcasecmp(var+offset, "unmerged"))
+		return WT_STATUS_UNMERGED;
+	die("bad config variable '%s'", var);
+}
+
+static int git_status_config(const char *k, const char *v, void *cb)
+{
+	struct wt_status *s = cb;
+
+	if (!strcmp(k, "status.submodulesummary")) {
+		int is_bool;
+		s->wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
+		if (is_bool && s->wt_status_submodule_summary)
+			s->wt_status_submodule_summary = -1;
+		return 0;
+	}
+	if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
+		s->wt_status_use_color = git_config_colorbool(k, v, -1);
+		return 0;
+	}
+	if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
+		int slot = parse_status_slot(k, 13);
+		if (!v)
+			return config_error_nonbool(k);
+		color_parse(v, k, s->wt_status_colors[slot]);
+		return 0;
+	}
+	if (!strcmp(k, "status.relativepaths")) {
+		s->wt_status_relative_paths = git_config_bool(k, v);
+		return 0;
+	}
+	if (!strcmp(k, "status.showuntrackedfiles")) {
+		if (!v)
+			return config_error_nonbool(k);
+		else if (!strcmp(v, "no"))
+			s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
+		else if (!strcmp(v, "normal"))
+			s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+		else if (!strcmp(v, "all"))
+			s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
+		else
+			return error("Invalid untracked files mode '%s'", v);
+		return 0;
+	}
+	return git_diff_ui_config(k, v, NULL);
+}
+
 int cmd_status(int argc, const char **argv, const char *prefix)
 {
 	struct wt_status s;
diff --git a/wt-status.c b/wt-status.c
index a2a7257..68e4d9b 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -19,24 +19,6 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_RED,    /* WT_STATUS_UNMERGED */
 };
 
-static int parse_status_slot(const char *var, int offset)
-{
-	if (!strcasecmp(var+offset, "header"))
-		return WT_STATUS_HEADER;
-	if (!strcasecmp(var+offset, "updated")
-		|| !strcasecmp(var+offset, "added"))
-		return WT_STATUS_UPDATED;
-	if (!strcasecmp(var+offset, "changed"))
-		return WT_STATUS_CHANGED;
-	if (!strcasecmp(var+offset, "untracked"))
-		return WT_STATUS_UNTRACKED;
-	if (!strcasecmp(var+offset, "nobranch"))
-		return WT_STATUS_NOBRANCH;
-	if (!strcasecmp(var+offset, "unmerged"))
-		return WT_STATUS_UNMERGED;
-	die("bad config variable '%s'", var);
-}
-
 static const char *color(int slot, struct wt_status *s)
 {
 	return s->wt_status_use_color > 0 ? s->wt_status_colors[slot] : "";
@@ -594,45 +576,3 @@ void wt_status_print(struct wt_status *s)
 			printf("nothing to commit (working directory clean)\n");
 	}
 }
-
-int git_status_config(const char *k, const char *v, void *cb)
-{
-	struct wt_status *s = cb;
-
-	if (!strcmp(k, "status.submodulesummary")) {
-		int is_bool;
-		s->wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
-		if (is_bool && s->wt_status_submodule_summary)
-			s->wt_status_submodule_summary = -1;
-		return 0;
-	}
-	if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
-		s->wt_status_use_color = git_config_colorbool(k, v, -1);
-		return 0;
-	}
-	if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
-		int slot = parse_status_slot(k, 13);
-		if (!v)
-			return config_error_nonbool(k);
-		color_parse(v, k, s->wt_status_colors[slot]);
-		return 0;
-	}
-	if (!strcmp(k, "status.relativepaths")) {
-		s->wt_status_relative_paths = git_config_bool(k, v);
-		return 0;
-	}
-	if (!strcmp(k, "status.showuntrackedfiles")) {
-		if (!v)
-			return config_error_nonbool(k);
-		else if (!strcmp(v, "no"))
-			s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
-		else if (!strcmp(v, "normal"))
-			s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
-		else if (!strcmp(v, "all"))
-			s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
-		else
-			return error("Invalid untracked files mode '%s'", v);
-		return 0;
-	}
-	return git_diff_ui_config(k, v, NULL);
-}
diff --git a/wt-status.h b/wt-status.h
index f22c3c1..12dc95e 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -50,7 +50,6 @@ struct wt_status {
 	struct string_list change;
 };
 
-int git_status_config(const char *var, const char *value, void *cb);
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect_changes(struct wt_status *s);
-- 
1.6.4.173.g72959

^ permalink raw reply related

* [PATCH v3 3/8] wt-status: move wt_status_colors[] into wt_status structure
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git
In-Reply-To: <1249894465-11018-3-git-send-email-gitster@pobox.com>

The benefit of this one alone is somewhat iffy, but for completeness this
moves the wt_status_colors[] color palette to the wt_status structure to
complete what the previous commit started.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 wt-status.c |    9 +++++----
 wt-status.h |    2 ++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index c84a18a..a2a7257 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1,6 +1,5 @@
 #include "cache.h"
 #include "wt-status.h"
-#include "color.h"
 #include "object.h"
 #include "dir.h"
 #include "commit.h"
@@ -11,7 +10,7 @@
 #include "run-command.h"
 #include "remote.h"
 
-static char wt_status_colors[][COLOR_MAXLEN] = {
+static char default_wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
 	GIT_COLOR_GREEN,  /* WT_STATUS_UPDATED */
 	GIT_COLOR_RED,    /* WT_STATUS_CHANGED */
@@ -40,7 +39,7 @@ static int parse_status_slot(const char *var, int offset)
 
 static const char *color(int slot, struct wt_status *s)
 {
-	return s->wt_status_use_color > 0 ? wt_status_colors[slot] : "";
+	return s->wt_status_use_color > 0 ? s->wt_status_colors[slot] : "";
 }
 
 void wt_status_prepare(struct wt_status *s)
@@ -49,6 +48,8 @@ void wt_status_prepare(struct wt_status *s)
 	const char *head;
 
 	memset(s, 0, sizeof(*s));
+	memcpy(s->wt_status_colors, default_wt_status_colors,
+	       sizeof(default_wt_status_colors));
 	s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
 	s->wt_status_use_color = -1;
 	s->wt_status_relative_paths = 1;
@@ -613,7 +614,7 @@ int git_status_config(const char *k, const char *v, void *cb)
 		int slot = parse_status_slot(k, 13);
 		if (!v)
 			return config_error_nonbool(k);
-		color_parse(v, k, wt_status_colors[slot]);
+		color_parse(v, k, s->wt_status_colors[slot]);
 		return 0;
 	}
 	if (!strcmp(k, "status.relativepaths")) {
diff --git a/wt-status.h b/wt-status.h
index 3d7fe30..f22c3c1 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include "string-list.h"
+#include "color.h"
 
 enum color_wt_status {
 	WT_STATUS_HEADER,
@@ -37,6 +38,7 @@ struct wt_status {
 	int wt_status_relative_paths;
 	int wt_status_submodule_summary;
 	enum untracked_status_type show_untracked_files;
+	char wt_status_colors[6][COLOR_MAXLEN];
 
 	/* These are computed during processing of the individual sections */
 	int commitable;
-- 
1.6.4.173.g72959

^ permalink raw reply related

* [PATCH v3 2/8] wt-status: move many global settings to wt_status structure
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git
In-Reply-To: <1249894465-11018-2-git-send-email-gitster@pobox.com>

Turn four global variables (wt_status_use_color, show_tracked_files,
wt_status_relative_paths, and wt_status_submodule_summary) into fields of
wt_status structure.  Get rid of "untracked" field that was used only to
keep track of otherwise available information redundantly.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-commit.c |   87 +++++++++++++++++++++++++++++------------------------
 wt-status.c      |   81 +++++++++++++++++++++++++-------------------------
 wt-status.h      |    9 +++--
 3 files changed, 93 insertions(+), 84 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index 3a7e35d..ca36ba2 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -343,27 +343,24 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
 	return false_lock.filename;
 }
 
-static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn)
+static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
+		      struct wt_status *s)
 {
-	struct wt_status s;
-
-	wt_status_prepare(&s);
-	if (wt_status_relative_paths)
-		s.prefix = prefix;
+	if (s->wt_status_relative_paths)
+		s->prefix = prefix;
 
 	if (amend) {
-		s.amend = 1;
-		s.reference = "HEAD^1";
+		s->amend = 1;
+		s->reference = "HEAD^1";
 	}
-	s.verbose = verbose;
-	s.untracked = (show_untracked_files == SHOW_ALL_UNTRACKED_FILES);
-	s.index_file = index_file;
-	s.fp = fp;
-	s.nowarn = nowarn;
+	s->verbose = verbose;
+	s->index_file = index_file;
+	s->fp = fp;
+	s->nowarn = nowarn;
 
-	wt_status_print(&s);
+	wt_status_print(s);
 
-	return s.commitable;
+	return s->commitable;
 }
 
 static int is_a_merge(const unsigned char *sha1)
@@ -417,7 +414,8 @@ static void determine_author_info(void)
 	author_date = date;
 }
 
-static int prepare_to_commit(const char *index_file, const char *prefix)
+static int prepare_to_commit(const char *index_file, const char *prefix,
+			     struct wt_status *s)
 {
 	struct stat statbuf;
 	int commitable, saved_color_setting;
@@ -559,10 +557,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
 		if (ident_shown)
 			fprintf(fp, "#\n");
 
-		saved_color_setting = wt_status_use_color;
-		wt_status_use_color = 0;
-		commitable = run_status(fp, index_file, prefix, 1);
-		wt_status_use_color = saved_color_setting;
+		saved_color_setting = s->wt_status_use_color;
+		s->wt_status_use_color = 0;
+		commitable = run_status(fp, index_file, prefix, 1, s);
+		s->wt_status_use_color = saved_color_setting;
 	} else {
 		unsigned char sha1[20];
 		const char *parent = "HEAD";
@@ -583,7 +581,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
 
 	if (!commitable && !in_merge && !allow_empty &&
 	    !(amend && is_a_merge(head_sha1))) {
-		run_status(stdout, index_file, prefix, 0);
+		run_status(stdout, index_file, prefix, 0, s);
 		return 0;
 	}
 
@@ -695,7 +693,8 @@ static const char *find_author_by_nickname(const char *name)
 
 static int parse_and_validate_options(int argc, const char *argv[],
 				      const char * const usage[],
-				      const char *prefix)
+				      const char *prefix,
+				      struct wt_status *s)
 {
 	int f = 0;
 
@@ -798,11 +797,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	if (!untracked_files_arg)
 		; /* default already initialized */
 	else if (!strcmp(untracked_files_arg, "no"))
-		show_untracked_files = SHOW_NO_UNTRACKED_FILES;
+		s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
 	else if (!strcmp(untracked_files_arg, "normal"))
-		show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+		s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
 	else if (!strcmp(untracked_files_arg, "all"))
-		show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
+		s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
 	else
 		die("Invalid untracked files mode '%s'", untracked_files_arg);
 
@@ -814,13 +813,14 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	return argc;
 }
 
-static int dry_run_commit(int argc, const char **argv, const char *prefix)
+static int dry_run_commit(int argc, const char **argv, const char *prefix,
+			  struct wt_status *s)
 {
 	int commitable;
 	const char *index_file;
 
 	index_file = prepare_index(argc, argv, prefix, 1);
-	commitable = run_status(stdout, index_file, prefix, 0);
+	commitable = run_status(stdout, index_file, prefix, 0, s);
 	rollback_index_files();
 
 	return commitable ? 0 : 1;
@@ -828,14 +828,18 @@ static int dry_run_commit(int argc, const char **argv, const char *prefix)
 
 int cmd_status(int argc, const char **argv, const char *prefix)
 {
-	git_config(git_status_config, NULL);
-	if (wt_status_use_color == -1)
-		wt_status_use_color = git_use_color_default;
+	struct wt_status s;
+
+	wt_status_prepare(&s);
+	git_config(git_status_config, &s);
+	if (s.wt_status_use_color == -1)
+		s.wt_status_use_color = git_use_color_default;
 	if (diff_use_color_default == -1)
 		diff_use_color_default = git_use_color_default;
 
-	argc = parse_and_validate_options(argc, argv, builtin_status_usage, prefix);
-	return dry_run_commit(argc, argv, prefix);
+	argc = parse_and_validate_options(argc, argv, builtin_status_usage,
+					  prefix, &s);
+	return dry_run_commit(argc, argv, prefix, &s);
 }
 
 static void print_summary(const char *prefix, const unsigned char *sha1)
@@ -887,10 +891,12 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
 
 static int git_commit_config(const char *k, const char *v, void *cb)
 {
+	struct wt_status *s = cb;
+
 	if (!strcmp(k, "commit.template"))
 		return git_config_string(&template_file, k, v);
 
-	return git_status_config(k, v, cb);
+	return git_status_config(k, v, s);
 }
 
 int cmd_commit(int argc, const char **argv, const char *prefix)
@@ -903,21 +909,24 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	struct commit_list *parents = NULL, **pptr = &parents;
 	struct stat statbuf;
 	int allow_fast_forward = 1;
+	struct wt_status s;
 
-	git_config(git_commit_config, NULL);
+	wt_status_prepare(&s);
+	git_config(git_commit_config, &s);
 
-	if (wt_status_use_color == -1)
-		wt_status_use_color = git_use_color_default;
+	if (s.wt_status_use_color == -1)
+		s.wt_status_use_color = git_use_color_default;
 
-	argc = parse_and_validate_options(argc, argv, builtin_commit_usage, prefix);
+	argc = parse_and_validate_options(argc, argv, builtin_commit_usage,
+					  prefix, &s);
 	if (dry_run)
-		return dry_run_commit(argc, argv, prefix);
+		return dry_run_commit(argc, argv, prefix, &s);
 
 	index_file = prepare_index(argc, argv, prefix, 0);
 
 	/* Set up everything for writing the commit object.  This includes
 	   running hooks, writing the trees, and interacting with the user.  */
-	if (!prepare_to_commit(index_file, prefix)) {
+	if (!prepare_to_commit(index_file, prefix, &s)) {
 		rollback_index_files();
 		return 1;
 	}
diff --git a/wt-status.c b/wt-status.c
index 97fedfa..c84a18a 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -11,9 +11,6 @@
 #include "run-command.h"
 #include "remote.h"
 
-int wt_status_relative_paths = 1;
-int wt_status_use_color = -1;
-static int wt_status_submodule_summary;
 static char wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
 	GIT_COLOR_GREEN,  /* WT_STATUS_UPDATED */
@@ -23,8 +20,6 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_RED,    /* WT_STATUS_UNMERGED */
 };
 
-enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
-
 static int parse_status_slot(const char *var, int offset)
 {
 	if (!strcasecmp(var+offset, "header"))
@@ -43,9 +38,9 @@ static int parse_status_slot(const char *var, int offset)
 	die("bad config variable '%s'", var);
 }
 
-static const char *color(int slot)
+static const char *color(int slot, struct wt_status *s)
 {
-	return wt_status_use_color > 0 ? wt_status_colors[slot] : "";
+	return s->wt_status_use_color > 0 ? wt_status_colors[slot] : "";
 }
 
 void wt_status_prepare(struct wt_status *s)
@@ -54,6 +49,9 @@ void wt_status_prepare(struct wt_status *s)
 	const char *head;
 
 	memset(s, 0, sizeof(*s));
+	s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+	s->wt_status_use_color = -1;
+	s->wt_status_relative_paths = 1;
 	head = resolve_ref("HEAD", sha1, 0, NULL);
 	s->branch = head ? xstrdup(head) : NULL;
 	s->reference = "HEAD";
@@ -64,7 +62,7 @@ void wt_status_prepare(struct wt_status *s)
 
 static void wt_status_print_unmerged_header(struct wt_status *s)
 {
-	const char *c = color(WT_STATUS_HEADER);
+	const char *c = color(WT_STATUS_HEADER, s);
 	color_fprintf_ln(s->fp, c, "# Unmerged paths:");
 	if (!s->is_initial)
 		color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
@@ -76,7 +74,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
 
 static void wt_status_print_cached_header(struct wt_status *s)
 {
-	const char *c = color(WT_STATUS_HEADER);
+	const char *c = color(WT_STATUS_HEADER, s);
 	color_fprintf_ln(s->fp, c, "# Changes to be committed:");
 	if (!s->is_initial) {
 		color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
@@ -89,7 +87,7 @@ static void wt_status_print_cached_header(struct wt_status *s)
 static void wt_status_print_dirty_header(struct wt_status *s,
 					 int has_deleted)
 {
-	const char *c = color(WT_STATUS_HEADER);
+	const char *c = color(WT_STATUS_HEADER, s);
 	color_fprintf_ln(s->fp, c, "# Changed but not updated:");
 	if (!has_deleted)
 		color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to update what will be committed)");
@@ -101,7 +99,7 @@ static void wt_status_print_dirty_header(struct wt_status *s,
 
 static void wt_status_print_untracked_header(struct wt_status *s)
 {
-	const char *c = color(WT_STATUS_HEADER);
+	const char *c = color(WT_STATUS_HEADER, s);
 	color_fprintf_ln(s->fp, c, "# Untracked files:");
 	color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to include in what will be committed)");
 	color_fprintf_ln(s->fp, c, "#");
@@ -109,7 +107,7 @@ static void wt_status_print_untracked_header(struct wt_status *s)
 
 static void wt_status_print_trailer(struct wt_status *s)
 {
-	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
+	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 }
 
 #define quote_path quote_path_relative
@@ -117,13 +115,13 @@ static void wt_status_print_trailer(struct wt_status *s)
 static void wt_status_print_unmerged_data(struct wt_status *s,
 					  struct string_list_item *it)
 {
-	const char *c = color(WT_STATUS_UNMERGED);
+	const char *c = color(WT_STATUS_UNMERGED, s);
 	struct wt_status_change_data *d = it->util;
 	struct strbuf onebuf = STRBUF_INIT;
 	const char *one, *how = "bug";
 
 	one = quote_path(it->string, -1, &onebuf, s->prefix);
-	color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
+	color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
 	switch (d->stagemask) {
 	case 1: how = "both deleted:"; break;
 	case 2: how = "added by us:"; break;
@@ -142,7 +140,7 @@ static void wt_status_print_change_data(struct wt_status *s,
 					struct string_list_item *it)
 {
 	struct wt_status_change_data *d = it->util;
-	const char *c = color(change_type);
+	const char *c = color(change_type, s);
 	int status = status;
 	char *one_name;
 	char *two_name;
@@ -164,7 +162,7 @@ static void wt_status_print_change_data(struct wt_status *s,
 	one = quote_path(one_name, -1, &onebuf, s->prefix);
 	two = quote_path(two_name, -1, &twobuf, s->prefix);
 
-	color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
+	color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
 	switch (status) {
 	case DIFF_STATUS_ADDED:
 		color_fprintf(s->fp, c, "new file:   %s", one);
@@ -450,7 +448,7 @@ static void wt_status_print_submodule_summary(struct wt_status *s)
 		NULL
 	};
 
-	sprintf(summary_limit, "%d", wt_status_submodule_summary);
+	sprintf(summary_limit, "%d", s->wt_status_submodule_summary);
 	snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
 
 	memset(&sm_summary, 0, sizeof(sm_summary));
@@ -471,8 +469,7 @@ static void wt_status_print_untracked(struct wt_status *s)
 	struct strbuf buf = STRBUF_INIT;
 
 	memset(&dir, 0, sizeof(dir));
-
-	if (!s->untracked)
+	if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
 		dir.flags |=
 			DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
 	setup_standard_excludes(&dir);
@@ -487,8 +484,8 @@ static void wt_status_print_untracked(struct wt_status *s)
 			wt_status_print_untracked_header(s);
 			shown_header = 1;
 		}
-		color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
-		color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED), "%s",
+		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
+		color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
 				quote_path(ent->name, ent->len,
 					&buf, s->prefix));
 	}
@@ -532,15 +529,15 @@ static void wt_status_print_tracking(struct wt_status *s)
 		return;
 
 	for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
-		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER),
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
 				 "# %.*s", (int)(ep - cp), cp);
-	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
+	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 }
 
 void wt_status_print(struct wt_status *s)
 {
 	unsigned char sha1[20];
-	const char *branch_color = color(WT_STATUS_HEADER);
+	const char *branch_color = color(WT_STATUS_HEADER, s);
 
 	s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
 	if (s->branch) {
@@ -550,10 +547,10 @@ void wt_status_print(struct wt_status *s)
 			branch_name += 11;
 		else if (!strcmp(branch_name, "HEAD")) {
 			branch_name = "";
-			branch_color = color(WT_STATUS_NOBRANCH);
+			branch_color = color(WT_STATUS_NOBRANCH, s);
 			on_what = "Not currently on any branch.";
 		}
-		color_fprintf(s->fp, color(WT_STATUS_HEADER), "# ");
+		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
 		color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
 		if (!s->is_initial)
 			wt_status_print_tracking(s);
@@ -562,17 +559,17 @@ void wt_status_print(struct wt_status *s)
 	wt_status_collect_changes(s);
 
 	if (s->is_initial) {
-		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
-		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "# Initial commit");
-		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
 	}
 
 	wt_status_print_unmerged(s);
 	wt_status_print_updated(s);
 	wt_status_print_changed(s);
-	if (wt_status_submodule_summary)
+	if (s->wt_status_submodule_summary)
 		wt_status_print_submodule_summary(s);
-	if (show_untracked_files)
+	if (s->show_untracked_files)
 		wt_status_print_untracked(s);
 	else if (s->commitable)
 		 fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");
@@ -590,7 +587,7 @@ void wt_status_print(struct wt_status *s)
 			printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
 		else if (s->is_initial)
 			printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
-		else if (!show_untracked_files)
+		else if (!s->show_untracked_files)
 			printf("nothing to commit (use -u to show untracked files)\n");
 		else
 			printf("nothing to commit (working directory clean)\n");
@@ -599,15 +596,17 @@ void wt_status_print(struct wt_status *s)
 
 int git_status_config(const char *k, const char *v, void *cb)
 {
+	struct wt_status *s = cb;
+
 	if (!strcmp(k, "status.submodulesummary")) {
 		int is_bool;
-		wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
-		if (is_bool && wt_status_submodule_summary)
-			wt_status_submodule_summary = -1;
+		s->wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
+		if (is_bool && s->wt_status_submodule_summary)
+			s->wt_status_submodule_summary = -1;
 		return 0;
 	}
 	if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
-		wt_status_use_color = git_config_colorbool(k, v, -1);
+		s->wt_status_use_color = git_config_colorbool(k, v, -1);
 		return 0;
 	}
 	if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
@@ -618,21 +617,21 @@ int git_status_config(const char *k, const char *v, void *cb)
 		return 0;
 	}
 	if (!strcmp(k, "status.relativepaths")) {
-		wt_status_relative_paths = git_config_bool(k, v);
+		s->wt_status_relative_paths = git_config_bool(k, v);
 		return 0;
 	}
 	if (!strcmp(k, "status.showuntrackedfiles")) {
 		if (!v)
 			return config_error_nonbool(k);
 		else if (!strcmp(v, "no"))
-			show_untracked_files = SHOW_NO_UNTRACKED_FILES;
+			s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
 		else if (!strcmp(v, "normal"))
-			show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+			s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
 		else if (!strcmp(v, "all"))
-			show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
+			s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
 		else
 			return error("Invalid untracked files mode '%s'", v);
 		return 0;
 	}
-	return git_diff_ui_config(k, v, cb);
+	return git_diff_ui_config(k, v, NULL);
 }
diff --git a/wt-status.h b/wt-status.h
index f80142f..3d7fe30 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -18,7 +18,6 @@ enum untracked_status_type {
 	SHOW_NORMAL_UNTRACKED_FILES,
 	SHOW_ALL_UNTRACKED_FILES
 };
-extern enum untracked_status_type show_untracked_files;
 
 struct wt_status_change_data {
 	int worktree_status;
@@ -33,8 +32,12 @@ struct wt_status {
 	const char *reference;
 	int verbose;
 	int amend;
-	int untracked;
 	int nowarn;
+	int wt_status_use_color;
+	int wt_status_relative_paths;
+	int wt_status_submodule_summary;
+	enum untracked_status_type show_untracked_files;
+
 	/* These are computed during processing of the individual sections */
 	int commitable;
 	int workdir_dirty;
@@ -46,8 +49,6 @@ struct wt_status {
 };
 
 int git_status_config(const char *var, const char *value, void *cb);
-extern int wt_status_use_color;
-extern int wt_status_relative_paths;
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect_changes(struct wt_status *s);
-- 
1.6.4.173.g72959

^ permalink raw reply related

* [PATCH v3 1/8] commit: --dry-run
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git
In-Reply-To: <1249894465-11018-1-git-send-email-gitster@pobox.com>

This teaches --dry-run option to "git commit".

It is the same as "git status", but in the longer term we would want to
change the semantics of "git status" not to be the preview of commit, and
this is the first step for doing so.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/git-commit.txt |    7 ++++++-
 builtin-commit.c             |   29 ++++++++++++++++-------------
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index b5d81be..d01ff5a 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -8,7 +8,7 @@ git-commit - Record changes to the repository
 SYNOPSIS
 --------
 [verse]
-'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend]
+'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
 	   [(-c | -C) <commit>] [-F <file> | -m <msg>]
 	   [--allow-empty] [--no-verify] [-e] [--author=<author>]
 	   [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
@@ -198,6 +198,11 @@ specified.
 --quiet::
 	Suppress commit summary message.
 
+--dry-run::
+	Do not create a commit, but show a list of paths that are
+	to be committed, paths with local changes that will be left
+	uncommitted and paths that are untracked.
+
 \--::
 	Do not interpret any more arguments as options.
 
diff --git a/builtin-commit.c b/builtin-commit.c
index 6d12c2e..3a7e35d 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -51,7 +51,7 @@ static const char *template_file;
 static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, no_verify, allow_empty;
+static int quiet, verbose, no_verify, allow_empty, dry_run;
 static char *untracked_files_arg;
 /*
  * The default commit message cleanup mode will remove the lines
@@ -103,6 +103,7 @@ static struct option builtin_commit_options[] = {
 	OPT_BOOLEAN(0, "interactive", &interactive, "interactively add files"),
 	OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
 	OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
+	OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
 	OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
 	{ 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_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
@@ -813,28 +814,28 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	return argc;
 }
 
-int cmd_status(int argc, const char **argv, const char *prefix)
+static int dry_run_commit(int argc, const char **argv, const char *prefix)
 {
-	const char *index_file;
 	int commitable;
+	const char *index_file;
 
-	git_config(git_status_config, NULL);
+	index_file = prepare_index(argc, argv, prefix, 1);
+	commitable = run_status(stdout, index_file, prefix, 0);
+	rollback_index_files();
 
+	return commitable ? 0 : 1;
+}
+
+int cmd_status(int argc, const char **argv, const char *prefix)
+{
+	git_config(git_status_config, NULL);
 	if (wt_status_use_color == -1)
 		wt_status_use_color = git_use_color_default;
-
 	if (diff_use_color_default == -1)
 		diff_use_color_default = git_use_color_default;
 
 	argc = parse_and_validate_options(argc, argv, builtin_status_usage, prefix);
-
-	index_file = prepare_index(argc, argv, prefix, 1);
-
-	commitable = run_status(stdout, index_file, prefix, 0);
-
-	rollback_index_files();
-
-	return commitable ? 0 : 1;
+	return dry_run_commit(argc, argv, prefix);
 }
 
 static void print_summary(const char *prefix, const unsigned char *sha1)
@@ -909,6 +910,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		wt_status_use_color = git_use_color_default;
 
 	argc = parse_and_validate_options(argc, argv, builtin_commit_usage, prefix);
+	if (dry_run)
+		return dry_run_commit(argc, argv, prefix);
 
 	index_file = prepare_index(argc, argv, prefix, 0);
 
-- 
1.6.4.173.g72959

^ permalink raw reply related

* [PATCH v3 0/8] shortstatus updates
From: Junio C Hamano @ 2009-08-10  8:54 UTC (permalink / raw)
  To: git

Another round of "git status won't be a preview of git commit someday".
This builds on the part that are already in 'pu', and is queued in 'pu'.

Junio C Hamano (8):
  commit: --dry-run
  wt-status: move many global settings to wt_status structure
  wt-status: move wt_status_colors[] into wt_status structure
  Make git_status_config() file scope static to builtin-commit.c
  wt-status: collect untracked files in a separate "collect" phase
  git stat: the beginning
  git stat: pathspec limits, unlike traditional "git status"
  git stat -s: short status output

 Documentation/git-commit.txt |    7 +-
 Makefile                     |    1 +
 builtin-commit.c             |  312 +++++++++++++++++++++++++++++++++++-------
 builtin.h                    |    1 +
 git.c                        |    1 +
 wt-status.c                  |  206 ++++++++++++----------------
 wt-status.h                  |   17 ++-
 7 files changed, 367 insertions(+), 178 deletions(-)

^ permalink raw reply

* Re: [PATCH v2] push: point to 'git pull' and 'git push --force' in case of non-fast forward
From: Junio C Hamano @ 2009-08-10  8:49 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Teemu Likonen, git
In-Reply-To: <vpq8whsawjs.fsf@bauges.imag.fr>

Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>> If you read "Integrate them with your changes" and understand that it is
>> talking about "git pull" or "git pull --rebase", then you do not have to
>> read the doc.  It should "click".
>
> But what's the point is being so vague, while you could just add "(see
> git pull)"? See what you've just wrote: one should "understand that it
> is about ...". So, why write Y thinking that the user should
> understand that it is about X while you could write X directly?

In order to cover both "pull" and "pull --rebase"?

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox