Merge branch 'mk/upload-pack-off-by-one-dead-code-removal'
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Jul 2013 18:24:05 +0000 (11:24 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Jul 2013 18:24:05 +0000 (11:24 -0700)
* mk/upload-pack-off-by-one-dead-code-removal:
upload-pack: remove a piece of dead code

1  2 
shallow.c
diff --combined shallow.c
index cbe2526d8c2b2643957eea2729a16269a7a74fab,04712ac25eaf86ce87ee0dd186149471ba7a2de3..8a9c96d019a1b3df4942f370fe0d312467a36799
+++ b/shallow.c
@@@ -3,16 -3,6 +3,16 @@@
  #include "tag.h"
  
  static int is_shallow = -1;
 +static struct stat shallow_stat;
 +static char *alternate_shallow_file;
 +
 +void set_alternate_shallow_file(const char *path)
 +{
 +      if (is_shallow != -1)
 +              die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file");
 +      free(alternate_shallow_file);
 +      alternate_shallow_file = path ? xstrdup(path) : NULL;
 +}
  
  int register_shallow(const unsigned char *sha1)
  {
@@@ -31,21 -21,12 +31,21 @@@ int is_repository_shallow(void
  {
        FILE *fp;
        char buf[1024];
 +      const char *path = alternate_shallow_file;
  
        if (is_shallow >= 0)
                return is_shallow;
  
 -      fp = fopen(git_path("shallow"), "r");
 -      if (!fp) {
 +      if (!path)
 +              path = git_path("shallow");
 +      /*
 +       * fetch-pack sets '--shallow-file ""' as an indicator that no
 +       * shallow file should be used. We could just open it and it
 +       * will likely fail. But let's do an explicit check instead.
 +       */
 +      if (!*path ||
 +          stat(path, &shallow_stat) ||
 +          (fp = fopen(path, "r")) == NULL) {
                is_shallow = 0;
                return is_shallow;
        }
@@@ -110,39 -91,15 +110,34 @@@ struct commit_list *get_shallow_commits
                                        continue;
                                *pointer = cur_depth;
                        }
-                       if (cur_depth < depth) {
-                               if (p->next)
-                                       add_object_array(&p->item->object,
-                                                       NULL, &stack);
-                               else {
-                                       commit = p->item;
-                                       cur_depth = *(int *)commit->util;
-                               }
-                       } else {
-                               commit_list_insert(p->item, &result);
-                               p->item->object.flags |= shallow_flag;
+                       if (p->next)
+                               add_object_array(&p->item->object,
+                                               NULL, &stack);
+                       else {
+                               commit = p->item;
+                               cur_depth = *(int *)commit->util;
                        }
                }
        }
  
        return result;
  }
 +
 +void check_shallow_file_for_update(void)
 +{
 +      struct stat st;
 +
 +      if (!is_shallow)
 +              return;
 +      else if (is_shallow == -1)
 +              die("BUG: shallow must be initialized by now");
 +
 +      if (stat(git_path("shallow"), &st))
 +              die("shallow file was removed during fetch");
 +      else if (st.st_mtime != shallow_stat.st_mtime
 +#ifdef USE_NSEC
 +               || ST_MTIME_NSEC(st) != ST_MTIME_NSEC(shallow_stat)
 +#endif
 +                 )
 +              die("shallow file was changed during fetch");
 +}