1 /*
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> 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.revwalk;
12
13 import java.text.MessageFormat;
14
15 import org.eclipse.jgit.internal.JGitText;
16
17 /**
18 * Application level mark bit for {@link org.eclipse.jgit.revwalk.RevObject}s.
19 * <p>
20 * To create a flag use
21 * {@link org.eclipse.jgit.revwalk.RevWalk#newFlag(String)}.
22 */
23 public class RevFlag {
24 /**
25 * Uninteresting by {@link RevWalk#markUninteresting(RevCommit)}.
26 * <p>
27 * We flag commits as uninteresting if the caller does not want commits
28 * reachable from a commit to {@link RevWalk#markUninteresting(RevCommit)}.
29 * This flag is always carried into the commit's parents and is a key part
30 * of the "rev-list B --not A" feature; A is marked UNINTERESTING.
31 * <p>
32 * This is a static flag. Its RevWalk is not available.
33 */
34 public static final RevFlag UNINTERESTING = new StaticRevFlag(
35 "UNINTERESTING", RevWalk.UNINTERESTING); //$NON-NLS-1$
36
37 /**
38 * Set on RevCommit instances added to {@link RevWalk#pending} queue.
39 * <p>
40 * We use this flag to avoid adding the same commit instance twice to our
41 * queue, especially if we reached it by more than one path.
42 * <p>
43 * This is a static flag. Its RevWalk is not available.
44 *
45 * @since 3.0
46 */
47 public static final RevFlag SEEN = new StaticRevFlag("SEEN", RevWalk.SEEN); //$NON-NLS-1$
48
49 final RevWalk walker;
50
51 final String name;
52
53 final int mask;
54
55 RevFlag(RevWalk w, String n, int m) {
56 walker = w;
57 name = n;
58 mask = m;
59 }
60
61 /**
62 * Get the revision walk instance this flag was created from.
63 *
64 * @return the walker this flag was allocated out of, and belongs to.
65 */
66 public RevWalk getRevWalk() {
67 return walker;
68 }
69
70 /** {@inheritDoc} */
71 @Override
72 public String toString() {
73 return name;
74 }
75
76 static class StaticRevFlag extends RevFlag {
77 StaticRevFlag(String n, int m) {
78 super(null, n, m);
79 }
80
81 @Override
82 public RevWalk getRevWalk() {
83 throw new UnsupportedOperationException(MessageFormat.format(
84 JGitText.get().isAStaticFlagAndHasNorevWalkInstance, toString()));
85 }
86 }
87 }