Prefer mixedCaps over underscore

This commit is contained in:
Florian Weingarten
2015-04-24 19:39:32 -04:00
parent 8be6dc0265
commit ebae478631
13 changed files with 76 additions and 76 deletions

View File

@@ -28,8 +28,8 @@ func rndRd(bytes int) io.Reader {
return io.LimitReader(urnd, int64(bytes))
}
func create_dir(target string, depth int) {
fmt.Printf("create_dir %s, depth %d\n", target, depth)
func createDir(target string, depth int) {
fmt.Printf("createDir %s, depth %d\n", target, depth)
err := os.Mkdir(target, 0755)
if err != nil && !os.IsExist(err) {
panic(err)
@@ -54,7 +54,7 @@ func create_dir(target string, depth int) {
panic(err)
}
} else {
create_dir(filepath.Join(target, fmt.Sprintf("dir%d", i)), depth-1)
createDir(filepath.Join(target, fmt.Sprintf("dir%d", i)), depth-1)
}
}
}
@@ -65,5 +65,5 @@ func main() {
os.Exit(1)
}
create_dir(os.Args[1], MaxDepth)
createDir(os.Args[1], MaxDepth)
}

View File

@@ -27,7 +27,7 @@ func init() {
}
}
func format_bytes(c uint64) string {
func formatBytes(c uint64) string {
b := float64(c)
switch {
@@ -44,7 +44,7 @@ func format_bytes(c uint64) string {
}
}
func format_seconds(sec uint64) string {
func formatSeconds(sec uint64) string {
hours := sec / 3600
sec -= hours * 3600
min := sec / 60
@@ -56,16 +56,16 @@ func format_seconds(sec uint64) string {
return fmt.Sprintf("%d:%02d", min, sec)
}
func format_duration(d time.Duration) string {
func formatDuration(d time.Duration) string {
sec := uint64(d / time.Second)
return format_seconds(sec)
return formatSeconds(sec)
}
func print_tree2(indent int, t *restic.Tree) {
func printTree2(indent int, t *restic.Tree) {
for _, node := range t.Nodes {
if node.Tree() != nil {
fmt.Printf("%s%s/\n", strings.Repeat(" ", indent), node.Name)
print_tree2(indent+1, node.Tree())
printTree2(indent+1, node.Tree())
} else {
fmt.Printf("%s%s\n", strings.Repeat(" ", indent), node.Name)
}
@@ -87,10 +87,10 @@ func newCacheRefreshProgress() *restic.Progress {
}
p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
fmt.Printf("\x1b[2K[%s] %d trees loaded\r", format_duration(d), s.Trees)
fmt.Printf("\x1b[2K[%s] %d trees loaded\r", formatDuration(d), s.Trees)
}
p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
fmt.Printf("\x1b[2Krefreshed cache in %s\n", format_duration(d))
fmt.Printf("\x1b[2Krefreshed cache in %s\n", formatDuration(d))
}
return p
@@ -103,10 +103,10 @@ func newScanProgress() *restic.Progress {
p := restic.NewProgress(time.Second)
p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
fmt.Printf("\x1b[2K[%s] %d directories, %d files, %s\r", format_duration(d), s.Dirs, s.Files, format_bytes(s.Bytes))
fmt.Printf("\x1b[2K[%s] %d directories, %d files, %s\r", formatDuration(d), s.Dirs, s.Files, formatBytes(s.Bytes))
}
p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
fmt.Printf("\x1b[2Kscanned %d directories, %d files in %s\n", s.Dirs, s.Files, format_duration(d))
fmt.Printf("\x1b[2Kscanned %d directories, %d files in %s\n", s.Dirs, s.Files, formatDuration(d))
}
return p
@@ -140,12 +140,12 @@ func newArchiveProgress(todo restic.Stat) *restic.Progress {
}
status1 := fmt.Sprintf("[%s] %3.2f%% %s/s %s / %s %d / %d items ",
format_duration(d),
formatDuration(d),
percent,
format_bytes(bps),
format_bytes(s.Bytes), format_bytes(todo.Bytes),
formatBytes(bps),
formatBytes(s.Bytes), formatBytes(todo.Bytes),
itemsDone, itemsTodo)
status2 := fmt.Sprintf("ETA %s ", format_seconds(eta))
status2 := fmt.Sprintf("ETA %s ", formatSeconds(eta))
w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
if err == nil {
@@ -161,7 +161,7 @@ func newArchiveProgress(todo restic.Stat) *restic.Progress {
archiveProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
sec := uint64(d / time.Second)
fmt.Printf("\nduration: %s, %.2fMiB/s\n",
format_duration(d),
formatDuration(d),
float64(todo.Bytes)/float64(sec)/(1<<20))
}

View File

@@ -161,7 +161,7 @@ func fsckTree(opts CmdFsck, s restic.Server, blob restic.Blob) error {
return firstErr
}
func fsck_snapshot(opts CmdFsck, s restic.Server, id backend.ID) error {
func fsckSnapshot(opts CmdFsck, s restic.Server, id backend.ID) error {
debug.Log("restic.fsck", "checking snapshot %v\n", id)
sn, err := restic.LoadSnapshot(s, id)
@@ -211,7 +211,7 @@ func (cmd CmdFsck) Execute(args []string) error {
fmt.Fprintf(os.Stderr, "invalid snapshot id %v\n", name)
}
err = fsck_snapshot(cmd, s, id)
err = fsckSnapshot(cmd, s, id)
if err != nil {
fmt.Fprintf(os.Stderr, "check for snapshot %v failed\n", id)
}
@@ -235,7 +235,7 @@ func (cmd CmdFsck) Execute(args []string) error {
continue
}
err = fsck_snapshot(cmd, s, id)
err = fsckSnapshot(cmd, s, id)
if err != nil {
fmt.Fprintf(os.Stderr, "check for snapshot %v failed\n", id)
firstErr = err

View File

@@ -21,7 +21,7 @@ func init() {
}
}
func list_keys(s restic.Server) error {
func listKeys(s restic.Server) error {
tab := NewTable()
tab.Header = fmt.Sprintf(" %-10s %-10s %-10s %s", "ID", "User", "Host", "Created")
tab.RowFormat = "%s%-10s %-10s %-10s %s"
@@ -56,7 +56,7 @@ func list_keys(s restic.Server) error {
return nil
}
func add_key(s restic.Server) error {
func addKey(s restic.Server) error {
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
@@ -74,7 +74,7 @@ func add_key(s restic.Server) error {
return nil
}
func delete_key(s restic.Server, name string) error {
func deleteKey(s restic.Server, name string) error {
if name == s.Key().Name() {
return errors.New("refusing to remove key currently used to access repository")
}
@@ -88,7 +88,7 @@ func delete_key(s restic.Server, name string) error {
return nil
}
func change_password(s restic.Server) error {
func changePassword(s restic.Server) error {
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
@@ -129,18 +129,18 @@ func (cmd CmdKey) Execute(args []string) error {
switch args[0] {
case "list":
return list_keys(s)
return listKeys(s)
case "add":
return add_key(s)
return addKey(s)
case "rm":
id, err := backend.Find(s, backend.Key, args[1])
if err != nil {
return err
}
return delete_key(s, id)
return deleteKey(s, id)
case "change":
return change_password(s)
return changePassword(s)
}
return nil

View File

@@ -21,7 +21,7 @@ func init() {
}
}
func print_node(prefix string, n *restic.Node) string {
func printNode(prefix string, n *restic.Node) string {
switch n.Type {
case "file":
return fmt.Sprintf("%s %5d %5d %6d %s %s",
@@ -37,14 +37,14 @@ func print_node(prefix string, n *restic.Node) string {
}
}
func print_tree(prefix string, s restic.Server, blob restic.Blob) error {
func printTree(prefix string, s restic.Server, blob restic.Blob) error {
tree, err := restic.LoadTree(s, blob)
if err != nil {
return err
}
for _, entry := range tree.Nodes {
fmt.Println(print_node(prefix, entry))
fmt.Println(printNode(prefix, entry))
if entry.Type == "dir" && entry.Subtree != nil {
b, err := tree.Map.FindID(entry.Subtree)
@@ -52,7 +52,7 @@ func print_tree(prefix string, s restic.Server, blob restic.Blob) error {
return err
}
err = print_tree(filepath.Join(prefix, entry.Name), s, b)
err = printTree(filepath.Join(prefix, entry.Name), s, b)
if err != nil {
return err
}
@@ -93,5 +93,5 @@ func (cmd CmdLs) Execute(args []string) error {
fmt.Printf("snapshot of %v at %s:\n", sn.Paths, sn.Time)
return print_tree("", s, sn.Tree)
return printTree("", s, sn.Tree)
}