# [PATCH JGIT] Minor : Make ObjectId, RemoteConfig Serializable

6 messages from 2009-02-06 to 2009-02-08. Participants: Nigel Magnay, Robin Rosenberg, Shawn O. Pearce.
Thread: https://gitlist.dev/t/17624

## Nigel Magnay, 2009-02-06 21:15

Subject: [PATCH JGIT] Minor : Make ObjectId, RemoteConfig Serializable
Message-ID: <320075ff0902061315g3f8b9c9bj92f528e700d59c50@mail.gmail.com>
URL: https://gitlist.dev/e/320075ff0902061315g3f8b9c9bj92f528e700d59c50%40mail.gmail.com
In-Reply-To: <320075ff0902060702n7573aaecu9054626ee9a6991@mail.gmail.com>

```
Make AnyObjectId and RemoteConfig Serializable.
When using jgit as a library in other tools, it's helpful to be able
to use the nice, tested bits of jgit rather than String, but need to
be able to serialize them.

Signed-off-by: Nigel Magnay <nigel.magnay@gmail.com>
---
 .../src/org/spearce/jgit/lib/AnyObjectId.java      |    3 ++-
 .../org/spearce/jgit/transport/RemoteConfig.java   |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
index e2f70ca..532174b 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AnyObjectId.java
@@ -39,6 +39,7 @@

 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.Serializable;
 import java.io.Writer;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
@@ -52,7 +53,7 @@
  * with this instance can alter at any time, if this instance is modified to
  * represent a different object name.
  */
-public abstract class AnyObjectId implements Comparable {
+public abstract class AnyObjectId implements Comparable, Serializable {
     static final int RAW_LEN = Constants.OBJECT_ID_LENGTH;

     static final int STR_LEN = RAW_LEN * 2;
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java
b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java
index 5bbf664..7949612 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteConfig.java
@@ -38,6 +38,7 @@

 package org.spearce.jgit.transport;

+import java.io.Serializable;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -53,7 +54,7 @@
  * describing how refs should be transferred between this repository and the
  * remote repository.
  */
-public class RemoteConfig {
+public class RemoteConfig implements Serializable {
     private static final String SECTION = "remote";

     private static final String KEY_URL = "url";
--
1.6.0.2

```

## Robin Rosenberg, 2009-02-08 02:13

Subject: Re: [PATCH JGIT] Minor : Make ObjectId, RemoteConfig Serializable
Message-ID: <200902080313.21785.robin.rosenberg.lists@dewire.com>
URL: https://gitlist.dev/e/200902080313.21785.robin.rosenberg.lists%40dewire.com
In-Reply-To: <320075ff0902061315g3f8b9c9bj92f528e700d59c50@mail.gmail.com>

```
fredag 06 februari 2009 22:15:29 skrev Nigel Magnay:
> Make AnyObjectId and RemoteConfig Serializable.
> When using jgit as a library in other tools, it's helpful to be able
> to use the nice, tested bits of jgit rather than String, but need to
> be able to serialize them.

A problem (big problem) with serialization is that it often leads to
fragile interfaces. One might want to have precise control over
the serialization so a change in the implementation doesn't affect
compatibility. Serializing AnyObjectId should not depend on the
implementation de jour. Second, how do we handle subclasses?

But maybe leaving it this way would be our way of saying that
the interface may break at any time, promise.

-- robin

```

## Nigel Magnay, 2009-02-08 13:26

Subject: Re: [PATCH JGIT] Minor : Make ObjectId, RemoteConfig Serializable
Message-ID: <320075ff0902080526g2bee8188g395397b06a0c80ee@mail.gmail.com>
URL: https://gitlist.dev/e/320075ff0902080526g2bee8188g395397b06a0c80ee%40mail.gmail.com
In-Reply-To: <200902080313.21785.robin.rosenberg.lists@dewire.com>

```
> A problem (big problem) with serialization is that it often leads to
> fragile interfaces. One might want to have precise control over
> the serialization so a change in the implementation doesn't affect
> compatibility. Serializing AnyObjectId should not depend on the
> implementation de jour. Second, how do we handle subclasses?
>
> But maybe leaving it this way would be our way of saying that
> the interface may break at any time, promise.
>


Well, we can of course implement writeObject / readObject (or do so
if/when compatibility breaks, and it's cared about)

That's how I tend to view it anyway (may break at any time) - you
can't just update a jar library to a significantly new version and
expect it all to stay compatible. Also for half my use, it's not for
persistence, it's for transferring over the wire to a slave process.

Thinking a bit more clearly, I probably don't need AnyObjectId, just
ObjectId - but I've also missed RefSpec and URIish as they're used in
RemoteConfig..

```

## Shawn O. Pearce, 2009-02-08 19:10

Subject: Re: [PATCH JGIT] Minor : Make ObjectId, RemoteConfig Serializable
Message-ID: <20090208191024.GA30557@spearce.org>
URL: https://gitlist.dev/e/20090208191024.GA30557%40spearce.org
In-Reply-To: <320075ff0902080526g2bee8188g395397b06a0c80ee@mail.gmail.com>

```
Nigel Magnay <nigel.magnay@gmail.com> wrote:
> > A problem (big problem) with serialization is that it often leads to
> > fragile interfaces. One might want to have precise control over
> > the serialization so a change in the implementation doesn't affect
> > compatibility. Serializing AnyObjectId should not depend on the
> > implementation de jour. Second, how do we handle subclasses?
> >
> > But maybe leaving it this way would be our way of saying that
> > the interface may break at any time, promise.
> 
> Well, we can of course implement writeObject / readObject (or do so
> if/when compatibility breaks, and it's cared about)
> 
> That's how I tend to view it anyway (may break at any time) - you
> can't just update a jar library to a significantly new version and
> expect it all to stay compatible. Also for half my use, it's not for
> persistence, it's for transferring over the wire to a slave process.
> 
> Thinking a bit more clearly, I probably don't need AnyObjectId, just
> ObjectId - but I've also missed RefSpec and URIish as they're used in
> RemoteConfig..

Here's my two cents... we can do this, but only if we implement
Externalizable and do the read and write ourselves so we have a
stable format.

In the case of any of the types you are discussing there is an easy
canonical form for them to be written on the wire, or to read back:

  ObjectId     - the 20 byte SHA-1
  RefSpec      - the string form as it appears in the config file
  URIish       - the string form as it appears in the config file
  RemoteConfig - a map of keys/values as it appears in the config

-- 
Shawn.

```

## Robin Rosenberg, 2009-02-08 19:45

Subject: Re: [PATCH JGIT] Minor : Make ObjectId, RemoteConfig Serializable
Message-ID: <200902082045.22703.robin.rosenberg.lists@dewire.com>
URL: https://gitlist.dev/e/200902082045.22703.robin.rosenberg.lists%40dewire.com
In-Reply-To: <20090208191024.GA30557@spearce.org>

```
söndag 08 februari 2009 20:10:24 skrev Shawn O. Pearce:
> Nigel Magnay <nigel.magnay@gmail.com> wrote:
> > > A problem (big problem) with serialization is that it often leads to
> > > fragile interfaces. One might want to have precise control over
> > > the serialization so a change in the implementation doesn't affect
> > > compatibility. Serializing AnyObjectId should not depend on the
> > > implementation de jour. Second, how do we handle subclasses?
> > >
> > > But maybe leaving it this way would be our way of saying that
> > > the interface may break at any time, promise.
> > 
> > Well, we can of course implement writeObject / readObject (or do so
> > if/when compatibility breaks, and it's cared about)
> > 
> > That's how I tend to view it anyway (may break at any time) - you
> > can't just update a jar library to a significantly new version and
> > expect it all to stay compatible. Also for half my use, it's not for
> > persistence, it's for transferring over the wire to a slave process.

Over-the wire has the same issue. Clients and servers often run with
slightly different versions.

> > Thinking a bit more clearly, I probably don't need AnyObjectId, just
> > ObjectId - but I've also missed RefSpec and URIish as they're used in
> > RemoteConfig..
> 
> Here's my two cents... we can do this, but only if we implement
> Externalizable and do the read and write ourselves so we have a
> stable format.

> In the case of any of the types you are discussing there is an easy
> canonical form for them to be written on the wire, or to read back:
> 
>   ObjectId     - the 20 byte SHA-1
>   RefSpec      - the string form as it appears in the config file
>   URIish       - the string form as it appears in the config file
with our without the password?

>   RemoteConfig - a map of keys/values as it appears in the config

I lean toward the do it correctly side too. Don't forget a few test cases
with pre-recorded serializations to verify compatibility over different
versions of jgit.

-- robin

```

## Shawn O. Pearce, 2009-02-08 19:47

Subject: Re: [PATCH JGIT] Minor : Make ObjectId, RemoteConfig Serializable
Message-ID: <20090208194745.GA30949@spearce.org>
URL: https://gitlist.dev/e/20090208194745.GA30949%40spearce.org
In-Reply-To: <200902082045.22703.robin.rosenberg.lists@dewire.com>

```
Robin Rosenberg <robin.rosenberg.lists@dewire.com> wrote:
> söndag 08 februari 2009 20:10:24 skrev Shawn O. Pearce:
> > In the case of any of the types you are discussing there is an easy
> > canonical form for them to be written on the wire, or to read back:
> > 
> >   ObjectId     - the 20 byte SHA-1
> >   RefSpec      - the string form as it appears in the config file
> >   URIish       - the string form as it appears in the config file
>
> with our without the password?

With.

We're serializing the object, we should store as much of the data
as we have.  Clients throwing this over the wire should either be
careful with their connection (e.g. use SSL) or be careful with
the data they are throwing (e.g. don't use URIish that has password).
 
-- 
Shawn.

```
