| | |
| | | import java.text.MessageFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | |
| | | import org.eclipse.jgit.lib.ObjectId; |
| | | import org.eclipse.jgit.lib.ObjectInserter; |
| | | import org.eclipse.jgit.lib.PersonIdent; |
| | | import org.eclipse.jgit.lib.Ref; |
| | | import org.eclipse.jgit.lib.RefRename; |
| | | import org.eclipse.jgit.lib.RefUpdate; |
| | | import org.eclipse.jgit.lib.RefUpdate.Result; |
| | |
| | | parameters.add(0, repository.getDirectory().getAbsolutePath()); |
| | | } |
| | | LOGGER.error(MessageFormat.format(pattern, parameters.toArray()), t); |
| | | } |
| | | |
| | | /** |
| | | * Returns true if the repository has a reflog branch. |
| | | * |
| | | * @param repository |
| | | * @return true if the repository has a reflog branch |
| | | */ |
| | | public static boolean hasRefLogBranch(Repository repository) { |
| | | try { |
| | | return repository.getRef(GB_REFLOG) != null; |
| | | } catch(Exception e) { |
| | | LOGGER.error("failed to determine hasRefLogBranch", e); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | user.displayName = displayname; |
| | | user.emailAddress = ident.getEmailAddress(); |
| | | return user; |
| | | } |
| | | |
| | | /** |
| | | * Logs a ref deletion. |
| | | * |
| | | * @param user |
| | | * @param repository |
| | | * @param ref |
| | | * @return true, if the update was successful |
| | | */ |
| | | public static boolean deleteRef(UserModel user, Repository repository, Ref ref) { |
| | | try { |
| | | if (ref == null) { |
| | | return false; |
| | | } |
| | | RefModel reflogBranch = getRefLogBranch(repository); |
| | | if (reflogBranch == null) { |
| | | return false; |
| | | } |
| | | |
| | | List<RevCommit> log = JGitUtils.getRevLog(repository, reflogBranch.getName(), ref.getName(), 0, 1); |
| | | if (log.isEmpty()) { |
| | | // this ref is not in the reflog branch |
| | | return false; |
| | | } |
| | | ReceiveCommand cmd = new ReceiveCommand(ref.getObjectId(), ObjectId.zeroId(), ref.getName()); |
| | | return updateRefLog(user, repository, Arrays.asList(cmd)); |
| | | } catch (Throwable t) { |
| | | error(t, repository, "Failed to commit reflog entry to {0}"); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | UserModel user = newUserModelFrom(push.getAuthorIdent()); |
| | | Date date = push.getAuthorIdent().getWhen(); |
| | | |
| | | RefLogEntry log = new RefLogEntry(repositoryName, date, user); |
| | | list.add(log); |
| | | RefLogEntry log = new RefLogEntry(repositoryName, date, user); |
| | | List<PathChangeModel> changedRefs = JGitUtils.getFilesInCommit(repository, push); |
| | | if (changedRefs.isEmpty()) { |
| | | // skip empty commits |
| | | continue; |
| | | } |
| | | list.add(log); |
| | | for (PathChangeModel change : changedRefs) { |
| | | switch (change.changeType) { |
| | | case DELETE: |
| | |
| | | String oldId = fields[1]; |
| | | String newId = fields[2]; |
| | | log.updateRef(change.path, ReceiveCommand.Type.valueOf(fields[0]), oldId, newId); |
| | | if (ObjectId.zeroId().getName().equals(newId)) { |
| | | // ref deletion |
| | | continue; |
| | | } |
| | | List<RevCommit> pushedCommits = JGitUtils.getRevLog(repository, oldId, newId); |
| | | for (RevCommit pushedCommit : pushedCommits) { |
| | | RepositoryCommit repoCommit = log.addCommit(change.path, pushedCommit); |