View Javadoc
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  
11  package org.eclipse.jgit.internal.storage.dfs;
12  
13  import java.io.IOException;
14  
15  import org.eclipse.jgit.lib.ObjectId;
16  import org.eclipse.jgit.lib.RefRename;
17  import org.eclipse.jgit.lib.RefUpdate;
18  import org.eclipse.jgit.lib.RefUpdate.Result;
19  
20  final class DfsRefRename extends RefRename {
21  	DfsRefRename(RefUpdate="../../../../../../org/eclipse/jgit/lib/RefUpdate.html#RefUpdate">RefUpdate src, RefUpdate dst) {
22  		super(src, dst);
23  	}
24  
25  	/** {@inheritDoc} */
26  	@Override
27  	protected Result doRename() throws IOException {
28  		// TODO Correctly handle renaming foo/bar to foo.
29  		// TODO Batch these together into one log update.
30  
31  		destination.setExpectedOldObjectId(ObjectId.zeroId());
32  		destination.setNewObjectId(source.getRef().getObjectId());
33  		switch (destination.update()) {
34  		case NEW:
35  			source.delete();
36  			return Result.RENAMED;
37  
38  		default:
39  			return destination.getResult();
40  		}
41  	}
42  }