Skip to content

Commit 97b7444

Browse files
authored
Add files via upload
0 parents  commit 97b7444

21 files changed

+1264
-0
lines changed

Branch.class

249 Bytes
Binary file not shown.

Commit.class

2.4 KB
Binary file not shown.

Commit.java

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package gitlet;
2+
3+
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.io.Serializable;
8+
import java.util.HashMap;
9+
import static gitlet.Utils.*;
10+
11+
/** Represents a gitlet commit object.
12+
* does at a high level.
13+
*
14+
* @author Matthew Koen
15+
*/
16+
public class Commit implements Serializable {
17+
/**
18+
* List all instance variables of the Commit class here with a useful
19+
* comment above them describing what that variable represents and how that
20+
* variable is used. We've provided one example for `message`.
21+
*/
22+
23+
/** The message of this Commit. */
24+
25+
private String parent;
26+
27+
private HashMap<String, String> blobs;
28+
29+
private String iD;
30+
31+
private String time;
32+
33+
private String message;
34+
35+
36+
public Commit(String message, String time) {
37+
this.message = message;
38+
this.time = time;
39+
}
40+
41+
public Commit(String parent, String message, String time, HashMap<String, String> blobs) {
42+
this.message = message;
43+
this.time = time;
44+
this.blobs = blobs;
45+
this.parent = parent;
46+
47+
}
48+
49+
public String getParent() {
50+
return parent;
51+
}
52+
53+
public String getID() {
54+
return iD;
55+
}
56+
57+
public HashMap<String, String> getBlobs() {
58+
return blobs;
59+
}
60+
61+
public void updateBlobs(HashMap<String, String> k) {
62+
blobs = k;
63+
}
64+
65+
public static void saveBlobs(HashMap<String, String> blobs) {
66+
for (String fileName: blobs.keySet()) {
67+
File baseFile = join(Repository.CWD, fileName);
68+
File blob = join(Repository.BLOB_DIR, blobs.get(fileName));
69+
70+
try {
71+
blob.createNewFile();
72+
} catch (IOException e) {
73+
e.printStackTrace();
74+
}
75+
76+
byte[] content = readContents(baseFile);
77+
writeContents(blob, content);
78+
}
79+
80+
}
81+
82+
public void updateParent(String parentSHA) {
83+
parent = parentSHA;
84+
85+
}
86+
87+
public void updateID(String identifier) {
88+
this.iD = identifier;
89+
}
90+
91+
public String getTime() {
92+
return time;
93+
}
94+
95+
public String getMessage() {
96+
return message;
97+
}
98+
99+
}

DumpObj.class

708 Bytes
Binary file not shown.

DumpObj.java

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package gitlet;
2+
3+
import java.io.File;
4+
5+
/** A debugging class whose main program may be invoked as follows:
6+
* java gitlet.DumpObj FILE...
7+
* where each FILE is a file produced by Utils.writeObject (or any file
8+
* containing a serialized object). This will simply read FILE,
9+
* deserialize it, and call the dump method on the resulting Object.
10+
* The object must implement the gitlet.Dumpable interface for this
11+
* to work. For example, you might define your class like this:
12+
*
13+
* import java.io.Serializable;
14+
* import java.util.TreeMap;
15+
* class MyClass implements Serializeable, Dumpable {
16+
* ...
17+
* @Override
18+
* public void dump() {
19+
* System.out.printf("size: %d%nmapping: %s%n", _size, _mapping);
20+
* }
21+
* ...
22+
* int _size;
23+
* TreeMap<String, String> _mapping = new TreeMap<>();
24+
* }
25+
*
26+
* As illustrated, your dump method should print useful information from
27+
* objects of your class.
28+
* @author P. N. Hilfinger
29+
*/
30+
public class DumpObj {
31+
32+
/** Deserialize and apply dump to the contents of each of the files
33+
* in FILES. */
34+
public static void main(String... files) {
35+
for (String fileName : files) {
36+
Dumpable obj = Utils.readObject(new File(fileName),
37+
Dumpable.class);
38+
obj.dump();
39+
System.out.println("---");
40+
}
41+
}
42+
}
43+

Dumpable.class

153 Bytes
Binary file not shown.

Dumpable.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package gitlet;
2+
3+
import java.io.Serializable;
4+
5+
/** An interface describing dumpable objects.
6+
* @author P. N. Hilfinger
7+
*/
8+
interface Dumpable extends Serializable {
9+
/** Print useful information about this object on System.out. */
10+
void dump();
11+
}

GitletException.class

307 Bytes
Binary file not shown.

GitletException.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package gitlet;
2+
3+
/** General exception indicating a Gitlet error. For fatal errors, the
4+
* result of .getMessage() is the error message to be printed.
5+
* @author P. N. Hilfinger
6+
*/
7+
class GitletException extends RuntimeException {
8+
9+
10+
/** A GitletException with no message. */
11+
GitletException() {
12+
super();
13+
}
14+
15+
/** A GitletException MSG as its message. */
16+
GitletException(String msg) {
17+
super(msg);
18+
}
19+
20+
}

Main.class

1.38 KB
Binary file not shown.

Main.java

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package gitlet;
2+
3+
4+
/** Driver class for Gitlet, a subset of the Git version-control system.
5+
* @author Matthew Koen
6+
*/
7+
public class Main {
8+
9+
/** Usage: java gitlet.Main ARGS, where ARGS contains
10+
* <COMMAND> <OPERAND1> <OPERAND2> ...
11+
*/
12+
13+
14+
public static void main(String[] args) {
15+
if (args.length == 0) {
16+
System.out.print("Must have at least one argument");
17+
return;
18+
}
19+
20+
String firstArg = args[0];
21+
switch (firstArg) {
22+
case "init":
23+
Repository.init();
24+
break;
25+
case "add":
26+
Repository.add(args[1]);
27+
break;
28+
case "commit":
29+
if ((args.length < 2) || (args[1].equals(""))) {
30+
System.out.print("Please enter a commit message.");
31+
break;
32+
}
33+
Repository.commit(args[1]);
34+
break;
35+
case "rm":
36+
Repository.rm(args[1]);
37+
break;
38+
case "log":
39+
Repository.log();
40+
break;
41+
case "global-log":
42+
Repository.globalLog();
43+
break;
44+
case "find":
45+
Repository.find(args[1]);
46+
break;
47+
case "status":
48+
Repository.status();
49+
break;
50+
case "checkout":
51+
if (args.length == 3) {
52+
Repository.checkout(args[2]);
53+
} else if (args.length == 4) {
54+
if (!args[2].equals("--")) {
55+
System.out.print("Incorrect operands.");
56+
break;
57+
}
58+
Repository.checkout(args[3], args[1]);
59+
} else if (args.length == 2) {
60+
Repository.checkoutBranch(args[1]);
61+
}
62+
break;
63+
case "branch":
64+
Repository.branch(args[1]);
65+
break;
66+
case "rm-branch":
67+
Repository.rmBranch(args[1]);
68+
break;
69+
case "reset":
70+
71+
break;
72+
case "merge":
73+
74+
break;
75+
default:
76+
System.out.print("Unknown argument.");
77+
}
78+
79+
80+
81+
}
82+
83+
84+
85+
86+
}

MiscTests.class

436 Bytes
Binary file not shown.

MiscTests.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package gitlet;
2+
import org.junit.Test;
3+
4+
import static org.junit.Assert.*;
5+
6+
/** A suite of tests for IntList.
7+
@author Zephyr Barkan, Maurice Lee, Kevin Lin
8+
*/
9+
10+
public class MiscTests {
11+
12+
13+
@Test
14+
public void testAdd() {
15+
String[] test = new String[]{"add", "kalsdf"};
16+
Main.main(test);
17+
}
18+
19+
20+
21+
}

Repository.class

5.75 KB
Binary file not shown.

0 commit comments

Comments
 (0)