From: Elijah Newren <newren@gmail.com>
To: git@vger.kernel.org
Cc: a.krey@gmx.de, Elijah Newren <newren@gmail.com>
Subject: [PATCH 2/3] move index_has_changes() from builtin/am.c to merge.c for reuse
Date: Thu, 21 Dec 2017 11:19:06 -0800 [thread overview]
Message-ID: <20171221191907.4251-2-newren@gmail.com> (raw)
In-Reply-To: <20171221191907.4251-1-newren@gmail.com>
index_has_changes() is a function we want to reuse outside of just am,
making it also available for merge-recursive and merge-ort.
Signed-off-by: Elijah Newren <newren@gmail.com>
---
builtin/am.c | 37 -------------------------------------
cache.h | 9 +++++++++
merge.c | 33 +++++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 37 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index 3d98e52085..a02d5186cb 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1142,43 +1142,6 @@ static void refresh_and_write_cache(void)
die(_("unable to write index file"));
}
-/**
- * Returns 1 if the index differs from HEAD, 0 otherwise. When on an unborn
- * branch, returns 1 if there are entries in the index, 0 otherwise. If an
- * strbuf is provided, the space-separated list of files that differ will be
- * appended to it.
- */
-static int index_has_changes(struct strbuf *sb)
-{
- struct object_id head;
- int i;
-
- if (!get_oid_tree("HEAD", &head)) {
- struct diff_options opt;
-
- diff_setup(&opt);
- opt.flags.exit_with_status = 1;
- if (!sb)
- opt.flags.quick = 1;
- do_diff_cache(&head, &opt);
- diffcore_std(&opt);
- for (i = 0; sb && i < diff_queued_diff.nr; i++) {
- if (i)
- strbuf_addch(sb, ' ');
- strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
- }
- diff_flush(&opt);
- return opt.flags.has_changes != 0;
- } else {
- for (i = 0; sb && i < active_nr; i++) {
- if (i)
- strbuf_addch(sb, ' ');
- strbuf_addstr(sb, active_cache[i]->name);
- }
- return !!active_nr;
- }
-}
-
/**
* Dies with a user-friendly message on how to proceed after resolving the
* problem. This message can be overridden with state->resolvemsg.
diff --git a/cache.h b/cache.h
index a2ec8c0b55..d8b975a571 100644
--- a/cache.h
+++ b/cache.h
@@ -644,6 +644,15 @@ extern int write_locked_index(struct index_state *, struct lock_file *lock, unsi
extern int discard_index(struct index_state *);
extern void move_index_extensions(struct index_state *dst, struct index_state *src);
extern int unmerged_index(const struct index_state *);
+
+/**
+ * Returns 1 if the index differs from HEAD, 0 otherwise. When on an unborn
+ * branch, returns 1 if there are entries in the index, 0 otherwise. If an
+ * strbuf is provided, the space-separated list of files that differ will be
+ * appended to it.
+ */
+extern int index_has_changes(struct strbuf *sb);
+
extern int verify_path(const char *path);
extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
extern int index_dir_exists(struct index_state *istate, const char *name, int namelen);
diff --git a/merge.c b/merge.c
index e5d796c9f2..195b578700 100644
--- a/merge.c
+++ b/merge.c
@@ -1,4 +1,6 @@
#include "cache.h"
+#include "diff.h"
+#include "diffcore.h"
#include "lockfile.h"
#include "commit.h"
#include "run-command.h"
@@ -15,6 +17,37 @@ static const char *merge_argument(struct commit *commit)
return EMPTY_TREE_SHA1_HEX;
}
+int index_has_changes(struct strbuf *sb)
+{
+ struct object_id head;
+ int i;
+
+ if (!get_oid_tree("HEAD", &head)) {
+ struct diff_options opt;
+
+ diff_setup(&opt);
+ opt.flags.exit_with_status = 1;
+ if (!sb)
+ opt.flags.quick = 1;
+ do_diff_cache(&head, &opt);
+ diffcore_std(&opt);
+ for (i = 0; sb && i < diff_queued_diff.nr; i++) {
+ if (i)
+ strbuf_addch(sb, ' ');
+ strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
+ }
+ diff_flush(&opt);
+ return opt.flags.has_changes != 0;
+ } else {
+ for (i = 0; sb && i < active_nr; i++) {
+ if (i)
+ strbuf_addch(sb, ' ');
+ strbuf_addstr(sb, active_cache[i]->name);
+ }
+ return !!active_nr;
+ }
+}
+
int try_merge_command(const char *strategy, size_t xopts_nr,
const char **xopts, struct commit_list *common,
const char *head_arg, struct commit_list *remotes)
--
2.15.1.436.g63a861020b
next prev parent reply other threads:[~2017-12-21 19:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-20 11:43 git merge commits staged files (when two trees are identical) Andreas Krey
2017-12-21 18:50 ` Elijah Newren
2017-12-21 19:19 ` [PATCH 1/3] t6044: recursive can silently incorporate dirty changes in a merge Elijah Newren
2017-12-21 19:19 ` Elijah Newren [this message]
2017-12-21 19:36 ` [PATCH 2/3] move index_has_changes() from builtin/am.c to merge.c for reuse Elijah Newren
2017-12-22 20:46 ` Junio C Hamano
2017-12-23 2:26 ` Elijah Newren
2017-12-21 19:19 ` [PATCH 3/3] merge-recursive: Avoid incorporating uncommitted changes in a merge Elijah Newren
2017-12-22 20:38 ` Junio C Hamano
2018-01-08 20:37 ` Junio C Hamano
2018-01-09 18:19 ` [PATCH] merge-recursive: do not look at the index during recursive merge Junio C Hamano
2018-01-09 18:25 ` Junio C Hamano
2018-01-09 18:27 ` Eric Sunshine
2018-01-09 18:29 ` Elijah Newren
2018-01-09 18:49 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171221191907.4251-2-newren@gmail.com \
--to=newren@gmail.com \
--cc=a.krey@gmx.de \
--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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).