Merge branch 'js/maint-graft-unhide-true-parents'
authorJunio C Hamano <gitster@pobox.com>
Sat, 25 Jul 2009 07:45:03 +0000 (00:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 25 Jul 2009 07:45:03 +0000 (00:45 -0700)
* js/maint-graft-unhide-true-parents:
git repack: keep commits hidden by a graft
Add a test showing that 'git repack' throws away grafted-away parents

Conflicts:
git-repack.sh

1  2 
builtin-pack-objects.c
cache.h
commit.c
environment.c
git-repack.sh
diff --combined builtin-pack-objects.c
index a27c2f6277cd55951cec5d9b5b207df426ed9ff0,527638168bec1a25bf89ab13771b9541b1504713..ef4bf6bc14aadffcd85999c2eca59e5a0e7e6451
@@@ -536,9 -536,11 +536,9 @@@ static void write_pack_file(void
                                 base_name, sha1_to_hex(sha1));
                        free_pack_by_name(tmpname);
                        if (adjust_perm(pack_tmp_name, mode))
 -                              die("unable to make temporary pack file readable: %s",
 -                                  strerror(errno));
 +                              die_errno("unable to make temporary pack file readable");
                        if (rename(pack_tmp_name, tmpname))
 -                              die("unable to rename temporary pack file: %s",
 -                                  strerror(errno));
 +                              die_errno("unable to rename temporary pack file");
  
                        /*
                         * Packs are runtime accessed in their mtime
                        snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
                                 base_name, sha1_to_hex(sha1));
                        if (adjust_perm(idx_tmp_name, mode))
 -                              die("unable to make temporary index file readable: %s",
 -                                  strerror(errno));
 +                              die_errno("unable to make temporary index file readable");
                        if (rename(idx_tmp_name, tmpname))
 -                              die("unable to rename temporary index file: %s",
 -                                  strerror(errno));
 +                              die_errno("unable to rename temporary index file");
  
                        free(idx_tmp_name);
                        free(pack_tmp_name);
@@@ -1875,7 -1879,7 +1875,7 @@@ static void read_object_list_from_stdin
                        if (!ferror(stdin))
                                die("fgets returned NULL, not EOF, not error!");
                        if (errno != EINTR)
 -                              die("fgets: %s", strerror(errno));
 +                              die_errno("fgets");
                        clearerr(stdin);
                        continue;
                }
@@@ -2255,6 -2259,10 +2255,10 @@@ int cmd_pack_objects(int argc, const ch
                                die("bad %s", arg);
                        continue;
                }
+               if (!strcmp(arg, "--keep-true-parents")) {
+                       grafts_replace_parents = 0;
+                       continue;
+               }
                usage(pack_usage);
        }
  
diff --combined cache.h
index c72f125bd4ccd8f5fe38c21a57ac611115519b0a,e902008297007f1f212af8773be1fbda2bb25156..e6c7f3307d09e592aa5bcc63fe6d372aa54a5da3
+++ b/cache.h
@@@ -543,6 -543,7 +543,6 @@@ enum rebase_setup_type 
  };
  
  enum push_default_type {
 -      PUSH_DEFAULT_UNSPECIFIED = -1,
        PUSH_DEFAULT_NOTHING = 0,
        PUSH_DEFAULT_MATCHING,
        PUSH_DEFAULT_TRACKING,
@@@ -560,6 -561,8 +560,8 @@@ enum object_creation_mode 
  
  extern enum object_creation_mode object_creation_mode;
  
+ extern int grafts_replace_parents;
  #define GIT_REPO_VERSION 0
  extern int repository_format_version;
  extern int check_repository_format(void);
@@@ -613,8 -616,6 +615,8 @@@ extern int is_empty_blob_sha1(const uns
  
  int git_mkstemp(char *path, size_t n, const char *template);
  
 +int git_mkstemps(char *path, size_t n, const char *template, int suffix_len);
 +
  /*
   * NOTE NOTE NOTE!!
   *
@@@ -743,17 -744,7 +745,17 @@@ struct checkout 
  };
  
  extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
 +
 +struct cache_def {
 +      char path[PATH_MAX + 1];
 +      int len;
 +      int flags;
 +      int track_flags;
 +      int prefix_len_stat_func;
 +};
 +
  extern int has_symlink_leading_path(const char *name, int len);
 +extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
  extern int has_symlink_or_noent_leading_path(const char *name, int len);
  extern int has_dirs_only_path(const char *name, int len, int prefix_len);
  extern void invalidate_lstat_cache(const char *name, int len);
diff --combined commit.c
index a47fb4da271beaf5595b6bbbe41f94bad08f404d,f69525a089de906f76046952824f5ba5c73f3537..e2bcbe814936989e7a86018e46ed6ca86f4c1f10
+++ b/commit.c
@@@ -50,6 -50,7 +50,6 @@@ struct commit *lookup_commit(const unsi
  
  static unsigned long parse_commit_date(const char *buf, const char *tail)
  {
 -      unsigned long date;
        const char *dateptr;
  
        if (buf + 6 >= tail)
        if (buf >= tail)
                return 0;
        /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
 -      date = strtoul(dateptr, NULL, 10);
 -      if (date == ULONG_MAX)
 -              date = 0;
 -      return date;
 +      return strtoul(dateptr, NULL, 10);
  }
  
  static struct commit_graft **commit_graft;
@@@ -262,7 -266,11 +262,11 @@@ int parse_commit_buffer(struct commit *
                    bufptr[47] != '\n')
                        return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
                bufptr += 48;
-               if (graft)
+               /*
+                * The clone is shallow if nr_parent < 0, and we must
+                * not traverse its real parents even when we unhide them.
+                */
+               if (graft && (graft->nr_parent < 0 || grafts_replace_parents))
                        continue;
                new_parent = lookup_commit(parent);
                if (new_parent)
diff --combined environment.c
index 720f26b67d8a7267dbde51a7285bd09d947ac20d,477d2e4da852356df21dadc47a82f106f8320a52..8f5eaa7dd89cbedd5a89e11f0ea24b29701b33c9
@@@ -42,11 -42,12 +42,12 @@@ enum safe_crlf safe_crlf = SAFE_CRLF_WA
  unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
  enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
  enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
 -enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
 +enum push_default_type push_default = PUSH_DEFAULT_MATCHING;
  #ifndef OBJECT_CREATION_MODE
  #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
  #endif
  enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
+ int grafts_replace_parents = 1;
  
  /* Parallel index stat data preload? */
  int core_preload_index = 0;
diff --combined git-repack.sh
index 1bf239499c7bdb04622ea6fa239bd7c0ace42065,be0c8435dccabd686ec07808c67f5cf569209ee2..1eb3bca352f38ec3807383cc5fff7f7e62731b2b
@@@ -24,7 -24,7 +24,7 @@@ SUBDIRECTORY_OK='Yes
  . git-sh-setup
  
  no_update_info= all_into_one= remove_redundant= unpack_unreachable=
 -local= quiet= no_reuse= extra=
 +local= no_reuse= extra=
  while test $# != 0
  do
        case "$1" in
@@@ -33,7 -33,7 +33,7 @@@
        -A)     all_into_one=t
                unpack_unreachable=--unpack-unreachable ;;
        -d)     remove_redundant=t ;;
 -      -q)     quiet=-q ;;
 +      -q)     GIT_QUIET=t ;;
        -f)     no_reuse=--no-reuse-object ;;
        -l)     local=--local ;;
        --max-pack-size|--window|--window-memory|--depth)
@@@ -80,11 -80,13 +80,11 @@@ case ",$all_into_one," i
        ;;
  esac
  
 -args="$args $local $quiet $no_reuse$extra"
 +args="$args $local ${GIT_QUIET:+-q} $no_reuse$extra"
- names=$(git pack-objects --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
+ names=$(git pack-objects --keep-true-parents --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
        exit 1
  if [ -z "$names" ]; then
 -      if test -z "$quiet"; then
 -              echo Nothing new to pack.
 -      fi
 +      say Nothing new to pack.
  fi
  
  # Ok we have prepared all new packfiles.
@@@ -174,7 -176,7 +174,7 @@@ the
                  done
                )
        fi
 -      git prune-packed $quiet
 +      git prune-packed ${GIT_QUIET:+-q}
  fi
  
  case "$no_update_info" in