test_class.file: server-core/src/test/java/io/onedev/server/git/BlobEditsTest.java
test_class.identifier: BlobEditsTest
test_class.superclass: extends AbstractGitTest
test_case.body: @Test
  	public void testAddFile() throws IOException {
  		createDir("client");
  		addFileAndCommit("client/a.java", "a", "add a");
  		addFileAndCommit("client/b.java", "b", "add b");
  		
  		createDir("server/src/com/example/a");
  		createDir("server/src/com/example/b");
  		addFileAndCommit("server/src/com/example/a/a.java", "a", "add a");
  		addFileAndCommit("server/src/com/example/b/b.java", "b", "add b");
  		
  		String refName = "refs/heads/master";
  		ObjectId oldCommitId = git.getRepository().resolve(refName);
  
  		Map<String, BlobContent> newBlobs = new HashMap<>();
  		newBlobs.put("/server/src/com/example/c/c.java", new BlobContent.Immutable("c".getBytes(), FileMode.REGULAR_FILE));
  		newBlobs.put("/server/src/com/example/d/d.java", new BlobContent.Immutable("d".getBytes(), FileMode.REGULAR_FILE));
  		BlobEdits edits = new BlobEdits(Sets.newHashSet(), newBlobs);
  		ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test add");
  		
  		try (RevWalk revWalk = new RevWalk(git.getRepository())) {
  			RevTree revTree = revWalk.parseCommit(newCommitId).getTree();
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/a/a.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/b/b.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/c/c.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/d/d.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "client/a.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "client/b.java", revTree));
  		}
  		
  		oldCommitId = newCommitId;
  		newBlobs = new HashMap<>();
  		newBlobs.put("/common/common.java", new BlobContent.Immutable("common".getBytes(), FileMode.REGULAR_FILE));
  		edits = new BlobEdits(Sets.newHashSet(), newBlobs);
  		newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test add");
  		
  		try (RevWalk revWalk = new RevWalk(git.getRepository())) {
  			RevTree revTree = revWalk.parseCommit(newCommitId).getTree();
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/a/a.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/b/b.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/c/c.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "client/a.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "client/b.java", revTree));
  			assertNotNull(TreeWalk.forPath(git.getRepository(), "common/common.java", revTree));
  		}
  	}
test_case.class_method_signature: BlobEditsTest.testAddFile()
test_case.full_signature: @Test public void testAddFile()
test_case.identifier: testAddFile
test_case.invocations: createDir addFileAndCommit addFileAndCommit createDir createDir addFileAndCommit addFileAndCommit resolve getRepository put getBytes put getBytes newHashSet commit getRepository getRepository getTree parseCommit assertNotNull forPath getRepository assertNotNull forPath getRepository assertNotNull forPath getRepository assertNotNull forPath getRepository assertNotNull forPath getRepository assertNotNull forPath getRepository put getBytes newHashSet commit getRepository getRepository getTree parseCommit assertNotNull forPath getRepository assertNotNull forPath getRepository assertNotNull forPath getRepository assertNotNull forPath getRepository assertNotNull forPath getRepository assertNotNull forPath getRepository
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testAddFile()
focal_class.declarator: serialVersionUID = 1L
focal_class.modifier: private static final
focal_class.original_string: private static final long serialVersionUID = 1L;
focal_class.type: long
focal_class.var_name: serialVersionUID
focal_class.declarator: oldPaths
focal_class.modifier: private final
focal_class.original_string: private final Set<String> oldPaths;
focal_class.type: Set<String>
focal_class.var_name: oldPaths
focal_class.declarator: newBlobs
focal_class.modifier: private final
focal_class.original_string: private final Map<String, BlobContent> newBlobs;
focal_class.type: Map<String, BlobContent>
focal_class.var_name: newBlobs
focal_class.file: server-core/src/main/java/io/onedev/server/git/BlobEdits.java
focal_class.identifier: BlobEdits
focal_class.interfaces: implements Serializable
focal_class.class_method_signature: BlobEdits.BlobEdits(Set<String> oldPaths, Map<String, BlobContent> newBlobs)
focal_class.full_signature: public  BlobEdits(Set<String> oldPaths, Map<String, BlobContent> newBlobs)
focal_class.identifier: BlobEdits
focal_class.modifiers: public
focal_class.parameters: (Set<String> oldPaths, Map<String, BlobContent> newBlobs)
focal_class.signature:  BlobEdits(Set<String> oldPaths, Map<String, BlobContent> newBlobs)
focal_class.class_method_signature: BlobEdits.getOldPaths()
focal_class.full_signature: public Set<String> getOldPaths()
focal_class.identifier: getOldPaths
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Set<String>
focal_class.signature: Set<String> getOldPaths()
focal_class.class_method_signature: BlobEdits.getNewBlobs()
focal_class.full_signature: public Map<String, BlobContent> getNewBlobs()
focal_class.identifier: getNewBlobs
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Map<String, BlobContent>
focal_class.signature: Map<String, BlobContent> getNewBlobs()
focal_class.class_method_signature: BlobEdits.insertTree(RevTree revTree, TreeWalk treeWalk, ObjectInserter inserter, 
  			String parentPath, Set<String> currentOldPaths, Map<String, BlobContent> currentNewBlobs)
focal_class.full_signature: private ObjectId insertTree(RevTree revTree, TreeWalk treeWalk, ObjectInserter inserter, 
  			String parentPath, Set<String> currentOldPaths, Map<String, BlobContent> currentNewBlobs)
focal_class.identifier: insertTree
focal_class.modifiers: private
focal_class.parameters: (RevTree revTree, TreeWalk treeWalk, ObjectInserter inserter, 
  			String parentPath, Set<String> currentOldPaths, Map<String, BlobContent> currentNewBlobs)
focal_class.return: ObjectId
focal_class.signature: ObjectId insertTree(RevTree revTree, TreeWalk treeWalk, ObjectInserter inserter, 
  			String parentPath, Set<String> currentOldPaths, Map<String, BlobContent> currentNewBlobs)
focal_class.class_method_signature: BlobEdits.commit(Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage)
focal_class.full_signature: public ObjectId commit(Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage)
focal_class.identifier: commit
focal_class.modifiers: public
focal_class.parameters: (Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage)
focal_class.return: ObjectId
focal_class.signature: ObjectId commit(Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage)
focal_method.body: public ObjectId commit(Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage) {
  		
  		try (	RevWalk revWalk = new RevWalk(repository); 
  				TreeWalk treeWalk = new TreeWalk(repository);
  				ObjectInserter inserter = repository.newObjectInserter();) {
  
  	        CommitBuilder commit = new CommitBuilder();
  	        
  	        commit.setAuthor(authorAndCommitter);
  	        commit.setCommitter(authorAndCommitter);
  	        commit.setMessage(commitMessage);
  
  			RevTree revTree;
  	        if (!parentCommitId.equals(ObjectId.zeroId())) {
  	        	commit.setParentId(parentCommitId);
  				revTree = revWalk.parseCommit(parentCommitId).getTree();
  				treeWalk.addTree(revTree);
  	        } else {
  				revTree = null;
  	        }
  
  			ObjectId treeId = insertTree(revTree, treeWalk, inserter, null, new HashSet<>(oldPaths), 
  					new HashMap<>(newBlobs));
  	        
  	        if (treeId != null)
  	        	commit.setTreeId(treeId);
  	        else 
  	        	commit.setTreeId(inserter.insert(new TreeFormatter()));
  	        
  	        ObjectId commitId = inserter.insert(commit);
  	        inserter.flush();
  	        RefUpdate ru = repository.updateRef(refName);
  	        ru.setRefLogIdent(authorAndCommitter);
  	        ru.setNewObjectId(commitId);
  	        ru.setExpectedOldObjectId(expectedOldCommitId);
  	        GitUtils.updateRef(ru);
  	        
  	        return commitId;
  		} catch (RevisionSyntaxException | IOException e) {
  			throw new RuntimeException(e);
  		}
  	}
focal_method.class_method_signature: BlobEdits.commit(Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage)
focal_method.full_signature: public ObjectId commit(Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage)
focal_method.identifier: commit
focal_method.invocations: newObjectInserter setAuthor setCommitter setMessage equals zeroId setParentId getTree parseCommit addTree insertTree setTreeId setTreeId insert insert flush updateRef setRefLogIdent setNewObjectId setExpectedOldObjectId updateRef
focal_method.modifiers: public
focal_method.parameters: (Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage)
focal_method.return: ObjectId
focal_method.signature: ObjectId commit(Repository repository, String refName, ObjectId expectedOldCommitId, ObjectId parentCommitId, 
  			PersonIdent authorAndCommitter, String commitMessage)