List of usage examples for org.eclipse.jgit.lib Constants HEAD
String HEAD
To view the source code for org.eclipse.jgit.lib Constants HEAD.
Click Source Link
From source file:com.google.gerrit.server.schema.AllProjectsCreator.java
License:Apache License
public void create() throws IOException, ConfigInvalidException { try (Repository git = mgr.openRepository(allProjectsName)) { initAllProjects(git);/*ww w . ja v a 2 s. c o m*/ } catch (RepositoryNotFoundException notFound) { // A repository may be missing if this project existed only to store // inheritable permissions. For example 'All-Projects'. try (Repository git = mgr.createRepository(allProjectsName)) { initAllProjects(git); RefUpdate u = git.updateRef(Constants.HEAD); u.link(RefNames.REFS_CONFIG); } catch (RepositoryNotFoundException err) { String name = allProjectsName.get(); throw new IOException("Cannot create repository " + name, err); } } }
From source file:com.google.gerrit.server.schema.Schema_56.java
License:Apache License
@Inject Schema_56(Provider<Schema_55> prior, LocalDiskRepositoryManager mgr) { super(prior); this.mgr = mgr; keysOne = new HashSet<String>(); keysTwo = new HashSet<String>(); keysOne.add(GitRepositoryManager.REF_CONFIG); keysTwo.add(GitRepositoryManager.REF_CONFIG); keysTwo.add(Constants.HEAD); }
From source file:com.google.gerrit.server.schema.Schema_56.java
License:Apache License
@Override protected void migrateData(ReviewDb db, UpdateUI ui) { for (Project.NameKey name : mgr.list()) { Repository git;//from w w w. j av a 2 s . co m try { git = mgr.openRepository(name); } catch (RepositoryNotFoundException e) { ui.message("warning: Cannot open " + name.get()); continue; } try { Map<String, Ref> all = git.getAllRefs(); if (all.keySet().equals(keysOne) || all.keySet().equals(keysTwo)) { try { RefUpdate update = git.updateRef(Constants.HEAD); update.disableRefLog(); update.link(GitRepositoryManager.REF_CONFIG); } catch (IOException err) { ui.message("warning: " + name.get() + ": Cannot update HEAD to " + GitRepositoryManager.REF_CONFIG + ": " + err.getMessage()); } } } finally { git.close(); } } }
From source file:com.google.gerrit.server.tools.hooks.CommitMsgHookTest.java
License:Apache License
private void setHEAD() throws Exception { try (ObjectInserter oi = repository.newObjectInserter()) { final CommitBuilder commit = new CommitBuilder(); commit.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {})); commit.setAuthor(author);/*w w w. ja v a 2 s. c om*/ commit.setCommitter(committer); commit.setMessage("test\n"); ObjectId commitId = oi.insert(commit); final RefUpdate ref = repository.updateRef(Constants.HEAD); ref.setNewObjectId(commitId); Result result = ref.forceUpdate(); assert_().withFailureMessage(Constants.HEAD + " did not change: " + ref.getResult()).that(result) .isAnyOf(Result.FAST_FORWARD, Result.FORCED, Result.NEW, Result.NO_CHANGE); } }
From source file:com.google.gerrit.sshd.commands.CreateProject.java
License:Apache License
@Override public void start(final Environment env) { startThread(new CommandRunnable() { @Override/*from ww w . ja v a2 s . c om*/ public void run() throws Exception { PrintWriter p = toPrintWriter(out); parseCommandLine(); try { validateParameters(); nameKey = new Project.NameKey(projectName); final Repository repo = repoManager.createRepository(nameKey); try { RefUpdate u = repo.updateRef(Constants.HEAD); u.disableRefLog(); u.link(branch); createProject(); repoManager.setProjectDescription(nameKey, projectDescription); if (createEmptyCommit) { createEmptyCommit(repo, nameKey, branch); } rq.replicateNewProject(nameKey, branch); } finally { repo.close(); } } catch (Exception e) { p.print("Error when trying to create project: " + e.getMessage() + "\n"); p.flush(); } } }); }
From source file:com.google.gerrit.sshd.commands.CreateProject.java
License:Apache License
private void createEmptyCommit(final Repository repo, final Project.NameKey project, final String ref) throws IOException { ObjectInserter oi = repo.newObjectInserter(); try {/*from w w w . j av a2 s .c o m*/ CommitBuilder cb = new CommitBuilder(); cb.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {})); cb.setAuthor(metaDataUpdateFactory.getUserPersonIdent()); cb.setCommitter(serverIdent); cb.setMessage("Initial empty repository\n"); ObjectId id = oi.insert(cb); oi.flush(); RefUpdate ru = repo.updateRef(Constants.HEAD); ru.setNewObjectId(id); final Result result = ru.update(); switch (result) { case NEW: rq.scheduleUpdate(project, ref); break; default: { throw new IOException(result.name()); } } } catch (IOException e) { log.error("Cannot create empty commit for " + projectName, e); throw e; } finally { oi.release(); } }
From source file:com.google.gitiles.RefServlet.java
License:Open Source License
static List<Map<String, Object>> getBranchesSoyData(HttpServletRequest req, int limit) throws IOException { RefDatabase refdb = ServletUtils.getRepository(req).getRefDatabase(); Ref head = refdb.getRef(Constants.HEAD); Ref headLeaf = head != null && head.isSymbolic() ? head.getLeaf() : null; return getRefsSoyData(refdb, ViewFilter.getView(req), Constants.R_HEADS, branchComparator(headLeaf), headLeaf, limit);/*from www .j a v a 2 s . c o m*/ }
From source file:com.googlesource.gerrit.plugins.replication.Destination.java
License:Apache License
void schedule(Project.NameKey project, String ref, URIish uri, ReplicationState state) { repLog.info("scheduling replication {}:{} => {}", project, ref, uri); if (!shouldReplicate(project, ref, state)) { return;//from ww w.j ava 2 s .c o m } if (!config.replicatePermissions()) { PushOne e; synchronized (stateLock) { e = pending.get(uri); } if (e == null) { try (Repository git = gitManager.openRepository(project)) { try { Ref head = git.exactRef(Constants.HEAD); if (head != null && head.isSymbolic() && RefNames.REFS_CONFIG.equals(head.getLeaf().getName())) { return; } } catch (IOException err) { stateLog.error(String.format("cannot check type of project %s", project), err, state); return; } } catch (IOException err) { stateLog.error(String.format("source project %s not available", project), err, state); return; } } } synchronized (stateLock) { PushOne e = pending.get(uri); if (e == null) { e = opFactory.create(project, uri); pool.schedule(e, config.getDelay(), TimeUnit.SECONDS); pending.put(uri, e); } e.addRef(ref); state.increasePushTaskCount(project.get(), ref); e.addState(ref, state); repLog.info("scheduled {}:{} => {} to run after {}s", project, ref, e, config.getDelay()); } }
From source file:com.googlesource.gerrit.plugins.replication.PushOne.java
License:Apache License
private void createRepository() { if (pool.isCreateMissingRepos()) { try {/*from w w w .ja v a 2s. co m*/ Ref head = git.exactRef(Constants.HEAD); if (replicationQueue.createProject(projectName, head != null ? head.getName() : null)) { repLog.warn("Missing repository created; retry replication to " + uri); pool.reschedule(this, Destination.RetryReason.REPOSITORY_MISSING); } else { repLog.warn("Missing repository could not be created when replicating " + uri + ". You can only create missing repositories locally, over SSH or when " + "using adminUrl in replication.config. See documentation for more information."); } } catch (IOException ioe) { stateLog.error("Cannot replicate to " + uri + "; failed to create missing repository", ioe, getStatesAsArray()); } } else { stateLog.error("Cannot replicate to " + uri + "; repository not found", getStatesAsArray()); } }
From source file:com.googlesource.gerrit.plugins.replication.PushOne.java
License:Apache License
private List<RemoteRefUpdate> doPushAll(Transport tn, Map<String, Ref> local) throws NotSupportedException, TransportException, IOException { List<RemoteRefUpdate> cmds = new ArrayList<>(); boolean noPerms = !pool.isReplicatePermissions(); Map<String, Ref> remote = listRemote(tn); for (Ref src : local.values()) { if (!canPushRef(src.getName(), noPerms)) { continue; }/* ww w . ja va2 s . c o m*/ RefSpec spec = matchSrc(src.getName()); if (spec != null) { Ref dst = remote.get(spec.getDestination()); if (dst == null || !src.getObjectId().equals(dst.getObjectId())) { // Doesn't exist yet, or isn't the same value, request to push. push(cmds, spec, src); } } } if (config.isMirror()) { for (Ref ref : remote.values()) { if (!Constants.HEAD.equals(ref.getName())) { RefSpec spec = matchDst(ref.getName()); if (spec != null && !local.containsKey(spec.getSource())) { // No longer on local side, request removal. delete(cmds, spec); } } } } return cmds; }