Re: [PATCH 03/19] Ensure index matches head before invoking merge machinery, round N
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jul 26, 2019, 11:23 UTC
- Message-ID
- <nycvar.QRO.7.76.6.1907261323000.21907@tvgsbejvaqbjf.bet>
- In-Reply-To
- <CABPp-BHahUojy1+cBrOTCvg-w3n-xJp3yE3Br6v8jMwnMzQwCQ@mail.gmail.com>
Hi Elijah,
On Thu, 25 Jul 2019, Elijah Newren wrote:
Show 40 quoted lines
> On Thu, Jul 25, 2019 at 12:41 PM Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> >
> > On Thu, 25 Jul 2019, Elijah Newren wrote:
> >
> > > diff --git a/builtin/merge-recursive.c b/builtin/merge-recursive.c
> > > index 5b910e351e..a4bfd8fc51 100644
> > > --- a/builtin/merge-recursive.c
> > > +++ b/builtin/merge-recursive.c
> > > @@ -1,3 +1,4 @@
> > > +#include "cache.h"
> > > #include "builtin.h"
> > > #include "commit.h"
> > > #include "tag.h"
> > > @@ -63,6 +64,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
> > > if (argc - i != 3) /* "--" "<head>" "<remote>" */
> > > die(_("not handling anything other than two heads merge."));
> > >
> > > + if (repo_read_index_unmerged(the_repository))
> > > + die_resolve_conflict("merge");
> >
> > For a moment I was unsure whether `_unmerged()` is the right thing to do
> > here, as it specifically allows to read the index even when there are
> > conflict stages. But I guess it does not matter too much here. I
> > probably would have opted for `repo_read_index()` instead, though.
>
> The names repo_read_index() and repo_read_index_unmerged() actually
> seem slightly misleading to me; they seem to do the opposite of what
> you'd think they do.
>
> repo_read_index() reads in an index and allows unmerged entries and
> returns istate->cache_nr.
>
> repo_read_index_unmerged() calls repo_read_index(), then checks to see
> if any of the entries are unmerged and returns whether or not any
> unmerged entries were found.
>
> So, the way to disallow conflict stages isn't to use
> repo_read_index(), but to use repo_read_index_unmerged(), as I did.
> Counter-intuitive, I know.Whoa. No wonder I get it wrong all the time.
Thanks for educating me, Dscho