Commit Graph

117 Commits

Author SHA1 Message Date
Thomas Otto 5d538b2303 Make relative-paths work with binary files
`relativize_path_maybe()` was not called in this case. Added
test and converted a few existing ones to insta.
2024-07-09 00:00:18 +01:00
Thomas Otto 995dc41525 Make relativize_path_maybe directly update the path argument
This simplifies the call sites.
Also skip updating if the path is already absolute, and handle
'/dev/null' on Windows so it is no longer converted to '\dev\null'.
2024-07-09 00:00:18 +01:00
Dan Davison d995bf76cf clippy (#1686) 2024-05-04 10:00:44 -04:00
Thomas Otto 3b953daac7 Repair --default-language, and highlight using full filename (#1549)
* Fix clippy warnings

* Repair --default-language, and highlight using full filename

Fixed that the "txt" fallback was used instead of --default-language

And when looking for syntax highlighting, keep the filename around
as long as possible.

Using simple custom logic (filename > 4) a Makefile can be highlighted
with make syntax, but a 'cc' or 'ini' file does not get treated like
a *.cc or *.ini file.

Currently the underlying highlighting lib syntect and the sublime syntax
definitions can not make this distinction
(<http://www.sublimetext.com/docs/syntax.html>).
2024-05-04 09:44:39 -04:00
Pawel Dominiak 9b775ecd36 Preserve "Binary files" line in color_only mode (#1649)
Closes #320
2024-03-12 07:53:12 -04:00
Dan Davison d41d02d10f Fix clippy complaints 2024-03-04 16:34:32 -05:00
Paul 977f89ae0d Fix headers of modified binary files, closes #1621 (#1629) 2024-03-02 09:06:31 -05:00
Josh Triplett f7ae06a5f1 Parse filename unambiguously using color escape sequences (#1634)
* Simplify handle_grep_line via early return

Rather than indenting the entire body of the function twice, return
early if the conditions aren't met.

* Parse filename unambiguously using color escape sequences

`git grep`, by default, emits ANSI color escape sequences around the
filename, separator, and line number. Parse these if available.

This currently assumes the default colors, and will fall back to the
previous parsing if any of the colors have been changed.

Add tests for filenames that previously failed to parse correctly.
2024-03-02 08:41:56 -05:00
Dan Davison 084a6d19b2 Accept clippy suggestions (#1632) 2024-02-19 12:56:22 -05:00
Dan Davison e208f4ed52 Bug fix: reset syntax highlighter across grep sections (#1613) 2024-01-20 14:06:03 -05:00
Zack Cerza 06b95306ac Make hunk header code fragment display optional (#1568)
Fixes: #1032
2023-11-20 22:18:19 -05:00
Dan Davison 7375f7a165 Add comment in lieu of test coverage for now 2023-08-13 17:28:38 -04:00
Dan Davison ae26b5497c Fix handling of tabs in grep output (#1507)
Fixes #1501
2023-08-12 22:08:54 -04:00
Sondeyy e0eef7decc Improve binary file added output (#1502)
* added binary file cases tests

* add binary file cases handling

* remove unnecessary return and comma
2023-08-05 14:05:09 -04:00
Pascal H ff5fd061f4 Fix alignment when author name contains unicode accent modifiers (#1456) 2023-06-23 09:38:40 -04:00
Dan Davison 481d3c1a26 Write directly, not by appending to output buffer
This was a bug when a box decoration was subsequently drawn since the
decoration enclosed pending content in the output buffer.
2023-06-03 08:05:11 -04:00
Dan Davison dda9a87421 Increase number of characters shown in submodule hashes
Fixes #1408
2023-06-02 19:40:38 -07:00
Dan Davison 83ca127e9e Introduce grep-output-type option: ripgrep or classic 2023-06-02 14:36:30 -07:00
Dan Davison 46e44d3ba9 Refactor grep handler 2023-06-02 14:36:30 -07:00
Thomas Otto 139cdb9656 Misc tab refactoring (#1424)
* Move tabs logic into utils

* Re-use buffer returned by tabs::expand

* Add TabCfg to configure tabs

Use the String from this config for the tab replacement. This avoids
creating a new String for each processed line.

* Avoid unicode segmentation for each line just to remove a prefix

In some code paths no prefix is removed, and in almost all other
cases the prefix is just ascii.

This simplifies a lot of calls.

* Set default tab with to 8

Editors like vim, emacs, nano and most terminal emulators set
this value as the default tab display width.
2023-05-31 13:17:18 -04:00
Thomas Otto b3ee8400dd Fix submodule diff parsing (#1413)
Added support for an optional -dirty hash suffix which is present
in `git diff` output when files were changed in a submodule.
2023-05-08 16:49:05 -04:00
nickelc 6a37445efb Add methods for getting GitConfig as reference (#1336) 2023-03-09 05:15:04 -05:00
nickelc 28bf556897 Fix clippy warnings (#1298)
* Fix clippy warnings

- `clippy::uninlined_format_args`

* Fix clippy warnings

- `clippy::clone_on_copy`
- `clippy::explicit_auto_deref`
- `clippy::iter_cloned_collect`
- `clippy::map_clone`
- `clippy::needless_borrow`
- `clippy::needless_lifetimes`
- `clippy::needless_return`
- `clippy::redundant_clone`
- `clippy::redundant_field_names`
- `clippy::seek_to_start_instead_of_rewind`
- `clippy::unnecessary_cast`
- `clippy::unused_unit`
2023-02-28 06:37:20 -05:00
Thomas Otto afa7a1a38d Handle quoted filenames in diff header
Otherwise the file extension would return 'rs"' which does not
match any language.
2022-11-15 07:40:49 -05:00
clnoll 6b2d0b7fc8 Fix clippy warnings (#1236) 2022-11-13 18:54:39 -05:00
mliszcz b99e6c5d9c Fix clippy warnings after rust 1.63 upgrade
Following fixes are included:

* derive_partial_eq_without_eq:
  Eq trait was added by running `cargo clippy --fix --no-deps`.
* get_first:
  Function was replaced by running `cargo clippy --fix --no-deps`.
* unnecessary_to_owned:
  This check was disabled for ANSIString as to_string call is required
  to enforce formatting. Otherwise the underlying string was returned
  directly (probably due to Deref implementation).
* type_complexity:
  Closure type was simplified and Box<> usage was removed.
2022-08-16 18:17:10 -04:00
mliszcz 6d96b78502 Support configurable timestamps in git blame output (#1157)
New CLI/config option is introduced: blame-timestamp-output-format.

Fixes #1157.
2022-08-16 18:17:10 -04:00
Jackson Popkin b3cc0f8cae Fix git-grep match-highlighting at line-start (#1057)
* Fix git-grep match-highlighting at line-start

This commit fixes highlighting the part of the line of code that matches
the git grep query in cases where the match starts at the beginning of
the lines.

Fixes #1056.

* Fix handling of non-match highlight

In some cases, `git grep` will customize the foreground-color for more
than just the subset of the line that matches the grep pattern. This
breaks the current match-detection behavior, which considers any
characters with a non-default "foreground color" within the "code" part
of a git-grep-ouput-line to be part of the match. This commit makes
match-detection check for boldness and a red foreground instead of just
checking for a non-default foreground-color.

git grep matches are bold and red by default. But git grep isn't the
only reason input to delta may contain color codes; there may still be
cases where the highlighting looks wrong here.
2022-07-15 21:58:05 -04:00
Dan Davison f556db8d4e Recreate highlighter on each line of git show $commit:$path output (#1127)
Prior to this commit, syntax highlighting of scala code was not
correct in `git show $commit:$path` output. It was working for other
languages as far as I know. I'm not sure why.
2022-07-15 08:39:33 -04:00
Björn Steinbrink bd54a51205 Fix whole-file changes being attributed to the wrong commit in "git log" output
The pending buffer for whole-file changes is currently only flushed when
encountering a new diff header. This leads to it being carried over
across commit boundaries in cases where multiple commits are shown. To
fix this, we simply need to flush the buffered data on a commit
boundary as well.

Fixes #1089
2022-06-22 08:49:42 -04:00
Dan Davison 29c9239ea5 Only trigger git show handler if a file extension was parsed (#1106)
Fixes #1105
2022-06-15 17:38:52 -04:00
Dan Davison 3ccf2bc8d2 Apply hyperlinks to diff stat file paths (#1035) 2022-04-04 20:53:27 -04:00
William Escande 9c840f6f4c Add support for irreversible-delete
Fix #128

Add support for `git diff -D` (aka irreversible delete)

The patch is adding a title for removed file, even when there is no file content in the diff output
Without the patch, there was no output related to the file at all
2022-03-30 08:41:48 -04:00
Dan Davison dd19c974ba Apply file-transformation to diff header, in addition to hunk header
Fixes #1010
2022-03-16 09:23:05 -04:00
Dan Davison a7765f8003 Flush minus/plus line buffers in additional code locations
Fixes #1002
2022-03-07 12:58:28 -05:00
Dan Davison e44435c8f8 Clippy 2022-02-27 10:31:09 -05:00
Jackson Popkin 10ff766a65 Fix parsing for .properties files with - in path (#975)
Fixes #974.
2022-02-19 12:24:23 -05:00
Dan Davison 3d5b6852a0 Fix hyperlink absolute paths (#939)
Fix file paths and hyperlinks

With this commit the target of a hyperlink should always be an absolute path. This should be true for all file hyperlinks, e.g.

- File hyperlink
- Hunk header hyperlink
- Line number hyperlink

Fixes #890
2022-02-14 12:30:30 -05:00
Thomas Otto b66d1d3717 Fix unused imports and functions warnings on windows
Otherwise these warnings clutter the github diff display.
2022-02-07 19:35:27 -05:00
Guillaume Gomez 9eed967543 Fix clippy lints 2022-01-25 09:12:04 -05:00
Guillaume Gomez 019752a664 Update sysinfo version to 0.23 2022-01-25 09:12:04 -05:00
Thomas Otto d08536eb58 Show blame line numbers via blame-separator-format
Prefix and suffix of the format string are separator-style highlighted,
format options are none, {n}, {n:block}, {n:every-N}.
2022-01-21 03:15:35 -05:00
Thomas Otto 3aed51cdc1 Center Align numbers right-ish (#883)
There is no such thing as "Center Align" with discrete terminal cells. In
some cases a decision has to be made whether to use the left or the right
cell, e.g. when centering one char in 4 cells: "_X__" or "__X_".

The format!() center/^ default is left, but when padding numbers these
are now aligned to the right if required. Strings remain left-aligned.
2022-01-18 19:33:09 -05:00
Dan Davison 7d8533c984 Cwd fixups (#918)
Do cwd computations once only; rename cwd variable
2022-01-18 09:02:21 -05:00
Dan Davison e9e9fb7c69 Construct hyperlink file path relative to cwd
Fixes #890
2022-01-17 18:30:32 -05:00
Dan Davison fb38eddd9a Add failing test of file hyperlink in git repo 2022-01-17 18:30:32 -05:00
Dan Davison 1f80503a56 Improve tests of hunk header / hyperlinks behaviour 2022-01-17 13:11:42 -05:00
Dan Davison 66b467ffe5 Fix idiotic test assertion 2022-01-16 16:07:33 -05:00
Thomas Otto e9bec95a57 Handle blame author names containing parentheses 2022-01-13 19:53:28 -05:00
Dan Davison 808ca48eef Clippy: remove redundant borrows 2022-01-05 18:55:02 -05:00