git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] attr: teach "--attr-source=<tree>" global option to "git"

From
Christian Couder <christian.couder@gmail.com>
Date
Apr 28, 2023, 20:22 UTC
Message-ID
<CAP8UFD0mfb1HSUGT3Bz1gHhH3fMpGDnMHVf2pT0CjirL0C5zuA@mail.gmail.com>
In-Reply-To
<pull.1470.v3.git.git.1682707848916.gitgitgadget@gmail.com>
>       +--attr-source=<tree-ish>::
>      -+ Read gitattributes from <tree-ish> instead of the worktree.
>      ++ Read gitattributes from <tree-ish> instead of the worktree. See
>      ++ linkgit:gitrevisions[7].

I think it's more sensible to link to gitattributes(5) instead of gitrevisions(7)

Show 8 quoted lines
> +static const char *default_attr_source_tree_object_name;
> +
> +void set_git_attr_source(const char *tree_object_name)
> +{
> +       default_attr_source_tree_object_name = xstrdup(tree_object_name);
> +}
> +
> +
One empty line is enough here.
Show 17 quoted lines
> +static void compute_default_attr_source(struct object_id *attr_source)
> +{
> +       int from_env = 0;
> +
> +       if (!default_attr_source_tree_object_name) {
> +               default_attr_source_tree_object_name = getenv(GIT_ATTR_SOURCE);
> +               from_env = 1;
> +       }
> +
> +       if (!default_attr_source_tree_object_name || !is_null_oid(attr_source))
> +               return;
> +
> +       if (repo_get_oid_treeish(the_repository, default_attr_source_tree_object_name, attr_source)) {
> +               if (from_env)
> +                       die(_("bad --attr-source object"));
> +               else
> +                       die(_("bad GIT_ATTR_SOURCE"));

I think it would be better to have just the following instead of the 4 lines above:

die(_("invalid tree object from --attr-source flag or GIT_ATTR_SOURCE env variable"));

as a bad GIT_ATTR_SOURCE in a subprocess could come from a bad --attr-source in the main process.

And this way the from_env variable is not needed.
> +       }
> +}
The rest looks good to me, thanks!
Previous: John Cai via GitGitGadgetNext: John Cai
Message 8 of 16 in “attr: teach "--attr-source=<tree>" global option to "git"”
  1. attr: teach "--attr-source=<tree>" global option to "git"John Cai via GitGitGadget, Mar 18, 2023
  2. attr: teach "--attr-source=<tree>" global option to "git"John Cai via GitGitGadget, Mar 27, 2023
  3. Junio C HamanoMar 27, 2023
  4. John CaiMar 27, 2023
  5. Christian CouderApr 27, 2023
  6. Christian CouderApr 27, 2023
  7. attr: teach "--attr-source=<tree>" global option to "git"John Cai via GitGitGadget, Apr 28, 2023
  8. Christian CouderApr 28, 2023
  9. John CaiApr 30, 2023
  10. attr: teach "--attr-source=<tree>" global option to "git"John Cai via GitGitGadget, Apr 30, 2023
  11. Junio C HamanoMay 1, 2023
  12. Christian CouderMay 3, 2023
  13. John CaiMay 3, 2023
  14. attr: teach "--attr-source=<tree>" global option to "git"John Cai via GitGitGadget, May 3, 2023
  15. Christian CouderMay 4, 2023
  16. attr: teach "--attr-source=<tree>" global option to "git"John Cai via GitGitGadget, May 6, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.