-
-
Notifications
You must be signed in to change notification settings - Fork 603
Description
We occasionally have users who want to know "how far ahead a branch is" which is kind of a tricky question. In the case of comparing two branches, you can do the following if you you know that "dev" is always strictly ahead of "main"
> select count(*) from dolt_log('main..dev')But this falls apart if main has progressed, and they have divergent histories. In that situation, the question is more specifically "how divergent are these two branches", and that is really best described in relation to their merge base. Something like this:
> SELECT dolt_merge_base('main','dev') INTO @base;
> SET @log_range_a = CONCAT(@base, '..main');
> SET @log_range_b = CONCAT(@base, '..dev');
> SELECT
'main' AS branch,
(SELECT COUNT(*) FROM dolt_log(@log_range_a)) AS commits_ahead
UNION ALL
SELECT
'dev' AS branch,
(SELECT COUNT(*) FROM dolt_log(@log_range_b)) AS commits_ahead;
+--------+---------------+
| branch | commits_ahead |
+--------+---------------+
| main | 3 |
| dev | 2 |
+--------+---------------+
2 rows in set (0.00 sec)Which is a pain.
Feature Request: Add a new SQL function which takes any number of inputs which should be commitish, find the common merge base for all those changes, and then output a table which indicates how far ahead of the merge base they are.
Eg:
> select * from dolt_divergence('main', 'dev', 'dev2');
+--------+---------------+
| branch | commits_ahead |
+--------+---------------+
| main | 0 |
| dev | 2 |
| dev2 | 42 |
+--------+---------------+
2 rows in set (0.00 sec)main having a value of 0 indicates that it is the merge base. There won't always be a 0 value. If all values are 0 it means that they are all on the same commit.
Also, I don't know what the name should be for this function. implementor's choice!