View Javadoc
1   /*
2    * Copyright (C) 2008, Charles O'Farrell <charleso@charleso.org>
3    * Copyright (C) 2009, Robin Rosenberg <robin.rosenberg@gmail.com>
4    * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
5    *
6    * This program and the accompanying materials are made available under the
7    * terms of the Eclipse Distribution License v. 1.0 which is available at
8    * https://www.eclipse.org/org/documents/edl-v10.php.
9    *
10   * SPDX-License-Identifier: BSD-3-Clause
11   */
12  
13  package org.eclipse.jgit.transport;
14  
15  import static org.eclipse.jgit.lib.Constants.R_HEADS;
16  import static org.eclipse.jgit.lib.Constants.R_REMOTES;
17  import static org.eclipse.jgit.lib.Constants.R_TAGS;
18  
19  import java.io.IOException;
20  import java.io.Writer;
21  
22  import org.eclipse.jgit.lib.ObjectId;
23  
24  class FetchHeadRecord {
25  	ObjectId newValue;
26  
27  	boolean notForMerge;
28  
29  	String sourceName;
30  
31  	URIish sourceURI;
32  
33  	void write(Writer pw) throws IOException {
34  		final String type;
35  		final String name;
36  		if (sourceName.startsWith(R_HEADS)) {
37  			type = "branch"; //$NON-NLS-1$
38  			name = sourceName.substring(R_HEADS.length());
39  		} else if (sourceName.startsWith(R_TAGS)) {
40  			type = "tag"; //$NON-NLS-1$
41  			name = sourceName.substring(R_TAGS.length());
42  		} else if (sourceName.startsWith(R_REMOTES)) {
43  			type = "remote branch"; //$NON-NLS-1$
44  			name = sourceName.substring(R_REMOTES.length());
45  		} else {
46  			type = ""; //$NON-NLS-1$
47  			name = sourceName;
48  		}
49  
50  		pw.write(newValue.name());
51  		pw.write('\t');
52  		if (notForMerge)
53  			pw.write("not-for-merge"); //$NON-NLS-1$
54  		pw.write('\t');
55  		pw.write(type);
56  		pw.write(" '"); //$NON-NLS-1$
57  		pw.write(name);
58  		pw.write("' of "); //$NON-NLS-1$
59  		pw.write(sourceURI.toString());
60  		pw.write("\n"); //$NON-NLS-1$
61  	}
62  }