Permalink
Browse files

fix the logic of detecting moved and copied changes

  • Loading branch information...
yysun committed Oct 27, 2012
1 parent a2da513 commit c5749ee8d63b28e6ac41f1e16a2cb6149396ad13
Showing with 23 additions and 18 deletions.
  1. +1 −0 GitApi/DataServices/Change.cs
  2. +22 −18 GitApi/DataServices/RepositoryGraph.cs
@@ -19,6 +19,7 @@ public enum ChangeType
TypeChanged,
Renamed,
Copied,
+ Unmerged,
Unknown
}
}
@@ -299,36 +299,36 @@ public IEnumerable<Change> GetChanges(string fromCommitId, string toCommitId)
lastNewLinePos = trimmedStatus.IndexOfAny(nl, ind >= 0 ? ind : 0);
trimmedStatus = trimmedStatus.Substring(0, lastNewLinePos).Trim(nl);
}
- else //Warning at beginning
+ else //Warning at beginning
trimmedStatus = trimmedStatus.Substring(lastNewLinePos).Trim(nl);
}
var files = trimmedStatus.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
for (int n = 0; n < files.Length; n++)
{
- if (string.IsNullOrEmpty(files[n]))
- continue;
+ string status = files[n];
+ var fileName = string.Empty;
+ var change = ParseStaus(status);
- int splitIndex = files[n].IndexOfAny(new char[] { '\0', '\t', ' ' }, 1);
-
- string status = string.Empty;
- string fileName = string.Empty;
-
- if (splitIndex < 0)
- {
- status = files[n];
- fileName = files[n + 1];
- n++;
- }
- else
+ switch (change)
{
- status = files[n].Substring(0, splitIndex);
- fileName = files[n].Substring(splitIndex);
+ case ChangeType.Renamed:
+ case ChangeType.Copied:
+ fileName = files[n + 2];
+ n++; n++;
+ break;
+ case ChangeType.Unknown:
+ continue;
+ default:
+
+ fileName = files[n + 1];
+ n++;
+ break;
}
changes.Add(new Change
{
- ChangeType = ParseStaus(status),
+ ChangeType = change,
Name = fileName.Trim()
});
}
@@ -344,6 +344,8 @@ public IEnumerable<Change> GetChanges(string fromCommitId, string toCommitId)
private ChangeType ParseStaus(string status)
{
+ if(string.IsNullOrEmpty(status)) return ChangeType.Unknown;
+
char x = status[0];
switch (x)
{
@@ -359,6 +361,8 @@ private ChangeType ParseStaus(string status)
return ChangeType.Renamed;
case 'T':
return ChangeType.TypeChanged;
+ case 'U':
+ return ChangeType.Unmerged;
}
return ChangeType.Unknown;
}

0 comments on commit c5749ee

Please sign in to comment.