stg refresh wish (splitting patches/removing files from a patch)
Hi,
I recently tried to split a stgit patch into 2 parts and it was not as easy as i would like it to be.
How do i exclude a file from a patch(use version of file present in HEAD^) without modifying the working dir?
with plain git i would use something like git reset HEAD^ files_i_do_not_want_in_first_patch git commit --amend
git add files_i_do_not_want_in_first_patch git commit
So my idea was to add a --use-index [1] option to stg refresh
When it is passed stg refresh will use the current index for the contenst of the refreshed patch instead of looking at the working dir.
This would solve my problem[2] and also make it possible to use git-gui for staging hunks.
Do you think this would be a useful/good idea?
Or do we want a separate command for removing files from a patch anyway?
Another thing that might be useful (in my scenario) would be a stg commit --top extension which commits at the top end of the stack
(unfortunately this will loose the patch history for splitting commits) then i can edit this commits without being afraid of confusing stgit
and then stg assimilate /stg repair to make them managed by stg again
Greetings Peter
[1] rename by desire
[2] new way for splitting a patch with extension git reset HEAD^ files_i_do_not_want_in_first_patch stg refresh --use-index
stg refresh -e
git add files_i_do_not_want_in_first_patch stg new
stg refresh --use-index
PATCH 1/1 refresh: add a --index option which takes the contents of the index as the new commit
just like git commit would do without the -a option
---
Quoted 13 lines · Peter Oberndorfer
Hi,
I recently tried to split a stgit patch into 2 parts and it was not as easy as i would like it to be.How do i exclude a file from a patch(use version of file present in HEAD^) without modifying the working dir?
with plain git i would use something like git reset HEAD^
files_i_do_not_want_in_first_patchgit commit --amend
git addfiles_i_do_not_want_in_first_patchgit commit
Quoted 6 lines
So my idea was to add a --use-index [1] option to stg refresh
When it is passed stg refresh will use the current index for the contenst of the refreshed patch instead of looking at the working dir.
This would solve my problem[2] and also make it possible to use git-gui for staging hunks.
OK, i got off my ass and hacked together the following patch
based on git://repo.or.cz/stgit/kha.git experimental
And i used it to create and update this commit a few times :-) Additionally it passes the (minimal) test i added.
But since i am not a stgit expert it is highly recommend that somebody else carefully looks at the patch before going wild on real data.
Quoted 2 lines
Do you think this would be a useful/good idea?
Or do we want a separate command for removing files from a patch anyway?
The question is still open if this is useful for somebody else.
Greetings Peter
PS: i hope i put the right people on CC
stgit/commands/refresh.py | 25 ++++++++++++++++--- stgit/stack.py | 6 ++++ t/t2700-refresh.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 83 insertions(+), 5 deletions(-)
stgit/commands/refresh.py +21 -4
@@ -45,6 +45,9 @@ options = [make_option('-f', '--force', make_option('--update', help = 'only update the current patch files', action = 'store_true'), + make_option('--index', + help = 'use the current contents of the index instead of looking at the working directory', + action = 'store_true'), make_option('--undo', help = 'revert the commit generated by the last refresh', action = 'store_true'),
@@ -76,6 +79,14 @@ def func(parser, options, args): if not patch: raise CmdException, 'No patches applied' + if options.index: + if args or options.update: + raise CmdException, \ + 'Only full refresh is available with the --index option' + if options.patch: + raise CmdException, \ + '--patch is not (yet) compatible with --index option' + if not options.force: check_head_top_equal(crt_series)
@@ -85,9 +96,10 @@ def func(parser, options, args): out.done() return - files = [path for (stat, path) in git.tree_status(files = args, verbose = True)] + if not options.index: + files = [path for (stat, path) in git.tree_status(files = args, verbose = True)] - if files or not crt_series.head_top_equal(): + if options.index or files or not crt_series.head_top_equal(): if options.patch: applied = crt_series.get_applied() between = applied[:applied.index(patch):-1]
@@ -105,8 +117,13 @@ def func(parser, options, args): if autoresolved == 'yes': resolved_all() - crt_series.refresh_patch(files = files, - backup = True, notes = options.annotate) + + if options.index: + crt_series.refresh_patch(use_index = True, + backup = True, notes = options.annotate) + else: + crt_series.refresh_patch(files = files, + backup = True, notes = options.annotate) if crt_series.empty_patch(patch): out.done('empty patch')
stgit/stack.py +6 -0
@@ -668,6 +668,7 @@ class Series(PatchSet): config.remove_section('branch.%s.stgit' % self.get_name()) def refresh_patch(self, files = None, message = None, edit = False, + use_index = False, empty = False, show_patch = False, cache_update = True,
@@ -717,6 +718,11 @@ class Series(PatchSet): else: tree_id = None + if use_index: + tree_id = None + files = None + cache_update = False + commit_id = git.commit(files = files, message = descr, parents = [bottom], cache_update = cache_update,
t/t2700-refresh.sh +56 -1
68 lines not on this page · raw message
Signature · 1 line
1.5.4.rc2
Re: [STG PATCH] refresh: add a --index option which takes the contents of the index as the new commit
Quoted 6 lines · Peter Oberndorfer
Quoted 2 lines · Peter Oberndorfer
Do you think this would be a useful/good idea? Or do we want a separate command for removing files from a patch anyway?
The question is still open if this is useful for somebody else.
I think it's a useful addition. Thanks!
Quoted 14 lines
stgit/stack.py +1
-0@@ -668,6 +668,7 @@ class Series(PatchSet): config.remove_section('branch.%s.stgit' % self.get_name()) def refresh_patch(self, files = None, message = None, edit = False, + use_index = False, empty = False, show_patch = False, cache_update = True,@@ -717,6 +718,11 @@ class Series(PatchSet): else:
stgit/stack.py class Series(PatchSet): · line 728
Quoted 10 lines
stgit/stack.py +5
-0tree_id = None + if use_index: + tree_id = None + files = None + cache_update = False + commit_id = git.commit(files = files, message = descr, parents = [bottom], cache_update = cache_update,
So the use_index parameter to refresh_patch is actually not necessary? In that case I'd rather you didn't add it, since the functions in stgit/stack.py have quite enough parameters already.
t/t2700-refresh.sh
Quoted 4 lines
t/t2700-refresh.sh +0
-0
Bonus points for adding a test case!
I still haven't rebased my patch stack since Catalin accepted most of it just before Christmas. Once I've gotten around to that, I'll take your patch -- hopefully by then updated to not add the exra argument to refresh_patch(). :-)
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Re: [STG PATCH] refresh: add a --index option which takes the contents of the index as the new commit
Quoted 2 lines · Karl Hasselström
hopefully by then updated to not add the exra argument to
refresh_patch(). :-)
And with a sign-off, too, please.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/1 add a --index option to refresh which takes the contents of the index as the new commit
In reply to Karl HasselströmThis allows to stage only certain changes to a file by only adding
the desired parts to the index with git-gui, ugit, git add -i or another tool that manipulates the index and then run stg refresh --index
it also allows removing a file from a patch by running git reset HEAD^ -- file_to_remove followed by a stg refresh --index
---
Quoted 10 lines · Karl Hasselström
Quoted 6 lines · Peter Oberndorfer
Quoted 2 lines · Peter Oberndorfer
Do you think this would be a useful/good idea? Or do we want a separate command for removing files from a patch anyway?
The question is still open if this is useful for somebody else.
I think it's a useful addition. Thanks!
Good since it was useful for me too even while writing this patch :-)
Quoted 4 lines
So the
use_indexparameter torefresh_patchis actually not necessary? In that case I'd rather you didn't add it, since the functions instgit/stack.pyhave quite enough parameters already.
In the beginning i was afraid it would be to obscure to call it this way with all parameters set to some specific values.
But having more parameters does not make it better :-)
Done
Quoted 7 lines
t/t2700-refresh.sh
Quoted 4 lines
t/t2700-refresh.sh +0
-0Bonus points for adding a test case!
Quoted 5 lines
I still haven't rebased my patch stack since Catalin accepted most of it just before Christmas. Once I've gotten around to that, I'll take your patch -- hopefully by then updated to not add the exra argument to
refresh_patch(). :-)
Patch now comes with a Signed-off-by and a log message that explains how this feature could be used.
It was tested with the testcase, used during development of this patch and on another repo, but still take care when using it :-)
stgit/commands/refresh.py | 25 ++++++++++++++++--- t/t2700-refresh.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 5 deletions(-)
stgit/commands/refresh.py +21 -4
@@ -45,6 +45,9 @@ options = [make_option('-f', '--force', make_option('--update', help = 'only update the current patch files', action = 'store_true'), + make_option('--index', + help = 'use the current contents of the index instead of looking at the working directory', + action = 'store_true'), make_option('--undo', help = 'revert the commit generated by the last refresh', action = 'store_true'),
@@ -76,6 +79,14 @@ def func(parser, options, args): if not patch: raise CmdException, 'No patches applied' + if options.index: + if args or options.update: + raise CmdException, \ + 'Only full refresh is available with the --index option' + if options.patch: + raise CmdException, \ + '--patch is not compatible with the --index option' + if not options.force: check_head_top_equal(crt_series)
@@ -85,9 +96,10 @@ def func(parser, options, args): out.done() return - files = [path for (stat, path) in git.tree_status(files = args, verbose = True)] + if not options.index: + files = [path for (stat, path) in git.tree_status(files = args, verbose = True)] - if files or not crt_series.head_top_equal(): + if options.index or files or not crt_series.head_top_equal(): if options.patch: applied = crt_series.get_applied() between = applied[:applied.index(patch):-1]
@@ -105,8 +117,13 @@ def func(parser, options, args): if autoresolved == 'yes': resolved_all() - crt_series.refresh_patch(files = files, - backup = True, notes = options.annotate) + + if options.index: + crt_series.refresh_patch(cache_update = False, + backup = True, notes = options.annotate) + else: + crt_series.refresh_patch(files = files, + backup = True, notes = options.annotate) if crt_series.empty_patch(patch): out.done('empty patch')
t/t2700-refresh.sh +56 -1
68 lines not on this page · raw message
Signature · 1 line
1.5.4.rc2
Re: [STG PATCH] add a --index option to refresh which takes the contents of the index as the new commit
Quoted 9 lines · Peter Oberndorfer
Quoted 3 lines · Karl Hasselström
So the
use_indexparameter torefresh_patchis actually not necessary? In that case I'd rather you didn't add it, since the functions instgit/stack.pyhave quite enough parameters already.In the beginning i was afraid it would be to obscure to call it this way with all parameters set to some specific values. But having more parameters does not make it better :-) Done
Thanks.
Quoted 4 lines
Patch now comes with a Signed-off-by and a log message that explains how this feature could be used. It was tested with the testcase, used during development of this patch and on another repo, but still take care when using it :-)
I may be promising too much now, but hopefully I'll get to this tonight.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Re: [STG PATCH] add a --index option to refresh which takes the contents of the index as the new commit
Quoted 9 lines · Karl Hasselström
Quoted 4 lines · Peter Oberndorfer
Patch now comes with a Signed-off-by and a log message that explains how this feature could be used. It was tested with the testcase, used during development of this patch and on another repo, but still take care when using it :-)
I may be promising too much now, but hopefully I'll get to this tonight.
I've rebased my patch stack on top of Catalin's master now, and put your two patches on top. The --index patch is only in experimental and not stable, since you recommend further testing.
I massaged the commit messages slightly, mainly to get a reasonably short first line and end all sentences with a period (except on the first line, of course!).
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle