Skip to content

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

Merged
merged 1 commit into from
Apr 15, 2015
Merged

Conversation

Therzok
Copy link
Member

@Therzok Therzok commented Nov 7, 2014

Test can be improved, what else needs done?

@carlosmn
Copy link
Member

carlosmn commented Nov 7, 2014

"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?

@Therzok
Copy link
Member Author

Therzok commented Nov 7, 2014

@Therzok
Copy link
Member Author

Therzok commented Nov 7, 2014

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.

@Therzok Therzok changed the title Introduce StatusOptions.IncludeUnaltered Introduce StatusOptions switches Nov 7, 2014
@Therzok Therzok changed the title Introduce StatusOptions switches Introduce StatusOptions.IncludeUnaltered Nov 7, 2014
@nulltoken
Copy link
Member

Looks clean to me. 👍

@Therzok Therzok force-pushed the therzok/statusUnmodified branch from 270a6b1 to 177e5f3 Compare November 10, 2014 12:31
@Therzok
Copy link
Member Author

Therzok commented Nov 10, 2014

Rebased.

{
RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { IncludeUnaltered = true });

Assert.Equal(17, status.Unaltered.Count());
Copy link
Member

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 😜

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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().

Copy link
Member Author

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.

Copy link
Member Author

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?

http://www.dotnetbitsandpieces.com/?p=11

Copy link
Member Author

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.

Copy link
Member

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.

@Therzok Therzok force-pushed the therzok/statusUnmodified branch from 177e5f3 to 7339b31 Compare November 10, 2014 20:54
@Therzok
Copy link
Member Author

Therzok commented Nov 10, 2014

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.

@Therzok
Copy link
Member Author

Therzok commented Nov 10, 2014

In fact, let me rephrase, this is the output.
1.txt
1/branch_file.txt
branch_file.txt
branch_file.txt
deleted_unstaged_file.txt
modified_staged_file.txt
modified_unstaged_file.txt
new.txt
new.txt
new_tracked_file.txt
README

{
RepositoryStatus status = repo.Index.RetrieveStatus(new StatusOptions() { IncludeUnaltered = true });

Assert.Equal(11, status.Unaltered.Count());
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

@nulltoken
Copy link
Member

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.

@ethomson I think you're one of the latest that have worked in this area. Any thoughts?

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be &&?

Copy link
Member Author

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.

@nulltoken
Copy link
Member

error CS1501: No overload for method 'RetrieveStatus' takes 1 arguments [C:\projects\libgit2sharp\LibGit2Sharp.Tests\LibGit2Sharp.Tests.csproj]

@Therzok Therzok force-pushed the therzok/statusUnmodified branch from 5fa6eef to a8493e3 Compare November 12, 2014 22:10
{
RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { IncludeUnaltered = true });

Assert.Equal(11, status.Unaltered.Count());
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

@Therzok Therzok force-pushed the therzok/statusUnmodified branch 2 times, most recently from fa21d54 to 77ab73a Compare November 13, 2014 09:02
@Therzok
Copy link
Member Author

Therzok commented Dec 2, 2014

@ethomson anything else you'd like to add? I'm at a loss.

@ethomson
Copy link
Member

ethomson commented Dec 5, 2014

Yeah, something fishy is going on in libgit2 land. I will try to dig in to this over the weekend.

@Therzok
Copy link
Member Author

Therzok commented Dec 29, 2014

@ethomson am I actually doing something wrong regarding this? Or is it really a libgit2 bug?

@ethomson
Copy link
Member

ethomson commented Jan 5, 2015

@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.

@Therzok
Copy link
Member Author

Therzok commented Apr 5, 2015

Okay, this seems fixed in latest libgit2. Merge at will. The appveyor failure seems unrelated.

@Therzok Therzok force-pushed the therzok/statusUnmodified branch from d63c300 to c930e2f Compare April 5, 2015 14:30
@@ -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);
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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.

👍

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

@Therzok Therzok force-pushed the therzok/statusUnmodified branch 2 times, most recently from 1a1be46 to a3fcb1e Compare April 5, 2015 18:01
[Theory]
[InlineData(false, 0)]
[InlineData(true, 5)]
public void CanRetrieveTheStatusOfTheWholeWorkingDirectory(bool includeUnaltered, int untrackedCount)
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

@Therzok Therzok force-pushed the therzok/statusUnmodified branch from a3fcb1e to 11da2fa Compare April 7, 2015 13:03
@Therzok
Copy link
Member Author

Therzok commented Apr 10, 2015

@nulltoken can you slap travis around with a large trout?

@nulltoken
Copy link
Member

@Therzok Travis seems to have recovered. Still needed?

@Therzok
Copy link
Member Author

Therzok commented Apr 11, 2015

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)
Copy link
Member

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)?

Copy link
Member

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.

@nulltoken nulltoken added this to the v0.22 milestone Apr 11, 2015
@nulltoken
Copy link
Member

@jamill Are you happy to see this in now?

@jamill
Copy link
Member

jamill commented Apr 15, 2015

Looks good, thanks!

nulltoken added a commit that referenced this pull request Apr 15, 2015
Introduce StatusOptions.IncludeUnaltered
@nulltoken nulltoken merged commit 40de694 into vNext Apr 15, 2015
@nulltoken nulltoken deleted the therzok/statusUnmodified branch April 15, 2015 18:11
@nulltoken
Copy link
Member

@Therzok 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants