Vadim Markovtsev 7 anni fa
parent
commit
d3788fdd9c
3 ha cambiato i file con 41 aggiunte e 1 eliminazioni
  1. 8 0
      blob_cache.go
  2. 27 0
      blob_cache_test.go
  3. 6 1
      cmd/hercules/main.go

+ 8 - 0
blob_cache.go

@@ -12,6 +12,8 @@ import (
 )
 )
 
 
 type BlobCache struct {
 type BlobCache struct {
+	IgnoreMissingSubmodules bool
+
 	repository *git.Repository
 	repository *git.Repository
 }
 }
 
 
@@ -90,6 +92,12 @@ func (cache *BlobCache) getBlob(entry *object.ChangeEntry, fileGetter FileGetter
 			fmt.Fprintf(os.Stderr, "getBlob(%s)\n", entry.TreeEntry.Hash.String())
 			fmt.Fprintf(os.Stderr, "getBlob(%s)\n", entry.TreeEntry.Hash.String())
 			return nil, err
 			return nil, err
 		}
 		}
+		if entry.TreeEntry.Mode != 0160000 {
+			// this is not a submodule
+			return nil, err
+		} else if cache.IgnoreMissingSubmodules {
+			return createDummyBlob(entry.TreeEntry.Hash)
+		}
 		file, err_modules := fileGetter(".gitmodules")
 		file, err_modules := fileGetter(".gitmodules")
 		if err_modules != nil {
 		if err_modules != nil {
 			return nil, err
 			return nil, err

+ 27 - 0
blob_cache_test.go

@@ -269,3 +269,30 @@ func TestBlobCacheInsertInvalidBlob(t *testing.T) {
 	assert.NotNil(t, err)
 	assert.NotNil(t, err)
 	assert.Equal(t, len(result), 0)
 	assert.Equal(t, len(result), 0)
 }
 }
+
+func TestBlobCacheGetBlobIgnoreMissing(t *testing.T) {
+	cache := fixtureBlobCache()
+	cache.IgnoreMissingSubmodules = true
+	treeFrom, _ := testRepository.TreeObject(plumbing.NewHash(
+		"80fe25955b8e725feee25c08ea5759d74f8b670d"))
+	entry := object.ChangeEntry{
+		Name: "commit",
+		Tree: treeFrom,
+		TreeEntry: object.TreeEntry{
+			Name: "commit",
+			Mode: 0160000,
+			Hash: plumbing.NewHash("ffffffffffffffffffffffffffffffffffffffff"),
+		},
+	}
+	getter := func(path string) (*object.File, error) {
+		return nil, plumbing.ErrObjectNotFound
+	}
+	blob, err := cache.getBlob(&entry, getter)
+	assert.NotNil(t, blob)
+	assert.Nil(t, err)
+	assert.Equal(t, blob.Size, int64(0))
+	cache.IgnoreMissingSubmodules = false
+	blob, err = cache.getBlob(&entry, getter)
+	assert.Nil(t, blob)
+	assert.NotNil(t, err)
+}

+ 6 - 1
cmd/hercules/main.go

@@ -67,6 +67,7 @@ func main() {
 	var profile bool
 	var profile bool
 	var granularity, sampling, similarity_threshold int
 	var granularity, sampling, similarity_threshold int
 	var commitsFile string
 	var commitsFile string
+	var ignoreMissingSubmodules bool
 	var debug bool
 	var debug bool
 	flag.BoolVar(&withFiles, "files", false, "Output detailed statistics per each file.")
 	flag.BoolVar(&withFiles, "files", false, "Output detailed statistics per each file.")
 	flag.BoolVar(&withPeople, "people", false, "Output detailed statistics per each developer.")
 	flag.BoolVar(&withPeople, "people", false, "Output detailed statistics per each developer.")
@@ -83,6 +84,8 @@ func main() {
 		"commit history to follow instead of the default rev-list "+
 		"commit history to follow instead of the default rev-list "+
 		"--first-parent. The format is the list of hashes, each hash on a "+
 		"--first-parent. The format is the list of hashes, each hash on a "+
 		"separate line. The first hash is the root.")
 		"separate line. The first hash is the root.")
+	flag.BoolVar(&ignoreMissingSubmodules, "ignore-missing-submodules", false,
+		"Do not panic on submodules which are not registered..")
 	flag.BoolVar(&protobuf, "pb", false, "The output format will be Protocol Buffers instead of YAML.")
 	flag.BoolVar(&protobuf, "pb", false, "The output format will be Protocol Buffers instead of YAML.")
 	flag.Parse()
 	flag.Parse()
 	if granularity <= 0 {
 	if granularity <= 0 {
@@ -149,7 +152,9 @@ func main() {
 		}
 		}
 	}
 	}
 
 
-	pipeline.AddItem(&hercules.BlobCache{})
+	pipeline.AddItem(&hercules.BlobCache{
+		IgnoreMissingSubmodules: ignoreMissingSubmodules,
+	})
 	pipeline.AddItem(&hercules.DaysSinceStart{})
 	pipeline.AddItem(&hercules.DaysSinceStart{})
 	pipeline.AddItem(&hercules.RenameAnalysis{SimilarityThreshold: similarity_threshold})
 	pipeline.AddItem(&hercules.RenameAnalysis{SimilarityThreshold: similarity_threshold})
 	pipeline.AddItem(&hercules.TreeDiff{})
 	pipeline.AddItem(&hercules.TreeDiff{})