List of usage examples for org.eclipse.jgit.lib CommitBuilder getMessage
public String getMessage()
From source file:com.amd.gerrit.plugins.manifestsubscription.VersionedManifests.java
License:Open Source License
@Override protected boolean onSave(CommitBuilder commit) throws IOException { StringBuilder commitMsg = new StringBuilder(); commitMsg.append("Snapshot manifest from " + srcManifestRepo + " updated\n\n"); if (extraCommitMsg != null && extraCommitMsg.length() > 0) { commitMsg.append(extraCommitMsg); }// w w w . j a va2s . c om String path; Manifest manifest; for (Map.Entry<String, Manifest> entry : manifests.entrySet()) { path = entry.getKey(); manifest = entry.getValue(); try { saveManifest(path, manifest); } catch (JAXBException e) { throw new IOException(e); } } // For some reason the default author and committer date is // invalid (always the same date and time) Date date = new Date(); commit.setAuthor(new PersonIdent(commit.getAuthor(), date)); commit.setCommitter(new PersonIdent(commit.getCommitter(), date)); if (commit.getMessage() == null || "".equals(commit.getMessage())) { commit.setMessage(commitMsg.toString()); } return true; }
From source file:com.google.gerrit.gpg.PublicKeyStore.java
License:Apache License
/** * Save pending keys to the store./*from w w w . j a v a 2 s .c o m*/ * <p> * One commit is created and the ref updated. The pending list is cleared if * and only if the ref update succeeds, which allows for easy retries in case * of lock failure. * * @param cb commit builder with at least author and identity populated; tree * and parent are ignored. * @return result of the ref update. */ public RefUpdate.Result save(CommitBuilder cb) throws PGPException, IOException { if (toAdd.isEmpty() && toRemove.isEmpty()) { return RefUpdate.Result.NO_CHANGE; } if (reader == null) { load(); } if (notes == null) { notes = NoteMap.newEmptyMap(); } ObjectId newTip; try (ObjectInserter ins = repo.newObjectInserter()) { for (PGPPublicKeyRing keyRing : toAdd.values()) { saveToNotes(ins, keyRing); } for (Fingerprint fp : toRemove) { deleteFromNotes(ins, fp); } cb.setTreeId(notes.writeTree(ins)); if (cb.getTreeId().equals(tip != null ? tip.getTree() : EMPTY_TREE)) { return RefUpdate.Result.NO_CHANGE; } if (tip != null) { cb.setParentId(tip); } if (cb.getMessage() == null) { int n = toAdd.size() + toRemove.size(); cb.setMessage(String.format("Update %d public key%s", n, n != 1 ? "s" : "")); } newTip = ins.insert(cb); ins.flush(); } RefUpdate ru = repo.updateRef(PublicKeyStore.REFS_GPG_KEYS); ru.setExpectedOldObjectId(tip); ru.setNewObjectId(newTip); ru.setRefLogIdent(cb.getCommitter()); ru.setRefLogMessage("Store public keys", true); RefUpdate.Result result = ru.update(); reset(); switch (result) { case FAST_FORWARD: case NEW: case NO_CHANGE: toAdd.clear(); toRemove.clear(); break; default: break; } return result; }
From source file:com.google.gerrit.pgm.init.VersionedAuthorizedKeysOnInit.java
License:Apache License
@Override protected boolean onSave(CommitBuilder commit) throws IOException { if (Strings.isNullOrEmpty(commit.getMessage())) { commit.setMessage("Updated SSH keys\n"); }//from w w w . ja v a2 s. com saveUTF8(AuthorizedKeys.FILE_NAME, AuthorizedKeys.serialize(keys)); return true; }
From source file:com.google.gerrit.server.account.VersionedAccountPreferences.java
License:Apache License
@Override protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException { if (Strings.isNullOrEmpty(commit.getMessage())) { commit.setMessage("Updated preferences\n"); }/*from w ww . j a v a 2 s . co m*/ saveConfig(PREFERENCES, cfg); return true; }
From source file:com.google.gerrit.server.account.WatchConfig.java
License:Apache License
@Override protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException { checkLoaded();//from w w w . j av a 2s . co m if (Strings.isNullOrEmpty(commit.getMessage())) { commit.setMessage("Updated watch configuration\n"); } Config cfg = readConfig(WATCH_CONFIG); for (String projectName : cfg.getSubsections(PROJECT)) { cfg.unsetSection(PROJECT, projectName); } ListMultimap<String, String> notifyValuesByProject = MultimapBuilder.hashKeys().arrayListValues().build(); for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : projectWatches.entrySet()) { NotifyValue notifyValue = NotifyValue.create(e.getKey().filter(), e.getValue()); notifyValuesByProject.put(e.getKey().project().get(), notifyValue.toString()); } for (Map.Entry<String, Collection<String>> e : notifyValuesByProject.asMap().entrySet()) { cfg.setStringList(PROJECT, e.getKey(), KEY_NOTIFY, new ArrayList<>(e.getValue())); } saveConfig(WATCH_CONFIG, cfg); return true; }
From source file:com.google.gerrit.server.git.ProjectConfig.java
License:Apache License
@Override protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException { if (commit.getMessage() == null || "".equals(commit.getMessage())) { commit.setMessage("Updated project configuration\n"); }/*from w ww .j av a 2s. c o m*/ Config rc = readConfig(PROJECT_CONFIG); Project p = project; if (p.getDescription() != null && !p.getDescription().isEmpty()) { rc.setString(PROJECT, null, KEY_DESCRIPTION, p.getDescription()); } else { rc.unset(PROJECT, null, KEY_DESCRIPTION); } set(rc, ACCESS, null, KEY_INHERIT_FROM, p.getParentName()); set(rc, RECEIVE, null, KEY_REQUIRE_CONTRIBUTOR_AGREEMENT, p.getUseContributorAgreements(), InheritableBoolean.INHERIT); set(rc, RECEIVE, null, KEY_REQUIRE_SIGNED_OFF_BY, p.getUseSignedOffBy(), InheritableBoolean.INHERIT); set(rc, RECEIVE, null, KEY_REQUIRE_CHANGE_ID, p.getRequireChangeID(), InheritableBoolean.INHERIT); set(rc, RECEIVE, null, KEY_USE_ALL_NOT_IN_TARGET, p.getCreateNewChangeForAllNotInTarget(), InheritableBoolean.INHERIT); set(rc, RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT, validMaxObjectSizeLimit(p.getMaxObjectSizeLimit())); set(rc, RECEIVE, null, KEY_ENABLE_SIGNED_PUSH, p.getEnableSignedPush(), InheritableBoolean.INHERIT); set(rc, SUBMIT, null, KEY_ACTION, p.getSubmitType(), defaultSubmitAction); set(rc, SUBMIT, null, KEY_MERGE_CONTENT, p.getUseContentMerge(), InheritableBoolean.INHERIT); set(rc, PROJECT, null, KEY_STATE, p.getState(), defaultStateValue); set(rc, DASHBOARD, null, KEY_DEFAULT, p.getDefaultDashboard()); set(rc, DASHBOARD, null, KEY_LOCAL_DEFAULT, p.getLocalDefaultDashboard()); Set<AccountGroup.UUID> keepGroups = new HashSet<>(); saveAccountsSection(rc, keepGroups); saveContributorAgreements(rc, keepGroups); saveAccessSections(rc, keepGroups); saveNotifySections(rc, keepGroups); groupList.retainUUIDs(keepGroups); saveLabelSections(rc); savePluginSections(rc); saveConfig(PROJECT_CONFIG, rc); saveGroupList(); return true; }
From source file:com.google.gerrit.server.git.ProjectLevelConfig.java
License:Apache License
@Override protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException { if (commit.getMessage() == null || "".equals(commit.getMessage())) { commit.setMessage("Updated configuration\n"); }/*from ww w .java 2 s.c o m*/ saveConfig(fileName, cfg); return true; }
From source file:com.google.gerrit.server.git.VersionedMetaData.java
License:Apache License
/** * Open a batch of updates to the same metadata ref. * <p>/*from w w w . j a va 2s .com*/ * This allows making multiple commits to a single metadata ref, at the end of * which is a single ref update. For batching together updates to multiple * refs (each consisting of one or more commits against their respective * refs), create the {@link MetaDataUpdate} with a {@link BatchRefUpdate}. * <p> * A ref update produced by this {@link BatchMetaDataUpdate} is only committed * if there is no associated {@link BatchRefUpdate}. As a result, the * configured ref updated event is not fired if there is an associated batch. * * @param update helper info about the update. * @throws IOException if the update failed. */ public BatchMetaDataUpdate openUpdate(final MetaDataUpdate update) throws IOException { final Repository db = update.getRepository(); reader = db.newObjectReader(); inserter = db.newObjectInserter(); final RevWalk rw = new RevWalk(reader); final RevTree tree = revision != null ? rw.parseTree(revision) : null; newTree = readTree(tree); return new BatchMetaDataUpdate() { AnyObjectId src = revision; AnyObjectId srcTree = tree; @Override public void write(CommitBuilder commit) throws IOException { write(VersionedMetaData.this, commit); } private boolean doSave(VersionedMetaData config, CommitBuilder commit) throws IOException { DirCache nt = config.newTree; ObjectReader r = config.reader; ObjectInserter i = config.inserter; try { config.newTree = newTree; config.reader = reader; config.inserter = inserter; return config.onSave(commit); } catch (ConfigInvalidException e) { throw new IOException( "Cannot update " + getRefName() + " in " + db.getDirectory() + ": " + e.getMessage(), e); } finally { config.newTree = nt; config.reader = r; config.inserter = i; } } @Override public void write(VersionedMetaData config, CommitBuilder commit) throws IOException { if (!doSave(config, commit)) { return; } // Reuse tree from parent commit unless there are contents in newTree or // there is no tree for a parent commit. ObjectId res = newTree.getEntryCount() != 0 || srcTree == null ? newTree.writeTree(inserter) : srcTree.copy(); if (res.equals(srcTree) && !update.allowEmpty() && (commit.getTreeId() == null)) { // If there are no changes to the content, don't create the commit. return; } // If changes are made to the DirCache and those changes are written as // a commit and then the tree ID is set for the CommitBuilder, then // those previous DirCache changes will be ignored and the commit's // tree will be replaced with the ID in the CommitBuilder. The same is // true if you explicitly set tree ID in a commit and then make changes // to the DirCache; that tree ID will be ignored and replaced by that of // the tree for the updated DirCache. if (commit.getTreeId() == null) { commit.setTreeId(res); } else { // In this case, the caller populated the tree without using DirCache. res = commit.getTreeId(); } if (src != null) { commit.addParentId(src); } if (update.insertChangeId()) { ObjectId id = ChangeIdUtil.computeChangeId(res, getRevision(), commit.getAuthor(), commit.getCommitter(), commit.getMessage()); commit.setMessage(ChangeIdUtil.insertId(commit.getMessage(), id)); } src = inserter.insert(commit); srcTree = res; } @Override public RevCommit createRef(String refName) throws IOException { if (Objects.equals(src, revision)) { return revision; } return updateRef(ObjectId.zeroId(), src, refName); } @Override public void removeRef(String refName) throws IOException { RefUpdate ru = db.updateRef(refName); ru.setForceUpdate(true); if (revision != null) { ru.setExpectedOldObjectId(revision); } RefUpdate.Result result = ru.delete(); switch (result) { case FORCED: update.fireGitRefUpdatedEvent(ru); return; default: throw new IOException( "Cannot delete " + ru.getName() + " in " + db.getDirectory() + ": " + ru.getResult()); } } @Override public RevCommit commit() throws IOException { return commitAt(revision); } @Override public RevCommit commitAt(ObjectId expected) throws IOException { if (Objects.equals(src, expected)) { return revision; } return updateRef(MoreObjects.firstNonNull(expected, ObjectId.zeroId()), src, getRefName()); } @Override public void close() { newTree = null; rw.close(); if (inserter != null) { inserter.close(); inserter = null; } if (reader != null) { reader.close(); reader = null; } } private RevCommit updateRef(AnyObjectId oldId, AnyObjectId newId, String refName) throws IOException { BatchRefUpdate bru = update.getBatch(); if (bru != null) { bru.addCommand(new ReceiveCommand(oldId.toObjectId(), newId.toObjectId(), refName)); inserter.flush(); revision = rw.parseCommit(newId); return revision; } RefUpdate ru = db.updateRef(refName); ru.setExpectedOldObjectId(oldId); ru.setNewObjectId(src); ru.setRefLogIdent(update.getCommitBuilder().getAuthor()); String message = update.getCommitBuilder().getMessage(); if (message == null) { message = "meta data update"; } try (BufferedReader reader = new BufferedReader(new StringReader(message))) { // read the subject line and use it as reflog message ru.setRefLogMessage("commit: " + reader.readLine(), true); } inserter.flush(); RefUpdate.Result result = ru.update(); switch (result) { case NEW: case FAST_FORWARD: revision = rw.parseCommit(ru.getNewObjectId()); update.fireGitRefUpdatedEvent(ru); return revision; default: throw new IOException( "Cannot update " + ru.getName() + " in " + db.getDirectory() + ": " + ru.getResult()); } } }; }
From source file:com.googlesource.gerrit.plugins.lfs.LfsProjectsConfig.java
License:Apache License
@Override protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException { if (Strings.isNullOrEmpty(commit.getMessage())) { commit.setMessage("Update LFS configuration\n"); }// w ww. ja v a2 s. c om saveConfig(configFilename, projectConfig); projectCache.evict(allProjects); return true; }
From source file:com.googlesource.gerrit.plugins.reviewers.ReviewersConfig.java
License:Apache License
@Override protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException { if (Strings.isNullOrEmpty(commit.getMessage())) { commit.setMessage("Update reviewers configuration\n"); }//www .j a v a 2 s . c o m saveConfig(FILENAME, cfg); return true; }