All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patryk Obara <patryk.obara@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, Git List <git@vger.kernel.org>,
	Stefan Beller <sbeller@google.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: Re: [PATCH v3 4/4] commit: rewrite read_graft_line
Date: Fri, 18 Aug 2017 13:30:23 +0200	[thread overview]
Message-ID: <CAJfL8+SHSAhgrMY6ONVHLMWEHcT0mhm4oKMmq6D=89SErDKiMA@mail.gmail.com> (raw)
In-Reply-To: <xmqqziaxcobp.fsf@gitster.mtv.corp.google.com>

Jeff King <peff@peff.net> wrote:
>
> So we're probably fine. The two parsing passes are right next to each
> other and are sufficiently simple and strict that we don't have to
> worry about them diverging.

That was my conclusion as well. I added comment before the first pass and
avoided any "cleverness" to make it perfectly clear to a reader.

> We'd reject such an input totally (though as an interesting side effect,
> you can convince the parser to allocate 20x as much RAM as you send it;
> one oid for each space).

Grafts are not populated during clone operation, so it really would be user
making his life miserable. I could allocate FLEXI_ARRAY of size
min(n, line->len / (GIT_*MIN*_HEXSZ+1)) instead… but I think it's not even
worth the cost of making the code more complicated (and I don't want
to reintroduce these size macros in here.

We _could_ put an artificial limit on graft parents, though (e.g. 10) and
display an error message urging the user to stop using grafts?

> The single-pass alternative would probably be to read into a dynamic
> structure like an oid_array, and then copy the result into the flex
> structure.

Before sending v3 I tried two other alternative implementations (perhaps I
should've listed them in the v3 cover letter):

  1. Using string_list_split_in_place. I resigned from this approach as soon
     as I noticed, that line->buf needs to be preserved for possible
     error message. string_list_split would have no benefits over using
     oid_array.

  2. Parsing into temporary oid_array and then copying memory to FLEXI_ARRAY.
     Throw-away oid_array still needs to be cleaned, which means we have
     new/different return path (one before xmalloc and one after xmalloc),
     which means "bad_graft_data" label needs to be changed into "cleanup"
     label (or removed), which means error description needs be conditionally
     put in earlier code… and at this point, I decided these changes are not
     making code cleaner nor more readable at all :)

Junio C Hamano <gitster@pobox.com> wrote:
>
> If I were doing the two-pass thing, I'd probably write a for loop
> that runs exactly twice, where the first iteration parses into a
> single throw-away oid struct only to count, and the second iteration
> parses the same input into the allocated array of oid struct.  That
> way, you do not have to worry about two phrases going out of sync.

Two passes would still differ in error handling due to xmalloc between them…

-- 
| ← Ceci n'est pas une pipe
Patryk Obara

  reply	other threads:[~2017-08-18 11:30 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 11:49 [PATCH 0/5] Modernize read_graft_line implementation Patryk Obara
2017-08-15 11:49 ` [PATCH 1/5] cache: extend object_id size to sha3-256 Patryk Obara
2017-08-15 11:49 ` [PATCH 2/5] sha1_file: fix hardcoded size in null_sha1 Patryk Obara
2017-08-15 18:23   ` Junio C Hamano
2017-08-15 18:29     ` Stefan Beller
2017-08-15 19:02       ` Junio C Hamano
2017-08-16 12:11         ` Patryk Obara
2017-08-16 19:32           ` Junio C Hamano
2017-08-15 11:49 ` [PATCH 3/5] commit: replace the raw buffer with strbuf in read_graft_line Patryk Obara
2017-08-15 17:02   ` Stefan Beller
2017-08-16 12:24     ` Patryk Obara
2017-08-16 22:59       ` brian m. carlson
2017-08-17  5:55         ` Jeff King
2017-08-17 21:17           ` Junio C Hamano
2017-08-17 21:38             ` Patryk Obara
2017-08-15 18:25   ` Junio C Hamano
2017-08-15 11:49 ` [PATCH 4/5] commit: implement free_commit_graft Patryk Obara
2017-08-15 17:04   ` Stefan Beller
2017-08-15 18:26   ` Junio C Hamano
2017-08-16 12:28     ` Patryk Obara
2017-08-15 11:49 ` [PATCH 5/5] commit: rewrite read_graft_line Patryk Obara
2017-08-15 17:11   ` Stefan Beller
2017-08-15 18:30   ` Junio C Hamano
2017-08-16 13:07     ` Patryk Obara
2017-08-16 19:39       ` Junio C Hamano
2017-08-15 17:19 ` [PATCH 0/5] Modernize read_graft_line implementation Stefan Beller
2017-08-16 17:58 ` [PATCH v2 0/4] " Patryk Obara
2017-08-16 17:58   ` [PATCH v2 1/4] sha1_file: fix hardcoded size in null_sha1 Patryk Obara
2017-08-16 19:46     ` Junio C Hamano
2017-08-16 17:58   ` [PATCH v2 2/4] commit: replace the raw buffer with strbuf in read_graft_line Patryk Obara
2017-08-16 17:58   ` [PATCH v2 3/4] commit: implement free_commit_graft Patryk Obara
2017-08-16 17:58   ` [PATCH v2 4/4] commit: rewrite read_graft_line Patryk Obara
2017-08-17 21:20     ` Junio C Hamano
2017-08-17 21:42       ` Patryk Obara
2017-08-18  1:59   ` [PATCH v3 0/4] Modernize read_graft_line implementation Patryk Obara
2017-08-18  1:59     ` [PATCH v3 1/4] sha1_file: fix definition of null_sha1 Patryk Obara
2017-08-18  1:59     ` [PATCH v3 2/4] commit: replace the raw buffer with strbuf in read_graft_line Patryk Obara
2017-08-18  6:29       ` Jeff King
2017-08-18 10:12         ` Patryk Obara
2017-08-18 11:50           ` Jeff King
2017-08-18  1:59     ` [PATCH v3 3/4] commit: allocate array using object_id size Patryk Obara
2017-08-18  1:59     ` [PATCH v3 4/4] commit: rewrite read_graft_line Patryk Obara
2017-08-18  6:43       ` Jeff King
2017-08-18  7:44         ` Junio C Hamano
2017-08-18 11:30           ` Patryk Obara [this message]
2017-08-18 11:45             ` Jeff King
2017-08-18 16:44             ` Junio C Hamano
2017-08-18 17:05               ` Patryk Obara
2017-08-18 18:29                 ` Junio C Hamano
2017-08-18  2:20     ` [PATCH v3 0/4] Modernize read_graft_line implementation Junio C Hamano
2017-08-18 18:33     ` [PATCH v4 " Patryk Obara
2017-08-18 18:33       ` [PATCH v4 1/4] sha1_file: fix definition of null_sha1 Patryk Obara
2017-08-18 18:33       ` [PATCH v4 2/4] commit: replace the raw buffer with strbuf in read_graft_line Patryk Obara
2017-08-18 18:33       ` [PATCH v4 3/4] commit: allocate array using object_id size Patryk Obara
2017-08-18 18:33       ` [PATCH v4 4/4] commit: rewrite read_graft_line Patryk Obara
2017-08-18 18:38         ` Patryk Obara
2017-08-18 19:12           ` Junio C Hamano
2017-08-18 19:33             ` Patryk Obara
2017-08-18 19:47           ` Junio C Hamano

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='CAJfL8+SHSAhgrMY6ONVHLMWEHcT0mhm4oKMmq6D=89SErDKiMA@mail.gmail.com' \
    --to=patryk.obara@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=sandals@crustytoothpaste.net \
    --cc=sbeller@google.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.