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

Expand 'show' command to display patches #48

Merged
merged 7 commits into from
Apr 20, 2020
Merged

Expand 'show' command to display patches #48

merged 7 commits into from
Apr 20, 2020

Conversation

craigds
Copy link
Member

@craigds craigds commented Apr 15, 2020

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 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.

To do

  • add tests

Output

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:

{
  "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"
  }
}

@craigds craigds requested a review from rcoup April 15, 2020 08:44
Copy link
Member

@rcoup rcoup left a 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?

sno/diff.py Outdated Show resolved Hide resolved
elif (not output_path) or output_path == "-":
return sys.stdout
else:
return output_path.open("w")
Copy link
Member

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?

Copy link
Member

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)

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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')

sno/show.py Outdated Show resolved Hide resolved
sno/show.py Outdated Show resolved Hide resolved
sno/diff.py Outdated Show resolved Hide resolved
sno/diff.py Outdated Show resolved Hide resolved
@craigds
Copy link
Member Author

craigds commented Apr 15, 2020

Possible to split the refactoring from the new additions into separate commits?

Sure I can split it up a bit.

Feels like we'll need the console pager to work reliably cross-platform though if we're including massive diffs.

I'm not really sure what this refers to; is there some context somewhere? The existing sno diff output isn't much smaller than the output of sno show, so it sounds like if the console pager isn't working well we should fix that regardless. That can go in a separate change though?

@rcoup
Copy link
Member

rcoup commented Apr 16, 2020

I'm not really sure what this refers to; is there some context somewhere?

I'm not sure the console pager works at all unless we're exec'ing git.

, so it sounds like if the console pager isn't working well we should fix that regardless. That can go in a separate change though?

Can you ticket?

@rcoup
Copy link
Member

rcoup commented Apr 16, 2020

Rethinking:

This PR expands it to work much more like git show.
The existing sno diff output isn't much smaller than the output of sno show

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 sno show returning a diff, seems like as an (effective) alias of log -1 it's more useful than as an alias of log -1 -p. For me that shows the context of "what's the last change made? where did I get up to?", and I feel 100s of lines of IDs doesn't seem particularly helpful in that regard? Though I'm but one user, and I have my own ways of working that are different too. Thoughts @hamishcampbell?

@craigds
Copy link
Member Author

craigds commented Apr 16, 2020

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 sno diff {sha1}^..{sha1} would work, but it's annoying to type, and that won't show the log message, so to get all the context for what's in the commit you need to run two commands?

Why not just make show do what git does, and show the whole commit?
or are you saying text diffs aren't useful at all for data?

@craigds
Copy link
Member Author

craigds commented Apr 19, 2020

talked with @rcoup out-of-band, he said:

Sure, ok.

I guess I pretty rarely use show {sha}, I’m more likely to do log -p. show (no args) I kinda use to see what the last change is and whether it’s mine 😀

To which I commented

I use them both in tandem - I have a git log open in one screen, and when i find a commit i think i might care about, i use git show {sha} in a separate window

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

`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"
  }
}
```
sno/diff.py Outdated Show resolved Hide resolved
help="Show commit in JSON patch format",
cls=MutexOption,
exclusive_with=["text"],
)
Copy link
Collaborator

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):

Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants