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
;
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
;
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";
34 * Obtain a file revision for a specific blob of an existing commit.
37 * the repository this commit was loaded out of, and that this
38 * file's blob should also be reachable through.
40 * the commit the blob was identified to be within.
42 * path within the commit's tree of the file.
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
);
54 * the repository which contains the index to use.
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
) {
69 public String
getName() {
70 final int last
= path
.lastIndexOf('/');
71 return last
>= 0 ? path
.substring(last
+ 1) : path
;
74 public boolean isPropertyMissing() {
78 public IFileRevision
withAllProperties(final IProgressMonitor monitor
)
79 throws CoreException
{
85 return new URI(null, null, path
, null);
86 } catch (URISyntaxException e
) {