// ModifyImport adds the package to the context.

ModifyImport adds the package to the context.
// ModifyImport adds the package to the context .
func (ctx *Context) ModifyImport(imp *pkgspec.Pkg, mod Modify, mops ...ModifyOption) error {
	var err error
	if ctx.added == nil {
		ctx.added = make(map[string]bool, 10)
	}
	if len(imp.Origin) == 0 {
		for _, vpkg := range ctx.VendorFile.Package {
			if vpkg.Remove {
				continue
			}
			if vpkg.Path == imp.Path {
				imp.Origin = vpkg.Origin
			}
		}
	}
	if !imp.MatchTree {
		if !ctx.added[imp.PathOrigin()] {
			err = ctx.modify(imp, mod, mops)
			if err != nil {
				return err
			}
		}
		return nil
	}
	list, err := ctx.Status()
	if err != nil {
		return err
	}
	match := imp.Path + "/"
	for _, item := range list {
		if ctx.added[item.Pkg.PathOrigin()] {
			continue
		}
		if item.Pkg.Path != imp.Path && !strings.HasPrefix(item.Pkg.Path, match) {
			continue
		}
		if imp.HasVersion {
			item.Pkg.HasVersion = true
			item.Pkg.Version = imp.Version
		}
		item.Pkg.Origin = path.Join(imp.PathOrigin(), strings.TrimPrefix(item.Pkg.Path, imp.Path))
		err = ctx.modify(item.Pkg, mod, mops)
		if err != nil {
			return err
		}
	}
	return nil
}
func ( ctx * Context ) ModifyImport ( imp * pkgspec . Pkg , mod Modify , mops ... ModifyOption ) error { var err error if ctx . added == nil { ctx . added = make ( map [ string ] bool , 10 ) } if len ( imp . Origin ) == 0 { for _ , vpkg := range ctx . VendorFile . Package { if vpkg . Remove { continue } if vpkg . Path == imp . Path { imp . Origin = vpkg . Origin } } } if ! imp . MatchTree { if ! ctx . added [ imp . PathOrigin ( ) ] { err = ctx . modify ( imp , mod , mops ) if err != nil { return err } } return nil } list , err := ctx . Status ( ) if err != nil { return err } match := imp . Path + " " for _ , item := range list { if ctx . added [ item . Pkg . PathOrigin ( ) ] { continue } if item . Pkg . Path != imp . Path && ! strings . HasPrefix ( item . Pkg . Path , match ) { continue } if imp . HasVersion { item . Pkg . HasVersion = true item . Pkg . Version = imp . Version } item . Pkg . Origin = path . Join ( imp . PathOrigin ( ) , strings . TrimPrefix ( item . Pkg . Path , imp . Path ) ) err = ctx . modify ( item . Pkg , mod , mops ) if err != nil { return err } } return nil }
ModifyImport adds the package to the context.
ModifyImport adds the package to the context .
// Grap the origin of the pkg spec from the vendor file as needed.
 // If add any matched from "...".
