@@ -43,15 +43,13 @@ type RepositoryManager interface {
4343 Add (gitCtx GitContext , gitProviderId int , location , url string , authMode sql.AuthMode , sshPrivateKeyContent string ) error
4444 GetSshPrivateKeyPath (gitCtx GitContext , gitProviderId int , location , url string , authMode sql.AuthMode , sshPrivateKeyContent string ) (string , error )
4545 FetchRepo (gitCtx GitContext , location string ) error
46- GetLocationForMaterial (material * sql.GitMaterial , cloningMode string ) (location string , httpMatched bool , shMatched bool , err error )
47- GetCheckoutPathAndLocation (gitCtx GitContext , material * sql.GitMaterial , url string ) ( string , string , error )
46+ GetCheckoutLocationFromGitUrl (material * sql.GitMaterial , cloningMode string ) (location string , httpMatched bool , shMatched bool , err error )
47+ GetCheckoutLocation (gitCtx GitContext , material * sql.GitMaterial , url , checkoutPath string ) string
4848 TrimLastGitCommit (gitCommits []* GitCommitBase , count int ) []* GitCommitBase
4949 // Clean cleans a directory
5050 Clean (cloneDir string ) error
51- // ChangesSince given the checkput path, retrieves the latest commits for the gt repo existing on the path
52- ChangesSince (gitCtx GitContext , checkoutPath string , branch string , from string , to string , count int ) ([]* GitCommitBase , error )
5351 // ChangesSinceByRepository returns the latest commits list for the given range and count for an existing repo
54- ChangesSinceByRepository (gitCtx GitContext , repository * GitRepository , branch string , from string , to string , count int , checkoutPath string ) ([]* GitCommitBase , error )
52+ ChangesSinceByRepository (gitCtx GitContext , repository * GitRepository , branch string , from string , to string , count int , checkoutPath string , openNewGitRepo bool ) ([]* GitCommitBase , error )
5553 // GetCommitMetadata retrieves the commit metadata for given hash
5654 GetCommitMetadata (gitCtx GitContext , checkoutPath , commitHash string ) (* GitCommitBase , error )
5755 // GetCommitForTag retrieves the commit metadata for given tag
@@ -84,7 +82,7 @@ func (impl *RepositoryManagerImpl) IsSpaceAvailableOnDisk() bool {
8482 return availableSpace > int64 (impl .configuration .MinLimit )* 1024 * 1024
8583}
8684
87- func (impl * RepositoryManagerImpl ) GetLocationForMaterial (material * sql.GitMaterial , cloningMode string ) (location string , httpMatched bool , shMatched bool , err error ) {
85+ func (impl * RepositoryManagerImpl ) GetCheckoutLocationFromGitUrl (material * sql.GitMaterial , cloningMode string ) (location string , httpMatched bool , shMatched bool , err error ) {
8886 //gitRegex := `/(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/`
8987 httpsRegex := `^https.*`
9088 httpsMatched , err := regexp .MatchString (httpsRegex , material .Url )
@@ -104,15 +102,8 @@ func (impl *RepositoryManagerImpl) GetLocationForMaterial(material *sql.GitMater
104102 return "" , httpsMatched , sshMatched , fmt .Errorf ("unsupported format url %s" , material .Url )
105103}
106104
107- func (impl * RepositoryManagerImpl ) GetCheckoutPathAndLocation (gitCtx GitContext , material * sql.GitMaterial , url string ) (string , string , error ) {
108- var checkoutPath string
109- var checkoutLocationForFetching string
110- checkoutPath , _ , _ , err := impl .GetLocationForMaterial (material , gitCtx .CloningMode )
111- if err != nil {
112- return checkoutPath , checkoutLocationForFetching , err
113- }
114- checkoutLocationForFetching = checkoutPath
115- return checkoutPath , checkoutLocationForFetching , nil
105+ func (impl * RepositoryManagerImpl ) GetCheckoutLocation (gitCtx GitContext , material * sql.GitMaterial , url , checkoutPath string ) string {
106+ return checkoutPath
116107}
117108
118109func (impl * RepositoryManagerImpl ) Add (gitCtx GitContext , gitProviderId int , location , url string , authMode sql.AuthMode , sshPrivateKeyContent string ) error {
@@ -239,12 +230,23 @@ func (impl *RepositoryManagerImpl) GetCommitMetadata(gitCtx GitContext, checkout
239230
240231// from -> old commit
241232// to -> new commit
242- func (impl * RepositoryManagerImpl ) ChangesSinceByRepository (gitCtx GitContext , repository * GitRepository , branch string , from string , to string , count int , checkoutPath string ) ([]* GitCommitBase , error ) {
233+ func (impl * RepositoryManagerImpl ) ChangesSinceByRepository (gitCtx GitContext , repository * GitRepository , branch string , from string , to string , count int , checkoutPath string , openNewGitRepo bool ) ([]* GitCommitBase , error ) {
243234 // fix for azure devops (manual trigger webhook bases pipeline) :
244235 // branch name comes as 'refs/heads/master', we need to extract actual branch name out of it.
245236 // https://stackoverflow.com/questions/59956206/how-to-get-a-branch-name-with-a-slash-in-azure-devops
246237
247238 var err error
239+ if count == 0 {
240+ count = impl .configuration .GitHistoryCount
241+ }
242+
243+ if openNewGitRepo {
244+ repository , err = impl .gitManager .OpenRepoPlain (checkoutPath )
245+ if err != nil {
246+ return nil , err
247+ }
248+ }
249+
248250 start := time .Now ()
249251 defer func () {
250252 util .TriggerGitOperationMetrics ("changesSinceByRepository" , start , err )
@@ -332,25 +334,6 @@ func (impl *RepositoryManagerImpl) TrimLastGitCommit(gitCommits []*GitCommitBase
332334 return gitCommits
333335}
334336
335- func (impl * RepositoryManagerImpl ) ChangesSince (gitCtx GitContext , checkoutPath string , branch string , from string , to string , count int ) ([]* GitCommitBase , error ) {
336- var err error
337- start := time .Now ()
338- defer func () {
339- util .TriggerGitOperationMetrics ("changesSince" , start , err )
340- }()
341- if count == 0 {
342- count = impl .configuration .GitHistoryCount
343- }
344- r , err := impl .gitManager .OpenRepoPlain (checkoutPath )
345- if err != nil {
346- return nil , err
347- }
348- ///---------------------
349- return impl .ChangesSinceByRepository (gitCtx , r , branch , from , to , count , checkoutPath )
350- ///----------------------
351-
352- }
353-
354337func (impl * RepositoryManagerImpl ) CreateSshFileIfNotExistsAndConfigureSshCommand (gitCtx GitContext , location string , gitProviderId int , sshPrivateKeyContent string ) (string , error ) {
355338 // add private key
356339 var err error
0 commit comments