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

[proposal] Custom git diff rendering for binary files #12288

Open
HarvsG opened this issue Jul 21, 2020 · 1 comment
Open

[proposal] Custom git diff rendering for binary files #12288

HarvsG opened this issue Jul 21, 2020 · 1 comment
Labels
topic/content-rendering Changes how certain filetypes are displayed type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@HarvsG
Copy link
Contributor

HarvsG commented Jul 21, 2020

Currently gitea only shows git diffs for text files, and can't for binary files.

image

git diff has native support for custom drivers for converting binary files to text in order to display a diff.

Since gitea just runs the git diff command and parses stdout we can leverage this

cmd = exec.CommandContext(ctx, git.GitExecutable, diffArgs...)

By customising git config --global --edit and adding:

[core]
        quotePath = false
        attributesfile = /root/gitea/custom/git/.gitattributes
[diff "pandoc"]
     textconv=pandoc --to=markdown
     prompt = false

Which is equivalent to running:

git config --global core.attributesfile /root/gitea/custom/git/.gitattributes
git config --global diff.pandoc.textconv "pandoc --to=markdown"
git config --global diff.pandoc.prompt false

And then creating the file /root/gitea/custom/git/.gitattributes with contents:

*.docx diff=pandoc

We get a much better outpjut:
image

The proposal

I propse that we allow users to implement this in an easier way, this could be done in a number of ways.

  1. Allow the user to customise their git config --global file - default location being /root/.gitconfig
    1. by using the includes field with value $GITEA_CUSTOM/git/config and allowing the user to configure that as they please
    2. or by creating a new section in app.ini called something like [git.config] and allow the user to build a git config from the entries there - this may require translation between .ini syntax and whatever syntax git config uses
  2. Expand the external renderer section with new fields CUSTOM_DIFF and TEXTCONV_DIFF_COMMAND and use that to autopopulate /root/.gitconfig and a .gitattributes file

Note 1.a and 1.b generailse to allow the user to configure all of the git config options, 2 is specific to the rendering of diffs

@HarvsG
Copy link
Contributor Author

HarvsG commented Jul 21, 2020

Currently git config is run here in the checkAndSetConfig() command

gitea/modules/git/git.go

Lines 159 to 161 in ae3cfa8

if _, stderr, err = process.GetManager().Exec(fmt.Sprintf("git.Init(set %s)", key), "git", "config", "--global", key, defaultValue); err != nil {
return fmt.Errorf("Failed to set git %s(%s): %s", key, err, stderr)
}

here (not sure this one is relevant)

var gitConfigCommand func() *git.Command
if version.Compare(binVersion, "1.8.0", ">=") {
gitConfigCommand = func() *git.Command {
return git.NewCommand("config", "--local")
}
} else {
gitConfigCommand = func() *git.Command {
return git.NewCommand("config")
}
}

and here (also probably not relevant)

# --- Config
allowunannotated=$(git config --bool hooks.allowunannotated)
allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
denycreatebranch=$(git config --bool hooks.denycreatebranch)
allowdeletetag=$(git config --bool hooks.allowdeletetag)
allowmodifytag=$(git config --bool hooks.allowmodifytag)

@lunny lunny added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Jul 21, 2020
@lunny lunny added the topic/content-rendering Changes how certain filetypes are displayed label May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic/content-rendering Changes how certain filetypes are displayed type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

No branches or pull requests

2 participants