analyser.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. package hercules
  2. import (
  3. "bufio"
  4. "bytes"
  5. "errors"
  6. "fmt"
  7. "io"
  8. "os"
  9. "sort"
  10. "time"
  11. "unicode/utf8"
  12. "github.com/sergi/go-diff/diffmatchpatch"
  13. "gopkg.in/src-d/go-git.v4"
  14. "gopkg.in/src-d/go-git.v4/config"
  15. "gopkg.in/src-d/go-git.v4/plumbing"
  16. "gopkg.in/src-d/go-git.v4/plumbing/object"
  17. "gopkg.in/src-d/go-git.v4/utils/merkletrie"
  18. )
  19. type Analyser struct {
  20. Repository *git.Repository
  21. Granularity int
  22. Sampling int
  23. SimilarityThreshold int
  24. Debug bool
  25. OnProgress func(int, int)
  26. }
  27. func checkClose(c io.Closer) {
  28. if err := c.Close(); err != nil {
  29. panic(err)
  30. }
  31. }
  32. func loc(file *object.Blob) (int, error) {
  33. reader, err := file.Reader()
  34. if err != nil {
  35. panic(err)
  36. }
  37. defer checkClose(reader)
  38. var scanner *bufio.Scanner
  39. buffer := make([]byte, bufio.MaxScanTokenSize)
  40. counter := 0
  41. for scanner == nil || scanner.Err() == bufio.ErrTooLong {
  42. if scanner != nil && !utf8.Valid(scanner.Bytes()) {
  43. return -1, errors.New("binary")
  44. }
  45. scanner = bufio.NewScanner(reader)
  46. scanner.Buffer(buffer, 0)
  47. for scanner.Scan() {
  48. if !utf8.Valid(scanner.Bytes()) {
  49. return -1, errors.New("binary")
  50. }
  51. counter++
  52. }
  53. }
  54. return counter, nil
  55. }
  56. func str(file *object.Blob) string {
  57. reader, err := file.Reader()
  58. if err != nil {
  59. panic(err)
  60. }
  61. defer checkClose(reader)
  62. buf := new(bytes.Buffer)
  63. buf.ReadFrom(reader)
  64. return buf.String()
  65. }
  66. type DummyIO struct {
  67. }
  68. func (DummyIO) Read(p []byte) (int, error) {
  69. return 0, io.EOF
  70. }
  71. func (DummyIO) Write(p []byte) (int, error) {
  72. return len(p), nil
  73. }
  74. func (DummyIO) Close() error {
  75. return nil
  76. }
  77. type DummyEncodedObject struct {
  78. FakeHash plumbing.Hash
  79. }
  80. func (obj DummyEncodedObject) Hash() plumbing.Hash {
  81. return obj.FakeHash
  82. }
  83. func (obj DummyEncodedObject) Type() plumbing.ObjectType {
  84. return plumbing.BlobObject
  85. }
  86. func (obj DummyEncodedObject) SetType(plumbing.ObjectType) {
  87. }
  88. func (obj DummyEncodedObject) Size() int64 {
  89. return 0
  90. }
  91. func (obj DummyEncodedObject) SetSize(int64) {
  92. }
  93. func (obj DummyEncodedObject) Reader() (io.ReadCloser, error) {
  94. return DummyIO{}, nil
  95. }
  96. func (obj DummyEncodedObject) Writer() (io.WriteCloser, error) {
  97. return DummyIO{}, nil
  98. }
  99. func createDummyBlob(hash *plumbing.Hash) (*object.Blob, error) {
  100. return object.DecodeBlob(DummyEncodedObject{*hash})
  101. }
  102. func (analyser *Analyser) handleInsertion(
  103. change *object.Change, day int, status map[int]int64, files map[string]*File,
  104. cache *map[plumbing.Hash]*object.Blob) {
  105. blob := (*cache)[change.To.TreeEntry.Hash]
  106. lines, err := loc(blob)
  107. if err != nil {
  108. return
  109. }
  110. name := change.To.Name
  111. file, exists := files[name]
  112. if exists {
  113. panic(fmt.Sprintf("file %s already exists", name))
  114. }
  115. file = NewFile(day, lines, status)
  116. files[name] = file
  117. }
  118. func (analyser *Analyser) handleDeletion(
  119. change *object.Change, day int, status map[int]int64, files map[string]*File,
  120. cache *map[plumbing.Hash]*object.Blob) {
  121. blob := (*cache)[change.From.TreeEntry.Hash]
  122. lines, err := loc(blob)
  123. if err != nil {
  124. return
  125. }
  126. name := change.From.Name
  127. file := files[name]
  128. file.Update(day, 0, 0, lines)
  129. delete(files, name)
  130. }
  131. func (analyser *Analyser) handleModification(
  132. change *object.Change, day int, status map[int]int64, files map[string]*File,
  133. cache *map[plumbing.Hash]*object.Blob) {
  134. blob_from := (*cache)[change.From.TreeEntry.Hash]
  135. blob_to := (*cache)[change.To.TreeEntry.Hash]
  136. // we are not validating UTF-8 here because for example
  137. // git/git 4f7770c87ce3c302e1639a7737a6d2531fe4b160 fetch-pack.c is invalid UTF-8
  138. str_from := str(blob_from)
  139. str_to := str(blob_to)
  140. file, exists := files[change.From.Name]
  141. if !exists {
  142. analyser.handleInsertion(change, day, status, files, cache)
  143. return
  144. }
  145. // possible rename
  146. if change.To.Name != change.From.Name {
  147. analyser.handleRename(change.From.Name, change.To.Name, files)
  148. }
  149. dmp := diffmatchpatch.New()
  150. src, dst, _ := dmp.DiffLinesToRunes(str_from, str_to)
  151. if file.Len() != len(src) {
  152. fmt.Fprintf(os.Stderr, "====TREE====\n%s", file.Dump())
  153. panic(fmt.Sprintf("%s: internal integrity error src %d != %d %s -> %s",
  154. change.To.Name, len(src), file.Len(),
  155. change.From.TreeEntry.Hash.String(), change.To.TreeEntry.Hash.String()))
  156. }
  157. diffs := dmp.DiffMainRunes(src, dst, false)
  158. // we do not call RunesToDiffLines so the number of lines equals
  159. // to the rune count
  160. position := 0
  161. pending := diffmatchpatch.Diff{Text: ""}
  162. apply := func(edit diffmatchpatch.Diff) {
  163. length := utf8.RuneCountInString(edit.Text)
  164. if edit.Type == diffmatchpatch.DiffInsert {
  165. file.Update(day, position, length, 0)
  166. position += length
  167. } else {
  168. file.Update(day, position, 0, length)
  169. }
  170. if analyser.Debug {
  171. file.Validate()
  172. }
  173. }
  174. for _, edit := range diffs {
  175. dump_before := ""
  176. if analyser.Debug {
  177. dump_before = file.Dump()
  178. }
  179. length := utf8.RuneCountInString(edit.Text)
  180. func() {
  181. defer func() {
  182. r := recover()
  183. if r != nil {
  184. fmt.Fprintf(os.Stderr, "%s: internal diff error\n", change.To.Name)
  185. fmt.Fprintf(os.Stderr, "Update(%d, %d, %d (0), %d (0))\n", day, position,
  186. length, utf8.RuneCountInString(pending.Text))
  187. if dump_before != "" {
  188. fmt.Fprintf(os.Stderr, "====TREE BEFORE====\n%s====END====\n", dump_before)
  189. }
  190. fmt.Fprintf(os.Stderr, "====TREE AFTER====\n%s====END====\n", file.Dump())
  191. panic(r)
  192. }
  193. }()
  194. switch edit.Type {
  195. case diffmatchpatch.DiffEqual:
  196. if pending.Text != "" {
  197. apply(pending)
  198. pending.Text = ""
  199. }
  200. position += length
  201. case diffmatchpatch.DiffInsert:
  202. if pending.Text != "" {
  203. if pending.Type == diffmatchpatch.DiffInsert {
  204. panic("DiffInsert may not appear after DiffInsert")
  205. }
  206. file.Update(day, position, length, utf8.RuneCountInString(pending.Text))
  207. if analyser.Debug {
  208. file.Validate()
  209. }
  210. position += length
  211. pending.Text = ""
  212. } else {
  213. pending = edit
  214. }
  215. case diffmatchpatch.DiffDelete:
  216. if pending.Text != "" {
  217. panic("DiffDelete may not appear after DiffInsert/DiffDelete")
  218. }
  219. pending = edit
  220. default:
  221. panic(fmt.Sprintf("diff operation is not supported: %d", edit.Type))
  222. }
  223. }()
  224. }
  225. if pending.Text != "" {
  226. apply(pending)
  227. pending.Text = ""
  228. }
  229. if file.Len() != len(dst) {
  230. panic(fmt.Sprintf("%s: internal integrity error dst %d != %d",
  231. change.To.Name, len(dst), file.Len()))
  232. }
  233. }
  234. func (analyser *Analyser) handleRename(from, to string, files map[string]*File) {
  235. file, exists := files[from]
  236. if !exists {
  237. panic(fmt.Sprintf("file %s does not exist", from))
  238. }
  239. files[to] = file
  240. delete(files, from)
  241. }
  242. func (analyser *Analyser) Commits() []*object.Commit {
  243. result := []*object.Commit{}
  244. repository := analyser.Repository
  245. head, err := repository.Head()
  246. if err != nil {
  247. panic(err)
  248. }
  249. commit, err := repository.CommitObject(head.Hash())
  250. if err != nil {
  251. panic(err)
  252. }
  253. result = append(result, commit)
  254. for ; err != io.EOF; commit, err = commit.Parents().Next() {
  255. if err != nil {
  256. panic(err)
  257. }
  258. result = append(result, commit)
  259. }
  260. // reverse the order
  261. for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
  262. result[i], result[j] = result[j], result[i]
  263. }
  264. return result
  265. }
  266. func (analyser *Analyser) groupStatus(status map[int]int64, day int) []int64 {
  267. granularity := analyser.Granularity
  268. if granularity == 0 {
  269. granularity = 1
  270. }
  271. day++
  272. adjust := 0
  273. if day%granularity < granularity-1 {
  274. adjust = 1
  275. }
  276. result := make([]int64, day/granularity+adjust)
  277. var group int64
  278. for i := 0; i < day; i++ {
  279. group += status[i]
  280. if i%granularity == (granularity - 1) {
  281. result[i/granularity] = group
  282. group = 0
  283. }
  284. }
  285. if day%granularity < granularity-1 {
  286. result[len(result)-1] = group
  287. }
  288. return result
  289. }
  290. type sortableChange struct {
  291. change *object.Change
  292. hash plumbing.Hash
  293. }
  294. type sortableChanges []sortableChange
  295. func (change *sortableChange) Less(other *sortableChange) bool {
  296. for x := 0; x < 20; x++ {
  297. if change.hash[x] < other.hash[x] {
  298. return true
  299. }
  300. }
  301. return false
  302. }
  303. func (slice sortableChanges) Len() int {
  304. return len(slice)
  305. }
  306. func (slice sortableChanges) Less(i, j int) bool {
  307. return slice[i].Less(&slice[j])
  308. }
  309. func (slice sortableChanges) Swap(i, j int) {
  310. slice[i], slice[j] = slice[j], slice[i]
  311. }
  312. type sortableBlob struct {
  313. change *object.Change
  314. size int64
  315. }
  316. type sortableBlobs []sortableBlob
  317. func (change *sortableBlob) Less(other *sortableBlob) bool {
  318. return change.size < other.size
  319. }
  320. func (slice sortableBlobs) Len() int {
  321. return len(slice)
  322. }
  323. func (slice sortableBlobs) Less(i, j int) bool {
  324. return slice[i].Less(&slice[j])
  325. }
  326. func (slice sortableBlobs) Swap(i, j int) {
  327. slice[i], slice[j] = slice[j], slice[i]
  328. }
  329. func (analyser *Analyser) sizesAreClose(size1 int64, size2 int64) bool {
  330. return abs64(size1-size2)*100/max64(1, min64(size1, size2)) <=
  331. int64(100-analyser.SimilarityThreshold)
  332. }
  333. func (analyser *Analyser) blobsAreClose(
  334. blob1 *object.Blob, blob2 *object.Blob) bool {
  335. str_from := str(blob1)
  336. str_to := str(blob2)
  337. dmp := diffmatchpatch.New()
  338. src, dst, _ := dmp.DiffLinesToRunes(str_from, str_to)
  339. diffs := dmp.DiffMainRunes(src, dst, false)
  340. common := 0
  341. for _, edit := range diffs {
  342. if edit.Type == diffmatchpatch.DiffEqual {
  343. common += utf8.RuneCountInString(edit.Text)
  344. }
  345. }
  346. return common*100/max(1, min(len(src), len(dst))) >=
  347. analyser.SimilarityThreshold
  348. }
  349. func (analyser *Analyser) getBlob(entry *object.ChangeEntry, commit *object.Commit) (
  350. *object.Blob, error) {
  351. blob, err := analyser.Repository.BlobObject(entry.TreeEntry.Hash)
  352. if err != nil {
  353. if err.Error() != git.ErrObjectNotFound.Error() {
  354. fmt.Fprintf(os.Stderr, "getBlob(%s)\n", entry.TreeEntry.Hash.String())
  355. return nil, err
  356. }
  357. file, err_modules := commit.File(".gitmodules")
  358. if err_modules != nil {
  359. return nil, err
  360. }
  361. contents, err_modules := file.Contents()
  362. if err_modules != nil {
  363. return nil, err
  364. }
  365. modules := config.NewModules()
  366. err_modules = modules.Unmarshal([]byte(contents))
  367. if err_modules != nil {
  368. return nil, err
  369. }
  370. _, exists := modules.Submodules[entry.Name]
  371. if exists {
  372. // we found that this is a submodule
  373. return createDummyBlob(&entry.TreeEntry.Hash)
  374. }
  375. return nil, err
  376. }
  377. return blob, nil
  378. }
  379. func (analyser *Analyser) cacheBlobs(changes *object.Changes, commit *object.Commit) (
  380. *map[plumbing.Hash]*object.Blob, error) {
  381. cache := make(map[plumbing.Hash]*object.Blob)
  382. for _, change := range *changes {
  383. action, err := change.Action()
  384. if err != nil {
  385. return nil, err
  386. }
  387. switch action {
  388. case merkletrie.Insert:
  389. cache[change.To.TreeEntry.Hash], err = analyser.getBlob(&change.To, commit)
  390. if err != nil {
  391. fmt.Fprintf(os.Stderr, "file to %s\n", change.To.Name)
  392. }
  393. case merkletrie.Delete:
  394. cache[change.From.TreeEntry.Hash], err = analyser.getBlob(&change.From, commit)
  395. if err != nil {
  396. if err.Error() != git.ErrObjectNotFound.Error() {
  397. fmt.Fprintf(os.Stderr, "file from %s\n", change.From.Name)
  398. } else {
  399. cache[change.From.TreeEntry.Hash], err = createDummyBlob(
  400. &change.From.TreeEntry.Hash)
  401. }
  402. }
  403. case merkletrie.Modify:
  404. cache[change.To.TreeEntry.Hash], err = analyser.getBlob(&change.To, commit)
  405. if err != nil {
  406. fmt.Fprintf(os.Stderr, "file to %s\n", change.To.Name)
  407. }
  408. cache[change.From.TreeEntry.Hash], err = analyser.getBlob(&change.From, commit)
  409. if err != nil {
  410. fmt.Fprintf(os.Stderr, "file from %s\n", change.From.Name)
  411. }
  412. default:
  413. panic(fmt.Sprintf("unsupported action: %d", change.Action))
  414. }
  415. if err != nil {
  416. return nil, err
  417. }
  418. }
  419. return &cache, nil
  420. }
  421. func (analyser *Analyser) detectRenames(
  422. changes *object.Changes, cache *map[plumbing.Hash]*object.Blob) object.Changes {
  423. reduced_changes := make(object.Changes, 0, changes.Len())
  424. // Stage 1 - find renames by matching the hashes
  425. // n log(n)
  426. // We sort additions and deletions by hash and then do the single scan along
  427. // both slices.
  428. deleted := make(sortableChanges, 0, changes.Len())
  429. added := make(sortableChanges, 0, changes.Len())
  430. for _, change := range *changes {
  431. action, err := change.Action()
  432. if err != nil {
  433. panic(err)
  434. }
  435. switch action {
  436. case merkletrie.Insert:
  437. added = append(added, sortableChange{change, change.To.TreeEntry.Hash})
  438. case merkletrie.Delete:
  439. deleted = append(deleted, sortableChange{change, change.From.TreeEntry.Hash})
  440. case merkletrie.Modify:
  441. reduced_changes = append(reduced_changes, change)
  442. default:
  443. panic(fmt.Sprintf("unsupported action: %d", change.Action))
  444. }
  445. }
  446. sort.Sort(deleted)
  447. sort.Sort(added)
  448. a := 0
  449. d := 0
  450. still_deleted := make(object.Changes, 0, deleted.Len())
  451. still_added := make(object.Changes, 0, added.Len())
  452. for a < added.Len() && d < deleted.Len() {
  453. if added[a].hash == deleted[d].hash {
  454. reduced_changes = append(
  455. reduced_changes,
  456. &object.Change{From: deleted[d].change.From, To: added[a].change.To})
  457. a++
  458. d++
  459. } else if added[a].Less(&deleted[d]) {
  460. still_added = append(still_added, added[a].change)
  461. a++
  462. } else {
  463. still_deleted = append(still_deleted, deleted[d].change)
  464. d++
  465. }
  466. }
  467. for ; a < added.Len(); a++ {
  468. still_added = append(still_added, added[a].change)
  469. }
  470. for ; d < deleted.Len(); d++ {
  471. still_deleted = append(still_deleted, deleted[d].change)
  472. }
  473. // Stage 2 - apply the similarity threshold
  474. // n^2 but actually linear
  475. // We sort the blobs by size and do the single linear scan.
  476. added_blobs := make(sortableBlobs, 0, still_added.Len())
  477. deleted_blobs := make(sortableBlobs, 0, still_deleted.Len())
  478. for _, change := range still_added {
  479. blob := (*cache)[change.To.TreeEntry.Hash]
  480. added_blobs = append(
  481. added_blobs, sortableBlob{change: change, size: blob.Size})
  482. }
  483. for _, change := range still_deleted {
  484. blob := (*cache)[change.From.TreeEntry.Hash]
  485. deleted_blobs = append(
  486. deleted_blobs, sortableBlob{change: change, size: blob.Size})
  487. }
  488. sort.Sort(added_blobs)
  489. sort.Sort(deleted_blobs)
  490. d_start := 0
  491. for a = 0; a < added_blobs.Len(); a++ {
  492. my_blob := (*cache)[added_blobs[a].change.To.TreeEntry.Hash]
  493. my_size := added_blobs[a].size
  494. for d = d_start; d < deleted_blobs.Len() && !analyser.sizesAreClose(my_size, deleted_blobs[d].size); d++ {
  495. }
  496. d_start = d
  497. found_match := false
  498. for d = d_start; d < deleted_blobs.Len() && analyser.sizesAreClose(my_size, deleted_blobs[d].size); d++ {
  499. if analyser.blobsAreClose(
  500. my_blob, (*cache)[deleted_blobs[d].change.From.TreeEntry.Hash]) {
  501. found_match = true
  502. reduced_changes = append(
  503. reduced_changes,
  504. &object.Change{From: deleted_blobs[d].change.From,
  505. To: added_blobs[a].change.To})
  506. break
  507. }
  508. }
  509. if found_match {
  510. added_blobs = append(added_blobs[:a], added_blobs[a+1:]...)
  511. a--
  512. deleted_blobs = append(deleted_blobs[:d], deleted_blobs[d+1:]...)
  513. }
  514. }
  515. // Stage 3 - we give up, everything left are independent additions and deletions
  516. for _, blob := range added_blobs {
  517. reduced_changes = append(reduced_changes, blob.change)
  518. }
  519. for _, blob := range deleted_blobs {
  520. reduced_changes = append(reduced_changes, blob.change)
  521. }
  522. return reduced_changes
  523. }
  524. func (analyser *Analyser) Analyse(commits []*object.Commit) [][]int64 {
  525. sampling := analyser.Sampling
  526. if sampling == 0 {
  527. sampling = 1
  528. }
  529. onProgress := analyser.OnProgress
  530. if onProgress == nil {
  531. onProgress = func(int, int) {}
  532. }
  533. if analyser.SimilarityThreshold < 0 || analyser.SimilarityThreshold > 100 {
  534. panic("hercules.Analyser: an invalid SimilarityThreshold was specified")
  535. }
  536. // current daily alive number of lines; key is the number of days from the
  537. // beginning of the history
  538. status := map[int]int64{}
  539. // weekly snapshots of status
  540. statuses := [][]int64{}
  541. // mapping <file path> -> hercules.File
  542. files := map[string]*File{}
  543. var day0 time.Time // will be initialized in the first iteration
  544. var prev_tree *object.Tree = nil
  545. var day, prev_day int
  546. for index, commit := range commits {
  547. onProgress(index, len(commits))
  548. tree, err := commit.Tree()
  549. if err != nil {
  550. panic(err)
  551. }
  552. if index == 0 {
  553. // first iteration - initialize the file objects from the tree
  554. day0 = commit.Author.When
  555. func() {
  556. file_iter := tree.Files()
  557. defer file_iter.Close()
  558. for {
  559. file, err := file_iter.Next()
  560. if err != nil {
  561. if err == io.EOF {
  562. break
  563. }
  564. panic(err)
  565. }
  566. lines, err := loc(&file.Blob)
  567. if err == nil {
  568. files[file.Name] = NewFile(0, lines, status)
  569. }
  570. }
  571. }()
  572. } else {
  573. day = int(commit.Author.When.Sub(day0).Hours() / 24)
  574. if day < prev_day {
  575. // rebase makes miracles
  576. day = prev_day
  577. }
  578. delta := (day / sampling) - (prev_day / sampling)
  579. if delta > 0 {
  580. prev_day = day
  581. gs := analyser.groupStatus(status, day)
  582. for i := 0; i < delta; i++ {
  583. statuses = append(statuses, gs)
  584. }
  585. }
  586. tree_diff, err := object.DiffTree(prev_tree, tree)
  587. if err != nil {
  588. fmt.Fprintf(os.Stderr, "commit #%d %s\n", index, commit.Hash.String())
  589. panic(err)
  590. }
  591. cache, err := analyser.cacheBlobs(&tree_diff, commit)
  592. if err != nil {
  593. fmt.Fprintf(os.Stderr, "commit #%d %s\n", index, commit.Hash.String())
  594. panic(err)
  595. }
  596. tree_diff = analyser.detectRenames(&tree_diff, cache)
  597. for _, change := range tree_diff {
  598. action, err := change.Action()
  599. if err != nil {
  600. fmt.Fprintf(os.Stderr, "commit #%d %s\n", index, commit.Hash.String())
  601. panic(err)
  602. }
  603. switch action {
  604. case merkletrie.Insert:
  605. analyser.handleInsertion(change, day, status, files, cache)
  606. case merkletrie.Delete:
  607. analyser.handleDeletion(change, day, status, files, cache)
  608. case merkletrie.Modify:
  609. func() {
  610. defer func() {
  611. r := recover()
  612. if r != nil {
  613. fmt.Fprintf(os.Stderr, "#%d - %s: modification error\n",
  614. index, commit.Hash.String())
  615. panic(r)
  616. }
  617. }()
  618. analyser.handleModification(change, day, status, files, cache)
  619. }()
  620. }
  621. }
  622. }
  623. prev_tree = tree
  624. }
  625. gs := analyser.groupStatus(status, day)
  626. statuses = append(statuses, gs)
  627. return statuses
  628. }