View Javadoc
1   /*
2    * Copyright (C) 2008, Mike Ralphson <mike@abacus.co.uk>
3    * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
4    *
5    * This program and the accompanying materials are made available under the
6    * terms of the Eclipse Distribution License v. 1.0 which is available at
7    * https://www.eclipse.org/org/documents/edl-v10.php.
8    *
9    * SPDX-License-Identifier: BSD-3-Clause
10   */
11  
12  package org.eclipse.jgit.transport;
13  
14  import java.text.MessageFormat;
15  
16  import org.eclipse.jgit.internal.JGitText;
17  
18  /**
19   * Specification of annotated tag behavior during fetch.
20   */
21  public enum TagOpt {
22  	/**
23  	 * Automatically follow tags if we fetch the thing they point at.
24  	 * <p>
25  	 * This is the default behavior and tries to balance the benefit of having
26  	 * an annotated tag against the cost of possibly objects that are only on
27  	 * branches we care nothing about. Annotated tags are fetched only if we can
28  	 * prove that we already have (or will have when the fetch completes) the
29  	 * object the annotated tag peels (dereferences) to.
30  	 */
31  	AUTO_FOLLOW(""), //$NON-NLS-1$
32  
33  	/**
34  	 * Never fetch tags, even if we have the thing it points at.
35  	 * <p>
36  	 * This option must be requested by the user and always avoids fetching
37  	 * annotated tags. It is most useful if the location you are fetching from
38  	 * publishes annotated tags, but you are not interested in the tags and only
39  	 * want their branches.
40  	 */
41  	NO_TAGS("--no-tags"), //$NON-NLS-1$
42  
43  	/**
44  	 * Always fetch tags, even if we do not have the thing it points at.
45  	 * <p>
46  	 * Unlike {@link #AUTO_FOLLOW} the tag is always obtained. This may cause
47  	 * hundreds of megabytes of objects to be fetched if the receiving
48  	 * repository does not yet have the necessary dependencies.
49  	 */
50  	FETCH_TAGS("--tags"); //$NON-NLS-1$
51  
52  	private final String option;
53  
54  	private TagOpt(String o) {
55  		option = o;
56  	}
57  
58  	/**
59  	 * Get the command line/configuration file text for this value.
60  	 *
61  	 * @return text that appears in the configuration file to activate this.
62  	 */
63  	public String option() {
64  		return option;
65  	}
66  
67  	/**
68  	 * Convert a command line/configuration file text into a value instance.
69  	 *
70  	 * @param o
71  	 *            the configuration file text value.
72  	 * @return the option that matches the passed parameter.
73  	 */
74  	public static TagOpt fromOption(String o) {
75  		if (o == null || o.length() == 0)
76  			return AUTO_FOLLOW;
77  		for (TagOpt tagopt : values()) {
78  			if (tagopt.option().equals(o))
79  				return tagopt;
80  		}
81  		throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidTagOption, o));
82  	}
83  }