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 walk #661

Merged
merged 26 commits into from
Jun 30, 2017
Merged

Blame walk #661

merged 26 commits into from
Jun 30, 2017

Conversation

stoivo
Copy link
Member

@stoivo stoivo commented May 30, 2017

closed #102 #152

First off, sorry for the big PR. Bit it is a big feature.

I would like to have some review of the code of one other contributor.

Hello, @yyyc514, @benmosher, @stevage, @rchl, @reagle, @dlnsk, @jipumarino, @jipumarino, @jipumarino, @maxim, @zx8
Finally, I got around to implement this. If you are running GitSavvy from git pull down the branch a see if there is something we can improve further?

@reagle
Copy link

reagle commented May 31, 2017

I'm not confident I know how to use it but...

If I hit enter in a row I see options to move blame and, the one's I'm interested in, open commit and show file at commit.

open commit gives:

Traceback (most recent call last):
  File "/Users/reagle/Library/Application Support/Sublime Text 3/Packages/GitSavvy/core/ui_mixins/quick_panel.py", line 59, in on_action_selection
    func(*args, **kwargs)
  File "/Users/reagle/Library/Application Support/Sublime Text 3/Packages/GitSavvy/core/commands/blame.py", line 285, in open_commit
    self.view.window().run_command("gs_show_commit", {"commit_hash": short_hash})
NameError: global name 'short_hash' is not defined

show file at commit results in an untitled and blank tab with the following in the console:

`/usr/bin/git rev-parse --short` failed with following output:

fatal: Needed a single revision

@reagle
Copy link

reagle commented May 31, 2017

ac4215a and 215c08a fix my problem above. But the distinction between (a) "Show file at this commit" and (b) "Show file at this lines commit" is not clear.

(a) shows the file at the most recent commit? And (b) should be "line's".

@stoivo
Copy link
Member Author

stoivo commented Jun 6, 2017

(a) Show file at commit does open the file in the commit without the blame details. In case you want to read the file with syntax highlighting. Maybe Show file without blame info?

@reagle
Copy link

reagle commented Jun 6, 2017

I'm not sure what you mean about the blame details. Both options seem to open a version of the file from the past. (a) is HEAD and (b) is the commit corresponding to "this line's commit."

Speaking of syntax highlighting, the resulting tabs that are opened have no syntax highlighting; they are opened as plain text for some reason....?

@stoivo
Copy link
Member Author

stoivo commented Jun 6, 2017

While you work on it, it is soo clear to you what everything means. It feels so obvious. Now after using it for a week, I understand how confusing it is.

So this pictures will explain it a bit better.
screen shot 2017-06-06 at 13 47 35

Syntax highlighting, Which language are you working with. It seams to work fine with .py extension.
mjvxeppfgi

@reagle
Copy link

reagle commented Jun 6, 2017

  1. I still don't understand the first distinction, but I am a git novice. Does "show file without blame info" mean show the file at HEAD? What is "blame info"?
  2. I suspect my highlighting problem is related to my use of magicpython. (I have default python disabled). It opens other python files fine, just not here.

@stoivo
Copy link
Member Author

stoivo commented Jun 6, 2017

  1. The reason why magicpython isn't working because it uses the old version of sublime syntax files. MagicPython is using .tmLanguage while GitSavvy only checks for '.sublime-syntax`.
    It is quite easy to fix for MagicPython if they want to. (You can create and issue)

  2. HEAD is just a reference to where you are in the your git commits. When you checkout a branche, HEAD will now point to that branch. One branch is just a pointer to a specific commit, when you commit on this branch you will update the branch and HEAD to point to at the new commit. This new commit then points back to the old commit.

  3. git checkout fix

A - B - D 
      \  C
        ^ master
         ^ fix

HEAD -> C
master -> D
fix -> C

  1. git commit -m"E"
A - B - D 
      \  C - E
        ^ master
             ^ fix

HEAD -> E
master -> D
fix -> E

  1. git checkout master
A - B - D 
      \  C - E
        ^ master
             ^ fix

HEAD -> D
master -> D
fix -> E

  1. git checkout C
A - B - D 
      \  C - E
        ^ master
             ^ fix

HEAD -> C
master -> D
fix -> E

At this stage, you are not on any branch. This is very useful if you want to look at how the code looked 2 weeks ago. If you make a commit when you have checked out a commit, it will be hard to find that commit again.

Hope That explain it a bit better. If you have other questions to git lets take it in the gitter chat. https://gitter.im/divmain/GitSavvy

@reagle
Copy link

reagle commented Jun 6, 2017

Okay, forgive my mentioning of HEAD, but what do you mean "without blame info." Could you show me what it is supposed to look like with blame info?

@1st1
Copy link

1st1 commented Jun 6, 2017

@stoivo

It is quite easy to fix for MagicPython if they want to. (You can create and issue)

Unfortunately is's not an "easy fix" for us. .sublime-syntax is a completely different format so it's not going to happen in the foreseeable future.

MagicPython is using .tmLanguage while GitSavvy only checks for '.sublime-syntax`.

Maybe GitSavvy should check for .tmLanguage files too?

@reagle
Copy link

reagle commented Jun 6, 2017

@stoivo, in MagicStack/MagicPython/issues/86 they say they aren't likely to migrate away from .tmLanguage. Could you detect that in addition to .sublime-syntax?

@stoivo
Copy link
Member Author

stoivo commented Jun 7, 2017

Could you show me what it is supposed to look like with blame info?

2017-06-07_08-01-08_commit 6524866 core commands blame py gitsavvy

I open a PR for sublime-syntax on MagicStack/MagicPython#86

@reagle
Copy link

reagle commented Jun 7, 2017

Okay. I would change:

  1. "Show file without blame info" as "Show file at most recent commit"

I think "Show file at this line's commit" is okay, though it is really "at this row" or "where the cursor is". For a while I thought "show file at this line's commit" meant that when it opened that version, it would automatically go to those line numbers, which would still be a neat feature.

@reagle
Copy link

reagle commented Jun 7, 2017

New thought for the second: "Show file at this chunk's commit"

@stoivo
Copy link
Member Author

stoivo commented Jun 7, 2017

@reagle, Thanks for naming commands with me. It is appreciated.

I added one more feature. When to select show file. it jumps to the line you were at. And fixed some other bug when a file is renamed.

@reagle
Copy link

reagle commented Jun 8, 2017

Looks great and the goto line is indeed handy.

@reagle
Copy link

reagle commented Jun 8, 2017

BTW: I think the blame tab should be opened read-only, like the GRAPH tab.

@@ -157,6 +157,7 @@ class PaginatedPanel:
limit = 6000
selected_index = None
on_highlight = None
is_this_selected = None
Copy link
Collaborator

@randy3k randy3k Jun 10, 2017

Choose a reason for hiding this comment

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

If I understand correctly, we need this because the index number of the selected item would be unknown if a generator is used. Instead of adding one more argument here, I suggest using the existing variable selected_index.

We could check if it is a callable. If it is, just do

if selected_index(entry):
    bla bla bla

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I squashed into 514b317, Blame option: Pick a new commit, if you are on a commit, set it as selected.

self.view.run_command("gs_blame_initialize_view")


class BlameCommitPanel(PaginatedPanel):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make more sense to extend it from LogPanel?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really. The only thing in common is format_item.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But one could argue that LogPanel and PaginatedPanel are only differed by format_item. The on_selection is almost identical.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, BlameCommitPanel and LogPanel are both history-related. I don't see why we shouldn't extend it from LogPanel.

Copy link
Member Author

Choose a reason for hiding this comment

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

Check this

@@ -63,12 +65,13 @@ def log(self, author=None, branch=None, file_path=None, start_end=None, cherry=N

return entries

def commit_generator(self, limit = 6000):
def commit_generator(self, limit = 6000, follow=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is related to an earlier refactoring, should we actually pass the arguments branch and file_path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Generally, I prefer to pass several arguments then to set instance variables. On log it looks a little ugly, but it is very nice and explicit what's all the arguments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

One less important point, this function returns a generator of log entries rather that commits. Maybe log_generator is a better name for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

log_generator seem good since it if calls to log.

"commit_hash": commit_hash,
"filepath": self.file_path,
"lineno": self.find_lineno(),
"lang" : self.view.settings().get('git_savvy.original_syntax', None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, any idea to patch the diff view? I don't think the same fix could be applied to diff view.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Or which diff did you think of?

Copy link
Collaborator

@randy3k randy3k Jun 10, 2017

Choose a reason for hiding this comment

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

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 can't think of any way to get that without opening the file and read the syntax, then close it. 👎

Copy link
Collaborator

@randy3k randy3k Jun 11, 2017

Choose a reason for hiding this comment

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

We could open the file in the output panel to make it invisible to users.

PS: it turns out we cannot open file directly in the output panel.
https://stackoverflow.com/questions/37905081/open-a-file-in-output-panel

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also capture the scopes of the file in the output panel to highlight the blame view.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but this can be a separate PR.

@stoivo stoivo force-pushed the blame_walk branch 2 times, most recently from 1a2c0b6 to 0f1c2e7 Compare June 10, 2017 16:41
@@ -63,12 +65,13 @@ def log(self, author=None, branch=None, file_path=None, start_end=None, cherry=N

return entries

def commit_generator(self, limit = 6000):
def commit_generator(self, file_path, branch=None, limit=6000, follow=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any reason to switch the order of file_path and branch?

Copy link
Collaborator

@randy3k randy3k Jun 10, 2017

Choose a reason for hiding this comment

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

Perhaps something like this?

    def log_generator(self, limit=6000, **kwargs):
        # Generator for show_log_panel
        skip = 0
        while True:
            logs = self.log(limit=limit, skip=skip, **kwargs)
            if not logs:
                break
            for l in logs:
                yield l
            skip = skip + limit
       

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

self._file_path = file_path
self._branch = branch
sublime.set_timeout_async(self.run_async)
sublime.set_timeout_async(lambda: self.run_async(file_path, branch), 0)

Copy link
Collaborator

@randy3k randy3k Jun 10, 2017

Choose a reason for hiding this comment

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

These changes are not necessary per se. But they do not hurt.

Copy link
Member

Choose a reason for hiding this comment

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

I have to disagree, the change does hurt, multiple commands get broken. Specifically, any command inheriting from LogMixin that overrides run_async and does not support the 2 new arguments.

I'm going to patch the occurrences I found so far, to support this cleaner call type: GsLogByAuthorCommand, GsLogByBranchCommand, GsResetCommand and GsBranchesLogCommand . See commit 0776af2

Unfortunately this patch did not fix the issue I was seeing in "reset to branch" command, and I have run out of time. Hope you guys can help me again 😅

Copy link
Member

Choose a reason for hiding this comment

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

Just answering my own question, as in commit message: implicitly passing more arguments into kwargs raises an issue in python3, as seen here: http://www.asmeurer.com/python3-presentation/slides.html#15

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 have also noticed that reset commands are not working as they should. Thanks for testing

Copy link
Collaborator

Choose a reason for hiding this comment

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

@asfaltboy you are absolutely right. 👍

@reagle
Copy link

reagle commented Jun 10, 2017

BTW: "hunk" is already a term in git, so maybe we should use that instead of chunk.

@stoivo
Copy link
Member Author

stoivo commented Jun 10, 2017

but I think of hunk as a park of the diff, and nothing else. I would stick with chunk

@randy3k
Copy link
Collaborator

randy3k commented Jun 10, 2017

We also need a help pop up for blame view: https://github.com/divmain/GitSavvy/blob/master/popups/diff_view.html

Some more keybinds to navigate between commits should also be considered.

@stoivo
Copy link
Member Author

stoivo commented Jun 10, 2017

Should , and . go one commit forth and back based on the cursor or just jump one commit forward and backward compared to the commit?

@randy3k
Copy link
Collaborator

randy3k commented Jun 11, 2017

I would say neither. Perhaps , and . to go up and down between chunks? > and < nagivate between commits of the current file. Ctrl + > and < move btw commits based on current chunk.

…file

When always opening the file with the original syntax if the file extension changes
it will be go wrong. I don't think thats a big deal.

We can't always find the correct syntax files since some packages uses tmLanguage like
https://github.com/MagicStack/MagicPython
I wanted to use the commit description but the syntax does not give it a scope
and it's simpler to to use the commit hash. I think it as good to use commit sha
as commit message. Maybe even better.
Blame popup option 2

sqash me Fix typoes
@asfaltboy
Copy link
Member

@stoivo @randy3k amazing work guys! I'm trying to add vintagious friendly mode to the blame command, at least for navigating hunks, and for some reason it's not working for me (see last commit 029e687). Any idea what I'm doing wrong?

@@ -71,8 +72,7 @@ def picked_commit(self, commit_hash):
super().run()



class GsBlameInitializeViewCommand(TextCommand, GitCommand):
class GsBlameInitializeViewCommand(GsHandleVintageousCommand, TextCommand, GitCommand):
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 am sorry, thought of vintage support but apparently forgot. Sorry.
I think the issue is that either you need to call
view.run_command("gs_handle_vintageous") on line 65
Then you won't need to inherit it here.

This is who it's done in inline diff core/commands/inline_diff.py#L84-L85

@stoivo
Copy link
Member Author

stoivo commented Jun 17, 2017

@asfaltboy, this should do the trick.

NOTE: I'm not sure whether this was added in python 3, but passing 3 positional
arguments when method expects 1 pos and 2 kwargs, seems to cause an issue...
@stoivo
Copy link
Member Author

stoivo commented Jun 18, 2017

Hi, I just want to tell you that I will leave for vacation on Wednesday next week, and will probably not reply or make any updated for the coming 5 weeks.

@divmain
Copy link
Collaborator

divmain commented Jun 20, 2017

@stoivo, what needs to be done for this to be merged? If documentation is all that is left, we can document the remaining work in a separate issue, so that this can be merged prior to your vacation. Also, have fun!

Copy link
Member

@asfaltboy asfaltboy left a comment

Choose a reason for hiding this comment

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

@divmain currently there's a bit of a regression going on on this branch. I've details these in a comment that's currently shown below as outdated. However, my last [WIP] commit 0776af2 doesn't fix regression entirely.

self._file_path = file_path
self._branch = branch
sublime.set_timeout_async(self.run_async)
sublime.set_timeout_async(lambda: self.run_async(file_path, branch), 0)

Copy link
Member

Choose a reason for hiding this comment

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

I have to disagree, the change does hurt, multiple commands get broken. Specifically, any command inheriting from LogMixin that overrides run_async and does not support the 2 new arguments.

I'm going to patch the occurrences I found so far, to support this cleaner call type: GsLogByAuthorCommand, GsLogByBranchCommand, GsResetCommand and GsBranchesLogCommand . See commit 0776af2

Unfortunately this patch did not fix the issue I was seeing in "reset to branch" command, and I have run out of time. Hope you guys can help me again 😅

self._file_path = file_path
self._branch = branch
sublime.set_timeout_async(self.run_async)
sublime.set_timeout_async(lambda: self.run_async(file_path, branch), 0)

Copy link
Member

Choose a reason for hiding this comment

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

Just answering my own question, as in commit message: implicitly passing more arguments into kwargs raises an issue in python3, as seen here: http://www.asmeurer.com/python3-presentation/slides.html#15

@stoivo
Copy link
Member Author

stoivo commented Jun 23, 2017

@asfaltboy, I fixed the reset.

Can you pull it and see if you can find any other bug?

@asfaltboy
Copy link
Member

Reset to branch works now, I'll keep using the branch for a while to see if anything else creeped in

@divmain
Copy link
Collaborator

divmain commented Jun 29, 2017

I pulled this down and it looks great to me. How do you feel about merging into master and resolving any issues that pop up there? This is a big branch, and my preference is to merge early in order to avoid merge conflicts and subtle errors from master/branch divergence. @stoivo @asfaltboy?

@asfaltboy
Copy link
Member

@divmain agreed, good point!

@stoivo
Copy link
Member Author

stoivo commented Jun 30, 2017

I would like to merge

@divmain divmain merged commit 03b112b into master Jun 30, 2017
@divmain divmain deleted the blame_walk branch June 30, 2017 21:35
@divmain
Copy link
Collaborator

divmain commented Jun 30, 2017

Thanks a ton @stoivo! This is merged :)

@asfaltboy
Copy link
Member

This also needs an update of the relevant docs.

@randy3k randy3k mentioned this pull request Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show current file feature
6 participants