Skip to content

remove repository update capability #2938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -226,20 +225,6 @@ boolean getHistoryGet(
return false;
}

@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());
List<String> cmd = new ArrayList<>();

cmd.add(RepoCommand);
cmd.add("update");

Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}

@Override
boolean fileHasHistory(File file) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,30 +167,6 @@ public boolean fileHasAnnotation(File file) {
return true;
}

@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());

List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("info");
Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}

if (executor.getOutputString().contains("parent branch:")) {
cmd.clear();
cmd.add(RepoCommand);
cmd.add("up");
executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}
}

@Override
public boolean fileHasHistory(File file) {
// Todo: is there a cheap test for whether Bazaar has history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,6 @@ public void buildTagList(File directory, boolean interactive) {
}
}

/* Update Stuff */

@Override
public void update() {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
String determineCurrentVersion(boolean interactive) throws IOException {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,6 @@ public boolean isRepositoryFor(File file, boolean interactive) {
return false;
}

@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());

List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("update");
Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}

@Override
String determineBranch(boolean interactive) throws IOException {
String branch = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
*/
package org.opengrok.indexer.history;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -177,44 +175,6 @@ public boolean fileHasAnnotation(File file) {
return true;
}

@SuppressWarnings("PMD.EmptyWhileStmt")
@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());

// Check if this is a snapshot view
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
String[] argv = {RepoCommand, "catcs"};
Executor executor = new Executor(Arrays.asList(argv), directory);
int status = executor.exec();
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed to determine if {0} is snapshot view",
directory);
return;
}
boolean snapshot = false;
String line;
try (BufferedReader in = new BufferedReader(
new InputStreamReader(executor.getOutputStream()))) {
while (!snapshot && (line = in.readLine()) != null) {
snapshot = line.startsWith("load");
}
}

if (snapshot) {
// It is a snapshot view, we need to update it manually
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv = new String[]{RepoCommand, "update", "-overwrite", "-f"};
executor = new Executor(Arrays.asList(argv), directory);
try (BufferedReader in = new BufferedReader(
new InputStreamReader(executor.getOutputStream()))) {
while ((line = in.readLine()) != null) {
// do nothing
}
}
}
}

@Override
public boolean fileHasHistory(File file) {
// Todo: is there a cheap test for whether ClearCase has history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,32 +487,6 @@ public boolean fileHasAnnotation(File file) {
return true;
}

@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("config");
cmd.add("--list");

Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}

if (executor.getOutputString().contains("remote.origin.url=")) {
cmd.clear();
cmd.add(RepoCommand);
cmd.add("pull");
cmd.add("-n");
cmd.add("-q");
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}
}

@Override
public boolean fileHasHistory(File file) {
// Todo: is there a cheap test for whether Git has history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,69 +506,6 @@ public Collection<RepositoryInfo> getRepositories() {
map(ri -> new RepositoryInfo(ri)).collect(Collectors.toSet());
}

/**
* Update the source contents in all repositories.
*/
public void updateRepositories() {
for (Map.Entry<String, Repository> entry : repositories.entrySet()) {
Repository repository = entry.getValue();

String path = entry.getKey();
String type = repository.getClass().getSimpleName();

if (repository.isWorking()) {
LOGGER.info(String.format("Update %s repository in %s",
type, path));

try {
repository.update();
} catch (UnsupportedOperationException e) {
LOGGER.warning(String.format("Skipping update of %s repository"
+ " in %s: Not implemented", type, path));
} catch (Exception e) {
LOGGER.log(Level.WARNING, "An error occurred while updating "
+ path + " (" + type + ")", e);
}
} else {
LOGGER.warning(String.format("Skipping update of %s repository in "
+ "%s: Missing SCM dependencies?", type, path));
}
}
}

/**
* Update the source contents in given repositories.
*
* @param paths A list of files/directories to update
*/
public void updateRepositories(Collection<String> paths) {
List<Repository> repos = getReposFromString(paths);

for (Repository repository : repos) {
String type = repository.getClass().getSimpleName();

if (repository.isWorking()) {
LOGGER.info(String.format("Update %s repository in %s", type,
repository.getDirectoryName()));

try {
repository.update();
} catch (UnsupportedOperationException e) {
LOGGER.warning(String.format("Skipping update of %s repository"
+ " in %s: Not implemented", type,
repository.getDirectoryName()));
} catch (Exception e) {
LOGGER.log(Level.WARNING, "An error occurred while updating "
+ repository.getDirectoryName() + " (" + type + ")", e);
}
} else {
LOGGER.warning(String.format("Skipping update of %s repository in"
+ " %s: Missing SCM dependencies?", type,
repository.getDirectoryName()));
}
}
}

private void createCache(Repository repository, String sinceRevision) {
String path = repository.getDirectoryName();
String type = repository.getClass().getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,31 +442,6 @@ public boolean fileHasAnnotation(File file) {
return true;
}

@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());

List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("showconfig");
Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}

if (executor.getOutputString().contains("paths.default=")) {
cmd.clear();
cmd.add(RepoCommand);
cmd.add("pull");
cmd.add("-u");
executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}
}

@Override
public boolean fileHasHistory(File file) {
// Todo: is there a cheap test for whether mercurial has history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,6 @@ public boolean fileHasAnnotation(File file) {
return true;
}

@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);

List<String> cmd = new ArrayList<>();
cmd.add(RepoCommand);
cmd.add("pull");
cmd.add(getQuietOption());
Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}

cmd.clear();
cmd.add(RepoCommand);
cmd.add("update");
cmd.add(getQuietOption());
executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}

@Override
public boolean fileHasHistory(File file) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,6 @@ boolean getHistoryGet(
return false;
}

@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());

List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("sync");
Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}

@Override
boolean fileHasHistory(File file) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ static IOException wrapInIOException(String message, Throwable t) {
return ioe;
}

@Override
void update() throws IOException {
throw new IOException("Not supported yet.");
}

@Override
boolean isRepositoryFor(File file, boolean interactive) {
File rcsDir = new File(file, "RCS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,6 @@ boolean fileHasAnnotation(File file) {
}
}

@Override
void update() {
throw new UnsupportedOperationException("Not supported yet.");
}

private File pathTranslation(File file, String intermediateElements,
String filePrefix, String fileSuffix) throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.opengrok.indexer.util.BufferSink;
import org.opengrok.indexer.util.Executor;

/**
* Access to a Git repository.
Expand Down Expand Up @@ -63,20 +60,6 @@ public boolean isWorking() {
return true;
}

@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("sync");

Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}

@Override
boolean isRepositoryFor(File file, boolean interactive) {
if (file.isDirectory()) {
Expand Down
Loading