Skip to content
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
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ Its tests run against real repositories made with `git` in a temporary folder
- `start.rs` (open, clone and create), `ui.rs` (tabs and toolbar), `graph.rs`, `sidebar.rs`, `details.rs`,
`diff.rs`, `history.rs` (a file's history), `blame.rs` (who last changed each line),
`merge.rs` (a conflicted file) and `rebase.rs` (an interactive rebase) draw the views, and
`theme.rs` has the colours.
`theme.rs` has the colours. `syntax.rs` colours code with the grammar of its language, from
the top of the file, so a diff reads both versions of the file in the background to colour it.

The app's tests (`crates/app/src/tests.rs`) drive the whole window the way a user does, through
the accessibility tree with [egui_kittest](https://crates.io/crates/egui_kittest). That also keeps
Expand Down
66 changes: 60 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ eframe = { version = "0.37", default-features = false, features = ["default_font
egui_kittest = "0.37"
rfd = "0.18"
image = { version = "0.25", default-features = false, features = ["png", "jpeg", "gif", "webp", "bmp", "ico"] }
syntect = { version = "5.3", default-features = false, features = ["default-syntaxes", "default-themes", "regex-fancy"] }
tempfile = "3"
proptest = "1"
criterion = { version = "0.8", default-features = false, features = ["cargo_bench_support"] }
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ GitCraft is young. This is what it does today; [ROADMAP.md](ROADMAP.md) has what
that name comes first, so typing its name takes you there. Large histories are searched as you
type, without the window waiting.
- **Commits**: message, author, parents and the files they changed, with the diff of each file.
- **Diffs**: in a line that changed, the words that changed stand out, so a renamed variable or a
new argument is easy to spot. "Side by side" puts the old version on the left and the new one on
- **Diffs**: code has the colours of its language, some fifty of them from Rust and C to Python,
JavaScript, PHP and Go, and a line in a comment or string that started above the change is
coloured as one. In a line that changed, the words that changed stand out, so a renamed
variable or a new argument is easy to spot. "Side by side" puts the old version on the left and the new one on
the right, each changed line facing the line that replaced it; you stage or discard lines from
either side the same way, and the choice stays for the next diff and the next run. A picture
(PNG, JPEG, GIF, WebP, BMP or ICO) shows its old and its new version next to each other, with
Expand Down
10 changes: 5 additions & 5 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ drive it the way a user does, and keeps every benchmark as fast as before.
- [x] Better diffs, part 1: the words that changed within a line stand out
- [x] Better diffs, part 2: the old and the new version side by side
- [x] Better diffs, part 3: a picture's old and new version next to each other
- [x] Better diffs, part 4: code in the colours of its language

## Next

1. **Better diffs, part 4**: syntax colouring.
2. **Keyboard**: shortcuts for everything, and a command palette.
3. **Settings**: light and dark theme, font size, date format, default pull mode.
4. **Graph polish**: resizable columns, compact lanes, author avatars (optional, never by default
1. **Keyboard**: shortcuts for everything, and a command palette.
2. **Settings**: light and dark theme, font size, date format, default pull mode.
3. **Graph polish**: resizable columns, compact lanes, author avatars (optional, never by default
over the network).
5. **Packaging**: installers with the icon for Windows (MSI), macOS (.app in a .dmg) and Linux
4. **Packaging**: installers with the icon for Windows (MSI), macOS (.app in a .dmg) and Linux
(AppImage, .deb, Flatpak), signed where the platform expects it.

## After 1.0
Expand Down
1 change: 1 addition & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gitcraft-core.workspace = true
eframe.workspace = true
rfd.workspace = true
image.workspace = true
syntect.workspace = true

[dev-dependencies]
egui_kittest.workspace = true
Expand Down
53 changes: 38 additions & 15 deletions crates/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use gitcraft_core::undo::{self, Undo};
use gitcraft_core::watch::Watch;
use gitcraft_core::{ObjectId, Result};

use crate::syntax;

/// What the user asked for.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Action {
Expand Down Expand Up @@ -190,10 +192,22 @@ pub struct OpenFile {
pub diff: FileDiff,
/// The picked lines, as hunk and line index.
pub lines: BTreeSet<(usize, usize)>,
/// The old and the new version, when the file is a picture.
pub pictures: [Version; 2],
/// The pictures being read, if they are.
pub reading: Reading<[Version; 2]>,
/// The old and the new version, once they are read.
pub versions: Versions,
/// The versions being read, if they are.
pub reading: Reading<Versions>,
}

/// The old and the new version of a file, to show more of them than the diff does.
#[derive(Debug, Default)]
pub enum Versions {
/// Not read.
#[default]
None,
/// A picture's.
Pictures([Version; 2]),
/// The lines of code, with their colours; none in a language without colours.
Code([Vec<syntax::Line>; 2]),
}

/// A version of a picture, or why it does not show; `None` when the version does not have the file.
Expand All @@ -218,22 +232,31 @@ impl std::fmt::Debug for Picture {

impl OpenFile {
fn new(ctx: &egui::Context, repo: &Repo, source: Source, diff: FileDiff) -> Self {
let mut file = Self { source, diff, lines: BTreeSet::new(), pictures: [None, None], reading: None };
file.read_pictures(ctx, repo);
let mut file = Self { source, diff, lines: BTreeSet::new(), versions: Versions::None, reading: None };
file.read_versions(ctx, repo);
file
}

/// Reads the old and the new version in the background, when git sees the file as binary
/// and its name says it is a picture.
fn read_pictures(&mut self, ctx: &egui::Context, repo: &Repo) {
/// Reads the old and the new version in the background: of a picture, when git sees the file
/// as binary and its name says it is one, and else of the code, to colour it.
fn read_versions(&mut self, ctx: &egui::Context, repo: &Repo) {
let format = image::ImageFormat::from_path(self.source.path());
if !self.diff.binary || !format.is_ok_and(|format| format.reading_enabled()) {
let binary = self.diff.binary;
// A link or a submodule has no code: its diff is where it points.
let link = self.diff.header.iter().any(|line| line.ends_with(" 120000") || line.ends_with(" 160000"));
if binary && !format.is_ok_and(|format| format.reading_enabled()) || !binary && link {
return;
}
let (repo, source, context) = (repo.clone(), self.source.clone(), ctx.clone());
self.reading = Some(read_in_background(ctx, move || {
let versions = repo.versions(&source)?;
Ok(versions.map(|version| version.map(|bytes| picture(&context, source.path(), &bytes))))
let (versions, path) = (repo.versions(&source)?, source.path());
Ok(if binary {
Versions::Pictures(versions.map(|version| version.map(|bytes| picture(&context, path, &bytes))))
} else {
Versions::Code(
versions.map(|version| version.map_or_else(Vec::new, |code| syntax::colour(path, &code))),
)
})
}));
}
}
Expand Down Expand Up @@ -739,7 +762,7 @@ impl Workspace {
self.open(ctx, source);
}

/// Takes in the history, the blame or the pictures of the file in the centre once they are
/// Takes in the history, the blame or the versions of the file in the centre once they are
/// read. A history shows the diff of its newest commit when none is open; a blame that
/// failed, as when the file is gone, closes.
fn take_reading(&mut self, ctx: &egui::Context) {
Expand All @@ -766,7 +789,7 @@ impl Workspace {
&& let Some(read) = take(&mut file.reading)
{
match read {
Ok(pictures) => file.pictures = pictures,
Ok(versions) => file.versions = versions,
Err(error) => self.error = Some(error),
}
}
Expand Down Expand Up @@ -986,7 +1009,7 @@ impl Workspace {
Ok(diff) if diff == file.diff => {}
Ok(diff) => {
(file.diff, file.lines) = (diff, BTreeSet::new());
file.read_pictures(ctx, &self.repo);
file.read_versions(ctx, &self.repo);
}
Err(error) => self.error = Some(error.to_string()),
}
Expand Down
Loading
Loading