From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "Kristian Høgsberg" <krh@redhat.com>
Cc: gitster@pobox.com, git@vger.kernel.org
Subject: Re: [PATCH] builtin-commit: fix "git add x y && git commit y" committing x, too
Date: Fri, 16 Nov 2007 00:43:17 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.64.0711160036450.30886@racer.site> (raw)
In-Reply-To: <1195146094.21076.6.camel@hinata.boston.redhat.com>
Hi,
On Thu, 15 Nov 2007, Kristian H?gsberg wrote:
> On Thu, 2007-11-15 at 16:11 +0000, Johannes Schindelin wrote:
> > Earlier, builtin commit would implicitly commit also the staged
> > changes.
> >
> > This patch fixes that.
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> >
> > The function reset_index_to_head() could be moved to somewhere
> > more central and be reused in builtin-reset.c instead of
> > reset_index_file() later...
> >
> > builtin-add.c | 1 +
> > builtin-commit.c | 30 +++++++++++++++++++++++++++++-
> > t/t7500-commit.sh | 10 ++++++++++
> > 3 files changed, 40 insertions(+), 1 deletions(-)
> >
> > diff --git a/builtin-add.c b/builtin-add.c
> > index 77dcde6..017c8f2 100644
> > --- a/builtin-add.c
> > +++ b/builtin-add.c
> > @@ -100,6 +100,7 @@ static void update_callback(struct diff_queue_struct *q,
> > case DIFF_STATUS_UNMERGED:
> > case DIFF_STATUS_MODIFIED:
> > case DIFF_STATUS_TYPE_CHANGED:
> > + case DIFF_STATUS_ADDED:
> > add_file_to_cache(path, verbose);
> > break;
> > case DIFF_STATUS_DELETED:
> > diff --git a/builtin-commit.c b/builtin-commit.c
> > index 535039c..0dc6e1c 100644
> > --- a/builtin-commit.c
> > +++ b/builtin-commit.c
> > @@ -19,6 +19,7 @@
> > #include "strbuf.h"
> > #include "utf8.h"
> > #include "parse-options.h"
> > +#include "unpack-trees.h"
> >
> > static const char * const builtin_commit_usage[] = {
> > "git-commit [options] [--] <filepattern>...",
> > @@ -77,6 +78,31 @@ static struct option builtin_commit_options[] = {
> > OPT_END()
> > };
> >
> > +static int reset_index_to_head(void)
> > +{
> > + struct unpack_trees_options opts;
> > + struct tree_desc tree_desc;
> > + struct tree *tree;
> > + unsigned char sha1[20];
> > +
> > + /* ignore if it is an initial commit */
> > + if (get_sha1("HEAD", sha1))
> > + return 0;
> > + tree = parse_tree_indirect(sha1);
> > + if (!tree || parse_tree(tree))
> > + return error("Could not get HEAD's tree");
> > + init_tree_desc(&tree_desc, tree->buffer, tree->size);
> > +
> > + memset(&opts, 0, sizeof(opts));
> > + opts.index_only = 1;
> > + opts.merge = 1;
> > + opts.head_idx = 1;
> > + opts.fn = oneway_merge;
> > + if (unpack_trees(1, &tree_desc, &opts))
> > + return error("Could not reset temporary index to HEAD");
> > + return 0;
> > +}
> > +
> > static char *prepare_index(const char **files, const char *prefix)
> > {
> > int fd;
> > @@ -120,12 +146,14 @@ static char *prepare_index(const char **files, const char *prefix)
> > die("failed to read HEAD tree object");
> > }
> >
> > + if (reset_index_to_head())
> > + die ("failed to reset temporary index to HEAD");
> > +
>
> If you look just above where you added these lines, there is code to
> deal with this case, except it doesn't work. I was trying to fix this
> too by adding a discard_cache() call before building the temp index, but
> then I couldn't add the files in question because the index was now
> newer than those files. Anyway, I don't know if your code is better
> that just doing read_tree(), but we should only have one or the other in
> there.
It's not only about discarding the cache. It's also about avoiding do
regenerate the index completely; this would waste time, especially for big
trees.
But the code you are referencing is only updating the index. The code I
added is to build the temporary index in a correct manner.
Unfortunately, I guess that the index as calculated by the code you are
referencing would be needed to show the correct status.
Therefore I propose to use a different struct index_state, copied from the
current one, for reset_index_to_head(), add_files_to_index() and
write_index() instead of working on the_index.
But that has to be done by somebody else than me, or wait for Tuesday, as
I will be travelling.
Ciao,
Dscho
next prev parent reply other threads:[~2007-11-16 0:44 UTC|newest]
Thread overview: 168+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-22 6:32 What's cooking in git/spearce.git (topics) Shawn O. Pearce
2007-10-22 6:59 ` Jeff King
2007-10-22 7:16 ` Jeff King
2007-10-23 2:32 ` Linus Torvalds
2007-10-23 3:48 ` Jeff King
2007-10-22 7:24 ` Pierre Habouzit
2007-10-22 15:27 ` Steffen Prohaska
2007-10-23 1:26 ` Junio C Hamano
2007-10-23 3:34 ` Shawn O. Pearce
2007-10-24 12:51 ` What's cooking in git.git (topics) Junio C Hamano
2007-10-24 13:09 ` David Symonds
2007-10-24 16:08 ` Scott Parish
2007-10-24 18:27 ` Andreas Ericsson
2007-10-25 0:35 ` Scott Parish
2007-11-01 5:41 ` Junio C Hamano
2007-11-01 11:02 ` Jakub Narebski
2007-11-01 20:57 ` Junio C Hamano
2007-11-01 18:33 ` Linus Torvalds
2007-11-01 19:19 ` Geert Bosch
2007-11-01 20:27 ` Junio C Hamano
2007-11-01 20:47 ` Mike Hommey
2007-11-01 21:20 ` Junio C Hamano
2007-11-02 0:32 ` Junio C Hamano
2007-11-01 21:44 ` Pierre Habouzit
2007-11-01 21:17 ` Geert Bosch
2007-11-02 0:00 ` Jonas Fonseca
2007-11-01 21:18 ` Theodore Tso
2007-11-01 21:26 ` Melchior FRANZ
2007-11-01 21:32 ` Johan Herland
2007-11-01 21:51 ` Junio C Hamano
2007-11-01 22:05 ` Linus Torvalds
2007-11-01 22:26 ` Bill Lear
2007-11-01 22:50 ` Junio C Hamano
2007-11-02 2:19 ` Petr Baudis
2007-11-01 21:42 ` Pierre Habouzit
2007-11-02 9:39 ` Andreas Ericsson
2007-11-01 21:57 ` Pierre Habouzit
2007-11-02 0:04 ` Jakub Narebski
2007-11-02 2:23 ` Petr Baudis
2007-11-02 7:25 ` Jakub Narebski
2007-11-02 7:28 ` Jakub Narebski
2007-11-02 8:42 ` Pierre Habouzit
2007-11-02 6:06 ` Miles Bader
2007-11-02 15:13 ` Miles Bader
2007-11-02 9:38 ` Andreas Ericsson
2007-11-02 11:03 ` Johannes Schindelin
2007-11-01 21:41 ` Brian Downing
2007-11-01 21:46 ` Pierre Habouzit
2007-11-02 10:26 ` Wincent Colaiuta
2007-11-04 4:14 ` Junio C Hamano
2007-11-04 9:43 ` Jakub Narebski
2007-11-04 11:38 ` Pierre Habouzit
2007-11-08 8:08 ` Junio C Hamano
2007-11-08 20:44 ` Steffen Prohaska
2007-11-12 7:09 ` Junio C Hamano
2007-11-12 12:21 ` Johannes Schindelin
2007-11-12 12:26 ` Pierre Habouzit
2007-11-12 12:33 ` Johannes Schindelin
2007-11-12 13:11 ` [PATCH] rebase: brown paper bag fix after the detached HEAD patch Johannes Schindelin
2007-11-12 14:53 ` What's cooking in git.git (topics) Pierre Habouzit
2007-11-12 14:27 ` Steffen Prohaska
2007-11-12 15:02 ` Johannes Schindelin
2007-11-18 16:13 ` [PATCH 1/2] push: Add '--matching' option and print warning if it should be used Steffen Prohaska
2007-11-18 16:13 ` [PATCH 2/2] push: Add '--current', which pushes only the current branch Steffen Prohaska
2007-11-19 1:28 ` Junio C Hamano
2007-11-19 6:41 ` Steffen Prohaska
2007-11-19 7:27 ` Junio C Hamano
2007-11-19 7:50 ` Junio C Hamano
2007-11-19 9:27 ` Andreas Ericsson
2007-11-19 8:17 ` Steffen Prohaska
2007-11-19 8:35 ` Junio C Hamano
2007-11-19 9:54 ` Steffen Prohaska
2007-11-19 16:51 ` [PATCH] push: Add "--current", " Steffen Prohaska
2007-11-19 11:17 ` [PATCH 2/2] push: Add '--current', " Jakub Narebski
2007-11-19 19:57 ` Junio C Hamano
2007-11-19 21:04 ` Jakub Narebski
2007-11-19 22:15 ` Junio C Hamano
2007-11-19 22:29 ` Jakub Narebski
2007-11-19 9:24 ` Andreas Ericsson
2007-11-12 15:15 ` [PATCH] git-commit: Add tests for invalid usage of -a/--interactive with paths Björn Steinbrink
2007-11-15 0:18 ` What's cooking in git.git (topics) Junio C Hamano
2007-11-15 0:49 ` Johannes Schindelin
2007-11-15 14:49 ` [PATCH] t7501-commit: Add test for git commit <file> with dirty index Kristian Høgsberg
2007-11-15 15:55 ` Johannes Schindelin
2007-11-15 16:11 ` [PATCH] builtin-commit: fix "git add x y && git commit y" committing x, too Johannes Schindelin
2007-11-15 16:37 ` Johannes Schindelin
2007-11-15 17:01 ` Kristian Høgsberg
2007-11-16 0:43 ` Johannes Schindelin [this message]
2007-11-17 8:45 ` Junio C Hamano
2007-11-18 9:18 ` Junio C Hamano
2007-11-17 12:40 ` What's cooking in git.git (topics) Jeff King
2007-11-17 20:51 ` Junio C Hamano
2007-11-17 23:42 ` Alex Riesen
2007-11-18 1:29 ` Junio C Hamano
2007-11-21 9:23 ` Junio C Hamano
2007-11-23 8:48 ` Junio C Hamano
2007-11-23 10:30 ` Jeff King
2007-11-23 13:23 ` Johannes Schindelin
2007-11-24 11:38 ` Jeff King
2007-11-24 15:47 ` Nicolas Pitre
2007-11-24 19:09 ` Junio C Hamano
2007-11-25 21:51 ` J. Bruce Fields
2007-11-25 22:42 ` Junio C Hamano
2007-11-25 23:08 ` J. Bruce Fields
2007-11-26 4:02 ` Nicolas Pitre
2007-11-26 4:15 ` J. Bruce Fields
2007-11-26 4:29 ` Nicolas Pitre
2007-11-26 4:45 ` J. Bruce Fields
2007-11-26 9:03 ` Jakub Narebski
2007-11-26 9:09 ` Andreas Ericsson
2007-11-26 19:11 ` Nicolas Pitre
2007-11-26 19:24 ` David Kastrup
2007-11-26 20:25 ` Nicolas Pitre
2007-11-26 20:40 ` Junio C Hamano
2007-11-26 20:45 ` David Kastrup
2007-11-26 21:09 ` Nicolas Pitre
2007-11-26 21:22 ` David Kastrup
2007-11-26 22:02 ` Nicolas Pitre
2007-11-26 23:05 ` David Kastrup
2007-11-26 23:28 ` Nicolas Pitre
2007-11-26 23:52 ` David Kastrup
2007-11-27 4:05 ` Nicolas Pitre
2007-12-05 21:58 ` Miles Bader
2007-11-26 21:14 ` Jakub Narebski
2007-11-26 21:36 ` Johannes Schindelin
2007-11-26 21:47 ` Nicolas Pitre
2007-11-26 6:15 ` Jan Hudec
2007-11-25 20:27 ` Junio C Hamano
2007-11-25 20:36 ` Jakub Narebski
2007-11-25 20:53 ` J. Bruce Fields
2007-12-01 2:37 ` Junio C Hamano
2007-12-01 8:55 ` Eric Wong
2007-12-02 14:14 ` [PATCH, next version] Add 'git fast-export', the sister of 'git fast-import' Johannes Schindelin
2007-12-02 14:40 ` What's cooking in git.git (topics) Johannes Schindelin
2007-12-04 8:43 ` Junio C Hamano
2007-12-04 9:40 ` Johannes Sixt
2007-12-04 10:08 ` msysGit on FAT32 (was: What's cooking in git.git (topics)) Jakub Narebski
2007-12-04 13:30 ` Johannes Schindelin
2007-12-04 13:48 ` msysGit on FAT32 Johannes Sixt
2007-12-04 14:37 ` Johannes Schindelin
2007-12-04 20:03 ` What's cooking in git.git (topics) Steffen Prohaska
2007-12-05 10:59 ` Junio C Hamano
2007-12-05 11:08 ` Jakub Narebski
2007-12-05 11:10 ` Jakub Narebski
2007-12-06 4:43 ` Jeff King
2007-12-05 11:37 ` [PATCH] Soft aliases: add "less" and minimal documentation Johannes Schindelin
2007-12-05 19:45 ` Junio C Hamano
2007-12-06 4:50 ` Jeff King
2007-12-06 4:32 ` What's cooking in git.git (topics) Jeff King
2007-12-07 9:51 ` Junio C Hamano
2007-12-07 11:11 ` Jakub Narebski
2007-12-07 19:29 ` Junio C Hamano
2007-12-07 21:36 ` Miklos Vajna
2007-12-09 10:27 ` Junio C Hamano
2007-12-13 2:48 ` Junio C Hamano
2007-12-13 3:22 ` Nicolas Pitre
2007-12-13 22:31 ` [PATCH 1/2] xdl_diff: identify call sites Junio C Hamano
2007-12-14 7:03 ` Junio C Hamano
2007-12-13 22:31 ` [PATCH 2/2] xdi_diff: trim common trailing lines Junio C Hamano
2007-12-14 9:06 ` Peter Baumann
2007-12-14 19:15 ` Junio C Hamano
2007-12-17 8:40 ` What's cooking in git.git (topics) Junio C Hamano
2007-12-23 9:20 ` Junio C Hamano
2007-12-31 10:47 ` checkout --push/--pop idea (Re: What's cooking in git.git (topics)) Jan Hudec
2008-01-05 11:01 ` What's cooking in git.git (topics) Junio C Hamano
2008-01-05 16:04 ` Johannes Schindelin
2008-01-22 8:47 ` What will be cooking in git.git post 1.5.4 (topics) Junio C Hamano
2007-12-04 16:18 ` What's cooking in git.git (topics) Brian Downing
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0711160036450.30886@racer.site \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=krh@redhat.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).