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

Re: [PATCH 2/3] Teach read_tree_recursive() how to traverse into submodules

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Jan 18, 2009, 16:13 UTC
Message-ID
<49735530.4090901@lsrfire.ath.cx>
In-Reply-To
<1232275999-14852-3-git-send-email-hjemli@gmail.com>
Lars Hjemli schrieb:
Show 7 quoted lines
> The traversal of submodules is only triggered if the current submodule
> HEAD commit object is accessible. To this end, read_tree_recursive()
> will try to insert the submodule odb as an alternate odb but the lack
> of such an odb is not treated as an error since it is then assumed that
> the user is not interested in the submodule content. However, if the
> submodule odb is found it is treated as an error if the HEAD commit
> object is missing.

Callers of read_tree_recursive() specify a tree to traverse. Unconditionally using the HEAD of submodules feels a bit restrictive, but I don't use submodules, so I have no idea what I'm actually talking about here. :)

Show 34 quoted lines
>  int read_tree_recursive(struct tree *tree,
>  			const char *base, int baselen,
>  			int stage, const char **match,
> @@ -132,6 +188,30 @@ int read_tree_recursive(struct tree *tree,
>  				return -1;
>  			continue;
>  		}
> +		if (S_ISGITLINK(entry.mode) && get_traverse_gitlinks()) {
> +			int retval;
> +			char *newbase;
> +			struct tree *subtree;
> +			unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
> +
> +			newbase = xmalloc(baselen + 1 + pathlen);
> +			memcpy(newbase, base, baselen);
> +			memcpy(newbase + baselen, entry.path, pathlen);
> +			newbase[baselen + pathlen] = 0;
> +			if (!traverse_gitlink(newbase, entry.sha1, &subtree)) {
> +				free(newbase);
> +				continue;
> +			}
> +			newbase[baselen + pathlen] = '/';
> +			retval = read_tree_recursive(subtree,
> +						     newbase,
> +						     baselen + pathlen + 1,
> +						     stage, match, fn, context);
> +			free(newbase);
> +			if (retval)
> +				return -1;
> +			continue;
> +		}
>  	}
>  	return 0;
>  }

You don't need to call get_traverse_gitlinks() in the if statement above if you make all read_tree_recursive() callback functions return 0 for gitlinks that they don't want to follow and READ_TREE_RECURSIVE for those they do. It's cleaner without the static variable and its accessors and more flexible, too: the callbacks might decide to traverse only certain submodules.

René
Previous: Junio C HamanoNext: Lars Hjemli
Message 21 of 26 in “Implement 'git archive --submodules'”
  1. 0/3 Implement 'git archive --submodules'Lars Hjemli, Jan 18, 2009
  2. 1/3 sha1_file: add function to insert alternate object dbLars Hjemli, Jan 18, 2009
  3. 2/3 Teach read_tree_recursive() how to traverse into submodulesLars Hjemli, Jan 18, 2009
  4. 3/3 git-archive: add support for --submodulesLars Hjemli, Jan 18, 2009
  5. Johannes SchindelinJan 18, 2009
  6. Johannes SchindelinJan 18, 2009
  7. Lars HjemliJan 18, 2009
  8. Johannes SchindelinJan 18, 2009
  9. Lars HjemliJan 18, 2009
  10. Johannes SchindelinJan 18, 2009
  11. Lars HjemliJan 18, 2009
  12. Johannes SchindelinJan 18, 2009
  13. Lars HjemliJan 18, 2009
  14. Johannes SchindelinJan 19, 2009
  15. 1/1 bug fix, diff whitespace ignore optionsKeith Cascio, Jan 19, 2009
  16. Johannes SchindelinJan 19, 2009
  17. 1/1 bug fix, diff whitespace ignore optionsKeith Cascio, Jan 19, 2009
  18. Johannes SchindelinJan 19, 2009
  19. Junio C HamanoJan 20, 2009
  20. Junio C HamanoJan 19, 2009
  21. René ScharfeJan 18, 2009
  22. Lars HjemliJan 18, 2009
  23. Junio C HamanoJan 18, 2009
  24. Lars HjemliJan 18, 2009
  25. Johannes SchindelinJan 18, 2009
  26. sha1_file: add function to insert alternate object dbLars Hjemli, Jan 18, 2009

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.