Conversation
rcoup
left a comment
There was a problem hiding this comment.
Looking promising!
Feels like we'll need the console pager to work reliably cross-platform though if we're including massive diffs.
Possible to split the refactoring from the new additions into separate commits?
| elif (not output_path) or output_path == "-": | ||
| return sys.stdout | ||
| else: | ||
| return output_path.open("w") |
There was a problem hiding this comment.
output_path can be a directory as well (eg: for geojson files)
There was a problem hiding this comment.
Should we use a mode here?
I assume you mean "a" for append-mode. I think probably not? For most formats (json, geojson, html) it doesn't make sense to append. I don't know why you'd want to for text either. if you need to you can just use - and then use >> outfile to do it in your shell
There was a problem hiding this comment.
output_path can be a directory as well (eg: for geojson files)
this function can't handle that, but diff_output_geojson deals with it specially
There was a problem hiding this comment.
I assume you mean "a" for append-mode.
I meant text-mode with an encoding, since we're writing text?
There was a problem hiding this comment.
ah right.
I don't think this is an issue nowadays? Everything defaults to UTF-8 in recent python versions, even if you have other locale settings:
LANG="en_NZ.latin-1" LC_COLLATE="en_NZ.latin-1" LC_CTYPE="en_NZ.latin-1" LC_MESSAGES="en_NZ.latin-1" LC_MONETARY="en_NZ.latin-1" LC_NUMERIC="en_NZ.latin-1" LC_TIME="en_NZ.latin-1" LC_ALL= ipython3
...
>>> import sys, locale, os
>>> locale.getpreferredencoding(True), sys.getdefaultencoding()
('UTF-8', 'utf-8')
Sure I can split it up a bit.
I'm not really sure what this refers to; is there some context somewhere? The existing |
I'm not sure the console pager works at all unless we're exec'ing git.
Can you ticket? |
|
Rethinking:
I think we need to revisit what the goal is here — why are we making this change? "matching git" isn't automatically desirable, we want to avoid a pile of historic git mis-steps and make it usable for our audience. Datasets aren't code. Personally i don't see the point of |
|
i'm a bit confused about it... if you don't use show to show what's in your commit, how would you view what's in your commit? I guess Why not just make show do what git does, and show the whole commit? |
|
talked with @rcoup out-of-band, he said:
To which I commented
IMHO since there's no objective or consensus reason to differ from general git behaviour here, we should stick closely to what git does. As @rcoup pointed out, it does seem important to implement an output pager so that the commit message and author info is visible on screen. That's tracked in #50 and can be implemented as a separate effort |
Refactor output handling so it can be re-used by the show command.
`sno show` already exists, but takes no options and actually just
displays a text log entry for the given commit.
This change expands it to work much more like `git show`.
Shows a commit (default `HEAD`) as a patch, in either text
(a la `git show`) or JSON (with `--json`).
HTML and 'quiet' output could be added in future.
The patch is a diff plus some meta-information. The diff
is just the same as the `sno diff` output for the relevant
commit.
In text mode, the meta-information is the same as what git show outputs:
```
commit ad9797ea83000864c2ab98c421d2d5256a12db8f
Author: Craig de Stigter <craig@destigter.nz>
Date: Wed Apr 15 13:19:16 2020 +1200
commit
<diff output follows>
```
In JSON mode, the metadata is added to the top level JSON object
so that the patch is also a diff. It looks like:
```json
{
"sno.diff/v1": {...},
"sno.patch/v1": {
"authorName": "Craig de Stigter",
"authorEmail": "craig@destigter.nz",
"authorTime": "2020-04-15T01:19:16Z",
"authorTimeOffset": "+12:00",
"message": "commit"
}
}
```
| help="Show commit in JSON patch format", | ||
| cls=MutexOption, | ||
| exclusive_with=["text"], | ||
| ) |
There was a problem hiding this comment.
Use
from .cli_util import do_json_option
@do_json_option
def show(ctx, *, refish, do_json, **kwargs):
There was a problem hiding this comment.
Discussed out-of-band: going to leave this as-is because:
- we're likely to add HTML output to this command shortly (we already have HTML diff output, so it's just a matter of adding a header with commit information)
- the aliases
-pand--patchare helpful (since JSON output is also the way you generate an applyable patch), so we don't want to remove those
sno showalready exists, but takes no options and actually just displays a text log entry for the given commit. This PR expands it to work much more likegit show.Shows a commit (default
HEAD) as a patch, in either text(a la
git show) or JSON (with--json).HTML and 'quiet' output could be added in future.
To do
Output
The patch is a diff plus some meta-information. The diff
is just the same as the
sno diffoutput for the relevantcommit.
In text mode, the meta-information is the same as what
git show outputs:
In JSON mode, the metadata is added to the top level JSON object
so that the patch is also a diff. It looks like:
{ "sno.diff/v1": {...}, "sno.patch/v1": { "authorName": "Craig de Stigter", "authorEmail": "craig@destigter.nz", "authorTime": "2020-04-15T01:19:16Z", "authorTimeOffset": "+12:00", "message": "commit" } }