Skip to content

Commit

Permalink
fix(gitextractor): update database store, set it incremental by defau…
Browse files Browse the repository at this point in the history
…lt (#7660)

* fix(gitextractor): update database store, set it incremental by default

* fix(gitextractor): add `SetIncrementalMode` to store

* style(gitextractor): fix ci errors
  • Loading branch information
d4x1 committed Jun 25, 2024
1 parent bf5c3e9 commit 12164c1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/plugins/gitextractor/models/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

type Store interface {
SetIncrementalMode(bool)
RepoCommits(repoCommit *code.RepoCommit) errors.Error
Commits(commit *code.Commit) errors.Error
Refs(ref *code.Ref) errors.Error
Expand Down
12 changes: 12 additions & 0 deletions backend/plugins/gitextractor/parser/clone_gitcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ type CloneRepoConfig struct {
NoShallowClone bool
}

func (g *GitcliCloner) IsIncremental() bool {
if g != nil && g.stateManager != nil {
if g.stateManager.GetSince() != nil {
return true
}
return g.stateManager.IsIncremental()
}

return false
}

func (g *GitcliCloner) CloneRepo(ctx plugin.SubTaskContext, localDir string) errors.Error {
taskData := ctx.GetData().(*GitExtractorTaskData)
var since *time.Time
Expand All @@ -75,6 +86,7 @@ func (g *GitcliCloner) CloneRepo(ctx plugin.SubTaskContext, localDir string) err
}
g.stateManager = stateManager
since = stateManager.GetSince()

}

cmd, err := g.buildCloneCommand(ctx, localDir, since)
Expand Down
2 changes: 1 addition & 1 deletion backend/plugins/gitextractor/parser/taskdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type GitExtractorTaskData struct {
Options *GitExtractorOptions
ParsedURL *url.URL
GitRepo RepoCollector
SkipAllSubtasks bool // siliently skip all tasks without raising error
SkipAllSubtasks bool // silently skip all tasks without raising errors
}

type GitExtractorApiParams struct {
Expand Down
3 changes: 3 additions & 0 deletions backend/plugins/gitextractor/store/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func NewCsvStore(dir string) (*CsvStore, errors.Error) {
return s, nil
}

func (c *CsvStore) SetIncrementalMode(incrementalMode bool) {
}

func (c *CsvStore) RepoCommits(repoCommit *code.RepoCommit) errors.Error {
return c.repoCommitWriter.Write(repoCommit)
}
Expand Down
5 changes: 5 additions & 0 deletions backend/plugins/gitextractor/store/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Database struct {
}

func NewDatabase(basicRes context.BasicRes, repoId string) *Database {

database := &Database{
table: "gitextractor",
params: repoId,
Expand All @@ -56,6 +57,10 @@ func (d *Database) updateRawDataFields(rawData *common.RawDataOrigin) {
rawData.RawDataParams = d.params
}

func (d *Database) SetIncrementalMode(incrementalMode bool) {
d.driver.SetIncrementalMode(incrementalMode)
}

func (d *Database) RepoCommits(repoCommit *code.RepoCommit) errors.Error {
batch, err := d.driver.ForType(reflect.TypeOf(repoCommit))
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion backend/plugins/gitextractor/tasks/repo_cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func CloneGitRepo(subTaskCtx plugin.SubTaskContext) errors.Error {
}
return err
}

if repoCloner.IsIncremental() {
storage.SetIncrementalMode(repoCloner.IsIncremental())
}
// We have done comparison experiments for git2go and go-git, and the results show that git2go has better performance.
var repoCollector parser.RepoCollector
if *taskData.Options.UseGoGit {
Expand Down

0 comments on commit 12164c1

Please sign in to comment.