starting work on new commit logic
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/asdine/storm/q"
|
||||
@@ -200,6 +201,7 @@ func (db *DB) FetchLastCommitOnBranch(branch string) (commitResult Commit, err e
|
||||
db.Err(err).Msgf("Failed to find last commit on branch: %s", branch)
|
||||
return commit, err
|
||||
}
|
||||
db.Info().Msgf("Last commit was of number: %d Last Commit Hash was: %s Last commit occurred on date: %s", commit.Number, hex.EncodeToString(commit.CommitHash), commit.Date)
|
||||
return commit, nil
|
||||
}
|
||||
|
||||
|
@@ -49,3 +49,46 @@ func (m *Manager) CreateInitialCommit(fileList []database.File, branch string, c
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// CreateCommit creates a new commit by running diffs on files, compressing, etc, as needed
|
||||
func (m *Manager) CreateCommit(changedFiles []database.File, trackedFiles []database.File, branch string, commitMessage string, commitNumber int) error {
|
||||
m.Info().Msgf("Starting commit number: %d on branch: %s", commitNumber, branch)
|
||||
//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
|
||||
//For initial commit no changes are made to files, so don't store anything, just save the list so you can send to server
|
||||
var newCommit database.Commit
|
||||
newCommit.Branch = "master"
|
||||
hashBytes, err := CreateCommitHash(trackedFiles, commitMessage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
currentTime := time.Now()
|
||||
newCommit.CommitHash = hashBytes
|
||||
newCommit.Number = 1
|
||||
newCommit.TrackedFiles = trackedFiles
|
||||
newCommit.Date = currentTime.String()
|
||||
folder := m.FilePaths.ObjectFolder + string(filepath.Separator) + hex.EncodeToString(hashBytes)
|
||||
err = os.Mkdir(folder, 0666)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create commit directory in object dir: %s err: %s", folder, err)
|
||||
}
|
||||
m.Info().Msgf("Total number of files to commit: %d", len(trackedFiles))
|
||||
fmt.Println("Total number of files to commit: ", len(trackedFiles))
|
||||
// TODO: CHeck for NEW Files and convert to starage, not changed files
|
||||
for _, file := range changedFiles {
|
||||
m.Info().Msgf("Converting changed fi")
|
||||
filename, err := ConvertFileForStorage(&file, folder)
|
||||
if err != nil {
|
||||
// TODO: roll back commit on error (folders/files created need to be deleted)
|
||||
return err
|
||||
}
|
||||
file.BaseFilePath = filename
|
||||
}
|
||||
// TODO: THis needs to be the delta calculation for changed files
|
||||
err = m.dB.NewCommit(newCommit, branch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//var hashList [][]byte
|
||||
return nil
|
||||
|
||||
}
|
||||
|
@@ -220,8 +220,10 @@ func (m *Manager) BeginCommit(branch string, commitMessage string) error {
|
||||
m.Err(err).Msgf("unable to create initial commit: %s", err)
|
||||
return err
|
||||
}
|
||||
m.Info().Msgf("Initial Commit Created, returning...")
|
||||
return nil
|
||||
}
|
||||
var filesToDiff []database.File // Contains the list of files that have changed
|
||||
var filesToDiff []database.File // Contains the list of files that have changed since the initial commit
|
||||
for _, trackedFile := range trackedFiles {
|
||||
fmt.Println("Working on file: ", trackedFile.Path)
|
||||
if trackedFile.Path == "" {
|
||||
@@ -253,7 +255,12 @@ func (m *Manager) BeginCommit(branch string, commitMessage string) error {
|
||||
m.Info().Msgf("No changed files found to commit on branch: %s", branch)
|
||||
return fmt.Errorf("no changed files, cannot commit on branch: %s", branch)
|
||||
}
|
||||
fmt.Println("COMMIT: ", commit.CommitHash)
|
||||
fmt.Println("COMMIT: ", hex.EncodeToString(commit.CommitHash))
|
||||
newCommitNumber := commit.Number + 1
|
||||
err = m.CreateCommit(filesToDiff, trackedFiles, branch, commitMessage, newCommitNumber)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user