Re: [PATCH 12/13] Add bundle transport

Previous thread: [PATCH 11/13] Move bundle specific stuff into bundle.[ch] by Johannes Schindelin on Monday, September 10, 2007 - 11:03 pm. (1 message)

Next thread: [PATCH] Add git-remote(1) to SEE ALSO by Jari Aalto on Monday, September 10, 2007 - 12:48 am. (1 message)
To: Junio C Hamano <junkio@...>
Cc: <git@...>
Date: Monday, September 10, 2007 - 11:03 pm

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,
...

To: Johannes Schindelin <Johannes.Schindelin@...>
Cc: Junio C Hamano <junkio@...>, <git@...>
Date: Tuesday, September 11, 2007 - 4:23 am

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

To: Pierre Habouzit <madcoder@...>
Cc: Junio C Hamano <junkio@...>, <git@...>
Date: Tuesday, September 11, 2007 - 12:26 pm

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

-

To: Johannes Schindelin <Johannes.Schindelin@...>
Cc: Junio C Hamano <junkio@...>, <git@...>
Date: Tuesday, September 11, 2007 - 1:30 pm

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_bundle

Or 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_bundle

It'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

To: Pierre Habouzit <madcoder@...>
Cc: Junio C Hamano <junkio@...>, Johannes Schindelin <Johannes.Schindelin@...>, <git@...>
Date: Tuesday, September 11, 2007 - 2:09 pm

No.

Git is meant to be compilable with as many C compilers as reasonably
possible, including old compilers found on some systems that don't

The 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
-

To: Pierre Habouzit <madcoder@...>
Cc: Junio C Hamano <junkio@...>, <git@...>
Date: Tuesday, September 11, 2007 - 1:55 pm

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

-

To: Pierre Habouzit <madcoder@...>
Cc: Junio C Hamano <junkio@...>, Johannes Schindelin <Johannes.Schindelin@...>, <git@...>
Date: Tuesday, September 11, 2007 - 1:46 pm

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
-

Previous thread: [PATCH 11/13] Move bundle specific stuff into bundle.[ch] by Johannes Schindelin on Monday, September 10, 2007 - 11:03 pm. (1 message)

Next thread: [PATCH] Add git-remote(1) to SEE ALSO by Jari Aalto on Monday, September 10, 2007 - 12:48 am. (1 message)