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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 7, 2010, 05:28 UTC
Message-ID
<7veiff274b.fsf@alter.siamese.dyndns.org>
In-Reply-To
<ab9c0f88b30060401d99735cb78eec7cc1e95b86.1278444110.git.hvoigt@hvoigt.net>
Heiko Voigt <hvoigt@hvoigt.net> writes:
> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>

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.
Show 191 quoted lines
> ---
>  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
Previous: Heiko VoigtNext: Heiko Voigt
Message 5 of 11 in “implement automatic submodule merge strategy when possible”
  1. 0/4 implement automatic submodule merge strategy when possibleHeiko Voigt, Jul 6, 2010
  2. 1/4 add missing && to submodule-merge testcaseHeiko Voigt, Jul 6, 2010
  3. 2/4 teach ref iteration module about submodulesHeiko Voigt, Jul 6, 2010
  4. 3/4 extent setup_revisions() so it works with submodulesHeiko Voigt, Jul 6, 2010
  5. Junio C HamanoJul 7, 2010
  6. Heiko VoigtJul 7, 2010
  7. 4/4 implement automatic fast forward merge for submodulesHeiko Voigt, Jul 6, 2010
  8. Johan HerlandJul 6, 2010
  9. Heiko VoigtJul 7, 2010
  10. Junio C HamanoJul 8, 2010
  11. Johan HerlandJul 6, 2010

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.