DfsRefRename.java

  1. /*
  2.  * Copyright (C) 2011, Google Inc. and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.internal.storage.dfs;

  11. import java.io.IOException;

  12. import org.eclipse.jgit.lib.ObjectId;
  13. import org.eclipse.jgit.lib.RefRename;
  14. import org.eclipse.jgit.lib.RefUpdate;
  15. import org.eclipse.jgit.lib.RefUpdate.Result;

  16. final class DfsRefRename extends RefRename {
  17.     DfsRefRename(RefUpdate src, RefUpdate dst) {
  18.         super(src, dst);
  19.     }

  20.     /** {@inheritDoc} */
  21.     @Override
  22.     protected Result doRename() throws IOException {
  23.         // TODO Correctly handle renaming foo/bar to foo.
  24.         // TODO Batch these together into one log update.

  25.         destination.setExpectedOldObjectId(ObjectId.zeroId());
  26.         destination.setNewObjectId(source.getRef().getObjectId());
  27.         switch (destination.update()) {
  28.         case NEW:
  29.             source.delete();
  30.             return Result.RENAMED;

  31.         default:
  32.             return destination.getResult();
  33.         }
  34.     }
  35. }