~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to read-cache.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-10-04 08:27:01 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20071004082701-rsd058ontoqz4i30
Tags: 1:1.5.3.4-1
new upstream point release (closes: #445188).

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
#include "cache.h"
8
8
#include "cache-tree.h"
9
9
#include "refs.h"
 
10
#include "dir.h"
10
11
 
11
12
/* Index extensions.
12
13
 *
92
93
 
93
94
        /*
94
95
         * We don't actually require that the .git directory
95
 
         * under DIRLNK directory be a valid git directory. It
 
96
         * under GITLINK directory be a valid git directory. It
96
97
         * might even be missing (in case nobody populated that
97
98
         * sub-project).
98
99
         *
115
116
                        return DATA_CHANGED;
116
117
                break;
117
118
        case S_IFDIR:
118
 
                if (S_ISDIRLNK(ntohl(ce->ce_mode)))
 
119
                if (S_ISGITLINK(ntohl(ce->ce_mode)))
119
120
                        return 0;
120
121
        default:
121
122
                return TYPE_CHANGED;
142
143
                    (has_symlinks || !S_ISREG(st->st_mode)))
143
144
                        changed |= TYPE_CHANGED;
144
145
                break;
145
 
        case S_IFDIRLNK:
 
146
        case S_IFGITLINK:
146
147
                if (!S_ISDIR(st->st_mode))
147
148
                        changed |= TYPE_CHANGED;
148
149
                else if (ce_compare_gitlink(ce))
166
167
                changed |= MTIME_CHANGED;
167
168
        if (ce->ce_ctime.nsec != htonl(st->st_ctim.tv_nsec))
168
169
                changed |= CTIME_CHANGED;
169
 
#endif  
 
170
#endif
170
171
 
171
172
        if (ce->ce_uid != htonl(st->st_uid) ||
172
173
            ce->ce_gid != htonl(st->st_gid))
350
351
        return 0;
351
352
}
352
353
 
 
354
static int compare_name(struct cache_entry *ce, const char *path, int namelen)
 
355
{
 
356
        return namelen != ce_namelen(ce) || memcmp(path, ce->name, namelen);
 
357
}
 
358
 
 
359
static int index_name_pos_also_unmerged(struct index_state *istate,
 
360
        const char *path, int namelen)
 
361
{
 
362
        int pos = index_name_pos(istate, path, namelen);
 
363
        struct cache_entry *ce;
 
364
 
 
365
        if (pos >= 0)
 
366
                return pos;
 
367
 
 
368
        /* maybe unmerged? */
 
369
        pos = -1 - pos;
 
370
        if (pos >= istate->cache_nr ||
 
371
                        compare_name((ce = istate->cache[pos]), path, namelen))
 
372
                return -1;
 
373
 
 
374
        /* order of preference: stage 2, 1, 3 */
 
375
        if (ce_stage(ce) == 1 && pos + 1 < istate->cache_nr &&
 
376
                        ce_stage((ce = istate->cache[pos + 1])) == 2 &&
 
377
                        !compare_name(ce, path, namelen))
 
378
                pos++;
 
379
        return pos;
 
380
}
 
381
 
353
382
int add_file_to_index(struct index_state *istate, const char *path, int verbose)
354
383
{
355
 
        int size, namelen;
 
384
        int size, namelen, pos;
356
385
        struct stat st;
357
386
        struct cache_entry *ce;
358
387
 
380
409
                 * from it, otherwise assume unexecutable regular file.
381
410
                 */
382
411
                struct cache_entry *ent;
383
 
                int pos = index_name_pos(istate, path, namelen);
 
412
                int pos = index_name_pos_also_unmerged(istate, path, namelen);
384
413
 
385
414
                ent = (0 <= pos) ? istate->cache[pos] : NULL;
386
415
                ce->ce_mode = ce_mode_from_stat(ent, st.st_mode);
387
416
        }
388
417
 
 
418
        pos = index_name_pos(istate, ce->name, namelen);
 
419
        if (0 <= pos &&
 
420
            !ce_stage(istate->cache[pos]) &&
 
421
            !ie_modified(istate, istate->cache[pos], &st, 1)) {
 
422
                /* Nothing changed, really */
 
423
                free(ce);
 
424
                return 0;
 
425
        }
 
426
 
389
427
        if (index_path(ce->sha1, path, &st, 1))
390
428
                die("unable to index file %s", path);
391
429
        if (add_index_entry(istate, ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE))
396
434
        return 0;
397
435
}
398
436
 
 
437
struct cache_entry *make_cache_entry(unsigned int mode,
 
438
                const unsigned char *sha1, const char *path, int stage,
 
439
                int refresh)
 
440
{
 
441
        int size, len;
 
442
        struct cache_entry *ce;
 
443
 
 
444
        if (!verify_path(path))
 
445
                return NULL;
 
446
 
 
447
        len = strlen(path);
 
448
        size = cache_entry_size(len);
 
449
        ce = xcalloc(1, size);
 
450
 
 
451
        hashcpy(ce->sha1, sha1);
 
452
        memcpy(ce->name, path, len);
 
453
        ce->ce_flags = create_ce_flags(len, stage);
 
454
        ce->ce_mode = create_ce_mode(mode);
 
455
 
 
456
        if (refresh)
 
457
                return refresh_cache_entry(ce, 0);
 
458
 
 
459
        return ce;
 
460
}
 
461
 
399
462
int ce_same_name(struct cache_entry *a, struct cache_entry *b)
400
463
{
401
464
        int len = ce_namelen(a);
597
660
 * is being added, or we already have path and path/file is being
598
661
 * added.  Either one would result in a nonsense tree that has path
599
662
 * twice when git-write-tree tries to write it out.  Prevent it.
600
 
 * 
 
663
 *
601
664
 * If ok-to-replace is specified, we remove the conflicting entries
602
665
 * from the cache so the caller should recompute the insert position.
603
666
 * When this happens, we return non-zero.
628
691
        return retval + has_dir_name(istate, ce, pos, ok_to_replace);
629
692
}
630
693
 
631
 
int add_index_entry(struct index_state *istate, struct cache_entry *ce, int option)
 
694
static int add_index_entry_with_check(struct index_state *istate, struct cache_entry *ce, int option)
632
695
{
633
696
        int pos;
634
697
        int ok_to_add = option & ADD_CACHE_OK_TO_ADD;
670
733
                pos = index_name_pos(istate, ce->name, ntohs(ce->ce_flags));
671
734
                pos = -pos-1;
672
735
        }
 
736
        return pos + 1;
 
737
}
 
738
 
 
739
int add_index_entry(struct index_state *istate, struct cache_entry *ce, int option)
 
740
{
 
741
        int pos;
 
742
 
 
743
        if (option & ADD_CACHE_JUST_APPEND)
 
744
                pos = istate->cache_nr;
 
745
        else {
 
746
                int ret;
 
747
                ret = add_index_entry_with_check(istate, ce, option);
 
748
                if (ret <= 0)
 
749
                        return ret;
 
750
                pos = ret - 1;
 
751
        }
673
752
 
674
753
        /* Make sure the array is big enough .. */
675
754
        if (istate->cache_nr == istate->cache_alloc) {
680
759
 
681
760
        /* Add it in.. */
682
761
        istate->cache_nr++;
683
 
        if (istate->cache_nr > pos)
 
762
        if (istate->cache_nr > pos + 1)
684
763
                memmove(istate->cache + pos + 1,
685
764
                        istate->cache + pos,
686
765
                        (istate->cache_nr - pos - 1) * sizeof(ce));
745
824
        return updated;
746
825
}
747
826
 
748
 
int refresh_index(struct index_state *istate, unsigned int flags)
 
827
int refresh_index(struct index_state *istate, unsigned int flags, const char **pathspec, char *seen)
749
828
{
750
829
        int i;
751
830
        int has_errors = 0;
771
850
                        continue;
772
851
                }
773
852
 
 
853
                if (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
 
854
                        continue;
 
855
 
774
856
                new = refresh_cache_ent(istate, ce, really, &cache_errno);
775
857
                if (new == ce)
776
858
                        continue;
970
1052
                write_buffer_len = buffered;
971
1053
                len -= partial;
972
1054
                data = (char *) data + partial;
973
 
        }
974
 
        return 0;
 
1055
        }
 
1056
        return 0;
975
1057
}
976
1058
 
977
1059
static int write_index_ext_header(SHA_CTX *context, int fd,
1037
1119
                 * size to zero here, then the object name recorded
1038
1120
                 * in index is the 6-byte file but the cached stat information
1039
1121
                 * becomes zero --- which would then match what we would
1040
 
                 * obtain from the filesystem next time we stat("frotz"). 
 
1122
                 * obtain from the filesystem next time we stat("frotz").
1041
1123
                 *
1042
1124
                 * However, the second update-index, before calling
1043
1125
                 * this function, notices that the cached size is 6