git/githistory: teach UpdateRefs
option
This commit is contained in:
parent
47afc58817
commit
68b76005c9
@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/git-lfs/git-lfs/errors"
|
||||||
"github.com/git-lfs/git-lfs/filepathfilter"
|
"github.com/git-lfs/git-lfs/filepathfilter"
|
||||||
"github.com/git-lfs/git-lfs/git"
|
"github.com/git-lfs/git-lfs/git"
|
||||||
"github.com/git-lfs/git-lfs/git/githistory/log"
|
"github.com/git-lfs/git-lfs/git/githistory/log"
|
||||||
@ -46,6 +47,11 @@ type RewriteOptions struct {
|
|||||||
// will be excluded.
|
// will be excluded.
|
||||||
Exclude []string
|
Exclude []string
|
||||||
|
|
||||||
|
// UpdateRefs specifies whether the Rewriter should move refs from the
|
||||||
|
// original graph onto the migrated one. If true, the refs will be
|
||||||
|
// moved, and a reflog entry will be created.
|
||||||
|
UpdateRefs bool
|
||||||
|
|
||||||
// BlobFn specifies a function to rewrite blobs.
|
// BlobFn specifies a function to rewrite blobs.
|
||||||
//
|
//
|
||||||
// It is called once per unique, unchanged path. That is to say, if
|
// It is called once per unique, unchanged path. That is to say, if
|
||||||
@ -233,6 +239,26 @@ func (r *Rewriter) Rewrite(opt *RewriteOptions) ([]byte, error) {
|
|||||||
tip = rewrittenCommit
|
tip = rewrittenCommit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opt.UpdateRefs {
|
||||||
|
refs, err := r.refsToMigrate()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not find refs to update")
|
||||||
|
}
|
||||||
|
|
||||||
|
root, _ := r.db.Root()
|
||||||
|
|
||||||
|
updater := &refUpdater{
|
||||||
|
CacheFn: r.uncacheCommit,
|
||||||
|
Logger: r.l,
|
||||||
|
Refs: refs,
|
||||||
|
Root: root,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := updater.UpdateRefs(); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not update refs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
r.l.Close()
|
r.l.Close()
|
||||||
|
|
||||||
return tip, err
|
return tip, err
|
||||||
|
@ -299,6 +299,37 @@ func TestHistoryRewriterUseOriginalParentsForPartialMigration(t *testing.T) {
|
|||||||
AssertCommitParent(t, db, hex.EncodeToString(tip), expectedParent)
|
AssertCommitParent(t, db, hex.EncodeToString(tip), expectedParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHistoryRewriterUpdatesRefs(t *testing.T) {
|
||||||
|
db := DatabaseFromFixture(t, "linear-history.git")
|
||||||
|
r := NewRewriter(db)
|
||||||
|
|
||||||
|
tip, err := r.Rewrite(&RewriteOptions{
|
||||||
|
Include: []string{"refs/heads/master"},
|
||||||
|
|
||||||
|
UpdateRefs: true,
|
||||||
|
|
||||||
|
BlobFn: func(path string, b *odb.Blob) (*odb.Blob, error) {
|
||||||
|
suffix := strings.NewReader("_suffix")
|
||||||
|
|
||||||
|
return &odb.Blob{
|
||||||
|
Contents: io.MultiReader(b.Contents, suffix),
|
||||||
|
Size: b.Size + int64(suffix.Len()),
|
||||||
|
}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
c1 := hex.EncodeToString(tip)
|
||||||
|
c2 := "66561fe3ae68651658e18e48053dcfe66a2e9da1"
|
||||||
|
c3 := "8268d8486c48024a871fa42fc487dbeabd6e3d86"
|
||||||
|
|
||||||
|
AssertRef(t, db, "refs/heads/master", tip)
|
||||||
|
|
||||||
|
AssertCommitParent(t, db, c1, c2)
|
||||||
|
AssertCommitParent(t, db, c2, c3)
|
||||||
|
}
|
||||||
|
|
||||||
func root(path string) string {
|
func root(path string) string {
|
||||||
if !strings.HasPrefix(path, string(os.PathSeparator)) {
|
if !strings.HasPrefix(path, string(os.PathSeparator)) {
|
||||||
path = string(os.PathSeparator) + path
|
path = string(os.PathSeparator) + path
|
||||||
|
Loading…
Reference in New Issue
Block a user