{"thread":{"id":"66698","subject":"[Outreachy PATCH] range-diff: use the repository from the diff options","startedAt":"2026-10-28T21:51:37Z","lastAt":"2026-10-29T16:19:17Z","messageCount":4,"participants":["Okhuomon Ajayi","Pablo Sabater","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"556713","messageId":"20261028215137.15262-1-okhuomonajayi54@gmail.com","threadId":"66698","inReplyTo":null,"subject":"[Outreachy PATCH] range-diff: use the repository from the diff options","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-10-28T21:51:37Z","receivedAt":"2026-10-28T21:51:37Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"output_pair_header() and patch_diff() already receive the diff\noptions, but use the_repository and the_hash_algo. Use the\nrepository from diffopt instead, and pass only the hash algorithm\nto get_filespec(), as that is all it needs.\n\nread_patches(), output() and is_range_diff_range() still use\nthe_repository, so USE_THE_REPOSITORY_VARIABLE stays.\n\nSigned-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n---\n range-diff.c | 16 +++++++++-------\n 1 file changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/range-diff.c b/range-diff.c\nindex 8e2dd2eb19..3f56a4f71a 100644\n--- a/range-diff.c\n+++ b/range-diff.c\n@@ -418,7 +418,7 @@ static void output_pair_header(struct diff_options *diffopt,\n \n \tif (!dashes->len)\n \t\tstrbuf_addchars(dashes, '-',\n-\t\t\t\tstrlen(repo_find_unique_abbrev(the_repository, oid, abbrev)));\n+\t\t\t\tstrlen(repo_find_unique_abbrev(diffopt->repo, oid, abbrev)));\n \n \tif (!b_util) {\n \t\tcolor = color_old;\n@@ -440,7 +440,7 @@ static void output_pair_header(struct diff_options *diffopt,\n \t\tstrbuf_addf(buf, \"%*s:  %s \", patch_no_width, \"-\", dashes->buf);\n \telse\n \t\tstrbuf_addf(buf, \"%*d:  %s \", patch_no_width, a_util->i + 1,\n-\t\t\t    repo_find_unique_abbrev(the_repository, &a_util->oid, abbrev));\n+\t\t\t    repo_find_unique_abbrev(diffopt->repo, &a_util->oid, abbrev));\n \n \tif (status == '!')\n \t\tstrbuf_addf(buf, \"%s%s\", color_reset, color);\n@@ -452,9 +452,9 @@ static void output_pair_header(struct diff_options *diffopt,\n \t\tstrbuf_addf(buf, \" %*s:  %s\", patch_no_width, \"-\", dashes->buf);\n \telse\n \t\tstrbuf_addf(buf, \" %*d:  %s\", patch_no_width, b_util->i + 1,\n-\t\t\t    repo_find_unique_abbrev(the_repository, &b_util->oid, abbrev));\n+\t\t\t    repo_find_unique_abbrev(diffopt->repo, &b_util->oid, abbrev));\n \n-\tcommit = lookup_commit_reference(the_repository, oid);\n+\tcommit = lookup_commit_reference(diffopt->repo, oid);\n \tif (commit) {\n \t\tif (status == '!')\n \t\t\tstrbuf_addf(buf, \"%s%s\", color_reset, color);\n@@ -474,11 +474,12 @@ static struct userdiff_driver section_headers = {\n \t},\n };\n \n-static struct diff_filespec *get_filespec(const char *name, const char *p)\n+static struct diff_filespec *get_filespec(const struct git_hash_algo *algop,\n+\t\t\t\t\t  const char *name, const char *p)\n {\n \tstruct diff_filespec *spec = alloc_filespec(name);\n \n-\tfill_filespec(spec, null_oid(the_hash_algo), 0, 0100644);\n+\tfill_filespec(spec, null_oid(algop), 0, 0100644);\n \tspec->data = (char *)p;\n \tspec->size = strlen(p);\n \tspec->should_munmap = 0;\n@@ -492,7 +493,8 @@ static void patch_diff(const char *a, const char *b,\n \t\t       struct diff_options *diffopt)\n {\n \tdiff_queue(&diff_queued_diff,\n-\t\t   get_filespec(\"a\", a), get_filespec(\"b\", b));\n+\t\t   get_filespec(diffopt->repo->hash_algo, \"a\", a),\n+\t\t   get_filespec(diffopt->repo->hash_algo, \"b\", b));\n \n \tdiffcore_std(diffopt);\n \tdiff_flush(diffopt);\n\nbase-commit: 8d1b215c01512b9658d4525c54ff9b9245f9a7e8\n-- \n2.56.0\n\n\n"},{"id":"556721","messageId":"DMGX0XEZIMHC.2P0KB28XC83HV@gmail.com","threadId":"66698","inReplyTo":"20261028215137.15262-1-okhuomonajayi54@gmail.com","subject":"Re: [Outreachy PATCH] range-diff: use the repository from the diff options","fromName":"Pablo Sabater","fromEmail":"pabloosabaterr@gmail.com","sentAt":"2026-10-29T01:02:44Z","receivedAt":"2026-10-29T01:02:44Z","isPatch":true,"sender":{"key":"pabloosabaterr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/63864637?v=4"},"body":"On Wed Oct 28, 2026 at 9:51 PM WET, Okhuomon Ajayi wrote:\n\nHi!\n\nI think that the title, \"range-diff: use the repository from the diff\noptions\" can be confusing for someone that doesn't know that diffopt has\na repo field (as it happened to me when reading this).\n\nAlso, when talking about variables in our code, using their names makes\nit easier to know which code is referred to.\n\nDoes this work for you as title?:\n\nrange-diff: use diffopt->repo instead of the_repository\n\n> output_pair_header() and patch_diff() already receive the diff\n> options, but use the_repository and the_hash_algo. Use the\n\nThis first sentence reads a bit strange. But apart from that, I miss a\nreason about why we want this [1].\n\n> repository from diffopt instead, and pass only the hash algorithm\n> to get_filespec(), as that is all it needs.\n\n\"and pass only\" reads as if now get_filespec() only receives the hash\nalgo, but it receives the hash algo on top of what it was already\nreceiving.\n\nAlso, saying that this is related to the_repository replacement because\nthe_hash_algo comes from the_repository would be nice.\n\n>\n> read_patches(), output() and is_range_diff_range() still use\n> the_repository, so USE_THE_REPOSITORY_VARIABLE stays.\n\nNice to know. But I think that it would read better [2] if you used the\nverb at the start, like:\n\nKeep USE_THE_REPOSITORY_VARIABLE because read_patches(), output() and\nis_range_diff_range() still use the_repository.\n\nI recommend reading Documentation/SubmittingPatches for this kind of\nthings. I left at the bottom two links.\n\n>\n> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n> ---\n>  range-diff.c | 16 +++++++++-------\n>  1 file changed, 9 insertions(+), 7 deletions(-)\n>\n> diff --git a/range-diff.c b/range-diff.c\n> index 8e2dd2eb19..3f56a4f71a 100644\n> --- a/range-diff.c\n> +++ b/range-diff.c\n> @@ -418,7 +418,7 @@ static void output_pair_header(struct diff_options *diffopt,\n>  \n>  \tif (!dashes->len)\n>  \t\tstrbuf_addchars(dashes, '-',\n> -\t\t\t\tstrlen(repo_find_unique_abbrev(the_repository, oid, abbrev)));\n> +\t\t\t\tstrlen(repo_find_unique_abbrev(diffopt->repo, oid, abbrev)));\n>  \n>  \tif (!b_util) {\n>  \t\tcolor = color_old;\n> @@ -440,7 +440,7 @@ static void output_pair_header(struct diff_options *diffopt,\n>  \t\tstrbuf_addf(buf, \"%*s:  %s \", patch_no_width, \"-\", dashes->buf);\n>  \telse\n>  \t\tstrbuf_addf(buf, \"%*d:  %s \", patch_no_width, a_util->i + 1,\n> -\t\t\t    repo_find_unique_abbrev(the_repository, &a_util->oid, abbrev));\n> +\t\t\t    repo_find_unique_abbrev(diffopt->repo, &a_util->oid, abbrev));\n>  \n>  \tif (status == '!')\n>  \t\tstrbuf_addf(buf, \"%s%s\", color_reset, color);\n> @@ -452,9 +452,9 @@ static void output_pair_header(struct diff_options *diffopt,\n>  \t\tstrbuf_addf(buf, \" %*s:  %s\", patch_no_width, \"-\", dashes->buf);\n>  \telse\n>  \t\tstrbuf_addf(buf, \" %*d:  %s\", patch_no_width, b_util->i + 1,\n> -\t\t\t    repo_find_unique_abbrev(the_repository, &b_util->oid, abbrev));\n> +\t\t\t    repo_find_unique_abbrev(diffopt->repo, &b_util->oid, abbrev));\n>  \n> -\tcommit = lookup_commit_reference(the_repository, oid);\n> +\tcommit = lookup_commit_reference(diffopt->repo, oid);\n>  \tif (commit) {\n>  \t\tif (status == '!')\n>  \t\t\tstrbuf_addf(buf, \"%s%s\", color_reset, color);\n> @@ -474,11 +474,12 @@ static struct userdiff_driver section_headers = {\n>  \t},\n>  };\n>  \n> -static struct diff_filespec *get_filespec(const char *name, const char *p)\n> +static struct diff_filespec *get_filespec(const struct git_hash_algo *algop,\n> +\t\t\t\t\t  const char *name, const char *p)\n>  {\n>  \tstruct diff_filespec *spec = alloc_filespec(name);\n>  \n> -\tfill_filespec(spec, null_oid(the_hash_algo), 0, 0100644);\n> +\tfill_filespec(spec, null_oid(algop), 0, 0100644);\n>  \tspec->data = (char *)p;\n>  \tspec->size = strlen(p);\n>  \tspec->should_munmap = 0;\n> @@ -492,7 +493,8 @@ static void patch_diff(const char *a, const char *b,\n>  \t\t       struct diff_options *diffopt)\n>  {\n>  \tdiff_queue(&diff_queued_diff,\n> -\t\t   get_filespec(\"a\", a), get_filespec(\"b\", b));\n> +\t\t   get_filespec(diffopt->repo->hash_algo, \"a\", a),\n> +\t\t   get_filespec(diffopt->repo->hash_algo, \"b\", b));\n>  \n>  \tdiffcore_std(diffopt);\n>  \tdiff_flush(diffopt);\n>\n> base-commit: 8d1b215c01512b9658d4525c54ff9b9245f9a7e8\n\nThe code looks good to me.\nPasses make DEVELOPER=1 and git clang-format --diff HEAD~\n\n[1]: https://git-scm.com/docs/SubmittingPatches#meaningful-message\n[2]: https://git-scm.com/docs/SubmittingPatches#imperative-mood\n\nGood job,\nPablo\n\n\n"},{"id":"556743","messageId":"20261029084720.93221-1-okhuomonajayi54@gmail.com","threadId":"66698","inReplyTo":"DMGX0XEZIMHC.2P0KB28XC83HV@gmail.com","subject":"[Outreachy PATCH v2] range-diff: use diffopt->repo instead of the_repository","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-10-29T08:47:20Z","receivedAt":"2026-10-29T08:47:20Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"output_pair_header() and patch_diff() receive a diffopt whose repo\nfield names the repository to work on, yet they abbreviate object\nnames and look up commits in the_repository. get_filespec(), called\nfrom patch_diff(), also uses the_hash_algo, which is the hash\nalgorithm of the_repository. If a caller set up diffopt for another\nrepository, these functions would still read from the global one.\n\nUse diffopt->repo in output_pair_header(), and add a hash algorithm\nparameter to get_filespec() so that patch_diff() can pass\ndiffopt->repo->hash_algo.\n\nKeep USE_THE_REPOSITORY_VARIABLE because read_patches(), output() and\nis_range_diff_range() still use the_repository.\n\nSigned-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n---\nChanges since v1:\n- Reworded the commit message as suggested by Pablo. No code was\n  changed.\n\nThanks, Pablo, for the review.\n\n range-diff.c | 16 +++++++++-------\n 1 file changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/range-diff.c b/range-diff.c\nindex 8e2dd2eb19..3f56a4f71a 100644\n--- a/range-diff.c\n+++ b/range-diff.c\n@@ -418,7 +418,7 @@ static void output_pair_header(struct diff_options *diffopt,\n \n \tif (!dashes->len)\n \t\tstrbuf_addchars(dashes, '-',\n-\t\t\t\tstrlen(repo_find_unique_abbrev(the_repository, oid, abbrev)));\n+\t\t\t\tstrlen(repo_find_unique_abbrev(diffopt->repo, oid, abbrev)));\n \n \tif (!b_util) {\n \t\tcolor = color_old;\n@@ -440,7 +440,7 @@ static void output_pair_header(struct diff_options *diffopt,\n \t\tstrbuf_addf(buf, \"%*s:  %s \", patch_no_width, \"-\", dashes->buf);\n \telse\n \t\tstrbuf_addf(buf, \"%*d:  %s \", patch_no_width, a_util->i + 1,\n-\t\t\t    repo_find_unique_abbrev(the_repository, &a_util->oid, abbrev));\n+\t\t\t    repo_find_unique_abbrev(diffopt->repo, &a_util->oid, abbrev));\n \n \tif (status == '!')\n \t\tstrbuf_addf(buf, \"%s%s\", color_reset, color);\n@@ -452,9 +452,9 @@ static void output_pair_header(struct diff_options *diffopt,\n \t\tstrbuf_addf(buf, \" %*s:  %s\", patch_no_width, \"-\", dashes->buf);\n \telse\n \t\tstrbuf_addf(buf, \" %*d:  %s\", patch_no_width, b_util->i + 1,\n-\t\t\t    repo_find_unique_abbrev(the_repository, &b_util->oid, abbrev));\n+\t\t\t    repo_find_unique_abbrev(diffopt->repo, &b_util->oid, abbrev));\n \n-\tcommit = lookup_commit_reference(the_repository, oid);\n+\tcommit = lookup_commit_reference(diffopt->repo, oid);\n \tif (commit) {\n \t\tif (status == '!')\n \t\t\tstrbuf_addf(buf, \"%s%s\", color_reset, color);\n@@ -474,11 +474,12 @@ static struct userdiff_driver section_headers = {\n \t},\n };\n \n-static struct diff_filespec *get_filespec(const char *name, const char *p)\n+static struct diff_filespec *get_filespec(const struct git_hash_algo *algop,\n+\t\t\t\t\t  const char *name, const char *p)\n {\n \tstruct diff_filespec *spec = alloc_filespec(name);\n \n-\tfill_filespec(spec, null_oid(the_hash_algo), 0, 0100644);\n+\tfill_filespec(spec, null_oid(algop), 0, 0100644);\n \tspec->data = (char *)p;\n \tspec->size = strlen(p);\n \tspec->should_munmap = 0;\n@@ -492,7 +493,8 @@ static void patch_diff(const char *a, const char *b,\n \t\t       struct diff_options *diffopt)\n {\n \tdiff_queue(&diff_queued_diff,\n-\t\t   get_filespec(\"a\", a), get_filespec(\"b\", b));\n+\t\t   get_filespec(diffopt->repo->hash_algo, \"a\", a),\n+\t\t   get_filespec(diffopt->repo->hash_algo, \"b\", b));\n \n \tdiffcore_std(diffopt);\n \tdiff_flush(diffopt);\n\nbase-commit: 8d1b215c01512b9658d4525c54ff9b9245f9a7e8\n-- \n2.56.0\n\n\n"},{"id":"556800","messageId":"xmqqzevw4gze.fsf@gitster.g","threadId":"66698","inReplyTo":"20261029084720.93221-1-okhuomonajayi54@gmail.com","subject":"Re: [Outreachy PATCH v2] range-diff: use diffopt->repo instead of the_repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-29T16:19:17Z","receivedAt":"2026-10-29T16:19:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:\n\n> output_pair_header() and patch_diff() receive a diffopt whose repo\n> field names the repository to work on, yet they abbreviate object\n> names and look up commits in the_repository. get_filespec(), called\n> from patch_diff(), also uses the_hash_algo, which is the hash\n> algorithm of the_repository. If a caller set up diffopt for another\n> repository, these functions would still read from the global one.\n>\n> Use diffopt->repo in output_pair_header(), and add a hash algorithm\n> parameter to get_filespec() so that patch_diff() can pass\n> diffopt->repo->hash_algo.\n>\n> Keep USE_THE_REPOSITORY_VARIABLE because read_patches(), output() and\n> is_range_diff_range() still use the_repository.\n>\n> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n> ---\n> Changes since v1:\n> - Reworded the commit message as suggested by Pablo. No code was\n>   changed.\n>\n> Thanks, Pablo, for the review.\n\nOK, well written.  Except for the \"In-reply-to:\" header that should\npoint at your earlier iteration of the patch (not a review message\nyour earlier iteration received), everything I see here looks good.\n\nWill queue.\n\n"}]}