From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH 5/5] Let the caller supply the diff text to diffstat()
Date: Tue, 29 Jan 2008 04:06:35 +0100 [thread overview]
Message-ID: <20080129030503.926.71863.stgit@yoghurt> (raw)
In-Reply-To: <20080129030059.926.29897.stgit@yoghurt>
Almost all diffstat() callers already have the diff text, so they
might as well pass it to diffstat() instead of letting it recompute
it. In some cases this even makes for a code simplification since the
diff (and thus diffstat) parameters were nontrivial.
Also, diffstat() wasn't as versatile as diff(); for example, it didn't
accept any extra diff options. This patch solves all of those problems
as a side-effect.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
I wanted this for the "stg edit" rewrite. It took some time before I
saw the TODO comment describing exactly the change I was in the
process of making!
stgit/commands/diff.py | 9 ++++-----
stgit/commands/edit.py | 2 +-
stgit/commands/export.py | 10 +++++-----
stgit/commands/files.py | 2 +-
stgit/commands/mail.py | 16 +++++++---------
stgit/git.py | 9 +++------
6 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/stgit/commands/diff.py b/stgit/commands/diff.py
index 7c213d1..fd6be34 100644
--- a/stgit/commands/diff.py
+++ b/stgit/commands/diff.py
@@ -81,12 +81,11 @@ def func(parser, options, args):
rev1 = 'HEAD'
rev2 = None
+ diff_str = git.diff(args, git_id(crt_series, rev1),
+ git_id(crt_series, rev2),
+ diff_flags = options.diff_flags)
if options.stat:
- out.stdout_raw(git.diffstat(args, git_id(crt_series, rev1),
- git_id(crt_series, rev2)) + '\n')
+ out.stdout_raw(git.diffstat(diff_str) + '\n')
else:
- diff_str = git.diff(args, git_id(crt_series, rev1),
- git_id(crt_series, rev2),
- diff_flags = options.diff_flags)
if diff_str:
pager(diff_str)
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index da67275..9915e49 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -154,9 +154,9 @@ def __generate_file(pname, write_fn, options):
'%(diffstat)s\n' \
'%(diff)s'
- tmpl_dict['diffstat'] = git.diffstat(rev1 = bottom, rev2 = top)
tmpl_dict['diff'] = git.diff(rev1 = bottom, rev2 = top,
diff_flags = options.diff_flags)
+ tmpl_dict['diffstat'] = git.diffstat(tmpl_dict['diff'])
for key in tmpl_dict:
# make empty strings if key is not available
diff --git a/stgit/commands/export.py b/stgit/commands/export.py
index 16c64ba..50f6f67 100644
--- a/stgit/commands/export.py
+++ b/stgit/commands/export.py
@@ -138,11 +138,13 @@ def func(parser, options, args):
long_descr = reduce(lambda x, y: x + '\n' + y,
descr_lines[1:], '').strip()
+ diff = git.diff(rev1 = patch.get_bottom(),
+ rev2 = patch.get_top(),
+ diff_flags = options.diff_flags)
tmpl_dict = {'description': patch.get_description().rstrip(),
'shortdescr': short_descr,
'longdescr': long_descr,
- 'diffstat': git.diffstat(rev1 = patch.get_bottom(),
- rev2 = patch.get_top()),
+ 'diffstat': git.diffstat(diff),
'authname': patch.get_authname(),
'authemail': patch.get_authemail(),
'authdate': patch.get_authdate(),
@@ -172,9 +174,7 @@ def func(parser, options, args):
print '-'*79
f.write(descr)
- f.write(git.diff(rev1 = patch.get_bottom(),
- rev2 = patch.get_top(),
- diff_flags = options.diff_flags))
+ f.write(diff)
if not options.stdout:
f.close()
patch_no += 1
diff --git a/stgit/commands/files.py b/stgit/commands/files.py
index ab1f6a3..b43b12f 100644
--- a/stgit/commands/files.py
+++ b/stgit/commands/files.py
@@ -60,7 +60,7 @@ def func(parser, options, args):
rev2 = git_id(crt_series, '%s//top' % patch)
if options.stat:
- out.stdout_raw(git.diffstat(rev1 = rev1, rev2 = rev2) + '\n')
+ out.stdout_raw(git.diffstat(git.diff(rev1 = rev1, rev2 = rev2)) + '\n')
elif options.bare:
out.stdout_raw(git.barefiles(rev1, rev2) + '\n')
else:
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index 4aa16fb..7d19eca 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -360,9 +360,9 @@ def __build_cover(tmpl, patches, msg_id, options):
'number': number_str,
'shortlog': stack.shortlog(crt_series.get_patch(p)
for p in patches),
- 'diffstat': git.diffstat(
+ 'diffstat': git.diffstat(git.diff(
rev1 = git_id(crt_series, '%s//bottom' % patches[0]),
- rev2 = git_id(crt_series, '%s//top' % patches[-1]))}
+ rev2 = git_id(crt_series, '%s//top' % patches[-1])))}
try:
msg_string = tmpl % tmpl_dict
@@ -433,6 +433,9 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options):
else:
number_str = ''
+ diff = git.diff(rev1 = git_id(crt_series, '%s//bottom' % patch),
+ rev2 = git_id(crt_series, '%s//top' % patch),
+ diff_flags = options.diff_flags)
tmpl_dict = {'patch': patch,
'sender': sender,
# for backward template compatibility
@@ -441,13 +444,8 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options):
'longdescr': long_descr,
# for backward template compatibility
'endofheaders': '',
- 'diff': git.diff(
- rev1 = git_id(crt_series, '%s//bottom' % patch),
- rev2 = git_id(crt_series, '%s//top' % patch),
- diff_flags = options.diff_flags),
- 'diffstat': git.diffstat(
- rev1 = git_id(crt_series, '%s//bottom'%patch),
- rev2 = git_id(crt_series, '%s//top' % patch)),
+ 'diff': diff,
+ 'diffstat': git.diffstat(diff),
# for backward template compatibility
'date': '',
'version': version_str,
diff --git a/stgit/git.py b/stgit/git.py
index 85cceb0..4dc4dcf 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -640,12 +640,9 @@ def diff(files = None, rev1 = 'HEAD', rev2 = None, diff_flags = [],
else:
return ''
-# TODO: take another parameter representing a diff string as we
-# usually invoke git.diff() form the calling functions
-def diffstat(files = None, rev1 = 'HEAD', rev2 = None):
- """Return the diffstat between rev1 and rev2."""
- return GRun('apply', '--stat', '--summary'
- ).raw_input(diff(files, rev1, rev2)).raw_output()
+def diffstat(diff):
+ """Return the diffstat of the supplied diff."""
+ return GRun('apply', '--stat', '--summary').raw_input(diff).raw_output()
def files(rev1, rev2, diff_flags = []):
"""Return the files modified between rev1 and rev2
next prev parent reply other threads:[~2008-01-29 3:07 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-29 2:58 kha/safe and kha/experimental updated Karl Hasselström
2008-01-29 3:02 ` [StGit PATCH 0/5] Various cleanups Karl Hasselström
2008-01-29 3:02 ` [StGit PATCH 1/5] Create index and worktree objects just once Karl Hasselström
2008-01-29 3:03 ` [StGit PATCH 2/5] Wrap excessively long line Karl Hasselström
2008-01-29 3:03 ` [StGit PATCH 3/5] Eliminate temp variable that's used just once Karl Hasselström
2008-01-29 3:04 ` [StGit PATCH 4/5] Simplify editor selection logic Karl Hasselström
2008-01-29 20:09 ` Peter Oberndorfer
2008-01-30 7:28 ` Karl Hasselström
2008-01-30 14:55 ` Jay Soffian
2008-01-30 17:57 ` Karl Hasselström
2008-01-29 3:06 ` Karl Hasselström [this message]
2008-01-29 3:10 ` [StGit PATCH 0/2] "stg clean" test+bugfix Karl Hasselström
2008-01-29 3:11 ` [StGit PATCH 1/2] Add test to ensure that "stg clean" preserves conflicting patches Karl Hasselström
2008-01-29 3:12 ` [StGit PATCH 2/2] Don't clean away patches with conflicts Karl Hasselström
2008-01-29 3:15 ` [StGit PATCH 0/4] Rewrite "stg edit" to use new infrastructure Karl Hasselström
2008-01-29 3:15 ` [StGit PATCH 1/4] Teach new infrastructure about the default author and committer Karl Hasselström
2008-01-29 3:15 ` [StGit PATCH 2/4] Teach new infrastructure to apply patches Karl Hasselström
2008-01-29 3:16 ` [StGit PATCH 3/4] Teach new infrastructure to diff two trees Karl Hasselström
2008-01-29 14:40 ` David Kågedal
2008-01-29 15:57 ` Karl Hasselström
2008-01-29 3:17 ` [StGit PATCH 4/4] Convert "stg edit" to the new infrastructure Karl Hasselström
2008-02-01 7:49 ` [StGit PATCH 0/3] "stg edit" fixups Karl Hasselström
2008-02-01 7:50 ` [StGit PATCH 1/3] Parse the date instead of treating it as an opaque string Karl Hasselström
2008-02-01 7:50 ` [StGit PATCH 2/3] Convert "stg edit" to the new infrastructure Karl Hasselström
2008-02-01 7:50 ` [StGit PATCH 3/3] It's possible to edit unapplied patches now Karl Hasselström
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080129030503.926.71863.stgit@yoghurt \
--to=kha@treskal.com \
--cc=catalin.marinas@gmail.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.
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 NNTP newsgroup(s).