Merge branch 'jc/attributes-checkout'
authorJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2009 07:27:33 +0000 (00:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2009 07:27:33 +0000 (00:27 -0700)
* jc/attributes-checkout:
Add a test for checking whether gitattributes is honored by checkout.
Read attributes from the index that is being checked out

1  2 
unpack-trees.c
diff --combined unpack-trees.c
index 86e28650b887b4fcc1b05cc4d3102367df18a9ac,661218c5aee90ac5c4933f3409b0858c3cd10ef0..6847c2d966c5e1d0299b21682d6fef2637329071
@@@ -7,6 -7,7 +7,7 @@@
  #include "unpack-trees.h"
  #include "progress.h"
  #include "refs.h"
+ #include "attr.h"
  
  /*
   * Error messages expected by scripts out of plumbing commands such as
@@@ -49,20 -50,39 +50,20 @@@ static void add_entry(struct unpack_tre
        memcpy(new, ce, size);
        new->next = NULL;
        new->ce_flags = (new->ce_flags & ~clear) | set;
 -      add_index_entry(&o->result, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE|ADD_CACHE_SKIP_DFCHECK);
 +      add_index_entry(&o->result, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
  }
  
 -/* Unlink the last component and attempt to remove leading
 - * directories, in case this unlink is the removal of the
 - * last entry in the directory -- empty directories are removed.
 +/*
 + * Unlink the last component and schedule the leading directories for
 + * removal, such that empty directories get removed.
   */
  static void unlink_entry(struct cache_entry *ce)
  {
 -      char *cp, *prev;
 -      char *name = ce->name;
 -
 -      if (has_symlink_or_noent_leading_path(ce_namelen(ce), ce->name))
 +      if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
                return;
 -      if (unlink(name))
 +      if (unlink(ce->name))
                return;
 -      prev = NULL;
 -      while (1) {
 -              int status;
 -              cp = strrchr(name, '/');
 -              if (prev)
 -                      *prev = '/';
 -              if (!cp)
 -                      break;
 -
 -              *cp = 0;
 -              status = rmdir(name);
 -              if (status) {
 -                      *cp = '/';
 -                      break;
 -              }
 -              prev = cp;
 -      }
 +      schedule_dir_for_removal(ce->name, ce_namelen(ce));
  }
  
  static struct checkout state;
@@@ -86,6 -106,7 +87,7 @@@ static int check_updates(struct unpack_
                cnt = 0;
        }
  
+       git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);
        for (i = 0; i < index->cache_nr; i++) {
                struct cache_entry *ce = index->cache[i];
  
                        display_progress(progress, ++cnt);
                        if (o->update)
                                unlink_entry(ce);
 -                      remove_index_entry_at(&o->result, i);
 -                      i--;
 -                      continue;
                }
        }
 +      remove_marked_cache_entries(&o->result);
 +      remove_scheduled_dirs();
  
        for (i = 0; i < index->cache_nr; i++) {
                struct cache_entry *ce = index->cache[i];
                }
        }
        stop_progress(&progress);
+       git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
        return errs != 0;
  }
  
@@@ -266,9 -289,9 +269,9 @@@ static int unpack_nondirectories(int n
        if (o->merge)
                return call_unpack_fn(src, o);
  
 -      n += o->merge;
        for (i = 0; i < n; i++)
 -              add_entry(o, src[i], 0, 0);
 +              if (src[i] && src[i] != o->df_conflict_entry)
 +                      add_entry(o, src[i], 0, 0);
        return 0;
  }
  
@@@ -360,10 -383,8 +363,10 @@@ int unpack_trees(unsigned len, struct t
  
        memset(&o->result, 0, sizeof(o->result));
        o->result.initialized = 1;
 -      if (o->src_index)
 -              o->result.timestamp = o->src_index->timestamp;
 +      if (o->src_index) {
 +              o->result.timestamp.sec = o->src_index->timestamp.sec;
 +              o->result.timestamp.nsec = o->src_index->timestamp.nsec;
 +      }
        o->merge_size = len;
  
        if (!dfc)
@@@ -428,7 -449,7 +431,7 @@@ static int verify_uptodate(struct cache
  {
        struct stat st;
  
 -      if (o->index_only || o->reset)
 +      if (o->index_only || o->reset || ce_uptodate(ce))
                return 0;
  
        if (!lstat(ce->name, &st)) {
@@@ -565,7 -586,7 +568,7 @@@ static int verify_absent(struct cache_e
        if (o->index_only || o->reset || !o->update)
                return 0;
  
 -      if (has_symlink_or_noent_leading_path(ce_namelen(ce), ce->name))
 +      if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
                return 0;
  
        if (!lstat(ce->name, &st)) {