-
Notifications
You must be signed in to change notification settings - Fork 899
Introduce StatusOptions.IncludeUnaltered #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
"unaltered" sounds like a weird way to talk about unmodified files; what's the reason behind the different name for the option than the libgit2 flag? |
I know why this fails, I haven't rebased on top of master and it appears to merge cleanly. When this has a 👍 from everyone, I'll rebase. |
Looks clean to me. 👍 |
270a6b1
to
177e5f3
Compare
Rebased. |
{ | ||
RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { IncludeUnaltered = true }); | ||
|
||
Assert.Equal(17, status.Unaltered.Count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ git ls-files
1.txt
1/branch_file.txt
README
branch_file.txt
deleted_unstaged_file.txt
modified_staged_file.txt
modified_unstaged_file.txt
new.txt
new_tracked_file.txt
$ git status -s
D deleted_staged_file.txt
D deleted_unstaged_file.txt
M modified_staged_file.txt
M modified_unstaged_file.txt
A new_tracked_file.txt
?? new_untracked_file.txt
Considering this above, 17
looks like a very high number to me 😜
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That includes the .git directory for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That includes the .git directory for some reason.
Huh? That's weird. Outputting to Console the content of Unaltered on my box renders the following
Unaltered: 1.txt
Unaltered: 1\branch_file.txt
Unaltered: branch_file.txt
Unaltered: branch_file.txt
Removed: deleted_staged_file.txt
Missing: deleted_unstaged_file.txt
Unaltered: deleted_unstaged_file.txt
Unaltered: modified_staged_file.txt
Staged: modified_staged_file.txt
Modified: modified_unstaged_file.txt
Unaltered: modified_unstaged_file.txt
Unaltered: new.txt
Unaltered: new.txt
Unaltered: new_tracked_file.txt
Added: new_tracked_file.txt
Untracked: new_untracked_file.txt
Unaltered: README
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wut? All items that are staged are also marked as unaltered. This is a weird one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unaltered
is defined as 0
, which means it's always being matched by HasFlag()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooooh. I see. Great, I'm going to modify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I want to state that HasFlag is slow code compared to bitwise check and a status is performance critical.
Should I change it to a bitwise comparison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which reminds me that the indexer operator on RepositoryStatus isn't tested, otherwise it would've been triggered in an unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's often premature optimization, but I agree that here it's probably worth it.
177e5f3
to
7339b31
Compare
Okay, new version up, I want to state that libgit2 is emitting two statuses for items that are changed in the index and unchanged in the workdir. So it ends up as Modified | Staged in the index and Unaltered in the workdir. |
In fact, let me rephrase, this is the output. |
{ | ||
RepositoryStatus status = repo.Index.RetrieveStatus(new StatusOptions() { IncludeUnaltered = true }); | ||
|
||
Assert.Equal(11, status.Unaltered.Count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we willing to retrieve here? The number of files that are identical in the workdir, the index and the HEAD? If that's the case, I've got the feeling that the number should be a bit lower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's why I'm confused over here. Probably a bug in libgit2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, what are you trying to compare to? Is the file in the working directory the same as the index? The same as HEAD?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to get all the files that are unchanged (both index and workdir) vs. HEAD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could've been solved easily if there were 2 entries of Unaltered, one for index, one for workdir, but README is the same as branch_file.txt in terms of status, yet the latter is appearing twice, while the former appears just once.
@ethomson I think you're one of the latest that have worked in this area. Any thoughts? |
7339b31
to
5fa6eef
Compare
@@ -81,7 +82,7 @@ internal RepositoryStatus(Repository repo, StatusOptions options) | |||
AddStatusEntryForDelta(entry.Status, deltaHeadToIndex, deltaIndexToWorkDir); | |||
} | |||
|
|||
isDirty = statusEntries.Any(entry => entry.State != FileStatus.Ignored); | |||
isDirty = statusEntries.Any(entry => entry.State != FileStatus.Ignored || entry.State != FileStatus.Unaltered); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be &&
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh, I'm a retard. Fixing it.
|
5fa6eef
to
a8493e3
Compare
{ | ||
RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { IncludeUnaltered = true }); | ||
|
||
Assert.Equal(11, status.Unaltered.Count()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Therzok Could you chnage the 11
so that it actually reflects the real number of files we'd like to see retrieved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can. And I will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, even better maybe, directly assert the expected filenames?
fa21d54
to
77ab73a
Compare
@ethomson anything else you'd like to add? I'm at a loss. |
Yeah, something fishy is going on in libgit2 land. I will try to dig in to this over the weekend. |
@ethomson am I actually doing something wrong regarding this? Or is it really a libgit2 bug? |
@Therzok There's a libgit2 bug in here around combining the two lists. I'll try to take a look at it further this week. Sorry about the delay with the holidays and the $DAYJOB and such. |
77ab73a
to
d63c300
Compare
Okay, this seems fixed in latest libgit2. Merge at will. The appveyor failure seems unrelated. |
d63c300
to
c930e2f
Compare
@@ -81,7 +82,7 @@ internal RepositoryStatus(Repository repo, StatusOptions options) | |||
AddStatusEntryForDelta(entry.Status, deltaHeadToIndex, deltaIndexToWorkDir); | |||
} | |||
|
|||
isDirty = statusEntries.Any(entry => entry.State != FileStatus.Ignored); | |||
isDirty = statusEntries.Any(entry => entry.State != FileStatus.Ignored && entry.State != FileStatus.Unaltered); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Therzok As we're modifying the behavior of the IsDirty
property, could you please add some test coverage regarding this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we don't quite modify the behaviour. We extend it here.
Without IncludeUnaltered, we never had Unaltered file status. I'll add coverage for it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, does having Untracked files mark the status as dirty? Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say no. What does git.git has to say about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a:
test -n "$(git status --porcelain)" || echo "asdf"
with untracked files and that makes it considered dirty. "asdf" isn't printed.
Okay, should be good to go now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the option to take out Untracked files is something else.
You can query the git commandline in two ways for status changes:
git status --porcelain
git status --porcelain -uno (no untracked)
That's for later, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the option to take out Untracked files is something else.
Dammit! I read it backwards.
That's for later, yes.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileStatus
is a Flag
enum - do you mean to use the !=
comparison, or should we use the Enum.HasFlag
to check for these instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are exclusive statuses. Unaltered and Ignored can only appear by themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, x & 0 == 0 always. So we can't use bitwise and on Unaltered.
1a1be46
to
a3fcb1e
Compare
[Theory] | ||
[InlineData(false, 0)] | ||
[InlineData(true, 5)] | ||
public void CanRetrieveTheStatusOfTheWholeWorkingDirectory(bool includeUnaltered, int untrackedCount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing both unaltered and altered for status dirtiness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be unalteredCount
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm an idiot, fixing that now.
a3fcb1e
to
11da2fa
Compare
@nulltoken can you slap travis around with a large trout? |
@Therzok Travis seems to have recovered. Still needed? |
As long as it's green, I'm okay with it. Ready to merge. 🎱 |
@@ -164,14 +171,21 @@ private void AddStatusEntryForDelta(FileStatus gitStatus, GitDiffDelta deltaHead | |||
|
|||
StatusEntry statusEntry = new StatusEntry(filePath, gitStatus, headToIndexRenameDetails, indexToWorkDirRenameDetails); | |||
|
|||
foreach (KeyValuePair<FileStatus, Action<RepositoryStatus, StatusEntry>> kvp in dispatcher) | |||
if (gitStatus == FileStatus.Unaltered) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we handle the FileStatus.Unaltered
value in the same way we handle the other values (in the dispatcher dictionary)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah - probably not if FileStatus.Unaltered = 0
.
@jamill Are you happy to see this in now? |
Looks good, thanks! |
Introduce StatusOptions.IncludeUnaltered
@Therzok 👍 |
Test can be improved, what else needs done?