git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Christian Couder <christian.couder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git <git@vger.kernel.org>, "Jeff King" <peff@peff.net>,
	"Ævar Arnfjörð" <avarab@gmail.com>,
	"Karsten Blees" <karsten.blees@gmail.com>,
	"Nguyen Thai Ngoc Duy" <pclouds@gmail.com>,
	"Stefan Beller" <sbeller@google.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Ramsay Jones" <ramsay@ramsayjones.plus.com>,
	"Johannes Sixt" <j6t@kdbg.org>, "René Scharfe" <l.s.r@web.de>,
	"Stefan Naewe" <stefan.naewe@atlas-elektronik.com>,
	"Christian Couder" <chriscool@tuxfamily.org>
Subject: Re: [PATCH v12 12/13] apply: learn to use a different index file
Date: Sat, 27 Aug 2016 01:46:24 +0200	[thread overview]
Message-ID: <CAP8UFD0UxpRbbBeONETjMmdAeA64NoHXc+eAjasYQSCuc5=EyQ@mail.gmail.com> (raw)
In-Reply-To: <xmqqvaz7ys9u.fsf@gitster.mtv.corp.google.com>

On Thu, Aug 11, 2016 at 10:17 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Christian Couder <christian.couder@gmail.com> writes:
>
>> Sometimes we want to apply in a different index file.
>>
>> Before the apply functionality was libified it was possible to
>> use the GIT_INDEX_FILE environment variable, for this purpose.
>>
>> But now, as the apply functionality has been libified, it should
>> be possible to do that in a libified way.
>>
>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
>> ---
>>  apply.c | 10 ++++++++--
>>  apply.h |  1 +
>>  2 files changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/apply.c b/apply.c
>> index 2ec2a8a..7e561a4 100644
>> --- a/apply.c
>> +++ b/apply.c
>> @@ -4674,8 +4674,14 @@ static int apply_patch(struct apply_state *state,
>>               state->apply = 0;
>>
>>       state->update_index = state->check_index && state->apply;
>> -     if (state->update_index && state->newfd < 0)
>> -             state->newfd = hold_locked_index(state->lock_file, 1);
>> +     if (state->update_index && state->newfd < 0) {
>> +             if (state->index_file)
>> +                     state->newfd = hold_lock_file_for_update(state->lock_file,
>> +                                                              state->index_file,
>> +                                                              LOCK_DIE_ON_ERROR);
>> +             else
>> +                     state->newfd = hold_locked_index(state->lock_file, 1);
>> +     }
>>
>>       if (state->check_index && read_cache() < 0) {
>>               error(_("unable to read index file"));
>
> Here is a call to read_cache() that reads the default index file on
> the filesystem into the default in-core index "the_index".
>
> Shouldn't it be reading from state->index_file instead?

Yes, it should.

> If we limit the review only to the context of your series, I think
>
>     fall_back_threeway()
>      -> build_fake_ancestor() -- uses index_path to use custom index
>      -> discard_cache()
>      -> read_cache_from(index_path) -- reads back the fake ancestor
>      -> write_index_as_tree() -- writes the fake_ancestor
>      -> run_apply(index_path)
>         -> apply_all_patches()
>            -> apply_patch()
>
> is the only codepath that uses a custom index file, so when the
> control reaches this function with a custom index file, the in-core
> index is already populated, making read_cache() a no-op, and that is
> the only thing that makes the resulting code avoid triggering this
> bug, but as part of a general "libified" codepath,

Yeah, I agree with this reasoning.

> I think it should
> be made to read from state->index_file using read_cache_from().

Yeah, I will change it.

> I only noticed this call to read_cache(), but there may be others
> lurking nearby.

Yeah, there is another one in get_current_sha1() which is only called
by build_fake_ancestor() (from apply.c not from builtin/am.c as there
is a function with this name in both files), but this function is
currently called only when --build-fake-ancestor is passed which is
not the case in run_apply() in am.c. I will change it too.

Thanks,
Christian.

  reply	other threads:[~2016-08-26 23:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-11 18:44 [PATCH v12 00/13] libify apply and use lib in am, part 3 Christian Couder
2016-08-11 18:44 ` [PATCH v12 01/13] builtin/apply: rename option parsing functions Christian Couder
2016-08-11 18:44 ` [PATCH v12 02/13] apply: rename and move opt constants to apply.h Christian Couder
2016-08-11 18:44 ` [PATCH v12 04/13] apply: make some parsing functions static again Christian Couder
2016-08-11 18:44 ` [PATCH v12 05/13] apply: use error_errno() where possible Christian Couder
2016-08-11 18:44 ` [PATCH v12 06/13] apply: make it possible to silently apply Christian Couder
2016-08-11 18:44 ` [PATCH v12 07/13] apply: don't print on stdout in verbosity_silent mode Christian Couder
2016-08-11 18:44 ` [PATCH v12 08/13] usage: add set_warn_routine() Christian Couder
2016-08-11 18:44 ` [PATCH v12 09/13] usage: add get_error_routine() and get_warn_routine() Christian Couder
2016-08-11 18:44 ` [PATCH v12 10/13] apply: change error_routine when silent Christian Couder
2016-08-11 18:44 ` [PATCH v12 11/13] apply: refactor `git apply` option parsing Christian Couder
2016-08-11 18:45 ` [PATCH v12 12/13] apply: learn to use a different index file Christian Couder
2016-08-11 20:17   ` Junio C Hamano
2016-08-26 23:46     ` Christian Couder [this message]
2016-08-11 18:45 ` [PATCH v12 13/13] builtin/am: use apply API in run_apply() Christian Couder

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='CAP8UFD0UxpRbbBeONETjMmdAeA64NoHXc+eAjasYQSCuc5=EyQ@mail.gmail.com' \
    --to=christian.couder@gmail.com \
    --cc=avarab@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=karsten.blees@gmail.com \
    --cc=l.s.r@web.de \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=sbeller@google.com \
    --cc=stefan.naewe@atlas-elektronik.com \
    --cc=sunshine@sunshineco.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).