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

Add pre-cloning-hook for mirror-prepolulation #66

Merged
merged 4 commits into from
Feb 22, 2024

Conversation

polac24
Copy link
Collaborator

@polac24 polac24 commented Feb 15, 2024

Introducing a new parameter (--pre-clone-hook) that is called before cloning a repo to the mirror.
This feature gives users the opportunity to prepopulate git's mirror from a different source.

Before merging:

  • validate if the attempt number is incremented (set to 1+) if a git inconsistency happens is recognized at the beginning of the git-fastclone flow. ie. provide a way to indicate if the hook was already triggered in a previous attempt.

@polac24 polac24 force-pushed the bartosz/20240214-pre-clean-clone branch 2 times, most recently from eaeb27b to c7fd460 Compare February 15, 2024 19:48
@polac24 polac24 force-pushed the bartosz/20240214-pre-clean-clone branch from c7fd460 to 02fb622 Compare February 15, 2024 19:49
@polac24 polac24 marked this pull request as ready for review February 15, 2024 19:57
@polac24 polac24 marked this pull request as draft February 15, 2024 20:59
private def trigger_pre_clone_hook(url, mirror, attempt_number)
return if Dir.exist?(mirror) || !options.include?(:pre_clone_hook)

popen2e_wrapper(options[:pre_clone_hook], url, mirror, attempt_number.to_s, quiet: !verbose)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to stringify the url and mirror params as well? I see are doing that above on the clone operation. If we know they'll be strings, then this is better, but I wanted to check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I can do that but I checked that in runtime and url and mirror are strings already.

end
end

# Creates or updates the mirror repo then stores an indication
# that this repo has been updated on this run of fastclone
def store_updated_repo(url, mirror, repo_name, fail_hard)
def store_updated_repo(url, mirror, repo_name, fail_hard, attempt_number)
trigger_pre_clone_hook(url, mirror, attempt_number)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might want to disambiguate which clone operation we're referring to. e.g. trigger_pre_mirror_clone_hook? Should we only call this when we think the clone might actually be called next (e.g. within the unless block)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you think that would be better, let me do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually not: now I remember why did I change that logic to a separate method:

lib/git-fastclone.rb:358:5: C: Metrics/CyclomaticComplexity: Cyclomatic complexity for store_updated_repo is too high. [8/7]

I need to revert that to the previous approach

private def trigger_pre_clone_hook(url, mirror, attempt_number)
return if Dir.exist?(mirror) || !options.include?(:pre_clone_hook)

popen2e_wrapper(options[:pre_clone_hook], url, mirror, attempt_number.to_s, quiet: !verbose)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I can do that but I checked that in runtime and url and mirror are strings already.

end
end

# Creates or updates the mirror repo then stores an indication
# that this repo has been updated on this run of fastclone
def store_updated_repo(url, mirror, repo_name, fail_hard)
def store_updated_repo(url, mirror, repo_name, fail_hard, attempt_number)
trigger_pre_clone_hook(url, mirror, attempt_number)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you think that would be better, let me do that.

lib/git-fastclone.rb Outdated Show resolved Hide resolved
lib/git-fastclone.rb Outdated Show resolved Hide resolved
lib/git-fastclone.rb Show resolved Hide resolved
Styling changes to invoking pre-clone-hook.
@polac24 polac24 marked this pull request as ready for review February 21, 2024 15:25
lib/git-fastclone.rb Outdated Show resolved Hide resolved
@polac24 polac24 merged commit 55adc9f into square:master Feb 22, 2024
5 checks passed
@polac24 polac24 deleted the bartosz/20240214-pre-clean-clone branch February 22, 2024 23:10
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