-
Notifications
You must be signed in to change notification settings - Fork 57
preserve commit signatures #958
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,18 @@ pub fn rewrite_commit( | |
parents, | ||
)?; | ||
|
||
if let Ok((sig, _)) = repo.extract_signature(&base.id(), None) { | ||
// Re-create the object with the original signature (which of course does not match any | ||
// more, but this is needed to guarantee perfect round-trips). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW there is a comment a few lines up that needs updating now -- or we could entirely remove that equality check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that equality check can be removed. It's value as an optimization is super low as it is an quite rare case. |
||
let b = b | ||
.as_str() | ||
.ok_or_else(|| josh_error("non-UTF-8 signed commit"))?; | ||
let sig = sig | ||
.as_str() | ||
.ok_or_else(|| josh_error("non-UTF-8 signature"))?; | ||
return Ok(repo.commit_signed(b, sig, None)?); | ||
} | ||
|
||
return Ok(repo.odb()?.write(git2::ObjectType::Commit, &b)?); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
$ git init -q 1> /dev/null | ||
|
||
Initial commit | ||
$ echo contents1 > file1 | ||
$ git add . | ||
$ git commit -m "add file1" 1> /dev/null | ||
|
||
Now create another commit for the same tree, but with a gpgsig | ||
$ git rev-parse HEAD | ||
0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb | ||
$ git cat-file commit HEAD | ||
tree 3d77ff51363c9825cc2a221fc0ba5a883a1a2c72 | ||
author Josh <josh@example.com> 1112911993 +0000 | ||
committer Josh <josh@example.com> 1112911993 +0000 | ||
|
||
add file1 | ||
$ git hash-object -t commit -w --stdin <<EOF | ||
> tree 3d77ff51363c9825cc2a221fc0ba5a883a1a2c72 | ||
> author Josh <josh@example.com> 1112911993 +0000 | ||
> committer Josh <josh@example.com> 1112911993 +0000 | ||
> gpgsig hello | ||
> | ||
> add file1 | ||
> EOF | ||
cb22ebb8e47b109f7add68b1043e561e0db09802 | ||
$ git reset --hard cb22ebb8e47b109f7add68b1043e561e0db09802 1>/dev/null | ||
|
||
Apply a josh round-trip to this. | ||
$ josh-filter :prefix=extra refs/heads/master --update refs/heads/filtered | ||
$ josh-filter :/extra refs/heads/filtered --update refs/heads/double-filtered | ||
|
||
And compare. Should be the same commit for both. | ||
If 0b4cf6c9efbbda1eada39fa9c1d21d2525b027bb shows up then the signature was lost. | ||
$ git diff master double-filtered | ||
$ git rev-parse master double-filtered | ||
cb22ebb8e47b109f7add68b1043e561e0db09802 | ||
cb22ebb8e47b109f7add68b1043e561e0db09802 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
$ git init -q 1> /dev/null | ||
|
||
Initial commit | ||
$ echo contents1 > file1 | ||
$ git add . | ||
$ git commit -m "add file1" 1> /dev/null | ||
|
||
Apply prefix filter | ||
$ josh-filter -s :prefix=subtree refs/heads/master --update refs/heads/filtered | ||
[1] :prefix=subtree | ||
|
||
$ git log --graph --pretty=%s refs/heads/filtered | ||
* add file1 | ||
|
||
$ git ls-tree --name-only -r refs/heads/filtered | ||
subtree/file1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,7 @@ | |
"real_repo.git" = [':/sub3'] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,7 @@ | |
"real_repo.git" = [':/sub1'] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ | |
"real_repo.git" = [':/sub1'] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
$ bash ${TESTDIR}/destroy_test_env.sh | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ | |
"real_repo.git" = [':/sub1'] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ | |
"real_repo.git" = [':/sub1'] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,7 +114,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
$ bash ${TESTDIR}/destroy_test_env.sh | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ | |
"real_repo.git" = [':prefix=sub1'] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,7 +328,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ test for that. | |
"real_repo.git" = [] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ | |
] | ||
. | ||
|-- josh | ||
| `-- 12 | ||
| `-- 13 | ||
| `-- sled | ||
| |-- blobs | ||
| |-- conf | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
here and in thecommit_signed
below refers to the name of the signature field. Looks like that can be customized. Roundtrips will still not work if there are commits that use a non-standard name for that field. I don't know how to get git to tell us tabout non-standard fields... really ideally we'd have an API to list all header fields, and preserve them all while only adjusting thetree
, but I am not sure if that is possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's quite interesting: We could maybe at some point even use that for out own metadata. Good to know.
About getting all extra header fields: Worst case we have to parse the commit buffer ourselves. But I think this is good enough for now.
One little thing: The constant
CACHE_VERSION
insrc/cache.rs
should be incremented whenever we make a change that can affect the output sha's of any filter. This is to avoid strange effects that could happen when somebody uses a cache that was computed using the old version and things could get mixed up.