annotate src/org/tmatesoft/hg/core/HgCatCommand.java @ 235:fd845a53f53d

Experimental access to working dir parents
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 07 Jun 2011 04:54:13 +0200
parents b7347daa50e3
children 6e1373b54e9b
rev   line source
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
130
7567f4a42fe5 Correct contact address
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 121
diff changeset
15 * contact TMate Software at support@hg4j.com
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
19 import static org.tmatesoft.hg.repo.HgInternals.wrongLocalRevision;
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import static org.tmatesoft.hg.repo.HgRepository.TIP;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.FileNotFoundException;
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
24 import java.io.IOException;
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.repo.HgDataFile;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.repo.HgRepository;
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
28 import org.tmatesoft.hg.util.ByteChannel;
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
29 import org.tmatesoft.hg.util.CancelledException;
133
4a948ec83980 core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 131
diff changeset
30 import org.tmatesoft.hg.util.Path;
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 /**
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 130
diff changeset
33 * Command to obtain content of a file, 'hg cat' counterpart.
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 *
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author Artem Tikhomirov
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @author TMate Software Ltd.
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 */
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
38 public class HgCatCommand extends HgAbstractCommand<HgCatCommand> {
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private final HgRepository repo;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 private Path file;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 private int localRevision = TIP;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 private Nodeid revision;
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
44 private Nodeid cset;
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 130
diff changeset
46 public HgCatCommand(HgRepository hgRepo) {
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 repo = hgRepo;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 }
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
50 /**
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
51 * File to read, required parameter
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
52 * @param fname path to a repository file, can't be <code>null</code>
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
53 * @return <code>this</code> for convenience
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
54 * @throws IllegalArgumentException if supplied fname is null or points to directory
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
55 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 130
diff changeset
56 public HgCatCommand file(Path fname) {
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
57 if (fname == null || fname.isDirectory()) {
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
58 throw new IllegalArgumentException(String.valueOf(fname));
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
59 }
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 file = fname;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 return this;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 }
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
64 /**
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
65 * Select specific local revision of the file to cat. Note, revision numbering is of particular file, not that of
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
66 * repository (i.e. revision 0 means initial content of the file, irrespective of changeset revision at the time of commit)
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
67 *
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
68 * Invocation of this method clears revision set with {@link #revision(Nodeid)} or {@link #revision(int)} earlier.
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
69 *
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
70 * XXX rev can't be WORKING_COPY (if allowed, need to implement in #execute())
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
71 * @param rev local revision number, non-negative, or one of predefined constants. Note, use of {@link HgRepository#BAD_REVISION},
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
72 * although possible, makes little sense (command would fail if executed).
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
73 * @return <code>this</code> for convenience
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
74 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 130
diff changeset
75 public HgCatCommand revision(int rev) {
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
76 if (wrongLocalRevision(rev)) {
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
77 throw new IllegalArgumentException(String.valueOf(rev));
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
78 }
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 localRevision = rev;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 revision = null;
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
81 cset = null;
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 return this;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 }
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
85 /**
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
86 * Select revision to read. Note, this revision is file revision (i.e. the one from manifest), not the changeset revision.
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
87 *
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
88 * Invocation of this method clears revision set with {@link #revision(int)} or {@link #revision(Nodeid)} earlier.
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
89 *
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
90 * @param nodeid - unique file revision identifier, Note, use of <code>null</code> or {@link Nodeid#NULL} is senseless
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
91 * @return <code>this</code> for convenience
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
92 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 130
diff changeset
93 public HgCatCommand revision(Nodeid nodeid) {
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
94 if (nodeid != null && nodeid.isNull()) {
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
95 nodeid = null;
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
96 }
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 revision = nodeid;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 localRevision = BAD_REVISION;
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
99 cset = null;
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
100 return this;
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
101 }
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
102
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
103 /**
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
104 * Select whatever revision of the file that was actual at the time of the specified changeset. Unlike {@link #revision(int)} or {@link #revision(Nodeid)}, this method
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
105 * operates in terms of repository global revisions (aka changesets).
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
106 *
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
107 * Invocation of this method clears local file revisions selection.
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
108 *
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
109 * @param nodeid changeset revision
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
110 * @return <code>this</code> for convenience
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
111 */
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
112 public HgCatCommand changeset(Nodeid nodeid) {
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
113 localRevision = BAD_REVISION;
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
114 revision = null;
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
115 cset = nodeid;
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 return this;
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 }
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
119 /**
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
120 * Runs the command with current set of parameters and pipes data to provided sink.
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
121 *
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
122 * @param sink output channel to write data to.
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
123 * @throws HgDataStreamException
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
124 * @throws IllegalArgumentException when command arguments are incomplete or wrong
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
125 */
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
126 public void execute(ByteChannel sink) throws HgDataStreamException, IOException, CancelledException {
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
127 if (localRevision == BAD_REVISION && revision == null && cset == null) {
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
128 throw new IllegalArgumentException("File revision, corresponing local number, or a changset nodeid shall be specified");
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 }
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 if (file == null) {
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 throw new IllegalArgumentException("Name of the file is missing");
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
133 if (sink == null) {
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
134 throw new IllegalArgumentException("Need an output channel");
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 HgDataFile dataFile = repo.getFileNode(file);
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 if (!dataFile.exists()) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
138 throw new HgDataStreamException(file, new FileNotFoundException(file.toString()));
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 }
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
140 int revToExtract;
232
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
141 if (cset != null) {
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
142 int csetRev = repo.getChangelog().getLocalRevision(cset);
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
143 Nodeid toExtract = null;
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
144 do {
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
145 toExtract = repo.getManifest().getFileRevision(csetRev, file);
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
146 if (toExtract == null) {
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
147 if (dataFile.isCopy()) {
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
148 file = dataFile.getCopySourceName();
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
149 dataFile = repo.getFileNode(file);
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
150 } else {
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
151 break;
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
152 }
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
153 }
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
154 } while (toExtract == null);
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
155 if (toExtract == null) {
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
156 throw new HgBadStateException(String.format("File %s not its origins were not known at repository %s revision", file, cset.shortNotation()));
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
157 }
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
158 revToExtract = dataFile.getLocalRevision(toExtract);
b7347daa50e3 Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
159 } else if (revision != null) {
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
160 revToExtract = dataFile.getLocalRevision(revision);
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 } else {
115
c0cc2535462c Introduced channels to pipeline (and easily filter) data streams
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
162 revToExtract = localRevision;
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 }
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
164 dataFile.contentWithFilters(revToExtract, sink);
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 }
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 }