Repository: sharkdp/bat
File: src/main.rs (Rust)

Code before:
                    Fixed(244).paint(format!("{:4}", line_nr)),
                    // Show git modificiation markers only for full style
                    match options.style {
                        OptionsStyle::Full => line_change,
                        _ => Style::default().paint(" "),
                    },
                    Fixed(GRID_COLOR).paint("│"),
                    as_terminal_escaped(&regions, options.true_color)
                )?
        }
    }

    // Show bars for all but plain style
    match options.style {
        OptionsStyle::LineNumbers | OptionsStyle::Full =>
            print_horizontal_line(handle, '┴', term_width)?,
        OptionsStyle::Plain => {}
    };

    Ok(())
}

fn get_git_diff(filename: &str) -> Option<LineChanges> {
    let repo = Repository::discover(Path::new(&filename)).ok()?;
    let workdir = repo.workdir()?;
    let absolute_file_path = workdir.join(Path::new(&filename));
    let relative_file_path = absolute_file_path.strip_prefix(workdir).ok()?;

    let mut diff_options = DiffOptions::new();
    let pathspec = format!("*{}", relative_file_path.display())
        .into_c_string()
        .ok()?;
    // GIT pathspec uses relative path
    diff_options.pathspec(pathspec);
    diff_options.context_lines(0);

    let diff = repo.diff_index_to_workdir(None, Some(&mut diff_options))
        .ok()?;

    let mut line_changes: LineChanges = HashMap::new();

    let mark_section =
        |line_changes: &mut LineChanges, start: u32, end: i32, change: LineChange| {
            for line in start..(end + 1) as u32 {
                line_changes.insert(line, change);
            }
        };

    let _ = diff.foreach(
        &mut |_, _| true,
        None,

Review comment (suggestion):
This will only work if the path `filename` starts at the root of the workdir. I have a fix for this and will push it to you branch. Hope that's okay.

Code after:
                    Fixed(244).paint(format!("{:4}", line_nr)),
                    // Show git modificiation markers only for full style
                    match options.style {
                        OptionsStyle::Full => line_change,
                        _ => Style::default().paint(" "),
                    },
                    Fixed(GRID_COLOR).paint("│"),
                    as_terminal_escaped(&regions, options.true_color)
                )?
        }
    }

    // Show bars for all but plain style
    match options.style {
        OptionsStyle::LineNumbers | OptionsStyle::Full =>
            print_horizontal_line(handle, '┴', term_width)?,
        OptionsStyle::Plain => {}
    };

    Ok(())
}

fn get_git_diff(filename: &str) -> Option<LineChanges> {
    let repo = Repository::discover(&filename).ok()?;
    let path_absolute = fs::canonicalize(&filename).ok()?;
    let path_relative_to_repo = path_absolute.strip_prefix(repo.workdir()?).ok()?;

    let mut diff_options = DiffOptions::new();
    let pathspec = path_relative_to_repo.into_c_string().ok()?;
    diff_options.pathspec(pathspec);
    diff_options.context_lines(0);

    let diff = repo.diff_index_to_workdir(None, Some(&mut diff_options))
        .ok()?;

    let mut line_changes: LineChanges = HashMap::new();

    let mark_section =
        |line_changes: &mut LineChanges, start: u32, end: i32, change: LineChange| {
            for line in start..(end + 1) as u32 {
                line_changes.insert(line, change);
            }
        };

    let _ = diff.foreach(
        &mut |_, _| true,
        None,
        Some(&mut |delta, hunk| {
            let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));

            if path_relative_to_repo != path {