Commit 790c9b59 authored by Russ Cox's avatar Russ Cox

codereview: new commands

	* clpatch
	* download
	* submit, on behalf of clpatch

stir hgpatch to fix a few bugs

R=r
CC=go-dev
http://go/go-review/1016051
parent 9786b3f1
This diff is collapsed.
...@@ -18,8 +18,11 @@ import ( ...@@ -18,8 +18,11 @@ import (
"strings"; "strings";
) )
var checkSync = flag.Bool("checksync", true, "check whether repository is out of sync")
func usage() { func usage() {
fmt.Fprintf(os.Stderr, "usage: hgpatch [patchfile]\n"); fmt.Fprintf(os.Stderr, "usage: hgpatch [options] [patchfile]\n");
flag.PrintDefaults();
os.Exit(2); os.Exit(2);
} }
...@@ -49,11 +52,8 @@ func main() { ...@@ -49,11 +52,8 @@ func main() {
chk(err); chk(err);
chk(os.Chdir(root)); chk(os.Chdir(root));
op, err := pset.Apply(io.ReadFile);
chk(err);
// Make sure there are no pending changes on the server. // Make sure there are no pending changes on the server.
if hgIncoming() { if *checkSync && hgIncoming() {
fmt.Fprintf(os.Stderr, "incoming changes waiting; run hg sync first\n"); fmt.Fprintf(os.Stderr, "incoming changes waiting; run hg sync first\n");
os.Exit(2); os.Exit(2);
} }
...@@ -66,16 +66,15 @@ func main() { ...@@ -66,16 +66,15 @@ func main() {
dirty[f] = 1; dirty[f] = 1;
} }
conflict := make(map[string]int); conflict := make(map[string]int);
for i := range op { for _, f := range pset.File {
o := &op[i]; if f.Verb == patch.Delete || f.Verb == patch.Rename {
if o.Verb == patch.Delete || o.Verb == patch.Rename { if _, ok := dirty[f.Src]; ok {
if _, ok := dirty[o.Src]; ok { conflict[f.Src] = 1;
conflict[o.Src] = 1;
} }
} }
if o.Verb != patch.Delete { if f.Verb != patch.Delete {
if _, ok := dirty[o.Dst]; ok { if _, ok := dirty[f.Dst]; ok {
conflict[o.Dst] = 1; conflict[f.Dst] = 1;
} }
} }
} }
...@@ -87,7 +86,11 @@ func main() { ...@@ -87,7 +86,11 @@ func main() {
os.Exit(2); os.Exit(2);
} }
// Apply to local copy: order of commands matters. // Apply changes in memory.
op, err := pset.Apply(io.ReadFile);
chk(err);
// Write changes to disk copy: order of commands matters.
// Accumulate undo log as we go, in case there is an error. // Accumulate undo log as we go, in case there is an error.
// Also accumulate list of modified files to print at end. // Also accumulate list of modified files to print at end.
changed := make(map[string]int); changed := make(map[string]int);
...@@ -343,7 +346,7 @@ func run(argv []string, input []byte) (out string, err os.Error) { ...@@ -343,7 +346,7 @@ func run(argv []string, input []byte) (out string, err os.Error) {
} }
lookPathCache[argv[0]] = prog; lookPathCache[argv[0]] = prog;
} }
fmt.Fprintf(os.Stderr, "%v\n", argv); // fmt.Fprintf(os.Stderr, "%v\n", argv);
var cmd *exec.Cmd; var cmd *exec.Cmd;
if len(input) == 0 { if len(input) == 0 {
cmd, err = exec.Run(prog, argv, os.Environ(), exec.DevNull, exec.Pipe, exec.MergeWithStdout); cmd, err = exec.Run(prog, argv, os.Environ(), exec.DevNull, exec.Pipe, exec.MergeWithStdout);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment