* [PATCH 0/2] some few more 'git checkout' improvements
@ 2009-03-04 17:47 Kjetil Barvik
2009-03-04 17:47 ` [PATCH 1/2] stat_tracking_info(): only count real commits Kjetil Barvik
2009-03-04 17:47 ` [PATCH 2/2] better introduction of GIT with USE_NSEC defined Kjetil Barvik
0 siblings, 2 replies; 11+ messages in thread
From: Kjetil Barvik @ 2009-03-04 17:47 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Kjetil Barvik
- one bugfix (I hope)
- and one patch to make life easier when using the USE_NSEC define
These 2 patches is based on 'next' because patch 2/2 is based on one
previous patch, which is only in 'next' for the moment.
Kjetil Barvik (2):
stat_tracking_info(): only count real commits
better introduction of GIT with USE_NSEC defined
read-cache.c | 23 +----------------------
remote.c | 3 ++-
unpack-trees.c | 2 --
3 files changed, 3 insertions(+), 25 deletions(-)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/2] stat_tracking_info(): only count real commits
2009-03-04 17:47 [PATCH 0/2] some few more 'git checkout' improvements Kjetil Barvik
@ 2009-03-04 17:47 ` Kjetil Barvik
2009-03-04 17:47 ` [PATCH 2/2] better introduction of GIT with USE_NSEC defined Kjetil Barvik
1 sibling, 0 replies; 11+ messages in thread
From: Kjetil Barvik @ 2009-03-04 17:47 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Kjetil Barvik
stat_tracking_info() in remote.c is used to collect the statistics to
be able to say (for instance) from the output of "git checkout':
Your branch and 'foo' have diverged,
and have X and Y different commit(s) each, respectively.
Currently X and Y also includes the count of merges. This patch
excludes the merges from being counted.
Signed-off-by: Kjetil Barvik <barvik@broadpark.no>
---
I hope this is a correct fix, and that it is realy a bugfix.
~~
By the way, I have noticed that when the Y number above is large
(for instance for a branch I have where Y is ~ 600), then the
function get_merge_bases_many() and in particular merge_bases_many()
in commit.c will take a noticable amount of user time (aprox 0.4
seconds). So if the chekcout results in that few files need to be
updated (< 10), this will sometimes acount for much of the total
time needed for the 'git checkout' command.
It seems that even though only max 4000 or so unique commits is
touched (when Y ~ 600), each commit is touched over 250 times, for
instancce by the insert_by_date() function inside the while-loop in
merge_bases_many().
Do someone think it is possible to have a better algorithm here?
Maybe O(Nlog(n)) or better? Does someone has a hint about how to
make it better?
remote.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/remote.c b/remote.c
index d7079c6..06c414e 100644
--- a/remote.c
+++ b/remote.c
@@ -1310,9 +1310,10 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
if (theirs == ours)
return 0;
- /* Run "rev-list --left-right ours...theirs" internally... */
+ /* Run "rev-list --no-merges --left-right ours...theirs" internally... */
rev_argc = 0;
rev_argv[rev_argc++] = NULL;
+ rev_argv[rev_argc++] = "--no-merges";
rev_argv[rev_argc++] = "--left-right";
rev_argv[rev_argc++] = symmetric;
rev_argv[rev_argc++] = "--";
--
1.6.1.GIT
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-04 17:47 [PATCH 0/2] some few more 'git checkout' improvements Kjetil Barvik
2009-03-04 17:47 ` [PATCH 1/2] stat_tracking_info(): only count real commits Kjetil Barvik
@ 2009-03-04 17:47 ` Kjetil Barvik
2009-03-05 0:41 ` Junio C Hamano
2009-03-05 9:11 ` Johannes Sixt
1 sibling, 2 replies; 11+ messages in thread
From: Kjetil Barvik @ 2009-03-04 17:47 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Kjetil Barvik
Change the source code such that when USE_NSEC is not defined,
possible nanosecond timestamps will still be saved in the index file,
but not used inside if-test's, and will therefore not affect the
outcome of GIT commands, other than the saved nanosecond timestamps in
the index file.
This will make it easier to use a system with 2 versions of GIT, one
with and one without USE_NSEC defined.
Signed-off-by: Kjetil Barvik <barvik@broadpark.no>
---
read-cache.c | 23 +----------------------
unpack-trees.c | 2 --
2 files changed, 1 insertions(+), 24 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 91f1d03..7fca804 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -69,13 +69,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
{
ce->ce_ctime.sec = (unsigned int)st->st_ctime;
ce->ce_mtime.sec = (unsigned int)st->st_mtime;
-#ifdef USE_NSEC
ce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;
ce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;
-#else
- ce->ce_ctime.nsec = 0;
- ce->ce_mtime.nsec = 0;
-#endif
ce->ce_dev = st->st_dev;
ce->ce_ino = st->st_ino;
ce->ce_uid = st->st_uid;
@@ -1183,13 +1178,8 @@ static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_en
ce->ce_ctime.sec = ntohl(ondisk->ctime.sec);
ce->ce_mtime.sec = ntohl(ondisk->mtime.sec);
-#ifdef USE_NSEC
ce->ce_ctime.nsec = ntohl(ondisk->ctime.nsec);
ce->ce_mtime.nsec = ntohl(ondisk->mtime.nsec);
-#else
- ce->ce_ctime.nsec = 0;
- ce->ce_mtime.nsec = 0;
-#endif
ce->ce_dev = ntohl(ondisk->dev);
ce->ce_ino = ntohl(ondisk->ino);
ce->ce_mode = ntohl(ondisk->mode);
@@ -1308,12 +1298,8 @@ int read_index_from(struct index_state *istate, const char *path)
src_offset += ondisk_ce_size(ce);
dst_offset += ce_size(ce);
}
- istate->timestamp.sec = st.st_mtime;
-#ifdef USE_NSEC
+ istate->timestamp.sec = (unsigned int)st.st_mtime;
istate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;
-#else
- istate->timestamp.nsec = 0;
-#endif
while (src_offset <= mmap_size - 20 - 8) {
/* After an array of active_nr index entries,
@@ -1500,13 +1486,8 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
-#ifdef USE_NSEC
ondisk->ctime.nsec = htonl(ce->ce_ctime.nsec);
ondisk->mtime.nsec = htonl(ce->ce_mtime.nsec);
-#else
- ondisk->ctime.nsec = 0;
- ondisk->mtime.nsec = 0;
-#endif
ondisk->dev = htonl(ce->ce_dev);
ondisk->ino = htonl(ce->ce_ino);
ondisk->mode = htonl(ce->ce_mode);
@@ -1583,9 +1564,7 @@ int write_index(struct index_state *istate, int newfd)
if (ce_flush(&c, newfd) || fstat(newfd, &st))
return -1;
istate->timestamp.sec = (unsigned int)st.st_ctime;
-#ifdef USE_NSEC
istate->timestamp.nsec = (unsigned int)st.st_ctim.tv_nsec;
-#endif
return 0;
}
diff --git a/unpack-trees.c b/unpack-trees.c
index 9fe0cd5..da2e3c0 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -362,9 +362,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
o->result.initialized = 1;
if (o->src_index) {
o->result.timestamp.sec = o->src_index->timestamp.sec;
-#ifdef USE_NSEC
o->result.timestamp.nsec = o->src_index->timestamp.nsec;
-#endif
}
o->merge_size = len;
--
1.6.1.GIT
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-04 17:47 ` [PATCH 2/2] better introduction of GIT with USE_NSEC defined Kjetil Barvik
@ 2009-03-05 0:41 ` Junio C Hamano
2009-03-05 7:17 ` Kjetil Barvik
2009-03-05 9:11 ` Johannes Sixt
1 sibling, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2009-03-05 0:41 UTC (permalink / raw)
To: Kjetil Barvik; +Cc: git
Kjetil Barvik <barvik@broadpark.no> writes:
> Change the source code such that when USE_NSEC is not defined,
> possible nanosecond timestamps will still be saved in the index file,
> but not used inside if-test's, and will therefore not affect the
> outcome of GIT commands, other than the saved nanosecond timestamps in
> the index file.
>
> This will make it easier to use a system with 2 versions of GIT, one
> with and one without USE_NSEC defined.
I take it that you are responding to my earlier question with this patch?
From: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH/RFC v2 2/3] make USE_NSEC work as expected
Date: Fri, 20 Feb 2009 00:35:35 -0800
Message-ID: <7vab8hfqug.fsf@gitster.siamese.dyndns.org>
Kjetil Barvik <barvik@broadpark.no> writes:
> diff --git a/read-cache.c b/read-cache.c
> index 940ec76..ca4bec2 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -67,8 +67,15 @@ void rename_index_entry_at(struct index_state *istate,..
> */
> void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
> {
> - ce->ce_ctime = st->st_ctime;
> - ce->ce_mtime = st->st_mtime;
> + ce->ce_ctime.sec = (unsigned int)st->st_ctime;
> + ce->ce_mtime.sec = (unsigned int)st->st_mtime;
> +#ifdef USE_NSEC
> + ce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;
> + ce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;
> +#else
> + ce->ce_ctime.nsec = 0;
> + ce->ce_mtime.nsec = 0;
> +#endif
How does this affect a use case where the same index file used with two
instances of git (one compiled with and another without USE_NSEC)?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-05 0:41 ` Junio C Hamano
@ 2009-03-05 7:17 ` Kjetil Barvik
2009-03-05 7:38 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Kjetil Barvik @ 2009-03-05 7:17 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Junio C Hamano <gitster@pobox.com> writes:
> Kjetil Barvik <barvik@broadpark.no> writes:
>
>> Change the source code such that when USE_NSEC is not defined,
>> possible nanosecond timestamps will still be saved in the index file,
>> but not used inside if-test's, and will therefore not affect the
>> outcome of GIT commands, other than the saved nanosecond timestamps in
>> the index file.
>>
>> This will make it easier to use a system with 2 versions of GIT, one
>> with and one without USE_NSEC defined.
>
> I take it that you are responding to my earlier question with this
> patch?
Yes, you are correct.
[....]
> How does this affect a use case where the same index file used with two
> instances of git (one compiled with and another without USE_NSEC)?
If both persons in this use case use this patch, the one with USE_NSEC
defined will now be able to take full advantage of the nanosecond
timestamps at all times.
The one without USE_NSEC defined should not be able to tell the
difference (without looking into to details of the index file).
-- kjetil
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-05 7:17 ` Kjetil Barvik
@ 2009-03-05 7:38 ` Junio C Hamano
0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2009-03-05 7:38 UTC (permalink / raw)
To: Kjetil Barvik; +Cc: git
Kjetil Barvik <barvik@broadpark.no> writes:
> Junio C Hamano <gitster@pobox.com> writes:
> ...
>> How does this affect a use case where the same index file used with two
>> instances of git (one compiled with and another without USE_NSEC)?
>
> If both persons in this use case use this patch, the one with USE_NSEC
> defined will now be able to take full advantage of the nanosecond
> timestamps at all times.
>
> The one without USE_NSEC defined should not be able to tell the
> difference (without looking into to details of the index file).
As long as the implementation does not give false cleanliness it is
perfectly fine; false dirtinesss is just a bit of wasted cycle.
Thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-04 17:47 ` [PATCH 2/2] better introduction of GIT with USE_NSEC defined Kjetil Barvik
2009-03-05 0:41 ` Junio C Hamano
@ 2009-03-05 9:11 ` Johannes Sixt
2009-03-05 11:55 ` Johannes Sixt
1 sibling, 1 reply; 11+ messages in thread
From: Johannes Sixt @ 2009-03-05 9:11 UTC (permalink / raw)
To: Kjetil Barvik; +Cc: git, Junio C Hamano
Kjetil Barvik schrieb:
> - istate->timestamp.sec = st.st_mtime;
> -#ifdef USE_NSEC
> + istate->timestamp.sec = (unsigned int)st.st_mtime;
> istate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;
> -#else
> - istate->timestamp.nsec = 0;
> -#endif
Doesn't this break on systems where st_mtime is time_t and st_mtim does
not exist?
-- Hannes
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-05 9:11 ` Johannes Sixt
@ 2009-03-05 11:55 ` Johannes Sixt
2009-03-05 18:55 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Johannes Sixt @ 2009-03-05 11:55 UTC (permalink / raw)
To: Kjetil Barvik; +Cc: git, Junio C Hamano
Johannes Sixt schrieb:
> Kjetil Barvik schrieb:
>> - istate->timestamp.sec = st.st_mtime;
>> -#ifdef USE_NSEC
>> + istate->timestamp.sec = (unsigned int)st.st_mtime;
>> istate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;
>> -#else
>> - istate->timestamp.nsec = 0;
>> -#endif
>
> Doesn't this break on systems where st_mtime is time_t and st_mtim does
> not exist?
Yes, it breaks. You can test this on Linux by commenting out these two
lines in git-compat-util.h:
diff --git a/git-compat-util.h b/git-compat-util.h
index dcf4127..ab4b615 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -44,8 +44,8 @@
#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
#endif
#define _ALL_SOURCE 1
-#define _GNU_SOURCE 1
-#define _BSD_SOURCE 1
+/*#define _GNU_SOURCE 1*/
+/*#define _BSD_SOURCE 1*/
#include <unistd.h>
#include <stdio.h>
The result even passes the test suite (as long as I don't merge
kb/checkout-optim, of course).
-- Hannes
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-05 11:55 ` Johannes Sixt
@ 2009-03-05 18:55 ` Junio C Hamano
2009-03-05 20:02 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2009-03-05 18:55 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Kjetil Barvik, git
Johannes Sixt <j.sixt@viscovery.net> writes:
> Yes, it breaks. You can test this on Linux by commenting out these two
> lines in git-compat-util.h:
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index dcf4127..ab4b615 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -44,8 +44,8 @@
> #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
> #endif
> #define _ALL_SOURCE 1
> -#define _GNU_SOURCE 1
> -#define _BSD_SOURCE 1
> +/*#define _GNU_SOURCE 1*/
> +/*#define _BSD_SOURCE 1*/
>
> #include <unistd.h>
> #include <stdio.h>
>
> The result even passes the test suite (as long as I don't merge
> kb/checkout-optim, of course).
Isn't it better to separate "do we want to use that information if we can
nanosecocond timestamps" and "is the API available for reading nanosecond
timestamps" into separete switches, like this partial patch on top of the
patch we are discussing, then? It is partial because it shows the way to
convert only one call site as an example and of course you need to update
the Makefile and autoconf.
diff --git a/git-compat-util.h b/git-compat-util.h
index 079cbe9..910aa03 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -384,4 +384,12 @@ void git_qsort(void *base, size_t nmemb, size_t size,
# define FORCE_DIR_SET_GID 0
#endif
+#ifdef HAS_NSEC
+#define ST_CTIME_NSEC(st) ((unsigned ing)((st).st_ctim.tv_nsec))
+#define ST_MTIME_NSEC(st) ((unsigned ing)((st).st_mtim.tv_nsec))
+#else
+#define ST_CTIME_NSEC(st) 0
+#define ST_MTIME_NSEC(st) 0
+#endif
+
#endif
diff --git a/read-cache.c b/read-cache.c
index 91f1d03..bb5cb2b 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -69,13 +69,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
{
ce->ce_ctime.sec = (unsigned int)st->st_ctime;
ce->ce_mtime.sec = (unsigned int)st->st_mtime;
-#ifdef USE_NSEC
- ce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;
- ce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;
-#else
- ce->ce_ctime.nsec = 0;
- ce->ce_mtime.nsec = 0;
-#endif
+ ce->ce_ctime.nsec = ST_CTIME_NSEC(*st);
+ ce->ce_mtime.nsec = ST_MTIME_NSEC(*st);
ce->ce_dev = st->st_dev;
ce->ce_ino = st->st_ino;
ce->ce_uid = st->st_uid;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-05 18:55 ` Junio C Hamano
@ 2009-03-05 20:02 ` Junio C Hamano
2009-03-06 7:56 ` Johannes Sixt
0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2009-03-05 20:02 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Kjetil Barvik, git
Junio C Hamano <gitster@pobox.com> writes:
> Johannes Sixt <j.sixt@viscovery.net> writes:
>
>> Yes, it breaks. You can test this on Linux by commenting out these two
>> lines in git-compat-util.h:
>>
>> diff --git a/git-compat-util.h b/git-compat-util.h
>> index dcf4127..ab4b615 100644
>> --- a/git-compat-util.h
>> +++ b/git-compat-util.h
>> @@ -44,8 +44,8 @@
>> #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */
>> #endif
>> #define _ALL_SOURCE 1
>> -#define _GNU_SOURCE 1
>> -#define _BSD_SOURCE 1
>> +/*#define _GNU_SOURCE 1*/
>> +/*#define _BSD_SOURCE 1*/
>> #include <unistd.h>
>> #include <stdio.h>
>>
>> The result even passes the test suite (as long as I don't merge
>> kb/checkout-optim, of course).
This actually will trigger more compilation breakages than that. For
example, it hides memmem() and strchrnul() from everybody, and makes the
compilation error out with this subtract as the compiler has to assume you
are subtracting a pointer from an integer:
linelen = strchrnul(msg_p, '\n') - msg_p;
I cannot test the result myself to see if it still works this way.
> Isn't it better to separate "do we want to use that information if we can
> nanosecocond timestamps" and "is the API available for reading nanosecond
> timestamps" into separete switches, like this partial patch on top of the
> patch we are discussing, then? It is partial because it shows the way to
> convert only one call site as an example and of course you need to update
> the Makefile and autoconf.
And here is what I did. It is meant to replace the patch in discussion.
-- >8 --
Record ns-timestamps if possible, but do not use it without USE_NSEC
Traditionally, the lack of USE_NSEC meant "do not record nor use the
nanosecond resolution part of the file timestamps". To avoid problems on
filesystems that lose the ns part when the metadata is flushed to the disk
and then later read back in, disabling USE_NSEC has been a good idea in
general.
If you are on a filesystem without such an issue, it does not hurt to read
and store them in the cached stat data in the index entries even if your
git is compiled without USE_NSEC. The index left with such a version of
git can be read by git compiled with USE_NSEC and it can make use of the
nanosecond part to optimize the check to see if the path on the filesystem
hsa been modified since we last looked at.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Makefile | 7 +++++++
builtin-fetch-pack.c | 4 +---
git-compat-util.h | 9 +++++++++
read-cache.c | 29 ++++-------------------------
unpack-trees.c | 2 --
5 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/Makefile b/Makefile
index 27b9569..e63034d 100644
--- a/Makefile
+++ b/Makefile
@@ -126,6 +126,9 @@ all::
# randomly break unless your underlying filesystem supports those sub-second
# times (my ext3 doesn't).
#
+# Define NO_NSEC if your "struct stat" does not have "st_ctim.tv_nsec"
+# available. This automatically turns USE_NSEC off.
+#
# Define USE_STDEV below if you want git to care about the underlying device
# change being considered an inode change from the update-index perspective.
#
@@ -802,6 +805,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
RUNTIME_PREFIX = YesPlease
NO_POSIX_ONLY_PROGRAMS = YesPlease
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
+ NO_NSEC = YesPlease
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch
COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
@@ -923,6 +927,9 @@ endif
ifdef NO_ST_BLOCKS_IN_STRUCT_STAT
BASIC_CFLAGS += -DNO_ST_BLOCKS_IN_STRUCT_STAT
endif
+ifdef NO_NSEC
+ BASIC_CFLAGS += -DNO_NSEC
+endif
ifdef NO_C99_FORMAT
BASIC_CFLAGS += -DNO_C99_FORMAT
endif
diff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c
index 3b210c7..59b0b0a 100644
--- a/builtin-fetch-pack.c
+++ b/builtin-fetch-pack.c
@@ -801,9 +801,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,
int fd;
mtime.sec = st.st_mtime;
-#ifdef USE_NSEC
- mtime.nsec = st.st_mtim.tv_nsec;
-#endif
+ mtime.nsec = ST_MTIME_NSEC(st);
if (stat(shallow, &st)) {
if (mtime.sec)
die("shallow file was removed during fetch");
diff --git a/git-compat-util.h b/git-compat-util.h
index 079cbe9..9b495dc 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -384,4 +384,13 @@ void git_qsort(void *base, size_t nmemb, size_t size,
# define FORCE_DIR_SET_GID 0
#endif
+#ifdef NO_NSEC
+#undef USE_NSEC
+#define ST_CTIME_NSEC(st) 0
+#define ST_MTIME_NSEC(st) 0
+#else
+#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec))
+#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec))
+#endif
+
#endif
diff --git a/read-cache.c b/read-cache.c
index 91f1d03..b819abb 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -69,13 +69,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
{
ce->ce_ctime.sec = (unsigned int)st->st_ctime;
ce->ce_mtime.sec = (unsigned int)st->st_mtime;
-#ifdef USE_NSEC
- ce->ce_ctime.nsec = (unsigned int)st->st_ctim.tv_nsec;
- ce->ce_mtime.nsec = (unsigned int)st->st_mtim.tv_nsec;
-#else
- ce->ce_ctime.nsec = 0;
- ce->ce_mtime.nsec = 0;
-#endif
+ ce->ce_ctime.nsec = ST_CTIME_NSEC(*st);
+ ce->ce_mtime.nsec = ST_MTIME_NSEC(*st);
ce->ce_dev = st->st_dev;
ce->ce_ino = st->st_ino;
ce->ce_uid = st->st_uid;
@@ -1183,13 +1178,8 @@ static void convert_from_disk(struct ondisk_cache_entry *ondisk, struct cache_en
ce->ce_ctime.sec = ntohl(ondisk->ctime.sec);
ce->ce_mtime.sec = ntohl(ondisk->mtime.sec);
-#ifdef USE_NSEC
ce->ce_ctime.nsec = ntohl(ondisk->ctime.nsec);
ce->ce_mtime.nsec = ntohl(ondisk->mtime.nsec);
-#else
- ce->ce_ctime.nsec = 0;
- ce->ce_mtime.nsec = 0;
-#endif
ce->ce_dev = ntohl(ondisk->dev);
ce->ce_ino = ntohl(ondisk->ino);
ce->ce_mode = ntohl(ondisk->mode);
@@ -1309,11 +1299,7 @@ int read_index_from(struct index_state *istate, const char *path)
dst_offset += ce_size(ce);
}
istate->timestamp.sec = st.st_mtime;
-#ifdef USE_NSEC
- istate->timestamp.nsec = (unsigned int)st.st_mtim.tv_nsec;
-#else
- istate->timestamp.nsec = 0;
-#endif
+ istate->timestamp.nsec = ST_MTIME_NSEC(st);
while (src_offset <= mmap_size - 20 - 8) {
/* After an array of active_nr index entries,
@@ -1500,13 +1486,8 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
-#ifdef USE_NSEC
ondisk->ctime.nsec = htonl(ce->ce_ctime.nsec);
ondisk->mtime.nsec = htonl(ce->ce_mtime.nsec);
-#else
- ondisk->ctime.nsec = 0;
- ondisk->mtime.nsec = 0;
-#endif
ondisk->dev = htonl(ce->ce_dev);
ondisk->ino = htonl(ce->ce_ino);
ondisk->mode = htonl(ce->ce_mode);
@@ -1583,9 +1564,7 @@ int write_index(struct index_state *istate, int newfd)
if (ce_flush(&c, newfd) || fstat(newfd, &st))
return -1;
istate->timestamp.sec = (unsigned int)st.st_ctime;
-#ifdef USE_NSEC
- istate->timestamp.nsec = (unsigned int)st.st_ctim.tv_nsec;
-#endif
+ istate->timestamp.nsec = ST_CTIME_NSEC(st);
return 0;
}
diff --git a/unpack-trees.c b/unpack-trees.c
index 9fe0cd5..da2e3c0 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -362,9 +362,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
o->result.initialized = 1;
if (o->src_index) {
o->result.timestamp.sec = o->src_index->timestamp.sec;
-#ifdef USE_NSEC
o->result.timestamp.nsec = o->src_index->timestamp.nsec;
-#endif
}
o->merge_size = len;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] better introduction of GIT with USE_NSEC defined
2009-03-05 20:02 ` Junio C Hamano
@ 2009-03-06 7:56 ` Johannes Sixt
0 siblings, 0 replies; 11+ messages in thread
From: Johannes Sixt @ 2009-03-06 7:56 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Kjetil Barvik, git
Junio C Hamano schrieb:
> Record ns-timestamps if possible, but do not use it without USE_NSEC
>
> Traditionally, the lack of USE_NSEC meant "do not record nor use the
> nanosecond resolution part of the file timestamps". To avoid problems on
> filesystems that lose the ns part when the metadata is flushed to the disk
> and then later read back in, disabling USE_NSEC has been a good idea in
> general.
>
> If you are on a filesystem without such an issue, it does not hurt to read
> and store them in the cached stat data in the index entries even if your
> git is compiled without USE_NSEC. The index left with such a version of
> git can be read by git compiled with USE_NSEC and it can make use of the
> nanosecond part to optimize the check to see if the path on the filesystem
> hsa been modified since we last looked at.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
...
> +# Define NO_NSEC if your "struct stat" does not have "st_ctim.tv_nsec"
> +# available. This automatically turns USE_NSEC off.
> +#
...
> @@ -802,6 +805,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
> RUNTIME_PREFIX = YesPlease
> NO_POSIX_ONLY_PROGRAMS = YesPlease
> NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
> + NO_NSEC = YesPlease
> COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch
> COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
> COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
Thanks, with this the build no longer breaks on Windows. But I need this
option on AIX as well:
diff --git a/Makefile b/Makefile
index 137a3ff..b974978 100644
--- a/Makefile
+++ b/Makefile
@@ -737,6 +737,7 @@ ifeq ($(uname_S),AIX)
NO_MEMMEM = YesPlease
NO_MKDTEMP = YesPlease
NO_STRLCPY = YesPlease
+ NO_NSEC = YesPlease
FREAD_READS_DIRECTORIES = UnfortunatelyYes
INTERNAL_QSORT = UnfortunatelyYes
NEEDS_LIBICONV=YesPlease
-- Hannes
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2009-03-06 7:58 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-04 17:47 [PATCH 0/2] some few more 'git checkout' improvements Kjetil Barvik
2009-03-04 17:47 ` [PATCH 1/2] stat_tracking_info(): only count real commits Kjetil Barvik
2009-03-04 17:47 ` [PATCH 2/2] better introduction of GIT with USE_NSEC defined Kjetil Barvik
2009-03-05 0:41 ` Junio C Hamano
2009-03-05 7:17 ` Kjetil Barvik
2009-03-05 7:38 ` Junio C Hamano
2009-03-05 9:11 ` Johannes Sixt
2009-03-05 11:55 ` Johannes Sixt
2009-03-05 18:55 ` Junio C Hamano
2009-03-05 20:02 ` Junio C Hamano
2009-03-06 7:56 ` Johannes Sixt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.