@@ -461,11 +461,11 @@ func (gd *GenericDownloader) Checkout(repoDir string, commit string) error {
461461 return err
462462}
463463
464- func ( gd * GenericDownloader ) ApplyPatches ( repoDir string , patches [] string ) error {
464+ func ApplyPatch ( repoDir string , patch string ) error {
465465 cmd := []string {
466466 "am" ,
467467 }
468- cmd = append (cmd , patches ... )
468+ cmd = append (cmd , patch )
469469
470470 _ , err := executeGitCommand (repoDir , cmd , true )
471471 if err != nil {
@@ -481,6 +481,77 @@ func (gd *GenericDownloader) ApplyPatches(repoDir string, patches []string) erro
481481 return nil
482482}
483483
484+ func spatchPath () (string , error ) {
485+ spatchPath , err := exec .LookPath ("spatch" )
486+ if err != nil {
487+ return "" , util .NewNewtError (fmt .Sprintf ("Can't find spatch binary: %s\n " ,
488+ err .Error ()))
489+ }
490+
491+ return filepath .ToSlash (spatchPath ), nil
492+ }
493+
494+ func executeSpatchCommand (dir string , cmd []string , logCmd bool ) ([]byte , error ) {
495+ wd , err := os .Getwd ()
496+ if err != nil {
497+ return nil , util .NewNewtError (err .Error ())
498+ }
499+
500+ sp , err := spatchPath ()
501+ if err != nil {
502+ return nil , err
503+ }
504+
505+ if err := os .Chdir (dir ); err != nil {
506+ return nil , util .ChildNewtError (err )
507+ }
508+
509+ defer os .Chdir (wd )
510+
511+ spatchCmd := []string {sp }
512+ spatchCmd = append (spatchCmd , cmd ... )
513+ output , err := util .ShellCommandLimitDbgOutput (spatchCmd , nil , logCmd , - 1 )
514+ if err != nil {
515+ return nil , err
516+ }
517+
518+ return output , nil
519+ }
520+
521+ func ApplyCocci (repoDir string , cocci string ) error {
522+ cmd := []string {
523+ "--sp-file" ,
524+ cocci ,
525+ "--in-place" ,
526+ "--include-headers" ,
527+ repoDir ,
528+ }
529+
530+ _ , err := executeSpatchCommand (repoDir , cmd , true )
531+ if err != nil {
532+ return err
533+ }
534+ return nil
535+ }
536+
537+ func (gd * GenericDownloader ) ApplyPatches (repoDir string , patches []string ) error {
538+ for _ , patch := range patches {
539+ if strings .HasSuffix (patch , ".patch" ) {
540+ err := ApplyPatch (repoDir , patch )
541+ if err != nil {
542+ return err
543+ }
544+ } else if strings .HasSuffix (patch , ".cocci" ) {
545+ err := ApplyCocci (repoDir , patch )
546+ if err != nil {
547+ return err
548+ }
549+ }
550+ }
551+
552+ return nil
553+ }
554+
484555// Update one submodule tree in a repo (under path)
485556func (gd * GenericDownloader ) UpdateSubmodule (path string , submodule string ) error {
486557 cmd := []string {
0 commit comments