2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org
.spearce
.jgit
.pgm
.opt
;
40 import java
.io
.IOException
;
42 import org
.kohsuke
.args4j
.CmdLineException
;
43 import org
.kohsuke
.args4j
.CmdLineParser
;
44 import org
.kohsuke
.args4j
.OptionDef
;
45 import org
.kohsuke
.args4j
.spi
.OptionHandler
;
46 import org
.kohsuke
.args4j
.spi
.Parameters
;
47 import org
.kohsuke
.args4j
.spi
.Setter
;
48 import org
.spearce
.jgit
.errors
.IncorrectObjectTypeException
;
49 import org
.spearce
.jgit
.errors
.MissingObjectException
;
50 import org
.spearce
.jgit
.lib
.ObjectId
;
51 import org
.spearce
.jgit
.revwalk
.RevTree
;
54 * Custom argument handler {@link RevTree} from string values.
56 * Assumes the parser has been initialized with a Repository.
58 public class RevTreeHandler
extends OptionHandler
<RevTree
> {
59 private final org
.spearce
.jgit
.pgm
.opt
.CmdLineParser clp
;
62 * Create a new handler for the command name.
64 * This constructor is used only by args4j.
70 public RevTreeHandler(final CmdLineParser parser
, final OptionDef option
,
71 final Setter
<?
super RevTree
> setter
) {
72 super(parser
, option
, setter
);
73 clp
= (org
.spearce
.jgit
.pgm
.opt
.CmdLineParser
) parser
;
77 public int parseArguments(final Parameters params
) throws CmdLineException
{
78 final String name
= params
.getParameter(0);
81 id
= clp
.getRepository().resolve(name
);
82 } catch (IOException e
) {
83 throw new CmdLineException(e
.getMessage());
86 throw new CmdLineException(name
+ " is not a tree");
90 c
= clp
.getRevWalk().parseTree(id
);
91 } catch (ClassCastException e
) {
92 throw new CmdLineException(name
+ " is not a tree");
93 } catch (MissingObjectException e
) {
94 throw new CmdLineException(name
+ " is not a tree");
95 } catch (IncorrectObjectTypeException e
) {
96 throw new CmdLineException(name
+ " is not a tree");
97 } catch (IOException e
) {
98 throw new CmdLineException("cannot read " + name
+ ": "
106 public String
getDefaultMetaVariable() {