Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29e673a

Browse files
committed
New commands for outgoing diffs including uncommitted changes
* lisp/vc/vc.el (vc-root-diff-outgoing-base) (vc-diff-outgoing-base): New commands (bug#62940). * lisp/vc/vc-hooks.el (vc-prefix-map): Bind them. * doc/emacs/vc1-xtra.texi (Outgoing Base Diffs): * etc/NEWS: Document them. * doc/emacs/emacs.texi (Outgoing Base Diffs): New node.
1 parent 14d20bf commit 29e673a

File tree

5 files changed

+167
-0
lines changed

5 files changed

+167
-0
lines changed

doc/emacs/emacs.texi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ Miscellaneous Commands and Features of VC
869869
* VC Delete/Rename:: Deleting and renaming version-controlled files.
870870
* Revision Tags:: Symbolic names for revisions.
871871
* Merge Bases:: The most recent revision existing on both branches.
872+
* Outgoing Base Diffs:: Diffs including all outstanding changes on a branch.
872873
* Other Working Trees:: Multiple sets of workfiles.
873874
* Version Headers:: Inserting version control headers into working files.
874875
* Editing VC Commands:: Editing the VC shell commands that Emacs will run.

doc/emacs/vc1-xtra.texi

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* VC Delete/Rename:: Deleting and renaming version-controlled files.
1616
* Revision Tags:: Symbolic names for revisions.
1717
* Merge Bases:: The most recent revision existing on both branches.
18+
* Outgoing Base Diffs:: Diffs including all outstanding changes on a branch.
1819
* Other Working Trees:: Multiple sets of workfiles.
1920
* Version Headers:: Inserting version control headers into working files.
2021
* Editing VC Commands:: Editing the VC shell commands that Emacs will run.
@@ -298,6 +299,90 @@ on the target branch if you were to merge the source branch into it, and
298299
@kbd{C-x v M L} shows you a log of the changes on the source branch not
299300
yet merged into the target branch.
300301

302+
@node Outgoing Base Diffs
303+
@subsubsection Commands for diffs including all outstanding changes
304+
@cindex outstanding changes
305+
306+
@table @kbd
307+
@item C-x v B =
308+
Display diffs of changes to the VC fileset since the merge base of this
309+
branch and its upstream counterpart (@code{vc-diff-outgoing-base}).
310+
311+
@item C-x v B D
312+
Display all changes since the merge base of this branch and its upstream
313+
counterpart (@code{vc-root-diff-outgoing-base}).
314+
@end table
315+
316+
For decentralized version control systems (@pxref{VCS Repositories}),
317+
these commands provide specialized versions of @kbd{C-x v M D} (see
318+
@pxref{Merge Bases}) which also take into account the state of upstream
319+
repositories. These commands are useful both when working on a single
320+
branch and when developing features on a separate branch
321+
(@pxref{Branches}). These two cases involve using the commands
322+
differently, and so we will describe them separately.
323+
324+
First, consider working on a single branch. @dfn{Outstanding changes}
325+
are those which you haven't yet pushed upstream. This includes both
326+
unpushed commits and uncommitted changes in your working tree. In many
327+
cases the reason these changes are not pushed yet is that they are not
328+
finished: the changes committed so far don't make sense in isolation.
329+
330+
@kindex C-x v B =
331+
@findex vc-diff-outgoing-base
332+
@kindex C-x v B D
333+
@findex vc-root-diff-outgoing-base
334+
Type @kbd{C-x v B D} (@code{vc-root-diff-outgoing-base}) to display a
335+
summary of all these changes, committed and uncommitted. This summary
336+
is in the form of a diff of what committing and pushing (@pxref{Pulling
337+
/ Pushing}) all these changes would do to the upstream repository. You
338+
can use @kbd{C-x v B =} (@code{vc-diff-outgoing-base}) instead to limit
339+
the display of changes to the current VC fileset. (The difference
340+
between @w{@kbd{C-x v B D}} and @w{@kbd{C-x v B =}} is like the
341+
difference between @kbd{C-x v D} and @kbd{C-x v =} (@pxref{Old
342+
Revisions}).)@footnote{Another point of comparison is that these
343+
commands are like @w{@kbd{C-x v O =}} (@code{vc-fileset-diff-outgoing})
344+
and @kbd{C-x v O D} (@code{vc-root-diff-outgoing}) except that they
345+
include uncommitted changes in the reported diffs. Like those other
346+
commands, you can use a prefix argument to specify a particular upstream
347+
location.}
348+
349+
Second, consider developing a feature on a separate branch. Call this
350+
the @dfn{feature branch},@footnote{Many version control workflows
351+
involve developing new features on isolated branches. However, the term
352+
``feature branch'' is usually reserved for a particular kind of isolated
353+
branch, one that other branches are repeatedly merged into.
354+
355+
That doesn't matter to this explanation, so we use ``feature branch'' to
356+
refer to the separate branch used for developing the feature even though
357+
whether it is really a feature branch depends on other aspects of the
358+
branching workflow in use.} and call the branch from which the feature
359+
branch was originally created the @dfn{trunk} or @dfn{development
360+
trunk}.
361+
362+
In this case, outstanding changes is a more specific notion than just
363+
unpushed and uncommitted changes on the feature branch. You're not
364+
finished sharing changes with your collaborators until they have been
365+
merged into the trunk, and pushed. Therefore, in this example,
366+
outstanding changes are those which haven't yet been integrated into the
367+
upstream repository's development trunk. That means committed changes
368+
on the feature branch that haven't yet been merged into the trunk, plus
369+
uncommitted changes.
370+
371+
@cindex outgoing base, version control
372+
The @dfn{outgoing base} is the upstream location for which the changes
373+
are destined once they are no longer outstanding. In this case, that's
374+
the upstream version of the trunk, to which you and your collaborators
375+
push finished work.
376+
377+
To display a summary of outgoing changes in this multi-branch example,
378+
supply a prefix argument, by typing @w{@kbd{C-u C-x v B =}} or
379+
@w{@kbd{C-u C-x v B D}}. When prompted, enter the outgoing base.
380+
Exactly what you must supply here depends on the name of your
381+
development trunk and the version control system in use. For example,
382+
with Git, usually you will enter @kbd{origin/master}. We hope to
383+
improve these commands such that no prefix argument is required in the
384+
multi-branch case, too.
385+
301386
@node Other Working Trees
302387
@subsubsection Multiple Working Trees for One Repository
303388

etc/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,14 @@ include were committed and will be pushed.
21732173
'vc-diff-incoming' and 'vc-diff-outgoing' are similar but limited to the
21742174
current VC fileset.
21752175

2176+
+++
2177+
*** New commands to report diffs of outstanding changes.
2178+
'C-x v B =' ('vc-diff-outgoing-base') and 'C-x v B D'
2179+
('vc-root-diff-outgoing-base') report diffs of changes since the merge
2180+
base with the remote branch, including uncommitted changes.
2181+
They are useful to view all outstanding (unmerged, unpushed) changes on
2182+
the current branch.
2183+
21762184
+++
21772185
*** New user option 'vc-use-incoming-outgoing-prefixes'.
21782186
If this is customized to non-nil, 'C-x v I' and 'C-x v O' become prefix

lisp/vc/vc-hooks.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ In the latter case, VC mode is deactivated for this buffer."
952952
"O" #'vc-log-outgoing
953953
"M L" #'vc-log-mergebase
954954
"M D" #'vc-diff-mergebase
955+
"B =" #'vc-diff-outgoing-base
956+
"B D" #'vc-root-diff-outgoing-base
955957
"m" #'vc-merge
956958
"r" #'vc-retrieve-tag
957959
"s" #'vc-create-tag

lisp/vc/vc.el

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,6 +2575,9 @@ When unspecified REMOTE-LOCATION is the place \\[vc-push] would push to.
25752575
When called interactively with a prefix argument, prompt for REMOTE-LOCATION.
25762576
In some version control systems REMOTE-LOCATION can be a remote branch name.
25772577
2578+
This command is like `vc-root-diff-outgoing-base' except that it does
2579+
not include uncommitted changes.
2580+
25782581
See `vc-use-incoming-outgoing-prefixes' regarding giving this command a
25792582
global binding."
25802583
(interactive (list (vc--maybe-read-remote-location)))
@@ -2589,6 +2592,9 @@ When called interactively with a prefix argument, prompt for REMOTE-LOCATION.
25892592
In some version control systems REMOTE-LOCATION can be a remote branch name.
25902593
When called from Lisp optional argument FILESET overrides the VC fileset.
25912594
2595+
This command is like `vc-diff-outgoing-base' except that it does not
2596+
include uncommitted changes.
2597+
25922598
See `vc-use-incoming-outgoing-prefixes' regarding giving this command a
25932599
global binding."
25942600
;; For this command, for distributed VCS, we want to ignore
@@ -2629,6 +2635,71 @@ global binding."
26292635
(car fileset))
26302636
(called-interactively-p 'interactive))))
26312637

2638+
;; For the following two commands, the default meaning for
2639+
;; REMOTE-LOCATION may become dependent on whether we are on a
2640+
;; shorter-lived or longer-lived ("trunk") branch. If we are on the
2641+
;; trunk then it will always be the place `vc-push' would push to. If
2642+
;; we are on a shorter-lived branch, it may instead become the remote
2643+
;; trunk branch from which the shorter-lived branch was branched. That
2644+
;; way you can use these commands to get a summary of all unmerged work
2645+
;; outstanding on the short-lived branch.
2646+
;;
2647+
;; The obstacle to doing this is that VC lacks any distinction between
2648+
;; shorter-lived and trunk branches. But we all work with both of
2649+
;; these, for almost any VCS workflow. E.g. modern workflows which
2650+
;; eschew traditional feature branches still have a long-lived trunk
2651+
;; plus shorter-lived local branches for merge requests or patch series.
2652+
;; --spwhitton
2653+
2654+
;;;###autoload
2655+
(defun vc-root-diff-outgoing-base (&optional remote-location)
2656+
"Report diff of all changes since the merge base with REMOTE-LOCATION.
2657+
The merge base with REMOTE-LOCATION means the common ancestor of the
2658+
working revision and REMOTE-LOCATION.
2659+
Uncommitted changes are included in the diff.
2660+
2661+
When unspecified REMOTE-LOCATION is the place \\[vc-push] would push to.
2662+
This default meaning for REMOTE-LOCATION may change in a future release
2663+
of Emacs.
2664+
2665+
When called interactively with a prefix argument, prompt for
2666+
REMOTE-LOCATION. In some version control systems, REMOTE-LOCATION can
2667+
be a remote branch name.
2668+
2669+
This command is like `vc-root-diff-outgoing' except that it includes
2670+
uncommitted changes."
2671+
(interactive (list (vc--maybe-read-remote-location)))
2672+
(vc--with-backend-in-rootdir "VC root-diff"
2673+
(vc-diff-outgoing-base remote-location `(,backend (,rootdir)))))
2674+
2675+
;;;###autoload
2676+
(defun vc-diff-outgoing-base (&optional remote-location fileset)
2677+
"Report changes to VC fileset since the merge base with REMOTE-LOCATION.
2678+
2679+
The merge base with REMOTE-LOCATION means the common ancestor of the
2680+
working revision and REMOTE-LOCATION.
2681+
Uncommitted changes are included in the diff.
2682+
2683+
When unspecified REMOTE-LOCATION is the place \\[vc-push] would push to.
2684+
This default meaning for REMOTE-LOCATION may change in a future release
2685+
of Emacs.
2686+
2687+
When called interactively with a prefix argument, prompt for
2688+
REMOTE-LOCATION. In some version control systems, REMOTE-LOCATION can
2689+
be a remote branch name.
2690+
2691+
This command is like to `vc-fileset-diff-outgoing' except that it
2692+
includes uncommitted changes."
2693+
(interactive (list (vc--maybe-read-remote-location) nil))
2694+
(let* ((fileset (or fileset (vc-deduce-fileset t)))
2695+
(backend (car fileset))
2696+
(incoming (vc--incoming-revision backend
2697+
(or remote-location ""))))
2698+
(vc-diff-internal vc-allow-async-diff fileset
2699+
(vc-call-backend backend 'mergebase incoming)
2700+
nil
2701+
(called-interactively-p 'interactive))))
2702+
26322703
(declare-function ediff-load-version-control "ediff" (&optional silent))
26332704
(declare-function ediff-vc-internal "ediff-vers"
26342705
(rev1 rev2 &optional startup-hooks))

0 commit comments

Comments
 (0)