git/githistory: only handle non-Windows paths

This commit is contained in:
Taylor Blau 2018-02-14 17:38:59 -08:00
parent 9d21cfcae5
commit 9e93c85684
3 changed files with 19 additions and 11 deletions

@ -44,7 +44,7 @@ func AssertBlobContents(t *testing.T, db *odb.ObjectDatabase, tree, path, conten
// Then, iterating through each part of the filepath (i.e., a/b/c.txt ->
// []string{"a", "b", "c.txt"}).
parts := strings.Split(path, string(os.PathSeparator))
parts := strings.Split(path, "/")
for i := 0; i < len(parts)-1; i++ {
part := parts[i]

@ -4,8 +4,7 @@ import (
"encoding/hex"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"sync"
"github.com/git-lfs/git-lfs/errors"
@ -311,9 +310,14 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn
entries := make([]*odb.TreeEntry, 0, len(tree.Entries))
for _, entry := range tree.Entries {
path := filepath.Join(path, entry.Name)
var epath string
if len(path) > 0 {
epath = strings.Join([]string{path, entry.Name}, "/")
} else {
epath = entry.Name
}
if !r.allows(entry.Type(), path) {
if !r.allows(entry.Type(), epath) {
entries = append(entries, entry)
continue
}
@ -327,9 +331,9 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn
switch entry.Type() {
case odb.BlobObjectType:
oid, err = r.rewriteBlob(commitOID, entry.Oid, path, fn, perc)
oid, err = r.rewriteBlob(commitOID, entry.Oid, epath, fn, perc)
case odb.TreeObjectType:
oid, err = r.rewriteTree(commitOID, entry.Oid, path, fn, tfn, perc)
oid, err = r.rewriteTree(commitOID, entry.Oid, epath, fn, tfn, perc)
default:
oid = entry.Oid
@ -345,7 +349,7 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn
}))
}
rewritten, err := tfn(string(os.PathSeparator)+path, &odb.Tree{Entries: entries})
rewritten, err := tfn("/"+path, &odb.Tree{Entries: entries})
if err != nil {
return nil, err
}
@ -359,7 +363,7 @@ func (r *Rewriter) rewriteTree(commitOID []byte, treeOID []byte, path string, fn
func (r *Rewriter) allows(typ odb.ObjectType, abs string) bool {
switch typ {
case odb.BlobObjectType:
return r.Filter().Allows(abs)
return r.Filter().Allows(strings.TrimPrefix(abs, "/"))
case odb.CommitObjectType, odb.TreeObjectType:
return true
default:

@ -3,9 +3,9 @@ package githistory
import (
"bytes"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"path/filepath"
"reflect"
"strconv"
"strings"
@ -165,7 +165,7 @@ func TestRewriterDoesntVisitUnchangedSubtrees(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 2, seen["a.txt"])
assert.Equal(t, 1, seen[filepath.Join("subdir", "b.txt")])
assert.Equal(t, 1, seen["subdir/b.txt"])
}
func TestRewriterVisitsUniqueEntriesWithIdenticalContents(t *testing.T) {
@ -189,6 +189,10 @@ func TestRewriterVisitsUniqueEntriesWithIdenticalContents(t *testing.T) {
tree := "bbbe0a7676523ae02234bfe874784ca2380c2d4b"
fmt.Println(hex.EncodeToString(tip))
root, _ := db.Root()
fmt.Println(root)
AssertCommitTree(t, db, hex.EncodeToString(tip), tree)
// After rewriting, the HEAD state of the repository should contain a