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

Support SHA256 git object format #1505

Open
AtmosphericIgnition opened this issue Jan 10, 2025 · 7 comments
Open

Support SHA256 git object format #1505

AtmosphericIgnition opened this issue Jan 10, 2025 · 7 comments
Labels
enhancement New feature or request

Comments

@AtmosphericIgnition
Copy link

Summary 💡

When trying to run Onefetch inside a git repo which uses the SHA256 object format, instead of the default SHA1, it immediately errors out:

Error: Failed to load the git configuration

Caused by:
    The key "extensions.objectFormat=sha256" was invalid

Motivation 🔦

While the SHA256 object format is not yet used by default, it will eventually be set as the default by upstream git.

@AtmosphericIgnition AtmosphericIgnition added the enhancement New feature or request label Jan 10, 2025
@spenserblack
Copy link
Collaborator

cc @Byron, is this related to gix?

@Byron
Copy link
Collaborator

Byron commented Jan 11, 2025

Indeed, gitoxide doesn't currently support SHA256, even though all the groundwork is laid. This means that for the purpose of reading repository data, such support could be added quite swiftly I think.

I think here we'd have to watch out for when SHA256 is going to be the set as default so gitoxide can get its support added and enabled as well.

@spenserblack
Copy link
Collaborator

@AtmosphericIgnition Just curious about git's current behavior: is that config option needed for git to be able to read commits with SHA256 hashes, or just to write commits with SHA256 hashes?

@AtmosphericIgnition
Copy link
Author

I'm not sure I understand your question.

The way I understand the git documentation, the when running git init, all git versions so far will use the SHA1 object format. Newer versions of git support using SHA256 as the object format, if the repo was created with git init --object-format=sha256. After the repo is created, the object format cannot be changed without loosing commit history. No extra configuration is necessary after the repo's creation.

@spenserblack
Copy link
Collaborator

spenserblack commented Jan 13, 2025

🤔 Can you report on the output of cat .git/config? Based on your error report, I'm assuming that --object-format=sha256 instructs git to set a certain configuration value on init (extensions.objectFormat to be precise). And I'm assuming that config value is what actually instructs git to use sha256 when creating commits. And, if it's controlled by a config value, that implies that sha256 and sha1 hashes could possibly be mixed together in a repository by adjusting the configuration.

So, essentially, my question is that, if extension.objectFormat is set to sha256, does that mean it can be assumed that all commits in the repo use that format, or should a mix of sha1 and sha256 object formats be supported? This is, IMO, dependent on what git itself does. Would git break or succeed if it encountered a sha1 object format in a repo where extensions.objectFormat = sha256?

@AtmosphericIgnition
Copy link
Author

.git/config:

[core]
	repositoryformatversion = 1
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = myrepo
	fetch = +refs/heads/*:refs/remotes/origin/*
[extensions]
	objectformat = sha256
[branch "main"]
	remote = origin
	merge = refs/heads/main

From everything I've read about this change, it seems the upstream git developers have no intention (point 3 of "Non-Goals") of making SHA1 and SHA256 object formats compatible in the same repository.

@spenserblack
Copy link
Collaborator

Thanks for the research!

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

No branches or pull requests

3 participants