Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 1ee16cf

Browse files
committed
Further minor code and comment cleanup
1 parent da506e8 commit 1ee16cf

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

common/memcache.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"crypto/md5"
66
"encoding/gob"
77
"encoding/hex"
8-
"errors"
98
"fmt"
109
"io"
1110
"log"
@@ -49,7 +48,7 @@ func ConnectCache() error {
4948
cacheTest := memcache.Item{Key: "connecttext", Value: []byte("1"), Expiration: 10}
5049
err := memCache.Set(&cacheTest)
5150
if err != nil {
52-
return errors.New(fmt.Sprintf("Couldn't connect to memcached server: %s", err))
51+
return fmt.Errorf("Couldn't connect to memcached server: %s", err)
5352
}
5453

5554
// Log successful connection message for Memcached

common/userinput.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// These functions extract (and validate) user provided form data.
21
package common
32

43
import (
@@ -114,7 +113,7 @@ func GetFormBranch(r *http.Request) (string, error) {
114113
}
115114
err = ValidateBranchName(b)
116115
if err != nil {
117-
return "", errors.New(fmt.Sprintf("Invalid branch name: '%v'", b))
116+
return "", fmt.Errorf("Invalid branch name: '%v'", b)
118117
}
119118
return b, nil
120119
}

common/util.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ import (
1818
)
1919

2020
// AddDatabase is handles database upload processing
21-
func AddDatabase(r *http.Request, loggedInUser string, dbOwner string, dbFolder string, dbName string,
22-
createBranch bool, branchName string, commitID string, public bool, licenceName string, commitMsg string,
23-
sourceURL string, newDB io.Reader, serverSw string, lastModified time.Time, commitTime time.Time,
24-
authorName string, authorEmail string, committerName string, committerEmail string, otherParents []string,
25-
dbSha string) (numBytes int64, newCommitID string, err error) {
21+
func AddDatabase(r *http.Request, loggedInUser, dbOwner, dbFolder, dbName string, createBranch bool, branchName,
22+
commitID string, public bool, licenceName, commitMsg, sourceURL string, newDB io.Reader, serverSw string,
23+
lastModified, commitTime time.Time, authorName, authorEmail, committerName, committerEmail string,
24+
otherParents []string, dbSha string) (numBytes int64, newCommitID string, err error) {
2625

2726
// Create a temporary file to store the database in
2827
tempDB, err := ioutil.TempFile(Conf.DiskCache.Directory, "dbhub-upload-")
2928
if err != nil {
30-
log.Printf("Error creating temporary file. User: '%s', Database: '%s%s%s', Filename: '%s', Error: %v\n",
31-
loggedInUser, dbOwner, dbFolder, dbName, tempDB.Name(), err)
29+
log.Printf("Error creating temporary file. User: '%s', Database: '%s%s%s', Error: %v\n", loggedInUser,
30+
dbOwner, dbFolder, dbName, err)
3231
return 0, "", err
3332
}
3433
tempDBName := tempDB.Name()
@@ -401,7 +400,7 @@ func AddDatabase(r *http.Request, loggedInUser string, dbOwner string, dbFolder
401400
}
402401

403402
// CommitLicenceSHA returns the licence used by the database in a given commit
404-
func CommitLicenceSHA(dbOwner string, dbFolder string, dbName string, commitID string) (licenceSHA string, err error) {
403+
func CommitLicenceSHA(dbOwner, dbFolder, dbName, commitID string) (licenceSHA string, err error) {
405404
commits, err := GetCommitList(dbOwner, dbFolder, dbName)
406405
if err != nil {
407406
return "", err
@@ -443,7 +442,7 @@ func CreateDBTreeID(entries []DBTreeEntry) string {
443442
for _, j := range entries {
444443
b.WriteString(string(j.EntryType))
445444
b.WriteByte(0)
446-
b.WriteString(string(j.LicenceSHA))
445+
b.WriteString(j.LicenceSHA)
447446
b.WriteByte(0)
448447
b.WriteString(j.Sha256)
449448
b.WriteByte(0)
@@ -459,7 +458,7 @@ func CreateDBTreeID(entries []DBTreeEntry) string {
459458

460459
// DeleteBranchHistory safely removes the commit history for a branch, from the head of the branch back to (but not
461460
// including) the specified commit. The new branch head will be at the commit ID specified
462-
func DeleteBranchHistory(dbOwner string, dbFolder string, dbName string, branchName string, commitID string) (isolatedTags []string, isolatedRels []string, err error) {
461+
func DeleteBranchHistory(dbOwner, dbFolder, dbName, branchName, commitID string) (isolatedTags, isolatedRels []string, err error) {
463462
// Make sure the requested commit is in the history for the specified branch
464463
ok, err := IsCommitInBranchHistory(dbOwner, dbFolder, dbName, branchName, commitID)
465464
if err != nil {
@@ -732,7 +731,7 @@ func DeleteBranchHistory(dbOwner string, dbFolder string, dbName string, branchN
732731
}
733732

734733
// Remove any no-longer-needed commits
735-
// TODO: We may want to consider clearing any memcache entries for the deleted commits too
734+
// TODO: We may want to consider clearing any Memcache entries for the deleted commits too
736735
for cid, del := range checkList {
737736
if del == true {
738737
delete(commitList, cid)
@@ -745,8 +744,8 @@ func DeleteBranchHistory(dbOwner string, dbFolder string, dbName string, branchN
745744
// GetCommonAncestorCommits determines the common ancestor commit (if any) between a source and destination branch.
746745
// Returns the commit ID of the ancestor and a slice of the commits between them. If no common ancestor exists, the
747746
// returned ancestorID will be an empty string. Created for use by our Merge Request functions.
748-
func GetCommonAncestorCommits(srcOwner string, srcFolder string, srcDBName string, srcBranch string, destOwner string,
749-
destFolder string, destName string, destBranch string) (ancestorID string, commitList []CommitEntry, err error, errType int) {
747+
func GetCommonAncestorCommits(srcOwner, srcFolder, srcDBName, srcBranch, destOwner, destFolder, destName,
748+
destBranch string) (ancestorID string, commitList []CommitEntry, errType int, err error) {
750749

751750
// To determine the common ancestor, we retrieve the source and destination commit lists, then starting from the
752751
// end of the source list, step backwards looking for a matching ID in the destination list.
@@ -825,7 +824,7 @@ func GetCurrentFunctionName() (FuncName string) {
825824
}
826825

827826
// IsCommitInBranchHistory checks if a given commit ID is in the history of the given branch
828-
func IsCommitInBranchHistory(dbOwner string, dbFolder string, dbName string, branchName string, commitID string) (bool, error) {
827+
func IsCommitInBranchHistory(dbOwner, dbFolder, dbName, branchName, commitID string) (bool, error) {
829828
// Get the commit list for the database
830829
commitList, err := GetCommitList(dbOwner, dbFolder, dbName)
831830
if err != nil {
@@ -934,12 +933,11 @@ func RandomString(length int) string {
934933
for i := range randomString {
935934
randomString[i] = alphaNum[rand.Intn(len(alphaNum))]
936935
}
937-
938936
return string(randomString)
939937
}
940938

941939
// StatusUpdateCheck checks if a status update for the user exists for a given discussion or MR, and if so then removes it
942-
func StatusUpdateCheck(dbOwner string, dbFolder string, dbName string, thisID int, userName string) (numStatusUpdates int, err error) {
940+
func StatusUpdateCheck(dbOwner, dbFolder, dbName string, thisID int, userName string) (numStatusUpdates int, err error) {
943941
var lst map[string][]StatusUpdateEntry
944942
lst, err = StatusUpdates(userName)
945943
if err != nil {

common/validate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ var (
2121
regexPGTable = regexp.MustCompile(`^[a-z,A-Z,0-9,\.,\-,\_,\(,\),\ ]+$`)
2222
regexUsername = regexp.MustCompile(`^[a-z,A-Z,0-9,\.,\-,\_]+$`)
2323

24-
// For input validation
24+
// Validate is used for input validation
2525
Validate *valid.Validate
2626
)
2727

28+
// VisGetFields is used when validating input
2829
type VisGetFields struct {
2930
VisName string `validate:"required,visname,min=1,max=63"` // 63 char limit seems reasonable
3031
}

webui/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ func createMergeHandler(w http.ResponseWriter, r *http.Request) {
975975
SourceOwner: srcOwner,
976976
}
977977
var ancestorID string
978-
ancestorID, mrDetails.Commits, err, _ = com.GetCommonAncestorCommits(srcOwner, srcFolder, srcDBName, srcBranch,
978+
ancestorID, mrDetails.Commits, _, err = com.GetCommonAncestorCommits(srcOwner, srcFolder, srcDBName, srcBranch,
979979
destOwner, destFolder, destDBName, destBranch)
980980
if err != nil {
981981
w.WriteHeader(http.StatusInternalServerError)
@@ -2662,7 +2662,7 @@ func diffCommitListHandler(w http.ResponseWriter, r *http.Request) {
26622662
}
26632663

26642664
// Get the commit list diff
2665-
ancestorID, cList, err, errType := com.GetCommonAncestorCommits(srcOwner, srcFolder, srcDBName, srcBranch, destOwner,
2665+
ancestorID, cList, errType, err := com.GetCommonAncestorCommits(srcOwner, srcFolder, srcDBName, srcBranch, destOwner,
26662666
destFolder, destDBName, destBranch)
26672667
if err != nil && errType != http.StatusBadRequest {
26682668
w.WriteHeader(http.StatusInternalServerError)

webui/pages.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ func comparePage(w http.ResponseWriter, r *http.Request) {
598598

599599
// If the initially chosen source and destinations can be directly applied, fill out the initial commit list entries
600600
// for display to the user
601-
ancestorID, cList, err, errType := com.GetCommonAncestorCommits(dbOwner, dbFolder, dbName,
601+
ancestorID, cList, errType, err := com.GetCommonAncestorCommits(dbOwner, dbFolder, dbName,
602602
pageData.SourceDBDefaultBranch, pageData.DestOwner, pageData.DestFolder, pageData.DestDBName,
603603
pageData.DestDBDefaultBranch)
604604
if err != nil && errType != http.StatusBadRequest {
@@ -2537,7 +2537,7 @@ func mergePage(w http.ResponseWriter, r *http.Request) {
25372537
} else {
25382538
// Check if the source branch can still be applied to the destination, and also check for new/changed
25392539
// commits
2540-
ancestorID, newCommitList, err, _ := com.GetCommonAncestorCommits(mr.MRDetails.SourceOwner,
2540+
ancestorID, newCommitList, _, err := com.GetCommonAncestorCommits(mr.MRDetails.SourceOwner,
25412541
mr.MRDetails.SourceFolder, mr.MRDetails.SourceDBName, mr.MRDetails.SourceBranch, dbOwner, dbFolder,
25422542
dbName, mr.MRDetails.DestBranch)
25432543
if err != nil {

0 commit comments

Comments
 (0)