为什么 Git 在 blob 文件中存储(和散列)blob 大小? [英] Why does Git store (and hash) blob size in the blob file?

查看:25
本文介绍了为什么 Git 在 blob 文件中存储(和散列)blob 大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git 的 blob 对象文件格式为 blob \0.标识 blob 的 SHA-1 哈希值不是仅根据 blob 内容计算的,而是根据标头增强的 blob 数据(如上所述)计算的.

Git's blob object file format is blob <size string>\0<data>. The blob-identifying SHA-1 hash is calculated not from the blob contents alone, but from the header-augmented blob data (as described above).

作为一个纯粹主义者,我不喜欢那种架构.它将数据的通用属性(其 SHA1 哈希)与一些特定于 git 的标头混合在一起.

As a purist I do not like that architecture. It mixes the universal property of the data (its SHA1 hash) with some git-specific header.

纯数据 blob 存储的另一个优点是可以使用写时复制"将文件添加到索引中,而不是复制整个文件.所需空间可以减半,某些操作可以变得更快.

Another advantage of pure-data blob storage is that the files can be added to the index using "copy-on-write" instead of copying the whole file. The required space could be halved and some operations could become faster.

那么,为什么 Git 开发者选择使用基于头的格式而不是纯数据格式?

So, why did Git developers choose to use the header-based format instead of the pure data format?

附言AFAIK 在 Git 的早期,SHA-1 哈希是基于压缩数据的.

P.S. AFAIK in the early days of Git the SHA-1 hash was based on the compressed data.

推荐答案

AFAIK 在 Git 的早期,SHA-1 哈希是基于压缩数据的.

AFAIK in the early days of Git the SHA-1 hash was based on the compressed data.

是的,这会导致各种优化",例如 commit 65c2e0c,2015 年 6 月:

Yes, and that lead to all kind of "optimizations" like commit 65c2e0c, git 0.99, June 2015:

在不膨胀所有内容的情况下查找 SHA1 对象的大小.

Find size of SHA1 object without inflating everything.

但是,git 如何计算文件哈希?"中说明的这种新格式可以追溯到:

But that new format, illustrated in "How does git compute file hashes?", can be traced back to:

  • git diff, in commit 051308f (git 1.4.0-rc1, May 2006)
  • git fast-import, started in commit db5e523 (git 1.5.0, Aug. 2006)

每次对数据本身做任何事情都需要数据的长度.

Each time, the length of the data is needed to do anything with the data itself.

这篇关于为什么 Git 在 blob 文件中存储(和散列)blob 大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆