Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

status fix #4

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/zeta-serve/shutdown_other.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright ©️ Ant Group. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//go:build darwin || linux || freebsd || netbsd || openbsd
//go:build darwin || linux || freebsd || netbsd || openbsd || dragonfly

package main

Expand Down
2 changes: 2 additions & 0 deletions modules/bitmap/bitmap_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !386

package bitmap

import (
Expand Down
4 changes: 4 additions & 0 deletions modules/merkletrie/filesystem/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (n *Node) Mode() filemode.FileMode {
return m
}

func (n *Node) HijackMode(mode filemode.FileMode) {
n.mode, _ = mode.ToOSFileMode()
}

func (n *Node) ModifiedAt() time.Time {
return n.modifiedAt
}
Expand Down
8 changes: 6 additions & 2 deletions modules/zeta/backend/pack/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (e *Encoder) Name() string {
return e.sum.String()
}

const (
offset64PosMask = uint64(1) << 31
)

// https://codewords.recurse.com/issues/three/unpacking-git-packfiles
func (e *Encoder) WriteIndex(fd *os.File) error {
sort.Sort(e.objects)
Expand Down Expand Up @@ -169,12 +173,12 @@ func (e *Encoder) WriteIndex(fd *os.File) error {
}
}
offset64Set := make([]uint64, 0, 20)
var offset64Pos int
var offset64Pos uint64
for _, o := range e.objects {
offset := o.Offset
if offset > math.MaxInt32 {
offset64Set = append(offset64Set, offset)
offset = uint64(offset64Pos | (1 << 31))
offset = uint64(offset64Pos | offset64PosMask)
offset64Pos++
}
if err := binary.WriteUint32(w, uint32(offset)); err != nil {
Expand Down
38 changes: 36 additions & 2 deletions pkg/zeta/worktree_bsd.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright 2018 Sourced Technologies, S.L.
// SPDX-License-Identifier: Apache-2.0

//go:build darwin || freebsd || netbsd
// +build darwin freebsd netbsd
//go:build freebsd || netbsd
// +build freebsd netbsd

package zeta

import (
"syscall"
"time"

"github.com/antgroup/hugescm/modules/merkletrie"
"github.com/antgroup/hugescm/modules/plumbing/format/index"
)

Expand All @@ -32,3 +33,36 @@ func init() {
func isSymlinkWindowsNonAdmin(error) bool {
return false
}

func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
if len(changes) == 0 {
return changes
}
m, err := w.ignoreMatcher()
if err != nil {
return changes
}

var res merkletrie.Changes
for _, ch := range changes {
var path []string
for _, n := range ch.To {
path = append(path, n.Name())
}
if len(path) == 0 {
for _, n := range ch.From {
path = append(path, n.Name())
}
}
if len(path) != 0 {
isDir := (len(ch.To) > 0 && ch.To.IsDir()) || (len(ch.From) > 0 && ch.From.IsDir())
if m.Match(path, isDir) {
if len(ch.From) == 0 {
continue
}
}
}
res = append(res, ch)
}
return res
}
25 changes: 8 additions & 17 deletions pkg/zeta/worktree_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/antgroup/hugescm/modules/merkletrie"
"github.com/antgroup/hugescm/modules/plumbing"
"github.com/antgroup/hugescm/modules/plumbing/filemode"
"github.com/antgroup/hugescm/modules/plumbing/format/index"
"github.com/antgroup/hugescm/modules/zeta/object"
"github.com/antgroup/hugescm/pkg/progress"
Expand Down Expand Up @@ -423,7 +422,7 @@ func (cg *checkoutGroup) coco(ctx context.Context, w *Worktree, bar ProgressBar)
fmt.Fprintf(os.Stderr, "\x1b[2K\rcheckout file %s error: %v\n", e.name, err)
return err
}
if err := w.addIndex(e.name, e.entry.Hash, cg.recv, e.entry.IsFragments()); err != nil {
if err := w.addIndex(e.name, e.entry, cg.recv); err != nil {
fmt.Fprintf(os.Stderr, "\x1b[2K\rreset file %s index error: %v\n", e.name, err)
return err
}
Expand All @@ -440,23 +439,15 @@ func (cg *checkoutGroup) run(ctx context.Context, w *Worktree, bar ProgressBar)
}()
}

func (w *Worktree) addIndex(name string, h plumbing.Hash, recv indexRecv, isFragments bool) error {
func (w *Worktree) addIndex(name string, entry *object.TreeEntry, recv indexRecv) error {
fi, err := w.fs.Lstat(name)
if err != nil {
return err
}

mode, err := filemode.NewFromOS(fi.Mode())
if err != nil {
return err
}
if isFragments {
mode |= filemode.Fragments
}
e := &index.Entry{
Hash: h,
Hash: entry.Hash,
Name: name,
Mode: mode,
Mode: entry.Mode,
ModifiedAt: fi.ModTime(),
Size: uint64(fi.Size()),
}
Expand All @@ -470,15 +461,15 @@ func (w *Worktree) addIndex(name string, h plumbing.Hash, recv indexRecv, isFrag
return nil
}

func (w *Worktree) addPseudoIndexRecv(name string, oe *object.TreeEntry, recv indexRecv) {
func (w *Worktree) addPseudoIndexRecv(name string, entry *object.TreeEntry, recv indexRecv) {
now := time.Now()
e := &index.Entry{
Hash: oe.Hash,
Hash: entry.Hash,
Name: name,
Mode: oe.Mode,
Mode: entry.Mode,
ModifiedAt: now,
CreatedAt: now,
Size: uint64(oe.Size),
Size: uint64(entry.Size),
}
recv(e)
}
Expand Down
96 changes: 96 additions & 0 deletions pkg/zeta/worktree_drawin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2018 Sourced Technologies, S.L.
// SPDX-License-Identifier: Apache-2.0

//go:build darwin
// +build darwin

package zeta

import (
"bytes"
"strings"
"syscall"
"time"

"github.com/antgroup/hugescm/modules/merkletrie"
"github.com/antgroup/hugescm/modules/plumbing/format/index"
)

const (
escapeChars = "*?[]\\"
)

func init() {
fillSystemInfo = func(e *index.Entry, sys any) {
if os, ok := sys.(*syscall.Stat_t); ok {
e.CreatedAt = time.Unix(os.Atimespec.Unix())
e.Dev = uint32(os.Dev)
e.Inode = uint32(os.Ino)
e.GID = os.Gid
e.UID = os.Uid
}
}
}

func isSymlinkWindowsNonAdmin(error) bool {
return false
}

func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
if len(changes) == 0 {
return changes
}
m, err := w.ignoreMatcher()
if err != nil {
return changes
}
var newItems merkletrie.Changes
var res merkletrie.Changes
rmItems := make(map[string]merkletrie.Change)
for _, ch := range changes {
var path []string
for _, n := range ch.To {
path = append(path, n.Name())
}
if len(path) == 0 {
for _, n := range ch.From {
path = append(path, n.Name())
}
}
if len(path) != 0 {
isDir := (len(ch.To) > 0 && ch.To.IsDir()) || (len(ch.From) > 0 && ch.From.IsDir())
if m.Match(path, isDir) {
if len(ch.From) == 0 {
continue
}
}
}
// Add
if ch.From == nil {
newItems = append(newItems, ch)
continue
}
// Del
if ch.To == nil {
rmItems[strings.ToLower(ch.From.String())] = ch
continue
}
res = append(res, ch)
}
for _, ch := range newItems {
name := strings.ToLower(ch.To.String())
if c, ok := rmItems[name]; ok {
if !bytes.Equal(c.From.Hash(), ch.To.Hash()) {
ch.From = c.From
res = append(res, ch) // rename and modify
}
delete(rmItems, name)
continue
}
res = append(res, ch)
}
for _, ch := range rmItems {
res = append(res, ch)
}
return res
}
34 changes: 34 additions & 0 deletions pkg/zeta/worktree_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"syscall"
"time"

"github.com/antgroup/hugescm/modules/merkletrie"
"github.com/antgroup/hugescm/modules/plumbing/format/index"
)

Expand All @@ -32,3 +33,36 @@ func init() {
func isSymlinkWindowsNonAdmin(error) bool {
return false
}

func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
if len(changes) == 0 {
return changes
}
m, err := w.ignoreMatcher()
if err != nil {
return changes
}

var res merkletrie.Changes
for _, ch := range changes {
var path []string
for _, n := range ch.To {
path = append(path, n.Name())
}
if len(path) == 0 {
for _, n := range ch.From {
path = append(path, n.Name())
}
}
if len(path) != 0 {
isDir := (len(ch.To) > 0 && ch.To.IsDir()) || (len(ch.From) > 0 && ch.From.IsDir())
if m.Match(path, isDir) {
if len(ch.From) == 0 {
continue
}
}
}
res = append(res, ch)
}
return res
}
30 changes: 0 additions & 30 deletions pkg/zeta/worktree_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,36 +319,6 @@ func (w *Worktree) ignoredChanges(changes merkletrie.Changes) []string {
return ignored
}

func (w *Worktree) excludeIgnoredChanges(changes merkletrie.Changes) merkletrie.Changes {
m, err := w.ignoreMatcher()
if err != nil {
return changes
}

var res merkletrie.Changes
for _, ch := range changes {
var path []string
for _, n := range ch.To {
path = append(path, n.Name())
}
if len(path) == 0 {
for _, n := range ch.From {
path = append(path, n.Name())
}
}
if len(path) != 0 {
isDir := (len(ch.To) > 0 && ch.To.IsDir()) || (len(ch.From) > 0 && ch.From.IsDir())
if m.Match(path, isDir) {
if len(ch.From) == 0 {
continue
}
}
}
res = append(res, ch)
}
return res
}

func (w *Worktree) doAddDirectory(ctx context.Context, idx *index.Index, s Status, directory string, ignorePattern []ignore.Pattern, dryRun bool) (added bool, err error) {
if len(ignorePattern) > 0 {
m := ignore.NewMatcher(ignorePattern)
Expand Down
6 changes: 5 additions & 1 deletion pkg/zeta/worktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"sort"
"testing"

"github.com/BurntSushi/toml"
"github.com/antgroup/hugescm/modules/merkletrie/noder"
"github.com/antgroup/hugescm/modules/plumbing"
"github.com/antgroup/hugescm/modules/plumbing/filemode"
"github.com/antgroup/hugescm/modules/strengthen"
"github.com/antgroup/hugescm/modules/zeta/config"
"github.com/antgroup/hugescm/modules/zeta/object"
"github.com/antgroup/hugescm/pkg/zeta/odb"
"github.com/BurntSushi/toml"
)

func TestWorktree(t *testing.T) {
Expand Down Expand Up @@ -753,3 +753,7 @@ func TestEncode(t *testing.T) {
}
_ = toml.NewEncoder(os.Stderr).Encode(a)
}

func TestMode(t *testing.T) {
fmt.Fprintf(os.Stderr, "%o\n", filemode.Regular&filemode.Executable)
}
Loading