Skip to content

Commit 7ef8a01

Browse files
committed
add p4charset to config file for both source and destination servers
* also address some linter issues * also errors start lowercase (hopefully doesn't break anyone's workflow?)
1 parent 636ff7a commit 7ef8a01

9 files changed

Lines changed: 75 additions & 65 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ Here's an example `config.toml` file:
4141
[source]
4242
p4port = "ssl:perforce.example.com:1667"
4343
p4user = "user"
44+
p4charset = "none"
4445
p4client = "user-UE4-Release-Latest-Minimal" # this needs to exist before running p4harmonize
4546

4647
# destination is the perforce server you want to update so that it matches the source
4748
[destination]
4849
p4port = "perforce.local:1666"
4950
p4user = "localuser"
51+
p4charset = "auto"
5052
new_client_name = "localuser-harmonize" # this will be created by p4harmonize
5153
new_client_root = "d:/p4/local/harmonize" # this will be created by p4harmonize
5254
new_client_stream = "//test/engine_epic" # this needs to already exist
@@ -110,11 +112,12 @@ Before opening a pull request, please run `mage longtest` and make sure it is pa
110112

111113
If your PR includes performance improvements, please include some benchmarks that show the benefits of your changes.
112114

113-
## Special Thanks!
115+
## Special Thanks
114116

115117
Thanks to [Bohdon Sayre](https://github.com/bohdon) and [Jørgen P. Tjernø](https://github.com/jorgenpt) for contributing time and code to help me fix my bugs and dramatically improve performance!
116118

117-
## TODO:
119+
## TODO
118120

121+
- add unicode vs non-unicode servers to longtest
119122
- run longtest via github actions?
120123
- test on a Mac (maybe with github actions?)

cmd/longtest/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func createLongtestLogger(filename string) (close func() error, log frog.Logger,
1111
// open file
1212
f, err := os.Create(filename)
1313
if err != nil {
14-
return nil, nil, fmt.Errorf("Error creating log file %s: %w", filename, err)
14+
return nil, nil, fmt.Errorf("error creating log file %s: %w", filename, err)
1515
}
1616

1717
// console logger

cmd/longtest/main.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
)
1717

1818
var Servers = []Server{
19-
{Src, "1661", "super", "UE4", "Release-4.20", "./p4/1"},
20-
{Src, "1662", "super", "UE4", "Release-4.20", "./p4/2"},
21-
{Dst, "1663", "super", "test", "engine", "./p4/3"},
22-
{Dst, "1664", "super", "test", "engine", "./p4/4"},
19+
{Src, "1661", "super", "none", "UE4", "Release-4.20", "./p4/1"},
20+
{Src, "1662", "super", "none", "UE4", "Release-4.20", "./p4/2"},
21+
{Dst, "1663", "super", "none", "test", "engine", "./p4/3"},
22+
{Dst, "1664", "super", "none", "test", "engine", "./p4/4"},
2323
}
2424

2525
func main() {
@@ -124,15 +124,15 @@ func bringUpServers(logParent frog.Logger, Servers []Server) {
124124
defer wg.Done()
125125
close, sh := createBshWithTransientLogger(log)
126126
defer close()
127-
pf := p4.New(sh, s.Port(), s.User(), "")
127+
pf := p4.New(sh, s.Port(), s.User(), s.Charset(), "")
128128
if s.IsSrc() {
129129
if err := setupSrc(sh, pf, s); err != nil {
130130
log.Error("error in setupSrc", frog.Err(err))
131131
return
132132
}
133133
} else {
134134
if err := setupDst(sh, pf, s); err != nil {
135-
log.Error("error in setupSrc", frog.Err(err))
135+
log.Error("error in setupDst", frog.Err(err))
136136
return
137137
}
138138
}
@@ -172,7 +172,7 @@ func runTwoServers(log frog.Logger, configSuffix int, src, dst Server, cl int64,
172172
for i := 0; i < expectedRuns; i++ {
173173

174174
// dst's client must not already exist
175-
if err := p4.New(sh, dst.Port(), dst.User(), "").DeleteClient(dst.Client()); err != nil {
175+
if err := p4.New(sh, dst.Port(), dst.User(), dst.Charset(), "").DeleteClient(dst.Client()); err != nil {
176176
return fmt.Errorf("error deleting client %s from %s: %w", dst.Client(), dst.Port(), err)
177177
}
178178
// dst's root folder must be empty
@@ -189,8 +189,8 @@ func runTwoServers(log frog.Logger, configSuffix int, src, dst Server, cl int64,
189189
return fmt.Errorf("p4harmonize with config %s: %w", cfgName, err)
190190
}
191191

192-
p4src := p4.New(sh, src.Port(), src.User(), src.Client())
193-
p4dst := p4.New(sh, dst.Port(), dst.User(), dst.Client())
192+
p4src := p4.New(sh, src.Port(), src.User(), src.Charset(), src.Client())
193+
p4dst := p4.New(sh, dst.Port(), dst.User(), dst.Charset(), dst.Client())
194194

195195
// submit p4harmonize's changes
196196
if err := p4dst.SubmitChangelist(cl); err != nil {
@@ -245,12 +245,6 @@ func buildDepotFilesLists(p4src, p4dst *p4.P4) (srcFiles, dstFiles string, err e
245245
return sb.String(), nil
246246
}
247247

248-
type result struct {
249-
pf *p4.P4
250-
list string
251-
err error
252-
}
253-
254248
var wg sync.WaitGroup
255249
wg.Add(2)
256250

@@ -269,13 +263,13 @@ func buildDepotFilesLists(p4src, p4dst *p4.P4) (srcFiles, dstFiles string, err e
269263
wg.Wait()
270264

271265
if srcErr != nil && dstErr != nil {
272-
return "", "", fmt.Errorf("Errors listing depot files from both %s and %s: %v; %v", p4src.Port, p4dst.Port, srcErr, dstErr)
266+
return "", "", fmt.Errorf("errors listing depot files from both %s and %s: %v; %v", p4src.Port, p4dst.Port, srcErr, dstErr)
273267
}
274268
if srcErr != nil {
275-
return "", "", fmt.Errorf("Error listing depot files from %s: %w", p4src.Port, srcErr)
269+
return "", "", fmt.Errorf("error listing depot files from %s: %w", p4src.Port, srcErr)
276270
}
277271
if dstErr != nil {
278-
return "", "", fmt.Errorf("Error listing depot files from %s: %w", p4dst.Port, dstErr)
272+
return "", "", fmt.Errorf("error listing depot files from %s: %w", p4dst.Port, dstErr)
279273
}
280274

281275
return srcList, dstList, nil

cmd/longtest/server.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ const (
1212
)
1313

1414
type Server struct {
15-
t ServerType
16-
port string
17-
user string
18-
depot string
19-
stream string
20-
root string
15+
t ServerType
16+
port string
17+
user string
18+
charset string
19+
depot string
20+
stream string
21+
root string
2122
}
2223

2324
func (s *Server) IsSrc() bool {
@@ -32,6 +33,10 @@ func (s *Server) Port() string {
3233
return s.port
3334
}
3435

36+
func (s *Server) Charset() string {
37+
return s.charset
38+
}
39+
3540
func (s *Server) User() string {
3641
return s.user
3742
}

cmd/p4harmonize/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func mainExit() int {
9595
start := time.Now()
9696
log, close := MakeLogger(frog.New(frog.Auto, frog.POLevel(false), frog.POFieldsLeftMsgRight, frog.POFieldIndent(10)))
9797
defer func() {
98-
dur := time.Now().Sub(start)
98+
dur := time.Since(start)
9999
log.Info("Running Time: %v", dur)
100100
close()
101101
}()

cmd/p4harmonize/update.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Harmonize(log Logger, cfg config.Config) error {
4949

5050
logDst := log.Dst()
5151
shDst := MakeLoggingBsh(logDst)
52-
p4dst := p4.New(shDst, cfg.Dst.P4Port, cfg.Dst.P4User, "")
52+
p4dst := p4.New(shDst, cfg.Dst.P4Port, cfg.Dst.P4User, cfg.Dst.P4Charset, "")
5353

5454
logDst.Info("Retrieving info for server %s", p4dst.DisplayName())
5555
info, err := p4dst.Info()
@@ -94,7 +94,7 @@ func Harmonize(log Logger, cfg config.Config) error {
9494
// block until sync source sync completes
9595
srcRes := <-chSrc
9696
chSrc = nil
97-
if srcRes.Success != true {
97+
if !srcRes.Success {
9898
return fmt.Errorf("error syncing from source server")
9999
}
100100

@@ -273,7 +273,7 @@ func preFlightChecks(log Logger, cfg config.Config) bool {
273273

274274
logSrc := log.Src()
275275
shSrc := MakeLoggingBsh(logSrc)
276-
p4src := p4.New(shSrc, cfg.Src.P4Port, cfg.Src.P4User, "")
276+
p4src := p4.New(shSrc, cfg.Src.P4Port, cfg.Src.P4User, cfg.Src.P4Charset, "")
277277

278278
if needsLogin, err := p4src.NeedsLogin(); err != nil {
279279
logSrc.Error("Error checking login status on %s: %v", p4src.Port, err)
@@ -285,7 +285,7 @@ func preFlightChecks(log Logger, cfg config.Config) bool {
285285

286286
logDst := log.Dst()
287287
shDst := MakeLoggingBsh(logDst)
288-
p4dst := p4.New(shDst, cfg.Dst.P4Port, cfg.Dst.P4User, "")
288+
p4dst := p4.New(shDst, cfg.Dst.P4Port, cfg.Dst.P4User, cfg.Dst.P4Charset, "")
289289

290290
if needsLogin, err := p4dst.NeedsLogin(); err != nil {
291291
logDst.Error("Error checking login status on %s: %v", p4dst.Port, err)
@@ -329,7 +329,7 @@ func preFlightChecks(log Logger, cfg config.Config) bool {
329329
// srcSyncAndList connects to the source perforce server, syncs to head, then
330330
// requests a list of all file names and types.
331331
func srcSyncAndList(logSrc Logger, shSrc *bsh.Bsh, cfg config.Config) srcThreadResults {
332-
p4src := p4.New(shSrc, cfg.Src.P4Port, cfg.Src.P4User, cfg.Src.P4Client)
332+
p4src := p4.New(shSrc, cfg.Src.P4Port, cfg.Src.P4User, cfg.Src.P4Charset, cfg.Src.P4Client)
333333

334334
spec, err := p4src.GetClientSpec()
335335
if err != nil {
@@ -495,7 +495,7 @@ func PerforceFileCopy(src, dst, filetype string) error {
495495
func verifyAndCopy(srcPath, dstPath string) error {
496496
srcInfo, err := os.Stat(srcPath)
497497
if err != nil {
498-
return fmt.Errorf("Unable to stat '%s': %w", srcPath, err)
498+
return fmt.Errorf("unable to stat '%s': %w", srcPath, err)
499499
}
500500

501501
if !srcInfo.Mode().IsRegular() {
@@ -505,26 +505,26 @@ func verifyAndCopy(srcPath, dstPath string) error {
505505

506506
dstDir := filepath.Dir(dstPath)
507507
if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
508-
return fmt.Errorf("Unable to mkdir '%s': %w", dstDir, err)
508+
return fmt.Errorf("unable to mkdir '%s': %w", dstDir, err)
509509
}
510510

511511
s, err := os.Open(srcPath)
512512
if err != nil {
513-
return fmt.Errorf("Unable to open '%s': %w", srcPath, err)
513+
return fmt.Errorf("unable to open '%s': %w", srcPath, err)
514514
}
515515
defer s.Close()
516516

517517
d, err := os.Create(dstPath)
518518
if err != nil {
519-
return fmt.Errorf("Unable to create '%s': %w", dstPath, err)
519+
return fmt.Errorf("unable to create '%s': %w", dstPath, err)
520520
}
521521
defer d.Close()
522522
n, err := io.Copy(d, s)
523523
if err != nil {
524-
return fmt.Errorf("Unable to copy '%s' to '%s': %w", srcPath, dstPath, err)
524+
return fmt.Errorf("unable to copy '%s' to '%s': %w", srcPath, dstPath, err)
525525
}
526526
if n != srcSize {
527-
return fmt.Errorf("Expected '%s' to copy %d bytes to '%s', but only %d were copied", srcPath, n, dstPath, srcSize)
527+
return fmt.Errorf("expected '%s' to copy %d bytes to '%s', but only %d were copied", srcPath, n, dstPath, srcSize)
528528
}
529529
return nil
530530
}

internal/config/config.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import (
1010
)
1111

1212
type Source struct {
13-
P4Port string `toml:"p4port"`
14-
P4User string `toml:"p4user"`
15-
P4Client string `toml:"p4client"`
13+
P4Port string `toml:"p4port"`
14+
P4User string `toml:"p4user"`
15+
P4Charset string `toml:"p4charset"`
16+
P4Client string `toml:"p4client"`
1617
}
1718

1819
type Destination struct {
1920
P4Port string `toml:"p4port"`
2021
P4User string `toml:"p4user"`
22+
P4Charset string `toml:"p4charset"`
2123
ClientName string `toml:"new_client_name"`
2224
ClientRoot string `toml:"new_client_root"`
2325
ClientStream string `toml:"new_client_stream"`
@@ -38,11 +40,11 @@ func (c *Config) Filename() string {
3840
func (c *Config) WriteToFile(path string) error {
3941
f, err := os.Create(path)
4042
if err != nil {
41-
return fmt.Errorf("Error opening '%s': %w", path, err)
43+
return fmt.Errorf("error opening '%s': %w", path, err)
4244
}
4345

4446
if err := toml.NewEncoder(f).Encode(c); err != nil {
45-
return fmt.Errorf("Error encoding/writing '%s': %w", path, err)
47+
return fmt.Errorf("error encoding/writing '%s': %w", path, err)
4648
}
4749

4850
return nil
@@ -53,7 +55,7 @@ func (c *Config) WriteToFile(path string) error {
5355
func LoadFromFile(path string) (Config, error) {
5456
f, err := os.Open(path)
5557
if err != nil {
56-
return Config{}, fmt.Errorf("Error opening '%s': %w", path, err)
58+
return Config{}, fmt.Errorf("error opening '%s': %w", path, err)
5759
}
5860
defer f.Close()
5961
cfg, err := loadConfig(f)

internal/p4/options.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ type oChangelist struct {
1818
CL int64
1919
}
2020

21-
func (_ oChangelist) isOption() {}
22-
func (_ oChangelist) String() string { return "Changelist" }
21+
func (oChangelist) isOption() {}
22+
func (oChangelist) String() string { return "Changelist" }
2323

2424
// Type holds a filetype as a string
2525

@@ -31,32 +31,32 @@ type oType struct {
3131
Type string
3232
}
3333

34-
func (_ oType) isOption() {}
35-
func (_ oType) String() string { return "Type" }
34+
func (oType) isOption() {}
35+
func (oType) String() string { return "Type" }
3636

3737
// Keep means to keep local files on disk (don't make local changes, just update the server)
3838

3939
var Keep oKeep
4040

4141
type oKeep struct{}
4242

43-
func (_ oKeep) isOption() {}
44-
func (_ oKeep) String() string { return "Keep" }
43+
func (oKeep) isOption() {}
44+
func (oKeep) String() string { return "Keep" }
4545

4646
// Do not perform any ignore checking, i.e. ignore any settings specified by P4IGNORE.
4747

4848
var DoNotIgnore oDoNotIgnore
4949

5050
type oDoNotIgnore struct{}
5151

52-
func (_ oDoNotIgnore) isOption() {}
53-
func (_ oDoNotIgnore) String() string { return "DoNotIgnore" }
52+
func (oDoNotIgnore) isOption() {}
53+
func (oDoNotIgnore) String() string { return "DoNotIgnore" }
5454

5555
// Allow wildcards in file names (see [p4 add](https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_add.html))
5656

5757
var AllowWildcards oAllowWildcards
5858

5959
type oAllowWildcards struct{}
6060

61-
func (_ oAllowWildcards) isOption() {}
62-
func (_ oAllowWildcards) String() string { return "AllowWildcards" }
61+
func (oAllowWildcards) isOption() {}
62+
func (oAllowWildcards) String() string { return "AllowWildcards" }

0 commit comments

Comments
 (0)