core.go 8.5 KB

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