Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/RevlogStream.java @ 396:0ae53c32ecef
Straighten out exceptions thrown when file access failed - three is too much
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Thu, 23 Feb 2012 01:06:24 +0100 | 
| parents | 86f049e6bcae | 
| children | c76c57f6b961 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 395:4732fffff58a | 396:0ae53c32ecef | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (c) 2010-2011 TMate Software Ltd | 2 * Copyright (c) 2010-2012 TMate Software Ltd | 
| 3 * | 3 * | 
| 4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify | 
| 5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by | 
| 6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. | 
| 7 * | 7 * | 
| 54 */ | 54 */ | 
| 55 private int[] indexRecordOffset; | 55 private int[] indexRecordOffset; | 
| 56 private int[] baseRevisions; | 56 private int[] baseRevisions; | 
| 57 private boolean inline = false; | 57 private boolean inline = false; | 
| 58 private final File indexFile; | 58 private final File indexFile; | 
| 59 private File dataFile; | |
| 59 private final DataAccessProvider dataAccess; | 60 private final DataAccessProvider dataAccess; | 
| 60 | 61 | 
| 61 // if we need anything else from HgRepo, might replace DAP parameter with HgRepo and query it for DAP. | 62 // if we need anything else from HgRepo, might replace DAP parameter with HgRepo and query it for DAP. | 
| 62 public RevlogStream(DataAccessProvider dap, File indexFile) { | 63 public RevlogStream(DataAccessProvider dap, File indexFile) { | 
| 63 this.dataAccess = dap; | 64 this.dataAccess = dap; | 
| 69 // to avoid mmap files when only few bytes are to be read (i.e. #dataLength()) | 70 // to avoid mmap files when only few bytes are to be read (i.e. #dataLength()) | 
| 70 return dataAccess.create(indexFile); | 71 return dataAccess.create(indexFile); | 
| 71 } | 72 } | 
| 72 | 73 | 
| 73 /*package*/ DataAccess getDataStream() { | 74 /*package*/ DataAccess getDataStream() { | 
| 74 final String indexName = indexFile.getName(); | 75 return dataAccess.create(getDataFile()); | 
| 75 File dataFile = new File(indexFile.getParentFile(), indexName.substring(0, indexName.length() - 1) + "d"); | 76 } | 
| 76 return dataAccess.create(dataFile); | 77 | 
| 77 } | 78 /** | 
| 79 * Constructs file object that corresponds to .d revlog counterpart. | |
| 80 * Note, it's caller responsibility to ensure this file makes any sense (i.e. check {@link #inline} attribute) | |
| 81 */ | |
| 82 private File getDataFile() { | |
| 83 if (dataFile == null) { | |
| 84 final String indexName = indexFile.getName(); | |
| 85 dataFile = new File(indexFile.getParentFile(), indexName.substring(0, indexName.length() - 1) + "d"); | |
| 86 } | |
| 87 return dataFile; | |
| 88 } | |
| 89 | |
| 90 // initialize exception with the file where revlog structure information comes from | |
| 91 public HgInvalidControlFileException initWithIndexFile(HgInvalidControlFileException ex) { | |
| 92 return ex.setFile(indexFile); | |
| 93 } | |
| 94 | |
| 95 // initialize exception with the file where revlog data comes from | |
| 96 public HgInvalidControlFileException initWithDataFile(HgInvalidControlFileException ex) { | |
| 97 // exceptions are usually raised after read attepmt, hence inline shall be initialized | |
| 98 // although honest approach is to call #initOutline() first | |
| 99 return ex.setFile(inline ? indexFile : getDataFile()); | |
| 100 } | |
| 101 | |
| 78 | 102 | 
| 79 public int revisionCount() { | 103 public int revisionCount() { | 
| 80 initOutline(); | 104 initOutline(); | 
| 81 return baseRevisions.length; | 105 return baseRevisions.length; | 
| 82 } | 106 } | 
