Merge lp:~stefan.goetz-deactivatedaccount/hipl/commitguard-usability into lp:hipl

Proposed by Stefan Götz
Status: Rejected
Rejected by: Stefan Götz
Proposed branch: lp:~stefan.goetz-deactivatedaccount/hipl/commitguard-usability
Merge into: lp:hipl
Prerequisite: lp:~stefan.goetz-deactivatedaccount/hipl/commitguard-whitespace
Diff against target: 91 lines (+20/-10)
4 files modified
.commitguards/author-attribution.guard (+1/-1)
.commitguards/copyright-guard-space.py (+1/-1)
.commitguards/copyright-year.guard (+1/-1)
tools/bazaar/plugins/commitguard.py (+17/-7)
To merge this branch: bzr merge lp:~stefan.goetz-deactivatedaccount/hipl/commitguard-usability
Reviewer Review Type Date Requested Status
René Hummen Approve
Diego Biurrun Abstain
Review via email: mp+89531@code.launchpad.net

Description of the change

Improves the usability of the commitguard plugin by making its output more readable and improving the interaction with the user.

To post a comment you must log in.
Revision history for this message
Diego Biurrun (diego-biurrun) wrote :

 review abstain

On Sat, Jan 21, 2012 at 11:38:39AM +0000, Stefan Götz wrote:
> Stefan Götz has proposed merging lp:~stefan.goetz/hipl/commitguard-usability into lp:hipl with lp:~stefan.goetz/hipl/commitguard-whitespace as a prerequisite.

This is Python, so I cannot really review. I'll trust you on it, though.

> --- .commitguards/copyright-year.guard 2012-01-21 11:37:29 +0000
> +++ .commitguards/copyright-year.guard 2012-01-21 11:37:29 +0000
> @@ -24,4 +24,4 @@
> [guard]
> files=\.(c|h|am|ac|in|py|sh|guard)$
> actions=amr
> -command=CR_TOKEN=" Copyright \(c\) "; CR_HOLDER=" Aalto "; Y=$(date +%Y); if ! egrep "$CR_TOKEN.*$CR_HOLDER" "{}" | egrep -q "\b$Y\b"; then echo "{}: The copyright statement is not up-to-date"; L=$(( $Y - 1 )); sed -r "/ Copyright \(c\) / { /\b$Y\b/ ! { /-$L / s/-$L /-$Y /; s/ $L / $L-$Y /; /\b$Y\b/ ! s/ ([0-9, -]+) ([a-zA-Z]+)/ \1, $Y \2/ } }" "{}" | diff -u "{}" - >&2; false; fi
> +command=CR_TOKEN=" Copyright \(c\) "; CR_HOLDER=" Aalto "; Y=$(date +%Y); if ! egrep "$CR_TOKEN.*$CR_HOLDER" "{}" | egrep -q "\b$Y\b"; then echo "The copyright statement is not up-to-date"; L=$(( $Y - 1 )); sed -r "/ Copyright \(c\) / { /\b$Y\b/ ! { /-$L / s/-$L /-$Y /; s/ $L / $L-$Y /; /\b$Y\b/ ! s/ ([0-9, -]+) ([a-zA-Z]+)/ \1, $Y \2/ } }" "{}" | diff -u "{}" - >&2; false; fi

Maybe you could break this sequence of commands:

> +command=CR_TOKEN=" Copyright \(c\) ";
                      CR_HOLDER=" Aalto ";
                      Y=$(date +%Y);
                      if ! egrep "$CR_TOKEN.*$CR_HOLDER" "{}" | egrep -q "\b$Y\b"; then
                          echo "The copyright statement is not up-to-date";
                          L=$(( $Y - 1 ));
                          sed -r "/ Copyright \(c\) / { /\b$Y\b/ ! { /-$L / s/-$L /-$Y /; s/ $L / $L-$Y /; /\b$Y\b/ ! s/ ([0-9, -]+) ([a-zA-Z]+)/ \1, $Y \2/ } }" "{}" | diff -u "{}" - >&2;
                          false;
                      fi

This might even work if the ';' are replaced by '\'. :)

Diego

review: Abstain
Revision history for this message
Stefan Götz (stefan.goetz-deactivatedaccount) wrote :

Hi Diego!

Thanks for the review!

> Maybe you could break this sequence of commands:

Thanks for making me look at that - it turns out that the python parser for
these guard files has support for line continuations built-in and the standard
line breaks and indentations of shell scripts can be used in those files which
makes them much more readable. I updated all guards on all commitguard branches
accordingly.

Cheers,
 Stefan

Revision history for this message
René Hummen (rene-hummen) :
review: Approve
Revision history for this message
Stefan Götz (stefan.goetz-deactivatedaccount) wrote :

Hi Rene!

> I just got a suggested workflow that would allow merging of the stylechecker with this script:
> 1) Make a local copy of the files touched in the current commit.
> 2) Apply the commit guards (including uncrustify) one after the other to each of the local copies.
> 2.1) Tell the user which guard failed on which file.
> 2.2) Apply an eventual change of a commit guard to the local copy.
> 3) After all commit guards have been executed (and the corresponding changes have been applied to the local copies incrementally), show the user the diff between the local files and the files in the commit.
> 3.1) Apply diff, if accepted by the user.

That makes a lot of sense and is certainly more usable than the current
approach. I'll work on it on the usability branch.

> Additionally, it might be worth having an install_bzr_hooks.sh script that copies the scripts to one of the two valid bazaar plugin locations in order to increase usage and acceptance.

Yeah, well, I don't think the difference between a single cp command and a
script will change something about usage and acceptance - so I'll let someone
else write that script :)

Stefan

6278. By Stefan Götz

Improve readability of output when a commit guard fails

6279. By Stefan Götz

Simplify output of commit guards. They do not need to print the name of
the affected file because the commit guard plugin takes care of that.

6280. By Stefan Götz

Make output more readable by asking for user intervention before
displaying a potentially long diff.

Unmerged revisions

6289. By Stefan Götz

When a file is added to a shadow repository, create it on the file system as a copy of the original

6288. By Stefan Götz

Ensure that both directory name strings in ShadowRepo do not end with a slash and make sure that the repository base directory is determined correctly

6287. By Stefan Götz

Create and delete shadow repository object, but do not use it

6286. By Stefan Götz

Add function for retrieving a patch file for the differences between the repository and the shadow repository

6285. By Stefan Götz

Add function for deleting a shadow repository

6284. By Stefan Götz

Add ShadowRepo class as infrastructure for in-place editing by commitguards

6283. By Stefan Götz

Add class definition that is part of new infrastructure for in-place editing through commitguards

6282. By Stefan Götz

Apply all commit guards to all committed files instead of aborting on the first violation

6281. By Stefan Götz

Remove the ability to apply patches printed on stderr by commit guards

6280. By Stefan Götz

Make output more readable by asking for user intervention before
displaying a potentially long diff.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.commitguards/author-attribution.guard'
2--- .commitguards/author-attribution.guard 2012-01-22 13:08:25 +0000
3+++ .commitguards/author-attribution.guard 2012-01-22 13:08:25 +0000
4@@ -26,6 +26,6 @@
5 actions=amr
6 command=
7 if AUTHORS="$(egrep "@author\b" "{}")"; then
8- echo "{}: files should not contain author attributions such as '$(echo "$AUTHORS" | head -n 1)'"
9+ echo "Authorship attributions (such as '$(echo "$AUTHORS" | head -n 1)') should be removed"
10 false
11 fi
12
13=== modified file '.commitguards/copyright-guard-space.py'
14--- .commitguards/copyright-guard-space.py 2012-01-22 13:08:25 +0000
15+++ .commitguards/copyright-guard-space.py 2012-01-22 13:08:25 +0000
16@@ -61,5 +61,5 @@
17 fh.close()
18
19 if not match:
20- print 'The copyright header in file %s should be followed by an empty line' % (sys.argv[1])
21+ print 'The copyright header should be followed by an empty line'
22 sys.exit(1)
23
24=== modified file '.commitguards/copyright-year.guard'
25--- .commitguards/copyright-year.guard 2012-01-22 13:08:25 +0000
26+++ .commitguards/copyright-year.guard 2012-01-22 13:08:25 +0000
27@@ -29,7 +29,7 @@
28 CR_HOLDER=" Aalto "
29 Y=$(date +%Y)
30 if ! egrep "$CR_TOKEN.*$CR_HOLDER" "{}" | egrep -q "\b$Y\b"; then
31- echo "{}: The copyright statement is not up-to-date"
32+ echo "The copyright statement is not up-to-date"
33 L=$(( $Y - 1 ))
34 sed -r "/ Copyright \(c\) / { /\b$Y\b/ ! { /-$L / s/-$L /-$Y /; s/ $L / $L-$Y /; /\b$Y\b/ ! s/ ([0-9, -]+) ([a-zA-Z]+)/ \1, $Y \2/ } }" "{}" | diff -u "{}" - >&2
35 false
36
37=== modified file 'tools/bazaar/plugins/commitguard.py'
38--- tools/bazaar/plugins/commitguard.py 2012-01-22 13:08:25 +0000
39+++ tools/bazaar/plugins/commitguard.py 2012-01-22 13:08:25 +0000
40@@ -310,12 +310,14 @@
41 guards = create_guards(local or master)
42
43 veto = False
44+ info_file = tempfile.NamedTemporaryFile(prefix = plugin_name + "-msg-")
45 diff_file = tempfile.NamedTemporaryFile(prefix = plugin_name + "-diff-")
46
47+ tree_file_name = None
48 for tree_file_name, action in get_commit_files(tree_delta):
49 local_file_name = get_local_file_name(local or master, tree_file_name)
50 for guard in guards:
51- if not guard.run(local_file_name, action, sys.stdout, diff_file):
52+ if not guard.run(local_file_name, action, info_file, diff_file):
53 veto = True
54 break
55
56@@ -323,16 +325,23 @@
57 break
58
59 if veto:
60+ info_file.flush()
61+ info_file.seek(0)
62+ print "\n\n%s:\n " % (tree_file_name), info_file.read()
63+ info_file.close()
64+
65 diff_file.flush()
66 if diff_file.tell():
67- print "\nThe following patch is suggested so as to comply with the commit guard requirements:\n"
68- diff_file.seek(0)
69- print diff_file.read()
70- print "\nWould you like to apply these changes to your local branch now? [y/N] ",
71+ print "Would you like to review a patch that solves this issue? [y|N] ",
72 reply = sys.stdin.readline()
73 if reply.strip() == 'y':
74- apply_patch(diff_file)
75- print "Changes successfully applied.\n"
76+ diff_file.seek(0)
77+ print "\n", diff_file.read()
78+ print "\nWould you like to apply these changes to your local branch now? [y/N] ",
79+ reply = sys.stdin.readline()
80+ if reply.strip() == 'y':
81+ apply_patch(diff_file)
82+ print "Changes successfully applied.\n"
83 diff_file.close()
84
85 msg_file = tempfile.NamedTemporaryFile(prefix = 'commit-msg-%d-' % future_revno, delete = False)
86@@ -340,6 +349,7 @@
87 msg_file.close()
88
89 raise bzrlib.errors.BzrError("This commit has been aborted. The original commit message, stored in %s, was:\n--\n%s\n--" % (msg_file.name, get_commit_message(local, master, future_revid)))
90+ info_file.close()
91 diff_file.close()
92
93

Subscribers

People subscribed via source and target branches

to all changes: