Improve error reporting in the branch dialog
[egit/imyousuf.git] / org.spearce.egit.core / src / org / spearce / egit / core / internal / storage / GitFileRevision.java
blob2f23c7decab3eb3de4b58207632fd5e9a17559fe
1 /*******************************************************************************
2 * Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * See LICENSE for the full license text, also available.
8 *******************************************************************************/
9 package org.spearce.egit.core.internal.storage;
11 import java.net.URI;
12 import java.net.URISyntaxException;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.team.core.history.IFileRevision;
17 import org.eclipse.team.core.history.provider.FileRevision;
18 import org.spearce.jgit.lib.ObjectId;
19 import org.spearce.jgit.lib.Repository;
20 import org.spearce.jgit.revwalk.RevCommit;
22 /**
23 * A Git related {@link IFileRevision}. It references a version and a resource,
24 * i.e. the version we think corresponds to the resource in specific version.
26 public abstract class GitFileRevision extends FileRevision {
27 /** Content identifier for the working copy. */
28 public static final String WORKSPACE = "Workspace";
30 /** Content identifier for the content staged in the index. */
31 public static final String INDEX = "Index";
33 /**
34 * Obtain a file revision for a specific blob of an existing commit.
36 * @param db
37 * the repository this commit was loaded out of, and that this
38 * file's blob should also be reachable through.
39 * @param commit
40 * the commit the blob was identified to be within.
41 * @param path
42 * path within the commit's tree of the file.
43 * @param blobId
44 * unique name of the content.
45 * @return revision implementation for this file in the given commit.
47 public static GitFileRevision inCommit(final Repository db,
48 final RevCommit commit, final String path, final ObjectId blobId) {
49 return new CommitFileRevision(db, commit, path, blobId);
52 /**
53 * @param db
54 * the repository which contains the index to use.
55 * @param path
56 * path of the resource in the index
57 * @return revision implementation for the given path in the index
59 public static GitFileRevision inIndex(final Repository db, final String path) {
60 return new IndexFileRevision(db, path);
63 private final String path;
65 GitFileRevision(final String fileName) {
66 path = fileName;
69 public String getName() {
70 final int last = path.lastIndexOf('/');
71 return last >= 0 ? path.substring(last + 1) : path;
74 public boolean isPropertyMissing() {
75 return false;
78 public IFileRevision withAllProperties(final IProgressMonitor monitor)
79 throws CoreException {
80 return this;
83 public URI getURI() {
84 try {
85 return new URI(null, null, path, null);
86 } catch (URISyntaxException e) {
87 return null;