Re: [PATCH v2 3/4] extent setup_revisions() so it works with submodules

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

 



Heiko Voigt <hvoigt@xxxxxxxxxx> writes:

> Signed-off-by: Heiko Voigt <hvoigt@xxxxxxxxxx>

This needs a bit more explanation.  "Exten_d_ setup_revisions()" is fine,
but "works with submodules"???  How? and what do the caller need to do?

Something like...

    Subject: setup_revisions(): allow walking history in a submodule

    By passing the path to a submodule in opt->submodule, the function can
    be used to walk history in the named submodule repository, instead of
    the toplevel repository.



> ---
>  refs.c     |   31 +++++++++++++++++++++++++++++++
>  refs.h     |    8 ++++++++
>  revision.c |   32 ++++++++++++++++++--------------
>  revision.h |    1 +
>  4 files changed, 58 insertions(+), 14 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index c8649b1..37e2794 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -721,31 +721,62 @@ int head_ref(each_ref_fn fn, void *cb_data)
>  	return do_head_ref(NULL, fn, cb_data);
>  }
>  
> +int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
> +{
> +	return do_head_ref(submodule, fn, cb_data);
> +}
> +
>  int for_each_ref(each_ref_fn fn, void *cb_data)
>  {
>  	return do_for_each_ref(NULL, "refs/", fn, 0, 0, cb_data);
>  }
>  
> +int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
> +{
> +	return do_for_each_ref(submodule, "refs/", fn, 0, 0, cb_data);
> +}
> +
>  int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
>  {
>  	return do_for_each_ref(NULL, prefix, fn, strlen(prefix), 0, cb_data);
>  }
>  
> +int for_each_ref_in_submodule(const char *submodule, const char *prefix,
> +		each_ref_fn fn, void *cb_data)
> +{
> +	return do_for_each_ref(submodule, prefix, fn, strlen(prefix), 0, cb_data);
> +}
> +
>  int for_each_tag_ref(each_ref_fn fn, void *cb_data)
>  {
>  	return for_each_ref_in("refs/tags/", fn, cb_data);
>  }
>  
> +int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
> +{
> +	return for_each_ref_in_submodule(submodule, "refs/tags/", fn, cb_data);
> +}
> +
>  int for_each_branch_ref(each_ref_fn fn, void *cb_data)
>  {
>  	return for_each_ref_in("refs/heads/", fn, cb_data);
>  }
>  
> +int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
> +{
> +	return for_each_ref_in_submodule(submodule, "refs/heads/", fn, cb_data);
> +}
> +
>  int for_each_remote_ref(each_ref_fn fn, void *cb_data)
>  {
>  	return for_each_ref_in("refs/remotes/", fn, cb_data);
>  }
>  
> +int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
> +{
> +	return for_each_ref_in_submodule(submodule, "refs/remotes/", fn, cb_data);
> +}
> +
>  int for_each_replace_ref(each_ref_fn fn, void *cb_data)
>  {
>  	return do_for_each_ref(NULL, "refs/replace/", fn, 13, 0, cb_data);
> diff --git a/refs.h b/refs.h
> index 762ce50..5e7a9a5 100644
> --- a/refs.h
> +++ b/refs.h
> @@ -28,6 +28,14 @@ extern int for_each_replace_ref(each_ref_fn, void *);
>  extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);
>  extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);
>  
> +extern int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
> +extern int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
> +extern int for_each_ref_in_submodule(const char *submodule, const char *prefix,
> +		each_ref_fn fn, void *cb_data);
> +extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
> +extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
> +extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
> +
>  static inline const char *has_glob_specials(const char *pattern)
>  {
>  	return strpbrk(pattern, "?*[");
> diff --git a/revision.c b/revision.c
> index 7e82efd..5f2cf1e 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -820,12 +820,12 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,
>  	cb->all_flags = flags;
>  }
>  
> -static void handle_refs(struct rev_info *revs, unsigned flags,
> -		int (*for_each)(each_ref_fn, void *))
> +static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags,
> +		int (*for_each)(const char *, each_ref_fn, void *))
>  {
>  	struct all_refs_cb cb;
>  	init_all_refs_cb(&cb, revs, flags);
> -	for_each(handle_one_ref, &cb);
> +	for_each(submodule, handle_one_ref, &cb);
>  }
>  
>  static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
> @@ -1417,14 +1417,14 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
>  	ctx->argc -= n;
>  }
>  
> -static int for_each_bad_bisect_ref(each_ref_fn fn, void *cb_data)
> +static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
>  {
> -	return for_each_ref_in("refs/bisect/bad", fn, cb_data);
> +	return for_each_ref_in_submodule(submodule, "refs/bisect/bad", fn, cb_data);
>  }
>  
> -static int for_each_good_bisect_ref(each_ref_fn fn, void *cb_data)
> +static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
>  {
> -	return for_each_ref_in("refs/bisect/good", fn, cb_data);
> +	return for_each_ref_in_submodule(submodule, "refs/bisect/good", fn, cb_data);
>  }
>  
>  static void append_prune_data(const char ***prune_data, const char **av)
> @@ -1466,6 +1466,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
>  {
>  	int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
>  	const char **prune_data = NULL;
> +	const char *submodule = NULL;
> +
> +	if (opt)
> +		submodule = opt->submodule;
>  
>  	/* First, search for "--" */
>  	seen_dashdash = 0;
> @@ -1490,26 +1494,26 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
>  			int opts;
>  
>  			if (!strcmp(arg, "--all")) {
> -				handle_refs(revs, flags, for_each_ref);
> -				handle_refs(revs, flags, head_ref);
> +				handle_refs(submodule, revs, flags, for_each_ref_submodule);
> +				handle_refs(submodule, revs, flags, head_ref_submodule);
>  				continue;
>  			}
>  			if (!strcmp(arg, "--branches")) {
> -				handle_refs(revs, flags, for_each_branch_ref);
> +				handle_refs(submodule, revs, flags, for_each_branch_ref_submodule);
>  				continue;
>  			}
>  			if (!strcmp(arg, "--bisect")) {
> -				handle_refs(revs, flags, for_each_bad_bisect_ref);
> -				handle_refs(revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
> +				handle_refs(submodule, revs, flags, for_each_bad_bisect_ref);
> +				handle_refs(submodule, revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
>  				revs->bisect = 1;
>  				continue;
>  			}
>  			if (!strcmp(arg, "--tags")) {
> -				handle_refs(revs, flags, for_each_tag_ref);
> +				handle_refs(submodule, revs, flags, for_each_tag_ref_submodule);
>  				continue;
>  			}
>  			if (!strcmp(arg, "--remotes")) {
> -				handle_refs(revs, flags, for_each_remote_ref);
> +				handle_refs(submodule, revs, flags, for_each_remote_ref_submodule);
>  				continue;
>  			}
>  			if (!prefixcmp(arg, "--glob=")) {
> diff --git a/revision.h b/revision.h
> index 36fdf22..05659c6 100644
> --- a/revision.h
> +++ b/revision.h
> @@ -151,6 +151,7 @@ extern volatile show_early_output_fn_t show_early_output;
>  struct setup_revision_opt {
>  	const char *def;
>  	void (*tweak)(struct rev_info *, struct setup_revision_opt *);
> +	const char *submodule;
>  };
>  
>  extern void init_revisions(struct rev_info *revs, const char *prefix);
> -- 
> 1.7.2.rc1.217.g7dc0db.dirty
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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