From cb16cee60edc4b5b6492cfa1a69b7638404415e5 Mon Sep 17 00:00:00 2001 From: shylinux Date: Mon, 20 Feb 2023 01:12:20 +0800 Subject: [PATCH] opt some --- misc/git/repos.go | 11 ++++++----- misc/git/server.go | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/misc/git/repos.go b/misc/git/repos.go index e4f638e8..49547140 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -103,6 +103,11 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit } else if file == nfs.PWD { file = "" } + if repos, e := gogit.OpenRepository(dir); !m.Warn(e, ice.ErrNotFound, dir) { + if refer, e := repos.LookupReference(REFS_TAGS + commit); !m.Warn(e, ice.ErrNotFound, branch) { + commit = refer.Oid.String() + } + } _repos_commit(m, dir, branch, func(ci *gogit.Commit, repos *gogit.Repository) bool { if !strings.HasPrefix(ci.Oid.String(), commit) { return false @@ -120,12 +125,9 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit } if tree, e := repos.LookupTree(ci.TreeId()); !m.Warn(e, ice.ErrNotValid, ci.TreeId().String) { m.Logs(mdb.SELECT, REPOS, dir, BRANCH, branch, COMMIT, commit, "tree", tree.Oid.Short()) - m.Logs("what", file, file) tree.Walk(func(p string, v *gogit.TreeEntry) bool { if pp := path.Join(p, v.Name) + kit.Select("", ice.PS, v.Type == gogit.ObjectTree); strings.HasPrefix(pp, file) { - m.Logs("what", file, pp) if cb == nil { - m.Logs("what", file, pp) if path.Dir(file) != path.Dir(pp) { } else if v.Type == gogit.ObjectTree { @@ -141,7 +143,6 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit } delete(prev, pp) } else if cb(v, repos) { - m.Logs("what", file, pp) return true } } @@ -149,7 +150,6 @@ func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit }) } kit.Fetch(prev, func(pp, id string) { - m.Logs("what", path.Dir(file), path.Dir(pp)) if path.Dir(file) != path.Dir(pp) { return } @@ -188,6 +188,7 @@ func _repos_cat(m *ice.Message, dir, branch, commit, file string) { const ( REFS_HEADS = "refs/heads/" + REFS_TAGS = "refs/tags/" INIT = "init" CONFIG = "config" diff --git a/misc/git/server.go b/misc/git/server.go index 517bc28f..87ae0942 100644 --- a/misc/git/server.go +++ b/misc/git/server.go @@ -92,11 +92,19 @@ const ( const SERVER = "server" func init() { - web.Index.MergeCommands(ice.Commands{"/x/": {Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) { + web.Index.MergeCommands(ice.Commands{"/x/": {Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) { if !m.IsCliUA() { - web.RenderCmds(m, - kit.Dict(ctx.DISPLAY, "/plugin/local/code/repos.js", ctx.INDEX, "web.code.git.inner", ctx.ARGS, kit.List(strings.TrimSuffix(arg[0], ".git"), kit.Select("master", arg, 1), "pwd", kit.Select("README.md", path.Join(kit.Slice(arg, 2)...)))), - ) + if strings.Contains(arg[0], ice.AT) { + ls := strings.Split(arg[0], ice.AT) + _repos_cat(m, path.Join(ice.USR_LOCAL_REPOS, ls[0]), "master", ls[1], path.Join(arg[1:]...)) + m.RenderResult() + } else if strings.HasPrefix(arg[1], "v") && strings.Contains(arg[1], ice.PT) { + _repos_cat(m, path.Join(ice.USR_LOCAL_REPOS, arg[0]), "master", arg[1], path.Join(arg[2:]...)) + m.RenderResult() + } else { + web.RenderCmds(m, kit.Dict(ctx.DISPLAY, "/plugin/local/code/repos.js", ctx.INDEX, "web.code.git.inner", + ctx.ARGS, kit.List(strings.TrimSuffix(arg[0], ".git"), arg[1], "pwd", kit.Select("README.md", path.Join(kit.Slice(arg, 2)...))))) + } return } if m.RenderVoid(); m.Option("go-get") == "1" { @@ -121,7 +129,7 @@ func init() { m.Warn(_server_repos(m, arg...), ice.ErrNotValid) }}}) Index.MergeCommands(ice.Commands{ - "inner": {Name: "inner repos branch commit path auto", Help: "服务器", Actions: ice.MergeActions(ice.Actions{}), Hand: func(m *ice.Message, arg ...string) { + "inner": {Name: "inner repos branch commit path auto", Help: "服务器", Actions: ice.MergeActions(ice.Actions{}, aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) { if m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_REPOS); len(arg) == 0 { } else if dir := path.Join(m.Option(nfs.DIR_ROOT), arg[0]); len(arg) == 1 { } else if len(arg) == 2 {