1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package com.aragost.javahg.commands;
27
28 import java.io.File;
29 import java.util.List;
30
31 import com.aragost.javahg.Bundle;
32 import com.aragost.javahg.Changeset;
33 import com.aragost.javahg.Repository;
34 import com.aragost.javahg.commands.flags.IncomingCommandFlags;
35 import com.aragost.javahg.internals.HgInputStream;
36 import com.aragost.javahg.internals.Utils;
37
38
39
40
41
42 public class IncomingCommand extends IncomingCommandFlags {
43
44 private File bundleFile;
45
46
47
48
49
50 public IncomingCommand(Repository repository) {
51 super(repository);
52 withDebugAndChangesetStyle();
53 cmdAppend("-y");
54 }
55
56 @Override
57 public IncomingCommand bundle(String file) {
58 this.bundleFile = new File(file);
59 return this;
60 }
61
62
63
64
65
66
67 public Bundle execute(String src) {
68 if (this.bundleFile == null) {
69 this.bundleFile = Utils.createTempFile(".bundle");
70 cmdAppend("--bundle", this.bundleFile.getPath());
71 }
72 HgInputStream stream = launchStream(src);
73 Bundle bundle = new Bundle(getRepository().getBaseRepository(), this.bundleFile, true);
74 List<Changeset> changesets = Changeset.readListFromStream(bundle.getOverlayRepository(), stream);
75 if (changesets.isEmpty()) {
76 bundle.close();
77 return null;
78 }
79 bundle.init(changesets);
80 return bundle;
81 }
82
83 public Bundle execute(File directory) {
84 return execute(directory.getPath());
85 }
86
87 public Bundle execute(Repository repository) {
88 return execute(repository.getDirectory());
89 }
90
91 @Override
92 public boolean isSuccessful() {
93 return super.isSuccessful() || getReturnCode() == 1;
94 }
95 }