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

fetch: enable deepening/shortening shallow clones #6662

Merged
merged 1 commit into from
Dec 14, 2023
Merged

fetch: enable deepening/shortening shallow clones #6662

merged 1 commit into from
Dec 14, 2023

Conversation

kempniu
Copy link
Contributor

@kempniu kempniu commented Dec 6, 2023

A shallow repository can currently only be completely unshallowed, which is caused by mark_local() only marking locally-existing objects as wanted if the fetch depth is set to INT_MAX (GIT_FETCH_DEPTH_UNSHALLOW). This prevents deepening the history of a shallow clone to an arbitrary number of commits, which may be preferable over full unshallowing for large repositories.

Enable deepening and shortening shallow clones by marking locally-existing objects as wanted whenever the fetch depth is set to any non-default value (either GIT_FETCH_DEPTH_UNSHALLOW or an arbitrary positive integer).

A shallow repository can currently only be completely unshallowed, which
is caused by mark_local() only marking locally-existing objects as
wanted if the fetch depth is set to INT_MAX (GIT_FETCH_DEPTH_UNSHALLOW).
This prevents deepening the history of a shallow clone to an arbitrary
number of commits, which may be preferable over full unshallowing for
large repositories.

Enable deepening and shortening shallow clones by marking
locally-existing objects as wanted whenever the fetch depth is set to
any non-default value (either GIT_FETCH_DEPTH_UNSHALLOW or an arbitrary
positive integer).
git_repository_free(repo);
}

void test_online_shallow__shorten_four(void)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
void test_online_shallow__shorten_four(void)
void test_online_shallow__shorten_five(void)

It looks like this actually deepens five not four?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both test_online_shallow__deepen_six() and test_online_shallow__shorten_four() start by cloning the test repository with a depth of 5 (clone_opts.fetch_opts.depth = 5;).

test_online_shallow__deepen_six() then fetches from the repository again, but with a depth of 6 (fetch_opts.depth = 6;), to demonstrate that libgit2 is able to make a shallow history deeper.

test_online_shallow__shorten_four(), which you called out in your comment, performs the post-cloning fetch with a depth of 4 (fetch_opts.depth = 4;), to demonstrate that libgit2 is also able to make a shallow history shorter.

Does this help?

Copy link
Member

Choose a reason for hiding this comment

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

Oops. 😓 Yes, sorry, I misread that.

@ethomson
Copy link
Member

Thanks for the fix! Sorry for the delay, I had to read the surrounding comment a few times to remember how this all works. 😅

One minor question about the name of the test - otherwise looks great.

@ethomson ethomson merged commit a52685f into libgit2:main Dec 14, 2023
25 of 26 checks passed
@ethomson
Copy link
Member

Thanks @kempniu !

@kempniu kempniu deleted the enable-deepening-and-shortening-shallow-clones branch December 14, 2023 10:51
@ethomson ethomson added the bug label Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants