git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Subject: [PATCH] fix stg edit command

From
Karl Hasselström <kha@treskal.com>
Date
Feb 12, 2008, 22:47 UTC
Message-ID
<20080212224724.GA24993@diana.vm.bytemark.co.uk>
In-Reply-To
<200802122305.05696.kumbayo84@arcor.de>
On 2008-02-12 23:05:05 +0100, Peter Oberndorfer wrote:
> While testing my editor searching ordering patch i found that this
> patch(Refactor --author/--committer options) seems to break "stg
> edit" (without arguments) starting a interactive editor for me. When
> i issue "stg edit" it silently does nothing.

Thanks for the report. And yes, as far as I can tell your analysis is spot on. In the initial patch I remember being careful to not replace cd unless it was actually changed, but obviously I got sloppy after that. :-(

Show 15 quoted lines
> It seems the following comparison does not return True
>
> > # Let user edit the patch manually.
> > if cd == orig_cd or options.edit:
>
> I can work around this by adding a comparison function to Commitdata
> but maybe __eq__ or __ne__ should be used instead(prevent similar
> bugs caused by == comparison)?
>
> +    def is_same(self, other):
> +        return (self.__tree == other.__tree and
> +                self.__parents == other.__parents and
> +                self.__author == other.__author and
> +                self.__committer == other.__committer and
> +                self.__message == other.__message)

Yes, you'd definitely want the common operators to work. But I usually implement __cmp__ instead of __eq__ and __ne__ -- that gives you all of <, <=, =, !=, >=, and > for the price of a single method. And it's usually possible to define it rather simply in terms of cmp() with tuple arguments, like this:

    def __cmp__(self, other):
        return cmp((self.__tree, self.__parents, self.__author,
                    self.__committer, self.__message),
                   (other.__tree, other.__parents, other.__author,
                    other.__committer, other.__message))

This sidesteps the great problem of cmp -- having to remember when to return 1 and when to return -1.

> So another way to fix this might be, to not overwrite cd
> unconditionally.

Yes, this is what we want -- if the user gives --author, we shouldn't open the interactive editor even if the given author is the same as the patch already had.

Updated patch on the way.
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Previous: Peter OberndorferNext: Karl Hasselström
Message 7 of 21 in “StGit: kha/safe and kha/experimental updated”
  1. Karl HasselströmFeb 10, 2008
  2. 0/5 Convert "stg new" to the new infrastructureKarl Hasselström, Feb 10, 2008
  3. 1/5 Disable patchlog test for "stg new"Karl Hasselström, Feb 10, 2008
  4. 2/5 Convert "stg new" to the new infrastructureKarl Hasselström, Feb 10, 2008
  5. 3/5 Refactor --author/--committer optionsKarl Hasselström, Feb 10, 2008
  6. Subject: [PATCH] fix stg edit commandPeter Oberndorfer, Feb 12, 2008
  7. Karl HasselströmFeb 12, 2008
  8. Refactor --author/--committer optionsKarl Hasselström, Feb 12, 2008
  9. 4/5 Let "stg new" support more message optionsKarl Hasselström, Feb 10, 2008
  10. 5/5 Emacs mode: use "stg new --file"Karl Hasselström, Feb 10, 2008
  11. David KågedalFeb 11, 2008
  12. Karl HasselströmFeb 11, 2008
  13. 0/2 Convert "stg delete" to the new infrastructureKarl Hasselström, Feb 10, 2008
  14. 1/2 Convert "stg delete" to the new infrastructureKarl Hasselström, Feb 10, 2008
  15. 2/2 Emacs mode: delete patchesKarl Hasselström, Feb 10, 2008
  16. David KågedalFeb 11, 2008
  17. Karl HasselströmFeb 11, 2008
  18. David KågedalFeb 11, 2008
  19. 1/2 Emacs mode: change "stg repair" bindingKarl Hasselström, Feb 11, 2008
  20. 2/2 Emacs mode: delete patchesKarl Hasselström, Feb 11, 2008
  21. Catalin MarinasFeb 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.