Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blame: allow user to specify rev arguments to blame #439

Merged
merged 1 commit into from
Sep 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,35 @@ blame_open(struct view *view, enum open_flags flags)

if (is_initial_view(view)) {
/* Finish validating and setting up blame options */
if (!opt_file_args || opt_file_args[1] || (opt_rev_args && opt_rev_args[1]))
if (!opt_file_args || opt_file_args[1])
usage("Invalid number of options to blame");

if (opt_rev_args) {
string_ncopy(view->env->ref, opt_rev_args[0], strlen(opt_rev_args[0]));
}

string_ncopy(view->env->file, opt_file_args[0], strlen(opt_file_args[0]));

opt_blame_options = opt_cmdline_args;
opt_cmdline_args = NULL;

/*
* flags (like "--max-age=123") and bottom limits (like "^foo")
* will be passed as-is, and retained even if we re-blame from
* a parent.
*
* Positive start points (like "HEAD") are placed only in
* view->env->ref, which may be later overridden. We must
* ensure there's only one of these.
*/
if (opt_rev_args) {
for (i = 0; opt_rev_args[i]; i++) {
const char *arg = opt_rev_args[i];

if (arg[0] == '-' || arg[0] == '^')
argv_append(&opt_blame_options, arg);
else if (!view->env->ref[0])
string_ncopy(view->env->ref, arg, strlen(arg));
else
usage("Invalid number of options to blame");
}
}
}

if (!view->env->file[0]) {
Expand Down
82 changes: 82 additions & 0 deletions test/blame/revargs-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/sh

. libtest.sh
. libgit.sh

steps '
:save-display limit.screen

:8
:parent
:save-display parent-of-4779f9b.screen
'

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"

test_tig blame 74537d9..HEAD project/Build.scala

# note that we show boundary commits, so the lower bound 74537d9 appears
assert_equals 'limit.screen' <<EOF
2013-10-29 18:46 Sébastien Doeraene 74537d9 import sbt._
2013-10-29 18:46 Sébastien Doeraene 74537d9 import Keys._
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 import scala.scalajs.sbtplugin._
2013-10-29 18:46 Sébastien Doeraene 74537d9 import ScalaJSPlugin._
2013-10-29 18:46 Sébastien Doeraene 74537d9 import ScalaJSKeys._
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-11-26 20:13 Jonas Fonseca 4779f9b object ScalaJSBenchmarks extends Bui
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-11-26 20:13 Jonas Fonseca 4779f9b val scalaJSScalaVersion = "2.10.2"
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 val projectSettings = Defaults.def
2013-10-29 18:46 Sébastien Doeraene 74537d9 organization := "scalajs-bench
2013-10-29 18:46 Sébastien Doeraene 74537d9 version := "0.1-SNAPSHOT"
2013-10-29 18:46 Sébastien Doeraene 74537d9 )
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 val defaultSettings = projectSetti
2013-11-26 20:13 Jonas Fonseca 4779f9b scalaVersion := scalaJSScalaVe
2013-10-29 18:46 Sébastien Doeraene 74537d9 scalacOptions ++= Seq(
2013-10-29 18:46 Sébastien Doeraene 74537d9 "-deprecation",
2013-10-29 18:46 Sébastien Doeraene 74537d9 "-unchecked",
2013-10-29 18:46 Sébastien Doeraene 74537d9 "-feature",
2013-10-29 18:46 Sébastien Doeraene 74537d9 "-encoding", "utf8"
2013-10-29 18:46 Sébastien Doeraene 74537d9 )
2013-10-29 18:46 Sébastien Doeraene 74537d9 )
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 lazy val parent: Project = Project
2013-10-29 18:46 Sébastien Doeraene 74537d9 id = "parent",
[blame] project/Build.scala - line 1 of 64 43%
EOF

# confirm that we kept our lower bound
assert_equals 'parent-of-4779f9b.screen' <<EOF
2013-10-29 18:46 Sébastien Doeraene 74537d9 import sbt._
2013-10-29 18:46 Sébastien Doeraene 74537d9 import Keys._
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 import scala.scalajs.sbtplugin._
2013-10-29 18:46 Sébastien Doeraene 74537d9 import ScalaJSPlugin._
2013-10-29 18:46 Sébastien Doeraene 74537d9 import ScalaJSKeys._
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 object ScalaJSBuild extends Build {
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 val scalajsScalaVersion = "2.10.2"
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 val projectSettings = Defaults.def
2013-10-29 18:46 Sébastien Doeraene 74537d9 organization := "scalajs-bench
2013-10-29 18:46 Sébastien Doeraene 74537d9 version := "0.1-SNAPSHOT"
2013-10-29 18:46 Sébastien Doeraene 74537d9 )
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 val defaultSettings = projectSetti
2013-10-29 18:46 Sébastien Doeraene 74537d9 scalaVersion := scalajsScalaVe
2013-10-29 18:46 Sébastien Doeraene 74537d9 scalacOptions ++= Seq(
2013-10-29 18:46 Sébastien Doeraene 74537d9 "-deprecation",
2013-10-29 18:46 Sébastien Doeraene 74537d9 "-unchecked",
2013-10-29 18:46 Sébastien Doeraene 74537d9 "-feature",
2013-10-29 18:46 Sébastien Doeraene 74537d9 "-encoding", "utf8"
2013-10-29 18:46 Sébastien Doeraene 74537d9 )
2013-10-29 18:46 Sébastien Doeraene 74537d9 )
2013-10-29 18:46 Sébastien Doeraene 74537d9
2013-10-29 18:46 Sébastien Doeraene 74537d9 lazy val benchmarkSettings = defau
2013-10-29 18:46 Sébastien Doeraene 74537d9 unmanagedSources in (Compile,
[blame] project/Build.scala - line 8 of 69 40%
EOF