{"thread":{"id":"18135","subject":"[PATCH 2/2] better introduction of GIT with USE_NSEC defined","startedAt":"2009-03-04T17:47:38Z","lastAt":"2009-03-06T07:56:41Z","messageCount":11,"participants":["Kjetil Barvik","Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"106992","messageId":"cover.1236187259.git.barvik@broadpark.no","threadId":"18135","inReplyTo":null,"subject":"[PATCH 0/2] some few more 'git checkout' improvements","fromName":"Kjetil Barvik","fromEmail":"barvik@broadpark.no","sentAt":"2009-03-04T17:47:38Z","receivedAt":"2009-03-04T17:47:38Z","isPatch":true,"sender":{"key":"barvik@broadpark.no","avatar":null},"body":"- one bugfix (I hope)\n- and one patch to make life easier when using the USE_NSEC define\n\nThese 2 patches is based on 'next' because patch 2/2 is based on one\nprevious patch, which is only in 'next' for the moment.\n\nKjetil Barvik (2):\n  stat_tracking_info(): only count real commits\n  better introduction of GIT with USE_NSEC defined\n\n read-cache.c   |   23 +----------------------\n remote.c       |    3 ++-\n unpack-trees.c |    2 --\n 3 files changed, 3 insertions(+), 25 deletions(-)\n"},{"id":"106993","messageId":"6f183d66558114720e5f193ed028eba53727b330.1236187259.git.barvik@broadpark.no","threadId":"18135","inReplyTo":"cover.1236187259.git.barvik@broadpark.no","subject":"[PATCH 1/2] stat_tracking_info(): only count real commits","fromName":"Kjetil Barvik","fromEmail":"barvik@broadpark.no","sentAt":"2009-03-04T17:47:39Z","receivedAt":"2009-03-04T17:47:39Z","isPatch":true,"sender":{"key":"barvik@broadpark.no","avatar":null},"body":"stat_tracking_info() in remote.c is used to collect the statistics to\nbe able to say (for instance) from the output of \"git checkout':\n\n  Your branch and 'foo' have diverged,\n  and have X and Y different commit(s) each, respectively.\n\nCurrently X and Y also includes the count of merges.  This patch\nexcludes the merges from being counted.\n\nSigned-off-by: Kjetil Barvik <barvik@broadpark.no>\n---\n\n  I hope this is a correct fix, and that it is realy a bugfix.\n\n  ~~\n\n  By the way, I have noticed that when the Y number above is large\n  (for instance for a branch I have where Y is ~ 600), then the\n  function get_merge_bases_many() and in particular merge_bases_many()\n  in commit.c will take a noticable amount of user time (aprox 0.4\n  seconds).  So if the chekcout results in that few files need to be\n  updated (< 10), this will sometimes acount for much of the total\n  time needed for the 'git checkout' command.\n\n  It seems that even though only max 4000 or so unique commits is\n  touched (when Y ~ 600), each commit is touched over 250 times, for\n  instancce by the insert_by_date() function inside the while-loop in\n  merge_bases_many().\n\n  Do someone think it is possible to have a better algorithm here?\n  Maybe O(Nlog(n)) or better?  Does someone has a hint about how to\n  make it better?\n\n\n remote.c |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex d7079c6..06c414e 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1310,9 +1310,10 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)\n \tif (theirs == ours)\n \t\treturn 0;\n \n-\t/* Run \"rev-list --left-right ours...theirs\" internally... */\n+\t/* Run \"rev-list --no-merges --left-right ours...theirs\" internally... */\n \trev_argc = 0;\n \trev_argv[rev_argc++] = NULL;\n+\trev_argv[rev_argc++] = \"--no-merges\";\n \trev_argv[rev_argc++] = \"--left-right\";\n \trev_argv[rev_argc++] = symmetric;\n \trev_argv[rev_argc++] = \"--\";\n-- \n1.6.1.GIT\n"},{"id":"106991","messageId":"6d937a859ca499f534eea08720fca84f3d4ded2f.1236187259.git.barvik@broadpark.no","threadId":"18135","inReplyTo":"cover.1236187259.git.barvik@broadpark.no","subject":"[PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Kjetil Barvik","fromEmail":"barvik@broadpark.no","sentAt":"2009-03-04T17:47:40Z","receivedAt":"2009-03-04T17:47:40Z","isPatch":true,"sender":{"key":"barvik@broadpark.no","avatar":null},"body":"Change the source code such that when USE_NSEC is not defined,\npossible nanosecond timestamps will still be saved in the index file,\nbut not used inside if-test's, and will therefore not affect the\noutcome of GIT commands, other than the saved nanosecond timestamps in\nthe index file.\n\nThis will make it easier to use a system with 2 versions of GIT, one\nwith and one without USE_NSEC defined.\n\nSigned-off-by: Kjetil Barvik <barvik@broadpark.no>\n---\n read-cache.c   |   23 +----------------------\n unpack-trees.c |    2 --\n 2 files changed, 1 insertions(+), 24 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 91f1d03..7fca804 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -69,13 +69,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)\n {\n \tce->ce_ctime.sec = (unsigned int)st->st_ctime;\n \tce->ce_mtime.sec = (unsigned int)st->st_mtime;\n-#ifdef USE_NSEC\n \tce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;\n \tce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;\n-#else\n-\tce->ce_ctime.nsec = 0;\n-\tce->ce_mtime.nsec = 0;\n-#endif\n \tce->ce_dev = st->st_dev;\n \tce->ce_ino = st->st_ino;\n \tce->ce_uid = st->st_uid;\n@@ -1183,13 +1178,8 @@ static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_en\n \n \tce->ce_ctime.sec = ntohl(ondisk->ctime.sec);\n \tce->ce_mtime.sec = ntohl(ondisk->mtime.sec);\n-#ifdef USE_NSEC\n \tce->ce_ctime.nsec = ntohl(ondisk->ctime.nsec);\n \tce->ce_mtime.nsec = ntohl(ondisk->mtime.nsec);\n-#else\n-\tce->ce_ctime.nsec = 0;\n-\tce->ce_mtime.nsec = 0;\n-#endif\n \tce->ce_dev   = ntohl(ondisk->dev);\n \tce->ce_ino   = ntohl(ondisk->ino);\n \tce->ce_mode  = ntohl(ondisk->mode);\n@@ -1308,12 +1298,8 @@ int read_index_from(struct index_state *istate, const char *path)\n \t\tsrc_offset += ondisk_ce_size(ce);\n \t\tdst_offset += ce_size(ce);\n \t}\n-\tistate->timestamp.sec = st.st_mtime;\n-#ifdef USE_NSEC\n+\tistate->timestamp.sec = (unsigned int)st.st_mtime;\n \tistate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;\n-#else\n-\tistate->timestamp.nsec = 0;\n-#endif\n \n \twhile (src_offset <= mmap_size - 20 - 8) {\n \t\t/* After an array of active_nr index entries,\n@@ -1500,13 +1486,8 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)\n \n \tondisk->ctime.sec = htonl(ce->ce_ctime.sec);\n \tondisk->mtime.sec = htonl(ce->ce_mtime.sec);\n-#ifdef USE_NSEC\n \tondisk->ctime.nsec = htonl(ce->ce_ctime.nsec);\n \tondisk->mtime.nsec = htonl(ce->ce_mtime.nsec);\n-#else\n-\tondisk->ctime.nsec = 0;\n-\tondisk->mtime.nsec = 0;\n-#endif\n \tondisk->dev  = htonl(ce->ce_dev);\n \tondisk->ino  = htonl(ce->ce_ino);\n \tondisk->mode = htonl(ce->ce_mode);\n@@ -1583,9 +1564,7 @@ int write_index(struct index_state *istate, int newfd)\n \tif (ce_flush(&c, newfd) || fstat(newfd, &st))\n \t\treturn -1;\n \tistate->timestamp.sec = (unsigned int)st.st_ctime;\n-#ifdef USE_NSEC\n \tistate->timestamp.nsec = (unsigned int)st.st_ctim.tv_nsec;\n-#endif\n \treturn 0;\n }\n \ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 9fe0cd5..da2e3c0 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -362,9 +362,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \to->result.initialized = 1;\n \tif (o->src_index) {\n \t\to->result.timestamp.sec = o->src_index->timestamp.sec;\n-#ifdef USE_NSEC\n \t\to->result.timestamp.nsec = o->src_index->timestamp.nsec;\n-#endif\n \t}\n \to->merge_size = len;\n \n-- \n1.6.1.GIT\n"},{"id":"107011","messageId":"7vk5744x87.fsf@gitster.siamese.dyndns.org","threadId":"18135","inReplyTo":"6d937a859ca499f534eea08720fca84f3d4ded2f.1236187259.git.barvik@broadpark.no","subject":"Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-05T00:41:44Z","receivedAt":"2009-03-05T00:41:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kjetil Barvik <barvik@broadpark.no> writes:\n\n> Change the source code such that when USE_NSEC is not defined,\n> possible nanosecond timestamps will still be saved in the index file,\n> but not used inside if-test's, and will therefore not affect the\n> outcome of GIT commands, other than the saved nanosecond timestamps in\n> the index file.\n>\n> This will make it easier to use a system with 2 versions of GIT, one\n> with and one without USE_NSEC defined.\n\nI take it that you are responding to my earlier question with this patch?\n\n    From: Junio C Hamano <gitster@pobox.com>\n    Subject: Re: [PATCH/RFC v2 2/3] make USE_NSEC work as expected\n    Date: Fri, 20 Feb 2009 00:35:35 -0800\n    Message-ID: <7vab8hfqug.fsf@gitster.siamese.dyndns.org>\n\n    Kjetil Barvik <barvik@broadpark.no> writes:\n\n    > diff --git a/read-cache.c b/read-cache.c\n    > index 940ec76..ca4bec2 100644\n    > --- a/read-cache.c\n    > +++ b/read-cache.c\n    > @@ -67,8 +67,15 @@ void rename_index_entry_at(struct index_state *istate,..\n    >   */\n    >  void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)\n    >  {\n    > -\tce->ce_ctime = st->st_ctime;\n    > -\tce->ce_mtime = st->st_mtime;\n    > +\tce->ce_ctime.sec = (unsigned int)st->st_ctime;\n    > +\tce->ce_mtime.sec = (unsigned int)st->st_mtime;\n    > +#ifdef USE_NSEC\n    > +\tce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;\n    > +\tce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;\n    > +#else\n    > +\tce->ce_ctime.nsec = 0;\n    > +\tce->ce_mtime.nsec = 0;\n    > +#endif\n\n    How does this affect a use case where the same index file used with two \n    instances of git (one compiled with and another without USE_NSEC)?\n"},{"id":"107021","messageId":"86prgwqvzr.fsf@broadpark.no","threadId":"18135","inReplyTo":"7vk5744x87.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Kjetil Barvik","fromEmail":"barvik@broadpark.no","sentAt":"2009-03-05T07:17:28Z","receivedAt":"2009-03-05T07:17:28Z","isPatch":true,"sender":{"key":"barvik@broadpark.no","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Kjetil Barvik <barvik@broadpark.no> writes:\n>\n>> Change the source code such that when USE_NSEC is not defined,\n>> possible nanosecond timestamps will still be saved in the index file,\n>> but not used inside if-test's, and will therefore not affect the\n>> outcome of GIT commands, other than the saved nanosecond timestamps in\n>> the index file.\n>>\n>> This will make it easier to use a system with 2 versions of GIT, one\n>> with and one without USE_NSEC defined.\n>\n> I take it that you are responding to my earlier question with this\n> patch?\n\n  Yes, you are correct.\n\n [....]\n>     How does this affect a use case where the same index file used with two \n>     instances of git (one compiled with and another without USE_NSEC)?\n\n  If both persons in this use case use this patch, the one with USE_NSEC\n  defined will now be able to take full advantage of the nanosecond\n  timestamps at all times.\n\n  The one without USE_NSEC defined should not be able to tell the\n  difference (without looking into to details of the index file).\n\n  -- kjetil\n"},{"id":"107025","messageId":"7v8wnk4dy6.fsf@gitster.siamese.dyndns.org","threadId":"18135","inReplyTo":"86prgwqvzr.fsf@broadpark.no","subject":"Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-05T07:38:09Z","receivedAt":"2009-03-05T07:38:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kjetil Barvik <barvik@broadpark.no> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n> ...\n>>     How does this affect a use case where the same index file used with two \n>>     instances of git (one compiled with and another without USE_NSEC)?\n>\n>   If both persons in this use case use this patch, the one with USE_NSEC\n>   defined will now be able to take full advantage of the nanosecond\n>   timestamps at all times.\n>\n>   The one without USE_NSEC defined should not be able to tell the\n>   difference (without looking into to details of the index file).\n\nAs long as the implementation does not give false cleanliness it is\nperfectly fine; false dirtinesss is just a bit of wasted cycle.\n\nThanks.\n"},{"id":"107037","messageId":"49AF9745.8050207@viscovery.net","threadId":"18135","inReplyTo":"6d937a859ca499f534eea08720fca84f3d4ded2f.1236187259.git.barvik@broadpark.no","subject":"Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-03-05T09:11:33Z","receivedAt":"2009-03-05T09:11:33Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Kjetil Barvik schrieb:\n> -\tistate->timestamp.sec = st.st_mtime;\n> -#ifdef USE_NSEC\n> +\tistate->timestamp.sec = (unsigned int)st.st_mtime;\n>  \tistate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;\n> -#else\n> -\tistate->timestamp.nsec = 0;\n> -#endif\n\nDoesn't this break on systems where st_mtime is time_t and st_mtim does\nnot exist?\n\n-- Hannes\n"},{"id":"107063","messageId":"49AFBDAD.5040501@viscovery.net","threadId":"18135","inReplyTo":"49AF9745.8050207@viscovery.net","subject":"Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-03-05T11:55:25Z","receivedAt":"2009-03-05T11:55:25Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Sixt schrieb:\n> Kjetil Barvik schrieb:\n>> -\tistate->timestamp.sec = st.st_mtime;\n>> -#ifdef USE_NSEC\n>> +\tistate->timestamp.sec = (unsigned int)st.st_mtime;\n>>  \tistate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;\n>> -#else\n>> -\tistate->timestamp.nsec = 0;\n>> -#endif\n> \n> Doesn't this break on systems where st_mtime is time_t and st_mtim does\n> not exist?\n\nYes, it breaks. You can test this on Linux by commenting out these two\nlines in git-compat-util.h:\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex dcf4127..ab4b615 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -44,8 +44,8 @@\n #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */\n #endif\n #define _ALL_SOURCE 1\n-#define _GNU_SOURCE 1\n-#define _BSD_SOURCE 1\n+/*#define _GNU_SOURCE 1*/\n+/*#define _BSD_SOURCE 1*/\n\n #include <unistd.h>\n #include <stdio.h>\n\nThe result even passes the test suite (as long as I don't merge\nkb/checkout-optim, of course).\n\n-- Hannes\n"},{"id":"107087","messageId":"7v4oy7241g.fsf@gitster.siamese.dyndns.org","threadId":"18135","inReplyTo":"49AFBDAD.5040501@viscovery.net","subject":"Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-05T18:55:07Z","receivedAt":"2009-03-05T18:55:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> Yes, it breaks. You can test this on Linux by commenting out these two\n> lines in git-compat-util.h:\n>\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index dcf4127..ab4b615 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -44,8 +44,8 @@\n>  #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */\n>  #endif\n>  #define _ALL_SOURCE 1\n> -#define _GNU_SOURCE 1\n> -#define _BSD_SOURCE 1\n> +/*#define _GNU_SOURCE 1*/\n> +/*#define _BSD_SOURCE 1*/\n>\n>  #include <unistd.h>\n>  #include <stdio.h>\n>\n> The result even passes the test suite (as long as I don't merge\n> kb/checkout-optim, of course).\n\nIsn't it better to separate \"do we want to use that information if we can\nnanosecocond timestamps\" and \"is the API available for reading nanosecond\ntimestamps\" into separete switches, like this partial patch on top of the\npatch we are discussing, then?  It is partial because it shows the way to\nconvert only one call site as an example and of course you need to update\nthe Makefile and autoconf.\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 079cbe9..910aa03 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -384,4 +384,12 @@ void git_qsort(void *base, size_t nmemb, size_t size,\n # define FORCE_DIR_SET_GID 0\n #endif\n \n+#ifdef HAS_NSEC\n+#define ST_CTIME_NSEC(st) ((unsigned ing)((st).st_ctim.tv_nsec))\n+#define ST_MTIME_NSEC(st) ((unsigned ing)((st).st_mtim.tv_nsec))\n+#else\n+#define ST_CTIME_NSEC(st) 0\n+#define ST_MTIME_NSEC(st) 0\n+#endif\n+\n #endif\ndiff --git a/read-cache.c b/read-cache.c\nindex 91f1d03..bb5cb2b 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -69,13 +69,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)\n {\n \tce->ce_ctime.sec = (unsigned int)st->st_ctime;\n \tce->ce_mtime.sec = (unsigned int)st->st_mtime;\n-#ifdef USE_NSEC\n-\tce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;\n-\tce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;\n-#else\n-\tce->ce_ctime.nsec = 0;\n-\tce->ce_mtime.nsec = 0;\n-#endif\n+\tce->ce_ctime.nsec = ST_CTIME_NSEC(*st);\n+\tce->ce_mtime.nsec = ST_MTIME_NSEC(*st);\n \tce->ce_dev = st->st_dev;\n \tce->ce_ino = st->st_ino;\n \tce->ce_uid = st->st_uid;\n"},{"id":"107091","messageId":"7vd4cvzqkl.fsf@gitster.siamese.dyndns.org","threadId":"18135","inReplyTo":"7v4oy7241g.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-05T20:02:02Z","receivedAt":"2009-03-05T20:02:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Johannes Sixt <j.sixt@viscovery.net> writes:\n>\n>> Yes, it breaks. You can test this on Linux by commenting out these two\n>> lines in git-compat-util.h:\n>>\n>> diff --git a/git-compat-util.h b/git-compat-util.h\n>> index dcf4127..ab4b615 100644\n>> --- a/git-compat-util.h\n>> +++ b/git-compat-util.h\n>> @@ -44,8 +44,8 @@\n>>  #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */\n>>  #endif\n>>  #define _ALL_SOURCE 1\n>> -#define _GNU_SOURCE 1\n>> -#define _BSD_SOURCE 1\n>> +/*#define _GNU_SOURCE 1*/\n>> +/*#define _BSD_SOURCE 1*/\n>>  #include <unistd.h>\n>>  #include <stdio.h>\n>>\n>> The result even passes the test suite (as long as I don't merge\n>> kb/checkout-optim, of course).\n\nThis actually will trigger more compilation breakages than that.  For\nexample, it hides memmem() and strchrnul() from everybody, and makes the\ncompilation error out with this subtract as the compiler has to assume you\nare subtracting a pointer from an integer:\n\n\t\tlinelen = strchrnul(msg_p, '\\n') - msg_p;\n\nI cannot test the result myself to see if it still works this way.\n\n> Isn't it better to separate \"do we want to use that information if we can\n> nanosecocond timestamps\" and \"is the API available for reading nanosecond\n> timestamps\" into separete switches, like this partial patch on top of the\n> patch we are discussing, then?  It is partial because it shows the way to\n> convert only one call site as an example and of course you need to update\n> the Makefile and autoconf.\n\nAnd here is what I did.  It is meant to replace the patch in discussion.\n\n-- >8 --\nRecord ns-timestamps if possible, but do not use it without USE_NSEC\n\nTraditionally, the lack of USE_NSEC meant \"do not record nor use the\nnanosecond resolution part of the file timestamps\".  To avoid problems on\nfilesystems that lose the ns part when the metadata is flushed to the disk\nand then later read back in, disabling USE_NSEC has been a good idea in\ngeneral.\n\nIf you are on a filesystem without such an issue, it does not hurt to read\nand store them in the cached stat data in the index entries even if your\ngit is compiled without USE_NSEC.  The index left with such a version of\ngit can be read by git compiled with USE_NSEC and it can make use of the\nnanosecond part to optimize the check to see if the path on the filesystem\nhsa been modified since we last looked at.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Makefile             |    7 +++++++\n builtin-fetch-pack.c |    4 +---\n git-compat-util.h    |    9 +++++++++\n read-cache.c         |   29 ++++-------------------------\n unpack-trees.c       |    2 --\n 5 files changed, 21 insertions(+), 30 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 27b9569..e63034d 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -126,6 +126,9 @@ all::\n # randomly break unless your underlying filesystem supports those sub-second\n # times (my ext3 doesn't).\n #\n+# Define NO_NSEC if your \"struct stat\" does not have \"st_ctim.tv_nsec\"\n+# available.  This automatically turns USE_NSEC off.\n+#\n # Define USE_STDEV below if you want git to care about the underlying device\n # change being considered an inode change from the update-index perspective.\n #\n@@ -802,6 +805,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))\n \tRUNTIME_PREFIX = YesPlease\n \tNO_POSIX_ONLY_PROGRAMS = YesPlease\n \tNO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease\n+\tNO_NSEC = YesPlease\n \tCOMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch\n \tCOMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1\n \tCOMPAT_CFLAGS += -DSTRIP_EXTENSION=\\\".exe\\\"\n@@ -923,6 +927,9 @@ endif\n ifdef NO_ST_BLOCKS_IN_STRUCT_STAT\n \tBASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT\n endif\n+ifdef NO_NSEC\n+\tBASIC_CFLAGS += -DNO_NSEC\n+endif\n ifdef NO_C99_FORMAT\n \tBASIC_CFLAGS += -DNO_C99_FORMAT\n endif\ndiff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c\nindex 3b210c7..59b0b0a 100644\n--- a/builtin-fetch-pack.c\n+++ b/builtin-fetch-pack.c\n@@ -801,9 +801,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,\n \t\tint fd;\n \n \t\tmtime.sec = st.st_mtime;\n-#ifdef USE_NSEC\n-\t\tmtime.nsec = st.st_mtim.tv_nsec;\n-#endif\n+\t\tmtime.nsec = ST_MTIME_NSEC(st);\n \t\tif (stat(shallow, &st)) {\n \t\t\tif (mtime.sec)\n \t\t\t\tdie(\"shallow file was removed during fetch\");\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 079cbe9..9b495dc 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -384,4 +384,13 @@ void git_qsort(void *base, size_t nmemb, size_t size,\n # define FORCE_DIR_SET_GID 0\n #endif\n \n+#ifdef NO_NSEC\n+#undef USE_NSEC\n+#define ST_CTIME_NSEC(st) 0\n+#define ST_MTIME_NSEC(st) 0\n+#else\n+#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))\n+#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))\n+#endif\n+\n #endif\ndiff --git a/read-cache.c b/read-cache.c\nindex 91f1d03..b819abb 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -69,13 +69,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)\n {\n \tce->ce_ctime.sec = (unsigned int)st->st_ctime;\n \tce->ce_mtime.sec = (unsigned int)st->st_mtime;\n-#ifdef USE_NSEC\n-\tce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;\n-\tce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;\n-#else\n-\tce->ce_ctime.nsec = 0;\n-\tce->ce_mtime.nsec = 0;\n-#endif\n+\tce->ce_ctime.nsec = ST_CTIME_NSEC(*st);\n+\tce->ce_mtime.nsec = ST_MTIME_NSEC(*st);\n \tce->ce_dev = st->st_dev;\n \tce->ce_ino = st->st_ino;\n \tce->ce_uid = st->st_uid;\n@@ -1183,13 +1178,8 @@ static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_en\n \n \tce->ce_ctime.sec = ntohl(ondisk->ctime.sec);\n \tce->ce_mtime.sec = ntohl(ondisk->mtime.sec);\n-#ifdef USE_NSEC\n \tce->ce_ctime.nsec = ntohl(ondisk->ctime.nsec);\n \tce->ce_mtime.nsec = ntohl(ondisk->mtime.nsec);\n-#else\n-\tce->ce_ctime.nsec = 0;\n-\tce->ce_mtime.nsec = 0;\n-#endif\n \tce->ce_dev   = ntohl(ondisk->dev);\n \tce->ce_ino   = ntohl(ondisk->ino);\n \tce->ce_mode  = ntohl(ondisk->mode);\n@@ -1309,11 +1299,7 @@ int read_index_from(struct index_state *istate, const char *path)\n \t\tdst_offset += ce_size(ce);\n \t}\n \tistate->timestamp.sec = st.st_mtime;\n-#ifdef USE_NSEC\n-\tistate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;\n-#else\n-\tistate->timestamp.nsec = 0;\n-#endif\n+\tistate->timestamp.nsec = ST_MTIME_NSEC(st);\n \n \twhile (src_offset <= mmap_size - 20 - 8) {\n \t\t/* After an array of active_nr index entries,\n@@ -1500,13 +1486,8 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)\n \n \tondisk->ctime.sec = htonl(ce->ce_ctime.sec);\n \tondisk->mtime.sec = htonl(ce->ce_mtime.sec);\n-#ifdef USE_NSEC\n \tondisk->ctime.nsec = htonl(ce->ce_ctime.nsec);\n \tondisk->mtime.nsec = htonl(ce->ce_mtime.nsec);\n-#else\n-\tondisk->ctime.nsec = 0;\n-\tondisk->mtime.nsec = 0;\n-#endif\n \tondisk->dev  = htonl(ce->ce_dev);\n \tondisk->ino  = htonl(ce->ce_ino);\n \tondisk->mode = htonl(ce->ce_mode);\n@@ -1583,9 +1564,7 @@ int write_index(struct index_state *istate, int newfd)\n \tif (ce_flush(&c, newfd) || fstat(newfd, &st))\n \t\treturn -1;\n \tistate->timestamp.sec = (unsigned int)st.st_ctime;\n-#ifdef USE_NSEC\n-\tistate->timestamp.nsec = (unsigned int)st.st_ctim.tv_nsec;\n-#endif\n+\tistate->timestamp.nsec = ST_CTIME_NSEC(st);\n \treturn 0;\n }\n \ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 9fe0cd5..da2e3c0 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -362,9 +362,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \to->result.initialized = 1;\n \tif (o->src_index) {\n \t\to->result.timestamp.sec = o->src_index->timestamp.sec;\n-#ifdef USE_NSEC\n \t\to->result.timestamp.nsec = o->src_index->timestamp.nsec;\n-#endif\n \t}\n \to->merge_size = len;\n \n"},{"id":"107159","messageId":"49B0D739.3050105@viscovery.net","threadId":"18135","inReplyTo":"7vd4cvzqkl.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-03-06T07:56:41Z","receivedAt":"2009-03-06T07:56:41Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Junio C Hamano schrieb:\n> Record ns-timestamps if possible, but do not use it without USE_NSEC\n> \n> Traditionally, the lack of USE_NSEC meant \"do not record nor use the\n> nanosecond resolution part of the file timestamps\".  To avoid problems on\n> filesystems that lose the ns part when the metadata is flushed to the disk\n> and then later read back in, disabling USE_NSEC has been a good idea in\n> general.\n> \n> If you are on a filesystem without such an issue, it does not hurt to read\n> and store them in the cached stat data in the index entries even if your\n> git is compiled without USE_NSEC.  The index left with such a version of\n> git can be read by git compiled with USE_NSEC and it can make use of the\n> nanosecond part to optimize the check to see if the path on the filesystem\n> hsa been modified since we last looked at.\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n...\n> +# Define NO_NSEC if your \"struct stat\" does not have \"st_ctim.tv_nsec\"\n> +# available.  This automatically turns USE_NSEC off.\n> +#\n...\n> @@ -802,6 +805,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))\n>  \tRUNTIME_PREFIX = YesPlease\n>  \tNO_POSIX_ONLY_PROGRAMS = YesPlease\n>  \tNO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease\n> +\tNO_NSEC = YesPlease\n>  \tCOMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch\n>  \tCOMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1\n>  \tCOMPAT_CFLAGS += -DSTRIP_EXTENSION=\\\".exe\\\"\n\nThanks, with this the build no longer breaks on Windows. But I need this\noption on AIX as well:\n\ndiff --git a/Makefile b/Makefile\nindex 137a3ff..b974978 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -737,6 +737,7 @@ ifeq ($(uname_S),AIX)\n \tNO_MEMMEM = YesPlease\n \tNO_MKDTEMP = YesPlease\n \tNO_STRLCPY = YesPlease\n+\tNO_NSEC = YesPlease\n \tFREAD_READS_DIRECTORIES = UnfortunatelyYes\n \tINTERNAL_QSORT = UnfortunatelyYes\n \tNEEDS_LIBICONV=YesPlease\n\n-- Hannes\n"}]}