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

Re: [PATCH v3 2/5] Teach mv to move submodules using a gitfile

From
Fredrik Gustafsson <iveqy@iveqy.com>
Date
Jul 31, 2013, 09:43 UTC
Message-ID
<20130731094314.GD19369@paksenarrion.iveqy.com>
In-Reply-To
<51F818EB.8010101@web.de>
On Tue, Jul 30, 2013 at 09:50:03PM +0200, Jens Lehmann wrote:
Show 30 quoted lines
> +/* Update gitfile and core.worktree setting to connect work tree and git dir */
> +void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
> +{
> +	struct strbuf file_name = STRBUF_INIT;
> +	struct strbuf rel_path = STRBUF_INIT;
> +	const char *real_work_tree = xstrdup(real_path(work_tree));
> +	FILE *fp;
> +
> +	/* Update gitfile */
> +	strbuf_addf(&file_name, "%s/.git", work_tree);
> +	fp = fopen(file_name.buf, "w");
> +	if (!fp)
> +		die(_("Could not create git link %s"), file_name.buf);
> +	fprintf(fp, "gitdir: %s\n", relative_path(git_dir, real_work_tree,
> +						  &rel_path));
> +	fclose(fp);
> +
> +	/* Update core.worktree setting */
> +	strbuf_reset(&file_name);
> +	strbuf_addf(&file_name, "%s/config", git_dir);
> +	if (git_config_set_in_file(file_name.buf, "core.worktree",
> +				   relative_path(real_work_tree, git_dir,
> +						 &rel_path)))
> +		die(_("Could not set core.worktree in %s"),
> +		    file_name.buf);
> +
> +	strbuf_release(&file_name);
> +	strbuf_release(&rel_path);
> +	free((void *)real_work_tree);
> +}

Would it make sense to return an int here and do the dying in builtin/mv.c instead? Again thinking of "libgit" and the die_errno for non-submodule errors are in mv.c and not in rename().

If that's the case the same applies for stage_updated_gitmodules() and update_path_in_gitmodules().

update_path_in_gitmodules() also needs a strbuf_release() if you haven't already found it.

-- 
Med vänliga hälsningar
Fredrik Gustafsson

tel: 0733-608274
e-post: iveqy@iveqy.com
Previous: Jens LehmannNext: Jens Lehmann
Message 4 of 18 in “Teach mv to move submodules”
  1. 0/5 Teach mv to move submodulesJens Lehmann, Jul 30, 2013
  2. 1/5 Teach mv to move submodules together with their work treesJens Lehmann, Jul 30, 2013
  3. 2/5 Teach mv to move submodules using a gitfileJens Lehmann, Jul 30, 2013
  4. Fredrik GustafssonJul 31, 2013
  5. 3/5 submodule.c: add .gitmodules staging helper functionsJens Lehmann, Jul 30, 2013
  6. Junio C HamanoJul 30, 2013
  7. Jens LehmannJul 30, 2013
  8. 4/5 Teach mv to update the path entry in .gitmodules for moved submodulesJens Lehmann, Jul 30, 2013
  9. Jens LehmannAug 6, 2013
  10. 5/5 rm: delete .gitmodules entry of submodules removed from the work treeJens Lehmann, Jul 30, 2013
  11. Fredrik GustafssonJul 30, 2013
  12. Jens LehmannJul 30, 2013
  13. Jens LehmannAug 6, 2013
  14. Junio C HamanoAug 6, 2013
  15. Jens LehmannAug 7, 2013
  16. Fredrik GustafssonAug 7, 2013
  17. Jens LehmannAug 8, 2013
  18. Fredrik GustafssonAug 8, 2013

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.