git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Let users override name of per-directory ignore file
@ 2007-10-15 12:09 Andreas Ericsson
  2007-10-22 10:50 ` Karl Hasselström
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Ericsson @ 2007-10-15 12:09 UTC (permalink / raw)
  To: git; +Cc: spearce

When collaborating with projects managed by some other
scm, it often makes sense to have git read that other
scm's ignore-files. This patch lets git do just that, if
the user only tells it the name of the per-directory
ignore file by specifying the newly introduced git config
option 'core.ignorefile'.

Theoretically, this could cause problems when projects get
ported from some other scm to git, but in practice that
is a moot point, as such changes are always followed by a
flagday anyway.

Signed-off-by: Andreas Ericsson <ae@op5.se>
---
 Documentation/config.txt    |   10 ++++++++++
 Documentation/gitignore.txt |    5 +++++
 builtin-add.c               |   11 +++++++++--
 wt-status.c                 |    9 ++++++++-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index edf50cd..5170e27 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -275,6 +275,16 @@ You probably do not need to adjust this value.
 +
 Common unit suffixes of 'k', 'm', or 'g' are supported.
 
+core.ignorefile::
+	Tells git to use a different file for per-directory ignores.
+	This is useful when one wishes to use git for a project
+	when the upstream repository is managed by some other SCM
+	whose ignore-file formats are the same as that of git.
+	For example, setting core.ignorefile to .svnignore in
+	repos where one interacts with the upstream project repo
+	using gitlink:git-svn[1] will make a both SVN users and
+	your own repo ignore the same files.
+
 core.excludesfile::
 	In addition to '.gitignore' (per-directory) and
 	'.git/info/exclude', git looks into this file for patterns
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index e8b8581..f82eac6 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -32,6 +32,11 @@ precedence, the last matching pattern decides the outcome):
    `.gitignore` file.  A project normally includes such
    `.gitignore` files in its repository, containing patterns for
    files generated as part of the project build.
+   The name of the `.gitignore` file can be changed by setting
+   the configuration variable 'core.ignorefile'. This is useful
+   when using git for projects where upstream is using some other
+   SCM. For example, setting 'core.ignorefile' to `.cvsignore`
+   will make git ignore the same files CVS would.
 
  * Patterns read from `$GIT_DIR/info/exclude`.
 
diff --git a/builtin-add.c b/builtin-add.c
index 966e145..c785d99 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -19,6 +19,7 @@ static const char builtin_add_usage[] =
 
 static int take_worktree_changes;
 static const char *excludes_file;
+static const char *ignore_file = ".gitignore";
 
 static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
 {
@@ -57,7 +58,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
 	memset(dir, 0, sizeof(*dir));
 	if (!ignored_too) {
 		dir->collect_ignored = 1;
-		dir->exclude_per_dir = ".gitignore";
+		dir->exclude_per_dir = ignore_file;
 		path = git_path("info/exclude");
 		if (!access(path, R_OK))
 			add_excludes_from_file(dir, path);
@@ -144,6 +145,12 @@ static int git_add_config(const char *var, const char *value)
 		excludes_file = xstrdup(value);
 		return 0;
 	}
+	if (!strcmp(var, "core.ignorefile")) {
+		if (!value)
+			die("core.ignorefile without value");
+		ignore_file = xstrdup(value);
+		return 0;
+	}
 
 	return git_default_config(var, value);
 }
@@ -158,7 +165,7 @@ int interactive_add(void)
 static struct lock_file lock_file;
 
 static const char ignore_error[] =
-"The following paths are ignored by one of your .gitignore files:\n";
+"The following paths are ignored:\n";
 
 int cmd_add(int argc, const char **argv, const char *prefix)
 {
diff --git a/wt-status.c b/wt-status.c
index 03b5ec4..103aefe 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -23,6 +23,7 @@ static const char use_add_rm_msg[] =
 static const char use_add_to_include_msg[] =
 "use \"git add <file>...\" to include in what will be committed";
 static const char *excludes_file;
+static const char *ignore_file = ".gitignore";
 
 static int parse_status_slot(const char *var, int offset)
 {
@@ -257,7 +258,7 @@ static void wt_status_print_untracked(struct wt_status *s)
 
 	memset(&dir, 0, sizeof(dir));
 
-	dir.exclude_per_dir = ".gitignore";
+	dir.exclude_per_dir = ignore_file;
 	if (!s->untracked) {
 		dir.show_other_directories = 1;
 		dir.hide_empty_directories = 1;
@@ -370,5 +371,11 @@ int git_status_config(const char *k, const char *v)
 		excludes_file = xstrdup(v);
 		return 0;
 	}
+	if (!strcmp(k, "core.ignorefile")) {
+		if (!v)
+			die("core.ignorefile without value");
+		ignore_file = xstrdup(v);
+		return 0;
+	}
 	return git_default_config(k, v);
 }
-- 
1.5.3.4.1273.g725c19

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] Let users override name of per-directory ignore file
@ 2007-10-15 12:30 Andreas Ericsson
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Ericsson @ 2007-10-15 12:30 UTC (permalink / raw)
  To: Git Mailing List

When collaborating with projects managed by some other
scm, it often makes sense to have git read that other
scm's ignore-files. This patch lets git do just that, if
the user only tells it the name of the per-directory
ignore file by specifying the newly introduced git config
option 'core.ignorefile'.

Theoretically, this could cause problems when projects get
ported from some other scm to git, but in practice that
is a moot point, as such changes are always followed by a
flagday anyway.

Signed-off-by: Andreas Ericsson <ae@op5.se>
---

I'm in the unfortunate position of being forced to work on a large
amount of projects where the upstream repo is in either CVS or SVN,
and fiddling with exclude-files gets more than just a little tedious.
I've tested this patch lightly. git-status and git-add pick up the
option. "make test" passes as well, and the patch is small enough to
seem obviously correct, so I left it at that.

git-svn should probably set this option by default after a successful
clone, and it has the smell of fruit so low-hanging it's practically
already dropped from the tree, but unfortunately my perl-fu is so weak
I can't even find where to add it. Volunteers?


 Documentation/config.txt    |   10 ++++++++++
 Documentation/gitignore.txt |    5 +++++
 builtin-add.c               |   11 +++++++++--
 wt-status.c                 |    9 ++++++++-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 6b2fc82..267f93c 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -275,6 +275,16 @@ You probably do not need to adjust this value.
 +
 Common unit suffixes of 'k', 'm', or 'g' are supported.
 
+core.ignorefile::
+	Tells git to use a different file for per-directory ignores.
+	This is useful when one wishes to use git for a project
+	when the upstream repository is managed by some other SCM
+	whose ignore-file formats are the same as that of git.
+	For example, setting core.ignorefile to .svnignore in
+	repos where one interacts with the upstream project repo
+	using gitlink:git-svn[1] will make a both SVN users and
+	your own repo ignore the same files.
+
 core.excludesfile::
 	In addition to '.gitignore' (per-directory) and
 	'.git/info/exclude', git looks into this file for patterns
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index e8b8581..f82eac6 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -32,6 +32,11 @@ precedence, the last matching pattern decides the outcome):
    `.gitignore` file.  A project normally includes such
    `.gitignore` files in its repository, containing patterns for
    files generated as part of the project build.
+   The name of the `.gitignore` file can be changed by setting
+   the configuration variable 'core.ignorefile'. This is useful
+   when using git for projects where upstream is using some other
+   SCM. For example, setting 'core.ignorefile' to `.cvsignore`
+   will make git ignore the same files CVS would.
 
  * Patterns read from `$GIT_DIR/info/exclude`.
 
diff --git a/builtin-add.c b/builtin-add.c
index 966e145..c785d99 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -19,6 +19,7 @@ static const char builtin_add_usage[] =
 
 static int take_worktree_changes;
 static const char *excludes_file;
+static const char *ignore_file = ".gitignore";
 
 static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
 {
@@ -57,7 +58,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
 	memset(dir, 0, sizeof(*dir));
 	if (!ignored_too) {
 		dir->collect_ignored = 1;
-		dir->exclude_per_dir = ".gitignore";
+		dir->exclude_per_dir = ignore_file;
 		path = git_path("info/exclude");
 		if (!access(path, R_OK))
 			add_excludes_from_file(dir, path);
@@ -144,6 +145,12 @@ static int git_add_config(const char *var, const char *value)
 		excludes_file = xstrdup(value);
 		return 0;
 	}
+	if (!strcmp(var, "core.ignorefile")) {
+		if (!value)
+			die("core.ignorefile without value");
+		ignore_file = xstrdup(value);
+		return 0;
+	}
 
 	return git_default_config(var, value);
 }
@@ -158,7 +165,7 @@ int interactive_add(void)
 static struct lock_file lock_file;
 
 static const char ignore_error[] =
-"The following paths are ignored by one of your .gitignore files:\n";
+"The following paths are ignored:\n";
 
 int cmd_add(int argc, const char **argv, const char *prefix)
 {
diff --git a/wt-status.c b/wt-status.c
index 03b5ec4..103aefe 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -23,6 +23,7 @@ static const char use_add_rm_msg[] =
 static const char use_add_to_include_msg[] =
 "use \"git add <file>...\" to include in what will be committed";
 static const char *excludes_file;
+static const char *ignore_file = ".gitignore";
 
 static int parse_status_slot(const char *var, int offset)
 {
@@ -257,7 +258,7 @@ static void wt_status_print_untracked(struct wt_status *s)
 
 	memset(&dir, 0, sizeof(dir));
 
-	dir.exclude_per_dir = ".gitignore";
+	dir.exclude_per_dir = ignore_file;
 	if (!s->untracked) {
 		dir.show_other_directories = 1;
 		dir.hide_empty_directories = 1;
@@ -370,5 +371,11 @@ int git_status_config(const char *k, const char *v)
 		excludes_file = xstrdup(v);
 		return 0;
 	}
+	if (!strcmp(k, "core.ignorefile")) {
+		if (!v)
+			die("core.ignorefile without value");
+		ignore_file = xstrdup(v);
+		return 0;
+	}
 	return git_default_config(k, v);
 }
-- 
1.5.3.4.1155.gfe96ee-dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Let users override name of per-directory ignore file
  2007-10-15 12:09 [PATCH] Let users override name of per-directory ignore file Andreas Ericsson
@ 2007-10-22 10:50 ` Karl Hasselström
  2007-10-22 11:18   ` Andreas Ericsson
  0 siblings, 1 reply; 4+ messages in thread
From: Karl Hasselström @ 2007-10-22 10:50 UTC (permalink / raw)
  To: Andreas Ericsson; +Cc: git, spearce

On 2007-10-15 14:09:32 +0200, Andreas Ericsson wrote:

> When collaborating with projects managed by some other scm, it often
> makes sense to have git read that other scm's ignore-files. This
> patch lets git do just that, if the user only tells it the name of
> the per-directory ignore file by specifying the newly introduced git
> config option 'core.ignorefile'.

> +	For example, setting core.ignorefile to .svnignore in
> +	repos where one interacts with the upstream project repo
> +	using gitlink:git-svn[1] will make a both SVN users and
> +	your own repo ignore the same files.

> +   The name of the `.gitignore` file can be changed by setting
> +   the configuration variable 'core.ignorefile'. This is useful
> +   when using git for projects where upstream is using some other
> +   SCM. For example, setting 'core.ignorefile' to `.cvsignore`
> +   will make git ignore the same files CVS would.

I agree with what you're trying to do, but you're ignoring the fact
that Subversion's ignore patterns (and possibly cvs's too -- I haven't
checked) are not recursive, while the patterns in .gitignore are
recursive per default. So using ignore patterns directly from
Subversion ignores more files under git than the same patterns did
under Subversion.

One possible way to solve that would be to optionally have
non-recursive per-directory ignore files. I haven't looked at how this
is implemented, though, so I don't know if it's a good suggestion or
not.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Let users override name of per-directory ignore file
  2007-10-22 10:50 ` Karl Hasselström
@ 2007-10-22 11:18   ` Andreas Ericsson
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Ericsson @ 2007-10-22 11:18 UTC (permalink / raw)
  To: Karl Hasselström; +Cc: git, spearce

Karl Hasselström wrote:
> On 2007-10-15 14:09:32 +0200, Andreas Ericsson wrote:
> 
>> When collaborating with projects managed by some other scm, it often
>> makes sense to have git read that other scm's ignore-files. This
>> patch lets git do just that, if the user only tells it the name of
>> the per-directory ignore file by specifying the newly introduced git
>> config option 'core.ignorefile'.
> 
>> +	For example, setting core.ignorefile to .svnignore in
>> +	repos where one interacts with the upstream project repo
>> +	using gitlink:git-svn[1] will make a both SVN users and
>> +	your own repo ignore the same files.
> 
>> +   The name of the `.gitignore` file can be changed by setting
>> +   the configuration variable 'core.ignorefile'. This is useful
>> +   when using git for projects where upstream is using some other
>> +   SCM. For example, setting 'core.ignorefile' to `.cvsignore`
>> +   will make git ignore the same files CVS would.
> 
> I agree with what you're trying to do, but you're ignoring the fact
> that Subversion's ignore patterns (and possibly cvs's too -- I haven't
> checked) are not recursive, while the patterns in .gitignore are
> recursive per default. So using ignore patterns directly from
> Subversion ignores more files under git than the same patterns did
> under Subversion.
> 

Yes, I just got bitten by this. The top-level .cvsignore file ignores 
Makefile (since it's generated from ./configure), but Makefile exists in 
several subdirectories where it's *not* generated, but adding !Makefile 
to all those places doesn't sit too well with some of the project 
maintainers, and cvs doesn't grok /Makefile to mean "toplevel Makefile" 
(and it shouldn't since it has no notion of recursive ignores).

> One possible way to solve that would be to optionally have
> non-recursive per-directory ignore files. I haven't looked at how this
> is implemented, though, so I don't know if it's a good suggestion or
> not.
> 

I'll have a look at it. Thanks for the review.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-22 11:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-15 12:09 [PATCH] Let users override name of per-directory ignore file Andreas Ericsson
2007-10-22 10:50 ` Karl Hasselström
2007-10-22 11:18   ` Andreas Ericsson
  -- strict thread matches above, loose matches on Subject: below --
2007-10-15 12:30 Andreas Ericsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).