core.go 8.9 KB

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