Skip to content
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

Add parents' commit hashes to repoVersionStringOut in tribits_generate_single_repo_version_string() #597

Closed
achauphan opened this issue Jan 4, 2024 · 2 comments

Comments

@achauphan
Copy link
Collaborator

achauphan commented Jan 4, 2024

Related issues

Description

The current repo version output in TriBITS does not include the current commit's parents (if there are any). The parent commits are desirable in cases such as a merge commit, where examining a merge commit's parents are useful for determining which parents had changes performed to them across other merge commits.

This issue is in relation to [add issue number here], which plans to utilize a merge commit's parent sha1.

The current TriBITS repo version output is:

ProjectName repos versions:
--------------------------------------------------------------------------------
*** Base Git Repo: ProjectName
910f407 [Mon Oct 9 14:11:01 2023 -0600] <[email protected]>
topic branch tip commit message
 --------------------------------------------------------------------------------

The desired output would be something like:

ProjectName repos versions:
--------------------------------------------------------------------------------
*** Base Git Repo: ProjectName
2b9117b [Thu Dec 21 20:12:25 2023 -0700] <[email protected]>
Merge commit '910f40782a2e5dcbe0ce0fd3c176fbb8e276815a' into develop
    *** Parent: 1
    68b1db3da7a [Mon Oct 9 13:21:55 2023 -0400] <[email protected]>
    target branch tip commit message
    *** Parent: 2
    910f40782a2 [Mon Oct 9 14:11:01 2023 -0600] <[email protected]>
    topic branch tip commit message
...
 --------------------------------------------------------------------------------

Proposed Solution

Modify repoVersionStringOut in tribits_generate_single_repo_version_string() to include the parent commits.

The parents of a commit can be found with the following git commands with the same date and author formatting:
git log -1 "--pretty=format:%h [%ad] <%ae>" HEAD^1
git log -1 "--pretty=format:%h [%ad] <%ae>" HEAD^2

Requirements

  • add new tests that can handle cases where parents are present and not present
bartlettroscoe added a commit that referenced this issue Jan 4, 2024
Added test TribitsHelloWorld_config_git_version that uses mockprogram.py as
git to generate and check git version info.

ToDo: We should also check the generated TribitsHelloWorldRepoVersion.txt file
bartlettroscoe added a commit that referenced this issue Jan 4, 2024
For some reason, mockprogram.py prints an newline that raw git does not.  But
this should work for raw git too.
@bartlettroscoe
Copy link
Member

bartlettroscoe commented Jan 5, 2024

@achauphan, we need to see if we can get the autotester to always generate a merge commit with git merge --no-ff <topic> even when a merge commit is not needed (because the tip of <topic> is downstream from the tip of <target>, i.e. develop). Otherwise, we need to add more complex logic to TriBITS and/or the Python script that pulls down data from CDash.

achauphan added a commit that referenced this issue Jan 11, 2024
Renamed the test TribitsHelloWorld_config_git_version to TribitsHelloWorld_config_git_version_single_repo_one_parent
to correctly state the scope of the test and allow for future similar tests with slightly a difference scopes
(such as single_repo_two_parents, multi_repo_one_parent, etc).
achauphan added a commit that referenced this issue Jan 12, 2024
…euse (#597)

Moved git commit info functionality of tribits_generate_single_repo_version_string to
a seperate helper function named tribites_generate_commit_info_string. The core functionality and
output is the same. This is in prep for reuse of that functionality inside of the original
tribits_generate_single_repo_version string.
achauphan added a commit that referenced this issue Jan 12, 2024
…#597)

Removed trailing whitespace to keep git command outputs consistent with other
functions performing git commands and for the output to be more processable.
achauphan added a commit that referenced this issue Jan 12, 2024
Renamed the test TribitsHelloWorld_config_git_version to TribitsHelloWorld_config_git_version_single_repo_one_parent
to correctly state the scope of the test and allow for future similar tests with slightly a difference scopes
(such as single_repo_two_parents, multi_repo_one_parent, etc).
achauphan added a commit that referenced this issue Jan 12, 2024
…euse (#597)

Moved git commit info functionality of tribits_generate_single_repo_version_string to
a separate helper function named tribites_generate_commit_info_string. The core functionality and
output is the same. This is in prep for reuse of that functionality inside of the original
tribits_generate_single_repo_version string.
achauphan added a commit that referenced this issue Jan 12, 2024
…#597)

Removed trailing whitespace to keep git command outputs consistent with other
functions performing git commands and for the output to be more processable.
achauphan added a commit that referenced this issue Jan 12, 2024
Make tribits_generate_commit_info_string output commit info based on a passed in
commit sha1.
achauphan added a commit that referenced this issue Jan 12, 2024
…est (#597)

Updated mockprogram inputs and outputs to be more specific about which
commit message is being outputted.
achauphan added a commit that referenced this issue Jan 13, 2024
If the HEAD sha1 contains more than one parent, include each parent's
commit info in the final repoVersionStringOut of tribits_generate_single_repo_version_string.
achauphan added a commit that referenced this issue Jan 13, 2024
Forgot to double quote variable and caused configure failures during Github Actions testing.
achauphan added a commit that referenced this issue Jan 16, 2024
Added global cmake cache variable `<PROJECT_NAME>_SHOW_GIT_COMMIT_PARENTS:BOOL`
that is default to OFF. This will be a project based variable to including
parent commit info in the repo version output.
achauphan added a commit that referenced this issue Jan 16, 2024
Reordered git log arguments to the expected order as well as condensed
cmake command arguments into a single line.
achauphan added a commit that referenced this issue Jan 16, 2024
Instead of passing in the deferenced HEAD SHA1 to tribites_generate_commit_info_string,
simply just pass in the HEAD pointer keyword for Git to deference itself.
achauphan added a commit that referenced this issue Jan 16, 2024
…tput (#597)

In the off chance that Git decides to change the output of git log -1 "--pretty=format:%p",
use a regex match and replace in cmake to match consecutive spaces and replace them with a
single ;.
achauphan added a commit that referenced this issue Jan 16, 2024
Simplified foreach loop in tribits_generate_single_repo_version_string and changed
the parent indexing to be 1-based instead of 0-based.
achauphan added a commit that referenced this issue Jan 17, 2024
Implemented usage of previously added global cmake variable,
`PROJECT_NAME_SHOW_GIT_COMMIT_PARENTS` in `tribits_generate_single_repo_version_string`.

This is done with an optional argument named INCLUDE_COMMIT_PARENTS whenever
calling `tribits_generate_single_repo_version_string`
achauphan added a commit that referenced this issue Jan 17, 2024
Cleaned up empty lines in `TribitsHelloWorld_Tests.cmake`
bartlettroscoe pushed a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
…#597)

Implemented usage of previously added global cmake variable,
`PROJECT_NAME_SHOW_GIT_COMMIT_PARENTS` in `tribits_generate_single_repo_version_string`.

This is done with an optional argument named INCLUDE_COMMIT_PARENTS whenever
calling `tribits_generate_single_repo_version_string`
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
With Clean Code ordering (i.e. the Newspaper Metaphor), in general, the
functions should be ordered from top-level to low-level in the calling order.
That is, the functions that are called in a given function should be listed
below that function.
bartlettroscoe pushed a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
Cleaned up empty lines in `TribitsHelloWorld_Tests.cmake`
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
This allows the calling code to be more compact.  Since this function is not
really called by any external users (perhaps ever), this seems like a good
trade-off.
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
…HANDLING_ONLY=ON (TriBITSPub#597)

This spead up these tests on my machine 'crf450' from about 3.4 sec to about
0.45 sec.

We don't need to enable the compilers and process the package CMakeLists.txt
files to test this version info.
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
This is a variable that project developers and users should know about.
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
…up (TriBITSPub#597)

Using camelCase for local vars helps to differentiate from UPPER_CACHE vars for
function argument keywords and global vars.

I figured I would clean this function up while I was working on it.

Now this fits in one screen-shot for me.
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
…utils/ (TriBITSPub#597)

I noticed that this module does not depend on the TriBITS framework in any way
so it should live under the core/utils/ directory to make that clear and to
allow easy reuse in non-TriBITS projects that would like to use it.
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
…IT_COMMIT_PARENTS (TriBITSPub#597)

We eventually need to use this for all of those vars to make that code more
compact.
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
I noticed this while looking at the documentation while working on TriBITSPub#597.
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
TriBITSPub#597)

This sets the option:

  -DTribitsExMetaProj_SHOW_GIT_COMMIT_PARENTS=ON

in the inner CMake configuration with a multi-repo setup so we can test the
extraction and printing of the parent commit info.  This tests a call of the
function tribits_generate_single_repo_version_string() for extra repos from
the function tribits_generate_repo_version_file_string().  This test also
validates that the correct Git commands are called since this uses real Git on
a Git repos.

The downside of this updated test is that it makes it a little more difficult
to maintain these tests when we have to update these snapshotted Git repos.
bartlettroscoe added a commit to bartlettroscoe/TriBITS that referenced this issue Jan 24, 2024
TriBITSPub#597)

This sets the option:

  -DTribitsExMetaProj_SHOW_GIT_COMMIT_PARENTS=ON

in the inner CMake configuration with a multi-repo setup so we can test the
extraction and printing of the parent commit info.  This tests a call of the
function tribits_generate_single_repo_version_string() for extra repos from
the function tribits_generate_repo_version_file_string().  This test also
validates that the correct Git commands are called since this uses real Git on
a Git repos.

The downside of this updated test is that it makes it a little more difficult
to maintain these tests when we have to update these snapshotted Git repos.
bartlettroscoe added a commit that referenced this issue Jan 25, 2024
…fo-rab

Should be final commits for Git version parent info PR #598 (#597)
bartlettroscoe added a commit that referenced this issue Jan 25, 2024
bartlettroscoe added a commit to bartlettroscoe/Trilinos that referenced this issue Jan 25, 2024
…arent-info (TriBITSPub/TriBITS#597)

Main purpose is to pull in the TriBITS PR for getting the git repo parent
commit info:

* TriBITSPub/TriBITS#598
@bartlettroscoe
Copy link
Member

With the merge of PR:

this story should be complete. This is in the process of being snapshotted to Trilinos in:

  • trilinos/Trilinos/#2695

@achauphan, can we close this issue?

bartlettroscoe added a commit to bartlettroscoe/Trilinos that referenced this issue Jan 25, 2024
…riBITSPub/TriBITS#597)

This is needed to know the versions of the target and topic branches for PR
builds submitted to CDash.  This is needed to be able to detect random test
failures.
@bartlettroscoe bartlettroscoe moved this to Done in TriBITS Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Status: Done
Development

No branches or pull requests

2 participants