gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/lava/gzz/storm/util DiffingStormFiler.java ...


From: Benja Fallenstein
Subject: [Gzz-commits] gzz/lava/gzz/storm/util DiffingStormFiler.java ...
Date: Tue, 14 Jan 2003 12:20:49 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Benja Fallenstein <address@hidden>      03/01/14 12:20:48

Modified files:
        lava/gzz/storm/util: DiffingStormFiler.java 
                             SimpleStormFiler.java 

Log message:
        More attempts at diffing...

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/util/DiffingStormFiler.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/util/SimpleStormFiler.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gzz/lava/gzz/storm/util/DiffingStormFiler.java
diff -u gzz/lava/gzz/storm/util/DiffingStormFiler.java:1.1 
gzz/lava/gzz/storm/util/DiffingStormFiler.java:1.2
--- gzz/lava/gzz/storm/util/DiffingStormFiler.java:1.1  Tue Jan 14 10:43:07 2003
+++ gzz/lava/gzz/storm/util/DiffingStormFiler.java      Tue Jan 14 12:20:48 2003
@@ -20,27 +20,66 @@
        index = (DiffIndexType.Index)pool.getIndex(DiffIndexType.indexTypeURI);
     }
 
-    public Version load() throws IOException {
-       return super.load();
+    /**
+    public Version load(BlockId id) throws IOException {
+       return load(id, new Header822[2]);
     }
 
-    public void save(Version v) throws IOException {
-       Version old = load();
-       if(old.equals(v)) return;
+    public Version load(BlockId id, Header822 hdr[]) throws IOException {
+       try {
+           return super.load(id);
+       } catch(FileNotFoundException _) {
+           Set diffs = index.getDiffsTo(id);
+           if(diffs.isEmpty())
+               throw new FileNotFoundException("No diff path to: "+id);
+           
+           BlockId diffId = (BlockId)diffs.iterator().next();
+           Block diffBlock = pool.get(diffId);
+           InputStream is = diffBlock.getInputStream();
+           Header822 fromHeader = Headers822.readHeader(is);
+           Header822 toHeader = Headers822.readHeader(is);
+           Version.Diff diff = format.readDiff(is);
+           is.close();
+
+           BlockId fromId;
+           try {
+               String hex = diffBlock.getHeader().get("X-Gzz-Diff-From");
+               fromId = BlockId.getMediaserverId(hex);
+           } catch(NoSuchElementException __) {
+               fromId = null;
+           }
+
+           Version from;
+           if(fromId != null)
+               from = load(fromId);
+           else
+               from = emptyVersion;
+
+           hdr[0] = fromHeader;
+           hdr[1] = toHeader;
+           return diff.applyTo(from);
+       }
+    }
 
+    public void save(Version v) throws IOException {
+       Version old;
        BlockId oldId = null;
        Header822 oldHeader = null;
 
        if(current != null) {
+           Header822[] old_hdrs = new Header822[2];
+           old = load(current.getTarget(), old_hdrs);
            oldId = current.getTarget();
-           oldHeader = pool.get(oldId).getHeader(); // XXX
+           oldHeader = old_hdrs[1];
        } else {
+           old = emptyVersion;
            oldHeader = new VerbatimHeader822(); // empty header
        }
 
+       if(old.equals(v)) return;
+
        Block newBlock = saveVersion(v);
 
-       /*
        BlockId newId = newBlock.getId();
        Header822 newHeader = newBlock.getHeader();
        
@@ -49,25 +88,19 @@
        Header822 hdr = new SortedHeader822();
        hdr.add("Content-Type", diffContentType);
        hdr.add("Content-Transfer-Encoding", "binary");
-       if(old != null)
+       if(oldId != null)
            hdr.add("X-Gzz-Diff-From", oldId.getHex());
        hdr.add("X-Gzz-Diff-To", newId.getHex());
 
        BlockOutputStream bos = pool.getBlockOutputStream(hdr);
-       if(old != null)
-           oldHeader.writeTo(bos);
-       else {
-           bos.write((byte)'\r');
-           bos.write((byte)'\n');
-       }
+       oldHeader.writeTo(bos);
        newHeader.writeTo(bos);
        format.writeDiff(bos, diff);
        bos.close();
-       */
 
        //pool.delete(newBlock);
     }
-
+    */
 
 
     // should be simply named .Group
Index: gzz/lava/gzz/storm/util/SimpleStormFiler.java
diff -u gzz/lava/gzz/storm/util/SimpleStormFiler.java:1.1 
gzz/lava/gzz/storm/util/SimpleStormFiler.java:1.2
--- gzz/lava/gzz/storm/util/SimpleStormFiler.java:1.1   Tue Jan 14 10:43:07 2003
+++ gzz/lava/gzz/storm/util/SimpleStormFiler.java       Tue Jan 14 12:20:48 2003
@@ -37,8 +37,11 @@
 
     public Version load() throws IOException {
        if(current == null) return emptyVersion;
+       return load(current.getTarget());
+    }
        
-       Block block = pool.get(current.getTarget());
+    public Version load(BlockId id) throws IOException {
+       Block block = pool.get(id);
        InputStream is = block.getInputStream();
        Version v = format.readVersion(is);
        is.close();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]