From: "Kristian Høgsberg" <krh@redhat.com>
To: git@vger.kernel.org
Cc: "Kristian Høgsberg" <krh@redhat.com>
Subject: [PATCH] Share add_files_to_cache() with builtin-add.c
Date: Fri, 21 Sep 2007 15:01:18 -0400 [thread overview]
Message-ID: <1190401278-2869-2-git-send-email-krh@redhat.com> (raw)
In-Reply-To: <1190401278-2869-1-git-send-email-krh@redhat.com>
This removes the extra copy in builtin-commit.c and uses
the update() function from builtin-add.c.
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---
builtin-add.c | 8 +++---
builtin-commit.c | 65 +++++++++++------------------------------------------
commit.h | 2 +
3 files changed, 20 insertions(+), 55 deletions(-)
diff --git a/builtin-add.c b/builtin-add.c
index 5e30380..966e145 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -107,7 +107,7 @@ static void update_callback(struct diff_queue_struct *q,
}
}
-static void update(int verbose, const char *prefix, const char **files)
+void add_files_to_cache(int verbose, const char *prefix, const char **files)
{
struct rev_info rev;
init_revisions(&rev, prefix);
@@ -116,8 +116,6 @@ static void update(int verbose, const char *prefix, const char **files)
rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = update_callback;
rev.diffopt.format_callback_data = &verbose;
- if (read_cache() < 0)
- die("index file corrupt");
run_diff_files(&rev, 0);
}
@@ -218,7 +216,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
}
if (take_worktree_changes) {
- update(verbose, prefix, argv + i);
+ if (read_cache() < 0)
+ die("index file corrupt");
+ add_files_to_cache(verbose, prefix, argv + i);
goto finish;
}
diff --git a/builtin-commit.c b/builtin-commit.c
index 90f23de..3768b53 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -56,53 +56,6 @@ static struct option commit_options[] = {
{ OPTION_STRING, "template", 't', &template_file },
};
-/* FIXME: Taken from builtin-add, should be shared. */
-
-static void update_callback(struct diff_queue_struct *q,
- struct diff_options *opt, void *cbdata)
-{
- int i, verbose;
-
- verbose = *((int *)cbdata);
- for (i = 0; i < q->nr; i++) {
- struct diff_filepair *p = q->queue[i];
- const char *path = p->one->path;
- switch (p->status) {
- default:
- die("unexpacted diff status %c", p->status);
- case DIFF_STATUS_UNMERGED:
- case DIFF_STATUS_MODIFIED:
- case DIFF_STATUS_TYPE_CHANGED:
- add_file_to_cache(path, verbose);
- break;
- case DIFF_STATUS_DELETED:
- remove_file_from_cache(path);
- if (verbose)
- printf("remove '%s'\n", path);
- break;
- }
- }
-}
-
-static void
-add_files_to_cache(int fd, const char **files, const char *prefix)
-{
- struct rev_info rev;
-
- init_revisions(&rev, "");
- setup_revisions(0, NULL, &rev, NULL);
- rev.prune_data = get_pathspec(prefix, files);
- rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
- rev.diffopt.format_callback = update_callback;
- rev.diffopt.format_callback_data = &verbose;
-
- run_diff_files(&rev, 0);
- refresh_cache(REFRESH_QUIET);
-
- if (write_cache(fd, active_cache, active_nr) || close(fd))
- die("unable to write new index file");
-}
-
static char *
prepare_index(const char **files, const char *prefix)
{
@@ -115,10 +68,16 @@ prepare_index(const char **files, const char *prefix)
die("index file corrupt");
if (all) {
- add_files_to_cache(fd, files, NULL);
+ add_files_to_cache(0, prefix, files);
+ if (write_cache(fd, active_cache, active_nr) || close(fd))
+ die("unable to write new index file");
+
return lock_file.filename;
} else if (also) {
- add_files_to_cache(fd, files, prefix);
+ add_files_to_cache(0, prefix, files);
+ if (write_cache(fd, active_cache, active_nr) || close(fd))
+ die("unable to write new index file");
+
return lock_file.filename;
}
@@ -146,7 +105,9 @@ prepare_index(const char **files, const char *prefix)
*/
/* update the user index file */
- add_files_to_cache(fd, files, prefix);
+ add_files_to_cache(0, prefix, files);
+ if (write_cache(fd, active_cache, active_nr) || close(fd))
+ die("unable to write new index file");
if (!initial_commit) {
tree = parse_tree_indirect(head_sha1);
@@ -160,7 +121,9 @@ prepare_index(const char **files, const char *prefix)
next_index_lock = xmalloc(sizeof(*next_index_lock));
fd = hold_lock_file_for_update(next_index_lock,
git_path("next-index-%d", getpid()), 1);
- add_files_to_cache(fd, files, prefix);
+ add_files_to_cache(0, prefix, files);
+ if (write_cache(fd, active_cache, active_nr) || close(fd))
+ die("unable to write new index file");
return next_index_lock->filename;
}
diff --git a/commit.h b/commit.h
index cc8d890..89caa12 100644
--- a/commit.h
+++ b/commit.h
@@ -130,6 +130,8 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
int in_merge_bases(struct commit *, struct commit **, int);
extern int interactive_add(void);
+extern void add_files_to_cache(int verbose,
+ const char *prefix, const char **files);
extern int rerere(void);
#endif /* COMMIT_H */
--
1.5.2.5
next prev parent reply other threads:[~2007-09-21 19:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-21 19:01 [PATCH] Move option parsing code to parse-options.[ch] Kristian Høgsberg
2007-09-21 19:01 ` Kristian Høgsberg [this message]
2007-09-21 19:44 ` Junio C Hamano
2007-09-24 18:41 ` Kristian Høgsberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1190401278-2869-2-git-send-email-krh@redhat.com \
--to=krh@redhat.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).