* Re: [PATCH 3/5] Unify whitespace checking
From: Wincent Colaiuta @ 2007-12-14 7:36 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <7vd4taywfw.fsf@gitster.siamese.dyndns.org>
El 14/12/2007, a las 1:03, Junio C Hamano escribió:
>> - git diff --check | grep "space before tab"
>> + git diff --check | grep "Space in indent is followed by a tab"
>>
> Hmph. I think with the multiple detection this rewording would make
> the
> error message very long to read. Was the rewording really necessary?
Well, that wording came from builtin-apply.c so it wasn't really a "re-
wording" but an extraction. The other string comes from "diff.c". So I
had to pick one of them in unifying them and basically the one from
builtin-apply.c won because it was the site where I extracted from
first. So basically it was arbitrary.
If I were to actually *re-word* the message I think something like
this would be the compromise between clarity and conciseness:
"space before tab in indent"
And in the same spirit, the other two strings extracted from builtin-
apply.c into the new whitespace_error_string() function:
"Adds trailing whitespace"
"Indent more than 8 places with spaces"
Could be shortened to:
"trailing whitespace" (diff.c says "white space at end")
"indent using spaces"
But I personally have no strong conviction about this, so I'm happy
for it to be whatever you want.
>> +/* If stream is non-NULL, emits the line after checking. */
>> +unsigned check_and_emit_line(const char *line, int len, unsigned
>> ws_rule,
>> + FILE *stream, const char *set,
>> + const char *reset, const char *ws)
>> +{
>
> Honestly, I regretted suggesting this, fearing that it might make the
> checking too costly, but the code is clean, readable, and does not
> look
> costly at all. Nice job.
Thanks. The check_and_emit_line function itself is fairly clean
internally (apart from the somewhat ugly parameter list, but that was
mostly inherited from the emit_line_with_ws function which it
replaces). It's the sites where check_and_emit_line is called that
look a bit ugly, but those can hopefully be cleaned up at some point
in the future.
Cheers,
Wincent
^ permalink raw reply
* Re: [PATCH] Don't use the pager when running "git diff --check"
From: Junio C Hamano @ 2007-12-14 7:33 UTC (permalink / raw)
To: Wincent Colaiuta; +Cc: Jeff King, git
In-Reply-To: <7vmysdx3la.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> By the way, there is no reason to make --check and --exit-code mutually
> exclusive either.
Perhaps something like this. Regardless of the exclusivity issue, I
think the "diff_result_code()" helper function is a good clean-up.
---
builtin-diff-files.c | 6 +-----
builtin-diff-index.c | 6 +-----
builtin-diff-tree.c | 6 ++----
builtin-diff.c | 11 ++++-------
diff.c | 19 ++++++++++++++-----
diff.h | 2 ++
t/t4015-diff-whitespace.sh | 4 ++--
7 files changed, 26 insertions(+), 28 deletions(-)
diff --git a/builtin-diff-files.c b/builtin-diff-files.c
index 4afc872..9c04111 100644
--- a/builtin-diff-files.c
+++ b/builtin-diff-files.c
@@ -31,9 +31,5 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
if (!rev.diffopt.output_format)
rev.diffopt.output_format = DIFF_FORMAT_RAW;
result = run_diff_files_cmd(&rev, argc, argv);
- if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
- return DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
- if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)
- return DIFF_OPT_TST(&rev.diffopt, CHECK_FAILED) != 0;
- return result;
+ return diff_result_code(&rev.diffopt, result);
}
diff --git a/builtin-diff-index.c b/builtin-diff-index.c
index 532b284..0f2390a 100644
--- a/builtin-diff-index.c
+++ b/builtin-diff-index.c
@@ -44,9 +44,5 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
return -1;
}
result = run_diff_index(&rev, cached);
- if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
- return DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
- if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)
- return DIFF_OPT_TST(&rev.diffopt, CHECK_FAILED) != 0;
- return result;
+ return diff_result_code(&rev.diffopt, result);
}
diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c
index 9ab90cb..ebc50ef 100644
--- a/builtin-diff-tree.c
+++ b/builtin-diff-tree.c
@@ -132,8 +132,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
diff_tree_stdin(line);
}
}
- if (opt->diffopt.output_format & DIFF_FORMAT_CHECKDIFF)
- return DIFF_OPT_TST(&opt->diffopt, CHECK_FAILED) != 0;
- return DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS)
- && DIFF_OPT_TST(&opt->diffopt, HAS_CHANGES);
+
+ return diff_result_code(&opt->diffopt, 0);
}
diff --git a/builtin-diff.c b/builtin-diff.c
index 9d878f6..29365a0 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -244,11 +244,11 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
- /* If the user asked for our exit code then don't start a
+ /*
+ * If the user asked for our exit code then don't start a
* pager or we would end up reporting its exit code instead.
*/
- if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS) &&
- (!(rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)))
+ if (!DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
setup_pager();
/* Do we have --cached and not have a pending object, then
@@ -352,10 +352,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
else
result = builtin_diff_combined(&rev, argc, argv,
ent, ents);
- if (DIFF_OPT_TST(&rev.diffopt, EXIT_WITH_STATUS))
- result = DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES) != 0;
- if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)
- return DIFF_OPT_TST(&rev.diffopt, CHECK_FAILED) != 0;
+ result = diff_result_code(&rev.diffopt, result);
if (1 < rev.diffopt.skip_stat_unmatch)
refresh_index_quietly();
return result;
diff --git a/diff.c b/diff.c
index 8237075..3e46ff8 100644
--- a/diff.c
+++ b/diff.c
@@ -2125,12 +2125,7 @@ int diff_setup_done(struct diff_options *options)
if (options->output_format & DIFF_FORMAT_NAME_STATUS)
count++;
if (options->output_format & DIFF_FORMAT_CHECKDIFF)
- {
count++;
- if (DIFF_OPT_TST(options, QUIET) ||
- DIFF_OPT_TST(options, EXIT_WITH_STATUS))
- die("--check may not be used with --quiet or --exit-code");
- }
if (options->output_format & DIFF_FORMAT_NO_OUTPUT)
count++;
if (count > 1)
@@ -3180,6 +3175,20 @@ void diffcore_std(struct diff_options *options)
DIFF_OPT_CLR(options, HAS_CHANGES);
}
+int diff_result_code(struct diff_options *opt, int status)
+{
+ int result = 0;
+ if (!DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
+ !(opt->output_format & DIFF_FORMAT_CHECKDIFF))
+ return status;
+ if (DIFF_OPT_TST(opt, EXIT_WITH_STATUS) &&
+ DIFF_OPT_TST(opt, HAS_CHANGES))
+ result |= 01;
+ if ((opt->output_format & DIFF_FORMAT_CHECKDIFF) &&
+ DIFF_OPT_TST(opt, CHECK_FAILED))
+ result |= 02;
+ return result;
+}
void diff_addremove(struct diff_options *options,
int addremove, unsigned mode,
diff --git a/diff.h b/diff.h
index 5d50d93..7e8000a 100644
--- a/diff.h
+++ b/diff.h
@@ -247,4 +247,6 @@ extern int run_diff_index(struct rev_info *revs, int cached);
extern int do_diff_cache(const unsigned char *, struct diff_options *);
extern int diff_flush_patch_id(struct diff_options *, unsigned char *);
+extern int diff_result_code(struct diff_options *, int);
+
#endif /* DIFF_H */
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index dc538b3..757a27a 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -148,14 +148,14 @@ test_expect_failure 'check with space before tab in indent' '
'
-test_expect_failure '--check and --exit-code are exclusive' '
+test_expect_success '--check and --exit-code are not exclusive' '
git checkout x &&
git diff --check --exit-code
'
-test_expect_failure '--check and --quiet are exclusive' '
+test_expect_success '--check and --quiet are not exclusive' '
git diff --check --quiet
^ permalink raw reply related
* Re: [BUG?] git rebase -i
From: Johannes Sixt @ 2007-12-14 7:30 UTC (permalink / raw)
To: Pieter de Bie; +Cc: git
In-Reply-To: <2791F15A-EB72-4FE4-8DB3-7A4B4DCB07B3@frim.nl>
Pieter de Bie schrieb:
> Another thing to note is
> that the 1.5.4.rc0 tries to apply 215 patches, while the 1.5.3.5 tries
> to apply 206 patches.
This is to be expected: 1.5.3.5 counts the comment lines at the top of the
action file, of which there are exactly 9, 1.5.4.rc0 does not count them.
-- Hannes
^ permalink raw reply
* Re: [PATCH 2/5] New version of pre-commit hook
From: Wincent Colaiuta @ 2007-12-14 7:24 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
In-Reply-To: <fjsi37$7ji$1@ger.gmane.org>
El 14/12/2007, a las 1:17, Jakub Narebski escribió:
> Wincent Colaiuta wrote:
>
>> Now that "git diff --check" indicates problems with its exit code the
>> pre-commit hook becomes a trivial one-liner.
>
>> - if (/^(?:[<>=]){7}/) {
>> - bad_line("unresolved merge conflict", $_);
>> - }
>
> Aren't you losing this check with rewrite?
Yes. If that's a problem then this is definitely a "no-goer".
Cheers,
Wincent
^ permalink raw reply
* Re: [PATCH 1/2] xdl_diff: identify call sites.
From: Junio C Hamano @ 2007-12-14 7:03 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: git
In-Reply-To: <7vtzmmz0ov.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
> This inserts a new function xdi_diff() that currently does not
> do anything other than calling the underlying xdl_diff() to the
> callchain of current callers of xdl_diff() function.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> Nicolas Pitre <nico@cam.org> writes:
>
> > On Wed, 12 Dec 2007, Junio C Hamano wrote:
> >
> >> Here are the topics that have been cooking.
> >
> > What about the blame speedup patch from Linus (Message-ID:
> > <alpine.LFD.0.9999.0712111548200.25032@woody.linux-foundation.org>)
>
> I would prefer to do a bit more generic solution, not a special hack for
> speeding up blame on prepend-only files, with a proper log message.
FWIW, I re-ran the gcc/ChangeLog annotation Linus cited and got similar
improvements (about 4x speed-up) with his version and this version and
their results seem to match. I'll apply these to 'master' and push the
results out.
^ permalink raw reply
* Re: [PATCH] Authentication support for pserver
From: Ævar Arnfjörð Bjarmason @ 2007-12-14 6:55 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, martyn, martin
In-Reply-To: <7vd4t9x2lw.fsf@gitster.siamese.dyndns.org>
[-- Attachment #1: Type: text/plain, Size: 2833 bytes --]
Junio C Hamano <gitster@pobox.com> writes:
> avar@cpan.org (Ævar Arnfjörð Bjarmason) writes:
>
>> + unless ($user eq 'anonymous') {
>> + # Trying to authenticate a user
>> + if (not exists $cfg->{gitcvs}->{users}) {
>> + print "E the repo config file needs a [gitcvs.users] section with user/password key-value pairs\n";
>> + print "I HATE YOU\n";
>> + exit 1;
>> + } elsif (exists $cfg->{gitcvs}->{users} and not exists $cfg->{gitcvs}->{users}->{$user}) {
>> + print "E the repo config file has a [gitcvs.users] section but the user $user is not defined in it\n";
>> + print "I HATE YOU\n";
>> + exit 1;
>> + } else {
>> + my $descrambled_password = descramble($password);
>> + my $cleartext_password = $cfg->{gitcvs}->{users}->{$user};
>> + if ($descrambled_password ne $cleartext_password) {
>> + print "E The password supplied for user $user was incorrect\n";
>> + print "I HATE YOU\n";
>> + exit 1;
>> + }
>
> I do not know what the real pserver does but by sending these E lines in
> the latter two different forms back to the client you are leaking
> sensitive information, which is probably not what you want (the first
> one is Ok, though. It would help the server administrator to notice
> misconfiguration, and until it is corrected nobody would be able to log
> in anyway).
I've commented out those two error messages, it now doesn't provide that
info.
> Admittedly, the pserver password scrambling is not a real security, but
> if we were paranoid, we would probably be even adding random delay in
> "no user found" case and "password does not match" case, so that the
> client cannot even tell from the response latency if a username exists
> at the server.
>
>> @@ -1176,12 +1196,6 @@ sub req_ci
>>
>> $log->info("req_ci : " . ( defined($data) ? $data : "[NULL]" ));
>>
>> - if ( $state->{method} eq 'pserver')
>> - {
>> - print "error 1 pserver access cannot commit\n";
>> - exit;
>> - }
>> -
>
> Is this correct? You are still allowing anonymous pserver access, so
> shouldn't you check if this was an anonymous access or authenticated one
> and refuse access like before for anonymous people?
No it's not, oops. Fixed.
>> + my ($str) = @_;
>> +
>> + # This should never happen, the same format has been used since
>> + # CVS was spawned
>> + $str =~ s/^(.)//;
>> + die "invalid password format $1" unless $1 eq 'A';
>
> I do not quite understand what "spawn" means in this sentence.
Shawn O. Pearce put it best but I've changed the comment to be more
readable to someone without a odd sense of humor:)
[-- Attachment #2: Fixed git-cvsserver patch --]
[-- Type: text/plain, Size: 5770 bytes --]
diff --git a/Documentation/git-cvsserver.txt b/Documentation/git-cvsserver.txt
index 258a62f..5ca84fc 100644
--- a/Documentation/git-cvsserver.txt
+++ b/Documentation/git-cvsserver.txt
@@ -69,9 +69,6 @@ plugin. Most functionality works fine with both of these clients.
LIMITATIONS
-----------
-Currently cvsserver works over SSH connections for read/write clients, and
-over pserver for anonymous CVS access.
-
CVS clients cannot tag, branch or perform GIT merges.
git-cvsserver maps GIT branches to CVS modules. This is very different
@@ -81,7 +78,7 @@ one or more directories.
INSTALLATION
------------
-1. If you are going to offer anonymous CVS access via pserver, add a line in
+1. If you are going to offer CVS access via pserver, add a line in
/etc/inetd.conf like
+
--
@@ -98,6 +95,22 @@ looks like
cvspserver stream tcp nowait nobody /usr/bin/git-cvsserver git-cvsserver pserver
------
+
+Only anonymous access is provided by pserve by default. To commit you
+will have to create pserver accounts, simply add a [gitcvs.users]
+section to the repositories you want to access, for example:
+
+------
+
+ [gitcvs.users]
+ someuser = somepassword
+ otheruser = otherpassword
+
+------
+Then provide your password via the pserver method, for example:
+------
+ cvs -d:pserver:someuser:somepassword@server/path/repo.git co <HEAD_name>
+------
No special setup is needed for SSH access, other than having GIT tools
in the PATH. If you have clients that do not accept the CVS_SERVER
environment variable, you can rename git-cvsserver to cvs.
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index ecded3b..9541049 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -150,12 +150,35 @@ if ($state->{method} eq 'pserver') {
exit 1;
}
$line = <STDIN>; chomp $line;
- unless ($line eq 'anonymous') {
- print "E Only anonymous user allowed via pserver\n";
- print "I HATE YOU\n";
- exit 1;
+ my $user = $line;
+ $line = <STDIN>; chomp $line;
+ my $password = $line;
+
+ unless ($user eq 'anonymous') {
+ # Trying to authenticate a user
+ if (not exists $cfg->{gitcvs}->{users}) {
+ print "E the repo config file needs a [gitcvs.users] section with user/password key-value pairs\n";
+ print "I HATE YOU\n";
+ exit 1;
+ } elsif (exists $cfg->{gitcvs}->{users} and not exists $cfg->{gitcvs}->{users}->{$user}) {
+ #print "E the repo config file has a [gitcvs.users] section but the user $user is not defined in it\n";
+ print "I HATE YOU\n";
+ exit 1;
+ } else {
+ my $descrambled_password = descramble($password);
+ my $cleartext_password = $cfg->{gitcvs}->{users}->{$user};
+ if ($descrambled_password ne $cleartext_password) {
+ #print "E The password supplied for user $user was incorrect\n";
+ print "I HATE YOU\n";
+ exit 1;
+ }
+ # else fall through to LOVE
+ }
}
- $line = <STDIN>; chomp $line; # validate the password?
+
+ # For checking whether the user is anonymous on commit
+ $state->{user} = $user;
+
$line = <STDIN>; chomp $line;
unless ($line eq "END $request REQUEST") {
die "E Do not understand $line -- expecting END $request REQUEST\n";
@@ -273,7 +296,7 @@ sub req_Root
}
foreach my $line ( @gitvars )
{
- next unless ( $line =~ /^(gitcvs)\.(?:(ext|pserver)\.)?([\w-]+)=(.*)$/ );
+ next unless ( $line =~ /^(gitcvs)\.(?:(ext|pserver|users)\.)?([\w-]+)=(.*)$/ );
unless ($2) {
$cfg->{$1}{$3} = $4;
} else {
@@ -1176,9 +1199,9 @@ sub req_ci
$log->info("req_ci : " . ( defined($data) ? $data : "[NULL]" ));
- if ( $state->{method} eq 'pserver')
+ if ($state->{method} eq 'pserver' and $state->{user} eq 'anonymous')
{
- print "error 1 pserver access cannot commit\n";
+ print "error 1 anonymous user cannot commit via pserver\n";
exit;
}
@@ -2107,6 +2130,41 @@ sub kopts_from_path
}
}
+
+sub descramble
+{
+ # This table is from src/scramble.c in the CVS source
+ my @SHIFTS = (
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 114,120, 53, 79, 96,109, 72,108, 70, 64, 76, 67,116, 74, 68, 87,
+ 111, 52, 75,119, 49, 34, 82, 81, 95, 65,112, 86,118,110,122,105,
+ 41, 57, 83, 43, 46,102, 40, 89, 38,103, 45, 50, 42,123, 91, 35,
+ 125, 55, 54, 66,124,126, 59, 47, 92, 71,115, 78, 88,107,106, 56,
+ 36,121,117,104,101,100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48,
+ 58,113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85,223,
+ 225,216,187,166,229,189,222,188,141,249,148,200,184,136,248,190,
+ 199,170,181,204,138,232,218,183,255,234,220,247,213,203,226,193,
+ 174,172,228,252,217,201,131,230,197,211,145,238,161,179,160,212,
+ 207,221,254,173,202,146,224,151,140,196,205,130,135,133,143,246,
+ 192,159,244,239,185,168,215,144,139,165,180,157,147,186,214,176,
+ 227,231,219,169,175,156,206,198,129,164,150,210,154,177,134,127,
+ 182,128,158,208,162,132,167,209,149,241,153,251,237,236,171,195,
+ 243,233,253,240,194,250,191,155,142,137,245,235,163,242,178,152
+ );
+ my ($str) = @_;
+
+ # This should never happen, the same password format (A) bas been
+ # used by CVS since the beginnin of time
+ $str =~ s/^(.)//;
+ die "invalid password format $1" unless $1 eq 'A';
+
+ $str =~ s/(.)/chr $SHIFTS[ord $1]/ge;
+
+ return $str;
+}
+
+
package GITCVS::log;
####
^ permalink raw reply related
* Re: git gui blame utf-8 bugs
From: Shawn O. Pearce @ 2007-12-14 6:47 UTC (permalink / raw)
To: Finn Arne Gangstad; +Cc: git
In-Reply-To: <20071212091744.GA5377@pvv.org>
Finn Arne Gangstad <finnag@pvv.org> wrote:
> git gui has some utf-8 bugs:
It has several. :-)
> If you do git gui blame <file>, and the file contains utf-8 text,
> the lines are not parsed as utf-8, but seemingly as iso-8859-1 instead.
Right. git-gui is keying off the environment setting for LANG, so I
guess its set to iso-8859-1 on your system but you are working with a
utf-8 file. We've talked about using something like .gitattributes
to store encoding hints, or to just put a global gui setting in
~/.gitconfig but neither has had any patches written for it.
UTF-8 is seemingly the most common encoding that git-gui is mangling
so maybe we should be defaulting to utf-8 until someone codes a
more intelligent patch.
> Also, the hovering comment is INITIALLY shown garbled (both Author and
> commit message), but if you click on a line, so that the commit
> message is shown in the bottom window, the hovering message is
> magically corrected to utf-8.
>
> The text in the lower window (showing specific commits) seems to
> always be handled correctly.
That's a "feature". :-)
What's happening here is the initial hovering message is obtained
from the machine formatted output from `git blame --incremental`
and in that format there is no encoding header so I'm just ignoring
any encoding problems.
Later when you click on a line it does `git cat-file commit $sha1`
and gets the proper encoding, and corrects the strings it originally
had gotten from git-blame. So the hovering message "fixes" itself
later on.
Maybe here too we should be defaulting to utf-8 instead of the
native encoding.
--
Shawn.
^ permalink raw reply
* Re: [StGit PATCH 5/5] Name the exit codes to improve legibility
From: Karl Hasselström @ 2007-12-14 6:45 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062527.29148.7928.stgit@yoghurt>
On 2007-12-14 07:25:27 +0100, Karl Hasselström wrote:
> +# Exit codes.
> +STGIT_SUCCESS = 0 # everything's OK
> +STGIT_GENERAL_ERROR = 1 # seems to be non-command-specific error
> +STGIT_COMMAND_ERROR = 2 # seems to be a command that failed
If anyone knows for sure, feel free to fix up these descriptions.
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply
* Re: [StGit PATCH 4/5] Make generic --message/--file/--save-template flags
From: Karl Hasselström @ 2007-12-14 6:44 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062521.29148.66456.stgit@yoghurt>
On 2007-12-14 07:25:21 +0100, Karl Hasselström wrote:
> And let "stg edit" use them.
Nothing else in the "safe" branch uses this currently. But one of the
"experimental" patches I just sent out does.
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply
* [StGit PATCH 5/5] Make "stg commit" fancier
From: Karl Hasselström @ 2007-12-14 6:32 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062618.29290.70792.stgit@yoghurt>
Allow the user to commit any patch. Changed behavior: with no
parameters, commit one applied patch, not all applied patches -- this
is what uncommit does.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/commit.py | 87 +++++++++++++++++++++++++++++++++-----------
stgit/commands/uncommit.py | 2 +
stgit/lib/transaction.py | 3 +-
t/t1300-uncommit.sh | 12 +++---
4 files changed, 74 insertions(+), 30 deletions(-)
diff --git a/stgit/commands/commit.py b/stgit/commands/commit.py
index f822181..1d741b3 100644
--- a/stgit/commands/commit.py
+++ b/stgit/commands/commit.py
@@ -15,39 +15,82 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
+from optparse import make_option
from stgit.commands import common
from stgit.lib import transaction
from stgit.out import *
help = 'permanently store the applied patches into stack base'
-usage = """%prog [options]
+usage = """%prog [<patchnames>] | -n NUM | --all
-Merge the applied patches into the base of the current stack and
-remove them from the series while advancing the base.
+Merge one or more patches into the base of the current stack and
+remove them from the series while advancing the base. This is the
+opposite of 'stg uncommit'. Use this command if you no longer want to
+manage a patch with StGIT.
-Use this command only if you want to permanently store the applied
-patches and no longer manage them with StGIT."""
+By default, the bottommost patch is committed. If patch names are
+given, the stack is rearranged so that those patches are at the
+bottom, and then they are committed.
-directory = common.DirectoryHasRepositoryLib()
-options = []
+The -n/--number option specifies the number of applied patches to
+commit (counting from the bottom of the stack). If -a/--all is given,
+all applied patches are committed."""
+directory = common.DirectoryHasRepositoryLib()
+options = [make_option('-n', '--number', type = 'int',
+ help = 'commit the specified number of patches'),
+ make_option('-a', '--all', action = 'store_true',
+ help = 'commit all applied patches')]
def func(parser, options, args):
- """Merge the applied patches into the base of the current stack
- and remove them from the series while advancing the base
- """
- if len(args) != 0:
- parser.error('incorrect number of arguments')
-
+ """Commit a number of patches."""
stack = directory.repository.current_stack
- patches = stack.patchorder.applied
+ args = common.parse_patches(args, (list(stack.patchorder.applied)
+ + list(stack.patchorder.unapplied)))
+ if len([x for x in [args, options.number != None, options.all] if x]) > 1:
+ parser.error('too many options')
+ if args:
+ patches = [pn for pn in (stack.patchorder.applied
+ + stack.patchorder.unapplied) if pn in args]
+ bad = set(args) - set(patches)
+ if bad:
+ raise common.CmdException('Bad patch names: %s'
+ % ', '.join(sorted(bad)))
+ elif options.number != None:
+ if options.number <= len(stack.patchorder.applied):
+ patches = stack.patchorder.applied[:options.number]
+ else:
+ raise common.CmdException('There are not that many applied patches')
+ elif options.all:
+ patches = stack.patchorder.applied
+ else:
+ patches = stack.patchorder.applied[:1]
if not patches:
- raise CmdException('No patches to commit')
- out.start('Committing %d patches' % len(patches))
+ raise common.CmdException('No patches to commit')
+
+ iw = stack.repository.default_iw()
trans = transaction.StackTransaction(stack, 'stg commit')
- for pn in patches:
- trans.patches[pn] = None
- trans.applied = []
- trans.base = stack.head
- trans.run()
- out.done()
+ try:
+ common_prefix = 0
+ for i in xrange(min(len(stack.patchorder.applied), len(patches))):
+ if stack.patchorder.applied[i] == patches[i]:
+ common_prefix += 1
+ if common_prefix < len(patches):
+ to_push = trans.pop_patches(
+ lambda pn: pn in stack.patchorder.applied[common_prefix:])
+ for pn in patches[common_prefix:]:
+ trans.push_patch(pn, iw)
+ else:
+ to_push = []
+ new_base = trans.patches[patches[-1]]
+ for pn in patches:
+ trans.patches[pn] = None
+ trans.applied = [pn for pn in trans.applied if pn not in patches]
+ trans.base = new_base
+ out.info('Committed %d patch%s' % (len(patches),
+ ['es', ''][len(patches) == 1]))
+ for pn in to_push:
+ trans.push_patch(pn, iw)
+ except transaction.TransactionHalted:
+ pass
+ return trans.run(iw)
diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py
index 8422952..933ec60 100644
--- a/stgit/commands/uncommit.py
+++ b/stgit/commands/uncommit.py
@@ -28,7 +28,7 @@ usage = """%prog [<patchnames>] | -n NUM [<prefix>]] | -t <committish> [-x]
Take one or more git commits at the base of the current stack and turn
them into StGIT patches. The new patches are created as applied patches
-at the bottom of the stack. This is the exact opposite of 'stg commit'.
+at the bottom of the stack. This is the opposite of 'stg commit'.
By default, the number of patches to uncommit is determined by the
number of patch names provided on the command line. First name is used
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index a7c4f7e..a60c5ff 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -51,7 +51,8 @@ class StackTransaction(object):
self.__unapplied = list(val)
unapplied = property(lambda self: self.__unapplied, __set_unapplied)
def __set_base(self, val):
- assert not self.__applied
+ assert (not self.__applied
+ or self.patches[self.applied[0]].data.parent == val)
self.__base = val
base = property(lambda self: self.__base, __set_base)
def __checkout(self, tree, iw):
diff --git a/t/t1300-uncommit.sh b/t/t1300-uncommit.sh
index 85408fd..d86e579 100755
--- a/t/t1300-uncommit.sh
+++ b/t/t1300-uncommit.sh
@@ -35,7 +35,7 @@ test_expect_success \
test_expect_success \
'Commit the patches' \
'
- stg commit
+ stg commit --all
'
test_expect_success \
@@ -43,7 +43,7 @@ test_expect_success \
'
stg uncommit bar foo &&
[ "$(stg id foo//top)" = "$(stg id bar//bottom)" ] &&
- stg commit
+ stg commit --all
'
test_expect_success \
@@ -51,7 +51,7 @@ test_expect_success \
'
stg uncommit --number=2 foobar &&
[ "$(stg id foobar1//top)" = "$(stg id foobar2//bottom)" ] &&
- stg commit
+ stg commit --all
'
test_expect_success \
@@ -59,7 +59,7 @@ test_expect_success \
'
stg uncommit --number=2 &&
[ "$(stg id foo-patch//top)" = "$(stg id bar-patch//bottom)" ] &&
- stg commit
+ stg commit --all
'
test_expect_success \
@@ -68,14 +68,14 @@ test_expect_success \
stg uncommit &&
stg uncommit &&
[ "$(stg id foo-patch//top)" = "$(stg id bar-patch//bottom)" ] &&
- stg commit
+ stg commit --all
'
test_expect_success \
'Uncommit the patches with --to' '
stg uncommit --to HEAD^ &&
[ "$(stg id foo-patch//top)" = "$(stg id bar-patch//bottom)" ] &&
- stg commit
+ stg commit --all
'
test_done
^ permalink raw reply related
* [StGit PATCH 4/5] Convert "stg commit" to new infrastructure
From: Karl Hasselström @ 2007-12-14 6:32 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062618.29290.70792.stgit@yoghurt>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/commit.py | 42 ++++++++++++++----------------------------
stgit/lib/transaction.py | 7 ++++++-
2 files changed, 20 insertions(+), 29 deletions(-)
diff --git a/stgit/commands/commit.py b/stgit/commands/commit.py
index e56f5a0..f822181 100644
--- a/stgit/commands/commit.py
+++ b/stgit/commands/commit.py
@@ -15,13 +15,9 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-import sys, os
-from optparse import OptionParser, make_option
-
-from stgit.commands.common import *
-from stgit.utils import *
+from stgit.commands import common
+from stgit.lib import transaction
from stgit.out import *
-from stgit import stack, git
help = 'permanently store the applied patches into stack base'
usage = """%prog [options]
@@ -32,7 +28,7 @@ remove them from the series while advancing the base.
Use this command only if you want to permanently store the applied
patches and no longer manage them with StGIT."""
-directory = DirectoryGotoToplevel()
+directory = common.DirectoryHasRepositoryLib()
options = []
@@ -43,25 +39,15 @@ def func(parser, options, args):
if len(args) != 0:
parser.error('incorrect number of arguments')
- check_local_changes()
- check_conflicts()
- check_head_top_equal(crt_series)
-
- applied = crt_series.get_applied()
- if not applied:
- raise CmdException, 'No patches applied'
-
- if crt_series.get_protected():
- raise CmdException, 'This branch is protected. Commit is not permitted'
-
- crt_head = git.get_head()
-
- out.start('Committing %d patches' % len(applied))
-
- crt_series.pop_patch(applied[0])
- git.switch(crt_head)
-
- for patch in applied:
- crt_series.delete_patch(patch)
-
+ stack = directory.repository.current_stack
+ patches = stack.patchorder.applied
+ if not patches:
+ raise CmdException('No patches to commit')
+ out.start('Committing %d patches' % len(patches))
+ trans = transaction.StackTransaction(stack, 'stg commit')
+ for pn in patches:
+ trans.patches[pn] = None
+ trans.applied = []
+ trans.base = stack.head
+ trans.run()
out.done()
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 0ca647e..a7c4f7e 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -41,6 +41,7 @@ class StackTransaction(object):
self.__unapplied = list(self.__stack.patchorder.unapplied)
self.__error = None
self.__current_tree = self.__stack.head.data.tree
+ self.__base = self.__stack.base
stack = property(lambda self: self.__stack)
patches = property(lambda self: self.__patches)
def __set_applied(self, val):
@@ -49,6 +50,10 @@ class StackTransaction(object):
def __set_unapplied(self, val):
self.__unapplied = list(val)
unapplied = property(lambda self: self.__unapplied, __set_unapplied)
+ def __set_base(self, val):
+ assert not self.__applied
+ self.__base = val
+ base = property(lambda self: self.__base, __set_base)
def __checkout(self, tree, iw):
if not self.__stack.head_top_equal():
out.error(
@@ -76,7 +81,7 @@ class StackTransaction(object):
if self.__applied:
return self.__patches[self.__applied[-1]]
else:
- return self.__stack.base
+ return self.__base
def abort(self, iw = None):
# The only state we need to restore is index+worktree.
if iw:
^ permalink raw reply related
* [StGit PATCH 3/5] Set exit code to 3 on merge conflict
From: Karl Hasselström @ 2007-12-14 6:32 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062618.29290.70792.stgit@yoghurt>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/coalesce.py | 6 +++---
stgit/commands/goto.py | 2 +-
stgit/lib/transaction.py | 7 ++++++-
stgit/main.py | 4 ++--
stgit/utils.py | 1 +
5 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/stgit/commands/coalesce.py b/stgit/commands/coalesce.py
index 2330231..d2cba3e 100644
--- a/stgit/commands/coalesce.py
+++ b/stgit/commands/coalesce.py
@@ -110,7 +110,7 @@ def _coalesce(stack, iw, name, msg, save_template, patches):
return
except transaction.TransactionHalted:
pass
- trans.run(iw)
+ return trans.run(iw)
def func(parser, options, args):
stack = directory.repository.current_stack
@@ -118,5 +118,5 @@ def func(parser, options, args):
+ list(stack.patchorder.unapplied)))
if len(patches) < 2:
raise common.CmdException('Need at least two patches')
- _coalesce(stack, stack.repository.default_iw(),
- options.name, options.message, options.save_template, patches)
+ return _coalesce(stack, stack.repository.default_iw(), options.name,
+ options.message, options.save_template, patches)
diff --git a/stgit/commands/goto.py b/stgit/commands/goto.py
index d78929d..763a8af 100644
--- a/stgit/commands/goto.py
+++ b/stgit/commands/goto.py
@@ -48,4 +48,4 @@ def func(parser, options, args):
pass
else:
raise common.CmdException('Patch "%s" does not exist' % patch)
- trans.run(iw)
+ return trans.run(iw)
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 663d393..0ca647e 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -1,4 +1,4 @@
-from stgit import exception
+from stgit import exception, utils
from stgit.out import *
from stgit.lib import git
@@ -111,6 +111,11 @@ class StackTransaction(object):
self.__stack.patchorder.applied = self.__applied
self.__stack.patchorder.unapplied = self.__unapplied
+ if self.__error:
+ return utils.STGIT_CONFLICT
+ else:
+ return utils.STGIT_SUCCESS
+
def __halt(self, msg):
self.__error = msg
raise TransactionHalted(msg)
diff --git a/stgit/main.py b/stgit/main.py
index a95eeb9..2577693 100644
--- a/stgit/main.py
+++ b/stgit/main.py
@@ -273,7 +273,7 @@ def main():
else:
command.crt_series = Series()
- command.func(parser, options, args)
+ ret = command.func(parser, options, args)
except (StgException, IOError, ParsingError, NoSectionError), err:
out.error(str(err), title = '%s %s' % (prog, cmd))
if debug_level > 0:
@@ -283,4 +283,4 @@ def main():
except KeyboardInterrupt:
sys.exit(utils.STGIT_GENERAL_ERROR)
- sys.exit(utils.STGIT_SUCCESS)
+ sys.exit(ret or utils.STGIT_SUCCESS)
diff --git a/stgit/utils.py b/stgit/utils.py
index 6568da5..2ff1d74 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -317,6 +317,7 @@ def make_message_options():
STGIT_SUCCESS = 0 # everything's OK
STGIT_GENERAL_ERROR = 1 # seems to be non-command-specific error
STGIT_COMMAND_ERROR = 2 # seems to be a command that failed
+STGIT_CONFLICT = 3 # merge conflict, otherwise OK
def strip_leading(prefix, s):
"""Strip leading prefix from a string. Blow up if the prefix isn't
^ permalink raw reply related
* Re: [PATCH] git-gui: Move frequently used commands to the top of the context menu.
From: Shawn O. Pearce @ 2007-12-14 6:32 UTC (permalink / raw)
To: Johannes Sixt
Cc: Johannes Schindelin, Junio C Hamano, Jason Sewall, David,
Marco Costalba, Andy Parkins, git
In-Reply-To: <47614419.3050604@viscovery.net>
Johannes Sixt <j.sixt@viscovery.net> wrote:
> "Stage/Unstage Hunk" is probably the most frequently used command of the
> patch context menu *and* it is not available in some other form than
> the context menu. Therefore, it should go to the top. "Less Context" and
> "More Context" entries are also not easily available otherwise, and are
> therefore, moved second. The other entries are available via key strokes
> (Copy, Paste, Refresh) or rarly used (Font Size, Options) and can go last.
Thanks. This will be in my repo.or.cz tree shortly.
--
Shawn.
^ permalink raw reply
* [StGit PATCH 2/5] stg coalesce: Support --file and --save-template
From: Karl Hasselström @ 2007-12-14 6:32 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062618.29290.70792.stgit@yoghurt>
--save-template was a bit tricky, because we want that
* if we reached the stage where the message is needed without
conflicts, the message should be written and no other side effects
should occur; but
* if we run into conflicts before reaching that point, behave just
as if --save-template was not given.
This makes this script
stg coalesce --save-template <patches>
if template was saved:
let user edit template
if user didn't abort:
stg coalesce --file <patches>
equivalent to
stg coalesce <patches>
with the added benefit that the user can abort the whole thing without
visible side effects.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/coalesce.py | 28 +++++++++++++++++++---------
1 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/stgit/commands/coalesce.py b/stgit/commands/coalesce.py
index e3e1629..2330231 100644
--- a/stgit/commands/coalesce.py
+++ b/stgit/commands/coalesce.py
@@ -34,11 +34,13 @@ you specify, you will have to resolve them manually just as if you had
done a sequence of pushes and pops yourself."""
directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-n', '--name', help = 'name of coalesced patch'),
- make_option('-m', '--message',
- help = 'commit message of coalesced patch')]
+options = [make_option('-n', '--name', help = 'name of coalesced patch')
+ ] + utils.make_message_options()
-def _coalesce_patches(trans, patches, msg):
+class SaveTemplateDone(Exception):
+ pass
+
+def _coalesce_patches(trans, patches, msg, save_template):
cd = trans.patches[patches[0]].data
cd = git.Commitdata(tree = cd.tree, parents = cd.parents)
for pn in patches[1:]:
@@ -53,12 +55,16 @@ def _coalesce_patches(trans, patches, msg):
msg = '\n\n'.join('%s\n\n%s' % (pn.ljust(70, '-'),
trans.patches[pn].data.message)
for pn in patches)
- msg = utils.edit_string(msg, '.stgit-coalesce.txt').strip()
+ if save_template:
+ save_template(msg)
+ raise SaveTemplateDone()
+ else:
+ msg = utils.edit_string(msg, '.stgit-coalesce.txt').strip()
cd = cd.set_message(msg)
return cd
-def _coalesce(stack, iw, name, msg, patches):
+def _coalesce(stack, iw, name, msg, save_template, patches):
# If a name was supplied on the command line, make sure it's OK.
def bad_name(pn):
@@ -75,8 +81,8 @@ def _coalesce(stack, iw, name, msg, patches):
trans = transaction.StackTransaction(stack, 'stg coalesce')
push_new_patch = bool(set(patches) & set(trans.applied))
- new_commit_data = _coalesce_patches(trans, patches, msg)
try:
+ new_commit_data = _coalesce_patches(trans, patches, msg, save_template)
if new_commit_data:
# We were able to construct the coalesced commit
# automatically. So just delete its constituent patches.
@@ -88,7 +94,8 @@ def _coalesce(stack, iw, name, msg, patches):
to_push = trans.pop_patches(lambda pn: pn in patches)
for pn in patches:
trans.push_patch(pn, iw)
- new_commit_data = _coalesce_patches(trans, patches, msg)
+ new_commit_data = _coalesce_patches(trans, patches, msg,
+ save_template)
assert not trans.delete_patches(lambda pn: pn in patches)
make_coalesced_patch(trans, new_commit_data)
@@ -98,6 +105,9 @@ def _coalesce(stack, iw, name, msg, patches):
trans.push_patch(get_name(new_commit_data), iw)
for pn in to_push:
trans.push_patch(pn, iw)
+ except SaveTemplateDone:
+ trans.abort(iw)
+ return
except transaction.TransactionHalted:
pass
trans.run(iw)
@@ -109,4 +119,4 @@ def func(parser, options, args):
if len(patches) < 2:
raise common.CmdException('Need at least two patches')
_coalesce(stack, stack.repository.default_iw(),
- options.name, options.message, patches)
+ options.name, options.message, options.save_template, patches)
^ permalink raw reply related
* [StGit PATCH 1/5] Expose transaction abort function
From: Karl Hasselström @ 2007-12-14 6:32 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062618.29290.70792.stgit@yoghurt>
Users of stack transactions may call abort() instead of run(), if they
wish to roll back the transaction instead of committing it.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/lib/transaction.py | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 77333b3..663d393 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -77,6 +77,10 @@ class StackTransaction(object):
return self.__patches[self.__applied[-1]]
else:
return self.__stack.base
+ def abort(self, iw = None):
+ # The only state we need to restore is index+worktree.
+ if iw:
+ self.__checkout(self.__stack.head.data.tree, iw)
def run(self, iw = None):
self.__check_consistency()
new_head = self.__head
@@ -85,9 +89,8 @@ class StackTransaction(object):
try:
self.__checkout(new_head.data.tree, iw)
except git.CheckoutException:
- # We have to abort the transaction. The only state we need
- # to restore is index+worktree.
- self.__checkout(self.__stack.head.data.tree, iw)
+ # We have to abort the transaction.
+ self.abort(iw)
self.__abort()
self.__stack.set_head(new_head, self.__msg)
^ permalink raw reply related
* [StGit PATCH 0/5] More experimental patches
From: Karl Hasselström @ 2007-12-14 6:32 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
Also available from
git://repo.or.cz/stgit/kha.git experimental
However, the experimentalness is getting decidedly low. And now that
we just had a release, I have just one more thing I intend to take a
look at -- subdirectory safeness -- before I'm going to transfer all
the "experimental" patches to "safe", wholesale.
So if anyone knows of problems that would make this a bad idea, please
say so.
---
Karl Hasselström (5):
Make "stg commit" fancier
Convert "stg commit" to new infrastructure
Set exit code to 3 on merge conflict
stg coalesce: Support --file and --save-template
Expose transaction abort function
stgit/commands/coalesce.py | 32 ++++++++-----
stgit/commands/commit.py | 111 ++++++++++++++++++++++++++++----------------
stgit/commands/goto.py | 2 -
stgit/commands/uncommit.py | 2 -
stgit/lib/transaction.py | 24 ++++++++--
stgit/main.py | 4 +-
stgit/utils.py | 1
t/t1300-uncommit.sh | 12 ++---
8 files changed, 121 insertions(+), 67 deletions(-)
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply
* [StGit PATCH 5/5] Name the exit codes to improve legibility
From: Karl Hasselström @ 2007-12-14 6:25 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062251.29148.86191.stgit@yoghurt>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/main.py | 25 +++++++++++++------------
stgit/utils.py | 5 +++++
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/stgit/main.py b/stgit/main.py
index a03447f..95e25f8 100644
--- a/stgit/main.py
+++ b/stgit/main.py
@@ -23,6 +23,7 @@ from optparse import OptionParser
import stgit.commands
from stgit.out import *
+from stgit import utils
#
# The commands map
@@ -39,11 +40,11 @@ class Commands(dict):
if not candidates:
out.error('Unknown command: %s' % key,
'Try "%s help" for a list of supported commands' % prog)
- sys.exit(1)
+ sys.exit(utils.STGIT_GENERAL_ERROR)
elif len(candidates) > 1:
out.error('Ambiguous command: %s' % key,
'Candidates are: %s' % ', '.join(candidates))
- sys.exit(1)
+ sys.exit(utils.STGIT_GENERAL_ERROR)
return candidates[0]
@@ -206,7 +207,7 @@ def main():
print >> sys.stderr, 'usage: %s <command>' % prog
print >> sys.stderr, \
' Try "%s --help" for a list of supported commands' % prog
- sys.exit(1)
+ sys.exit(utils.STGIT_GENERAL_ERROR)
cmd = sys.argv[1]
@@ -216,13 +217,13 @@ def main():
sys.argv[2] = '--help'
else:
print_help()
- sys.exit(0)
+ sys.exit(utils.STGIT_SUCCESS)
if cmd == 'help':
if len(sys.argv) == 3 and not sys.argv[2] in ['-h', '--help']:
cmd = commands.canonical_cmd(sys.argv[2])
if not cmd in commands:
out.error('%s help: "%s" command unknown' % (prog, cmd))
- sys.exit(1)
+ sys.exit(utils.STGIT_GENERAL_ERROR)
sys.argv[0] += ' %s' % cmd
command = commands[cmd]
@@ -232,16 +233,16 @@ def main():
pager(parser.format_help())
else:
print_help()
- sys.exit(0)
+ sys.exit(utils.STGIT_SUCCESS)
if cmd in ['-v', '--version', 'version']:
from stgit.version import version
print 'Stacked GIT %s' % version
os.system('git --version')
print 'Python version %s' % sys.version
- sys.exit(0)
+ sys.exit(utils.STGIT_SUCCESS)
if cmd in ['copyright']:
print __copyright__
- sys.exit(0)
+ sys.exit(utils.STGIT_SUCCESS)
# re-build the command line arguments
cmd = commands.canonical_cmd(cmd)
@@ -265,7 +266,7 @@ def main():
debug_level = int(os.environ.get('STGIT_DEBUG_LEVEL', 0))
except ValueError:
out.error('Invalid STGIT_DEBUG_LEVEL environment variable')
- sys.exit(1)
+ sys.exit(utils.STGIT_GENERAL_ERROR)
try:
directory.setup()
@@ -284,8 +285,8 @@ def main():
if debug_level > 0:
raise
else:
- sys.exit(2)
+ sys.exit(utils.STGIT_COMMAND_ERROR)
except KeyboardInterrupt:
- sys.exit(1)
+ sys.exit(utils.STGIT_GENERAL_ERROR)
- sys.exit(0)
+ sys.exit(utils.STGIT_SUCCESS)
diff --git a/stgit/utils.py b/stgit/utils.py
index 837c6c2..29a5f63 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -301,3 +301,8 @@ def make_message_options():
m('--save-template', action = 'callback', callback = templ_callback,
metavar = 'FILE', dest = 'save_template', type = 'string',
help = 'save the message template to FILE and exit')]
+
+# Exit codes.
+STGIT_SUCCESS = 0 # everything's OK
+STGIT_GENERAL_ERROR = 1 # seems to be non-command-specific error
+STGIT_COMMAND_ERROR = 2 # seems to be a command that failed
^ permalink raw reply related
* [StGit PATCH 3/5] Let parse_patch take a string instead of a file parameter
From: Karl Hasselström @ 2007-12-14 6:25 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062251.29148.86191.stgit@yoghurt>
This makes it more generally useful, since all future callers may not
have the input in a file.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/common.py | 6 +++---
stgit/commands/edit.py | 3 ++-
stgit/commands/imprt.py | 2 +-
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/stgit/commands/common.py b/stgit/commands/common.py
index 3840387..7cf700e 100644
--- a/stgit/commands/common.py
+++ b/stgit/commands/common.py
@@ -482,11 +482,11 @@ def parse_mail(msg):
return (descr, authname, authemail, authdate, diff)
-def parse_patch(fobj):
- """Parse the input file and return (description, authname,
+def parse_patch(text):
+ """Parse the input text and return (description, authname,
authemail, authdate, diff)
"""
- descr, diff = __split_descr_diff(fobj.read())
+ descr, diff = __split_descr_diff(text)
descr, authname, authemail, authdate = __parse_description(descr)
# we don't yet have an agreed place for the creation date.
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index 4d1475f..65b54d9 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -100,7 +100,8 @@ def __update_patch(pname, fname, options):
f = sys.stdin
else:
f = open(fname)
- message, author_name, author_email, author_date, diff = parse_patch(f)
+ (message, author_name, author_email, author_date, diff
+ ) = parse_patch(f.read())
f.close()
out.start('Updating patch "%s"' % pname)
diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index 1c21a74..4a4b792 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -192,7 +192,7 @@ def __import_file(filename, options, patch = None):
parse_mail(msg)
else:
message, author_name, author_email, author_date, diff = \
- parse_patch(f)
+ parse_patch(f.read())
if filename:
f.close()
^ permalink raw reply related
* [StGit PATCH 4/5] Make generic --message/--file/--save-template flags
From: Karl Hasselström @ 2007-12-14 6:25 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062251.29148.86191.stgit@yoghurt>
And let "stg edit" use them.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/edit.py | 77 +++++++++++++++++++-----------------------------
stgit/utils.py | 45 ++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 47 deletions(-)
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index 65b54d9..b9699d5 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -61,8 +61,6 @@ directory = DirectoryGotoToplevel()
options = [make_option('-d', '--diff',
help = 'edit the patch diff',
action = 'store_true'),
- make_option('-f', '--file',
- help = 'use FILE instead of invoking the editor'),
make_option('-O', '--diff-opts',
help = 'options to pass to git-diff'),
make_option('--undo',
@@ -70,10 +68,6 @@ options = [make_option('-d', '--diff',
action = 'store_true'),
make_option('-a', '--annotate', metavar = 'NOTE',
help = 'annotate the patch log entry'),
- make_option('-m', '--message',
- help = 'replace the patch description with MESSAGE'),
- make_option('--save-template', metavar = 'FILE',
- help = 'save the patch to FILE in the format used by -f'),
make_option('--author', metavar = '"NAME <EMAIL>"',
help = 'replae the author details with "NAME <EMAIL>"'),
make_option('--authname',
@@ -86,47 +80,48 @@ options = [make_option('-d', '--diff',
help = 'replace the committer name with COMMNAME'),
make_option('--commemail',
help = 'replace the committer e-mail with COMMEMAIL')
- ] + make_sign_options()
+ ] + make_sign_options() + make_message_options()
-def __update_patch(pname, fname, options):
- """Update the current patch from the given file.
+def __update_patch(pname, text, options):
+ """Update the current patch from the given text.
"""
patch = crt_series.get_patch(pname)
bottom = patch.get_bottom()
top = patch.get_top()
- if fname == '-':
- f = sys.stdin
- else:
- f = open(fname)
- (message, author_name, author_email, author_date, diff
- ) = parse_patch(f.read())
- f.close()
+ message, author_name, author_email, author_date, diff = parse_patch(text)
out.start('Updating patch "%s"' % pname)
if options.diff:
git.switch(bottom)
try:
- git.apply_patch(fname)
+ git.apply_patch(diff = diff)
except:
# avoid inconsistent repository state
git.switch(top)
raise
+ def c(a, b):
+ if a != None:
+ return a
+ return b
crt_series.refresh_patch(message = message,
- author_name = author_name,
- author_email = author_email,
- author_date = author_date,
- backup = True, log = 'edit')
+ author_name = c(options.authname, author_name),
+ author_email = c(options.authemail, author_email),
+ author_date = c(options.authdate, author_date),
+ committer_name = options.commname,
+ committer_email = options.commemail,
+ backup = True, sign_str = options.sign_str,
+ log = 'edit', notes = options.annotate)
if crt_series.empty_patch(pname):
out.done('empty patch')
else:
out.done()
-def __generate_file(pname, fname, options):
+def __generate_file(pname, write_fn, options):
"""Generate a file containing the description to edit
"""
patch = crt_series.get_patch(pname)
@@ -175,12 +170,7 @@ def __generate_file(pname, fname, options):
text = tmpl % tmpl_dict
# write the file to be edited
- if fname == '-':
- sys.stdout.write(text)
- else:
- f = open(fname, 'w+')
- f.write(text)
- f.close()
+ write_fn(text)
def __edit_update_patch(pname, options):
"""Edit the given patch interactively.
@@ -189,13 +179,17 @@ def __edit_update_patch(pname, options):
fname = '.stgit-edit.diff'
else:
fname = '.stgit-edit.txt'
+ def write_fn(text):
+ f = file(fname, 'w')
+ f.write(text)
+ f.close()
- __generate_file(pname, fname, options)
+ __generate_file(pname, write_fn, options)
# invoke the editor
call_editor(fname)
- __update_patch(pname, fname, options)
+ __update_patch(pname, file(fname).read(), options)
def func(parser, options, args):
"""Edit the given patch or the current one.
@@ -232,25 +226,14 @@ def func(parser, options, args):
out.start('Undoing the editing of "%s"' % pname)
crt_series.undo_refresh()
out.done()
- elif options.message or options.authname or options.authemail \
- or options.authdate or options.commname or options.commemail \
- or options.sign_str:
- # just refresh the patch with the given information
- out.start('Updating patch "%s"' % pname)
- crt_series.refresh_patch(message = options.message,
- author_name = options.authname,
- author_email = options.authemail,
- author_date = options.authdate,
- committer_name = options.commname,
- committer_email = options.commemail,
- backup = True, sign_str = options.sign_str,
- log = 'edit',
- notes = options.annotate)
- out.done()
elif options.save_template:
__generate_file(pname, options.save_template, options)
- elif options.file:
- __update_patch(pname, options.file, options)
+ elif any([options.message, options.authname, options.authemail,
+ options.authdate, options.commname, options.commemail,
+ options.sign_str]):
+ out.start('Updating patch "%s"' % pname)
+ __update_patch(pname, options.message, options)
+ out.done()
else:
__edit_update_patch(pname, options)
diff --git a/stgit/utils.py b/stgit/utils.py
index 3a480c0..837c6c2 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -256,3 +256,48 @@ def add_sign_line(desc, sign_str, name, email):
if not any(s in desc for s in ['\nSigned-off-by:', '\nAcked-by:']):
desc = desc + '\n'
return '%s\n%s\n' % (desc, sign_str)
+
+def make_message_options():
+ def no_dup(parser):
+ if parser.values.message != None:
+ raise optparse.OptionValueError(
+ 'Cannot give more than one --message or --file')
+ def no_combine(parser):
+ if (parser.values.message != None
+ and parser.values.save_template != None):
+ raise optparse.OptionValueError(
+ 'Cannot give both --message/--file and --save-template')
+ def msg_callback(option, opt_str, value, parser):
+ no_dup(parser)
+ parser.values.message = value
+ no_combine(parser)
+ def file_callback(option, opt_str, value, parser):
+ no_dup(parser)
+ if value == '-':
+ parser.values.message = sys.stdin.read()
+ else:
+ f = file(value)
+ parser.values.message = f.read()
+ f.close()
+ no_combine(parser)
+ def templ_callback(option, opt_str, value, parser):
+ if value == '-':
+ def w(s):
+ sys.stdout.write(s)
+ else:
+ def w(s):
+ f = file(value, 'w+')
+ f.write(s)
+ f.close()
+ parser.values.save_template = w
+ no_combine(parser)
+ m = optparse.make_option
+ return [m('-m', '--message', action = 'callback', callback = msg_callback,
+ dest = 'message', type = 'string',
+ help = 'use MESSAGE instead of invoking the editor'),
+ m('-f', '--file', action = 'callback', callback = file_callback,
+ dest = 'message', type = 'string', metavar = 'FILE',
+ help = 'use FILE instead of invoking the editor'),
+ m('--save-template', action = 'callback', callback = templ_callback,
+ metavar = 'FILE', dest = 'save_template', type = 'string',
+ help = 'save the message template to FILE and exit')]
^ permalink raw reply related
* [StGit PATCH 2/5] Treat filename '-' as stdin/stdout in edit
From: Karl Hasselström @ 2007-12-14 6:25 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062251.29148.86191.stgit@yoghurt>
From: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/edit.py | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index ec2c4ae..4d1475f 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -96,7 +96,10 @@ def __update_patch(pname, fname, options):
bottom = patch.get_bottom()
top = patch.get_top()
- f = open(fname)
+ if fname == '-':
+ f = sys.stdin
+ else:
+ f = open(fname)
message, author_name, author_email, author_date, diff = parse_patch(f)
f.close()
@@ -171,9 +174,12 @@ def __generate_file(pname, fname, options):
text = tmpl % tmpl_dict
# write the file to be edited
- f = open(fname, 'w+')
- f.write(text)
- f.close()
+ if fname == '-':
+ sys.stdout.write(text)
+ else:
+ f = open(fname, 'w+')
+ f.write(text)
+ f.close()
def __edit_update_patch(pname, options):
"""Edit the given patch interactively.
^ permalink raw reply related
* [StGit PATCH 1/5] Added --save-template flag to edit command
From: Karl Hasselström @ 2007-12-14 6:25 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
In-Reply-To: <20071214062251.29148.86191.stgit@yoghurt>
From: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/edit.py | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py
index a4d8f96..ec2c4ae 100644
--- a/stgit/commands/edit.py
+++ b/stgit/commands/edit.py
@@ -72,6 +72,8 @@ options = [make_option('-d', '--diff',
help = 'annotate the patch log entry'),
make_option('-m', '--message',
help = 'replace the patch description with MESSAGE'),
+ make_option('--save-template', metavar = 'FILE',
+ help = 'save the patch to FILE in the format used by -f'),
make_option('--author', metavar = '"NAME <EMAIL>"',
help = 'replae the author details with "NAME <EMAIL>"'),
make_option('--authname',
@@ -120,8 +122,8 @@ def __update_patch(pname, fname, options):
else:
out.done()
-def __edit_update_patch(pname, options):
- """Edit the given patch interactively.
+def __generate_file(pname, fname, options):
+ """Generate a file containing the description to edit
"""
patch = crt_series.get_patch(pname)
@@ -168,15 +170,20 @@ def __edit_update_patch(pname, options):
text = tmpl % tmpl_dict
+ # write the file to be edited
+ f = open(fname, 'w+')
+ f.write(text)
+ f.close()
+
+def __edit_update_patch(pname, options):
+ """Edit the given patch interactively.
+ """
if options.diff:
fname = '.stgit-edit.diff'
else:
fname = '.stgit-edit.txt'
- # write the file to be edited
- f = open(fname, 'w+')
- f.write(text)
- f.close()
+ __generate_file(pname, fname, options)
# invoke the editor
call_editor(fname)
@@ -233,6 +240,8 @@ def func(parser, options, args):
log = 'edit',
notes = options.annotate)
out.done()
+ elif options.save_template:
+ __generate_file(pname, options.save_template, options)
elif options.file:
__update_patch(pname, options.file, options)
else:
^ permalink raw reply related
* [StGit PATCH 0/5] Various odds and ends
From: Karl Hasselström @ 2007-12-14 6:24 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git, David Kågedal
Also available from
git://repo.or.cz/stgit/kha.git safe
---
David Kågedal (2):
Treat filename '-' as stdin/stdout in edit
Added --save-template flag to edit command
Karl Hasselström (3):
Name the exit codes to improve legibility
Make generic --message/--file/--save-template flags
Let parse_patch take a string instead of a file parameter
stgit/commands/common.py | 6 ++--
stgit/commands/edit.py | 73 +++++++++++++++++++++++-----------------------
stgit/commands/imprt.py | 2 +
stgit/main.py | 25 ++++++++--------
stgit/utils.py | 50 ++++++++++++++++++++++++++++++++
5 files changed, 103 insertions(+), 53 deletions(-)
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply
* Re: Something is broken in repack
From: Nguyen Thai Ngoc Duy @ 2007-12-14 6:24 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: git, gcc
In-Reply-To: <fjt6vm$n7d$1@ger.gmane.org>
On Dec 14, 2007 1:14 PM, Paolo Bonzini <bonzini@gnu.org> wrote:
> > Hmmm... it is even documented in git-gc(1)... and git-index-pack(1) of
> > all things.
>
> I found that the .keep file is not transmitted over the network (at
> least I tried with git+ssh:// and http:// protocols), however.
I'm thinking about "git clone --keep" to mark initial packs precious.
But 'git clone' is under rewrite to C. Let's wait until C rewrite is
done.
--
Duy
^ permalink raw reply
* Re: Something is broken in repack
From: Paolo Bonzini @ 2007-12-14 6:14 UTC (permalink / raw)
To: git; +Cc: gcc
In-Reply-To: <fjskqt$eap$1@ger.gmane.org>
> Hmmm... it is even documented in git-gc(1)... and git-index-pack(1) of
> all things.
I found that the .keep file is not transmitted over the network (at
least I tried with git+ssh:// and http:// protocols), however.
Paolo
^ permalink raw reply
* Re: [Funky] "git -p cmd" inside a bare repository
From: Junio C Hamano @ 2007-12-14 6:07 UTC (permalink / raw)
To: Jeff King; +Cc: Nguyễn Thái Ngọc Duy, git, Johannes Schindelin
In-Reply-To: <20071214051434.GE10169@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> On Fri, Dec 14, 2007 at 12:12:23AM -0500, Jeff King wrote:
>
>> -- >8 --
>> delay "git -p" page spawning until command runtime
>
> Hrmph. Bad timing. :)
>
> Your patch is much nicer, though, so please ignore mine.
It may look nicer, but I do not know if it is correct, though. I do not
do much "work tree" stuff, and would really appreciate testing by people
who are more involved in that part of the system.
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox