Jul 5, 2011

Experience with having a non Dist::Zilla user contribute to a Dist::Zilla project (it's not hard for them or me)

I've heard many times that Dist::Zilla makes it harder for people to contribute to the project. This is not true, it is either unfortunately either ignorance or FUD (much like saying Linux is harder to use than Windows). Truly, there are things that some dzil users do that can make it harder, but it doesn't have to be that way. Michael Schwern recently contributed to one of my dzil projects without ever realizing I was using dzil, until I told him. He more recently stated on twitter, "While your solution works, it seems like it makes more work for you to shield contributors from dzil". This was true in this case because I wasn't sure how to effectively move a series of multiple patches, I now know it's easy to do with git. Here's how you can allow contributors to contribute to your dzil project without causing you or them undo pain.

  1. Don't use anything that changes the line numbers of your source
    Examples: don't use DZP::Prepender. Use modules like OurPkgVersion to insert VERSION, and make sure your # ABSTRACT and any pod is below the 1; at the end of your module. This will keep the line numbers of errors in your code from being different from the final build. It's still ok to use PodWeaver as it will save you way more time than it'll hurt, so long as you follow the rules about pod being at the bottom


  2. Use a plugin that commits builds to your source control software
    I personally recommend DZP::Git::CommitBuild






  3. Make your build branch your default branch
    I'm not sure how to do this with just git, but on github you can go to the admin section of your repository and change the default branch there. This makes it so that when someone clone's your repository the initial checkout is of your build branch. Your build branch shouldn't require dzil, it's the final build.







Now that you have your final build branch as the default branch anyone who wants to contribute can simply clone your repo and start hacking. Their are a couple of mistakes they could make, They could either change or add files that are maintained, or pruned by dzil. This did happen when Schwern sent me patches, one of them was the addition of a .gitignore, which I already had, but is being pruned out of the build branch. I can also see it happening to meta's and makefiles. These patches can simply be rejected as unnecessary, dzil-ified, or if they are truly a bug, then they can be reported and fixed upstream.

So what if someone sends you a pull request from build/master? well if it's just one or two patches, you add their remote, and do a git remote update and then you can git log remote build/master to find the sha1 of this patch. Now that you have the sha1 all you have to do is git cherry-pick [sha1] and it should apply. If there are any conflicts you may have to resolve them with git mergetool. However, the only conflict with Schwern's patches for me was the .gitignore, all other patches applied without assistance and applied correcly, surprisingly even the pod patch applied without issue.

If you have more patches than is comfortable with git cherry-pick then you need git rebase. The command you want is git rebase -i --onto master [sha1 before first sha1 in series] [tip of remote branch checkout]. So in my case git rebase -i --onto master 3f1e3748 schwern. What this appears to do is ends up rewriting my local schwern/build/master checkout and removes all the build commits, and then applies the patches on top. This means I can now do git merge schwern from the master branch, and all of his patches that I want will be successfully merged. For more on this strategy you may want to read this stackoverflow question.

given this is not quite as easy as a git pull that's a fast forward, but reality is it's not that hard once you know how to do the rebase and how it works. Of course this isn't ideal for constant contributors, those should simply learn to use dzil, but for the random contributor it should be ok.

5 comments:

  1. You can set the default branch on a bare repository in git like this:
    % git symbolic-ref HEAD refs/heads/build/master

    ReplyDelete
  2. I think calling it FUD is inaccurate given this is the first time I've seen anybody explain this layout - and the first time I've seen a project using it, as well.

    Perhaps it would be better to say that "the way people generally seem to use Dist::Zilla makes it harder for contributors to get started" - but if you've never seen it used any other way, the generalisation is still reasonably valid.

    I'd love to see the layout you describe featured prominently in the Dist::Zilla docs - were it widely adopted, I'd retract pretty much all of my complaints.

    However, for the moment "almost all Dist::Zilla projects are harder to get started to contribute to than non-Dist::Zilla projects" *does* hold, and I think that's a valid statement to make.

    -- mst

    ReplyDelete
  3. @mst I have discussed much of this layout in previous dzil blogs Most of it here. Almost a year ago. I think the only thing new here is what to actually do if someone does contribute.

    ReplyDelete
  4. Not FUD: contributing to a DZ project that uses buggy plugins or a buggy dist.ini IS painful, even for a DZ user.

    For example, to fix your own buggy DZP::Test::EOL distribution I had to fix your buggy build first. See this commit.

    Also, your way of doing things is broken as your CPAN distribution does not include anymore the full source that would allow someone else to rebuild it cleanly: it lacks the dist.ini file. This breaks an unsaid contract of CPAN distributions and will disallow your dist to be distributed by Debian.
    Example: Dist::Zilla::Test::Version 0.002000.

    ReplyDelete
  5. @Dolmen no still FUD all software has bugs. your dist.ini patch references a feature I was not aware of and probably did not exist at one time. The referenced repo was forked from RAFL who did not use it. I'd never used said plugin before that.

    I don't care about Debian, they do a good enough job breaking source from upstream (*cough* openssl *cough*), my dist.ini is in my vcs (publicly), it does not need to be on CPAN. If Debian wants to shoot itself in the foot it can go ahead and do that, I suggest getting a distro that attempts to follow upstream (arch) instead of one that attempts to modify upstream (debian) without sharing it's patches back up. Give me a better reason to put my dist.ini on CPAN, because as far as I can tell on CPAN it's just a noise file, and if you try to use the dist.ini in the built dist I suspect you'll end up generating some interesting bugs.

    ReplyDelete

No trolling, profanity, or flame wars :: My Blog, my rules! No crying or arguing about them.