Skip to content

Should we allow Configuration to parse a local repository config? #1042

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 3 commits into from
Jun 6, 2015

Conversation

nulltoken
Copy link
Member

@shiftkey in #1031 made an amazing job getting rid of the optional parameters in favor of overloads. While taking a look at the changes in Configuration, I wondered if there was a use case where one would need to access the config of a repository without instantiating it.

Should this need be fulfilled, we'd rather make it happen in v0.22 as it will be quite a nasty breaking change.

/cc @jamill @ethomson

@carlosmn
Copy link
Member

Would you need to do a breaking change? Why not have a

Configuration.FromRepository(string path)

named constructor which would make sure ther's a repo at path and open a single config file. You should be able to add that at any point.

@nulltoken
Copy link
Member Author

@carlosmn even if we make this method static, it would still be exposed by an instance ot the type. And this could lead to such unexpected code construct

var repo = new Repository(@"c:\a)
var configFromA = repo.Config;
var configFromB = repo.Config.FromRepository(@"c:\b");

@carlosmn
Copy link
Member

Well, don't do that? If you do that you're ignoring the documentation which says that's a named constructor plus your IDE telling you it's a static method and you should not use an instance to refer to it.

@nulltoken
Copy link
Member Author

that's a named constructor

There's no such thing in C#

your IDE telling you it's a static method

It's perfectly valid to call a static method from an instance

If you do that you're ignoring the documentation

I think very few people actually read the documentation. Most of them rely on intellisense and try-outs.

  • I'd rather prevent the user from shooting him/herself in the foot by making such code construct impossible
  • I'd rather not depend on "hoping" he/she'll make the good choice because he/she previously carefully read the documentation

I may indeed have little faith in humanity...

@Therzok
Copy link
Member

Therzok commented May 10, 2015

I may indeed have little faith in humanity...

seconded.

@bording
Copy link
Member

bording commented May 11, 2015

@nulltoken, I think you might be confusing static methods with extension methods here. For your code example above to be valid, FromRepository() would have to be declared as:

public static Configuration FromRepository(this Configuration configuration, string path)

but if you do it this way instead:

public static Configuration FromRepository(string path)

the method would work as @carlosmn proposes with no intellisense confusion.

@nulltoken
Copy link
Member Author

public static Configuration FromRepository(string path)

the method would work as @carlosmn proposes with no intellisense confusion.

@bording You're totally right! Thanks for having corrected me. (crawling back shamefully under my rock)

@nulltoken nulltoken force-pushed the ntk/config_frompaths branch 2 times, most recently from 6edfe44 to 76e88dd Compare May 30, 2015 15:04
@nulltoken
Copy link
Member Author

So, I did this thing.... which is now ready for review.

@nulltoken nulltoken force-pushed the ntk/config_frompaths branch from a0c2c9c to b03c9d1 Compare May 31, 2015 15:09
string xdgConfigurationFileLocation, string systemConfigurationFileLocation)
{
this.repository = repository;

if (repositoryConfigurationFileLocation != null)
{
repoConfigPath = NormalizeConfigPath(repositoryConfigurationFileLocation);
Copy link
Member

Choose a reason for hiding this comment

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

when does this have to be normalized? Could we have a single expected format for the incoming config file location?

Copy link
Member Author

Choose a reason for hiding this comment

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

This probing was added because @ethomson mentioned once that it might be interesting to not being compelled to pass the full path to the config.

As such, it would accept a working directory, a bare repository folder or a full path to a known config file.

If this is no longer required, I can easily remove it.

@jamill
Copy link
Member

jamill commented Jun 1, 2015

👍 I think this looks good!

@nulltoken
Copy link
Member Author

Note to self: drop the Repository member if it's not needed

@nulltoken nulltoken force-pushed the ntk/config_frompaths branch from b03c9d1 to ca4d15e Compare June 6, 2015 08:30
nulltoken added a commit that referenced this pull request Jun 6, 2015
Should we allow Configuration to parse a local repository config?
@nulltoken nulltoken merged commit 01b4c5e into vNext Jun 6, 2015
@nulltoken nulltoken deleted the ntk/config_frompaths branch June 6, 2015 09:19
@nulltoken
Copy link
Member Author

Published as NuGet pre-release package LibGit2Sharp.0.22.0-pre20150606092322

@nulltoken nulltoken added this to the v0.22 milestone Jun 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants