Make git-mv a builtin
This also moves add_file_to_index() to read-cache.c. Oh, and while touching builtin-add.c, it also removes a duplicate git_config() call. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Jul 26, 2006 at 03:52 UTC
11be42a47632a6f7219d34f5e312aa20ae076142
8 files changed
+269
-295
Makefile
+6
-5
@@ -151,7 +151,7 @@ SCRIPT_PERL = \
151
git-archimport.perl git-cvsimport.perl git-relink.perl \
152
git-shortlog.perl git-rerere.perl \
153
git-annotate.perl git-cvsserver.perl \
154
- git-svnimport.perl git-mv.perl git-cvsexportcommit.perl \
154
+ git-svnimport.perl git-cvsexportcommit.perl \
155
git-send-email.perl git-svn.perl
156
157
SCRIPT_PYTHON = \
@@ -192,7 +192,7 @@ BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
192
git-read-tree$X git-commit-tree$X git-write-tree$X \
193
git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \
194
git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \
195
- git-fmt-merge-msg$X git-prune$X
195
+ git-fmt-merge-msg$X git-prune$X git-mv$X
196
197
# what 'all' will build and 'install' will install, in gitexecdir
198
ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
@@ -221,7 +221,7 @@ LIB_H = \
221
blob.h cache.h commit.h csum-file.h delta.h \
222
diff.h object.h pack.h pkt-line.h quote.h refs.h \
223
run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
224
- tree-walk.h log-tree.h dir.h
224
+ tree-walk.h log-tree.h dir.h path-list.h
225
226
DIFF_OBJS = \
227
diff.o diff-lib.o diffcore-break.o diffcore-order.o \
@@ -236,7 +236,7 @@ LIB_OBJS = \
236
server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
237
tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
238
fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
239
- alloc.o merge-file.o $(DIFF_OBJS)
239
+ alloc.o merge-file.o path-list.o $(DIFF_OBJS)
240
241
BUILTIN_OBJS = \
242
builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
@@ -248,7 +248,8 @@ BUILTIN_OBJS = \
248
builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
249
builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
250
builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \
251
- builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o
251
+ builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \
252
+ builtin-mv.o
253
254
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
255
LIBS = $(GITLIBS) -lz
builtin-add.c
-40
@@ -82,45 +82,6 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
82
prune_directory(dir, pathspec, baselen);
83
}
84
85
-static int add_file_to_index(const char *path, int verbose)
86
-{
87
- int size, namelen;
88
- struct stat st;
89
- struct cache_entry *ce;
90
-
91
- if (lstat(path, &st))
92
- die("%s: unable to stat (%s)", path, strerror(errno));
93
-
94
- if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
95
- die("%s: can only add regular files or symbolic links", path);
96
-
97
- namelen = strlen(path);
98
- size = cache_entry_size(namelen);
99
- ce = xcalloc(1, size);
100
- memcpy(ce->name, path, namelen);
101
- ce->ce_flags = htons(namelen);
102
- fill_stat_cache_info(ce, &st);
103
-
104
- ce->ce_mode = create_ce_mode(st.st_mode);
105
- if (!trust_executable_bit) {
106
- /* If there is an existing entry, pick the mode bits
107
- * from it.
108
- */
109
- int pos = cache_name_pos(path, namelen);
110
- if (pos >= 0)
111
- ce->ce_mode = active_cache[pos]->ce_mode;
112
- }
113
-
114
- if (index_path(ce->sha1, path, &st, 1))
115
- die("unable to index file %s", path);
116
- if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD))
117
- die("unable to add %s to index",path);
118
- if (verbose)
119
- printf("add '%s'\n", path);
120
- cache_tree_invalidate_path(active_cache_tree, path);
121
- return 0;
122
-}
123
-
85
static struct lock_file lock_file;
86
87
int cmd_add(int argc, const char **argv, char **envp)
@@ -159,7 +120,6 @@ int cmd_add(int argc, const char **argv, char **envp)
120
}
121
die(builtin_add_usage);
122
}
162
- git_config(git_default_config);
123
pathspec = get_pathspec(prefix, argv + i);
124
125
fill_directory(&dir, pathspec);
builtin-mv.c
new
+221
@@ -0,0 +1,221 @@
1
+/*
2
+ * "git mv" builtin command
3
+ *
4
+ * Copyright (C) 2006 Johannes Schindelin
5
+ */
6
+#include <fnmatch.h>
7
+
8
+#include "cache.h"
9
+#include "builtin.h"
10
+#include "dir.h"
11
+#include "cache-tree.h"
12
+#include "path-list.h"
13
+
14
+static const char builtin_mv_usage[] =
15
+"git-mv [-n] [-f] (<source> <destination> | [-k] <source>... <destination>)";
16
+
17
+static const char **copy_pathspec(const char *prefix, const char **pathspec,
18
+ int count, int base_name)
19
+{
20
+ const char **result = xmalloc((count + 1) * sizeof(const char *));
21
+ memcpy(result, pathspec, count * sizeof(const char *));
22
+ result[count] = NULL;
23
+ if (base_name) {
24
+ int i;
25
+ for (i = 0; i < count; i++) {
26
+ const char *last_slash = strrchr(result[i], '/');
27
+ if (last_slash)
28
+ result[i] = last_slash + 1;
29
+ }
30
+ }
31
+ return get_pathspec(prefix, result);
32
+}
33
+
34
+static void show_list(const char *label, struct path_list *list)
35
+{
36
+ if (list->nr > 0) {
37
+ int i;
38
+ printf("%s", label);
39
+ for (i = 0; i < list->nr; i++)
40
+ printf("%s%s", i > 0 ? ", " : "", list->items[i].path);
41
+ putchar('\n');
42
+ }
43
+}
44
+
45
+static struct lock_file lock_file;
46
+
47
+int cmd_mv(int argc, const char **argv, char **envp)
48
+{
49
+ int i, newfd, count;
50
+ int verbose = 0, show_only = 0, force = 0, ignore_errors = 0;
51
+ const char *prefix = setup_git_directory();
52
+ const char **source, **destination, **dest_path;
53
+ struct stat st;
54
+ struct path_list overwritten = {NULL, 0, 0, 0};
55
+ struct path_list src_for_dst = {NULL, 0, 0, 0};
56
+ struct path_list added = {NULL, 0, 0, 0};
57
+ struct path_list deleted = {NULL, 0, 0, 0};
58
+ struct path_list changed = {NULL, 0, 0, 0};
59
+
60
+ git_config(git_default_config);
61
+
62
+ newfd = hold_lock_file_for_update(&lock_file, get_index_file());
63
+ if (newfd < 0)
64
+ die("unable to create new index file");
65
+
66
+ if (read_cache() < 0)
67
+ die("index file corrupt");
68
+
69
+ for (i = 1; i < argc; i++) {
70
+ const char *arg = argv[i];
71
+
72
+ if (arg[0] != '-')
73
+ break;
74
+ if (!strcmp(arg, "--")) {
75
+ i++;
76
+ break;
77
+ }
78
+ if (!strcmp(arg, "-n")) {
79
+ show_only = 1;
80
+ continue;
81
+ }
82
+ if (!strcmp(arg, "-f")) {
83
+ force = 1;
84
+ continue;
85
+ }
86
+ if (!strcmp(arg, "-k")) {
87
+ ignore_errors = 1;
88
+ continue;
89
+ }
90
+ die(builtin_mv_usage);
91
+ }
92
+ count = argc - i - 1;
93
+ if (count < 1)
94
+ usage(builtin_mv_usage);
95
+
96
+ source = copy_pathspec(prefix, argv + i, count, 0);
97
+ dest_path = copy_pathspec(prefix, argv + argc - 1, 1, 0);
98
+
99
+ if (!lstat(dest_path[0], &st) && S_ISDIR(st.st_mode))
100
+ destination = copy_pathspec(dest_path[0], argv + i, count, 1);
101
+ else {
102
+ if (count != 1)
103
+ usage(builtin_mv_usage);
104
+ destination = dest_path;
105
+ }
106
+
107
+ /* Checking */
108
+ for (i = 0; i < count; i++) {
109
+ const char *bad = NULL;
110
+
111
+ if (show_only)
112
+ printf("Checking rename of '%s' to '%s'\n",
113
+ source[i], destination[i]);
114
+
115
+ if (lstat(source[i], &st) < 0)
116
+ bad = "bad source";
117
+ else if (lstat(destination[i], &st) == 0) {
118
+ bad = "destination exists";
119
+ if (force) {
120
+ /*
121
+ * only files can overwrite each other:
122
+ * check both source and destination
123
+ */
124
+ if (S_ISREG(st.st_mode)) {
125
+ fprintf(stderr, "Warning: %s;"
126
+ " will overwrite!\n",
127
+ bad);
128
+ bad = NULL;
129
+ path_list_insert(destination[i],
130
+ &overwritten);
131
+ } else
132
+ bad = "Cannot overwrite";
133
+ }
134
+ }
135
+
136
+ if (!bad &&
137
+ !strncmp(destination[i], source[i], strlen(source[i])))
138
+ bad = "can not move directory into itself";
139
+
140
+ if (!bad && cache_name_pos(source[i], strlen(source[i])) < 0)
141
+ bad = "not under version control";
142
+
143
+ if (!bad) {
144
+ if (path_list_has_path(&src_for_dst, destination[i]))
145
+ bad = "multiple sources for the same target";
146
+ else
147
+ path_list_insert(destination[i], &src_for_dst);
148
+ }
149
+
150
+ if (bad) {
151
+ if (ignore_errors) {
152
+ if (--count > 0) {
153
+ memmove(source + i, source + i + 1,
154
+ (count - i) * sizeof(char *));
155
+ memmove(destination + i,
156
+ destination + i + 1,
157
+ (count - i) * sizeof(char *));
158
+ }
159
+ } else
160
+ die ("Error: %s, source=%s, destination=%s",
161
+ bad, source[i], destination[i]);
162
+ }
163
+ }
164
+
165
+ for (i = 0; i < count; i++) {
166
+ if (show_only || verbose)
167
+ printf("Renaming %s to %s\n",
168
+ source[i], destination[i]);
169
+ if (!show_only &&
170
+ rename(source[i], destination[i]) < 0 &&
171
+ !ignore_errors)
172
+ die ("renaming %s failed: %s",
173
+ source[i], strerror(errno));
174
+
175
+ if (cache_name_pos(source[i], strlen(source[i])) >= 0) {
176
+ path_list_insert(source[i], &deleted);
177
+
178
+ /* destination can be a directory with 1 file inside */
179
+ if (path_list_has_path(&overwritten, destination[i]))
180
+ path_list_insert(destination[i], &changed);
181
+ else
182
+ path_list_insert(destination[i], &added);
183
+ } else
184
+ path_list_insert(destination[i], &added);
185
+ }
186
+
187
+ if (show_only) {
188
+ show_list("Changed : ", &changed);
189
+ show_list("Adding : ", &added);
190
+ show_list("Deleting : ", &deleted);
191
+ } else {
192
+ for (i = 0; i < changed.nr; i++) {
193
+ const char *path = changed.items[i].path;
194
+ int i = cache_name_pos(path, strlen(path));
195
+ struct cache_entry *ce = active_cache[i];
196
+
197
+ if (i < 0)
198
+ die ("Huh? Cache entry for %s unknown?", path);
199
+ refresh_cache_entry(ce, 0);
200
+ }
201
+
202
+ for (i = 0; i < added.nr; i++) {
203
+ const char *path = added.items[i].path;
204
+ add_file_to_index(path, verbose);
205
+ }
206
+
207
+ for (i = 0; i < deleted.nr; i++) {
208
+ const char *path = deleted.items[i].path;
209
+ remove_file_from_cache(path);
210
+ }
211
+
212
+ if (active_cache_changed) {
213
+ if (write_cache(newfd, active_cache, active_nr) ||
214
+ close(newfd) ||
215
+ commit_lock_file(&lock_file))
216
+ die("Unable to write new index file");
217
+ }
218
+ }
219
+
220
+ return 0;
221
+}
builtin.h
+1
@@ -52,6 +52,7 @@ extern int cmd_rev_parse(int argc, const char **argv, char **envp);
52
extern int cmd_update_index(int argc, const char **argv, char **envp);
53
extern int cmd_update_ref(int argc, const char **argv, char **envp);
54
extern int cmd_fmt_merge_msg(int argc, const char **argv, char **envp);
55
+extern int cmd_mv(int argc, const char **argv, char **envp);
56
57
extern int cmd_write_tree(int argc, const char **argv, char **envp);
58
extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
cache.h
+1
@@ -154,6 +154,7 @@ extern int add_cache_entry(struct cache_entry *ce, int option);
154
extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
155
extern int remove_cache_entry_at(int pos);
156
extern int remove_file_from_cache(const char *path);
157
+extern int add_file_to_index(const char *path, int verbose);
158
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
159
extern int ce_match_stat(struct cache_entry *ce, struct stat *st, int);
160
extern int ce_modified(struct cache_entry *ce, struct stat *st, int);
git-mv.perl
deleted
-250
@@ -1,250 +0,0 @@
1
-#!/usr/bin/perl
2
-#
3
-# Copyright 2005, Ryan Anderson <ryan@michonline.com>
4
-# Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
5
-#
6
-# This file is licensed under the GPL v2, or a later version
7
-# at the discretion of Linus Torvalds.
8
-
9
-
10
-use warnings;
11
-use strict;
12
-use Getopt::Std;
13
-
14
-sub usage() {
15
- print <<EOT;
16
-$0 [-f] [-n] <source> <destination>
17
-$0 [-f] [-n] [-k] <source> ... <destination directory>
18
-EOT
19
- exit(1);
20
-}
21
-
22
-our ($opt_n, $opt_f, $opt_h, $opt_k, $opt_v);
23
-getopts("hnfkv") || usage;
24
-usage() if $opt_h;
25
-@ARGV >= 1 or usage;
26
-
27
-my $GIT_DIR = `git rev-parse --git-dir`;
28
-exit 1 if $?; # rev-parse would have given "not a git dir" message.
29
-chomp($GIT_DIR);
30
-
31
-my (@srcArgs, @dstArgs, @srcs, @dsts);
32
-my ($src, $dst, $base, $dstDir);
33
-
34
-# remove any trailing slash in arguments
35
-for (@ARGV) { s/\/*$//; }
36
-
37
-my $argCount = scalar @ARGV;
38
-if (-d $ARGV[$argCount-1]) {
39
- $dstDir = $ARGV[$argCount-1];
40
- @srcArgs = @ARGV[0..$argCount-2];
41
-
42
- foreach $src (@srcArgs) {
43
- $base = $src;
44
- $base =~ s/^.*\///;
45
- $dst = "$dstDir/". $base;
46
- push @dstArgs, $dst;
47
- }
48
-}
49
-else {
50
- if ($argCount < 2) {
51
- print "Error: need at least two arguments\n";
52
- exit(1);
53
- }
54
- if ($argCount > 2) {
55
- print "Error: moving to directory '"
56
- . $ARGV[$argCount-1]
57
- . "' not possible; not existing\n";
58
- exit(1);
59
- }
60
- @srcArgs = ($ARGV[0]);
61
- @dstArgs = ($ARGV[1]);
62
- $dstDir = "";
63
-}
64
-
65
-my $subdir_prefix = `git rev-parse --show-prefix`;
66
-chomp($subdir_prefix);
67
-
68
-# run in git base directory, so that git-ls-files lists all revisioned files
69
-chdir "$GIT_DIR/..";
70
-
71
-# normalize paths, needed to compare against versioned files and update-index
72
-# also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
73
-for (@srcArgs, @dstArgs) {
74
- # prepend git prefix as we run from base directory
75
- $_ = $subdir_prefix.$_;
76
- s|^\./||;
77
- s|/\./|/| while (m|/\./|);
78
- s|//+|/|g;
79
- # Also "a/b/../c" ==> "a/c"
80
- 1 while (s,(^|/)[^/]+/\.\./,$1,);
81
-}
82
-
83
-my (@allfiles,@srcfiles,@dstfiles);
84
-my $safesrc;
85
-my (%overwritten, %srcForDst);
86
-
87
-$/ = "\0";
88
-open(F, 'git-ls-files -z |')
89
- or die "Failed to open pipe from git-ls-files: " . $!;
90
-
91
-@allfiles = map { chomp; $_; } <F>;
92
-close(F);
93
-
94
-
95
-my ($i, $bad);
96
-while(scalar @srcArgs > 0) {
97
- $src = shift @srcArgs;
98
- $dst = shift @dstArgs;
99
- $bad = "";
100
-
101
- for ($src, $dst) {
102
- # Be nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
103
- s|^\./||;
104
- s|/\./|/| while (m|/\./|);
105
- s|//+|/|g;
106
- # Also "a/b/../c" ==> "a/c"
107
- 1 while (s,(^|/)[^/]+/\.\./,$1,);
108
- }
109
-
110
- if ($opt_v) {
111
- print "Checking rename of '$src' to '$dst'\n";
112
- }
113
-
114
- unless (-f $src || -l $src || -d $src) {
115
- $bad = "bad source '$src'";
116
- }
117
-
118
- $safesrc = quotemeta($src);
119
- @srcfiles = grep /^$safesrc(\/|$)/, @allfiles;
120
-
121
- $overwritten{$dst} = 0;
122
- if (($bad eq "") && -e $dst) {
123
- $bad = "destination '$dst' already exists";
124
- if ($opt_f) {
125
- # only files can overwrite each other: check both source and destination
126
- if (-f $dst && (scalar @srcfiles == 1)) {
127
- print "Warning: $bad; will overwrite!\n";
128
- $bad = "";
129
- $overwritten{$dst} = 1;
130
- }
131
- else {
132
- $bad = "Can not overwrite '$src' with '$dst'";
133
- }
134
- }
135
- }
136
-
137
- if (($bad eq "") && ($dst =~ /^$safesrc\//)) {
138
- $bad = "can not move directory '$src' into itself";
139
- }
140
-
141
- if ($bad eq "") {
142
- if (scalar @srcfiles == 0) {
143
- $bad = "'$src' not under version control";
144
- }
145
- }
146
-
147
- if ($bad eq "") {
148
- if (defined $srcForDst{$dst}) {
149
- $bad = "can not move '$src' to '$dst'; already target of ";
150
- $bad .= "'".$srcForDst{$dst}."'";
151
- }
152
- else {
153
- $srcForDst{$dst} = $src;
154
- }
155
- }
156
-
157
- if ($bad ne "") {
158
- if ($opt_k) {
159
- print "Warning: $bad; skipping\n";
160
- next;
161
- }
162
- print "Error: $bad\n";
163
- exit(1);
164
- }
165
- push @srcs, $src;
166
- push @dsts, $dst;
167
-}
168
-
169
-# Final pass: rename/move
170
-my (@deletedfiles,@addedfiles,@changedfiles);
171
-$bad = "";
172
-while(scalar @srcs > 0) {
173
- $src = shift @srcs;
174
- $dst = shift @dsts;
175
-
176
- if ($opt_n || $opt_v) { print "Renaming $src to $dst\n"; }
177
- if (!$opt_n) {
178
- if (!rename($src,$dst)) {
179
- $bad = "renaming '$src' failed: $!";
180
- if ($opt_k) {
181
- print "Warning: skipped: $bad\n";
182
- $bad = "";
183
- next;
184
- }
185
- last;
186
- }
187
- }
188
-
189
- $safesrc = quotemeta($src);
190
- @srcfiles = grep /^$safesrc(\/|$)/, @allfiles;
191
- @dstfiles = @srcfiles;
192
- s/^$safesrc(\/|$)/$dst$1/ for @dstfiles;
193
-
194
- push @deletedfiles, @srcfiles;
195
- if (scalar @srcfiles == 1) {
196
- # $dst can be a directory with 1 file inside
197
- if ($overwritten{$dst} ==1) {
198
- push @changedfiles, $dstfiles[0];
199
-
200
- } else {
201
- push @addedfiles, $dstfiles[0];
202
- }
203
- }
204
- else {
205
- push @addedfiles, @dstfiles;
206
- }
207
-}
208
-
209
-if ($opt_n) {
210
- if (@changedfiles) {
211
- print "Changed : ". join(", ", @changedfiles) ."\n";
212
- }
213
- if (@addedfiles) {
214
- print "Adding : ". join(", ", @addedfiles) ."\n";
215
- }
216
- if (@deletedfiles) {
217
- print "Deleting : ". join(", ", @deletedfiles) ."\n";
218
- }
219
-}
220
-else {
221
- if (@changedfiles) {
222
- open(H, "| git-update-index -z --stdin")
223
- or die "git-update-index failed to update changed files with code $!\n";
224
- foreach my $fileName (@changedfiles) {
225
- print H "$fileName\0";
226
- }
227
- close(H);
228
- }
229
- if (@addedfiles) {
230
- open(H, "| git-update-index --add -z --stdin")
231
- or die "git-update-index failed to add new names with code $!\n";
232
- foreach my $fileName (@addedfiles) {
233
- print H "$fileName\0";
234
- }
235
- close(H);
236
- }
237
- if (@deletedfiles) {
238
- open(H, "| git-update-index --remove -z --stdin")
239
- or die "git-update-index failed to remove old names with code $!\n";
240
- foreach my $fileName (@deletedfiles) {
241
- print H "$fileName\0";
242
- }
243
- close(H);
244
- }
245
-}
246
-
247
-if ($bad ne "") {
248
- print "Error: $bad\n";
249
- exit(1);
250
-}
git.c
+1
@@ -202,6 +202,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
202
{ "update-ref", cmd_update_ref },
203
{ "fmt-merge-msg", cmd_fmt_merge_msg },
204
{ "prune", cmd_prune },
205
+ { "mv", cmd_mv },
206
};
207
int i;
208
read-cache.c
+39
@@ -319,6 +319,45 @@ int remove_file_from_cache(const char *path)
319
return 0;
320
}
321
322
+int add_file_to_index(const char *path, int verbose)
323
+{
324
+ int size, namelen;
325
+ struct stat st;
326
+ struct cache_entry *ce;
327
+
328
+ if (lstat(path, &st))
329
+ die("%s: unable to stat (%s)", path, strerror(errno));
330
+
331
+ if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
332
+ die("%s: can only add regular files or symbolic links", path);
333
+
334
+ namelen = strlen(path);
335
+ size = cache_entry_size(namelen);
336
+ ce = xcalloc(1, size);
337
+ memcpy(ce->name, path, namelen);
338
+ ce->ce_flags = htons(namelen);
339
+ fill_stat_cache_info(ce, &st);
340
+
341
+ ce->ce_mode = create_ce_mode(st.st_mode);
342
+ if (!trust_executable_bit) {
343
+ /* If there is an existing entry, pick the mode bits
344
+ * from it.
345
+ */
346
+ int pos = cache_name_pos(path, namelen);
347
+ if (pos >= 0)
348
+ ce->ce_mode = active_cache[pos]->ce_mode;
349
+ }
350
+
351
+ if (index_path(ce->sha1, path, &st, 1))
352
+ die("unable to index file %s", path);
353
+ if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD))
354
+ die("unable to add %s to index",path);
355
+ if (verbose)
356
+ printf("add '%s'\n", path);
357
+ cache_tree_invalidate_path(active_cache_tree, path);
358
+ return 0;
359
+}
360
+
361
int ce_same_name(struct cache_entry *a, struct cache_entry *b)
362
{
363
int len = ce_namelen(a);