-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepo.cpp
More file actions
88 lines (77 loc) · 2.39 KB
/
Copy pathRepo.cpp
File metadata and controls
88 lines (77 loc) · 2.39 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Repo.hpp"
#include <iostream>
using namespace std;
doublyNode* Repo::createDoublyNode(int commitNum) {
doublyNode* initialNode = new doublyNode;
initialNode->head = NULL;
initialNode->previous = NULL;
initialNode->commitNumber = commitNum;
nodeCount ++;
initialNode->next = NULL;
return initialNode;
}
doublyNode* Repo::createDoublyNode(int commitNum, doublyNode* previous) {
doublyNode* initialNode = new doublyNode;
initialNode->head = NULL;
initialNode->previous = previous;
initialNode->commitNumber = commitNum;
nodeCount ++;
initialNode->next = NULL;
return initialNode;
}
Repo::Repo() : nodeCount(0)
//constructor
{
headNode = createDoublyNode(getLatestCommitNum());
latestCommit = headNode;
currentCommit = headNode;
}
void Repo::commit() {
latestCommit->next = createDoublyNode(getLatestCommitNum(), latestCommit);
latestCommit = latestCommit->next;
currentCommit = latestCommit;
}
bool Repo::currentLatestMismatch() {
if((currentCommit->commitNumber) == latestCommit->commitNumber) return false;
cout << "Error: operation prohibited while checking out code." << endl;
return true;
}
doublyNode* Repo::getCurrentCommit() {
return currentCommit;
}
singlyNode* createSinglyNode(string fileName, singlyNode* next) {
singlyNode* newNode = new singlyNode;
newNode->fileName = fileName;
newNode->next = next;
newNode->fileVersion = "00";
return newNode;
}
void Repo::addFile(string fileName) {
singlyNode* newNode = createSinglyNode(fileName, latestCommit->head);
latestCommit->head = newNode;
cout << " Successfully added." << endl;
}
int Repo::getLatestCommitNum() {
return nodeCount;
}
bool Repo::removeFile(string fileName) {
bool found = false;
singlyNode* current = latestCommit->head;
if(current == NULL) {
return false;
}
if(current->fileName == fileName) {
latestCommit->head = current->next;
delete current;
return true;
}
while(found == false && current->next != NULL) {
if(current->next->fileName == fileName) found == true;
else current = current->next;
}
if(found == false) return false;
singlyNode* temp = current->next;
current->next = current->next->next;
delete temp;
return true;
}