Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
transport.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 51 insertions(+), 1 deletions(-)diff --git a/transport.c b/transport.c
index 7d52769..d9bc16a 100644
--- a/transport.c
+++ b/transport.c
@@ -5,6 +5,7 @@
#include "pkt-line.h"
#include "fetch-pack.h"
#include "walker.h"
+#include "bundle.h"/* Generic functions for using commit walkers */
@@ -185,7 +186,55 @@ static const struct transport_ops curl_transport = {
/* disconnect */ disconnect_walker
};+struct bundle_transport_data {
+ int fd;
+ struct bundle_header header;
+};
+
+static struct ref *get_refs_from_bundle(const struct transport *transport)
+{
+ struct bundle_transport_data *data = transport->data;
+ struct ref *result = NULL;
+ int i;
+
+ if (data->fd > 0)
+ close(data->fd);
+ data->fd = read_bundle_header(transport->url, &data->header);
+ if (data->fd < 0)
+ die ("Could not read bundle '%s'.", transport->url);
+ for (i = 0; i < data->header.references.nr; i++) {
+ struct ref_list_entry *e = data->header.references.list + i;
+ struct ref *ref = alloc_ref(strlen(e->name));
+ hashcpy(ref->old_sha1, e->sha1);
+ strcpy(ref->name, e->name);
+ ref->next = result;
+ result = ref;
+ }
+ return result;
+}
+
+static int fetch_refs_from_bundle(const struct transport *transport,
+ int nr_heads, char **heads)
+{
+ struct bundle_transport_data *data = transport->data;
+ return unbundle(&data->header, data->fd);
+}
+
+static int close_bundle(struct transport *transport)
+{
+ struct bundle_transport_data *data = transport->data;
+ if (data->fd > 0)
+ close(data->fd);
+ return 0;
+}
+
static const struct transport_ops bundle_transport = {
+ /* set_option */ NULL,
+ /* get_refs_list */ get_refs_from_bundle,
+ /* fetch_refs */ fetch_refs_from_bundle,
+ /* fetch_objs */ NULL,
...
Not that I care that much, and I don't know what is done in git
usually. But aren't C99 initializer safer ? (wrt struct transport_ops
API possible changes in the future).--=20
=C2=B7O=C2=B7 Pierre Habouzit
=C2=B7=C2=B7O madcoder@debia=
n.org
OOO http://www.madism.org
Hi,
No, they are not, since we do not allow such backwards incompatibilifiers
to creep into git's code.Yes, I know some would prefer the latest and greatest, and another
language altogether, but keep this in mind: what if somebody made git
incompatible with _your_ setup? So really, don't do it to others that
lightly.Ciao,
Dscho-
It has nothing to do with latest. I feel that if for some reason
transport_ops need a new function, it will break silentely, whereas if
you use:static const struct transport_ops bundle_transport =3D {
+ .set_option =3D NULL,
+ .get_refs_list =3D &get_refs_from_bundle,
+ .fetch_refs =3D &fetch_refs_from_bundle,
+ .fetch_objs =3D NULL,
+ .push =3D NULL,
+ .disconnect =3D &close_bundleOr even:
static const struct transport_ops bundle_transport =3D {
+ .get_refs_list =3D &get_refs_from_bundle,
+ .fetch_refs =3D &fetch_refs_from_bundle,
+ .disconnect =3D &close_bundleIt's pretty straightforward to extend the transport_ops API, afaict
it's what the kernel does e.g.. I wasn't suggesting anything else.
--=20
=C2=B7O=C2=B7 Pierre Habouzit
=C2=B7=C2=B7O madcoder@debia=
n.org
OOO http://www.madism.org
No.
Git is meant to be compilable with as many C compilers as reasonably
possible, including old compilers found on some systems that don'tThe Linux kernel is a different story. It is intimately tied to gcc and
heavily relies on gcc extensions already. That makes it impossible to
compile with anything else than gcc or a gcc clone.Nicolas
-
Hi,
As far as I am concerned, this kind of depending on newer features (this
_is_ C99, right?) will not happen. So the discussion is moot.Ciao,
Dscho-
But it does.
The "latest" being the compiler.
A lot of people have old compilers, possibly even ones where there *are*
The best way to handle that is to make sure you use ANSI C (which we *do*
depend on), and strict prototypes everywhere. Then, any breakage will not
be silent, because different functions will have different prototypes.Yes, C99 structure initializers are a good thing, and we use them in the
linux kernel, but the kernel can make more assumptions about the compiler
than a random user land tool can. So git should be more conservative than
that.It wasn't that long ago that people avoided even ANSI C, on the grounds
that some (totally broken crap) OS's shipped with just a K&R compiler by
default, and you had to pay for the "fancy" ANSI C compiler. Now, *that*
kind of ass-backwards compatibility is just stupid in this day and age
(especially since the advantages of ANSI over K&R are just so huge), but
at assuming everybody has C99 is not really realistic yet, and the things
C99 brings aren't quite worth breaking old compiler setups for.(But we may be getting close to being able to assume C99. It's getting
pretty common).Linus
-
| Jeremy Allison | Re: [RFC] Heads up on sys_fallocate() |
| Greg KH | [GIT PATCH] driver core patches against 2.6.24 |
| Joerg Roedel | [PATCH 03/34] AMD IOMMU: add defines and structures for ACPI scanning code |
| Eric W. Biederman | [PATCH] powerpc pseries eeh: Convert to kthread API |
| David Miller | [GIT]: Networking |
| Gerrit Renker | [PATCH 27/37] dccp: Integration of dynamic feature activation - part 2 (server side) |
| Natalie Protasevich | [BUG] New Kernel Bugs |
git: | |
