mirror of
https://github.com/splitsh/lite.git
synced 2024-06-08 08:42:22 +02:00
Compare commits
5 commits
4aa9676740
...
cf9970e7ff
Author | SHA1 | Date | |
---|---|---|---|
cf9970e7ff | |||
a5c6982fcd | |||
8f693c4bc2 | |||
2e82f4a273 | |||
e6d25ea821 |
16
.github/workflows/tests.yml
vendored
16
.github/workflows/tests.yml
vendored
|
@ -10,8 +10,8 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Install libgit2-dev
|
||||
run: sudo apt-get install -y libgit2-dev
|
||||
name: Install deps
|
||||
run: sudo apt-get install -y pkg-config cmake
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
@ -29,10 +29,14 @@ jobs:
|
|||
restore-keys: |
|
||||
${{ runner.os }}-go-
|
||||
-
|
||||
name: Set the right libgit2 version
|
||||
name: Building
|
||||
run: |
|
||||
sed -i -e 's/v34/v31/g' go.mod splitter/*.go
|
||||
go mod tidy
|
||||
go mod vendor
|
||||
rm -rf vendor/github.com/libgit2/git2go
|
||||
git clone https://github.com/libgit2/git2go vendor/github.com/libgit2/git2go/v34
|
||||
cd vendor/github.com/libgit2/git2go/v34 && git checkout v34.0.0 && git submodule update --init && make install-static
|
||||
-
|
||||
name: Test
|
||||
run: go test -v ./...
|
||||
run: |
|
||||
export PKG_CONFIG_PATH=/home/runner/work/lite/lite/vendor/github.com/libgit2/git2go/v34/static-build/build
|
||||
go test -v ./...
|
||||
|
|
2
main.go
2
main.go
|
@ -32,7 +32,7 @@ func (p *prefixesFlag) Set(value string) error {
|
|||
for _, prefix := range []*splitter.Prefix(*p) {
|
||||
// FIXME: to should be normalized (xxx vs xxx/ for instance)
|
||||
if prefix.To == to {
|
||||
return fmt.Errorf("Cannot have two prefix splits under the same directory: %s -> %s vs %s -> %s", prefix.From, prefix.To, from, to)
|
||||
return fmt.Errorf("cannot have two prefix splits under the same directory: %s -> %s vs %s -> %s", prefix.From, prefix.To, from, to)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ func newCache(branch string, config *Config) (*cache, error) {
|
|||
return err1
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Impossible to create bucket: %s", err)
|
||||
return nil, fmt.Errorf("impossible to create bucket: %s", err)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
|
@ -120,13 +120,8 @@ func (c *cache) get(rev *git.Oid) *git.Oid {
|
|||
return oid
|
||||
}
|
||||
|
||||
func (c *cache) set(rev, newrev *git.Oid, created bool) {
|
||||
func (c *cache) set(rev, newrev *git.Oid) {
|
||||
c.data[string(rev[0:20])] = newrev[0:20]
|
||||
postfix := "/newest"
|
||||
if created {
|
||||
postfix = "/oldest"
|
||||
}
|
||||
c.data[string(append(newrev[0:20], []byte(postfix)...))] = rev[0:20]
|
||||
}
|
||||
|
||||
func (c *cache) gets(commits []*git.Oid) []*git.Oid {
|
||||
|
|
|
@ -53,17 +53,25 @@ func Split(config *Config, result *Result) error {
|
|||
|
||||
// Validate validates the configuration
|
||||
func (config *Config) Validate() error {
|
||||
if !git.ReferenceIsValidName(config.Origin) {
|
||||
return fmt.Errorf("The origin is not a valid Git reference")
|
||||
ok, err := git.ReferenceNameIsValid(config.Origin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return fmt.Errorf("the origin is not a valid Git reference")
|
||||
}
|
||||
|
||||
if config.Target != "" && !git.ReferenceIsValidName(config.Target) {
|
||||
return fmt.Errorf("The target is not a valid Git reference")
|
||||
ok, err = git.ReferenceNameIsValid(config.Target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if config.Target != "" && !ok {
|
||||
return fmt.Errorf("the target is not a valid Git reference")
|
||||
}
|
||||
|
||||
git, ok := supportedGitVersions[config.GitVersion]
|
||||
if !ok {
|
||||
return fmt.Errorf(`The git version can only be one of "<1.8.2", "<2.8.0", or "latest"`)
|
||||
return fmt.Errorf(`the git version can only be one of "<1.8.2", "<2.8.0", or "latest"`)
|
||||
}
|
||||
config.Git = git
|
||||
|
||||
|
|
|
@ -84,12 +84,12 @@ func roundDuration(d, r time.Duration) time.Duration {
|
|||
}
|
||||
neg := d < 0
|
||||
if neg {
|
||||
d = -d
|
||||
d -= d
|
||||
}
|
||||
if m := d % r; m+m < r {
|
||||
d = d - m
|
||||
d -= m
|
||||
} else {
|
||||
d = d + r - m
|
||||
d += r - m
|
||||
}
|
||||
if neg {
|
||||
return -d
|
||||
|
|
|
@ -119,7 +119,7 @@ func (s *state) split() error {
|
|||
|
||||
revWalk, err := s.walker()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Impossible to walk the repository: %s", err)
|
||||
return fmt.Errorf("impossible to walk the repository: %s", err)
|
||||
}
|
||||
defer revWalk.Free()
|
||||
|
||||
|
@ -163,12 +163,12 @@ func (s *state) split() error {
|
|||
func (s *state) walker() (*git.RevWalk, error) {
|
||||
revWalk, err := s.repo.Walk()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Impossible to walk the repository: %s", err)
|
||||
return nil, fmt.Errorf("impossible to walk the repository: %s", err)
|
||||
}
|
||||
|
||||
err = s.pushRevs(revWalk)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Impossible to determine split range: %s", err)
|
||||
return nil, fmt.Errorf("impossible to determine split range: %s", err)
|
||||
}
|
||||
|
||||
revWalk.Sorting(git.SortTopological | git.SortReverse)
|
||||
|
@ -239,7 +239,7 @@ func (s *state) splitRev(rev *git.Commit) (*git.Oid, error) {
|
|||
s.result.incCreated()
|
||||
}
|
||||
|
||||
s.cache.set(rev.Id(), newrev, created)
|
||||
s.cache.set(rev.Id(), newrev)
|
||||
|
||||
return newrev, nil
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ func (s *state) mergeTrees(t1, t2 *git.Tree) (*git.Tree, error) {
|
|||
defer index.Free()
|
||||
|
||||
if index.HasConflicts() {
|
||||
return nil, fmt.Errorf("Cannot split as there is a merge conflict between two paths")
|
||||
return nil, fmt.Errorf("cannot split as there is a merge conflict between two paths")
|
||||
}
|
||||
|
||||
oid, err := index.WriteTreeTo(s.repo)
|
||||
|
@ -373,7 +373,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi
|
|||
continue
|
||||
}
|
||||
|
||||
if 0 == ptree.Cmp(tree.Id()) {
|
||||
if ptree.Cmp(tree.Id()) == 0 {
|
||||
// an identical parent could be used in place of this rev.
|
||||
identical = parent
|
||||
} else {
|
||||
|
@ -384,7 +384,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi
|
|||
// eliminate duplicates
|
||||
isNew := true
|
||||
for _, gp := range gotParents {
|
||||
if 0 == gp.Cmp(parent) {
|
||||
if gp.Cmp(parent) == 0 {
|
||||
isNew = false
|
||||
break
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi
|
|||
if s.config.Git > 2 && nil != identical && nil != nonIdentical {
|
||||
revWalk, err := s.repo.Walk()
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("Impossible to walk the repository: %s", err)
|
||||
return nil, false, fmt.Errorf("impossible to walk the repository: %s", err)
|
||||
}
|
||||
|
||||
s.repoMu.Lock()
|
||||
|
@ -413,7 +413,7 @@ func (s *state) copyOrSkip(rev *git.Commit, tree *git.Tree, newParents []*git.Oi
|
|||
|
||||
err = revWalk.PushRange(fmt.Sprintf("%s..%s", identical, nonIdentical))
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("Impossible to determine split range: %s", err)
|
||||
return nil, false, fmt.Errorf("impossible to determine split range: %s", err)
|
||||
}
|
||||
|
||||
err = revWalk.Iterate(func(rev *git.Commit) bool {
|
||||
|
@ -494,7 +494,7 @@ func (s *state) updateTarget() error {
|
|||
}
|
||||
|
||||
if nil == s.result.Head() {
|
||||
return fmt.Errorf("Unable to create branch %s as it is empty (no commits were split)", s.config.Target)
|
||||
return fmt.Errorf("unable to create branch %s as it is empty (no commits were split)", s.config.Target)
|
||||
}
|
||||
|
||||
obj, ref, err := s.repo.RevparseExt(s.config.Target)
|
||||
|
|
|
@ -63,7 +63,7 @@ func normalizeOriginBranch(repo *git.Repository, origin string) (string, error)
|
|||
|
||||
obj, ref, err := repo.RevparseExt(origin)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Bad revision for origin: %s", err)
|
||||
return "", fmt.Errorf("bad revision for origin: %s", err)
|
||||
}
|
||||
if obj != nil {
|
||||
obj.Free()
|
||||
|
|
Loading…
Reference in a new issue