starting on the commit logic
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/asdine/storm"
|
||||
"github.com/asdine/storm/q"
|
||||
)
|
||||
|
||||
// ConfigureDB sets up bolt and Storm according to the path of the database
|
||||
@@ -187,3 +188,39 @@ func (db *DB) UpdateDescription(patchID int, description string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchCommitByNumber fetches the commit number of the passed branch
|
||||
func (db *DB) FetchCommitByNumber(branch string, commitNumber string) (commitResult Commit, err error) {
|
||||
var commit Commit
|
||||
db.Info().Msgf("fetching commit by number: %s in branch: %s", commitNumber, branch)
|
||||
query := db.Select(q.And(q.Eq("Branch", branch), q.Eq("Number", commitNumber)))
|
||||
err = query.Find(&commit)
|
||||
if err != nil {
|
||||
db.Err(err).Msgf("Failed to find commit by number: %s on branch: %s", commitNumber, branch)
|
||||
return commit, err
|
||||
}
|
||||
return commit, nil
|
||||
}
|
||||
|
||||
// FetchCommitByHash fetches a single commit on any branch by hash //TODO: Hash collision?
|
||||
func (db *DB) FetchCommitByHash(hash string) (commitResult Commit, err error) {
|
||||
var commit Commit
|
||||
db.Info().Msgf("Searching for commit by hash: %s", hash)
|
||||
if err := db.One("CommitHash", hash, &commit); err != nil {
|
||||
db.Err(err).Msgf("Failed to find commit by hash: %s", hash)
|
||||
return commit, err
|
||||
}
|
||||
return commit, nil
|
||||
}
|
||||
|
||||
// FetchLastCommitOnBranch gets the latest commit to the provided branch
|
||||
func (db *DB) FetchLastCommitOnBranch(branch string) (commitResult Commit, err error) {
|
||||
var commit Commit
|
||||
db.Info().Msgf("Fetching last commit on branch: %s", branch)
|
||||
query := db.Select(q.Eq("Branch", branch)) //Selecting everything that applies to that branch
|
||||
err = query.OrderBy("Number").Reverse().First(&commit) // Getting the last entry by number
|
||||
if err != nil {
|
||||
db.Err(err).Msgf("Failed to find last commit on branch: %s", branch)
|
||||
}
|
||||
return commit, nil
|
||||
}
|
||||
|
@@ -8,6 +8,8 @@ type Commit struct {
|
||||
TrackedFiles []File // All of the tracked files for this commit
|
||||
Date string
|
||||
Version string //User can tag a commit with a version number
|
||||
Branch string //Branch this commit belongs to
|
||||
Number string // The commit number
|
||||
|
||||
}
|
||||
|
||||
|
@@ -8,21 +8,9 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
logger "github.com/apsdehal/go-logger"
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
)
|
||||
|
||||
var log *logger.Logger
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
log, err = logger.New("utilities logger", 1, os.Stdout)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.SetFormat("[%{module}] [%{level}] %{message}")
|
||||
log.Info("Utilities logger Created")
|
||||
}
|
||||
|
||||
// CompressIntArray compresses an array of integers into a buffer
|
||||
func CompressIntArray(arry []int64, compressionBuffer *bytes.Buffer) (float64, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -83,22 +71,28 @@ func InitiateDirectory(directory string) {
|
||||
// For the keys-folder we need to check if the folder exists...
|
||||
checkDir, err := IsDirectory(directory)
|
||||
if err != nil {
|
||||
log.ErrorF("Error checking for "+directory+" directory: %s\r\n", err)
|
||||
fmt.Println("Error checking for "+directory+" directory: %s\r\n", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if checkDir == true {
|
||||
log.Warning(directory + " already exists")
|
||||
fmt.Println(directory + " already exists")
|
||||
} else {
|
||||
// Create the directory.
|
||||
log.Info("Creating " + directory)
|
||||
fmt.Println("Creating " + directory)
|
||||
err = CreateDirectory(directory)
|
||||
if err != nil {
|
||||
log.ErrorF("Error creating the folder %s\r\n", err)
|
||||
fmt.Println("Error creating the folder %s\r\n", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CreateInitialCommit copies the files over and compresses them if they are not in the NoCompress struct
|
||||
func CreateInitialCommit(conf *clientconfig.Gvcconfig) {
|
||||
//Need to deduplicate so we aren't storing duplicates of files, storing all the files in one folder won't work, will need something like git
|
||||
}
|
||||
|
||||
func IsDirectory(path string) (bool, error) {
|
||||
|
||||
s, err := os.Stat(path) // returns an error if the path does not exist.
|
||||
|
@@ -6,11 +6,13 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/deranjer/gvc/common/database"
|
||||
engine "github.com/deranjer/gvc/common/engine"
|
||||
"github.com/rs/zerolog"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// NewManager creates a new manager interface that contains all the needed information to make changes to the repo
|
||||
@@ -31,12 +33,13 @@ func NewManager(rootDir string, version string, dbPath string, informer chan Ope
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("unable to create or open db: %s", err)
|
||||
}
|
||||
|
||||
var wg *sync.WaitGroup
|
||||
m := Manager{
|
||||
version,
|
||||
|
||||
//settings,
|
||||
log,
|
||||
wg,
|
||||
patcher,
|
||||
gvcDB,
|
||||
informer,
|
||||
@@ -160,6 +163,22 @@ func (m *Manager) prepareDatabaseForFile(tmpFile database.File) (int, error) {
|
||||
|
||||
}
|
||||
|
||||
func (m *Manager) BeginCommit(fileList []database.File, branch string) error {
|
||||
diffChannel := make(chan database.DiffObject)
|
||||
diffContext := context.Background()
|
||||
m.WaitGroup.Add(2)
|
||||
commit, err := m.dB.FetchLastCommitOnBranch(branch)
|
||||
if err != nil {
|
||||
m.Err(err).Msgf("unable to fetch last commit on branch, assuming first commit on branch", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) FetchCommitByNumber(branch string, commitNumber string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchTrackedFiles just grabbes all the files currently tracked in the repo
|
||||
func (m *Manager) FetchTrackedFiles() ([]database.File, error) {
|
||||
files, err := m.dB.RetrieveTrackedFiles()
|
||||
|
@@ -3,6 +3,7 @@ package manager
|
||||
//https://github.com/apsdehal/go-logger
|
||||
import (
|
||||
"os/user"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
database "github.com/deranjer/gvc/common/database"
|
||||
@@ -14,7 +15,7 @@ type Manager struct {
|
||||
Version string //What version of the client or server are we using
|
||||
//Settings *UserSettings
|
||||
*zerolog.Logger
|
||||
//*sync.WaitGroup
|
||||
*sync.WaitGroup
|
||||
//watcher engine.FileWatcher
|
||||
patcher engine.Patcher
|
||||
dB *database.DB
|
||||
|
Reference in New Issue
Block a user