-
Notifications
You must be signed in to change notification settings - Fork 41
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
Expand 'show' command to display patches #48
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use a mode here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output_path can be a directory as well (eg: for geojson files)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
-p
and--patch
are helpful (since JSON output is also the way you generate an applyable patch), so we don't want to remove those
sno show
already 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 diff
output 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: