Skip to content

Commit

Permalink
[#251] Change p4 -d default directory from p4 rootDir to TCR base dir…
Browse files Browse the repository at this point in the history
… for p4 diff and reconcile
  • Loading branch information
mengdaming committed Feb 9, 2023
1 parent 3585ce3 commit 4e39712
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/vcs/p4/p4_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (p *p4Impl) Add(paths ...string) error {
} else {
p4Args = append(p4Args, paths...)
}
return p.traceP4(p4Args...)
return p.traceP4FromBaseDir(p4Args...)
}

type changeList struct {
Expand Down Expand Up @@ -213,7 +213,7 @@ func (*p4Impl) UnStash(_ bool) error {
// Diff returns the list of files modified since last commit with diff info for each file
func (p *p4Impl) Diff() (diffs vcs.FileDiffs, err error) {
var p4Output []byte
p4Output, err = p.runP4("diff", "-f", "-Od", "-dw", "-ds")
p4Output, err = p.runP4FromBaseDir("diff", "-f", "-Od", "-dw", "-ds")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -275,12 +275,24 @@ func (p *p4Impl) traceP4(args ...string) error {
return p.traceP4Function(p.buildP4Args(args...)...)
}

// traceP4 runs a p4 command and traces its output.
// The command is launched from the p4 root directory
func (p *p4Impl) traceP4FromBaseDir(args ...string) error {
return p.traceP4Function(p.buildP4ArgsWithBaseDir(args...)...)
}

// runP4 calls p4 command in a separate process and returns its output traces
// The command is launched from the p4 root directory
func (p *p4Impl) runP4(args ...string) (output []byte, err error) {
return p.runP4Function(p.buildP4Args(args...)...)
}

// runP4 calls p4 command in a separate process and returns its output traces
// The command is launched from the p4 root directory
func (p *p4Impl) runP4FromBaseDir(args ...string) (output []byte, err error) {
return p.runP4Function(p.buildP4ArgsWithBaseDir(args...)...)
}

func (p *p4Impl) runPipedP4(toCmd shell.Command, args ...string) (output []byte, err error) {
return p.runPipedP4Function(toCmd, p.buildP4Args(args...)...)
}
Expand All @@ -289,6 +301,10 @@ func (p *p4Impl) buildP4Args(args ...string) []string {
return append([]string{"-d", p.GetRootDir(), "-c", p.clientName}, args...)
}

func (p *p4Impl) buildP4ArgsWithBaseDir(args ...string) []string {
return append([]string{"-d", p.baseDir, "-c", p.clientName}, args...)
}

func (p *p4Impl) createChangeList(messages ...string) (*changeList, error) {
// Command: p4 --field "Description=<message>" change -o | p4 change -i
out, err := p.runPipedP4(newP4Command(p.buildP4Args("change", "-i")...),
Expand Down

0 comments on commit 4e39712

Please sign in to comment.