Rename --branch option to --starting-revision Use a more appropriate option name. Branch is just one way of providing a revision For example, tags, SHA1s, symbolic refs are other possible ways of providing one. Change-Id: I85703b6d95004212cd7bf6033aaaac7d03a30b2e
diff --git a/README.md b/README.md index 56c9609..dec0ef6 100644 --- a/README.md +++ b/README.md
@@ -70,9 +70,9 @@ - --until -e Ending timestamp (excluded) to consider - --aggregate -granularity -g one of email, email_year, email_month, email_day, email_hour defaulting to aggregation by email - --extract-branches -r enables splitting of aggregation by branch name and expose branch name in the payload -- --branch -f extract results only for a specific branch +- --starting-revision -s extract results starting from a specific revision. Default: `HEAD`. -> **NOTE**: The `--extract-branches` and `--branch` options are mutually exclusive. +> **NOTE**: The `--extract-branches` and `--starting-revision` options are mutually exclusive. Note: `since` and/or `until` parameters are compulsory when using `--extract-branches`. Using `--extract-branches` without `since` or `until` would most likely cause OutOfMemory errors.
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala index c111226..a8ce1e5 100644 --- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala +++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/Contributors.scala
@@ -41,9 +41,9 @@ usage = "Do extra parsing to extract a list of all branches for each line") private var extractBranches: Boolean = false - @ArgOption(name = "--branch", aliases = Array("-f"), - usage = "Extract results only for a specific branch", required = false) - private var branchName: String = HEAD + @ArgOption(name = "--starting-revision", aliases = Array("-s"), + usage = "Extract results starting from a specific revision", required = false) + private var startingRevision: String = HEAD @ArgOption(name = "--since", aliases = Array("--after", "-b"), usage = "(included) begin timestamp. Must be in the format 2006-01-02[ 15:04:05[.890][ -0700]]") @@ -76,11 +76,11 @@ } override protected def run = { - if (extractBranches && branchName != HEAD) { - throw die(s"--extract-branches` and `--branch` options are mutually exclusive") + if (extractBranches && startingRevision != HEAD) { + throw die(s"--extract-branches` and `--starting-revision` options are mutually exclusive") } gsonFmt.format(executor.get(projectRes, beginDate, endDate, - granularity.getOrElse(AggregationStrategy.EMAIL), extractBranches, branchName), stdout) + granularity.getOrElse(AggregationStrategy.EMAIL), extractBranches, startingRevision), stdout) } } @@ -129,18 +129,18 @@ usage = "Do extra parsing to extract a list of all branches for each line") private var extractBranches: Boolean = false - @ArgOption(name = "--branch", aliases = Array("-f"), - usage = "Extract results only for a specific branch", required = false) - private var branchName: String = HEAD + @ArgOption(name = "--starting-revision", aliases = Array("-s"), + usage = "Extract results starting from a specific revision", required = false) + private var startingRevision: String = HEAD override def apply(projectRes: ProjectResource) = { - if (extractBranches && branchName != HEAD) { - Response.withStatusCode(400, s"'extract-branches' and 'branch' options are mutually exclusive") + if (extractBranches && startingRevision != HEAD) { + Response.withStatusCode(400, s"'extract-branches' and 'starting-revision' options are mutually exclusive") } else { Response.ok( new GsonStreamedResult[UserActivitySummary](gson, executor.get(projectRes, beginDate, endDate, - granularity.getOrElse(AggregationStrategy.EMAIL), extractBranches, branchName))) + granularity.getOrElse(AggregationStrategy.EMAIL), extractBranches, startingRevision))) }
diff --git a/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/UserActivityHistogram.scala b/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/UserActivityHistogram.scala index d3bb145..9e9856e 100644 --- a/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/UserActivityHistogram.scala +++ b/src/main/scala/com/googlesource/gerrit/plugins/analytics/common/UserActivityHistogram.scala
@@ -22,11 +22,11 @@ @Singleton class UserActivityHistogram { - def get(repo: Repository, filter: AbstractCommitHistogramFilter, branchName: String = HEAD) = { + def get(repo: Repository, filter: AbstractCommitHistogramFilter, startingRevision: String = HEAD) = { val finder = new CommitFinder(repo) try { - finder.setFilter(filter).findFrom(branchName) + finder.setFilter(filter).findFrom(startingRevision) val histogram = filter.getHistogram histogram.getAggregatedUserActivity } catch {
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/analytics/common/UserActivityHistogramSpec.scala b/src/test/scala/com/googlesource/gerrit/plugins/analytics/common/UserActivityHistogramSpec.scala index 12e100c..aa124c7 100644 --- a/src/test/scala/com/googlesource/gerrit/plugins/analytics/common/UserActivityHistogramSpec.scala +++ b/src/test/scala/com/googlesource/gerrit/plugins/analytics/common/UserActivityHistogramSpec.scala
@@ -33,14 +33,14 @@ new UserActivityHistogram().get(testFileRepository.getRepository, filter) should have size 1 } - it should "filter by branch" in { - val branch = "testBranch" - testFileRepository.commitFile("test.txt", "content", branch=branch) + it should "extract starting from the specified revision" in { + val startingBranch = "testBranch" + testFileRepository.commitFile("test.txt", "content", branch=startingBranch) val filter = new AggregatedHistogramFilterByDates(aggregationStrategy = EMAIL_YEAR) new UserActivityHistogram().get(testFileRepository.getRepository, filter) should have size 0 - new UserActivityHistogram().get(testFileRepository.getRepository, filter, branch) should have size 1 + new UserActivityHistogram().get(testFileRepository.getRepository, filter, startingBranch) should have size 1 } }