core.go 8.3 KB

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