/*******************************************************************************
 * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
 *
 * 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.gitflow.ui.internal.factories;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdapterFactory;
import static org.eclipse.egit.core.project.RepositoryMapping.getMapping;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.team.ui.history.IHistoryPage;
import org.eclipse.team.ui.history.IHistoryView;

/**
 * Get JGit repository for element selected in Git Flow UI.
 */
public class GitFlowAdapterFactory implements IAdapterFactory {
	@Override
	public Repository getAdapter(Object adaptableObject, Class adapterType) {
		Repository repository = null;
		if (adaptableObject instanceof IResource) {
			IResource resource = (IResource) adaptableObject;
			repository = getRepository(resource);
		} else if (adaptableObject instanceof IHistoryView) {
			IHistoryView historyView = (IHistoryView) adaptableObject;
			IHistoryPage historyPage = historyView.getHistoryPage();
			Object input = historyPage.getInput();
			if (input instanceof RepositoryNode) {
				RepositoryNode node = (RepositoryNode) input;
				repository = node.getRepository();
			} else if (input instanceof IResource) {
				repository = getRepository((IResource) input);
			}
		} else {
			throw new IllegalStateException();
		}

		return repository;
	}

	private Repository getRepository(IResource resource) {
		return getMapping(resource.getProject()).getRepository();
	}

	@Override
	public Class[] getAdapterList() {
		return new Class[] { IResource.class, IHistoryView.class };
	}
}

@@ -629,15 +629,8 @@
 ort 
-static 
 org.
@@ -676,19 +676,8 @@
 ping
-.getMapping
 ;%0Aim
@@ -1863,48 +1863,128 @@
 %7B%0A%09%09
-return getMapping(resource.getProject())
+RepositoryMapping mapping = RepositoryMapping%0A%09%09%09%09.getMapping(resource.getProject());%0A%09%09return mapping != null ? mapping
 .get
@@ -1995,16 +1995,23 @@
 sitory()
+ : null
 ;%0A%09%7D%0A%0A%09@

Fix NPE in GitFlowAdapterFactory