git/githistory: include TreeCallbackFn in *RewriteOptions type
This commit is contained in:
parent
994221fef7
commit
d6af33d70e
@ -48,6 +48,10 @@ type RewriteOptions struct {
|
||||
// each blob for subsequent revisions, so long as each entry remains
|
||||
// unchanged.
|
||||
BlobFn BlobRewriteFn
|
||||
// TreeCallbackFn specifies a function to rewrite trees after they have
|
||||
// been reassembled by calling the above BlobFn on all existing tree
|
||||
// entries.
|
||||
TreeCallbackFn TreeCallbackFn
|
||||
}
|
||||
|
||||
// blobFn returns a useable BlobRewriteFn, either the one that was given in the
|
||||
@ -59,6 +63,15 @@ func (r *RewriteOptions) blobFn() BlobRewriteFn {
|
||||
return r.BlobFn
|
||||
}
|
||||
|
||||
// treeFn returns a useable TreeRewriteFn, either the one that was given in the
|
||||
// *RewriteOptions, or a noopTreeFn.
|
||||
func (r *RewriteOptions) treeFn() TreeCallbackFn {
|
||||
if r.TreeCallbackFn == nil {
|
||||
return noopTreeFn
|
||||
}
|
||||
return r.TreeCallbackFn
|
||||
}
|
||||
|
||||
// BlobRewriteFn is a mapping function that takes a given blob and returns a
|
||||
// new, modified blob. If it returns an error, the new blob will not be written
|
||||
// and instead the error will be returned from the Rewrite() function.
|
||||
@ -75,6 +88,21 @@ func (r *RewriteOptions) blobFn() BlobRewriteFn {
|
||||
// of filepath.Join(...) or os.PathSeparator.
|
||||
type BlobRewriteFn func(path string, b *odb.Blob) (*odb.Blob, error)
|
||||
|
||||
// TreeCallbackFn specifies a function to call before writing a re-written tree
|
||||
// to the object database. The TreeCallbackFn can return a modified tree to be
|
||||
// written to the object database instead of one generated from calling BlobFn
|
||||
// on all of the tree entries.
|
||||
//
|
||||
// Trees returned from a TreeCallbackFn MUST have all objects referenced in the
|
||||
// entryset already written to the object database.
|
||||
//
|
||||
// TreeCallbackFn can be nil, and will therefore exhibit behavior equivalent to
|
||||
// only calling the BlobFn on existing tree entries.
|
||||
//
|
||||
// If the TreeCallbackFn returns an error, it will be returned from the
|
||||
// Rewrite() invocation.
|
||||
type TreeCallbackFn func(path string, t *odb.Tree) (*odb.Tree, error)
|
||||
|
||||
type rewriterOption func(*Rewriter)
|
||||
|
||||
var (
|
||||
@ -90,6 +118,9 @@ var (
|
||||
// noopBlobFn is a no-op implementation of the BlobRewriteFn. It returns
|
||||
// the blob that it was given, and returns no error.
|
||||
noopBlobFn = func(path string, b *odb.Blob) (*odb.Blob, error) { return b, nil }
|
||||
// noopTreeFn is a no-op implementation of the TreeRewriteFn. It returns
|
||||
// the tree that it was given, and returns no error.
|
||||
noopTreeFn = func(path string, t *odb.Tree) (*odb.Tree, error) { return t, nil }
|
||||
)
|
||||
|
||||
// NewRewriter constructs a *Rewriter from the given *ObjectDatabase instance.
|
||||
|
Loading…
Reference in New Issue
Block a user