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

Re: [JGIT PATCH v2 14/24] Added the class IgnoreRuleListFactory.

From
Shawn O. Pearce <spearce@spearce.org>
Date
May 14, 2008, 01:06 UTC
Message-ID
<20080514010600.GK29038@spearce.org>
In-Reply-To
<48296B41.9020105@web.de>
Florian Kberle <FloriansKarten@web.de> wrote:
Show 13 quoted lines
> Shawn O. Pearce wrote:
> >
> >Why go through all this work to buffer the lines we don't care about
> >(starting with # or are blank) when we could just discard them in the
> >inside of createIgnoreRuleList and then create the rule right away?
>
> I did this to reduce complexity and to increase modularity.
> The method createIgnoreRuleList(Iterable<String> lineIterable) can now 
> be tested without the need to create files. Also it is so possible to 
> read the patterns from different sources.
> 
> If you worry about memory usuage I could create some kind of 
> RulesBuilder class:

OK. I guess I can see that. I wasn't worried about memory, it just seemed odd to me that the "parser" (splitting the file into lines) was also not skipping the lines that were not interesting.

Given your explanation I don't see a reason to change it, it just
struck me as odd.
 
Show 13 quoted lines
> >I suspect this code would be easier to follow if you just accepted
> >changing the method parameter, such as:
> >
> >	private Rule createRule(String pattern) {
> >		boolean exclude = true;
> >		if (pattern.startsWith("!)) {
> >			pattern = pattern.substring(1);
> >			exclude = false;
> >		}
>
> If I remember correctly Intellij IDEA marks per default cases where you 
> change a parameter. So it looks like that there are style guides which 
> are against the practice of changing the values of parameters.

Yes, there are style guides floating around that say "do not modify parameters". There is also a Java keyword that means "do not modify this variable in scope", its called "final".

Personally I think whether or not something should be final in a scope depends on the size of the scope and what is clearer to read to modify the existing variable, or to introduce a copy with a different name and a potentially different value. Forcing everything to not modify parameters by compiler edict is nuts.

In the code I was talking about you had two different variables for the pattern, just to avoid not modifying the parameter. Yet within the scope of the method once the "!" is cut off the original pattern string is worthless. In my very humble opinion it is more risky to have two different variables (one whose scope has expired the moment the method starts and one that is useful) then to have a mutable parameter.

But as I said, its only my humble opinion.  Since I'm American my
$0.02 is worth what, 0.00000002 rupees these days?  ;-)
 
> I implemented it that way, becasue git behave the same way:
> * create the follwing file: a/a/b/test.txt
> * add the line "a/b" to .gitignore
> * add a and notice that it adds the test.txt file.

OK. You are correct. If the ignore rule contains "/" it appears to only apply from the top level of the repository. That wasn't my understanding of how it worked, but I stand corrected. Thank you.

-- 
Shawn.
Previous: Florian KöberleNext: Florian Koeberle
Message 29 of 46 in “Implementation of a file tree iteration using ignore rules.”
  1. 0/24 Implementation of a file tree iteration using ignore rules.Florian Koeberle, May 12, 2008
  2. 01/24 Start of an implementation of a git like command line tool.Florian Koeberle, May 12, 2008
  3. 02/24 Formatted Repository class.Florian Koeberle, May 12, 2008
  4. 03/24 Formatted Constats class.Florian Koeberle, May 12, 2008
  5. 04/24 Added path related constats to Constats class.Florian Koeberle, May 12, 2008
  6. Shawn O. PearceMay 12, 2008
  7. Florian KöberleMay 23, 2008
  8. 05/24 Added WorkTree class which can be constructed over Repository.Florian Koeberle, May 12, 2008
  9. Shawn O. PearceMay 13, 2008
  10. Robin RosenbergMay 13, 2008
  11. Shawn O. PearceMay 14, 2008
  12. 06/24 Added a "init" command to the git like command line tool.Florian Koeberle, May 12, 2008
  13. 07/24 Added findWorkTree method to Repository class.Florian Koeberle, May 12, 2008
  14. Shawn O. PearceMay 13, 2008
  15. Florian KöberleMay 23, 2008
  16. Miklos VajnaMay 23, 2008
  17. Shawn O. PearceMay 23, 2008
  18. Robin RosenbergMay 23, 2008
  19. 08/24 Added the interface FilePattern.Florian Koeberle, May 12, 2008
  20. 09/24 Added the class Rule.Florian Koeberle, May 12, 2008
  21. 10/24 Added the iterface Rules.Florian Koeberle, May 12, 2008
  22. 11/24 Added the class FNMatchPattern.Florian Koeberle, May 12, 2008
  23. Shawn O. PearceMay 13, 2008
  24. 12/24 Added the class GlobalFilePatternFlorian Koeberle, May 12, 2008
  25. 13/24 Added the class ComplexFilePattern.Florian Koeberle, May 12, 2008
  26. 14/24 Added the class IgnoreRuleListFactory.Florian Koeberle, May 12, 2008
  27. Shawn O. PearceMay 13, 2008
  28. Florian KöberleMay 13, 2008
  29. Shawn O. PearceMay 14, 2008
  30. 15/24 Added a Rules interface implementation and a factory for it.Florian Koeberle, May 12, 2008
  31. 16/24 Added test class OverallIgnoreRulestest.Florian Koeberle, May 12, 2008
  32. 17/24 Added the class TreeFilePattern.Florian Koeberle, May 12, 2008
  33. Shawn O. PearceMay 13, 2008
  34. 18/24 Added InvalidPatternException and PathNotInProjectDirectoryExceptionFlorian Koeberle, May 12, 2008
  35. 19/24 Added the class AddRuleListFactory.Florian Koeberle, May 12, 2008
  36. Shawn O. PearceMay 13, 2008
  37. Florian KöberleMay 13, 2008
  38. Robin RosenbergMay 13, 2008
  39. Shawn O. PearceMay 14, 2008
  40. 20/24 Added class AddRulesFactory.Florian Koeberle, May 12, 2008
  41. 21/24 Added the class LightFileTreeIterator and a test for it.Florian Koeberle, May 12, 2008
  42. Paolo BonziniMay 14, 2008
  43. 22/24 Added class LightFileTreeIterable.Florian Koeberle, May 12, 2008
  44. 23/24 Added the test class AddCommandIterationTest.Florian Koeberle, May 12, 2008
  45. 24/24 Added a "add" command to the git like command line tool.Florian Koeberle, May 12, 2008
  46. Miklos VajnaMay 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.