]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/loose-object-fsck'
authorJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2017 21:14:57 +0000 (13:14 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 Jan 2017 21:14:57 +0000 (13:14 -0800)
"git fsck" inspects loose objects more carefully now.

* jk/loose-object-fsck:
  fsck: detect trailing garbage in all object types
  fsck: parse loose object paths directly
  sha1_file: add read_loose_object() function
  t1450: test fsck of packed objects
  sha1_file: fix error message for alternate objects
  t1450: refactor loose-object removal

1  2 
cache.h
sha1_file.c

diff --cc cache.h
Simple merge
diff --cc sha1_file.c
index b5e827ac9e716db9fad69960058f1bf2fa50c9d3,b2c66480852c458f79f794a47de7d76c854097a0..c40ef7111c7f1ce3dfc4478a37512111acf96d90
@@@ -1603,34 -1586,43 +1603,43 @@@ int check_sha1_signature(const unsigne
        return hashcmp(sha1, real_sha1) ? -1 : 0;
  }
  
 -int git_open(const char *name)
 +int git_open_cloexec(const char *name, int flags)
  {
 -      static int sha1_file_open_flag = O_NOATIME | O_CLOEXEC;
 -
 -      for (;;) {
 -              int fd;
 -
 -              errno = 0;
 -              fd = open(name, O_RDONLY | sha1_file_open_flag);
 -              if (fd >= 0)
 -                      return fd;
 +      int fd;
 +      static int o_cloexec = O_CLOEXEC;
  
 +      fd = open(name, flags | o_cloexec);
 +      if ((o_cloexec & O_CLOEXEC) && fd < 0 && errno == EINVAL) {
                /* Try again w/o O_CLOEXEC: the kernel might not support it */
 -              if ((sha1_file_open_flag & O_CLOEXEC) && errno == EINVAL) {
 -                      sha1_file_open_flag &= ~O_CLOEXEC;
 -                      continue;
 -              }
 +              o_cloexec &= ~O_CLOEXEC;
 +              fd = open(name, flags | o_cloexec);
 +      }
  
 -              /* Might the failure be due to O_NOATIME? */
 -              if (errno != ENOENT && (sha1_file_open_flag & O_NOATIME)) {
 -                      sha1_file_open_flag &= ~O_NOATIME;
 -                      continue;
 +#if defined(F_GETFL) && defined(F_SETFL) && defined(FD_CLOEXEC)
 +      {
 +              static int fd_cloexec = FD_CLOEXEC;
 +
 +              if (!o_cloexec && 0 <= fd && fd_cloexec) {
 +                      /* Opened w/o O_CLOEXEC?  try with fcntl(2) to add it */
 +                      int flags = fcntl(fd, F_GETFL);
 +                      if (fcntl(fd, F_SETFL, flags | fd_cloexec))
 +                              fd_cloexec = 0;
                }
 -              return -1;
        }
 +#endif
 +      return fd;
  }
  
- static int stat_sha1_file(const unsigned char *sha1, struct stat *st)
+ /*
+  * Find "sha1" as a loose object in the local repository or in an alternate.
+  * Returns 0 on success, negative on failure.
+  *
+  * The "path" out-parameter will give the path of the object we found (if any).
+  * Note that it may point to static storage and is only valid until another
+  * call to sha1_file_name(), etc.
+  */
+ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
+                         const char **path)
  {
        struct alternate_object_database *alt;