Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d9066573d99b57a848de48de53ad5ea63febf8ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
 * Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.egit.core.internal.storage;

import java.net.URI;
import java.net.URISyntaxException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.history.IFileRevision;
import org.eclipse.team.core.history.provider.FileRevision;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;

/**
 * A Git related {@link IFileRevision}. It references a version and a resource,
 * i.e. the version we think corresponds to the resource in specific version.
 */
public abstract class GitFileRevision extends FileRevision {
	/** Content identifier for the working copy. */
	public static final String WORKSPACE = "Workspace";

	/** Content identifier for the content staged in the index. */
	public static final String INDEX = "Index";

	/**
	 * Obtain a file revision for a specific blob of an existing commit.
	 * 
	 * @param db
	 *            the repository this commit was loaded out of, and that this
	 *            file's blob should also be reachable through.
	 * @param commit
	 *            the commit the blob was identified to be within.
	 * @param path
	 *            path within the commit's tree of the file.
	 * @param blobId
	 *            unique name of the content.
	 * @return revision implementation for this file in the given commit.
	 */
	public static GitFileRevision inCommit(final Repository db,
			final RevCommit commit, final String path, final ObjectId blobId) {
		return new CommitFileRevision(db, commit, path, blobId);
	}

	/**
	 * @param db
	 *            the repository which contains the index to use.
	 * @param path
	 *            path of the resource in the index
	 * @return revision implementation for the given path in the index
	 */
	public static GitFileRevision inIndex(final Repository db, final String path) {
		return new IndexFileRevision(db, path);
	}

	private final String path;

	GitFileRevision(final String fileName) {
		path = fileName;
	}

	public String getName() {
		final int last = path.lastIndexOf('/');
		return last >= 0 ? path.substring(last + 1) : path;
	}

	public boolean isPropertyMissing() {
		return false;
	}

	public IFileRevision withAllProperties(final IProgressMonitor monitor)
			throws CoreException {
		return this;
	}

	public URI getURI() {
		try {
			return new URI(null, null, path, null);
		} catch (URISyntaxException e) {
			return null;
		}
	}
}

Back to the top