Skip to content
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

Automatically create shared-cache directory if necessary #206

Conversation

jeffhostetler
Copy link
Collaborator

Teach git to create the shared-cache directory named in gvfs.sharedCache
if it does not exist on disk. Additionally, create it as an in-memory alternate
if it not listed in .git/objects/info/alternates.

Most of this code runs in git_default_config() and prepare_alt_odb(), so all
Git commands should properly handle shared-caches and gvfs.sharedCache
-- whether the directory is listed as an alternate or not.

As an additional safety net, the code in gvfs-helper-client.c passes a shared-cache
argument to gvfs-helper. This lets gvfs-helper use exactly the shared-cache
directory expected by the client.

This latter step may not be necessary, since git.exe clients spawn the helper as
git.exe gvfs-helper (rather than git-gvfs-helper.exe) and this form allows
git.exe -c gvfs.sharedcache=/path/to/shared/cache gvfs-helper ....

Copy link
Member

@wilbaker wilbaker left a comment

Choose a reason for hiding this comment

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

Just a few questions on the changes.

*
* See GIT_ALTERNATE_OBJECT_DIRECTORIES for another example
* of this kind of usage.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I think this change is a good one, I'm having trouble thinking of a scenario where we'd have gvfs.sharedCache set and not want git to treat it as an alternate.

Force this directory into the odb-list as an in-memory alternate.

With this change does it still makes sense for us to put gvfs.sharedCache in the alternates file when cloning? Or can/should we rely on git always treating the shared cache location as an alternate?

cc: @derrickstolee for his thoughts as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

While this change makes it not completely necessary to have the shared cache in the alternates file, it is still important to put it there, if only for interoperability with other tools or Git versions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the proper thing to do is to put it into .git/objects/info/alternates during our setup, so that everything
in the Git ecosystem understands that it exists. This is a backstop to try to keep us from falling back to
.git/objects (and to force the creation of the directory).

I debated updating the .git/objects/info/alternates on disk to completely fix the mis-match, but
chickened out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated the comment block to indicate that the don't want to rely on this behavior.

gvfs-helper.c Show resolved Hide resolved
* alt_odb_usable() nulls this if it cannot create the
* directory on disk, so fallback to the previous choice
* if this one failed.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I'm having some trouble following how the code manages the lifetime of gvfs_shared_cache_pathname.

It looks like alt_odb_usable will not free gvfs_shared_cache_pathname before setting it to NULL. Should it be freed first? (I'm wondering if we might be leaking the memory returned by strbuf_detach)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, i was ok with leaking it. i originally created the variable as a const (there were times when it was just set to something from argv during early iterations, rather than privately copying it). And i wasn't sure it was worth the bother to refactor that.

I'll take another look and see if i can tidy it up a bit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I converted the global var to a strbuf which better lets me manage the underlying string (and simplified a few things too).

We will leak the final value of the string at exit() but lots of things do that.

gvfs-helper-client.c Show resolved Hide resolved
sha1-file.c Show resolved Hide resolved
Copy link
Collaborator

@derrickstolee derrickstolee left a comment

Choose a reason for hiding this comment

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

I've got successful builds in the C# layer, so I approve with the existing suggestions from @dscho and @wilbaker.

@microsoft microsoft deleted a comment from derrickstolee Oct 8, 2019
Remove unnecessary includes from gvfs-helper-client.c.

An earlier WIP draft of this commit included additional functionality
that was removed before final publication.  In particular, it included
code to do a custom object traversal and the additional header files
were necessary.  When I removed that functionality, I forgot to remove
the additional headers.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
gvfs-helper-client.c Outdated Show resolved Hide resolved
The config variable `gvfs.sharedCache` contains the pathname to an alternate
<odb> that will be used by `gvfs-helper` to store dynamically-fetched missing
objects.  If this directory does not exist on disk, `prepare_alt_odb()` omits
this directory from the in-memory list of alternates.  This causes `git`
commands (and `gvfs-helper` in particular) to fall-back to `.git/objects` for
storage of these objects.  This disables the shared-cache and leads to poorer
performance.

Teach `alt_obj_usable()` and `prepare_alt_odb()`, match up the directory
named in `gvfs.sharedCache` with an entry in `.git/objects/info/alternates`
and force-create the `<odb>` root directory (and the associated `<odb>/pack`
directory) if necessary.

If the value of `gvfs.sharedCache` refers to a directory that is NOT listed
as an alternate, create an in-memory alternate entry in the odb-list.  (This
is similar to how GIT_ALTERNATE_OBJECT_DIRECTORIES works.)

This work happens the first time that `prepare_alt_odb()` is called.

Furthermore, teach the `--shared-cache=<odb>` command line option in
`gvfs-helper` (which is runs after the first call to `prepare_alt_odb()`)
to override the inherited shared-cache (and again, create the ODB directory
if necessary).

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
@jeffhostetler jeffhostetler force-pushed the users/jeffhost/auto-create-shared-cache branch from 09a9ff7 to 205244f Compare October 8, 2019 16:47
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
…or clarity

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Add trace2 message for CURL and HTTP errors.

Fix typo reporting network error code back to gvfs-helper-client.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Fix parsing of the "loose <odb>" response from `gvfs-helper` and
use the actually parsed OID when updating the loose oid cache.

Previously, an uninitialized "struct oid" was used to update
the cache.  This did not cause any corruption, but could cause
extra fetches for objects visited multiple times.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
@jeffhostetler
Copy link
Collaborator Author

This patch series now also includes a couple of bug fixes.
[] "... better handling of network errors ..."
[] "... properly update loose cache ..."

I also included trace2 messages for network errors.

@jeffhostetler jeffhostetler merged commit 1174dc2 into microsoft:features/sparse-checkout-2.23.0 Oct 9, 2019
derrickstolee added a commit to microsoft/scalar that referenced this pull request Oct 9, 2019
See microsoft/git#206 and microsoft/git#207 for the Git updates.

Un-ignore a functional test now that Git is doing the right thing.

Resolves #147
derrickstolee pushed a commit that referenced this pull request Jun 1, 2020
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
derrickstolee pushed a commit that referenced this pull request Jul 20, 2020
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
derrickstolee pushed a commit that referenced this pull request Jul 27, 2020
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
derrickstolee pushed a commit that referenced this pull request Jul 28, 2020
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
derrickstolee pushed a commit that referenced this pull request Oct 6, 2020
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
derrickstolee pushed a commit that referenced this pull request Mar 2, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
derrickstolee pushed a commit that referenced this pull request Mar 8, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Mar 14, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
derrickstolee pushed a commit that referenced this pull request Apr 25, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
vdye pushed a commit that referenced this pull request May 17, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
vdye pushed a commit that referenced this pull request May 17, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
vdye pushed a commit that referenced this pull request May 17, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
vdye pushed a commit that referenced this pull request May 20, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
vdye pushed a commit that referenced this pull request May 25, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
vdye pushed a commit that referenced this pull request Jun 1, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Jul 7, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
vdye pushed a commit that referenced this pull request Jul 19, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Aug 8, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Aug 8, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Aug 11, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
jeffhostetler added a commit that referenced this pull request Aug 23, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Nov 3, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Nov 3, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Nov 3, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Nov 8, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Nov 14, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Nov 20, 2023
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
vdye pushed a commit that referenced this pull request Feb 27, 2024
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Apr 23, 2024
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Apr 23, 2024
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Apr 23, 2024
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Apr 24, 2024
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request Apr 29, 2024
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request May 14, 2024
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
dscho pushed a commit that referenced this pull request May 14, 2024
Includes commits from these pull requests:

	#191
	#205
	#206
	#207
	#208
	#215
	#220
	#221

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
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.

None yet

5 participants