t4041: use submodule repository for commit abbreviations
PATCH 1/1 t4041: use submodule repository for commit abbreviations
From: Srujith A Poojary <[email protected]>
Use the submodule repository when abbreviating commit IDs in submodule diff headers, so uniqueness is checked against the correct object database.
---
[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2288
submodule.c | 10 ++++++++-- t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)
submodule.c +8 -2
@@ -599,9 +599,15 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +if (sub) +strbuf_repo_add_unique_abbrev (&sb, sub, one,DEFAULT_ABBREV ); +else +strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +if (sub) +strbuf_repo_add_unique_abbrev (&sb, sub, two,DEFAULT_ABBREV ); +else +strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else
t/t4041-diff-submodule-option.sh +18 -0
@@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV then
base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
Signature · 1 line
gitgitgadget
Hi Srujith,
I applied this on top of master and ran t4041. The new test fails without the submodule.c change and passes with it, so it does catch the problem.
A few small things:
Quoted 3 lines · Srujith A Poojary via GitGitGadget
Use the submodule repository when abbreviating commit IDs in submodule diff headers, so uniqueness is checked against the correct object database.
It would help to first describe what happens today: the commit IDs in the "Submodule ..." header are abbreviated against the superproject's objects, even though the commits live in the submodule, so the abbreviation may not be unique there.
Quoted 2 lines
[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
The change itself is in submodule.c, so the title might read better with that area, e.g. "submodule: use the submodule repository to abbreviate commits".
Quoted 5 lines
-
strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
+ if (sub)
+strbuf_repo_add_unique_abbrev(&sb, sub, one, DEFAULT_ABBREV);
+ else
+strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
The same if/else appears twice. Maybe choose the repository once, at the top of the function, and call strbuf_repo_add_unique_abbrev() with it in both places. I also wonder whether the fallback could be o->repo instead of the_repository, since the diff options already carry a repository.
Thanks,
Okhuomon
PATCH v2 1/1 Submodule: use the submodule repository to abbreviate commits
In reply to Srujith A Poojary via GitGitGadgetFrom: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However, strbuf_add_unique_abbrev() uses the_repository, so it checks the superproject's object database when abbreviating those IDs.
Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
---
[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2288
Range-diff vs v1:
1: 7b2af1b46a ! 1: 3133cd3017 [Outreachy PATCH] t4041: use submodule repository for commit abbreviations
@@ Metadata
Author: Srujith A Poojary <[email protected]>
## Commit message ##
- [Outreachy PATCH] t4041: use submodule repository for commit abbreviations
+ Submodule: use the submodule repository to abbreviate commits
- Use the submodule repository when abbreviating commit IDs in
- submodule diff headers, so uniqueness is checked against the
- correct object database.
+ The commit IDs shown in a submodule diff header belong to the
+ submodule's object database. However, strbuf_add_unique_abbrev()
+ uses the_repository, so it checks the superproject's object
+ database when abbreviating those IDs.
+
+ Use the submodule repository when it is available, and fall back
+ to the repository from the diff options when it is not.
## submodule.c ##
@@ submodule.c: static void show_submodule_header(struct diff_options *o,
+ struct commit **left, struct commit **right,
+ struct commit_list **merge_bases)
+ {
++ struct repository *repo = sub ? sub : o->repo;
+ const char *message = NULL;
+ struct strbuf sb = STRBUF_INIT;
+ int fast_forward = 0, fast_backward = 0;
+@@ submodule.c: static void show_submodule_header(struct diff_options *o,
output_header:
strbuf_addf(&sb, "Submodule %s ", path);
- strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
-+ if (sub)
-+ strbuf_repo_add_unique_abbrev(&sb, sub, one, DEFAULT_ABBREV);
-+ else
-+ strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
++ strbuf_repo_add_unique_abbrev(&sb, repo, one, DEFAULT_ABBREV);
strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
- strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
-+ if (sub)
-+ strbuf_repo_add_unique_abbrev(&sb, sub, two, DEFAULT_ABBREV);
-+ else
-+ strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
++ strbuf_repo_add_unique_abbrev(&sb, repo, two, DEFAULT_ABBREV);
if (message)
strbuf_addf(&sb, " %s\n", message);
else
submodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-)
submodule.c +3 -2
@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;
@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else
t/t4041-diff-submodule-option.sh +18 -0
@@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV then
base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
Signature · 1 line
gitgitgadget
Quoted 33 lines · Okhuomon Ajayi
Hi Srujith,
I applied this on top of master and ran t4041. The new test fails without the
submodule.cchange and passes with it, so it does catch the problem.A few small things:
Quoted 3 lines · Srujith A Poojary via GitGitGadget
Use the submodule repository when abbreviating commit IDs in submodule diff headers, so uniqueness is checked against the correct object database.
It would help to first describe what happens today: the commit IDs in the "Submodule ..." header are abbreviated against the superproject's objects, even though the commits live in the submodule, so the abbreviation may not be unique there.
Quoted 2 lines
[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
The change itself is in
submodule.c, so the title might read better with that area, e.g. "submodule: use the submodule repository to abbreviate commits".Quoted 5 lines
-
strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
+ if (sub)
+strbuf_repo_add_unique_abbrev(&sb, sub, one, DEFAULT_ABBREV);
+ else
+strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
Quoted 8 lines
The same if/else appears twice. Maybe choose the repository once, at the top of the function, and call
strbuf_repo_add_unique_abbrev()with it in both places. I also wonder whether the fallback could beo->repoinstead ofthe_repository, since the diff options already carry a repository.Thanks,
Okhuomon
Hi Okhuomon,
Thanks for reviewing the patch and testing the new test case.
I've made the suggested changes and submitted v2. I now use sub when available and fall back to o->repo when it isn't. I also simplified the code and updated the commit message.
Here is the updated patch:
https://lore.kernel.org/git/[email protected]
Thanks again!
Regards,
Srujith
Re: [PATCH v2] Submodule: use the submodule repository to abbreviate commits
In reply to Srujith A Poojary via GitGitGadgetHi Srujith,
Quoted 1 line · Srujith A Poojary via GitGitGadget
+ struct repository *repo = sub ? sub :
o->repo;
Thanks, v2 looks good to me.
Quoted 1 line
Submodule: use the submodule repository to abbreviate commits
One small nit: "git log --no-merges submodule.c" shows the area is always written in lowercase ("submodule:"), so "submodule: use the submodule repository to abbreviate commits" would match.
Thanks,
Okhuomon
Quoted 136 lines · Srujith A Poojary via GitGitGadget
From: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However,
strbuf_add_unique_abbrev()usesthe_repository, so it checks the superproject's object database when abbreviating those IDs.Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
Signed-off-by Srujith A Poojary <[email protected]>---
[Outreachy PATCH] t4041: use submodule repository for commit abbreviationsPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2288Range-diff vs v1:
1:
7b2af1b46a! 1:3133cd3017[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
@@ Metadata
Author: Srujith A Poojary <[email protected]>## Commit message ##
- [Outreachy PATCH] t4041: use submodule repository for commit abbreviations
+ Submodule: use the submodule repository to abbreviate commits- Use the submodule repository when abbreviating commit IDs in
- submodule diff headers, so uniqueness is checked against the
- correct object database.
+ The commit IDs shown in a submodule diff header belong to the
+ submodule's object database. However,strbuf_add_unique_abbrev()
+ usesthe_repository, so it checks the superproject's object
+ database when abbreviating those IDs.
+
+ Use the submodule repository when it is available, and fall back
+ to the repository from the diff options when it is not.Signed-off-by Srujith A Poojary <[email protected]>##
submodule.c##
@@submodule.c: static void show_submodule_header(structdiff_options*o,
+ struct commit **left, struct commit **right,
+ structcommit_list**merge_bases)
+ {
++ struct repository *repo = sub ? sub :o->repo;
+ const char *message = NULL;
+ struct strbuf sb =STRBUF_INIT;
+ intfast_forward= 0,fast_backward= 0;
+@@submodule.c: static void show_submodule_header(structdiff_options*o,
output_header:
strbuf_addf(&sb, "Submodule %s ", path);
-strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
-+ if (sub)
-+strbuf_repo_add_unique_abbrev(&sb, sub, one, DEFAULT_ABBREV);
-+ else
-+strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
++strbuf_repo_add_unique_abbrev(&sb, repo, one, DEFAULT_ABBREV);
strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
-strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
-+ if (sub)
-+strbuf_repo_add_unique_abbrev(&sb, sub, two, DEFAULT_ABBREV);
-+ else
-+strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
++strbuf_repo_add_unique_abbrev(&sb, repo, two, DEFAULT_ABBREV);
if (message)
strbuf_addf(&sb, " %s\n", message);
elsesubmodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-)submodule.c +3
-2@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else t/t4041-diff-submodule-option.sh +18
-0@@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV thenbase-commit:
50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7--
gitgitgadget
PATCH v3 1/1 submodule: use the submodule repository to abbreviate commits
In reply to Srujith A Poojary via GitGitGadgetFrom: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However, strbuf_add_unique_abbrev() uses the_repository, so it checks the superproject's object database when abbreviating those IDs.
Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
---
[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/2288
Range-diff vs v2:
1: 3133cd3017 ! 1: a8c54b9292 Submodule: use the submodule repository to abbreviate commits
@@ Metadata
Author: Srujith A Poojary <[email protected]>
## Commit message ##
- Submodule: use the submodule repository to abbreviate commits
+ submodule: use the submodule repository to abbreviate commits
The commit IDs shown in a submodule diff header belong to the submodule's object database. However, strbuf_add_unique_abbrev()
submodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-)
submodule.c +3 -2
@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;
@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else
t/t4041-diff-submodule-option.sh +18 -0
@@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV then
base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
Signature · 1 line
gitgitgadget
Re: [PATCH v2] Submodule: use the submodule repository to abbreviate commits
In reply to Okhuomon AjayiQuoted 152 lines · Okhuomon Ajayi
Hi Srujith,
Quoted 1 line · Srujith A Poojary via GitGitGadget
+ struct repository *repo = sub ? sub :
o->repo;Thanks, v2 looks good to me.
Quoted 1 line
Submodule: use the submodule repository to abbreviate commits
One small nit: "git log --no-merges
submodule.c" shows the area is always written in lowercase ("submodule:"), so "submodule: use the submodule repository to abbreviate commits" would match.Thanks,
OkhuomonQuoted 132 lines · Srujith A Poojary via GitGitGadget
From: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However,
strbuf_add_unique_abbrev()usesthe_repository, so it checks the superproject's object database when abbreviating those IDs.Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
Signed-off-by Srujith A Poojary <[email protected]>---
[Outreachy PATCH] t4041: use submodule repository for commit abbreviationsPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2288Range-diff vs v1:
1:
7b2af1b46a! 1:3133cd3017[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
@@ Metadata
Author: Srujith A Poojary <[email protected]>## Commit message ##
- [Outreachy PATCH] t4041: use submodule repository for commit abbreviations
+ Submodule: use the submodule repository to abbreviate commits- Use the submodule repository when abbreviating commit IDs in
- submodule diff headers, so uniqueness is checked against the
- correct object database.
+ The commit IDs shown in a submodule diff header belong to the
+ submodule's object database. However,strbuf_add_unique_abbrev()
+ usesthe_repository, so it checks the superproject's object
+ database when abbreviating those IDs.
+
+ Use the submodule repository when it is available, and fall back
+ to the repository from the diff options when it is not.Signed-off-by Srujith A Poojary <[email protected]>##
submodule.c##
@@submodule.c: static void show_submodule_header(structdiff_options*o,
+ struct commit **left, struct commit **right,
+ structcommit_list**merge_bases)
+ {
++ struct repository *repo = sub ? sub :o->repo;
+ const char *message = NULL;
+ struct strbuf sb =STRBUF_INIT;
+ intfast_forward= 0,fast_backward= 0;
+@@submodule.c: static void show_submodule_header(structdiff_options*o,
output_header:
strbuf_addf(&sb, "Submodule %s ", path);
-strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
-+ if (sub)
-+strbuf_repo_add_unique_abbrev(&sb, sub, one, DEFAULT_ABBREV);
-+ else
-+strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
++strbuf_repo_add_unique_abbrev(&sb, repo, one, DEFAULT_ABBREV);
strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
-strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
-+ if (sub)
-+strbuf_repo_add_unique_abbrev(&sb, sub, two, DEFAULT_ABBREV);
-+ else
-+strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
++strbuf_repo_add_unique_abbrev(&sb, repo, two, DEFAULT_ABBREV);
if (message)
strbuf_addf(&sb, " %s\n", message);
elsesubmodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-)submodule.c +3
-2@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else t/t4041-diff-submodule-option.sh +18
-0@@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV then
Quoted 3 lines
Quoted 3 lines
base-commit:
50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7--
gitgitgadget
Hi Okhuomon,
Thanks for pointing that out. I've corrected the subject to use lowercase submodule and submitted v3.
Regards,
Srujith
Quoted 1 line
Quoted 1 line
Re: [PATCH v3] submodule: use the submodule repository to abbreviate commits
In reply to Srujith A Poojary via GitGitGadget"Srujith A Poojary via GitGitGadget" <[email protected]>
Quoted 9 lines · writes:
From: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However,
strbuf_add_unique_abbrev()usesthe_repository, so it checks the superproject's object database when abbreviating those IDs.Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
While the fallback behaviour does not make much sense (the commit object recorded in gitlink is not expected to be found in the superproject's repository, which is the reason why you are adding this fix in the first place), it would mean that for unpopulated submodules for which you haven't run "git submodule init", the behaviour would stay the ame as before.
Quoted 14 lines
submodule.c +1
-0@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o,
submodule.c static void show_submodule_header(struct diff_options *o, · line 608
Quoted 10 lines
submodule.c +2
-2output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else
Quite straightforward.
Quoted 1 line
+test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' '
Hmph. I wonder if there is a way to use the test_oid_cache facility to allow test with both SHA-1 and SHA-256 hashes?
Will queue.
Thanks.
v4 cover t4041: use submodule repository for commit abbreviations
In reply to Srujith A Poojary via GitGitGadgetSrujith A Poojary (2):
submodule: use the submodule repository to abbreviate commits
t4041: test SHA-256 submodule abbreviations
submodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)
base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/2288
Range-diff vs v3:
1: a8c54b9292 = 1: a8c54b9292 submodule: use the submodule repository to abbreviate commits -: ---------- > 2: 99a1234544 t4041: test SHA-256 submodule abbreviations
Signature · 1 line
gitgitgadget
PATCH v4 1/2 submodule: use the submodule repository to abbreviate commits
From: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However, strbuf_add_unique_abbrev() uses the_repository, so it checks the superproject's object database when abbreviating those IDs.
Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
--- submodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-)
submodule.c +3 -2
@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;
@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else
t/t4041-diff-submodule-option.sh +18 -0
@@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV then
Signature · 1 line
gitgitgadget
PATCH v4 2/2 t4041: test SHA-256 submodule abbreviations
In reply to Srujith A Poojary via GitGitGadgetFrom: Srujith A Poojary <[email protected]>
The expected abbreviation for a submodule commit depends on the repository's hash algorithm. Use test_oid_cache to provide the expected value for each algorithm and remove the SHA1 prerequisite so this test runs with both SHA-1 and SHA-256.
--- t/t4041-diff-submodule-option.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
t/t4041-diff-submodule-option.sh +7 -2
@@ -14,7 +14,11 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' +test_expect_success 'submodule commit abbreviation uses submodule object database' ' + test_oid_cache <<-EOF && + submodule_commit1_abbrev sha1:0000000000e + submodule_commit1_abbrev sha256:24c81a5 + EOF test_when_finished "rm -rf collision-super" && git init -q collision-super && git init -q collision-super/sm1 &&
@@ -27,7 +31,8 @@ test_expect_success SHA1 'submodule commit abbreviation uses submodule object da git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && git -C collision-super commit -q -m "Add submodule" && git -C collision-super diff --submodule=log >actual && - printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + printf "Submodule sm1 %s..%s:\n > child\n" \ + "$(test_oid submodule_commit1_abbrev)" \ "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && test_cmp expected actual '
Signature · 1 line
gitgitgadget
Re: [PATCH v4 1/2] submodule: use the submodule repository to abbreviate commits
In reply to Srujith A Poojary via GitGitGadgetQuoted 71 lines · Srujith A Poojary via GitGitGadget
From: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However,
strbuf_add_unique_abbrev()usesthe_repository, so it checks the superproject's object database when abbreviating those IDs.Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
Signed-off-by Srujith A Poojary <[email protected]>--- submodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-)submodule.c +3
-2@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else t/t4041-diff-submodule-option.sh +18
-1@@ -14,6 +14,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV then --
Quoted 2 lines
gitgitgadget
Hi Junio,
Thanks for the suggestion.
I've updated the t4041 test to use test_oid_cache with separate expected abbreviations for SHA-1 and SHA-256. I've also removed the SHA1-only prerequisite so that the test runs with both hash algorithms.
I tested the updated test script using both configurations:
- SHA-1: all 48 tests passed.
- SHA-256: all 48 tests passed.
I've updated the commit message, added the Signed-off-by trailer, and submitted the revised v4 patch series.
The updated patch series is available here:
https://lore.kernel.org/git/[email protected]/
Thanks for the suggestion and review.
Regards,
Srujith
"Srujith A Poojary via GitGitGadget" <[email protected]>
Quoted 3 lines · writes:
Srujith A Poojary (2):
submodule: use the submodule repository to abbreviate commits
t4041: test SHA-256 submodule abbreviations
If you are sending a cover letter, you are expected to summarize the changes since the previous iteration(s) in it, so that those who are joining the discussion in the middle can tell the history behind the current iteration.
Quoted 14 lines
submodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)base-commit:
50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/2288Range-diff vs v3:
1: a8c54b9292 = 1: a8c54b9292 submodule: use the submodule repository to abbreviate commits -: ---------- > 2: 99a1234544 t4041: test SHA-256 submodule abbreviations
Re: [PATCH v4 2/2] t4041: test SHA-256 submodule abbreviations
In reply to Srujith A Poojary via GitGitGadget"Srujith A Poojary via GitGitGadget" <[email protected]>
Quoted 11 lines · writes:
From: Srujith A Poojary <[email protected]>
The expected abbreviation for a submodule commit depends on the repository's hash algorithm. Use
test_oid_cacheto provide the expected value for each algorithm and remove the SHA1 prerequisite so this test runs with both SHA-1 and SHA-256.Signed-off-by Srujith A Poojary <[email protected]>--- t/t4041-diff-submodule-option.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
It is strange to test SHA-1 in 1/2 and add test for SHA-256 as if an afterthought in 2/2. Shouldn't all of these come in a single patch?
The change to add the second hash algorithm support is surprisingly clean, primarily thanks to how test_oid* support was done long ago.
Quoted 27 lines
t/t4041-diff-submodule-option.sh +7
-2@@ -14,7 +14,11 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' +test_expect_success 'submodule commit abbreviation uses submodule object database' ' + test_oid_cache <<-EOF && + submodule_commit1_abbrev sha1:0000000000e + submodule_commit1_abbrev sha256:24c81a5 + EOF test_when_finished "rm -rf collision-super" && git init -q collision-super && git init -q collision-super/sm1 &&@@ -27,7 +31,8 @@ test_expect_success SHA1 'submodule commit abbreviation uses submodule object da git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && git -C collision-super commit -q -m "Add submodule" && git -C collision-super diff --submodule=log >actual && - printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + printf "Submodule sm1 %s..%s:\n > child\n" \ + "$(test_oid submodule_commit1_abbrev)" \ "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && test_cmp expected actual '
PATCH v5 1/1 submodule: use the submodule repository to abbreviate commits
In reply to Srujith A Poojary via GitGitGadgetFrom: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However, strbuf_add_unique_abbrev() uses the_repository, so it checks the superproject's object database when abbreviating those IDs.
Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
The expected abbreviation for a submodule commit depends on the repository's hash algorithm. Use test_oid_cache to provide the expected value for each algorithm and remove the SHA1 prerequisite so this test runs with both SHA-1 and SHA-256.
---
[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v5
Pull-Request: https://github.com/gitgitgadget/git/pull/2288
Range-diff vs v4:
1: a8c54b9292 ! 1: f94aa2476f submodule: use the submodule repository to abbreviate commits
@@ Commit message
Use the submodule repository when it is available, and fall back
to the repository from the diff options when it is not.
+ The expected abbreviation for a submodule commit depends on the
+ repository's hash algorithm. Use test_oid_cache to provide the
+ expected value for each algorithm and remove the SHA1 prerequisite
+ so this test runs with both SHA-1 and SHA-256.
+
Signed-off-by: Srujith A Poojary <[email protected]>
## submodule.c ##
@@ t/t4041-diff-submodule-option.sh: export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
-+test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' '
++test_expect_success 'submodule commit abbreviation uses submodule object database' '
++ test_oid_cache <<-EOF &&
++ submodule_commit1_abbrev sha1:0000000000e
++ submodule_commit1_abbrev sha256:24c81a5
++ EOF
+ test_when_finished "rm -rf collision-super" &&
+ git init -q collision-super &&
+ git init -q collision-super/sm1 &&
@@ t/t4041-diff-submodule-option.sh: export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+ git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 &&
+ git -C collision-super commit -q -m "Add submodule" &&
+ git -C collision-super diff --submodule=log >actual &&
-+ printf "Submodule sm1 0000000000e..%s:\n > child\n" \
++ printf "Submodule sm1 %s..%s:\n > child\n" \
++ "$(test_oid submodule_commit1_abbrev)" \
+ "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected &&
+ test_cmp expected actual
+' 2: 99a1234544 < -: ---------- t4041: test SHA-256 submodule abbreviations
submodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)
submodule.c +3 -2
@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;
@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else
t/t4041-diff-submodule-option.sh +23 -0
@@ -14,6 +14,29 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success 'submodule commit abbreviation uses submodule object database' ' + test_oid_cache <<-EOF && + submodule_commit1_abbrev sha1:0000000000e + submodule_commit1_abbrev sha256:24c81a5 + EOF + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 %s..%s:\n > child\n" \ + "$(test_oid submodule_commit1_abbrev)" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV then
base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
Signature · 1 line
gitgitgadget
Re: [PATCH v4 2/2] t4041: test SHA-256 submodule abbreviations
In reply to Junio C HamanoQuoted 41 lines · Junio C Hamano
"Srujith A Poojary via GitGitGadget" <[email protected]>
Quoted 11 lines · writes:
From: Srujith A Poojary <[email protected]>
The expected abbreviation for a submodule commit depends on the repository's hash algorithm. Use
test_oid_cacheto provide the expected value for each algorithm and remove the SHA1 prerequisite so this test runs with both SHA-1 and SHA-256.Signed-off-by Srujith A Poojary <[email protected]>--- t/t4041-diff-submodule-option.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)It is strange to test SHA-1 in 1/2 and add test for SHA-256 as if an afterthought in 2/2. Shouldn't all of these come in a single patch?
The change to add the second hash algorithm support is surprisingly clean, primarily thanks to how test_oid* support was done long ago.
Quoted 19 lines
t/t4041-diff-submodule-option.sh +5
-1@@ -14,7 +14,11 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -test_expect_success SHA1 'submodule commit abbreviation uses submodule object database' ' +test_expect_success 'submodule commit abbreviation uses submodule object database' ' + test_oid_cache <<-EOF && + submodule_commit1_abbrev sha1:0000000000e + submodule_commit1_abbrev sha256:24c81a5 + EOF test_when_finished "rm -rf collision-super" && git init -q collision-super && git init -q collision-super/sm1 &&@@ -27,7 +31,8 @@ test_expect_success SHA1 'submodule commit abbreviation uses submodule object da git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 &&
Quoted 8 lines
t/t4041-diff-submodule-option.sh test_expect_success SHA1 'submodule commit abbreviation uses submodule object da · line 38
Quoted 8 lines
t/t4041-diff-submodule-option.sh +2
-1git -C collision-super commit -q -m "Add submodule" && git -C collision-super diff --submodule=log >actual && - printf "Submodule sm1 0000000000e..%s:\n > child\n" \ + printf "Submodule sm1 %s..%s:\n > child\n" \ + "$(test_oid submodule_commit1_abbrev)" \ "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && test_cmp expected actual '
Hi Usman and Harald,
I wanted to share a progress update on my Git contribution.
I have submitted v5 of my submodule commit abbreviation patch through GitGitGadget.
The latest version incorporates feedback from Junio C. Hamano and Okhuomon Ajayi. I combined the implementation and SHA-256 test changes into one commit.
The targeted test suite, t4041-diff-submodule-option.sh, passes all 48 tests.
PR: https://github.com/gitgitgadget/git/pull/2288
I will continue monitoring the review discussion and work on any further feedback.
Regards,
Srujith
Re: [PATCH v5] submodule: use the submodule repository to abbreviate commits
In reply to Srujith A Poojary via GitGitGadget"Srujith A Poojary via GitGitGadget" <[email protected]>
Quoted 7 lines · writes:
From: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However,
strbuf_add_unique_abbrev()usesthe_repository, so it checks the superproject's object database when abbreviating those IDs.
Quoted 7 lines
Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
The expected abbreviation for a submodule commit depends on the repository's hash algorithm. Use
test_oid_cacheto provide the expected value for each algorithm and remove the SHA1 prerequisite so this test runs with both SHA-1 and SHA-256.
"remove"? What are you talking about???
Above the three-dash line, decribe the change to those who read _ONLY_ this iteration, not any earlier ones, because that is what "git log" readers will see. Perhaps write it more like
As the expected abbreviation depends on the hash algorithm used, the test uses the test_oid mechanism to switch the expectation between SHA-1 and SHA-256 repositories.
or something, if you want to help readers who are not as familiar with our system and its test infrastructure as you are understand what you did.
Quoted 2 lines
Signed-off-by Srujith A Poojary <[email protected]>---
Here below the three-dash line is a place for you to describe what changed since the earlier rounds in your own words. Range-diff is added to aid it, but not as a replacement.
Changes since v4 is to squash two pieces into a single patch, as far as I can tell. Such a change is not visible in range-diff as #2 goes away, readers cannot tell where the additional material in #1 came from.
Overall it is looking good. Thanks.
PATCH v6 1/1 submodule: use the submodule repository to abbreviate commits
In reply to Srujith A Poojary via GitGitGadgetFrom: Srujith A Poojary <[email protected]>
The commit IDs shown in a submodule diff header belong to the submodule's object database. However, strbuf_add_unique_abbrev() uses the_repository, so it checks the superproject's object database when abbreviating those IDs.
Use the submodule repository when it is available, and fall back to the repository from the diff options when it is not.
As the expected abbreviation depends on the hash algorithm used, the test uses the test_oid mechanism to switch the expectation between SHA-1 and SHA-256 repositories.
---
[Outreachy PATCH] t4041: use submodule repository for commit abbreviations
Changes since v4:
* Combine the implementation and SHA-256 test updates into a single patch.
* Update the commit message to explain how the test uses test_oid to switch expectations between SHA-1 and SHA-256 repositories.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2288%2Fpoojarysrujith%2Fmicroproject-git-libification-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2288/poojarysrujith/microproject-git-libification-v6
Pull-Request: https://github.com/gitgitgadget/git/pull/2288
Range-diff vs v5:
1: f94aa2476f ! 1: 01c3cc2573 submodule: use the submodule repository to abbreviate commits
@@ Commit message
Use the submodule repository when it is available, and fall back
to the repository from the diff options when it is not.
- The expected abbreviation for a submodule commit depends on the
- repository's hash algorithm. Use test_oid_cache to provide the
- expected value for each algorithm and remove the SHA1 prerequisite
- so this test runs with both SHA-1 and SHA-256.
+ As the expected abbreviation depends on the hash algorithm used,
+ the test uses the test_oid mechanism to switch the expectation
+ between SHA-1 and SHA-256 repositories.
submodule.c | 5 +++-- t/t4041-diff-submodule-option.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)
submodule.c +3 -2
@@ -543,6 +543,7 @@ static void show_submodule_header(struct diff_options *o, struct commit **left, struct commit **right, struct commit_list **merge_bases) { + struct repository *repo = sub ? sub : o->repo;const char *message =NULL ;struct strbuf sb =STRBUF_INIT ;int fast_forward =0 , fast_backward =0 ;
@@ -599,9 +600,9 @@ static void show_submodule_header(struct diff_options *o, output_header:strbuf_addf (&sb,"Submodule %s " , path); -strbuf_add_unique_abbrev (&sb, one,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, one,DEFAULT_ABBREV );strbuf_addstr (&sb, (fast_backward || fast_forward) ?".." :"..." ); -strbuf_add_unique_abbrev (&sb, two,DEFAULT_ABBREV ); +strbuf_repo_add_unique_abbrev (&sb, repo, two,DEFAULT_ABBREV );if (message)strbuf_addf (&sb," %s\n" , message);else
t/t4041-diff-submodule-option.sh +23 -0
@@ -14,6 +14,29 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success 'submodule commit abbreviation uses submodule object database' ' + test_oid_cache <<-EOF && + submodule_commit1_abbrev sha1:0000000000e + submodule_commit1_abbrev sha256:24c81a5 + EOF + test_when_finished "rm -rf collision-super" && + git init -q collision-super && + git init -q collision-super/sm1 && + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n\nb1rwzyc3\n" >collision-super/sm1/a0blgqsjc && + git -C collision-super/sm1 add a0blgqsjc && + tree=$(git -C collision-super/sm1 write-tree) && + commit1=$(GIT_AUTHOR_DATE="1112911993 -0700" GIT_COMMITTER_DATE="1112911993 -0700" git -C collision-super/sm1 commit-tree "$tree" -m a2onsxbvj) && + commit2=$(printf "child\n" | GIT_AUTHOR_DATE="1112912053 -0700" GIT_COMMITTER_DATE="1112912053 -0700" git -C collision-super/sm1 commit-tree "$tree" -p "$commit1") && + git -C collision-super/sm1 checkout -q "$commit2" && + git -C collision-super update-index --add --cacheinfo 160000,"$commit1",sm1 && + git -C collision-super commit -q -m "Add submodule" && + git -C collision-super diff --submodule=log >actual && + printf "Submodule sm1 %s..%s:\n > child\n" \ + "$(test_oid submodule_commit1_abbrev)" \ + "$(git -C collision-super/sm1 rev-parse --short "$commit2")" >expected && + test_cmp expected actual +' + # Test non-UTF-8 encoding in case iconv is available. if test_have_prereq ICONV then
base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
Signature · 1 line
gitgitgadget
Re: [PATCH v6] submodule: use the submodule repository to abbreviate commits
"Srujith A Poojary via GitGitGadget" <[email protected]>
Quoted 15 lines · writes:
Range-diff vs v5:
1:
f94aa2476f! 1:01c3cc2573submodule: use the submodule repository to abbreviate commits
@@ Commit message
Use the submodule repository when it is available, and fall back
to the repository from the diff options when it is not.- The expected abbreviation for a submodule commit depends on the
- repository's hash algorithm. Usetest_oid_cacheto provide the
- expected value for each algorithm and remove the SHA1 prerequisite
- so this test runs with both SHA-1 and SHA-256.
+ As the expected abbreviation depends on the hash algorithm used,
+ the test uses thetest_oidmechanism to switch the expectation
+ between SHA-1 and SHA-256 repositories.
Quoted 1 line
Signed-off-by Srujith A Poojary <[email protected]>
Very good. The patch text was already good at v4 and hasn't changed since then.
Let's queue and mark it as ready for 'next'.
Thanks.
Re: [PATCH v6] submodule: use the submodule repository to abbreviate commits
Quoted 19 lines · Junio C Hamano
"Srujith A Poojary via GitGitGadget" <[email protected]>
Quoted 15 lines · writes:
Range-diff vs v5:
1:
f94aa2476f! 1:01c3cc2573submodule: use the submodule repository to abbreviate commits
@@ Commit message
Use the submodule repository when it is available, and fall back
to the repository from the diff options when it is not.- The expected abbreviation for a submodule commit depends on the
- repository's hash algorithm. Usetest_oid_cacheto provide the
- expected value for each algorithm and remove the SHA1 prerequisite
- so this test runs with both SHA-1 and SHA-256.
+ As the expected abbreviation depends on the hash algorithm used,
+ the test uses thetest_oidmechanism to switch the expectation
+ between SHA-1 and SHA-256 repositories.
Quoted 8 lines
Quoted 1 line
Signed-off-by Srujith A Poojary <[email protected]>Very good. The patch text was already good at v4 and hasn't changed since then.
Let's queue and mark it as ready for 'next'.
Thanks.
Hi Junio,
Thank you for reviewing the patch and for your feedback. I appreciate your time and support.
Thanks,
Srujith