Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
c8b511f3
Commit
c8b511f3
authored
Oct 31, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better naming for file timestamp/size checker
parent
744cc03e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
31 deletions
+57
-31
src/attr.c
+7
-9
src/attr_file.h
+1
-1
src/fileops.c
+20
-10
src/fileops.h
+29
-11
No files found.
src/attr.c
View file @
c8b511f3
...
...
@@ -261,13 +261,13 @@ bool git_attr_cache__is_cached(
static
int
load_attr_file
(
const
char
**
data
,
git_futils_
stat_sig
*
sig
,
git_futils_
file_stamp
*
stamp
,
const
char
*
filename
)
{
int
error
;
git_buf
content
=
GIT_BUF_INIT
;
error
=
git_futils_
stat_sig_needs_reload
(
sig
,
filename
);
error
=
git_futils_
file_stamp_has_changed
(
stamp
,
filename
);
if
(
error
<
0
)
return
error
;
...
...
@@ -380,7 +380,7 @@ int git_attr_cache__push_file(
git_attr_cache
*
cache
=
git_repository_attr_cache
(
repo
);
git_attr_file
*
file
=
NULL
;
git_blob
*
blob
=
NULL
;
git_futils_
stat_sig
sig
;
git_futils_
file_stamp
stamp
;
assert
(
filename
&&
stack
);
...
...
@@ -402,12 +402,10 @@ int git_attr_cache__push_file(
/* if not in cache, load data, parse, and cache */
if
(
source
==
GIT_ATTR_FILE_FROM_FILE
)
{
if
(
file
)
memcpy
(
&
sig
,
&
file
->
cache_data
.
sig
,
sizeof
(
sig
));
else
memset
(
&
sig
,
0
,
sizeof
(
sig
));
git_futils_file_stamp_set
(
&
stamp
,
file
?
&
file
->
cache_data
.
stamp
:
NULL
);
error
=
load_attr_file
(
&
content
,
&
s
ig
,
filename
);
error
=
load_attr_file
(
&
content
,
&
s
tamp
,
filename
);
}
else
{
error
=
load_attr_blob_from_index
(
&
content
,
&
blob
,
repo
,
file
?
&
file
->
cache_data
.
oid
:
NULL
,
relfile
);
...
...
@@ -442,7 +440,7 @@ int git_attr_cache__push_file(
if
(
blob
)
git_oid_cpy
(
&
file
->
cache_data
.
oid
,
git_object_id
((
git_object
*
)
blob
));
else
memcpy
(
&
file
->
cache_data
.
sig
,
&
sig
,
sizeof
(
sig
)
);
git_futils_file_stamp_set
(
&
file
->
cache_data
.
stamp
,
&
stamp
);
finish:
/* push file onto vector if we found one*/
...
...
src/attr_file.h
View file @
c8b511f3
...
...
@@ -61,7 +61,7 @@ typedef struct {
bool
pool_is_allocated
;
union
{
git_oid
oid
;
git_futils_
stat_sig
sig
;
git_futils_
file_stamp
stamp
;
}
cache_data
;
}
git_attr_file
;
...
...
src/fileops.c
View file @
c8b511f3
...
...
@@ -671,27 +671,37 @@ int git_futils_cp_r(
return
error
;
}
int
git_futils_
stat_sig_needs_reloa
d
(
git_futils_
stat_sig
*
sig
,
const
char
*
path
)
int
git_futils_
file_stamp_has_change
d
(
git_futils_
file_stamp
*
stamp
,
const
char
*
path
)
{
struct
stat
st
;
/* if the s
ig is NULL, then alway
reload */
if
(
s
ig
==
NULL
)
/* if the s
tamp is NULL, then always
reload */
if
(
s
tamp
==
NULL
)
return
1
;
if
(
p_stat
(
path
,
&
st
)
<
0
)
return
GIT_ENOTFOUND
;
if
(
(
git_time_t
)
st
.
st_mtime
==
sig
->
seconds
&&
(
git_off_t
)
st
.
st_size
==
sig
->
size
&&
(
unsigned
int
)
st
.
st_ino
==
sig
->
ino
)
if
(
stamp
->
mtime
==
(
git_time_t
)
st
.
st_mtime
&&
stamp
->
size
==
(
git_off_t
)
st
.
st_size
&&
stamp
->
ino
==
(
unsigned
int
)
st
.
st_
ino
)
return
0
;
s
ig
->
seconds
=
(
git_time_t
)
st
.
st_mtime
;
s
ig
->
size
=
(
git_off_t
)
st
.
st_size
;
s
ig
->
ino
=
(
unsigned
int
)
st
.
st_ino
;
s
tamp
->
mtime
=
(
git_time_t
)
st
.
st_mtime
;
s
tamp
->
size
=
(
git_off_t
)
st
.
st_size
;
s
tamp
->
ino
=
(
unsigned
int
)
st
.
st_ino
;
return
1
;
}
void
git_futils_file_stamp_set
(
git_futils_file_stamp
*
target
,
const
git_futils_file_stamp
*
source
)
{
assert
(
target
);
if
(
source
)
memcpy
(
target
,
source
,
sizeof
(
*
target
));
else
memset
(
target
,
0
,
sizeof
(
*
target
));
}
src/fileops.h
View file @
c8b511f3
...
...
@@ -267,26 +267,44 @@ extern int git_futils_find_system_file(git_buf *path, const char *filename);
*/
extern
int
git_futils_fake_symlink
(
const
char
*
new
,
const
char
*
old
);
/**
* A file stamp represents a snapshot of information about a file that can
* be used to test if the file changes. This portable implementation is
* based on stat data about that file, but it is possible that OS specific
* versions could be implemented in the future.
*/
typedef
struct
{
git_time_t
seconds
;
git_time_t
mtime
;
git_off_t
size
;
unsigned
int
ino
;
}
git_futils_
stat_sig
;
}
git_futils_
file_stamp
;
/**
* Compare stat information for file with reference info.
*
*
Use this as a way to track if a file has changed on disk. This will
*
return GIT_ENOTFOUND if the file doesn't exist, 0 if the file is up-to-date
*
with regards to the signature, and 1 if the file needs to reloaded. When
*
a 1 is returned, the signature will also be updated with the latest data.
*
This function updates the file stamp to current data for the given path
*
and returns 0 if the file is up-to-date relative to the prior setting or
*
1 if the file has been changed. (This also may return GIT_ENOTFOUND if
*
the file doesn't exist.)
*
* @param s
ig stat signature structure
* @param path
path to be statt
ed
* @param s
tamp File stamp to be checked
* @param path
Path to stat and check if chang
ed
* @return 0 if up-to-date, 1 if out-of-date, <0 on error
*/
extern
int
git_futils_stat_sig_needs_reload
(
git_futils_stat_sig
*
sig
,
const
char
*
path
);
extern
int
git_futils_file_stamp_has_changed
(
git_futils_file_stamp
*
stamp
,
const
char
*
path
);
/**
* Set or reset file stamp data
*
* This writes the target file stamp. If the source is NULL, this will set
* the target stamp to values that will definitely be out of date. If the
* source is not NULL, this copies the source values to the target.
*
* @param tgt File stamp to write to
* @param src File stamp to copy from or NULL to clear the target
*/
extern
void
git_futils_file_stamp_set
(
git_futils_file_stamp
*
tgt
,
const
git_futils_file_stamp
*
src
);
#endif
/* INCLUDE_fileops_h__ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment