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

Add support for abbreviating hashes in URLs #22

Closed
zx8 opened this issue Apr 25, 2020 · 10 comments
Closed

Add support for abbreviating hashes in URLs #22

zx8 opened this issue Apr 25, 2020 · 10 comments

Comments

@zx8
Copy link

zx8 commented Apr 25, 2020

Would be neat if there was an option or environment variable that we could use to configure the length of commits in URLs, i.e. when linking things to other people it's neater to link short links rather than long links.

Example

export GIT_BRWS_GIT_COMMIT_LENGTH=8

Would result in:

https://github.com/rhysd/git-brws/blob/6c250cc5/Cargo.toml

Rather than:

https://github.com/rhysd/git-brws/blob/6c250cc53e39666f415f28fd49d3b224e47a2309/Cargo.toml

@rhysd
Copy link
Owner

rhysd commented Apr 25, 2020

Including entire hash is more accurate. And browser will redirect to the expanded hash URL automatically when accessing abbreviated hash URL. So I'm not seeing advantage to open a page with abbreviated hash URL. What is your use case?

@zx8
Copy link
Author

zx8 commented Apr 25, 2020

I agree, it's most accurate, but for me 8 characters is always enough to reach the desired commit, and is very handy when linking commits in windows which are very narrow (e.g. Slack threads).

I'm not suggesting changing the default of 40 characters, just making it configurable for people like me where horizontal real estate is limited in some cases. 😄

@rhysd
Copy link
Owner

rhysd commented Apr 25, 2020

Do you mean you're not using git-brws for opening browser directly, but for making a string to share it on some other service like Slack?

e.g.

git brws --url | pbcopy

@zx8
Copy link
Author

zx8 commented Apr 25, 2020

Yes, that's my exact use case. See the issue I accidentally raised #23 before I found the --url functionality!

For browsing alone, I don't have much use for shortened URLs, this would just be for linking shorter URLs to other people.

@rhysd
Copy link
Owner

rhysd commented Apr 25, 2020

OK, I'm considering interface. Two options:

  1. Setting export GIT_BRWS_COMMIT_HAS_ABBREV=true always makes use of abbreviated hashes (default value is false)
  2. Specifying --hash-abbrev option makes use of abbreviated hashes for the command execution

I guess 1. is more useful for you, am I correct?

@zx8
Copy link
Author

zx8 commented Apr 25, 2020

Yeah, I think 1. would be my preference, but I think it's both more flexible and consistent with git rev-parse --short=<N> if its value was a number rather than a boolean?

$ git rev-parse--help
...
       --short[=length]
           Same as --verify but shortens the object name to a unique prefix
           with at least length characters. The minimum length is 4, the
           default is the effective value of the core.abbrev configuration
           variable (see git-config(1)).
...

See also core.abbrev:

core.abbrev

set the length object names are abbreviated to. If unspecified or set to
"auto", an appropriate value is computed based on the approximate number of
packed objects in your repository, which hopefully is enough for abbreviated
object names to stay unique for some time. The minimum length is 4.

@rhysd
Copy link
Owner

rhysd commented Apr 26, 2020

I want to start from minimal feature. Specifying length causes several error cases so I prefer fixed 7 length.

  • when value other than unsigned integer
  • when value is zero
  • when value is longer than original hash
  • when value is small (e.g. 2), generated URL is useless

7 length is used by Git and GitHub for human-friendly hash abbreviation. I could not come up with a use case where they want to specify a value other than 7 for the hash length. So I feel boolean value to switch full length or abbreviated short length is sufficient.

If someone raises a feature request to specify the hash length with practical use case, I would add a new option to specify hash length in the future.

@zx8
Copy link
Author

zx8 commented Apr 26, 2020

Fair enough, but I think 8 is more suitable as a default because I’ve actually experienced collisions with 7 in very large repositories.

@rhysd
Copy link
Owner

rhysd commented Apr 26, 2020

But experiencing conflict with 7 length does not mean that 8 length is enough.. I want to use the same value as Git and GitHub because there would be some discussions to determine the size.

I know that the length used by Git had been 6 previously and was increased to 7 after. When Git increases the length to 8 in the future, git-brws also will follow it.

@zx8
Copy link
Author

zx8 commented Apr 26, 2020

Ok, sounds reasonable!

@rhysd rhysd added this to Doing in git-brws Apr 27, 2020
@rhysd rhysd closed this as completed in 3cc187f Apr 27, 2020
@rhysd rhysd moved this from Doing to Done in git-brws Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants