M Makefile +3 -8
@@ 1,10 1,8 @@
.PHONY: functional test clean
-PROGS=cgi server restserver client
+PROGS=cgi/cgi server/server restserver/restserver client/client
all: $(PROGS)
-
-config.a: config/*.go
- gobuild -lib
+ gb
functional:
gobuild -o _functional test/functionaltest.go config/testing_test.go
@@ 15,12 13,9 @@ clean:
rm config/*.6 config/*.8 config/*.a
test:
- $(MAKE) -C config test
+ gb -t
format:
gofmt -comments -tabindent -spaces -tabwidth=4 -s -l *.go config/*.go
gofmt -comments -tabindent -spaces -tabwidth=4 -s -w *.go config/*.go
govet *.go config/*.go
-
-%: %.go config.a
- gobuild -keep-a-files -single-main $<
M cgi/main.go +6 -6
@@ 3,15 3,15 @@ package main
import (
"bytes"
"config"
+ "encoding/json"
"fmt"
- "http"
- "json"
"log"
+ "net/http"
+ "net/url"
"os"
"regexp"
"strconv"
"strings"
- "url"
)
func main() {
@@ 66,7 66,7 @@ func handleComponents(conf *config.Confi
code := http.StatusOK
switch method {
case "GET":
- var err os.Error
+ var err error
malformed := "Malformed request: " + path +
"; must be /components[/COMPONENT[/..][?rev=REV]]"
if component == "" {
@@ 108,7 108,7 @@ func handleWorkspaces(config *config.Con
code := http.StatusOK
switch method {
case "GET":
- var err os.Error
+ var err error
malformed := "Malformed request: " + path +
"; must be /workspaces[/REV] or /workspaces[?limit=COUNT]"
if component == "" {
@@ 120,7 120,7 @@ func handleWorkspaces(config *config.Con
payload = config.GetWorkspace(component)
}
if err != nil {
- log.Fatalf("Error: %s", err.String())
+ log.Fatalf("Error: %s", err.Error())
payload = malformed
code = http.StatusBadRequest
}
M client/main.go +8 -7
@@ 1,17 1,18 @@
package main
+
// RPC client
import (
"config"
+ "encoding/json"
"flag"
"fmt"
"log"
+ "net/rpc"
+ "net/rpc/jsonrpc"
"os"
- "json"
- "rpc/jsonrpc"
"strconv"
"strings"
- "rpc"
)
const (
@@ 60,7 61,7 @@ func main() {
}
}
-func doSet(client *rpc.Client, set string) os.Error {
+func doSet(client *rpc.Client, set string) error {
if flag.NArg() < 1 {
usage("Component name argument is required (for a list, try -l)")
os.Exit(1)
@@ 74,7 75,7 @@ func doSet(client *rpc.Client, set strin
return err
}
-func doGetAttr(client *rpc.Client, attribute string) os.Error {
+func doGetAttr(client *rpc.Client, attribute string) error {
if flag.NArg() < 1 {
usage("Component name argument is required (for a list, try -l)")
os.Exit(1)
@@ 90,7 91,7 @@ func doGetAttr(client *rpc.Client, attri
return nil
}
-func doGetComponent(client *rpc.Client) os.Error {
+func doGetComponent(client *rpc.Client) error {
if flag.NArg() < 1 {
usage("Component name argument is required (for a list, try -l)")
os.Exit(1)
@@ 105,7 106,7 @@ func doGetComponent(client *rpc.Client)
return nil
}
-func doList(client *rpc.Client) os.Error {
+func doList(client *rpc.Client) error {
var ids []string
err := client.Call("Wrapper.ComponentIds", "", &ids)
if err != nil {
M config/config.go +5 -3
@@ 1,13 1,15 @@
package config
import (
+ "encoding/json"
"strings"
- "json"
)
type Store map[string]interface{}
+
// [ store name ] -> Store
type StoreMap map[string]Store
+
// [ rev ] -> map of stores
type Revisions map[string]StoreMap
@@ 69,7 71,7 @@ func (h *Configuration) Branch(parent_re
}
func (h *Configuration) Delete(component_name string) {
- h.Workspace[component_name] = nil, false
+ delete(h.Workspace, component_name)
}
func to_string(path []string) string {
@@ 96,7 98,7 @@ func reduce(workspace StoreMap, path []s
parent = expand(workspace, parent_path)
for k, v := range parent {
if v == config[k] {
- config[k] = "", false
+ delete(config, k)
}
}
}
M documentation/doc.go => config/doc.go +1 -1
@@ 42,4 42,4 @@
Creates a new workspace, optionally branching off of a specified version.
Response: ""
*/
-package documentation
+package config
M config/hg.go +11 -12
@@ 1,12 1,11 @@
package config
import (
- "exec"
"io/ioutil"
- "os"
+ "log"
+ "os/exec"
+ "path/filepath"
"strings"
- "path/filepath"
- "log"
)
///////////////////////////////////////////////////////////////////////////////
@@ 36,7 35,7 @@ func (r *Hg) Init(repo_dir string) {
hasHg := false
isEmpty := true
for _, fi := range finfo {
- switch fi.Name {
+ switch fi.Name() {
case ".", "..": // No-op
case ".hg":
hasHg = true
@@ 67,13 66,13 @@ func (r *Hg) Init(repo_dir string) {
}
if err := ioutil.WriteFile(r.repo_path+"/config.json", []byte("{}"), 0600); err != nil {
- panic("Error writing config.json: " + err.String())
+ panic("Error writing config.json: " + err.Error())
}
if _, err := runHg(r.repo_path, "add", CONF_FILENAME); err != nil {
- panic("Error adding config.json: " + err.String())
+ panic("Error adding config.json: " + err.Error())
}
if _, err := runHg(r.repo_path, "ci", "-m", "Initial commit"); err != nil {
- panic("Error committing config.json: " + err.String())
+ panic("Error committing config.json: " + err.Error())
}
}
@@ 152,23 151,23 @@ func (r Hg) Branch(version string, name
r.revs_cache[name] = string(bytes)
}
-func runHg(path string, args ...string) (output string, err os.Error) {
+func runHg(path string, args ...string) (output string, err error) {
//log.Print( args )
cmd := exec.Command("hg", args[:]...)
cmd.Dir = path
outputBytes, err := cmd.Output()
output = string(outputBytes)
if err != nil {
- log.Printf("Failure %v:\n %s", args, err.String())
+ log.Printf("Failure %v:\n %s", args, err.Error())
}
return output, err
}
-func (r *Hg) Write(json string) os.Error {
+func (r *Hg) Write(json string) error {
path := filepath.Join(r.repo_path, CONF_FILENAME)
err := ioutil.WriteFile(path, []byte(json), 0600)
if err != nil {
- log.Fatalf("Failure to write %s: %s", CONF_FILENAME, err.String())
+ log.Fatalf("Failure to write %s: %s", CONF_FILENAME, err.Error())
return err
}
return nil
M config/hg_test.go +6 -6
@@ 1,23 1,23 @@
package config
import (
- "testing"
+ "fmt"
"os"
- "fmt"
+ "testing"
)
func TestInit(tx *testing.T) {
t := T{testing.T: tx}
r := new(Hg)
r.Init("test.repo")
- var res *os.FileInfo
- var e os.Error
+ var res os.FileInfo
+ var e error
res, e = os.Lstat("test.repo")
- if e != nil || !res.IsDirectory() {
+ if e != nil || !res.IsDir() {
t.Error("test.repo must be a directory")
}
res, e = os.Lstat("test.repo/config.json")
- if e != nil || !res.IsRegular() {
+ if e != nil || !!res.IsDir() {
t.Error("test.repo/config.json must be a directory")
}
os.RemoveAll("test.repo")
M config/props.go +2 -4
@@ 1,11 1,9 @@
package config
-import "os"
-
-func Marshal(i interface{}) (retVal []byte, err os.Error) {
+func Marshal(i interface{}) (retVal []byte, err error) {
return
}
-func Unmarshal(val []byte, i interface{}) os.Error {
+func Unmarshal(val []byte, i interface{}) error {
return nil
}
M config/vcs.go +1 -3
@@ 1,7 1,5 @@
package config
-import "os"
-
type Vcs interface {
Init(repo_dir string)
Tip() (revnum string)
@@ 13,5 11,5 @@ type Vcs interface {
Get(rev_tag_branch string) (json_config string)
Commit(payload string, tag string) (revnum string)
Branch(parent_rev string, name string)
- Write(json string) os.Error
+ Write(json string) error
}
M restserver/main.go +3 -3
@@ 1,14 1,14 @@
package main
import (
+ "code.google.com/p/gorest/gorest"
"config"
+ "encoding/json"
"flag"
"fmt"
"github.com/mattn/go-uwsgi"
- "gorest.googlecode.com/hg/gorest"
- "http"
- "json"
"net"
+ "net/http"
"os"
"strings"
)
M server/main.go +19 -19
@@ 1,16 1,16 @@
package main
import (
- "strings"
+ "config"
+ "encoding/json"
+ "flag"
"log"
- "flag"
+
+ "net"
+ "net/rpc"
+ "net/rpc/jsonrpc"
"strconv"
- "os"
- "json"
- "config"
- "net"
- "rpc"
- "rpc/jsonrpc"
+ "strings"
)
///////////////////////////////////////////////////////////////////////////////
@@ 30,7 30,7 @@ func main() {
RunServer(*repo_dir, *port, nil)
}
-func RunServer(repo_dir string, port int, ready chan os.Error) {
+func RunServer(repo_dir string, port int, ready chan error) {
addr := ":" + strconv.Itoa(port)
var wrap Wrapper
@@ 68,7 68,7 @@ func RunServer(repo_dir string, port int
}
}
-func (serv *Wrapper) ComponentIds(_ string, ids *[]string) os.Error {
+func (serv *Wrapper) ComponentIds(_ string, ids *[]string) error {
serv.channel <- func(conf *config.Configuration) {
c := conf.GetComponents()
*ids = c
@@ 76,7 76,7 @@ func (serv *Wrapper) ComponentIds(_ stri
return nil
}
-func (serv *Wrapper) Component(path string, store *config.Store) os.Error {
+func (serv *Wrapper) Component(path string, store *config.Store) error {
serv.channel <- func(conf *config.Configuration) {
//rev := values.Get("rev")
s := conf.GetComponent(path, "")
@@ 85,7 85,7 @@ func (serv *Wrapper) Component(path stri
return nil
}
-func (serv *Wrapper) Workspaces(limit int, workspaces *map[string]([]string)) os.Error {
+func (serv *Wrapper) Workspaces(limit int, workspaces *map[string]([]string)) error {
serv.channel <- func(conf *config.Configuration) {
w := conf.GetWorkspaces(limit)
*workspaces = w
@@ 93,7 93,7 @@ func (serv *Wrapper) Workspaces(limit in
return nil
}
-func (serv *Wrapper) Workspace(num string, workspace *string) os.Error {
+func (serv *Wrapper) Workspace(num string, workspace *string) error {
serv.channel <- func(conf *config.Configuration) {
w := conf.GetWorkspace(num)
*workspace = w
@@ 101,7 101,7 @@ func (serv *Wrapper) Workspace(num strin
return nil
}
-func (serv *Wrapper) ReplaceComponent(args []string, _ *string) os.Error {
+func (serv *Wrapper) ReplaceComponent(args []string, _ *string) error {
serv.channel <- func(conf *config.Configuration) {
body := args[0]
path := args[1:]
@@ 113,14 113,14 @@ func (serv *Wrapper) ReplaceComponent(ar
return nil
}
-func (serv *Wrapper) CommitWorkspace(tag string, _ *string) os.Error {
+func (serv *Wrapper) CommitWorkspace(tag string, _ *string) error {
serv.channel <- func(conf *config.Configuration) {
conf.PutWorkspace(tag)
}
return nil
}
-func (serv *Wrapper) BranchWorkspace(args []string, _ *string) os.Error {
+func (serv *Wrapper) BranchWorkspace(args []string, _ *string) error {
serv.channel <- func(conf *config.Configuration) {
parent_rev := args[0]
branch_name := args[1]
@@ 129,7 129,7 @@ func (serv *Wrapper) BranchWorkspace(arg
return nil
}
-func (serv *Wrapper) RemoveComponent(path []string, _ *string) os.Error {
+func (serv *Wrapper) RemoveComponent(path []string, _ *string) error {
serv.channel <- func(conf *config.Configuration) {
component := strings.TrimRight(strings.Join(path, "/"), "/")
conf.Delete(component)
@@ 137,7 137,7 @@ func (serv *Wrapper) RemoveComponent(pat
return nil
}
-func (serv *Wrapper) Set(args []string, ok *bool) os.Error {
+func (serv *Wrapper) Set(args []string, ok *bool) error {
serv.channel <- func(conf *config.Configuration) {
path := args[0]
attribute := args[1]
@@ 157,7 157,7 @@ func (serv *Wrapper) Set(args []string,
return nil
}
-func (serv *Wrapper) Get(args []string, value *interface{}) os.Error {
+func (serv *Wrapper) Get(args []string, value *interface{}) error {
serv.channel <- func(conf *config.Configuration) {
path := args[0]
attribute := args[1]