From fcc1ad70be5ff89996358b6d770cd229fec2a3ba Mon Sep 17 00:00:00 2001 From: Chuck Lever Date: Tue, 15 Nov 2005 17:58:47 -0500 Subject: [PATCH] Seamlessly allow diffs "from" the current working directory 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 Signed-off-by: Chuck Lever --- stgit/commands/diff.py | 2 -- stgit/git.py | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stgit/commands/diff.py b/stgit/commands/diff.py index 6a730ee..5645eca 100644 --- a/stgit/commands/diff.py +++ b/stgit/commands/diff.py @@ -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: diff --git a/stgit/git.py b/stgit/git.py index 066a8f0..abdd2fc 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -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) -- 2.11.0