From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>
Subject: [PATCH 1/4] remote, revision: factor out exclusive counting between two commits
Date: Wed, 8 Nov 2017 11:55:06 -0800 [thread overview]
Message-ID: <20171108195509.7839-2-sbeller@google.com> (raw)
In-Reply-To: <20171108195509.7839-1-sbeller@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
remote.c | 40 +---------------------------------------
revision.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
revision.h | 7 +++++++
3 files changed, 53 insertions(+), 39 deletions(-)
diff --git a/remote.c b/remote.c
index 685e776a65..60c689383a 100644
--- a/remote.c
+++ b/remote.c
@@ -1990,9 +1990,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
{
struct object_id oid;
struct commit *ours, *theirs;
- struct rev_info revs;
const char *base;
- struct argv_array argv = ARGV_ARRAY_INIT;
/* Cannot stat unless we are marked to build on top of somebody else. */
base = branch_get_upstream(branch, NULL);
@@ -2014,43 +2012,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
if (!ours)
return -1;
- /* are we the same? */
- if (theirs == ours) {
- *num_theirs = *num_ours = 0;
- return 0;
- }
-
- /* Run "rev-list --left-right ours...theirs" internally... */
- argv_array_push(&argv, ""); /* ignored */
- argv_array_push(&argv, "--left-right");
- argv_array_pushf(&argv, "%s...%s",
- oid_to_hex(&ours->object.oid),
- oid_to_hex(&theirs->object.oid));
- argv_array_push(&argv, "--");
-
- init_revisions(&revs, NULL);
- setup_revisions(argv.argc, argv.argv, &revs, NULL);
- if (prepare_revision_walk(&revs))
- die("revision walk setup failed");
-
- /* ... and count the commits on each side. */
- *num_ours = 0;
- *num_theirs = 0;
- while (1) {
- struct commit *c = get_revision(&revs);
- if (!c)
- break;
- if (c->object.flags & SYMMETRIC_LEFT)
- (*num_ours)++;
- else
- (*num_theirs)++;
- }
-
- /* clear object flags smudged by the above traversal */
- clear_commit_marks(ours, ALL_REV_FLAGS);
- clear_commit_marks(theirs, ALL_REV_FLAGS);
-
- argv_array_clear(&argv);
+ compare_commits(ours, theirs, num_ours, num_theirs);
return 0;
}
diff --git a/revision.c b/revision.c
index 99c95c19b0..fe1faf2628 100644
--- a/revision.c
+++ b/revision.c
@@ -1159,6 +1159,51 @@ int ref_excluded(struct string_list *ref_excludes, const char *path)
return 0;
}
+void compare_commits(struct commit *ours, struct commit *theirs,
+ int *num_ours, int *num_theirs)
+{
+ struct rev_info revs;
+ struct argv_array argv = ARGV_ARRAY_INIT;
+
+ /* are we the same? */
+ if (theirs == ours) {
+ *num_theirs = *num_ours = 0;
+ return;
+ }
+
+ /* Run "rev-list --left-right ours...theirs" internally... */
+ argv_array_push(&argv, ""); /* ignored */
+ argv_array_push(&argv, "--left-right");
+ argv_array_pushf(&argv, "%s...%s",
+ oid_to_hex(&ours->object.oid),
+ oid_to_hex(&theirs->object.oid));
+ argv_array_push(&argv, "--");
+
+ init_revisions(&revs, NULL);
+ setup_revisions(argv.argc, argv.argv, &revs, NULL);
+ if (prepare_revision_walk(&revs))
+ die("revision walk setup failed");
+
+ /* ... and count the commits on each side. */
+ *num_ours = 0;
+ *num_theirs = 0;
+ while (1) {
+ struct commit *c = get_revision(&revs);
+ if (!c)
+ break;
+ if (c->object.flags & SYMMETRIC_LEFT)
+ (*num_ours)++;
+ else
+ (*num_theirs)++;
+ }
+
+ /* clear object flags smudged by the above traversal */
+ clear_commit_marks(ours, ALL_REV_FLAGS);
+ clear_commit_marks(theirs, ALL_REV_FLAGS);
+
+ argv_array_clear(&argv);
+}
+
static int handle_one_ref(const char *path, const struct object_id *oid,
int flag, void *cb_data)
{
diff --git a/revision.h b/revision.h
index 54761200ad..3ff6a5190b 100644
--- a/revision.h
+++ b/revision.h
@@ -324,4 +324,11 @@ extern int rewrite_parents(struct rev_info *revs, struct commit *commit,
*/
extern struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
+/*
+ * Compute the number of commits between 'one' and 'two' storing the number
+ * of commits in their parent DAG ncluded in each but not the other.
+ */
+extern void compare_commits(struct commit *one, struct commit *two,
+ int *num_one, int *num_two);
+
#endif
--
2.15.0.128.g40905b34bf.dirty
next prev parent reply other threads:[~2017-11-08 19:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-08 19:55 [RFC PATCH 0/4] git-status reports relation to superproject Stefan Beller
2017-11-08 19:55 ` Stefan Beller [this message]
2017-11-08 19:55 ` [PATCH 2/4] submodule.c: factor start_ls_files_dot_dot out of get_superproject_working_tree Stefan Beller
2017-11-08 19:55 ` [PATCH 3/4] submodule.c: get superprojects gitlink value Stefan Beller
2017-11-08 19:55 ` [PATCH 4/4] git-status: report reference to superproject Stefan Beller
2017-11-08 22:36 ` [RFC PATCH 0/4] git-status reports relation " Jonathan Tan
2017-11-09 0:10 ` [RFD] Long term plan with submodule refs? Stefan Beller
2017-11-09 1:29 ` Jonathan Tan
2017-11-09 5:47 ` Junio C Hamano
2017-11-09 5:08 ` Junio C Hamano
2017-11-09 19:57 ` Stefan Beller
2017-11-09 6:54 ` Jacob Keller
2017-11-09 20:16 ` Stefan Beller
2017-11-10 3:37 ` Jacob Keller
2017-11-10 20:01 ` Stefan Beller
2017-11-11 5:25 ` Jacob Keller
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=20171108195509.7839-2-sbeller@google.com \
--to=sbeller@google.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.
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).