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

Diffstat #672

Merged
merged 2 commits into from
Jun 16, 2017
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
14 changes: 13 additions & 1 deletion GitSavvy.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
// to use columns globally, --no-columns should be added here.
// "branch": ["--no-columns"]
},

/*
Prints branches sorted by recent commit (works with git 2.7.0+)
https://www.kernel.org/pub/software/scm/git/docs/git-branch.html
Expand Down Expand Up @@ -165,6 +165,18 @@
*/
"log_show_more_commit_info": true,

/*
Diffstat look like
core/commands/blame.py | 13 +++++--------
core/commands/log.py | 9 +++------
core/git_mixins/history.py | 8 ++------
3 files changed, 10 insertions(+), 20 deletions(-)

Set to `false` if don't want to show this when view a commit.
*/
"show_diffstat": true,
Copy link
Collaborator

@randy3k randy3k Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be more clear to separate the settings for show_commit.py and show_commit_info.py?
I suggest using show_diff_stat_in_show_commit_view for show_commit.py and show_diff_stat_in_commit_info or somethings along this line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep it all in one setting since if you are interested in diffstat somewhere you would probably like so see it elsewhere.
Maybe we can have one setting for all views and one setting to display it in commit view

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. #488 is a separated issue.



/*
When set to `true`, GitSavvy will automatically display more info about the
current commit in a output panel. When set to `false`, this function must
Expand Down
7 changes: 7 additions & 0 deletions core/commands/show_commit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

import sublime
from sublime_plugin import WindowCommand, TextCommand

from ..git_command import GitCommand
Expand All @@ -15,12 +16,14 @@ def run(self, commit_hash):
# need to get repo_path before the new view is created.
repo_path = self.repo_path
view = self.window.new_file()
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
view.set_syntax_file("Packages/GitSavvy/syntax/show_commit.sublime-syntax")
view.settings().set("git_savvy.show_commit_view", True)
view.settings().set("git_savvy.show_commit_view.commit", commit_hash)
view.settings().set("git_savvy.repo_path", repo_path)
view.settings().set("git_savvy.show_commit_view.ignore_whitespace", False)
view.settings().set("git_savvy.show_commit_view.show_word_diff", False)
view.settings().set("git_savvy.show_commit_view.show_diffstat", savvy_settings.get("show_diffstat", True))
view.settings().set("word_wrap", False)
view.settings().set("line_numbers", False)
view.set_name(SHOW_COMMIT_TITLE.format(self.get_short_hash(commit_hash)))
Expand All @@ -35,10 +38,14 @@ def run(self, edit):
commit_hash = self.view.settings().get("git_savvy.show_commit_view.commit")
ignore_whitespace = self.view.settings().get("git_savvy.show_commit_view.ignore_whitespace")
show_word_diff = self.view.settings().get("git_savvy.show_commit_view.show_word_diff")
show_diffstat = self.view.settings().get("git_savvy.show_commit_view.show_diffstat")
content = self.git(
"show",
"--ignore-all-space" if ignore_whitespace else None,
"--word-diff" if show_word_diff else None,
"--stat" if show_diffstat else None,
"--patch",
"--format=fuller",
"--no-color",
commit_hash)
self.view.run_command("gs_replace_view_text", {"text": content, "nuke_cursors": True})
Expand Down
10 changes: 9 additions & 1 deletion core/commands/show_commit_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ def run(self, commit_hash):
def run_async(self):
savvy_settings = sublime.load_settings("GitSavvy.sublime-settings")
show_full = savvy_settings.get("show_full_commit_info")
text = self.git("show", self._commit_hash, "--no-color", "--format=fuller", "--quiet" if not show_full else None)
show_diffstat = savvy_settings.get("show_diffstat")
text = self.git(
"show",
"--no-color",
"--format=fuller",
"--stat" if show_diffstat else None,
"--patch" if show_full else None,
self._commit_hash
)
output_view = self.window.create_output_panel("show_commit_info")
output_view.set_read_only(False)
output_view.run_command("gs_replace_view_text", {"text": text, "nuke_cursors": True})
Expand Down
5 changes: 5 additions & 0 deletions syntax/show_commit.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ contexts:
2: string.other.commit-info.header.key.punctuation.git-savvy
3: meta.commit-info.header.value.git-savvy

- match: ^---$
scope: meta.commit-header-and-stat-splitter
comment: Separator between commit message and diffstat

- include: "scope:git-savvy.commit-diffstat"
- include: "scope:git-savvy.diff"
34 changes: 34 additions & 0 deletions syntax/show_commit_diffstat.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: GitSavvy Diffstat
hidden: true
scope: git-savvy.commit-diffstat
contexts:
main:
- match: ^ (.+) \| +(\d+) (\+*)(-*)$\n?
comment: author and date info
scope: meta.commit-info.diffstat.line
captures:
1: meta.filename.diff
2: constant.numeric.lines-count.git-savvy
3: markup.inserted.git-savvy.add-block.content
4: markup.deleted.git-savvy.delete-block.content

- match: (\d+) files? changed
comment: Count files changed
scope: meta.commit-info.files.changes
captures:
1: constant.numeric.lines-count.git-savvy

- match: (\d+) insertions?\(\+\)
comment: Count of lines insertions
scope: markup.inserted.git-savvy.add-block.content
captures:
1: constant.numeric.lines-count.git-savvy

- match: (\d+) deletions?\(-\)
comment: Count of lines deletions
scope: markup.deleted.git-savvy.delete-block.content
captures:
1: constant.numeric.lines-count.git-savvy
64 changes: 64 additions & 0 deletions syntax/test/syntax_test_show_commit_with_stat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SYNTAX TEST "Packages/GitSavvy/syntax/show_commit.sublime-syntax"
commit b79e485c7a3e589c7866555eca6fd9ec7388b5cb
Author: Simon <simon.toivo@telhaug.no>
AuthorDate: Mon Jun 12 19:45:23 2017 +0200
Commit: Simon <simon.toivo@telhaug.no>
CommitDate: Mon Jun 12 19:58:27 2017 +0200

Blame popup option 2
---
# <- git-savvy.commit meta.commit-header-and-stat-splitter
Default.sublime-keymap | 22 +-
# ^ meta.filename.diff
# ^ meta.filename.diff
# ^ constant.numeric.lines-count.git-savvy
# ^ constant.numeric.lines-count.git-savvy
# ^ markup.inserted.git-savvy.add-block.content
# ^ markup.deleted.git-savvy.delete-block.content
# <- meta.commit-info.diffstat.line
common/ui.py | 3 ---
# ^ constant.numeric.lines-count.git-savvy
# ^ markup.deleted.git-savvy.delete-block.content
# ^ markup.deleted.git-savvy.delete-block.content
# <- meta.commit-info.diffstat.line
popups/bl|me_view.html | 8 ++++
# ^ markup.inserted.git-savvy.add-block.content
# ^ markup.inserted.git-savvy.add-block.content
# <- meta.commit-info.diffstat.line
# ^ meta.filename.diff
# ^ meta.filename.diff
# ^ meta.filename.diff
33 files changed, 5 insertions(+), 8 deletions(-)
#^ git-savvy.commit meta.commit-info.files.changes constant.numeric.lines-count.git-savvy
# ^ git-savvy.commit meta.commit-info.files.changes constant.numeric.lines-count.git-savvy
# ^ meta.commit-info.files.changes
# ^ markup.inserted.git-savvy.add-block.content constant.numeric.lines-count.git-savvy
# ^ markup.inserted.git-savvy.add-block.content
# ^ markup.inserted.git-savvy.add-block.content
# ^ markup.deleted.git-savvy.delete-block.content constant.numeric.lines-count.git-savvy
# ^ markup.deleted.git-savvy.delete-block.content

2 files changed, 55 insertions(+)
#^ git-savvy.commit meta.commit-info.files.changes constant.numeric.lines-count.git-savvy
# ^ meta.commit-info.files.changes
# ^ markup.inserted.git-savvy.add-block.content constant.numeric.lines-count.git-savvy
# ^ markup.inserted.git-savvy.add-block.content constant.numeric.lines-count.git-savvy
# ^ markup.inserted.git-savvy.add-block.content
# ^ markup.inserted.git-savvy.add-block.content

1 files changed, 48 deletions(-)
#^ git-savvy.commit meta.commit-info.files.changes constant.numeric.lines-count.git-savvy
# ^ meta.commit-info.files.changes
# ^ markup.deleted.git-savvy.delete-block.content constant.numeric
# ^ markup.deleted.git-savvy.delete-block.content constant.numeric
# ^ markup.deleted.git-savvy.delete-block.content


1 file changed, 1 insertion(+), 1 deletion(-)
#^ git-savvy.commit meta.commit-info.files.changes constant.numeric.lines-count.git-savvy
# ^ meta.commit-info.files.changes
# ^ markup.inserted.git-savvy.add-block.content constant.numeric.lines-count.git-savvy
# ^ markup.inserted.git-savvy.add-block.content
# ^ git-savvy.commit markup.deleted.git-savvy.delete-block.content constant.numeric.lines-count.git-savvy
# ^ markup.deleted.git-savvy.delete-block.content
# ^ markup.deleted.git-savvy.delete-block.content