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

« back to all changes in this revision

Viewing changes to builtin-update-index.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20070422133105-tkmhz328g2p0epz1
Tags: 1:1.5.1.2-1
* new upstream point release.
* debian/changelog.upstream: upstream changes taken from mailing list
  announcement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
        ce->ce_flags = htons(namelen);
110
110
        fill_stat_cache_info(ce, &st);
111
111
 
112
 
        ce->ce_mode = create_ce_mode(st.st_mode);
113
 
        if (!trust_executable_bit) {
114
 
                /* If there is an existing entry, pick the mode bits
115
 
                 * from it, otherwise assume unexecutable.
 
112
        if (trust_executable_bit && has_symlinks)
 
113
                ce->ce_mode = create_ce_mode(st.st_mode);
 
114
        else {
 
115
                /* If there is an existing entry, pick the mode bits and type
 
116
                 * from it, otherwise assume unexecutable regular file.
116
117
                 */
 
118
                struct cache_entry *ent;
117
119
                int pos = cache_name_pos(path, namelen);
118
 
                if (0 <= pos)
119
 
                        ce->ce_mode = active_cache[pos]->ce_mode;
120
 
                else if (S_ISREG(st.st_mode))
121
 
                        ce->ce_mode = create_ce_mode(S_IFREG | 0666);
 
120
 
 
121
                ent = (0 <= pos) ? active_cache[pos] : NULL;
 
122
                ce->ce_mode = ce_mode_from_stat(ent, st.st_mode);
122
123
        }
123
124
 
124
125
        if (index_path(ce->sha1, path, &st, !info_only))
226
227
                char *path_name;
227
228
                unsigned char sha1[20];
228
229
                unsigned int mode;
 
230
                unsigned long ul;
229
231
                int stage;
230
232
 
231
233
                /* This reads lines formatted in one of three formats:
248
250
                if (buf.eof)
249
251
                        break;
250
252
 
251
 
                mode = strtoul(buf.buf, &ptr, 8);
252
 
                if (ptr == buf.buf || *ptr != ' ')
 
253
                errno = 0;
 
254
                ul = strtoul(buf.buf, &ptr, 8);
 
255
                if (ptr == buf.buf || *ptr != ' '
 
256
                    || errno || (unsigned int) ul != ul)
253
257
                        goto bad_line;
 
258
                mode = ul;
254
259
 
255
260
                tab = strchr(ptr, '\t');
256
261
                if (!tab || tab - ptr < 41)
486
491
        int prefix_length = prefix ? strlen(prefix) : 0;
487
492
        char set_executable_bit = 0;
488
493
        unsigned int refresh_flags = 0;
 
494
        int lock_error = 0;
489
495
        struct lock_file *lock_file;
490
496
 
491
497
        git_config(git_default_config);
493
499
        /* We can't free this memory, it becomes part of a linked list parsed atexit() */
494
500
        lock_file = xcalloc(1, sizeof(struct lock_file));
495
501
 
496
 
        newfd = hold_lock_file_for_update(lock_file, get_index_file(), 1);
 
502
        newfd = hold_lock_file_for_update(lock_file, get_index_file(), 0);
 
503
        if (newfd < 0)
 
504
                lock_error = errno;
497
505
 
498
506
        entries = read_cache();
499
507
        if (entries < 0)
501
509
 
502
510
        for (i = 1 ; i < argc; i++) {
503
511
                const char *path = argv[i];
 
512
                const char *p;
504
513
 
505
514
                if (allow_options && *path == '-') {
506
515
                        if (!strcmp(path, "--")) {
542
551
                                if (i+3 >= argc)
543
552
                                        die("git-update-index: --cacheinfo <mode> <sha1> <path>");
544
553
 
545
 
                                if ((sscanf(argv[i+1], "%o", &mode) != 1) ||
 
554
                                if (strtoul_ui(argv[i+1], 8, &mode) ||
546
555
                                    get_sha1_hex(argv[i+2], sha1) ||
547
556
                                    add_cacheinfo(mode, sha1, argv[i+3], 0))
548
557
                                        die("git-update-index: --cacheinfo"
616
625
                                usage(update_index_usage);
617
626
                        die("unknown option %s", path);
618
627
                }
619
 
                update_one(path, prefix, prefix_length);
 
628
                p = prefix_path(prefix, prefix_length, path);
 
629
                update_one(p, NULL, 0);
620
630
                if (set_executable_bit)
621
 
                        chmod_path(set_executable_bit, path);
 
631
                        chmod_path(set_executable_bit, p);
 
632
                if (p < path || p > path + strlen(path))
 
633
                        free((char*)p);
622
634
        }
623
635
        if (read_from_stdin) {
624
636
                struct strbuf buf;
646
658
 
647
659
 finish:
648
660
        if (active_cache_changed) {
 
661
                if (newfd < 0) {
 
662
                        if (refresh_flags & REFRESH_QUIET)
 
663
                                exit(128);
 
664
                        die("unable to create '%s.lock': %s",
 
665
                            get_index_file(), strerror(lock_error));
 
666
                }
649
667
                if (write_cache(newfd, active_cache, active_nr) ||
650
668
                    close(newfd) || commit_lock_file(lock_file))
651
669
                        die("Unable to write new index file");