View Javadoc
1   /*
2    * Copyright (C) 2016, 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.reftree;
12  
13  import java.io.IOException;
14  
15  import org.eclipse.jgit.lib.ObjectIdRef;
16  import org.eclipse.jgit.lib.Ref;
17  import org.eclipse.jgit.lib.RefDatabase;
18  import org.eclipse.jgit.lib.RefUpdate;
19  import org.eclipse.jgit.lib.Repository;
20  
21  /** Update that always rejects with {@code LOCK_FAILURE}. */
22  class AlwaysFailUpdate extends RefUpdate {
23  	private final RefTreeDatabase refdb;
24  
25  	AlwaysFailUpdate(RefTreeDatabase refdb, String name) {
26  		super(new ObjectIdRef.Unpeeled(Ref.Storage.NEW, name, null));
27  		this.refdb = refdb;
28  		setCheckConflicting(false);
29  	}
30  
31  	/** {@inheritDoc} */
32  	@Override
33  	protected RefDatabase getRefDatabase() {
34  		return refdb;
35  	}
36  
37  	/** {@inheritDoc} */
38  	@Override
39  	protected Repository getRepository() {
40  		return refdb.getRepository();
41  	}
42  
43  	/** {@inheritDoc} */
44  	@Override
45  	protected boolean tryLock(boolean deref) throws IOException {
46  		return false;
47  	}
48  
49  	/** {@inheritDoc} */
50  	@Override
51  	protected void unlock() {
52  		// No locks are held here.
53  	}
54  
55  	/** {@inheritDoc} */
56  	@Override
57  	protected Result doUpdate(Result desiredResult) {
58  		return Result.LOCK_FAILURE;
59  	}
60  
61  	/** {@inheritDoc} */
62  	@Override
63  	protected Result doDelete(Result desiredResult) {
64  		return Result.LOCK_FAILURE;
65  	}
66  
67  	/** {@inheritDoc} */
68  	@Override
69  	protected Result doLink(String target) {
70  		return Result.LOCK_FAILURE;
71  	}
72  }