git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff Hostetler <git@jeffhostetler.com>
Cc: Jeff Hostetler <jeffhost@microsoft.com>,
	git@vger.kernel.org, peff@peff.net
Subject: Re: [PATCH v1 3/6] Per-file output for Porcelain Status V2
Date: Fri, 22 Jul 2016 10:01:10 -0700	[thread overview]
Message-ID: <xmqqinvxboa1.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <57911B5B.9090604@jeffhostetler.com> (Jeff Hostetler's message of "Thu, 21 Jul 2016 14:58:35 -0400")

Jeff Hostetler <git@jeffhostetler.com> writes:

>>> +	case DIFF_STATUS_DELETED:
>>> +		d->porcelain_v2.mode_index = p->one->mode;
>>> +		hashcpy(d->porcelain_v2.sha1_index, p->one->sha1);
>>> +		break;
>>> +
>>> +	case DIFF_STATUS_COPIED:
>>> +	case DIFF_STATUS_MODIFIED:
>>> +	case DIFF_STATUS_RENAMED:
>>
>> Can RENAMED or COPIED happen here?
>
> If we don't report renamed or copied for unstaged changes, then no.

The question was "do we report such cases"?

>>> +	if (!d->index_status) {
>>> +		if (d->worktree_status == DIFF_STATUS_MODIFIED ||
>>> +			d->worktree_status == DIFF_STATUS_DELETED) {
>>> +			/* X=' ' Y=[MD]
>>> +			 * The item did not change in head-vs-index scan so the head
>>> +			 * column was never set. (The index column was set during the
>>> +			 * index-vs-worktree scan.)
>>> +			 * Force set the head column to make the output complete.
>>> +			 */
>>> +			d->porcelain_v2.mode_head = d->porcelain_v2.mode_index;
>>> +			hashcpy(d->porcelain_v2.sha1_head, d->porcelain_v2.sha1_index);
>>> +		}
>>
>> Can there be "else" clause for this inner "if"?  When
>> d->index_status is not set, but worktree_status is not one of these
>> two, what does it indicate?  The same for the next one.
>
> For a normal entry (not unmerged) when X is ' ', Y can only
> be 'M' or 'D'.  The only other value for Y is ' ', but then if
> both were ' ' the entry would not be in the list.  So I think
> we're OK, but I'll document that here.  And below.

Good.

>>> +	memset(stages, 0, sizeof(stages));
>>> +	pos = cache_name_pos(it->string, strlen(it->string));
>>> +	assert(pos < 0);
>>> +	pos = -pos-1;
>>> +	while (pos < active_nr) {
>>> +		ce = active_cache[pos++];
>>> +		stage = ce_stage(ce);
>>> +		if (strcmp(ce->name, it->string) || !stage)
>>> +			break;
>>> +		stages[stage - 1].mode = ce->ce_mode;
>>> +		hashcpy(stages[stage - 1].sha1, ce->sha1);
>>> +	}
>>
>> You did assert(pos < 0) to make sure that the path the caller told
>> you is unmerged indeed is unmerged, which is a very good check.  In
>> the same spirit, you would want to make sure that you got at least
>> one result from the above loop, to diagnose a bug where the path did
>> not even exist at all in the index.
>
> Would that be possible for a conflict/unmerged entry?

It is possible to exactly the same degree as it is possible you
would get !(pos < 0) answer from cache_name_pos() here, I would
think.  The assert() you have up above is protecting us from either
a broken caller to this function that gives an it that points at a
merged path (in which case the assert is violated) or a breakage in
cache_name_pos().  Making sure the loop finds at least one unmerged
entry protects us from similar kind of breakage that violates the
expectation this code has from the other parts of the code.


Thanks.

  reply	other threads:[~2016-07-22 17:01 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-19 22:10 [PATCH v1 0/6] Porcelain Status V2 Jeff Hostetler
2016-07-19 22:10 ` [PATCH v1 1/6] Allow --porcelain[=<n>] in status and commit commands Jeff Hostetler
2016-07-20 15:08   ` Johannes Schindelin
2016-07-20 15:38     ` Jeff Hostetler
2016-07-21 14:28       ` Johannes Schindelin
2016-07-20 15:58   ` Jeff King
2016-07-20 17:26     ` Jeff Hostetler
2016-07-20 20:46   ` Junio C Hamano
2016-07-19 22:10 ` [PATCH v1 2/6] Status and checkout unit tests for --porcelain[=<n>] Jeff Hostetler
2016-07-20 15:19   ` Johannes Schindelin
2016-07-20 15:51     ` Jeff Hostetler
2016-07-20 16:00   ` Jeff King
2016-07-20 16:03     ` Jeff King
2016-07-20 17:31       ` Jeff Hostetler
2016-07-20 17:29     ` Jeff Hostetler
2016-07-19 22:10 ` [PATCH v1 3/6] Per-file output for Porcelain Status V2 Jeff Hostetler
2016-07-20 20:50   ` Junio C Hamano
2016-07-21 14:19     ` Johannes Schindelin
2016-07-20 21:31   ` Junio C Hamano
2016-07-21 18:58     ` Jeff Hostetler
2016-07-22 17:01       ` Junio C Hamano [this message]
2016-07-19 22:10 ` [PATCH v1 4/6] Expanded branch header " Jeff Hostetler
2016-07-20 16:06   ` Jeff King
2016-07-20 18:20     ` Jeff Hostetler
2016-07-20 20:54       ` Jeff King
2016-07-21 15:46         ` Johannes Schindelin
2016-07-21 19:03           ` Jeff Hostetler
2016-07-19 22:10 ` [PATCH v1 5/6] Add porcelain V2 documentation to status manpage Jeff Hostetler
2016-07-20 15:29   ` Jakub Narębski
2016-07-20 15:42     ` Jeff Hostetler
2016-07-20 15:55       ` Jakub Narębski
2016-07-20 21:50   ` Junio C Hamano
2016-07-19 22:10 ` [PATCH v1 6/6] Unit tests for V2 porcelain status Jeff Hostetler
2016-07-20 15:30   ` Jakub Narębski
2016-07-20 15:47     ` Jeff Hostetler
2016-07-20 16:01       ` Jakub Narębski
2016-07-21 15:54         ` Johannes Schindelin
2016-07-20 16:15 ` [PATCH v1 0/6] Porcelain Status V2 Jeff King
2016-07-20 19:27   ` Jeff Hostetler
2016-07-20 20:57     ` Jeff King
2016-07-21 16:02       ` Johannes Schindelin

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=xmqqinvxboa1.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@jeffhostetler.com \
    --cc=git@vger.kernel.org \
    --cc=jeffhost@microsoft.com \
    --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.
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).