Java-based application that allowed for version tracking, branching, merging, and basic collaboration features, utilizing data structures and algorithms
Name: Alysa Liu
-
public static final File CWD: The current working directory
-
public static final File GITLET_DIR: The .gitlet directory
-
public static final File REPO_OBJECT: File that stores the repository object
-
public static final File CWD: The current working directory
-
public static final File GITLET_DIR: The .gitlet directory
-
public static final File COMMITS_DIR: The directory of commits
-
public static final File BLOBS_DIR: The directory of blobs
-
public String head: head pointer with hash of working commit
-
public HashMap branches: HashMap of all branches (keys are working branch, values are hash code of branch)
-
public String workingBranch: current working branch
-
public HashMap stagedAddition: HashMap of files to be added to staging area (file name as key, hash of file contents as value)
-
public HashMap stagedRemoval: HashMap of files to be removed from staging area (file name as key, hash of file contents as value)
-
public String message: the message of the commit
-
public String author: the author of the commit
-
public String timeStamp: timestamp of the commit
-
public HashMap trackedFiles: HashMap of files tracked by the commit
-
public String parent: hashcode of parent of the commit
-
private static final File CWD: The current working directory
-
private static final File COMMITS_DIR: The directory of commits
Method that takes in commands entered by the user and calls the appropriate method in the Repository class. If there were no commands entered or Gitlet has not been initialized and the first argument is not "init", exits system. At the end, saves the state of the repository object in a file.
Initializes the Gitlet version-control system by creating directories for .gitlet, commits, and blobs. It also instantiates the HashMap for saving branches and files in the staging area. The head points to the hash code of the initial commit. If it has already been initialized, it only prints out a message.
If the file is not already in the staging area, it adds the specified file to the staging area by saving it to the HashMap that keeps track of files staged for addition. Otherwise, it removes the file from the staging area. At the end, it saves the contents of the file (blob). It then saves the state of the staging area to a file.
Creates a new Commit object with the current time, the commit message, and parent as the current head. Checks that there was a commit message entered. Loads the files staged for addition and removal into their respective HashMaps, and checks that they are not empty. Then, it adds and removes the specified files to and from the new Commit object, and saves it. Clears the staging areas and saves them.
Uses instance variables of the Commit object corresponding to the head pointer to display information about the current commit and ones before it.
Checks out the version of the file that exists in the specified commit by joining a file with the contents of the specified version of the file to the current working directory.
Checks out version of file at head by calling the checkout method.
Checks out version of file as it exists in the commit passed in by calling the checkout method.
Checks out version of file at head by calling the checkout method.
Helper method that loads the HashMap saved in a file that contains the names of files that were staged for addition. It then saves the HashMap in that file as the current HashMap containing names of files staged for addition.
Helper method that saves the HashMap containing names of files staged for addition into a file.
Helper method that loads the HashMap saved in a file that contains the names of files that were staged for removal. It then saves the HashMap in that file as the current HashMap containing names of files staged for removal.
Helper method that saves the HashMap containing names of files staged for removal into a file.
Helper method that loads the file containing a HashMap that kept track of all previous branches into the current branches HashMap.
Helper method that saves the HashMap containing all the previous branches into a file.
Helper method that returns the Commit with the specified hashcode.
Helper method that returns hashcode of the Commit object.
Helper method that saves the specified commit to a file labeled as its hashcode. It also saves the tracked files of the commit to a file labeled with its hashcode followed by "tf."
Helper method that saves the contents of the blob to a file labeled with the hashcode of its contents.
Helper method that returns the contents of the file specified by the hashcode as a String.
Creates a Commit object with the date, message, and parent passed in. If it is not the initial commit, the tracked files of its parent get put into its tracked files HashMap.
Returns the commit of the specified hashcode by reading from a file with that hashcode containing a Commit object.
Loads file containing tracked files of commit with specified hashcode to current Commit object's HashMap containing its tracked files.
Goes through the HashMap containing files staged for addition and adds them to the Commit object's tracked files.
Goes through the HashMap containing files staged for removal and removes them from the Commit object's tracked files.
The Repository class will set up all persistence. It will:
- Create the .gitlet directory if it doesn’t already exist
- Create the commits directory if it doesn’t already exist
- Create the blobs directory if it doesn't already exist
Times we need to record the state of our files: