1 /*******************************************************************************
2 * Copyright (C) 2007, Robin Rosenberg <me@lathund.dewire.com>
3 * Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
4 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *******************************************************************************/
11 package org
.eclipse
.egit
.core
.internal
.storage
;
13 import java
.io
.IOException
;
15 import org
.eclipse
.core
.internal
.resources
.ResourceException
;
16 import org
.eclipse
.core
.resources
.IResourceStatus
;
17 import org
.eclipse
.core
.resources
.IStorage
;
18 import org
.eclipse
.core
.runtime
.CoreException
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.Path
;
21 import org
.eclipse
.team
.core
.history
.IFileRevision
;
22 import org
.spearce
.jgit
.lib
.GitIndex
;
23 import org
.spearce
.jgit
.lib
.ObjectId
;
24 import org
.spearce
.jgit
.lib
.Repository
;
25 import org
.spearce
.jgit
.lib
.GitIndex
.Entry
;
27 /** An {@link IFileRevision} for the version in the Git index. */
28 class IndexFileRevision
extends GitFileRevision
implements IFileRevision
{
29 private final Repository db
;
31 private final String path
;
33 private ObjectId blobId
;
35 IndexFileRevision(final Repository repo
, final String fileName
) {
41 public IStorage
getStorage(IProgressMonitor monitor
) throws CoreException
{
43 blobId
= locateBlobObjectId();
44 return new BlobStorage(db
, path
, blobId
);
47 public boolean isPropertyMissing() {
51 public IFileRevision
withAllProperties(IProgressMonitor monitor
)
52 throws CoreException
{
56 public String
getAuthor() {
60 public long getTimestamp() {
64 public String
getComment() {
68 public String
getContentIdentifier() {
72 private ObjectId
locateBlobObjectId() throws CoreException
{
74 final GitIndex idx
= db
.getIndex();
75 final Entry e
= idx
.getEntry(path
);
77 throw new ResourceException(IResourceStatus
.FAILED_READ_LOCAL
,
78 Path
.fromPortableString(path
),
79 "Git index entry not found", null);
80 return e
.getObjectId();
82 } catch (IOException e
) {
83 throw new ResourceException(IResourceStatus
.FAILED_READ_LOCAL
, Path
84 .fromPortableString(path
),
85 "IO error looking up path in index.", e
);