function GitRepoStorageHandler(user, streamUtilities) { var storageKey = user + 'GitP4Repos'; var mStreamUtilities = streamUtilities; this.addRepo = function(repo) { //grab all the gitRepos from localStorage, add this one to it, then store them again. var repoObjects = getAllValidGitRepos(); repoObjects.push(repo); localStorage[storageKey] = JSON.stringify(repoObjects); } this.deleteRepo = function(repo) { //get the repos from localStorage, find this one, delete it, then store the rest. var repoObjects = getAllValidGitRepos(); var buf = []; for( var i = 0; i < repoObjects.length; i++ ) { if( repo.mStream != repoObjects[i].mStream ) buf.push(repoObjects[i]); else console.log('not adding ' + repoObjects[i].mStream + ' to buf'); } localStorage[storageKey] = JSON.stringify(buf); } this.getGitDepotRepos = function() { var allRepos = getAllValidGitRepos(); var depotRepos = []; for( var i = 0; i < allRepos.length; i++ ) if( allRepos[i].mPort === mStreamUtilities.getPort() && allRepos[i].mDepot === mStreamUtilities.currentDepot ) depotRepos.push( allRepos[i] ); return depotRepos; } function getAllValidGitRepos() { /* Overview: This is how the git repos and branches are assembled. First, we get git repo meta-data from localStorage (this is created when the user makes git repos and branches in the stream graph). Next, we match the metadata with the actual repos and branches that are on the user's local hard drive. There might be some mismatch here--e.g. a user may have created and deleted things on their hard drive--so if the metadata doesn't match reality, get rid of the offending metadata. And here's the algorithm: create an empty array called validBranches get all of the localStorage gitRepos create a hash called allBranches that will contain the git locations stored in metadata: key == gitRepo.mGitRepoFolder and value == array of the names of actual existing branches for that repo (not localStorage branches) create a hash called metaBranches that has only the branches from the metadata: key == gitRepo.mGitRepoFolder and value == the array of gitRepos associated with that folder go through each branch in allBranches if it has an associated gitRepo in metaBranches if that gitRepo's parent no longer exists change the gitRepo's parent to 'master' add the gitRepo to validBranches else create a gitRepo for the branch and add it to validBranches Save this setup to localStorage: localStorage[storageKey] = JSON.stringify(validBranches); return validBranches */ //create an empty array called validBranches var validBranches = []; //get all of the localStorage gitRepos var gitRepos = getMetaData(); //keep all of the metadata that DOESN'T belong to this depot, we only want to validate the stuff in this depot. var port = mStreamUtilities.getPort(); var currentDepot = mStreamUtilities.currentDepot; for( var i = 0; i < gitRepos.length; i++ ) { if( gitRepos[i].mDepot != currentDepot || gitRepos[i].mPort != port ) { //console.log( 'adding ' + gitRepos[i].mName ); validBranches.push( gitRepos[i] ); } } var allDirectories = []; //create a hash called allBranches that will contain the git locations stored in metadata: key == gitRepo.mGitRepoFolder and //value == array of the names of actual existing branches for that repo (not localStorage branches) //create a hash called metaBranches that has only the branches from the metadata: key == gitRepo.mGitRepoFolder and //value == the array of gitRepos associated with that folder var allBranches = {}; var metaBranches = {}; for( var i = 0; i < gitRepos.length; i++ ) { var directory = gitRepos[i].mGitRepoFolder; if( !allBranches[directory] && !metaBranches[directory] ) { var branches = mStreamUtilities.getGitBranches(directory); allBranches[directory] = branches; metaBranches[directory] = []; allDirectories.push(directory); } metaBranches[directory].push( gitRepos[i] ); } //go through each branch in allBranches for( var i = 0; i < allDirectories.length; i++ ) { var directory = allDirectories[i]; var branches = allBranches[directory]; for( var j = 0; j < branches.length; j++ ) { var branch = branches[j]; // if it has an associated gitRepo in metaBranches var metaBranchExists = false; for( var k = 0; k < metaBranches[directory].length; k++ ) { var gitRepo = metaBranches[directory][k]; if( gitRepo.mName === branch ) { metaBranchExists = true; //if this is the master repo, it's parent is a stream so we don't have to check for it's parent being missing. //Unless of course that stream has been deleted. Writing software is complex sometimes, you know? if( gitRepo.mType === mStreamUtilities.StreamType.gitBranch ) { var parentExists = false; // if that gitRepo's parent no longer exists for( var l = 0; l < allBranches[directory].length; l++ ) { if( gitRepo.mParentName === allBranches[directory][l] ) { parentExists = true; break; } } // change the gitRepo's parent to 'master' if( !parentExists ) { gitRepo.mParent = gitRepo.mGitRepoFolder + '/master'; gitRepo.mParentType = mStreamUtilities.StreamType.gitRepo; } } // add the gitRepo to validBranches validBranches.push(gitRepo); break; } } // else if(!metaBranchExists) { //get the master repo, use it to create the new gitRepo var master = getNamedBranch('master', metaBranches[directory]); // create a gitRepo for the branch and add it to validBranches if( master ) { var gitRepo = mStreamUtilities.createGitBranchObj(master, branch); validBranches.push(gitRepo); } } } } //Save this setup to localStorage localStorage[storageKey] = JSON.stringify(validBranches); return validBranches } function getNamedBranch(name, gitRepos) { for( var i = 0; i < gitRepos.length; i++ ) if( name === gitRepos[i].mName ) return gitRepos[i]; return null; } function getMetaData() { //grab the gitReps from localStorage, convert them into GitRepo objects (they'll come back as just Objects), //and return them to the user. /* Returned from localStorage: mChangeFlowsFromParent: true mChangeFlowsToParent: true mDescription: "my repo description" mFirmerThanParent: true mName: "DevCode" mOptions: "git repo options" mOwner: "" mParent: "//SomeDepot/subdev" mStream: "//users/temp/devWs " mType: 1 mP4WorkspaceFolder mGitRepoFolder GitRepo signature: function GitRepo( repoData, owner, parent, parentType, type, description, options, changeFlowsFromParent, changeFlowsToParent, firmerThanParent) And repoData: GitP4Stream=true GitRepoName=monkey GitRepoFolder=gorilla WorkspaceName=chimp WorkspaceFolder=orangutan */ var objString = localStorage[storageKey]; var repoObjects = []; var temp = {}; if( objString ) { var objects = JSON.parse(objString); for(var i = 0; i < objects.length; i++) { //if( objects[i].mPort === mStreamUtilities.getPort() && objects[i].mDepot === mStreamUtilities.currentDepot ) if( !(objects[i].mStream in temp) ) { temp[objects[i].mStream] = 'monkey'; var repoData = {}; repoData.gitP4Stream = true; repoData.gitRepoName = objects[i].mName; repoData.gitRepoFolder = objects[i].mGitRepoFolder; repoData.workspaceName = objects[i].mWorkspaceName; repoData.workspaceFolder = objects[i].mP4WorkspaceFolder; var gitRepo = new GitRepo(repoData, objects[i].mOwner, objects[i].mParent, objects[i].mType, objects[i].mParentType, objects[i].mDescription, objects[i].mOptions, objects[i].mChangeFlowsFromParent, objects[i].mChangeFlowsToParent, objects[i].mFirmerThanParent, objects[i].mDepot, objects[i].mPort ); repoObjects.push(gitRepo); } } } return repoObjects; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 8081 | David George |
Initial submit of JavaScript StreamGraph. Main functionality is: Change Trajectory (Change Flow), Timeline, and GitStreams. |