Skip to content

Commit

Permalink
changed files to reflect .gitignore file
Browse files Browse the repository at this point in the history
  • Loading branch information
yysun committed Oct 15, 2011
1 parent faf158e commit d5f5e9d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
9 changes: 8 additions & 1 deletion GitFileStatus.cs
Expand Up @@ -23,7 +23,14 @@ public class GitFile : INotifyPropertyChanged
{
public GitFileStatus Status { get; set; }
public string FileName { get; set; }
public bool IsStaged { get; set; }
public bool IsStaged {
get
{
return Status == GitFileStatus.Added ||
Status == GitFileStatus.Staged ||
Status == GitFileStatus.Removed;
}
}

public bool isSelected;
public bool IsSelected
Expand Down
65 changes: 30 additions & 35 deletions GitFileStatusTracker.cs
Expand Up @@ -24,9 +24,8 @@ public class GitFileStatusTracker : IDisposable
private Repository repository;
private Tree commitTree;
private GitIndex index;
private IList<IgnoreRule> ignoreRules;

private Dictionary<string, GitFileStatus> cache;
private IEnumerable<string> changedFiles;

public GitFileStatusTracker(string workingFolder)
{
Expand Down Expand Up @@ -85,9 +84,11 @@ public void Refresh()
this.index = repository.GetIndex();
this.index.RereadIfNecessary();

ignoreRules = File.ReadAllLines(Path.Combine(this.initFolder, Constants.GITIGNORE_FILENAME))
.Where(line => !line.StartsWith("#") && line.Trim().Length > 0)
.Select(line => new IgnoreRule(line)).ToList();
//ignoreRules = File.ReadAllLines(Path.Combine(this.initFolder, Constants.GITIGNORE_FILENAME))
// .Where(line => !line.StartsWith("#") && line.Trim().Length > 0)
// .Select(line => new IgnoreRule(line)).ToList();

this.changedFiles = GetChangedFiles();
}
}
catch (Exception ex)
Expand Down Expand Up @@ -185,12 +186,14 @@ private GitFileStatus GetFileStatusNoCache(string fileName)
}
if (File.Exists(fileName))
{
if (ignoreRules != null && ignoreRules.Any(rule => rule.IsMatch(fileName, false)))
if (changedFiles.Any(file => string.Compare(file, fileName, true) == 0))
{
return GitFileStatus.New;
}
else
{
return GitFileStatus.Ignored;
}

return GitFileStatus.New;
}
}

Expand Down Expand Up @@ -473,37 +476,36 @@ public static void Init(string folderName)
//}
}

private IEnumerable<GitFile> changedFiles;
public IEnumerable<GitFile> ChangedFiles
{
get
{
if (changedFiles == null)
if (changedFiles == null) changedFiles = GetChangedFiles();

foreach(string f in changedFiles)
{
FillCache();

changedFiles = from f in this.cache
where f.Value != GitFileStatus.Tracked &&
f.Value != GitFileStatus.NotControlled &&
f.Value != GitFileStatus.Ignored
select new GitFile
{
FileName = GetRelativeFileName(f.Key),
Status = f.Value,
IsStaged = f.Value == GitFileStatus.Added ||
f.Value == GitFileStatus.Staged ||
f.Value == GitFileStatus.Removed
};
this.cache[this.GetCacheKey(f)] = GetFileStatusNoCache(f);
}
return changedFiles;

return from f in this.cache
where f.Value != GitFileStatus.Tracked &&
f.Value != GitFileStatus.NotControlled &&
f.Value != GitFileStatus.Ignored
select new GitFile
{
FileName = GetRelativeFileName(f.Key),
Status = f.Value
};
}
}

private const int INDEX = 1;
private const int WORKDIR = 2;

public void FillCache()
public IList<string> GetChangedFiles()
{
var list = new List<string>();

var treeWalk = new TreeWalk(this.repository);
treeWalk.Recursive = true;
treeWalk.Filter = TreeFilter.ANY_DIFF;
Expand All @@ -526,17 +528,10 @@ public void FillCache()
while (treeWalk.Next())
{
var fileName = GetFullPath(treeWalk.PathString);

if (Directory.Exists(fileName)) continue; // this excludes sub modules

var cacheKey = GetCacheKey(fileName);
if (!this.cache.ContainsKey(cacheKey))
{
var status = GetFileStatusNoCache(fileName);
this.cache[cacheKey] = status;
//Debug.WriteLine(string.Format("==== Fill cache for {0} <- {1}", fileName, status));
}
list.Add(fileName);
}
return list;
}

private string GetCacheKey(string fileName)
Expand Down

0 comments on commit d5f5e9d

Please sign in to comment.