Re: [PATCH 07/20] path: hide functions using `the_repository` by default

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

 



On 24/08/07 08:57AM, Patrick Steinhardt wrote:
> The path subsytem provides a bunch of legacy functions that compute

s/subsytem/subsystem/

> paths relative to the "gitdir" and "commondir" directories of the global
> `the_repository` variable. Use of those functions is discouraged, and it
> is easy to miss the implicit dependency on `the_repository` that calls
> to those functions may cause.
> 
> With `USE_THE_REPOSITORY_VARIABLE`, we have recently introduced a tool
> that allows us to get rid of such functions over time. With this define,

s/define/defined/

> we can hide away functions that have such implicit dependency such that
> other subsystems that want to be free of `the_repository` will not use
> them by accident.
> 
> Move all path-related functions that use `the_repository` into a block
> that gets only conditionally compiled depending on whether or not the
> macro has been defined. This also removes all dependencies on that
> variable in "path.c", allowing us to remove the definition of said
> preprocessor macro.

Nice! So now the "path.c" is `the_repository` free. Implicit use of
`the_repository` is guarded behind `USE_THE_REPOSITORY_VARIABLE`. This
is quite neat. :)

> 
> Signed-off-by: Patrick Steinhardt <ps@xxxxxx>
> ---
>  path.c |  52 +-------------------
>  path.h | 147 ++++++++++++++++++++++++++++++++++++++-------------------
>  2 files changed, 100 insertions(+), 99 deletions(-)
> 
> diff --git a/path.c b/path.c
> index 567eff5253..d073ae6449 100644
> --- a/path.c
> +++ b/path.c
> @@ -2,8 +2,6 @@
>   * Utilities for paths and pathnames
>   */
>  
> -#define USE_THE_REPOSITORY_VARIABLE
> -
>  #include "git-compat-util.h"
>  #include "abspath.h"
>  #include "environment.h"
> @@ -30,7 +28,7 @@ static int get_st_mode_bits(const char *path, int *mode)
>  	return 0;
>  }
>  
> -static struct strbuf *get_pathname(void)
> +struct strbuf *get_pathname(void)

Now that functions with implicit `the_repository` usage are static
inlined we are required to expose `get_pathname()` for the same reason
as some of the other functions in previous commits.

[snip]
> +# ifdef USE_THE_REPOSITORY_VARIABLE
> +#  include "strbuf.h"
> +#  include "repository.h"

Naive question, what is the purpose of providing the include statements
here? Wouldn't they always already be included?

> +
> +/*
> + * Return a statically allocated path into the main repository's
> + * (the_repository) common git directory.
> + */
> +__attribute__((format (printf, 1, 2)))
> +static inline const char *git_common_path(const char *fmt, ...)
> +{
> +	struct strbuf *pathname = get_pathname();
> +	va_list args;
> +	va_start(args, fmt);
> +	strbuf_git_common_pathv(pathname, the_repository, fmt, args);
> +	va_end(args);
> +	return pathname->buf;
> +}
> +
> +/*
> + * Construct a path into the main repository's (the_repository) git directory
> + * and place it in the provided buffer `buf`, the contents of the buffer will
> + * be overridden.
> + */
> +__attribute__((format (printf, 2, 3)))
> +static inline char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
> +{
> +	va_list args;
> +	strbuf_reset(buf);
> +	va_start(args, fmt);
> +	repo_git_pathv(the_repository, NULL, buf, fmt, args);
> +	va_end(args);
> +	return buf->buf;
> +}
> +
> +/*
> + * Construct a path into the main repository's (the_repository) git directory
> + * and append it to the provided buffer `sb`.
> + */
> +__attribute__((format (printf, 2, 3)))
> +static inline void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
> +{
> +	va_list args;
> +	va_start(args, fmt);
> +	repo_git_pathv(the_repository, NULL, sb, fmt, args);
> +	va_end(args);
> +}
> +
> +/*
> + * Return a statically allocated path into the main repository's
> + * (the_repository) git directory.
> + */
> +__attribute__((format (printf, 1, 2)))
> +static inline const char *git_path(const char *fmt, ...)
> +{
> +	struct strbuf *pathname = get_pathname();
> +	va_list args;
> +	va_start(args, fmt);
> +	repo_git_pathv(the_repository, NULL, pathname, fmt, args);
> +	va_end(args);
> +	return pathname->buf;
> +}
> +
> +#define GIT_PATH_FUNC(func, filename) \
> +	const char *func(void) \
> +	{ \
> +		static char *ret; \
> +		if (!ret) \
> +			ret = git_pathdup(filename); \
> +		return ret; \
> +	}
> +
> +/*
> + * Return a path into the main repository's (the_repository) git directory.
> + */
> +__attribute__((format (printf, 1, 2)))
> +static inline char *git_pathdup(const char *fmt, ...)
> +{
> +	struct strbuf path = STRBUF_INIT;
> +	va_list args;
> +	va_start(args, fmt);
> +	repo_git_pathv(the_repository, NULL, &path, fmt, args);
> +	va_end(args);
> +	return strbuf_detach(&path, NULL);
> +}
> +
> +# endif /* USE_THE_REPOSITORY_VARIABLE */

I like how it's all consolidated into this one block. Very nice! :)




[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]

  Powered by Linux