项目:flow-platform
文件:JGitBasedClient.java
@Override
public File clone(String branch,Set<String> checkoutFiles,ProgressMonitor monitor) throws GitException {
checkGitUrl();
File gitDir = getGitPath().toFile();
// delete existing git folder since may have conflict
if (gitDir.exists()) {
try {
FileUtils.delete(gitDir.getParentFile(),FileUtils.RECURSIVE);
} catch (IOException e) {
// IO error on delete existing folder
}
}
// git init
initGit(checkoutFiles);
pull(branch,monitor);
return gitDir;
}
项目:JGitFX
文件:GitHelper.java
/**
*
* Clones a git repository using the given uri and stores it in the parent directory. Checks out the
* given reference or (if value is null) does not check out a branch
* (which reduces time needed to complete command).
* @param cloneURI the uri to the remote repository
* @param parentDirectory the directory in which to store the git Meta directory (".git" directory)
* @param checkoutRef the ref name ("refs/heads/master"),branch name ("master") or tag name ("v1.2.3"). If
* {@code null} is passed,will not checkout a branch.
* @param branchesToClone the branches to clone or all branches if passed a {@code null} value.
* @param monitor reports the progress of the clone command; can be null
* @return the cloned Git repository
* @throws GitAPIException
*/
public static Git cloneRepo(String cloneURI,File parentDirectory,String remoteName,String checkoutRef,List<String> branchesToClone,ProgressMonitor monitor) throws GitAPIException {
CloneCommand clone = Git.cloneRepository();
if (checkoutRef == null) {
clone.setNoCheckout(true);
} else {
clone.setBranch(checkoutRef);
}
if (branchesToClone == null) {
clone.setCloneAllBranches(true);
} else {
clone.setBranchesToClone(branchesToClone);
}
if (monitor != null) { clone.setProgressMonitor(monitor); }
return clone
.setURI(cloneURI)
.setDirectory(parentDirectory)
.setRemote(remoteName)
.call();
}
项目:gerrit
文件:AllChangesIndexer.java
@Override
public Result indexAll(ChangeIndex index) {
ProgressMonitor pm = new TextProgressMonitor();
pm.beginTask("Collecting projects",ProgressMonitor.UNKNowN);
SortedSet<ProjectHolder> projects = new TreeSet<>();
int changeCount = 0;
Stopwatch sw = Stopwatch.createStarted();
for (Project.NameKey name : projectCache.all()) {
try (Repository repo = repoManager.openRepository(name)) {
long size = estimateSize(repo);
changeCount += size;
projects.add(new ProjectHolder(name,size));
} catch (IOException e) {
log.error("Error collecting projects",e);
return new Result(sw,false,0);
}
pm.update(1);
}
pm.endTask();
setTotalWork(changeCount);
return indexAll(index,projects);
}
项目:gerrit
文件:Schema_154.java
@Override
protected void migrateData(ReviewDb db,UpdateUI ui) throws OrmException,sqlException {
try {
try (Repository repo = repoManager.openRepository(allUsersName)) {
ProgressMonitor pm = new TextProgressMonitor();
pm.beginTask("Collecting accounts",ProgressMonitor.UNKNowN);
Set<Account> accounts = scanAccounts(db,pm);
pm.endTask();
pm.beginTask("Migrating accounts to NoteDb",accounts.size());
for (Account account : accounts) {
updateAccountInNoteDb(repo,account);
pm.update(1);
}
pm.endTask();
}
} catch (IOException | ConfigInvalidException e) {
throw new OrmException("Migrating accounts to NoteDb Failed",e);
}
}
项目:gerrit
文件:Schema_154.java
private Set<Account> scanAccounts(ReviewDb db,ProgressMonitor pm) throws sqlException {
try (Statement stmt = newStatement(db);
ResultSet rs =
stmt.executeQuery(
"SELECT account_id,"
+ " registered_on,"
+ " full_name,"
+ " preferred_email,"
+ " status,"
+ " inactive"
+ " FROM accounts")) {
Set<Account> s = new HashSet<>();
while (rs.next()) {
Account a = new Account(new Account.Id(rs.getInt(1)),rs.getTimestamp(2));
a.setFullName(rs.getString(3));
a.setPreferredEmail(rs.getString(4));
a.setStatus(rs.getString(5));
a.setActive(rs.getString(6).equals("N"));
s.add(a);
pm.update(1);
}
return s;
}
}
项目:gerrit
文件:Schema_160.java
@Override
protected void migrateData(ReviewDb db,UpdateUI ui) throws OrmException {
try {
try (Repository repo = repoManager.openRepository(allUsersName)) {
ProgressMonitor pm = new TextProgressMonitor();
pm.beginTask("Removing \"My Drafts\" menu items",ProgressMonitor.UNKNowN);
for (Account.Id id : (Iterable<Account.Id>) Accounts.readUserRefs(repo)::iterator) {
if (removeMyDrafts(repo,id)) {
pm.update(1);
}
}
pm.endTask();
}
} catch (IOException | ConfigInvalidException e) {
throw new OrmException("Removing \"My Drafts\" menu items Failed",e);
}
}
@Override
public void doImport(ProgressMonitor progress)
throws GitCloneFailedException,GitDestinationAlreadyExistsException,GitDestinationNotWritableException {
CloneCommand clone = new CloneCommand();
clone.setCredentialsProvider(getRepository().getCredentialsProvider());
String sourceUri = getSourceUri();
clone.setURI(sourceUri);
clone.setBare(true);
clone.setDirectory(destinationDirectory);
if (progress != null) {
clone.setProgressMonitor(progress);
}
try {
LOG.info(sourceUri + "| Clone into " + destinationDirectory);
clone.call();
} catch (Throwable e) {
throw new GitCloneFailedException(sourceUri,e);
}
}
项目:plugins_github
文件:CreateProjectStep.java
@Override
public void doImport(ProgressMonitor progress) throws Exception {
MetaDataUpdate md = null;
try {
md = MetaDataUpdateFactory.create(getProjectNameKey());
projectConfig = ProjectConfig.read(md);
progress.beginTask("Configure Gerrit project",2);
setProjectSettings();
progress.update(1);
setProjectPermissions();
progress.update(1);
md.setMessage("Imported from " + getSourceUri());
projectConfig.commit(md);
projectCache.onCreateProject(getProjectNameKey());
} finally {
if (md != null) {
md.close();
}
progress.endTask();
}
}
项目:mOrgAnd
文件:JGitWrapper.java
private void createNewRepo(ProgressMonitor monitor) throws GitAPIException,IllegalArgumentException {
File localRepo = new File(localPath);
if (localRepo.exists()) // Safety check so we don't accidentally delete directory
throw new IllegalStateException("Directory already exists");
try {
CloneCommand cloneCommand = Git.cloneRepository()
.setCredentialsProvider(credentialsProvider)
.setURI(remotePath)
.setBranch(branch)
.setDirectory(localRepo)
.setBare(false);
if (monitor != null)
cloneCommand.setProgressMonitor(monitor);
cloneCommand.call();
} catch (GitAPIException e) {
FileUtils.deleteDirectory(localRepo);
throw e;
}
}
项目:csap-core
文件:SourceControlManager.java
private ProgressMonitor gitMonitor ( Writer w ) {
return new TextProgressMonitor( w ) {
};
// return new ProgressMonitor() {
//
// @Override
// public void update ( int completed ) {
// // Todo Auto-generated method stub
// logger.info( "items completed: {}",completed );
// }
//
// @Override
// public void start ( int totalTasks ) {
// // Todo Auto-generated method stub
//
// }
//
// @Override
// public boolean isCancelled () {
// // Todo Auto-generated method stub
// return false;
// }
//
// @Override
// public void endTask () {
// // Todo Auto-generated method stub
//
// }
//
// @Override
// public void beginTask ( String title,int totalWork ) {
// // Todo Auto-generated method stub
// logger.info( "progress: {},items remaining: {}",title,totalWork );
//
// }
// } ;
}
项目:flow-platform
文件:GitLabClient.java
@Override
public String fetch(String branch,String filePath,ProgressMonitor monitor) throws GitException {
checkProject();
try {
GitlabRepositoryFile file = connect.getRepositoryFile(project,filePath,branch);
String base64Content = file.getContent();
byte[] contentBytes = Base64.getDecoder().decode(base64Content);
return new String(contentBytes,"UTF-8");
} catch (IOException e) {
return null;
}
}
项目:flow-platform
文件:JGitBasedClient.java
@Override
public String fetch(String branch,ProgressMonitor monitor) throws GitException {
clone(branch,Sets.newHashSet(filePath),monitor);
Path targetPath = Paths.get(targetDir.toString(),filePath);
if (Files.exists(targetPath)) {
try {
return com.google.common.io.Files.toString(targetPath.toFile(),Charset.forName("UTF-8"));
} catch (IOException e) {
return null;
}
}
return null;
}
项目:flow-platform
文件:JGitBasedClient.java
@Override
public void pull(String branch,ProgressMonitor monitor) throws GitException {
try (Git git = gitopen()) {
PullCommand pullCommand = pullCommand(branch,git);
if (monitor != null) {
pullCommand.setProgressMonitor(monitor);
} else {
pullCommand.setProgressMonitor(new DebugProgressMonitor());
}
pullCommand.call();
} catch (Throwable e) {
throw new GitException("Fail to pull with specific files: " + ExceptionUtil.findRootCause(e).getMessage());
}
}
项目:JGitFX
文件:GitHelper.java
private static void setupMergeCommand(MergeCommand merge,List<Ref> commitsByRef,List<AnyObjectId> commitsById,List<NamedCommit> commitsByNameAndId,ProgressMonitor monitor,MergeStrategy strategy,MergeCommand.FastForwardMode fastForwardMode) {
commitsByRef.forEach(merge::include);
commitsById.forEach(merge::include);
commitsByNameAndId.forEach(nc -> merge.include(nc.getName(),nc.getobjectId()));
if (monitor != null) { merge.setProgressMonitor(monitor); }
merge
.setFastForward(fastForwardMode)
.setStrategy(strategy);
}
项目:JGitFX
文件:GitHelper.java
public static MergeResult mergeWithSquash(Git git,MergeCommand.FastForwardMode fastForwardMode,ProgressMonitor monitor) throws GitAPIException {
MergeCommand merge = git.merge();
setupMergeCommand(merge,commitsByRef,commitsById,commitsByNameAndId,monitor,strategy,fastForwardMode);
return merge
.setStrategy(strategy)
.setFastForward(fastForwardMode)
.setSquash(true)
.call();
}
项目:JGitFX
文件:GitHelper.java
public static MergeResult mergeWithoutCommit(Git git,fastForwardMode);
return merge
.setStrategy(strategy)
.setFastForward(fastForwardMode)
.setCommit(false)
.call();
}
项目:JGitFX
文件:GitHelper.java
public static MergeResult mergeWithCommit(Git git,String commitMessage,fastForwardMode);
return git.merge()
.setMessage(commitMessage) // message to be used for merge commit
.call();
}
项目:JGitFX
文件:GitHelper.java
/**
* Pulls from the given repository and merges changes from the given remote branch into
* the local checked-out branch using the given strategy. Progress is reported via the {@code monitor}.
* @param git the git repository
* @param strategy the merge strategy:
* @param remoteName the name of the repository
* @param branchName the name of the remote branch
* @param monitor reports the progress of the pull
* @return result of the pull
* @throws GitAPIException
*/
public static PullResult pullWithMerge(Git git,String branchName,ProgressMonitor monitor) throws GitAPIException {
PullCommand pull = git.pull();
if (monitor != null) { pull.setProgressMonitor(monitor); }
return pull
.setStrategy(strategy)
.setRemote(remoteName) // value -> current branch config -> DEFAULT_REMOTE_NAME = "origin"
.setRemoteBranchName(branchName) // value -> current branch config -> current branch name
.call();
}
项目:JGitFX
文件:GitHelper.java
/**
* Pulls from the given repository and rebases the currently checked-out branch onto the given remote branch
* and includes a report on the progress of the pull.
* @param git the git repository
* @param remoteName the name of the remote repository
* @param branchName the name of the branch on which to rebase the current branch
* @param monitor reports the progress of the pull
* @return result of the pull
* @throws GitAPIException
*/
public static PullResult pullWithRebase(Git git,ProgressMonitor monitor) throws GitAPIException {
PullCommand pull = git.pull();
if (monitor != null) { pull.setProgressMonitor(monitor); }
return pull
.setRebase(true) // when true,ignores merge strategy
.setRemote(remoteName) // value -> current branch config -> DEFAULT_REMOTE_NAME = "origin"
.setRemoteBranchName(branchName) // value -> current branch config -> current branch name
.setProgressMonitor(monitor)
.call();
}
项目:gerrit
文件:ProtobufImport.java
@Override
public int run() throws Exception {
mustHaveValidSite();
Injector dbInjector = createDbInjector(SINGLE_USER);
manager.add(dbInjector);
manager.start();
RuntimeShutdown.add(manager::stop);
dbInjector.injectMembers(this);
ProgressMonitor progress = new TextProgressMonitor();
progress.beginTask("Importing entities",ProgressMonitor.UNKNowN);
try (ReviewDb db = schemaFactory.open()) {
for (RelationModel model : new JavaSchemaModel(ReviewDb.class).getRelations()) {
relations.put(model.getRelationID(),Relation.create(model,db));
}
Parser<UnkNownFieldSet> parser = UnkNownFieldSet.getDefaultInstance().getParserForType();
try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
UnkNownFieldSet msg;
while ((msg = parser.parseDelimitedFrom(in)) != null) {
Map.Entry<Integer,UnkNownFieldSet.Field> e =
Iterables.getonlyElement(msg.asMap().entrySet());
Relation rel =
checkNotNull(
relations.get(e.getKey()),"unkNown relation ID %s in message: %s",e.getKey(),msg);
List<ByteString> values = e.getValue().getLengthDelimitedList();
checkState(values.size() == 1,"expected one string field in message: %s",msg);
upsert(rel,values.get(0));
progress.update(1);
}
}
progress.endTask();
}
return 0;
}
项目:gerrit
文件:LocalUsernamesToLowerCase.java
private int reindexAccounts() throws Exception {
monitor.beginTask("Reindex accounts",ProgressMonitor.UNKNowN);
String[] reindexArgs = {
"--site-path",getSitePath().toString(),"--index",AccountSchemaDeFinitions.NAME
};
System.out.println("Migration complete,reindexing accounts with:");
System.out.println(" reindex " + String.join(" ",reindexArgs));
Reindex reindexpgm = new Reindex();
int exitCode = reindexpgm.main(reindexArgs);
monitor.endTask();
return exitCode;
}
项目:gerrit
文件:SiteIndexer.java
private ErrorListener(
ListenableFuture<?> future,String desc,ProgressMonitor progress,AtomicBoolean ok) {
this.future = future;
this.desc = desc;
this.progress = progress;
this.ok = ok;
}
项目:gerrit
文件:AllProjectsIndexer.java
@Override
public SiteIndexer.Result indexAll(final ProjectIndex index) {
ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
progress.start(2);
List<Project.NameKey> names = collectProjects(progress);
return reindexProjects(index,names,progress);
}
项目:gerrit
文件:AllProjectsIndexer.java
private List<Project.NameKey> collectProjects(ProgressMonitor progress) {
progress.beginTask("Collecting projects",ProgressMonitor.UNKNowN);
List<Project.NameKey> names = new ArrayList<>();
for (Project.NameKey nameKey : projectCache.all()) {
names.add(nameKey);
}
progress.endTask();
return names;
}
项目:gerrit
文件:AllGroupsIndexer.java
@Override
public SiteIndexer.Result indexAll(GroupIndex index) {
ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
progress.start(2);
Stopwatch sw = Stopwatch.createStarted();
List<AccountGroup.UUID> uuids;
try {
uuids = collectGroups(progress);
} catch (OrmException e) {
log.error("Error collecting groups",e);
return new SiteIndexer.Result(sw,0);
}
return reindexGroups(index,uuids,progress);
}
项目:gerrit
文件:AllGroupsIndexer.java
项目:gerrit
文件:AllAccountsIndexer.java
@Override
public SiteIndexer.Result indexAll(AccountIndex index) {
ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
progress.start(2);
Stopwatch sw = Stopwatch.createStarted();
List<Account.Id> ids;
try {
ids = collectAccounts(progress);
} catch (IOException e) {
log.error("Error collecting accounts",0);
}
return reindexAccounts(index,ids,progress);
}
项目:gerrit
文件:AllAccountsIndexer.java
private List<Account.Id> collectAccounts(ProgressMonitor progress) throws IOException {
progress.beginTask("Collecting accounts",ProgressMonitor.UNKNowN);
List<Account.Id> ids = new ArrayList<>();
for (Account.Id accountId : accounts.allIds()) {
ids.add(accountId);
progress.update(1);
}
progress.endTask();
return ids;
}
项目:gerrit
文件:AllChangesIndexer.java
项目:plugins_github
文件:ReplicateProjectStep.java
@Override
public void doImport(ProgressMonitor progress) throws Exception {
progress.beginTask("Setting up Gerrit replication",2);
String repositoryName = getorganisation() + "/" + getRepositoryName();
progress.update(1);
replicationConfig.addSecureCredentials(authUsername,authToken);
progress.update(1);
replicationConfig.addReplicationRemote(
authUsername,gitHubUrl + "/${name}.git",repositoryName);
progress.endTask();
}
项目:mOrgAnd
文件:JGitWrapper.java
private Git initGitRepo(ProgressMonitor monitor) throws Exception {
if (new File(localPath).exists() == false)
createNewRepo(monitor);
FileRepository fileRepository = new FileRepository(localPath + "/.git");
return new Git(fileRepository);
}
项目:mOrgAnd
文件:JGitWrapper.java
public Git getGit(ProgressMonitor monitor) throws Exception {
if (this.git == null)
this.git = initGitRepo(monitor);
boolean hasConflicts = false;
try {
hasConflicts = this.git.status().call().getConflicting().isEmpty() == false;
} catch (Exception ex) {}
if (hasConflicts)
throw new IllegalStateException("Unresolved conflict(s) in git repository");
return this.git;
}
项目:mOrgAnd
文件:JGitWrapper.java
public void updateChanges(ProgressMonitor monitor) throws Exception {
Git git = getGit(monitor);
FetchCommand fetch = git.fetch();
fetch.setCredentialsProvider(credentialsProvider);
if (monitor != null)
fetch.setProgressMonitor(monitor);
fetch.call();
SyncState state = getSyncState(git);
Ref fetchHead = git.getRepository().getRef("FETCH_HEAD");
switch (state) {
case Equal:
// Do nothing
Log.d("Git","Local branch is up-to-date");
break;
case Ahead:
Log.d("Git","Local branch ahead,pushing changes to remote");
git.push().setCredentialsProvider(credentialsProvider).setRemote(remotePath).call();
break;
case Behind:
Log.d("Git","Local branch behind,fast forwarding changes");
MergeResult result = git.merge().include(fetchHead).setFastForward(MergeCommand.FastForwardMode.FF_ONLY).call();
if (result.getMergeStatus().isSuccessful() == false)
throw new IllegalStateException("Fast forward Failed on behind merge");
break;
case diverged:
Log.d("Git","Branches are diverged,merging with strategy " + mergeStrategy.getName());
MergeResult mergeResult = git.merge().include(fetchHead).setStrategy(mergeStrategy).call();
if (mergeResult.getMergeStatus().isSuccessful()) {
git.push().setCredentialsProvider(credentialsProvider).setRemote(remotePath).call();
} else
throw new IllegalStateException("Merge Failed for diverged branches using strategy " + mergeStrategy.getName());
break;
}
}
@Override
public void update(int i) {
mWorkDone += i;
if (mTotalWork != ProgressMonitor.UNKNowN && mTotalWork != 0 && mTotalWork - mLastProgress >= 1) {
setProgress();
mLastProgress = mWorkDone;
}
}
项目:incubator-netbeans
文件:DelegatingProgressMonitor.java
public DelegatingProgressMonitor (org.netbeans.libs.git.progress.ProgressMonitor monitor) {
this.monitor = monitor;
}
项目:centraldogma
文件:GitWithAuth.java
private ProgressMonitor progressMonitor(String name) {
return progressMonitors.computeIfAbsent(name,MirrorProgressMonitor::new);
}
项目:flow-platform
文件:GitLabClient.java
@Override
public File clone(String branch,ProgressMonitor monitor) throws GitException {
throw new UnsupportedOperationException("Git clone not supported for GitLab");
}
项目:flow-platform
文件:GitLabClient.java
@Override
public void pull(String branch,ProgressMonitor monitor) throws GitException {
throw new UnsupportedOperationException("Pull not supported for GitLab");
}
项目:gerrit
文件:SiteIndexer.java
protected final void addErrorListener(
ListenableFuture<?> future,AtomicBoolean ok) {
future.addListener(
new ErrorListener(future,desc,progress,ok),MoreExecutors.directExecutor());
}
项目:gerrit
文件:ChangeProgressOp.java
ChangeProgressOp(ProgressMonitor progress) {
this.progress = progress;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。