chiark / gitweb /
Seamlessly allow diffs "from" the current working directory
authorChuck Lever <cel@netapp.com>
Tue, 15 Nov 2005 22:58:47 +0000 (17:58 -0500)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 17 Nov 2005 10:25:57 +0000 (10:25 +0000)
Sometimes I get a big patch B (say it applies to a tree T) that I
want to split up into smaller patches P_1,...,P_n.  Say I've written
patches P_1 and P_2 so far. I'd like a quick way to generate a diff
between T + P_1 + P_2 and T + B, to see what's left to be done.

Currently I use a dirty trick that depends on editing backup files
directly.  If stg already stores trees with the results of applying the
currently unapplied patches, then a way to diff my working tree with one
of those would do the job.

OK, I wrote the above and then discovered:
stg diff -r patchname/top

Does what I want, except reversed.  OK, so stg diff is nifty.  I could
do it with the following patch that changes the empty string to refer to
the current working directory instead of the top of the last applied
patch.  Then

stg diff -r :patchname/top

gives what I want.  Since "/" is already available to refer to the top
of the last applied patch, it makes more sense to me to allow "" for the
current working directory anyway.

IE, there's no way to explicitly refer to the current working directory.
So the only way to get diffs with the current working directory is with a
-r argument that has no colon or trailing slash, in which case you get a
diff *to* the current working directory.

So my proposal gives you an explicit way to refer to the cwd--the empty
string, "".  That seems like a fairly symmetric way to do things, and it
takes advantage of the unused syntax ":patchname" which currently just
gives an error.

Signed-off-by: J. Bruce Fields <bfields@fieldses.org>
Signed-off-by: Chuck Lever <cel@netapp.com>
stgit/commands/diff.py
stgit/git.py

index 6a730ee4f4041482969f1d046ee86fe63ac03d3e..5645eca4ad892049f754f88890e8e9d20387371c 100644 (file)
@@ -64,8 +64,6 @@ def func(parser, options, args):
         elif rev_list_len == 2:
             rev1 = rev_list[0]
             rev2 = rev_list[1]
-            if rev2 == '':
-                rev2 = 'HEAD'
         else:
             parser.error('incorrect parameters to -r')
     else:
index 066a8f055409fe6460c6bd92f77eb83ac4561264..abdd2fc4e0fb996907df4c078b53b8874d903f66 100644 (file)
@@ -519,11 +519,16 @@ def diff(files = None, rev1 = 'HEAD', rev2 = None, out_fd = None):
     if not files:
         files = []
 
-    if rev2:
+    if rev1 and rev2:
         diff_str = _output(['git-diff-tree', '-p', rev1, rev2] + files)
-    else:
+    elif rev1 or rev2:
         refresh_index()
-        diff_str = _output(['git-diff-index', '-p', rev1] + files)
+        if rev2:
+            diff_str = _output(['git-diff-index', '-p', '-R', rev2] + files)
+        else:
+            diff_str = _output(['git-diff-index', '-p', rev1] + files)
+    else:
+        diff_str = ''
 
     if out_fd:
         out_fd.write(diff_str)