paulfitz / daff

align and compare tables
https://paulfitz.github.io/daff
MIT License
800 stars 67 forks source link

How to get the difference using GIT diff in a browser? #124

Closed bushev closed 4 years ago

bushev commented 6 years ago

Hi!

I'm looking a way to display the difference between tables using GIT diff in a browser. Is it possible?

Thanks!

paulfitz commented 6 years ago

I'm not sure I understand this question. If you have two table stored as javascript arrays, you can produce a diff in html using daff (for example, there's a demo on the left of https://paulfitz.github.io/daff/, and daff's README works through how to do this). But if you have files in a git repository, and wish to diff them just as git would do by default without daff installed, and you want to do that in a browser - I think there are pure javascript implementations of parts of git, so you might be able to do something. But I don't think I get what you are trying to do.

rolfkleef commented 5 years ago

While exploring daff and looking at the issues I came across this. If I understand it correctly, you would want the output of running git diff a.csv on the command line to open in a browser?

I simply added the --www parameter in .gitconfig which seems to work:

~/.gitconfig:

# ...
[diff "daff-csv"]
    command = daff diff --www --git
# ...

~/.gitatttributes:

*.csv diff=daff-csv
paulfitz commented 5 years ago

Thanks @rolfkleef, I bet you're right and that's what this question was.

ghost commented 4 years ago

While exploring daff and looking at the issues I came across this. If I understand it correctly, you would want the output of running git diff a.csv on the command line to open in a browser?

I simply added the --www parameter in .gitconfig which seems to work:

~/.gitconfig:

# ...
[diff "daff-csv"]
  command = daff diff --www --git
# ...

~/.gitatttributes:

*.csv diff=daff-csv

@rolfkleef I gave this a try but am getting "do not know how to send to browser in this language" when I try to use it in git diff. Running on Windows with Python 3.6.

paulfitz commented 4 years ago

@frogger72 sorry, it looks like I implemented --www only in the javascript flavor of daff. I can look at adding it to the python flavor.

ghost commented 4 years ago

That would be hugely useful! Thanks @paulfitz

paulfitz commented 4 years ago

@frogger72 let me know if daff version 1.3.45 works for you.

ghost commented 4 years ago

@paulfitz just tried - getting the following:

Traceback (most recent call last):
  File "c:\programdata\miniconda3\envs\py3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\programdata\miniconda3\envs\py3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Miniconda3\envs\py3\Scripts\daff.exe\__main__.py", line 9, in <module>
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 11284, in main
    Coopy.main()
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 2714, in main
    ret = coopy.coopyhx(io)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 2600, in coopyhx
    return self.run(args,io)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 2587, in run
    raise haxe_Exception.thrown(e)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 2563, in run
    self.runDiff(parent,a,b,self.flags,output)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 1796, in runDiff
    self.saveTables(output,os,use_color,True)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 1683, in saveTables
    return self.saveTable(name,os.one(),render)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 1643, in saveTable
    txt = self.encodeTable(name,t,render)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 1662, in encodeTable
    self.renderTable(name,t)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 1635, in renderTable
    return self.applyRenderer(name,renderer)
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 1625, in applyRenderer
    self.io.sendToBrowser(renderer.html())
  File "c:\programdata\miniconda3\envs\py3\lib\site-packages\daff\__init__.py", line 8948, in sendToBrowser
    f.write(html)
  File "c:\programdata\miniconda3\envs\py3\lib\tempfile.py", line 485, in func_wrapper
    return func(*args, **kwargs)
  File "c:\programdata\miniconda3\envs\py3\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u03bc' in position 73054: character maps to <undefined>
fatal: external diff died, stopping at sample.csv
ghost commented 4 years ago

I added environment variable PYTHONIOENCODING = UTF-8, but still getting the error.

I think one of the first two answers below might be relevant. Maybe the html variable that's being sent to sendToBrowser might needs to be explicitly encoded as utf-8 or have to use open with encoding='utf-8'

https://stackoverflow.com/questions/10490816/how-to-create-a-temporary-file-with-unicode-encoding

paulfitz commented 4 years ago

Thanks for testing @frogger72. How about daff version 1.3.46?

ghost commented 4 years ago

Thanks! Just tried and it successfully renders in browser now. Commands like git log -p --ext-diff don't append everything to a large html (like it does when it outputs to the console), but that may be a separate issue.

paulfitz commented 4 years ago

Great, I'm glad that part works. For the git log thing, I think using --www in .gitconfig isn't going to work, since daff is called by git file by file.