Skip to content

Commit e33e684

Browse files
committed
adding files to remote repository
1 parent 99df803 commit e33e684

22 files changed

+1105
-2
lines changed

Commit.class

1.67 KB
Binary file not shown.

Commit.java

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package gitlet;
2+
import java.io.File;
3+
import java.io.Serializable;
4+
import java.util.Date;
5+
import java.util.HashMap;
6+
7+
public class Commit implements Serializable {
8+
9+
private String message;
10+
11+
/** something that keeps tracks of what files this commit is tracking. file name is the key, value is the blobs or the sha1.*/
12+
private HashMap<String, String> Tracker;
13+
14+
/** the Head commit of a commit object, will be a file name which were we can find the parent.*/
15+
private String parent;
16+
17+
/** the Hash of the given Commit object */
18+
private String ownHash;
19+
20+
/** the variable representing the date of a commit object */
21+
private String _date;
22+
23+
private String _merge;
24+
25+
public Commit(String message, HashMap<String,String> Tracker, String parent, String date, String merge) {
26+
this.Tracker = Tracker;
27+
this.message = message;
28+
_date = date;
29+
this.parent = parent;
30+
ownHash = Utils.sha1((Object) Utils.serialize(this), getMessage(), getDate());
31+
this._merge = merge;
32+
}
33+
34+
public String getMessage() {
35+
return this.message;
36+
}
37+
38+
public String getDate() {
39+
return _date;
40+
}
41+
public String getOwnHash() {
42+
return ownHash;
43+
}
44+
45+
public String getParent() {
46+
return this.parent;
47+
}
48+
public HashMap<String, String> getTracker() {
49+
return this.Tracker;
50+
}
51+
public String getMerge() {
52+
return this._merge;
53+
}
54+
55+
}

DumpObj.class

877 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

435 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.39 KB
Binary file not shown.

Main.java

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package gitlet;
2+
import java.io.File;
3+
import java.util.Arrays;
4+
import java.util.Date;
5+
6+
/** Driver class for Gitlet, the tiny stupid version-control system.
7+
* @author Jorge Emanuel Nunez
8+
*/
9+
public abstract class Main {
10+
11+
/** Usage: java gitlet.Main ARGS, where ARGS contains
12+
* <COMMAND> <OPERAND> ....
13+
* java gitlet.Main add hello.txt*/
14+
15+
private static File CWD = new File(System.getProperty("user.dir"));
16+
private static Repository repo = new Repository();
17+
18+
19+
public static void main(String... args) {
20+
if (args[0].equals("add")) {
21+
repo.add(args[1]);
22+
}
23+
if (args[0].equals("init")) {
24+
repo.init();
25+
}
26+
if (args[0].equals("commit")) {
27+
repo.commit(args[1]);
28+
}
29+
if (args[0].equals("log")) {
30+
repo.log();
31+
}
32+
if (args[0].equals("checkout")) {
33+
repo.checkout(args);
34+
}
35+
if (args[0].equals("branch")) {
36+
repo.branch(args[1]);
37+
}
38+
if (args[0].equals("global-log")) {
39+
repo.globalLog();
40+
}
41+
if (args[0].equals("find")) {
42+
repo.find(args[1]);
43+
}
44+
if (args[0].equals("rm-branch")) {
45+
repo.rmBranch(args[1]);
46+
}
47+
if (args[0].equals("status")) {
48+
repo.status();
49+
}
50+
if (args[0].equals("reset")) {
51+
repo.reset(args[1]);
52+
}
53+
if (args[0].equals("rm")) {
54+
repo.rm(args[1]);
55+
}
56+
}
57+
}

Makefile

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# This makefile is defined to give you the following targets:
2+
#
3+
# default: The default target: Compiles $(PROG) and whatever it
4+
# depends on.
5+
# style: Run our style checker on the project source files. Requires that
6+
# the source files compile.
7+
# check: Compile $(PROG), if needed, and then for each file, F.in, in
8+
# directory testing, use F.in as input to "java $(MAIN_CLASS)" and
9+
# compare the output to the contents of the file names F.out.
10+
# Report discrepencies.
11+
# clean: Remove all the .class files produced by java compilation,
12+
# all Emacs backup files, and testing output files.
13+
#
14+
# In other words, type 'gmake' to compile everything; 'gmake check' to
15+
# compile and test everything, and 'gmake clean' to clean things up.
16+
#
17+
# You can use this file without understanding most of it, of course, but
18+
# I strongly recommend that you try to figure it out, and where you cannot,
19+
# that you ask questions. The Lab Reader contains documentation.
20+
21+
STYLEPROG = style61b
22+
23+
JFLAGS = -g -Xlint:unchecked -Xlint:deprecation
24+
25+
CLASSDIR = ../classes
26+
27+
# See comment in ../Makefile
28+
PYTHON = python3
29+
30+
RMAKE = "$(MAKE)"
31+
32+
# A CLASSPATH value that (seems) to work on both Windows and Unix systems.
33+
# To Unix, it looks like ..:$(CLASSPATH):JUNK and to Windows like
34+
# JUNK;..;$(CLASSPATH).
35+
CPATH = "..:$(CLASSPATH):;..;$(CLASSPATH)"
36+
37+
# All .java files in this directory.
38+
SRCS := $(wildcard *.java)
39+
40+
.PHONY: default check clean style acceptance unit
41+
42+
# As a convenience, you can compile a single Java file X.java in this directory
43+
# with 'make X.class'
44+
%.class: %.java
45+
javac $(JFLAGS) -cp $(CPATH) $<
46+
47+
# First, and therefore default, target.
48+
default: compile
49+
50+
compile: $(SRCS)
51+
javac $(JFLAGS) -cp $(CPATH) $(SRCS)
52+
53+
style: default
54+
$(STYLEPROG) $(SRCS)
55+
56+
check:
57+
$(RMAKE) -C .. PYTHON=$(PYTHON) check
58+
59+
acceptance:
60+
$(RMAKE) -C .. PYTHON=$(PYTHON) acceptance
61+
62+
unit: default
63+
java -ea -cp $(CPATH) gitlet.UnitTest
64+
65+
# 'make clean' will clean up stuff you can reconstruct.
66+
clean:
67+
$(RM) *~ *.class sentinel
68+
69+

README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
# Gitlet
2-
Version-Control System
1+
# Gitlet: A Miniature Version-Control System
2+
Gitlet is a simplified version-control system inspired by Git, designed to implement essential features for managing and tracking changes in a collection of files. This project was developed as part of UC Berkeley's CS 61B: Data Structures course and aims to provide hands-on experience with building a lightweight version-control system from the ground up.
3+
4+
# Features:
5+
Commit System: Save the entire state of a directory with a single commit, capturing snapshots of your project at different points in time.
6+
7+
File Restoration: Check out and restore specific versions of files or entire commits to recover previous states of the project.
8+
9+
Version History: View the complete log of commits to track the history and evolution of your project.
10+
11+
Branching: Create and manage branches to organize related sequences of commits for different development paths.
12+
13+
Merging: Merge changes from one branch into another, allowing collaboration and combination of different code versions.
14+
15+
Gitlet mimics the basic functionality of Git but is designed to be smaller and simpler, making it ideal for learning core version-control concepts.
16+
17+
# Technical Notes:
18+
The project is written in Java and emphasizes implementing fundamental version-control operations manually to understand their internal mechanics.

Repository.class

12.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)