public void commit_file(string traked_file) { if (Depend_on.get_commit_num(traked_file) == -1) { string file_text = File.ReadAllText(traked_file); write_commit_node(traked_file, file_text); Depend_on.add_file(traked_file, commit_num); } else { int dependon_num = Depend_on.get_commit_num(traked_file); string current_content = File.ReadAllText(traked_file).Trim(' ', '\n'); Commit dependon_commit = new Commit(dependon_num); string source_content = dependon_commit.get_file_content(traked_file); string changes = helper.delta(source_content, current_content); if (changes == "THEY ARE SAME") { return; } write_commit_node(traked_file, changes); } }
public static void checkout(int commit_num) { Commit commit = new Commit(commit_num); string[] files_commited = commit.get_files_commited(); for (int i = 0; i < files_commited.Length; i++) { string[] file_changes = commit.get_file_content(files_commited[i]).Split("\n"); int commit_depend_on = Depend_on.get_commit_num(files_commited[i]); Commit dependon_commit = new Commit(commit_depend_on); List <string> dependon_file = new List <string>(dependon_commit.get_file_content(files_commited[i]).Split("\n")); if (commit_depend_on == commit_num) // the place for the origional file { File.WriteAllLines(files_commited[i], dependon_file); continue; } foreach (string line in file_changes) { bool add = line[0] == '+'; int line_num = Convert.ToInt32(line.Split("/>")[1]); string line_content = line.Split("/>")[2]; if (add) { dependon_file.Insert(line_num, line_content); } else { dependon_file.Remove(line_content); } } File.WriteAllLines(files_commited[i], dependon_file); } }