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

Re: [PATCH] Add git-save script

From
Nanako Shiraishi <nanako3@bluebottle.com>
Date
Jun 24, 2007, 10:43 UTC
Message-ID
<200706241044.l5OAiMCB012492@mi0.bluebottle.com>
In-Reply-To
<7vmyyq2zrz.fsf@assigned-by-dhcp.pobox.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 11 quoted lines
> Nanako Shiraishi <nanako3@bluebottle.com> writes:
>
>> +function save_work () {
>
> No noiseword "function" for portability.
>
> When you say "#!/bin/sh", you are writing for the family of
> generic Bourne shells, not specifically for korn nor bash.  For
> example, dash is a fine POSIX shell, but does not grok function
> noiseword.  When in doubt, please stay away from things not in
> POSIX (e.g. function, [[, ]], ${parameter//pattern/string/}).
Is there a good reference you can point me?
Show 9 quoted lines
>  - $GIT_DIR could contain shell metachararcters / whitespace, so
>    could $TMP as well.  Always quote such variables, or you risk
>    a surprise from "rm".
>
>  - You probably would not want to create a new "save" if your
>    working tree and the index are clean.  To test for the
>    condition, you can do something like:
>
> 	git-diff --quiet --cached && git-diff --quiet
I did not think of these problems, but I understand now.
Show 7 quoted lines
>  - Although you keep a separate tree for the index (before the
>    "git add -u" to grab the working tree changes) in the saved
>    data, it does not seem to be used.  It _might_ make sense to
>    replace "git add -u" with "git add ." so that work/ tree
>    contains even untracked (but not ignored) files, and on the
>    restore side unstage the paths that appear in work/ but not
>    in indx/.  I dunno.

At first I wanted to do git-add . instead of git-add -u, but then I became worried that will add files that are not interesting such as temporary files.

Show 10 quoted lines
>> +
>> +	head=$(git-log --abbrev-commit --pretty=oneline -n 1 HEAD)
>> +	if branch=$(git symbolic-ref -q HEAD); then
>> +		branch=${branch#refs/heads/}
>> +	else
>> +		branch='(no branch)'
>> +	fi &&
>
> Minor style.  Please don't write "; then\n".  Line-up "then",
> "elif", "else", and "fi"; it is much easier to read that way.
I see.
Show 22 quoted lines
> Nice, but after trying this myself a bit, I seriously wished for
> "git save show -p", so I did it myself, like this:
>
> 	show_save () {
> 		flags=$(git rev-parse --no-revs --flags "$@")
> 		if test -z "$flags"
> 		then
> 			flags=--stat
> 		fi
> 		save=$(git rev-parse --revs-only --no-flags --default saved "$@")
> 		git diff-tree $flags $save:base $save:work
> 	}
>
> It's a dense (and ancient style) plumbing code so needs a bit of
> explanation:
>
>  - The first git-rev-parse looks at "$@", discards everything
>    that are not options and discards object names.  So 'git save
>    show -p some' will give you "-p" in flags.
>
>  - The second one discards flags, and grabs 'some' out of '-p
>    some', or defaults to "saved".

I did not know about these commands. I will study the manual pages and I will re-submit my patch after adding these.

-- 
しらいし ななこ http://ivory.ap.teacup.com/nanako3/

----------------------------------------------------------------------
Get a free email account with anti spam protection.
http://www.bluebottle.com
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 12 in “Add git-save script”
  1. Add git-save scriptNanako Shiraishi, Jun 23, 2007
  2. Johannes SchindelinJun 23, 2007
  3. Bill LearJun 23, 2007
  4. Johannes SchindelinJun 23, 2007
  5. しらいしななこJun 25, 2007
  6. Junio C HamanoJun 25, 2007
  7. Junio C HamanoJun 23, 2007
  8. Nanako ShiraishiJun 24, 2007
  9. Junio C HamanoJun 24, 2007
  10. Junio C HamanoJun 27, 2007
  11. しらいしななこJun 27, 2007
  12. Johannes SchindelinJun 25, 2007

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.