-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
get language from .gitattributes file #14833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
rules: linguist-language=<lang> attribute to an lang linguist-vendored attribute to vendor or un-vendor path ref: https://stackoverflow.com/questions/40659265/using-gitattributes-for-linguist-examples Signed-off-by: a1012112796 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs need to explain this feature & its syntax, similar to https://github.com/github/linguist/blob/master/docs/overrides.md
fixes #14786
Why aren't you using check-attr and already written function that uses it? |
// CheckAttributeOpts represents the possible options to CheckAttribute
type CheckAttributeOpts struct {
CachedOnly bool
AllAttributes bool
Attributes []string
Filenames []string
}
func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[string]string, error) {
...
return name2attribute2info, nil
} The signature of this function isn't great but it could easily be improved. |
Ah... Ok. There's a way to make it work in bare repos - you read-tree into a (temporary) index file and then use that index file with --cached. (Which reminds me as to why I hadn't done this already.) I guess we need to decide which is better - potentially parsing the file incorrectly ourselves versus the complexity of the above operation. Certainly if we're planning on calling gitattribites a lot we don't want to be writing and throwing away index files all the time. I'll have to take a look at the .gitattribites format - iirc it's kinda complex with lots of globbing. We'll have to be cautious with reading this. |
I see, but maybe create index file in the bare repo is a dangerous work, becaue maybe will be double write ... |
No, you can create an index file anywhere and make git use it with the environment variable GIT_INDEX_FILE. Creating a temp repo is very slow. |
Ok The reason for the restore rather than read-tree is that read-tree has to read the entire tree and subtrees so restore should be quicker. It would be great if we could figure out a way to tell check-attr to just use a piped in .gitattributes but I don't think that's possible. |
I see, but sadly can't use |
modules/indexer/stats/db.go
Outdated
return "", false | ||
} | ||
|
||
name2attribute2info, err := gitRepo.CheckAttribute(git.CheckAttributeOpts{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK Now I understand what this is doing - I think we're gonna need a pipe which goes to write to an open
git check-attr --stdin ...
and then read and parse the line produced per path.
Otherwise you're going to get n calls to git check-attr per repository.
…guage stats and diffs (#16773) Replaces #16262 Replaces #16250 Replaces #14833 This PR first implements a `git check-attr` pipe reader - using `git check-attr --stdin -z --cached` - taking account of the change in the output format in git 1.8.5 and creates a helper function to read a tree into a temporary index file for that pipe reader. It then wires this in to the language stats helper and into the git diff generation. Files which are marked generated will be folded by default. Fixes #14786 Fixes #12653
Close via #16773 |
rules:
linguist-language= attribute to an lang
linguist-vendored attribute to vendor or un-vendor path
ref:
https://stackoverflow.com/questions/40659265/using-gitattributes-for-linguist-examples
fixes #14786