~/selfhut

628f9ab9b4e3874d8e4e584a8d9928d913a1d6c4 — Arthur Melton ba910f90 2 years ago
dont 404 if there is no parent
3 files changed, 13 insertions(+), 16 deletions(-)

M src/git/diffs.rs
M src/repository/commit.rs
M templates/repository/commit.html.hbs
M src/git/diffs.rs => src/git/diffs.rs +7 -13
@@ 1,17 1,11 @@

pub fn diffs<'a>(commit: git2::Commit<'a>, repo: &'a git2::Repository) -> Option<git2::Diff<'a>> {
    match commit.tree() {
        Ok(tree) => match commit.parent(0) {
            Ok(parent) => match parent.tree() {
                Ok(parent_tree) => {
                    match repo.diff_tree_to_tree(Some(&parent_tree), Some(&tree), None) {
                        Ok(diff) => Some(diff),
                        Err(_) => None,
                    }
                }
                Err(_) => None,
            },
            Err(_) => None,
        },
    let tree = commit.tree().ok()?;
    let parent_tree = match commit.parent(0) {
        Ok(parent) => Some(parent.tree().ok()?),
        Err(_) => Some(repo.find_tree(git2::Oid::from_str("4b825dc642cb6eb9a060e54bf8d69288fbee4904").ok()?).ok()?),
    }?;
    match repo.diff_tree_to_tree(Some(&parent_tree), Some(&tree), None) {
        Ok(diff) => Some(diff),
        Err(_) => None,
    }
}

M src/repository/commit.rs => src/repository/commit.rs +4 -1
@@ 40,7 40,10 @@ pub fn commit(repo: String, oid: String) -> Option<Template> {

            parent: match commit.parent_id(0) {
                Ok(parent) => {
                    match get_commits(repo_clone.clone(), 1, Some(parent.to_string()), None) {
                        Some(x) => Some(x.first()?.clone()),
                        Some(x) => match x.first() {
                            Some(x) => Some(x.clone()),
                            None => None
                        },
                        None => None
                    }
                },

M templates/repository/commit.html.hbs => templates/repository/commit.html.hbs +2 -2
@@ 39,11 39,11 @@

                </div>
                <div style="margin-bottom: 2rem"></div>
                {{#each files}}
                    <pre style="margin-bottom: 0; background: transparent; padding: 0;">{{this.status}} <a href="/{{../repo}}/tree/{{../parent.commit_hash}}/{{this.beging_path}}" id="{{this.beging_path}}">{{this.beging_path}}</a> =&gt; <a href="/{{../repo}}/tree/{{../commit.commit_hash}}/{{this.end_path}}" id="{{this.end_path}}">{{this.end_path}}</a> <span class="pull-right"><ins class="text-success">+{{this.insertions}}</ins> <del class="text-danger">-{{this.deletions}}</del></span></pre>
                    <pre style="margin-bottom: 0; background: transparent; padding: 0;">{{this.status}}{{#unless (or (eq this.status "A") (eq this.status "D"))}} <a href="/{{../repo}}/tree/{{../parent.commit_hash}}/{{this.beging_path}}" id="{{this.beging_path}}">{{this.beging_path}}</a> =&gt;{{/unless}} <a href="/{{../repo}}/tree/{{../commit.commit_hash}}/{{this.end_path}}" id="{{this.end_path}}">{{this.end_path}}</a> <span class="pull-right"><ins class="text-success">+{{this.insertions}}</ins> <del class="text-danger">-{{this.deletions}}</del></span></pre>
                    <div class="event diff">
                    <pre>
{{#each hunks}}
<strong class="text-info">@@ <a href="/{{../../repo}}/tree/{{../../parent.commit_hash}}/{{this.end_path}}#L{{this.first}}" style="text-decoration: underline">{{this.first}}</a>,{{this.second}} <a href="/{{../../repo}}/tree/{{../../commit.commit_hash}}/{{this.end_path}}#L{{this.third}}" style="text-decoration: underline">{{this.third}}</a>,{{this.fourth}} @@{{this.first_line}}</strong>
<strong class="text-info">@@ {{#if ../../parent}}<a href="/{{../../repo}}/tree/{{../../parent.commit_hash}}/{{this.end_path}}#L{{this.first}}" style="text-decoration: underline">{{/if}}{{this.first}}{{#if ../../parent}}</a>{{/if}},{{this.second}} <a href="/{{../../repo}}/tree/{{../../commit.commit_hash}}/{{this.end_path}}#L{{this.third}}" style="text-decoration: underline">{{this.third}}</a>,{{this.fourth}} @@{{this.first_line}}</strong>
{{#each lines}}</span><span class="{{this.class}}"><a aria-hidden="true" class="lineno" href="#{{../../this.end_path}}-{{../this.hunk_n}}-{{this.line_n}}" id="{{../../this.end_path}}-{{../this.hunk_n}}-{{this.line_n}}" style="color: inherit">{{this.types}}</a>{{this.line}}</span>{{/each}}
{{/each}}
</pre>