git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>, Thomas Rast <trast@inf.ethz.ch>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Michael Haggerty <mhagger@alum.mit.edu>
Subject: Re: [PATCH v2 05/16] blame: accept multiple -L ranges
Date: Tue, 6 Aug 2013 18:44:44 -0400	[thread overview]
Message-ID: <CAPig+cTHbV-ijfXNBn45v2opOH7Jh0A22QaxCeKhRBPA39xAwQ@mail.gmail.com> (raw)
In-Reply-To: <7v1u66fqrz.fsf@alter.siamese.dyndns.org>

On Tue, Aug 6, 2013 at 5:33 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> +     for (range_i = ranges.nr; range_i > 0; --range_i) {
>> +             const struct range *r = &ranges.ranges[range_i - 1];
>> +             long bottom = r->start;
>> +             long top = r->end;
>> +             struct blame_entry *next = ent;
>> +             ent = xcalloc(1, sizeof(*ent));
>> +             ent->lno = bottom;
>> +             ent->num_lines = top - bottom;
>> +             ent->suspect = o;
>> +             ent->s_lno = bottom;
>> +             ent->next = next;
>> +             if (next)
>> +                     next->prev = ent;
>> +             origin_incref(o);
>> +     }
>> +     origin_decref(o);
>
> Hmph, I do not see where the need for this decref is coming from.
> Did we incref once too many somewhere?

Each constructed blame_entry must own a reference to the suspect.
o->refcnt should equal the number of blame_entries. At construction, a
'struct origin' has refcnt 1. In the original code, which supported
only a single initial range (blame_entry), we had:

  o = get-initial-suspect();  # refcnt already 1
  ent->suspect = o;  # refcnt still 1
  sb.ent = ent;
  assign_blame(&sb);

So, o->refcnt equals the number of blame_entries (1) when
assign_blame() is called.

The new for-loop calls origin_incref() on each iteration since each
blame_entry needs to own a reference to the suspect. Assume that we
have two disjoint -L ranges:

  o = get-initial-suspect();  # refcnt already 1
  foreach range:
    ent = new blame_entry;
    ent->suspect = o;
    origin_incref(o);  # refcnt++
  end
  # for 2 ranges, refcnt incremented twice, so value is 3
  origin_decref(o);  # refcnt = 2
  sb.ent = ent;
  assign_blame(&sb);

Thus, as with the original code, o->refcnt equals the number of
blame_entries (2) when assign_blame() is called.

The same holds for the boundary case when the file is empty and there
is no range. o->refcnt starts at 1, the loop is never entered so no
blame_entries are created, and o->refcnt gets decremented to 0, which
again matches the number of blame_entries (0).

  reply	other threads:[~2013-08-06 22:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-06 13:59 [PATCH v2 00/16] blame: accept multiple -L ranges Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 01/16] git-log.txt: place each -L option variation on its own line Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 02/16] line-range-format.txt: clarify -L:regex usage form Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 03/16] range-set: publish API for re-use by git-blame -L Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 04/16] blame: inline one-line function into its lone caller Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 05/16] blame: accept multiple -L ranges Eric Sunshine
2013-08-06 21:33   ` Junio C Hamano
2013-08-06 22:44     ` Eric Sunshine [this message]
2013-08-06 22:47       ` Junio C Hamano
2013-08-06 13:59 ` [PATCH v2 06/16] t8001/t8002: blame: add tests of multiple -L options Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 07/16] blame: document multiple -L support Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 08/16] line-range: teach -L/RE/ to search relative to anchor point Eric Sunshine
2013-08-06 21:44   ` Junio C Hamano
2013-08-06 13:59 ` [PATCH v2 09/16] blame: teach -L/RE/ to search from end of previous -L range Eric Sunshine
2013-08-06 21:45   ` Junio C Hamano
2013-08-06 13:59 ` [PATCH v2 10/16] log: " Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 11/16] line-range-format.txt: document -L/RE/ relative search Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 12/16] line-range: teach -L^/RE/ to search from start of file Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 13/16] line-range: teach -L:RE to search from end of previous -L range Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 14/16] line-range: teach -L^:RE to search from start of file Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 15/16] t8001/t8002: blame: add tests of -L line numbers less than 1 Eric Sunshine
2013-08-06 13:59 ` [PATCH v2 16/16] line-range: reject " Eric Sunshine

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPig+cTHbV-ijfXNBn45v2opOH7Jh0A22QaxCeKhRBPA39xAwQ@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=mhagger@alum.mit.edu \
    --cc=trast@inf.ethz.ch \
    /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.
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 NNTP newsgroup(s).