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

Interactive rebase: Highlight 4 byte sha #8648

Merged

Conversation

gerhardol
Copy link
Member

Proposed changes

TryHighlightInteractiveRebaseCommand() assumes that Git sha are longer than 5 chars when highlighting.
The minimum is 4, can be set:
git config --global core.abbrev 4
(Separate note: I would like to read and use this value in the GUI to limit printouts, separate.)

Also a minor optimization to use a compiled RegEx. (One of the few situations where RegexOptions.Compiled makes sense, should slow down in most other situations.)
(Seen in other situations, no good PR to attach it to and not worth a PR on its own.)

Screenshots

Before

image

After

image

Test methodology

Manual


✒️ I contribute this code under The Developer Certificate of Origin.

@ghost ghost assigned gerhardol Nov 30, 2020
@codecov
Copy link

codecov bot commented Nov 30, 2020

Codecov Report

Merging #8648 (067e22d) into master (2b51726) will increase coverage by 0.00%.
The diff coverage is 50.00%.

@@           Coverage Diff           @@
##           master    #8648   +/-   ##
=======================================
  Coverage   55.09%   55.10%           
=======================================
  Files         906      906           
  Lines       65562    65562           
  Branches    11874    11874           
=======================================
+ Hits        36124    36125    +1     
- Misses      26602    26603    +1     
+ Partials     2836     2834    -2     
Flag Coverage Δ
production 42.09% <50.00%> (+<0.01%) ⬆️
tests 94.91% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@RussKie RussKie merged commit af321b4 into gitextensions:master Nov 30, 2020
@ghost ghost added this to the 4.0 milestone Nov 30, 2020
@gerhardol gerhardol deleted the feature/highlight-editor-short-sha branch November 30, 2020 06:03
@@ -127,7 +127,7 @@ private static bool TryHighlightInteractiveRebaseCommand(IDocument document, Lin
{
var idLength = index - idStartIndex;

if (idLength <= 5)
if (idLength < 4)
Copy link
Member

Choose a reason for hiding this comment

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

This will highlight a 3 byte SHA too. Is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

The minimum length is 4 so 3 should have been excluded. But it makes not much difference, should be changed if updating again

Copy link
Member Author

Choose a reason for hiding this comment

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

This is correct, a sha with 4 chars is highlighted, 3 is not

@@ -3017,7 +3017,7 @@ public IReadOnlyList<IGitRef> ParseRefs([NotNull] string refList)
//
// Lines may also use \t as a column delimiter, such as output of "ls-remote --heads origin".

var regex = new Regex(@"^(?<objectid>[0-9a-f]{40})[ \t](?<refname>.+)$", RegexOptions.Multiline);
var regex = new Regex(@"^(?<objectid>[0-9a-f]{40})[ \t](?<refname>.+)$", RegexOptions.Multiline | RegexOptions.Compiled);
Copy link
Member

Choose a reason for hiding this comment

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

If compiling the Regex, it should ideally be cached so that it's not compiled again the next time refList is called.

Copy link
Member

Choose a reason for hiding this comment

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

Regex compilation is fairly slow. It does give slightly faster run time, but the main benefit is a reduction in memory allocation while matching, in my experience. If it's being recompiled each time then my hunch is the overhead likely outweighs the benefit.

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 did not try to measure (I expect it to be hard to see the difference), but this situation seem to be parsing a larger amount of data and I assume it to be faster.

In most other situations where Compiled is used, it should be changed.

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.

None yet

3 participants