Skip to content

Write directly to the ODB when possible #724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 30, 2014
Merged

Write directly to the ODB when possible #724

merged 4 commits into from
May 30, 2014

Conversation

carlosmn
Copy link
Member

While trying to get rid of the uglyness that is git_blob_create_fromchunks(), I realised we can do it bit by bit, so here's the first bit.

If we're given no path (and thus cannot do any filtering) and a size, we know that we can stream the data directly into the database, so let's do that with a git_odb_stream.

This brought up the fact that we expect a short read to succeed, which is only possible because fromchunks waits for an EOF signal from us, which we can simply pass along from Stream.Read(). Trying to keep this behaviour would make it impossible to optimise anything, and it also seems like a great place to introduce subtle bugs, so I've changed the tests to reflect that we need to read that amount of bytes.

This however is still the behaviour for the case when we have a path, since that needs filtering and thus must still rely on fromchunks. This however means that the place where we would raise the exception is beyond a C wall, so that probably wouldn't work without storing the exception somewhere.

[Theory]
[InlineData(16, 32)]
[InlineData(7854, 9785)]
public void CreatingABlobTooShortAStreamThrows(int contentSize, int numberOfBytesToConsume)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreatingABlob From TooShortAStreamThrows?

@nulltoken nulltoken added this to the v0.18.0 milestone May 29, 2014
@nulltoken
Copy link
Member

Rebased. Ok to merge?

@@ -148,7 +155,8 @@ public int Provider(IntPtr content, int max_length, IntPtr data)
}

/// <summary>
/// Inserts a <see cref="Blob"/> into the object database, created from the content of a data provider.
/// Inserts a <see cref="Blob"/> into the object database, created from the content of a stream.
/// <para>Optionally, git filters will be applied to the content prior it's stored.</para>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a word missing here. Either "prior to being stored" or "before storing it" or something work work.

nulltoken and others added 4 commits May 30, 2014 18:36
ObjectDatabase.CreateBlob() accepts a number of bytes to read. It
currently however treats this as a max, rather than a hard size, which
seems ripe for introducing bugs.

Assert that we should throw when asked to read too much from a Stream.
When given a size and no path, we know that we do not need to buffer the
content or apply any filters, so we can create an write-stream into the
object database and put in our content directly, avoiding the temporary
file and callbacks altogether.
@nulltoken nulltoken merged commit f65af84 into vNext May 30, 2014
@nulltoken nulltoken deleted the cmn/write-stream branch May 30, 2014 17:00
@nulltoken
Copy link
Member

💥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants