-
Notifications
You must be signed in to change notification settings - Fork 5
fix: resolve git fetch/pull returning stale refs #192
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -694,21 +694,35 @@ func (r *Repository) GetUpstreamRefs(ctx context.Context) (map[string]string, er | |
| return ParseGitRefs(output), nil | ||
| } | ||
|
|
||
| // repackTimeout bounds `git repack` so a slow repack on a large repository | ||
| // cannot block the scheduler queue indefinitely. | ||
| const repackTimeout = 10 * time.Minute | ||
|
|
||
| // Repack consolidates pack files using geometric repacking. Unlike a full | ||
| // repack (-a), geometric repacking only merges packs when there is significant | ||
| // fragmentation (many small packs), making it orders of magnitude faster on | ||
| // large repositories in steady state. The --write-midx and --write-bitmap-index | ||
| // flags maintain the multi-pack index and reachability bitmaps for efficient | ||
| // serving via git http-backend. | ||
| func (r *Repository) Repack(ctx context.Context) error { | ||
| r.mu.RLock() | ||
| defer r.mu.RUnlock() | ||
|
|
||
| logger := logging.FromContext(ctx) | ||
| logger.InfoContext(ctx, "Full repack started", "upstream", r.upstreamURL) | ||
| logger.InfoContext(ctx, "Geometric repack started", "upstream", r.upstreamURL) | ||
|
|
||
| repackCtx, cancel := context.WithTimeout(ctx, repackTimeout) | ||
| defer cancel() | ||
|
|
||
| // #nosec G204 - r.path is controlled by us | ||
| cmd := exec.CommandContext(ctx, "git", "-C", r.path, "repack", "-adb", "--write-midx", "--write-bitmap-index") | ||
| cmd := exec.CommandContext(repackCtx, "git", "-C", r.path, "repack", "-d", "--geometric=2", "--write-midx", "--write-bitmap-index") | ||
| cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} | ||
| cmd.Cancel = func() error { | ||
| return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this will be called always at the end (defer), but process might be already gone by then.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| output, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| return errors.Wrapf(err, "git repack: %s", string(output)) | ||
| } | ||
|
|
||
| logger.InfoContext(ctx, "Full repack completed", "upstream", r.upstreamURL) | ||
| logger.InfoContext(ctx, "Geometric repack completed", "upstream", r.upstreamURL) | ||
| return nil | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why locking is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git handles its own file locking during repack so this wasn't needed