From: Junio C Hamano <gitster@pobox•com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH 01/24] dir.c: optionally compute sha-1 of a .gitignore file
Date: Wed, 11 Feb 2015 13:23:04 -0800 [thread overview]
Message-ID: <xmqqiof8ta6f.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1423385748-19825-2-git-send-email-pclouds@gmail.com> ("Nguyễn Thái Ngọc Duy"'s message of "Sun, 8 Feb 2015 15:55:25 +0700")
Nguyễn Thái Ngọc Duy <pclouds@gmail•com> writes:
> -int add_excludes_from_file_to_list(const char *fname,
> - const char *base,
> - int baselen,
> - struct exclude_list *el,
> - int check_index)
> +/*
> + * Given a file with name "fname", read it (either from disk, or from
> + * the index if "check_index" is non-zero), parse it and store the
> + * exclude rules in "el".
> + *
> + * If "ss" is not NULL, compute SHA-1 of the exclude file and fill
> + * stat data from disk (only valid if add_excludes returns zero). If
> + * ss_valid is non-zero, "ss" must contain good value as input.
> + */
> +static int add_excludes(const char *fname, const char *base, int baselen,
> + struct exclude_list *el, int check_index,
> + struct sha1_stat *sha1_stat)
> ...
> @@ -571,6 +588,21 @@ int add_excludes_from_file_to_list(const char *fname,
> }
> buf[size++] = '\n';
> close(fd);
> + if (sha1_stat) {
> + int pos;
> + if (sha1_stat->valid &&
> + !match_stat_data(&sha1_stat->stat, &st))
> + ; /* no content change, ss->sha1 still good */
> + else if (check_index &&
> + (pos = cache_name_pos(fname, strlen(fname))) >= 0 &&
> + !ce_stage(active_cache[pos]) &&
> + ce_uptodate(active_cache[pos]))
> + hashcpy(sha1_stat->sha1, active_cache[pos]->sha1);
> + else
> + hash_sha1_file(buf, size, "blob", sha1_stat->sha1);
I do not think this would work well on DOS.
This helper function originally is meant to work *only* on the
checked out representation of the file and that is what is read by
read_in_full(), and that is the reason why it handles the case where
the contents of buf[] happens to be CRLF terminated in the function.
If you want to detect the content changes across working tree, index
and the tree objects by reusing hash_sha1_file(), however, you must
not feed the checked out (aka "smudged") representation to it.
You'd need to turn it into "cleaned" representation by doing the
equivalent of calling index_path(). Some helpers in the callchain
that originates from index_path() might directly be reusable for
your purpose.
next prev parent reply other threads:[~2015-02-11 21:23 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-08 8:55 [PATCH 00/24] nd/untracked-cache updates Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 01/24] dir.c: optionally compute sha-1 of a .gitignore file Nguyễn Thái Ngọc Duy
2015-02-11 21:23 ` Junio C Hamano [this message]
2015-02-16 9:45 ` Duy Nguyen
2015-02-16 21:59 ` Junio C Hamano
2015-02-08 8:55 ` [PATCH 02/24] untracked cache: record .gitignore information and dir hierarchy Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 03/24] untracked cache: initial untracked cache validation Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 04/24] untracked cache: invalidate dirs recursively if .gitignore changes Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 05/24] untracked cache: make a wrapper around {open,read,close}dir() Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 06/24] untracked cache: record/validate dir mtime and reuse cached output Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 07/24] untracked cache: mark what dirs should be recursed/saved Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 08/24] untracked cache: don't open non-existent .gitignore Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 09/24] ewah: add convenient wrapper ewah_serialize_strbuf() Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 10/24] untracked cache: save to an index extension Nguyễn Thái Ngọc Duy
2015-03-07 19:08 ` Stefan Beller
2015-02-08 8:55 ` [PATCH 11/24] untracked cache: load from UNTR " Nguyễn Thái Ngọc Duy
2015-02-09 22:26 ` Junio C Hamano
2015-02-08 8:55 ` [PATCH 12/24] untracked cache: invalidate at index addition or removal Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 13/24] read-cache.c: split racy stat test to a separate function Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 14/24] untracked cache: avoid racy timestamps Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 15/24] untracked cache: print stats with $GIT_TRACE_UNTRACKED_STATS Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 16/24] untracked cache: mark index dirty if untracked cache is updated Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 17/24] untracked-cache: temporarily disable with $GIT_DISABLE_UNTRACKED_CACHE Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 18/24] status: enable untracked cache Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 19/24] update-index: manually enable or disable " Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 20/24] update-index: test the system before enabling " Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 21/24] t7063: tests for " Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 22/24] mingw32: add uname() Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 23/24] untracked cache: guard and disable on system changes Nguyễn Thái Ngọc Duy
2015-02-08 8:55 ` [PATCH 24/24] git-status.txt: advertisement for untracked cache Nguyễn Thái Ngọc Duy
-- strict thread matches above, loose matches on Subject: below --
2015-03-08 10:12 [PATCH 00/24] nd/untracked-cache updates Nguyễn Thái Ngọc Duy
2015-03-08 10:12 ` [PATCH 01/24] dir.c: optionally compute sha-1 of a .gitignore file Nguyễn Thái Ngọc Duy
2015-01-20 13:03 [PATCH 00/24] nd/untracked-cache update Nguyễn Thái Ngọc Duy
2015-01-20 13:03 ` [PATCH 01/24] dir.c: optionally compute sha-1 of a .gitignore file Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqiof8ta6f.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=pclouds@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox