From 543d39246f0b7cd5a75f74c0ed5f04a7aeb137ee Mon Sep 17 00:00:00 2001
From: Eric Amodio <eamodio@gmail.com>
Date: Tue, 12 Sep 2017 17:46:22 -0400
Subject: [PATCH] Closes #138 - adds ignore whitespace setting

---
 CHANGELOG.md         | 21 +++++++++++++--------
 README.md            |  6 +++++-
 package.json         |  5 +++++
 src/configuration.ts |  2 ++
 src/git/git.ts       | 10 ++++++----
 src/gitService.ts    | 11 +++++++++--
 6 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f57728e..451a842 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,13 +58,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
   - Quickly switch between views using the `Switch to Repository View` or `Switch to History View` commands
   - Provides toolbar commands to `Search Commits`, `Switch to Repository View` or `Switch to History View`, and `Refresh`
 
-- Adds command-links to the `details` hover annotation
-  - Clicking the commit id will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
-- Adds command-links to the `changes` hover annotation
-  - Clicking on `Changes` will run the `Compare File Revisions` command (`gitlens.diffWith`)
-  - Clicking the current and previous commit ids will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
-- Adds support for remote services with custom domains - see [#120](https://github.com/eamodio/vscode-gitlens/issues/120)
-- Adds support for the Bitbucket Server (previously called Stash) remote service - see [#120](https://github.com/eamodio/vscode-gitlens/issues/120)
+- Adds all-new interactivity to the hover annotations
+
+  ![Hover Annotations](https://raw.githubusercontent.com/eamodio/vscode-gitlens/develop/images/screenshot-line-blame-annotations.png)
+
+  - Adds the following command-links to the `details` hover annotation
+    - Clicking the commit id will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
+  - Adds the following command-links to the `changes` hover annotation
+    - Clicking on `Changes` will run the `Compare File Revisions` command (`gitlens.diffWith`)
+    - Clicking the current and previous commit ids will run the `Show Commit Details` command (`gitlens.showQuickCommitDetails`)
+
+- Adds support for remote services with custom domains -- closes [#120](https://github.com/eamodio/vscode-gitlens/issues/120)
+- Adds support for the Bitbucket Server (previously called Stash) remote service -- closes [#120](https://github.com/eamodio/vscode-gitlens/issues/120)
+- Adds `gitlens.blame.ignoreWhitespace` setting to specify whether or not to ignore whitespace when comparing revisions during blame operations -- closes [#138](https://github.com/eamodio/vscode-gitlens/issues/138)
 - Adds `Compare File Revisions` command (`gitlens.diffWith`) - compares the specified file revisions
 - Adds `Open Branches in Remote` command (`gitlens.openBranchesInRemote`) - opens the branches in the supported remote service
 - Adds `Stash Changes` command (`gitlens.stashSave`) to the source control group context menu -- can now stash a group of files
@@ -97,7 +103,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
 - Fixes an issue where double hover annotations could be shown on blank lines
 - Fixes an issue where remote branches couldn't be opened properly in their remote service
 - Fixes [#130](https://github.com/eamodio/vscode-gitlens/issues/130) - First-run "Thank you for choosing GitLens! [...]" info message shown on every start up
-- Fixes [#120](https://github.com/eamodio/vscode-gitlens/issues/120) - Feature Request: "Open in Remote" support for custom repositories
 - Fixes an issue where sometimes diffs (via branch name) wouldn't open properly
 - Fixes an issue where remotes are queried more than once on startup
 
diff --git a/README.md b/README.md
index d04c223..4ddaea7 100644
--- a/README.md
+++ b/README.md
@@ -287,7 +287,11 @@ GitLens is highly customizable and provides many configuration settings to allow
 |`gitlens.insiders`|Opts into the insiders channel -- provides access to upcoming features
 |`gitlens.outputLevel`|Specifies how much (if any) output will be sent to the GitLens output channel
 
-### Blame Annotation Settings
+### Blame Settings
+
+|Name | Description
+|-----|------------
+|`gitlens.blame.ignoreWhitespace`|Specifies whether or not to ignore whitespace when comparing revisions during blame operations
 
 #### File Blame Annotation Settings
 
diff --git a/package.json b/package.json
index fa7d010..4b1c4bc 100644
--- a/package.json
+++ b/package.json
@@ -172,6 +172,11 @@
                     "default": false,
                     "description": "Specifies whether or not to trigger hover annotations over the whole line"
                 },
+                "gitlens.blame.ignoreWhitespace": {
+                    "type": "boolean",
+                    "default": false,
+                    "description": "Specifies whether or not to ignore whitespace when comparing revisions during blame operations"
+                },
                 "gitlens.blame.file.annotationType": {
                     "type": "string",
                     "default": "gutter",
diff --git a/src/configuration.ts b/src/configuration.ts
index 667e741..830ab51 100644
--- a/src/configuration.ts
+++ b/src/configuration.ts
@@ -275,6 +275,8 @@ export interface IConfig {
     };
 
     blame: {
+        ignoreWhitespace: boolean;
+
         file: {
             annotationType: FileAnnotationType;
             lineHighlight: {
diff --git a/src/git/git.ts b/src/git/git.ts
index 15b578b..dd98ce9 100644
--- a/src/git/git.ts
+++ b/src/git/git.ts
@@ -177,15 +177,17 @@ export class Git {
 
     // Git commands
 
-    static blame(repoPath: string | undefined, fileName: string, sha?: string, startLine?: number, endLine?: number) {
+    static blame(repoPath: string | undefined, fileName: string, sha?: string, options: { ignoreWhitespace?: boolean, startLine?: number, endLine?: number } = {}) {
         const [file, root] = Git.splitPath(fileName, repoPath);
 
         const params = [`blame`, `--root`, `--incremental`];
 
-        if (startLine != null && endLine != null) {
-            params.push(`-L ${startLine},${endLine}`);
+        if (options.ignoreWhitespace) {
+            params.push('-w');
+        }
+        if (options.startLine != null && options.endLine != null) {
+            params.push(`-L ${options.startLine},${options.endLine}`);
         }
-
         if (sha) {
             params.push(sha);
         }
diff --git a/src/gitService.ts b/src/gitService.ts
index f35e7c6..7ce8314 100644
--- a/src/gitService.ts
+++ b/src/gitService.ts
@@ -193,7 +193,14 @@ export class GitService extends Disposable {
             });
         }
 
+        const ignoreWhitespace = this.config && this.config.blame.ignoreWhitespace;
+
         this.config = cfg;
+
+        if (this.config.blame.ignoreWhitespace !== ignoreWhitespace) {
+            this._gitCache.clear();
+            this._fireGitCacheChange();
+        }
     }
 
     private _onRemoteProviderChanged() {
@@ -428,7 +435,7 @@ export class GitService extends Disposable {
         }
 
         try {
-            const data = await Git.blame(root, file, uri.sha);
+            const data = await Git.blame(root, file, uri.sha, { ignoreWhitespace: this.config.blame.ignoreWhitespace });
             const blame = GitBlameParser.parse(data, root, file);
             return blame;
         }
@@ -477,7 +484,7 @@ export class GitService extends Disposable {
         const fileName = uri.fsPath;
 
         try {
-            const data = await Git.blame(uri.repoPath, fileName, uri.sha, line + 1, line + 1);
+            const data = await Git.blame(uri.repoPath, fileName, uri.sha, { ignoreWhitespace: this.config.blame.ignoreWhitespace, startLine: line + 1, endLine: line + 1 });
             const blame = GitBlameParser.parse(data, uri.repoPath, fileName);
             if (blame === undefined) return undefined;