From fadc2447013bd6cb78cef645ca822b607178c5e5 Mon Sep 17 00:00:00 2001 From: shylinux Date: Wed, 12 Jul 2023 22:47:19 +0800 Subject: [PATCH] opt some --- base/nfs/dir.go | 2 +- base/web/render.go | 8 +++++++- core/code/autogen.go | 1 + core/code/binpack.go | 2 +- info.go | 3 +++ misc/chrome/field.go | 11 +++++------ misc/git/repos.go | 43 +++++++++++++++++++++++++++++++++++-------- 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/base/nfs/dir.go b/base/nfs/dir.go index fdc3bdfa..7eb67d9c 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -118,7 +118,7 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di } if deep && isDir { switch s.Name() { - case "node_modules", "pluged": + case "pluged": continue } _dir_list(m, root, pp, level+1, deep, dir_type, dir_reg, fields) diff --git a/base/web/render.go b/base/web/render.go index df7e83ac..48735d84 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -10,6 +10,7 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/log" "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/tcp" @@ -137,11 +138,16 @@ func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) { )) } func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { RenderPodCmd(m, "", cmd, arg...) } + func RenderVersion(m *ice.Message) string { if ice.Info.Make.Hash == "" { return "" } - return kit.Format("?_v=%s-%s", ice.Info.Make.Version, ice.Info.Make.Hash[:6]) + ls := []string{ice.Info.Make.Version, ice.Info.Make.Forword, ice.Info.Make.Hash[:6]} + if m.Option(log.DEBUG) == ice.TRUE || m.R != nil && strings.Contains(m.R.URL.RawQuery, "debug=true") { + ls = append(ls, kit.Format("%d", time.Now().Unix()-kit.Time(ice.Info.Make.When)/int64(time.Second))) + } + return "?_v=" + strings.Join(ls, "-") } const ( diff --git a/core/code/autogen.go b/core/code/autogen.go index 99424fe1..71ce736a 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -83,6 +83,7 @@ func _autogen_git(m *ice.Message, arg ...string) ice.Map { mdb.TIME, m.Time(), nfs.PATH, kit.Path("")+nfs.PS, web.DOMAIN, tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB)), mdb.HASH, msg.Append(mdb.HASH), nfs.REMOTE, msg.Append(nfs.REMOTE), nfs.BRANCH, msg.Append(nfs.BRANCH), nfs.VERSION, msg.Append(nfs.VERSION), aaa.EMAIL, msg.Append(aaa.EMAIL), aaa.USERNAME, msg.Append(aaa.USERNAME), + msg.AppendSimple("when,message,forword"), ) } func _autogen_mod(m *ice.Message, file string) (mod string) { diff --git a/core/code/binpack.go b/core/code/binpack.go index 0bfd6464..dab0e07c 100644 --- a/core/code/binpack.go +++ b/core/code/binpack.go @@ -20,7 +20,7 @@ func _binpack_file(m *ice.Message, w io.Writer, arg ...string) { if kit.IsIn(kit.Ext(arg[0]), "zip", "gz") { return } - if kit.Contains(arg[0], "/node_modules/", "/dist/", "/bin/", "/log/") { + if kit.Contains(arg[0], "/dist/", "/bin/", "/log/") { return } if strings.HasPrefix(arg[0], "usr/volcanos/publish/") && !strings.HasSuffix(arg[0], "/proto.js") { diff --git a/info.go b/info.go index 47dffcf5..2ab910a5 100644 --- a/info.go +++ b/info.go @@ -21,6 +21,9 @@ type MakeInfo struct { Hostname string Username string Email string + When string + Message string + Forword string } var Info = struct { diff --git a/misc/chrome/field.go b/misc/chrome/field.go index 36e7fda5..b95e23ff 100644 --- a/misc/chrome/field.go +++ b/misc/chrome/field.go @@ -17,9 +17,9 @@ type field struct { list string `name:"list domain id auto insert" help:"插件"` } -func (s field) Inputs(m *ice.Message, arg ...string) { - s.daemon.Inputs(m, arg...) -} +func (s field) Init(m *ice.Message, arg ...string) { s.Zone.Imports(m) } +func (s field) Exit(m *ice.Message, arg ...string) { s.Zone.Exports(m) } +func (s field) Inputs(m *ice.Message, arg ...string) { s.daemon.Inputs(m, arg...) } func (s field) Command(m *ice.Message, arg ...string) { s.Zone.List(m.Spawn(), kit.Simple(m.Option(web.DOMAIN), arg)...).Table(func(index int, value ice.Maps, head []string) { if len(arg) == 0 { @@ -36,7 +36,6 @@ func (s field) Run(m *ice.Message, arg ...string) { m.Cmdy(value[mdb.INDEX], arg[1:]) }) } -func (s field) List(m *ice.Message, arg ...string) { - s.Zone.List(m, arg...) -} +func (s field) List(m *ice.Message, arg ...string) { s.Zone.List(m, arg...) } + func init() { ice.CodeCtxCmd(field{}) } diff --git a/misc/git/repos.go b/misc/git/repos.go index 4bc63f04..c9def359 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -49,6 +49,24 @@ func _repos_recent(m *ice.Message, repos *git.Repository) (r *plumbing.Reference } return } +func _repos_forword(m *ice.Message, repos *git.Repository, version string) int { + if refer, err := repos.Head(); err == nil { + if commit, err := repos.CommitObject(refer.Hash()); err == nil { + n := 0 + for { + if commit.Hash.String() == version { + break + } + if commit, err = commit.Parent(0); err != nil || commit == nil { + break + } + n++ + } + return n + } + } + return 0 +} func _repos_insert(m *ice.Message, p string) { if repos, err := git.PlainOpen(p); err == nil { args := []string{REPOS, path.Base(p), nfs.PATH, p} @@ -59,7 +77,11 @@ func _repos_insert(m *ice.Message, p string) { } } if refer := _repos_recent(m, repos); refer != nil { - args = append(args, VERSION, refer.Name().Short()) + if n := _repos_forword(m, repos, refer.Hash().String()); n > 0 { + args = append(args, VERSION, kit.Format("%s-%d", refer.Name().Short(), n)) + } else { + args = append(args, VERSION, refer.Name().Short()) + } } if remote, err := repos.Remote("origin"); err == nil { args = append(args, ORIGIN, remote.Config().URLs[0]) @@ -507,16 +529,21 @@ func init() { if _remote, err := repos.Remote(ORIGIN); err == nil { m.Push(REMOTE, kit.Select("", _remote.Config().URLs, 0)) } + version := "" + if refer := _repos_recent(m, repos); refer != nil { + m.Push(nfs.VERSION, refer.Name().Short()) + version = refer.Hash().String() + } if refer, err := repos.Head(); err == nil { m.Push(BRANCH, refer.Name().Short()) m.Push(mdb.HASH, refer.Hash().String()) - } - if refer := _repos_recent(m, repos); refer != nil { - m.Push(nfs.VERSION, refer.Name().Short()) - } - if cfg, err := config.LoadConfig(config.GlobalScope); err == nil { - m.Push(aaa.EMAIL, kit.Select(m.Option(ice.MSG_USERNAME)+"@163.com", cfg.User.Email)) - m.Push(aaa.USERNAME, kit.Select(m.Option(ice.MSG_USERNAME), cfg.User.Name)) + if commit, err := repos.CommitObject(refer.Hash()); err == nil { + m.Push(aaa.USERNAME, commit.Author.Name) + m.Push(aaa.EMAIL, commit.Author.Email) + m.Push("when", commit.Author.When) + m.Push("message", commit.Message) + m.Push("forword", _repos_forword(m, repos, version)) + } } }}, TOTAL: {Hand: func(m *ice.Message, arg ...string) {