Re: [RFC PATCH] rev-parse: add --show-superproject-working-tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stefan Beller <sbeller@xxxxxxxxxx> writes:

> +const char *get_superproject_working_tree()

const char *get_superproject_working_tree(void)

The same for the *.h file declaration.

> +{
> +	struct child_process cp = CHILD_PROCESS_INIT;
> +	struct strbuf sb = STRBUF_INIT;
> +
> +	if (!superproject_exists())
> +		return NULL;
> + ...
> +	return strbuf_detach(&sb, NULL);

Having reviewed it, I somehow think you do not want to have a
separate superproject_exists() that grabs some part of the
information this caller needs and then discards it.

The helper already does these things:

    - xgetcwd(), which may give you "/local/repo/super/sub/dir"

    - relative_path() with the result and "..", which may give you
      "dir"

    - ls-tree HEAD "dir" to see what is in "sub/dir" of the
      repository that governs ".."; if "sub/dir" is a gitlink,
      you know you started in a working tree of a repository
      different from the one that governs "..".

And the caller is trying to figure out where the root of the
superproject is, i.e. "/local/repo/super", and the helper has half
of the answer to that already.  If you ask the "ls-tree HEAD" (as I
said, I think it should be "ls-files") to give you not "dir" but
"sub/dir", you can subtract it from the result of xgetcwd() you did
at the beginning of the helper, and that gives what this caller of
the helper wants.

So perhaps your superproject_exists() helper can be eliminated and
instead coded in get_superproject_working_tree() in place to do:

	- xgetcwd() to get "/local/repo/super/sub/dir".

	- relative_path() to get "dir".

	- ask "ls-{tree,files} --full-name HEAD dir" to get "160000"
          and "sub/dir".

	- subtract "sub/dir" from the tail of the "/local/repo/super/sub/dir"
	  you got from xgetcwd() earlier.

	- return the result.

with a failure/unmet expectations (like not finding 160000) from any
step returning an error, or something like that.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]