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

GIS_H_VERSION: use git hash #325

Merged
merged 12 commits into from
Mar 31, 2020
Merged

GIS_H_VERSION: use git hash #325

merged 12 commits into from
Mar 31, 2020

Conversation

metzm
Copy link
Contributor

@metzm metzm commented Feb 2, 2020

Previously, GIS_H_VERSION was the svn revision number of gis.h and GIS_H_DATE was the svn revision date of gis.h.

Now they are the git hash and date of the last change to GRASS headers (and anything else in include)

In g.version, these have been and are still referred to as GIS library revision number (now git hash) and date which is wrong: GIS_H_VERSION and GIS_H_DATE refer to GIS headers, not the GIS library. This phrasing can not be changed without breaking backwards compatibility when parsing the output of g.version, because e.g. libgis_revision would need to be changed to gisheaders_version.

use current (target) location + mapset when calling GPJ_init_transform()
previously, GIS_H_VERSION was the svn revision number of gis.h and GIS_H_DATE was the svn revision date of gis.h

now they are the git hash and date of the last change to GRASS headers (and anything else in include)
in g.version, these have been and are still referred to as GIS library revision number and date which is wrong, these are
GIS headers revision number and date, which is not the same
@metzm metzm requested a review from wenzeslaus February 2, 2020 21:51
use $SRCDIR for git log
@landam landam added the enhancement New feature or request label Feb 3, 2020
@landam
Copy link
Member

landam commented Feb 3, 2020

@metzm , are r.in.gdal/r.proj/v.proj related commits relevant to this PR? Thanks for clarification.

@metzm
Copy link
Contributor Author

metzm commented Feb 4, 2020

@metzm , are r.in.gdal/r.proj/v.proj related commits relevant to this PR? Thanks for clarification.

No, I must have created this feature branch from another feature branch. I will remove these commits from this feature branch.

@wenzeslaus
Copy link
Member

Thanks for clarifying the headers versus library. I agree that having whole include/ there makes more sense. As for the non-header files, I think eventually we should have there only header files and move the Make directory elsewhere (or we will have CMake in cmake directory).

The new code looks like that it should work. I'm not sure if it is just a naming issue (see below), but can you please describe the reasons behind the following values (here or in the code)?

date is a fallback when Git is not available, right? That makes sense.

GRASS_HEADERS_GIT_HASH=`date`

But the triplet below looks like fallback as well, or is it to provide a more readable error message to users when the check in lib/gis/gisinit.c fails?

#define GRASS_HEADERS_GIT_HASH "@GRASS_VERSION_NUMBER@ (@GRASS_VERSION_DATE@) @GRASS_HEADERS_GIT_HASH@"

It seems to me the name should be different. In Git, hash is really the hexadecimal string. The point in code history Git calls commit or revision like in Subversion.

To keep in line with that terminology, what has "hash" in it should probably not contain anything else. So, what ends up being GIS_H_VERSION, and is used both for check and user message, should be something like GRASS_HEADERS_REVISION (it is not a version and commit sounds like version control system info only).

As for the renaming/backwards compatibility (grass --config and g.version keys and GIS_...) now is the best time to do right (so that lib does not stand for interface/headers, version for revision, and GIS for GRASS), but that's for a separate PR.

@metzm
Copy link
Contributor Author

metzm commented Feb 6, 2020

The new code looks like that it should work. I'm not sure if it is just a naming issue (see below), but can you please describe the reasons behind the following values (here or in the code)?

date is a fallback when Git is not available, right? That makes sense.

Yes, datewould work as a fallback to determine the date when GRASS was configured

But the triplet below looks like fallback as well, or is it to provide a more readable error message to users when the check in lib/gis/gisinit.c fails?

#define GRASS_HEADERS_GIT_HASH "@GRASS_VERSION_NUMBER@ (@GRASS_VERSION_DATE@) @GRASS_HEADERS_GIT_HASH@"

Yes, the purpose is to provide a more informative error message. A git commit hash is not really informative for users not compiling GRASS from a git clone soucre.

It seems to me the name should be different. In Git, hash is really the hexadecimal string. The point in code history Git calls commit or revision like in Subversion.

The code in configure calls $GIT log -1 --pretty=format:"%h". From git help log:

 ·   %h: abbreviated commit hash

To keep in line with that terminology, what has "hash" in it should probably not contain anything else. So, what ends up being GIS_H_VERSION, and is used both for check and user message, should be something like GRASS_HEADERS_REVISION (it is not a version and commit sounds like version control system info only).

Revision comes from svn, we are now on git. If you do not like GRASS_HEADERS_GIT_HASH, how about GRASS_HEADERS_GIT_VERSION in include/version.h.in:

#define GRASS_HEADERS_GIT_VERSION "@GRASS_VERSION_NUMBER@ (@GRASS_VERSION_DATE@) @GRASS_HEADERS_GIT_HASH@"

Maybe it is better to remove GIT from these macros, to be more generic. I am more interested in the content of GRASS_HEADERS_GIT_HASH and less interested in its name. *_GIT_HASH might be a bit restrictive.

remove git reference from macro names
@neteler
Copy link
Member

neteler commented Feb 15, 2020

I just applied the patch locally, it now looks like this:

GRASS 7.9.dev (nc_spm_08):~ > g.version -rge
version=7.9.dev
date=2020
revision=55cc84109
build_date=2020-01-15
build_platform=x86_64-pc-linux-gnu
build_off_t_size=8
libgis_revision=7.9.dev (2020) fda3b2441
libgis_date="Sun Jan 12 14:29:41 2020 +0100"
proj=5.2.0
gdal=2.3.2
geos=3.7.1
sqlite=3.30.0

To better understand:

  • revision=55cc84109

is the current master hash:

git log
commit 55cc841094158255a63510eddfdf3daee66807a3 (HEAD -> master, origin/master, origin/HEAD)
Author: ...

while

libgis_revision=7.9.dev (2020) fda3b2441

comes from where?

@neteler neteler added this to the 7.8.3 milestone Feb 15, 2020
@metzm
Copy link
Contributor Author

metzm commented Feb 15, 2020

The git short hash fda3b24 comes from the latest change to include, see https://github.com/OSGeo/grass/commits/master/include (git log -1 --pretty=format:"%h" -- include).

Previously, GIS_H_VERSION was the svn revision number of gis.h and GIS_H_DATE was the svn revision date of gis.h.

Now they are the git hash and date of the last change to GRASS headers (and anything else in include).

As I mentioned in my initial commit, the name libgis_revision in the output of g.version was always misleading because it referred to the latest svn change of include/gis.h and not lib/gis.

@neteler
Copy link
Member

neteler commented Feb 15, 2020

For me it looks good, what do you think, @wenzeslaus ?

@neteler
Copy link
Member

neteler commented Feb 22, 2020

For me it looks good, what do you think, @wenzeslaus ?

Ping
Can we merge?

@HuidaeCho
Copy link
Member

Looks good for me. Actually, I like this one better than #365. Closing mine.

As for naming, I prefer to use the more generic GRASS_HEADERS_VERSION. I think we can merge it.

general/g.version/main.c Outdated Show resolved Hide resolved
rev_ver has spaces.
@landam
Copy link
Member

landam commented Mar 12, 2020

@metzm What is reason for duplication (version and date are already defined by separated variables)?

libgis_revision="7.9.dev (2020) df76b070f"

Wouldn't be

libgis_revision=df76b070f

enough?

@metzm
Copy link
Contributor Author

metzm commented Mar 12, 2020

@landam The reason is that G__gisinit() and G__no_gisinit only check GIS_H_VERSION, but you are right, the git short hash should be sufficient to check for compatibility.

use only git short hash as GRASS_HEADERS_VERSION
@landam
Copy link
Member

landam commented Mar 13, 2020

@metzm I would suggest to remove quotes from libgis_revision:

g.version -gre
...
revision=35f284289
...
libgis_revision="5872054b4"

general/g.version/main.c Outdated Show resolved Hide resolved
general/g.version/main.c Outdated Show resolved Hide resolved
change output of g.version -r to e.g.
libgis revision: 5872054
libgis date: Thu Mar 12 22:06:12 2020 +0100
@neteler
Copy link
Member

neteler commented Mar 29, 2020

Seems we are fine to go now?

@HuidaeCho
Copy link
Member

Seems we are fine to go now?

I think so.

@landam
Copy link
Member

landam commented Mar 30, 2020

@metzm Can we merge?

@neteler
Copy link
Member

neteler commented Mar 30, 2020

Let me suggest, to:

  • merge it now into master
  • see how it "behaves"
  • backport once happy (but asap of course, for 7.8.3)

@landam landam merged commit f062bff into OSGeo:master Mar 31, 2020
@neteler
Copy link
Member

neteler commented Mar 31, 2020

For reference, it now looks like this:

GRASS 7.9.dev (nc_spm_08):~/software/grass_master > g.version -rge
version=7.9.dev
date=2020
revision=f062bffc8
build_date=2020-03-31
build_platform=x86_64-pc-linux-gnu
build_off_t_size=8
libgis_revision=f062bffc8
libgis_date="Tue Mar 31 20:34:57 2020 +0200"
proj=5.2.0
gdal=2.3.2
geos=3.7.1
sqlite=3.30.0

@veroandreo
Copy link
Contributor

Is there a reason why buid_date and libgis_date are displayed differently? My OCD could not avoid noticing that, sorry :) Is it too complex to display them with the same date format (ideally as in build_date)?

@landam
Copy link
Member

landam commented Apr 1, 2020

Well libgis_date is truly to say a timestamp ;-) But this is beyond this PR. And sure build_date can be turned to a timestamp. Let's create a new PR for that.

@HuidaeCho
Copy link
Member

HuidaeCho commented Apr 1, 2020 via email

@HuidaeCho
Copy link
Member

One more potential improvement... because we're checking for only one character (space)

                if (strstr(rev_ver, " ") != NULL)

to

                if (strchr(rev_ver, ' ') != NULL)

would make more sense semantically and avoid function calls internally.

GCC strchr vs. strstr

@landam
Copy link
Member

landam commented Apr 2, 2020

One more potential improvement... because we're checking for only one character (space)

Let's create a new PR for this purpose.

@landam
Copy link
Member

landam commented Apr 2, 2020

I have tested merged PR also on Windows.

wingrass

I will backport PR to releasebranch_7_8.

landam added a commit that referenced this pull request Apr 2, 2020
previously, GIS_H_VERSION was the svn revision number of gis.h and GIS_H_DATE was the svn revision date of gis.h

now they are the git hash and date of the last change to GRASS headers (and anything else in include)
in g.version, these have been and are still referred to as GIS library revision number and date which is wrong, these are
GIS headers revision number and date, which is not the same

Co-authored-by: Huidae Cho <grass4u@gmail.com>
Co-authored-by: Martin Landa <landa.martin@gmail.com>
@landam
Copy link
Member

landam commented Apr 2, 2020

One more potential improvement... because we're checking for only one character (space)

Let's create a new PR for this purpose.

See #478

@landam
Copy link
Member

landam commented Apr 2, 2020

Good catch! I agree it should use the same format (ideally, build_date).

In any case libgis_revision should be a timestamp (if git is not available).

@HuidaeCho
Copy link
Member

Good catch! I agree it should use the same format (ideally, build_date).

In any case libgis_revision should be a timestamp (if git is not available).

We can change date to date -I for both GRASS_HEADERS_GIT_HASH and GRASS_HEADERS_GIT_DATE in configure if we don't care about time (preferred because build_date is also only date).

2020-04-02

If we need time, date -Iseconds.

2020-04-02T09:05:08-04:00

Actually, it also addresses the space issue and we can remove the strchr.

What do you think?

@landam
Copy link
Member

landam commented Apr 4, 2020

We can change date to date -I for both GRASS_HEADERS_GIT_HASH and GRASS_HEADERS_GIT_DATE in configure if we don't care about time (preferred because build_date is also only date).

date -I would be probably not enough for GRASS_HEADERS_GIT_HASH since it must be unique when git not available (from this point of view a timestamp is a better choice).

If we need time, date -Iseconds.

2020-04-02T09:05:08-04:00

Actually, it also addresses the space issue and we can remove the strchr.

What do you think?

Would be fine. But let's discuss it in a new PR.

ninsbl added a commit to ninsbl/grass that referenced this pull request Apr 8, 2020
ninsbl added a commit to ninsbl/grass that referenced this pull request Apr 8, 2020
ninsbl added a commit that referenced this pull request Apr 20, 2020
* use space delimiter for GIS_H_VERSION

* choose GRASS_VERSION_STRING list element

* report header version and date

* write GRASS_VERSION_GIT to grass.py

* use GRASS_VERSION_GIT

* write GRASS_VERSION_GIT to grass.py

* fix tab indent

* add date

* add date

* get date correctly after #325

* get date correctly after #325

* date: no indent, no quotes

* Update lib/init/grass.py

Co-Authored-By: Markus Neteler <neteler@gmail.com>

Co-authored-by: Stefan Blumentrath <stefan@vm-srv-wallace.vm.ntnu.no>
Co-authored-by: Martin Landa <landa.martin@gmail.com>
Co-authored-by: Markus Neteler <neteler@gmail.com>
landam added a commit that referenced this pull request Apr 20, 2020
* use space delimiter for GIS_H_VERSION

* choose GRASS_VERSION_STRING list element

* report header version and date

* write GRASS_VERSION_GIT to grass.py

* use GRASS_VERSION_GIT

* write GRASS_VERSION_GIT to grass.py

* fix tab indent

* add date

* add date

* get date correctly after #325

* get date correctly after #325

* date: no indent, no quotes

* Update lib/init/grass.py

Co-Authored-By: Markus Neteler <neteler@gmail.com>

Co-authored-by: Stefan Blumentrath <stefan@vm-srv-wallace.vm.ntnu.no>
Co-authored-by: Martin Landa <landa.martin@gmail.com>
Co-authored-by: Markus Neteler <neteler@gmail.com>
@metzm metzm deleted the grass_version branch September 9, 2020 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants