Loading...
Searching...
No Matches
bitpitStyleGuide.hpp
1
459\endverbatim
460The doxygen comment block of a class should include a general description of
461the class and a list of its features and possible limitations.
462
463A doxygen comment block should be added for every method of a class (both
464public and private methos should be commented), this comment block should
465contain a general description of the method and a description of all the
466arguments and the return value of the method. For instance:
467\verbatim
477\endverbatim
478
479To document the members of a file, struct, union, class, or enum, it is sometimes
480desired to place the documentation block after the member instead of before.
481For this purpose an additional < marker is required in the comment block.
482Note that this also works for the parameters of a function. For instance:
483\verbatim
484 int var;
485\endverbatim
486To simplify the documentation of class members, define just one member per
487line (no commas for multiple members declarations).
488
489Doxygen commands should start with a backslash (\\).
490
491As a rule of thumb, the code should run through doxygen without generating any
492warnings; in fact, doxygen is sometimes helpful at pointing out inconsistencies
493in your class declaration.
494
495\subsection automatic_formatting Automatic code formatting
496
497<B>%bitpit</B> provides a .clang-format file that can be used by clang-format
498to automatically format the code. Code formatting can be enforced manually by
499calling clang-format directly or automatically through the the CMake targets
500defined by <B>%bitpit</B>. Each <B>%bitpit</B> module provides a CMake target
501called clang-format-<MODULE_NAME> that allows to format all the code of the
502module. There is also a Git pre-commit hook which uses the "clang-format git
503hooks" tool to ensure the changes are properly formatted.
504
505\section git Git Repository Practices
506As most of our code repositories uses git as the revision control system, it is important to decide on a workflow that can be followed by the individual developer. The way that any individual developer interact with the upstream git repository can have an important impact on other developers and the ability to identify and manage individual changes. This set of guidelines and practices attempts to establish some standards for how developers will interact with the upstream git repository.
507
508\subsection commits Making Repository Commits
509As a general rule, developers should update frequently, and commit changes often. However, the repository should always remain
510in a state where the code can be compiled. Most of the time, the code should also successfully execute "make check" run from the
511top-level directory. If you commit code that violates this principal, it should be your first priority to return the repository
512code to a compilable state, and your second priority to make sure "make check" runs without errors.
513Although it would be possible and many software projects do it, we prefer not to force successful execution of the test suite
514before every commit. Developers should make every effort to avoid having to impose this constraint, by running a make check
515before every commit.
516
517Commits to the repository should also come with a non-trivial and useful log message.
518
519\subsection outside-master Working Outside the Master Branch
520A critical concept is that all changes shall be developed outside of the master<sup>1</sup> branch. Whether they are in a different branch of the upstream<sup>2</sup> repository (gitflow) or a branch of an entirely different fork (forking workflow) is secondary. This is a well-established concept regardless of the workflow being adopted, and allows a number of other benefits as described below.
521
522\subsubsection fork Working on a Different Fork
523There are a number of benefits of working on a different fork rather than a branch of the upstream repo, although not strictly technical:
524- Developers, particularly new developers, are liberated from the constant oversight of others as they explore new code options. The impact of this may depend on an individual developer’s personality, but for some it creates a refuge where they can be more free and creative.
525- Similarly, assuming that all changesets in the upstream repo are communicated to the entire development team, the team is spared a noisy stream of notifications and can focus their attention on the rarer occurrence of a pull request notification.
526
527\subsubsection pr All Changes are Committed by Pull Request
528Although this can be imposed technically by limiting the authority to alter the upstream repo (as in the forking workflow), a healthy developer community can also simply rely on convention. The advantage of doing it by convention rather than by restriction is that it is easier to distribute the load of reviewing and accepting changes.
529A critical consequence of this decision is that all code is reviewed before it is committed to the upstream master branch. This has benefits to overall quality in two related ways:
530- the code under review will improve due to the review itself, and
531- those involved in the review will maintain a broad awareness of the code base resulting in better contributions from them.
532
533This practice does, however, place a substantial burden on the developers to perform timely reviews of the pull requested (PR’ed) code. PR’s that languish without sufficient review have a number of negative consequences:
534- they need to be refreshed simply to keep them up-to-date with the possibly advancing upstream/master
535- they may delay further development on similar or related features
536- they breed frustration in the original developer, undermining the community as a whole.
537github provides powerful collaboration tools that greatly facilitate this process.
538
539<sup>1</sup> Although a repository may choose a different name for its main development branch, this document will refer to that as the “master” branch.
540
541<sup>2</sup> For this discussion, the “upstream” repo will refer to the centralized authoritative repository used to synchronize changes.
542
543\subsection git-mechanics Some Git Mechanics to Keep it Clean
544Given the above practices, there are some mechanical details that can help ensure that the upstream/master repository is always in a state that facilitates all repository actions and interactions.
545
546-# Feature branches being used for development should be kept up-to-date with the upstream/master by rebase only. When a feature branch is rebased against the upstream/master, all changes in the upstream/master are inserted into the feature branch at a point in its history that is prior to any of the changes of the feature branch. This can require conflict resultion as the feature branch changes are “replayed” on top of the new upstream/master in its current state. The primary advantage of this policy is that it keeps all of the feature branch changes contiguous. If, by contrast, the upstream/master is merged into the feature branch, the recent changes in the upstream/master become woven into the set of changes in the feature branch. This can make it more difficult to isolate changes later on.
547
548 Strict adoption of this practice is important since a single merge into a feature branch that is then merged back into the upstream/master can make it nearly impossible for others to rebase.
549
550 A typical workflow with pull-request might look like this, all using the command-line, except for submitting the final pull request. Note that there is never a merge operation.
551 -# synchronize your local `master` branch before anything else
552 \code{.sh}
553 $ git checkout master
554 $ git fetch upstream
555 $ git rebase upstream/master
556 \endcode
557
558 -# now create a new feature branch from master
559 \code{.sh}
560 $ git checkout -b my_feature_branch master
561 \endcode
562
563 -# now make changes, editing A.cpp, B.hpp, C.cpp
564
565 -# now add/commit your changes to your local feature branch
566 \code{.sh}
567 $ git add A.cpp B.hpp C.cpp
568 $ git commit -m “Make sure you have a good commit message”
569 \endcode
570 -# push your changes to your feature branch on your fork (often called `origin`)
571 \code{.sh}
572 $ git push origin my_feature_branch
573 \endcode
574 -# make more changes, editing B.hpp, D.hpp, E.cpp
575
576 -# add/commit your changes to your local feature branch
577 \code{.sh}
578 $ git add B.hpp D.hpp E.cpp
579 $ git commit -m “Be sure you have another good commit message”
580 \endcode
581 -# push your changes to your freature branch on your fork (often called `origin`)
582 \code{.sh}
583 $ git push origin my_feature_ranch
584 \endcode
585 -# When you are ready to submit a pull request, be sure that your feature branch is up-to-date. This first step may seem redundant but is here to be clear which branch we are acting on
586 \code{.sh}
587 $ git checkout my_feature_branch
588 $ git fetch upstream
589 $ git rebase upstream/master
590 \endcode
591 This may generate conflicts that can be addressed at this point.
592
593 NOTE: This step can be performed at any time and should be performed as often as practical to reduce the scope of potential conflicts.
594
595 -# push your updated feature branch on your fork (often called `origin`)
596 \code{.sh}
597 $ git push origin my_feature_branch
598 \endcode
599 This may require the ‘-f’ option to force the push. (It is frequently necessary to force this push because the act of rebasing will “replay” the commits from the feature branch on top of the master, leading to different commit hashes. Each of the commits will contain the same actual information, but because it has a different set of hashes, git will think there is an inconsistency and ask you to force the change.)
600
601 -# Submit a pull request on github, from your fork to the fathomteam fork.
602
603
604-# When ready to be adopted into the upstream/master, feature branches should be combined by merge only. This adds the changeset to the end of the upstream/master as a set of individual commits but in a contiguous block.
605
606 A typical workflow to merge a pull-request might look like this, all using the command-line.
607 -# synchronize your local `master` branch before anything else (just because it’s never a bad idea!)
608 \code{.sh}
609 $ git checkout master
610 $ git fetch upstream
611 $ git rebase upstream/master
612 \endcode
613 -# add a remote for the user with the pull-request, perhaps the user is ‘other_user’
614 \code{.sh}
615 $ git remote add other_user \
616 git@bitbucket.org:other_user/moab.git
617 \endcode
618 -# fetch the other users repo
619 \code{.sh}
620 $ git fetch other_user
621 \endcode
622 -# check out their feature branch
623 \code{.sh}
624 $ git checkout -b pr_feature_branch \
625 other_user/feature_branch
626 \endcode
627 -# confirm that it is up-to-date with the master. This first step may seem redundant but is here to be clear which branch we are acting on
628 \code{.sh}
629 $ git checkout pr_feature_branch
630 $ git fetch upstream
631 $ git rebase upstream/master
632 \endcode
633 This may generate conflicts that can be addressed at this point. You may want to request the original author (other_user) take care of these.
634 -# once confirmed that it’s up-to-date with master, review this branch including:
635 -reading the code
636 -building the code
637 -running tests
638 -# once satisfied that the code meets the necessary standards and that all required/requested changes are fully incorporated into other_users’s feature branch, merge it into master
639 \code{.sh}
640 $ git checkout master
641 \endcode
642 The next two steps may seem redundant but provide some QA
643 \code{.sh}
644 $ git fetch upstream
645 $ git rebase upstream/master
646 $ git merge other_user/feature_branch
647 \endcode
648 -# push those changes into the master branch on bitbucket
649 \code{.sh}
650 $ git push upstream/master
651 \endcode
652
653-# When a pull request is open for review, any changes to the feature branch will automatically update the pull request. This is the appropriate way for a developer to respond to requests for changes that occur through the PR process.
654
655
656-# If a developer has ongoing work that is based on a feature branch that is under consideration in an open PR, a new feature branch (B) should be created that is based on the previous feature branch (A). Moreover, as changes are made to the original feature branch (A) due to the review process, the new feature branch (B) should be kept up-to-date by rebase against feature branch (A). This keeps all subsequent changes of (B) downstream from the changes in (A). Once feature branch (A) has been adopted into the upstream/master, the new feature branch (B) can start being rebased against the upstream/master instead.
657
658
659-# When a repo is forked, its branches are not automatically synchronized with the corresponding branches on the upstream repo. This requires a manual process of synchronization via a local clone. Assuming that the local repo’s branch has the same name as the upstream branch (\<branch\>), and that the fork is known as “origin”:
660 \code{.sh}
661 $ git fetch upstream
662 $ git checkout <branch>
663 $ git rebase upstream/<branch>
664 $ git push origin <branch>
665 \endcode
666The decision of which branches to keep up-to-date is up to the developers. Developers may choose to delete some branches from their own fork to avoid (a) the need to update it and (b) accidentally assuming that it is up-to-date.
667
668
669-# When rebasing, it is not uncommon to encounter conflicts. This will interrupt the rebasing process, and each conflicted file will contain conflict blocks. You will be offered three choices:
670 - manually resolve the conflicts, add the resolved files with git add, and then git rebase --continue (do not commit the resolved files!)
671 - abort the rebasing process entirely with git rebase --abort
672 - skip the commit that causes the conflict, assuming that you are sure that this is the right thing to do, with git rebase --skip
673
674
675-# github offers a number of buttons/tools to manage changes between branches and forks. Some of these operate in ways that are contrary to the practices recommended here, and others are consistent with these practices. In general, it is best to know how to do all of those operations with the command-line instead of relying on github, as it gives you full control over important details.
676
677
678-# During code development, it might be necessary to work on the same branch on different machines. The workflow to update the local branch is to first fetch the remote changes and then perform a hard reset.
679 \code{.sh}
680 $ git fetch origin
681 $ git reset --hard origin/branch_name
682 \endcode
683One should be careful with the branch name as a hard reset would overwrite all changes in the working directory.
684
685
686Top: \ref styleguide
687
688*/
--- layout: doxygen_footer ---