/** * Method updateTargetFile. * * @param aFile IFile * @return IFile * @throws CoreException * @throws ReviewsFileStorageException */ public static R4EFileVersion updateTargetFile(IFile aFile) throws CoreException, ReviewsFileStorageException { if (null == aFile) { return null; // should never happen } String remoteID = null; String localID = null; // Get handle to local storage repository final IRFSRegistry localRepository = RFSRegistryFactory.getRegistry(R4EUIModelController.getActiveReview().getReview()); if (null == localRepository) { return null; } // Get Remote repository file info final ScmConnector connector = ScmCore.getConnector(aFile.getProject()); if (null != connector) { final ScmArtifact artifact = connector.getArtifact(aFile); if ((null != artifact) && (null != artifact.getPath())) { // File found in remote repo. // Here we check if the file in the remote repository is different than the input file. // We cannot use the artifact ID directly and we need to fetch and calculate that SHA of the // remote file // because we do not know which version control system is used. // We need to do this comparison because the versions always return the latest file stored. final IFileRevision fileRev = artifact.getFileRevision(null); if (null != fileRev) { final IStorage fileStore = fileRev.getStorage(null); if (null != fileStore) { remoteID = localRepository.blobIdFor(fileStore.getContents()); localID = localRepository.blobIdFor(aFile.getContents()); if ((null != remoteID) && remoteID.equals(localID)) { // The files are the same. Copy from the remote repo return copyRemoteFileToLocalRepository(localRepository, artifact); } } } // The files are different. This means the current user modified the file in his workspace return copyWorkspaceFileToLocalRepository(localRepository, aFile); } } // Else we copy the file that is in the current workspace return copyWorkspaceFileToLocalRepository(localRepository, aFile); }
@Override public ChangeSet getChangeSet(ScmRepository repository, IResource resource) { Assert.isNotNull(resource); final IProject project = resource.getProject(); Assert.isNotNull(project); // Resolve Git Scm connector final ScmConnector scmConnector = ScmCore.getConnector(resource); Assert.isNotNull(scmConnector); // Check if the provider is for Git if (!GitProvider.class.getName().equals(scmConnector.getProviderId())) { throw new RuntimeException("No Git connector: " + scmConnector.getProviderId()); } final GetChangeSetDialog dialog = new GetChangeSetDialog(null, project); final int result = dialog.open(); if (result == Window.OK) { return dialog.getChangeSet(); } // else Window.CANCEL return null; }
/** * Method updateBaseFile. * * @param aFile IFile * @return IFile * @throws CoreException * @throws ReviewsFileStorageException */ public static R4EFileVersion updateBaseFile(IFile aFile) throws CoreException, ReviewsFileStorageException { if (null == aFile) { return null; // should never happen } // Get Remote repository file info final ScmConnector connector = ScmCore.getConnector(aFile.getProject()); if (null != connector) { final ScmArtifact artifact = connector.getArtifact(aFile); if ((null != artifact) && (null != artifact.getId())) { // File was modified, so we need to fetch the base file from the versions repository and // copy it to our own local repository final IRFSRegistry localRepository = RFSRegistryFactory.getRegistry(R4EUIModelController.getActiveReview().getReview()); return copyRemoteFileToLocalRepository(localRepository, artifact); } } // else file not in source control // File was not modified, or No Version Control System or Remote File detected, so there is no // base return null; }