GP 2.1 | Initialize Git Repository
- Constructor calls generateGitDirectory() in gitRepository file (also defines global var for compression on/off)
- Returns message if it all already exists (doesn't continue to the rest of the method)
- Attempts to creating whatever is missing
- Returns Output (Git Repository Created) (main branch prints, if called outside of that for some reason???? needs to be printed)
Tester -> projectTester.java, testGenerateGitDirectory();
- Resets repo with resetRepo(false); -> reset repo clears all files and constructs new repo (returns it for future use), false bc not testing compression rn
- Prints out trial number, results per file in repo initialization and if it recognizes that there is a repo that already exists
- Resets multiple times to ensure robustness >:|
GP-2.2 | Hash Function Reads in Data from file -> getFileContents(String fileName)
- Takes file name as input returns string w/ contents of file provided
Generate Hash -> createSha1Hash(String inputData) Taken from GeeksforGeeks
- takes data (from previous function) as an input
- getInstance() method is called with SHA-1 Algorithm (try catch necessary in case algorithm doesnt exist)
- digest() method is called to calculate byte array of message digest
- byte array is converted to signum representation
- converted to hex value (precedding 0s added to make it 40 digits long) and returned
GP-2.3 | Create Blob File & Store -> BLOB(String fileName)
- Gets contents from fileName -> getFileContents(String fileName)
- Generates Hash from Contents -> createSha1Hash(String inputData)
- Writes to File (doesnt return anything)
- Tester projectTester.java
- starts with fresh repo / does full reset
- blobs file and sees if its in the objects folder (prints true / false for success)
Tester -> projectTester.java, testBLOB();
- Resets repo with resetRepo(boolean compression); -> reset repo clears all files and constructs new repo (returns it for future use), true and false both tested to test compression on and off
- Generates files with generateTestFiles() -> uses pre-determined global constants for file names and uses the same phrase + random number for the contents so that each trial will have different contents to be hashed
- Prints out trial number, results per file
- Resets multiple times to ensure robustness >:|
Compression -> public static void compressContents(String fileName) Taken from stack overflow https://stackoverflow.com/questions/3649485/how-to-compress-a-string-in-java
- global var enabled
- getFileContents(String fileName) will make a temp file to compress then get the contents of the compressed version
GP-2.4 | index(String fileName)
- gets hash and add its to index w/ file name
Tester -> projectTester.java, testBLOB();
- Resets repo with resetRepo(boolean compression); -> reset repo clears all files and constructs new repo (returns it for future use), true and false both tested to test compression on and off
- Generates files with generateTestFiles() -> uses pre-determined global constants for file names and uses the same phrase + random number for the contents so that each trial will have different contents to be hashed
- Prints out trial number, results per file in index
- Resets multiple times to ensure robustness >:|
GP-3.0 | addTree(String directoryPath)
- reads first line of index and trims whitespace
- If the line exists, generates a SHA-1 hash of the content
- Creates a new file in the "git/objects/" directory, using the hash as the filename.
- Writes the tree entry into this newly created file.
- Prints the created tree object’s hash, or notifies if index is empty.
GP-3.1.0 | addTreeRecursive()
- Starts with a flat working list of file and directory entries, representing paths and their hashes.
- Repeatedly identifies the deepest-level directories in the list, grouping entries by their parent directory.
- For each such directory group, calls writeTreeObj to format their contents, compute a SHA-1 hash, and write a tree object file under "git/objects/" with that hash as the filename.
- Replaces all grouped entries in the working list with a single reference to the newly created tree object (using its hash and directory name).
- Continues this process recursively, ascending directory levels, until the working list is collapsed to one or more entries at the root level.
- If multiple root entries remain, combines and writes a final root tree object, then prints and returns its hash as the reference to the entire directory tree.
- The writeTreeObj method takes a list of entries, extracts relevant parts, formats the tree content, hashes it, writes it to the "git/objects/" folder, and returns the hash.