core.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package hercules
  2. import (
  3. "gopkg.in/src-d/go-git.v4"
  4. "gopkg.in/src-d/go-git.v4/plumbing/object"
  5. "gopkg.in/src-d/hercules.v6/internal/core"
  6. "gopkg.in/src-d/hercules.v6/internal/plumbing"
  7. "gopkg.in/src-d/hercules.v6/internal/plumbing/identity"
  8. "gopkg.in/src-d/hercules.v6/internal/plumbing/uast"
  9. "gopkg.in/src-d/hercules.v6/internal/yaml"
  10. "gopkg.in/src-d/hercules.v6/leaves"
  11. )
  12. // ConfigurationOptionType represents the possible types of a ConfigurationOption's value.
  13. type ConfigurationOptionType = core.ConfigurationOptionType
  14. const (
  15. // BoolConfigurationOption reflects the boolean value type.
  16. BoolConfigurationOption = core.BoolConfigurationOption
  17. // IntConfigurationOption reflects the integer value type.
  18. IntConfigurationOption = core.IntConfigurationOption
  19. // StringConfigurationOption reflects the string value type.
  20. StringConfigurationOption = core.StringConfigurationOption
  21. // FloatConfigurationOption reflects a floating point value type.
  22. FloatConfigurationOption = core.FloatConfigurationOption
  23. // StringsConfigurationOption reflects the array of strings value type.
  24. StringsConfigurationOption = core.StringsConfigurationOption
  25. )
  26. // ConfigurationOption allows for the unified, retrospective way to setup PipelineItem-s.
  27. type ConfigurationOption = core.ConfigurationOption
  28. // PipelineItem is the interface for all the units in the Git commits analysis pipeline.
  29. type PipelineItem = core.PipelineItem
  30. // FeaturedPipelineItem enables switching the automatic insertion of pipeline items on or off.
  31. type FeaturedPipelineItem = core.FeaturedPipelineItem
  32. // LeafPipelineItem corresponds to the top level pipeline items which produce the end results.
  33. type LeafPipelineItem = core.LeafPipelineItem
  34. // ResultMergeablePipelineItem specifies the methods to combine several analysis results together.
  35. type ResultMergeablePipelineItem = core.ResultMergeablePipelineItem
  36. // CommonAnalysisResult holds the information which is always extracted at Pipeline.Run().
  37. type CommonAnalysisResult = core.CommonAnalysisResult
  38. // NoopMerger provides an empty Merge() method suitable for PipelineItem.
  39. type NoopMerger = core.NoopMerger
  40. // OneShotMergeProcessor provides the convenience method to consume merges only once.
  41. type OneShotMergeProcessor = core.OneShotMergeProcessor
  42. // MetadataToCommonAnalysisResult copies the data from a Protobuf message.
  43. func MetadataToCommonAnalysisResult(meta *core.Metadata) *CommonAnalysisResult {
  44. return core.MetadataToCommonAnalysisResult(meta)
  45. }
  46. // Pipeline is the core Hercules entity which carries several PipelineItems and executes them.
  47. // See the extended example of how a Pipeline works in doc.go
  48. type Pipeline = core.Pipeline
  49. const (
  50. // ConfigPipelineDAGPath is the name of the Pipeline configuration option (Pipeline.Initialize())
  51. // which enables saving the items DAG to the specified file.
  52. ConfigPipelineDAGPath = core.ConfigPipelineDAGPath
  53. // ConfigPipelineDumpPlan is the name of the Pipeline configuration option (Pipeline.Initialize())
  54. // which outputs the execution plan to stderr.
  55. ConfigPipelineDumpPlan = core.ConfigPipelineDumpPlan
  56. // ConfigPipelineDryRun is the name of the Pipeline configuration option (Pipeline.Initialize())
  57. // which disables Configure() and Initialize() invocation on each PipelineItem during the
  58. // Pipeline initialization.
  59. // Subsequent Run() calls are going to fail. Useful with ConfigPipelineDAGPath=true.
  60. ConfigPipelineDryRun = core.ConfigPipelineDryRun
  61. // ConfigPipelineCommits is the name of the Pipeline configuration option (Pipeline.Initialize())
  62. // which allows to specify the custom commit sequence. By default, Pipeline.Commits() is used.
  63. ConfigPipelineCommits = core.ConfigPipelineCommits
  64. )
  65. // NewPipeline initializes a new instance of Pipeline struct.
  66. func NewPipeline(repository *git.Repository) *Pipeline {
  67. return core.NewPipeline(repository)
  68. }
  69. // LoadCommitsFromFile reads the file by the specified FS path and generates the sequence of commits
  70. // by interpreting each line as a Git commit hash.
  71. func LoadCommitsFromFile(path string, repository *git.Repository) ([]*object.Commit, error) {
  72. return core.LoadCommitsFromFile(path, repository)
  73. }
  74. // ForkSamePipelineItem clones items by referencing the same origin.
  75. func ForkSamePipelineItem(origin PipelineItem, n int) []PipelineItem {
  76. return core.ForkSamePipelineItem(origin, n)
  77. }
  78. // ForkCopyPipelineItem clones items by copying them by value from the origin.
  79. func ForkCopyPipelineItem(origin PipelineItem, n int) []PipelineItem {
  80. return core.ForkCopyPipelineItem(origin, n)
  81. }
  82. // PipelineItemRegistry contains all the known PipelineItem-s.
  83. type PipelineItemRegistry = core.PipelineItemRegistry
  84. // Registry contains all known pipeline item types.
  85. var Registry = core.Registry
  86. const (
  87. // DependencyCommit is the name of one of the three items in `deps` supplied to PipelineItem.Consume()
  88. // which always exists. It corresponds to the currently analyzed commit.
  89. DependencyCommit = core.DependencyCommit
  90. // DependencyIndex is the name of one of the three items in `deps` supplied to PipelineItem.Consume()
  91. // which always exists. It corresponds to the currently analyzed commit's index.
  92. DependencyIndex = core.DependencyIndex
  93. // DependencyIsMerge is the name of one of the three items in `deps` supplied to PipelineItem.Consume()
  94. // which always exists. It indicates whether the analyzed commit is a merge commit.
  95. // Checking the number of parents is not correct - we remove the back edges during the DAG simplification.
  96. DependencyIsMerge = core.DependencyIsMerge
  97. // DependencyAuthor is the name of the dependency provided by identity.Detector.
  98. DependencyAuthor = identity.DependencyAuthor
  99. // DependencyBlobCache identifies the dependency provided by BlobCache.
  100. DependencyBlobCache = plumbing.DependencyBlobCache
  101. // DependencyDay is the name of the dependency which DaysSinceStart provides - the number
  102. // of days since the first commit in the analysed sequence.
  103. DependencyDay = plumbing.DependencyDay
  104. // DependencyFileDiff is the name of the dependency provided by FileDiff.
  105. DependencyFileDiff = plumbing.DependencyFileDiff
  106. // DependencyTreeChanges is the name of the dependency provided by TreeDiff.
  107. DependencyTreeChanges = plumbing.DependencyTreeChanges
  108. // DependencyUastChanges is the name of the dependency provided by Changes.
  109. DependencyUastChanges = uast.DependencyUastChanges
  110. // DependencyUasts is the name of the dependency provided by Extractor.
  111. DependencyUasts = uast.DependencyUasts
  112. // FactCommitsByDay contains the mapping between day indices and the corresponding commits.
  113. FactCommitsByDay = plumbing.FactCommitsByDay
  114. // FactIdentityDetectorPeopleCount is the name of the fact which is inserted in
  115. // identity.Detector.Configure(). It is equal to the overall number of unique authors
  116. // (the length of ReversedPeopleDict).
  117. FactIdentityDetectorPeopleCount = identity.FactIdentityDetectorPeopleCount
  118. // FactIdentityDetectorPeopleDict is the name of the fact which is inserted in
  119. // identity.Detector.Configure(). It corresponds to identity.Detector.PeopleDict - the mapping
  120. // from the signatures to the author indices.
  121. FactIdentityDetectorPeopleDict = identity.FactIdentityDetectorPeopleDict
  122. // FactIdentityDetectorReversedPeopleDict is the name of the fact which is inserted in
  123. // identity.Detector.Configure(). It corresponds to identity.Detector.ReversedPeopleDict -
  124. // the mapping from the author indices to the main signature.
  125. FactIdentityDetectorReversedPeopleDict = identity.FactIdentityDetectorReversedPeopleDict
  126. )
  127. // FileDiffData is the type of the dependency provided by plumbing.FileDiff.
  128. type FileDiffData = plumbing.FileDiffData
  129. // CachedBlob allows to explicitly cache the binary data associated with the Blob object.
  130. // Such structs are returned by DependencyBlobCache.
  131. type CachedBlob = plumbing.CachedBlob
  132. // SafeYamlString escapes the string so that it can be reliably used in YAML.
  133. func SafeYamlString(str string) string {
  134. return yaml.SafeString(str)
  135. }
  136. func init() {
  137. // hack to link with .leaves
  138. _ = leaves.BurndownAnalysis{}
  139. }