Skip to content

Commit 80f0c45

Browse files
committed
Rework during review
* use view->env for inter-views communication * move state initialisation after view->lines is known * I don't see a real added value for open-diff-test over existing default-test for the blame view
1 parent cfdc85f commit 80f0c45

File tree

7 files changed

+23
-161
lines changed

7 files changed

+23
-161
lines changed

include/tig/argv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ typedef unsigned long argv_number;
6363
struct argv_env {
6464
ARGV_ENV_INFO(ARGV_ENV_FIELDS)
6565
unsigned long goto_lineno;
66+
unsigned long blame_lineno;
6667
char goto_id[SIZEOF_REV];
6768
char search[SIZEOF_STR];
6869
char none[1];

include/tig/blame.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#include "tig/view.h"
1818

1919
extern struct view blame_view;
20-
extern char *filename_from_blame;
21-
extern unsigned long lineno_from_blame;
2220

2321
static inline void
2422
open_blame_view(struct view *prev, enum open_flags flags)

include/tig/view.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ enum open_flags {
174174
OPEN_PREPARED = 32, /* Open already prepared command. */
175175
OPEN_EXTRA = 64, /* Open extra data from command. */
176176
OPEN_WITH_STDERR = 128, /* Redirect stderr to stdin. */
177-
OPEN_BLAMED_LINE = 256, /* Open the file and line stored by blame view */
178177

179178
OPEN_PAGER_MODE = OPEN_STDIN | OPEN_FORWARD_STDIN,
180179
OPEN_ALWAYS_LOAD = OPEN_RELOAD | OPEN_REFRESH | OPEN_PREPARED | OPEN_EXTRA | OPEN_PAGER_MODE,

src/blame.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
* GNU General Public License for more details.
1212
*/
1313

14-
#include "tig/blame.h"
1514
#include "tig/io.h"
1615
#include "tig/refdb.h"
1716
#include "tig/repo.h"
@@ -24,9 +23,6 @@
2423
#include "tig/diff.h"
2524
#include "tig/main.h"
2625

27-
char *filename_from_blame = NULL;
28-
unsigned long lineno_from_blame;
29-
3026
/*
3127
* Blame backend
3228
*/
@@ -455,12 +451,9 @@ blame_request(struct view *view, enum request request, struct line *line)
455451
if (diff->pipe)
456452
string_copy_rev(diff->ref, NULL_ID);
457453
} else {
458-
if (filename_from_blame) {
459-
free(filename_from_blame);
460-
}
461-
filename_from_blame = strdup(blame->commit->filename);
462-
lineno_from_blame = blame -> lineno;
463-
open_diff_view(view, flags | OPEN_RELOAD | OPEN_BLAMED_LINE);
454+
string_ncopy(view->env->file, blame->commit->filename, strlen(blame->commit->filename));
455+
view->env->blame_lineno = blame->lineno;
456+
open_diff_view(view, flags | OPEN_RELOAD);
464457
}
465458
break;
466459

src/diff.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
#include "tig/argv.h"
15-
#include "tig/blame.h"
1615
#include "tig/refdb.h"
1716
#include "tig/repo.h"
1817
#include "tig/options.h"
@@ -453,14 +452,6 @@ diff_save_line(struct view *view, struct diff_state *state, enum open_flags flag
453452
state->pos = view->pos;
454453
}
455454
}
456-
if (flags & OPEN_BLAMED_LINE) {
457-
const char *file = filename_from_blame;
458-
if (file) {
459-
state->file = get_path(file);
460-
state->lineno = lineno_from_blame;
461-
state->pos.offset = 5; // TODO: Should be half screen
462-
}
463-
}
464455
}
465456

466457
void
@@ -552,6 +543,15 @@ diff_read(struct view *view, struct buffer *buf, bool force_stop)
552543
}
553544
}
554545

546+
if (view->env->blame_lineno) {
547+
state->file = get_path(view->env->file);
548+
state->lineno = view->env->blame_lineno;
549+
state->pos.offset = 0;
550+
state->pos.lineno = view->lines - 1;
551+
552+
view->env->blame_lineno = 0;
553+
}
554+
555555
diff_restore_line(view, state);
556556

557557
if (!state->adding_describe_ref && !ref_list_contains_tag(view->vid)) {

test/blame/default-test

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,24 @@ assert_equals 'blame-with-diff.screen' <<EOF
7171
4779f9b Jonas Fonseca 2013-11-26 20:13 -0500 8| object ScalaJSBenchmarks
7272
90286e0 Jonas Fonseca 2013-10-14 13:15 -0400 9|
7373
[blame] 74537d9b257954056d3caa19eb3837500aded883 changed project/Build.scala 14%
74-
74+
7575
diff --git a/project/Build.scala b/project/Build.scala
7676
index 560bca1..1713681 100644
7777
--- a/project/Build.scala
7878
+++ b/project/Build.scala
7979
@@ -1,7 +1,7 @@
8080
import sbt._
8181
import Keys._
82-
82+
8383
-import ch.epfl.lamp.sbtscalajs._
8484
+import scala.scalajs.sbtplugin._
8585
import ScalaJSPlugin._
8686
import ScalaJSKeys._
87-
88-
89-
90-
91-
87+
88+
89+
90+
91+
9292
[diff] Changes to 'project/Build.scala' - line 20 of 24 100%
9393
EOF
9494

@@ -103,20 +103,20 @@ assert_equals 'blame-with-diff-no-file-filter.screen' <<EOF
103103
4779f9b Jonas Fonseca 2013-11-26 20:13 -0500 8| object ScalaJSBenchmarks
104104
90286e0 Jonas Fonseca 2013-10-14 13:15 -0400 9|
105105
[blame] 74537d9b257954056d3caa19eb3837500aded883 changed project/Build.scala 14%
106-
106+
107107
diff --git a/project/Build.scala b/project/Build.scala
108108
index 560bca1..1713681 100644
109109
--- a/project/Build.scala
110110
+++ b/project/Build.scala
111111
@@ -1,7 +1,7 @@
112112
import sbt._
113113
import Keys._
114-
114+
115115
-import ch.epfl.lamp.sbtscalajs._
116116
+import scala.scalajs.sbtplugin._
117117
import ScalaJSPlugin._
118118
import ScalaJSKeys._
119-
119+
120120
diff --git a/project/build.sbt b/project/build.sbt
121121
index 63f84d4..f5971c3 100644
122122
--- a/project/build.sbt

test/blame/open-diff-test

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)