/** * Initialize a new rename operation. * * @param src * operation to read and delete the source. * @param dst * operation to create (or overwrite) the destination. */ protected RefRename(RefUpdate src, RefUpdate dst) { source = src; destination = dst; String cmd = ""; //$NON-NLS-1$ if (source.getName().startsWith(Constants.R_HEADS) && destination.getName().startsWith(Constants.R_HEADS)) cmd = "Branch: "; //$NON-NLS-1$ setRefLogMessage(cmd + "renamed " //$NON-NLS-1$ + Repository.shortenRefName(source.getName()) + " to " //$NON-NLS-1$ + Repository.shortenRefName(destination.getName())); }
private boolean renameLog(RefUpdate src, RefUpdate dst) { File srcLog = refdb.logFor(src.getName()); File dstLog = refdb.logFor(dst.getName()); if (!srcLog.exists()) return true; if (!rename(srcLog, dstLog)) return false; try { final int levels = RefDirectory.levelsIn(src.getName()) - 2; RefDirectory.delete(srcLog, levels); return true; } catch (IOException e) { rename(dstLog, srcLog); return false; } }
private boolean linkHEAD(RefUpdate target) { try { RefUpdate u = refdb.newUpdate(Constants.HEAD, false); u.disableRefLog(); switch (u.link(target.getName())) { case NEW: case FORCED: case NO_CHANGE: return true; default: return false; } } catch (IOException e) { return false; } } }
/** * Whether the {@code Constants#HEAD} reference needs to be linked to the * new destination name. * * @return true if the {@code Constants#HEAD} reference needs to be linked * to the new destination name. * @throws java.io.IOException * the current value of {@code HEAD} cannot be read. */ protected boolean needToUpdateHEAD() throws IOException { Ref head = source.getRefDatabase().getRef(Constants.HEAD); if (head != null && head.isSymbolic()) { head = head.getTarget(); return head.getName().equals(source.getName()); } return false; } }
if (!target.startsWith(Constants.R_REFS)) throw new IllegalArgumentException(MessageFormat.format(JGitText.get().illegalArgumentNotA, Constants.R_REFS)); if (checkConflicting && getRefDatabase().isNameConflicting(getName())) return Result.LOCK_FAILURE; try { return Result.LOCK_FAILURE; final Ref old = getRefDatabase().getRef(getName()); if (old != null && old.isSymbolic()) { final Ref dst = old.getTarget();
/** {@inheritDoc} */ @Override protected Result doRename() throws IOException { try (RevWalk rw = new RevWalk(refdb.getRepository())) { RefTreeBatch batch = new RefTreeBatch(refdb); batch.setRefLogIdent(getRefLogIdent()); batch.setRefLogMessage(getRefLogMessage(), false); batch.init(rw); Ref head = batch.exactRef(rw.getObjectReader(), HEAD); Ref oldRef = batch.exactRef(rw.getObjectReader(), source.getName()); if (oldRef == null) { return REJECTED; } Ref newRef = asNew(oldRef); List<Command> mv = new ArrayList<>(3); mv.add(new Command(oldRef, null)); mv.add(new Command(null, newRef)); if (head != null && head.isSymbolic() && head.getTarget().getName().equals(oldRef.getName())) { mv.add(new Command( head, new SymbolicRef(head.getName(), newRef))); } batch.execute(rw, mv); return RefTreeUpdate.translate(mv.get(1).getResult(), RENAMED); } }
private Ref asNew(Ref src) { String name = destination.getName(); if (src.isSymbolic()) { return new SymbolicRef(name, src.getTarget()); } ObjectId peeled = src.getPeeledObjectId(); if (peeled != null) { return new ObjectIdRef.PeeledTag( src.getStorage(), name, src.getObjectId(), peeled); } return new ObjectIdRef.PeeledNonTag( src.getStorage(), name, src.getObjectId()); } }
JGitText.get().cannotLock, ru.getName()));
/** * Initialize a new rename operation. * * @param src * operation to read and delete the source. * @param dst * operation to create (or overwrite) the destination. */ protected RefRename(final RefUpdate src, final RefUpdate dst) { source = src; destination = dst; String cmd = ""; //$NON-NLS-1$ if (source.getName().startsWith(Constants.R_HEADS) && destination.getName().startsWith(Constants.R_HEADS)) cmd = "Branch: "; //$NON-NLS-1$ setRefLogMessage(cmd + "renamed " //$NON-NLS-1$ + Repository.shortenRefName(source.getName()) + " to " //$NON-NLS-1$ + Repository.shortenRefName(destination.getName())); }
&& getRefDatabase().isNameConflicting(getName())) { return Result.LOCK_FAILURE;
private void runReceiveHook(@NotNull Repository repository, @NotNull RefUpdate refUpdate, @NotNull SVNErrorCode svnErrorCode, @Nullable String hook, @NotNull User userInfo) throws IOException, SVNException { runHook(repository, svnErrorCode, hook, userInfo, processBuilder -> { final Process process = processBuilder.start(); try (Writer stdin = new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8)) { stdin.write(getObjectId(refUpdate.getOldObjectId())); stdin.write(' '); stdin.write(getObjectId(refUpdate.getNewObjectId())); stdin.write(' '); stdin.write(refUpdate.getName()); stdin.write('\n'); } return process; }); }
private void runUpdateHook(@NotNull Repository repository, @NotNull RefUpdate refUpdate, @Nullable String hook, @NotNull User userInfo) throws IOException, SVNException { runHook(repository, SVNErrorCode.REPOS_HOOK_FAILURE, hook, userInfo, processBuilder -> { processBuilder.command().addAll(Arrays.asList( refUpdate.getName(), getObjectId(refUpdate.getOldObjectId()), getObjectId(refUpdate.getNewObjectId()) )); return processBuilder.start(); }); }
private boolean renameLog(RefUpdate src, RefUpdate dst) { File srcLog = refdb.logFor(src.getName()); File dstLog = refdb.logFor(dst.getName()); if (!srcLog.exists()) return true; if (!rename(srcLog, dstLog)) return false; try { final int levels = RefDirectory.levelsIn(src.getName()) - 2; RefDirectory.delete(srcLog, levels); return true; } catch (IOException e) { rename(dstLog, srcLog); return false; } }
private boolean renameLog(RefUpdate src, RefUpdate dst) { File srcLog = refdb.getLogWriter().logFor(src.getName()); File dstLog = refdb.getLogWriter().logFor(dst.getName()); if (!srcLog.exists()) return true; if (!rename(srcLog, dstLog)) return false; try { final int levels = RefDirectory.levelsIn(src.getName()) - 2; RefDirectory.delete(srcLog, levels); return true; } catch (IOException e) { rename(dstLog, srcLog); return false; } }
private boolean linkHEAD(RefUpdate target) { try { RefUpdate u = refdb.newUpdate(Constants.HEAD, false); u.disableRefLog(); switch (u.link(target.getName())) { case NEW: case FORCED: case NO_CHANGE: return true; default: return false; } } catch (IOException e) { return false; } } }
private boolean linkHEAD(RefUpdate target) { try { RefUpdate u = refdb.newUpdate(Constants.HEAD, false); u.disableRefLog(); switch (u.link(target.getName())) { case NEW: case FORCED: case NO_CHANGE: return true; default: return false; } } catch (IOException e) { return false; } } }
/** * @return true if the {@code Constants#HEAD} reference needs to be linked * to the new destination name. * @throws IOException * the current value of {@code HEAD} cannot be read. */ protected boolean needToUpdateHEAD() throws IOException { Ref head = source.getRefDatabase().getRef(Constants.HEAD); if (head != null && head.isSymbolic()) { head = head.getTarget(); return head.getName().equals(source.getName()); } return false; } }
/** * Whether the {@code Constants#HEAD} reference needs to be linked to the * new destination name. * * @return true if the {@code Constants#HEAD} reference needs to be linked * to the new destination name. * @throws java.io.IOException * the current value of {@code HEAD} cannot be read. */ protected boolean needToUpdateHEAD() throws IOException { Ref head = source.getRefDatabase().getRef(Constants.HEAD); if (head != null && head.isSymbolic()) { head = head.getTarget(); return head.getName().equals(source.getName()); } return false; } }
@Override public Void call() throws Exception { try { RefUpdate refUpdate = fromRepository.updateRef("refs/temp/fetch"); refUpdate.setNewObjectId(fromCommit); updateRef(refUpdate); new FetchCommand(toRepository.getDirectory()) .from(fromRepository.getDirectory().getAbsolutePath()) .refspec(refUpdate.getName()) .call(); } catch (IOException e) { throw new RuntimeException(e); } return null; }
private Ref asNew(Ref src) { String name = destination.getName(); if (src.isSymbolic()) { return new SymbolicRef(name, src.getTarget()); } ObjectId peeled = src.getPeeledObjectId(); if (peeled != null) { return new ObjectIdRef.PeeledTag( src.getStorage(), name, src.getObjectId(), peeled); } return new ObjectIdRef.PeeledNonTag( src.getStorage(), name, src.getObjectId()); } }