forked from x/icebergs
opt git
This commit is contained in:
parent
35c5a799f1
commit
8dcde629d8
@ -40,6 +40,11 @@ func ProcessCommandOpt(m *ice.Message, arg []string, args ...string) {
|
||||
}
|
||||
m.Push("opt", kit.Format(m.OptionSimple(args...)))
|
||||
}
|
||||
func ProcessFloat(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_PROCESS, ice.PROCESS_FLOAT)
|
||||
m.Option(ice.PROCESS_ARG, arg)
|
||||
m.Cmdy(COMMAND, arg[0])
|
||||
}
|
||||
func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) {
|
||||
if cmd = kit.Select(m.PrefixKey(), cmd); len(arg) == 0 || arg[0] != ice.RUN {
|
||||
m.Option("_index", m.PrefixKey())
|
||||
@ -52,11 +57,6 @@ func ProcessField(m *ice.Message, cmd string, args []string, arg ...string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func ProcessFloat(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_PROCESS, ice.PROCESS_FLOAT)
|
||||
m.Option(ice.PROCESS_ARG, arg)
|
||||
m.Cmdy(COMMAND, arg[0])
|
||||
}
|
||||
|
||||
func ProcessRefresh(m *ice.Message, arg ...string) { m.ProcessRefresh(arg...) }
|
||||
func ProcessRewrite(m *ice.Message, arg ...ice.Any) { m.ProcessRewrite(arg...) }
|
||||
|
@ -179,6 +179,9 @@ func init() {
|
||||
return
|
||||
}
|
||||
fields := kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1))))
|
||||
if root != "" {
|
||||
m.Logs(mdb.SELECT, DIR_ROOT, root)
|
||||
}
|
||||
_dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)), fields)
|
||||
m.Sort(PATH).StatusTimeCount()
|
||||
}},
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"shylinux.com/x/gogit"
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -26,8 +27,7 @@ func _repos_cmd(m *ice.Message, name string, arg ...string) *ice.Message {
|
||||
func _repos_init(m *ice.Message, p string) string {
|
||||
os.MkdirAll(path.Join(p, "refs/heads/"), ice.MOD_DIR)
|
||||
os.MkdirAll(path.Join(p, "objects/info/"), ice.MOD_DIR)
|
||||
m.Cmd(nfs.SAVE, path.Join(p, "HEAD"), "ref: refs/heads/master")
|
||||
return p
|
||||
return m.Cmdx(nfs.SAVE, path.Join(p, "HEAD"), "ref: refs/heads/master")
|
||||
}
|
||||
func _repos_insert(m *ice.Message, name string, path string) bool {
|
||||
if repos, e := gogit.OpenRepository(_git_dir(path)); e == nil {
|
||||
@ -42,29 +42,112 @@ func _repos_insert(m *ice.Message, name string, path string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
func _repos_branch(m *ice.Message, dir string) {
|
||||
if repos, e := gogit.OpenRepository(dir); !m.Warn(e, ice.ErrNotFound, dir) {
|
||||
nfs.DirDeepAll(m, path.Join(dir, "refs/heads/"), "", func(value ice.Maps) {
|
||||
if refer, e := repos.LookupReference("refs/heads/" + value[nfs.PATH]); !m.Warn(e, ice.ErrNotValid, value[nfs.PATH]) {
|
||||
if ci, e := repos.LookupCommit(refer.Oid); !m.Warn(e, ice.ErrNotValid, refer.Oid.String()) {
|
||||
m.Push(mdb.TIME, ci.Author.When.Format(ice.MOD_TIME))
|
||||
m.Push(BRANCH, value[nfs.PATH])
|
||||
m.Push(COMMIT, ci.Oid.String()[:6])
|
||||
m.Push(AUTHOR, ci.Author.Name)
|
||||
m.Push(mdb.TEXT, ci.Message)
|
||||
}
|
||||
}
|
||||
}, nfs.PATH)
|
||||
}
|
||||
}
|
||||
func _repos_commit(m *ice.Message, dir, branch string, cb func(*gogit.Commit, *gogit.Repository) bool) {
|
||||
if repos, e := gogit.OpenRepository(dir); !m.Warn(e, ice.ErrNotFound, dir) {
|
||||
if refer, e := repos.LookupReference("refs/heads/" + branch); !m.Warn(e, ice.ErrNotFound, branch) {
|
||||
if cb == nil {
|
||||
m.Push(mdb.TIME, m.Time())
|
||||
m.Push(COMMIT, cli.PWD)
|
||||
m.Push(AUTHOR, kit.Select(m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERNICK)))
|
||||
m.Push(mdb.TEXT, "opt some")
|
||||
}
|
||||
for oid := refer.Oid; oid != nil; {
|
||||
if ci, e := repos.LookupCommit(oid); !m.Warn(e, ice.ErrNotValid, oid.String()) {
|
||||
if cb == nil {
|
||||
m.Push(mdb.TIME, ci.Author.When.Format(ice.MOD_TIME))
|
||||
m.Push(COMMIT, ci.Oid.String()[:6])
|
||||
m.Push(AUTHOR, ci.Author.Name)
|
||||
m.Push(mdb.TEXT, ci.Message)
|
||||
} else if cb(ci, repos) {
|
||||
break
|
||||
}
|
||||
if p := ci.Parent(0); p != nil {
|
||||
oid = p.Oid
|
||||
continue
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func _repos_dir(m *ice.Message, dir, branch, commit, file string, cb func(*gogit.TreeEntry, *gogit.Repository) bool) {
|
||||
if commit == cli.PWD {
|
||||
nfs.DirDeepAll(m, path.Dir(dir), file, nil, "time,line,path")
|
||||
return
|
||||
} else if file == nfs.PWD {
|
||||
file = ""
|
||||
}
|
||||
_repos_commit(m, dir, branch, func(ci *gogit.Commit, repos *gogit.Repository) bool {
|
||||
if strings.HasPrefix(ci.Oid.String(), commit) {
|
||||
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.String()[:6])
|
||||
tree.Walk(func(p string, v *gogit.TreeEntry) int {
|
||||
if strings.HasPrefix(path.Join(p, v.Name), file) {
|
||||
if cb == nil {
|
||||
m.Push(mdb.HASH, v.Id.String()[:6])
|
||||
m.Push(nfs.PATH, path.Join(p, v.Name)+kit.Select("", ice.PS, v.Type == gogit.ObjectTree))
|
||||
} else if cb(v, repos) {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
})
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
func _repos_cat(m *ice.Message, dir, branch, commit, file string) {
|
||||
if commit == cli.PWD {
|
||||
m.Cmdy(nfs.CAT, path.Join(path.Dir(dir), file))
|
||||
return
|
||||
}
|
||||
_repos_dir(m, dir, branch, commit, file, func(v *gogit.TreeEntry, repos *gogit.Repository) bool {
|
||||
if blob, e := repos.LookupBlob(v.Id); e == nil {
|
||||
m.Logs(mdb.IMPORT, REPOS, dir, BRANCH, branch, COMMIT, commit, "blob", v.Id.String()[:6])
|
||||
m.Echo(string(blob.Contents()))
|
||||
} else {
|
||||
m.Option(cli.CMD_DIR, dir)
|
||||
m.Echo(_git_cmds(m, "cat-file", "-p", v.Id.String()))
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
const (
|
||||
ORIGIN = "origin"
|
||||
BRANCH = "branch"
|
||||
MASTER = "master"
|
||||
AUTHOR = "author"
|
||||
INIT = "init"
|
||||
)
|
||||
const REPOS = "repos"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
REPOS: {Name: "repos repos path auto create", Help: "代码库", Actions: ice.MergeActions(ice.Actions{
|
||||
REPOS: {Name: "repos repos branch commit path auto create inner", Help: "代码库", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.DIR, ice.USR, "name,path", func(value ice.Maps) { _repos_insert(m, value[mdb.NAME], value[nfs.PATH]) })
|
||||
_repos_insert(m, path.Base(kit.Pwd()), kit.Pwd())
|
||||
cli.IsSystem(m, GIT)
|
||||
}},
|
||||
INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if dir := _repos_init(m, _git_dir(m.Option(cli.CMD_DIR))); m.Option(ORIGIN, kit.Select("", kit.Split(m.Option(ORIGIN)), -1)) != "" {
|
||||
m.Cmd(nfs.SAVE, path.Join(dir, "config"), kit.Format(_repos_config, m.Option(ORIGIN)))
|
||||
_git_cmd(m, PULL, ORIGIN, m.OptionDefault(BRANCH, MASTER))
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create origin name path", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionDefault(mdb.NAME, strings.TrimSuffix(path.Base(m.Option(ORIGIN)), ".git"))
|
||||
m.OptionDefault(nfs.PATH, path.Join(ice.USR, m.Option(mdb.NAME)))
|
||||
@ -74,12 +157,38 @@ func init() {
|
||||
m.Cmd("", INIT, kit.Dict(cli.CMD_DIR, m.Option(nfs.PATH)))
|
||||
_repos_insert(m, m.Option(mdb.NAME), m.Option(nfs.PATH))
|
||||
}},
|
||||
INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if dir := _repos_init(m, _git_dir(m.Option(cli.CMD_DIR))); m.Option(ORIGIN, kit.Select("", kit.Split(m.Option(ORIGIN)), -1)) != "" {
|
||||
m.Cmd(nfs.SAVE, path.Join(dir, "config"), kit.Format(_repos_config, m.Option(ORIGIN)))
|
||||
_git_cmd(m, PULL, ORIGIN, m.OptionDefault(BRANCH, MASTER))
|
||||
}
|
||||
}},
|
||||
"inner": {Help: "编辑器", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || arg[0] != ice.RUN {
|
||||
arg = []string{_repos_path(arg[0]), kit.Select("README.md", arg, 3)}
|
||||
} else if kit.Select("", arg, 1) != ctx.ACTION {
|
||||
if ctx.DisplayLocal(m, "code/inner.js"); len(arg) < 3 {
|
||||
_repos_dir(m, _git_dir(_repos_path(m.Option(REPOS))), m.Option(BRANCH), m.Option(COMMIT), kit.Select("", arg, 1), nil)
|
||||
} else {
|
||||
_repos_cat(m, _git_dir(_repos_path(m.Option(REPOS))), m.Option(BRANCH), m.Option(COMMIT), arg[2])
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.ProcessField(m, "web.code.inner", arg, arg...)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,commit,origin"), mdb.ClearHashOnExitAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
if len(arg) == 0 || arg[0] == "" {
|
||||
mdb.HashSelect(m, arg...)
|
||||
} else if len(arg) == 1 || arg[1] == "" {
|
||||
_repos_branch(m, _git_dir(_repos_path(arg[0])))
|
||||
} else if len(arg) == 2 || arg[2] == "" {
|
||||
_repos_commit(m, _git_dir(_repos_path(arg[0])), arg[1], nil)
|
||||
} else if len(arg) == 3 || arg[3] == "" || strings.HasSuffix(arg[3], ice.PS) {
|
||||
_repos_dir(m, _git_dir(_repos_path(arg[0])), arg[1], arg[2], kit.Select("", arg, 3), nil)
|
||||
} else {
|
||||
m.Cmdy(nfs.CAT, kit.Select(nfs.PWD, arg, 1), "time,line,path", kit.Dict(nfs.DIR_ROOT, _repos_path(arg[0])))
|
||||
m.Cmdy("", "inner", arg)
|
||||
}
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func init() {
|
||||
}},
|
||||
}, gdb.EventAction(web.DREAM_INPUTS)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(nfs.DIR_ROOT, ice.USR_LOCAL_REPOS); len(arg) == 0 {
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, func(value ice.Maps) { m.PushScript("git clone " + _git_url(m, value[nfs.PATH]) }).Cut("time,path,size,script,action")
|
||||
m.Cmdy(nfs.DIR, nfs.PWD, func(value ice.Maps) { m.PushScript("git clone " + _git_url(m, value[nfs.PATH])) }).Cut("time,path,size,script,action")
|
||||
}
|
||||
}},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user