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

Re: [PATCH] ls-remote: add "--diff" option to show only refs that differ

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 2, 2017, 20:03 UTC
Message-ID
<xmqqshnws6ma.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<alpine.LFD.2.20.1702021143470.21619@i7.lan>
Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 10 quoted lines
> My main use of "git ls-remote" tends to be to check what the other end
> has when some pull request goes wrong (they forgot to push, or they used
> the wrong ref name or whatever), and it ends up being hard to see all
> the relevant data from the noise of people just having the same basic
> tags etc from upstream.
>
> So this adds a "--diff" option that shows only the refs that are
> different from the local repository.  So when somebody asks me to pull,
> I can now just trivially look at what they have that isn't already my
> basic branches and tags.

Most downstream folks seem to care about refs/remotes/origin/$branch and I think in that context "git ls-remote --diff [origin]" that compares their refs/heads/* and refs/remotes/origin/* would make sense. Your has_ref_locally() seems to return true by comparing their value with the value of the local ref without any the fetch refspec mapping.

When one contributor asks you to pull refs/heads/master you want to go and see if it is different from refs/heads/master you have?

Show 21 quoted lines
> Comments?
>
> +static int has_ref_locally(const struct ref *ref)
> +{
> +	unsigned char sha1[20];
> +
> +	if (!resolve_ref_unsafe(ref->name, RESOLVE_REF_READING, sha1, NULL))
> +		return 0;
> +
> +	return !hashcmp(ref->old_oid.hash, sha1);
> +}
> +
> @@ -105,6 +121,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
>  			continue;
>  		if (!tail_match(pattern, ref->name))
>  			continue;
> +		if (diff && has_ref_locally(ref))
> +			continue;
>  		if (show_symref_target && ref->symref)
>  			printf("ref: %s\t%s\n", ref->symref, ref->name);
>  		printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
Previous: Linus TorvaldsNext: Linus Torvalds
Message 2 of 5 in “ls-remote: add "--diff" option to show only refs that differ”
  1. ls-remote: add "--diff" option to show only refs that differLinus Torvalds, Feb 2, 2017
  2. Junio C HamanoFeb 2, 2017
  3. Linus TorvaldsFeb 2, 2017
  4. Junio C HamanoFeb 2, 2017
  5. Linus TorvaldsFeb 2, 2017

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.