Skip to contentSkip to conversation

check_everything_connected: assume alternate ref tips are valid

PATCH Superseded Jeff King 5 participants 20 messages Jun 28, 2019 – Jul 3, 2019 Documentation

lore
Share & tools
lore

Jeff King

author
#0 lore raw

PATCH 1/1 check_everything_connected: assume alternate ref tips are valid

When we receive a remote ref update to sha1 "X", we want to check that we have all of the objects needed by "X". We can assume that our repository is not currently corrupted, and therefore if we have a ref pointing at "Y", we have all of its objects. So we can stop our traversal from "X" as soon as we hit "Y".

If we make the same non-corruption assumption about any repositories we use to store alternates, then we can also use their ref tips to shorten the traversal.

This is especially useful when cloning with "--reference", as we otherwise do not have any local refs to check against, and have to traverse the whole history, even though the other side may have sent us few or no objects. Here are results for the included perf test (which shows off more or less the maximal savings, getting one new commit and sharing the whole history):

Test HEAD^ HEAD
--------------------------------------------------------------------
[on git.git]
5600.3: clone --reference 2.94(2.86+0.08) 0.09(0.08+0.01) -96.9%
[on linux.git]
5600.3: clone --reference 45.74(45.34+0.41) 0.36(0.30+0.08) -99.2%

---
 Documentation/rev-list-options.txt |  8 ++++
 connected.c                        |  1 +
 revision.c                         | 30 +++++++++++++++
 t/perf/p5600-clone-reference.sh    | 27 ++++++++++++++
 t/t5618-alternate-refs.sh          | 60 ++++++++++++++++++++++++++++++
 5 files changed, 126 insertions(+)
 create mode 100755 t/perf/p5600-clone-reference.sh
 create mode 100755 t/t5618-alternate-refs.sh
Documentation/rev-list-options.txt +8 -0
index 71a1fcc093..90a2c027ea 100644
@@ -182,6 +182,14 @@ explicitly.
 	Pretend as if all objects mentioned by reflogs are listed on the
 	command line as `<commit>`.
 
+--alternate-refs::
+	Pretend as if all objects mentioned as ref tips of alternate
+	repositories were listed on the command line. An alternate
+	repository is any repository whose object directory is specified
+	in `objects/info/alternates`.  The set of included objects may
+	be modified by `core.alternateRefsCommand`, etc. See
+	linkgit:git-config[1].
+
 --single-worktree::
 	By default, all working trees will be examined by the
 	following options when there are more than one (see
connected.c +1 -0
index 1ab481fed6..cd9b324afa 100644
@@ -80,6 +80,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
 		argv_array_push(&rev_list.args, "--all");
 	}
 	argv_array_push(&rev_list.args, "--quiet");
+	argv_array_push(&rev_list.args, "--alternate-refs");
 	if (opt->progress)
 		argv_array_pushf(&rev_list.args, "--progress=%s",
 				 _("Checking connectivity"));
revision.c +30 -0
index 621feb9df7..b9be08e9df 100644
@@ -28,6 +28,7 @@
 #include "commit-graph.h"
 #include "prio-queue.h"
 #include "hashmap.h"
+#include "transport.h"
 
 volatile show_early_output_fn_t show_early_output;
 
@@ -1554,6 +1555,32 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
 	free_worktrees(worktrees);
 }
 
+struct add_alternate_refs_data {
+	struct rev_info *revs;
+	unsigned int flags;
+};
+
+static void add_one_alternate_ref(const struct object_id *oid,
+				  void *vdata)
+{
+	const char *name = ".alternate";
+	struct add_alternate_refs_data *data = vdata;
+	struct object *obj;
+
+	obj = get_reference(data->revs, name, oid, data->flags);
+	add_rev_cmdline(data->revs, obj, name, REV_CMD_REV, data->flags);
+	add_pending_object(data->revs, obj, name);
+}
+
+static void add_alternate_refs_to_pending(struct rev_info *revs,
+					  unsigned int flags)
+{
+	struct add_alternate_refs_data data;
+	data.revs = revs;
+	data.flags = flags;
+	for_each_alternate_ref(add_one_alternate_ref, &data);
+}
+
 static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
 			    int exclude_parent)
 {
@@ -1956,6 +1983,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	    !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
 	    !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") ||
 	    !strcmp(arg, "--indexed-objects") ||
+	    !strcmp(arg, "--alternate-refs") ||
 	    starts_with(arg, "--exclude=") ||
 	    starts_with(arg, "--branches=") || starts_with(arg, "--tags=") ||
 	    starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk="))
@@ -2442,6 +2470,8 @@ static int handle_revision_pseudo_opt(const char *submodule,
 		add_reflogs_to_pending(revs, *flags);
 	} else if (!strcmp(arg, "--indexed-objects")) {
 		add_index_objects_to_pending(revs, *flags);
+	} else if (!strcmp(arg, "--alternate-refs")) {
+		add_alternate_refs_to_pending(revs, *flags);
 	} else if (!strcmp(arg, "--not")) {
 		*flags ^= UNINTERESTING | BOTTOM;
 	} else if (!strcmp(arg, "--no-walk")) {
t/perf/p5600-clone-reference.sh new file +27 -0
new file mode 100755
index 0000000000..68fed66347
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+test_description='speed of clone --reference'
+. ./perf-lib.sh
+
+test_perf_default_repo
+
+test_expect_success 'create shareable repository' '
+	git clone --bare . shared.git
+'
+
+test_expect_success 'advance base repository' '
+	# Do not use test_commit here; its test_tick will
+	# use some ancient hard-coded date. The resulting clock
+	# skew will cause pack-objects to traverse in a very
+	# sub-optimal order, skewing the results.
+	echo content >new-file-that-does-not-exist &&
+	git add new-file-that-does-not-exist &&
+	git commit -m "new commit"
+'
+
+test_perf 'clone --reference' '
+	rm -rf dst.git &&
+	git clone --no-local --bare --reference shared.git . dst.git
+'
+
+test_done
t/t5618-alternate-refs.sh new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.22.0.775.g4ba9815492
author
#1 lore raw
Quoted 1 line · Jeff King

Subject: [PATCH] check_everything_connected: assume alternate ref tips...

Heh. This subject should just be "check_connected" these days. I wrote this patch originally many years ago, before 7043c7071c (check_everything_connected: use a struct with named options, 2016-07-15) gave the function a shorter name.

But the patch has been updated recently to match other updates to the alternates code. In particular, in the original "rev-list --alternate-refs" behaved as if all of the refs from the alternate were mentioned on the command line, and you could use --exclude, etc as if they were real refs. But we've since simplified the alternates interface to just get a list of oids, so now it behaves more like "--indexed-objects" in that it acts as if those oids were mentioned on the command line.

I think "--alternate-refs" is still the right name, though, since we're just giving the oids at the ref tips. And I think the included documentation makes this clear.

-Peff

#2 lore raw
In reply to Jeff King
Quoted 9 lines · Jeff King

When we receive a remote ref update to sha1 "X", we want to check that we have all of the objects needed by "X". We can assume that our repository is not currently corrupted, and therefore if we have a ref pointing at "Y", we have all of its objects. So we can stop our traversal from "X" as soon as we hit "Y".

If we make the same non-corruption assumption about any repositories we use to store alternates, then we can also use their ref tips to shorten the traversal.

I was confused by this paragraph, because I didn't know about for_each_alternate_ref() and how refs_From_alternate_cb() will strip the "/objects" and append "/refs" to check refs if they exist. All of that logic is in transport.c but used by fetch-pack.c and builtin/receive-pack.c. But now we are adding to revision.c, so the restriction to "this helps data transfer" is getting murkier.

Is this something that should be extracted to the object-store layer? Or is it so tricky to use that we shouldn't make it too easy to fall into a bad pattern?

Quoted 7 lines

This is especially useful when cloning with "--reference", as we otherwise do not have any local refs to check against, and have to traverse the whole history, even though the other side may have sent us few or no objects. Here are results for the included perf test (which shows off more or less the maximal savings, getting one new commit and sharing the whole history):

Quoted 6 lines

Test HEAD^ HEAD
--------------------------------------------------------------------
[on git.git]
5600.3: clone --reference 2.94(2.86+0.08) 0.09(0.08+0.01) -96.9%
[on linux.git]
5600.3: clone --reference 45.74(45.34+0.41) 0.36(0.30+0.08) -99.2%

It's really hard to argue with numbers like these. Kudos!

Quoted 8 lines
---
 Documentation/rev-list-options.txt |  8 ++++
 connected.c                        |  1 +
 revision.c                         | 30 +++++++++++++++
 t/perf/p5600-clone-reference.sh    | 27 ++++++++++++++
 t/t5618-alternate-refs.sh          | 60 ++++++++++++++++++++++++++++++

Other than the high-level questions above, the code and tests look good to me.

Thanks,
-Stolee

author
#3 lore raw
Quoted 11 lines · Derrick Stolee
Quoted 9 lines · Jeff King

When we receive a remote ref update to sha1 "X", we want to check that we have all of the objects needed by "X". We can assume that our repository is not currently corrupted, and therefore if we have a ref pointing at "Y", we have all of its objects. So we can stop our traversal from "X" as soon as we hit "Y".

If we make the same non-corruption assumption about any repositories we use to store alternates, then we can also use their ref tips to shorten the traversal.

Quoted 7 lines

I was confused by this paragraph, because I didn't know about for_each_alternate_ref() and how refs_From_alternate_cb() will strip the "/objects" and append "/refs" to check refs if they exist. All of that logic is in transport.c but used by fetch-pack.c and builtin/receive-pack.c. But now we are adding to revision.c, so the restriction to "this helps data transfer" is getting murkier.

Using it for data transfer is still the main thing for our internal calls, but I think it's worth exposing it for general use via rev-list. I imagine it would mostly be for poking around and debugging, but it should allow things like:

  # what do we have that our alternate does not
  git rev-list --all --not --alternate-refs
Quoted 3 lines

Is this something that should be extracted to the object-store layer? Or is it so tricky to use that we shouldn't make it too easy to fall into a bad pattern?

I'm not sure what you have in mind, exactly. If you are asking whether there are more places that alternate refs could be used, I can't think of any. If you are asking whether this is in the wrong place, no, I think it's the right place. :)

-Peff

#4 lore raw
Quoted 21 lines · Jeff King
Quoted 11 lines · Derrick Stolee
Quoted 9 lines · Jeff King

When we receive a remote ref update to sha1 "X", we want to check that we have all of the objects needed by "X". We can assume that our repository is not currently corrupted, and therefore if we have a ref pointing at "Y", we have all of its objects. So we can stop our traversal from "X" as soon as we hit "Y".

If we make the same non-corruption assumption about any repositories we use to store alternates, then we can also use their ref tips to shorten the traversal.

Quoted 7 lines

I was confused by this paragraph, because I didn't know about for_each_alternate_ref() and how refs_From_alternate_cb() will strip the "/objects" and append "/refs" to check refs if they exist. All of that logic is in transport.c but used by fetch-pack.c and builtin/receive-pack.c. But now we are adding to revision.c, so the restriction to "this helps data transfer" is getting murkier.

Quoted 7 lines

Using it for data transfer is still the main thing for our internal calls, but I think it's worth exposing it for general use via rev-list. I imagine it would mostly be for poking around and debugging, but it should allow things like:

  # what do we have that our alternate does not
  git rev-list --all --not --alternate-refs

So this is an example where the alternate refs are being used without any network activity.

Quoted 8 lines
Quoted 3 lines

Is this something that should be extracted to the object-store layer? Or is it so tricky to use that we shouldn't make it too easy to fall into a bad pattern?

I'm not sure what you have in mind, exactly. If you are asking whether there are more places that alternate refs could be used, I can't think of any. If you are asking whether this is in the wrong place, no, I think it's the right place. :)

Just double-checking that it is appropriate for revision.c to take dependence on transport.h instead of moving the alternate ref stuff into a different header file. I trust your opinion.

-Stolee

author
#5 lore raw
Quoted 8 lines · Derrick Stolee
Quoted 4 lines

I'm not sure what you have in mind, exactly. If you are asking whether there are more places that alternate refs could be used, I can't think of any. If you are asking whether this is in the wrong place, no, I think it's the right place. :)

Just double-checking that it is appropriate for revision.c to take dependence on transport.h instead of moving the alternate ref stuff into a different header file. I trust your opinion.

Ah, I see. I misunderstood you before.

Yes, this is weakening the ties of the feature to the transport code. Traditionally transport-oriented code was the only user, but it also used the upload-pack transport under the hood to access the alternate (that was changed a while ago to for-each-ref for speed).

I don't think there's any functional difference in having it there, but it could be moved to live alongside foreach_alt_odb() in sha1-file.c.

-Peff

author
#6 lore raw
Quoted 7 lines · Jeff King

Yes, this is weakening the ties of the feature to the transport code. Traditionally transport-oriented code was the only user, but it also used the upload-pack transport under the hood to access the alternate (that was changed a while ago to for-each-ref for speed).

I don't think there's any functional difference in having it there, but it could be moved to live alongside foreach_alt_odb() in sha1-file.c.

Looks like this hasn't quite hit 'next' yet, so perhaps we can reorganize it as a preparatory patch.

[1/2]: object-store.h: move for_each_alternate_ref() from transport.h [2/2]: check_everything_connected: assume alternate ref tips are valid

 Documentation/rev-list-options.txt |  8 +++
 builtin/receive-pack.c             |  1 -
 connected.c                        |  1 +
 object-store.h                     |  2 +
 revision.c                         | 29 +++++++++
 sha1-file.c                        | 97 ++++++++++++++++++++++++++++++
 t/perf/p5600-clone-reference.sh    | 27 +++++++++
 t/t5618-alternate-refs.sh          | 60 ++++++++++++++++++
 transport.c                        | 97 ------------------------------
 transport.h                        |  2 -
 10 files changed, 224 insertions(+), 100 deletions(-)
 create mode 100755 t/perf/p5600-clone-reference.sh
 create mode 100755 t/t5618-alternate-refs.sh

-Peff

author
#7 lore raw

PATCH 1/2 object-store.h: move for_each_alternate_ref() from transport.h

There's nothing inherently transport-related about enumerating the alternate ref tips. The code has lived in transport.[ch] because the only use so far had been advertising available tips during transport. But it could be used for more, and a future patch will teach rev-list to access these refs.

Let's move it alongside the other alt-odb code, declaring it in object-store.h with the implementation in sha1-file.c.

This lets us drop the inclusion of transport.h from receive-pack, which perhaps shows how it was misplaced (though receive-pack is about transporting objects, transport.h is mostly about the client side).

---
 builtin/receive-pack.c |  1 -
 object-store.h         |  2 +
 sha1-file.c            | 97 ++++++++++++++++++++++++++++++++++++++++++
 transport.c            | 97 ------------------------------------------
 transport.h            |  2 -
 5 files changed, 99 insertions(+), 100 deletions(-)
builtin/receive-pack.c +0 -1
index 77b7122456..557e686d5d 100644
@@ -12,7 +12,6 @@
 #include "object.h"
 #include "remote.h"
 #include "connect.h"
-#include "transport.h"
 #include "string-list.h"
 #include "sha1-array.h"
 #include "connected.h"
object-store.h +2 -0
index 49f56ab8d9..7f7b3cdd80 100644
@@ -33,6 +33,8 @@ void prepare_alt_odb(struct repository *r);
 char *compute_alternate_path(const char *path, struct strbuf *err);
 typedef int alt_odb_fn(struct object_directory *, void *);
 int foreach_alt_odb(alt_odb_fn, void*);
+typedef void alternate_ref_fn(const struct object_id *oid, void *);
+void for_each_alternate_ref(alternate_ref_fn, void *);
 
 /*
  * Add the directory to the on-disk alternates file; the new entry will also
sha1-file.c +97 -0

103 lines not on this page · raw message

transport.c +0 -97

100 lines not on this page · raw message

transport.h +0 -2
index 06e06d3d89..0b5f7806f6 100644
@@ -262,6 +262,4 @@ int transport_refs_pushed(struct ref *ref);
 void transport_print_push_status(const char *dest, struct ref *refs,
 		  int verbose, int porcelain, unsigned int *reject_reasons);
 
-typedef void alternate_ref_fn(const struct object_id *oid, void *);
-void for_each_alternate_ref(alternate_ref_fn, void *);
 #endif
Signature · 1 line
2.22.0.776.g16867c022c
#8 lore raw

Re: [PATCH 1/2] object-store.h: move for_each_alternate_ref() from transport.h

Quoted 8 lines · Jeff King

There's nothing inherently transport-related about enumerating the alternate ref tips. The code has lived in transport.[ch] because the only use so far had been advertising available tips during transport. But it could be used for more, and a future patch will teach rev-list to access these refs.

Let's move it alongside the other alt-odb code, declaring it in object-store.h with the implementation in sha1-file.c.

Thanks!

Quoted 3 lines

This lets us drop the inclusion of transport.h from receive-pack, which perhaps shows how it was misplaced (though receive-pack is about transporting objects, transport.h is mostly about the client side).

That's an interesting de-coupling. Thanks for looking into reorganizing the code. This series looks good to me.

-Stolee

author
#9 lore raw

PATCH v2 2/2 check_everything_connected: assume alternate ref tips are valid

In reply to Jeff King

When we receive a remote ref update to sha1 "X", we want to check that we have all of the objects needed by "X". We can assume that our repository is not currently corrupted, and therefore if we have a ref pointing at "Y", we have all of its objects. So we can stop our traversal from "X" as soon as we hit "Y".

If we make the same non-corruption assumption about any repositories we use to store alternates, then we can also use their ref tips to shorten the traversal.

This is especially useful when cloning with "--reference", as we otherwise do not have any local refs to check against, and have to traverse the whole history, even though the other side may have sent us few or no objects. Here are results for the included perf test (which shows off more or less the maximal savings, getting one new commit and sharing the whole history):

Test HEAD^ HEAD
--------------------------------------------------------------------
[on git.git]
5600.3: clone --reference 2.94(2.86+0.08) 0.09(0.08+0.01) -96.9%
[on linux.git]
5600.3: clone --reference 45.74(45.34+0.41) 0.36(0.30+0.08) -99.2%

---
Identical to v1 except for dropping the transport.h include in revision.c.

 Documentation/rev-list-options.txt |  8 ++++
 connected.c                        |  1 +
 revision.c                         | 29 +++++++++++++++
 t/perf/p5600-clone-reference.sh    | 27 ++++++++++++++
 t/t5618-alternate-refs.sh          | 60 ++++++++++++++++++++++++++++++
 5 files changed, 125 insertions(+)
 create mode 100755 t/perf/p5600-clone-reference.sh
 create mode 100755 t/t5618-alternate-refs.sh
Documentation/rev-list-options.txt +8 -0
index 71a1fcc093..90a2c027ea 100644
@@ -182,6 +182,14 @@ explicitly.
 	Pretend as if all objects mentioned by reflogs are listed on the
 	command line as `<commit>`.
 
+--alternate-refs::
+	Pretend as if all objects mentioned as ref tips of alternate
+	repositories were listed on the command line. An alternate
+	repository is any repository whose object directory is specified
+	in `objects/info/alternates`.  The set of included objects may
+	be modified by `core.alternateRefsCommand`, etc. See
+	linkgit:git-config[1].
+
 --single-worktree::
 	By default, all working trees will be examined by the
 	following options when there are more than one (see
connected.c +1 -0
index 1ab481fed6..cd9b324afa 100644
@@ -80,6 +80,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
 		argv_array_push(&rev_list.args, "--all");
 	}
 	argv_array_push(&rev_list.args, "--quiet");
+	argv_array_push(&rev_list.args, "--alternate-refs");
 	if (opt->progress)
 		argv_array_pushf(&rev_list.args, "--progress=%s",
 				 _("Checking connectivity"));
revision.c +29 -0
index 621feb9df7..07412297f0 100644
@@ -1554,6 +1554,32 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
 	free_worktrees(worktrees);
 }
 
+struct add_alternate_refs_data {
+	struct rev_info *revs;
+	unsigned int flags;
+};
+
+static void add_one_alternate_ref(const struct object_id *oid,
+				  void *vdata)
+{
+	const char *name = ".alternate";
+	struct add_alternate_refs_data *data = vdata;
+	struct object *obj;
+
+	obj = get_reference(data->revs, name, oid, data->flags);
+	add_rev_cmdline(data->revs, obj, name, REV_CMD_REV, data->flags);
+	add_pending_object(data->revs, obj, name);
+}
+
+static void add_alternate_refs_to_pending(struct rev_info *revs,
+					  unsigned int flags)
+{
+	struct add_alternate_refs_data data;
+	data.revs = revs;
+	data.flags = flags;
+	for_each_alternate_ref(add_one_alternate_ref, &data);
+}
+
 static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
 			    int exclude_parent)
 {
@@ -1956,6 +1982,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	    !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
 	    !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") ||
 	    !strcmp(arg, "--indexed-objects") ||
+	    !strcmp(arg, "--alternate-refs") ||
 	    starts_with(arg, "--exclude=") ||
 	    starts_with(arg, "--branches=") || starts_with(arg, "--tags=") ||
 	    starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk="))
@@ -2442,6 +2469,8 @@ static int handle_revision_pseudo_opt(const char *submodule,
 		add_reflogs_to_pending(revs, *flags);
 	} else if (!strcmp(arg, "--indexed-objects")) {
 		add_index_objects_to_pending(revs, *flags);
+	} else if (!strcmp(arg, "--alternate-refs")) {
+		add_alternate_refs_to_pending(revs, *flags);
 	} else if (!strcmp(arg, "--not")) {
 		*flags ^= UNINTERESTING | BOTTOM;
 	} else if (!strcmp(arg, "--no-walk")) {
t/perf/p5600-clone-reference.sh new file +27 -0
new file mode 100755
index 0000000000..68fed66347
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+test_description='speed of clone --reference'
+. ./perf-lib.sh
+
+test_perf_default_repo
+
+test_expect_success 'create shareable repository' '
+	git clone --bare . shared.git
+'
+
+test_expect_success 'advance base repository' '
+	# Do not use test_commit here; its test_tick will
+	# use some ancient hard-coded date. The resulting clock
+	# skew will cause pack-objects to traverse in a very
+	# sub-optimal order, skewing the results.
+	echo content >new-file-that-does-not-exist &&
+	git add new-file-that-does-not-exist &&
+	git commit -m "new commit"
+'
+
+test_perf 'clone --reference' '
+	rm -rf dst.git &&
+	git clone --no-local --bare --reference shared.git . dst.git
+'
+
+test_done
t/t5618-alternate-refs.sh new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.22.0.776.g16867c022c
#10 lore raw

t/t5618-alternate-refs.sh line 55

Quoted 10 lines · Jeff King
t/t5618-alternate-refs.sh new file +3 -0
new file mode 100755
index 0000000000..3353216f09
@@ -0,0 +1,60 @@
 
+test_expect_success 'log --source shows .alternate marker' '
+	git log --oneline --source --remotes=origin >expect.orig &&
+	sed "s/origin.* /.alternate /" <expect.orig >expect &&

Unnecessary redirection, 'sed' can open that file on its own as well.

Quoted 7 lines
t/t5618-alternate-refs.sh new file +5 -0
+	git log --oneline --source --alternate-refs >actual &&
+	test_cmp expect actual
+'
+
+test_done
Signature · 1 line
2.22.0.776.g16867c022c
author
#11 lore raw
Quoted 8 lines · SZEDER Gábor
Quoted 6 lines · Jeff King
t/t5618-alternate-refs.sh new file +0 -0
new file mode 100755
index 0000000000..3353216f09
@@ -0,0 +1,60 @@
Quoted 5 lines

t/t5618-alternate-refs.sh line 55

Quoted 3 lines
t/t5618-alternate-refs.sh new file +3 -0
+test_expect_success 'log --source shows .alternate marker' '
+	git log --oneline --source --remotes=origin >expect.orig &&
+	sed "s/origin.* /.alternate /" <expect.orig >expect &&

Unnecessary redirection, 'sed' can open that file on its own as well.

Sure, but is there a compelling reason not to feed it as stdin?

-Peff

#12 lore raw
Quoted 10 lines · Jeff King
Quoted 8 lines · SZEDER Gábor
Quoted 6 lines · Jeff King
t/t5618-alternate-refs.sh new file +0 -0
new file mode 100755
index 0000000000..3353216f09
@@ -0,0 +1,60 @@
Quoted 7 lines
Quoted 5 lines

t/t5618-alternate-refs.sh line 55

Quoted 3 lines
t/t5618-alternate-refs.sh new file +3 -0
+test_expect_success 'log --source shows .alternate marker' '
+	git log --oneline --source --remotes=origin >expect.orig &&
+	sed "s/origin.* /.alternate /" <expect.orig >expect &&

Unnecessary redirection, 'sed' can open that file on its own as well.

Sure, but is there a compelling reason not to feed it as stdin?

FWIW I do not think it is bad to redirect into a command at all ;-)

#13 lore raw
In reply to Jeff King
Quoted 10 lines · Jeff King
Quoted 8 lines · SZEDER Gábor
Quoted 6 lines · Jeff King
t/t5618-alternate-refs.sh new file +0 -0
new file mode 100755
index 0000000000..3353216f09
@@ -0,0 +1,60 @@
Quoted 7 lines
Quoted 5 lines

t/t5618-alternate-refs.sh line 55

Quoted 3 lines
t/t5618-alternate-refs.sh new file +3 -0
+test_expect_success 'log --source shows .alternate marker' '
+	git log --oneline --source --remotes=origin >expect.orig &&
+	sed "s/origin.* /.alternate /" <expect.orig >expect &&

Unnecessary redirection, 'sed' can open that file on its own as well.

Sure, but is there a compelling reason not to feed it as stdin?

Not really, other than there is no compelling reason to do so :)

#14 lore raw
Quoted 17 lines · SZEDER Gábor
Quoted 16 lines · Jeff King
Quoted 13 lines · SZEDER Gábor

t/t5618-alternate-refs.sh line 55

Quoted 10 lines · Jeff King
t/t5618-alternate-refs.sh new file +3 -0
new file mode 100755
index 0000000000..3353216f09
@@ -0,0 +1,60 @@
 
+test_expect_success 'log --source shows .alternate marker' '
+	git log --oneline --source --remotes=origin >expect.orig &&
+	sed "s/origin.* /.alternate /" <expect.orig >expect &&

Unnecessary redirection, 'sed' can open that file on its own as well.

Quoted 3 lines
Quoted 1 line

Sure, but is there a compelling reason not to feed it as stdin?

Not really, other than there is no compelling reason to do so :)

For this particular one, it would not make much difference, but when feeding a single file to a command that can take many instructions as command line arguments, I tend to prefer

	$ cmd <input \
		-e 's/foo/bar/' \
		-e 's/xyzzy/frotz/g' \
		...

which I find slightly easier to read than

	$ cmd \
		-e 's/foo/bar/' \
		-e 's/xyzzy/frotz/g' \
		... \
		input
#15 lore raw
In reply to Jeff King

Hi Peff,

Quoted 16 lines · Jeff King
Quoted 7 lines · Jeff King

Yes, this is weakening the ties of the feature to the transport code. Traditionally transport-oriented code was the only user, but it also used the upload-pack transport under the hood to access the alternate (that was changed a while ago to for-each-ref for speed).

I don't think there's any functional difference in having it there, but it could be moved to live alongside foreach_alt_odb() in sha1-file.c.

Looks like this hasn't quite hit 'next' yet, so perhaps we can reorganize it as a preparatory patch.

[1/2]: object-store.h: move for_each_alternate_ref() from transport.h [2/2]: check_everything_connected: assume alternate ref tips are valid

Quoted 13 lines
 Documentation/rev-list-options.txt |  8 +++
 builtin/receive-pack.c             |  1 -
 connected.c                        |  1 +
 object-store.h                     |  2 +
 revision.c                         | 29 +++++++++
 sha1-file.c                        | 97 ++++++++++++++++++++++++++++++
 t/perf/p5600-clone-reference.sh    | 27 +++++++++
 t/t5618-alternate-refs.sh          | 60 ++++++++++++++++++
 transport.c                        | 97 ------------------------------
 transport.h                        |  2 -
 10 files changed, 224 insertions(+), 100 deletions(-)
 create mode 100755 t/perf/p5600-clone-reference.sh
 create mode 100755 t/t5618-alternate-refs.sh

This looks good to me, too (and matches my recollection from our prior off-list review against GitHub's fork).

One thing that I didn't catch in my initial review that I am seeing now is the ".alternate" marker. Why did you choose this? I was thinking that ".have" would make more sense since it's consistent with what's shown in the ref advertisement, but I think that actually ".alternate" is a _better_ choice: the two really do refer to different things.

Either way, I don't think that it matters much: this series is already on 'next' and I think that either is fine (especially since ".have" refers to a nameless ref and ".alternate" refers to a nameless pseudo-remote).

Quoted 1 line

-Peff

Thanks,
Taylor

author
#16 lore raw
Quoted 5 lines · Taylor Blau

One thing that I didn't catch in my initial review that I am seeing now is the ".alternate" marker. Why did you choose this? I was thinking that ".have" would make more sense since it's consistent with what's shown in the ref advertisement, but I think that actually ".alternate" is a _better_ choice: the two really do refer to different things.

Yeah, I had called these ".have" originally, but decided that was too tied up with the current users, and not with the concept. I think keeping the leading "." is worthwhile as that's an invalid refname.

I also thought about an empty string, but it's probably more informative to show _something_. After all, the user would not see these unless they specifically asked for them _and_ used something like --source, so presumably it's a useful piece of information at that point (I don't know of any other way to show these names except for --source).

I suppose one other option would be to name them after the oid itself. So with --source you'd find out that 1234abcd came from 1234abcd (duh), but also that its children came from 1234abcd. Maybe that has value. I dunno.

It would be easy to change, but I'd also be OK punting until somebody comes up with a compelling use case.

-Peff

#17 lore raw
In reply to Jeff King
Quoted 15 lines · Jeff King

When we receive a remote ref update to sha1 "X", we want to check that we have all of the objects needed by "X". We can assume that our repository is not currently corrupted, and therefore if we have a ref pointing at "Y", we have all of its objects. So we can stop our traversal from "X" as soon as we hit "Y".

If we make the same non-corruption assumption about any repositories we use to store alternates, then we can also use their ref tips to shorten the traversal.
...

connected.c +0 -0
index 1ab481fed6..cd9b324afa 100644

connected.c int check_connected(oid_iterate_fn fn, void *cb_data, · line 86

Quoted 7 lines
connected.c +1 -0
@@ -80,6 +80,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
 		argv_array_push(&rev_list.args, "--all");
 	}
 	argv_array_push(&rev_list.args, "--quiet");
+	argv_array_push(&rev_list.args, "--alternate-refs");
 	if (opt->progress)
 		argv_array_pushf(&rev_list.args, "--progress=%s",
 				 _("Checking connectivity"));

Quite honestly, I am very surprised that we did not do this. The idea of alternate object store, as well as reducing transfer cost by advertising their tips as '.have' phony refs, is almost as old as the pack protocol itself.

author
#18 lore raw
Quoted 10 lines · Junio C Hamano

connected.c int check_connected(oid_iterate_fn fn, void *cb_data, · line 86

Quoted 5 lines
connected.c +1 -0
 	argv_array_push(&rev_list.args, "--quiet");
+	argv_array_push(&rev_list.args, "--alternate-refs");
 	if (opt->progress)
 		argv_array_pushf(&rev_list.args, "--progress=%s",
 				 _("Checking connectivity"));

Quite honestly, I am very surprised that we did not do this. The idea of alternate object store, as well as reducing transfer cost by advertising their tips as '.have' phony refs, is almost as old as the pack protocol itself.

Yeah, as you note we are already telling the other side of the push "hey, we already have these objects". So we are almost always just walking over our own local objects in the connectivity check, which is silly.

I only did "clone --reference" in the perf test because it was the simplest, but a push to a server with alternates should be similarly improved. E.g., doing this in a clone of linux.git:

  git init --bare dst.git
  echo '../../.git/objects' >dst.git/objects/info/alternates
  time git push dst.git HEAD

goes from 40+ seconds to 100ms or so. Again, obviously that's the best case, but it should also improve the normal case of somebody pulling down "torvalds/linux.git" and pushing it back up to their own "peff/linux.git", too.

I don't have real-world numbers yet from GitHub, because we're not actually advertising .haves on push right now. All of the Git pieces are now in places to do so, but we still have to make some tweaks at our replication layer. But soon. :)

-Peff

#19 lore raw
Quoted 31 lines · Jeff King
Quoted 10 lines · Junio C Hamano

connected.c int check_connected(oid_iterate_fn fn, void *cb_data, · line 86

Quoted 5 lines
connected.c +1 -0
 	argv_array_push(&rev_list.args, "--quiet");
+	argv_array_push(&rev_list.args, "--alternate-refs");
 	if (opt->progress)
 		argv_array_pushf(&rev_list.args, "--progress=%s",
 				 _("Checking connectivity"));

Quite honestly, I am very surprised that we did not do this. The idea of alternate object store, as well as reducing transfer cost by advertising their tips as '.have' phony refs, is almost as old as the pack protocol itself.

Yeah, as you note we are already telling the other side of the push "hey, we already have these objects". So we are almost always just walking over our own local objects in the connectivity check, which is silly.

I only did "clone --reference" in the perf test because it was the simplest, but a push to a server with alternates should be similarly improved. E.g., doing this in a clone of linux.git:

  git init --bare dst.git
  echo '../../.git/objects' >dst.git/objects/info/alternates
  time git push dst.git HEAD

goes from 40+ seconds to 100ms or so. Again, obviously that's the best case, but it should also improve the normal case of somebody pulling down "torvalds/linux.git" and pushing it back up to their own "peff/linux.git", too.

Quoted 4 lines

I don't have real-world numbers yet from GitHub, because we're not actually advertising .haves on push right now. All of the Git pieces are now in places to do so, but we still have to make some tweaks at our replication layer. But soon. :)

Exciting! Should improve the user's experience keeping their forks updated!

-Stolee