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

[WIP]: Extend gitDownloader to support new cache structure #496

Conversation

Manoramsharma
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

fix #384

2. What is the scope of this PR (e.g. component or file name):

pkg/downloader/downloader.go
pkg/downloader/downloader_test.go
pkg/utils/utils.go

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

We already have completed CloneWithOpts to support bare cloning , in this PR I have extended the gitDownloader to clone the dependency as bare repo to the cache path.

// If caching is enabled, clone the repo as a bare repository to the cache.
if opts.EnableCache {
// Check if the bare repository already exists in the cache.
if utils.DirExists(opts.CachePath) {
Copy link
Contributor

@zong-zhe zong-zhe Oct 11, 2024

Choose a reason for hiding this comment

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

Hi @Manoramsharma 😄

are some logical issues here that need to be considered:

  1. Whether the bare repository exists.
  2. Whether the corresponding tag/commit/branch exists in the bare repository.

Only when both conditions are met, that the bare repository exists and that the corresponding tag/commit/branch exists in the repository will the cache be hit, and the corresponding content will be cloned from the cache. Your current if statement only considers the first condition. The second condition needs to be added.

And before going to the bare repository to look for dependencies, it can look directly in the download path and use them if they already exist.

if err != nil {
return err
// Now checkout the specific version (commit/tag/branch) from the bare repository.
checkoutPath := filepath.Join(opts.LocalPath, "git", "checkouts", fmt.Sprintf("%s-%s", filepath.Base(gitSource.Url), utils.GenerateHash(gitSource.Url)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @Manoramsharma 😄

The hash is not only used here, the path to the bare repo should also be a hash value.

kpm/git
├── checkouts.   # checkout the specific version of git repository from cache bare repository 
│   ├── kcl-2a81898195a215f1
│   │   └── 33bb450. . # All the version of kcl package from git repository will be replaced with commit id
│   ├── kcl-578669463c900b87
│   │   └── 33bb450
└── db    # A bare git repository for cache git repo
    ├── kcl-2a81898195a215f1.      # <NAME>-<HASH> <NAME> is the name of git repo, 
    ├── kcl-578669463c900b87.   # <HASH> is calculated by the git full url.

Add more details, the hashed paths are default paths, that is, the user has not specified localpath and cachepath in DownloadOptions, we use the hash value to compute a default path, and if the user specifies paths, we use the specified paths directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @zong-zhe can you help me with this one, how to use hash value to generate a default path? Currently I have covered only the part when the localpath and cachepath are defined by the user in DownloadOptions.

Where can I get the reference of using hash-value and genrate default storage path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This GenerateHash function I have added in the utils should I move forward with this one? OR you have thought something different with hash-value and default path generation

@zong-zhe zong-zhe closed this Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants