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

Gitx dev diff word highlight #243

Merged
merged 13 commits into from
Oct 13, 2013
Merged

Conversation

muhqu
Copy link

@muhqu muhqu commented Aug 12, 2013

Integrated an inline word diff algorithm to highlight changed words in diffs. similar to github's hybrid mode.
Addressing #168

The javascript implementation is based on John Resig's javascript diff algorithm described here: http://ejohn.org/projects/javascript-diff-algorithm/

diff-testfile


Known Issues

  • fix "stage line" behaviour when clicking on highlighted words
  • fix invalid diff displayed e.g. just append something at the end of a line
  • fix highlight of indention changes e.g. tabs to spaces: need to preserve tabs when passing diff data to javascript, currently tabs are already replaced by spaces
  • fix diff view keeps showing "This is a large commit..." for some commits... need to figure out what's happening... invalid

Bonus Todos

  • allow diff colors to be customized via git config superseded by Customisable CSS #249
  • display file renames inline, e.g. very/long/path/to/{ old -> new }-filename.html

@muhqu
Copy link
Author

muhqu commented Aug 13, 2013

There are still some issues with this, which I need to sort out before it's ready to merge... see "Known Issues / Todos" within the description.

@atuttle
Copy link

atuttle commented Aug 13, 2013

👍 That screenshot looks great. How well does it handle indentation changes? It sounds like, after you fix the 2nd to-do item, we'd expect just a green bar showing added indentation, not a pair of red+green lines?

@muhqu
Copy link
Author

muhqu commented Aug 14, 2013

as far as I can tell all displaying issues have been fixed now.

@atuttle heres a screenshot showing various changes... unfortunately indention changes (e.g. tabs to spaces) will not yet correctly highlighted because the diff line data I receive in javascript already converted tabs to spaces. so there is no way to detect any changes.
diff-demo

@atuttle
Copy link

atuttle commented Aug 14, 2013

Actually I'm less concerned with conversion between tabs and spaces and more concerned with addition of more tabs/spaces. For example, the case where I decide to wrap a block with an If statement, or a new div - in this case the content inside the new wrapping statement gets indented but doesn't otherwise change.

It seems, based on lines 16-18 of your screenshotted diff that the support is more or less what I'm looking for. Although I'd rather it be a nice dark green block for added spaces, ala the reddish block for the removed whitespace at the end of line 21. Otherwise, perfect.

@atuttle
Copy link

atuttle commented Aug 14, 2013

For what it's worth, I also preferred the red-on-red-on-red, and green-on-green-on-green of the original screenshot over this new gray-ish background for changes in the new screenshot.

@muhqu
Copy link
Author

muhqu commented Aug 14, 2013

Yeah, I changed the colors a bit. First Screenshot already changed the
background colors to be like the ones GitHub is using. But then I felt
the original GitX colors were just fine, so I based the highlighted
background-color on GitX original colors making them a tip darker. I
don't want the highlight colors to be too distracting. The
highlighting should just be a minor hint, while the trailing
whitespace can be seen as a major hint.

Hope this clarifies my intention. But I'm absolutely open to color
suggestions. ;-)

Btw, the GitHub diff uses black text on all colored backgrounds... How
about that?

@rowanj
Copy link
Owner

rowanj commented Aug 14, 2013

Looks really interesting!

@atuttle
Copy link

atuttle commented Aug 14, 2013

I'd be all for making it look more like GitHub... black text with 2 shades of red/green.

@muhqu
Copy link
Author

muhqu commented Aug 14, 2013

just fixed the tabs-to-spaces issue

@atuttle
Copy link

atuttle commented Aug 14, 2013

border-radius, eh? Got an updated screenshot?

@muhqu
Copy link
Author

muhqu commented Aug 14, 2013

@atuttle look here:
tiny border radius

@muhqu
Copy link
Author

muhqu commented Aug 15, 2013

just updated the screenshot in the description to match the latest version of this. From my point of view this is ready for merge, further improvements can be added later with additional pull requests.

Maybe it could make sense to add a User Preference wether to use contrastful or sober diff colors... or just let users define gitx.diffcolors using git config?

@atuttle
Copy link

atuttle commented Aug 15, 2013

I don't feel like the border radius is really adding anything. It's not hurting anything either, but meh.

Hope this is merged in soon!

@muhqu
Copy link
Author

muhqu commented Aug 16, 2013

I'm using it now for work now. I doesn't crash but I have some commits where the diff view keeps showing "This is a large commit. Click here or press 'v' to view". Guess I have to investigate this before this is ready to merge...

@muhqu
Copy link
Author

muhqu commented Aug 21, 2013

If anyone wants to help test this PR:
a) patch your javascript/css files by hand, e.g. open a terminal window in the Folder where your GitX.app is and type: open GitX.app/Contents/Resources/html
b) install this binary: http://muhqu.de/builds/GitX-dev-DiffWordHighlight@9097c08fc3.zip

@atuttle
Copy link

atuttle commented Aug 22, 2013

Installed. I'll see how it works for me today.

@atuttle
Copy link

atuttle commented Aug 22, 2013

  • Installed via the zip file & overwrote my existing Gitx.app
  • Opened by typing gitx from the CLI
  • Doesn't look like I'm getting any word highlighting:

muhqu added 9 commits August 24, 2013 21:23
javascript diff algorithm by John Resig ( http://ejohn.org/ )
- make the inline diff aware of whitespace changes
- added a test page to verify the diff output stays the same
- line selection for stage/unstage in commit dialog
- increase saturation of highlight backgrounds
- make highlighted text a bit darker
- add tiny border-radius to highlighted blocks *blingbling*
changed whitespaceAwareTokenize to split at line breaks or spaces/tabs so that tokens of preceding whitespace do not include the last line break
it splits on:
- every line break
- bunch of whitespace
- bunch of word characters
- every non-word characters (e.g. punctuation)
@muhqu
Copy link
Author

muhqu commented Aug 24, 2013

rebased PR: rowanj/master@dda41e4440e549a83d9a9dfcd3a0ded093c8db66 tag: builds/testing/2

@atuttle
Copy link

atuttle commented Aug 25, 2013

@muhqu any chance of a new binary download with your latest changes?

@rowanj
Copy link
Owner

rowanj commented Aug 26, 2013

It does look pretty good; I still need to review it properly but I'm considering merging it and putting out a new testing build soon.

Is the "this is a large commit" a bug in these changes, or are those commits over the existing threshold?

I've been considering either dropping that code, or hugely changing the threshold anyway; I don't think that loading the larger commits is the problem it may have once been.

@atuttle
Copy link

atuttle commented Aug 28, 2013

Sigh. I would have sworn I only had 1 GitX install, but I was wrong. I removed all existing binaries, reinstalled the latest from @muhqu and reset the CLI command, and now I see word diffs.

Thanks!

@atuttle
Copy link

atuttle commented Aug 28, 2013

Now that I've got it working, @muhqu's build needs more work (sorry!)... Sometimes clicking on a modified file in the stage view shows nothing, sometimes it shows the wrong contents (sometimes it's right...). I'm available to demo this via G+ hangout (adam@fusiongrokker.com) if you want to see what I see.

@muhqu
Copy link
Author

muhqu commented Aug 29, 2013

@atuttle thanks for testing! I have just pushed a few changes which might already fix you issues (if they relate to line-break issues...). You can find a fresh binary here: http://muhqu.de/builds/GitX-dev-DiffWordHighlight@3717db3.app.zip

If your issue is still present, it would be great if you could send me the corresponding git diff -M output.

@atuttle
Copy link

atuttle commented Aug 29, 2013

@muhqu thanks for the new build. So far so good in stage view, but I'm still having trouble with viewing history. Sometimes the history shows up as expected, sometimes the filenames are listed but not their contents, and sometimes I get the "loading" graphic, but it doesn't seem to finish within 5-10 sec so I moved on.

@atuttle
Copy link

atuttle commented Aug 29, 2013

@muhqu Here's an issue with the stage view... Line numbers are wrong. I can illustrate this by changing the amount of context shown:

With context set to pretty low, this change appears to be on "line 2":

But if I bump up the context, it changes lines:

And it gets weirder. If I bump the context any higher than pictured above, the amount of included context goes crazy. This is with the slider just 1 increment higher: (note the visible scrollbar -- there's more above that's out of the viewport!)

@atuttle
Copy link

atuttle commented Aug 29, 2013

@muhqu Also, line numbering seems to continue through hunks. For example:

"Line 133" here is actually line 117; and because of this bug, the line numbers displayed in GitX can far exceed the number of lines in the file. This particular file is 191 lines, but with context cranked up to maximum GitX shows up to "line 242"

@muhqu
Copy link
Author

muhqu commented Aug 30, 2013

@atuttle thanks a lot for the details. The underlaying diff data comes directly from a call to git diff. What git version are us using with GitX? ( ...I'm currently using 1.8.3.1 )

@atuttle
Copy link

atuttle commented Aug 30, 2013

I'm on 1.8.0. Suppose I could upgrade...

Adam

On Fri, Aug 30, 2013 at 3:22 AM, Mathias Leppich
notifications@github.comwrote:

@atuttle https://github.com/atuttle thanks a lot for the details. The
underlaying diff data comes directly from a call to git diff. What git
version are us using with GitX? ( ...I'm currently using 1.8.3.1 )


Reply to this email directly or view it on GitHubhttps://github.com//pull/243#issuecomment-23544558
.

@atuttle
Copy link

atuttle commented Aug 30, 2013

Upgraded to 1.8.3.4 and I'm not having any line-numbering or hunk-size
issues any more.

Adam

On Fri, Aug 30, 2013 at 7:08 AM, Adam Tuttle adam@fusiongrokker.com wrote:

I'm on 1.8.0. Suppose I could upgrade...

Adam

On Fri, Aug 30, 2013 at 3:22 AM, Mathias Leppich <notifications@github.com

wrote:

@atuttle https://github.com/atuttle thanks a lot for the details. The
underlaying diff data comes directly from a call to git diff. What git
version are us using with GitX? ( ...I'm currently using 1.8.3.1 )


Reply to this email directly or view it on GitHubhttps://github.com//pull/243#issuecomment-23544558
.

@muhqu
Copy link
Author

muhqu commented Aug 30, 2013

Oh... thanks a lot for clarifying ... I will try to repro with 1.8.0 to identify the issue. It has to be some difference in the diff output thats generated from the cmd-line git diff...

@atuttle
Copy link

atuttle commented Aug 30, 2013

Can you tell I really want this feature? ;)

Adam

On Fri, Aug 30, 2013 at 9:37 AM, Mathias Leppich
notifications@github.comwrote:

Oh... thanks a lot for clarifying ... I will try to repro with 1.8.0 to
identify the issue. It has to be some difference in the diff output thats
generated from the cmd-line git diff...


Reply to this email directly or view it on GitHubhttps://github.com//pull/243#issuecomment-23561371
.

@rowanj
Copy link
Owner

rowanj commented Sep 2, 2013

Heh, chalk up another point in the "reasons not to use command-line git output" column :-)

I guess I'll try to parse the Sparkle stats to see how common Git 1.8.0.x is.

@muhqu
Copy link
Author

muhqu commented Sep 2, 2013

awesome, that would be quiet interesting!

@muhqu
Copy link
Author

muhqu commented Sep 4, 2013

@rowanj yesterday I played around with the 'large commit' handling and found a way to make the diff-loading-process more progressively. All diffs are now handled the same way, a progress bar shows and updates only at 100ms. So most of the time commits are loaded fast enough to not show a progress bar at all.

Here's a screenshot:
gitx_progressive_diff_highlight

Should I add this change to this pull request or do you prefer a separate, rebased pull request?

@rowanj
Copy link
Owner

rowanj commented Sep 20, 2013

  • Add attribution and disclaimer notice as per MIT license

rowanj added a commit that referenced this pull request Oct 13, 2013
@rowanj rowanj merged commit 3717db3 into rowanj:master Oct 13, 2013
@muhqu
Copy link
Author

muhqu commented Oct 13, 2013

👍 awesome! looking fwd to a new beta build! ;-)

@atuttle
Copy link

atuttle commented Oct 13, 2013

👏

@mitio
Copy link

mitio commented May 13, 2014

Wait, does this word diff rendering look right to you:

wrong word diff rendering

The screenshot is from Version 0.15.1869 dev (0.15.1869).

@muhqu
Copy link
Author

muhqu commented May 13, 2014

@mitio huh... that's interesting. I created this pen which illustrates and helps isolating the issue.

@muhqu
Copy link
Author

muhqu commented May 13, 2014

so the issue is when text parts just move around... anyway, this is an issue and I will look into it once I find time for it, thanks for reporting

@mitio
Copy link

mitio commented May 13, 2014

No problem. I created #321 since this has already been merged. Let's continue the discussion there.

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.

4 participants