grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Start of hgweb support
feature/hgweb
2019-09-17, Gary Kramlich
45b57bfc4382
Start of hgweb support
package
hg
import
(
"os"
"os/exec"
"path/filepath"
"strings"
log
"github.com/sirupsen/logrus"
"bitbucket.org/rw_grim/hgkeeper/access"
)
type
Command
struct
{
cmd
*
exec
.
Cmd
tmpHgrc
string
writeable
bool
}
func
(
c
*
Command
)
Setup
()
error
{
hgrc
,
err
:=
createHgrc
(
c
.
writeable
)
if
err
!=
nil
{
return
err
}
c
.
tmpHgrc
=
hgrc
rcs
:=
[]
string
{
filepath
.
Join
(
access
.
AdminRepoPath
(),
"site.hgrc"
),
c
.
tmpHgrc
,
}
c
.
cmd
.
Env
=
append
(
os
.
Environ
(),
"HGRCPATH="
+
strings
.
Join
(
rcs
,
string
(
filepath
.
ListSeparator
)),
)
return
nil
}
func
(
c
*
Command
)
Teardown
()
{
if
c
.
tmpHgrc
!=
""
{
if
err
:=
os
.
Remove
(
c
.
tmpHgrc
);
err
!=
nil
{
log
.
Warnf
(
"failed to remove %q: %v"
,
c
.
tmpHgrc
,
err
)
}
c
.
tmpHgrc
=
""
}
}
func
(
c
*
Command
)
Cmd
()
*
exec
.
Cmd
{
return
c
.
cmd
}
func
Init
(
path
string
)
*
Command
{
return
&
Command
{
cmd
:
exec
.
Command
(
"hg"
,
"init"
,
path
),
}
}
func
Serve
(
path
string
,
writeable
bool
)
*
Command
{
return
&
Command
{
cmd
:
exec
.
Command
(
"hg"
,
"-R"
,
path
,
"serve"
,
"--stdio"
),
writeable
:
writeable
,
}
}
func
Add
(
path
string
,
files
...
string
)
*
Command
{
args
:=
append
([]
string
{
"add"
,
"--cwd"
,
path
},
files
...
)
return
&
Command
{
cmd
:
exec
.
Command
(
"hg"
,
args
...
),
}
}
func
Commit
(
path
,
username
,
message
string
)
*
Command
{
args
:=
[]
string
{
"commit"
,
"--cwd"
,
path
,
"--config"
,
"ui.username="
+
username
,
"-m"
,
message
,
}
return
&
Command
{
cmd
:
exec
.
Command
(
"hg"
,
args
...
),
}
}