@@ -56,6 +56,10 @@ func NewGitStorage(path string) (*GitStorage, error) {
5656	return  storage , nil 
5757}
5858
59+ func  (s  * GitStorage ) GC () error  {
60+ 	return  s .execGit ("gc" )
61+ }
62+ 
5963// handle handles different operations on git 
6064func  (s  * GitStorage ) handle (timestamp  time.Time , gvr  schema.GroupVersionResource , oldObj , obj  * unstructured.Unstructured , delete  bool ) {
6165	filePath , content , err  :=  decodeUnstructuredObject (gvr , obj )
@@ -102,7 +106,7 @@ func (s *GitStorage) handle(timestamp time.Time, gvr schema.GroupVersionResource
102106	klog .Infof ("Calling write for %s" , filePath )
103107	operation , err  :=  s .write (filePath , content )
104108	if  err  !=  nil  {
105- 		klog .Warningf ("Writing file content failed %q: %v" , filePath , err )
109+ 		klog .Errorf ("Writing file content failed %q: %v" , filePath , err )
106110		return 
107111	}
108112
@@ -219,12 +223,15 @@ func resourceFilename(gvr schema.GroupVersionResource, namespace, name string) s
219223	return  filepath .Join ("namespaces" , namespace , groupStr , gvr .Resource , name + ".yaml" )
220224}
221225
222- func  (s  * GitStorage ) exec (command  string , args  ... string ) error  {
223- 	osCommand  :=  exec .Command (command , args ... )
226+ func  (s  * GitStorage ) execGit (args  ... string ) error  {
227+ 	// Disable automatic garbage collection to avoid racing with other processes. 
228+ 	args  =  append ([]string {"-c" , "gc.auto=0" }, args ... )
229+ 
230+ 	osCommand  :=  exec .Command ("git" , args ... )
224231	osCommand .Dir  =  s .path 
225232	output , err  :=  osCommand .CombinedOutput ()
226233	if  err  !=  nil  {
227- 		klog .Errorf ("Ran %s  %v\n %v\n \n " ,  command , args , string (output ))
234+ 		klog .Errorf ("Ran git  %v\n %v\n \n " , args , string (output ))
228235		return  err 
229236	}
230237	return  nil 
@@ -234,11 +241,11 @@ func (s *GitStorage) commit(timestamp time.Time, path, author, commitMessage str
234241	authorString  :=  fmt .
Sprintf (
"%s <[email protected] >" , 
author )
 235242	dateString  :=  timestamp .Format (time .RFC3339 )
236243
237- 	return  s .exec ( "git" ,  "commit" , "--author" , authorString , "--date" , dateString , "-m" , commitMessage )
244+ 	return  s .execGit ( "commit" , "--author" , authorString , "--date" , dateString , "-m" , commitMessage )
238245}
239246
240247func  (s  * GitStorage ) commitAdd (timestamp  time.Time , path , author , ocCommand  string ) error  {
241- 	if  err  :=  s .exec ( "git" ,  "add" , path ); err  !=  nil  {
248+ 	if  err  :=  s .execGit ( "add" , path ); err  !=  nil  {
242249		return  err 
243250	}
244251
@@ -252,7 +259,7 @@ func (s *GitStorage) commitAdd(timestamp time.Time, path, author, ocCommand stri
252259}
253260
254261func  (s  * GitStorage ) commitModify (timestamp  time.Time , path , author , ocCommand  string ) error  {
255- 	if  err  :=  s .exec ( "git" ,  "add" , path ); err  !=  nil  {
262+ 	if  err  :=  s .execGit ( "add" , path ); err  !=  nil  {
256263		return  err 
257264	}
258265
@@ -266,7 +273,7 @@ func (s *GitStorage) commitModify(timestamp time.Time, path, author, ocCommand s
266273}
267274
268275func  (s  * GitStorage ) commitRemove (timestamp  time.Time , path , author , ocCommand  string ) error  {
269- 	if  err  :=  s .exec ( "git" ,  "rm" , path ); err  !=  nil  {
276+ 	if  err  :=  s .execGit ( "rm" , path ); err  !=  nil  {
270277		return  err 
271278	}
272279
0 commit comments