/[gzz]/gzz/lava/gzz/storm/util/DiffingStormFiler.java
ViewVC logotype

Diff of /gzz/lava/gzz/storm/util/DiffingStormFiler.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by benja, Tue Jan 14 17:21:51 2003 UTC revision 1.4 by benja, Sat Jan 18 23:56:36 2003 UTC
# Line 20  public class DiffingStormFiler extends S Line 20  public class DiffingStormFiler extends S
20      }      }
21    
22    
23      // XXX      public VersionBlock load(BlockId id) throws IOException {
24            try {
25                return super.load(id);
26            } catch(FileNotFoundException _) {
27                Set diffs = index.getDiffBlocksTo(id, format);
28                System.out.println("ndiffs: "+diffs.size());
29                for(Iterator i=diffs.iterator(); i.hasNext();) {
30                    try {
31                        DiffBlock diffBlock = (DiffBlock)i.next();
32                        VersionBlock fromBlock = load(diffBlock.getFromId());
33                        Version from = fromBlock.version;
34                        Version to = diffBlock.diff.applyTo(from);
35                        VersionBlock toBlock =
36                            new VersionBlock(diffBlock.headerTo, to, format);
37                        toBlock.checkId(id);
38    
39                        return toBlock;
40                    } catch(IOException e) {
41                        System.err.println("Exception while loading diff: "+e);
42                        System.err.println("Ignore.");
43                    }
44                }
45                
46                throw new FileNotFoundException("No valid diff path to "+id+" found");
47            }
48        }
49    
50    
51        public void save(Version toVersion) throws IOException {
52            if(current == null) {
53                // First version -> no diff
54                saveVersion(toVersion);
55                return;
56            }
57    
58            BlockId fromId = current.getTarget();
59            VersionBlock fromVersionBlock = load(fromId);
60            Version fromVersion = fromVersionBlock.version;
61            if(fromVersion.equals(toVersion)) return;
62    
63            Block toBlock = saveVersion(toVersion);
64            VersionBlock toVersionBlock = new VersionBlock(toBlock, format);
65            BlockId toId = toBlock.getId();
66    
67            Block diffStormBlock = saveDiff(fromVersionBlock, fromId,
68                                            toVersionBlock, toId);
69            
70            DiffBlock diffBlock = new DiffBlock(diffStormBlock, format);
71            Version reconstructed = diffBlock.diff.applyTo(fromVersion);
72    
73            VersionBlock versionBlock =
74                new VersionBlock(diffBlock.headerTo, reconstructed, format);
75            
76            try {
77                versionBlock.checkId(toBlock.getId());
78                pool.delete(toBlock);
79            } catch(BlockId.WrongIdException e) {
80                System.err.println("======= correct ======= ("+toBlock.getId()+")");
81                System.err.println(CopyUtil.readString(toBlock.getRawInputStream()));
82                System.err.println("=======  wrong  =======");
83                ByteArrayOutputStream out = new ByteArrayOutputStream();
84                versionBlock.writeTo(out);
85                System.err.println(new String(out.toByteArray()));
86                System.err.println("=======================");
87                System.err.println("verify...");
88                toBlock.getId().check(CopyUtil.readBytes(toBlock.getRawInputStream()));
89                System.err.println("...es geht mit rechten Dingen zu.");
90                throw e;
91            }
92        }
93    
94    
95        protected Block saveDiff(VersionBlock from, BlockId fromId,
96                                 VersionBlock to, BlockId toId) throws IOException {
97            Header822 hdr = new SortedHeader822();
98            hdr.add("Content-Type", diffContentType);
99            hdr.add("Content-Transfer-Encoding", "binary");
100            hdr.add("X-Gzz-Diff-From", fromId.getHex());
101            hdr.add("X-Gzz-Diff-To", toId.getHex());
102    
103            BlockOutputStream bos = pool.getBlockOutputStream(hdr);
104            from.header.writeTo(bos);
105            to.header.writeTo(bos);
106            format.writeDiff(bos, to.version.getDiffFrom(from.version));
107            bos.close();
108    
109            return bos.getBlock();
110        }
111    
112    
113      // should be simply named .Group      // should be simply named .Group

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26