水银文件ID

发布于 2025-01-01 14:27:40 字数 253 浏览 3 评论 0原文

有没有办法获取存储库中文件的不可变文件 ID?

我需要一个在文件重命名后仍然存在的标识符。因此,如果有文件 Test01.txt 并将其重命名为 Test02.txt(使用 TortoiseHG 重命名菜单项或 hg rename 命令)。我想要一些与修订版 1 的 Test01.txt 和修订版 2 的 Test02.txt 相对应的 ID。

Is there any way to get an immutable file ID for a file in repository?

I need an identifier which will survive a file rename. So if there was file Test01.txt and it was renamed to Test02.txt (using TortoiseHG rename menu item or the hg rename command). I want to have some ID which will correspond to Test01.txt at revision 1 and Test02.txt at revision 2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东走西顾 2025-01-08 14:27:40

Mercurial 不会为文件提供任何 ID。这与其他一些系统不同,例如 Bazaar,其中每个文件(和目录)都有一个唯一的 ID,该 ID 在文件的整个生命周期中都跟随该 ID。

Mercurial 存储库中的结构如下:

  • 变更日志中的每个条目都有一个指向
    • 清单中的一个条目,每个文件都有一个指向
      • 文件文件日志中的条目

因此,如果您在修订版 0 中添加 Test01.txt,那么您将拥有一个像这样的链

changelog@0 -> manifest@0 -> Test01.txt@0

如果您现在重命名并创建一个新的提交,您将创建一个新的变更日志和清单条目,并为 Test02.txt 创建一个文件日志:

changelog@1 -> manifest@1 -> Test02.txt@0

新的 Test02.txt文件日志条目将引用Test01.txt 条目。这就是 Mercurial 跟踪重命名的方式:

$ hg debugdata Test02.txt 0

copy: Test01.txt
copyrev: 0936f74a58571dd87ad343cc3d6ae8434ad86fc4

test01

因此,您可以谈论的最佳“文件 ID”是原始文件日志中第一个条目的 ID。您可以使用 hg debugindex 来挖掘它:

$ hg debugindex Test01.txt
   rev    offset  length   base linkrev nodeid       p1           p2
     0         0       8      0       0 0936f74a5857 000000000000 000000000000

“nodeid”列为您提供

“linkrev”告诉您该版本的文件由变更集 0 引用。您可以使用 hg debugdata -c 0< 查找该变更日志条目中的数据/code>,但出于我们的目的,正常的 hg log 命令还包含信息:

$ hg log -r 0 --debug
changeset:   0:8e62ecaada0e5ba9efec234d0d9a66583347becf
phase:       draft
parent:      -1:0000000000000000000000000000000000000000
parent:      -1:0000000000000000000000000000000000000000
manifest:    0:0537c846cd545da8f826b9d94fdb2fdae457bd07
user:        Martin Geisler <[email protected]>
date:        Thu Feb 02 09:00:18 2012 +0100
files+:      Test01.txt
extra:       branch=default
description:
01

我们对清单 ID 感兴趣。您现在可以在正确的清单条目中查找数据:

$ hg debugdata -m 0537c846cd545da8f826b9d94fdb2fdae457bd07
Test01.txt0936f74a58571dd87ad343cc3d6ae8434ad86fc4

文件名和文件日志 ID 之间确实有一个 NUL 字节,但它在您的终端中不可见。您现在拥有 Test01.txt 文件第一个修订版的完整文件日志 ID。

您还需要从 Test02.txt 转到 Test01.txt。您可以使用 hg log --followhg debugrename 来实现此目的:使用 hg log 获取有关文件的修订版本,并使用 hg debugrename 查看每个步骤中文件被重命名的内容。

Mercurial does not give any ID to files. This is different from some other systems, such as Bazaar, where each file (and directory) has a unique ID that follows the file throughout it's life time.

The structure in a Mercurial repository is as follows:

  • each entry in the changelog has a single pointer to
    • an entry in the manifest, which has a pointer per file to
      • an entry in the file's filelog

So if you add Test01.txt in revision 0, then you'll have a chain like this

changelog@0 -> manifest@0 -> Test01.txt@0

If you now rename and make a new commit, you will create a new changelog and manifest entry, and create a new filelog for Test02.txt:

changelog@1 -> manifest@1 -> Test02.txt@0

The new Test02.txt filelog entry will reference the Test01.txt entry. This is how Mercurial can keep track of renames:

$ hg debugdata Test02.txt 0

copy: Test01.txt
copyrev: 0936f74a58571dd87ad343cc3d6ae8434ad86fc4

test01

The best "file ID" you can talk about is therefore the ID of the first entry in the original file log. You can dig it out with hg debugindex:

$ hg debugindex Test01.txt
   rev    offset  length   base linkrev nodeid       p1           p2
     0         0       8      0       0 0936f74a5857 000000000000 000000000000

The "nodeid" column gives you the IDs for the revlog entries in the filelog for Test01.txt. Here we see that the first revision of the file has ID 0936f74a5857. This is just a short, 12 character prefix of the full 40 character SHA-1 hash. If you need the full hash, then read on...

The "linkrev" tells you that this version of the file is referenced by changeset 0. You can lookup the data in that changelog entry with hg debugdata -c 0, but for our purposes the normal hg log command also has the information:

$ hg log -r 0 --debug
changeset:   0:8e62ecaada0e5ba9efec234d0d9a66583347becf
phase:       draft
parent:      -1:0000000000000000000000000000000000000000
parent:      -1:0000000000000000000000000000000000000000
manifest:    0:0537c846cd545da8f826b9d94fdb2fdae457bd07
user:        Martin Geisler <[email protected]>
date:        Thu Feb 02 09:00:18 2012 +0100
files+:      Test01.txt
extra:       branch=default
description:
01

We're interested in the manifest ID. You can now look up the data in the correct manifest entry with:

$ hg debugdata -m 0537c846cd545da8f826b9d94fdb2fdae457bd07
Test01.txt0936f74a58571dd87ad343cc3d6ae8434ad86fc4

There is really a NUL byte between the file name and the filelog ID, but it's not visible in your terminal. You now have the full filelog ID for the first revision of the Test01.txt file.

You also need to go from Test02.txt to Test01.txt. You can use hg log --follow and hg debugrename for this: use hg log to get the revisions concerning the file, and use hg debugrename to see what the file was renamed from in each step.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文